Some performance tweaks etc.

This commit is contained in:
Martin Rotter 2016-04-14 09:40:30 +02:00
parent ba3fcde339
commit 45aa2f4ae2
5 changed files with 50 additions and 45 deletions

View File

@ -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<Message>() << 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<Message>() << m_message,
RootItem::Read);
@ -149,8 +155,8 @@ void MessagePreviewer::markMessageAsUnread() {
QList<Message>() << 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<Message>() << m_message,
RootItem::Unread);

View File

@ -2,6 +2,7 @@
#include "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h"
#include "network-web/networkfactory.h"
MessageTextBrowser::MessageTextBrowser(QWidget *parent) : QTextBrowser(parent) {

View File

@ -220,20 +220,20 @@ QMap<int,int> DatabaseQueries::getMessageCountsForCategory(QSqlDatabase db, int
return counts;
}
QMap<int,int> DatabaseQueries::getMessageCountsForAccount(QSqlDatabase db, int account_id,
bool including_total_counts, bool *ok) {
QMap<int,int> counts;
QMap<int, QPair<int,int> > DatabaseQueries::getMessageCountsForAccount(QSqlDatabase db, int account_id,
bool including_total_counts, bool *ok) {
QMap<int, QPair<int,int> > 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<int,int> 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<int,int>(unread_count, total_count));
}
else {
counts.insert(feed_id, QPair<int,int>(unread_count, 0));
}
}
if (ok != NULL) {

View File

@ -43,7 +43,7 @@ class DatabaseQueries {
static bool purgeRecycleBin(QSqlDatabase db);
static QMap<int,int> getMessageCountsForCategory(QSqlDatabase db, int custom_id, int account_id,
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);
static int getMessageCountsForFeed(QSqlDatabase db, int feed_custom_id, int account_id,
bool including_total_counts, bool *ok = NULL);

View File

@ -93,22 +93,13 @@ void ServiceRoot::updateCounts(bool including_total_count) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
bool ok;
QMap<int,QPair<int,int> > counts = DatabaseQueries::getMessageCountsForAccount(database, accountId(), including_total_count, &ok);
if (including_total_count) {
QMap<int,int> 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<int,int> 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);
}
}
}