From f28c6818276b0d9f63cd493402139d2ae19bd7f7 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Thu, 4 Mar 2021 13:59:51 +0100 Subject: [PATCH] save --- src/librssguard/core/messagesmodel.cpp | 51 +++++++++++++++++++ src/librssguard/core/messagesmodel.h | 3 ++ src/librssguard/definitions/definitions.h | 3 ++ src/librssguard/miscellaneous/iconfactory.cpp | 4 ++ .../standardfeedsimportexportmodel.cpp | 31 ++++++++--- 5 files changed, 86 insertions(+), 6 deletions(-) diff --git a/src/librssguard/core/messagesmodel.cpp b/src/librssguard/core/messagesmodel.cpp index 65fad1fa7..f46e7e447 100644 --- a/src/librssguard/core/messagesmodel.cpp +++ b/src/librssguard/core/messagesmodel.cpp @@ -13,6 +13,8 @@ #include "services/abstract/recyclebin.h" #include "services/abstract/serviceroot.h" +#include +#include #include #include @@ -38,6 +40,37 @@ void MessagesModel::setupIcons() { m_enclosuresIcon = qApp->icons()->fromTheme(QSL("mail-attachment")); } +QIcon MessagesModel::generateIconForScore(double score) { + QPixmap pix(64, 64); + QPainter paint(&pix); + + paint.setRenderHint(QPainter::RenderHint::Antialiasing); + + int level = std::min(MSG_SCORE_MAX, std::max(MSG_SCORE_MIN, int(std::floor(score / 10.0)))); + QPainterPath path; + + path.addRoundedRect(QRectF(2, 2, 60, 60), 5, 5); + + QPen pen(Qt::GlobalColor::black, 2); + + paint.setPen(pen); + paint.fillPath(path, Qt::GlobalColor::white); + paint.drawPath(path); + + path.clear(); + paint.setPen(Qt::GlobalColor::transparent); + + int bar_height = 6 * level; + + // TODO: pokračovat tady, optimalizovat voláni vytváření těch ikon, skrýt text + // a zobrazit jen ikony, barva od červené do zelené + + path.addRoundedRect(QRectF(2, 64 - bar_height - 2, 60, bar_height), 5, 5); + paint.fillPath(path, Qt::GlobalColor::green); + + return pix; +} + MessagesModelCache* MessagesModel::cache() const { return m_cache; } @@ -281,6 +314,19 @@ QVariant MessagesModel::data(const QModelIndex& idx, int role) const { case Qt::ItemDataRole::EditRole: return m_cache->containsData(idx.row()) ? m_cache->data(idx) : QSqlQueryModel::data(idx, role); + case Qt::ItemDataRole::ToolTipRole: { + if (idx.column() == MSG_DB_SCORE_INDEX) { + QVariant dta = m_cache->containsData(idx.row()) + ? m_cache->data(idx) + : QSqlQueryModel::data(idx); + + return dta.toString(); + } + else { + return QVariant(); + } + } + case Qt::ItemDataRole::FontRole: { QModelIndex idx_read = index(idx.row(), MSG_DB_READ_INDEX); QVariant data_read = data(idx_read, Qt::EditRole); @@ -367,6 +413,11 @@ QVariant MessagesModel::data(const QModelIndex& idx, int role) const { return dta.toBool() ? m_enclosuresIcon : QVariant(); } + else if (index_column == MSG_DB_SCORE_INDEX) { + QVariant dta = QSqlQueryModel::data(idx); + + return generateIconForScore(dta.toDouble()); + } else { return QVariant(); } diff --git a/src/librssguard/core/messagesmodel.h b/src/librssguard/core/messagesmodel.h index b886e373a..5324fdd54 100644 --- a/src/librssguard/core/messagesmodel.h +++ b/src/librssguard/core/messagesmodel.h @@ -85,6 +85,9 @@ class MessagesModel : public QSqlQueryModel, public MessagesModelSqlLayer { void setupHeaderData(); void setupIcons(); + static QIcon generateIconForScore(double score); + + private: MessagesModelCache* m_cache; MessageHighlighter m_messageHighlighter; QString m_customDateFormat; diff --git a/src/librssguard/definitions/definitions.h b/src/librssguard/definitions/definitions.h index f0aedb683..a11472e51 100755 --- a/src/librssguard/definitions/definitions.h +++ b/src/librssguard/definitions/definitions.h @@ -39,6 +39,9 @@ #define ID_IMPORTANT -3 #define ID_LABELS -4 +#define MSG_SCORE_MAX 100 +#define MSG_SCORE_MIN 0 + #define ARGUMENTS_LIST_SEPARATOR "\n" #define IS_IN_ARRAY(offset, array) ((offset >= 0) && (offset < array.count())) #define DEFAULT_SQL_MESSAGES_FILTER "0 > 1" diff --git a/src/librssguard/miscellaneous/iconfactory.cpp b/src/librssguard/miscellaneous/iconfactory.cpp index 3b93dc7eb..8714d9367 100755 --- a/src/librssguard/miscellaneous/iconfactory.cpp +++ b/src/librssguard/miscellaneous/iconfactory.cpp @@ -14,6 +14,10 @@ IconFactory::~IconFactory() { } QIcon IconFactory::fromByteArray(QByteArray array) { + if (array.isEmpty()) { + return {}; + } + array = QByteArray::fromBase64(array); QIcon icon; QBuffer buffer(&array); diff --git a/src/librssguard/services/standard/standardfeedsimportexportmodel.cpp b/src/librssguard/services/standard/standardfeedsimportexportmodel.cpp index 5bd8d1e3a..3884d0725 100644 --- a/src/librssguard/services/standard/standardfeedsimportexportmodel.cpp +++ b/src/librssguard/services/standard/standardfeedsimportexportmodel.cpp @@ -76,7 +76,11 @@ bool FeedsImportExportModel::exportToOMPL20(QByteArray& result) { outline_category.setAttribute(QSL("text"), child_item->title()); outline_category.setAttribute(QSL("description"), child_item->description()); - outline_category.setAttribute(QSL("rssguard:icon"), QString(qApp->icons()->toByteArray(child_item->icon()))); + + if (!child_item->icon().isNull()) { + outline_category.setAttributeNS(APP_URL, QSL("rssguard:icon"), QString(qApp->icons()->toByteArray(child_item->icon()))); + } + active_element.appendChild(outline_category); items_to_process.push(child_item); elements_to_use.push(outline_category); @@ -93,7 +97,13 @@ bool FeedsImportExportModel::exportToOMPL20(QByteArray& result) { outline_feed.setAttribute(QSL("description"), child_feed->description()); outline_feed.setAttribute(QSL("encoding"), child_feed->encoding()); outline_feed.setAttribute(QSL("title"), child_feed->title()); - outline_feed.setAttribute(QSL("rssguard:icon"), QString(qApp->icons()->toByteArray(child_feed->icon()))); + + outline_feed.setAttributeNS(APP_URL, QSL("rssguard:xmlUrlType"), QString::number(int(child_feed->sourceType()))); + outline_feed.setAttributeNS(APP_URL, QSL("rssguard:postProcess"), child_feed->postProcessScript()); + + if (!child_feed->icon().isNull()) { + outline_feed.setAttributeNS(APP_URL, QSL("rssguard:icon"), QString(qApp->icons()->toByteArray(child_feed->icon()))); + } switch (child_feed->type()) { case StandardFeed::Type::Rss0X: @@ -205,7 +215,9 @@ void FeedsImportExportModel::importAsOPML20(const QByteArray& data, bool fetch_m QString feed_encoding = child_element.attribute(QSL("encoding"), DEFAULT_FEED_ENCODING); QString feed_type = child_element.attribute(QSL("version"), DEFAULT_FEED_TYPE).toUpper(); QString feed_description = child_element.attribute(QSL("description")); - QIcon feed_icon = qApp->icons()->fromByteArray(child_element.attribute(QSL("rssguard:icon")).toLocal8Bit()); + QIcon feed_icon = qApp->icons()->fromByteArray(child_element.attributeNS(APP_URL, QSL("icon")).toLocal8Bit()); + QString source_type = child_element.attributeNS(APP_URL, QSL("xmlUrlType")); + QString post_process = child_element.attributeNS(APP_URL, QSL("postProcess")); auto* new_feed = new StandardFeed(active_model_item); new_feed->setTitle(feed_title); @@ -213,7 +225,10 @@ void FeedsImportExportModel::importAsOPML20(const QByteArray& data, bool fetch_m new_feed->setEncoding(feed_encoding); new_feed->setSource(feed_url); new_feed->setCreationDate(QDateTime::currentDateTime()); - new_feed->setIcon(feed_icon); + + if (!feed_icon.isNull()) { + new_feed->setIcon(feed_icon); + } if (feed_type == QL1S("RSS1")) { new_feed->setType(StandardFeed::Type::Rdf); @@ -244,7 +259,7 @@ void FeedsImportExportModel::importAsOPML20(const QByteArray& data, bool fetch_m // Add category and continue. QString category_title = child_element.attribute(QSL("text")); QString category_description = child_element.attribute(QSL("description")); - QIcon category_icon = qApp->icons()->fromByteArray(child_element.attribute(QSL("rssguard:icon")).toLocal8Bit()); + QIcon category_icon = qApp->icons()->fromByteArray(child_element.attributeNS(APP_URL, QSL("icon")).toLocal8Bit()); if (category_title.isEmpty()) { qWarningNN << LOGSEC_CORE @@ -259,7 +274,11 @@ void FeedsImportExportModel::importAsOPML20(const QByteArray& data, bool fetch_m auto* new_category = new StandardCategory(active_model_item); new_category->setTitle(category_title); - new_category->setIcon(category_icon); + + if (!category_icon.isNull()) { + new_category->setIcon(category_icon); + } + new_category->setCreationDate(QDateTime::currentDateTime()); new_category->setDescription(category_description); active_model_item->appendChild(new_category);