clazy refactoring, need to finish it later

This commit is contained in:
Martin Rotter 2021-03-17 14:31:22 +01:00
parent 95892001f6
commit aa18d074a3
19 changed files with 80 additions and 63 deletions

View file

@ -226,7 +226,7 @@ void FeedDownloader::updateOneFeed(Feed* feed) {
} }
// Process changed labels. // Process changed labels.
for (Label* lbl : msg_backup.m_assignedLabels) { for (Label* lbl : qAsConst(msg_backup.m_assignedLabels)) {
if (!msg_orig->m_assignedLabels.contains(lbl)) { if (!msg_orig->m_assignedLabels.contains(lbl)) {
// Label is not there anymore, it was deassigned. // Label is not there anymore, it was deassigned.
lbl->deassignFromMessage(*msg_orig); lbl->deassignFromMessage(*msg_orig);
@ -238,7 +238,7 @@ void FeedDownloader::updateOneFeed(Feed* feed) {
} }
} }
for (Label* lbl : msg_orig->m_assignedLabels) { for (Label* lbl : qAsConst(msg_orig->m_assignedLabels)) {
if (!msg_backup.m_assignedLabels.contains(lbl)) { if (!msg_backup.m_assignedLabels.contains(lbl)) {
// Label is in new message, but is not in old message, it // Label is in new message, but is not in old message, it
// was newly assigned. // was newly assigned.

View file

@ -3,9 +3,9 @@
#include "core/feedsmodel.h" #include "core/feedsmodel.h"
#include "3rd-party/boolinq/boolinq.h" #include "3rd-party/boolinq/boolinq.h"
#include "database/databasefactory.h"
#include "definitions/definitions.h" #include "definitions/definitions.h"
#include "gui/dialogs/formmain.h" #include "gui/dialogs/formmain.h"
#include "database/databasefactory.h"
#include "miscellaneous/feedreader.h" #include "miscellaneous/feedreader.h"
#include "miscellaneous/iconfactory.h" #include "miscellaneous/iconfactory.h"
#include "miscellaneous/textfactory.h" #include "miscellaneous/textfactory.h"
@ -292,8 +292,9 @@ void FeedsModel::reassignNodeToNewParent(RootItem* original_node, RootItem* new_
QList<ServiceRoot*>FeedsModel::serviceRoots() const { QList<ServiceRoot*>FeedsModel::serviceRoots() const {
QList<ServiceRoot*> roots; QList<ServiceRoot*> roots;
auto ch = m_rootItem->childItems();
for (RootItem* root : m_rootItem->childItems()) { for (RootItem* root : qAsConst(ch)) {
if (root->kind() == RootItem::Kind::ServiceRoot) { if (root->kind() == RootItem::Kind::ServiceRoot) {
roots.append(root->toServiceRoot()); roots.append(root->toServiceRoot());
} }
@ -304,8 +305,9 @@ QList<ServiceRoot*>FeedsModel::serviceRoots() const {
QList<Feed*>FeedsModel::feedsForScheduledUpdate(bool auto_update_now) { QList<Feed*>FeedsModel::feedsForScheduledUpdate(bool auto_update_now) {
QList<Feed*>feeds_for_update; QList<Feed*>feeds_for_update;
auto stf = m_rootItem->getSubTreeFeeds();
for (Feed* feed : m_rootItem->getSubTreeFeeds()) { for (Feed* feed : qAsConst(stf)) {
switch (feed->autoUpdateType()) { switch (feed->autoUpdateType()) {
case Feed::AutoUpdateType::DontAutoUpdate: case Feed::AutoUpdateType::DontAutoUpdate:
@ -489,8 +491,9 @@ bool FeedsModel::addServiceAccount(ServiceRoot* root, bool freshly_activated) {
bool FeedsModel::restoreAllBins() { bool FeedsModel::restoreAllBins() {
bool result = true; bool result = true;
auto srts = serviceRoots();
for (ServiceRoot* root : serviceRoots()) { for (ServiceRoot* root : qAsConst(srts)) {
RecycleBin* bin_of_root = root->recycleBin(); RecycleBin* bin_of_root = root->recycleBin();
if (bin_of_root != nullptr) { if (bin_of_root != nullptr) {
@ -503,8 +506,9 @@ bool FeedsModel::restoreAllBins() {
bool FeedsModel::emptyAllBins() { bool FeedsModel::emptyAllBins() {
bool result = true; bool result = true;
auto srts = serviceRoots();
for (ServiceRoot* root : serviceRoots()) { for (ServiceRoot* root : qAsConst(srts)) {
RecycleBin* bin_of_root = root->recycleBin(); RecycleBin* bin_of_root = root->recycleBin();
if (bin_of_root != nullptr) { if (bin_of_root != nullptr) {
@ -516,8 +520,10 @@ bool FeedsModel::emptyAllBins() {
} }
void FeedsModel::loadActivatedServiceAccounts() { void FeedsModel::loadActivatedServiceAccounts() {
auto serv = qApp->feedReader()->feedServices();
// Iterate all globally available feed "service plugins". // Iterate all globally available feed "service plugins".
for (const ServiceEntryPoint* entry_point : qApp->feedReader()->feedServices()) { for (const ServiceEntryPoint* entry_point : qAsConst(serv)) {
// Load all stored root nodes from the entry point and add those to the model. // Load all stored root nodes from the entry point and add those to the model.
QList<ServiceRoot*> roots = entry_point->initializeSubtree(); QList<ServiceRoot*> roots = entry_point->initializeSubtree();
@ -534,7 +540,9 @@ void FeedsModel::loadActivatedServiceAccounts() {
} }
void FeedsModel::stopServiceAccounts() { void FeedsModel::stopServiceAccounts() {
for (ServiceRoot* account : serviceRoots()) { auto serv = serviceRoots();
for (ServiceRoot* account : qAsConst(serv)) {
account->stop(); account->stop();
} }
} }

View file

@ -20,13 +20,14 @@ Enclosure::Enclosure(QString url, QString mime) : m_url(std::move(url)), m_mimeT
QList<Enclosure> Enclosures::decodeEnclosuresFromString(const QString& enclosures_data) { QList<Enclosure> Enclosures::decodeEnclosuresFromString(const QString& enclosures_data) {
QList<Enclosure> enclosures; QList<Enclosure> enclosures;
auto enc = enclosures_data.split(ENCLOSURES_OUTER_SEPARATOR,
for (const QString& single_enclosure : enclosures_data.split(ENCLOSURES_OUTER_SEPARATOR,
#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& single_enclosure : qAsConst(enc)) {
Enclosure enclosure; Enclosure enclosure;
if (single_enclosure.contains(ECNLOSURES_INNER_SEPARATOR)) { if (single_enclosure.contains(ECNLOSURES_INNER_SEPARATOR)) {

View file

@ -22,7 +22,7 @@ bool MessageObject::isDuplicateWithAttribute(MessageObject::DuplicationAttribute
// Check database according to duplication attribute_check. // Check database according to duplication attribute_check.
QSqlQuery q(*m_db); QSqlQuery q(*m_db);
QStringList where_clauses; QStringList where_clauses;
QList<QPair<QString, QVariant>> bind_values; QVector<QPair<QString, QVariant>> bind_values;
// Now we construct the query according to parameter. // Now we construct the query according to parameter.
if ((attribute_check& DuplicationAttributeCheck::SameTitle) == DuplicationAttributeCheck::SameTitle) { if ((attribute_check& DuplicationAttributeCheck::SameTitle) == DuplicationAttributeCheck::SameTitle) {

View file

@ -70,7 +70,7 @@ class MessageObject : public QObject {
// Check if message is duplicate with another messages in DB. // Check if message is duplicate with another messages in DB.
// Parameter "attribute_check" is DuplicationAttributeCheck enum // Parameter "attribute_check" is DuplicationAttributeCheck enum
// value casted to int. // value casted to int.
Q_INVOKABLE bool isDuplicateWithAttribute(DuplicationAttributeCheck attribute_check) const; Q_INVOKABLE bool isDuplicateWithAttribute(MessageObject::DuplicationAttributeCheck attribute_check) const;
// Adds given label to list of assigned labels to this message. // Adds given label to list of assigned labels to this message.
// Returns true if label was assigned now or if the message already has it assigned. // Returns true if label was assigned now or if the message already has it assigned.

View file

@ -48,7 +48,7 @@ void DatabaseFactory::determineDriver() {
if (m_dbDriver->driverType() != DatabaseDriver::DriverType::SQLite) { if (m_dbDriver->driverType() != DatabaseDriver::DriverType::SQLite) {
// Try to setup connection and fallback to SQLite. // Try to setup connection and fallback to SQLite.
try { try {
m_dbDriver->connection(metaObject()->className()); m_dbDriver->connection(QSL("DatabaseFactory"));
} }
catch (const ApplicationException& ex) { catch (const ApplicationException& ex) {
qCriticalNN << LOGSEC_DB qCriticalNN << LOGSEC_DB

View file

@ -598,8 +598,6 @@ int DatabaseQueries::getMessageCountsForLabel(const QSqlDatabase& db, Label* lab
return q.value(0).toInt(); return q.value(0).toInt();
} }
else { else {
auto aa = q.lastError().text();
if (ok != nullptr) { if (ok != nullptr) {
*ok = false; *ok = false;
} }
@ -877,8 +875,6 @@ QList<Message> DatabaseQueries::getUndeletedMessagesForAccount(const QSqlDatabas
} }
} }
else { else {
auto aa = q.lastError().text();
if (ok != nullptr) { if (ok != nullptr) {
*ok = false; *ok = false;
} }
@ -1268,7 +1264,7 @@ bool DatabaseQueries::deleteAccount(const QSqlDatabase& db, int account_id) {
<< QSL("DELETE FROM Labels WHERE account_id = :account_id;") << QSL("DELETE FROM Labels WHERE account_id = :account_id;")
<< QSL("DELETE FROM Accounts WHERE id = :account_id;"); << QSL("DELETE FROM Accounts WHERE id = :account_id;");
for (const QString& q : queries) { for (const QString& q : qAsConst(queries)) {
query.prepare(q); query.prepare(q);
query.bindValue(QSL(":account_id"), account_id); query.bindValue(QSL(":account_id"), account_id);
@ -1483,8 +1479,6 @@ bool DatabaseQueries::purgeLeftoverLabelAssignments(const QSqlDatabase& db, int
} }
if (!succ) { if (!succ) {
auto xx = q.lastError().text();
qWarningNN << LOGSEC_DB qWarningNN << LOGSEC_DB
<< "Removing of leftover label assignments failed: '" << "Removing of leftover label assignments failed: '"
<< q.lastError().text() << q.lastError().text()
@ -1509,11 +1503,10 @@ bool DatabaseQueries::purgeLabelsAndLabelAssignments(const QSqlDatabase& db, int
} }
bool DatabaseQueries::storeAccountTree(const QSqlDatabase& db, RootItem* tree_root, int account_id) { bool DatabaseQueries::storeAccountTree(const QSqlDatabase& db, RootItem* tree_root, int account_id) {
QSqlQuery query_category(db);
QSqlQuery query_feed(db);
// Iterate all children. // Iterate all children.
for (RootItem* child : tree_root->getSubTree()) { auto str = tree_root->getSubTree();
for (RootItem* child : qAsConst(str)) {
if (child->kind() == RootItem::Kind::Category) { if (child->kind() == RootItem::Kind::Category) {
createOverwriteCategory(db, child->toCategory(), account_id, child->parent()->id()); createOverwriteCategory(db, child->toCategory(), account_id, child->parent()->id());
} }
@ -1522,7 +1515,9 @@ bool DatabaseQueries::storeAccountTree(const QSqlDatabase& db, RootItem* tree_ro
} }
else if (child->kind() == RootItem::Kind::Labels) { else if (child->kind() == RootItem::Kind::Labels) {
// Add all labels. // Add all labels.
for (RootItem* lbl : child->childItems()) { auto ch = child->childItems();
for (RootItem* lbl : qAsConst(ch)) {
Label* label = lbl->toLabel(); Label* label = lbl->toLabel();
if (!createLabel(db, label, account_id)) { if (!createLabel(db, label, account_id)) {
@ -1733,8 +1728,6 @@ void DatabaseQueries::createOverwriteFeed(const QSqlDatabase& db, Feed* feed, in
q.bindValue(QSL(":custom_data"), serialized_custom_data); q.bindValue(QSL(":custom_data"), serialized_custom_data);
if (!q.exec()) { if (!q.exec()) {
auto xx = q.lastError().text();
throw ApplicationException(q.lastError().text()); throw ApplicationException(q.lastError().text());
} }
} }

View file

@ -41,7 +41,7 @@ bool DynamicShortcutsWidget::areShortcutsUnique() const {
} }
void DynamicShortcutsWidget::updateShortcuts() { void DynamicShortcutsWidget::updateShortcuts() {
for (const ActionBinding& binding : m_actionBindings) { for (const ActionBinding& binding : qAsConst(m_actionBindings)) {
binding.first->setShortcut(binding.second->shortcut()); binding.first->setShortcut(binding.second->shortcut());
} }
} }

View file

@ -58,7 +58,7 @@ ServiceEntryPoint* FormAddAccount::selectedEntryPoint() const {
} }
void FormAddAccount::loadEntryPoints() { void FormAddAccount::loadEntryPoints() {
for (const ServiceEntryPoint* entry_point : m_entryPoints) { for (const ServiceEntryPoint* entry_point : qAsConst(m_entryPoints)) {
QListWidgetItem* item = new QListWidgetItem(entry_point->icon(), entry_point->name(), m_ui->m_listEntryPoints); QListWidgetItem* item = new QListWidgetItem(entry_point->icon(), entry_point->name(), m_ui->m_listEntryPoints);
item->setToolTip(entry_point->description()); item->setToolTip(entry_point->description());

View file

@ -2,6 +2,7 @@
#include "gui/dialogs/formmain.h" #include "gui/dialogs/formmain.h"
#include "database/databasefactory.h"
#include "definitions/definitions.h" #include "definitions/definitions.h"
#include "gui/dialogs/formabout.h" #include "gui/dialogs/formabout.h"
#include "gui/dialogs/formaddaccount.h" #include "gui/dialogs/formaddaccount.h"
@ -22,7 +23,6 @@
#include "gui/systemtrayicon.h" #include "gui/systemtrayicon.h"
#include "gui/tabbar.h" #include "gui/tabbar.h"
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include "database/databasefactory.h"
#include "miscellaneous/feedreader.h" #include "miscellaneous/feedreader.h"
#include "miscellaneous/iconfactory.h" #include "miscellaneous/iconfactory.h"
#include "miscellaneous/mutex.h" #include "miscellaneous/mutex.h"
@ -257,7 +257,9 @@ void FormMain::updateAddItemMenu() {
// NOTE: Clear here deletes items from memory but only those OWNED by the menu. // NOTE: Clear here deletes items from memory but only those OWNED by the menu.
m_ui->m_menuAddItem->clear(); m_ui->m_menuAddItem->clear();
for (ServiceRoot* activated_root : qApp->feedReader()->feedsModel()->serviceRoots()) { auto srts = qApp->feedReader()->feedsModel()->serviceRoots();
for (ServiceRoot* activated_root : qAsConst(srts)) {
QMenu* root_menu = new QMenu(activated_root->title(), m_ui->m_menuAddItem); QMenu* root_menu = new QMenu(activated_root->title(), m_ui->m_menuAddItem);
root_menu->setIcon(activated_root->icon()); root_menu->setIcon(activated_root->icon());
@ -312,7 +314,9 @@ void FormMain::updateAddItemMenu() {
void FormMain::updateRecycleBinMenu() { void FormMain::updateRecycleBinMenu() {
m_ui->m_menuRecycleBin->clear(); m_ui->m_menuRecycleBin->clear();
for (const ServiceRoot* activated_root : qApp->feedReader()->feedsModel()->serviceRoots()) { auto srts = qApp->feedReader()->feedsModel()->serviceRoots();
for (const ServiceRoot* activated_root : qAsConst(srts)) {
QMenu* root_menu = new QMenu(activated_root->title(), m_ui->m_menuRecycleBin); QMenu* root_menu = new QMenu(activated_root->title(), m_ui->m_menuRecycleBin);
root_menu->setIcon(activated_root->icon()); root_menu->setIcon(activated_root->icon());
@ -354,7 +358,9 @@ void FormMain::updateRecycleBinMenu() {
void FormMain::updateAccountsMenu() { void FormMain::updateAccountsMenu() {
m_ui->m_menuAccounts->clear(); m_ui->m_menuAccounts->clear();
for (ServiceRoot* activated_root : qApp->feedReader()->feedsModel()->serviceRoots()) { auto srts = qApp->feedReader()->feedsModel()->serviceRoots();
for (ServiceRoot* activated_root : srts) {
QMenu* root_menu = new QMenu(activated_root->title(), m_ui->m_menuAccounts); QMenu* root_menu = new QMenu(activated_root->title(), m_ui->m_menuAccounts);
root_menu->setIcon(activated_root->icon()); root_menu->setIcon(activated_root->icon());

View file

@ -9,11 +9,11 @@
#include "3rd-party/boolinq/boolinq.h" #include "3rd-party/boolinq/boolinq.h"
#include "core/messagefilter.h" #include "core/messagefilter.h"
#include "core/messagesforfiltersmodel.h" #include "core/messagesforfiltersmodel.h"
#include "database/databasequeries.h"
#include "exceptions/filteringexception.h" #include "exceptions/filteringexception.h"
#include "gui/guiutilities.h" #include "gui/guiutilities.h"
#include "gui/messagebox.h" #include "gui/messagebox.h"
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include "database/databasequeries.h"
#include "miscellaneous/feedreader.h" #include "miscellaneous/feedreader.h"
#include "miscellaneous/iconfactory.h" #include "miscellaneous/iconfactory.h"
#include "network-web/webfactory.h" #include "network-web/webfactory.h"
@ -157,7 +157,9 @@ void FormMessageFiltersManager::removeSelectedFilter() {
} }
void FormMessageFiltersManager::loadFilters() { void FormMessageFiltersManager::loadFilters() {
for (auto* fltr : m_reader->messageFilters()) { auto flt = m_reader->messageFilters();
for (auto* fltr : qAsConst(flt)) {
auto* it = new QListWidgetItem(fltr->name(), m_ui.m_listFilters); auto* it = new QListWidgetItem(fltr->name(), m_ui.m_listFilters);
it->setData(Qt::ItemDataRole::UserRole, QVariant::fromValue<MessageFilter*>(fltr)); it->setData(Qt::ItemDataRole::UserRole, QVariant::fromValue<MessageFilter*>(fltr));
@ -344,7 +346,7 @@ void FormMessageFiltersManager::processCheckedFeeds() {
} }
// Process changed labels. // Process changed labels.
for (Label* lbl : msg_backup.m_assignedLabels) { for (Label* lbl : qAsConst(msg_backup.m_assignedLabels)) {
if (!msg->m_assignedLabels.contains(lbl)) { if (!msg->m_assignedLabels.contains(lbl)) {
// Label is not there anymore, it was deassigned. // Label is not there anymore, it was deassigned.
lbl->deassignFromMessage(*msg); lbl->deassignFromMessage(*msg);
@ -356,7 +358,7 @@ void FormMessageFiltersManager::processCheckedFeeds() {
} }
} }
for (Label* lbl : msg->m_assignedLabels) { for (Label* lbl : qAsConst(msg->m_assignedLabels)) {
if (!msg_backup.m_assignedLabels.contains(lbl)) { if (!msg_backup.m_assignedLabels.contains(lbl)) {
// Label is in new message, but is not in old message, it // Label is in new message, but is not in old message, it
// was newly assigned. // was newly assigned.
@ -428,8 +430,9 @@ void FormMessageFiltersManager::loadFilterFeedAssignments(MessageFilter* filter,
} }
m_loadingFilter = true; m_loadingFilter = true;
auto stf = account->getSubTreeFeeds();
for (auto* feed : account->getSubTreeFeeds()) { for (auto* feed : qAsConst(stf)) {
if (feed->messageFilters().contains(filter)) { if (feed->messageFilters().contains(filter)) {
m_feedsModel->sourceModel()->setItemChecked(feed, Qt::CheckState::Checked); m_feedsModel->sourceModel()->setItemChecked(feed, Qt::CheckState::Checked);
} }
@ -503,10 +506,8 @@ void FormMessageFiltersManager::showFilter(MessageFilter* filter) {
} }
void FormMessageFiltersManager::loadAccounts() { void FormMessageFiltersManager::loadAccounts() {
for (auto* acc : m_accounts) { for (auto* acc : qAsConst(m_accounts)) {
m_ui.m_cmbAccounts->addItem(acc->icon(), m_ui.m_cmbAccounts->addItem(acc->icon(), acc->title(), QVariant::fromValue(acc));
acc->title(),
QVariant::fromValue(acc));
} }
} }

View file

@ -56,7 +56,7 @@ void FormSettings::applySettings() {
m_settings.checkSettings(); m_settings.checkSettings();
QStringList panels_for_restart; QStringList panels_for_restart;
for (SettingsPanel* panel : m_panels) { for (SettingsPanel* panel : qAsConst(m_panels)) {
if (panel->isDirty()) { if (panel->isDirty()) {
panel->saveSettings(); panel->saveSettings();
} }
@ -94,7 +94,7 @@ void FormSettings::applySettings() {
void FormSettings::cancelSettings() { void FormSettings::cancelSettings() {
QStringList changed_panels; QStringList changed_panels;
for (SettingsPanel* panel : m_panels) { for (SettingsPanel* panel : qAsConst(m_panels)) {
if (panel->isDirty()) { if (panel->isDirty()) {
changed_panels.append(panel->title().toLower()); changed_panels.append(panel->title().toLower());
} }

View file

@ -148,7 +148,7 @@ void FormUpdate::saveUpdateFile(const QByteArray& file_contents) {
void FormUpdate::loadAvailableFiles() { void FormUpdate::loadAvailableFiles() {
m_ui.m_listFiles->clear(); m_ui.m_listFiles->clear();
for (const UpdateUrl& url : m_updateInfo.m_urls) { for (const UpdateUrl& url : qAsConst(m_updateInfo.m_urls)) {
if (SystemFactory::supportedUpdateFiles().match(url.m_name).hasMatch()) { if (SystemFactory::supportedUpdateFiles().match(url.m_name).hasMatch()) {
QListWidgetItem* item = new QListWidgetItem(url.m_name + tr(" (size ") + url.m_size + QSL(")")); QListWidgetItem* item = new QListWidgetItem(url.m_name + tr(" (size ") + url.m_size + QSL(")"));

View file

@ -60,12 +60,13 @@ void DiscoverFeedsButton::linkTriggered(QAction* action) {
void DiscoverFeedsButton::fillMenu() { void DiscoverFeedsButton::fillMenu() {
menu()->clear(); menu()->clear();
auto srts = qApp->feedReader()->feedsModel()->serviceRoots();
for (const ServiceRoot* root : qApp->feedReader()->feedsModel()->serviceRoots()) { for (const ServiceRoot* root : qAsConst(srts)) {
if (root->supportsFeedAdding()) { if (root->supportsFeedAdding()) {
QMenu* root_menu = menu()->addMenu(root->icon(), root->title()); QMenu* root_menu = menu()->addMenu(root->icon(), root->title());
for (const QString& url : m_addresses) { for (const QString& url : qAsConst(m_addresses)) {
QAction* url_action = root_menu->addAction(root->icon(), url); QAction* url_action = root_menu->addAction(root->icon(), url);
url_action->setProperty("url", url); url_action->setProperty("url", url);

View file

@ -717,7 +717,7 @@ void FeedsView::selectionChanged(const QItemSelection& selected, const QItemSele
if (!selectedIndexes().isEmpty() && if (!selectedIndexes().isEmpty() &&
qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::AutoExpandOnSelection)).toBool()) { qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::AutoExpandOnSelection)).toBool()) {
expand(selectedIndexes().first()); expand(selectedIndexes().constFirst());
} }
} }

View file

@ -3,8 +3,8 @@
#include "gui/labelsmenu.h" #include "gui/labelsmenu.h"
#include "3rd-party/boolinq/boolinq.h" #include "3rd-party/boolinq/boolinq.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 <QCheckBox> #include <QCheckBox>
@ -22,7 +22,7 @@ LabelsMenu::LabelsMenu(const QList<Message>& messages, const QList<Label*>& labe
addAction(act_not_labels); addAction(act_not_labels);
} }
else { else {
QSqlDatabase db = qApp->database()->driver()->connection(metaObject()->className()); QSqlDatabase db = qApp->database()->driver()->connection(QSL("LabelsMenu"));
for (Label* label: boolinq::from(labels).orderBy([](const Label* label) { for (Label* label: boolinq::from(labels).orderBy([](const Label* label) {
return label->title().toLower(); return label->title().toLower();
@ -73,13 +73,13 @@ void LabelsMenu::changeLabelAssignment(Qt::CheckState state) {
if (origin != nullptr) { if (origin != nullptr) {
if (state == Qt::CheckState::Checked) { if (state == Qt::CheckState::Checked) {
// Assign this label to selected messages. // Assign this label to selected messages.
for (const auto& msg : m_messages) { for (const auto& msg : qAsConst(m_messages)) {
origin->label()->assignToMessage(msg); origin->label()->assignToMessage(msg);
} }
} }
else if (state == Qt::CheckState::Unchecked) { else if (state == Qt::CheckState::Unchecked) {
// Remove label from selected messages. // Remove label from selected messages.
for (const auto& msg : m_messages) { for (const auto& msg : qAsConst(m_messages)) {
origin->label()->deassignFromMessage(msg); origin->label()->deassignFromMessage(msg);
} }
} }
@ -140,7 +140,7 @@ void LabelAction::updateActionForState() {
break; break;
case Qt::CheckState::PartiallyChecked: case Qt::CheckState::PartiallyChecked:
highlight = QColor("#ff8c00"); highlight = QColor(100, 50, 0);
break; break;
case Qt::CheckState::Unchecked: case Qt::CheckState::Unchecked:

View file

@ -231,8 +231,9 @@ void MessagePreviewer::updateLabels(bool only_clear) {
if (m_root.data() != nullptr && !m_root.data()->getParentServiceRoot()->labelsNode()->labels().isEmpty()) { if (m_root.data() != nullptr && !m_root.data()->getParentServiceRoot()->labelsNode()->labels().isEmpty()) {
m_separator = m_toolBar->addSeparator(); m_separator = m_toolBar->addSeparator();
QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className()); QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className());
auto lbls = m_root.data()->getParentServiceRoot()->labelsNode()->labels();
for (auto* label : m_root.data()->getParentServiceRoot()->labelsNode()->labels()) { for (auto* label : lbls) {
LabelButton* btn_label = new LabelButton(this); LabelButton* btn_label = new LabelButton(this);
btn_label->setLabel(label); btn_label->setLabel(label);

View file

@ -209,10 +209,11 @@ void MessagesView::initializeContextMenu() {
// External tools. // External tools.
QFileIconProvider icon_provider; QFileIconProvider icon_provider;
QMenu* menu_ext_tools = new QMenu(tr("Open with external tool"), m_contextMenu); QMenu* menu_ext_tools = new QMenu(tr("Open with external tool"), m_contextMenu);
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()));
@ -375,7 +376,9 @@ void MessagesView::switchShowUnreadOnly(bool set_new_value, bool show_unread_onl
} }
void MessagesView::openSelectedSourceMessagesExternally() { void MessagesView::openSelectedSourceMessagesExternally() {
for (const QModelIndex& index : selectionModel()->selectedRows()) { auto rws = selectionModel()->selectedRows();
for (const QModelIndex& index : qAsConst(rws)) {
QString link = m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row()) QString link = m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row())
.m_url .m_url
.replace(QRegularExpression("[\\t\\n]"), QString()); .replace(QRegularExpression("[\\t\\n]"), QString());
@ -397,8 +400,9 @@ void MessagesView::openSelectedSourceMessagesExternally() {
void MessagesView::openSelectedMessagesInternally() { void MessagesView::openSelectedMessagesInternally() {
QList<Message> messages; QList<Message> messages;
auto rws = selectionModel()->selectedRows();
for (const QModelIndex& index : selectionModel()->selectedRows()) { for (const QModelIndex& index : qAsConst(rws)) {
messages << m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row()); messages << m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row());
} }
@ -591,8 +595,9 @@ void MessagesView::openSelectedMessagesWithExternalTool() {
if (sndr != nullptr) { if (sndr != nullptr) {
auto tool = sndr->data().value<ExternalTool>(); auto tool = sndr->data().value<ExternalTool>();
auto rws = selectionModel()->selectedRows();
for (const QModelIndex& index : selectionModel()->selectedRows()) { for (const QModelIndex& index : qAsConst(rws)) {
const QString link = m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row()) const QString link = m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row())
.m_url .m_url
.replace(QRegularExpression("[\\t\\n]"), QString()); .replace(QRegularExpression("[\\t\\n]"), QString());

View file

@ -92,8 +92,9 @@ void SettingsFeedsMessages::initializeMessageDateFormats() {
QStringList best_formats; QStringList best_formats;
const QDateTime current_dt = QDateTime::currentDateTime(); const QDateTime current_dt = QDateTime::currentDateTime();
const QLocale current_locale = qApp->localization()->loadedLocale(); const QLocale current_locale = qApp->localization()->loadedLocale();
auto installed_languages = qApp->localization()->installedLanguages();
for (const Language& lang : qApp->localization()->installedLanguages()) { for (const Language& lang : qAsConst(installed_languages)) {
QLocale locale(lang.m_code); QLocale locale(lang.m_code);
best_formats << locale.dateTimeFormat(QLocale::LongFormat) best_formats << locale.dateTimeFormat(QLocale::LongFormat)
@ -103,7 +104,7 @@ void SettingsFeedsMessages::initializeMessageDateFormats() {
best_formats.removeDuplicates(); best_formats.removeDuplicates();
for (const QString& format : best_formats) { for (const QString& format : qAsConst(best_formats)) {
m_ui->m_cmbMessagesDateTimeFormat->addItem(current_locale.toString(current_dt, format), format); m_ui->m_cmbMessagesDateTimeFormat->addItem(current_locale.toString(current_dt, format), format);
} }
} }