General work, will refactore some methods probably now.

This commit is contained in:
Martin Rotter 2015-12-11 07:21:49 +01:00
parent 85ca65bc39
commit 43b1aaa1a4
7 changed files with 24 additions and 17 deletions

View File

@ -32,7 +32,7 @@ namespace RootItemKind {
// Describes the kind of the item.
enum Kind {
Root = 1,
Bin = 2,
Bin = 2,
Feed = 4,
Category = 8,
ServiceRoot = 16
@ -50,21 +50,20 @@ class RootItem : public QObject {
Q_OBJECT
public:
// Holds statuses for feeds/messages
// to be marked read/unread.
enum ReadStatus {
Unread = 0,
Read = 1
};
// Holds statuses for messages
// to be switched importance (starred).
enum Importance {
NotImportant = 0,
Important = 1
};
enum CleanStatus {
Clean,
Unclean
};
// Constructors and destructors.
explicit RootItem(RootItem *parent_item = NULL);
virtual ~RootItem();
@ -104,7 +103,7 @@ class RootItem : public QObject {
// What "clean" means? It means delete messages -> move them to recycle bin
// or eventually remove them completely if there is no recycle bin functionality.
// If this method is called on "recycle bin" instance of your
// service account, it should NOT do anything.
// service account, it should "empty" the recycle bin.
virtual bool cleanMessages(bool clear_only_read);
// Updates counts of all/unread messages for this feed.

View File

@ -202,7 +202,7 @@ void FeedMessageViewer::updateFeedButtonsAvailability() {
form_main->m_ui->m_actionBackupDatabaseSettings->setEnabled(!critical_action_running);
form_main->m_ui->m_actionCleanupDatabase->setEnabled(!critical_action_running);
form_main->m_ui->m_actionClearSelectedItems->setEnabled(feed_selected || category_selected || service_selected);
form_main->m_ui->m_actionClearSelectedItems->setEnabled(anything_selected);
form_main->m_ui->m_actionDeleteSelectedItem->setEnabled(!critical_action_running && anything_selected);
form_main->m_ui->m_actionEditSelectedItem->setEnabled(!critical_action_running && anything_selected);
form_main->m_ui->m_actionMarkSelectedItemsAsRead->setEnabled(anything_selected);
@ -210,7 +210,7 @@ void FeedMessageViewer::updateFeedButtonsAvailability() {
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_actionExpandCollapseItem->setEnabled(feed_selected || category_selected || service_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);
}

View File

@ -127,7 +127,7 @@ bool RecycleBin::markAsReadUnread(RootItem::ReadStatus status) {
}
}
bool RecycleBin::empty() {
bool RecycleBin::cleanMessages(bool clear_only_read) {
QSqlDatabase db_handle = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
if (!db_handle.transaction()) {
@ -139,7 +139,15 @@ bool RecycleBin::empty() {
QSqlQuery query_empty_bin(db_handle);
query_empty_bin.setForwardOnly(true);
query_empty_bin.prepare(QSL("UPDATE Messages SET is_pdeleted = 1 WHERE is_deleted = 1 AND account_id = :account_id;"));
if (clear_only_read) {
query_empty_bin.prepare("UPDATE Messages SET is_pdeleted = 1 "
"WHERE is_read = 1 AND is_deleted = 1 AND account_id = :account_id;");
}
else {
query_empty_bin.prepare(QSL("UPDATE Messages SET is_pdeleted = 1 WHERE is_deleted = 1 AND account_id = :account_id;"));
}
query_empty_bin.bindValue(QSL(":account_id"), parent_root->accountId());
if (!query_empty_bin.exec()) {
@ -161,6 +169,10 @@ bool RecycleBin::empty() {
}
}
bool RecycleBin::empty() {
return cleanMessages(false);
}
bool RecycleBin::restore() {
QSqlDatabase db_handle = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);

View File

@ -31,6 +31,8 @@ class RecycleBin : public RootItem {
QVariant data(int column, int role) const;
bool markAsReadUnread(ReadStatus status);
bool cleanMessages(bool clear_only_read);
int countOfUnreadMessages() const;
int countOfAllMessages() const;

View File

@ -133,4 +133,3 @@ void ServiceRoot::assembleCategories(Assignment categories) {
}
}
}

View File

@ -351,7 +351,6 @@ RootItem *TtRssGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons, QS
}
}
// TODO: stahnout a nastavit ikonu
feed->setTitle(item["name"].toString());
feed->setCustomId(item_id);
act_parent->appendChild(feed);

View File

@ -268,8 +268,6 @@ void TtRssServiceRoot::saveAccountDataToDatabase() {
}
void TtRssServiceRoot::loadFromDatabase() {
// TODO: Load feeds/categories from DB.
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
Assignment categories;
Assignment feeds;
@ -444,7 +442,6 @@ void TtRssServiceRoot::storeNewFeedTree(RootItem *root) {
child->setId(query_category.lastInsertId().toInt());
}
else {
// TODO: logovat
}
}
else if (child->kind() == RootItemKind::Feed) {
@ -463,7 +460,6 @@ void TtRssServiceRoot::storeNewFeedTree(RootItem *root) {
feed->setId(query_feed.lastInsertId().toInt());
}
else {
// TODO: logovat.
}
}
}