meedocs.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. MeeDocs - A Google Docs / Google Drive client for N9
  3. Copyright 2012 Marcel D. Juhnke <marcel.juhnke@ovi.com>
  4. This file is part of MeeDocs.
  5. MeeDocs is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 2 of the License, or
  8. (at your option) any later version.
  9. MeeDocs is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with MeeDocs. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef MEEDOCS_H
  17. #define MEEDOCS_H
  18. #include <QDir>
  19. #include <QFile>
  20. #include <QFileInfo>
  21. #include <QList>
  22. #include <QNetworkAccessManager>
  23. #include <QNetworkRequest>
  24. #include <QNetworkReply>
  25. #include <QStringList>
  26. #include <QTextStream>
  27. #include <QTimer>
  28. #include <QUrl>
  29. #include <QtGui/QApplication>
  30. #include <TransferUI/Client>
  31. #include <TransferUI/Transfer>
  32. #include <maemo-meegotouch-interfaces/shareuiinterface.h>
  33. #include <MDataUri>
  34. #include <QtDebug>
  35. class MeeDocs: public QObject
  36. {
  37. Q_OBJECT
  38. QNetworkAccessManager manager;
  39. QNetworkReply *downReply; //NetworkReply Object for Downloads
  40. QNetworkReply *putReply; //NetworkReply Object for Downloads
  41. TransferUI::Client *transferClient; //Global client for TransferUI
  42. TransferUI::Transfer *downloadTransfer; //Tranfser pointer for download Transfers
  43. TransferUI::Transfer *uploadTransfer; //Tranfser pointer for download Transfers
  44. public:
  45. MeeDocs();
  46. //the following methods handle down- and uploads from and to GDrive
  47. Q_INVOKABLE void doDownload(const QUrl &url, const QString &accessToken, QString name, const QString &doctype);
  48. Q_INVOKABLE void doUpload(const QString &path, const QString &filename, const QString &accessToken);
  49. Q_INVOKABLE QByteArray uploadFileSize(const QString &path, const QString &filename);
  50. //the following methods handle GDrive collection/folder management
  51. Q_INVOKABLE void createCollection(const QString &collectionTitle, const QString &accessToken);
  52. Q_INVOKABLE void deleteCollection(const QString &collectionTitle, const QString &accessToken);
  53. Q_INVOKABLE void addToCollection(const QString &collectionId, const QString &resourceId, const QString &accessToken);
  54. Q_INVOKABLE void removeFromCollection(const QString &url, const QString &accessToken);
  55. Q_INVOKABLE void shareDoc(const QString &selflink, const QString &accessToken);
  56. Q_INVOKABLE void openShareUI(const QString &url);
  57. //the following methods handle GDrive file movement/deletion
  58. Q_INVOKABLE void trashFile(const QString &selfLink, const QString &accessToken);
  59. //the following methods handle local (on-device) file access for uploads
  60. Q_INVOKABLE QStringList listDirContent(const QString &path);
  61. Q_INVOKABLE bool isDir(const QString &path);
  62. signals:
  63. void downloadDone();
  64. void uploadDone();
  65. void uploadFailed();
  66. void nextBytes();
  67. void collectionCreated();
  68. void collectionFailed();
  69. void addedToCollection();
  70. void addedToCollectionFailed();
  71. public slots:
  72. void downloadFinished();
  73. void resumeUpload();
  74. void downloadStatus(const qint64 &bytesReceived, const qint64 &bytesTotal);
  75. void uploadStatus(const qint64 &bytesSent, const qint64 &bytesTotal);
  76. void cancelDownload();
  77. void cancelUpload();
  78. void isCollectionCreated();
  79. void isCollectionDeleted();
  80. void isAddedToCollection();
  81. void isRemovedFromCollection();
  82. void isFileTrashed();
  83. void isDocShared();
  84. private:
  85. QByteArray m_auth_header; //GData API authentication header
  86. QString m_filename; //filename for file downloads
  87. QByteArray m_file_size; //holds the file size of the file to be uploaded
  88. QByteArray m_content_type; //holds the content (MIME) type of the file to be uploaded
  89. qint64 m_content_range_begin; //holds the beginning of the byte range for the current upload chunk
  90. qint64 m_content_range_end; //holds the end of the byte range for the current upload chunk
  91. int m_file_parts; //holds the number of chunks of which the uploaded file consists
  92. int m_current_file_part; //holds the number of chunk which currently being uploaded
  93. QUrl m_next_location; //holds the URL to where the next upload chunk has to be PUT
  94. QByteArray m_succeeded_range; //holds the reply from GDrive which bytes have already been received successfully
  95. void nextUpload(const QUrl &url);
  96. bool saveToDisk(const QString &filename, QIODevice *data);
  97. QByteArray contentType(const QString &filename);
  98. QFile *m_upload_file; //pointer to the file which is to be uploaded
  99. qint64 m_bytes_received; //holds how much bytes have been downloaded for the Transfer UI
  100. qint64 m_bytes_total; //holds how much bytes the transfer is in total for the Transfer UI
  101. qint64 m_chunk_size; //holds the chunk size for the GDrive upload
  102. qint64 m_bytes_sent; //holds how much bytes have been uploaded for the Transfer UI
  103. //iterators and percentages for Transfer UI progress bars
  104. float m_download_progress_iterator;
  105. float m_download_progress;
  106. float m_upload_progress_iterator;
  107. float m_upload_progress;
  108. bool m_transfer_size_set; //holds if the transfer size for Transfer UI is alreadys set to avoid continuous rewriting
  109. };
  110. #endif // DOWNLOADMANAGER_H