This commit is contained in:
Martin Rotter 2016-09-01 07:20:46 +02:00
parent 6d48863b1f
commit ab01f6b91c
6 changed files with 44 additions and 23 deletions

View File

@ -1,3 +1,13 @@
3.3.5
—————
Added:
Changed:
▪ Made some tweaks regarding bug #41. Number of new messages is now determined in feed downloader working thread too.
Fixed:
3.3.4 3.3.4
————— —————

View File

@ -73,7 +73,7 @@ APP_LOW_NAME = "rssguard"
APP_LOW_H_NAME = ".rssguard" APP_LOW_H_NAME = ".rssguard"
APP_AUTHOR = "Martin Rotter" APP_AUTHOR = "Martin Rotter"
APP_COPYRIGHT = "(C) 2011-2016 $$APP_AUTHOR" APP_COPYRIGHT = "(C) 2011-2016 $$APP_AUTHOR"
APP_VERSION = "3.3.4" APP_VERSION = "3.3.5"
APP_LONG_NAME = "$$APP_NAME $$APP_VERSION" APP_LONG_NAME = "$$APP_NAME $$APP_VERSION"
APP_EMAIL = "rotter.martinos@gmail.com" APP_EMAIL = "rotter.martinos@gmail.com"
APP_URL = "https://github.com/martinrotter/rssguard" APP_URL = "https://github.com/martinrotter/rssguard"

View File

