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() {
|
void FeedsModelRecycleBin::updateCounts() {
|
||||||
QSqlDatabase database = qApp->database()->connection("FeedsModelRecycleBin",
|
QSqlDatabase database = qApp->database()->connection("FeedsModelRecycleBin",
|
||||||
DatabaseFactory::FromSettings);
|
DatabaseFactory::FromSettings);
|
||||||
|
|
|
@ -36,6 +36,9 @@ class FeedsModelRecycleBin : public FeedsModelRootItem {
|
||||||
int countOfAllMessages() const;
|
int countOfAllMessages() const;
|
||||||
QVariant data(int column, int role) const;
|
QVariant data(int column, int role) const;
|
||||||
|
|
||||||
|
bool empty();
|
||||||
|
bool restore();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateCounts();
|
void updateCounts();
|
||||||
|
|
||||||
|
|
|
@ -267,6 +267,10 @@ void FeedMessageViewer::createConnections() {
|
||||||
SIGNAL(triggered()), m_feedsView, SLOT(editSelectedItem()));
|
SIGNAL(triggered()), m_feedsView, SLOT(editSelectedItem()));
|
||||||
connect(form_main->m_ui->m_actionViewSelectedItemsNewspaperMode,
|
connect(form_main->m_ui->m_actionViewSelectedItemsNewspaperMode,
|
||||||
SIGNAL(triggered()), m_feedsView, SLOT(openSelectedFeedsInNewspaperMode()));
|
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,
|
connect(form_main->m_ui->m_actionDeleteSelectedFeedCategory,
|
||||||
SIGNAL(triggered()), m_feedsView, SLOT(deleteSelectedItem()));
|
SIGNAL(triggered()), m_feedsView, SLOT(deleteSelectedItem()));
|
||||||
connect(form_main->m_ui->m_actionSwitchFeedsList,
|
connect(form_main->m_ui->m_actionSwitchFeedsList,
|
||||||
|
|
|
@ -44,6 +44,7 @@ FeedsView::FeedsView(QWidget *parent)
|
||||||
: QTreeView(parent),
|
: QTreeView(parent),
|
||||||
m_contextMenuCategoriesFeeds(NULL),
|
m_contextMenuCategoriesFeeds(NULL),
|
||||||
m_contextMenuEmptySpace(NULL),
|
m_contextMenuEmptySpace(NULL),
|
||||||
|
m_contextMenuRecycleBin(NULL),
|
||||||
m_autoUpdateTimer(new QTimer(this)) {
|
m_autoUpdateTimer(new QTimer(this)) {
|
||||||
setObjectName("FeedsView");
|
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) {
|
void FeedsView::updateCountsOfSelectedFeeds(bool update_total_too) {
|
||||||
foreach (FeedsModelFeed *feed, selectedFeeds()) {
|
foreach (FeedsModelFeed *feed, selectedFeeds()) {
|
||||||
feed->updateCounts(update_total_too);
|
feed->updateCounts(update_total_too);
|
||||||
|
@ -497,13 +512,20 @@ void FeedsView::initializeContextMenuCategoriesFeeds() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedsView::initializeContextMenuEmptySpace() {
|
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*>() <<
|
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 <<
|
||||||
qApp->mainForm()->m_ui->m_actionAddFeed);
|
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() {
|
void FeedsView::setupAppearance() {
|
||||||
#if QT_VERSION >= 0x050000
|
#if QT_VERSION >= 0x050000
|
||||||
// Setup column resize strategies.
|
// Setup column resize strategies.
|
||||||
|
@ -590,7 +612,12 @@ void FeedsView::contextMenuEvent(QContextMenuEvent *event) {
|
||||||
m_contextMenuCategoriesFeeds->exec(event->globalPos());
|
m_contextMenuCategoriesFeeds->exec(event->globalPos());
|
||||||
}
|
}
|
||||||
else if (clicked_item->kind() == FeedsModelRootItem::RecycleBin) {
|
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 {
|
else {
|
||||||
|
|
|
@ -87,6 +87,10 @@ class FeedsView : public QTreeView {
|
||||||
// Newspaper accessors.
|
// Newspaper accessors.
|
||||||
void openSelectedFeedsInNewspaperMode();
|
void openSelectedFeedsInNewspaperMode();
|
||||||
|
|
||||||
|
// Recycle bin operators.
|
||||||
|
void emptyRecycleBin();
|
||||||
|
void restoreRecycleBin();
|
||||||
|
|
||||||
// Feed clearers.
|
// Feed clearers.
|
||||||
void setSelectedFeedsClearStatus(int clear);
|
void setSelectedFeedsClearStatus(int clear);
|
||||||
void setAllFeedsClearStatus(int clear);
|
void setAllFeedsClearStatus(int clear);
|
||||||
|
@ -135,6 +139,7 @@ class FeedsView : public QTreeView {
|
||||||
// Initializes context menus.
|
// Initializes context menus.
|
||||||
void initializeContextMenuCategoriesFeeds();
|
void initializeContextMenuCategoriesFeeds();
|
||||||
void initializeContextMenuEmptySpace();
|
void initializeContextMenuEmptySpace();
|
||||||
|
void initializeContextMenuRecycleBin();
|
||||||
|
|
||||||
// Sets up appearance of this widget.
|
// Sets up appearance of this widget.
|
||||||
void setupAppearance();
|
void setupAppearance();
|
||||||
|
@ -166,6 +171,7 @@ class FeedsView : public QTreeView {
|
||||||
private:
|
private:
|
||||||
QMenu *m_contextMenuCategoriesFeeds;
|
QMenu *m_contextMenuCategoriesFeeds;
|
||||||
QMenu *m_contextMenuEmptySpace;
|
QMenu *m_contextMenuEmptySpace;
|
||||||
|
QMenu *m_contextMenuRecycleBin;
|
||||||
|
|
||||||
QList<int> m_selectedFeeds;
|
QList<int> m_selectedFeeds;
|
||||||
FeedsModel *m_sourceModel;
|
FeedsModel *m_sourceModel;
|
||||||
|
|
Loading…
Add table
Reference in a new issue