diff --git a/src/gui/messagepreviewer.cpp b/src/gui/messagepreviewer.cpp index 8728e2dfa..4c7ae55da 100644 --- a/src/gui/messagepreviewer.cpp +++ b/src/gui/messagepreviewer.cpp @@ -35,29 +35,35 @@ MessagePreviewer::MessagePreviewer(QWidget *parent) : QWidget(parent), m_ui->m_txtMessage->viewport()->setAutoFillBackground(true); connect(m_ui->m_txtMessage, &QTextBrowser::anchorClicked, [=](const QUrl &url) { - // User clicked some URL. Open it in external browser or download? - MessageBox box(qApp->mainForm()); + if (!url.isEmpty()) { + // User clicked some URL. Open it in external browser or download? + MessageBox box(qApp->mainForm()); - box.setText(tr("You clicked some link. You can download the link contents or open it in external web browser.")); - box.setInformativeText(tr("What action do you want to take?")); - box.setDetailedText(url.toString()); - QAbstractButton *btn_open = box.addButton(tr("Open in external browser"), QMessageBox::AcceptRole); - QAbstractButton *btn_download = box.addButton(tr("Download"), QMessageBox::RejectRole); - QAbstractButton *btn_cancel = box.addButton(QMessageBox::Cancel); + box.setText(tr("You clicked some link. You can download the link contents or open it in external web browser.")); + box.setInformativeText(tr("What action do you want to take?")); + box.setDetailedText(url.toString()); + QAbstractButton *btn_open = box.addButton(tr("Open in external browser"), QMessageBox::AcceptRole); + QAbstractButton *btn_download = box.addButton(tr("Download"), QMessageBox::RejectRole); + QAbstractButton *btn_cancel = box.addButton(QMessageBox::Cancel); - box.setDefaultButton(QMessageBox::Cancel); - box.exec(); + box.setDefaultButton(QMessageBox::Cancel); + box.exec(); - if (box.clickedButton() == btn_open) { - WebFactory::instance()->openUrlInExternalBrowser(url.toString()); + if (box.clickedButton() == btn_open) { + WebFactory::instance()->openUrlInExternalBrowser(url.toString()); + } + else if (box.clickedButton() == btn_download) { + qApp->downloadManager()->download(url); + } + + btn_download->deleteLater(); + btn_open->deleteLater(); + btn_cancel->deleteLater(); } - else if (box.clickedButton() == btn_download) { - qApp->downloadManager()->download(url); + else { + MessageBox::show(qApp->mainForm(), QMessageBox::Warning, tr("Incorrect link"), + tr("Selected hyperlink is invalid.")); } - - btn_download->deleteLater(); - btn_open->deleteLater(); - btn_cancel->deleteLater(); }); m_toolBar = new QToolBar(this); @@ -130,8 +136,8 @@ void MessagePreviewer::markMessageAsRead() { QList() << m_message, RootItem::Read)) { DatabaseQueries::markMessagesReadUnread(qApp->database()->connection(objectName(), DatabaseFactory::FromSettings), - QStringList() << QString::number(m_message.m_id), - RootItem::Read); + QStringList() << QString::number(m_message.m_id), + RootItem::Read); m_root->getParentServiceRoot()->onAfterSetMessagesRead(m_root.data(), QList() << m_message, RootItem::Read); @@ -149,8 +155,8 @@ void MessagePreviewer::markMessageAsUnread() { QList() << m_message, RootItem::Unread)) { DatabaseQueries::markMessagesReadUnread(qApp->database()->connection(objectName(), DatabaseFactory::FromSettings), - QStringList() << QString::number(m_message.m_id), - RootItem::Unread); + QStringList() << QString::number(m_message.m_id), + RootItem::Unread); m_root->getParentServiceRoot()->onAfterSetMessagesRead(m_root.data(), QList() << m_message, RootItem::Unread); diff --git a/src/gui/messagetextbrowser.cpp b/src/gui/messagetextbrowser.cpp index c395ac800..d201d01d3 100644 --- a/src/gui/messagetextbrowser.cpp +++ b/src/gui/messagetextbrowser.cpp @@ -2,6 +2,7 @@ #include "miscellaneous/application.h" #include "miscellaneous/iconfactory.h" +#include "network-web/networkfactory.h" MessageTextBrowser::MessageTextBrowser(QWidget *parent) : QTextBrowser(parent) { diff --git a/src/miscellaneous/databasequeries.cpp b/src/miscellaneous/databasequeries.cpp index f1ef39cca..47681767a 100644 --- a/src/miscellaneous/databasequeries.cpp +++ b/src/miscellaneous/databasequeries.cpp @@ -220,20 +220,20 @@ QMap DatabaseQueries::getMessageCountsForCategory(QSqlDatabase db, int return counts; } -QMap DatabaseQueries::getMessageCountsForAccount(QSqlDatabase db, int account_id, - bool including_total_counts, bool *ok) { - QMap counts; +QMap > DatabaseQueries::getMessageCountsForAccount(QSqlDatabase db, int account_id, + bool including_total_counts, bool *ok) { + QMap > counts; QSqlQuery q(db); q.setForwardOnly(true); if (including_total_counts) { - q.prepare("SELECT feed, count(*) FROM Messages " + q.prepare("SELECT feed, sum((is_read + 1) % 2), count(*) FROM Messages " "WHERE feed IN (SELECT custom_id FROM Feeds WHERE 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, count(*) FROM Messages " - "WHERE feed IN (SELECT custom_id FROM Feeds WHERE account_id = :account_id) AND is_deleted = 0 AND is_pdeleted = 0 AND is_read = 0 AND account_id = :account_id " + q.prepare("SELECT feed, sum((is_read + 1) % 2) FROM Messages " + "WHERE feed IN (SELECT custom_id FROM Feeds WHERE account_id = :account_id) AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id " "GROUP BY feed;"); } @@ -242,9 +242,16 @@ QMap DatabaseQueries::getMessageCountsForAccount(QSqlDatabase db, int a if (q.exec()) { while (q.next()) { int feed_id = q.value(0).toInt(); - int new_count = q.value(1).toInt(); + int unread_count = q.value(1).toInt(); - counts.insert(feed_id, new_count); + if (including_total_counts) { + int total_count = q.value(2).toInt(); + + counts.insert(feed_id, QPair(unread_count, total_count)); + } + else { + counts.insert(feed_id, QPair(unread_count, 0)); + } } if (ok != NULL) { diff --git a/src/miscellaneous/databasequeries.h b/src/miscellaneous/databasequeries.h index 97ae93352..571d64092 100644 --- a/src/miscellaneous/databasequeries.h +++ b/src/miscellaneous/databasequeries.h @@ -43,7 +43,7 @@ class DatabaseQueries { static bool purgeRecycleBin(QSqlDatabase db); static QMap getMessageCountsForCategory(QSqlDatabase db, int custom_id, int account_id, bool including_total_counts, bool *ok = NULL); - static QMap getMessageCountsForAccount(QSqlDatabase db, int account_id, + static QMap > getMessageCountsForAccount(QSqlDatabase db, int account_id, bool including_total_counts, bool *ok = NULL); static int getMessageCountsForFeed(QSqlDatabase db, int feed_custom_id, int account_id, bool including_total_counts, bool *ok = NULL); diff --git a/src/services/abstract/serviceroot.cpp b/src/services/abstract/serviceroot.cpp index 2d576d2ef..be8dd9062 100755 --- a/src/services/abstract/serviceroot.cpp +++ b/src/services/abstract/serviceroot.cpp @@ -93,22 +93,13 @@ void ServiceRoot::updateCounts(bool including_total_count) { QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); bool ok; + QMap > counts = DatabaseQueries::getMessageCountsForAccount(database, accountId(), including_total_count, &ok); - if (including_total_count) { - QMap counts = DatabaseQueries::getMessageCountsForAccount(database, accountId(), including_total_count, &ok); + foreach (Feed *feed, feeds) { + feed->setCountOfUnreadMessages(counts.value(feed->customId()).first); - if (ok) { - foreach (Feed *feed, feeds) { - feed->setCountOfAllMessages(counts.value(feed->customId())); - } - } - } - - QMap counts = DatabaseQueries::getMessageCountsForAccount(database, accountId(), false, &ok); - - if (ok) { - foreach (Feed *feed, feeds) { - feed->setCountOfUnreadMessages(counts.value(feed->customId())); + if (including_total_count) { + feed->setCountOfAllMessages(counts.value(feed->customId()).second); } } }