Undeleted messages refactoring.
This commit is contained in:
parent
562ea97ffa
commit
c40961ccba
@ -209,7 +209,7 @@ void FeedMessageViewer::updateFeedButtonsAvailability() {
|
||||
form_main->m_ui->m_actionMarkSelectedItemsAsUnread->setEnabled(anything_selected);
|
||||
form_main->m_ui->m_actionUpdateAllItems->setEnabled(!critical_action_running);
|
||||
form_main->m_ui->m_actionUpdateSelectedItems->setEnabled(!critical_action_running && (feed_selected || category_selected || service_selected));
|
||||
form_main->m_ui->m_actionViewSelectedItemsNewspaperMode->setEnabled(feed_selected || category_selected || service_selected);
|
||||
form_main->m_ui->m_actionViewSelectedItemsNewspaperMode->setEnabled(anything_selected);
|
||||
form_main->m_ui->m_actionExpandCollapseItem->setEnabled(anything_selected);
|
||||
form_main->m_ui->m_menuAddItem->setEnabled(!critical_action_running);
|
||||
form_main->m_ui->m_menuRecycleBin->setEnabled(!critical_action_running);
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
#include "miscellaneous/textfactory.h"
|
||||
#include "services/abstract/serviceroot.h"
|
||||
|
||||
#include <QSqlQuery>
|
||||
@ -85,6 +86,42 @@ QVariant RecycleBin::data(int column, int role) const {
|
||||
}
|
||||
}
|
||||
|
||||
QList<Message> RecycleBin::undeletedMessages() const {
|
||||
QList<Message> messages;
|
||||
int account_id = const_cast<RecycleBin*>(this)->getParentServiceRoot()->accountId();
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
QSqlQuery query_read_msg(database);
|
||||
|
||||
query_read_msg.setForwardOnly(true);
|
||||
query_read_msg.prepare("SELECT title, url, author, date_created, contents, enclosures, custom_id, id, feed "
|
||||
"FROM Messages "
|
||||
"WHERE is_deleted = 1 AND is_pdeleted = 0 AND account_id = :account_id;");
|
||||
query_read_msg.bindValue(QSL(":account_id"), account_id);
|
||||
|
||||
// FIXME: Fix those const functions, this is fucking ugly.
|
||||
|
||||
if (query_read_msg.exec()) {
|
||||
while (query_read_msg.next()) {
|
||||
Message message;
|
||||
|
||||
message.m_feedId = query_read_msg.value(7).toString();
|
||||
message.m_title = query_read_msg.value(0).toString();
|
||||
message.m_url = query_read_msg.value(1).toString();
|
||||
message.m_author = query_read_msg.value(2).toString();
|
||||
message.m_created = TextFactory::parseDateTime(query_read_msg.value(3).value<qint64>());
|
||||
message.m_contents = query_read_msg.value(4).toString();
|
||||
message.m_enclosures = Enclosures::decodeEnclosuresFromString(query_read_msg.value(5).toString());
|
||||
message.m_accountId = account_id;
|
||||
message.m_customId = query_read_msg.value(6).toString();
|
||||
message.m_id = query_read_msg.value(7).toInt();
|
||||
|
||||
messages.append(message);
|
||||
}
|
||||
}
|
||||
|
||||
return messages;
|
||||
}
|
||||
|
||||
bool RecycleBin::markAsReadUnread(RootItem::ReadStatus status) {
|
||||
QSqlDatabase db_handle = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
|
||||
|
@ -30,6 +30,8 @@ class RecycleBin : public RootItem {
|
||||
|
||||
QVariant data(int column, int role) const;
|
||||
|
||||
QList<Message> undeletedMessages() const;
|
||||
|
||||
bool markAsReadUnread(ReadStatus status);
|
||||
bool cleanMessages(bool clear_only_read);
|
||||
|
||||
|
@ -73,7 +73,13 @@ bool RootItem::markAsReadUnread(ReadStatus status) {
|
||||
}
|
||||
|
||||
QList<Message> RootItem::undeletedMessages() const {
|
||||
return QList<Message>();
|
||||
QList<Message> messages;
|
||||
|
||||
foreach (RootItem *child, m_childItems) {
|
||||
messages.append(child->undeletedMessages());
|
||||
}
|
||||
|
||||
return messages;
|
||||
}
|
||||
|
||||
bool RootItem::cleanMessages(bool clear_only_read) {
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "core/feedsmodel.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/textfactory.h"
|
||||
#include "services/abstract/category.h"
|
||||
|
||||
#include <QSqlQuery>
|
||||
@ -59,6 +60,46 @@ bool ServiceRoot::deleteViaGui() {
|
||||
return data_removed;
|
||||
}
|
||||
|
||||
QList<Message> ServiceRoot::undeletedMessages() const {
|
||||
QList<Message> messages;
|
||||
int account_id = accountId();
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
QSqlQuery query_read_msg(database);
|
||||
|
||||
query_read_msg.setForwardOnly(true);
|
||||
query_read_msg.prepare("SELECT title, url, author, date_created, contents, enclosures, custom_id, id, feed "
|
||||
"FROM Messages "
|
||||
"WHERE is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;");
|
||||
query_read_msg.bindValue(QSL(":account_id"), account_id);
|
||||
|
||||
// FIXME: Fix those const functions, this is fucking ugly.
|
||||
|
||||
if (query_read_msg.exec()) {
|
||||
while (query_read_msg.next()) {
|
||||
Message message;
|
||||
|
||||
// TODO: napsat funkci static Message Message::fromSqlRecord(const QSqlRecord &record)
|
||||
// ta prostě bude brat record z SELECT * FROM Messages WHERE ....;
|
||||
// a vrati ho jako objekt Message;
|
||||
|
||||
message.m_feedId = query_read_msg.value(7).toString();
|
||||
message.m_title = query_read_msg.value(0).toString();
|
||||
message.m_url = query_read_msg.value(1).toString();
|
||||
message.m_author = query_read_msg.value(2).toString();
|
||||
message.m_created = TextFactory::parseDateTime(query_read_msg.value(3).value<qint64>());
|
||||
message.m_contents = query_read_msg.value(4).toString();
|
||||
message.m_enclosures = Enclosures::decodeEnclosuresFromString(query_read_msg.value(5).toString());
|
||||
message.m_accountId = account_id;
|
||||
message.m_customId = query_read_msg.value(6).toString();
|
||||
message.m_id = query_read_msg.value(7).toInt();
|
||||
|
||||
messages.append(message);
|
||||
}
|
||||
}
|
||||
|
||||
return messages;
|
||||
}
|
||||
|
||||
void ServiceRoot::itemChanged(const QList<RootItem *> &items) {
|
||||
emit dataChanged(items);
|
||||
}
|
||||
|
@ -66,6 +66,8 @@ class ServiceRoot : public RootItem {
|
||||
// Access to recycle bin of this account if there is any.
|
||||
virtual RecycleBin *recycleBin() = 0;
|
||||
|
||||
QList<Message> undeletedMessages() const;
|
||||
|
||||
// Start/stop services.
|
||||
// Start method is called when feed model gets initialized OR after user adds new service.
|
||||
// Account should synchronously initialize its children (load them from DB is recommended
|
||||
|
@ -120,7 +120,7 @@ QList<Message> TtRssFeed::undeletedMessages() const {
|
||||
query_read_msg.setForwardOnly(true);
|
||||
query_read_msg.prepare("SELECT title, url, author, date_created, contents, enclosures, custom_id, id "
|
||||
"FROM Messages "
|
||||
"WHERE is_deleted = 0 AND feed = :feed AND account_id = :account_id;");
|
||||
"WHERE is_deleted = 0 AND is_pdeleted = 0 AND feed = :feed AND account_id = :account_id;");
|
||||
|
||||
query_read_msg.bindValue(QSL(":feed"), customId());
|
||||
query_read_msg.bindValue(QSL(":account_id"), account_id);
|
||||
|
Loading…
x
Reference in New Issue
Block a user