diff --git a/CMakeLists.txt b/CMakeLists.txt index e6c931e16..490c4ba22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,6 +197,11 @@ optional_component(UBUNTU_ONE ON "Ubuntu One file support" DEPENDS "Taglib 1.8" "TAGLIB_VERSION VERSION_GREATER 1.7.999" ) +optional_component(DROPBOX ON "Dropbox support" + DEPENDS "Google sparsehash" SPARSEHASH_INCLUDE_DIRS + DEPENDS "Taglib 1.8" "TAGLIB_VERSION VERSION_GREATER 1.7.999" +) + optional_component(AUDIOCD ON "Devices: Audio CD support" DEPENDS "libcdio" CDIO_FOUND ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e025e7523..611952420 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1054,6 +1054,14 @@ optional_source(HAVE_UBUNTU_ONE internet/ubuntuonesettingspage.ui ) +# Dropbox support +optional_source(HAVE_DROPBOX + SOURCES + internet/dropboxauthenticator.cpp + HEADERS + internet/dropboxauthenticator.h +) + # Hack to add Clementine to the Unity system tray whitelist optional_source(LINUX SOURCES core/ubuntuunityhack.cpp diff --git a/src/config.h.in b/src/config.h.in index 65d3b7f01..52b87e75b 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -25,6 +25,7 @@ #cmakedefine HAVE_BREAKPAD #cmakedefine HAVE_DBUS #cmakedefine HAVE_DEVICEKIT +#cmakedefine HAVE_DROPBOX #cmakedefine HAVE_GIO #cmakedefine HAVE_GOOGLE_DRIVE #cmakedefine HAVE_IMOBILEDEVICE diff --git a/src/internet/dropboxauthenticator.cpp b/src/internet/dropboxauthenticator.cpp new file mode 100644 index 000000000..1ff1ad59b --- /dev/null +++ b/src/internet/dropboxauthenticator.cpp @@ -0,0 +1,52 @@ +#include "dropboxauthenticator.h" + +#include + +#include + +#include "core/closure.h" +#include "core/logging.h" +#include "core/network.h" + +namespace { +static const char* kAppKey = "qh6ca27eclt9p2k"; +static const char* kAppSecret = "pg7y68h5efap8r6"; + +static const char* kRequestTokenEndpoint = + "https://api.dropbox.com/1/oauth/request_token"; +} // namespace + +DropboxAuthenticator::DropboxAuthenticator(QObject* parent) + : QObject(parent), + network_(new NetworkAccessManager(this)) { +} + +void DropboxAuthenticator::StartAuthorisation(const QString& email) { + QUrl url(kRequestTokenEndpoint); + typedef QPair Param; + + QByteArray signature = QUrl::toPercentEncoding(QString(kAppSecret) + "&"); + QList params; + params << Param("oauth_consumer_key", kAppKey) + << Param("oauth_signature_method", "PLAINTEXT") + << Param("oauth_timestamp", QString::number(time(NULL))) + << Param("oauth_nonce", QString::number(qrand())) + << Param("oauth_signature", signature); + QStringList encoded_params; + foreach (const Param& p, params) { + encoded_params << QString("%1=\"%2\"").arg(p.first, p.second); + } + QString authorisation_header = QString("OAuth ") + encoded_params.join(", "); + qLog(Debug) << authorisation_header; + + QNetworkRequest request(url); + request.setRawHeader("Authorization", authorisation_header.toUtf8()); + + QNetworkReply* reply = network_->post(request, QByteArray()); + NewClosure(reply, SIGNAL(finished()), + this, SLOT(RequestTokenFinished(QNetworkReply*)), reply); +} + +void DropboxAuthenticator::RequestTokenFinished(QNetworkReply* reply) { + qLog(Debug) << reply->readAll(); +} diff --git a/src/internet/dropboxauthenticator.h b/src/internet/dropboxauthenticator.h new file mode 100644 index 000000000..f8dea88a7 --- /dev/null +++ b/src/internet/dropboxauthenticator.h @@ -0,0 +1,22 @@ +#ifndef DROPBOXAUTHENTICATOR_H +#define DROPBOXAUTHENTICATOR_H + +#include + +class NetworkAccessManager; +class QNetworkReply; + +class DropboxAuthenticator : public QObject { + Q_OBJECT + public: + explicit DropboxAuthenticator(QObject* parent = 0); + void StartAuthorisation(const QString& email); + + private slots: + void RequestTokenFinished(QNetworkReply* reply); + + private: + NetworkAccessManager* network_; +}; + +#endif // DROPBOXAUTHENTICATOR_H diff --git a/src/main.cpp b/src/main.cpp index 61397080c..1061c3f30 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -110,6 +110,8 @@ using boost::scoped_ptr; Q_IMPORT_PLUGIN(qsqlite) #endif +#include "internet/dropboxauthenticator.h" + void LoadTranslation(const QString& prefix, const QString& path, const QString& override_language = QString()) { #if QT_VERSION < 0x040700 @@ -447,6 +449,9 @@ int main(int argc, char *argv[]) { } #endif + DropboxAuthenticator authenticator; + authenticator.StartAuthorisation("foo"); + // Window MainWindow w(&app, tray_icon.get(), &osd); #ifdef Q_OS_DARWIN