Refactoring.
This commit is contained in:
parent
3c8b0441b5
commit
c44d71b7c9
@ -132,6 +132,40 @@ void Feed::setAutoUpdateRemainingInterval(int auto_update_remaining_interval) {
|
|||||||
m_autoUpdateRemainingInterval = auto_update_remaining_interval;
|
m_autoUpdateRemainingInterval = auto_update_remaining_interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Feed::updateCounts(bool including_total_count) {
|
||||||
|
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||||
|
QSqlQuery query_all(database);
|
||||||
|
|
||||||
|
query_all.setForwardOnly(true);
|
||||||
|
|
||||||
|
if (including_total_count) {
|
||||||
|
query_all.prepare("SELECT count(*) FROM Messages "
|
||||||
|
"WHERE feed = :feed AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;");
|
||||||
|
query_all.bindValue(QSL(":feed"), customId());
|
||||||
|
query_all.bindValue(QSL(":account_id"), getParentServiceRoot()->accountId());
|
||||||
|
|
||||||
|
if (query_all.exec() && query_all.next()) {
|
||||||
|
setCountOfAllMessages(query_all.value(0).toInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
query_all.prepare("SELECT count(*) FROM Messages "
|
||||||
|
"WHERE feed = :feed AND is_deleted = 0 AND is_pdeleted = 0 AND is_read = 0 AND account_id = :account_id;");
|
||||||
|
query_all.bindValue(QSL(":feed"), customId());
|
||||||
|
query_all.bindValue(QSL(":account_id"), getParentServiceRoot()->accountId());
|
||||||
|
|
||||||
|
// Obtain count of unread messages.
|
||||||
|
if (query_all.exec() && query_all.next()) {
|
||||||
|
int new_unread_count = query_all.value(0).toInt();
|
||||||
|
|
||||||
|
if (status() == NewMessages && new_unread_count < countOfUnreadMessages()) {
|
||||||
|
setStatus(Normal);
|
||||||
|
}
|
||||||
|
|
||||||
|
setCountOfUnreadMessages(new_unread_count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int Feed::updateMessages(const QList<Message> &messages) {
|
int Feed::updateMessages(const QList<Message> &messages) {
|
||||||
if (messages.isEmpty()) {
|
if (messages.isEmpty()) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -94,6 +94,8 @@ class Feed : public RootItem {
|
|||||||
m_url = url;
|
m_url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateCounts(bool including_total_count);
|
||||||
|
|
||||||
virtual int messageForeignKeyId() const = 0;
|
virtual int messageForeignKeyId() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -127,6 +127,52 @@ void ServiceRoot::cleanAllItems() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ServiceRoot::cleanFeeds(QList<Feed *> items, bool clean_read_only) {
|
||||||
|
QSqlDatabase db_handle = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||||
|
QSqlQuery query_delete_msg(db_handle);
|
||||||
|
int account_id = accountId();
|
||||||
|
query_delete_msg.setForwardOnly(true);
|
||||||
|
|
||||||
|
if (clean_read_only) {
|
||||||
|
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 AND account_id = :account_id;")
|
||||||
|
.arg(textualFeedIds(items).join(QSL(", "))));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
query_delete_msg.prepare(QString("UPDATE Messages SET is_deleted = :deleted "
|
||||||
|
"WHERE feed IN (%1) AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;")
|
||||||
|
.arg(textualFeedIds(items).join(QSL(", "))));
|
||||||
|
}
|
||||||
|
|
||||||
|
query_delete_msg.bindValue(QSL(":deleted"), 1);
|
||||||
|
query_delete_msg.bindValue(QSL(":account_id"), account_id);
|
||||||
|
|
||||||
|
if (query_delete_msg.exec()) {
|
||||||
|
// Messages are cleared, now inform model about need to reload data.
|
||||||
|
QList<RootItem*> itemss;
|
||||||
|
|
||||||
|
foreach (Feed *feed, items) {
|
||||||
|
feed->updateCounts(true);
|
||||||
|
itemss.append(feed);
|
||||||
|
}
|
||||||
|
|
||||||
|
RecycleBin *bin = recycleBin();
|
||||||
|
|
||||||
|
if (bin != NULL) {
|
||||||
|
bin->updateCounts(true);
|
||||||
|
itemss.append(bin);
|
||||||
|
}
|
||||||
|
|
||||||
|
itemChanged(itemss);
|
||||||
|
requestReloadMessageList(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qDebug("Cleaning of feeds failed: '%s'.", qPrintable(query_delete_msg.lastError().text()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ServiceRoot::storeNewFeedTree(RootItem *root) {
|
void ServiceRoot::storeNewFeedTree(RootItem *root) {
|
||||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||||
QSqlQuery query_category(database);
|
QSqlQuery query_category(database);
|
||||||
|
@ -88,6 +88,9 @@ class ServiceRoot : public RootItem {
|
|||||||
// NOTE: Keep in sync with ServiceEntryRoot::code().
|
// NOTE: Keep in sync with ServiceEntryRoot::code().
|
||||||
virtual QString code() const = 0;
|
virtual QString code() const = 0;
|
||||||
|
|
||||||
|
// Removes all/read only messages from given underlying feeds.
|
||||||
|
bool cleanFeeds(QList<Feed*> items, bool clean_read_only);
|
||||||
|
|
||||||
// This method should prepare messages for given "item" (download them maybe?)
|
// This method should prepare messages for given "item" (download them maybe?)
|
||||||
// into predefined "Messages" table
|
// into predefined "Messages" table
|
||||||
// and then use method QSqlTableModel::setFilter(....).
|
// and then use method QSqlTableModel::setFilter(....).
|
||||||
|
@ -352,7 +352,7 @@ QList<Message> OwnCloudGetMessagesResponse::messages() const {
|
|||||||
|
|
||||||
msg.m_author = message_map["author"].toString();
|
msg.m_author = message_map["author"].toString();
|
||||||
msg.m_contents = message_map["body"].toString();
|
msg.m_contents = message_map["body"].toString();
|
||||||
msg.m_created = TextFactory::parseDateTime(message_map["pubDate"].value<qint64>());
|
msg.m_created = TextFactory::parseDateTime(message_map["pubDate"].value<qint64>() * 1000);
|
||||||
msg.m_createdFromFeed = true;
|
msg.m_createdFromFeed = true;
|
||||||
msg.m_customId = message_map["id"].toString();
|
msg.m_customId = message_map["id"].toString();
|
||||||
|
|
||||||
|
@ -185,37 +185,6 @@ QString StandardFeed::typeToString(StandardFeed::Type type) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StandardFeed::updateCounts(bool including_total_count) {
|
|
||||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
|
||||||
QSqlQuery query(database);
|
|
||||||
query.setForwardOnly(true);
|
|
||||||
|
|
||||||
if (including_total_count) {
|
|
||||||
query.prepare(QSL("SELECT count(*) FROM Messages WHERE feed = :feed AND is_pdeleted = 0 AND is_deleted = 0 AND account_id = :account_id;"));
|
|
||||||
query.bindValue(QSL(":feed"), id());
|
|
||||||
query.bindValue(QSL(":account_id"), serviceRoot()->accountId());
|
|
||||||
|
|
||||||
if (query.exec() && query.next()) {
|
|
||||||
setCountOfAllMessages(query.value(0).toInt());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtain count of unread messages.
|
|
||||||
query.prepare(QSL("SELECT count(*) FROM Messages WHERE feed = :feed AND is_pdeleted = 0 AND is_deleted = 0 AND is_read = 0 AND account_id = :account_id;"));
|
|
||||||
query.bindValue(QSL(":feed"), id());
|
|
||||||
query.bindValue(QSL(":account_id"), serviceRoot()->accountId());
|
|
||||||
|
|
||||||
if (query.exec() && query.next()) {
|
|
||||||
int new_unread_count = query.value(0).toInt();
|
|
||||||
|
|
||||||
if (status() == NewMessages && new_unread_count < countOfUnreadMessages()) {
|
|
||||||
setStatus(Normal);
|
|
||||||
}
|
|
||||||
|
|
||||||
setCountOfUnreadMessages(new_unread_count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void StandardFeed::fetchMetadataForItself() {
|
void StandardFeed::fetchMetadataForItself() {
|
||||||
QPair<StandardFeed*,QNetworkReply::NetworkError> metadata = guessFeed(url(), username(), password());
|
QPair<StandardFeed*,QNetworkReply::NetworkError> metadata = guessFeed(url(), username(), password());
|
||||||
|
|
||||||
|
@ -76,9 +76,6 @@ class StandardFeed : public Feed {
|
|||||||
Qt::ItemFlags additionalFlags() const;
|
Qt::ItemFlags additionalFlags() const;
|
||||||
bool performDragDropChange(RootItem *target_item);
|
bool performDragDropChange(RootItem *target_item);
|
||||||
|
|
||||||
// Updates counts of all/unread messages for this feed.
|
|
||||||
void updateCounts(bool including_total_count);
|
|
||||||
|
|
||||||
// Removes this standard feed from persistent
|
// Removes this standard feed from persistent
|
||||||
// storage.
|
// storage.
|
||||||
bool removeItself();
|
bool removeItself();
|
||||||
|
@ -199,48 +199,6 @@ bool StandardServiceRoot::markFeedsReadUnread(QList<Feed*> items, ReadStatus rea
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StandardServiceRoot::cleanFeeds(QList<Feed*> items, bool clean_read_only) {
|
|
||||||
QSqlDatabase db_handle = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
|
||||||
QSqlQuery query_delete_msg(db_handle);
|
|
||||||
int account_id = accountId();
|
|
||||||
query_delete_msg.setForwardOnly(true);
|
|
||||||
|
|
||||||
if (clean_read_only) {
|
|
||||||
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 AND account_id = :account_id;")
|
|
||||||
.arg(textualFeedIds(items).join(QSL(", "))));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
query_delete_msg.prepare(QString("UPDATE Messages SET is_deleted = :deleted "
|
|
||||||
"WHERE feed IN (%1) AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;")
|
|
||||||
.arg(textualFeedIds(items).join(QSL(", "))));
|
|
||||||
}
|
|
||||||
|
|
||||||
query_delete_msg.bindValue(QSL(":deleted"), 1);
|
|
||||||
query_delete_msg.bindValue(QSL(":account_id"), account_id);
|
|
||||||
|
|
||||||
if (query_delete_msg.exec()) {
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
qDebug("Cleaning of feeds failed: '%s'.", qPrintable(query_delete_msg.lastError().text()));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void StandardServiceRoot::loadFromDatabase(){
|
void StandardServiceRoot::loadFromDatabase(){
|
||||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||||
Assignment categories;
|
Assignment categories;
|
||||||
|
@ -70,7 +70,6 @@ class StandardServiceRoot : public ServiceRoot {
|
|||||||
bool mergeImportExportModel(FeedsImportExportModel *model, RootItem *target_root_node, QString &output_message);
|
bool mergeImportExportModel(FeedsImportExportModel *model, RootItem *target_root_node, QString &output_message);
|
||||||
|
|
||||||
bool markFeedsReadUnread(QList<Feed*> items, ReadStatus read);
|
bool markFeedsReadUnread(QList<Feed*> items, ReadStatus read);
|
||||||
bool cleanFeeds(QList<Feed*> items, bool clean_read_only);
|
|
||||||
|
|
||||||
void loadFromDatabase();
|
void loadFromDatabase();
|
||||||
void checkArgumentForFeedAdding(const QString &argument);
|
void checkArgumentForFeedAdding(const QString &argument);
|
||||||
|
@ -101,40 +101,6 @@ QVariant TtRssFeed::data(int column, int role) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TtRssFeed::updateCounts(bool including_total_count) {
|
|
||||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
|
||||||
QSqlQuery query_all(database);
|
|
||||||
|
|
||||||
query_all.setForwardOnly(true);
|
|
||||||
|
|
||||||
if (including_total_count) {
|
|
||||||
query_all.prepare("SELECT count(*) FROM Messages "
|
|
||||||
"WHERE feed = :feed AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;");
|
|
||||||
query_all.bindValue(QSL(":feed"), customId());
|
|
||||||
query_all.bindValue(QSL(":account_id"), serviceRoot()->accountId());
|
|
||||||
|
|
||||||
if (query_all.exec() && query_all.next()) {
|
|
||||||
setCountOfAllMessages(query_all.value(0).toInt());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
query_all.prepare("SELECT count(*) FROM Messages "
|
|
||||||
"WHERE feed = :feed AND is_deleted = 0 AND is_pdeleted = 0 AND is_read = 0 AND account_id = :account_id;");
|
|
||||||
query_all.bindValue(QSL(":feed"), customId());
|
|
||||||
query_all.bindValue(QSL(":account_id"), serviceRoot()->accountId());
|
|
||||||
|
|
||||||
// Obtain count of unread messages.
|
|
||||||
if (query_all.exec() && query_all.next()) {
|
|
||||||
int new_unread_count = query_all.value(0).toInt();
|
|
||||||
|
|
||||||
if (status() == NewMessages && new_unread_count < countOfUnreadMessages()) {
|
|
||||||
setStatus(Normal);
|
|
||||||
}
|
|
||||||
|
|
||||||
setCountOfUnreadMessages(new_unread_count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TtRssFeed::canBeEdited() const {
|
bool TtRssFeed::canBeEdited() const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,6 @@ class TtRssFeed : public Feed {
|
|||||||
int messageForeignKeyId() const;
|
int messageForeignKeyId() const;
|
||||||
TtRssServiceRoot *serviceRoot() const;
|
TtRssServiceRoot *serviceRoot() const;
|
||||||
QVariant data(int column, int role) const;
|
QVariant data(int column, int role) const;
|
||||||
void updateCounts(bool including_total_count);
|
|
||||||
bool canBeEdited() const;
|
bool canBeEdited() const;
|
||||||
bool editViaGui();
|
bool editViaGui();
|
||||||
bool canBeDeleted() const;
|
bool canBeDeleted() const;
|
||||||
|
@ -319,50 +319,6 @@ 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.
|
||||||
|
@ -59,7 +59,6 @@ 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