Refactoring.

This commit is contained in:
Martin Rotter 2014-02-02 14:44:00 +01:00
parent 161dd2fcab
commit 898a8eb6f3
8 changed files with 100 additions and 61 deletions

View File

@ -679,8 +679,9 @@ bool FeedsModel::markFeedsRead(const QList<FeedsModelFeed*> &feeds,
}
}
bool FeedsModel::markFeedsDeleted(const QList<FeedsModelFeed *> &feeds,
int deleted) {
bool FeedsModel::markFeedsDeleted(const QList<FeedsModelFeed*> &feeds,
int deleted,
bool read_only) {
QSqlDatabase db_handle = DatabaseFactory::instance()->connection(objectName(),
DatabaseFactory::FromSettings);
@ -692,12 +693,23 @@ bool FeedsModel::markFeedsDeleted(const QList<FeedsModelFeed *> &feeds,
QSqlQuery query_delete_msg(db_handle);
query_delete_msg.setForwardOnly(true);
if (!query_delete_msg.prepare(QString("UPDATE Messages SET deleted = :deleted "
"WHERE feed IN (%1) AND deleted = 0;").arg(textualFeedIds(feeds).join(", ")))) {
qWarning("Query preparation failed for feeds clearing.");
if (read_only) {
if (!query_delete_msg.prepare(QString("UPDATE Messages SET deleted = :deleted "
"WHERE feed IN (%1) AND deleted = 0 AND read = 1;").arg(textualFeedIds(feeds).join(", ")))) {
qWarning("Query preparation failed for feeds clearing.");
db_handle.rollback();
return false;
db_handle.rollback();
return false;
}
}
else {
if (!query_delete_msg.prepare(QString("UPDATE Messages SET deleted = :deleted "
"WHERE feed IN (%1) AND deleted = 0;").arg(textualFeedIds(feeds).join(", ")))) {
qWarning("Query preparation failed for feeds clearing.");
db_handle.rollback();
return false;
}
}
query_delete_msg.bindValue(":deleted", deleted);

View File

@ -117,7 +117,9 @@ class FeedsModel : public QAbstractItemModel {
public slots:
// Feeds operations.
bool markFeedsRead(const QList<FeedsModelFeed*> &feeds, int read);
bool markFeedsDeleted(const QList<FeedsModelFeed*> &feeds, int deleted);
bool markFeedsDeleted(const QList<FeedsModelFeed*> &feeds,
int deleted,
bool read_only);
// Signals that properties (probably counts)
// of ALL items have changed.

View File

@ -128,6 +128,8 @@ void FeedMessageViewer::onFeedUpdatesFinished() {
}
void FeedMessageViewer::createConnections() {
FormMain *form_main = FormMain::instance();
// Message changers.
connect(m_messagesView, SIGNAL(currentMessagesRemoved()),
m_messagesBrowser, SLOT(clear()));
@ -153,13 +155,13 @@ void FeedMessageViewer::createConnections() {
// Message openers.
connect(m_messagesView, SIGNAL(openMessagesInNewspaperView(QList<Message>)),
FormMain::instance()->m_ui->m_tabWidget,
form_main->m_ui->m_tabWidget,
SLOT(addBrowserWithMessages(QList<Message>)));
connect(m_messagesView, SIGNAL(openLinkNewTab(QString)),
FormMain::instance()->m_ui->m_tabWidget,
form_main->m_ui->m_tabWidget,
SLOT(addLinkedBrowser(QString)));
connect(m_feedsView, SIGNAL(openMessagesInNewspaperView(QList<Message>)),
FormMain::instance()->m_ui->m_tabWidget,
form_main->m_ui->m_tabWidget,
SLOT(addBrowserWithMessages(QList<Message>)));
// Downloader connections.
@ -175,41 +177,41 @@ void FeedMessageViewer::createConnections() {
this, SLOT(onFeedUpdatesProgress(FeedsModelFeed*,int,int)));
// Toolbar forwardings.
connect(FormMain::instance()->m_ui->m_actionSwitchImportanceOfSelectedMessages,
connect(form_main->m_ui->m_actionSwitchImportanceOfSelectedMessages,
SIGNAL(triggered()), m_messagesView, SLOT(switchSelectedMessagesImportance()));
connect(FormMain::instance()->m_ui->m_actionDeleteSelectedMessages,
connect(form_main->m_ui->m_actionDeleteSelectedMessages,
SIGNAL(triggered()), m_messagesView, SLOT(deleteSelectedMessages()));
connect(FormMain::instance()->m_ui->m_actionMarkSelectedMessagesAsRead,
connect(form_main->m_ui->m_actionMarkSelectedMessagesAsRead,
SIGNAL(triggered()), m_messagesView, SLOT(markSelectedMessagesRead()));
connect(FormMain::instance()->m_ui->m_actionMarkSelectedMessagesAsUnread,
connect(form_main->m_ui->m_actionMarkSelectedMessagesAsUnread,
SIGNAL(triggered()), m_messagesView, SLOT(markSelectedMessagesUnread()));
connect(FormMain::instance()->m_ui->m_actionOpenSelectedSourceArticlesExternally,
connect(form_main->m_ui->m_actionOpenSelectedSourceArticlesExternally,
SIGNAL(triggered()), m_messagesView, SLOT(openSelectedSourceArticlesExternally()));
connect(FormMain::instance()->m_ui->m_actionOpenSelectedSourceArticlesInternally,
connect(form_main->m_ui->m_actionOpenSelectedSourceArticlesInternally,
SIGNAL(triggered()), m_messagesView, SLOT(openSelectedSourceMessagesInternally()));
connect(FormMain::instance()->m_ui->m_actionOpenSelectedMessagesInternally,
connect(form_main->m_ui->m_actionOpenSelectedMessagesInternally,
SIGNAL(triggered()), m_messagesView, SLOT(openSelectedMessagesInternally()));
connect(FormMain::instance()->m_ui->m_actionMarkAllFeedsRead,
connect(form_main->m_ui->m_actionMarkAllFeedsRead,
SIGNAL(triggered()), m_feedsView, SLOT(markAllFeedsRead()));
connect(FormMain::instance()->m_ui->m_actionMarkSelectedFeedsAsRead,
connect(form_main->m_ui->m_actionMarkSelectedFeedsAsRead,
SIGNAL(triggered()), m_feedsView, SLOT(markSelectedFeedsRead()));
connect(FormMain::instance()->m_ui->m_actionMarkSelectedFeedsAsUnread,
connect(form_main->m_ui->m_actionMarkSelectedFeedsAsUnread,
SIGNAL(triggered()), m_feedsView, SLOT(markSelectedFeedsUnread()));
connect(FormMain::instance()->m_ui->m_actionClearFeeds,
connect(form_main->m_ui->m_actionClearFeeds,
SIGNAL(triggered()), m_feedsView, SLOT(clearSelectedFeeds()));
connect(FormMain::instance()->m_ui->m_actionUpdateSelectedFeedsCategories,
connect(form_main->m_ui->m_actionUpdateSelectedFeedsCategories,
SIGNAL(triggered()), m_feedsView, SLOT(updateSelectedFeeds()));
connect(FormMain::instance()->m_ui->m_actionUpdateAllFeeds,
connect(form_main->m_ui->m_actionUpdateAllFeeds,
SIGNAL(triggered()), m_feedsView, SLOT(updateAllFeeds()));
connect(FormMain::instance()->m_ui->m_actionAddStandardCategory,
connect(form_main->m_ui->m_actionAddStandardCategory,
SIGNAL(triggered()), m_feedsView, SLOT(addNewStandardCategory()));
connect(FormMain::instance()->m_ui->m_actionAddStandardFeed,
connect(form_main->m_ui->m_actionAddStandardFeed,
SIGNAL(triggered()), m_feedsView, SLOT(addNewStandardFeed()));
connect(FormMain::instance()->m_ui->m_actionEditSelectedFeedCategory,
connect(form_main->m_ui->m_actionEditSelectedFeedCategory,
SIGNAL(triggered()), m_feedsView, SLOT(editSelectedItem()));
connect(FormMain::instance()->m_ui->m_actionViewSelectedItemsNewspaperMode,
connect(form_main->m_ui->m_actionViewSelectedItemsNewspaperMode,
SIGNAL(triggered()), m_feedsView, SLOT(openSelectedFeedsInNewspaperMode()));
connect(FormMain::instance()->m_ui->m_actionDeleteSelectedFeedCategory,
connect(form_main->m_ui->m_actionDeleteSelectedFeedCategory,
SIGNAL(triggered()), m_feedsView, SLOT(deleteSelectedItem()));
}

View File

@ -103,7 +103,7 @@ void FeedsView::updateSelectedFeeds() {
}
void FeedsView::setSelectedFeedsClearStatus(int clear) {
m_sourceModel->markFeedsDeleted(selectedFeeds(), clear);
m_sourceModel->markFeedsDeleted(selectedFeeds(), clear, 0);
updateCountsOfSelectedFeeds();
emit feedsNeedToBeReloaded(1);
@ -326,6 +326,10 @@ void FeedsView::markAllFeedsRead() {
markAllFeedsReadStatus(1);
}
void FeedsView::clearAllReadMessages() {
m_sourceModel->markFeedsDeleted(allFeeds(), 1, 1);
}
void FeedsView::openSelectedFeedsInNewspaperMode() {
QList<Message> messages = m_sourceModel->messagesForFeeds(selectedFeeds());

View File

@ -59,6 +59,7 @@ class FeedsView : public QTreeView {
// Feed clearers.
void setSelectedFeedsClearStatus(int clear);
void clearSelectedFeeds();
void clearAllReadMessages();
// Base manipulators.
void editSelectedItem();

View File

@ -6,6 +6,7 @@
#include "core/databasefactory.h"
#include "gui/formabout.h"
#include "gui/formsettings.h"
#include "gui/feedsview.h"
#include "gui/webbrowser.h"
#include "gui/iconthemefactory.h"
#include "gui/systemtrayicon.h"
@ -189,6 +190,9 @@ void FormMain::onAboutToQuit() {
qDebug("Cleaning up resources and saving application state.");
m_ui->m_tabWidget->feedMessageViewer()->quitDownloader();
// TODO: podle nastaveni
m_ui->m_tabWidget->feedMessageViewer()->feedsView()->clearAllReadMessages();
DatabaseFactory::instance()->saveMemoryDatabase();
saveSize();
}
@ -198,40 +202,42 @@ bool FormMain::event(QEvent *event) {
}
void FormMain::setupIcons() {
IconThemeFactory *icon_theme_factory = IconThemeFactory::instance();
// Setup icons of this main window.
m_ui->m_actionSettings->setIcon(IconThemeFactory::instance()->fromTheme("application-settings"));
m_ui->m_actionQuit->setIcon(IconThemeFactory::instance()->fromTheme("application-exit"));
m_ui->m_actionAboutGuard->setIcon(IconThemeFactory::instance()->fromTheme("application-about"));
m_ui->m_actionImport->setIcon(IconThemeFactory::instance()->fromTheme("document-import"));
m_ui->m_actionExport->setIcon(IconThemeFactory::instance()->fromTheme("document-export"));
m_ui->m_actionFullscreen->setIcon(IconThemeFactory::instance()->fromTheme("view-fullscreen"));
m_ui->m_actionSettings->setIcon(icon_theme_factory->fromTheme("application-settings"));
m_ui->m_actionQuit->setIcon(icon_theme_factory->fromTheme("application-exit"));
m_ui->m_actionAboutGuard->setIcon(icon_theme_factory->fromTheme("application-about"));
m_ui->m_actionImport->setIcon(icon_theme_factory->fromTheme("document-import"));
m_ui->m_actionExport->setIcon(icon_theme_factory->fromTheme("document-export"));
m_ui->m_actionFullscreen->setIcon(icon_theme_factory->fromTheme("view-fullscreen"));
// Web browser.
m_ui->m_actionAddBrowser->setIcon(IconThemeFactory::instance()->fromTheme("list-add"));
m_ui->m_actionCloseCurrentTab->setIcon(IconThemeFactory::instance()->fromTheme("list-remove"));
m_ui->m_actionCloseAllTabs->setIcon(IconThemeFactory::instance()->fromTheme("list-remove"));
m_ui->m_menuCurrentTab->setIcon(IconThemeFactory::instance()->fromTheme("list-current"));
m_ui->m_actionAddBrowser->setIcon(icon_theme_factory->fromTheme("list-add"));
m_ui->m_actionCloseCurrentTab->setIcon(icon_theme_factory->fromTheme("list-remove"));
m_ui->m_actionCloseAllTabs->setIcon(icon_theme_factory->fromTheme("list-remove"));
m_ui->m_menuCurrentTab->setIcon(icon_theme_factory->fromTheme("list-current"));
// Feeds/messages.
m_ui->m_menuAddItem->setIcon(IconThemeFactory::instance()->fromTheme("item-new"));
m_ui->m_actionUpdateAllFeeds->setIcon(IconThemeFactory::instance()->fromTheme("item-update-all"));
m_ui->m_actionUpdateSelectedFeedsCategories->setIcon(IconThemeFactory::instance()->fromTheme("item-update-selected"));
m_ui->m_actionClearFeeds->setIcon(IconThemeFactory::instance()->fromTheme("mail-remove"));
m_ui->m_actionDeleteSelectedFeedCategory->setIcon(IconThemeFactory::instance()->fromTheme("item-remove"));
m_ui->m_actionDeleteSelectedMessages->setIcon(IconThemeFactory::instance()->fromTheme("mail-remove"));
m_ui->m_actionAddStandardCategory->setIcon(IconThemeFactory::instance()->fromTheme("item-new"));
m_ui->m_actionAddStandardFeed->setIcon(IconThemeFactory::instance()->fromTheme("item-new"));
m_ui->m_actionEditSelectedFeedCategory->setIcon(IconThemeFactory::instance()->fromTheme("item-edit"));
m_ui->m_actionMarkAllFeedsRead->setIcon(IconThemeFactory::instance()->fromTheme("mail-mark-read"));
m_ui->m_actionMarkSelectedFeedsAsRead->setIcon(IconThemeFactory::instance()->fromTheme("mail-mark-read"));
m_ui->m_actionMarkSelectedFeedsAsUnread->setIcon(IconThemeFactory::instance()->fromTheme("mail-mark-unread"));
m_ui->m_actionMarkSelectedMessagesAsRead->setIcon(IconThemeFactory::instance()->fromTheme("mail-mark-read"));
m_ui->m_actionMarkSelectedMessagesAsUnread->setIcon(IconThemeFactory::instance()->fromTheme("mail-mark-unread"));
m_ui->m_actionSwitchImportanceOfSelectedMessages->setIcon(IconThemeFactory::instance()->fromTheme("mail-mark-favorite"));
m_ui->m_actionOpenSelectedSourceArticlesInternally->setIcon(IconThemeFactory::instance()->fromTheme("item-open"));
m_ui->m_actionOpenSelectedSourceArticlesExternally->setIcon(IconThemeFactory::instance()->fromTheme("item-open"));
m_ui->m_actionOpenSelectedMessagesInternally->setIcon(IconThemeFactory::instance()->fromTheme("item-open"));
m_ui->m_actionViewSelectedItemsNewspaperMode->setIcon(IconThemeFactory::instance()->fromTheme("item-newspaper"));
m_ui->m_menuAddItem->setIcon(icon_theme_factory->fromTheme("item-new"));
m_ui->m_actionUpdateAllFeeds->setIcon(icon_theme_factory->fromTheme("item-update-all"));
m_ui->m_actionUpdateSelectedFeedsCategories->setIcon(icon_theme_factory->fromTheme("item-update-selected"));
m_ui->m_actionClearFeeds->setIcon(icon_theme_factory->fromTheme("mail-remove"));
m_ui->m_actionDeleteSelectedFeedCategory->setIcon(icon_theme_factory->fromTheme("item-remove"));
m_ui->m_actionDeleteSelectedMessages->setIcon(icon_theme_factory->fromTheme("mail-remove"));
m_ui->m_actionAddStandardCategory->setIcon(icon_theme_factory->fromTheme("item-new"));
m_ui->m_actionAddStandardFeed->setIcon(icon_theme_factory->fromTheme("item-new"));
m_ui->m_actionEditSelectedFeedCategory->setIcon(icon_theme_factory->fromTheme("item-edit"));
m_ui->m_actionMarkAllFeedsRead->setIcon(icon_theme_factory->fromTheme("mail-mark-read"));
m_ui->m_actionMarkSelectedFeedsAsRead->setIcon(icon_theme_factory->fromTheme("mail-mark-read"));
m_ui->m_actionMarkSelectedFeedsAsUnread->setIcon(icon_theme_factory->fromTheme("mail-mark-unread"));
m_ui->m_actionMarkSelectedMessagesAsRead->setIcon(icon_theme_factory->fromTheme("mail-mark-read"));
m_ui->m_actionMarkSelectedMessagesAsUnread->setIcon(icon_theme_factory->fromTheme("mail-mark-unread"));
m_ui->m_actionSwitchImportanceOfSelectedMessages->setIcon(icon_theme_factory->fromTheme("mail-mark-favorite"));
m_ui->m_actionOpenSelectedSourceArticlesInternally->setIcon(icon_theme_factory->fromTheme("item-open"));
m_ui->m_actionOpenSelectedSourceArticlesExternally->setIcon(icon_theme_factory->fromTheme("item-open"));
m_ui->m_actionOpenSelectedMessagesInternally->setIcon(icon_theme_factory->fromTheme("item-open"));
m_ui->m_actionViewSelectedItemsNewspaperMode->setIcon(icon_theme_factory->fromTheme("item-newspaper"));
// Setup icons for underlying components: opened web browsers...
foreach (WebBrowser *browser, WebBrowser::runningWebBrowsers()) {

View File

@ -163,6 +163,9 @@
<property name="shortcut">
<string notr="true">Ctrl+Shift+Q</string>
</property>
<property name="menuRole">
<enum>QAction::QuitRole</enum>
</property>
</action>
<action name="m_actionSettings">
<property name="text">
@ -185,6 +188,9 @@
<property name="shortcut">
<string notr="true">Ctrl+Shift+A</string>
</property>
<property name="menuRole">
<enum>QAction::AboutRole</enum>
</property>
</action>
<action name="m_actionFullscreen">
<property name="text">

View File

@ -51,6 +51,7 @@ void MessagesView::reloadSelections(int mark_current_index_read) {
QModelIndex mapped_current_index = m_proxyModel->mapToSource(current_index);
QModelIndexList selected_indexes = selectionModel()->selectedRows();
QModelIndexList mapped_indexes = m_proxyModel->mapListToSource(selected_indexes);
int row_count;
// Reload the model now.
m_sourceModel->select();
@ -62,8 +63,6 @@ void MessagesView::reloadSelections(int mark_current_index_read) {
current_index = m_proxyModel->mapFromSource(m_sourceModel->index(mapped_current_index.row(),
mapped_current_index.column()));
if (current_index.isValid()) {
if (mark_current_index_read == 0) {
// User selected to mark some messages as unread, if one
@ -79,6 +78,13 @@ void MessagesView::reloadSelections(int mark_current_index_read) {
scrollTo(current_index);
reselectIndexes(selected_indexes);
}
else if ((row_count = m_proxyModel->rowCount()) > 0) {
current_index = m_proxyModel->index(row_count - 1, 0);
setCurrentIndex(current_index);
scrollTo(current_index);
reselectIndexes(QModelIndexList() << current_index);
}
else {
// Messages were probably removed from the model, nothing can
// be selected and no message can be displayed.