Refactoring regarding reloading of displayed messages and some little cleanups.

This commit is contained in:
Martin Rotter 2015-11-23 13:13:03 +01:00
parent adae003ed5
commit 46eba51247
10 changed files with 35 additions and 33 deletions

View File

@ -401,9 +401,22 @@ void FeedsModel::reloadChangedItem(RootItem *item) {
reloadChangedLayout(QModelIndexList() << index_item);
}
void FeedsModel::notifyWithCounts() {
if (SystemTrayIcon::isSystemTrayActivated()) {
qApp->trayIcon()->setNumber(countOfUnreadMessages(), hasAnyFeedNewMessages());
}
}
void FeedsModel::onItemDataChanged(QList<RootItem*> items) {
foreach (RootItem *item, items) {
reloadChangedItem(item);
if (items.size() > RELOAD_MODEL_BORDER_NUM) {
qDebug("There is request to reload feed model for more than %d items, reloading model fully.", RELOAD_MODEL_BORDER_NUM);
}
else {
qDebug("There is request to reload feed model, reloading the %d items individually.", items.size());
foreach (RootItem *item, items) {
reloadChangedItem(item);
}
}
notifyWithCounts();
@ -431,6 +444,7 @@ bool FeedsModel::addServiceAccount(ServiceRoot *root) {
// Connect.
connect(root, SIGNAL(readFeedsFilterInvalidationRequested()), this, SIGNAL(readFeedsFilterInvalidationRequested()));
connect(root, SIGNAL(dataChanged(QList<RootItem*>)), this, SLOT(onItemDataChanged(QList<RootItem*>)));
connect(root, SIGNAL(reloadMessageListRequested(bool)), this, SIGNAL(reloadMessageListRequested(bool)));
root->start();
return true;

View File

@ -153,9 +153,7 @@ class FeedsModel : public QAbstractItemModel {
// Notifies other components about messages
// counts.
inline void notifyWithCounts() {
emit messageCountsChanged(countOfUnreadMessages(), countOfAllMessages(), hasAnyFeedNewMessages());
}
void notifyWithCounts();
private slots:
void onItemDataChanged(QList<RootItem*> items);
@ -172,6 +170,9 @@ class FeedsModel : public QAbstractItemModel {
// Emitted if counts of messages are changed.
void messageCountsChanged(int unread_messages, int total_messages, bool any_feed_has_unread_messages);
// Emitted when there is a need of reloading of displayed messages.
void reloadMessageListRequested(bool mark_selected_messages_read);
private:
// Returns converted ids of given feeds
// which are suitable as IN clause for SQL queries.

View File

@ -86,6 +86,7 @@
#define GOOGLE_SEARCH_URL "https://www.google.com/search?q=%1&ie=utf-8&oe=utf-8"
#define GOOGLE_SUGGEST_URL "http://suggestqueries.google.com/complete/search?output=toolbar&hl=en&q=%1"
#define ENCRYPTION_FILE_NAME "key.private"
#define RELOAD_MODEL_BORDER_NUM 10
#define FEED_INITIAL_OPML_PATTERN "feeds-%1.opml"

View File

@ -220,14 +220,6 @@ void FeedMessageViewer::setListHeadersEnabled(bool enable) {
m_messagesView->header()->setVisible(enable);
}
void FeedMessageViewer::updateTrayIconStatus(int unread_messages, int total_messages, bool any_unread_messages) {
Q_UNUSED(total_messages)
if (SystemTrayIcon::isSystemTrayActivated()) {
qApp->trayIcon()->setNumber(unread_messages, any_unread_messages);
}
}
void FeedMessageViewer::onFeedUpdatesStarted() {
//: Text display in status bar when feed update is started.
qApp->mainForm()->statusBar()->showProgressFeeds(0, tr("Feed update started"));
@ -329,10 +321,7 @@ void FeedMessageViewer::createConnections() {
// State of many messages is changed, then we need
// to reload selections.
connect(m_feedsView, SIGNAL(feedsNeedToBeReloaded(bool)), m_messagesView, SLOT(reloadSelections(bool)));
// If counts of unread/all messages change, update the tray icon.
connect(m_feedsView->sourceModel(), SIGNAL(messageCountsChanged(int,int,bool)), this, SLOT(updateTrayIconStatus(int,int,bool)));
connect(m_feedsView->sourceModel(), SIGNAL(reloadMessageListRequested(bool)), m_messagesView, SLOT(reloadSelections(bool)));
// Message openers.
connect(m_messagesView, SIGNAL(openLinkMiniBrowser(QString)), m_messagesBrowser, SLOT(navigateToUrl(QString)));

View File

@ -99,9 +99,6 @@ class FeedMessageViewer : public TabContent {
void updateFeeds(QList<Feed*> feeds);
private slots:
// Updates counts of messages for example in tray icon.
void updateTrayIconStatus(int unread_messages, int total_messages, bool any_unread_messages);
// Reacts on feed updates.
void onFeedUpdatesStarted();
void onFeedUpdatesProgress(Feed *feed, int current, int total);

View File

@ -169,12 +169,10 @@ void FeedsView::updateAllItemsOnStartup() {
void FeedsView::clearSelectedFeeds() {
m_sourceModel->markItemCleared(selectedItem(), false);
emit feedsNeedToBeReloaded(true);
}
void FeedsView::clearAllFeeds() {
m_sourceModel->markItemCleared(m_sourceModel->rootItem(), false);
emit feedsNeedToBeReloaded(true);
}
void FeedsView::editSelectedItem() {
@ -274,7 +272,6 @@ void FeedsView::deleteSelectedItem() {
void FeedsView::markSelectedItemReadStatus(RootItem::ReadStatus read) {
m_sourceModel->markItemRead(selectedItem(), read);
emit feedsNeedToBeReloaded(read == 1);
}
void FeedsView::markSelectedItemsRead() {
@ -287,7 +284,6 @@ void FeedsView::markSelectedItemsUnread() {
void FeedsView::markAllItemsReadStatus(RootItem::ReadStatus read) {
m_sourceModel->markItemRead(m_sourceModel->rootItem(), read);
emit feedsNeedToBeReloaded(read == 1);
}
void FeedsView::markAllItemsRead() {

View File

@ -99,9 +99,6 @@ class FeedsView : public QTreeView {
// Emitted if user/application requested updating of some feeds.
void feedsUpdateRequested(const QList<Feed*> feeds);
// Emitted if currently selected feeds needs to be reloaded.
void feedsNeedToBeReloaded(bool mark_current_index_read);
// Emitted if user selects new feeds.
void itemSelected(RootItem *item);

View File

@ -34,3 +34,7 @@ FeedsModel *ServiceRoot::feedsModel() const {
void ServiceRoot::itemChanged(QList<RootItem*> items) {
emit dataChanged(items);
}
void ServiceRoot::requestReloadMessageList(bool mark_selected_messages_read) {
emit reloadMessageListRequested(mark_selected_messages_read);
}

View File

@ -122,15 +122,15 @@ class ServiceRoot : public RootItem {
// Access to feed model.
FeedsModel *feedsModel() const;
// Obvious method to wrap dataChanged(...) signal
// which can be used by items themselves or any
// other component.
// Obvious methods to wrap signals.
void itemChanged(QList<RootItem*> items);
void requestReloadMessageList(bool mark_selected_messages_read);
signals:
// Emitted if data in any item belonging to this root are changed.
void dataChanged(QList<RootItem*> items);
void readFeedsFilterInvalidationRequested();
void reloadMessageListRequested(bool mark_selected_messages_read);
private:
FeedsModel *m_feedsModel;

View File

@ -165,7 +165,8 @@ bool StandardServiceRoot::markFeedsReadUnread(QList<Feed*> items, ReadStatus rea
itemss.append(feed);
}
emit dataChanged(itemss);
itemChanged(itemss);
requestReloadMessageList(read == RootItem::Read);
return true;
}
else {
@ -202,7 +203,8 @@ bool StandardServiceRoot::markRecycleBinReadUnread(RootItem::ReadStatus read) {
if (db_handle.commit()) {
m_recycleBin->updateCounts(true);
emit dataChanged(QList<RootItem*>() << m_recycleBin);
itemChanged(QList<RootItem*>() << m_recycleBin);
requestReloadMessageList(read == RootItem::Read);
return true;
}
else {
@ -248,7 +250,8 @@ bool StandardServiceRoot::cleanFeeds(QList<Feed*> items, bool clean_read_only) {
m_recycleBin->updateCounts(true);
itemss.append(m_recycleBin);
emit dataChanged(itemss);
itemChanged(itemss);
requestReloadMessageList(true);
return true;
}
}