diff --git a/src/core/feedsmodelrecyclebin.cpp b/src/core/feedsmodelrecyclebin.cpp index 5879a34b8..a136bf220 100644 --- a/src/core/feedsmodelrecyclebin.cpp +++ b/src/core/feedsmodelrecyclebin.cpp @@ -110,6 +110,62 @@ QVariant FeedsModelRecycleBin::data(int column, int role) const { } } +bool FeedsModelRecycleBin::empty() { + QSqlDatabase db_handle = qApp->database()->connection("FeedsModelRecycleBin", + DatabaseFactory::FromSettings); + + if (!db_handle.transaction()) { + qWarning("Starting transaction for recycle bin emptying."); + return false; + } + + QSqlQuery query_empty_bin(db_handle); + query_empty_bin.setForwardOnly(true); + + if (!query_empty_bin.exec("DELETE FROM Messages WHERE is_deleted = 1;")) { + qWarning("Query execution failed for recycle bin emptying."); + + db_handle.rollback(); + return false; + } + + // Commit changes. + if (db_handle.commit()) { + return true; + } + else { + return db_handle.rollback(); + } +} + +bool FeedsModelRecycleBin::restore() { + QSqlDatabase db_handle = qApp->database()->connection("FeedsModelRecycleBin", + DatabaseFactory::FromSettings); + + if (!db_handle.transaction()) { + qWarning("Starting transaction for recycle bin restoring."); + return false; + } + + QSqlQuery query_empty_bin(db_handle); + query_empty_bin.setForwardOnly(true); + + if (!query_empty_bin.exec("UPDATE Messages SET is_deleted = 0 WHERE is_deleted = 1;")) { + qWarning("Query execution failed for recycle bin restoring."); + + db_handle.rollback(); + return false; + } + + // Commit changes. + if (db_handle.commit()) { + return true; + } + else { + return db_handle.rollback(); + } +} + void FeedsModelRecycleBin::updateCounts() { QSqlDatabase database = qApp->database()->connection("FeedsModelRecycleBin", DatabaseFactory::FromSettings); diff --git a/src/core/feedsmodelrecyclebin.h b/src/core/feedsmodelrecyclebin.h index 7b0e0d1fb..44e9c43ee 100644 --- a/src/core/feedsmodelrecyclebin.h +++ b/src/core/feedsmodelrecyclebin.h @@ -36,6 +36,9 @@ class FeedsModelRecycleBin : public FeedsModelRootItem { int countOfAllMessages() const; QVariant data(int column, int role) const; + bool empty(); + bool restore(); + public slots: void updateCounts(); diff --git a/src/gui/feedmessageviewer.cpp b/src/gui/feedmessageviewer.cpp index adc293462..ead7057fd 100755 --- a/src/gui/feedmessageviewer.cpp +++ b/src/gui/feedmessageviewer.cpp @@ -267,6 +267,10 @@ void FeedMessageViewer::createConnections() { SIGNAL(triggered()), m_feedsView, SLOT(editSelectedItem())); connect(form_main->m_ui->m_actionViewSelectedItemsNewspaperMode, SIGNAL(triggered()), m_feedsView, SLOT(openSelectedFeedsInNewspaperMode())); + connect(form_main->m_ui->m_actionEmptyRecycleBin, + SIGNAL(triggered()), m_feedsView, SLOT(emptyRecycleBin())); + connect(form_main->m_ui->m_actionRestoreAllMessages, + SIGNAL(triggered()), m_feedsView, SLOT(restoreRecycleBin())); connect(form_main->m_ui->m_actionDeleteSelectedFeedCategory, SIGNAL(triggered()), m_feedsView, SLOT(deleteSelectedItem())); connect(form_main->m_ui->m_actionSwitchFeedsList, diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index 460d4415c..342c9cf6b 100755 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -44,6 +44,7 @@ FeedsView::FeedsView(QWidget *parent) : QTreeView(parent), m_contextMenuCategoriesFeeds(NULL), m_contextMenuEmptySpace(NULL), + m_contextMenuRecycleBin(NULL), m_autoUpdateTimer(new QTimer(this)) { setObjectName("FeedsView"); @@ -410,6 +411,20 @@ void FeedsView::openSelectedFeedsInNewspaperMode() { } } +void FeedsView::emptyRecycleBin() { + m_sourceModel->recycleBin()->empty(); + updateCountsOfSelectedFeeds(); + + emit feedsNeedToBeReloaded(1); +} + +void FeedsView::restoreRecycleBin() { + m_sourceModel->recycleBin()->restore(); + updateCountsOfAllFeeds(true); + + emit feedsNeedToBeReloaded(1); +} + void FeedsView::updateCountsOfSelectedFeeds(bool update_total_too) { foreach (FeedsModelFeed *feed, selectedFeeds()) { feed->updateCounts(update_total_too); @@ -497,13 +512,20 @@ void FeedsView::initializeContextMenuCategoriesFeeds() { } void FeedsView::initializeContextMenuEmptySpace() { - m_contextMenuEmptySpace = new QMenu(tr("Context menu"), this); + m_contextMenuEmptySpace = new QMenu(tr("Context menu for empty space"), this); m_contextMenuEmptySpace->addActions(QList() << qApp->mainForm()->m_ui->m_actionUpdateAllFeeds << qApp->mainForm()->m_ui->m_actionAddCategory << qApp->mainForm()->m_ui->m_actionAddFeed); } +void FeedsView::initializeContextMenuRecycleBin() { + m_contextMenuRecycleBin = new QMenu(tr("Context menu for recycle bin"), this); + m_contextMenuRecycleBin->addActions(QList() << + qApp->mainForm()->m_ui->m_actionRestoreAllMessages << + qApp->mainForm()->m_ui->m_actionEmptyRecycleBin); +} + void FeedsView::setupAppearance() { #if QT_VERSION >= 0x050000 // Setup column resize strategies. @@ -590,7 +612,12 @@ void FeedsView::contextMenuEvent(QContextMenuEvent *event) { m_contextMenuCategoriesFeeds->exec(event->globalPos()); } else if (clicked_item->kind() == FeedsModelRootItem::RecycleBin) { - // TODO: Display context menu for recycle bin. + // Display context menu for recycle bin. + if (m_contextMenuRecycleBin == NULL) { + initializeContextMenuRecycleBin(); + } + + m_contextMenuRecycleBin->exec(event->globalPos()); } } else { diff --git a/src/gui/feedsview.h b/src/gui/feedsview.h index 3b35f6a50..fbc8b6ac6 100644 --- a/src/gui/feedsview.h +++ b/src/gui/feedsview.h @@ -87,6 +87,10 @@ class FeedsView : public QTreeView { // Newspaper accessors. void openSelectedFeedsInNewspaperMode(); + // Recycle bin operators. + void emptyRecycleBin(); + void restoreRecycleBin(); + // Feed clearers. void setSelectedFeedsClearStatus(int clear); void setAllFeedsClearStatus(int clear); @@ -135,6 +139,7 @@ class FeedsView : public QTreeView { // Initializes context menus. void initializeContextMenuCategoriesFeeds(); void initializeContextMenuEmptySpace(); + void initializeContextMenuRecycleBin(); // Sets up appearance of this widget. void setupAppearance(); @@ -166,6 +171,7 @@ class FeedsView : public QTreeView { private: QMenu *m_contextMenuCategoriesFeeds; QMenu *m_contextMenuEmptySpace; + QMenu *m_contextMenuRecycleBin; QList m_selectedFeeds; FeedsModel *m_sourceModel;