diff options
Diffstat (limited to 'src/fetch/amazonfetcher.cpp')
-rw-r--r-- | src/fetch/amazonfetcher.cpp | 117 |
1 files changed, 77 insertions, 40 deletions
diff --git a/src/fetch/amazonfetcher.cpp b/src/fetch/amazonfetcher.cpp index 9088643..1cb6b0c 100644 --- a/src/fetch/amazonfetcher.cpp +++ b/src/fetch/amazonfetcher.cpp @@ -12,6 +12,7 @@ ***************************************************************************/ #include "amazonfetcher.h" +#include "amazonrequest.h" #include "messagehandler.h" #include "../translators/xslthandler.h" #include "../translators/tellicoimporter.h" @@ -47,7 +48,6 @@ namespace { static const int AMAZON_RETURNS_PER_REQUEST = 10; static const int AMAZON_MAX_RETURNS_TOTAL = 20; - static const char* AMAZON_ACCESS_KEY = "0834VQ4S71KYPVSYQD02"; static const char* AMAZON_ASSOC_TOKEN = "tellico-20"; // need to have these in the translation file static const char* linkText = I18N_NOOP("Amazon Link"); @@ -84,7 +84,6 @@ const AmazonFetcher::SiteData& AmazonFetcher::siteData(int site_) { AmazonFetcher::AmazonFetcher(Site site_, TQObject* parent_, const char* name_) : Fetcher(parent_, name_), m_xsltHandler(0), m_site(site_), m_imageSize(MediumImage), - m_access(TQString::fromLatin1(AMAZON_ACCESS_KEY)), m_assoc(TQString::fromLatin1(AMAZON_ASSOC_TOKEN)), m_addLinkField(true), m_limit(AMAZON_MAX_RETURNS_TOTAL), m_countOffset(0), m_page(1), m_total(-1), m_numResults(0), m_job(0), m_started(false) { m_name = siteData(site_).title; @@ -109,7 +108,8 @@ bool AmazonFetcher::canFetch(int type) const { || type == Data::Collection::Bibtex || type == Data::Collection::Album || type == Data::Collection::Video - || type == Data::Collection::Game; + || type == Data::Collection::Game + || type == Data::Collection::BoardGame; } void AmazonFetcher::readConfigHook(const TDEConfigGroup& config_) { @@ -117,6 +117,10 @@ void AmazonFetcher::readConfigHook(const TDEConfigGroup& config_) { if(!s.isEmpty()) { m_access = s; } + s = config_.readEntry("SecretKey"); + if(!s.isEmpty()) { + m_amazonKey = s; + } s = config_.readEntry("AssocToken"); if(!s.isEmpty()) { m_assoc = s; @@ -152,35 +156,41 @@ void AmazonFetcher::doSearch() { // myDebug() << "AmazonFetcher::doSearch() - getting page " << m_page << endl; const SiteData& data = siteData(m_site); - KURL u = data.url; - u.addQueryItem(TQString::fromLatin1("Service"), TQString::fromLatin1("AWSECommerceService")); - u.addQueryItem(TQString::fromLatin1("AssociateTag"), m_assoc); - u.addQueryItem(TQString::fromLatin1("AWSAccessKeyId"), m_access); - u.addQueryItem(TQString::fromLatin1("Operation"), TQString::fromLatin1("ItemSearch")); - u.addQueryItem(TQString::fromLatin1("ResponseGroup"), TQString::fromLatin1("Large")); - u.addQueryItem(TQString::fromLatin1("ItemPage"), TQString::number(m_page)); - u.addQueryItem(TQString::fromLatin1("Version"), TQString::fromLatin1("2007-10-29")); + + TQMap<TQString, TQString> params; + params.insert(TQString::fromLatin1("Service"), TQString::fromLatin1("AWSECommerceService")); + params.insert(TQString::fromLatin1("AssociateTag"), m_assoc); + params.insert(TQString::fromLatin1("AWSAccessKeyId"), m_access); + params.insert(TQString::fromLatin1("Operation"), TQString::fromLatin1("ItemSearch")); + params.insert(TQString::fromLatin1("ResponseGroup"), TQString::fromLatin1("Large")); + params.insert(TQString::fromLatin1("ItemPage"), TQString::number(m_page)); + params.insert(TQString::fromLatin1("Version"), TQString::fromLatin1("2007-10-29")); const int type = Kernel::self()->collectionType(); switch(type) { case Data::Collection::Book: case Data::Collection::ComicBook: case Data::Collection::Bibtex: - u.addQueryItem(TQString::fromLatin1("SearchIndex"), TQString::fromLatin1("Books")); - u.addQueryItem(TQString::fromLatin1("SortIndex"), TQString::fromLatin1("relevancerank")); + params.insert(TQString::fromLatin1("SearchIndex"), TQString::fromLatin1("Books")); + params.insert(TQString::fromLatin1("SortIndex"), TQString::fromLatin1("relevancerank")); break; case Data::Collection::Album: - u.addQueryItem(TQString::fromLatin1("SearchIndex"), TQString::fromLatin1("Music")); + params.insert(TQString::fromLatin1("SearchIndex"), TQString::fromLatin1("Music")); break; case Data::Collection::Video: - u.addQueryItem(TQString::fromLatin1("SearchIndex"), TQString::fromLatin1("Video")); - u.addQueryItem(TQString::fromLatin1("SortIndex"), TQString::fromLatin1("relevancerank")); + params.insert(TQString::fromLatin1("SearchIndex"), TQString::fromLatin1("Video")); + params.insert(TQString::fromLatin1("SortIndex"), TQString::fromLatin1("relevancerank")); break; case Data::Collection::Game: - u.addQueryItem(TQString::fromLatin1("SearchIndex"), TQString::fromLatin1("VideoGames")); + params.insert(TQString::fromLatin1("SearchIndex"), TQString::fromLatin1("VideoGames")); + break; + + case Data::Collection::BoardGame: + params.insert(TQString::fromLatin1("SearchIndex"), TQString::fromLatin1("Toys")); + params.insert(TQString::fromLatin1("SortIndex"), TQString::fromLatin1("relevancerank")); break; case Data::Collection::Coin: @@ -188,7 +198,6 @@ void AmazonFetcher::doSearch() { case Data::Collection::Wine: case Data::Collection::Base: case Data::Collection::Card: - default: message(i18n("%1 does not allow searching for this collection type.").arg(source()), MessageHandler::Warning); stop(); return; @@ -207,29 +216,28 @@ void AmazonFetcher::doSearch() { switch(m_key) { case Title: - u.addQueryItem(TQString::fromLatin1("Title"), value, mib); + params.insert(TQString::fromLatin1("Title"), value); break; case Person: if(type == Data::Collection::Video) { - u.addQueryItem(TQString::fromLatin1("Actor"), value, mib); - u.addQueryItem(TQString::fromLatin1("Director"), value, mib); + params.insert(TQString::fromLatin1("Actor"), value); + params.insert(TQString::fromLatin1("Director"), value); } else if(type == Data::Collection::Album) { - u.addQueryItem(TQString::fromLatin1("Artist"), value, mib); + params.insert(TQString::fromLatin1("Artist"), value); } else if(type == Data::Collection::Game) { - u.addQueryItem(TQString::fromLatin1("Manufacturer"), value, mib); + params.insert(TQString::fromLatin1("Manufacturer"), value); } else { // books and bibtex TQString s = TQString::fromLatin1("author:%1 or publisher:%2").arg(value, value); -// u.addQueryItem(TQString::fromLatin1("Author"), value, mib); -// u.addQueryItem(TQString::fromLatin1("Publisher"), value, mib); - u.addQueryItem(TQString::fromLatin1("Power"), s, mib); +// params.insert(TQString::fromLatin1("Author"), value, mib); +// params.insert(TQString::fromLatin1("Publisher"), value, mib); + params.insert(TQString::fromLatin1("Power"), s); } break; case ISBN: { - u.removeQueryItem(TQString::fromLatin1("Operation")); - u.addQueryItem(TQString::fromLatin1("Operation"), TQString::fromLatin1("ItemLookup")); + params.insert(TQString::fromLatin1("Operation"), TQString::fromLatin1("ItemLookup")); TQString s = m_value; // not encValue!!! s.remove('-'); @@ -260,47 +268,46 @@ void AmazonFetcher::doSearch() { } } // the default search is by ASIN, which prohibits SearchIndex - u.removeQueryItem(TQString::fromLatin1("SearchIndex")); + params.remove(TQString::fromLatin1("SearchIndex")); } // limit to first 10 while(isbns.size() > 10) { isbns.pop_back(); } - u.addQueryItem(TQString::fromLatin1("ItemId"), isbns.join(TQString::fromLatin1(","))); + params.insert(TQString::fromLatin1("ItemId"), isbns.join(TQString::fromLatin1(","))); if(isbn13) { - u.addQueryItem(TQString::fromLatin1("IdType"), TQString::fromLatin1("EAN")); + params.insert(TQString::fromLatin1("IdType"), TQString::fromLatin1("EAN")); } } break; case UPC: { - u.removeQueryItem(TQString::fromLatin1("Operation")); - u.addQueryItem(TQString::fromLatin1("Operation"), TQString::fromLatin1("ItemLookup")); + params.insert(TQString::fromLatin1("Operation"), TQString::fromLatin1("ItemLookup")); // US allows UPC, all others are EAN if(m_site == US) { - u.addQueryItem(TQString::fromLatin1("IdType"), TQString::fromLatin1("UPC")); + params.insert(TQString::fromLatin1("IdType"), TQString::fromLatin1("UPC")); } else { - u.addQueryItem(TQString::fromLatin1("IdType"), TQString::fromLatin1("EAN")); + params.insert(TQString::fromLatin1("IdType"), TQString::fromLatin1("EAN")); } TQString s = m_value; // not encValue!!! s.remove('-'); // limit to first 10 s.replace(TQString::fromLatin1("; "), TQString::fromLatin1(",")); s = s.section(',', 0, 9); - u.addQueryItem(TQString::fromLatin1("ItemId"), s); + params.insert(TQString::fromLatin1("ItemId"), s); } break; case Keyword: - u.addQueryItem(TQString::fromLatin1("Keywords"), m_value, mib); + params.insert(TQString::fromLatin1("Keywords"), value); break; case Raw: { TQString key = value.section('=', 0, 0).stripWhiteSpace(); TQString str = value.section('=', 1).stripWhiteSpace(); - u.addQueryItem(key, str, mib); + params.insert(key, str); } break; @@ -309,9 +316,11 @@ void AmazonFetcher::doSearch() { stop(); return; } -// myDebug() << "AmazonFetcher::search() - url: " << u.url() << endl; + AmazonRequest request(siteData(m_site).url, m_amazonKey); + KURL newUrl = request.signedRequest(params); +// myDebug() << "AmazonFetcher::search() - url: " << newUrl.url() << endl; - m_job = TDEIO::get(u, false, false); + m_job = TDEIO::get(newUrl, false, false); connect(m_job, TQT_SIGNAL(data(TDEIO::Job*, const TQByteArray&)), TQT_SLOT(slotData(TDEIO::Job*, const TQByteArray&))); connect(m_job, TQT_SIGNAL(result(TDEIO::Job*)), @@ -520,6 +529,12 @@ void AmazonFetcher::slotComplete(TDEIO::Job* job_) { + entry->field(TQString::fromLatin1("year")); break; + case Data::Collection::BoardGame: + desc = entry->field(TQString::fromLatin1("publisher")) + + TQChar('/') + + entry->field(TQString::fromLatin1("year")); + break; + default: break; } @@ -889,11 +904,25 @@ AmazonFetcher::ConfigWidget::ConfigWidget(TQWidget* parent_, const AmazonFetcher TQWhatsThis::add(m_assocEdit, w); label->setBuddy(m_assocEdit); + label = new TQLabel(i18n("Access key: "), optionsWidget()); + l->addWidget(label, ++row, 0); + m_accessEdit = new KLineEdit(optionsWidget()); + connect(m_accessEdit, SIGNAL(textChanged(const TQString&)), SLOT(slotSetModified())); + l->addWidget(m_accessEdit, row, 1); + + label = new TQLabel(i18n("Secret Key: "), optionsWidget()); + l->addWidget(label, ++row, 0); + m_secretKeyEdit = new KLineEdit(optionsWidget()); + connect(m_secretKeyEdit, SIGNAL(textChanged(const TQString&)), SLOT(slotSetModified())); + l->addWidget(m_secretKeyEdit, row, 1); + l->setRowStretch(++row, 10); if(fetcher_) { m_siteCombo->setCurrentData(fetcher_->m_site); m_assocEdit->setText(fetcher_->m_assoc); + m_accessEdit->setText(fetcher_->m_access); + m_secretKeyEdit->setText(fetcher_->m_amazonKey); m_imageCombo->setCurrentData(fetcher_->m_imageSize); } else { // defaults m_assocEdit->setText(TQString::fromLatin1(AMAZON_ASSOC_TOKEN)); @@ -912,6 +941,14 @@ void AmazonFetcher::ConfigWidget::saveConfig(TDEConfigGroup& config_) { if(!s.isEmpty()) { config_.writeEntry("AssocToken", s); } + s = m_accessEdit->text().stripWhiteSpace(); + if(!s.isEmpty()) { + config_.writeEntry("AccessKey", s); + } + s = m_secretKeyEdit->text().stripWhiteSpace(); + if(!s.isEmpty()) { + config_.writeEntry("SecretKey", s); + } n = m_imageCombo->currentData().toInt(); config_.writeEntry("Image Size", n); |