This commit is contained in:
Martin Rotter 2020-08-06 07:57:01 +02:00
parent 8ca1b7f3ae
commit 092b862da9
7 changed files with 52 additions and 38 deletions

View file

@ -35,7 +35,7 @@ FeedsProxyModel::FeedsProxyModel(FeedsModel* source_model, QObject* parent)
}
FeedsProxyModel::~FeedsProxyModel() {
qDebug("Destroying FeedsProxyModel instance");
qDebugNN << LOGSEC_FEEDMODEL << "Destroying FeedsProxyModel instance";
}
QModelIndexList FeedsProxyModel::match(const QModelIndex& start, int role, const QVariant& value, int hits, Qt::MatchFlags flags) const {
@ -62,7 +62,7 @@ QModelIndexList FeedsProxyModel::match(const QModelIndex& start, int role, const
QVariant item_value = m_sourceModel->itemForIndex(mapped_idx)->title();
// QVariant based matching.
if (match_type == Qt::MatchExactly) {
if (match_type == Qt::MatchFlag::MatchExactly) {
if (value == item_value) {
result.append(idx);
}
@ -78,9 +78,9 @@ QModelIndexList FeedsProxyModel::match(const QModelIndex& start, int role, const
switch (match_type) {
#if QT_VERSION >= 0x050F00 // Qt >= 5.15.0
case Qt::MatchRegularExpression:
case Qt::MatchFlag::MatchRegularExpression:
#else
case Qt::MatchRegExp:
case Qt::MatchFlag::MatchRegExp:
#endif
if (QRegularExpression(entered_text,
QRegularExpression::PatternOption::CaseInsensitiveOption |
@ -90,7 +90,7 @@ QModelIndexList FeedsProxyModel::match(const QModelIndex& start, int role, const
break;
case Qt::MatchWildcard:
case Qt::MatchFlag::MatchWildcard:
if (QRegularExpression(RegexFactory::wildcardToRegularExpression(entered_text),
QRegularExpression::PatternOption::CaseInsensitiveOption |
QRegularExpression::PatternOption::UseUnicodePropertiesOption).match(item_text).hasMatch()) {
@ -99,28 +99,28 @@ QModelIndexList FeedsProxyModel::match(const QModelIndex& start, int role, const
break;
case Qt::MatchStartsWith:
case Qt::MatchFlag::MatchStartsWith:
if (item_text.startsWith(entered_text, cs)) {
result.append(idx);
}
break;
case Qt::MatchEndsWith:
case Qt::MatchFlag::MatchEndsWith:
if (item_text.endsWith(entered_text, cs)) {
result.append(idx);
}
break;
case Qt::MatchFixedString:
case Qt::MatchFlag::MatchFixedString:
if (item_text.compare(entered_text, cs) == 0) {
result.append(idx);
}
break;
case Qt::MatchContains:
case Qt::MatchFlag::MatchContains:
default:
if (item_text.contains(entered_text, cs)) {
result.append(idx);

View file

@ -4,6 +4,7 @@
#include "miscellaneous/textfactory.h"
#include <QDebug>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
@ -146,7 +147,10 @@ void MessageObject::setMessage(Message* message) {
bool MessageObject::isDuplicateWithAttribute(int attribute_check) const {
if (attribute_check <= 0) {
qCritical("Bad DuplicationAttributeCheck value '%d' was passed from JS filter script.", attribute_check);
qCriticalNN << LOGSEC_MESSAGEMODEL
<< "Bad DuplicationAttributeCheck value '"
<< attribute_check
<< "' was passed from JS filter script.";
return true;
}
@ -198,13 +202,18 @@ bool MessageObject::isDuplicateWithAttribute(int attribute_check) const {
if (q.exec() && q.next()) {
if (q.record().value(0).toInt() > 0) {
// Whoops, we have the "same" message in database.
qDebug("Message '%s' was identified as duplicate by filter script.", qPrintable(title()));
qDebugNN << LOGSEC_MESSAGEMODEL
<< "Message '"
<< title()
<< "' was identified as duplicate by filter script.";
return true;
}
}
else if (q.lastError().isValid()) {
qWarning("Error when checking for duplicate messages via filtering system, error: '%s'.",
qPrintable(q.lastError().text()));
qWarningNN << LOGSEC_MESSAGEMODEL
<< "Error when checking for duplicate messages via filtering system, error: '"
<< q.lastError().text()
<< "'.";
}
return false;

View file

@ -27,20 +27,19 @@ FilteringAction MessageFilter::filterMessage(QJSEngine* engine) {
// of DuplicationAttributeCheck enumeration (see file core/message.h).
//
// Example filtering script might look like this:
//
// function helper() {
// if (msg.title.includes("A")) {
// msg.isImportant = true;
// }
//
// return 1;
// }
//
// function filterMessage() {
// return helper();
// }
/*
function helper() {
if (msg.title.includes("A")) {
msg.isImportant = true;
}
return 1;
}
function filterMessage() {
return helper();
}
*/
QJSValue filter_func = engine->evaluate(m_script);
if (filter_func.isError()) {

View file

@ -27,7 +27,7 @@ MessagesModel::MessagesModel(QObject* parent)
}
MessagesModel::~MessagesModel() {
qDebug("Destroying MessagesModel instance.");
qDebugNN << LOGSEC_MESSAGEMODEL << "Destroying MessagesModel instance.";
}
void MessagesModel::setupIcons() {
@ -37,8 +37,7 @@ void MessagesModel::setupIcons() {
m_enclosuresIcon = qApp->icons()->fromTheme(QSL("mail-attachment"));
}
MessagesModelCache* MessagesModel::cache() const
{
MessagesModelCache* MessagesModel::cache() const {
return m_cache;
}
@ -47,8 +46,8 @@ void MessagesModel::repopulate() {
setQuery(selectStatement(), m_db);
if (lastError().isValid()) {
qCritical() << "Error when setting new msg view query:" << lastError().text();
qCritical() << "Used SQL select statement:" << selectStatement();
qCriticalNN << LOGSEC_MESSAGEMODEL << "Error when setting new msg view query: '" << lastError().text() << "'.";
qCriticalNN << LOGSEC_MESSAGEMODEL << "Used SQL select statement: '" << selectStatement() << "'.";
}
while (canFetchMore()) {
@ -94,10 +93,12 @@ void MessagesModel::loadMessages(RootItem* item) {
else {
if (!item->getParentServiceRoot()->loadMessagesForItem(item, this)) {
setFilter(QSL(DEFAULT_SQL_MESSAGES_FILTER));
qWarning("Loading of messages from item '%s' failed.", qPrintable(item->title()));
qCriticalNN << LOGSEC_MESSAGEMODEL
<< "Loading of messages from item '"
<< item->title() << "' failed.";
qApp->showGuiMessage(tr("Loading of messages from item '%1' failed.").arg(item->title()),
tr("Loading of messages failed, maybe messages could not be downloaded."),
QSystemTrayIcon::Critical,
QSystemTrayIcon::MessageIcon::Critical,
qApp->mainFormWidget(),
true);
}
@ -135,7 +136,7 @@ int MessagesModel::messageId(int row_index) const {
}
RootItem::Importance MessagesModel::messageImportance(int row_index) const {
return (RootItem::Importance) data(row_index, MSG_DB_IMPORTANT_INDEX, Qt::EditRole).toInt();
return RootItem::Importance(data(row_index, MSG_DB_IMPORTANT_INDEX, Qt::EditRole).toInt());
}
RootItem* MessagesModel::loadedItem() const {
@ -414,7 +415,7 @@ bool MessagesModel::switchMessageImportance(int row_index) {
if (!working_change) {
// If rewriting in the model failed, then cancel all actions.
qDebug("Setting of new data to the model failed for message importance change.");
qDebugNN << LOGSEC_MESSAGEMODEL << "Setting of new data to the model failed for message importance change.";
return false;
}

View file

@ -56,7 +56,7 @@ void MessagesModelSqlLayer::addSortState(int column, Qt::SortOrder order) {
m_sortOrders.removeAt(existing);
}
if (m_sortColumns.size() > MAX_MULTICOLUMN_SORT_STATES) {
if (m_sortColumns.size() >= MAX_MULTICOLUMN_SORT_STATES) {
// We support only limited number of sort states
// due to DB performance.
m_sortColumns.removeAt(0);
@ -73,7 +73,10 @@ void MessagesModelSqlLayer::addSortState(int column, Qt::SortOrder order) {
m_sortOrders.prepend(order);
}
qDebug("Added sort state, select statement is now:\n'%s'", qPrintable(selectStatement()));
qDebugNN << LOGSEC_MESSAGEMODEL
<< "Added sort state, select statement is now:\n'"
<< selectStatement()
<< "'";
}
void MessagesModelSqlLayer::setFilter(const QString& filter) {

View file

@ -26,7 +26,7 @@ MessagesProxyModel::MessagesProxyModel(MessagesModel* source_model, QObject* par
}
MessagesProxyModel::~MessagesProxyModel() {
qDebug("Destroying MessagesProxyModel instance.");
qDebugNN << LOGSEC_MESSAGEMODEL << "Destroying MessagesProxyModel instance.";
}
QModelIndex MessagesProxyModel::getNextPreviousUnreadItemIndex(int default_row) {

View file

@ -3,6 +3,7 @@
#ifndef DEFINITIONS_H
#define DEFINITIONS_H
#include <QDebug>
#include <QtGlobal>
#define SERVICE_CODE_STD_RSS "std-rss"
@ -84,6 +85,7 @@
#define LOGSEC_FEEDMODEL "feed-model: "
#define LOGSEC_FEEDDOWNLOADER "feed-downloader: "
#define LOGSEC_MESSAGEMODEL "message-model: "
#define MAX_ZOOM_FACTOR 5.0f
#define MIN_ZOOM_FACTOR 0.25f