Work on restoring.ˇ
This commit is contained in:
parent
54cf90baa3
commit
adae003ed5
@ -318,7 +318,7 @@ QList<Feed*> FeedsModel::feedsForScheduledUpdate(bool auto_update_now) {
|
||||
QList<Message> FeedsModel::messagesForFeeds(const QList<Feed*> &feeds) {
|
||||
QList<Message> messages;
|
||||
|
||||
foreach (const Feed *feed, feeds) {
|
||||
foreach (Feed *feed, feeds) {
|
||||
messages.append(feed->undeletedMessages());
|
||||
}
|
||||
|
||||
|
@ -431,27 +431,30 @@ bool MessagesModel::setBatchMessagesRead(const QModelIndexList &messages, RootIt
|
||||
}
|
||||
|
||||
bool MessagesModel::setBatchMessagesRestored(const QModelIndexList &messages) {
|
||||
QSqlDatabase db_handle = database();
|
||||
QSqlQuery query_read_msg(db_handle);
|
||||
QStringList message_ids;
|
||||
|
||||
query_read_msg.setForwardOnly(true);
|
||||
QList<int> message_ids_num;
|
||||
|
||||
// Obtain IDs of all desired messages.
|
||||
foreach (const QModelIndex &message, messages) {
|
||||
message_ids.append(QString::number(messageId(message.row())));
|
||||
int msg_id = messageId(message.row());
|
||||
|
||||
message_ids_num.append(msg_id);
|
||||
message_ids.append(QString::number(msg_id));
|
||||
}
|
||||
|
||||
if (!m_selectedItem->getParentServiceRoot()->onBeforeMessagesRestoredFromBin(m_selectedItem, message_ids_num)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QSqlQuery query_read_msg(database());
|
||||
QString sql_delete_query = QString(QSL("UPDATE Messages SET is_deleted = 0 WHERE id IN (%1);")).arg(message_ids.join(QSL(", ")));
|
||||
|
||||
query_read_msg.setForwardOnly(true);
|
||||
|
||||
if (query_read_msg.exec(sql_delete_query)) {
|
||||
fetchAllData();
|
||||
|
||||
//emit messageCountsChanged();
|
||||
|
||||
// TODO: counts changed
|
||||
//emit messageCountsChanged(m_selectedItem.mode(), true, true);
|
||||
return true;
|
||||
return m_selectedItem->getParentServiceRoot()->onAfterMessagesRestoredFromBin(m_selectedItem, message_ids_num);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
|
@ -105,10 +105,20 @@ class ServiceRoot : public RootItem {
|
||||
// by the user from message list.
|
||||
virtual bool onBeforeMessagesDelete(RootItem *selected_item, QList<int> message_db_ids) = 0;
|
||||
|
||||
// Called AFTER the list of messages is about to be deleted
|
||||
// Called AFTER the list of messages was deleted
|
||||
// by the user from message list.
|
||||
virtual bool onAfterMessagesDelete(RootItem *selected_item, QList<int> message_db_ids) = 0;
|
||||
|
||||
// Called BEFORE the list of messages is about to be restored from recycle bin
|
||||
// by the user from message list.
|
||||
// Selected item is naturally recycle bin.
|
||||
virtual bool onBeforeMessagesRestoredFromBin(RootItem *selected_item, QList<int> message_db_ids) = 0;
|
||||
|
||||
// Called AFTER the list of messages was restored from recycle bin
|
||||
// by the user from message list.
|
||||
// Selected item is naturally recycle bin.
|
||||
virtual bool onAfterMessagesRestoredFromBin(RootItem *selected_item, QList<int> message_db_ids) = 0;
|
||||
|
||||
// Access to feed model.
|
||||
FeedsModel *feedsModel() const;
|
||||
|
||||
|
@ -610,6 +610,21 @@ bool StandardServiceRoot::onAfterMessagesDelete(RootItem *selected_item, QList<i
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StandardServiceRoot::onBeforeMessagesRestoredFromBin(RootItem *selected_item, QList<int> message_db_ids) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StandardServiceRoot::onAfterMessagesRestoredFromBin(RootItem *selected_item, QList<int> message_db_ids) {
|
||||
// TODO: ok, nejake zpravy obnoveny z koše, ale nevíme přesně
|
||||
// do jakých původně kanálů, obnovíme všecko.
|
||||
Q_UNUSED(selected_item)
|
||||
Q_UNUSED(message_db_ids)
|
||||
|
||||
emit dataChanged(getSubTree());
|
||||
emit readFeedsFilterInvalidationRequested();
|
||||
return true;
|
||||
}
|
||||
|
||||
void StandardServiceRoot::assembleCategories(CategoryAssignment categories) {
|
||||
QHash<int,RootItem*> assignments;
|
||||
assignments.insert(NO_PARENT_CATEGORY, this);
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QPair>
|
||||
#include <QSqlDatabase>
|
||||
|
||||
|
||||
class StandardRecycleBin;
|
||||
@ -69,6 +70,9 @@ class StandardServiceRoot : public ServiceRoot {
|
||||
bool onBeforeMessagesDelete(RootItem *selected_item, QList<int> message_db_ids);
|
||||
bool onAfterMessagesDelete(RootItem *selected_item, QList<int> message_db_ids);
|
||||
|
||||
bool onBeforeMessagesRestoredFromBin(RootItem *selected_item, QList<int> message_db_ids);
|
||||
bool onAfterMessagesRestoredFromBin(RootItem *selected_item, QList<int> message_db_ids);
|
||||
|
||||
// Returns all standard categories which are lying under given root node.
|
||||
// This does NOT include the root node even if the node is category.
|
||||
QHash<int,StandardCategory*> categoriesForItem(RootItem *root);
|
||||
@ -92,6 +96,9 @@ class StandardServiceRoot : public ServiceRoot {
|
||||
bool markRecycleBinReadUnread(ReadStatus read);
|
||||
bool cleanFeeds(QList<Feed*> items, bool clean_read_only);
|
||||
|
||||
// DB connection to be used by child items - feeds/categories.
|
||||
QSqlDatabase dbConnection() const;
|
||||
|
||||
public slots:
|
||||
void addNewCategory();
|
||||
void addNewFeed();
|
||||
@ -121,6 +128,8 @@ class StandardServiceRoot : public ServiceRoot {
|
||||
QList<QAction*> m_feedContextMenu;
|
||||
|
||||
QAction *m_actionFeedFetchMetadata;
|
||||
|
||||
QSqlDatabase m_database;
|
||||
};
|
||||
|
||||
#endif // STANDARDSERVICEROOT_H
|
||||
|
@ -60,6 +60,14 @@ class TtRssServiceRoot : public ServiceRoot {
|
||||
bool onAfterMessagesDelete(RootItem *selected_item, QList<int> message_db_ids) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool onBeforeMessagesRestoredFromBin(RootItem *selected_item, QList<int> message_db_ids) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool onAfterMessagesRestoredFromBin(RootItem *selected_item, QList<int> message_db_ids) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // TTRSSSERVICEROOT_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user