Skip to content

Loading…

listFile #12

Merged
merged 15 commits into from

2 participants

@lynx-cpp

filelist function was implemented in qcloud_tool

lynx-cpp added some commits
@lynx-cpp lynx-cpp modified: backend/dropbox/dropbox.cpp
	modified:   backend/dropbox/dropbox.h
	modified:   backend/dropbox/dropboxrequest.cpp
	modified:   backend/dropbox/dropboxrequest.h
	modified:   tests/dropbox/dropbox_test.cpp
9ad56f3
@lynx-cpp lynx-cpp Merge branch 'master' of git://github.com/csslayer/qcloud 7ebbe9e
@lynx-cpp lynx-cpp modified: backend/dropbox/dropbox.cpp
	modified:   backend/dropbox/dropbox.h
	modified:   backend/dropbox/dropboxrequest.cpp
	modified:   backend/dropbox/dropboxrequest.h
	modified:   daemon/accountmanager.cpp
	modified:   daemon/service.cpp
	modified:   daemon/service.h
	modified:   include/CMakeLists.txt
	modified:   include/ibackend.h
	modified:   lib/CMakeLists.txt
	modified:   tests/dropbox/dropbox_test.cpp
	modified:   tool/tool.ui
	include/entryinfo.h
	lib/entryinfo.cpp
d7910b2
@lynx-cpp lynx-cpp new file: include/entryinfo.h
	new file:   lib/entryinfo.cpp
07c4a5e
@lynx-cpp lynx-cpp modified: daemon/service.cpp
	modified:   daemon/service.h
	modified:   include/client.h
	modified:   include/server.h
	modified:   lib/client.cpp
	modified:   lib/daemon.xml
	modified:   tool/mainwindow.cpp
	modified:   tool/mainwindow.h
	modified:   tool/tool.ui
f7e98e8
@lynx-cpp lynx-cpp modified: daemon/service.cpp
	modified:   daemon/service.h
	modified:   include/client.h
	modified:   include/server.h
	modified:   lib/client.cpp
	modified:   lib/daemon.xml
	modified:   tool/mainwindow.cpp
	modified:   tool/mainwindow.h
	modified:   tool/tool.ui
7f19b67
@lynx-cpp lynx-cpp modified: daemon/service.cpp
	modified:   lib/entryinfo.cpp
	modified:   tool/mainwindow.cpp
	modified:   tool/mainwindow.h
	modified:   tool/tool.ui
