refactorings

This commit is contained in:
Martin Rotter 2021-08-25 13:59:37 +02:00
parent a0215dcbf0
commit dbb59e49ea
39 changed files with 303 additions and 294 deletions

View File

@ -864,7 +864,7 @@ or this functionality is not implemented yet.</source>
<name>FormAccountDetails</name>
<message>
<source>Edit account &apos;%1&apos;</source>
<translation>Updavit účet &apos;%1&apos;</translation>
<translation>Upravit účet &apos;%1&apos;</translation>
</message>
<message>
<source>Network proxy</source>

View File

@ -65,7 +65,7 @@ QString Enclosures::encodeEnclosuresToString(const QList<Enclosure>& enclosures)
}
Message::Message() {
m_title = m_url = m_author = m_contents = m_rawContents = m_feedId = m_customId = m_customHash = "";
m_title = m_url = m_author = m_contents = m_rawContents = m_feedId = m_customId = m_customHash = QSL("");
m_enclosures = QList<Enclosure>();
m_accountId = m_id = 0;
m_score = 0.0;
@ -88,7 +88,7 @@ void Message::sanitize(const Feed* feed) {
// Check if messages contain relative URLs and if they do, then replace them.
if (m_url.startsWith(QL1S("//"))) {
m_url = QString(URI_SCHEME_HTTPS) + m_url.mid(2);
m_url = QSL(URI_SCHEME_HTTPS) + m_url.mid(2);
}
else if (QUrl(m_url).isRelative()) {
QUrl base(feed->source());

View File

@ -59,10 +59,10 @@ void MessageFilter::initializeFilteringEngine(QJSEngine& engine, MessageObject*
// Register the wrapper.
auto js_object = engine.newQObject(message_wrapper);
auto js_meta_object = engine.newQMetaObject(&message_wrapper->staticMetaObject);
auto js_meta_object = engine.newQMetaObject(&MessageObject::staticMetaObject);
engine.globalObject().setProperty(QSL("msg"), js_object);
engine.globalObject().setProperty(message_wrapper->staticMetaObject.className(), js_meta_object);
engine.globalObject().setProperty(MessageObject::staticMetaObject.className(), js_meta_object);
// Register "utils".
auto* utils = new FilterUtils(&engine);

View File

@ -9,7 +9,7 @@
#include <QSqlQuery>
MessageObject::MessageObject(QSqlDatabase* db, const QString& feed_custom_id, int account_id,
QList<Label*> available_labels, bool is_new_message, QObject* parent)
const QList<Label*>& available_labels, bool is_new_message, QObject* parent)
: QObject(parent), m_db(db), m_feedCustomId(feed_custom_id), m_accountId(account_id), m_message(nullptr),
m_availableLabels(available_labels), m_runningAfterFetching(is_new_message) {}
@ -26,31 +26,31 @@ bool MessageObject::isDuplicateWithAttribute(MessageObject::DuplicationAttribute
// Now we construct the query according to parameter.
if ((attribute_check& DuplicationAttributeCheck::SameTitle) == DuplicationAttributeCheck::SameTitle) {
where_clauses.append(QSL("title = :title"));
bind_values.append({ ":title", title() });
bind_values.append({ QSL(":title"), title() });
}
if ((attribute_check& DuplicationAttributeCheck::SameUrl) == DuplicationAttributeCheck::SameUrl) {
where_clauses.append(QSL("url = :url"));
bind_values.append({ ":url", url() });
bind_values.append({ QSL(":url"), url() });
}
if ((attribute_check& DuplicationAttributeCheck::SameAuthor) == DuplicationAttributeCheck::SameAuthor) {
where_clauses.append(QSL("author = :author"));
bind_values.append({ ":author", author() });
bind_values.append({ QSL(":author"), author() });
}
if ((attribute_check& DuplicationAttributeCheck::SameDateCreated) == DuplicationAttributeCheck::SameDateCreated) {
where_clauses.append(QSL("date_created = :date_created"));
bind_values.append({ ":date_created", created().toMSecsSinceEpoch() });
bind_values.append({ QSL(":date_created"), created().toMSecsSinceEpoch() });
}
where_clauses.append(QSL("account_id = :account_id"));
bind_values.append({ ":account_id", accountId() });
bind_values.append({ QSL(":account_id"), accountId() });
if ((attribute_check& DuplicationAttributeCheck::AllFeedsSameAccount) != DuplicationAttributeCheck::AllFeedsSameAccount) {
// Limit to current feed.
where_clauses.append(QSL("feed = :feed"));
bind_values.append({ ":feed", feedCustomId() });
bind_values.append({ QSL(":feed"), feedCustomId() });
}
QString full_query = QSL("SELECT COUNT(*) FROM Messages WHERE ") + where_clauses.join(QSL(" AND ")) + QSL(";");
@ -87,7 +87,7 @@ bool MessageObject::isDuplicateWithAttribute(MessageObject::DuplicationAttribute
return false;
}
bool MessageObject::assignLabel(QString label_custom_id) const {
bool MessageObject::assignLabel(const QString& label_custom_id) const {
if (m_message->m_id <= 0 && m_message->m_customId.isEmpty()) {
return false;
}
@ -108,7 +108,7 @@ bool MessageObject::assignLabel(QString label_custom_id) const {
}
}
bool MessageObject::deassignLabel(QString label_custom_id) const {
bool MessageObject::deassignLabel(const QString& label_custom_id) const {
if (m_message->m_id <= 0 && m_message->m_customId.isEmpty()) {
return false;
}

View File

@ -64,7 +64,7 @@ class MessageObject : public QObject {
explicit MessageObject(QSqlDatabase* db,
const QString& feed_custom_id,
int account_id,
QList<Label*> available_labels,
const QList<Label*>& available_labels,
bool is_new_message,
QObject* parent = nullptr);
@ -77,11 +77,11 @@ class MessageObject : public QObject {
// 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.
Q_INVOKABLE bool assignLabel(QString label_custom_id) const;
Q_INVOKABLE bool assignLabel(const QString& label_custom_id) const;
// Removes given label from list of assigned labels of this message.
// Returns true if label was now removed or if it is not assigned to the message at all.
Q_INVOKABLE bool deassignLabel(QString label_custom_id) const;
Q_INVOKABLE bool deassignLabel(const QString& label_custom_id) const;
// Returns list of assigned and available messages.
QList<Label*> assignedLabels() const;

View File

@ -41,8 +41,8 @@ void MessagesModel::setupIcons() {
m_unreadIcon = qApp->icons()->fromTheme(QSL("mail-mark-unread"));
m_enclosuresIcon = qApp->icons()->fromTheme(QSL("mail-attachment"));
for (double i = MSG_SCORE_MIN; i <= MSG_SCORE_MAX; i += 10.0) {
m_scoreIcons.append(generateIconForScore(i));
for (int i = int(MSG_SCORE_MIN); i <= int(MSG_SCORE_MAX); i += 10) {
m_scoreIcons.append(generateIconForScore(double(i)));
}
}
@ -271,8 +271,8 @@ Qt::ItemFlags MessagesModel::flags(const QModelIndex& index) const {
return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemNeverHasChildren;
}
QList<Message> MessagesModel::messagesAt(QList<int> row_indices) const {
QList<Message> msgs;
QList<Message> MessagesModel::messagesAt(const QList<int>& row_indices) const {
QList<Message> msgs; msgs.reserve(row_indices.size());
for (int idx : row_indices) {
msgs << messageAt(idx);
@ -537,8 +537,8 @@ bool MessagesModel::switchMessageImportance(int row_index) {
}
bool MessagesModel::switchBatchMessageImportance(const QModelIndexList& messages) {
QStringList message_ids;
QList<QPair<Message, RootItem::Importance>> message_states;
QStringList message_ids; message_ids.reserve(messages.size());
QList<QPair<Message, RootItem::Importance>> message_states; message_states.reserve(messages.size());
// Obtain IDs of all desired messages.
for (const QModelIndex& message : messages) {
@ -572,8 +572,8 @@ bool MessagesModel::switchBatchMessageImportance(const QModelIndexList& messages
}
bool MessagesModel::setBatchMessagesDeleted(const QModelIndexList& messages) {
QStringList message_ids;
QList<Message> msgs;
QStringList message_ids; message_ids.reserve(messages.size());
QList<Message> msgs; msgs.reserve(messages.size());
// Obtain IDs of all desired messages.
for (const QModelIndex& message : messages) {
@ -614,8 +614,8 @@ bool MessagesModel::setBatchMessagesDeleted(const QModelIndexList& messages) {
}
bool MessagesModel::setBatchMessagesRead(const QModelIndexList& messages, RootItem::ReadStatus read) {
QStringList message_ids;
QList<Message> msgs;
QStringList message_ids; message_ids.reserve(messages.size());
QList<Message> msgs; msgs.reserve(messages.size());
// Obtain IDs of all desired messages.
for (const QModelIndex& message : messages) {
@ -641,8 +641,8 @@ bool MessagesModel::setBatchMessagesRead(const QModelIndexList& messages, RootIt
}
bool MessagesModel::setBatchMessagesRestored(const QModelIndexList& messages) {
QStringList message_ids;
QList<Message> msgs;
QStringList message_ids; message_ids.reserve(messages.size());
QList<Message> msgs; msgs.reserve(messages.size());
// Obtain IDs of all desired messages.
for (const QModelIndex& message : messages) {

View File

@ -45,7 +45,7 @@ class MessagesModel : public QSqlQueryModel, public MessagesModelSqlLayer {
// Returns message at given index.
QList<Message> messagesAt(QList<int> row_indices) const;
QList<Message> messagesAt(const QList<int>& row_indices) const;
Message messageAt(int row_index) const;
int messageId(int row_index) const;
RootItem::Importance messageImportance(int row_index) const;

View File

@ -15,24 +15,24 @@ MessagesModelSqlLayer::MessagesModelSqlLayer()
m_fieldNames = DatabaseQueries::messageTableAttributes(false);
// Used in <x>: SELECT ... FROM ... ORDER BY <x1> DESC, <x2> ASC;
m_orderByNames[MSG_DB_ID_INDEX] = "Messages.id";
m_orderByNames[MSG_DB_READ_INDEX] = "Messages.is_read";
m_orderByNames[MSG_DB_IMPORTANT_INDEX] = "Messages.is_important";
m_orderByNames[MSG_DB_DELETED_INDEX] = "Messages.is_deleted";
m_orderByNames[MSG_DB_PDELETED_INDEX] = "Messages.is_pdeleted";
m_orderByNames[MSG_DB_FEED_CUSTOM_ID_INDEX] = "Messages.feed";
m_orderByNames[MSG_DB_TITLE_INDEX] = "Messages.title";
m_orderByNames[MSG_DB_URL_INDEX] = "Messages.url";
m_orderByNames[MSG_DB_AUTHOR_INDEX] = "Messages.author";
m_orderByNames[MSG_DB_DCREATED_INDEX] = "Messages.date_created";
m_orderByNames[MSG_DB_CONTENTS_INDEX] = "Messages.contents";
m_orderByNames[MSG_DB_ENCLOSURES_INDEX] = "Messages.enclosures";
m_orderByNames[MSG_DB_SCORE_INDEX] = "Messages.score";
m_orderByNames[MSG_DB_ACCOUNT_ID_INDEX] = "Messages.account_id";
m_orderByNames[MSG_DB_CUSTOM_ID_INDEX] = "Messages.custom_id";
m_orderByNames[MSG_DB_CUSTOM_HASH_INDEX] = "Messages.custom_hash";
m_orderByNames[MSG_DB_FEED_TITLE_INDEX] = "Feeds.title";
m_orderByNames[MSG_DB_HAS_ENCLOSURES] = "has_enclosures";
m_orderByNames[MSG_DB_ID_INDEX] = QSL("Messages.id");
m_orderByNames[MSG_DB_READ_INDEX] = QSL("Messages.is_read");
m_orderByNames[MSG_DB_IMPORTANT_INDEX] = QSL("Messages.is_important");
m_orderByNames[MSG_DB_DELETED_INDEX] = QSL("Messages.is_deleted");
m_orderByNames[MSG_DB_PDELETED_INDEX] = QSL("Messages.is_pdeleted");
m_orderByNames[MSG_DB_FEED_CUSTOM_ID_INDEX] = QSL("Messages.feed");
m_orderByNames[MSG_DB_TITLE_INDEX] = QSL("Messages.title");
m_orderByNames[MSG_DB_URL_INDEX] = QSL("Messages.url");
m_orderByNames[MSG_DB_AUTHOR_INDEX] = QSL("Messages.author");
m_orderByNames[MSG_DB_DCREATED_INDEX] = QSL("Messages.date_created");
m_orderByNames[MSG_DB_CONTENTS_INDEX] = QSL("Messages.contents");
m_orderByNames[MSG_DB_ENCLOSURES_INDEX] = QSL("Messages.enclosures");
m_orderByNames[MSG_DB_SCORE_INDEX] = QSL("Messages.score");
m_orderByNames[MSG_DB_ACCOUNT_ID_INDEX] = QSL("Messages.account_id");
m_orderByNames[MSG_DB_CUSTOM_ID_INDEX] = QSL("Messages.custom_id");
m_orderByNames[MSG_DB_CUSTOM_HASH_INDEX] = QSL("Messages.custom_hash");
m_orderByNames[MSG_DB_FEED_TITLE_INDEX] = QSL("Feeds.title");
m_orderByNames[MSG_DB_HAS_ENCLOSURES] = QSL("has_enclosures");
m_numericColumns << MSG_DB_ID_INDEX << MSG_DB_READ_INDEX << MSG_DB_DELETED_INDEX << MSG_DB_PDELETED_INDEX
<< MSG_DB_IMPORTANT_INDEX << MSG_DB_ACCOUNT_ID_INDEX << MSG_DB_DCREATED_INDEX

View File

@ -211,7 +211,7 @@ void MessagesProxyModel::sort(int column, Qt::SortOrder order) {
}
QModelIndexList MessagesProxyModel::mapListToSource(const QModelIndexList& indexes) const {
QModelIndexList source_indexes;
QModelIndexList source_indexes; source_indexes.reserve(indexes.size());
for (const QModelIndex& index : indexes) {
source_indexes << mapToSource(index);

View File

@ -10,7 +10,7 @@
DatabaseCleaner::DatabaseCleaner(QObject* parent) : QObject(parent) {}
void DatabaseCleaner::purgeDatabaseData(const CleanerOrders& which_data) {
void DatabaseCleaner::purgeDatabaseData(CleanerOrders which_data) {
qDebugNN << LOGSEC_DB << "Performing database cleanup in thread: '" << QThread::currentThreadId() << "'.";
// Inform everyone about the start of the process.

View File

@ -29,7 +29,7 @@ class DatabaseCleaner : public QObject {
void purgeFinished(bool result);
public slots:
void purgeDatabaseData(const CleanerOrders& which_data);
void purgeDatabaseData(CleanerOrders which_data);
private:
bool purgeStarredMessages(const QSqlDatabase& database);

View File

@ -18,7 +18,7 @@ QStringList DatabaseDriver::prepareScript(const QString& base_sql_folder,
QStringList statements;
QString next_file = base_sql_folder + QDir::separator() + sql_file;
QString sql_script = QString::fromUtf8(IOFactory::readFile(next_file));
QStringList new_statements = sql_script.split(APP_DB_COMMENT_SPLIT,
QStringList new_statements = sql_script.split(QSL(APP_DB_COMMENT_SPLIT),
#if QT_VERSION >= 0x050F00 // Qt >= 5.15.0
Qt::SplitBehaviorFlags::SkipEmptyParts);
#else
@ -26,13 +26,13 @@ QStringList DatabaseDriver::prepareScript(const QString& base_sql_folder,
#endif
for (int i = 0; i < new_statements.size(); i++) {
if (new_statements.at(i).startsWith(APP_DB_INCLUDE_PLACEHOLDER)) {
if (new_statements.at(i).startsWith(QSL(APP_DB_INCLUDE_PLACEHOLDER))) {
// We include another file.
QString included_file_name = new_statements.at(i).mid(QSL(APP_DB_INCLUDE_PLACEHOLDER).size() + 1);
QString included_file = base_sql_folder + QDir::separator() + included_file_name;
QString included_sql_script = QString::fromUtf8(IOFactory::readFile(included_file));
QStringList included_statements = included_sql_script.split(APP_DB_COMMENT_SPLIT,
QStringList included_statements = included_sql_script.split(QSL(APP_DB_COMMENT_SPLIT),
#if QT_VERSION >= 0x050F00 // Qt >= 5.15.0
Qt::SplitBehaviorFlags::SkipEmptyParts);
#else
@ -46,9 +46,9 @@ QStringList DatabaseDriver::prepareScript(const QString& base_sql_folder,
}
}
statements.replaceInStrings(APP_DB_NAME_PLACEHOLDER, database_name);
statements.replaceInStrings(APP_DB_AUTO_INC_PRIM_KEY_PLACEHOLDER, autoIncrementPrimaryKey());
statements.replaceInStrings(APP_DB_BLOB_PLACEHOLDER, blob());
statements.replaceInStrings(QSL(APP_DB_NAME_PLACEHOLDER), database_name);
statements.replaceInStrings(QSL(APP_DB_AUTO_INC_PRIM_KEY_PLACEHOLDER), autoIncrementPrimaryKey());
statements.replaceInStrings(QSL(APP_DB_BLOB_PLACEHOLDER), blob());
return statements;
}

View File

@ -31,7 +31,7 @@ void DatabaseFactory::determineDriver() {
new SqliteDriver(qApp->settings()->value(GROUP(Database), SETTING(Database::UseInMemory)).toBool(), this)
};
if (QSqlDatabase::isDriverAvailable(APP_DB_MYSQL_DRIVER)) {
if (QSqlDatabase::isDriverAvailable(QSL(APP_DB_MYSQL_DRIVER))) {
m_allDbDrivers.append(new MariaDbDriver(this));
}

View File

@ -16,24 +16,27 @@
QMap<int, QString> DatabaseQueries::messageTableAttributes(bool only_msg_table) {
QMap<int, QString> field_names;
field_names[MSG_DB_ID_INDEX] = "Messages.id";
field_names[MSG_DB_READ_INDEX] = "Messages.is_read";
field_names[MSG_DB_IMPORTANT_INDEX] = "Messages.is_important";
field_names[MSG_DB_DELETED_INDEX] = "Messages.is_deleted";
field_names[MSG_DB_PDELETED_INDEX] = "Messages.is_pdeleted";
field_names[MSG_DB_FEED_CUSTOM_ID_INDEX] = "Messages.feed";
field_names[MSG_DB_TITLE_INDEX] = "Messages.title";
field_names[MSG_DB_URL_INDEX] = "Messages.url";
field_names[MSG_DB_AUTHOR_INDEX] = "Messages.author";
field_names[MSG_DB_DCREATED_INDEX] = "Messages.date_created";
field_names[MSG_DB_CONTENTS_INDEX] = "Messages.contents";
field_names[MSG_DB_ENCLOSURES_INDEX] = "Messages.enclosures";
field_names[MSG_DB_SCORE_INDEX] = "Messages.score";
field_names[MSG_DB_ACCOUNT_ID_INDEX] = "Messages.account_id";
field_names[MSG_DB_CUSTOM_ID_INDEX] = "Messages.custom_id";
field_names[MSG_DB_CUSTOM_HASH_INDEX] = "Messages.custom_hash";
field_names[MSG_DB_FEED_TITLE_INDEX] = only_msg_table ? "Messages.feed" : "Feeds.title";
field_names[MSG_DB_HAS_ENCLOSURES] = "CASE WHEN length(Messages.enclosures) > 10 THEN 'true' ELSE 'false' END AS has_enclosures";
field_names[MSG_DB_ID_INDEX] = QSL("Messages.id");
field_names[MSG_DB_READ_INDEX] = QSL("Messages.is_read");
field_names[MSG_DB_IMPORTANT_INDEX] = QSL("Messages.is_important");
field_names[MSG_DB_DELETED_INDEX] = QSL("Messages.is_deleted");
field_names[MSG_DB_PDELETED_INDEX] = QSL("Messages.is_pdeleted");
field_names[MSG_DB_FEED_CUSTOM_ID_INDEX] = QSL("Messages.feed");
field_names[MSG_DB_TITLE_INDEX] = QSL("Messages.title");
field_names[MSG_DB_URL_INDEX] = QSL("Messages.url");
field_names[MSG_DB_AUTHOR_INDEX] = QSL("Messages.author");
field_names[MSG_DB_DCREATED_INDEX] = QSL("Messages.date_created");
field_names[MSG_DB_CONTENTS_INDEX] = QSL("Messages.contents");
field_names[MSG_DB_ENCLOSURES_INDEX] = QSL("Messages.enclosures");
field_names[MSG_DB_SCORE_INDEX] = QSL("Messages.score");
field_names[MSG_DB_ACCOUNT_ID_INDEX] = QSL("Messages.account_id");
field_names[MSG_DB_CUSTOM_ID_INDEX] = QSL("Messages.custom_id");
field_names[MSG_DB_CUSTOM_HASH_INDEX] = QSL("Messages.custom_hash");
field_names[MSG_DB_FEED_TITLE_INDEX] = only_msg_table ? QSL("Messages.feed") : QSL("Feeds.title");
field_names[MSG_DB_HAS_ENCLOSURES] = QSL("CASE WHEN length(Messages.enclosures) > 10 "
"THEN 'true' "
"ELSE 'false' "
"END AS has_enclosures");
return field_names;
}
@ -63,7 +66,8 @@ bool DatabaseQueries::isLabelAssignedToMessage(const QSqlDatabase& db, Label* la
QSqlQuery q(db);
q.setForwardOnly(true);
q.prepare("SELECT COUNT(*) FROM LabelsInMessages WHERE label = :label AND message = :message AND account_id = :account_id;");
q.prepare(QSL("SELECT COUNT(*) FROM LabelsInMessages "
"WHERE label = :label AND message = :message AND account_id = :account_id;"));
q.bindValue(QSL(":label"), label->customId());
q.bindValue(QSL(":message"), msg.m_customId);
q.bindValue(QSL(":account_id"), label->getParentServiceRoot()->accountId());
@ -77,7 +81,8 @@ bool DatabaseQueries::deassignLabelFromMessage(const QSqlDatabase& db, Label* la
QSqlQuery q(db);
q.setForwardOnly(true);
q.prepare("DELETE FROM LabelsInMessages WHERE label = :label AND message = :message AND account_id = :account_id;");
q.prepare(QSL("DELETE FROM LabelsInMessages "
"WHERE label = :label AND message = :message AND account_id = :account_id;"));
q.bindValue(QSL(":label"), label->customId());
q.bindValue(QSL(":message"), msg.m_customId.isEmpty() ? QString::number(msg.m_id) : msg.m_customId);
q.bindValue(QSL(":account_id"), label->getParentServiceRoot()->accountId());
@ -89,7 +94,8 @@ bool DatabaseQueries::assignLabelToMessage(const QSqlDatabase& db, Label* label,
QSqlQuery q(db);
q.setForwardOnly(true);
q.prepare("DELETE FROM LabelsInMessages WHERE label = :label AND message = :message AND account_id = :account_id;");
q.prepare(QSL("DELETE FROM LabelsInMessages "
"WHERE label = :label AND message = :message AND account_id = :account_id;"));
q.bindValue(QSL(":label"), label->customId());
q.bindValue(QSL(":message"), msg.m_customId.isEmpty() ? QString::number(msg.m_id) : msg.m_customId);
q.bindValue(QSL(":account_id"), label->getParentServiceRoot()->accountId());
@ -97,7 +103,8 @@ bool DatabaseQueries::assignLabelToMessage(const QSqlDatabase& db, Label* label,
auto succ = q.exec();
if (succ) {
q.prepare("INSERT INTO LabelsInMessages (label, message, account_id) VALUES (:label, :message, :account_id);");
q.prepare(QSL("INSERT INTO LabelsInMessages (label, message, account_id) "
"VALUES (:label, :message, :account_id);"));
q.bindValue(QSL(":label"), label->customId());
q.bindValue(QSL(":message"), msg.m_customId.isEmpty() ? QString::number(msg.m_id) : msg.m_customId);
q.bindValue(QSL(":account_id"), label->getParentServiceRoot()->accountId());
@ -142,8 +149,7 @@ QList<Label*> DatabaseQueries::getLabelsForAccount(const QSqlDatabase& db, int a
QSqlQuery q(db);
q.setForwardOnly(true);
q.prepare("SELECT * FROM Labels WHERE account_id = :account_id;");
q.prepare(QSL("SELECT * FROM Labels WHERE account_id = :account_id;"));
q.bindValue(QSL(":account_id"), account_id);
if (q.exec()) {
@ -167,7 +173,7 @@ QList<Label*> DatabaseQueries::getLabelsForMessage(const QSqlDatabase& db,
QSqlQuery q(db);
q.setForwardOnly(true);
q.prepare("SELECT DISTINCT label FROM LabelsInMessages WHERE message = :message AND account_id = :account_id;");
q.prepare(QSL("SELECT DISTINCT label FROM LabelsInMessages WHERE message = :message AND account_id = :account_id;"));
q.bindValue(QSL(":account_id"), msg.m_accountId);
q.bindValue(QSL(":message"), msg.m_customId.isEmpty() ? QString::number(msg.m_id) : msg.m_customId);
@ -194,8 +200,8 @@ bool DatabaseQueries::updateLabel(const QSqlDatabase& db, Label* label) {
QSqlQuery q(db);
q.setForwardOnly(true);
q.prepare("UPDATE Labels SET name = :name, color = :color "
"WHERE id = :id AND account_id = :account_id;");
q.prepare(QSL("UPDATE Labels SET name = :name, color = :color "
"WHERE id = :id AND account_id = :account_id;"));
q.bindValue(QSL(":name"), label->title());
q.bindValue(QSL(":color"), label->color().name());
q.bindValue(QSL(":id"), label->id());
@ -210,12 +216,12 @@ bool DatabaseQueries::deleteLabel(const QSqlDatabase& db, Label* label) {
QSqlQuery q(db);
q.setForwardOnly(true);
q.prepare("DELETE FROM Labels WHERE id = :id AND account_id = :account_id;");
q.prepare(QSL("DELETE FROM Labels WHERE id = :id AND account_id = :account_id;"));
q.bindValue(QSL(":id"), label->id());
q.bindValue(QSL(":account_id"), label->getParentServiceRoot()->accountId());
if (q.exec()) {
q.prepare("DELETE FROM LabelsInMessages WHERE label = :custom_id AND account_id = :account_id;");
q.prepare(QSL("DELETE FROM LabelsInMessages WHERE label = :custom_id AND account_id = :account_id;"));
q.bindValue(QSL(":custom_id"), label->customId());
q.bindValue(QSL(":account_id"), label->getParentServiceRoot()->accountId());
@ -230,8 +236,8 @@ bool DatabaseQueries::createLabel(const QSqlDatabase& db, Label* label, int acco
QSqlQuery q(db);
q.setForwardOnly(true);
q.prepare("INSERT INTO Labels (name, color, custom_id, account_id) "
"VALUES (:name, :color, :custom_id, :account_id);");
q.prepare(QSL("INSERT INTO Labels (name, color, custom_id, account_id) "
"VALUES (:name, :color, :custom_id, :account_id);"));
q.bindValue(QSL(":name"), label->title());
q.bindValue(QSL(":color"), label->color().name());
q.bindValue(QSL(":custom_id"), label->customId());
@ -249,7 +255,7 @@ bool DatabaseQueries::createLabel(const QSqlDatabase& db, Label* label, int acco
}
// Fixup missing custom IDs.
q.prepare("UPDATE Labels SET custom_id = id WHERE custom_id IS NULL OR custom_id = '';");
q.prepare(QSL("UPDATE Labels SET custom_id = id WHERE custom_id IS NULL OR custom_id = '';"));
return q.exec() && res;
}
@ -258,12 +264,12 @@ bool DatabaseQueries::markLabelledMessagesReadUnread(const QSqlDatabase& db, Lab
QSqlQuery q(db);
q.setForwardOnly(true);
q.prepare("UPDATE Messages SET is_read = :read "
"WHERE "
" is_deleted = 0 AND "
" is_pdeleted = 0 AND "
" account_id = :account_id AND "
" EXISTS (SELECT * FROM LabelsInMessages WHERE LabelsInMessages.label = :label AND Messages.account_id = LabelsInMessages.account_id AND Messages.custom_id = LabelsInMessages.message);");
q.prepare(QSL("UPDATE Messages SET is_read = :read "
"WHERE "
" is_deleted = 0 AND "
" is_pdeleted = 0 AND "
" account_id = :account_id AND "
" EXISTS (SELECT * FROM LabelsInMessages WHERE LabelsInMessages.label = :label AND Messages.account_id = LabelsInMessages.account_id AND Messages.custom_id = LabelsInMessages.message);"));
q.bindValue(QSL(":read"), read == RootItem::ReadStatus::Read ? 1 : 0);
q.bindValue(QSL(":account_id"), label->getParentServiceRoot()->accountId());
q.bindValue(QSL(":label"), label->customId());
@ -275,8 +281,8 @@ bool DatabaseQueries::markImportantMessagesReadUnread(const QSqlDatabase& db, in
QSqlQuery q(db);
q.setForwardOnly(true);
q.prepare("UPDATE Messages SET is_read = :read "
"WHERE is_important = 1 AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;");
q.prepare(QSL("UPDATE Messages SET is_read = :read "
"WHERE is_important = 1 AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;"));
q.bindValue(QSL(":read"), read == RootItem::ReadStatus::Read ? 1 : 0);
q.bindValue(QSL(":account_id"), account_id);
return q.exec();
@ -286,8 +292,8 @@ bool DatabaseQueries::markUnreadMessagesRead(const QSqlDatabase& db, int account
QSqlQuery q(db);
q.setForwardOnly(true);
q.prepare("UPDATE Messages SET is_read = :read "
"WHERE is_read = 0 AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;");
q.prepare(QSL("UPDATE Messages SET is_read = :read "
"WHERE is_read = 0 AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;"));
q.bindValue(QSL(":read"), 1);
q.bindValue(QSL(":account_id"), account_id);
return q.exec();
@ -323,8 +329,8 @@ bool DatabaseQueries::markFeedsReadUnread(const QSqlDatabase& db, const QStringL
QSqlQuery q(db);
q.setForwardOnly(true);
q.prepare(QString("UPDATE Messages SET is_read = :read "
"WHERE feed IN (%1) AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;").arg(ids.join(QSL(", "))));
q.prepare(QSL("UPDATE Messages SET is_read = :read "
"WHERE feed IN (%1) AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;").arg(ids.join(QSL(", "))));
q.bindValue(QSL(":read"), read == RootItem::ReadStatus::Read ? 1 : 0);
q.bindValue(QSL(":account_id"), account_id);
return q.exec();
@ -334,8 +340,8 @@ bool DatabaseQueries::markBinReadUnread(const QSqlDatabase& db, int account_id,
QSqlQuery q(db);
q.setForwardOnly(true);
q.prepare("UPDATE Messages SET is_read = :read "
"WHERE is_deleted = 1 AND is_pdeleted = 0 AND account_id = :account_id;");
q.prepare(QSL("UPDATE Messages SET is_read = :read "
"WHERE is_deleted = 1 AND is_pdeleted = 0 AND account_id = :account_id;"));
q.bindValue(QSL(":read"), read == RootItem::ReadStatus::Read ? 1 : 0);
q.bindValue(QSL(":account_id"), account_id);
return q.exec();
@ -355,31 +361,31 @@ bool DatabaseQueries::switchMessagesImportance(const QSqlDatabase& db, const QSt
QSqlQuery q(db);
q.setForwardOnly(true);
return q.exec(QString(QSL("UPDATE Messages SET is_important = NOT is_important WHERE id IN (%1);")).arg(ids.join(QSL(", "))));
return q.exec(QSL("UPDATE Messages SET is_important = NOT is_important WHERE id IN (%1);").arg(ids.join(QSL(", "))));
}
bool DatabaseQueries::permanentlyDeleteMessages(const QSqlDatabase& db, const QStringList& ids) {
QSqlQuery q(db);
q.setForwardOnly(true);
return q.exec(QString(QSL("UPDATE Messages SET is_pdeleted = 1 WHERE id IN (%1);")).arg(ids.join(QSL(", "))));
return q.exec(QSL("UPDATE Messages SET is_pdeleted = 1 WHERE id IN (%1);").arg(ids.join(QSL(", "))));
}
bool DatabaseQueries::deleteOrRestoreMessagesToFromBin(const QSqlDatabase& db, const QStringList& ids, bool deleted) {
QSqlQuery q(db);
q.setForwardOnly(true);
return q.exec(QString(QSL("UPDATE Messages SET is_deleted = %2, is_pdeleted = %3 WHERE id IN (%1);")).arg(ids.join(QSL(", ")),
QString::number(deleted ? 1 : 0),
QString::number(0)));
return q.exec(QSL("UPDATE Messages SET is_deleted = %2, is_pdeleted = %3 WHERE id IN (%1);").arg(ids.join(QSL(", ")),
QString::number(deleted ? 1 : 0),
QString::number(0)));
}
bool DatabaseQueries::restoreBin(const QSqlDatabase& db, int account_id) {
QSqlQuery q(db);
q.setForwardOnly(true);
q.prepare("UPDATE Messages SET is_deleted = 0 "
"WHERE is_deleted = 1 AND is_pdeleted = 0 AND account_id = :account_id;");
q.prepare(QSL("UPDATE Messages SET is_deleted = 0 "
"WHERE is_deleted = 1 AND is_pdeleted = 0 AND account_id = :account_id;"));
q.bindValue(QSL(":account_id"), account_id);
return q.exec();
}
@ -388,7 +394,7 @@ bool DatabaseQueries::purgeMessage(const QSqlDatabase& db, int message_id) {
QSqlQuery q(db);
q.setForwardOnly(true);
q.prepare("DELETE FROM Messages WHERE id = :id;");
q.prepare(QSL("DELETE FROM Messages WHERE id = :id;"));
q.bindValue(QSL(":id"), message_id);
return q.exec();
@ -410,7 +416,8 @@ bool DatabaseQueries::purgeReadMessages(const QSqlDatabase& db) {
QSqlQuery q(db);
q.setForwardOnly(true);
q.prepare(QSL("DELETE FROM Messages WHERE is_important = :is_important AND is_deleted = :is_deleted AND is_read = :is_read;"));
q.prepare(QSL("DELETE FROM Messages "
"WHERE is_important = :is_important AND is_deleted = :is_deleted AND is_read = :is_read;"));
q.bindValue(QSL(":is_read"), 1);
// Remove only messages which are NOT in recycle bin.
@ -458,14 +465,14 @@ QMap<QString, QPair<int, int>> DatabaseQueries::getMessageCountsForCategory(cons
q.setForwardOnly(true);
if (only_total_counts) {
q.prepare("SELECT feed, sum((is_read + 1) % 2), count(*) FROM Messages "
"WHERE feed IN (SELECT custom_id FROM Feeds WHERE category = :category AND account_id = :account_id) AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id "
"GROUP BY feed;");
q.prepare(QSL("SELECT feed, sum((is_read + 1) % 2), count(*) FROM Messages "
"WHERE feed IN (SELECT custom_id FROM Feeds WHERE category = :category AND account_id = :account_id) AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id "
"GROUP BY feed;"));
}
else {
q.prepare("SELECT feed, sum((is_read + 1) % 2) FROM Messages "
"WHERE feed IN (SELECT custom_id FROM Feeds WHERE category = :category AND account_id = :account_id) AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id "
"GROUP BY feed;");
q.prepare(QSL("SELECT feed, sum((is_read + 1) % 2) FROM Messages "
"WHERE feed IN (SELECT custom_id FROM Feeds WHERE category = :category AND account_id = :account_id) AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id "
"GROUP BY feed;"));
}
q.bindValue(QSL(":category"), custom_id);
@ -507,14 +514,14 @@ QMap<QString, QPair<int, int>> DatabaseQueries::getMessageCountsForAccount(const
q.setForwardOnly(true);
if (only_total_counts) {
q.prepare("SELECT feed, sum((is_read + 1) % 2), count(*) FROM Messages "
"WHERE is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id "
"GROUP BY feed;");
q.prepare(QSL("SELECT feed, sum((is_read + 1) % 2), count(*) FROM Messages "
"WHERE is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id "
"GROUP BY feed;"));
}
else {
q.prepare("SELECT feed, sum((is_read + 1) % 2) FROM Messages "
"WHERE is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id "
"GROUP BY feed;");
q.prepare(QSL("SELECT feed, sum((is_read + 1) % 2) FROM Messages "
"WHERE is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id "
"GROUP BY feed;"));
}
q.bindValue(QSL(":account_id"), account_id);
@ -554,12 +561,12 @@ int DatabaseQueries::getMessageCountsForFeed(const QSqlDatabase& db, const QStri
q.setForwardOnly(true);
if (only_total_counts) {
q.prepare("SELECT count(*) FROM Messages "
"WHERE feed = :feed AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;");
q.prepare(QSL("SELECT count(*) FROM Messages "
"WHERE feed = :feed AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;"));
}
else {
q.prepare("SELECT count(*) FROM Messages "
"WHERE feed = :feed AND is_deleted = 0 AND is_pdeleted = 0 AND is_read = 0 AND account_id = :account_id;");
q.prepare(QSL("SELECT count(*) FROM Messages "
"WHERE feed = :feed AND is_deleted = 0 AND is_pdeleted = 0 AND is_read = 0 AND account_id = :account_id;"));
}
q.bindValue(QSL(":feed"), feed_custom_id);
@ -587,20 +594,20 @@ int DatabaseQueries::getMessageCountsForLabel(const QSqlDatabase& db, Label* lab
q.setForwardOnly(true);
if (only_total_counts) {
q.prepare("SELECT COUNT(*) FROM Messages "
"INNER JOIN LabelsInMessages "
"ON "
" Messages.is_pdeleted = 0 AND Messages.is_deleted = 0 AND "
" LabelsInMessages.account_id = :account_id AND LabelsInMessages.account_id = Messages.account_id AND "
" LabelsInMessages.label = :label AND LabelsInMessages.message = Messages.custom_id;");
q.prepare(QSL("SELECT COUNT(*) FROM Messages "
"INNER JOIN LabelsInMessages "
"ON "
" Messages.is_pdeleted = 0 AND Messages.is_deleted = 0 AND "
" LabelsInMessages.account_id = :account_id AND LabelsInMessages.account_id = Messages.account_id AND "
" LabelsInMessages.label = :label AND LabelsInMessages.message = Messages.custom_id;"));
}
else {
q.prepare("SELECT COUNT(*) FROM Messages "
"INNER JOIN LabelsInMessages "
"ON "
" Messages.is_pdeleted = 0 AND Messages.is_deleted = 0 AND Messages.is_read = 0 AND "
" LabelsInMessages.account_id = :account_id AND LabelsInMessages.account_id = Messages.account_id AND "
" LabelsInMessages.label = :label AND LabelsInMessages.message = Messages.custom_id;");
q.prepare(QSL("SELECT COUNT(*) FROM Messages "
"INNER JOIN LabelsInMessages "
"ON "
" Messages.is_pdeleted = 0 AND Messages.is_deleted = 0 AND Messages.is_read = 0 AND "
" LabelsInMessages.account_id = :account_id AND LabelsInMessages.account_id = Messages.account_id AND "
" LabelsInMessages.label = :label AND LabelsInMessages.message = Messages.custom_id;"));
}
q.bindValue(QSL(":account_id"), account_id);
@ -628,12 +635,12 @@ int DatabaseQueries::getImportantMessageCounts(const QSqlDatabase& db, int accou
q.setForwardOnly(true);
if (only_total_counts) {
q.prepare("SELECT count(*) FROM Messages "
"WHERE is_important = 1 AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;");
q.prepare(QSL("SELECT count(*) FROM Messages "
"WHERE is_important = 1 AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;"));
}
else {
q.prepare("SELECT count(*) FROM Messages "
"WHERE is_read = 0 AND is_important = 1 AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;");
q.prepare(QSL("SELECT count(*) FROM Messages "
"WHERE is_read = 0 AND is_important = 1 AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;"));
}
q.bindValue(QSL(":account_id"), account_id);
@ -658,8 +665,8 @@ int DatabaseQueries::getUnreadMessageCounts(const QSqlDatabase& db, int account_
QSqlQuery q(db);
q.setForwardOnly(true);
q.prepare("SELECT count(*) FROM Messages "
"WHERE is_read = 0 AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;");
q.prepare(QSL("SELECT count(*) FROM Messages "
"WHERE is_read = 0 AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;"));
q.bindValue(QSL(":account_id"), account_id);
@ -685,12 +692,12 @@ int DatabaseQueries::getMessageCountsForBin(const QSqlDatabase& db, int account_
q.setForwardOnly(true);
if (including_total_counts) {
q.prepare("SELECT count(*) FROM Messages "
"WHERE is_deleted = 1 AND is_pdeleted = 0 AND account_id = :account_id;");
q.prepare(QSL("SELECT count(*) FROM Messages "
"WHERE is_deleted = 1 AND is_pdeleted = 0 AND account_id = :account_id;"));
}
else {
q.prepare("SELECT count(*) FROM Messages "
"WHERE is_read = 0 AND is_deleted = 1 AND is_pdeleted = 0 AND account_id = :account_id;");
q.prepare(QSL("SELECT count(*) FROM Messages "
"WHERE is_read = 0 AND is_deleted = 1 AND is_pdeleted = 0 AND account_id = :account_id;"));
}
q.bindValue(QSL(":account_id"), account_id);
@ -1054,37 +1061,37 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
// 4) they have same TITLE.
// NOTE: This only applies to messages from standard RSS/ATOM/JSON feeds without ID/GUID.
query_select_with_url.setForwardOnly(true);
query_select_with_url.prepare("SELECT id, date_created, is_read, is_important, contents, feed FROM Messages "
"WHERE feed = :feed AND title = :title AND url = :url AND author = :author AND account_id = :account_id;");
query_select_with_url.prepare(QSL("SELECT id, date_created, is_read, is_important, contents, feed FROM Messages "
"WHERE feed = :feed AND title = :title AND url = :url AND author = :author AND account_id = :account_id;"));
// When we have custom ID of the message which is service-specific (synchronized services).
query_select_with_custom_id.setForwardOnly(true);
query_select_with_custom_id.prepare("SELECT id, date_created, is_read, is_important, contents, feed, title FROM Messages "
"WHERE custom_id = :custom_id AND account_id = :account_id;");
query_select_with_custom_id.prepare(QSL("SELECT id, date_created, is_read, is_important, contents, feed, title FROM Messages "
"WHERE custom_id = :custom_id AND account_id = :account_id;"));
// We have custom ID of message, but it is feed-specific not service-specific (standard RSS/ATOM/JSON).
query_select_with_custom_id_for_feed.setForwardOnly(true);
query_select_with_custom_id_for_feed.prepare("SELECT id, date_created, is_read, is_important, contents, title FROM Messages "
"WHERE feed = :feed AND custom_id = :custom_id AND account_id = :account_id;");
query_select_with_custom_id_for_feed.prepare(QSL("SELECT id, date_created, is_read, is_important, contents, title FROM Messages "
"WHERE feed = :feed AND custom_id = :custom_id AND account_id = :account_id;"));
// In some case, messages are already stored in the DB and they all have primary DB ID.
// This is particularly the case when user runs some message filter manually on existing messages
// of some feed.
query_select_with_id.setForwardOnly(true);
query_select_with_id.prepare("SELECT date_created, is_read, is_important, contents, feed, title FROM Messages "
"WHERE id = :id AND account_id = :account_id;");
query_select_with_id.prepare(QSL("SELECT date_created, is_read, is_important, contents, feed, title FROM Messages "
"WHERE id = :id AND account_id = :account_id;"));
// Used to insert new messages.
query_insert.setForwardOnly(true);
query_insert.prepare("INSERT INTO Messages "
"(feed, title, is_read, is_important, is_deleted, url, author, score, date_created, contents, enclosures, custom_id, custom_hash, account_id) "
"VALUES (:feed, :title, :is_read, :is_important, :is_deleted, :url, :author, :score, :date_created, :contents, :enclosures, :custom_id, :custom_hash, :account_id);");
query_insert.prepare(QSL("INSERT INTO Messages "
"(feed, title, is_read, is_important, is_deleted, url, author, score, date_created, contents, enclosures, custom_id, custom_hash, account_id) "
"VALUES (:feed, :title, :is_read, :is_important, :is_deleted, :url, :author, :score, :date_created, :contents, :enclosures, :custom_id, :custom_hash, :account_id);"));
// Used to update existing messages.
query_update.setForwardOnly(true);
query_update.prepare("UPDATE Messages "
"SET title = :title, is_read = :is_read, is_important = :is_important, is_deleted = :is_deleted, url = :url, author = :author, score = :score, date_created = :date_created, contents = :contents, enclosures = :enclosures, feed = :feed "
"WHERE id = :id;");
query_update.prepare(QSL("UPDATE Messages "
"SET title = :title, is_read = :is_read, is_important = :is_important, is_deleted = :is_deleted, url = :url, author = :author, score = :score, date_created = :date_created, contents = :contents, enclosures = :enclosures, feed = :feed "
"WHERE id = :id;"));
if (use_transactions && !db.transaction()) {
qCriticalNN << LOGSEC_DB
@ -2073,7 +2080,7 @@ MessageFilter* DatabaseQueries::addMessageFilter(const QSqlDatabase& db, const Q
QSqlQuery q(db);
q.prepare("INSERT INTO MessageFilters (name, script) VALUES(:name, :script);");
q.prepare(QSL("INSERT INTO MessageFilters (name, script) VALUES(:name, :script);"));
q.bindValue(QSL(":name"), title);
q.bindValue(QSL(":script"), script);
@ -2095,7 +2102,7 @@ MessageFilter* DatabaseQueries::addMessageFilter(const QSqlDatabase& db, const Q
void DatabaseQueries::removeMessageFilter(const QSqlDatabase& db, int filter_id, bool* ok) {
QSqlQuery q(db);
q.prepare("DELETE FROM MessageFilters WHERE id = :id;");
q.prepare(QSL("DELETE FROM MessageFilters WHERE id = :id;"));
q.bindValue(QSL(":id"), filter_id);
q.setForwardOnly(true);
@ -2115,7 +2122,7 @@ void DatabaseQueries::removeMessageFilter(const QSqlDatabase& db, int filter_id,
void DatabaseQueries::removeMessageFilterAssignments(const QSqlDatabase& db, int filter_id, bool* ok) {
QSqlQuery q(db);
q.prepare("DELETE FROM MessageFiltersInFeeds WHERE filter = :filter;");
q.prepare(QSL("DELETE FROM MessageFiltersInFeeds WHERE filter = :filter;"));
q.bindValue(QSL(":filter"), filter_id);
q.setForwardOnly(true);
@ -2167,7 +2174,7 @@ QMultiMap<QString, int> DatabaseQueries::messageFiltersInFeeds(const QSqlDatabas
QSqlQuery q(db);
QMultiMap<QString, int> filters_in_feeds;
q.prepare("SELECT filter, feed_custom_id FROM MessageFiltersInFeeds WHERE account_id = :account_id;");
q.prepare(QSL("SELECT filter, feed_custom_id FROM MessageFiltersInFeeds WHERE account_id = :account_id;"));
q.bindValue(QSL(":account_id"), account_id);
q.setForwardOnly(true);
@ -2196,8 +2203,8 @@ void DatabaseQueries::assignMessageFilterToFeed(const QSqlDatabase& db, const QS
int filter_id, int account_id, bool* ok) {
QSqlQuery q(db);
q.prepare("INSERT INTO MessageFiltersInFeeds (filter, feed_custom_id, account_id) "
"VALUES(:filter, :feed_custom_id, :account_id);");
q.prepare(QSL("INSERT INTO MessageFiltersInFeeds (filter, feed_custom_id, account_id) "
"VALUES(:filter, :feed_custom_id, :account_id);"));
q.bindValue(QSL(":filter"), filter_id);
q.bindValue(QSL(":feed_custom_id"), feed_custom_id);
@ -2219,7 +2226,7 @@ void DatabaseQueries::assignMessageFilterToFeed(const QSqlDatabase& db, const QS
void DatabaseQueries::updateMessageFilter(const QSqlDatabase& db, MessageFilter* filter, bool* ok) {
QSqlQuery q(db);
q.prepare("UPDATE MessageFilters SET name = :name, script = :script WHERE id = :id;");
q.prepare(QSL("UPDATE MessageFilters SET name = :name, script = :script WHERE id = :id;"));
q.bindValue(QSL(":name"), filter->name());
q.bindValue(QSL(":script"), filter->script());
@ -2242,8 +2249,8 @@ void DatabaseQueries::removeMessageFilterFromFeed(const QSqlDatabase& db, const
int filter_id, int account_id, bool* ok) {
QSqlQuery q(db);
q.prepare("DELETE FROM MessageFiltersInFeeds "
"WHERE filter = :filter AND feed_custom_id = :feed_custom_id AND account_id = :account_id;");
q.prepare(QSL("DELETE FROM MessageFiltersInFeeds "
"WHERE filter = :filter AND feed_custom_id = :feed_custom_id AND account_id = :account_id;"));
q.bindValue(QSL(":filter"), filter_id);
q.bindValue(QSL(":feed_custom_id"), feed_custom_id);
@ -2300,7 +2307,7 @@ bool DatabaseQueries::storeNewOauthTokens(const QSqlDatabase& db,
QVariantHash custom_data = deserializeCustomData(query.value(0).toString());
custom_data["refresh_token"] = refresh_token;
custom_data[QSL("refresh_token")] = refresh_token;
query.clear();
query.prepare(QSL("UPDATE Accounts SET custom_data = :custom_data WHERE id = :id;"));
@ -2319,5 +2326,5 @@ bool DatabaseQueries::storeNewOauthTokens(const QSqlDatabase& db,
}
QString DatabaseQueries::unnulifyString(const QString& str) {
return str.isNull() ? "" : str;
return str.isNull() ? QSL("") : str;
}

View File

@ -16,7 +16,7 @@ MariaDbDriver::MariaDbDriver(QObject* parent) : DatabaseDriver(parent), m_databa
MariaDbDriver::MariaDbError MariaDbDriver::testConnection(const QString& hostname, int port,
const QString& w_database, const QString& username,
const QString& password) {
QSqlDatabase database = QSqlDatabase::addDatabase(APP_DB_MYSQL_DRIVER, APP_DB_MYSQL_TEST);
QSqlDatabase database = QSqlDatabase::addDatabase(QSL(APP_DB_MYSQL_DRIVER), QSL(APP_DB_MYSQL_TEST));
database.setHostName(hostname);
database.setPort(port);
@ -93,7 +93,7 @@ QString MariaDbDriver::humanDriverType() const {
}
QString MariaDbDriver::qtDriverCode() const {
return APP_DB_MYSQL_DRIVER;
return QSL(APP_DB_MYSQL_DRIVER);
}
DatabaseDriver::DriverType MariaDbDriver::driverType() const {
@ -146,7 +146,7 @@ qint64 MariaDbDriver::databaseDataSize() {
QSqlDatabase MariaDbDriver::initializeDatabase(const QString& connection_name) {
// Folders are created. Create new QSqlDatabase object.
QSqlDatabase database = QSqlDatabase::addDatabase(APP_DB_MYSQL_DRIVER, connection_name);
QSqlDatabase database = QSqlDatabase::addDatabase(QSL(APP_DB_MYSQL_DRIVER), connection_name);
const QString database_name = qApp->settings()->value(GROUP(Database), SETTING(Database::MySQLDatabase)).toString();
database.setHostName(qApp->settings()->value(GROUP(Database), SETTING(Database::MySQLHostname)).toString());
@ -163,13 +163,13 @@ QSqlDatabase MariaDbDriver::initializeDatabase(const QString& connection_name) {
query_db.setForwardOnly(true);
if (!query_db.exec(QString("USE %1").arg(database_name)) ||
if (!query_db.exec(QSL("USE %1").arg(database_name)) ||
!query_db.exec(QSL("SELECT inf_value FROM Information WHERE inf_key = 'schema_version'"))) {
// If no "rssguard" database exists or schema version is wrong, then initialize it.
qWarningNN << LOGSEC_DB << "Error occurred. MySQL database is not initialized. Initializing now.";
try {
const QStringList statements = prepareScript(APP_SQL_PATH, APP_DB_MYSQL_INIT, database_name);
const QStringList statements = prepareScript(APP_SQL_PATH, QSL(APP_DB_MYSQL_INIT), database_name);
for (const QString& statement : statements) {
query_db.exec(statement);
@ -190,7 +190,7 @@ QSqlDatabase MariaDbDriver::initializeDatabase(const QString& connection_name) {
query_db.next();
const QString installed_db_schema = query_db.value(0).toString();
if (installed_db_schema.toInt() < QString(APP_DB_SCHEMA_VERSION).toInt()) {
if (installed_db_schema.toInt() < QSL(APP_DB_SCHEMA_VERSION).toInt()) {
if (updateDatabaseSchema(database, installed_db_schema, database_name)) {
qDebugNN << LOGSEC_DB
<< "Database schema was updated from"
@ -218,14 +218,14 @@ bool MariaDbDriver::updateDatabaseSchema(const QSqlDatabase& database,
const QString& source_db_schema_version,
const QString& database_name) {
int working_version = QString(source_db_schema_version).remove('.').toInt();
const int current_version = QString(APP_DB_SCHEMA_VERSION).remove('.').toInt();
const int current_version = QSL(APP_DB_SCHEMA_VERSION).remove('.').toInt();
while (working_version != current_version) {
try {
const QStringList statements = prepareScript(APP_SQL_PATH,
QString(APP_DB_UPDATE_FILE_PATTERN).arg(QSL("mysql"),
QString::number(working_version),
QString::number(working_version + 1)),
QSL(APP_DB_UPDATE_FILE_PATTERN).arg(QSL("mysql"),
QString::number(working_version),
QString::number(working_version + 1)),
database_name);
for (const QString& statement : statements) {
@ -275,7 +275,7 @@ QSqlDatabase MariaDbDriver::connection(const QString& connection_name, DatabaseD
else {
// Database connection with this name does not exist
// yet, add it and set it up.
database = QSqlDatabase::addDatabase(APP_DB_MYSQL_DRIVER, connection_name);
database = QSqlDatabase::addDatabase(QSL(APP_DB_MYSQL_DRIVER), connection_name);
database.setHostName(qApp->settings()->value(GROUP(Database), SETTING(Database::MySQLHostname)).toString());
database.setPort(qApp->settings()->value(GROUP(Database), SETTING(Database::MySQLPort)).toInt());
database.setUserName(qApp->settings()->value(GROUP(Database), SETTING(Database::MySQLUsername)).toString());

View File

@ -12,7 +12,7 @@
SqliteDriver::SqliteDriver(bool in_memory, QObject* parent)
: DatabaseDriver(parent), m_inMemoryDatabase(in_memory),
m_databaseFilePath(qApp->userDataFolder() + QDir::separator() + QString(APP_DB_SQLITE_PATH)),
m_databaseFilePath(qApp->userDataFolder() + QDir::separator() + QSL(APP_DB_SQLITE_PATH)),
m_fileBasedDatabaseInitialized(false),
m_inMemoryDatabaseInitialized(false) {}
@ -123,7 +123,7 @@ QSqlDatabase SqliteDriver::connection(const QString& connection_name, DesiredSto
database = QSqlDatabase::database(connection_name);
}
else {
database = QSqlDatabase::addDatabase(APP_DB_SQLITE_DRIVER, connection_name);
database = QSqlDatabase::addDatabase(QSL(APP_DB_SQLITE_DRIVER), connection_name);
if (want_in_memory) {
database.setConnectOptions(QSL("QSQLITE_OPEN_URI;QSQLITE_ENABLE_SHARED_CACHE"));
@ -131,7 +131,7 @@ QSqlDatabase SqliteDriver::connection(const QString& connection_name, DesiredSto
}
else {
const QDir db_path(m_databaseFilePath);
QFile db_file(db_path.absoluteFilePath(APP_DB_SQLITE_FILE));
QFile db_file(db_path.absoluteFilePath(QSL(APP_DB_SQLITE_FILE)));
database.setDatabaseName(db_file.fileName());
}
@ -196,7 +196,7 @@ QSqlDatabase SqliteDriver::initializeDatabase(const QString& connection_name, bo
if (!in_memory) {
// Prepare file paths.
const QDir db_path(m_databaseFilePath);
QFile db_file(db_path.absoluteFilePath(APP_DB_SQLITE_FILE));
QFile db_file(db_path.absoluteFilePath(QSL(APP_DB_SQLITE_FILE)));
// Check if database directory exists.
if (!db_path.exists()) {
@ -218,7 +218,7 @@ QSqlDatabase SqliteDriver::initializeDatabase(const QString& connection_name, bo
// Folders are created. Create new QSQLDatabase object.
QSqlDatabase database;
database = QSqlDatabase::addDatabase(APP_DB_SQLITE_DRIVER, connection_name);
database = QSqlDatabase::addDatabase(QSL(APP_DB_SQLITE_DRIVER), connection_name);
if (in_memory) {
database.setConnectOptions(QSL("QSQLITE_OPEN_URI;QSQLITE_ENABLE_SHARED_CACHE"));
@ -241,7 +241,7 @@ QSqlDatabase SqliteDriver::initializeDatabase(const QString& connection_name, bo
qWarningNN << LOGSEC_DB << "SQLite database is not initialized. Initializing now.";
try {
const QStringList statements = prepareScript(APP_SQL_PATH, APP_DB_SQLITE_INIT);
const QStringList statements = prepareScript(APP_SQL_PATH, QSL(APP_DB_SQLITE_INIT));
for (const QString& statement : statements) {
query_db.exec(statement);
@ -261,7 +261,7 @@ QSqlDatabase SqliteDriver::initializeDatabase(const QString& connection_name, bo
query_db.next();
const QString installed_db_schema = query_db.value(0).toString();
if (installed_db_schema.toInt() < QString(APP_DB_SCHEMA_VERSION).toInt()) {
if (installed_db_schema.toInt() < QSL(APP_DB_SCHEMA_VERSION).toInt()) {
if (updateDatabaseSchema(database, installed_db_schema)) {
qDebugNN << LOGSEC_DB
<< "Database schema was updated from '"
@ -302,7 +302,7 @@ QSqlDatabase SqliteDriver::initializeDatabase(const QString& connection_name, bo
QSqlQuery copy_contents(database);
// Attach database.
copy_contents.exec(QString("ATTACH DATABASE '%1' AS 'storage';").arg(file_database.databaseName()));
copy_contents.exec(QSL("ATTACH DATABASE '%1' AS 'storage';").arg(file_database.databaseName()));
// Copy all stuff.
QStringList tables;
@ -317,7 +317,7 @@ QSqlDatabase SqliteDriver::initializeDatabase(const QString& connection_name, bo
}
for (const QString& table : tables) {
copy_contents.exec(QString("INSERT INTO main.%1 SELECT * FROM storage.%1;").arg(table));
copy_contents.exec(QSL("INSERT INTO main.%1 SELECT * FROM storage.%1;").arg(table));
}
qDebugNN << LOGSEC_DB
@ -344,7 +344,7 @@ QString SqliteDriver::databaseFilePath() const {
bool SqliteDriver::updateDatabaseSchema(const QSqlDatabase& database, const QString& source_db_schema_version) {
int working_version = QString(source_db_schema_version).remove('.').toInt();
const int current_version = QString(APP_DB_SCHEMA_VERSION).remove('.').toInt();
const int current_version = QSL(APP_DB_SCHEMA_VERSION).remove('.').toInt();
// Now, it would be good to create backup of SQLite DB file.
if (IOFactory::copyFile(databaseFilePath(), databaseFilePath() + ".bak")) {
@ -357,9 +357,9 @@ bool SqliteDriver::updateDatabaseSchema(const QSqlDatabase& database, const QStr
while (working_version != current_version) {
try {
const QStringList statements = prepareScript(APP_SQL_PATH,
QString(APP_DB_UPDATE_FILE_PATTERN).arg(QSL("sqlite"),
QString::number(working_version),
QString::number(working_version + 1)));
QSL(APP_DB_UPDATE_FILE_PATTERN).arg(QSL("sqlite"),
QString::number(working_version),
QString::number(working_version + 1)));
for (const QString& statement : statements) {
QSqlQuery query = database.exec(statement);
@ -425,7 +425,7 @@ QString SqliteDriver::humanDriverType() const {
}
QString SqliteDriver::qtDriverCode() const {
return APP_DB_SQLITE_DRIVER;
return QSL(APP_DB_SQLITE_DRIVER);
}
void SqliteDriver::backupDatabase(const QString& backup_folder, const QString& backup_name) {

View File

@ -18,7 +18,7 @@
FormAbout::FormAbout(QWidget* parent) : QDialog(parent) {
m_ui.setupUi(this);
m_ui.m_lblIcon->setPixmap(QPixmap(APP_ICON_PATH));
GuiUtilities::applyDialogProperties(*this, qApp->icons()->fromTheme(QSL("help-about")), tr("About %1").arg(APP_NAME));
GuiUtilities::applyDialogProperties(*this, qApp->icons()->fromTheme(QSL("help-about")), tr("About %1").arg(QSL(APP_NAME)));
loadLicenseAndInformation();
loadSettingsAndPaths();
}
@ -73,20 +73,21 @@ void FormAbout::loadLicenseAndInformation() {
// Set other informative texts.
m_ui.m_lblDesc->setText(tr("<b>%8</b><br>" "<b>Version:</b> %1 (built on %2/%3)<br>" "<b>Revision:</b> %4<br>" "<b>Build date:</b> %5<br>"
"<b>Qt:</b> %6 (compiled against %7)<br>").arg(
qApp->applicationVersion(), APP_SYSTEM_NAME, APP_SYSTEM_VERSION, APP_REVISION,
QLocale().toString(TextFactory::parseDateTime(QString("%1 %2").arg(__DATE__, __TIME__)),
qApp->applicationVersion(), QSL(APP_SYSTEM_NAME),
QSL(APP_SYSTEM_VERSION), QSL(APP_REVISION),
QLocale().toString(TextFactory::parseDateTime(QSL("%1 %2").arg(__DATE__, __TIME__)),
QLocale::FormatType::ShortFormat),
qVersion(), QT_VERSION_STR,
APP_NAME));
qVersion(), QSL(QT_VERSION_STR),
QSL(APP_NAME)));
m_ui.m_txtInfo->setText(tr("<body>%5 is a (very) tiny feed reader."
"<br><br>This software is distributed under the terms of GNU General Public License, version 3."
"<br><br>Contacts:"
"<ul><li><a href=\"mailto://%1\">%1</a> ~e-mail</li>"
"<li><a href=\"%2\">%2</a> ~website</li></ul>"
"You can obtain source code for %5 from its website."
"<br><br><br>Copyright (C) 2011-%3 %4</body>").arg(APP_EMAIL, APP_URL,
"<br><br><br>Copyright (C) 2011-%3 %4</body>").arg(QSL(APP_EMAIL), QSL(APP_URL),
QString::number(QDateTime::currentDateTime()
.date()
.year()),
APP_AUTHOR, APP_NAME));
QSL(APP_AUTHOR), QSL(APP_NAME)));
}

View File

@ -29,7 +29,7 @@ FormBackupDatabaseSettings::FormBackupDatabaseSettings(QWidget* parent) : QDialo
connect(m_ui->m_txtBackupName->lineEdit(), &BaseLineEdit::textChanged, this, &FormBackupDatabaseSettings::checkOkButton);
connect(m_ui->m_btnSelectFolder, &QPushButton::clicked, this, &FormBackupDatabaseSettings::selectFolderInitial);
selectFolder(qApp->documentsFolder());
m_ui->m_txtBackupName->lineEdit()->setText(QString(APP_LOW_NAME) + QL1S("_") +
m_ui->m_txtBackupName->lineEdit()->setText(QSL(APP_LOW_NAME) + QL1S("_") +
QDateTime::currentDateTime().toString(QSL("yyyyMMddHHmm")));
m_ui->m_lblResult->setStatus(WidgetWithStatus::StatusType::Warning, tr("No operation executed yet."), tr("No operation executed yet."));

View File

@ -60,7 +60,7 @@ FormMain::FormMain(QWidget* parent, Qt::WindowFlags f)
qApp->setMainForm(this);
setWindowIcon(qApp->desktopAwareIcon());
setWindowTitle(APP_LONG_NAME);
setWindowTitle(QSL(APP_LONG_NAME));
#if defined(USE_WEBENGINE)
m_ui->m_menuWebBrowserTabs->addAction(qApp->web()->adBlock()->adBlockIcon());
@ -209,7 +209,7 @@ void FormMain::prepareMenus() {
// Setup menu for tray icon.
if (SystemTrayIcon::isSystemTrayAreaAvailable()) {
#if defined(Q_OS_WIN)
m_trayMenu = new TrayIconMenu(APP_NAME, this);
m_trayMenu = new TrayIconMenu(QSL(APP_NAME), this);
#else
m_trayMenu = new QMenu(QSL(APP_NAME), this);
#endif
@ -228,6 +228,7 @@ void FormMain::prepareMenus() {
m_ui->m_menuWebBrowserTabs->removeAction(m_ui->m_actionTabNewWebBrowser);
m_ui->m_menuWebBrowserTabs->setTitle(tr("Ta&bs"));
#endif
#if defined(Q_OS_MACOS)
m_ui->m_actionSwitchMainMenu->setVisible(false);
m_ui->m_actionFullscreen->setVisible(false);
@ -878,7 +879,7 @@ void FormMain::hideEvent(QHideEvent* event) {
}
void FormMain::showDocs() {
qApp->web()->openUrlInExternalBrowser(APP_URL_DOCUMENTATION);
qApp->web()->openUrlInExternalBrowser(QSL(APP_URL_DOCUMENTATION));
}
void FormMain::showAddAccountDialog() {

View File

@ -57,7 +57,7 @@ FormMessageFiltersManager::FormMessageFiltersManager(FeedReader* reader, const Q
m_ui.m_treeExistingMessages->header()->setSectionResizeMode(MFM_MODEL_URL, QHeaderView::ResizeMode::Interactive);
connect(m_ui.m_btnDetailedHelp, &QPushButton::clicked, this, []() {
qApp->web()->openUrlInExternalBrowser(MSG_FILTERING_HELP);
qApp->web()->openUrlInExternalBrowser(QSL(MSG_FILTERING_HELP));
});
connect(m_ui.m_listFilters, &QListWidget::currentRowChanged,
this, &FormMessageFiltersManager::loadFilter);

View File

@ -75,7 +75,7 @@ void FormSettings::applySettings() {
if (!panels_for_restart.isEmpty()) {
const QStringList changed_settings_description = panels_for_restart.replaceInStrings(QRegularExpression(QSL("^")),
QString::fromUtf8(""));
QString::fromUtf8(QByteArray("")));
const QMessageBox::StandardButton clicked_button = MessageBox::show(this,
QMessageBox::Icon::Question,
tr("Critical settings were changed"),
@ -111,7 +111,7 @@ void FormSettings::cancelSettings() {
}
else {
const QStringList changed_settings_description = changed_panels.replaceInStrings(QRegularExpression(QSL("^")),
QString::fromUtf8(""));
QString::fromUtf8(QByteArray("")));
if (MessageBox::show(this,
QMessageBox::Icon::Critical,

View File

@ -20,7 +20,7 @@
FormUpdate::FormUpdate(QWidget* parent)
: QDialog(parent) {
m_ui.setupUi(this);
m_ui.m_lblCurrentRelease->setText(APP_VERSION);
m_ui.m_lblCurrentRelease->setText(QSL(APP_VERSION));
m_ui.m_tabInfo->removeTab(1);
m_ui.m_buttonBox->setEnabled(false);
@ -78,7 +78,7 @@ void FormUpdate::checkForUpdates() {
m_ui.m_lblAvailableRelease->setText(m_updateInfo.m_availableVersion);
m_ui.m_txtChanges->setText(m_updateInfo.m_changes);
if (SystemFactory::isVersionNewer(m_updateInfo.m_availableVersion, APP_VERSION)) {
if (SystemFactory::isVersionNewer(m_updateInfo.m_availableVersion, QSL(APP_VERSION))) {
m_btnUpdate->setVisible(true);
m_ui.m_lblStatus->setStatus(WidgetWithStatus::StatusType::Ok,
tr("New release available."),
@ -200,7 +200,7 @@ void FormUpdate::startUpdate() {
m_ui.m_listFiles->setEnabled(false);
}
else {
url_file = APP_URL;
url_file = QSL(APP_URL);
}
if (m_readyToInstall) {

View File

@ -415,7 +415,7 @@ void FeedsView::selectNextUnreadItem() {
}
}
QModelIndex FeedsView::nextPreviousUnreadItem(QModelIndex default_row) {
QModelIndex FeedsView::nextPreviousUnreadItem(const QModelIndex& default_row) {
const bool started_from_zero = default_row.row() == 0 && !default_row.parent().isValid();
QModelIndex next_index = nextUnreadItem(default_row);
@ -427,34 +427,34 @@ QModelIndex FeedsView::nextPreviousUnreadItem(QModelIndex default_row) {
return next_index;
}
QModelIndex FeedsView::nextUnreadItem(QModelIndex default_row) {
default_row = m_proxyModel->index(default_row.row(), 0, default_row.parent());
QModelIndex FeedsView::nextUnreadItem(const QModelIndex& default_row) {
QModelIndex nconst_default_row = m_proxyModel->index(default_row.row(), 0, default_row.parent());
const QModelIndex starting_row = default_row;
while (true) {
bool has_unread = m_sourceModel->itemForIndex(m_proxyModel->mapToSource(default_row))->countOfUnreadMessages() > 0;
bool has_unread = m_sourceModel->itemForIndex(m_proxyModel->mapToSource(nconst_default_row))->countOfUnreadMessages() > 0;
if (has_unread) {
if (m_proxyModel->hasChildren(default_row)) {
if (m_proxyModel->hasChildren(nconst_default_row)) {
// Current index has unread items, but is expandable, go to first child.
expand(default_row);
default_row = indexBelow(default_row);
expand(nconst_default_row);
nconst_default_row = indexBelow(nconst_default_row);
continue;
}
else {
// We found unread feed, return it.
return default_row;
return nconst_default_row;
}
}
else {
QModelIndex next_row = indexBelow(default_row);
QModelIndex next_row = indexBelow(nconst_default_row);
if (next_row == default_row || !next_row.isValid() || starting_row == next_row) {
if (next_row == nconst_default_row || !next_row.isValid() || starting_row == next_row) {
// We came to last row probably.
break;
}
else {
default_row = next_row;
nconst_default_row = next_row;
}
}
}

View File

@ -101,8 +101,8 @@ class RSSGUARD_DLLSPEC FeedsView : public QTreeView {
void onItemExpandStateSaveRequested(RootItem* item);
private:
QModelIndex nextPreviousUnreadItem(QModelIndex default_row);
QModelIndex nextUnreadItem(QModelIndex default_row);
QModelIndex nextPreviousUnreadItem(const QModelIndex& default_row);
QModelIndex nextUnreadItem(const QModelIndex& default_row);
// Initializes context menus.
QMenu* initializeContextMenuBin(RootItem* clicked_item);

View File

@ -54,10 +54,6 @@ void GuiUtilities::applyResponsiveDialogResize(QWidget& widget, double factor) {
}
void GuiUtilities::restoreState(QWidget* wdg, QByteArray state) {
QHash<QString, QStringList> props_to_serialize {
{ QSL("QCheckBox"), { QSL("checked") } },
{ QSL("QSpinBox"), { QSL("value") } }
};
QHash<QString, QHash<QString, QVariant>> props;
QDataStream str(&state, QIODevice::OpenModeFlag::ReadOnly);

View File

@ -63,7 +63,7 @@ QMessageBox::StandardButton MessageBox::show(QWidget* parent,
QMessageBox::StandardButton default_button,
bool* dont_show_again,
const QString& functor_heading,
std::function<void ()> functor) {
const std::function<void()>& functor) {
// Create and find needed components.
MessageBox msg_box(parent);

View File

@ -30,7 +30,7 @@ class MessageBox : public QMessageBox {
QMessageBox::StandardButton default_button = QMessageBox::Ok,
bool* dont_show_again = nullptr,
const QString& functor_heading = {},
std::function<void()> functor = nullptr);
const std::function<void()>& functor = nullptr);
static QIcon iconForStatus(QMessageBox::Icon status);
};

View File

@ -31,15 +31,15 @@
void MessagePreviewer::createConnections() {
installEventFilter(this);
connect(m_actionMarkRead = m_toolBar->addAction(qApp->icons()->fromTheme("mail-mark-read"), tr("Mark article read")),
connect(m_actionMarkRead = m_toolBar->addAction(qApp->icons()->fromTheme(QSL("mail-mark-read")), tr("Mark article read")),
&QAction::triggered,
this,
&MessagePreviewer::markMessageAsRead);
connect(m_actionMarkUnread = m_toolBar->addAction(qApp->icons()->fromTheme("mail-mark-unread"), tr("Mark article unread")),
connect(m_actionMarkUnread = m_toolBar->addAction(qApp->icons()->fromTheme(QSL("mail-mark-unread")), tr("Mark article unread")),
&QAction::triggered,
this,
&MessagePreviewer::markMessageAsUnread);
connect(m_actionSwitchImportance = m_toolBar->addAction(qApp->icons()->fromTheme("mail-mark-important"), tr("Switch article importance")),
connect(m_actionSwitchImportance = m_toolBar->addAction(qApp->icons()->fromTheme(QSL("mail-mark-important")), tr("Switch article importance")),
&QAction::triggered,
this,
&MessagePreviewer::switchMessageImportance);

View File

@ -445,7 +445,7 @@ void MessagesView::openSelectedSourceMessagesExternally() {
for (const QModelIndex& index : qAsConst(rws)) {
QString link = m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row())
.m_url
.replace(QRegularExpression("[\\t\\n]"), QString());
.replace(QRegularExpression(QSL("[\\t\\n]")), QString());
qApp->web()->openUrlInExternalBrowser(link);
}
@ -691,7 +691,7 @@ void MessagesView::openSelectedMessagesWithExternalTool() {
for (const QModelIndex& index : qAsConst(rws)) {
const QString link = m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row())
.m_url
.replace(QRegularExpression("[\\t\\n]"), QString());
.replace(QRegularExpression(QSL("[\\t\\n]")), QString());
if (!link.isEmpty()) {
if (!tool.run(link)) {

View File

@ -2,6 +2,8 @@
#include "gui/reusable/colortoolbutton.h"
#include "definitions/definitions.h"
#include <QColorDialog>
#include <QPainter>
#include <QPainterPath>
@ -34,7 +36,7 @@ void ColorToolButton::setColor(const QColor& color) {
void ColorToolButton::setRandomColor() {
auto rnd_color = QRandomGenerator::global()->bounded(0xFFFFFF);
auto rnd_color_name = QString("#%1").arg(QString::number(rnd_color, 16));
auto rnd_color_name = QSL("#%1").arg(QString::number(rnd_color, 16));
setColor(rnd_color_name);
emit colorChanged(rnd_color_name);

View File

@ -16,7 +16,7 @@ LabelsMenu::LabelsMenu(const QList<Message>& messages, const QList<Label*>& labe
setIcon(qApp->icons()->fromTheme(QSL("tag-folder")));
if (labels.isEmpty()) {
QAction* act_not_labels = new QAction("No labels found");
QAction* act_not_labels = new QAction(tr("No labels found"));
act_not_labels->setEnabled(false);
addAction(act_not_labels);

View File

@ -15,7 +15,7 @@ void NonClosableMenu::keyPressEvent(QKeyEvent* event) {
}
void NonClosableMenu::mousePressEvent(QMouseEvent* event) {
auto* act = dynamic_cast<QAction*>(activeAction());
auto* act = activeAction();
if (act != nullptr) {
act->toggle();

View File

@ -2,6 +2,8 @@
#include "gui/reusable/timespinbox.h"
#include "definitions/definitions.h"
#include <QStringList>
TimeSpinBox::TimeSpinBox(QWidget* parent) : QDoubleSpinBox(parent) {
@ -19,7 +21,7 @@ double TimeSpinBox::valueFromText(const QString& text) const {
return value;
}
else {
QRegularExpression rx("\\b[0-9]{1,}\\b");
QRegularExpression rx(QSL("\\b[0-9]{1,}\\b"));
QStringList numbers;
int pos = 0;
int count = 0;
@ -84,7 +86,7 @@ TimeSpinBox::Mode TimeSpinBox::mode() const {
return m_mode;
}
void TimeSpinBox::setMode(const TimeSpinBox::Mode& mode) {
void TimeSpinBox::setMode(TimeSpinBox::Mode mode) {
m_mode = mode;
setValue(value());

View File

@ -22,7 +22,7 @@ class TimeSpinBox : public QDoubleSpinBox {
QValidator::State validate(QString& input, int& pos) const;
Mode mode() const;
void setMode(const TimeSpinBox::Mode& mode);
void setMode(Mode mode);
private:
Mode m_mode;

View File

@ -93,8 +93,8 @@ void SettingsBrowserMail::selectBrowserExecutable() {
}
}
QList<ExternalTool> SettingsBrowserMail::externalTools() const {
QList<ExternalTool> list;
QVector<ExternalTool> SettingsBrowserMail::externalTools() const {
QVector<ExternalTool> list; list.reserve(m_ui->m_listTools->topLevelItemCount());
for (int i = 0; i < m_ui->m_listTools->topLevelItemCount(); i++) {
list.append(m_ui->m_listTools->topLevelItem(i)->data(0, Qt::ItemDataRole::UserRole).value<ExternalTool>());
@ -241,7 +241,7 @@ ExternalTool SettingsBrowserMail::tweakExternalTool(const ExternalTool& tool) co
bool ok;
QString parameters = QInputDialog::getText(window(),
tr("Enter parameters"),
tr("Enter (optional) parameters separated by \"%1\":").arg(EXECUTION_LINE_SEPARATOR),
tr("Enter (optional) parameters separated by \"%1\":").arg(QSL(EXECUTION_LINE_SEPARATOR)),
QLineEdit::EchoMode::Normal,
tool.parameters(),
&ok);

View File

@ -35,7 +35,7 @@ class SettingsBrowserMail : public SettingsPanel {
ExternalTool tweakExternalTool(const ExternalTool& tool) const;
private:
QList<ExternalTool> externalTools() const;
QVector<ExternalTool> externalTools() const;
void setExternalTools(const QList<ExternalTool>& list);
NetworkProxyDetails* m_proxyDetails;

View File

@ -188,8 +188,8 @@ void Application::offerChanges() const {
qApp->showGuiMessage(Notification::Event::GeneralEvent,
QSL(APP_NAME),
QObject::tr("Welcome to %1.\n\nPlease, check NEW stuff included in this\n"
"version by clicking this popup notification.").arg(APP_LONG_NAME),
QSystemTrayIcon::MessageIcon::NoIcon, {}, {}, "Go to changelog", [] {
"version by clicking this popup notification.").arg(QSL(APP_LONG_NAME)),
QSystemTrayIcon::MessageIcon::NoIcon, {}, {}, tr("Go to changelog"), [] {
FormAbout(qApp->mainForm()).exec();
});
}
@ -198,12 +198,12 @@ void Application::offerChanges() const {
bool Application::isAlreadyRunning() {
return m_allowMultipleInstances
? false
: sendMessage((QStringList() << QSL("-%1").arg(CLI_IS_RUNNING)
<< Application::arguments().mid(1)).join(ARGUMENTS_LIST_SEPARATOR));
: sendMessage((QStringList() << QSL("-%1").arg(QSL(CLI_IS_RUNNING))
<< Application::arguments().mid(1)).join(QSL(ARGUMENTS_LIST_SEPARATOR)));
}
QStringList Application::builtinSounds() const {
auto builtin_sounds = QDir(SOUNDS_BUILTIN_DIRECTORY).entryInfoList(QDir::Filter::Files, QDir::SortFlag::Name);
auto builtin_sounds = QDir(QSL(SOUNDS_BUILTIN_DIRECTORY)).entryInfoList(QDir::Filter::Files, QDir::SortFlag::Name);
auto iter = boolinq::from(builtin_sounds).select([](const QFileInfo& i) {
return i.absoluteFilePath();
}).toStdList();
@ -652,32 +652,32 @@ void Application::parseCmdArgumentsFromOtherInstance(const QString& message) {
<< "execution message.";
#if QT_VERSION >= 0x050F00 // Qt >= 5.15.0
QStringList messages = message.split(ARGUMENTS_LIST_SEPARATOR, Qt::SplitBehaviorFlags::SkipEmptyParts);
QStringList messages = message.split(QSL(ARGUMENTS_LIST_SEPARATOR), Qt::SplitBehaviorFlags::SkipEmptyParts);
#else
QStringList messages = message.split(ARGUMENTS_LIST_SEPARATOR, QString::SplitBehavior::SkipEmptyParts);
QStringList messages = message.split(QSL(ARGUMENTS_LIST_SEPARATOR), QString::SplitBehavior::SkipEmptyParts);
#endif
QCommandLineParser cmd_parser;
messages.prepend(qApp->applicationFilePath());
cmd_parser.addOption(QCommandLineOption(QStringList() << CLI_QUIT_INSTANCE));
cmd_parser.addOption(QCommandLineOption(QStringList() << CLI_IS_RUNNING));
cmd_parser.addPositionalArgument("urls",
"List of URL addresses pointing to individual online feeds which should be added.",
"[url-1 ... url-n]");
cmd_parser.addOption(QCommandLineOption({ QSL(CLI_QUIT_INSTANCE) }));
cmd_parser.addOption(QCommandLineOption({ QSL(CLI_IS_RUNNING) }));
cmd_parser.addPositionalArgument(QSL("urls"),
QSL("List of URL addresses pointing to individual online feeds which should be added."),
QSL("[url-1 ... url-n]"));
if (!cmd_parser.parse(messages)) {
qCriticalNN << LOGSEC_CORE << cmd_parser.errorText();
}
if (cmd_parser.isSet(CLI_QUIT_INSTANCE)) {
if (cmd_parser.isSet(QSL(CLI_QUIT_INSTANCE))) {
quit();
return;
}
else if (cmd_parser.isSet(CLI_IS_RUNNING)) {
else if (cmd_parser.isSet(QSL(CLI_IS_RUNNING))) {
showGuiMessage(Notification::Event::GeneralEvent,
APP_NAME,
QSL(APP_NAME),
tr("Application is already running."),
QSystemTrayIcon::MessageIcon::Information);
mainForm()->display();
@ -705,35 +705,35 @@ void Application::parseCmdArgumentsFromOtherInstance(const QString& message) {
}
void Application::parseCmdArgumentsFromMyInstance() {
QCommandLineOption help(QStringList() << CLI_HELP_SHORT << CLI_HELP_LONG,
"Displays overview of CLI.");
QCommandLineOption version(QStringList() << CLI_VER_SHORT << CLI_VER_LONG,
"Displays version of the application.");
QCommandLineOption log_file(QStringList() << CLI_LOG_SHORT << CLI_LOG_LONG,
"Write application debug log to file. Note that logging to file may slow application down.",
"log-file");
QCommandLineOption custom_data_folder(QStringList() << CLI_DAT_SHORT << CLI_DAT_LONG,
"Use custom folder for user data and disable single instance application mode.",
"user-data-folder");
QCommandLineOption disable_singleinstance(QStringList() << CLI_SIN_SHORT << CLI_SIN_LONG,
"Allow running of multiple application instances.");
QCommandLineOption disable_debug(QStringList() << CLI_NDEBUG_SHORT << CLI_NDEBUG_LONG,
"Completely disable stdout/stderr outputs.");
QCommandLineOption help({ QSL(CLI_HELP_SHORT), QSL(CLI_HELP_LONG) },
QSL("Displays overview of CLI."));
QCommandLineOption version({ QSL(CLI_VER_SHORT), QSL(CLI_VER_LONG) },
QSL("Displays version of the application."));
QCommandLineOption log_file({ QSL(CLI_LOG_SHORT), QSL(CLI_LOG_LONG) },
QSL("Write application debug log to file. Note that logging to file may slow application down."),
QSL("log-file"));
QCommandLineOption custom_data_folder({ QSL(CLI_DAT_SHORT), QSL(CLI_DAT_LONG) },
QSL("Use custom folder for user data and disable single instance application mode."),
QSL("user-data-folder"));
QCommandLineOption disable_singleinstance({ QSL(CLI_SIN_SHORT), QSL(CLI_SIN_LONG) },
QSL("Allow running of multiple application instances."));
QCommandLineOption disable_debug({ QSL(CLI_NDEBUG_SHORT), QSL(CLI_NDEBUG_LONG) },
QSL("Completely disable stdout/stderr outputs."));
m_cmdParser.addOptions({ help, version, log_file, custom_data_folder, disable_singleinstance, disable_debug });
m_cmdParser.addPositionalArgument("urls",
"List of URL addresses pointing to individual online feeds which should be added.",
"[url-1 ... url-n]");
m_cmdParser.setApplicationDescription(APP_NAME);
m_cmdParser.addPositionalArgument(QSL("urls"),
QSL("List of URL addresses pointing to individual online feeds which should be added."),
QSL("[url-1 ... url-n]"));
m_cmdParser.setApplicationDescription(QSL(APP_NAME));
if (!m_cmdParser.parse(QCoreApplication::arguments())) {
qCriticalNN << LOGSEC_CORE << m_cmdParser.errorText();
}
s_customLogFile = m_cmdParser.value(CLI_LOG_SHORT);
s_customLogFile = m_cmdParser.value(QSL(CLI_LOG_SHORT));
if (!m_cmdParser.value(CLI_DAT_SHORT).isEmpty()) {
auto data_folder = QDir::toNativeSeparators(m_cmdParser.value(CLI_DAT_SHORT));
if (!m_cmdParser.value(QSL(CLI_DAT_SHORT)).isEmpty()) {
auto data_folder = QDir::toNativeSeparators(m_cmdParser.value(QSL(CLI_DAT_SHORT)));
qDebugNN << LOGSEC_CORE
<< "User wants to use custom directory for user data (and disable single instance mode):"
@ -745,19 +745,19 @@ void Application::parseCmdArgumentsFromMyInstance() {
m_allowMultipleInstances = false;
}
if (m_cmdParser.isSet(CLI_HELP_SHORT)) {
if (m_cmdParser.isSet(QSL(CLI_HELP_SHORT))) {
m_cmdParser.showHelp();
}
else if (m_cmdParser.isSet(CLI_VER_SHORT)) {
else if (m_cmdParser.isSet(QSL(CLI_VER_SHORT))) {
m_cmdParser.showVersion();
}
if (m_cmdParser.isSet(CLI_SIN_SHORT)) {
if (m_cmdParser.isSet(QSL(CLI_SIN_SHORT))) {
m_allowMultipleInstances = true;
qDebugNN << LOGSEC_CORE << "Explicitly allowing this instance to run.";
}
if (m_cmdParser.isSet(CLI_NDEBUG_SHORT)) {
if (m_cmdParser.isSet(QSL(CLI_NDEBUG_SHORT))) {
s_disableDebug = true;
qDebugNN << LOGSEC_CORE << "Disabling any stdout/stderr outputs.";
}

View File

@ -59,7 +59,7 @@ QList<ExternalTool> ExternalTool::toolsFromSettings() {
return tools;
}
void ExternalTool::setToolsToSettings(QList<ExternalTool>& tools) {
void ExternalTool::setToolsToSettings(QVector<ExternalTool>& tools) {
QStringList encode;
for (ExternalTool tool : tools) {

View File

@ -21,7 +21,7 @@ class ExternalTool {
public:
static ExternalTool fromString(const QString& str);
static QList<ExternalTool> toolsFromSettings();
static void setToolsToSettings(QList<ExternalTool>& tools);
static void setToolsToSettings(QVector<ExternalTool>& tools);
private:
QString m_executable;