Quark  0.1
GDriveFilesystem.h++
Go to the documentation of this file.
1 #ifndef __libquark_gdrive_GDriveFilesystem_hxx
2 #define __libquark_gdrive_GDriveFilesystem_hxx
3 
4 #include <QFile>
5 #include <QList>
6 #include <QNetworkAccessManager>
7 #include <QNetworkReply>
8 #include <QScopedPointer>
9 #include <QString>
10 #include <QStringList>
11 
12 class QFile;
13 class QHttpMultiPart;
14 class QJsonObject;
15 
17 #include <quark/GDriveFile.h++>
19 
20 namespace quark {
21 namespace gdrive {
22 
23 class GDriveFilesystem : public QObject
24 {
25  Q_OBJECT;
26 
27  public:
28 
29  GDriveFilesystem(QNetworkAccessManager *networkAccess,
30  QObject *parent = NULL);
31  virtual ~GDriveFilesystem();
32 
33  void setAccessToken(const oauth2::OAuth2AccessToken &token);
34 
35  bool isRequestInProgress() const;
36  void cancelRequest();
37 
38  bool createFolder(const QString &title, const QString &folderId = QString());
39  bool createFile(const QString &localPath, const GDriveFile &file);
40  bool deleteFile(const QString &fileId);
41  bool statFile(const QString &fileId);
42 
43  bool listFiles(const QString &folderId = QString(),
44  const QString &fileQuery = QString(),
45  int maxResults = 100);
46 
47  bool downloadFile(const GDriveFile &file, const QString &localPath);
48  bool uploadFile(const QString &localPath, const GDriveFile &file);
49 
53  static const QString PER_FILE_ACCESS_SCOPE;
58  static const QString FULL_ACCESS_SCOPE;
63  static const QString READ_ONLY_APP_LIST_SCOPE;
67  static const QString READ_ONLY_FILE_ACCESS_SCOPE;
76  static const QString APP_INSTALLATION_SCOPE;
80  static const QString APP_DATA_FOLDER_ACCESS_SCOPE;
81 
85  static const QString FOLDER_MIME_TYPE;
86 
87  signals:
88 
89  void folderCreated(const QString &id);
91  void fileDeleted(const QString &id);
92  void fileTransferProgress(qint64 bytesTransferred, qint64 bytesTotal);
93  void fileDownloaded(const QString &id, const QString &localPath);
94  void fileUploaded(const QString &localPath, quark::gdrive::GDriveFile file);
95  void fileListAvailable(QList<quark::gdrive::GDriveFile> files);
97 
98  void requestFailed();
99  void requestCancelled();
100 
101  private slots:
102 
103  void handleError(QNetworkReply::NetworkError error);
104  void handleJsonReply();
105  void handleTransferProgress(qint64 bytesTransferred, qint64 bytesTotal);
106  void handleDownloadFinished();
107 
108  private:
109 
110  enum RequestType { REQ_NONE = 0, REQ_CREATE_FOLDER, REQ_CREATE, REQ_DELETE,
111  REQ_STAT, REQ_LIST, REQ_UPLOAD, REQ_DOWNLOAD };
112 
113  QHttpMultiPart *buildMultiPartForUpload(const GDriveFile &file);
114  bool parseFileMetadata(const QJsonObject &object, GDriveFile &file);
115  bool parseFileList(const QJsonObject &object, QList<GDriveFile> &files);
116  qint64 parseTime(const QString &value);
117 
118  QNetworkAccessManager *_networkAccess;
120  QScopedPointer<QFile> _localFile;
121  QString _currentFileId;
122  RequestType _requestType;
123  QNetworkReply *_networkReply;
124 };
125 
126 } // namespace gdrive
127 } // namespace quark
128 
129 #endif // __libquark_gdrive_GDriveFilesystem_hxx
Definition: GDriveFilesystem.h++:23
void fileTransferProgress(qint64 bytesTransferred, qint64 bytesTotal)
void fileUploaded(const QString &localPath, quark::gdrive::GDriveFile file)
bool deleteFile(const QString &fileId)
static const QString READ_ONLY_FILE_ACCESS_SCOPE
Allows read-only access to file metadata and file content.
Definition: GDriveFilesystem.h++:67
bool listFiles(const QString &folderId=QString(), const QString &fileQuery=QString(), int maxResults=100)
GDriveFilesystem(QNetworkAccessManager *networkAccess, QObject *parent=NULL)
void fileInfoAvailable(quark::gdrive::GDriveFile file)
bool downloadFile(const GDriveFile &file, const QString &localPath)
static const QString READ_ONLY_FILE_METADATA_ACCESS_SCOPE
Allows read-only access to file metadata, but does not allow any access to read or download file cont...
Definition: GDriveFilesystem.h++:72
bool uploadFile(const QString &localPath, const GDriveFile &file)
Definition: GDriveFile.h++:16
bool createFolder(const QString &title, const QString &folderId=QString())
Definition: BarChartView.h++:6
bool createFile(const QString &localPath, const GDriveFile &file)
static const QString APP_DATA_FOLDER_ACCESS_SCOPE
Allows access to the Application Data folder.
Definition: GDriveFilesystem.h++:80
static const QString APP_INSTALLATION_SCOPE
Special scope used to let users approve installation of an app.
Definition: GDriveFilesystem.h++:76
A representation of an OAuth2 access token.
Definition: OAuth2AccessToken.h++:17
void folderCreated(const QString &id)
void fileDownloaded(const QString &id, const QString &localPath)
bool statFile(const QString &fileId)
static const QString FOLDER_MIME_TYPE
The mime type for a folder.
Definition: GDriveFilesystem.h++:85
static const QString FULL_ACCESS_SCOPE
Full, permissive scope to access all of a user&#39;s files.
Definition: GDriveFilesystem.h++:58
void setAccessToken(const oauth2::OAuth2AccessToken &token)
static const QString PER_FILE_ACCESS_SCOPE
Per-file access to files created or opened by the app.
Definition: GDriveFilesystem.h++:53
static const QString READ_ONLY_APP_LIST_SCOPE
Allows apps read-only access to the list of Drive apps a user has installed.
Definition: GDriveFilesystem.h++:63
void fileListAvailable(QList< quark::gdrive::GDriveFile > files)
void fileCreated(quark::gdrive::GDriveFile file)
void fileDeleted(const QString &id)