87a3d00
@wengxt wengxt commented on an outdated diff
daemon/accountmanager.cpp
@@ -95,7 +95,7 @@ Account* AccountManager::parseConfig (const QString& id)
Account* AccountManager::findAccount (const QUuid& uuid)
{
- return NULL;
+ return m_accounts[uuid];
@wengxt Owner
wengxt added a note

qmap单纯这么引用会导致多一个为null的项吧,
应该先用 contains check一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@wengxt wengxt commented on an outdated diff
include/ibackend.h
@@ -25,7 +25,12 @@ class QCLOUD_EXPORT IBackend : public QObject
virtual bool authorize (QWidget* widget = 0) = 0;
virtual void setNetworkAccessManager (QNetworkAccessManager* manager);
virtual Request* uploadFile (const QString& localFileName, const QString& remoteFilePath) = 0;
- virtual Request* downloadFile(const QString& remoteFilePath,const QString& localFileName) = 0;
+ virtual Request* downloadFile (const QString& remoteFilePath,const QString& localFileName) = 0;
+ virtual Request* copyFile (const QString& fromPath,const QString& toPath) = 0;
+ virtual Request* moveFile (const QString& fromPath,const QString& toPath) = 0;
+ virtual Request* createFolder (const QString& path) = 0;
+ virtual Request* deleteFile (const QString& path) = 0;
+ virtual Request* pathInfo (const QString& path,QVariantMap* value) = 0;
@wengxt Owner
wengxt added a note

path info 的接口明显定义不对,应该通过返回 EntryInfo 的形式。
具体的key是限定于特定的backend的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lynx-cpp added some commits
@lynx-cpp lynx-cpp modified: daemon/accountmanager.cpp 13d8dfe
@lynx-cpp lynx-cpp modified: backend/dropbox/dropbox.cpp
	modified:   backend/dropbox/dropbox.h
	modified:   backend/dropbox/dropboxrequest.cpp
	modified:   backend/dropbox/dropboxrequest.h
	modified:   include/entryinfo.h
	modified:   include/ibackend.h
	modified:   lib/entryinfo.cpp
e4b0ed2
@lynx-cpp lynx-cpp modified: backend/dropbox/dropbox.cpp
	modified:   backend/dropbox/dropbox.h
	modified:   backend/dropbox/dropboxrequest.cpp
	modified:   backend/dropbox/dropboxrequest.h
	modified:   daemon/service.cpp
	modified:   include/entryinfo.h
	modified:   lib/entryinfo.cpp
	modified:   tests/dropbox/dropbox_test.cpp
3786cf3
@wengxt wengxt commented on an outdated diff
lib/entryinfo.cpp
((67 lines not shown))
+ m_size = value.toULongLong();
+ break;
+ case EntryInfo::DirType:
+ is_dir = value.toBool();
+ break;
+ case EntryInfo::HashType:
+ m_hash = value.toString();
+ break;
+ case EntryInfo::IconType:
+ m_icon = value.toString();
+ break;
+ case EntryInfo::PathType:
+ m_path = value.toString();
+ break;
+ case EntryInfo::ModifiedTimeType:
+ m_modifiedTime = value.toString();
@wengxt Owner
wengxt added a note

toDateTime 因此传进来的也要注意是datetime的类型。也就是说要先parse转换好,再丢进来,不要是string就丢进来。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@wengxt wengxt commented on an outdated diff
tool/mainwindow.h
@@ -1,4 +1,5 @@
#include <QMainWindow>
+#include <qabstractitemmodel.h>
@wengxt Owner
wengxt added a note

用类名

额..这个好像是KDevelop自己生成的...

@wengxt Owner
wengxt added a note

就算是也注意自己改了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@wengxt wengxt commented on an outdated diff
lib/entryinfo.cpp
((32 lines not shown))
+QString EntryInfo::hash()
+{
+ return m_hash;
+}
+
+QString EntryInfo::path()
+{
+ return m_path;
+}
+
+QString EntryInfo::icon()
+{
+ return m_icon;
+}
+
+bool EntryInfo::getContents(EntryList& list)
@wengxt Owner
wengxt added a note

意义不明,为什么要存在entryinfo这里面?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@wengxt wengxt commented on an outdated diff
include/entryinfo.h
@@ -0,0 +1,43 @@
+#ifndef QCLOUD_ENTRYINFO_H
+#define QCLOUD_ENTRYINFO_H
+#include "qcloud_global.h"
+#include "ibackend.h"
+#include <QObject>
+#include <QMap>
+#include <QVariant>
+
+
+namespace QCloud{
+class EntryInfo;
+typedef QList<EntryInfo> EntryList;
@wengxt Owner
wengxt added a note

似乎应该定义在后面比较好,如果删掉我下面提到的函数

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@wengxt wengxt commented on an outdated diff
include/entryinfo.h
@@ -0,0 +1,43 @@
+#ifndef QCLOUD_ENTRYINFO_H
+#define QCLOUD_ENTRYINFO_H
+#include "qcloud_global.h"
+#include "ibackend.h"
+#include <QObject>
+#include <QMap>
+#include <QVariant>
@wengxt Owner
wengxt added a note

Qt 的在前面

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@wengxt wengxt commented on an outdated diff
daemon/service.cpp
((7 lines not shown))
+ QCloud::InfoList infoList;
+ infoList.clear();
+ Account *account = m_daemon->accountManager()->findAccount(uuid);
+ qDebug() << account->backend()->userName();
+ QCloud::EntryInfo entryInfo;
+ QCloud::Request* request = account->backend()->pathInfo(directory,&entryInfo);
+ request->waitForFinished();
+ QCloud::EntryList entryList;
+ if (!entryInfo.getContents(entryList)){
+ qDebug() << "Error !";
+ }
+ QCloud::Info info;
+
+ //set ..
+ QFileInfo fileInfo(entryInfo.path());
+ info.setName(fileInfo.path());
@wengxt Owner
wengxt added a note

这里最好处理下路径

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@wengxt wengxt commented on an outdated diff
backend/dropbox/dropboxrequest.cpp
((8 lines not shown))
+ info.setValue(QCloud::EntryInfo::DirType, infoMap["is_dir"]);
+ info.setValue(QCloud::EntryInfo::HashType,infoMap["hash"]);
+ info.setValue(QCloud::EntryInfo::IconType,infoMap["icon"]);
+ info.setValue(QCloud::EntryInfo::PathType,infoMap["path"]);
+ info.setValue(QCloud::EntryInfo::ModifiedTimeType,infoMap["modified"]);
+ return info;
+}
+
+DropboxGetInfoRequest::DropboxGetInfoRequest(Dropbox* dropbox, const QString& path,QCloud::EntryInfo* info)
+{
+ qDebug() << "Path : " << path;
+ m_dropbox = dropbox;
+ m_info = info;
+ QString paramSt = "%1";
+ paramSt = paramSt.arg(path);
+ removeFrontSlash(paramSt);
@wengxt Owner
wengxt added a note

合并吧这俩函数

除了这个俩操作之外,另外把连续的 / 也替换成一个吧,例如 a////b -> a/b,这样的话不要inplace的改吧。新建个qstring不要紧的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lynx-cpp added some commits
@lynx-cpp lynx-cpp modified: include/encrypter.h
	modified:   include/entryinfo.h
	modified:   lib/entryinfo.cpp
	modified:   tool/mainwindow.h
4b5012f
@lynx-cpp lynx-cpp modified: ../backend/dropbox/dropbox.cpp
	modified:   ../backend/dropbox/dropbox.h
	modified:   ../backend/dropbox/dropboxrequest.cpp
	modified:   ../backend/dropbox/dropboxrequest.h
	modified:   ../daemon/service.cpp
	modified:   ../include/entryinfo.h
	modified:   ../include/ibackend.h
	modified:   ../lib/entryinfo.cpp
b24f4cb
@lynx-cpp lynx-cpp modified: ../include/ibackend.h
	modified:   ../lib/entryinfo.cpp
1f202f7
@wengxt

这个network error好诡异。

嗯...但是调用者认为它是目录(所以才传指针进来),dropbox后端发现不是,也就只能归结成NetworkError了。

@wengxt

呼唤异步。

lynx-cpp added some commits
@lynx-cpp lynx-cpp modified: backend/dropbox/dropboxrequest.cpp 41ff677
@lynx-cpp lynx-cpp modified: daemon/service.cpp
	modified:   daemon/service.h
	modified:   include/client.h
	modified:   include/server.h
	modified:   lib/client.cpp
	modified:   lib/daemon.xml
	modified:   lib/server.cpp
	modified:   tool/clientapp.h
	modified:   tool/mainwindow.cpp
	modified:   tool/mainwindow.h
786ea38
@wengxt wengxt merged commit 786ea38 into wengxt:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 8, 2012
  1. @lynx-cpp

    modified: backend/dropbox/dropbox.cpp

    lynx-cpp committed
    	modified:   backend/dropbox/dropbox.h
    	modified:   backend/dropbox/dropboxrequest.cpp
    	modified:   backend/dropbox/dropboxrequest.h
    	modified:   tests/dropbox/dropbox_test.cpp
  2. @lynx-cpp
Commits on May 9, 2012
  1. @lynx-cpp

    modified: backend/dropbox/dropbox.cpp

    lynx-cpp committed
    	modified:   backend/dropbox/dropbox.h
    	modified:   backend/dropbox/dropboxrequest.cpp
    	modified:   backend/dropbox/dropboxrequest.h
    	modified:   daemon/accountmanager.cpp
    	modified:   daemon/service.cpp
    	modified:   daemon/service.h
    	modified:   include/CMakeLists.txt
    	modified:   include/ibackend.h
    	modified:   lib/CMakeLists.txt
    	modified:   tests/dropbox/dropbox_test.cpp
    	modified:   tool/tool.ui
    	include/entryinfo.h
    	lib/entryinfo.cpp
  2. @lynx-cpp

    new file: include/entryinfo.h

    lynx-cpp committed
    	new file:   lib/entryinfo.cpp
  3. @lynx-cpp

    modified: daemon/service.cpp

    lynx-cpp committed
    	modified:   daemon/service.h
    	modified:   include/client.h
    	modified:   include/server.h
    	modified:   lib/client.cpp
    	modified:   lib/daemon.xml
    	modified:   tool/mainwindow.cpp
    	modified:   tool/mainwindow.h
    	modified:   tool/tool.ui
  4. @lynx-cpp

    modified: daemon/service.cpp

    lynx-cpp committed
    	modified:   daemon/service.h
    	modified:   include/client.h
    	modified:   include/server.h
    	modified:   lib/client.cpp
    	modified:   lib/daemon.xml
    	modified:   tool/mainwindow.cpp
    	modified:   tool/mainwindow.h
    	modified:   tool/tool.ui
Commits on May 10, 2012
  1. @lynx-cpp

    modified: daemon/service.cpp

    lynx-cpp committed
    	modified:   lib/entryinfo.cpp
    	modified:   tool/mainwindow.cpp
    	modified:   tool/mainwindow.h
    	modified:   tool/tool.ui
  2. @lynx-cpp
  3. @lynx-cpp

    modified: backend/dropbox/dropbox.cpp

    lynx-cpp committed
    	modified:   backend/dropbox/dropbox.h
    	modified:   backend/dropbox/dropboxrequest.cpp
    	modified:   backend/dropbox/dropboxrequest.h
    	modified:   include/entryinfo.h
    	modified:   include/ibackend.h
    	modified:   lib/entryinfo.cpp
  4. @lynx-cpp

    modified: backend/dropbox/dropbox.cpp

    lynx-cpp committed
    	modified:   backend/dropbox/dropbox.h
    	modified:   backend/dropbox/dropboxrequest.cpp
    	modified:   backend/dropbox/dropboxrequest.h
    	modified:   daemon/service.cpp
    	modified:   include/entryinfo.h
    	modified:   lib/entryinfo.cpp
    	modified:   tests/dropbox/dropbox_test.cpp
Commits on May 16, 2012
  1. @lynx-cpp

    modified: include/encrypter.h

    lynx-cpp committed
    	modified:   include/entryinfo.h
    	modified:   lib/entryinfo.cpp
    	modified:   tool/mainwindow.h
  2. @lynx-cpp

    modified: ../backend/dropbox/dropbox.cpp

    lynx-cpp committed
    	modified:   ../backend/dropbox/dropbox.h
    	modified:   ../backend/dropbox/dropboxrequest.cpp
    	modified:   ../backend/dropbox/dropboxrequest.h
    	modified:   ../daemon/service.cpp
    	modified:   ../include/entryinfo.h
    	modified:   ../include/ibackend.h
    	modified:   ../lib/entryinfo.cpp
  3. @lynx-cpp

    modified: ../include/ibackend.h

    lynx-cpp committed
    	modified:   ../lib/entryinfo.cpp
Commits on Jun 11, 2012
  1. @lynx-cpp
Commits on Jun 17, 2012
  1. @lynx-cpp

    modified: daemon/service.cpp

    lynx-cpp committed
    	modified:   daemon/service.h
    	modified:   include/client.h
    	modified:   include/server.h
    	modified:   lib/client.cpp
    	modified:   lib/daemon.xml
    	modified:   lib/server.cpp
    	modified:   tool/clientapp.h
    	modified:   tool/mainwindow.cpp
    	modified:   tool/mainwindow.h
View
7 backend/dropbox/dropbox.cpp
@@ -15,7 +15,7 @@
#include "authdialog.h"
#include "qcloud_utils.h"
#include "request.h"
-#include <isecurestore.h>
+#include "isecurestore.h"
Dropbox::Dropbox (QObject* parent) : OAuthBackend (parent)
,m_globalAccess(false)
@@ -106,6 +106,11 @@ QCloud::Request* Dropbox::deleteFile(const QString& path)
return new DropboxDeleteRequest(this, path);
}
+QCloud::Request* Dropbox::pathInfo(const QString& path,QCloud::EntryInfo* info,QCloud::EntryList* contents)
+{
+ return new DropboxGetInfoRequest(this,path,info,contents);
+}
+
QString Dropbox::userName() {
if (m_userName.isEmpty()) {
QUrl url("https://api.dropbox.com/1/account/info");
View
7 backend/dropbox/dropbox.h
@@ -2,7 +2,9 @@
#define DROPBOX_H
#include <QFile>
+#include <QVariant>
#include "oauthbackend.h"
+#include "entryinfo.h"
class DropboxRequest;
@@ -10,6 +12,7 @@ namespace QCloud
{
class App;
class Request;
+class EntryInfo;
}
class Dropbox : public QCloud::OAuthBackend
@@ -26,7 +29,8 @@ class Dropbox : public QCloud::OAuthBackend
virtual QCloud::Request* copyFile (const QString& fromPath,const QString& toPath);
virtual QCloud::Request* moveFile (const QString& fromPath,const QString& toPath);
virtual QCloud::Request* createFolder (const QString& path);
- virtual QCloud::Request* deleteFile(const QString& path);
+ virtual QCloud::Request* deleteFile (const QString& path);
+ virtual QCloud::Request* pathInfo (const QString& path,QCloud::EntryInfo* info = NULL,QCloud::EntryList* contents = NULL);
virtual void startAuth (QCloud::OAuthWidget* widget);
virtual void loadAccountInfo (const QString& key, QSettings& settings, QCloud::ISecureStore* securestore);
virtual void saveAccountInfo (const QString& key, QSettings& settings, QCloud::ISecureStore* securestore);
@@ -37,5 +41,4 @@ class Dropbox : public QCloud::OAuthBackend
bool m_globalAccess;
QString m_userName;
};
-
#endif
View
107 backend/dropbox/dropboxrequest.cpp
@@ -13,6 +13,26 @@
#define BUF_SIZE 512
+inline static QString removeInvalidSlash(const QString& str)
+{
+ QString retString = "";
+ if (str.size()==0)
+ return retString;
+ retString += str[0];
+ for (int i=1;i<str.size();i++){
+ if (str[i]!='/' || str[i - 1]!='/')
+ retString += str[i];
+ }
+ if (retString[0]=='/')
+ retString.remove(0,1);
+ int pos = retString.size() - 1;
+ if (pos<=0)
+ return retString;
+ if (retString[pos]=='/')
+ retString.remove(pos,1);
+ return retString;
+}
+
QCloud::Request::Error DropboxRequest::error()
{
return m_error;
@@ -57,21 +77,21 @@ QString DropboxRequest::getRootType()
void DropboxRequest::readyForRead()
{
-
+
}
void DropboxRequest::replyFinished()
{
-
+
}
DropboxRequest::~DropboxRequest()
{
-
+
}
DropboxUploadRequest::DropboxUploadRequest (Dropbox* dropbox, const QString& localFileName, const QString& remoteFilePath) :
- m_file (localFileName)
+m_file (localFileName)
{
m_dropbox = dropbox;
if (!m_file.open (QIODevice::ReadOnly)) {
@@ -79,12 +99,13 @@ DropboxUploadRequest::DropboxUploadRequest (Dropbox* dropbox, const QString& loc
QTimer::singleShot (0, this, SIGNAL (finished()));
return;
}
-
+
m_buffer.open (QBuffer::ReadWrite);
-
+
QString surl;
surl = "https://api-content.dropbox.com/1/files_put/%1/%2";
- QUrl url (surl.arg (getRootType()).arg (remoteFilePath));
+ surl = surl.arg (getRootType(),remoteFilePath);
+ QUrl url (removeInvalidSlash(surl));
sendRequest (url, QOAuth::PUT, &m_file);
}
@@ -104,7 +125,7 @@ void DropboxUploadRequest::replyFinished()
qDebug() << "Reponse error " << m_reply->errorString();
m_error = NetworkError;
}
-
+
m_buffer.seek (0);
// Lets print the HTTP PUT response.
QVariant result = m_parser.parse (m_buffer.data());
@@ -114,7 +135,7 @@ void DropboxUploadRequest::replyFinished()
}
DropboxDownloadRequest::DropboxDownloadRequest (Dropbox* dropbox, const QString& remoteFilePath, const QString& localFileName) :
- m_file (localFileName)
+m_file (localFileName)
{
m_dropbox = dropbox;
if (!m_file.open (QIODevice::WriteOnly)) {
@@ -125,7 +146,8 @@ DropboxDownloadRequest::DropboxDownloadRequest (Dropbox* dropbox, const QString&
}
QString urlString;
urlString = "https://api-content.dropbox.com/1/files/%1/%2";
- QUrl url (urlString.arg (getRootType()).arg (remoteFilePath));
+ urlString = urlString.arg (getRootType(),remoteFilePath);
+ QUrl url (removeInvalidSlash(urlString));
sendRequest (url, QOAuth::GET);
}
@@ -284,4 +306,69 @@ DropboxDeleteRequest::~DropboxDeleteRequest()
m_buffer.close();
}
+QCloud::EntryInfo DropboxGetInfoRequest::getInfoFromMap(const QVariantMap& infoMap)
+{
+ QCloud::EntryInfo info;
+ info.setValue(QCloud::EntryInfo::SizeType,infoMap["bytes"]);
+ info.setValue(QCloud::EntryInfo::DirType, infoMap["is_dir"]);
+ info.setValue(QCloud::EntryInfo::HashType,infoMap["hash"]);
+ info.setValue(QCloud::EntryInfo::IconType,infoMap["icon"]);
+ info.setValue(QCloud::EntryInfo::PathType,infoMap["path"]);
+ info.setValue(QCloud::EntryInfo::ModifiedTimeType,infoMap["modified"]);
+ return info;
+}
+
+DropboxGetInfoRequest::DropboxGetInfoRequest(Dropbox* dropbox, const QString& path,QCloud::EntryInfo* info,QCloud::EntryList* contents)
+{
+ m_dropbox = dropbox;
+ m_info = info;
+ m_contents = contents;
+ QString paramSt = "%1";
+ paramSt = paramSt.arg(path);
+ QString urlString = "https://api.dropbox.com/1/metadata/%1/";
+ urlString = urlString.arg(getRootType()) + removeInvalidSlash(paramSt);
+ m_buffer.open(QIODevice::ReadWrite);
+ sendRequest(QUrl(urlString),QOAuth::GET);
+}
+
+void DropboxGetInfoRequest::readyForRead()
+{
+ m_buffer.write(m_reply->readAll());
+}
+
+void DropboxGetInfoRequest::replyFinished()
+{
+ if (m_reply->error() != QNetworkReply::NoError){
+ m_error = NetworkError;
+ qDebug() << "Reponse error " << m_reply->errorString();
+ return ;
+ }
+ QVariant result = m_parser.parse(m_buffer.data());
+ qDebug() << result;
+ QVariantMap infoMap = result.toMap();
+ if (m_info!=NULL){
+ (*m_info) = getInfoFromMap(infoMap);
+ }
+ if (m_contents){
+ if (infoMap["is_dir"].toBool()==false)
+ qDebug() << "Not a directory!";
+ else{
+ QCloud::EntryList infoList;
+ infoList.clear();
+ QVariantList contentsList = infoMap["contents"].toList();
+ foreach(QVariant i,contentsList){
+ QCloud::EntryInfo info = getInfoFromMap(i.toMap());
+ infoList << info;
+ qDebug() << info.path();
+ }
+ (*m_contents) = infoList;
+ }
+ }
+ emit finished();
+}
+
+DropboxGetInfoRequest::~DropboxGetInfoRequest()
+{
+ m_buffer.close();
+}
View
22 backend/dropbox/dropboxrequest.h
@@ -3,12 +3,16 @@
#include <QFile>
#include <QBuffer>
+#include <QVariant>
+#include <QMap>
#include <qjson/parser.h>
#include <QtOAuth/QtOAuth>
#include "request.h"
+#include "entryinfo.h"
class QNetworkReply;
class QFile;
+class EntryInfo;
class Dropbox;
class DropboxRequest : public QCloud::Request
@@ -116,4 +120,22 @@ protected slots:
QBuffer m_buffer;
};
+class DropboxGetInfoRequest : public DropboxRequest
+{
+ Q_OBJECT
+public:
+ DropboxGetInfoRequest (Dropbox* dropbox, const QString& path,QCloud::EntryInfo* info,QCloud::EntryList* contents);
+ virtual ~DropboxGetInfoRequest();
+protected slots:
+ virtual void readyForRead();
+ virtual void replyFinished();
+protected:
+ QJson::Parser m_parser;
+ QBuffer m_buffer;
+ QCloud::EntryInfo* m_info;
+ QCloud::EntryList* m_contents;
+private:
+ QCloud::EntryInfo getInfoFromMap(const QVariantMap& infoMap);
+};
+
#endif
View
5 daemon/accountmanager.cpp
@@ -95,7 +95,10 @@ Account* AccountManager::parseConfig (const QString& id)
Account* AccountManager::findAccount (const QUuid& uuid)
{
- return NULL;
+ if (m_accounts.contains(uuid))
+ return m_accounts[uuid];
+ else
+ return NULL;
}
QList< Account* > AccountManager::listAccounts()
View
47 daemon/service.cpp
@@ -5,6 +5,9 @@
#include "daemon.h"
#include "accountmanager.h"
#include "account.h"
+#include "request.h"
+#include "entryinfo.h"
+#include <QFileInfo>
#include <QDebug>
@@ -96,3 +99,47 @@ QCloud::InfoList Service::listAccounts()
}
return infoList;
}
+
+void Service::listFiles(const QString& uuid,const QString& directory)
+{
+ Account *account = m_daemon->accountManager()->findAccount(uuid);
+ qDebug() << account->backend()->userName();
+ QCloud::Request* request = account->backend()->pathInfo(directory,&entryInfo,&entryList);
+ //request->waitForFinished();
+ connect(request,SIGNAL(finished()),this,SLOT(listFilesRequestFinished()));
+}
+
+void Service::listFilesRequestFinished()
+{
+ qDebug() << "Sending finished signal...";
+ QCloud::InfoList infoList;
+ infoList.clear();
+ QCloud::Info info;
+ //set ..
+ QFileInfo fileInfo(entryInfo.path());
+ info.setName(fileInfo.path());
+ if (entryInfo.isDir())
+ info.setDescription("is_dir");
+ else
+ info.setDescription("not_a_dir");
+ info.setDisplayName("..");
+ info.setIconName(entryInfo.icon());
+ infoList << info;
+
+ foreach(QCloud::EntryInfo i,entryList){
+ fileInfo = QFileInfo(i.path());
+ info.setName(i.path());
+ if (i.isDir())
+ info.setDescription("is_dir");
+ else
+ info.setDescription("not_a_dir");
+ info.setDisplayName(fileInfo.fileName());
+ info.setIconName(i.icon());
+
+ qDebug() << info.name() << " " << info.description();
+
+ infoList << info;
+ }
+
+ notifyDirectoryInfoTransformed(infoList);
+}
View
9 daemon/service.h
@@ -3,6 +3,7 @@
#include <QCoreApplication>
#include "server.h"
+#include "entryinfo.h"
class Daemon;
class QNetworkAccessManager;
@@ -16,13 +17,19 @@ class Service : public QCloud::Server
virtual QCloud::InfoList listApps();
virtual QCloud::InfoList listBackends();
virtual QCloud::InfoList listAccounts();
+ virtual void listFiles(const QString& uuid,const QString& directory);
virtual void addAccount (const QString& backendName, const QString& appName);
virtual void deleteAccount (const QString& uuid);
virtual int uploadFile (const QString& app_name, const QStringList& file_list);
virtual int sync (const QString& app_name);
-
+
+public slots:
+ virtual void listFilesRequestFinished();
+
private:
Daemon* m_daemon;
+ QCloud::EntryList entryList;
+ QCloud::EntryInfo entryInfo;
};
View
1 include/CMakeLists.txt
@@ -15,6 +15,7 @@ set(qcloud_HEADER
authwidget.h
appmanager.h
encrypter.h
+ entryinfo.h
)
#install(FILES ${qcloud_HEADER} DESTINATION include)
View
2 include/client.h
@@ -22,12 +22,14 @@ class QCLOUD_EXPORT Client : public QObject
QDBusPendingReply<InfoList> listApps();
QDBusPendingReply<InfoList> listBackends();
QDBusPendingReply<InfoList> listAccounts();
+ QDBusPendingReply<InfoList> listFiles(const QString& uuid,const QString& directory);
QDBusPendingReply<void> addAccount (const QString& backend_name, const QString& user_name);
QDBusPendingReply<void> deleteAccount (const QString& uuid);
QDBusPendingReply<int> sync (const QString& app_name);
QDBusPendingReply<int> uploadFile (const QString& app_name, const QStringList& file_list);
signals:
void accountUpdated();
+ void directoryInfoTransformed(QCloud::InfoList info);
protected:
ClientPrivate* d;
};
View
2 include/encrypter.h
@@ -3,8 +3,8 @@
#include <QtCore/QObject>
#include <QtCore/QString>
-#include "isecurestore.h"
#include <QtCrypto/QtCrypto>
+#include "isecurestore.h"
#include "qcloud_global.h"
#define GROUP_NAME "QCloud_Encrypter"
#define KEY_NAME "Key"
View
40 include/entryinfo.h
@@ -0,0 +1,40 @@
+#ifndef QCLOUD_ENTRYINFO_H
+#define QCLOUD_ENTRYINFO_H
+#include <QObject>
+#include <QMap>
+#include <QVariant>
+#include <QDateTime>
+#include "qcloud_global.h"
+
+
+namespace QCloud{
+
+class QCLOUD_EXPORT EntryInfo
+{
+public:
+ enum EntryType{
+ SizeType,
+ DirType,
+ HashType,
+ IconType,
+ PathType,
+ ModifiedTimeType
+ };
+ EntryInfo();
+ virtual ~EntryInfo();
+ qulonglong size();
+ bool isDir();
+ QDateTime modifiedTime();
+ QString hash();
+ QString path();
+ QString icon();
+ void setValue(EntryType type,const QVariant& value);
+protected:
+ qulonglong m_size;
+ bool is_dir;
+ QString m_hash,m_path,m_icon;
+ QDateTime m_modifiedTime;
+};
+typedef QList<EntryInfo> EntryList;
+}
+#endif
View
8 include/ibackend.h
@@ -4,6 +4,7 @@
#include <QtCore/QtPlugin>
#include "qcloud_global.h"
#include "info.h"
+#include "entryinfo.h"
class QNetworkAccessManager;
namespace QCloud
@@ -25,7 +26,12 @@ class QCLOUD_EXPORT IBackend : public QObject
virtual bool authorize (QWidget* widget = 0) = 0;
virtual void setNetworkAccessManager (QNetworkAccessManager* manager);
virtual Request* uploadFile (const QString& localFileName, const QString& remoteFilePath) = 0;
- virtual Request* downloadFile(const QString& remoteFilePath,const QString& localFileName) = 0;
+ virtual Request* downloadFile (const QString& remoteFilePath,const QString& localFileName) = 0;
+ virtual Request* copyFile (const QString& fromPath,const QString& toPath) = 0;
+ virtual Request* moveFile (const QString& fromPath,const QString& toPath) = 0;
+ virtual Request* createFolder (const QString& path) = 0;
+ virtual Request* deleteFile (const QString& path) = 0;
+ virtual Request* pathInfo (const QString& path,EntryInfo* info = NULL,EntryList* contents = NULL) = 0;
virtual void saveAccountInfo (const QString& key, QSettings& settings, ISecureStore* secureStore) = 0;
virtual void loadAccountInfo (const QString& key, QSettings& settings, ISecureStore* secureStore) = 0;
virtual void deleteSecretInfo (const QString& key, ISecureStore* securestore) = 0;
View
4 include/server.h
@@ -22,14 +22,18 @@ class QCLOUD_EXPORT Server : public QObject
virtual InfoList listApps() = 0;
virtual InfoList listBackends() = 0;
virtual InfoList listAccounts() = 0;
+ virtual void listFiles(const QString& uuid,const QString& directory) = 0;
virtual int uploadFile (const QString& app_name, const QStringList& file_list) = 0;
virtual void addAccount (const QString& backend_name, const QString& user_name) = 0;
virtual void deleteAccount (const QString& uuid) = 0;
virtual int sync (const QString& app_name) = 0;
void notifyAccountUpdated();
+ void notifyDirectoryInfoTransformed(QCloud::InfoList info);
bool isValid() const;
+
signals:
void accountUpdated();
+ void directoryInfoTransformed(QCloud::InfoList info);
private:
Q_DISABLE_COPY (Server)
ServerPrivate* d;
View
2 lib/CMakeLists.txt
@@ -25,6 +25,7 @@ set(qcloud_SRCS
encrypter.cpp
info.cpp
request.cpp
+ entryinfo.cpp
)
set(qcloud_HDRS
@@ -42,6 +43,7 @@ set(qcloud_HDRS
../include/packager.h
../include/encrypter.h
../include/request.h
+ ../include/entryinfo.h
)
set(qcloud_MOC_HDRS ${qcloud_HDRS}
View
6 lib/client.cpp
@@ -20,6 +20,7 @@ Client::Client (QObject* parent) : QObject (parent)
, d (new ClientPrivate (this))
{
connect(d->daemon, SIGNAL(accountUpdated()), this, SIGNAL(accountUpdated()));
+ connect(d->daemon, SIGNAL(directoryInfoTransformed(QCloud::InfoList)), this, SIGNAL(directoryInfoTransformed(QCloud::InfoList)));
}
Client::~Client()
@@ -47,6 +48,11 @@ QDBusPendingReply<InfoList> Client::listAccounts()
return d->daemon->listAccounts();
}
+QDBusPendingReply<InfoList> Client::listFiles(const QString& uuid,const QString& directory)
+{
+ return d->daemon->listFiles(uuid,directory);
+}
+
QDBusPendingReply< void > Client::addAccount (const QString& backend_name, const QString& user_name)
{
return d->daemon->addAccount (backend_name, user_name);
View
12 lib/daemon.xml
@@ -10,7 +10,7 @@
<annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="QCloud::InfoList" />
</method>
<method name="listAccounts">
- <arg name="accounts" type="a(sss)" direction="out" />
+ <arg name="accounts" type="a(ssss)" direction="out" />
<annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="QCloud::InfoList" />
</method>
<method name="uploadFile">
@@ -30,7 +30,17 @@
<method name="deleteAccount">
<arg name="uuid" type="s" direction="in" />
</method>
+ <method name="listFiles">
+ <arg name="uuid" type="s" direction="in" />
+ <arg name="directory" type="s" direction="in" />
+ <!---<arg name="file_list" type="a(ssss)" direction="out" />
+ <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="QCloud::InfoList" /> -->
+ </method>
<signal name="accountUpdated">
</signal>
+ <signal name="directoryInfoTransformed">
+ <arg name="info" type="a(ssss)" direction="out"/>
+ <annotation name="com.trolltech.QtDBus.QtTypeName.In0" value="QCloud::InfoList" />
+ </signal>
</interface>
</node>
View
73 lib/entryinfo.cpp
@@ -0,0 +1,73 @@
+#include <QDebug>
+#include "entryinfo.h"
+#include "request.h"
+
+namespace QCloud{
+
+EntryInfo::~EntryInfo()
+{
+
+}
+
+EntryInfo::EntryInfo()
+{
+
+}
+
+qulonglong EntryInfo::size()
+{
+ return m_size;
+}
+
+bool EntryInfo::isDir()
+{
+ return is_dir;
+}
+
+QDateTime EntryInfo::modifiedTime()
+{
+ return m_modifiedTime;
+}
+
+QString EntryInfo::hash()
+{
+ return m_hash;
+}
+
+QString EntryInfo::path()
+{
+ return m_path;
+}
+
+QString EntryInfo::icon()
+{
+ return m_icon;
+}
+
+void EntryInfo::setValue(EntryInfo::EntryType type,const QVariant& value)
+{
+ switch (type){
+ case EntryInfo::SizeType:
+ m_size = value.toULongLong();
+ break;
+ case EntryInfo::DirType:
+ is_dir = value.toBool();
+ break;
+ case EntryInfo::HashType:
+ m_hash = value.toString();
+ break;
+ case EntryInfo::IconType:
+ m_icon = value.toString();
+ break;
+ case EntryInfo::PathType:
+ m_path = value.toString();
+ break;
+ case EntryInfo::ModifiedTimeType:
+ m_modifiedTime = QDateTime::fromString(value.toString());
+ break;
+ default:
+ qDebug() << "No such type";
+ return ;
+ }
+}
+}
View
6 lib/server.cpp
@@ -37,6 +37,12 @@ void Server::notifyAccountUpdated()
emit accountUpdated();
}
+void Server::notifyDirectoryInfoTransformed(QCloud::InfoList info)
+{
+ emit directoryInfoTransformed(info);
+ qDebug() << "signal directoryInfoTransformed() sent";
+}
+
bool Server::isValid() const
{
return d->valid;
View
10 tests/dropbox/dropbox_test.cpp
@@ -6,11 +6,14 @@
#include "factory.h"
#include "app.h"
#include "request.h"
+#include "entryinfo.h"
+
+using namespace QCloud;
void printUsage(char **argv)
{
printf ("Usage : %s appfile download/upload/move/copy [source] [destination]\n",argv[0]);
- printf ("or : %s appfile create_folder/delete [path]\n",argv[0]);
+ printf ("or : %s appfile create_folder/delete/get_info [path]\n",argv[0]);
}
int main (int argc, char* argv[])
@@ -71,6 +74,11 @@ int main (int argc, char* argv[])
QCloud::Request* request = dropbox->deleteFile(QString::fromLocal8Bit(argv[3]));
request->waitForFinished();
}
+ else if (strcmp(argv[2], "get_info") == 0){
+ EntryInfo info;
+ QCloud::Request* request = dropbox->pathInfo(QString::fromLocal8Bit(argv[3]),&info);
+ request->waitForFinished();
+ }
else {
qDebug() << "Invalid operation " << argv[2];
return 1;
View
1 tool/clientapp.h
@@ -2,6 +2,7 @@
#define QCLOUD_CLIENTAPP_H
#include <QApplication>
+#include "infomodel.h"
class MainWindow;
namespace QCloud
View
67 tool/mainwindow.cpp
@@ -14,7 +14,10 @@ MainWindow::MainWindow (QWidget* parent, Qt::WindowFlags flags) : QMainWindow (p
, m_widget (new QWidget (this))
, m_ui (new Ui::Tool)
, m_accountModel (new InfoModel(this))
+ , m_fileModel(new InfoModel(this))
{
+ currentDir = "";
+
setCentralWidget (m_widget);
m_ui->setupUi (m_widget);
m_ui->accountView->setModel(m_accountModel);
@@ -22,15 +25,21 @@ MainWindow::MainWindow (QWidget* parent, Qt::WindowFlags flags) : QMainWindow (p
m_addAccountButton = m_ui->addAccountButton;
m_deleteAccountButton = m_ui->deleteAccountButton;
+ m_listButton = m_ui->listButton;
m_addAccountButton->setIcon (QIcon::fromTheme ("list-add"));
m_deleteAccountButton->setIcon (QIcon::fromTheme ("list-remove"));
+
+ m_ui->fileView->setModel(m_fileModel);
+ m_ui->fileView->setSelectionMode(QAbstractItemView::SingleSelection);
setWindowTitle (tr ("QCloud"));
setWindowIcon (QIcon::fromTheme ("qcloud"));
connect (m_addAccountButton, SIGNAL (clicked (bool)), this, SLOT (addAccountButtonClicked()));
connect (m_deleteAccountButton, SIGNAL(clicked(bool)), this, SLOT(deleteAccountButtonClicked()));
+ connect (m_ui->fileView, SIGNAL(activated(QModelIndex)),this, SLOT(fileListActivated()));
+ connect (m_listButton, SIGNAL(clicked(bool)),this, SLOT(listButtonClicked()));
}
MainWindow::~MainWindow()
@@ -76,4 +85,60 @@ void MainWindow::loadAccount()
QDBusPendingReply< QCloud::InfoList > accounts = ClientApp::instance()->client()->listAccounts();
QDBusPendingCallWatcher* appsWatcher = new QDBusPendingCallWatcher(accounts);
connect(appsWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(accountsFinished(QDBusPendingCallWatcher*)));
-}
+}
+
+bool MainWindow::loadFileList()
+{
+ qDebug() << "Loading file list...";
+ if (!m_ui->accountView->currentIndex().isValid()){
+ qDebug() << "Invalid index!";
+ return false;
+ }
+ QModelIndex index;
+ index = m_ui->accountView->currentIndex();
+ QString uuid = static_cast< QCloud::Info* > (index.internalPointer())->name();
+ if (uuid.isEmpty()){
+ return false;
+ }
+ //QDBusPendingReply< QCloud::InfoList > files = ClientApp::instance()->client()->listFiles(uuid,currentDir);
+ ClientApp::instance()->client()->listFiles(uuid,currentDir);
+ //QDBusPendingCallWatcher* appsWatcher = new QDBusPendingCallWatcher(files);
+ //connect(appsWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(filesFinished(QDBusPendingCallWatcher*)));
+ connect(ClientApp::instance()->client(),SIGNAL(directoryInfoTransformed(const QCloud::InfoList&)),this,SLOT(fileListFinished(QCloud::InfoList)));
+ return true;
+}
+
+void MainWindow::filesFinished(QDBusPendingCallWatcher* watcher)
+{
+ QDBusPendingReply< QCloud::InfoList > backends(*watcher);
+ m_fileModel->setInfoList(backends.value());
+}
+
+void MainWindow::fileListActivated()
+{ if (!m_ui->fileView->currentIndex().isValid()){
+ qDebug() << "Invalid index!";
+ return ;
+ }
+ QModelIndex index;
+ index = m_ui->fileView->currentIndex();
+ QString lastDir = currentDir;
+ currentDir = static_cast<QCloud::Info*> (index.internalPointer())->name();
+ QString is_dir = static_cast< QCloud::Info* > (index.internalPointer())->description();
+ qDebug() << is_dir << " " << currentDir;
+ if (is_dir!="is_dir" || (!loadFileList())){
+ currentDir = lastDir;
+ return ;
+ }
+}
+
+void MainWindow::listButtonClicked()
+{
+ loadFileList();
+}
+
+void MainWindow::fileListFinished(const QCloud::InfoList& info)
+{
+ qDebug() << "Got file list info";
+ m_fileModel->setInfoList(info);
+}
+
View
9 tool/mainwindow.h
@@ -1,4 +1,5 @@
#include <QMainWindow>
+#include "infomodel.h"
class QDBusPendingCallWatcher;
class InfoModel;
@@ -17,15 +18,23 @@ class MainWindow : public QMainWindow
virtual ~MainWindow();
void loadAccount();
+ bool loadFileList();
private slots:
void accountsFinished(QDBusPendingCallWatcher* watcher);
+ void filesFinished(QDBusPendingCallWatcher* watcher);
void addAccountButtonClicked();
void deleteAccountButtonClicked();
+ void fileListActivated();
+ void listButtonClicked();
+ void fileListFinished(const QCloud::InfoList& info);
private:
QWidget* m_widget;
Ui::Tool* m_ui;
InfoModel* m_accountModel;
+ InfoModel* m_fileModel;
QPushButton* m_addAccountButton;
QPushButton* m_deleteAccountButton;
+ QPushButton* m_listButton;
+ QString currentDir;
};
View
27 tool/tool.ui
@@ -117,29 +117,32 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
- <widget class="QGroupBox" name="groupBox">
+ <widget class="QGroupBox" name="groupBox_2">
<property name="title">
- <string>GroupBox</string>
+ <string>file list</string>
</property>
- <layout class="QVBoxLayout" name="verticalLayout_3">
+ <layout class="QVBoxLayout" name="verticalLayout_2">
<item>
- <widget class="QPushButton" name="authorizeButton">
- <property name="text">
- <string>PushButton</string>
- </property>
- </widget>
+ <widget class="QListView" name="fileView"/>
</item>
</layout>
</widget>
</item>
<item>
- <widget class="QGroupBox" name="groupBox_2">
+ <widget class="QGroupBox" name="groupBox">
<property name="title">
- <string>GroupBox</string>
+ <string/>
</property>
- <layout class="QVBoxLayout" name="verticalLayout_2">
+ <property name="alignment">
+ <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
<item>
- <widget class="QListView" name="listView_2"/>
+ <widget class="QPushButton" name="listButton">
+ <property name="text">
+ <string>ListFiles</string>
+ </property>
+ </widget>
</item>
</layout>
</widget>
Something went wrong with that request. Please try again.