diff --git a/src/services/abstract/serviceroot.cpp b/src/services/abstract/serviceroot.cpp index f939ff9a0..8783b455c 100755 --- a/src/services/abstract/serviceroot.cpp +++ b/src/services/abstract/serviceroot.cpp @@ -69,6 +69,12 @@ QList ServiceRoot::serviceMenu() { return QList(); } +void ServiceRoot::start(bool freshly_activated) { + Q_UNUSED(freshly_activated) +} + +void ServiceRoot::stop() {} + void ServiceRoot::updateCounts(bool including_total_count) { QList feeds; @@ -187,6 +193,14 @@ QList ServiceRoot::undeletedMessages() const { return DatabaseQueries::getUndeletedMessagesForAccount(database, accountId()); } +bool ServiceRoot::supportsFeedAdding() const { + return false; +} + +bool ServiceRoot::supportsCategoryAdding() const { + return false; +} + void ServiceRoot::itemChanged(const QList& items) { emit dataChanged(items); } @@ -211,6 +225,12 @@ void ServiceRoot::requestItemRemoval(RootItem* item) { emit itemRemovalRequested(item); } +void ServiceRoot::addNewFeed(const QString& url) { + Q_UNUSED(url) +} + +void ServiceRoot::addNewCategory() {} + QMap ServiceRoot::storeCustomFeedsData() { QMap custom_data; diff --git a/src/services/abstract/serviceroot.h b/src/services/abstract/serviceroot.h index d0cc61b12..792a90f2f 100755 --- a/src/services/abstract/serviceroot.h +++ b/src/services/abstract/serviceroot.h @@ -35,8 +35,8 @@ class ServiceRoot : public RootItem { virtual RecycleBin* recycleBin() const; QList undeletedMessages() const; - virtual bool supportsFeedAdding() const = 0; - virtual bool supportsCategoryAdding() const = 0; + virtual bool supportsFeedAdding() const; + virtual bool supportsCategoryAdding() const; // Returns list of specific actions for "Add new item" main window menu. // So typical list of returned actions could look like: @@ -61,8 +61,8 @@ class ServiceRoot : public RootItem { // // Stop method is called just before application exits OR when // user explicitly deletes existing service instance. - virtual void start(bool freshly_activated) = 0; - virtual void stop() = 0; + virtual void start(bool freshly_activated); + virtual void stop(); // Account ID corresponds with DB attribute Accounts (id). int accountId() const; @@ -145,8 +145,8 @@ class ServiceRoot : public RootItem { void requestItemRemoval(RootItem* item); public slots: - virtual void addNewFeed(const QString& url = QString()) = 0; - virtual void addNewCategory() = 0; + virtual void addNewFeed(const QString& url = QString()); + virtual void addNewCategory(); virtual void syncIn(); protected: diff --git a/src/services/gmail/gmailfeed.cpp b/src/services/gmail/gmailfeed.cpp index 7c0f0ec9d..b910a4d06 100755 --- a/src/services/gmail/gmailfeed.cpp +++ b/src/services/gmail/gmailfeed.cpp @@ -9,6 +9,12 @@ GmailFeed::GmailFeed(RootItem* parent) : Feed(parent) {} +GmailFeed::GmailFeed(const QString& title, const QString& custom_id, const QIcon& icon, RootItem* parent) : GmailFeed(parent) { + setTitle(title); + setCustomId(custom_id); + setIcon(icon); +} + GmailFeed::GmailFeed(const QSqlRecord& record) : Feed(record) {} GmailServiceRoot* GmailFeed::serviceRoot() const { diff --git a/src/services/gmail/gmailfeed.h b/src/services/gmail/gmailfeed.h index cbc388f46..402cbe260 100755 --- a/src/services/gmail/gmailfeed.h +++ b/src/services/gmail/gmailfeed.h @@ -10,6 +10,7 @@ class GmailServiceRoot; class GmailFeed : public Feed { public: explicit GmailFeed(RootItem* parent = nullptr); + explicit GmailFeed(const QString& title, const QString& custom_id, const QIcon& icon, RootItem* parent = nullptr); explicit GmailFeed(const QSqlRecord& record); GmailServiceRoot* serviceRoot() const; diff --git a/src/services/gmail/gmailserviceroot.cpp b/src/services/gmail/gmailserviceroot.cpp index a5b20f87e..29ee64d2a 100755 --- a/src/services/gmail/gmailserviceroot.cpp +++ b/src/services/gmail/gmailserviceroot.cpp @@ -25,6 +25,7 @@ #include "network-web/oauth2service.h" #include "services/abstract/recyclebin.h" #include "services/gmail/gmailentrypoint.h" +#include "services/gmail/gmailfeed.h" #include "services/gmail/network/gmailnetworkfactory.h" GmailServiceRoot::GmailServiceRoot(GmailNetworkFactory* network, RootItem* parent) : ServiceRoot(parent), @@ -47,13 +48,10 @@ void GmailServiceRoot::updateTitle() { } void GmailServiceRoot::loadFromDatabase() { - QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); - Assignment categories = DatabaseQueries::getCategories(database, accountId()); - Assignment feeds = DatabaseQueries::getInoreaderFeeds(database, accountId()); - - // All data are now obtained, lets create the hierarchy. - assembleCategories(categories); - assembleFeeds(feeds); + appendChild(new GmailFeed(tr("Inbox"), QSL("INBOX"), qApp->icons()->fromTheme(QSL("mail-inbox")), this)); + appendChild(new GmailFeed(tr("Sent"), QSL("SENT"), qApp->icons()->fromTheme(QSL("mail-sent")), this)); + appendChild(new GmailFeed(tr("Drafts"), QSL("DRAFT"), qApp->icons()->fromTheme(QSL("gtk-edit")), this)); + appendChild(new GmailFeed(tr("Spam"), QSL("SPAM"), qApp->icons()->fromTheme(QSL("mail-mark-junk")), this)); // As the last item, add recycle bin, which is needed. appendChild(recycleBin()); @@ -121,27 +119,12 @@ void GmailServiceRoot::start(bool freshly_activated) { loadCacheFromFile(accountId()); m_network->oauth()->login(); - - if (childCount() <= 1) { - syncIn(); - } } void GmailServiceRoot::stop() { saveCacheToFile(accountId()); } -QList GmailServiceRoot::serviceMenu() { - if (m_serviceMenu.isEmpty()) { - QAction* act_sync_in = new QAction(qApp->icons()->fromTheme(QSL("view-refresh")), tr("Sync in"), this); - - connect(act_sync_in, &QAction::triggered, this, &GmailServiceRoot::syncIn); - m_serviceMenu.append(act_sync_in); - } - - return m_serviceMenu; -} - QString GmailServiceRoot::code() const { return GmailEntryPoint().code(); } @@ -153,16 +136,6 @@ QString GmailServiceRoot::additionalTooltip() const { network()->oauth()->tokensExpireIn().toString() : QSL("-")); } -RootItem* GmailServiceRoot::obtainNewTreeForSyncIn() const { - return m_network->feedsCategories(); -} - -void GmailServiceRoot::addNewFeed(const QString& url) { - Q_UNUSED(url) -} - -void GmailServiceRoot::addNewCategory() {} - void GmailServiceRoot::saveAllCachedData(bool async) { QPair, QMap>> msgCache = takeMessageCache(); QMapIterator i(msgCache.first); diff --git a/src/services/gmail/gmailserviceroot.h b/src/services/gmail/gmailserviceroot.h index 88569d857..79ebb3bdb 100755 --- a/src/services/gmail/gmailserviceroot.h +++ b/src/services/gmail/gmailserviceroot.h @@ -49,18 +49,13 @@ class GmailServiceRoot : public ServiceRoot, public CacheForServiceRoot { QString additionalTooltip() const; - RootItem* obtainNewTreeForSyncIn() const; - void saveAllCachedData(bool async = true); public slots: - void addNewFeed(const QString& url); - void addNewCategory(); void updateTitle(); private: void loadFromDatabase(); - QList serviceMenu(); private: QList m_serviceMenu; diff --git a/src/services/gmail/network/gmailnetworkfactory.cpp b/src/services/gmail/network/gmailnetworkfactory.cpp index 04939f858..d1023a5e5 100755 --- a/src/services/gmail/network/gmailnetworkfactory.cpp +++ b/src/services/gmail/network/gmailnetworkfactory.cpp @@ -70,32 +70,33 @@ void GmailNetworkFactory::setUsername(const QString& username) { m_username = username; } -RootItem* GmailNetworkFactory::feedsCategories() { - Downloader downloader; - QEventLoop loop; - QString bearer = m_oauth2->bearer().toLocal8Bit(); +/* + RootItem* GmailNetworkFactory::feedsCategories() { + Downloader downloader; + QEventLoop loop; + QString bearer = m_oauth2->bearer().toLocal8Bit(); - if (bearer.isEmpty()) { + if (bearer.isEmpty()) { return nullptr; - } + } - downloader.appendRawHeader(QString(HTTP_HEADERS_AUTHORIZATION).toLocal8Bit(), bearer.toLocal8Bit()); + downloader.appendRawHeader(QString(HTTP_HEADERS_AUTHORIZATION).toLocal8Bit(), bearer.toLocal8Bit()); - // We need to quit event loop when the download finishes. - connect(&downloader, &Downloader::completed, &loop, &QEventLoop::quit); + // We need to quit event loop when the download finishes. + connect(&downloader, &Downloader::completed, &loop, &QEventLoop::quit); - // TODO: dodělat - downloader.manipulateData(GMAIL_API_LABELS_LIST, QNetworkAccessManager::Operation::GetOperation); - loop.exec(); + // TODO: dodělat + downloader.manipulateData(GMAIL_API_LABELS_LIST, QNetworkAccessManager::Operation::GetOperation); + loop.exec(); - if (downloader.lastOutputError() != QNetworkReply::NetworkError::NoError) { + if (downloader.lastOutputError() != QNetworkReply::NetworkError::NoError) { return nullptr; - } + } - QString category_data = downloader.lastOutputData(); + QString category_data = downloader.lastOutputData(); - return decodeFeedCategoriesData(category_data); -} + return decodeFeedCategoriesData(category_data); + }*/ QList GmailNetworkFactory::messages(const QString& stream_id, Feed::Status& error) { Downloader downloader; @@ -356,14 +357,15 @@ QList GmailNetworkFactory::decodeMessages(const QString& messages_json_ return messages; } -RootItem* GmailNetworkFactory::decodeFeedCategoriesData(const QString& categories) { - RootItem* parent = new RootItem(); - QJsonArray json = QJsonDocument::fromJson(categories.toUtf8()).object()["labels"].toArray(); +/* + RootItem* GmailNetworkFactory::decodeFeedCategoriesData(const QString& categories) { + RootItem* parent = new RootItem(); + QJsonArray json = QJsonDocument::fromJson(categories.toUtf8()).object()["labels"].toArray(); - QMap cats; - cats.insert(QString(), parent); + QMap cats; + cats.insert(QString(), parent); - foreach (const QJsonValue& obj, json) { + foreach (const QJsonValue& obj, json) { auto label = obj.toObject(); QString label_id = label["id"].toString(); QString label_name = label["name"].toString(); @@ -381,7 +383,7 @@ RootItem* GmailNetworkFactory::decodeFeedCategoriesData(const QString& categorie parent->appendChild(feed); } -/* + if (label_id.contains(QSL("/label/"))) { // We have label (not "state"). Category* category = new Category(); @@ -394,10 +396,9 @@ RootItem* GmailNetworkFactory::decodeFeedCategoriesData(const QString& categorie // All categories in ownCloud are top-level. parent->appendChild(category); - }*/ - } + } + } -/* json = QJsonDocument::fromJson(feeds.toUtf8()).object()["subscriptions"].toArray(); foreach (const QJsonValue& obj, json) { @@ -428,7 +429,8 @@ RootItem* GmailNetworkFactory::decodeFeedCategoriesData(const QString& categorie if (cats.contains(parent_label)) { cats[parent_label]->appendChild(feed); } - }*/ + } - return parent; -} + return parent; + } + */ diff --git a/src/services/gmail/network/gmailnetworkfactory.h b/src/services/gmail/network/gmailnetworkfactory.h index b04b8a0f2..fa70a2d22 100755 --- a/src/services/gmail/network/gmailnetworkfactory.h +++ b/src/services/gmail/network/gmailnetworkfactory.h @@ -36,7 +36,7 @@ class GmailNetworkFactory : public QObject { // Returns tree of feeds/categories. // Top-level root of the tree is not needed here. // Returned items do not have primary IDs assigned. - RootItem* feedsCategories(); + //RootItem* feedsCategories(); QList messages(const QString& stream_id, Feed::Status& error); void markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids, bool async = true); @@ -48,7 +48,8 @@ class GmailNetworkFactory : public QObject { private: QList decodeMessages(const QString& messages_json_data, const QString& stream_id); - RootItem* decodeFeedCategoriesData(const QString& categories); + + //RootItem* decodeFeedCategoriesData(const QString& categories); void initializeOauth();