refactoring with clazy

This commit is contained in:
Martin Rotter 2021-03-19 14:02:42 +01:00
parent aa18d074a3
commit 1538c1261f
26 changed files with 129 additions and 85 deletions

View File

@ -30,7 +30,7 @@
<url type="donation">https://martinrotter.github.io/donate/</url> <url type="donation">https://martinrotter.github.io/donate/</url>
<content_rating type="oars-1.1" /> <content_rating type="oars-1.1" />
<releases> <releases>
<release version="3.9.0" date="2021-03-17"/> <release version="3.9.0" date="2021-03-19"/>
</releases> </releases>
<content_rating type="oars-1.0"> <content_rating type="oars-1.0">
<content_attribute id="violence-cartoon">none</content_attribute> <content_attribute id="violence-cartoon">none</content_attribute>

View File

@ -99,8 +99,9 @@ void SettingsGui::loadSettings() {
// Load settings of icon theme. // Load settings of icon theme.
const QString current_theme = qApp->icons()->currentIconTheme(); 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) { if (icon_theme_name == APP_NO_THEME) {
// Add just "no theme" on other systems. // Add just "no theme" on other systems.
//: Label for disabling icon theme. //: Label for disabling icon theme.
@ -129,8 +130,9 @@ void SettingsGui::loadSettings() {
// Load skin. // Load skin.
const QString selected_skin = qApp->skins()->selectedSkinName(); 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() << QTreeWidgetItem* new_item = new QTreeWidgetItem(QStringList() <<
skin.m_visibleName << skin.m_visibleName <<
skin.m_version << skin.m_version <<
@ -155,7 +157,9 @@ void SettingsGui::loadSettings() {
} }
// Load styles. // 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); m_ui->m_cmbStyles->addItem(style_name);
} }

View File

@ -32,7 +32,9 @@ SettingsLocalization::~SettingsLocalization() {
void SettingsLocalization::loadSettings() { void SettingsLocalization::loadSettings() {
onBeginLoadSettings(); 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); auto* item = new QTreeWidgetItem(m_ui->m_treeLanguages);
item->setText(0, language.m_name); item->setText(0, language.m_name);

View File

@ -178,10 +178,11 @@ void WebViewer::contextMenuEvent(QContextMenuEvent* event) {
if (menu_data.mediaUrl().isValid() || menu_data.linkUrl().isValid()) { if (menu_data.mediaUrl().isValid() || menu_data.linkUrl().isValid()) {
QFileIconProvider icon_provider; QFileIconProvider icon_provider;
QMenu* menu_ext_tools = new QMenu(tr("Open with external tool"), menu); 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"))); 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); QAction* act_tool = new QAction(QFileInfo(tool.executable()).fileName(), menu_ext_tools);
act_tool->setIcon(icon_provider.icon(tool.executable())); act_tool->setIcon(icon_provider.icon(tool.executable()));

View File

@ -8,9 +8,9 @@
#include "core/feedsproxymodel.h" #include "core/feedsproxymodel.h"
#include "core/messagesmodel.h" #include "core/messagesmodel.h"
#include "core/messagesproxymodel.h" #include "core/messagesproxymodel.h"
#include "database/databasequeries.h"
#include "gui/dialogs/formmessagefiltersmanager.h" #include "gui/dialogs/formmessagefiltersmanager.h"
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include "database/databasequeries.h"
#include "miscellaneous/mutex.h" #include "miscellaneous/mutex.h"
#include "services/abstract/cacheforserviceroot.h" #include "services/abstract/cacheforserviceroot.h"
#include "services/abstract/serviceroot.h" #include "services/abstract/serviceroot.h"
@ -164,7 +164,7 @@ void FeedReader::loadSavedMessageFilters() {
// all feeds. // all feeds.
m_messageFilters = DatabaseQueries::getMessageFilters(qApp->database()->driver()->connection(metaObject()->className())); m_messageFilters = DatabaseQueries::getMessageFilters(qApp->database()->driver()->connection(metaObject()->className()));
for (auto* filter : m_messageFilters) { for (auto* filter : qAsConst(m_messageFilters)) {
filter->setParent(this); filter->setParent(this);
} }
} }

View File

@ -57,14 +57,15 @@ QIcon IconFactory::miscIcon(const QString& name) {
} }
void IconFactory::setupSearchPaths() { void IconFactory::setupSearchPaths() {
QIcon::setThemeSearchPaths(QIcon::themeSearchPaths() auto paths = QIcon::themeSearchPaths();
<< APP_THEME_PATH
<< qApp->applicationDirPath() + QDir::separator() + APP_LOCAL_THEME_FOLDER); paths << APP_THEME_PATH
<< qApp->applicationDirPath() + QDir::separator() + APP_LOCAL_THEME_FOLDER;
QIcon::setThemeSearchPaths(paths);
qDebugNN << LOGSEC_GUI qDebugNN << LOGSEC_GUI
<< "Available icon theme paths: " << "Available icon theme paths: "
<< QIcon::themeSearchPaths() << paths;
.replaceInStrings(QRegularExpression(QSL("^|$")), QSL("\'"))
.replaceInStrings(QRegularExpression(QSL("/")), QDir::separator()).join(QSL(", "));
} }
void IconFactory::setCurrentIconTheme(const QString& theme_name) { void IconFactory::setCurrentIconTheme(const QString& theme_name) {
@ -129,12 +130,13 @@ QStringList IconFactory::installedIconThemes() const {
for (const QString& icon_path : icon_themes_paths) { for (const QString& icon_path : icon_themes_paths) {
const QDir icon_dir(icon_path); 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. // Iterate all icon themes in this directory.
for (const QFileInfo& icon_theme_path : icon_dir.entryInfoList(QDir::Filter::Dirs | QDir::Filter::NoDotAndDotDot | for (const QFileInfo& icon_theme_path : qAsConst(icon_paths)) {
QDir::Filter::Readable | QDir::Filter::CaseSensitive |
QDir::Filter::NoSymLinks,
QDir::SortFlag::Time)) {
QDir icon_theme_dir = QDir(icon_theme_path.absoluteFilePath()); QDir icon_theme_dir = QDir(icon_theme_path.absoluteFilePath());
if (icon_theme_dir.exists(filters_index.at(0))) { if (icon_theme_dir.exists(filters_index.at(0))) {

View File

@ -72,9 +72,10 @@ QList<Language> Localization::installedLanguages() const {
QList<Language> languages; QList<Language> languages;
const QDir file_dir(APP_LANG_PATH); const QDir file_dir(APP_LANG_PATH);
QTranslator translator; QTranslator translator;
auto lang_files = file_dir.entryInfoList(QStringList() << QSL("rssguard_*.qm"), QDir::Files, QDir::Name);
// Iterate all found language files. // 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())) { if (translator.load(file.absoluteFilePath())) {
Language new_language; Language new_language;

View File

@ -86,7 +86,7 @@ QDateTime TextFactory::parseDateTime(const QString& date_time) {
<< QSL("-hhmm") << QSL("+hh") << QSL("-hh"); << QSL("-hhmm") << QSL("+hh") << QSL("-hh");
// Iterate over patterns and check if input date/time matches the pattern. // 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); dt = locale.toDateTime(input_date.left(pattern.size()), pattern);
if (dt.isValid()) { if (dt.isValid()) {
@ -97,7 +97,7 @@ QDateTime TextFactory::parseDateTime(const QString& date_time) {
if (input_date.size() >= TIMEZONE_OFFSET_LIMIT) { if (input_date.size() >= TIMEZONE_OFFSET_LIMIT) {
QString offset_sanitized = input_date.mid(pattern.size()).replace(QL1S(" "), QString()); 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); time_zone_offset = QTime::fromString(offset_sanitized.left(pattern_t.size()), pattern_t);
if (time_zone_offset.isValid()) { if (time_zone_offset.isValid()) {

View File

@ -22,7 +22,7 @@ class TextFactory {
// Tries to parse input textual date/time representation. // Tries to parse input textual date/time representation.
// Returns invalid date/time if processing fails. // 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); static QDateTime parseDateTime(const QString& date_time);
// Converts 1970-epoch miliseconds to date/time. // Converts 1970-epoch miliseconds to date/time.

View File

@ -28,16 +28,12 @@ AdBlockAddSubscriptionDialog::AdBlockAddSubscriptionDialog(QWidget* parent)
: QDialog(parent), m_ui(new Ui::AdBlockAddSubscriptionDialog) { : QDialog(parent), m_ui(new Ui::AdBlockAddSubscriptionDialog) {
m_ui->setupUi(this); m_ui->setupUi(this);
m_knownSubscriptions m_knownSubscriptions
<< Subscription(QSL("EasyList"), << Subscription(QSL("EasyList"), QSL(ADBLOCK_EASYLIST_URL))
QSL(ADBLOCK_EASYLIST_URL)) << Subscription(QSL("EasyPrivacy"), QSL("https://easylist.to/easylist/easyprivacy.txt"))
<< Subscription(QSL("EasyPrivacy"), << Subscription(QSL("EasyPrivacy Tracking Protection List"), QSL("https://easylist-downloads.adblockplus.org/easyprivacy.tpl"))
QSL("https://easylist.to/easylist/easyprivacy.txt")) << Subscription(QSL("Adblock Warning Removal List"), QSL("https://easylist-downloads.adblockplus.org/antiadblockfilters.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); m_ui->m_cmbPresets->addItem(subscription.m_title);
} }

View File

@ -159,7 +159,9 @@ void AdBlockDialog::load() {
return; 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); auto* tree = new AdBlockTreeWidget(subscription, m_ui->m_tabSubscriptions);
m_ui->m_tabSubscriptions->addTab(tree, subscription->title()); m_ui->m_tabSubscriptions->addTab(tree, subscription->title());

View File

@ -178,7 +178,9 @@ void AdBlockManager::load(bool initial_load) {
QDir().mkpath(storedListsPath()); 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) { if (subscription_file_name == ADBLOCK_CUSTOMLIST_NAME) {
continue; continue;
} }
@ -216,7 +218,7 @@ void AdBlockManager::load(bool initial_load) {
m_subscriptions.append(custom_list); m_subscriptions.append(custom_list);
// Load all subscriptions. // Load all subscriptions.
for (AdBlockSubscription* subscription : m_subscriptions) { for (AdBlockSubscription* subscription : qAsConst(m_subscriptions)) {
subscription->loadSubscription(m_disabledRules); subscription->loadSubscription(m_disabledRules);
connect(subscription, &AdBlockSubscription::subscriptionChanged, this, &AdBlockManager::updateMatcher); connect(subscription, &AdBlockSubscription::subscriptionChanged, this, &AdBlockManager::updateMatcher);
} }
@ -244,7 +246,7 @@ void AdBlockManager::updateMatcher() {
} }
void AdBlockManager::updateAllSubscriptions() { void AdBlockManager::updateAllSubscriptions() {
for (AdBlockSubscription* subscription : m_subscriptions) { for (AdBlockSubscription* subscription : qAsConst(m_subscriptions)) {
subscription->updateSubscription(); subscription->updateSubscription();
} }
@ -256,7 +258,7 @@ void AdBlockManager::save() {
return; return;
} }
for (AdBlockSubscription* subscription : m_subscriptions) { for (AdBlockSubscription* subscription : qAsConst(m_subscriptions)) {
subscription->saveSubscription(); subscription->saveSubscription();
} }

View File

@ -133,9 +133,12 @@ void AdBlockMatcher::update() {
clear(); clear();
QHash<QString, const AdBlockRule*> cssRulesHash; QHash<QString, const AdBlockRule*> cssRulesHash;
QVector<const AdBlockRule*> exceptionCssRules; QVector<const AdBlockRule*> exceptionCssRules;
auto subs = m_manager->subscriptions();
for (AdBlockSubscription* subscription : m_manager->subscriptions()) { for (AdBlockSubscription* subscription : qAsConst(subs)) {
for (const AdBlockRule* rule : subscription->allRules()) { auto rls = subscription->allRules();
for (const AdBlockRule* rule : qAsConst(rls)) {
// Don't add internally disabled rules to cache. // Don't add internally disabled rules to cache.
if (rule->isInternalDisabled()) { if (rule->isInternalDisabled()) {
continue; continue;

View File

@ -329,7 +329,7 @@ void AdBlockCustomList::saveSubscription() {
textStream << "Url: " << url().toString() << QL1C('\n'); textStream << "Url: " << url().toString() << QL1C('\n');
textStream << "[Adblock Plus 1.1.1]" << 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'); textStream << rule->filter() << QL1C('\n');
} }

View File

@ -171,17 +171,18 @@ QList<HttpResponse> Downloader::decodeMultipartAnswer(QNetworkReply* reply) {
start_of_body - start_of_headers).replace(QRegularExpression(QSL("[\\n\\r]+")), start_of_body - start_of_headers).replace(QRegularExpression(QSL("[\\n\\r]+")),
QSL("\n")); 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 #if QT_VERSION >= 0x050F00 // Qt >= 5.15.0
Qt::SplitBehaviorFlags::SkipEmptyParts)) { Qt::SplitBehaviorFlags::SkipEmptyParts);
#else #else
QString::SplitBehavior::SkipEmptyParts)) { QString::SplitBehavior::SkipEmptyParts);
#endif #endif
for (const QString& header_line : qAsConst(header_lines)) {
int index_colon = header_line.indexOf(QL1C(':')); int index_colon = header_line.indexOf(QL1C(':'));
if (index_colon > 0) { if (index_colon > 0) {
new_part.appendHeader(header_line.mid(0, index_colon), new_part.appendHeader(header_line.mid(0, index_colon), header_line.mid(index_colon + 2));
header_line.mid(index_colon + 2));
} }
} }

View File

@ -33,7 +33,7 @@ void NetworkUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo& info) {
// NOTE: Here we can add custom headers for each webengine request, for example "User-Agent". // 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); interceptor->interceptRequest(info);
} }
} }

View File

@ -156,7 +156,7 @@ QString WebFactory::unescapeHtml(const QString& html) {
} }
else { else {
// Failed to convert to number, leave intact. // 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; pos = pos_end + 1;

View File

@ -41,7 +41,6 @@ class WebFactory : public QObject {
NetworkUrlInterceptor* urlIinterceptor(); NetworkUrlInterceptor* urlIinterceptor();
#endif #endif
public slots:
void updateProxy(); void updateProxy();
bool openUrlInExternalBrowser(const QString& url) const; bool openUrlInExternalBrowser(const QString& url) const;
bool sendMessageViaEmail(const Message& message); bool sendMessageViaEmail(const Message& message);

View File

@ -42,7 +42,9 @@ void AccountCheckModel::setRootItem(RootItem* root_item, bool delete_previous_ro
void AccountCheckModel::checkAllItems() { void AccountCheckModel::checkAllItems() {
if (m_rootItem != nullptr) { 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) { if (root_child->kind() == RootItem::Kind::Feed || root_child->kind() == RootItem::Kind::Category) {
setItemChecked(root_child, Qt::Checked); setItemChecked(root_child, Qt::Checked);
} }
@ -52,7 +54,9 @@ void AccountCheckModel::checkAllItems() {
void AccountCheckModel::uncheckAllItems() { void AccountCheckModel::uncheckAllItems() {
if (m_rootItem != nullptr) { 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) { if (root_child->kind() == RootItem::Kind::Feed || root_child->kind() == RootItem::Kind::Category) {
setData(indexForItem(root_child), Qt::Unchecked, Qt::CheckStateRole); 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); RootItem* item = itemForIndex(index);
if (role == Qt::CheckStateRole) { if (role == Qt::ItemDataRole::CheckStateRole) {
if (m_checkStates.contains(item)) { if (m_checkStates.contains(item)) {
return m_checkStates.value(item); return m_checkStates.value(item);
} }
@ -169,15 +173,13 @@ QVariant AccountCheckModel::data(const QModelIndex& index, int role) const {
return static_cast<int>(Qt::Unchecked); return static_cast<int>(Qt::Unchecked);
} }
} }
else if (role == Qt::DecorationRole) { else if (role == Qt::ItemDataRole::DecorationRole) {
auto ic = item->icon();
return item->data(0, 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); return QVariant::fromValue(item);
} }
else if (role == Qt::DisplayRole) { else if (role == Qt::ItemDataRole::DisplayRole) {
switch (item->kind()) { switch (item->kind()) {
case RootItem::Kind::Category: case RootItem::Kind::Category:
return QVariant(item->data(index.column(), role).toString() + QSL(" ") + tr("(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. // 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); 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. // Check children of this new parent item.
bool all_checked = true; bool all_checked = true;
bool all_unchecked = 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)) { if (m_checkStates.contains(child_of_parent)) {
all_checked &= m_checkStates[child_of_parent] == Qt::CheckState::Checked; all_checked &= m_checkStates[child_of_parent] == Qt::CheckState::Checked;
all_unchecked &= m_checkStates[child_of_parent] == Qt::CheckState::Unchecked; all_unchecked &= m_checkStates[child_of_parent] == Qt::CheckState::Unchecked;

View File

@ -2,8 +2,8 @@
#include "services/abstract/category.h" #include "services/abstract/category.h"
#include "miscellaneous/application.h"
#include "database/databasequeries.h" #include "database/databasequeries.h"
#include "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h" #include "miscellaneous/iconfactory.h"
#include "miscellaneous/textfactory.h" #include "miscellaneous/textfactory.h"
#include "services/abstract/cacheforserviceroot.h" #include "services/abstract/cacheforserviceroot.h"
@ -20,8 +20,9 @@ Category::Category(const Category& other) : RootItem(other) {
void Category::updateCounts(bool including_total_count) { void Category::updateCounts(bool including_total_count) {
QList<Feed*> feeds; QList<Feed*> feeds;
auto str = getSubTree();
for (RootItem* child : getSubTree()) { for (RootItem* child : qAsConst(str)) {
if (child->kind() == RootItem::Kind::Feed) { if (child->kind() == RootItem::Kind::Feed) {
feeds.append(child->toFeed()); feeds.append(child->toFeed());
} }

View File

@ -97,7 +97,7 @@ void Feed::setCountOfAllMessages(int count_all_messages) {
} }
void Feed::setCountOfUnreadMessages(int count_unread_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); setStatus(Status::Normal);
} }

View File

@ -74,7 +74,7 @@ bool RootItem::deleteViaGui() {
bool RootItem::markAsReadUnread(ReadStatus status) { bool RootItem::markAsReadUnread(ReadStatus status) {
bool result = true; bool result = true;
for (RootItem* child : m_childItems) { for (RootItem* child : qAsConst(m_childItems)) {
result &= child->markAsReadUnread(status); result &= child->markAsReadUnread(status);
} }
@ -84,7 +84,7 @@ bool RootItem::markAsReadUnread(ReadStatus status) {
QList<Message> RootItem::undeletedMessages() const { QList<Message> RootItem::undeletedMessages() const {
QList<Message> messages; QList<Message> 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) { if (child->kind() != Kind::Bin && child->kind() != Kind::Labels && child->kind() != Kind::Label) {
messages.append(child->undeletedMessages()); messages.append(child->undeletedMessages());
} }
@ -96,7 +96,7 @@ QList<Message> RootItem::undeletedMessages() const {
bool RootItem::cleanMessages(bool clear_only_read) { bool RootItem::cleanMessages(bool clear_only_read) {
bool result = true; bool result = true;
for (RootItem* child : m_childItems) { for (RootItem* child : qAsConst(m_childItems)) {
if (child->kind() != RootItem::Kind::Bin) { if (child->kind() != RootItem::Kind::Bin) {
result &= child->cleanMessages(clear_only_read); result &= child->cleanMessages(clear_only_read);
} }
@ -106,7 +106,7 @@ bool RootItem::cleanMessages(bool clear_only_read) {
} }
void RootItem::updateCounts(bool including_total_count) { void RootItem::updateCounts(bool including_total_count) {
for (RootItem* child : m_childItems) { for (RootItem* child : qAsConst(m_childItems)) {
child->updateCounts(including_total_count); child->updateCounts(including_total_count);
} }
} }

View File

@ -120,8 +120,9 @@ void ServiceRoot::stop() {}
void ServiceRoot::updateCounts(bool including_total_count) { void ServiceRoot::updateCounts(bool including_total_count) {
QList<Feed*> feeds; QList<Feed*> feeds;
auto str = getSubTree();
for (RootItem* child : getSubTree()) { for (RootItem* child : qAsConst(str)) {
if (child->kind() == RootItem::Kind::Feed) { if (child->kind() == RootItem::Kind::Feed) {
feeds.append(child->toFeed()); feeds.append(child->toFeed());
} }
@ -194,7 +195,9 @@ void ServiceRoot::removeOldAccountFromDatabase(bool including_messages) {
} }
void ServiceRoot::cleanAllItemsFromModel() { 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 && if (top_level_item->kind() != RootItem::Kind::Bin &&
top_level_item->kind() != RootItem::Kind::Important && top_level_item->kind() != RootItem::Kind::Important &&
top_level_item->kind() != RootItem::Kind::Labels) { top_level_item->kind() != RootItem::Kind::Labels) {
@ -203,7 +206,9 @@ void ServiceRoot::cleanAllItemsFromModel() {
} }
if (labelsNode() != nullptr) { if (labelsNode() != nullptr) {
for (RootItem* lbl : labelsNode()->childItems()) { auto lbl_chi = labelsNode()->childItems();
for (RootItem* lbl : qAsConst(lbl_chi)) {
requestItemRemoval(lbl); requestItemRemoval(lbl);
} }
} }
@ -218,10 +223,8 @@ void ServiceRoot::appendCommonNodes() {
appendChild(importantNode()); appendChild(importantNode());
} }
if (labelsNode() != nullptr) { if (labelsNode() != nullptr && !childItems().contains(labelsNode())) {
if (!childItems().contains(labelsNode())) { appendChild(labelsNode());
appendChild(labelsNode());
}
} }
} }
@ -338,10 +341,13 @@ void ServiceRoot::addNewCategory(RootItem* selected_item) {
QMap<QString, QVariantMap> ServiceRoot::storeCustomFeedsData() { QMap<QString, QVariantMap> ServiceRoot::storeCustomFeedsData() {
QMap<QString, QVariantMap> custom_data; QMap<QString, QVariantMap> custom_data;
auto str = getSubTreeFeeds();
for (const Feed* feed : getSubTreeFeeds()) { for (const Feed* feed : qAsConst(str)) {
QVariantMap feed_custom_data; 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_interval"), feed->autoUpdateInitialInterval());
feed_custom_data.insert(QSL("auto_update_type"), int(feed->autoUpdateType())); feed_custom_data.insert(QSL("auto_update_type"), int(feed->autoUpdateType()));
feed_custom_data.insert(QSL("msg_filters"), QVariant::fromValue(feed->messageFilters())); feed_custom_data.insert(QSL("msg_filters"), QVariant::fromValue(feed->messageFilters()));
@ -412,7 +418,9 @@ void ServiceRoot::syncIn() {
removeLeftOverMessageFilterAssignments(); removeLeftOverMessageFilterAssignments();
removeLeftOverMessageLabelAssignments(); 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) { if (top_level_item->kind() != Kind::Labels) {
top_level_item->setParent(nullptr); top_level_item->setParent(nullptr);
requestItemReassignment(top_level_item, this); requestItemReassignment(top_level_item, this);
@ -420,7 +428,9 @@ void ServiceRoot::syncIn() {
else { else {
// It seems that some labels got synced-in. // It seems that some labels got synced-in.
if (labelsNode() != nullptr) { 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); new_lbl->setParent(nullptr);
requestItemReassignment(new_lbl, labelsNode()); requestItemReassignment(new_lbl, labelsNode());
} }
@ -464,7 +474,9 @@ QStringList ServiceRoot::customIDSOfMessagesForItem(RootItem* item) {
switch (item->kind()) { switch (item->kind()) {
case RootItem::Kind::Labels: case RootItem::Kind::Labels:
case RootItem::Kind::Category: { case RootItem::Kind::Category: {
for (RootItem* child : item->childItems()) { auto chi = item->childItems();
for (RootItem* child : qAsConst(chi)) {
list.append(customIDSOfMessagesForItem(child)); list.append(customIDSOfMessagesForItem(child));
} }

View File

@ -40,13 +40,14 @@ class ServiceRoot : public RootItem {
virtual ~ServiceRoot(); virtual ~ServiceRoot();
// These methods bellow are part of "interface". // These methods bellow are part of "interface".
RecycleBin* recycleBin() const;
ImportantNode* importantNode() const;
LabelsNode* labelsNode() const;
virtual void updateCounts(bool including_total_count); virtual void updateCounts(bool including_total_count);
virtual bool canBeDeleted() const; virtual bool canBeDeleted() const;
virtual bool deleteViaGui(); virtual bool deleteViaGui();
virtual bool markAsReadUnread(ReadStatus status); 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 bool downloadAttachmentOnMyOwn(const QUrl& url) const;
virtual QList<Message> undeletedMessages() const; virtual QList<Message> undeletedMessages() const;
virtual bool supportsFeedAdding() const; virtual bool supportsFeedAdding() const;

View File

@ -231,7 +231,9 @@ QList<Message> FeedlyNetwork::decodeStreamContents(const QByteArray& stream_cont
continuation = json.object()["continuation"].toString(); 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(); const QJsonObject& entry_obj = entry.toObject();
Message message; Message message;
@ -255,7 +257,9 @@ QList<Message> FeedlyNetwork::decodeStreamContents(const QByteArray& stream_cont
message.m_url = entry_obj["canonical"].toObject()["href"].toString(); 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 QJsonObject& enc_obj = enc.toObject();
const QString& enc_href = enc_obj["href"].toString(); const QString& enc_href = enc_obj["href"].toString();
@ -266,7 +270,9 @@ QList<Message> 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 QJsonObject& tag_obj = tag.toObject();
const QString& tag_id = tag_obj["id"].toString(); 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); QJsonDocument doc = QJsonDocument::fromJson(json);
auto* parent = new RootItem(); auto* parent = new RootItem();
QList<QString> used_feeds; QList<QString> used_feeds;
auto coll = doc.array();
for (const QJsonValue& cat : doc.array()) { for (const QJsonValue& cat : qAsConst(coll)) {
QJsonObject cat_obj = cat.toObject(); QJsonObject cat_obj = cat.toObject();
auto* category = new Category(parent); auto* category = new Category(parent);
category->setTitle(cat_obj["label"].toString()); category->setTitle(cat_obj["label"].toString());
category->setCustomId(cat_obj["id"].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(); QJsonObject fee_obj = fee.toObject();
if (used_feeds.contains(fee_obj["id"].toString())) { if (used_feeds.contains(fee_obj["id"].toString())) {
@ -446,8 +455,9 @@ QList<RootItem*> FeedlyNetwork::tags() {
QJsonDocument json = QJsonDocument::fromJson(output); QJsonDocument json = QJsonDocument::fromJson(output);
QList<RootItem*> lbls; QList<RootItem*> lbls;
auto tags = json.array();
for (const QJsonValue& tag : json.array()) { for (const QJsonValue& tag : qAsConst(tags)) {
const QJsonObject& tag_obj = tag.toObject(); const QJsonObject& tag_obj = tag.toObject();
QString name_id = tag_obj["id"].toString(); QString name_id = tag_obj["id"].toString();

View File

@ -130,7 +130,9 @@ void FeedlyAccountDetails::performTest(const QNetworkProxy& custom_proxy) {
factory.setDeveloperAccessToken(m_ui.m_txtDeveloperAccessToken->lineEdit()->text()); factory.setDeveloperAccessToken(m_ui.m_txtDeveloperAccessToken->lineEdit()->text());
try { 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, m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Ok,
tr("Login was successful."), tr("Login was successful."),
tr("Access granted.")); tr("Access granted."));