mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-02-03 10:47:47 +01:00
save
This commit is contained in:
parent
56c4619cfd
commit
f28c681827
@ -13,6 +13,8 @@
|
|||||||
#include "services/abstract/recyclebin.h"
|
#include "services/abstract/recyclebin.h"
|
||||||
#include "services/abstract/serviceroot.h"
|
#include "services/abstract/serviceroot.h"
|
||||||
|
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPainterPath>
|
||||||
#include <QSqlError>
|
#include <QSqlError>
|
||||||
#include <QSqlField>
|
#include <QSqlField>
|
||||||
|
|
||||||
@ -38,6 +40,37 @@ void MessagesModel::setupIcons() {
|
|||||||
m_enclosuresIcon = qApp->icons()->fromTheme(QSL("mail-attachment"));
|
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 {
|
MessagesModelCache* MessagesModel::cache() const {
|
||||||
return m_cache;
|
return m_cache;
|
||||||
}
|
}
|
||||||
@ -281,6 +314,19 @@ QVariant MessagesModel::data(const QModelIndex& idx, int role) const {
|
|||||||
case Qt::ItemDataRole::EditRole:
|
case Qt::ItemDataRole::EditRole:
|
||||||
return m_cache->containsData(idx.row()) ? m_cache->data(idx) : QSqlQueryModel::data(idx, role);
|
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: {
|
case Qt::ItemDataRole::FontRole: {
|
||||||
QModelIndex idx_read = index(idx.row(), MSG_DB_READ_INDEX);
|
QModelIndex idx_read = index(idx.row(), MSG_DB_READ_INDEX);
|
||||||
QVariant data_read = data(idx_read, Qt::EditRole);
|
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();
|
return dta.toBool() ? m_enclosuresIcon : QVariant();
|
||||||
}
|
}
|
||||||
|
else if (index_column == MSG_DB_SCORE_INDEX) {
|
||||||
|
QVariant dta = QSqlQueryModel::data(idx);
|
||||||
|
|
||||||
|
return generateIconForScore(dta.toDouble());
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,9 @@ class MessagesModel : public QSqlQueryModel, public MessagesModelSqlLayer {
|
|||||||
void setupHeaderData();
|
void setupHeaderData();
|
||||||
void setupIcons();
|
void setupIcons();
|
||||||
|
|
||||||
|
static QIcon generateIconForScore(double score);
|
||||||
|
|
||||||
|
private:
|
||||||
MessagesModelCache* m_cache;
|
MessagesModelCache* m_cache;
|
||||||
MessageHighlighter m_messageHighlighter;
|
MessageHighlighter m_messageHighlighter;
|
||||||
QString m_customDateFormat;
|
QString m_customDateFormat;
|
||||||
|
@ -39,6 +39,9 @@
|
|||||||
#define ID_IMPORTANT -3
|
#define ID_IMPORTANT -3
|
||||||
#define ID_LABELS -4
|
#define ID_LABELS -4
|
||||||
|
|
||||||
|
#define MSG_SCORE_MAX 100
|
||||||
|
#define MSG_SCORE_MIN 0
|
||||||
|
|
||||||
#define ARGUMENTS_LIST_SEPARATOR "\n"
|
#define ARGUMENTS_LIST_SEPARATOR "\n"
|
||||||
#define IS_IN_ARRAY(offset, array) ((offset >= 0) && (offset < array.count()))
|
#define IS_IN_ARRAY(offset, array) ((offset >= 0) && (offset < array.count()))
|
||||||
#define DEFAULT_SQL_MESSAGES_FILTER "0 > 1"
|
#define DEFAULT_SQL_MESSAGES_FILTER "0 > 1"
|
||||||
|
@ -14,6 +14,10 @@ IconFactory::~IconFactory() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QIcon IconFactory::fromByteArray(QByteArray array) {
|
QIcon IconFactory::fromByteArray(QByteArray array) {
|
||||||
|
if (array.isEmpty()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
array = QByteArray::fromBase64(array);
|
array = QByteArray::fromBase64(array);
|
||||||
QIcon icon;
|
QIcon icon;
|
||||||
QBuffer buffer(&array);
|
QBuffer buffer(&array);
|
||||||
|
@ -76,7 +76,11 @@ bool FeedsImportExportModel::exportToOMPL20(QByteArray& result) {
|
|||||||
|
|
||||||
outline_category.setAttribute(QSL("text"), child_item->title());
|
outline_category.setAttribute(QSL("text"), child_item->title());
|
||||||
outline_category.setAttribute(QSL("description"), child_item->description());
|
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);
|
active_element.appendChild(outline_category);
|
||||||
items_to_process.push(child_item);
|
items_to_process.push(child_item);
|
||||||
elements_to_use.push(outline_category);
|
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("description"), child_feed->description());
|
||||||
outline_feed.setAttribute(QSL("encoding"), child_feed->encoding());
|
outline_feed.setAttribute(QSL("encoding"), child_feed->encoding());
|
||||||
outline_feed.setAttribute(QSL("title"), child_feed->title());
|
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()) {
|
switch (child_feed->type()) {
|
||||||
case StandardFeed::Type::Rss0X:
|
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_encoding = child_element.attribute(QSL("encoding"), DEFAULT_FEED_ENCODING);
|
||||||
QString feed_type = child_element.attribute(QSL("version"), DEFAULT_FEED_TYPE).toUpper();
|
QString feed_type = child_element.attribute(QSL("version"), DEFAULT_FEED_TYPE).toUpper();
|
||||||
QString feed_description = child_element.attribute(QSL("description"));
|
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);
|
auto* new_feed = new StandardFeed(active_model_item);
|
||||||
|
|
||||||
new_feed->setTitle(feed_title);
|
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->setEncoding(feed_encoding);
|
||||||
new_feed->setSource(feed_url);
|
new_feed->setSource(feed_url);
|
||||||
new_feed->setCreationDate(QDateTime::currentDateTime());
|
new_feed->setCreationDate(QDateTime::currentDateTime());
|
||||||
|
|
||||||
|
if (!feed_icon.isNull()) {
|
||||||
new_feed->setIcon(feed_icon);
|
new_feed->setIcon(feed_icon);
|
||||||
|
}
|
||||||
|
|
||||||
if (feed_type == QL1S("RSS1")) {
|
if (feed_type == QL1S("RSS1")) {
|
||||||
new_feed->setType(StandardFeed::Type::Rdf);
|
new_feed->setType(StandardFeed::Type::Rdf);
|
||||||
@ -244,7 +259,7 @@ void FeedsImportExportModel::importAsOPML20(const QByteArray& data, bool fetch_m
|
|||||||
// Add category and continue.
|
// Add category and continue.
|
||||||
QString category_title = child_element.attribute(QSL("text"));
|
QString category_title = child_element.attribute(QSL("text"));
|
||||||
QString category_description = child_element.attribute(QSL("description"));
|
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()) {
|
if (category_title.isEmpty()) {
|
||||||
qWarningNN << LOGSEC_CORE
|
qWarningNN << LOGSEC_CORE
|
||||||
@ -259,7 +274,11 @@ void FeedsImportExportModel::importAsOPML20(const QByteArray& data, bool fetch_m
|
|||||||
auto* new_category = new StandardCategory(active_model_item);
|
auto* new_category = new StandardCategory(active_model_item);
|
||||||
|
|
||||||
new_category->setTitle(category_title);
|
new_category->setTitle(category_title);
|
||||||
|
|
||||||
|
if (!category_icon.isNull()) {
|
||||||
new_category->setIcon(category_icon);
|
new_category->setIcon(category_icon);
|
||||||
|
}
|
||||||
|
|
||||||
new_category->setCreationDate(QDateTime::currentDateTime());
|
new_category->setCreationDate(QDateTime::currentDateTime());
|
||||||
new_category->setDescription(category_description);
|
new_category->setDescription(category_description);
|
||||||
active_model_item->appendChild(new_category);
|
active_model_item->appendChild(new_category);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user