From 1538c1261ffd075251fdcd55c3bc653aad7d6f80 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Fri, 19 Mar 2021 14:02:42 +0100 Subject: [PATCH] refactoring with clazy --- .../desktop/com.github.rssguard.appdata.xml | 2 +- src/librssguard/gui/settings/settingsgui.cpp | 10 ++++-- .../gui/settings/settingslocalization.cpp | 4 ++- src/librssguard/gui/webviewer.cpp | 3 +- src/librssguard/miscellaneous/feedreader.cpp | 4 +-- src/librssguard/miscellaneous/iconfactory.cpp | 22 ++++++------ .../miscellaneous/localization.cpp | 3 +- src/librssguard/miscellaneous/textfactory.cpp | 4 +-- src/librssguard/miscellaneous/textfactory.h | 2 +- .../adblock/adblockaddsubscriptiondialog.cpp | 14 +++----- .../network-web/adblock/adblockdialog.cpp | 4 ++- .../network-web/adblock/adblockmanager.cpp | 10 +++--- .../network-web/adblock/adblockmatcher.cpp | 7 ++-- .../adblock/adblocksubscription.cpp | 2 +- src/librssguard/network-web/downloader.cpp | 11 +++--- .../network-web/networkurlinterceptor.cpp | 2 +- src/librssguard/network-web/webfactory.cpp | 2 +- src/librssguard/network-web/webfactory.h | 1 - .../services/abstract/accountcheckmodel.cpp | 25 ++++++++------ .../services/abstract/category.cpp | 5 +-- src/librssguard/services/abstract/feed.cpp | 2 +- .../services/abstract/rootitem.cpp | 8 ++--- .../services/abstract/serviceroot.cpp | 34 +++++++++++++------ .../services/abstract/serviceroot.h | 7 ++-- .../services/feedly/feedlynetwork.cpp | 22 ++++++++---- .../feedly/gui/feedlyaccountdetails.cpp | 4 ++- 26 files changed, 129 insertions(+), 85 deletions(-) diff --git a/resources/desktop/com.github.rssguard.appdata.xml b/resources/desktop/com.github.rssguard.appdata.xml index cb454eccc..303260415 100644 --- a/resources/desktop/com.github.rssguard.appdata.xml +++ b/resources/desktop/com.github.rssguard.appdata.xml @@ -30,7 +30,7 @@ https://martinrotter.github.io/donate/ - + none diff --git a/src/librssguard/gui/settings/settingsgui.cpp b/src/librssguard/gui/settings/settingsgui.cpp index ba5e6ffed..8ec2661b7 100755 --- a/src/librssguard/gui/settings/settingsgui.cpp +++ b/src/librssguard/gui/settings/settingsgui.cpp @@ -99,8 +99,9 @@ void SettingsGui::loadSettings() { // Load settings of icon theme. const QString current_theme = qApp->icons()->currentIconTheme(); + auto icons = qApp->icons()->installedIconThemes(); - for (const QString& icon_theme_name : qApp->icons()->installedIconThemes()) { + for (const QString& icon_theme_name : qAsConst(icons)) { if (icon_theme_name == APP_NO_THEME) { // Add just "no theme" on other systems. //: Label for disabling icon theme. @@ -129,8 +130,9 @@ void SettingsGui::loadSettings() { // Load skin. const QString selected_skin = qApp->skins()->selectedSkinName(); + auto skins = qApp->skins()->installedSkins(); - for (const Skin& skin : qApp->skins()->installedSkins()) { + for (const Skin& skin : qAsConst(skins)) { QTreeWidgetItem* new_item = new QTreeWidgetItem(QStringList() << skin.m_visibleName << skin.m_version << @@ -155,7 +157,9 @@ void SettingsGui::loadSettings() { } // Load styles. - for (const QString& style_name : QStyleFactory::keys()) { + auto styles = QStyleFactory::keys(); + + for (const QString& style_name : qAsConst(styles)) { m_ui->m_cmbStyles->addItem(style_name); } diff --git a/src/librssguard/gui/settings/settingslocalization.cpp b/src/librssguard/gui/settings/settingslocalization.cpp index f519ff68e..4e6fc68c3 100644 --- a/src/librssguard/gui/settings/settingslocalization.cpp +++ b/src/librssguard/gui/settings/settingslocalization.cpp @@ -32,7 +32,9 @@ SettingsLocalization::~SettingsLocalization() { void SettingsLocalization::loadSettings() { onBeginLoadSettings(); - for (const Language& language : qApp->localization()->installedLanguages()) { + auto langs = qApp->localization()->installedLanguages(); + + for (const Language& language : qAsConst(langs)) { auto* item = new QTreeWidgetItem(m_ui->m_treeLanguages); item->setText(0, language.m_name); diff --git a/src/librssguard/gui/webviewer.cpp b/src/librssguard/gui/webviewer.cpp index 666b9844c..5c09d4d3c 100644 --- a/src/librssguard/gui/webviewer.cpp +++ b/src/librssguard/gui/webviewer.cpp @@ -178,10 +178,11 @@ void WebViewer::contextMenuEvent(QContextMenuEvent* event) { if (menu_data.mediaUrl().isValid() || menu_data.linkUrl().isValid()) { QFileIconProvider icon_provider; QMenu* menu_ext_tools = new QMenu(tr("Open with external tool"), menu); + auto tools = ExternalTool::toolsFromSettings(); menu_ext_tools->setIcon(qApp->icons()->fromTheme(QSL("document-open"))); - for (const ExternalTool& tool : ExternalTool::toolsFromSettings()) { + for (const ExternalTool& tool : qAsConst(tools)) { QAction* act_tool = new QAction(QFileInfo(tool.executable()).fileName(), menu_ext_tools); act_tool->setIcon(icon_provider.icon(tool.executable())); diff --git a/src/librssguard/miscellaneous/feedreader.cpp b/src/librssguard/miscellaneous/feedreader.cpp index 6c3644374..afd5d61d7 100644 --- a/src/librssguard/miscellaneous/feedreader.cpp +++ b/src/librssguard/miscellaneous/feedreader.cpp @@ -8,9 +8,9 @@ #include "core/feedsproxymodel.h" #include "core/messagesmodel.h" #include "core/messagesproxymodel.h" +#include "database/databasequeries.h" #include "gui/dialogs/formmessagefiltersmanager.h" #include "miscellaneous/application.h" -#include "database/databasequeries.h" #include "miscellaneous/mutex.h" #include "services/abstract/cacheforserviceroot.h" #include "services/abstract/serviceroot.h" @@ -164,7 +164,7 @@ void FeedReader::loadSavedMessageFilters() { // all feeds. m_messageFilters = DatabaseQueries::getMessageFilters(qApp->database()->driver()->connection(metaObject()->className())); - for (auto* filter : m_messageFilters) { + for (auto* filter : qAsConst(m_messageFilters)) { filter->setParent(this); } } diff --git a/src/librssguard/miscellaneous/iconfactory.cpp b/src/librssguard/miscellaneous/iconfactory.cpp index e708e14af..1d3e2afbd 100755 --- a/src/librssguard/miscellaneous/iconfactory.cpp +++ b/src/librssguard/miscellaneous/iconfactory.cpp @@ -57,14 +57,15 @@ QIcon IconFactory::miscIcon(const QString& name) { } void IconFactory::setupSearchPaths() { - QIcon::setThemeSearchPaths(QIcon::themeSearchPaths() - << APP_THEME_PATH - << qApp->applicationDirPath() + QDir::separator() + APP_LOCAL_THEME_FOLDER); + auto paths = QIcon::themeSearchPaths(); + + paths << APP_THEME_PATH + << qApp->applicationDirPath() + QDir::separator() + APP_LOCAL_THEME_FOLDER; + + QIcon::setThemeSearchPaths(paths); qDebugNN << LOGSEC_GUI << "Available icon theme paths: " - << QIcon::themeSearchPaths() - .replaceInStrings(QRegularExpression(QSL("^|$")), QSL("\'")) - .replaceInStrings(QRegularExpression(QSL("/")), QDir::separator()).join(QSL(", ")); + << paths; } void IconFactory::setCurrentIconTheme(const QString& theme_name) { @@ -129,12 +130,13 @@ QStringList IconFactory::installedIconThemes() const { for (const QString& icon_path : icon_themes_paths) { const QDir icon_dir(icon_path); + auto icon_paths = icon_dir.entryInfoList(QDir::Filter::Dirs | QDir::Filter::NoDotAndDotDot | + QDir::Filter::Readable | QDir::Filter::CaseSensitive | + QDir::Filter::NoSymLinks, + QDir::SortFlag::Time); // Iterate all icon themes in this directory. - for (const QFileInfo& icon_theme_path : icon_dir.entryInfoList(QDir::Filter::Dirs | QDir::Filter::NoDotAndDotDot | - QDir::Filter::Readable | QDir::Filter::CaseSensitive | - QDir::Filter::NoSymLinks, - QDir::SortFlag::Time)) { + for (const QFileInfo& icon_theme_path : qAsConst(icon_paths)) { QDir icon_theme_dir = QDir(icon_theme_path.absoluteFilePath()); if (icon_theme_dir.exists(filters_index.at(0))) { diff --git a/src/librssguard/miscellaneous/localization.cpp b/src/librssguard/miscellaneous/localization.cpp index b127b54bb..5ec09581e 100644 --- a/src/librssguard/miscellaneous/localization.cpp +++ b/src/librssguard/miscellaneous/localization.cpp @@ -72,9 +72,10 @@ QList Localization::installedLanguages() const { QList languages; const QDir file_dir(APP_LANG_PATH); QTranslator translator; + auto lang_files = file_dir.entryInfoList(QStringList() << QSL("rssguard_*.qm"), QDir::Files, QDir::Name); // Iterate all found language files. - for (const QFileInfo& file : file_dir.entryInfoList(QStringList() << "rssguard_*.qm", QDir::Files, QDir::Name)) { + for (const QFileInfo& file : qAsConst(lang_files)) { if (translator.load(file.absoluteFilePath())) { Language new_language; diff --git a/src/librssguard/miscellaneous/textfactory.cpp b/src/librssguard/miscellaneous/textfactory.cpp index 803908d65..e2a8f96f2 100755 --- a/src/librssguard/miscellaneous/textfactory.cpp +++ b/src/librssguard/miscellaneous/textfactory.cpp @@ -86,7 +86,7 @@ QDateTime TextFactory::parseDateTime(const QString& date_time) { << QSL("-hhmm") << QSL("+hh") << QSL("-hh"); // Iterate over patterns and check if input date/time matches the pattern. - for (const QString& pattern : date_patterns) { + for (const QString& pattern : qAsConst(date_patterns)) { dt = locale.toDateTime(input_date.left(pattern.size()), pattern); if (dt.isValid()) { @@ -97,7 +97,7 @@ QDateTime TextFactory::parseDateTime(const QString& date_time) { if (input_date.size() >= TIMEZONE_OFFSET_LIMIT) { QString offset_sanitized = input_date.mid(pattern.size()).replace(QL1S(" "), QString()); - for (const QString& pattern_t : timezone_offset_patterns) { + for (const QString& pattern_t : qAsConst(timezone_offset_patterns)) { time_zone_offset = QTime::fromString(offset_sanitized.left(pattern_t.size()), pattern_t); if (time_zone_offset.isValid()) { diff --git a/src/librssguard/miscellaneous/textfactory.h b/src/librssguard/miscellaneous/textfactory.h index c091f50e9..54fc5ae4d 100755 --- a/src/librssguard/miscellaneous/textfactory.h +++ b/src/librssguard/miscellaneous/textfactory.h @@ -22,7 +22,7 @@ class TextFactory { // Tries to parse input textual date/time representation. // Returns invalid date/time if processing fails. - // NOTE: This method tries to always return time in UTC+00:00. + // NOTE: This method tries to always return time in UTC. static QDateTime parseDateTime(const QString& date_time); // Converts 1970-epoch miliseconds to date/time. diff --git a/src/librssguard/network-web/adblock/adblockaddsubscriptiondialog.cpp b/src/librssguard/network-web/adblock/adblockaddsubscriptiondialog.cpp index a01f03b32..89a6d63b1 100644 --- a/src/librssguard/network-web/adblock/adblockaddsubscriptiondialog.cpp +++ b/src/librssguard/network-web/adblock/adblockaddsubscriptiondialog.cpp @@ -28,16 +28,12 @@ AdBlockAddSubscriptionDialog::AdBlockAddSubscriptionDialog(QWidget* parent) : QDialog(parent), m_ui(new Ui::AdBlockAddSubscriptionDialog) { m_ui->setupUi(this); m_knownSubscriptions - << Subscription(QSL("EasyList"), - QSL(ADBLOCK_EASYLIST_URL)) - << Subscription(QSL("EasyPrivacy"), - QSL("https://easylist.to/easylist/easyprivacy.txt")) - << Subscription(QSL("EasyPrivacy Tracking Protection List"), - QSL("https://easylist-downloads.adblockplus.org/easyprivacy.tpl")) - << Subscription(QSL("Adblock Warning Removal List"), - QSL("https://easylist-downloads.adblockplus.org/antiadblockfilters.txt")); + << Subscription(QSL("EasyList"), QSL(ADBLOCK_EASYLIST_URL)) + << Subscription(QSL("EasyPrivacy"), QSL("https://easylist.to/easylist/easyprivacy.txt")) + << Subscription(QSL("EasyPrivacy Tracking Protection List"), QSL("https://easylist-downloads.adblockplus.org/easyprivacy.tpl")) + << Subscription(QSL("Adblock Warning Removal List"), QSL("https://easylist-downloads.adblockplus.org/antiadblockfilters.txt")); - for (const Subscription& subscription : m_knownSubscriptions) { + for (const Subscription& subscription : qAsConst(m_knownSubscriptions)) { m_ui->m_cmbPresets->addItem(subscription.m_title); } diff --git a/src/librssguard/network-web/adblock/adblockdialog.cpp b/src/librssguard/network-web/adblock/adblockdialog.cpp index 529625119..5c37b0b14 100644 --- a/src/librssguard/network-web/adblock/adblockdialog.cpp +++ b/src/librssguard/network-web/adblock/adblockdialog.cpp @@ -159,7 +159,9 @@ void AdBlockDialog::load() { return; } - for (AdBlockSubscription* subscription : m_manager->subscriptions()) { + auto subs = m_manager->subscriptions(); + + for (AdBlockSubscription* subscription : qAsConst(subs)) { auto* tree = new AdBlockTreeWidget(subscription, m_ui->m_tabSubscriptions); m_ui->m_tabSubscriptions->addTab(tree, subscription->title()); diff --git a/src/librssguard/network-web/adblock/adblockmanager.cpp b/src/librssguard/network-web/adblock/adblockmanager.cpp index ada89197b..5ddfee207 100644 --- a/src/librssguard/network-web/adblock/adblockmanager.cpp +++ b/src/librssguard/network-web/adblock/adblockmanager.cpp @@ -178,7 +178,9 @@ void AdBlockManager::load(bool initial_load) { QDir().mkpath(storedListsPath()); } - for (const QString& subscription_file_name : adblock_dir.entryList(QStringList("*.txt"), QDir::Files)) { + auto subs_files = adblock_dir.entryList({ QSL("*.txt") }, QDir::Filter::Files); + + for (const QString& subscription_file_name : qAsConst(subs_files)) { if (subscription_file_name == ADBLOCK_CUSTOMLIST_NAME) { continue; } @@ -216,7 +218,7 @@ void AdBlockManager::load(bool initial_load) { m_subscriptions.append(custom_list); // Load all subscriptions. - for (AdBlockSubscription* subscription : m_subscriptions) { + for (AdBlockSubscription* subscription : qAsConst(m_subscriptions)) { subscription->loadSubscription(m_disabledRules); connect(subscription, &AdBlockSubscription::subscriptionChanged, this, &AdBlockManager::updateMatcher); } @@ -244,7 +246,7 @@ void AdBlockManager::updateMatcher() { } void AdBlockManager::updateAllSubscriptions() { - for (AdBlockSubscription* subscription : m_subscriptions) { + for (AdBlockSubscription* subscription : qAsConst(m_subscriptions)) { subscription->updateSubscription(); } @@ -256,7 +258,7 @@ void AdBlockManager::save() { return; } - for (AdBlockSubscription* subscription : m_subscriptions) { + for (AdBlockSubscription* subscription : qAsConst(m_subscriptions)) { subscription->saveSubscription(); } diff --git a/src/librssguard/network-web/adblock/adblockmatcher.cpp b/src/librssguard/network-web/adblock/adblockmatcher.cpp index 90e157700..71edec90f 100644 --- a/src/librssguard/network-web/adblock/adblockmatcher.cpp +++ b/src/librssguard/network-web/adblock/adblockmatcher.cpp @@ -133,9 +133,12 @@ void AdBlockMatcher::update() { clear(); QHash cssRulesHash; QVector exceptionCssRules; + auto subs = m_manager->subscriptions(); - for (AdBlockSubscription* subscription : m_manager->subscriptions()) { - for (const AdBlockRule* rule : subscription->allRules()) { + for (AdBlockSubscription* subscription : qAsConst(subs)) { + auto rls = subscription->allRules(); + + for (const AdBlockRule* rule : qAsConst(rls)) { // Don't add internally disabled rules to cache. if (rule->isInternalDisabled()) { continue; diff --git a/src/librssguard/network-web/adblock/adblocksubscription.cpp b/src/librssguard/network-web/adblock/adblocksubscription.cpp index 132181b8d..9ab410de0 100644 --- a/src/librssguard/network-web/adblock/adblocksubscription.cpp +++ b/src/librssguard/network-web/adblock/adblocksubscription.cpp @@ -329,7 +329,7 @@ void AdBlockCustomList::saveSubscription() { textStream << "Url: " << url().toString() << QL1C('\n'); textStream << "[Adblock Plus 1.1.1]" << QL1C('\n'); - for (const AdBlockRule* rule : m_rules) { + for (const AdBlockRule* rule : qAsConst(m_rules)) { textStream << rule->filter() << QL1C('\n'); } diff --git a/src/librssguard/network-web/downloader.cpp b/src/librssguard/network-web/downloader.cpp index 8b7b17684..7e20768d2 100644 --- a/src/librssguard/network-web/downloader.cpp +++ b/src/librssguard/network-web/downloader.cpp @@ -171,17 +171,18 @@ QList Downloader::decodeMultipartAnswer(QNetworkReply* reply) { start_of_body - start_of_headers).replace(QRegularExpression(QSL("[\\n\\r]+")), QSL("\n")); - for (const QString& header_line : headers.split(QL1C('\n'), + auto header_lines = headers.split(QL1C('\n'), #if QT_VERSION >= 0x050F00 // Qt >= 5.15.0 - Qt::SplitBehaviorFlags::SkipEmptyParts)) { + Qt::SplitBehaviorFlags::SkipEmptyParts); #else - QString::SplitBehavior::SkipEmptyParts)) { + QString::SplitBehavior::SkipEmptyParts); #endif + + for (const QString& header_line : qAsConst(header_lines)) { int index_colon = header_line.indexOf(QL1C(':')); if (index_colon > 0) { - new_part.appendHeader(header_line.mid(0, index_colon), - header_line.mid(index_colon + 2)); + new_part.appendHeader(header_line.mid(0, index_colon), header_line.mid(index_colon + 2)); } } diff --git a/src/librssguard/network-web/networkurlinterceptor.cpp b/src/librssguard/network-web/networkurlinterceptor.cpp index d5cc2809a..6d668cdc8 100644 --- a/src/librssguard/network-web/networkurlinterceptor.cpp +++ b/src/librssguard/network-web/networkurlinterceptor.cpp @@ -33,7 +33,7 @@ void NetworkUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo& info) { // NOTE: Here we can add custom headers for each webengine request, for example "User-Agent". - for (UrlInterceptor* interceptor : m_interceptors) { + for (UrlInterceptor* interceptor : qAsConst(m_interceptors)) { interceptor->interceptRequest(info); } } diff --git a/src/librssguard/network-web/webfactory.cpp b/src/librssguard/network-web/webfactory.cpp index 20f388cc5..782d91b54 100644 --- a/src/librssguard/network-web/webfactory.cpp +++ b/src/librssguard/network-web/webfactory.cpp @@ -156,7 +156,7 @@ QString WebFactory::unescapeHtml(const QString& html) { } else { // Failed to convert to number, leave intact. - output.append(html.mid(pos, pos_end - pos + 1)); + output.append(html.midRef(pos, pos_end - pos + 1)); } pos = pos_end + 1; diff --git a/src/librssguard/network-web/webfactory.h b/src/librssguard/network-web/webfactory.h index 0d80fc1e8..a0eaae396 100644 --- a/src/librssguard/network-web/webfactory.h +++ b/src/librssguard/network-web/webfactory.h @@ -41,7 +41,6 @@ class WebFactory : public QObject { NetworkUrlInterceptor* urlIinterceptor(); #endif - public slots: void updateProxy(); bool openUrlInExternalBrowser(const QString& url) const; bool sendMessageViaEmail(const Message& message); diff --git a/src/librssguard/services/abstract/accountcheckmodel.cpp b/src/librssguard/services/abstract/accountcheckmodel.cpp index 117a235f6..736aff3fd 100644 --- a/src/librssguard/services/abstract/accountcheckmodel.cpp +++ b/src/librssguard/services/abstract/accountcheckmodel.cpp @@ -42,7 +42,9 @@ void AccountCheckModel::setRootItem(RootItem* root_item, bool delete_previous_ro void AccountCheckModel::checkAllItems() { if (m_rootItem != nullptr) { - for (RootItem* root_child : m_rootItem->childItems()) { + auto chi = m_rootItem->childItems(); + + for (RootItem* root_child : qAsConst(chi)) { if (root_child->kind() == RootItem::Kind::Feed || root_child->kind() == RootItem::Kind::Category) { setItemChecked(root_child, Qt::Checked); } @@ -52,7 +54,9 @@ void AccountCheckModel::checkAllItems() { void AccountCheckModel::uncheckAllItems() { if (m_rootItem != nullptr) { - for (RootItem* root_child : m_rootItem->childItems()) { + auto chi = m_rootItem->childItems(); + + for (RootItem* root_child : qAsConst(chi)) { if (root_child->kind() == RootItem::Kind::Feed || root_child->kind() == RootItem::Kind::Category) { setData(indexForItem(root_child), Qt::Unchecked, Qt::CheckStateRole); } @@ -161,7 +165,7 @@ QVariant AccountCheckModel::data(const QModelIndex& index, int role) const { RootItem* item = itemForIndex(index); - if (role == Qt::CheckStateRole) { + if (role == Qt::ItemDataRole::CheckStateRole) { if (m_checkStates.contains(item)) { return m_checkStates.value(item); } @@ -169,15 +173,13 @@ QVariant AccountCheckModel::data(const QModelIndex& index, int role) const { return static_cast(Qt::Unchecked); } } - else if (role == Qt::DecorationRole) { - auto ic = item->icon(); - + else if (role == Qt::ItemDataRole::DecorationRole) { return item->data(0, Qt::ItemDataRole::DecorationRole); } - else if (role == Qt::EditRole) { + else if (role == Qt::ItemDataRole::EditRole) { return QVariant::fromValue(item); } - else if (role == Qt::DisplayRole) { + else if (role == Qt::ItemDataRole::DisplayRole) { switch (item->kind()) { case RootItem::Kind::Category: return QVariant(item->data(index.column(), role).toString() + QSL(" ") + tr("(category)")); @@ -213,7 +215,9 @@ bool AccountCheckModel::setData(const QModelIndex& index, const QVariant& value, } // Set new data for all descendants of this actual item. - for (RootItem* child : item->childItems()) { + auto chi = item->childItems(); + + for (RootItem* child : qAsConst(chi)) { setData(indexForItem(child), value, Qt::CheckStateRole); } @@ -230,8 +234,9 @@ bool AccountCheckModel::setData(const QModelIndex& index, const QVariant& value, // Check children of this new parent item. bool all_checked = true; bool all_unchecked = true; + auto chi = item->childItems(); - for (RootItem* child_of_parent : item->childItems()) { + for (RootItem* child_of_parent : qAsConst(chi)) { if (m_checkStates.contains(child_of_parent)) { all_checked &= m_checkStates[child_of_parent] == Qt::CheckState::Checked; all_unchecked &= m_checkStates[child_of_parent] == Qt::CheckState::Unchecked; diff --git a/src/librssguard/services/abstract/category.cpp b/src/librssguard/services/abstract/category.cpp index 841903e41..5bb8368fd 100644 --- a/src/librssguard/services/abstract/category.cpp +++ b/src/librssguard/services/abstract/category.cpp @@ -2,8 +2,8 @@ #include "services/abstract/category.h" -#include "miscellaneous/application.h" #include "database/databasequeries.h" +#include "miscellaneous/application.h" #include "miscellaneous/iconfactory.h" #include "miscellaneous/textfactory.h" #include "services/abstract/cacheforserviceroot.h" @@ -20,8 +20,9 @@ Category::Category(const Category& other) : RootItem(other) { void Category::updateCounts(bool including_total_count) { QList feeds; + auto str = getSubTree(); - for (RootItem* child : getSubTree()) { + for (RootItem* child : qAsConst(str)) { if (child->kind() == RootItem::Kind::Feed) { feeds.append(child->toFeed()); } diff --git a/src/librssguard/services/abstract/feed.cpp b/src/librssguard/services/abstract/feed.cpp index 7c77af75b..a7e98a905 100755 --- a/src/librssguard/services/abstract/feed.cpp +++ b/src/librssguard/services/abstract/feed.cpp @@ -97,7 +97,7 @@ void Feed::setCountOfAllMessages(int count_all_messages) { } void Feed::setCountOfUnreadMessages(int count_unread_messages) { - if (status() == Status::NewMessages && count_unread_messages < countOfUnreadMessages()) { + if (status() == Status::NewMessages && count_unread_messages < m_unreadCount) { setStatus(Status::Normal); } diff --git a/src/librssguard/services/abstract/rootitem.cpp b/src/librssguard/services/abstract/rootitem.cpp index 73ea2926d..e371f0af5 100644 --- a/src/librssguard/services/abstract/rootitem.cpp +++ b/src/librssguard/services/abstract/rootitem.cpp @@ -74,7 +74,7 @@ bool RootItem::deleteViaGui() { bool RootItem::markAsReadUnread(ReadStatus status) { bool result = true; - for (RootItem* child : m_childItems) { + for (RootItem* child : qAsConst(m_childItems)) { result &= child->markAsReadUnread(status); } @@ -84,7 +84,7 @@ bool RootItem::markAsReadUnread(ReadStatus status) { QList RootItem::undeletedMessages() const { QList messages; - for (RootItem* child : m_childItems) { + for (RootItem* child : qAsConst(m_childItems)) { if (child->kind() != Kind::Bin && child->kind() != Kind::Labels && child->kind() != Kind::Label) { messages.append(child->undeletedMessages()); } @@ -96,7 +96,7 @@ QList RootItem::undeletedMessages() const { bool RootItem::cleanMessages(bool clear_only_read) { bool result = true; - for (RootItem* child : m_childItems) { + for (RootItem* child : qAsConst(m_childItems)) { if (child->kind() != RootItem::Kind::Bin) { result &= child->cleanMessages(clear_only_read); } @@ -106,7 +106,7 @@ bool RootItem::cleanMessages(bool clear_only_read) { } void RootItem::updateCounts(bool including_total_count) { - for (RootItem* child : m_childItems) { + for (RootItem* child : qAsConst(m_childItems)) { child->updateCounts(including_total_count); } } diff --git a/src/librssguard/services/abstract/serviceroot.cpp b/src/librssguard/services/abstract/serviceroot.cpp index 0d3618bf0..15d02d083 100644 --- a/src/librssguard/services/abstract/serviceroot.cpp +++ b/src/librssguard/services/abstract/serviceroot.cpp @@ -120,8 +120,9 @@ void ServiceRoot::stop() {} void ServiceRoot::updateCounts(bool including_total_count) { QList feeds; + auto str = getSubTree(); - for (RootItem* child : getSubTree()) { + for (RootItem* child : qAsConst(str)) { if (child->kind() == RootItem::Kind::Feed) { feeds.append(child->toFeed()); } @@ -194,7 +195,9 @@ void ServiceRoot::removeOldAccountFromDatabase(bool including_messages) { } void ServiceRoot::cleanAllItemsFromModel() { - for (RootItem* top_level_item : childItems()) { + auto chi = childItems(); + + for (RootItem* top_level_item : qAsConst(chi)) { if (top_level_item->kind() != RootItem::Kind::Bin && top_level_item->kind() != RootItem::Kind::Important && top_level_item->kind() != RootItem::Kind::Labels) { @@ -203,7 +206,9 @@ void ServiceRoot::cleanAllItemsFromModel() { } if (labelsNode() != nullptr) { - for (RootItem* lbl : labelsNode()->childItems()) { + auto lbl_chi = labelsNode()->childItems(); + + for (RootItem* lbl : qAsConst(lbl_chi)) { requestItemRemoval(lbl); } } @@ -218,10 +223,8 @@ void ServiceRoot::appendCommonNodes() { appendChild(importantNode()); } - if (labelsNode() != nullptr) { - if (!childItems().contains(labelsNode())) { - appendChild(labelsNode()); - } + if (labelsNode() != nullptr && !childItems().contains(labelsNode())) { + appendChild(labelsNode()); } } @@ -338,10 +341,13 @@ void ServiceRoot::addNewCategory(RootItem* selected_item) { QMap ServiceRoot::storeCustomFeedsData() { QMap custom_data; + auto str = getSubTreeFeeds(); - for (const Feed* feed : getSubTreeFeeds()) { + for (const Feed* feed : qAsConst(str)) { QVariantMap feed_custom_data; + // TODO: This could potentially call Feed::customDatabaseData() and append it + // to this map and also subsequently restore. feed_custom_data.insert(QSL("auto_update_interval"), feed->autoUpdateInitialInterval()); feed_custom_data.insert(QSL("auto_update_type"), int(feed->autoUpdateType())); feed_custom_data.insert(QSL("msg_filters"), QVariant::fromValue(feed->messageFilters())); @@ -412,7 +418,9 @@ void ServiceRoot::syncIn() { removeLeftOverMessageFilterAssignments(); removeLeftOverMessageLabelAssignments(); - for (RootItem* top_level_item : new_tree->childItems()) { + auto chi = new_tree->childItems(); + + for (RootItem* top_level_item : qAsConst(chi)) { if (top_level_item->kind() != Kind::Labels) { top_level_item->setParent(nullptr); requestItemReassignment(top_level_item, this); @@ -420,7 +428,9 @@ void ServiceRoot::syncIn() { else { // It seems that some labels got synced-in. if (labelsNode() != nullptr) { - for (RootItem* new_lbl : top_level_item->childItems()) { + auto lbl_chi = top_level_item->childItems(); + + for (RootItem* new_lbl : qAsConst(lbl_chi)) { new_lbl->setParent(nullptr); requestItemReassignment(new_lbl, labelsNode()); } @@ -464,7 +474,9 @@ QStringList ServiceRoot::customIDSOfMessagesForItem(RootItem* item) { switch (item->kind()) { case RootItem::Kind::Labels: case RootItem::Kind::Category: { - for (RootItem* child : item->childItems()) { + auto chi = item->childItems(); + + for (RootItem* child : qAsConst(chi)) { list.append(customIDSOfMessagesForItem(child)); } diff --git a/src/librssguard/services/abstract/serviceroot.h b/src/librssguard/services/abstract/serviceroot.h index 801089f18..0d4601649 100644 --- a/src/librssguard/services/abstract/serviceroot.h +++ b/src/librssguard/services/abstract/serviceroot.h @@ -40,13 +40,14 @@ class ServiceRoot : public RootItem { virtual ~ServiceRoot(); // These methods bellow are part of "interface". + RecycleBin* recycleBin() const; + ImportantNode* importantNode() const; + LabelsNode* labelsNode() const; + virtual void updateCounts(bool including_total_count); virtual bool canBeDeleted() const; virtual bool deleteViaGui(); virtual bool markAsReadUnread(ReadStatus status); - virtual RecycleBin* recycleBin() const; - virtual ImportantNode* importantNode() const; - virtual LabelsNode* labelsNode() const; virtual bool downloadAttachmentOnMyOwn(const QUrl& url) const; virtual QList undeletedMessages() const; virtual bool supportsFeedAdding() const; diff --git a/src/librssguard/services/feedly/feedlynetwork.cpp b/src/librssguard/services/feedly/feedlynetwork.cpp index e5f34ff74..8e92ee3e9 100755 --- a/src/librssguard/services/feedly/feedlynetwork.cpp +++ b/src/librssguard/services/feedly/feedlynetwork.cpp @@ -231,7 +231,9 @@ QList FeedlyNetwork::decodeStreamContents(const QByteArray& stream_cont continuation = json.object()["continuation"].toString(); - for (const QJsonValue& entry : json.object()["items"].toArray()) { + auto items = json.object()["items"].toArray(); + + for (const QJsonValue& entry : qAsConst(items)) { const QJsonObject& entry_obj = entry.toObject(); Message message; @@ -255,7 +257,9 @@ QList FeedlyNetwork::decodeStreamContents(const QByteArray& stream_cont message.m_url = entry_obj["canonical"].toObject()["href"].toString(); } - for (const QJsonValue& enc : entry_obj["enclosure"].toArray()) { + auto enclosures = entry_obj["enclosure"].toArray(); + + for (const QJsonValue& enc : qAsConst(enclosures)) { const QJsonObject& enc_obj = enc.toObject(); const QString& enc_href = enc_obj["href"].toString(); @@ -266,7 +270,9 @@ QList FeedlyNetwork::decodeStreamContents(const QByteArray& stream_cont } } - for (const QJsonValue& tag : entry_obj["tags"].toArray()) { + auto tags = entry_obj["tags"].toArray(); + + for (const QJsonValue& tag : qAsConst(tags)) { const QJsonObject& tag_obj = tag.toObject(); const QString& tag_id = tag_obj["id"].toString(); @@ -332,15 +338,18 @@ RootItem* FeedlyNetwork::decodeCollections(const QByteArray& json, bool obtain_i QJsonDocument doc = QJsonDocument::fromJson(json); auto* parent = new RootItem(); QList used_feeds; + auto coll = doc.array(); - for (const QJsonValue& cat : doc.array()) { + for (const QJsonValue& cat : qAsConst(coll)) { QJsonObject cat_obj = cat.toObject(); auto* category = new Category(parent); category->setTitle(cat_obj["label"].toString()); category->setCustomId(cat_obj["id"].toString()); - for (const QJsonValue& fee : cat["feeds"].toArray()) { + auto feeds = cat["feeds"].toArray(); + + for (const QJsonValue& fee : qAsConst(feeds)) { QJsonObject fee_obj = fee.toObject(); if (used_feeds.contains(fee_obj["id"].toString())) { @@ -446,8 +455,9 @@ QList FeedlyNetwork::tags() { QJsonDocument json = QJsonDocument::fromJson(output); QList lbls; + auto tags = json.array(); - for (const QJsonValue& tag : json.array()) { + for (const QJsonValue& tag : qAsConst(tags)) { const QJsonObject& tag_obj = tag.toObject(); QString name_id = tag_obj["id"].toString(); diff --git a/src/librssguard/services/feedly/gui/feedlyaccountdetails.cpp b/src/librssguard/services/feedly/gui/feedlyaccountdetails.cpp index ddd807ba8..12c6d3aca 100755 --- a/src/librssguard/services/feedly/gui/feedlyaccountdetails.cpp +++ b/src/librssguard/services/feedly/gui/feedlyaccountdetails.cpp @@ -130,7 +130,9 @@ void FeedlyAccountDetails::performTest(const QNetworkProxy& custom_proxy) { factory.setDeveloperAccessToken(m_ui.m_txtDeveloperAccessToken->lineEdit()->text()); try { - m_ui.m_txtUsername->lineEdit()->setText(factory.profile(custom_proxy)["email"].toString()); + auto prof = factory.profile(custom_proxy); + + m_ui.m_txtUsername->lineEdit()->setText(prof["email"].toString()); m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Ok, tr("Login was successful."), tr("Access granted."));