Much work, cleaning, marking...
This commit is contained in:
parent
a161e57118
commit
ffd220e4f2
@ -147,7 +147,7 @@ bool RecycleBin::markAsReadUnread(RootItem::ReadStatus status) {
|
|||||||
|
|
||||||
// Commit changes.
|
// Commit changes.
|
||||||
if (db_handle.commit()) {
|
if (db_handle.commit()) {
|
||||||
updateCounts(true);
|
updateCounts(false);
|
||||||
|
|
||||||
parent_root->itemChanged(QList<RootItem*>() << this);
|
parent_root->itemChanged(QList<RootItem*>() << this);
|
||||||
parent_root->requestReloadMessageList(status == RootItem::Read);
|
parent_root->requestReloadMessageList(status == RootItem::Read);
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "services/abstract/serviceroot.h"
|
#include "services/abstract/serviceroot.h"
|
||||||
#include "services/abstract/feed.h"
|
#include "services/abstract/feed.h"
|
||||||
#include "services/abstract/category.h"
|
#include "services/abstract/category.h"
|
||||||
|
#include "services/abstract/recyclebin.h"
|
||||||
#include "miscellaneous/application.h"
|
#include "miscellaneous/application.h"
|
||||||
|
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
@ -84,9 +85,19 @@ QList<Message> RootItem::undeletedMessages() const {
|
|||||||
|
|
||||||
bool RootItem::cleanMessages(bool clear_only_read) {
|
bool RootItem::cleanMessages(bool clear_only_read) {
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
RecycleBin *bin = NULL;
|
||||||
|
|
||||||
foreach (RootItem *child, m_childItems) {
|
foreach (RootItem *child, m_childItems) {
|
||||||
result &= child->cleanMessages(clear_only_read);
|
if (child->kind() == RootItemKind::Bin) {
|
||||||
|
bin = qobject_cast<RecycleBin*>(child);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result &= child->cleanMessages(clear_only_read);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bin != NULL) {
|
||||||
|
result &= bin->cleanMessages(clear_only_read);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -196,14 +196,14 @@ bool StandardServiceRoot::cleanFeeds(QList<Feed*> items, bool clean_read_only) {
|
|||||||
|
|
||||||
if (clean_read_only) {
|
if (clean_read_only) {
|
||||||
if (!query_delete_msg.prepare(QString("UPDATE Messages SET is_deleted = :deleted "
|
if (!query_delete_msg.prepare(QString("UPDATE Messages SET is_deleted = :deleted "
|
||||||
"WHERE feed IN (%1) AND is_deleted = 0 AND is_read = 1;").arg(textualFeedIds(items).join(QSL(", "))))) {
|
"WHERE feed IN (%1) AND is_deleted = 0 AND is_pdeleted = 0 AND is_read = 1;").arg(textualFeedIds(items).join(QSL(", "))))) {
|
||||||
qWarning("Query preparation failed for feeds clearing.");
|
qWarning("Query preparation failed for feeds clearing.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!query_delete_msg.prepare(QString("UPDATE Messages SET is_deleted = :deleted "
|
if (!query_delete_msg.prepare(QString("UPDATE Messages SET is_deleted = :deleted "
|
||||||
"WHERE feed IN (%1) AND is_deleted = 0;").arg(textualFeedIds(items).join(QSL(", "))))) {
|
"WHERE feed IN (%1) AND is_deleted = 0 AND is_pdeleted = 0;").arg(textualFeedIds(items).join(QSL(", "))))) {
|
||||||
qWarning("Query preparation failed for feeds clearing.");
|
qWarning("Query preparation failed for feeds clearing.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,10 @@ bool TtRssCategory::markAsReadUnread(RootItem::ReadStatus status) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TtRssCategory::cleanMessages(bool clear_only_read) {
|
||||||
|
return serviceRoot()->cleanFeeds(getSubTreeFeeds(), clear_only_read);
|
||||||
|
}
|
||||||
|
|
||||||
int TtRssCategory::customId() const {
|
int TtRssCategory::customId() const {
|
||||||
return m_customId;
|
return m_customId;
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ class TtRssCategory : public Category {
|
|||||||
TtRssServiceRoot *serviceRoot();
|
TtRssServiceRoot *serviceRoot();
|
||||||
|
|
||||||
bool markAsReadUnread(ReadStatus status);
|
bool markAsReadUnread(ReadStatus status);
|
||||||
|
bool cleanMessages(bool clear_only_read);
|
||||||
|
|
||||||
int customId() const;
|
int customId() const;
|
||||||
void setCustomId(int custom_id);
|
void setCustomId(int custom_id);
|
||||||
|
@ -161,6 +161,10 @@ bool TtRssFeed::markAsReadUnread(RootItem::ReadStatus status) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TtRssFeed::cleanMessages(bool clear_only_read) {
|
||||||
|
return serviceRoot()->cleanFeeds(QList<Feed*>() << this, clear_only_read);
|
||||||
|
}
|
||||||
|
|
||||||
int TtRssFeed::customId() const {
|
int TtRssFeed::customId() const {
|
||||||
return m_customId;
|
return m_customId;
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@ class TtRssFeed : public Feed {
|
|||||||
QList<Message> undeletedMessages() const;
|
QList<Message> undeletedMessages() const;
|
||||||
|
|
||||||
bool markAsReadUnread(ReadStatus status);
|
bool markAsReadUnread(ReadStatus status);
|
||||||
|
bool cleanMessages(bool clear_only_read);
|
||||||
|
|
||||||
int customId() const;
|
int customId() const;
|
||||||
void setCustomId(int custom_id);
|
void setCustomId(int custom_id);
|
||||||
|
@ -17,6 +17,10 @@
|
|||||||
|
|
||||||
#include "services/tt-rss/ttrssrecyclebin.h"
|
#include "services/tt-rss/ttrssrecyclebin.h"
|
||||||
|
|
||||||
|
#include "services/tt-rss/definitions.h"
|
||||||
|
#include "services/tt-rss/network/ttrssnetworkfactory.h"
|
||||||
|
#include "services/tt-rss/ttrssserviceroot.h"
|
||||||
|
|
||||||
|
|
||||||
TtRssRecycleBin::TtRssRecycleBin(RootItem *parent) : RecycleBin(parent) {
|
TtRssRecycleBin::TtRssRecycleBin(RootItem *parent) : RecycleBin(parent) {
|
||||||
|
|
||||||
@ -24,3 +28,24 @@ TtRssRecycleBin::TtRssRecycleBin(RootItem *parent) : RecycleBin(parent) {
|
|||||||
|
|
||||||
TtRssRecycleBin::~TtRssRecycleBin() {
|
TtRssRecycleBin::~TtRssRecycleBin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TtRssServiceRoot *TtRssRecycleBin::serviceRoot() {
|
||||||
|
return qobject_cast<TtRssServiceRoot*>(getParentServiceRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TtRssRecycleBin::markAsReadUnread(RootItem::ReadStatus status) {
|
||||||
|
QNetworkReply::NetworkError error;
|
||||||
|
QStringList ids = serviceRoot()->customIDSOfMessagesForItem(this);
|
||||||
|
TtRssUpdateArticleResponse response = serviceRoot()->network()->updateArticles(ids, UpdateArticle::Unread,
|
||||||
|
status == RootItem::Unread ?
|
||||||
|
UpdateArticle::SetToTrue :
|
||||||
|
UpdateArticle::SetToFalse,
|
||||||
|
error);
|
||||||
|
|
||||||
|
if (error != QNetworkReply::NoError || response.updateStatus() != STATUS_OK) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return RecycleBin::markAsReadUnread(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -21,12 +21,18 @@
|
|||||||
#include "services/abstract/recyclebin.h"
|
#include "services/abstract/recyclebin.h"
|
||||||
|
|
||||||
|
|
||||||
|
class TtRssServiceRoot;
|
||||||
|
|
||||||
class TtRssRecycleBin : public RecycleBin {
|
class TtRssRecycleBin : public RecycleBin {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TtRssRecycleBin(RootItem *parent = 0);
|
explicit TtRssRecycleBin(RootItem *parent = 0);
|
||||||
virtual ~TtRssRecycleBin();
|
virtual ~TtRssRecycleBin();
|
||||||
|
|
||||||
|
TtRssServiceRoot *serviceRoot();
|
||||||
|
|
||||||
|
bool markAsReadUnread(ReadStatus status);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TTRSSRECYCLEBIN_H
|
#endif // TTRSSRECYCLEBIN_H
|
||||||
|
@ -43,15 +43,13 @@ TtRssServiceRoot::TtRssServiceRoot(RootItem *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
TtRssServiceRoot::~TtRssServiceRoot() {
|
TtRssServiceRoot::~TtRssServiceRoot() {
|
||||||
if (m_network != NULL) {
|
delete m_network;
|
||||||
delete m_network;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TtRssServiceRoot::start() {
|
void TtRssServiceRoot::start() {
|
||||||
loadFromDatabase();
|
loadFromDatabase();
|
||||||
|
|
||||||
if (childCount() == 0) {
|
if (childCount() == 1 && child(0)->kind() == RootItemKind::Bin) {
|
||||||
syncIn();
|
syncIn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -158,7 +156,6 @@ QList<QAction*> TtRssServiceRoot::serviceMenu() {
|
|||||||
m_actionSyncIn = new QAction(qApp->icons()->fromTheme(QSL("item-sync")), tr("Sync in"), this);
|
m_actionSyncIn = new QAction(qApp->icons()->fromTheme(QSL("item-sync")), tr("Sync in"), this);
|
||||||
|
|
||||||
connect(m_actionSyncIn, SIGNAL(triggered()), this, SLOT(syncIn()));
|
connect(m_actionSyncIn, SIGNAL(triggered()), this, SLOT(syncIn()));
|
||||||
|
|
||||||
m_serviceMenu.append(m_actionSyncIn);
|
m_serviceMenu.append(m_actionSyncIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,7 +175,7 @@ bool TtRssServiceRoot::onBeforeSetMessagesRead(RootItem *selected_item, const QL
|
|||||||
read == RootItem::Unread ? UpdateArticle::SetToTrue : UpdateArticle::SetToFalse,
|
read == RootItem::Unread ? UpdateArticle::SetToTrue : UpdateArticle::SetToFalse,
|
||||||
error);
|
error);
|
||||||
|
|
||||||
if (error == QNetworkReply::NoError && response.updateStatus() == STATUS_OK && response.articlesUpdated() == messages.size()) {
|
if (error == QNetworkReply::NoError && response.updateStatus() == STATUS_OK) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -191,7 +188,6 @@ bool TtRssServiceRoot::onAfterSetMessagesRead(RootItem *selected_item, const QLi
|
|||||||
Q_UNUSED(read)
|
Q_UNUSED(read)
|
||||||
|
|
||||||
selected_item->updateCounts(false);
|
selected_item->updateCounts(false);
|
||||||
|
|
||||||
itemChanged(QList<RootItem*>() << selected_item);
|
itemChanged(QList<RootItem*>() << selected_item);
|
||||||
requestFeedReadFilterReload();
|
requestFeedReadFilterReload();
|
||||||
return true;
|
return true;
|
||||||
@ -210,7 +206,7 @@ bool TtRssServiceRoot::onBeforeSwitchMessageImportance(RootItem *selected_item,
|
|||||||
UpdateArticle::Togggle,
|
UpdateArticle::Togggle,
|
||||||
error);
|
error);
|
||||||
|
|
||||||
if (error == QNetworkReply::NoError && response.updateStatus() == STATUS_OK && response.articlesUpdated() == changes.size()) {
|
if (error == QNetworkReply::NoError && response.updateStatus() == STATUS_OK) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -246,7 +242,6 @@ bool TtRssServiceRoot::onAfterMessagesDelete(RootItem *selected_item, const QLis
|
|||||||
itemChanged(QList<RootItem*>() << selected_item << m_recycleBin);
|
itemChanged(QList<RootItem*>() << selected_item << m_recycleBin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
requestFeedReadFilterReload();
|
requestFeedReadFilterReload();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -378,6 +373,50 @@ bool TtRssServiceRoot::markFeedsReadUnread(QList<Feed*> items, RootItem::ReadSta
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TtRssServiceRoot::cleanFeeds(QList<Feed*> items, bool clean_read_only) {
|
||||||
|
QSqlDatabase db_handle = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||||
|
QSqlQuery query_delete_msg(db_handle);
|
||||||
|
query_delete_msg.setForwardOnly(true);
|
||||||
|
|
||||||
|
if (clean_read_only) {
|
||||||
|
if (!query_delete_msg.prepare(QString("UPDATE Messages SET is_deleted = :deleted "
|
||||||
|
"WHERE feed IN (%1) AND is_deleted = 0 AND is_pdeleted = 0 AND is_read = 1;").arg(textualFeedIds(items).join(QSL(", "))))) {
|
||||||
|
qWarning("Query preparation failed for feeds clearing.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!query_delete_msg.prepare(QString("UPDATE Messages SET is_deleted = :deleted "
|
||||||
|
"WHERE feed IN (%1) AND is_deleted = 0 AND is_pdeleted = 0;").arg(textualFeedIds(items).join(QSL(", "))))) {
|
||||||
|
qWarning("Query preparation failed for feeds clearing.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
query_delete_msg.bindValue(QSL(":deleted"), 1);
|
||||||
|
|
||||||
|
if (!query_delete_msg.exec()) {
|
||||||
|
qDebug("Query execution for feeds clearing failed.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Messages are cleared, now inform model about need to reload data.
|
||||||
|
QList<RootItem*> itemss;
|
||||||
|
|
||||||
|
foreach (Feed *feed, items) {
|
||||||
|
feed->updateCounts(true);
|
||||||
|
itemss.append(feed);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_recycleBin->updateCounts(true);
|
||||||
|
itemss.append(m_recycleBin);
|
||||||
|
|
||||||
|
itemChanged(itemss);
|
||||||
|
requestReloadMessageList(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TtRssServiceRoot::saveAccountDataToDatabase() {
|
void TtRssServiceRoot::saveAccountDataToDatabase() {
|
||||||
if (accountId() != NO_PARENT_CATEGORY) {
|
if (accountId() != NO_PARENT_CATEGORY) {
|
||||||
// We are overwritting previously saved data.
|
// We are overwritting previously saved data.
|
||||||
|
@ -75,6 +75,7 @@ class TtRssServiceRoot : public ServiceRoot {
|
|||||||
QStringList customIDSOfMessagesForItem(RootItem *item);
|
QStringList customIDSOfMessagesForItem(RootItem *item);
|
||||||
|
|
||||||
bool markFeedsReadUnread(QList<Feed*> items, ReadStatus read);
|
bool markFeedsReadUnread(QList<Feed*> items, ReadStatus read);
|
||||||
|
bool cleanFeeds(QList<Feed*> items, bool clean_read_only);
|
||||||
|
|
||||||
void saveAccountDataToDatabase();
|
void saveAccountDataToDatabase();
|
||||||
void updateTitle();
|
void updateTitle();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user