1 // For license of this file, see <project-root-folder>/LICENSE.md. 2 3 #ifndef OWNCLOUDNETWORKFACTORY_H 4 #define OWNCLOUDNETWORKFACTORY_H 5 6 #include "core/message.h" 7 #include "network-web/networkfactory.h" 8 #include "services/abstract/rootitem.h" 9 10 #include <QDateTime> 11 #include <QIcon> 12 #include <QJsonObject> 13 #include <QNetworkReply> 14 #include <QString> 15 16 class OwnCloudResponse { 17 public: 18 explicit OwnCloudResponse(QNetworkReply::NetworkError response, const QString& raw_content = QString()); 19 virtual ~OwnCloudResponse(); 20 21 bool isLoaded() const; 22 QString toString() const; 23 QNetworkReply::NetworkError networkError() const; 24 25 protected: 26 QNetworkReply::NetworkError m_networkError; 27 QJsonObject m_rawContent; 28 bool m_emptyString; 29 }; 30 31 class OwnCloudGetMessagesResponse : public OwnCloudResponse { 32 public: 33 explicit OwnCloudGetMessagesResponse(QNetworkReply::NetworkError response, const QString& raw_content = QString()); 34 virtual ~OwnCloudGetMessagesResponse(); 35 36 QList<Message> messages() const; 37 }; 38 39 class OwnCloudStatusResponse : public OwnCloudResponse { 40 public: 41 explicit OwnCloudStatusResponse(QNetworkReply::NetworkError response, const QString& raw_content = QString()); 42 virtual ~OwnCloudStatusResponse(); 43 44 QString version() const; 45 }; 46 47 class RootItem; 48 49 class OwnCloudGetFeedsCategoriesResponse : public OwnCloudResponse { 50 public: 51 explicit OwnCloudGetFeedsCategoriesResponse(QNetworkReply::NetworkError response, QString raw_categories = QString(), QString raw_feeds = QString()); 52 virtual ~OwnCloudGetFeedsCategoriesResponse(); 53 54 // Returns tree of feeds/categories. 55 // Top-level root of the tree is not needed here. 56 // Returned items do not have primary IDs assigned. 57 RootItem* feedsCategories(bool obtain_icons) const; 58 59 private: 60 QString m_contentCategories; 61 QString m_contentFeeds; 62 }; 63 64 class OwnCloudNetworkFactory { 65 public: 66 explicit OwnCloudNetworkFactory(); 67 virtual ~OwnCloudNetworkFactory(); 68 69 QString url() const; 70 void setUrl(const QString& url); 71 72 bool forceServerSideUpdate() const; 73 void setForceServerSideUpdate(bool force_update); 74 75 QString authUsername() const; 76 void setAuthUsername(const QString& auth_username); 77 78 QString authPassword() const; 79 void setAuthPassword(const QString& auth_password); 80 81 // Gets/sets the amount of messages to obtain during single feed update. 82 int batchSize() const; 83 void setBatchSize(int batch_size); 84 85 bool downloadOnlyUnreadMessages() const; 86 void setDownloadOnlyUnreadMessages(bool dowload_only_unread_messages); 87 88 // Operations. 89 90 // Get version info. 91 OwnCloudStatusResponse status(const QNetworkProxy& custom_proxy); 92 93 // Get feeds & categories (used for sync-in). 94 OwnCloudGetFeedsCategoriesResponse feedsCategories(const QNetworkProxy& custom_proxy); 95 96 // Feed operations. 97 bool deleteFeed(const QString& feed_id, const QNetworkProxy& custom_proxy); 98 bool createFeed(const QString& url, int parent_id, const QNetworkProxy& custom_proxy); 99 bool renameFeed(const QString& new_name, const QString& custom_feed_id, const QNetworkProxy& custom_proxy); 100 101 // Get messages for given feed. 102 OwnCloudGetMessagesResponse getMessages(int feed_id, const QNetworkProxy& custom_proxy); 103 104 // Misc methods. 105 QNetworkReply::NetworkError triggerFeedUpdate(int feed_id, const QNetworkProxy& custom_proxy); 106 107 NetworkResult markMessagesRead(RootItem::ReadStatus status, 108 const QStringList& custom_ids, 109 const QNetworkProxy& custom_proxy); 110 111 NetworkResult markMessagesStarred(RootItem::Importance importance, 112 const QStringList& feed_ids, 113 const QStringList& guid_hashes, 114 const QNetworkProxy& custom_proxy); 115 116 private: 117 QString m_url; 118 QString m_fixedUrl; 119 bool m_downloadOnlyUnreadMessages; 120 bool m_forceServerSideUpdate; 121 QString m_authUsername; 122 QString m_authPassword; 123 int m_batchSize; 124 125 // Endpoints. 126 QString m_urlUser; 127 QString m_urlStatus; 128 QString m_urlFolders; 129 QString m_urlFeeds; 130 QString m_urlMessages; 131 QString m_urlFeedsUpdate; 132 QString m_urlDeleteFeed; 133 QString m_urlRenameFeed; 134 }; 135 136 #endif // OWNCLOUDNETWORKFACTORY_H 137