Start of dropbox support. Only whitelisted accounts work for now.
This commit is contained in:
parent
c5ce522576
commit
6bf0b4736a
|
@ -197,6 +197,11 @@ optional_component(UBUNTU_ONE ON "Ubuntu One file support"
|
||||||
DEPENDS "Taglib 1.8" "TAGLIB_VERSION VERSION_GREATER 1.7.999"
|
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"
|
optional_component(AUDIOCD ON "Devices: Audio CD support"
|
||||||
DEPENDS "libcdio" CDIO_FOUND
|
DEPENDS "libcdio" CDIO_FOUND
|
||||||
)
|
)
|
||||||
|
|
|
@ -1054,6 +1054,14 @@ optional_source(HAVE_UBUNTU_ONE
|
||||||
internet/ubuntuonesettingspage.ui
|
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
|
# Hack to add Clementine to the Unity system tray whitelist
|
||||||
optional_source(LINUX
|
optional_source(LINUX
|
||||||
SOURCES core/ubuntuunityhack.cpp
|
SOURCES core/ubuntuunityhack.cpp
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#cmakedefine HAVE_BREAKPAD
|
#cmakedefine HAVE_BREAKPAD
|
||||||
#cmakedefine HAVE_DBUS
|
#cmakedefine HAVE_DBUS
|
||||||
#cmakedefine HAVE_DEVICEKIT
|
#cmakedefine HAVE_DEVICEKIT
|
||||||
|
#cmakedefine HAVE_DROPBOX
|
||||||
#cmakedefine HAVE_GIO
|
#cmakedefine HAVE_GIO
|
||||||
#cmakedefine HAVE_GOOGLE_DRIVE
|
#cmakedefine HAVE_GOOGLE_DRIVE
|
||||||
#cmakedefine HAVE_IMOBILEDEVICE
|
#cmakedefine HAVE_IMOBILEDEVICE
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
#include "dropboxauthenticator.h"
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
#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<QString, QString> Param;
|
||||||
|
|
||||||
|
QByteArray signature = QUrl::toPercentEncoding(QString(kAppSecret) + "&");
|
||||||
|
QList<Param> 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();
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef DROPBOXAUTHENTICATOR_H
|
||||||
|
#define DROPBOXAUTHENTICATOR_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
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
|
|
@ -110,6 +110,8 @@ using boost::scoped_ptr;
|
||||||
Q_IMPORT_PLUGIN(qsqlite)
|
Q_IMPORT_PLUGIN(qsqlite)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "internet/dropboxauthenticator.h"
|
||||||
|
|
||||||
void LoadTranslation(const QString& prefix, const QString& path,
|
void LoadTranslation(const QString& prefix, const QString& path,
|
||||||
const QString& override_language = QString()) {
|
const QString& override_language = QString()) {
|
||||||
#if QT_VERSION < 0x040700
|
#if QT_VERSION < 0x040700
|
||||||
|
@ -447,6 +449,9 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
DropboxAuthenticator authenticator;
|
||||||
|
authenticator.StartAuthorisation("foo");
|
||||||
|
|
||||||
// Window
|
// Window
|
||||||
MainWindow w(&app, tray_icon.get(), &osd);
|
MainWindow w(&app, tray_icon.get(), &osd);
|
||||||
#ifdef Q_OS_DARWIN
|
#ifdef Q_OS_DARWIN
|
||||||
|
|
Loading…
Reference in New Issue