Restoring of individual messages added.

This commit is contained in:
Martin Rotter 2015-11-23 19:31:03 +01:00
parent 7ea94ef42f
commit 6abe99ed54
8 changed files with 63 additions and 12 deletions

View File

@ -71,6 +71,8 @@ void MessagesModel::setupFonts() {
m_boldFont.setBold(true);
}
void MessagesModel::loadMessages(RootItem *item) {
m_selectedItem = item;
@ -110,6 +112,10 @@ RootItem::Importance MessagesModel::messageImportance(int row_index) const {
return (RootItem::Importance) data(row_index, MSG_DB_IMPORTANT_INDEX, Qt::EditRole).toInt();
}
RootItem *MessagesModel::loadedItem() const {
return m_selectedItem;
}
void MessagesModel::updateDateFormat() {
if (qApp->settings()->value(GROUP(Messages), SETTING(Messages::UseCustomDate)).toBool()) {
m_customDateFormat = qApp->settings()->value(GROUP(Messages), SETTING(Messages::CustomDateFormat)).toString();
@ -360,7 +366,7 @@ bool MessagesModel::switchBatchMessageImportance(const QModelIndexList &messages
}
}
bool MessagesModel::setBatchMessagesDeleted(const QModelIndexList &messages, int deleted) {
bool MessagesModel::setBatchMessagesDeleted(const QModelIndexList &messages) {
QStringList message_ids;
QList<int> message_ids_num;
@ -382,12 +388,10 @@ bool MessagesModel::setBatchMessagesDeleted(const QModelIndexList &messages, int
query_read_msg.setForwardOnly(true);
if (m_selectedItem->kind() != RootItemKind::Bin) {
sql_delete_query = QString(QSL("UPDATE Messages SET is_deleted = %2 WHERE id IN (%1);")).arg(message_ids.join(QSL(", ")),
QString::number(deleted));
sql_delete_query = QString(QSL("UPDATE Messages SET is_deleted = 1 WHERE id IN (%1);")).arg(message_ids.join(QSL(", ")));
}
else {
sql_delete_query = QString(QSL("UPDATE Messages SET is_pdeleted = %2 WHERE id IN (%1);")).arg(message_ids.join(QSL(", ")),
QString::number(deleted));
sql_delete_query = QString(QSL("UPDATE Messages SET is_pdeleted = 1 WHERE id IN (%1);")).arg(message_ids.join(QSL(", ")));
}
if (query_read_msg.exec(sql_delete_query)) {

View File

@ -55,6 +55,8 @@ class MessagesModel : public QSqlTableModel {
int messageId(int row_index) const;
RootItem::Importance messageImportance(int row_index) const;
RootItem *loadedItem() const;
void updateDateFormat();
void reloadWholeLayout();
@ -71,7 +73,7 @@ class MessagesModel : public QSqlTableModel {
// NOTE: Model is reset after one of these methods is applied and
// changes ARE written to the database.
bool switchBatchMessageImportance(const QModelIndexList &messages);
bool setBatchMessagesDeleted(const QModelIndexList &messages, int deleted);
bool setBatchMessagesDeleted(const QModelIndexList &messages);
bool setBatchMessagesRead(const QModelIndexList &messages, RootItem::ReadStatus read);
bool setBatchMessagesRestored(const QModelIndexList &messages);

View File

@ -323,6 +323,7 @@ void FormMain::setupIcons() {
m_ui->m_actionSelectPreviousMessage->setIcon(icon_theme_factory->fromTheme(QSL("go-up")));
m_ui->m_actionShowOnlyUnreadItems->setIcon(icon_theme_factory->fromTheme(QSL("mail-mark-unread")));
m_ui->m_actionExpandCollapseItem->setIcon(icon_theme_factory->fromTheme(QSL("expand-collapse")));
m_ui->m_actionRestoreSelectedMessages->setIcon(icon_theme_factory->fromTheme(QSL("recycle-bin-restore-one")));
// Setup icons for underlying components: opened web browsers...
foreach (WebBrowser *browser, WebBrowser::runningWebBrowsers()) {

View File

@ -643,6 +643,11 @@
<string>&amp;Edit selected service account</string>
</property>
</action>
<action name="m_actionRestoreSelectedMessages">
<property name="text">
<string>&amp;Restore selected messages</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@ -313,6 +313,8 @@ void FeedMessageViewer::createConnections() {
this, SLOT(switchMessageSplitterOrientation()));
connect(form_main->m_ui->m_actionShowOnlyUnreadItems, SIGNAL(toggled(bool)),
this, SLOT(toggleShowOnlyUnreadFeeds()));
connect(form_main->m_ui->m_actionRestoreSelectedMessages, SIGNAL(triggered()),
m_messagesView, SLOT(restoreSelectedMessages()));
}
void FeedMessageViewer::initialize() {

View File

@ -140,16 +140,18 @@ void MessagesView::contextMenuEvent(QContextMenuEvent *event) {
return;
}
if (m_contextMenu == NULL) {
// Context menu is not initialized, initialize.
initializeContextMenu();
}
// Context menu is not initialized, initialize.
initializeContextMenu();
m_contextMenu->exec(event->globalPos());
}
void MessagesView::initializeContextMenu() {
m_contextMenu = new QMenu(tr("Context menu for messages"), this);
if (m_contextMenu == NULL) {
m_contextMenu = new QMenu(tr("Context menu for messages"), this);
}
m_contextMenu->clear();
m_contextMenu->addActions(QList<QAction*>() <<
qApp->mainForm()->m_ui->m_actionSendMessageViaEmail <<
qApp->mainForm()->m_ui->m_actionOpenSelectedSourceArticlesExternally <<
@ -159,6 +161,10 @@ void MessagesView::initializeContextMenu() {
qApp->mainForm()->m_ui->m_actionMarkSelectedMessagesAsUnread <<
qApp->mainForm()->m_ui->m_actionSwitchImportanceOfSelectedMessages <<
qApp->mainForm()->m_ui->m_actionDeleteSelectedMessages);
if (m_sourceModel->loadedItem() != NULL && m_sourceModel->loadedItem()->kind() == RootItemKind::Bin) {
m_contextMenu->addAction(qApp->mainForm()->m_ui->m_actionRestoreSelectedMessages);
}
}
void MessagesView::mousePressEvent(QMouseEvent *event) {
@ -359,7 +365,35 @@ void MessagesView::deleteSelectedMessages() {
QModelIndexList selected_indexes = selectionModel()->selectedRows();
QModelIndexList mapped_indexes = m_proxyModel->mapListToSource(selected_indexes);
m_sourceModel->setBatchMessagesDeleted(mapped_indexes, 1);
m_sourceModel->setBatchMessagesDeleted(mapped_indexes);
sortByColumn(header()->sortIndicatorSection(), header()->sortIndicatorOrder());
int row_count = m_sourceModel->rowCount();
if (row_count > 0) {
QModelIndex last_item = current_index.row() < row_count ?
m_proxyModel->index(current_index.row(), MSG_DB_TITLE_INDEX) :
m_proxyModel->index(row_count - 1, MSG_DB_TITLE_INDEX);
setCurrentIndex(last_item);
scrollTo(last_item);
reselectIndexes(QModelIndexList() << last_item);
}
else {
emit currentMessagesRemoved();
}
}
void MessagesView::restoreSelectedMessages() {
QModelIndex current_index = selectionModel()->currentIndex();
if (!current_index.isValid()) {
return;
}
QModelIndexList selected_indexes = selectionModel()->selectedRows();
QModelIndexList mapped_indexes = m_proxyModel->mapListToSource(selected_indexes);
m_sourceModel->setBatchMessagesRestored(mapped_indexes);
sortByColumn(header()->sortIndicatorSection(), header()->sortIndicatorOrder());
int row_count = m_sourceModel->rowCount();

View File

@ -72,6 +72,7 @@ class MessagesView : public QTreeView {
void markSelectedMessagesUnread();
void switchSelectedMessagesImportance();
void deleteSelectedMessages();
void restoreSelectedMessages();
void selectNextItem();
void selectPreviousItem();

View File

@ -623,6 +623,8 @@ bool StandardServiceRoot::onAfterMessagesRestoredFromBin(RootItem *selected_item
Q_UNUSED(selected_item)
Q_UNUSED(message_db_ids)
updateCounts(true);
emit dataChanged(getSubTree());
emit readFeedsFilterInvalidationRequested();
return true;