diff --git a/gemini/cloud/dropbox/3rdparty/droprestapi.cc b/gemini/cloud/dropbox/3rdparty/droprestapi.cc index 94db559e3c8..868336087cf 100644 --- a/gemini/cloud/dropbox/3rdparty/droprestapi.cc +++ b/gemini/cloud/dropbox/3rdparty/droprestapi.cc @@ -1,159 +1,172 @@ /* Copyright 2011 Cuong Le This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "droprestapi.h" #include "json.h" +#include #include DropRestAPI::DropRestAPI() { oauth = new OAuth(); } DropRestAPI::~DropRestAPI(){ delete oauth; } QNetworkRequest DropRestAPI::request_token() { QUrl url(REQUEST_TOKEN_URL); QNetworkRequest rt; rt.setUrl(url); oauth->sign("GET", &rt); return rt; } QNetworkRequest DropRestAPI::request_access_token() { QUrl url(REQUEST_ACCESS_TOKEN); QNetworkRequest rt; rt.setUrl(url); oauth->sign("POST", &rt); return rt; } QNetworkRequest DropRestAPI::root_dir(const QString &folder_name){ QUrl url(QString("%1%2").arg(FILES_URL).arg(folder_name)); QNetworkRequest rt; rt.setUrl(url); oauth->sign("GET", &rt); return rt; } void DropRestAPI::oauth_request_token_reply_process(QNetworkReply *networkreply){ QList oauth_content = networkreply->readAll().split('&'); oauth->m_secret = oauth_content.at(0).split('=').at(1); oauth->m_token = oauth_content.at(1).split('=').at(1); } QNetworkRequest DropRestAPI::file_transfer(QString filename, QString dropbox_folder, QString boundaryStr){ QUrl url; QNetworkRequest rt; url.setUrl(QString("%1%2").arg(FILES_TRANSFER_URL).arg(dropbox_folder)); - url.addQueryItem("file", filename); + QUrlQuery query; + query.addQueryItem("file", filename); + url.setQuery(query); rt.setUrl(url); rt.setHeader(QNetworkRequest::ContentTypeHeader, QString("multipart/form-data; boundary=").append(boundaryStr)); oauth->sign("POST", &rt); return rt; } QNetworkRequest DropRestAPI::file_transfer_download(QString dropbox_filepath){ QUrl url; url.setUrl(QString("%1%2").arg(FILES_TRANSFER_URL).arg(dropbox_filepath)); QNetworkRequest rt(url); oauth->sign("GET", &rt); return rt; } QNetworkRequest DropRestAPI::__delete(QString dropbox_filepath){ QUrl url; url.setUrl(QString("%1").arg(FILE_DELETE_URL)); - url.addQueryItem("root","dropbox"); - url.addQueryItem("path",dropbox_filepath); + QUrlQuery query; + query.addQueryItem("root", "dropbox"); + query.addQueryItem("path", dropbox_filepath); + url.setQuery(query); QNetworkRequest rt(url); oauth->sign("GET", &rt); return rt; } QNetworkRequest DropRestAPI::__create(QString dropbox_filepath){ QUrl url; url.setUrl(QString("%1").arg(CREATE_FOLDER_URL)); - url.addQueryItem("root","dropbox"); - url.addQueryItem("path",dropbox_filepath); + QUrlQuery query; + query.addQueryItem("root", "dropbox"); + query.addQueryItem("path", dropbox_filepath); + url.setQuery(query); QNetworkRequest rt(url); oauth->sign("GET", &rt); return rt; } QNetworkRequest DropRestAPI::__move(QString path_source, QString path_destination){ QUrl url; url.setUrl(QString("%1").arg(FILE_MOVE_URL)); - url.addQueryItem("root", "dropbox"); - url.addQueryItem("from_path", path_source); - url.addQueryItem("to_path", path_destination); + QUrlQuery query; + query.addQueryItem("root", "dropbox"); + query.addQueryItem("from_path", path_source); + query.addQueryItem("to_path", path_destination); + url.setQuery(query); QNetworkRequest rt(url); oauth->sign("GET", &rt); return rt; } QNetworkRequest DropRestAPI::__copy(QString path_source, QString path_destination){ QUrl url; url.setUrl(QString("%1").arg(FILE_COPY_URL)); - url.addQueryItem("root", "dropbox"); - url.addQueryItem("from_path", path_source); - url.addQueryItem("to_path", path_destination); + QUrlQuery query; + query.addQueryItem("root", "dropbox"); + query.addQueryItem("from_path", path_source); + query.addQueryItem("to_path", path_destination); + url.setQuery(query); QNetworkRequest rt(url); oauth->sign("GET", &rt); return rt; } QNetworkRequest DropRestAPI::__shares(QString dropbox_filepath){ QUrl url; url.setUrl(QString("%1").arg(SHARES_URL)); - url.addQueryItem("root","dropbox"); - url.addQueryItem("path",dropbox_filepath); + QUrlQuery query; + query.addQueryItem("root", "dropbox"); + query.addQueryItem("path", dropbox_filepath); + url.setQuery(query); QNetworkRequest rt(url); oauth->sign("POST", &rt); return rt; } QNetworkRequest DropRestAPI::accountinfo() { QUrl url; url.setUrl(QString("%1").arg(ACCOUNT_INFO_URL)); QNetworkRequest rt(url); oauth->sign("GET", &rt); return rt; } diff --git a/gemini/cloud/dropbox/3rdparty/listmodel.cc b/gemini/cloud/dropbox/3rdparty/listmodel.cc index 7d2f97ffb5b..8412465ce2b 100644 --- a/gemini/cloud/dropbox/3rdparty/listmodel.cc +++ b/gemini/cloud/dropbox/3rdparty/listmodel.cc @@ -1,183 +1,183 @@ /* Copyright 2011 Cuong Le This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include "listmodel.h" #include "folderitem.h" #include "filetransferitem.h" ListModel::ListModel(ListItem* prototype, QObject *parent) : QAbstractListModel(parent), m_prototype(prototype) +{ +} + +QHash ListModel::roleNames() const { QHash roles; roles[ListItem::ModifiedRole] = "modified"; roles[ListItem::PathRole] = "path"; roles[ListItem::Is_dirRole] = "is_dir"; roles[ListItem::SizeRole] = "size"; roles[ListItem::Mime_typeRole] = "mime_type"; roles[FileTransferItem::FileNameRole] = "filename"; roles[FileTransferItem::Is_downloadRole] = "is_download"; roles[FileTransferItem::Is_finishedRole] = "is_finished"; roles[FileTransferItem::ProgressingRole] = "progressing"; roles[FileTransferItem::CompletedRole] = "completed"; roles[FileTransferItem::Dropbox_pathRole] = "dropbox_path"; roles[FileTransferItem::In_queueRole] = "in_queue"; roles[FileTransferItem::Is_CancelledRolse] = "is_cancelled"; roles[FileTransferItem::DateRole] = "date"; - setRoleNames(roles); + return roles; } -// QHash ListModel::roleNames() const { -// return m_prototype->roleNames(); -// } - int ListModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); return m_list.count(); } QVariant ListModel::data(const QModelIndex &index, int role) const { if(index.row() < 0 || index.row() >= m_list.size()) return QVariant(); return m_list.at(index.row())->data(role); } ListModel::~ListModel() { delete m_prototype; qDeleteAll(m_list); } void ListModel::appendRow(ListItem *item) { appendRows(QList() << item); } void ListModel::appendRows(const QList &items) { beginInsertRows(QModelIndex(), rowCount(), rowCount()+items.size()-1); foreach(ListItem *item, items) { connect(item, SIGNAL(dataChanged()), SLOT(handleItemChange())); m_list.append(item); } endInsertRows(); } void ListModel::insertRow(int row, ListItem *item) { beginInsertRows(QModelIndex(), row, row); connect(item, SIGNAL(dataChanged()), SLOT(handleItemChange())); m_list.insert(row, item); endInsertRows(); } void ListModel::handleItemChange() { ListItem* item = static_cast(sender()); QModelIndex index = indexFromItem(item); if(index.isValid()) emit dataChanged(index, index); } ListItem * ListModel::find(const QString &id) const { foreach(ListItem* item, m_list) { if(item->id() == id) return item; } return 0; } QModelIndex ListModel::indexFromItem(const ListItem *item) const { Q_ASSERT(item); for(int row=0; row= m_list.size()) return false; beginRemoveRows(QModelIndex(), row, row); delete m_list.takeAt(row); endRemoveRows(); //reset(); return true; } bool ListModel::removeRows(int row, int count, const QModelIndex &parent) { Q_UNUSED(parent); if(row < 0 || (row+count) >= m_list.size()) return false; beginRemoveRows(QModelIndex(), row, row+count-1); for(int i=0; i itemData; QHashIterator hashItr(item->roleNames()); while(hashItr.hasNext()){ hashItr.next(); itemData.insert(hashItr.value(),item->data(hashItr.key()).toString()); } return QVariantMap(itemData);*/ QVariantMap elem; if (row < 0 || row > m_list.count()) return elem; FolderItem *item = (FolderItem*)m_list.at(row); elem["section"] = item->xsection(); return elem; } int ListModel::count() const { return m_list.count(); } diff --git a/gemini/cloud/dropbox/3rdparty/listmodel.h b/gemini/cloud/dropbox/3rdparty/listmodel.h index 985a8e87640..5e4df7ddb0b 100644 --- a/gemini/cloud/dropbox/3rdparty/listmodel.h +++ b/gemini/cloud/dropbox/3rdparty/listmodel.h @@ -1,93 +1,93 @@ /* Copyright 2011 Cuong Le This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef LISTMODEL_H #define LISTMODEL_H #include #include #include class ListItem: public QObject { Q_OBJECT public: enum Roles { RevisionRole = Qt::UserRole+1, Thumb_existsRole, BytesRole, ModifiedRole, PathRole, Is_dirRole, IconRole, Mime_typeRole, SizeRole, CheckedRole, NameRole, SectionRole }; ListItem(QObject* parent = 0) : QObject(parent) {} virtual ~ListItem() {} virtual QString id() const = 0; virtual QVariant data(int role) const = 0; -// virtual QHash roleNames() const = 0; Q_SIGNALS: void dataChanged(); }; class ListModel : public QAbstractListModel { Q_OBJECT Q_PROPERTY( int count READ count) public: explicit ListModel(ListItem* prototype, QObject* parent = 0); ~ListModel(); int rowCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; void appendRow(ListItem* item); void appendRows(const QList &items); void insertRow(int row, ListItem* item); bool removeRow(int row, const QModelIndex &parent = QModelIndex()); bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); ListItem* takeRow(int row); ListItem* getRow(int row); ListItem* find(const QString &id) const; QModelIndex indexFromItem( const ListItem* item) const; void clear(); - //QHash roleNames() const; - int count() const; int getCount() { return this->rowCount();} Q_INVOKABLE QVariantMap get(int row) const; private Q_SLOTS: void handleItemChange(); Q_SIGNALS: void countChanged(); +protected: + QHash roleNames() const; + private: ListItem* m_prototype; QList m_list; }; #endif // LISTMODEL_H diff --git a/gemini/cloud/dropbox/3rdparty/oauth.cc b/gemini/cloud/dropbox/3rdparty/oauth.cc index 5cbd36700d3..8c5e0d16351 100644 --- a/gemini/cloud/dropbox/3rdparty/oauth.cc +++ b/gemini/cloud/dropbox/3rdparty/oauth.cc @@ -1,177 +1,178 @@ /* Copyright 2011 Cuong Le This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "oauth.h" #include +#include #include #include #include #include #include OAuth::OAuth(): m_consumer_key("7y6cr1w19khjkft"), m_consumer_secret("jyxb5gu2dp7npz6") // old dropN9 keys below // m_consumer_key("8xf1b5hrsgmempk"), // m_consumer_secret("6se47g35sdqsouw") { qsrand(QDateTime::currentDateTime().toTime_t()); m_token = ""; m_secret = ""; } void OAuth::sign(QString method, QNetworkRequest *nr) { QString header = "OAuth "; QUrl url(nr->url()); header += oauth_timestamp() + ","; header += oauth_consumer_key() + ","; header += oauth_signature_method() + ","; header += oauth_token() + ","; header += oauth_version() + ","; header += oauth_signature(method,&url,header) + ","; header.chop(1); nr->setRawHeader("Authorization", header.toLatin1()); } QString OAuth::oauth_timestamp() { int currentTimeStamp = QDateTime::currentDateTime().toUTC().toTime_t(); QString strtimestamp("oauth_timestamp=\"%1\",oauth_nonce=\"%2\""); return strtimestamp.arg(currentTimeStamp).arg(qrand()); } QString OAuth::oauth_consumer_key() { return QString("oauth_consumer_key=\"%1\"").arg(m_consumer_key); } QString OAuth::oauth_signature_method() { return QString("oauth_signature_method=\"%1\"").arg("HMAC-SHA1"); } QString OAuth::oauth_token() { return QString("oauth_token=\"%1\"").arg(m_token); } QString OAuth::oauth_version() { return QString("oauth_version=\"%1\"").arg(OAUTH_VERSION); } QString OAuth::oauth_signature(QString method,QUrl *url,QString oAuthHeader) { QString urlSchemeAndHost = url->toString( QUrl::RemovePort | QUrl::RemovePath | QUrl::RemoveQuery | QUrl::RemoveFragment ); QString urlPath = url->path(); QStringList urlPathParts = urlPath.split("/"); for(int i = 0; i < urlPathParts.length(); ++i) { urlPathParts[i] = urlPathParts[i].toUtf8().toPercentEncoding(); } urlPath = urlPathParts.join("/"); QByteArray readyForUseUrl = (urlSchemeAndHost+urlPath).toLatin1().toPercentEncoding(); QList< QPair > parameters; - parameters.append(url->queryItems()); + parameters.append(QUrlQuery(*url).queryItems()); oAuthHeader.remove("OAuth "); QStringList oAuthParameters = oAuthHeader.split(",", QString::SkipEmptyParts); foreach(QString oAuthParameter, oAuthParameters) { QStringList oAuthParameterParts = oAuthParameter.split("="); QString first = oAuthParameterParts.at(0); QString second = oAuthParameterParts.at(1); second.remove("\""); QPair parameter = qMakePair(first, second); parameters.append(parameter); } for(int i = 0; i < parameters.length(); ++i) { QPair parameter = parameters[i]; parameter.second = parameter.second.toUtf8().toPercentEncoding(); parameters[i] = parameter; } qSort(parameters); QString parametersString; QPair parameter; foreach(parameter, parameters) parametersString += parameter.first + "=" + parameter.second + "&"; parametersString.chop(1); QString readyForUseParametersString = parametersString.toLatin1().toPercentEncoding(); QString base = method+"&"+readyForUseUrl+"&"+readyForUseParametersString; QString hash = SHA1(base,m_consumer_secret + "&" + m_secret); return QString("oauth_signature=\"%1\"").arg(hash); } QString OAuth::SHA1(QString base, QString key) { QByteArray ipad; ipad.fill(char(0), 64); for(int i = 0; i < key.length(); ++i) ipad[i] = key[i].toLatin1(); QByteArray opad; opad.fill(char(0), 64); for(int i = 0; i < key.length(); ++i) opad[i] = key[i].toLatin1(); for(int i = 0; i < ipad.length(); ++i) ipad[i] = ipad[i] ^ 0x36; for(int i = 0; i < opad.length(); ++i) opad[i] = opad[i] ^ 0x5c; QByteArray innerSha1 = QCryptographicHash::hash( ipad + base.toLatin1(), QCryptographicHash::Sha1 ); QByteArray outerSha1 = QCryptographicHash::hash( opad + innerSha1, QCryptographicHash::Sha1 ); return outerSha1.toBase64(); }