Recycle bin is now able to restore/permanently delete all messages it contains. It now offers own context menu.
This commit is contained in:
parent
db996e4c22
commit
0e6f807d85
5 changed files with 98 additions and 2 deletions
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<QAction*>() <<
|
||||
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<QAction*>() <<
|
||||
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 {
|
||||
|
|
|
@ -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<int> m_selectedFeeds;
|
||||
FeedsModel *m_sourceModel;
|
||||
|
|
Loading…
Add table
Reference in a new issue