[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: extragear/office/tellico
From: Robby Stephenson <robby () periapsis ! org>
Date: 2009-07-15 3:45:39
Message-ID: 1247629539.990903.13109.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 996869 by rstephenson:
initial work to enable new Amazon API. Requires QCA2 for signing requests
M +10 -0 CMakeLists.txt
M +2 -0 config.h.cmake
M +4 -0 src/CMakeLists.txt
M +1 -0 src/fetch/CMakeLists.txt
M +70 -9 src/fetch/amazonfetcher.cpp
M +3 -0 src/fetch/amazonfetcher.h
A src/fetch/amazonrequest.cpp [License: GPL (v2/3)]
A src/fetch/amazonrequest.h [License: GPL (v2/3)]
M +3 -3 src/fetch/crossreffetcher.cpp
M +45 -1 src/tellico_kernel.cpp
M +8 -0 src/tellico_kernel.h
--- trunk/extragear/office/tellico/CMakeLists.txt #996868:996869
@@ -78,6 +78,15 @@
include_directories(${LIBEXEMPI_INCLUDE_DIR})
endif(LIBEXEMPI_FOUND)
+macro_optional_find_package(QCA2)
+macro_log_feature(QCA2_FOUND "QCA" "Support for signing Amazon requests" \
"http://api.kde.org/kdesupport-api/kdesupport-apidocs/qca/html/" FALSE "2.0" "") \
+if(QCA2_FOUND) +# add_definitions(${PC_QCA2_DEFINITIONS})
+ include_directories(${QCA2_INCLUDE_DIR})
+else(QCA2_FOUND)
+ set(ENABLE_AMAZON FALSE)
+endif(QCA2_FOUND)
+
if(CMAKE_SYSTEM_NAME MATCHES Linux)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Wno-long-long \
-pedantic -Wextra -fno-check-new") endif(CMAKE_SYSTEM_NAME MATCHES Linux)
@@ -125,6 +134,7 @@
macro_bool_to_01(KCDDB_FOUND HAVE_KCDDB)
macro_bool_to_01(KABC_FOUND HAVE_KABC)
macro_bool_to_01(KCAL_FOUND HAVE_KCAL)
+macro_bool_to_01(QCA2_FOUND HAVE_QCA2)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake \
${CMAKE_CURRENT_BINARY_DIR}/config.h)
--- trunk/extragear/office/tellico/config.h.cmake #996868:996869
@@ -33,3 +33,5 @@
#cmakedefine HAVE_YAZ
#cmakedefine HAVE_KSANE
+
+#cmakedefine HAVE_QCA2
--- trunk/extragear/office/tellico/src/CMakeLists.txt #996868:996869
@@ -132,6 +132,10 @@
TARGET_LINK_LIBRARIES(tellico ${KSANE_LIBRARY})
ENDIF( KSANE_FOUND )
+IF( QCA2_FOUND )
+ TARGET_LINK_LIBRARIES(tellico ${QCA2_LIBRARIES})
+ENDIF( QCA2_FOUND )
+
INSTALL( TARGETS tellico ${INSTALL_TARGETS_DEFAULT_ARGS} )
########### install files ###############
--- trunk/extragear/office/tellico/src/fetch/CMakeLists.txt #996868:996869
@@ -4,6 +4,7 @@
SET(fetch_STAT_SRCS
amazonfetcher.cpp
+ amazonrequest.cpp
animenfofetcher.cpp
arxivfetcher.cpp
bibsonomyfetcher.cpp
--- trunk/extragear/office/tellico/src/fetch/amazonfetcher.cpp #996868:996869
@@ -23,6 +23,7 @@
***************************************************************************/
#include "amazonfetcher.h"
+#include "amazonrequest.h"
#include "messagehandler.h"
#include "searchresult.h"
#include "../translators/xslthandler.h"
@@ -34,9 +35,10 @@
#include "../entry.h"
#include "../field.h"
#include "../tellico_utils.h"
-#include "../tellico_debug.h"
+#include "../tellico_kernel.h"
#include "../utils/isbnvalidator.h"
#include "../gui/combobox.h"
+#include "../tellico_debug.h"
#include <klocale.h>
#include <kio/job.h>
@@ -60,7 +62,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");
@@ -97,7 +98,6 @@
AmazonFetcher::AmazonFetcher(Site site_, QObject* parent_)
: Fetcher(parent_), m_xsltHandler(0), m_site(site_), m_imageSize(MediumImage),
- m_access(QLatin1String(AMAZON_ACCESS_KEY)),
m_assoc(QLatin1String(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;
@@ -131,6 +131,12 @@
QString s = config_.readEntry("AccessKey");
if(!s.isEmpty()) {
m_access = s;
+ QByteArray maybeKey = Kernel::self()->readWalletEntry(m_access);
+ if(!maybeKey.isNull()) {
+ m_amazonKey = maybeKey;
+ } else {
+ myDebug() << "no amazon secret key found";
+ }
}
s = config_.readEntry("AssocToken");
if(!s.isEmpty()) {
@@ -161,6 +167,14 @@
}
void AmazonFetcher::doSearch() {
+ if(m_access.isEmpty() || m_amazonKey.isEmpty()) {
+ message(i18n("Access to data from Amazon.com requires an AWS Access Key ID and a \
Secret Key.") + + QLatin1Char(' ') +
+ i18n("Those values must be entered in the data source settings."), \
MessageHandler::Error); + stop();
+ return;
+ }
+
// myDebug() << "value = " << m_value;
// myDebug() << "getting page " << m_page;
@@ -326,9 +340,13 @@
stop();
return;
}
-// myDebug() << "url: " << u.url();
+// myDebug() << u;
- m_job = KIO::storedGet(u, KIO::NoReload, KIO::HideProgressInfo);
+ AmazonRequest request(data.url, m_amazonKey);
+ KUrl newUrl = request.signedRequest(u.queryItems());
+// myDebug() << newUrl;
+
+ m_job = KIO::storedGet(newUrl, KIO::NoReload, KIO::HideProgressInfo);
m_job->ui()->setWindow(GUI::Proxy::widget());
connect(m_job, SIGNAL(result(KJob*)),
SLOT(slotComplete(KJob*)));
@@ -813,8 +831,41 @@
l->setColumnStretch(1, 10);
int row = -1;
- QLabel* label = new QLabel(i18n("Co&untry: "), optionsWidget());
+
+ QLabel* al = new QLabel(i18n("An Access ID and Secret Key are required for \
accessing the Amazon Web Services. " + "If you agree to \
the terms and conditions, " + "<a \
href='https://affiliate-program.amazon.com/gp/flex/advertising/api/sign-in.html'>" + \
"sign up for an account</a>, and enter your account information below."), + \
optionsWidget()); + al->setOpenExternalLinks(true);
+ al->setWordWrap(true);
+ ++row;
+ l->addWidget(al, row, 0, 1, 2);
+ // richtext gets weird with size
+ al->setMinimumWidth(al->sizeHint().width());
+
+ QLabel* label = new QLabel(i18n("Access key &ID: "), optionsWidget());
l->addWidget(label, ++row, 0);
+ m_accessEdit = new KLineEdit(optionsWidget());
+ connect(m_accessEdit, SIGNAL(textChanged(const QString&)), \
SLOT(slotSetModified())); + l->addWidget(m_accessEdit, row, 1);
+ QString w = i18n("Access to data from Amazon.com requires an AWS Access Key ID and \
a Secret Key."); + label->setWhatsThis(w);
+ m_accessEdit->setWhatsThis(w);
+ label->setBuddy(m_accessEdit);
+
+ label = new QLabel(i18n("Secret &key: "), optionsWidget());
+ l->addWidget(label, ++row, 0);
+ m_secretKeyEdit = new KLineEdit(optionsWidget());
+ m_secretKeyEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit);
+ connect(m_secretKeyEdit, SIGNAL(textChanged(const QString&)), \
SLOT(slotSetModified())); + l->addWidget(m_secretKeyEdit, row, 1);
+ label->setWhatsThis(w);
+ m_secretKeyEdit->setWhatsThis(w);
+ label->setBuddy(m_secretKeyEdit);
+
+ label = new QLabel(i18n("Co&untry: "), optionsWidget());
+ l->addWidget(label, ++row, 0);
m_siteCombo = new GUI::ComboBox(optionsWidget());
m_siteCombo->addItem(i18n("United States"), US);
m_siteCombo->addItem(i18n("United Kingdom"), UK);
@@ -825,8 +876,8 @@
connect(m_siteCombo, SIGNAL(activated(int)), SLOT(slotSetModified()));
connect(m_siteCombo, SIGNAL(activated(int)), SLOT(slotSiteChanged()));
l->addWidget(m_siteCombo, row, 1);
- QString w = i18n("Amazon.com provides data from several different localized sites. \
Choose the one "
- "you wish to use for this data source.");
+ w = i18n("Amazon.com provides data from several different localized sites. Choose \
the one " + "you wish to use for this data source.");
label->setWhatsThis(w);
m_siteCombo->setWhatsThis(w);
label->setBuddy(m_siteCombo);
@@ -861,6 +912,8 @@
if(fetcher_) {
m_siteCombo->setCurrentData(fetcher_->m_site);
+ m_accessEdit->setText(fetcher_->m_access);
+ m_secretKeyEdit->setText(QString::fromUtf8(fetcher_->m_amazonKey));
m_assocEdit->setText(fetcher_->m_assoc);
m_imageCombo->setCurrentData(fetcher_->m_imageSize);
} else { // defaults
@@ -876,8 +929,16 @@
void AmazonFetcher::ConfigWidget::saveConfig(KConfigGroup& config_) {
int n = m_siteCombo->currentData().toInt();
config_.writeEntry("Site", n);
- QString s = m_assocEdit->text().trimmed();
+ QString s = m_accessEdit->text().trimmed();
if(!s.isEmpty()) {
+ config_.writeEntry("AccessKey", s);
+ QByteArray key = m_secretKeyEdit->text().trimmed().toUtf8();
+ if(!key.isEmpty()) {
+ Kernel::self()->writeWalletEntry(s, key);
+ }
+ }
+ s = m_assocEdit->text().trimmed();
+ if(!s.isEmpty()) {
config_.writeEntry("AssocToken", s);
}
n = m_imageCombo->currentData().toInt();
--- trunk/extragear/office/tellico/src/fetch/amazonfetcher.h #996868:996869
@@ -128,6 +128,7 @@
QString m_access;
QString m_assoc;
+ QByteArray m_amazonKey;
bool m_addLinkField;
int m_limit;
int m_countOffset;
@@ -157,6 +158,8 @@
void slotSiteChanged();
private:
+ KLineEdit* m_accessEdit;
+ KLineEdit* m_secretKeyEdit;
KLineEdit* m_assocEdit;
GUI::ComboBox* m_siteCombo;
GUI::ComboBox* m_imageCombo;
--- trunk/extragear/office/tellico/src/fetch/crossreffetcher.cpp #996868:996869
@@ -335,11 +335,11 @@
int row = 0;
QLabel* al = new QLabel(i18n("CrossRef requires an account for access. "
- "Please read the terms and conditions and "
+ "If you agree to the terms and conditions, "
"<a href='http://www.crossref.org/requestaccount/'>"
- "request an account</a>. Enter your OpenURL "
+ "request an account</a>, and enter your OpenURL "
"account information below."),
- optionsWidget());
+ optionsWidget());
al->setOpenExternalLinks(true);
al->setWordWrap(true);
++row;
--- trunk/extragear/office/tellico/src/tellico_kernel.cpp #996868:996869
@@ -52,12 +52,14 @@
#include <kinputdialog.h>
#include <klocale.h>
#include <kundostack.h>
+#include <kwallet.h>
using Tellico::Kernel;
Kernel* Kernel::s_self = 0;
Kernel::Kernel(Tellico::MainWindow* parent) : m_widget(parent)
- , m_commandHistory(new KUndoStack(parent)) {
+ , m_commandHistory(new KUndoStack(parent))
+ , m_wallet(0) {
}
const KUrl& Kernel::URL() const {
@@ -395,3 +397,45 @@
}
return 0;
}
+
+bool Kernel::prepareWallet() {
+ if(!m_wallet || !m_wallet->isOpen()) {
+ delete m_wallet;
+ m_wallet = KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(), 0);
+ }
+ if(!m_wallet || !m_wallet->isOpen()) {
+ delete m_wallet;
+ m_wallet = 0;
+ return false;
+ }
+
+ if(!m_wallet->hasFolder(KWallet::Wallet::PasswordFolder()) &&
+ !m_wallet->createFolder(KWallet::Wallet::PasswordFolder())) {
+ return false;
+ }
+
+ return m_wallet->setFolder(KWallet::Wallet::PasswordFolder());
+}
+
+QByteArray Kernel::readWalletEntry(const QString& key_) {
+ QByteArray value;
+
+ if(!prepareWallet()) {
+ return value;
+ }
+
+ if(m_wallet->readEntry(key_, value) != 0) {
+ return QByteArray();
+ }
+
+ return value;
+}
+
+bool Kernel::writeWalletEntry(const QString& key_, const QByteArray& value_) {
+ if(!prepareWallet()) {
+ return false;
+ }
+
+ return m_wallet->writeEntry(key_, value_) == 0;
+}
+
--- trunk/extragear/office/tellico/src/tellico_kernel.h #996868:996869
@@ -30,6 +30,9 @@
class KUrl;
class KUndoStack;
+namespace KWallet {
+ class Wallet;
+}
class QWidget;
class QString;
@@ -134,6 +137,9 @@
int askAndMerge(Data::EntryPtr entry1, Data::EntryPtr entry2, Data::FieldPtr \
field,
QString value1 = QString(), QString value2 = QString());
+ QByteArray readWalletEntry(const QString& key);
+ bool writeWalletEntry(const QString& key, const QByteArray& value);
+
private:
static Kernel* s_self;
@@ -143,9 +149,11 @@
Kernel& operator=(const Kernel&);
void doCommand(QUndoCommand* command);
+ bool prepareWallet();
QWidget* m_widget;
KUndoStack* m_commandHistory;
+ KWallet::Wallet* m_wallet;
};
} // end namespace
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic