From e289da58fcfbd360e30300962a81302e84f8c1d1 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Fri, 22 Sep 2017 15:17:58 +0200 Subject: [PATCH] Converted custom IDS of feeds/categories to QString from int - probably broken. --- src/definitions/definitions.h | 1 + src/miscellaneous/databasequeries.cpp | 30 +++--- src/miscellaneous/databasequeries.h | 16 ++-- src/services/abstract/category.cpp | 16 ++-- src/services/abstract/feed.cpp | 2 +- src/services/abstract/rootitem.cpp | 14 +-- src/services/abstract/rootitem.h | 8 +- src/services/abstract/serviceroot.cpp | 16 ++-- src/services/abstract/serviceroot.h | 4 +- src/services/inoreader/definitions.h | 3 + .../inoreader/inoreaderserviceroot.cpp | 29 +++++- src/services/inoreader/inoreaderserviceroot.h | 6 ++ .../network/inoreadernetworkfactory.cpp | 95 ++++++++++++++++++- .../network/inoreadernetworkfactory.h | 12 ++- .../owncloud/gui/formowncloudfeeddetails.cpp | 2 +- .../network/owncloudnetworkfactory.cpp | 21 ++-- .../owncloud/network/owncloudnetworkfactory.h | 4 +- src/services/owncloud/owncloudfeed.cpp | 6 +- src/services/owncloud/owncloudserviceroot.cpp | 8 +- src/services/standard/standardcategory.cpp | 2 +- src/services/standard/standardfeed.cpp | 6 +- .../tt-rss/gui/formttrssfeeddetails.cpp | 2 +- .../tt-rss/network/ttrssnetworkfactory.cpp | 4 +- src/services/tt-rss/ttrssfeed.cpp | 8 +- 24 files changed, 221 insertions(+), 94 deletions(-) diff --git a/src/definitions/definitions.h b/src/definitions/definitions.h index 25da22181..a83287e90 100755 --- a/src/definitions/definitions.h +++ b/src/definitions/definitions.h @@ -55,6 +55,7 @@ #define RESELECT_MESSAGE_THRESSHOLD 500 #define ICON_SIZE_SETTINGS 16 #define NO_PARENT_CATEGORY -1 +#define NO_PARENT_CATEGORY_STR "" #define ID_RECYCLE_BIN -2 #define TRAY_ICON_BUBBLE_TIMEOUT 20000 #define CLOSE_LOCK_TIMEOUT 500 diff --git a/src/miscellaneous/databasequeries.cpp b/src/miscellaneous/databasequeries.cpp index 2e8971fba..4e0d30b27 100755 --- a/src/miscellaneous/databasequeries.cpp +++ b/src/miscellaneous/databasequeries.cpp @@ -177,9 +177,9 @@ bool DatabaseQueries::purgeRecycleBin(QSqlDatabase db) { return q.exec(); } -QMap> DatabaseQueries::getMessageCountsForCategory(QSqlDatabase db, int custom_id, int account_id, - bool including_total_counts, bool* ok) { - QMap> counts; +QMap> DatabaseQueries::getMessageCountsForCategory(QSqlDatabase db, const QString& custom_id, int account_id, + bool including_total_counts, bool* ok) { + QMap> counts; QSqlQuery q(db); q.setForwardOnly(true); @@ -200,16 +200,16 @@ QMap> DatabaseQueries::getMessageCountsForCategory(QSqlData if (q.exec()) { while (q.next()) { - int feed_id = q.value(0).toInt(); + QString feed_custom_id = q.value(0).toString(); int unread_count = q.value(1).toInt(); if (including_total_counts) { int total_count = q.value(2).toInt(); - counts.insert(feed_id, QPair(unread_count, total_count)); + counts.insert(feed_custom_id, QPair(unread_count, total_count)); } else { - counts.insert(feed_id, QPair(unread_count, 0)); + counts.insert(feed_custom_id, QPair(unread_count, 0)); } } @@ -226,9 +226,9 @@ QMap> DatabaseQueries::getMessageCountsForCategory(QSqlData return counts; } -QMap> DatabaseQueries::getMessageCountsForAccount(QSqlDatabase db, int account_id, - bool including_total_counts, bool* ok) { - QMap> counts; +QMap> DatabaseQueries::getMessageCountsForAccount(QSqlDatabase db, int account_id, + bool including_total_counts, bool* ok) { + QMap> counts; QSqlQuery q(db); q.setForwardOnly(true); @@ -248,7 +248,7 @@ QMap> DatabaseQueries::getMessageCountsForAccount(QSqlDatab if (q.exec()) { while (q.next()) { - int feed_id = q.value(0).toInt(); + QString feed_id = q.value(0).toString(); int unread_count = q.value(1).toInt(); if (including_total_counts) { @@ -274,7 +274,7 @@ QMap> DatabaseQueries::getMessageCountsForAccount(QSqlDatab return counts; } -int DatabaseQueries::getMessageCountsForFeed(QSqlDatabase db, int feed_custom_id, +int DatabaseQueries::getMessageCountsForFeed(QSqlDatabase db, const QString& feed_custom_id, int account_id, bool including_total_counts, bool* ok) { QSqlQuery q(db); @@ -340,7 +340,7 @@ int DatabaseQueries::getMessageCountsForBin(QSqlDatabase db, int account_id, boo } } -QList DatabaseQueries::getUndeletedMessagesForFeed(QSqlDatabase db, int feed_custom_id, int account_id, bool* ok) { +QList DatabaseQueries::getUndeletedMessagesForFeed(QSqlDatabase db, const QString& feed_custom_id, int account_id, bool* ok) { QList messages; QSqlQuery q(db); @@ -442,7 +442,7 @@ QList DatabaseQueries::getUndeletedMessagesForAccount(QSqlDatabase db, int DatabaseQueries::updateMessages(QSqlDatabase db, const QList& messages, - int feed_custom_id, + const QString& feed_custom_id, int account_id, const QString& url, bool* any_message_changed, @@ -779,7 +779,7 @@ bool DatabaseQueries::storeAccountTree(QSqlDatabase db, RootItem* tree_root, int query_category.bindValue(QSL(":parent_id"), child->parent()->id()); query_category.bindValue(QSL(":title"), child->title()); query_category.bindValue(QSL(":account_id"), account_id); - query_category.bindValue(QSL(":custom_id"), QString::number(child->toCategory()->customId())); + query_category.bindValue(QSL(":custom_id"), child->toCategory()->customId()); if (query_category.exec()) { child->setId(query_category.lastInsertId().toInt()); @@ -856,7 +856,7 @@ QStringList DatabaseQueries::customIdsOfMessagesFromBin(QSqlDatabase db, int acc return ids; } -QStringList DatabaseQueries::customIdsOfMessagesFromFeed(QSqlDatabase db, int feed_custom_id, int account_id, bool* ok) { +QStringList DatabaseQueries::customIdsOfMessagesFromFeed(QSqlDatabase db, const QString& feed_custom_id, int account_id, bool* ok) { QSqlQuery q(db); QStringList ids; diff --git a/src/miscellaneous/databasequeries.h b/src/miscellaneous/databasequeries.h index 8693a6ed3..b05eaa11b 100755 --- a/src/miscellaneous/databasequeries.h +++ b/src/miscellaneous/databasequeries.h @@ -49,26 +49,26 @@ class DatabaseQueries { static bool purgeLeftoverMessages(QSqlDatabase db, int account_id); // Obtain counts of unread/all messages. - static QMap> getMessageCountsForCategory(QSqlDatabase db, int custom_id, int account_id, - bool including_total_counts, bool* ok = nullptr); - static QMap> getMessageCountsForAccount(QSqlDatabase db, int account_id, - bool including_total_counts, bool* ok = nullptr); - static int getMessageCountsForFeed(QSqlDatabase db, int feed_custom_id, int account_id, + static QMap> getMessageCountsForCategory(QSqlDatabase db, const QString& custom_id, int account_id, + bool including_total_counts, bool* ok = nullptr); + static QMap> getMessageCountsForAccount(QSqlDatabase db, int account_id, + bool including_total_counts, bool* ok = nullptr); + static int getMessageCountsForFeed(QSqlDatabase db, const QString& feed_custom_id, int account_id, bool including_total_counts, bool* ok = nullptr); static int getMessageCountsForBin(QSqlDatabase db, int account_id, bool including_total_counts, bool* ok = nullptr); // Get messages (for newspaper view for example). - static QList getUndeletedMessagesForFeed(QSqlDatabase db, int feed_custom_id, int account_id, bool* ok = nullptr); + static QList getUndeletedMessagesForFeed(QSqlDatabase db, const QString& feed_custom_id, int account_id, bool* ok = nullptr); static QList getUndeletedMessagesForBin(QSqlDatabase db, int account_id, bool* ok = nullptr); static QList getUndeletedMessagesForAccount(QSqlDatabase db, int account_id, bool* ok = nullptr); // Custom ID accumulators. static QStringList customIdsOfMessagesFromAccount(QSqlDatabase db, int account_id, bool* ok = nullptr); static QStringList customIdsOfMessagesFromBin(QSqlDatabase db, int account_id, bool* ok = nullptr); - static QStringList customIdsOfMessagesFromFeed(QSqlDatabase db, int feed_custom_id, int account_id, bool* ok = nullptr); + static QStringList customIdsOfMessagesFromFeed(QSqlDatabase db, const QString& feed_custom_id, int account_id, bool* ok = nullptr); // Common accounts methods. - static int updateMessages(QSqlDatabase db, const QList& messages, int feed_custom_id, + static int updateMessages(QSqlDatabase db, const QList& messages, const QString& feed_custom_id, int account_id, const QString& url, bool* any_message_changed, bool* ok = nullptr); static bool deleteAccount(QSqlDatabase db, int account_id); static bool deleteAccountData(QSqlDatabase db, int account_id, bool delete_messages_too); diff --git a/src/services/abstract/category.cpp b/src/services/abstract/category.cpp index 6811ce3aa..1b3d8104d 100755 --- a/src/services/abstract/category.cpp +++ b/src/services/abstract/category.cpp @@ -36,10 +36,10 @@ Category::Category(RootItem* parent) : RootItem(parent) { Category::Category(const QSqlRecord& record) : Category(nullptr) { setId(record.value(CAT_DB_ID_INDEX).toInt()); - setCustomId(record.value(CAT_DB_CUSTOM_ID_INDEX).toInt()); + setCustomId(record.value(CAT_DB_CUSTOM_ID_INDEX).toString()); - if (customId() <= 0) { - setCustomId(id()); + if (customId().isEmpty()) { + setCustomId(QString::number(id())); } setTitle(record.value(CAT_DB_TITLE_INDEX).toString()); @@ -71,11 +71,11 @@ void Category::updateCounts(bool including_total_count) { QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); bool ok; - QMap> counts = DatabaseQueries::getMessageCountsForCategory(database, - customId(), - getParentServiceRoot()->accountId(), - including_total_count, - &ok); + QMap> counts = DatabaseQueries::getMessageCountsForCategory(database, + customId(), + getParentServiceRoot()->accountId(), + including_total_count, + &ok); if (ok) { foreach (Feed* feed, feeds) { diff --git a/src/services/abstract/feed.cpp b/src/services/abstract/feed.cpp index e938168b3..68ca34c12 100755 --- a/src/services/abstract/feed.cpp +++ b/src/services/abstract/feed.cpp @@ -252,7 +252,7 @@ int Feed::updateMessages(const QList& messages, bool error_during_obtai bool ok = true; if (!messages.isEmpty()) { - int custom_id = customId(); + QString custom_id = customId(); int account_id = getParentServiceRoot()->accountId(); QSqlDatabase database = is_main_thread ? qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings) : diff --git a/src/services/abstract/rootitem.cpp b/src/services/abstract/rootitem.cpp index f83f8255f..0f7ce0753 100755 --- a/src/services/abstract/rootitem.cpp +++ b/src/services/abstract/rootitem.cpp @@ -30,7 +30,7 @@ RootItem::RootItem(RootItem* parent_item) : QObject(nullptr), m_kind(RootItemKind::Root), m_id(NO_PARENT_CATEGORY), - m_customId(NO_PARENT_CATEGORY), + m_customId(QSL(NO_PARENT_CATEGORY_STR)), m_title(QString()), m_description(QString()), m_icon(QIcon()), @@ -317,8 +317,8 @@ QHash RootItem::getHashedSubTreeCategories() const { while (!traversable_items.isEmpty()) { RootItem* active_item = traversable_items.takeFirst(); - if (active_item->kind() == RootItemKind::Category && !children.contains(active_item->customId())) { - children.insert(active_item->customId(), active_item->toCategory()); + if (active_item->kind() == RootItemKind::Category && !children.contains(active_item->id())) { + children.insert(active_item->id(), active_item->toCategory()); } traversable_items.append(active_item->childItems()); @@ -327,8 +327,8 @@ QHash RootItem::getHashedSubTreeCategories() const { return children; } -QHash RootItem::getHashedSubTreeFeeds() const { - QHash children; +QHash RootItem::getHashedSubTreeFeeds() const { + QHash children; QList traversable_items; traversable_items.append(const_cast(this)); @@ -448,11 +448,11 @@ bool RootItem::removeChild(RootItem* child) { return m_childItems.removeOne(child); } -int RootItem::customId() const { +QString RootItem::customId() const { return m_customId; } -void RootItem::setCustomId(int custom_id) { +void RootItem::setCustomId(const QString& custom_id) { m_customId = custom_id; } diff --git a/src/services/abstract/rootitem.h b/src/services/abstract/rootitem.h index 33c6a0573..d4964c5f6 100755 --- a/src/services/abstract/rootitem.h +++ b/src/services/abstract/rootitem.h @@ -175,7 +175,7 @@ class RootItem : public QObject { QList getSubTree(RootItemKind::Kind kind_of_item) const; QList getSubTreeCategories() const; QHash getHashedSubTreeCategories() const; - QHash getHashedSubTreeFeeds() const; + QHash getHashedSubTreeFeeds() const; QList getSubTreeFeeds() const; // Returns the service root node which is direct or indirect parent of current item. @@ -210,8 +210,8 @@ class RootItem : public QObject { void setBoldFont(const QFont& bold_font); // NOTE: For standard feed/category, this WILL equal to id(). - int customId() const; - void setCustomId(int custom_id); + QString customId() const; + void setCustomId(const QString& custom_id); // Converters Category* toCategory() const; @@ -223,7 +223,7 @@ class RootItem : public QObject { RootItemKind::Kind m_kind; int m_id; - int m_customId; + QString m_customId; QString m_title; QString m_description; QIcon m_icon; diff --git a/src/services/abstract/serviceroot.cpp b/src/services/abstract/serviceroot.cpp index 5165b2073..e668bc798 100755 --- a/src/services/abstract/serviceroot.cpp +++ b/src/services/abstract/serviceroot.cpp @@ -104,7 +104,7 @@ void ServiceRoot::updateCounts(bool including_total_count) { QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); bool ok; - QMap> counts = DatabaseQueries::getMessageCountsForAccount(database, accountId(), including_total_count, &ok); + QMap> counts = DatabaseQueries::getMessageCountsForAccount(database, accountId(), including_total_count, &ok); if (ok) { foreach (Feed* feed, feeds) { @@ -229,8 +229,8 @@ void ServiceRoot::requestItemRemoval(RootItem* item) { emit itemRemovalRequested(item); } -QMap ServiceRoot::storeCustomFeedsData() { - QMap custom_data; +QMap ServiceRoot::storeCustomFeedsData() { + QMap custom_data; foreach (const Feed* feed, getSubTreeFeeds()) { QVariantMap feed_custom_data; @@ -243,12 +243,12 @@ QMap ServiceRoot::storeCustomFeedsData() { return custom_data; } -void ServiceRoot::restoreCustomFeedsData(const QMap& data, const QHash& feeds) { - QMapIterator i(data); +void ServiceRoot::restoreCustomFeedsData(const QMap& data, const QHash& feeds) { + QMapIterator i(data); while (i.hasNext()) { i.next(); - const int custom_id = i.key(); + const QString custom_id = i.key(); if (feeds.contains(custom_id)) { Feed* feed = feeds.value(custom_id); @@ -270,7 +270,7 @@ void ServiceRoot::syncIn() { if (new_tree != nullptr) { // Purge old data from SQL and clean all model items. requestItemExpandStateSave(this); - QMap feed_custom_data = storeCustomFeedsData(); + QMap feed_custom_data = storeCustomFeedsData(); removeOldFeedTree(false); cleanAllItems(); restoreCustomFeedsData(feed_custom_data, new_tree->getHashedSubTreeFeeds()); @@ -392,7 +392,7 @@ QStringList ServiceRoot::textualFeedIds(const QList& feeds) const { stringy_ids.reserve(feeds.size()); foreach (const Feed* feed, feeds) { - stringy_ids.append(QString("'%1'").arg(QString::number(feed->customId()))); + stringy_ids.append(QString("'%1'").arg(feed->customId())); } return stringy_ids; diff --git a/src/services/abstract/serviceroot.h b/src/services/abstract/serviceroot.h index 93f3283ef..89635a8de 100755 --- a/src/services/abstract/serviceroot.h +++ b/src/services/abstract/serviceroot.h @@ -203,8 +203,8 @@ class ServiceRoot : public RootItem { void itemRemovalRequested(RootItem* item); private: - virtual QMap storeCustomFeedsData(); - virtual void restoreCustomFeedsData(const QMap& data, const QHash& feeds); + virtual QMap storeCustomFeedsData(); + virtual void restoreCustomFeedsData(const QMap& data, const QHash& feeds); private: RecycleBin* m_recycleBin; diff --git a/src/services/inoreader/definitions.h b/src/services/inoreader/definitions.h index 5fbc92718..3b39761ff 100755 --- a/src/services/inoreader/definitions.h +++ b/src/services/inoreader/definitions.h @@ -30,4 +30,7 @@ #define INOREADER_DEFAULT_BATCH_SIZE -1 #define INOREADER_UNLIMITED_BATCH_SIZE -1 +#define INOREADER_API_LIST_LABELS "https://www.inoreader.com/reader/api/0/tag/list" +#define INOREADER_API_LIST_FEEDS "https://www.inoreader.com/reader/api/0/subscription/list" + #endif // INOREADER_DEFINITIONS_H diff --git a/src/services/inoreader/inoreaderserviceroot.cpp b/src/services/inoreader/inoreaderserviceroot.cpp index 8100ff688..3fc7922c6 100755 --- a/src/services/inoreader/inoreaderserviceroot.cpp +++ b/src/services/inoreader/inoreaderserviceroot.cpp @@ -21,13 +21,14 @@ #include "miscellaneous/application.h" #include "miscellaneous/databasequeries.h" +#include "miscellaneous/iconfactory.h" #include "services/inoreader/gui/formeditinoreaderaccount.h" #include "services/inoreader/inoreaderentrypoint.h" #include "services/inoreader/network/inoreadernetworkfactory.h" InoreaderServiceRoot::InoreaderServiceRoot(InoreaderNetworkFactory* network, RootItem* parent) : ServiceRoot(parent), - m_network(network) { - if (m_network == nullptr) { + m_serviceMenu(QList()), m_network(network) { + if (network == nullptr) { m_network = new InoreaderNetworkFactory(this); } else { @@ -89,14 +90,36 @@ bool InoreaderServiceRoot::supportsCategoryAdding() const { return false; } -void InoreaderServiceRoot::start(bool freshly_activated) {} +void InoreaderServiceRoot::start(bool freshly_activated) { + Q_UNUSED(freshly_activated) + + //loadFromDatabase(); + //loadCacheFromFile(accountId()); + + m_network->logInIfNeeded(); +} void InoreaderServiceRoot::stop() {} +QList InoreaderServiceRoot::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, &InoreaderServiceRoot::syncIn); + m_serviceMenu.append(act_sync_in); + } + + return m_serviceMenu; +} + QString InoreaderServiceRoot::code() const { return InoreaderEntryPoint().code(); } +RootItem* InoreaderServiceRoot::obtainNewTreeForSyncIn() const { + return m_network->feedsCategories(true); +} + void InoreaderServiceRoot::addNewFeed(const QString& url) {} void InoreaderServiceRoot::addNewCategory() {} diff --git a/src/services/inoreader/inoreaderserviceroot.h b/src/services/inoreader/inoreaderserviceroot.h index 986593966..270511f49 100755 --- a/src/services/inoreader/inoreaderserviceroot.h +++ b/src/services/inoreader/inoreaderserviceroot.h @@ -44,12 +44,18 @@ class InoreaderServiceRoot : public ServiceRoot { void stop(); QString code() const; + RootItem* obtainNewTreeForSyncIn() const; + public slots: void addNewFeed(const QString& url); void addNewCategory(); void updateTitle(); + protected: + QList serviceMenu(); + private: + QList m_serviceMenu; InoreaderNetworkFactory* m_network; }; diff --git a/src/services/inoreader/network/inoreadernetworkfactory.cpp b/src/services/inoreader/network/inoreadernetworkfactory.cpp index 50fad354d..dcbbd7967 100755 --- a/src/services/inoreader/network/inoreadernetworkfactory.cpp +++ b/src/services/inoreader/network/inoreadernetworkfactory.cpp @@ -24,13 +24,19 @@ #include "miscellaneous/application.h" #include "network-web/silentnetworkaccessmanager.h" #include "network-web/webfactory.h" +#include "services/abstract/category.h" #include "services/inoreader/definitions.h" +#include +#include +#include +#include #include #include InoreaderNetworkFactory::InoreaderNetworkFactory(QObject* parent) : QObject(parent), - m_batchSize(INOREADER_DEFAULT_BATCH_SIZE), m_oauth2(new QOAuth2AuthorizationCodeFlow(this)) { + m_username(QString()), m_refreshToken(QString()), m_batchSize(INOREADER_DEFAULT_BATCH_SIZE), + m_oauth2(new QOAuth2AuthorizationCodeFlow(this)) { initializeOauth(); } @@ -127,6 +133,93 @@ void InoreaderNetworkFactory::setRefreshToken(const QString& refreshToken) { m_refreshToken = refreshToken; } +RootItem* InoreaderNetworkFactory::feedsCategories(bool obtain_icons) { + RootItem* parent = new RootItem(); + + QMap cats; + cats.insert(NO_PARENT_CATEGORY_STR, parent); + + QNetworkReply* reply = m_oauth2->get(QUrl(INOREADER_API_LIST_LABELS)); + QEventLoop loop; + RootItem* result = nullptr; + + connect(reply, &QNetworkReply::finished, [&, this]() { + if (reply->error() == QNetworkReply::NoError) { + QByteArray repl_data = reply->readAll(); + QJsonArray json = QJsonDocument::fromJson(repl_data).object()["tags"].toArray(); + + foreach (const QJsonValue& obj, json) { + auto label = obj.toObject(); + QString label_id = label["id"].toString(); + + if (label_id.contains(QSL("/label/"))) { + // We have label (not "state"). + Category* category = new Category(); + + category->setTitle(label_id.mid(label_id.lastIndexOf(QL1C('/')) + 1)); + category->setCustomId(label_id); + cats.insert(category->customId(), category); + + // All categories in ownCloud are top-level. + parent->appendChild(category); + } + } + } + + loop.exit(); + }); + + loop.exec(); + + return result; + +/* + // Process categories first, then process feeds. + foreach (const QJsonValue& cat, QJsonDocument::fromJson(m_contentCategories.toUtf8()).object()["folders"].toArray()) { + QJsonObject item = cat.toObject(); + Category* category = new Category(); + + category->setTitle(item["name"].toString()); + category->setCustomId(item["id"].toInt()); + cats.insert(category->customId(), category); + + // All categories in ownCloud are top-level. + parent->appendChild(category); + }*/ + +/* + // We have categories added, now add all feeds. + foreach (const QJsonValue& fed, QJsonDocument::fromJson(m_contentFeeds.toUtf8()).object()["feeds"].toArray()) { + QJsonObject item = fed.toObject(); + OwnCloudFeed* feed = new OwnCloudFeed(); + + if (obtain_icons) { + QString icon_path = item["faviconLink"].toString(); + + if (!icon_path.isEmpty()) { + QByteArray icon_data; + + if (NetworkFactory::performNetworkOperation(icon_path, DOWNLOAD_TIMEOUT, + QByteArray(), QString(), icon_data, + QNetworkAccessManager::GetOperation).first == + QNetworkReply::NoError) { + // Icon downloaded, set it up. + QPixmap icon_pixmap; + + icon_pixmap.loadFromData(icon_data); + feed->setIcon(QIcon(icon_pixmap)); + } + } + } + + feed->setUrl(item["link"].toString()); + feed->setTitle(item["title"].toString()); + feed->setCustomId(item["id"].toInt()); + qDebug("Custom ID of next fetched Nextcloud feed is '%d'.", item["id"].toInt()); + cats.value(item["folderId"].toInt())->appendChild(feed); + }*/ +} + void InoreaderNetworkFactory::setAccessToken(const QString& accessToken) { m_oauth2->setToken(accessToken); } diff --git a/src/services/inoreader/network/inoreadernetworkfactory.h b/src/services/inoreader/network/inoreadernetworkfactory.h index c3ffbd2e1..c3f583354 100755 --- a/src/services/inoreader/network/inoreadernetworkfactory.h +++ b/src/services/inoreader/network/inoreadernetworkfactory.h @@ -21,7 +21,10 @@ #include -#include +#include + +class RootItem; +class QOAuth2AuthorizationCodeFlow; class InoreaderNetworkFactory : public QObject { Q_OBJECT @@ -43,6 +46,11 @@ class InoreaderNetworkFactory : public QObject { void setAccessToken(const QString& accessToken); void setRefreshToken(const QString& refreshToken); + // 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(bool obtain_icons); + public slots: void logIn(); void logInIfNeeded(); @@ -59,9 +67,9 @@ class InoreaderNetworkFactory : public QObject { void initializeOauth(); private: - int m_batchSize; QString m_username; QString m_refreshToken; + int m_batchSize; QOAuth2AuthorizationCodeFlow* m_oauth2; }; diff --git a/src/services/owncloud/gui/formowncloudfeeddetails.cpp b/src/services/owncloud/gui/formowncloudfeeddetails.cpp index bfe25f6fa..92ba08b33 100755 --- a/src/services/owncloud/gui/formowncloudfeeddetails.cpp +++ b/src/services/owncloud/gui/formowncloudfeeddetails.cpp @@ -68,7 +68,7 @@ void FormOwnCloudFeedDetails::apply() { else { const RootItem* parent = static_cast(m_ui->m_cmbParentCategory->itemData( m_ui->m_cmbParentCategory->currentIndex()).value()); - const int category_id = parent->kind() == RootItemKind::ServiceRoot ? 0 : parent->customId(); + const int category_id = parent->kind() == RootItemKind::ServiceRoot ? 0 : parent->customId().toInt(); const bool response = qobject_cast(m_serviceRoot)->network()->createFeed(m_ui->m_txtUrl->lineEdit()->text(), category_id); diff --git a/src/services/owncloud/network/owncloudnetworkfactory.cpp b/src/services/owncloud/network/owncloudnetworkfactory.cpp index eb71f6e98..40ff0f971 100755 --- a/src/services/owncloud/network/owncloudnetworkfactory.cpp +++ b/src/services/owncloud/network/owncloudnetworkfactory.cpp @@ -173,8 +173,8 @@ OwnCloudGetFeedsCategoriesResponse OwnCloudNetworkFactory::feedsCategories() { return OwnCloudGetFeedsCategoriesResponse(content_categories, content_feeds); } -bool OwnCloudNetworkFactory::deleteFeed(int feed_id) { - QString final_url = m_urlDeleteFeed.arg(QString::number(feed_id)); +bool OwnCloudNetworkFactory::deleteFeed(const QString& feed_id) { + QString final_url = m_urlDeleteFeed.arg(feed_id); QByteArray raw_output; NetworkResult network_reply = NetworkFactory::performNetworkOperation(final_url, qApp->settings()->value(GROUP(Feeds), @@ -221,8 +221,8 @@ bool OwnCloudNetworkFactory::createFeed(const QString& url, int parent_id) { } } -bool OwnCloudNetworkFactory::renameFeed(const QString& new_name, int feed_id) { - QString final_url = m_urlRenameFeed.arg(QString::number(feed_id)); +bool OwnCloudNetworkFactory::renameFeed(const QString& new_name, const QString& custom_feed_id) { + QString final_url = m_urlRenameFeed.arg(custom_feed_id); QByteArray result_raw; QJsonObject json; @@ -230,8 +230,7 @@ bool OwnCloudNetworkFactory::renameFeed(const QString& new_name, int feed_id) { NetworkResult network_reply = NetworkFactory::performNetworkOperation( final_url, - qApp->settings()->value(GROUP(Feeds), - SETTING(Feeds::UpdateTimeout)).toInt(), + qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt(), QJsonDocument(json).toJson(QJsonDocument::Compact), QSL("application/json"), result_raw, QNetworkAccessManager::PutOperation, @@ -480,8 +479,8 @@ OwnCloudGetFeedsCategoriesResponse::~OwnCloudGetFeedsCategoriesResponse() {} RootItem* OwnCloudGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons) const { RootItem* parent = new RootItem(); - QMapcats; - cats.insert(0, parent); + QMapcats; + cats.insert(NO_PARENT_CATEGORY_STR, parent); // Process categories first, then process feeds. foreach (const QJsonValue& cat, QJsonDocument::fromJson(m_contentCategories.toUtf8()).object()["folders"].toArray()) { @@ -489,7 +488,7 @@ RootItem* OwnCloudGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons) Category* category = new Category(); category->setTitle(item["name"].toString()); - category->setCustomId(item["id"].toInt()); + category->setCustomId(item["id"].toString()); cats.insert(category->customId(), category); // All categories in ownCloud are top-level. @@ -522,9 +521,9 @@ RootItem* OwnCloudGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons) feed->setUrl(item["link"].toString()); feed->setTitle(item["title"].toString()); - feed->setCustomId(item["id"].toInt()); + feed->setCustomId(item["id"].toString()); qDebug("Custom ID of next fetched Nextcloud feed is '%d'.", item["id"].toInt()); - cats.value(item["folderId"].toInt())->appendChild(feed); + cats.value(item["folderId"].toString())->appendChild(feed); } return parent; diff --git a/src/services/owncloud/network/owncloudnetworkfactory.h b/src/services/owncloud/network/owncloudnetworkfactory.h index aa4a768d5..9dd895244 100755 --- a/src/services/owncloud/network/owncloudnetworkfactory.h +++ b/src/services/owncloud/network/owncloudnetworkfactory.h @@ -120,9 +120,9 @@ class OwnCloudNetworkFactory { OwnCloudGetFeedsCategoriesResponse feedsCategories(); // Feed operations. - bool deleteFeed(int feed_id); + bool deleteFeed(const QString& feed_id); bool createFeed(const QString& url, int parent_id); - bool renameFeed(const QString& new_name, int feed_id); + bool renameFeed(const QString& new_name, const QString& custom_feed_id); // Get messages for given feed. OwnCloudGetMessagesResponse getMessages(int feed_id); diff --git a/src/services/owncloud/owncloudfeed.cpp b/src/services/owncloud/owncloudfeed.cpp index 72bbf2445..59529d9ca 100755 --- a/src/services/owncloud/owncloudfeed.cpp +++ b/src/services/owncloud/owncloudfeed.cpp @@ -34,7 +34,7 @@ OwnCloudFeed::OwnCloudFeed(const QSqlRecord& record) : Feed(nullptr) { setIcon(qApp->icons()->fromByteArray(record.value(FDS_DB_ICON_INDEX).toByteArray())); setAutoUpdateType(static_cast(record.value(FDS_DB_UPDATE_TYPE_INDEX).toInt())); setAutoUpdateInitialInterval(record.value(FDS_DB_UPDATE_INTERVAL_INDEX).toInt()); - setCustomId(record.value(FDS_DB_CUSTOM_ID_INDEX).toInt()); + setCustomId(record.value(FDS_DB_CUSTOM_ID_INDEX).toString()); qDebug("Custom ID of Nextcloud feed when loading from DB is '%s'.", qPrintable(record.value(FDS_DB_CUSTOM_ID_INDEX).toString())); } @@ -83,7 +83,7 @@ bool OwnCloudFeed::editItself(OwnCloudFeed* new_feed_data) { bool OwnCloudFeed::removeItself() { QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); - return DatabaseQueries::deleteFeed(database, customId(), serviceRoot()->accountId()); + return DatabaseQueries::deleteFeed(database, customId().toInt(), serviceRoot()->accountId()); } OwnCloudServiceRoot* OwnCloudFeed::serviceRoot() const { @@ -91,7 +91,7 @@ OwnCloudServiceRoot* OwnCloudFeed::serviceRoot() const { } QList OwnCloudFeed::obtainNewMessages(bool* error_during_obtaining) { - OwnCloudGetMessagesResponse messages = serviceRoot()->network()->getMessages(customId()); + OwnCloudGetMessagesResponse messages = serviceRoot()->network()->getMessages(customId().toInt()); if (serviceRoot()->network()->lastError() != QNetworkReply::NoError) { setStatus(Feed::NetworkError); diff --git a/src/services/owncloud/owncloudserviceroot.cpp b/src/services/owncloud/owncloudserviceroot.cpp index 9a61a9080..9e205a6da 100755 --- a/src/services/owncloud/owncloudserviceroot.cpp +++ b/src/services/owncloud/owncloudserviceroot.cpp @@ -89,7 +89,7 @@ void OwnCloudServiceRoot::start(bool freshly_activated) { loadFromDatabase(); loadCacheFromFile(accountId()); - if (qApp->isFirstRun(QSL("3.1.1")) || (childCount() == 1 && child(0)->kind() == RootItemKind::Bin)) { + if (childCount() <= 1) { syncIn(); } } @@ -180,12 +180,6 @@ bool OwnCloudServiceRoot::onBeforeSwitchMessageImportance(RootItem* selected_ite } void OwnCloudServiceRoot::updateTitle() { - QString host = QUrl(m_network->url()).host(); - - if (host.isEmpty()) { - host = m_network->url(); - } - setTitle(m_network->authUsername() + QSL(" (Nextcloud News)")); } diff --git a/src/services/standard/standardcategory.cpp b/src/services/standard/standardcategory.cpp index b8274654f..25bfb43d0 100755 --- a/src/services/standard/standardcategory.cpp +++ b/src/services/standard/standardcategory.cpp @@ -148,7 +148,7 @@ bool StandardCategory::addItself(RootItem* parent) { } else { setId(new_id); - setCustomId(new_id); + setCustomId(QString::number(new_id)); return true; } } diff --git a/src/services/standard/standardfeed.cpp b/src/services/standard/standardfeed.cpp index 935690d24..984736c0f 100755 --- a/src/services/standard/standardfeed.cpp +++ b/src/services/standard/standardfeed.cpp @@ -323,7 +323,7 @@ bool StandardFeed::performDragDropChange(RootItem* target_item) { bool StandardFeed::removeItself() { QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); - return DatabaseQueries::deleteFeed(database, customId(), getParentServiceRoot()->accountId()); + return DatabaseQueries::deleteFeed(database, customId().toInt(), getParentServiceRoot()->accountId()); } bool StandardFeed::addItself(RootItem* parent) { @@ -341,7 +341,7 @@ bool StandardFeed::addItself(RootItem* parent) { else { // New feed was added, fetch is primary id from the database. setId(new_id); - setCustomId(new_id); + setCustomId(QString::number(new_id)); return true; } } @@ -441,7 +441,7 @@ QNetworkReply::NetworkError StandardFeed::networkError() const { StandardFeed::StandardFeed(const QSqlRecord& record) : Feed(nullptr) { setTitle(QString::fromUtf8(record.value(FDS_DB_TITLE_INDEX).toByteArray())); setId(record.value(FDS_DB_ID_INDEX).toInt()); - setCustomId(id()); + setCustomId(QString::number(id())); setDescription(QString::fromUtf8(record.value(FDS_DB_DESCRIPTION_INDEX).toByteArray())); setCreationDate(TextFactory::parseDateTime(record.value(FDS_DB_DCREATED_INDEX).value()).toLocalTime()); setIcon(qApp->icons()->fromByteArray(record.value(FDS_DB_ICON_INDEX).toByteArray())); diff --git a/src/services/tt-rss/gui/formttrssfeeddetails.cpp b/src/services/tt-rss/gui/formttrssfeeddetails.cpp index 2f1ea5b47..e9b34310b 100755 --- a/src/services/tt-rss/gui/formttrssfeeddetails.cpp +++ b/src/services/tt-rss/gui/formttrssfeeddetails.cpp @@ -55,7 +55,7 @@ void FormTtRssFeedDetails::apply() { TtRssServiceRoot* root = qobject_cast(parent->getParentServiceRoot()); const int category_id = parent->kind() == RootItemKind::ServiceRoot ? 0 : - parent->customId(); + parent->customId().toInt(); const TtRssSubscribeToFeedResponse response = root->network()->subscribeToFeed(m_ui->m_txtUrl->lineEdit()->text(), category_id, m_ui->m_gbAuthentication->isChecked(), diff --git a/src/services/tt-rss/network/ttrssnetworkfactory.cpp b/src/services/tt-rss/network/ttrssnetworkfactory.cpp index a9117e535..51c1f0cfa 100755 --- a/src/services/tt-rss/network/ttrssnetworkfactory.cpp +++ b/src/services/tt-rss/network/ttrssnetworkfactory.cpp @@ -505,7 +505,7 @@ RootItem* TtRssGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons, QS Category* category = new Category(); category->setTitle(item["name"].toString()); - category->setCustomId(item_id); + category->setCustomId(QString::number(item_id)); act_parent->appendChild(category); if (item.contains("items")) { @@ -540,7 +540,7 @@ RootItem* TtRssGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons, QS } feed->setTitle(item["name"].toString()); - feed->setCustomId(item_id); + feed->setCustomId(QString::number(item_id)); act_parent->appendChild(feed); } } diff --git a/src/services/tt-rss/ttrssfeed.cpp b/src/services/tt-rss/ttrssfeed.cpp index 61a7f4726..a6a62d449 100755 --- a/src/services/tt-rss/ttrssfeed.cpp +++ b/src/services/tt-rss/ttrssfeed.cpp @@ -39,7 +39,7 @@ TtRssFeed::TtRssFeed(const QSqlRecord& record) : Feed(nullptr) { setIcon(qApp->icons()->fromByteArray(record.value(FDS_DB_ICON_INDEX).toByteArray())); setAutoUpdateType(static_cast(record.value(FDS_DB_UPDATE_TYPE_INDEX).toInt())); setAutoUpdateInitialInterval(record.value(FDS_DB_UPDATE_INTERVAL_INDEX).toInt()); - setCustomId(record.value(FDS_DB_CUSTOM_ID_INDEX).toInt()); + setCustomId(record.value(FDS_DB_CUSTOM_ID_INDEX).toString()); qDebug("Custom ID of TT-RSS feed when loading from DB is '%s'.", qPrintable(record.value(FDS_DB_CUSTOM_ID_INDEX).toString())); } @@ -65,7 +65,7 @@ bool TtRssFeed::canBeDeleted() const { } bool TtRssFeed::deleteViaGui() { - TtRssUnsubscribeFeedResponse response = serviceRoot()->network()->unsubscribeFeed(customId()); + TtRssUnsubscribeFeedResponse response = serviceRoot()->network()->unsubscribeFeed(customId().toInt()); if (response.code() == UFF_OK && removeItself()) { serviceRoot()->requestItemRemoval(this); @@ -98,7 +98,7 @@ QList TtRssFeed::obtainNewMessages(bool* error_during_obtaining) { int skip = 0; do { - TtRssGetHeadlinesResponse headlines = serviceRoot()->network()->getHeadlines(customId(), limit, skip, + TtRssGetHeadlinesResponse headlines = serviceRoot()->network()->getHeadlines(customId().toInt(), limit, skip, true, true, false); if (serviceRoot()->network()->lastError() != QNetworkReply::NoError) { @@ -123,5 +123,5 @@ QList TtRssFeed::obtainNewMessages(bool* error_during_obtaining) { bool TtRssFeed::removeItself() { QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); - return DatabaseQueries::deleteFeed(database, customId(), serviceRoot()->accountId()); + return DatabaseQueries::deleteFeed(database, customId().toInt(), serviceRoot()->accountId()); }