@ -106,11 +106,13 @@ void FeedDownloader::oneFeedUpdateFinished(const QList<Message> &messages) {
<< feed->id() << " in thread: \'" << feed->id() << " in thread: \'"
<< QThread::currentThreadId() << "\'."; << QThread::currentThreadId() << "\'.";
int updated_messages; int updated_messages = feed->updateMessages(messages);
/*
QMetaObject::invokeMethod(feed, "updateMessages", Qt::BlockingQueuedConnection, QMetaObject::invokeMethod(feed, "updateMessages", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(int, updated_messages), Q_RETURN_ARG(int, updated_messages),
Q_ARG(QList<Message>, messages)); Q_ARG(QList<Message>, messages));
*/
if (updated_messages > 0) { if (updated_messages > 0) {
m_results.appendUpdatedFeed(QPair<QString,int>(feed->title(), updated_messages)); m_results.appendUpdatedFeed(QPair<QString,int>(feed->title(), updated_messages));

View File

@ -38,7 +38,6 @@
#include <QDebug> #include <QDebug>
#include <QTimer> #include <QTimer>
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
for (int i = 0; i < argc; i++) { for (int i = 0; i < argc; i++) {
const QString str = QString::fromLocal8Bit(argv[i]); const QString str = QString::fromLocal8Bit(argv[i]);

View File

@ -49,16 +49,16 @@ QVariant Feed::data(int column, int role) const {
switch (status()) { switch (status()) {
case NewMessages: case NewMessages:
return QColor(Qt::blue); return QColor(Qt::blue);
case Error: case Error:
case ParsingError: case ParsingError:
case OtherError: case OtherError:
return QColor(Qt::red); return QColor(Qt::red);
default: default:
return QVariant(); return QVariant();
} }
default: default:
return RootItem::data(column, role); return RootItem::data(column, role);
} }
@ -84,7 +84,7 @@ void Feed::setCountOfUnreadMessages(int count_unread_messages) {
if (status() == NewMessages && count_unread_messages < countOfUnreadMessages()) { if (status() == NewMessages && count_unread_messages < countOfUnreadMessages()) {
setStatus(Normal); setStatus(Normal);
} }
m_unreadCount = count_unread_messages; m_unreadCount = count_unread_messages;
} }
@ -128,13 +128,16 @@ void Feed::setUrl(const QString &url) {
} }
void Feed::updateCounts(bool including_total_count) { void Feed::updateCounts(bool including_total_count) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); bool is_main_thread = QThread::currentThread() == qApp->thread();
QSqlDatabase database = is_main_thread ?
qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings) :
qApp->database()->connection(QSL("feed_upd"), DatabaseFactory::FromSettings);
int account_id = getParentServiceRoot()->accountId(); int account_id = getParentServiceRoot()->accountId();
if (including_total_count) { if (including_total_count) {
setCountOfAllMessages(DatabaseQueries::getMessageCountsForFeed(database, customId(), account_id, true)); setCountOfAllMessages(DatabaseQueries::getMessageCountsForFeed(database, customId(), account_id, true));
} }
setCountOfUnreadMessages(DatabaseQueries::getMessageCountsForFeed(database, customId(), account_id, false)); setCountOfUnreadMessages(DatabaseQueries::getMessageCountsForFeed(database, customId(), account_id, false));
} }
@ -142,23 +145,25 @@ void Feed::run() {
qDebug().nospace() << "Downloading new messages for feed " qDebug().nospace() << "Downloading new messages for feed "
<< customId() << " in thread: \'" << customId() << " in thread: \'"
<< QThread::currentThreadId() << "\'."; << QThread::currentThreadId() << "\'.";
QList<Message> msgs = obtainNewMessages(); QList<Message> msgs = obtainNewMessages();
emit messagesObtained(msgs); emit messagesObtained(msgs);
} }
int Feed::updateMessages(const QList<Message> &messages) { int Feed::updateMessages(const QList<Message> &messages) {
qDebug().nospace() << "Updating messages in DB. Main thread: " << bool is_main_thread = QThread::currentThread() == qApp->thread();
(QThread::currentThread() == qApp->thread() ? "true." : "false.");
qDebug("Updating messages in DB. Main thread: '%s'.", qPrintable(is_main_thread ? "true." : "false."));
int custom_id = customId(); int custom_id = customId();
int account_id = getParentServiceRoot()->accountId(); int account_id = getParentServiceRoot()->accountId();
bool anything_updated = false; bool anything_updated = false;
bool ok; bool ok;
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = is_main_thread ?
int updated_messages = DatabaseQueries::updateMessages(database, messages, custom_id, account_id, url(), qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings) :
&anything_updated, &ok); qApp->database()->connection(QSL("feed_upd"), DatabaseFactory::FromSettings);
int updated_messages = DatabaseQueries::updateMessages(database, messages, custom_id, account_id, url(), &anything_updated, &ok);
if (ok) { if (ok) {
if (updated_messages > 0) { if (updated_messages > 0) {
setStatus(NewMessages); setStatus(NewMessages);
@ -166,19 +171,19 @@ int Feed::updateMessages(const QList<Message> &messages) {
else { else {
setStatus(Normal); setStatus(Normal);
} }
QList<RootItem*> items_to_update; QList<RootItem*> items_to_update;
updateCounts(true); updateCounts(true);
items_to_update.append(this); items_to_update.append(this);
if (getParentServiceRoot()->recycleBin() != nullptr && anything_updated) { if (getParentServiceRoot()->recycleBin() != nullptr && anything_updated) {
getParentServiceRoot()->recycleBin()->updateCounts(true); getParentServiceRoot()->recycleBin()->updateCounts(true);
items_to_update.append(getParentServiceRoot()->recycleBin()); items_to_update.append(getParentServiceRoot()->recycleBin());
} }
getParentServiceRoot()->itemChanged(items_to_update); getParentServiceRoot()->itemChanged(items_to_update);
} }
return updated_messages; return updated_messages;
} }

View File

@ -23,6 +23,8 @@
#include "miscellaneous/databasequeries.h" #include "miscellaneous/databasequeries.h"
#include "services/abstract/serviceroot.h" #include "services/abstract/serviceroot.h"
#include <QThread>
RecycleBin::RecycleBin(RootItem *parent_item) : RootItem(parent_item), m_totalCount(0), RecycleBin::RecycleBin(RootItem *parent_item) : RootItem(parent_item), m_totalCount(0),
m_unreadCount(0), m_contextMenu(QList<QAction*>()) { m_unreadCount(0), m_contextMenu(QList<QAction*>()) {
@ -46,7 +48,10 @@ int RecycleBin::countOfAllMessages() const {
} }
void RecycleBin::updateCounts(bool update_total_count) { void RecycleBin::updateCounts(bool update_total_count) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); bool is_main_thread = QThread::currentThread() == qApp->thread();
QSqlDatabase database = is_main_thread ?
qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings) :
qApp->database()->connection(QSL("feed_upd"), DatabaseFactory::FromSettings);
m_unreadCount = DatabaseQueries::getMessageCountsForBin(database, getParentServiceRoot()->accountId(), false); m_unreadCount = DatabaseQueries::getMessageCountsForBin(database, getParentServiceRoot()->accountId(), false);