Some performance tweaks etc.
This commit is contained in:
parent
ba3fcde339
commit
45aa2f4ae2
@ -35,29 +35,35 @@ MessagePreviewer::MessagePreviewer(QWidget *parent) : QWidget(parent),
|
|||||||
m_ui->m_txtMessage->viewport()->setAutoFillBackground(true);
|
m_ui->m_txtMessage->viewport()->setAutoFillBackground(true);
|
||||||
|
|
||||||
connect(m_ui->m_txtMessage, &QTextBrowser::anchorClicked, [=](const QUrl &url) {
|
connect(m_ui->m_txtMessage, &QTextBrowser::anchorClicked, [=](const QUrl &url) {
|
||||||
// User clicked some URL. Open it in external browser or download?
|
if (!url.isEmpty()) {
|
||||||
MessageBox box(qApp->mainForm());
|
// 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.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.setInformativeText(tr("What action do you want to take?"));
|
||||||
box.setDetailedText(url.toString());
|
box.setDetailedText(url.toString());
|
||||||
QAbstractButton *btn_open = box.addButton(tr("Open in external browser"), QMessageBox::AcceptRole);
|
QAbstractButton *btn_open = box.addButton(tr("Open in external browser"), QMessageBox::AcceptRole);
|
||||||
QAbstractButton *btn_download = box.addButton(tr("Download"), QMessageBox::RejectRole);
|
QAbstractButton *btn_download = box.addButton(tr("Download"), QMessageBox::RejectRole);
|
||||||
QAbstractButton *btn_cancel = box.addButton(QMessageBox::Cancel);
|
QAbstractButton *btn_cancel = box.addButton(QMessageBox::Cancel);
|
||||||
|
|
||||||
box.setDefaultButton(QMessageBox::Cancel);
|
box.setDefaultButton(QMessageBox::Cancel);
|
||||||
box.exec();
|
box.exec();
|
||||||
|
|
||||||
if (box.clickedButton() == btn_open) {
|
if (box.clickedButton() == btn_open) {
|
||||||
WebFactory::instance()->openUrlInExternalBrowser(url.toString());
|
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) {
|
else {
|
||||||
qApp->downloadManager()->download(url);
|
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);
|
m_toolBar = new QToolBar(this);
|
||||||
@ -130,8 +136,8 @@ void MessagePreviewer::markMessageAsRead() {
|
|||||||
QList<Message>() << m_message,
|
QList<Message>() << m_message,
|
||||||
RootItem::Read)) {
|
RootItem::Read)) {
|
||||||
DatabaseQueries::markMessagesReadUnread(qApp->database()->connection(objectName(), DatabaseFactory::FromSettings),
|
DatabaseQueries::markMessagesReadUnread(qApp->database()->connection(objectName(), DatabaseFactory::FromSettings),
|
||||||
QStringList() << QString::number(m_message.m_id),
|
QStringList() << QString::number(m_message.m_id),
|
||||||
RootItem::Read);
|
RootItem::Read);
|
||||||
m_root->getParentServiceRoot()->onAfterSetMessagesRead(m_root.data(),
|
m_root->getParentServiceRoot()->onAfterSetMessagesRead(m_root.data(),
|
||||||
QList<Message>() << m_message,
|
QList<Message>() << m_message,
|
||||||
RootItem::Read);
|
RootItem::Read);
|
||||||
@ -149,8 +155,8 @@ void MessagePreviewer::markMessageAsUnread() {
|
|||||||
QList<Message>() << m_message,
|
QList<Message>() << m_message,
|
||||||
RootItem::Unread)) {
|
RootItem::Unread)) {
|
||||||
DatabaseQueries::markMessagesReadUnread(qApp->database()->connection(objectName(), DatabaseFactory::FromSettings),
|
DatabaseQueries::markMessagesReadUnread(qApp->database()->connection(objectName(), DatabaseFactory::FromSettings),
|
||||||
QStringList() << QString::number(m_message.m_id),
|
QStringList() << QString::number(m_message.m_id),
|
||||||
RootItem::Unread);
|
RootItem::Unread);
|
||||||
m_root->getParentServiceRoot()->onAfterSetMessagesRead(m_root.data(),
|
m_root->getParentServiceRoot()->onAfterSetMessagesRead(m_root.data(),
|
||||||
QList<Message>() << m_message,
|
QList<Message>() << m_message,
|
||||||
RootItem::Unread);
|
RootItem::Unread);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "miscellaneous/application.h"
|
#include "miscellaneous/application.h"
|
||||||
#include "miscellaneous/iconfactory.h"
|
#include "miscellaneous/iconfactory.h"
|
||||||
|
#include "network-web/networkfactory.h"
|
||||||
|
|
||||||
|
|
||||||
MessageTextBrowser::MessageTextBrowser(QWidget *parent) : QTextBrowser(parent) {
|
MessageTextBrowser::MessageTextBrowser(QWidget *parent) : QTextBrowser(parent) {
|
||||||
|
@ -220,20 +220,20 @@ QMap<int,int> DatabaseQueries::getMessageCountsForCategory(QSqlDatabase db, int
|
|||||||
return counts;
|
return counts;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<int,int> DatabaseQueries::getMessageCountsForAccount(QSqlDatabase db, int account_id,
|
QMap<int, QPair<int,int> > DatabaseQueries::getMessageCountsForAccount(QSqlDatabase db, int account_id,
|
||||||
bool including_total_counts, bool *ok) {
|
bool including_total_counts, bool *ok) {
|
||||||
QMap<int,int> counts;
|
QMap<int, QPair<int,int> > counts;
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
q.setForwardOnly(true);
|
q.setForwardOnly(true);
|
||||||
|
|
||||||
if (including_total_counts) {
|
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 "
|
"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;");
|
"GROUP BY feed;");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
q.prepare("SELECT feed, count(*) FROM Messages "
|
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 is_read = 0 AND account_id = :account_id "
|
"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;");
|
"GROUP BY feed;");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,9 +242,16 @@ QMap<int,int> DatabaseQueries::getMessageCountsForAccount(QSqlDatabase db, int a
|
|||||||
if (q.exec()) {
|
if (q.exec()) {
|
||||||
while (q.next()) {
|
while (q.next()) {
|
||||||
int feed_id = q.value(0).toInt();
|
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<int,int>(unread_count, total_count));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
counts.insert(feed_id, QPair<int,int>(unread_count, 0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ok != NULL) {
|
if (ok != NULL) {
|
||||||
|
@ -43,7 +43,7 @@ class DatabaseQueries {
|
|||||||
static bool purgeRecycleBin(QSqlDatabase db);
|
static bool purgeRecycleBin(QSqlDatabase db);
|
||||||
static QMap<int,int> getMessageCountsForCategory(QSqlDatabase db, int custom_id, int account_id,
|
static QMap<int,int> getMessageCountsForCategory(QSqlDatabase db, int custom_id, int account_id,
|
||||||
bool including_total_counts, bool *ok = NULL);
|
bool including_total_counts, bool *ok = NULL);
|
||||||
static QMap<int,int> getMessageCountsForAccount(QSqlDatabase db, int account_id,
|
static QMap<int,QPair<int,int> > getMessageCountsForAccount(QSqlDatabase db, int account_id,
|
||||||
bool including_total_counts, bool *ok = NULL);
|
bool including_total_counts, bool *ok = NULL);
|
||||||
static int getMessageCountsForFeed(QSqlDatabase db, int feed_custom_id, int account_id,
|
static int getMessageCountsForFeed(QSqlDatabase db, int feed_custom_id, int account_id,
|
||||||
bool including_total_counts, bool *ok = NULL);
|
bool including_total_counts, bool *ok = NULL);
|
||||||
|
@ -93,22 +93,13 @@ void ServiceRoot::updateCounts(bool including_total_count) {
|
|||||||
|
|
||||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||||
bool ok;
|
bool ok;
|
||||||
|
QMap<int,QPair<int,int> > counts = DatabaseQueries::getMessageCountsForAccount(database, accountId(), including_total_count, &ok);
|
||||||
|
|
||||||
if (including_total_count) {
|
foreach (Feed *feed, feeds) {
|
||||||
QMap<int,int> counts = DatabaseQueries::getMessageCountsForAccount(database, accountId(), including_total_count, &ok);
|
feed->setCountOfUnreadMessages(counts.value(feed->customId()).first);
|
||||||
|
|
||||||
if (ok) {
|
if (including_total_count) {
|
||||||
foreach (Feed *feed, feeds) {
|
feed->setCountOfAllMessages(counts.value(feed->customId()).second);
|
||||||
feed->setCountOfAllMessages(counts.value(feed->customId()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QMap<int,int> counts = DatabaseQueries::getMessageCountsForAccount(database, accountId(), false, &ok);
|
|
||||||
|
|
||||||
if (ok) {
|
|
||||||
foreach (Feed *feed, feeds) {
|
|
||||||
feed->setCountOfUnreadMessages(counts.value(feed->customId()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user