Refactoring.

This commit is contained in:
Martin Rotter 2016-05-03 08:57:56 +02:00
parent e1742d82e1
commit 9a0e17814e
3 changed files with 17 additions and 11 deletions

View file

@ -59,10 +59,7 @@ bool OwnCloudFeed::canBeDeleted() const {
} }
bool OwnCloudFeed::deleteViaGui() { bool OwnCloudFeed::deleteViaGui() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); if (removeItself()) {
if (serviceRoot()->network()->deleteFeed(customId()) &&
DatabaseQueries::deleteFeed(database, customId(), serviceRoot()->accountId())) {
serviceRoot()->requestItemRemoval(this); serviceRoot()->requestItemRemoval(this);
return true; return true;
} }
@ -86,6 +83,14 @@ bool OwnCloudFeed::editItself(OwnCloudFeed *new_feed_data) {
} }
} }
bool OwnCloudFeed::removeItself() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
return
serviceRoot()->network()->deleteFeed(customId()) &&
DatabaseQueries::deleteFeed(database, customId(), serviceRoot()->accountId());
}
bool OwnCloudFeed::markAsReadUnread(RootItem::ReadStatus status) { bool OwnCloudFeed::markAsReadUnread(RootItem::ReadStatus status) {
QStringList ids = getParentServiceRoot()->customIDSOfMessagesForItem(this); QStringList ids = getParentServiceRoot()->customIDSOfMessagesForItem(this);
QNetworkReply::NetworkError response = serviceRoot()->network()->markMessagesRead(status, ids); QNetworkReply::NetworkError response = serviceRoot()->network()->markMessagesRead(status, ids);

View file

@ -37,6 +37,7 @@ class OwnCloudFeed : public Feed {
bool deleteViaGui(); bool deleteViaGui();
bool editItself(OwnCloudFeed *new_feed_data); bool editItself(OwnCloudFeed *new_feed_data);
bool removeItself();
bool markAsReadUnread(ReadStatus status); bool markAsReadUnread(ReadStatus status);
bool cleanMessages(bool clear_only_read); bool cleanMessages(bool clear_only_read);

View file

@ -383,8 +383,8 @@ bool StandardFeed::addItself(RootItem *parent) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
bool ok; bool ok;
int new_id = DatabaseQueries::addFeed(database, parent->id(), parent->getParentServiceRoot()->accountId(), title(), int new_id = DatabaseQueries::addFeed(database, parent->id(), parent->getParentServiceRoot()->accountId(), title(),
description(), creationDate(), icon(), encoding(), url(), passwordProtected(), description(), creationDate(), icon(), encoding(), url(), passwordProtected(),
username(), password(), autoUpdateType(), autoUpdateInitialInterval(), type(), &ok); username(), password(), autoUpdateType(), autoUpdateInitialInterval(), type(), &ok);
if (!ok) { if (!ok) {
// Query failed. // Query failed.
@ -405,11 +405,11 @@ bool StandardFeed::editItself(StandardFeed *new_feed_data) {
RootItem *new_parent = new_feed_data->parent(); RootItem *new_parent = new_feed_data->parent();
if (!DatabaseQueries::editFeed(database, new_parent->id(), original_feed->id(), new_feed_data->title(), if (!DatabaseQueries::editFeed(database, new_parent->id(), original_feed->id(), new_feed_data->title(),
new_feed_data->description(), new_feed_data->icon(), new_feed_data->description(), new_feed_data->icon(),
new_feed_data->encoding(), new_feed_data->url(), new_feed_data->passwordProtected(), new_feed_data->encoding(), new_feed_data->url(), new_feed_data->passwordProtected(),
new_feed_data->username(), new_feed_data->password(), new_feed_data->username(), new_feed_data->password(),
new_feed_data->autoUpdateType(), new_feed_data->autoUpdateInitialInterval(), new_feed_data->autoUpdateType(), new_feed_data->autoUpdateInitialInterval(),
new_feed_data->type())) { new_feed_data->type())) {
// Persistent storage update failed, no way to continue now. // Persistent storage update failed, no way to continue now.
return false; return false;
} }