Refactorings.

This commit is contained in:
Martin Rotter 2014-09-16 21:20:47 +02:00
parent d15d2460bb
commit 52d1975664
4 changed files with 37 additions and 58 deletions

View file

@ -69,6 +69,7 @@
#define SEPARATOR_ACTION_NAME "separator" #define SEPARATOR_ACTION_NAME "separator"
#define FILTER_WIDTH 150 #define FILTER_WIDTH 150
#define FILTER_RIGHT_MARGIN 5 #define FILTER_RIGHT_MARGIN 5
#define FEEDS_VIEW_INDENTATION 10
#define APP_DB_MYSQL_DRIVER "QMYSQL" #define APP_DB_MYSQL_DRIVER "QMYSQL"
#define APP_DB_MYSQL_INIT "db_init_mysql.sql" #define APP_DB_MYSQL_INIT "db_init_mysql.sql"

View file

@ -195,55 +195,40 @@ void FeedMessageViewer::createConnections() {
m_messagesView, SLOT(filterMessages(MessagesModel::DisplayFilter))); m_messagesView, SLOT(filterMessages(MessagesModel::DisplayFilter)));
// Message changers. // Message changers.
connect(m_messagesView, SIGNAL(currentMessagesRemoved()), connect(m_messagesView, SIGNAL(currentMessagesRemoved()), m_messagesBrowser, SLOT(clear()));
m_messagesBrowser, SLOT(clear())); connect(m_messagesView, SIGNAL(currentMessagesChanged(QList<Message>)), m_messagesBrowser, SLOT(navigateToMessages(QList<Message>)));
connect(m_messagesView, SIGNAL(currentMessagesChanged(QList<Message>)),
m_messagesBrowser, SLOT(navigateToMessages(QList<Message>)));
// Import & export of feeds. // Import & export of feeds.
connect(form_main->m_ui->m_actionExportFeeds, SIGNAL(triggered()), connect(form_main->m_ui->m_actionExportFeeds, SIGNAL(triggered()), this, SLOT(exportFeeds()));
this, SLOT(exportFeeds())); connect(form_main->m_ui->m_actionImportFeeds, SIGNAL(triggered()), this, SLOT(importFeeds()));
connect(form_main->m_ui->m_actionImportFeeds, SIGNAL(triggered()),
this, SLOT(importFeeds()));
// If user selects feeds, load their messages. // If user selects feeds, load their messages.
connect(m_feedsView, SIGNAL(feedsSelected(QList<int>)), connect(m_feedsView, SIGNAL(feedsSelected(QList<int>)), m_messagesView, SLOT(loadFeeds(QList<int>)));
m_messagesView, SLOT(loadFeeds(QList<int>)));
// If user changes status of some messages, recalculate message counts. // If user changes status of some messages, recalculate message counts.
connect(m_messagesView, SIGNAL(feedCountsChanged()), connect(m_messagesView, SIGNAL(feedCountsChanged()), m_feedsView, SLOT(updateCountsOfSelectedFeeds()));
m_feedsView, SLOT(updateCountsOfSelectedFeeds()));
// State of many messages is changed, then we need // State of many messages is changed, then we need
// to reload selections. // to reload selections.
connect(m_feedsView, SIGNAL(feedsNeedToBeReloaded(int)), m_messagesView, SLOT(reloadSelections(int))); connect(m_feedsView, SIGNAL(feedsNeedToBeReloaded(int)), m_messagesView, SLOT(reloadSelections(int)));
// If counts of unread/all messages change, update the tray icon. // If counts of unread/all messages change, update the tray icon.
connect(m_feedsView, SIGNAL(feedCountsChanged(int,int)), connect(m_feedsView, SIGNAL(feedCountsChanged(int,int)), this, SLOT(updateTrayIconStatus(int,int)));
this, SLOT(updateTrayIconStatus(int,int)));
// Message openers. // Message openers.
connect(m_messagesView, SIGNAL(openMessagesInNewspaperView(QList<Message>)), connect(m_messagesView, SIGNAL(openMessagesInNewspaperView(QList<Message>)),
form_main->m_ui->m_tabWidget, form_main->m_ui->m_tabWidget, SLOT(addBrowserWithMessages(QList<Message>)));
SLOT(addBrowserWithMessages(QList<Message>)));
connect(m_messagesView, SIGNAL(openLinkNewTab(QString)), connect(m_messagesView, SIGNAL(openLinkNewTab(QString)),
form_main->m_ui->m_tabWidget, form_main->m_ui->m_tabWidget, SLOT(addLinkedBrowser(QString)));
SLOT(addLinkedBrowser(QString)));
connect(m_feedsView, SIGNAL(openMessagesInNewspaperView(QList<Message>)), connect(m_feedsView, SIGNAL(openMessagesInNewspaperView(QList<Message>)),
form_main->m_ui->m_tabWidget, form_main->m_ui->m_tabWidget, SLOT(addBrowserWithMessages(QList<Message>)));
SLOT(addBrowserWithMessages(QList<Message>)));
// Downloader connections. // Downloader connections.
connect(m_feedDownloaderThread, SIGNAL(finished()), connect(m_feedDownloaderThread, SIGNAL(finished()), m_feedDownloaderThread, SLOT(deleteLater()));
m_feedDownloaderThread, SLOT(deleteLater())); connect(m_feedsView, SIGNAL(feedsUpdateRequested(QList<FeedsModelFeed*>)), m_feedDownloader, SLOT(updateFeeds(QList<FeedsModelFeed*>)));
connect(m_feedsView, SIGNAL(feedsUpdateRequested(QList<FeedsModelFeed*>)), connect(m_feedDownloader, SIGNAL(finished()), this, SLOT(onFeedUpdatesFinished()));
m_feedDownloader, SLOT(updateFeeds(QList<FeedsModelFeed*>))); connect(m_feedDownloader, SIGNAL(started()), this, SLOT(onFeedUpdatesStarted()));
connect(m_feedDownloader, SIGNAL(finished()), connect(m_feedDownloader, SIGNAL(progress(FeedsModelFeed*,int,int)), this, SLOT(onFeedUpdatesProgress(FeedsModelFeed*,int,int)));
this, SLOT(onFeedUpdatesFinished()));
connect(m_feedDownloader, SIGNAL(started()),
this, SLOT(onFeedUpdatesStarted()));
connect(m_feedDownloader, SIGNAL(progress(FeedsModelFeed*,int,int)),
this, SLOT(onFeedUpdatesProgress(FeedsModelFeed*,int,int)));
// Toolbar forwardings. // Toolbar forwardings.
connect(form_main->m_ui->m_actionSwitchImportanceOfSelectedMessages, connect(form_main->m_ui->m_actionSwitchImportanceOfSelectedMessages,

View file

@ -90,28 +90,27 @@ void FeedsView::updateAutoUpdateStatus() {
} }
} }
void FeedsView::setSortingEnabled(bool enable) {
QTreeView::setSortingEnabled(enable);
header()->setSortIndicatorShown(false);
}
QList<FeedsModelFeed*> FeedsView::selectedFeeds() const { QList<FeedsModelFeed*> FeedsView::selectedFeeds() const {
QModelIndexList selection = selectionModel()->selectedRows(); QModelIndex current_index = currentIndex();
QModelIndexList mapped_selection = m_proxyModel->mapListToSource(selection);
return m_sourceModel->feedsForIndexes(mapped_selection); if (current_index.isValid()) {
return m_sourceModel->feedsForIndex(m_proxyModel->mapToSource(current_index));
}
else {
return QList<FeedsModelFeed*>();
}
} }
QList<FeedsModelFeed*> FeedsView::allFeeds() const { QList<FeedsModelFeed*> FeedsView::allFeeds() const {
return m_sourceModel->allFeeds(); return m_sourceModel->allFeeds();
} }
FeedsModelCategory *FeedsView::isCurrentIndexCategory() const { FeedsModelCategory *FeedsView::selectedCategory() const {
QModelIndex current_mapped = m_proxyModel->mapToSource(currentIndex()); QModelIndex current_mapped = m_proxyModel->mapToSource(currentIndex());
return m_sourceModel->categoryForIndex(current_mapped); return m_sourceModel->categoryForIndex(current_mapped);
} }
FeedsModelFeed *FeedsView::isCurrentIndexFeed() const { FeedsModelFeed *FeedsView::selectedFeed() const {
QModelIndex current_mapped = m_proxyModel->mapToSource(currentIndex()); QModelIndex current_mapped = m_proxyModel->mapToSource(currentIndex());
return m_sourceModel->feedForIndex(current_mapped); return m_sourceModel->feedForIndex(current_mapped);
} }
@ -301,10 +300,10 @@ void FeedsView::editSelectedItem() {
FeedsModelCategory *category; FeedsModelCategory *category;
FeedsModelFeed *feed; FeedsModelFeed *feed;
if ((category = isCurrentIndexCategory()) != NULL) { if ((category = selectedCategory()) != NULL) {
editCategory(static_cast<FeedsModelCategory*>(category)); editCategory(static_cast<FeedsModelCategory*>(category));
} }
else if ((feed = isCurrentIndexFeed()) != NULL) { else if ((feed = selectedFeed()) != NULL) {
// Feed is selected. // Feed is selected.
switch (feed->type()) { switch (feed->type()) {
case FeedsModelFeed::Atom10: case FeedsModelFeed::Atom10:
@ -407,7 +406,7 @@ void FeedsView::openSelectedFeedsInNewspaperMode() {
if (!messages.isEmpty()) { if (!messages.isEmpty()) {
emit openMessagesInNewspaperView(messages); emit openMessagesInNewspaperView(messages);
markSelectedFeedsRead(); QTimer::singleShot(0, this, SLOT(markSelectedFeedsRead()));
} }
} }
@ -421,7 +420,6 @@ void FeedsView::updateCountsOfSelectedFeeds(bool update_total_too) {
// Make sure that selected view reloads changed indexes. // Make sure that selected view reloads changed indexes.
m_sourceModel->reloadChangedLayout(m_proxyModel->mapListToSource(selectionModel()->selectedRows())); m_sourceModel->reloadChangedLayout(m_proxyModel->mapListToSource(selectionModel()->selectedRows()));
notifyWithCounts(); notifyWithCounts();
} }
} }
@ -489,7 +487,7 @@ void FeedsView::initializeContextMenuCategoriesFeeds() {
} }
void FeedsView::initializeContextMenuEmptySpace() { void FeedsView::initializeContextMenuEmptySpace() {
m_contextMenuEmptySpace = new QMenu(tr("Context menu for feeds"), this); m_contextMenuEmptySpace = new QMenu(tr("Context menu"), this);
m_contextMenuEmptySpace->addActions(QList<QAction*>() << m_contextMenuEmptySpace->addActions(QList<QAction*>() <<
qApp->mainForm()->m_ui->m_actionUpdateAllFeeds << qApp->mainForm()->m_ui->m_actionUpdateAllFeeds <<
qApp->mainForm()->m_ui->m_actionAddCategory << qApp->mainForm()->m_ui->m_actionAddCategory <<
@ -508,13 +506,14 @@ void FeedsView::setupAppearance() {
#endif #endif
header()->setStretchLastSection(false); header()->setStretchLastSection(false);
header()->setSortIndicatorShown(false);
setUniformRowHeights(true); setUniformRowHeights(true);
setAnimated(true); setAnimated(true);
setSortingEnabled(true); setSortingEnabled(true);
setItemsExpandable(true); setItemsExpandable(true);
setExpandsOnDoubleClick(true); setExpandsOnDoubleClick(true);
setEditTriggers(QAbstractItemView::NoEditTriggers); setEditTriggers(QAbstractItemView::NoEditTriggers);
setIndentation(10); setIndentation(FEEDS_VIEW_INDENTATION);
setAcceptDrops(false); setAcceptDrops(false);
setDragEnabled(false); setDragEnabled(false);
setDropIndicatorShown(false); setDropIndicatorShown(false);
@ -525,11 +524,10 @@ void FeedsView::setupAppearance() {
// Sort in ascending order, that is categories are // Sort in ascending order, that is categories are
// "bigger" than feeds. // "bigger" than feeds.
sortByColumn(0, Qt::AscendingOrder); sortByColumn(FDS_MODEL_TITLE_INDEX, Qt::AscendingOrder);
} }
void FeedsView::selectionChanged(const QItemSelection &selected, void FeedsView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) {
const QItemSelection &deselected) {
QTreeView::selectionChanged(selected, deselected); QTreeView::selectionChanged(selected, deselected);
m_selectedFeeds.clear(); m_selectedFeeds.clear();
@ -538,8 +536,7 @@ void FeedsView::selectionChanged(const QItemSelection &selected,
#if defined(DEBUG) #if defined(DEBUG)
QModelIndex index_for_feed = m_sourceModel->indexForItem(feed); QModelIndex index_for_feed = m_sourceModel->indexForItem(feed);
qDebug("Selecting feed '%s' (source index [%d, %d]).", qDebug("Selecting feed '%s' (source index [%d, %d]).", qPrintable(feed->title()), index_for_feed.row(), index_for_feed.column());
qPrintable(feed->title()), index_for_feed.row(), index_for_feed.column());
#endif #endif
m_selectedFeeds << feed->id(); m_selectedFeeds << feed->id();

View file

@ -53,9 +53,6 @@ class FeedsView : public QTreeView {
// Resets global auto-update intervals according to settings // Resets global auto-update intervals according to settings
// and starts/stop the timer as needed. // and starts/stop the timer as needed.
void updateAutoUpdateStatus(); void updateAutoUpdateStatus();
// Enables or disables sorting.
void setSortingEnabled(bool enable);
// Returns list of selected/all feeds. // Returns list of selected/all feeds.
QList<FeedsModelFeed*> selectedFeeds() const; QList<FeedsModelFeed*> selectedFeeds() const;
@ -64,8 +61,8 @@ class FeedsView : public QTreeView {
// Return true if current index contains category/feed and // Return true if current index contains category/feed and
// stores category/feed in the parameter pointer, // stores category/feed in the parameter pointer,
// otherwise false. // otherwise false.
FeedsModelCategory *isCurrentIndexCategory() const; FeedsModelCategory *selectedCategory() const;
FeedsModelFeed *isCurrentIndexFeed() const; FeedsModelFeed *selectedFeed() const;
// Saves/loads expand states of all nodes (feeds/categories) of the list // Saves/loads expand states of all nodes (feeds/categories) of the list
// to/from settings. // to/from settings.
@ -144,8 +141,7 @@ class FeedsView : public QTreeView {
void setupAppearance(); void setupAppearance();
// Handle selections. // Handle selections.
void selectionChanged(const QItemSelection &selected, void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
const QItemSelection &deselected);
void keyPressEvent(QKeyEvent *event); void keyPressEvent(QKeyEvent *event);