diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index b4d399e15..175aafc34 100755 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -35,7 +35,8 @@ #include -FeedsModel::FeedsModel(QObject *parent) : QAbstractItemModel(parent) { +FeedsModel::FeedsModel(QObject *parent) + : QAbstractItemModel(parent), m_recycleBin(new FeedsModelRecycleBin()) { setObjectName("FeedsModel"); // Create root item. @@ -692,7 +693,8 @@ void FeedsModel::loadFromDatabase() { assembleCategories(categories); assembleFeeds(feeds); - m_rootItem->appendChild(new FeedsModelRecycleBin()); + // As the last item, add recycle bin, which is needed. + m_rootItem->appendChild(m_recycleBin); } QList FeedsModel::feedsForIndex(const QModelIndex &index) { diff --git a/src/core/feedsmodel.h b/src/core/feedsmodel.h index 89b07525a..e76a69abc 100644 --- a/src/core/feedsmodel.h +++ b/src/core/feedsmodel.h @@ -28,6 +28,7 @@ class FeedsModelCategory; class FeedsModelFeed; +class FeedsModelRecycleBin; class FeedsImportExportModel; typedef QList > CategoryAssignment; @@ -170,6 +171,7 @@ class FeedsModel : public QAbstractItemModel { private: FeedsModelRootItem *m_rootItem; + FeedsModelRecycleBin *m_recycleBin; QList m_headerData; QList m_tooltipData; QIcon m_countsIcon; diff --git a/src/core/feedsmodelrecyclebin.cpp b/src/core/feedsmodelrecyclebin.cpp index de16d75f6..10254926c 100644 --- a/src/core/feedsmodelrecyclebin.cpp +++ b/src/core/feedsmodelrecyclebin.cpp @@ -20,20 +20,25 @@ #include "miscellaneous/application.h" #include "miscellaneous/iconfactory.h" +#include -FeedsModelRecycleBin::FeedsModelRecycleBin(FeedsModelRootItem *parent) : FeedsModelRootItem(parent) { + +FeedsModelRecycleBin::FeedsModelRecycleBin(FeedsModelRootItem *parent) + : FeedsModelRootItem(parent) { m_kind = FeedsModelRootItem::RecycleBin; m_icon = qApp->icons()->fromTheme("folder-recycle-bin"); m_id = ID_RECYCLE_BIN; m_title = tr("Recycle bin"); m_description = tr("Recycle bin contains all deleted messages from all feeds."); m_creationDate = QDateTime::currentDateTime(); + + updateCounts(); } FeedsModelRecycleBin::~FeedsModelRecycleBin() { + qDebug("Destroying FeedsModelRecycleBin instance."); } - int FeedsModelRecycleBin::childCount() const { return 0; } @@ -43,14 +48,13 @@ void FeedsModelRecycleBin::appendChild(FeedsModelRootItem *child) { } int FeedsModelRecycleBin::countOfUnreadMessages() const { - return 0; + return m_totalCount; } int FeedsModelRecycleBin::countOfAllMessages() const { - return 0; + return m_totalCount; } - QVariant FeedsModelRecycleBin::data(int column, int role) const { switch (role) { case Qt::DisplayRole: @@ -102,3 +106,17 @@ QVariant FeedsModelRecycleBin::data(int column, int role) const { return QVariant(); } } + +void FeedsModelRecycleBin::updateCounts() { + QSqlDatabase database = qApp->database()->connection("FeedsModelRecycleBin", + DatabaseFactory::FromSettings); + QSqlQuery query_all(database); + query_all.setForwardOnly(true); + + if (query_all.exec("SELECT count(*) FROM Messages WHERE is_deleted = 1;") && query_all.next()) { + m_totalCount = query_all.value(0).toInt(); + } + else { + m_totalCount = 0; + } +} diff --git a/src/core/feedsmodelrecyclebin.h b/src/core/feedsmodelrecyclebin.h index 71224f3f2..7b0e0d1fb 100644 --- a/src/core/feedsmodelrecyclebin.h +++ b/src/core/feedsmodelrecyclebin.h @@ -35,6 +35,12 @@ class FeedsModelRecycleBin : public FeedsModelRootItem { int countOfUnreadMessages() const; int countOfAllMessages() const; QVariant data(int column, int role) const; + + public slots: + void updateCounts(); + + private: + int m_totalCount; }; #endif // FEEDSMODELRECYCLEBIN_H diff --git a/src/core/feedsmodelrootitem.cpp b/src/core/feedsmodelrootitem.cpp index 71bd81a74..d4940353b 100755 --- a/src/core/feedsmodelrootitem.cpp +++ b/src/core/feedsmodelrootitem.cpp @@ -37,7 +37,6 @@ FeedsModelRootItem::FeedsModelRootItem(FeedsModelRootItem *parent_item) } FeedsModelRootItem::~FeedsModelRootItem() { - qDebug("Destroying FeedsModelRootItem instance."); qDeleteAll(m_childItems); } diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index 1007909b3..47bbb9a03 100755 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -132,9 +132,7 @@ void FeedsView::loadExpandedStates() { // Iterate all categories and save their expand statuses. foreach (FeedsModelCategory *category, sourceModel()->allCategories().values()) { setExpanded(model()->mapFromSource(sourceModel()->indexForItem(category)), - settings->value(APP_CFG_CAT_EXP, - QString::number(category->id()), - true).toBool()); + settings->value(APP_CFG_CAT_EXP, QString::number(category->id()), true).toBool()); } } @@ -169,8 +167,7 @@ void FeedsView::updateSelectedFeeds() { void FeedsView::executeNextAutoUpdate() { if (!qApp->closeLock()->tryLock()) { - qDebug("Delaying scheduled feed auto-updates for one minute " - "due to another running update."); + qDebug("Delaying scheduled feed auto-updates for one minute due to another running update."); // Cannot update, quit. return; diff --git a/src/gui/feedsview.h b/src/gui/feedsview.h index 35255c598..3b35f6a50 100644 --- a/src/gui/feedsview.h +++ b/src/gui/feedsview.h @@ -55,17 +55,16 @@ class FeedsView : public QTreeView { void updateAutoUpdateStatus(); // Returns list of selected/all feeds. + // NOTE: This is recursive method which returns all descendants. QList selectedFeeds() const; QList allFeeds() const; - // Return true if current index contains category/feed and - // stores category/feed in the parameter pointer, - // otherwise false. + // Returns pointers to selected feed/category if they are really + // selected. FeedsModelCategory *selectedCategory() const; FeedsModelFeed *selectedFeed() const; - // Saves/loads expand states of all nodes (feeds/categories) of the list - // to/from settings. + // Saves/loads expand states of all nodes (feeds/categories) of the list to/from settings. void saveExpandedStates(); void loadExpandedStates(); diff --git a/src/gui/messagesview.cpp b/src/gui/messagesview.cpp index b30352c59..4db1b986b 100755 --- a/src/gui/messagesview.cpp +++ b/src/gui/messagesview.cpp @@ -63,6 +63,12 @@ void MessagesView::createConnections() { this, SLOT(adjustColumns())); } +void MessagesView::keyboardSearch(const QString &search) { + setSelectionMode(QAbstractItemView::SingleSelection); + QTreeView::keyboardSearch(search); + setSelectionMode(QAbstractItemView::ExtendedSelection); +} + void MessagesView::reloadSelections(int mark_current_index_read) { QModelIndex current_index = selectionModel()->currentIndex(); QModelIndex mapped_current_index = m_proxyModel->mapToSource(current_index); diff --git a/src/gui/messagesview.h b/src/gui/messagesview.h index ec8d2577b..c281a7c6c 100755 --- a/src/gui/messagesview.h +++ b/src/gui/messagesview.h @@ -52,6 +52,12 @@ class MessagesView : public QTreeView { void createConnections(); public slots: + void keyboardSearch(const QString &search) { + setSelectionMode(QAbstractItemView::SingleSelection); + QTreeView::keyboardSearch(search); + setSelectionMode(QAbstractItemView::ExtendedSelection); + } + // Called after data got changed externally // and it needs to be reloaded to the view. // If "mark_current_index_read" is 0, then message with