Working loading of stored OC contents from DB.
This commit is contained in:
parent
f9f461d1a3
commit
e98172afaa
@ -26,5 +26,12 @@ OwnCloudCategory::OwnCloudCategory(RootItem *parent) : Category(parent) {
|
|||||||
setIcon(qApp->icons()->fromTheme(QSL("folder-category")));
|
setIcon(qApp->icons()->fromTheme(QSL("folder-category")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OwnCloudCategory::OwnCloudCategory(const QSqlRecord &record) : Category(NULL) {
|
||||||
|
setIcon(qApp->icons()->fromTheme(QSL("folder-category")));
|
||||||
|
setId(record.value(CAT_DB_ID_INDEX).toInt());
|
||||||
|
setTitle(record.value(CAT_DB_TITLE_INDEX).toString());
|
||||||
|
setCustomId(record.value(CAT_DB_CUSTOM_ID_INDEX).toInt());
|
||||||
|
}
|
||||||
|
|
||||||
OwnCloudCategory::~OwnCloudCategory() {
|
OwnCloudCategory::~OwnCloudCategory() {
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
class OwnCloudCategory : public Category {
|
class OwnCloudCategory : public Category {
|
||||||
public:
|
public:
|
||||||
explicit OwnCloudCategory(RootItem *parent = NULL);
|
explicit OwnCloudCategory(RootItem *parent = NULL);
|
||||||
|
explicit OwnCloudCategory(const QSqlRecord &record);
|
||||||
virtual ~OwnCloudCategory();
|
virtual ~OwnCloudCategory();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -17,10 +17,21 @@
|
|||||||
|
|
||||||
#include "owncloudfeed.h"
|
#include "owncloudfeed.h"
|
||||||
|
|
||||||
|
#include "miscellaneous/iconfactory.h"
|
||||||
|
|
||||||
|
|
||||||
OwnCloudFeed::OwnCloudFeed(RootItem *parent) : Feed(parent) {
|
OwnCloudFeed::OwnCloudFeed(RootItem *parent) : Feed(parent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OwnCloudFeed::OwnCloudFeed(const QSqlRecord &record) : Feed(NULL) {
|
||||||
|
setTitle(record.value(FDS_DB_TITLE_INDEX).toString());
|
||||||
|
setId(record.value(FDS_DB_ID_INDEX).toInt());
|
||||||
|
setIcon(qApp->icons()->fromByteArray(record.value(FDS_DB_ICON_INDEX).toByteArray()));
|
||||||
|
setAutoUpdateType(static_cast<Feed::AutoUpdateType>(record.value(FDS_DB_UPDATE_TYPE_INDEX).toInt()));
|
||||||
|
setAutoUpdateInitialInterval(record.value(FDS_DB_UPDATE_INTERVAL_INDEX).toInt());
|
||||||
|
setCustomId(record.value(FDS_DB_CUSTOM_ID_INDEX).toInt());
|
||||||
|
}
|
||||||
|
|
||||||
OwnCloudFeed::~OwnCloudFeed() {
|
OwnCloudFeed::~OwnCloudFeed() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
class OwnCloudFeed : public Feed {
|
class OwnCloudFeed : public Feed {
|
||||||
public:
|
public:
|
||||||
explicit OwnCloudFeed(RootItem *parent = NULL);
|
explicit OwnCloudFeed(RootItem *parent = NULL);
|
||||||
|
explicit OwnCloudFeed(const QSqlRecord &record);
|
||||||
virtual ~OwnCloudFeed();
|
virtual ~OwnCloudFeed();
|
||||||
|
|
||||||
int update();
|
int update();
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
#include "services/owncloud/owncloudrecyclebin.h"
|
#include "services/owncloud/owncloudrecyclebin.h"
|
||||||
|
|
||||||
|
#include "services/owncloud/owncloudserviceroot.h"
|
||||||
|
|
||||||
|
|
||||||
OwnCloudRecycleBin::OwnCloudRecycleBin(RootItem *parent) : RecycleBin(parent) {
|
OwnCloudRecycleBin::OwnCloudRecycleBin(RootItem *parent) : RecycleBin(parent) {
|
||||||
}
|
}
|
||||||
@ -24,6 +26,10 @@ OwnCloudRecycleBin::OwnCloudRecycleBin(RootItem *parent) : RecycleBin(parent) {
|
|||||||
OwnCloudRecycleBin::~OwnCloudRecycleBin() {
|
OwnCloudRecycleBin::~OwnCloudRecycleBin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OwnCloudServiceRoot *OwnCloudRecycleBin::serviceRoot() {
|
||||||
|
return qobject_cast<OwnCloudServiceRoot*>(getParentServiceRoot());
|
||||||
|
}
|
||||||
|
|
||||||
bool OwnCloudRecycleBin::markAsReadUnread(RootItem::ReadStatus status) {
|
bool OwnCloudRecycleBin::markAsReadUnread(RootItem::ReadStatus status) {
|
||||||
// TODO: proved zmenu online.
|
// TODO: proved zmenu online.
|
||||||
/*QStringList ids = serviceRoot()->customIDSOfMessagesForItem(this);
|
/*QStringList ids = serviceRoot()->customIDSOfMessagesForItem(this);
|
||||||
|
@ -21,11 +21,14 @@
|
|||||||
#include "services/abstract/recyclebin.h"
|
#include "services/abstract/recyclebin.h"
|
||||||
|
|
||||||
|
|
||||||
|
class OwnCloudServiceRoot;
|
||||||
|
|
||||||
class OwnCloudRecycleBin : public RecycleBin {
|
class OwnCloudRecycleBin : public RecycleBin {
|
||||||
public:
|
public:
|
||||||
explicit OwnCloudRecycleBin(RootItem *parent = NULL);
|
explicit OwnCloudRecycleBin(RootItem *parent = NULL);
|
||||||
virtual ~OwnCloudRecycleBin();
|
virtual ~OwnCloudRecycleBin();
|
||||||
|
|
||||||
|
OwnCloudServiceRoot *serviceRoot();
|
||||||
bool markAsReadUnread(ReadStatus status);
|
bool markAsReadUnread(ReadStatus status);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
#include "miscellaneous/iconfactory.h"
|
#include "miscellaneous/iconfactory.h"
|
||||||
#include "services/owncloud/owncloudserviceentrypoint.h"
|
#include "services/owncloud/owncloudserviceentrypoint.h"
|
||||||
#include "services/owncloud/owncloudrecyclebin.h"
|
#include "services/owncloud/owncloudrecyclebin.h"
|
||||||
|
#include "services/owncloud/owncloudfeed.h"
|
||||||
|
#include "services/owncloud/owncloudcategory.h"
|
||||||
#include "services/owncloud/network/owncloudnetworkfactory.h"
|
#include "services/owncloud/network/owncloudnetworkfactory.h"
|
||||||
|
|
||||||
#include <QSqlQuery>
|
#include <QSqlQuery>
|
||||||
@ -90,16 +92,10 @@ void OwnCloudServiceRoot::start(bool freshly_activated) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OwnCloudServiceRoot::stop() {
|
void OwnCloudServiceRoot::stop() {
|
||||||
// TODO: TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString OwnCloudServiceRoot::code() const {
|
QString OwnCloudServiceRoot::code() const {
|
||||||
return SERVICE_CODE_OWNCLOUD;
|
return OwnCloudServiceEntryPoint().code();
|
||||||
}
|
|
||||||
|
|
||||||
bool OwnCloudServiceRoot::loadMessagesForItem(RootItem *item, QSqlTableModel *model) {
|
|
||||||
// TODO: TODO
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OwnCloudNetworkFactory *OwnCloudServiceRoot::network() const {
|
OwnCloudNetworkFactory *OwnCloudServiceRoot::network() const {
|
||||||
@ -157,7 +153,7 @@ void OwnCloudServiceRoot::saveAccountDataToDatabase() {
|
|||||||
|
|
||||||
query.prepare(QSL("INSERT INTO Accounts (id, type) VALUES (:id, :type);"));
|
query.prepare(QSL("INSERT INTO Accounts (id, type) VALUES (:id, :type);"));
|
||||||
query.bindValue(QSL(":id"), id_to_assign);
|
query.bindValue(QSL(":id"), id_to_assign);
|
||||||
query.bindValue(QSL(":type"), SERVICE_CODE_OWNCLOUD);
|
query.bindValue(QSL(":type"), code());
|
||||||
|
|
||||||
saved &= query.exec();
|
saved &= query.exec();
|
||||||
|
|
||||||
@ -246,6 +242,50 @@ void OwnCloudServiceRoot::syncIn() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OwnCloudServiceRoot::loadFromDatabase() {
|
void OwnCloudServiceRoot::loadFromDatabase() {
|
||||||
|
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||||
|
Assignment categories;
|
||||||
|
Assignment feeds;
|
||||||
|
|
||||||
|
// Obtain data for categories from the database.
|
||||||
|
QSqlQuery query_categories(database);
|
||||||
|
query_categories.setForwardOnly(true);
|
||||||
|
query_categories.prepare(QSL("SELECT * FROM Categories WHERE account_id = :account_id;"));
|
||||||
|
query_categories.bindValue(QSL(":account_id"), accountId());
|
||||||
|
|
||||||
|
if (!query_categories.exec()) {
|
||||||
|
qFatal("Query for obtaining categories failed. Error message: '%s'.", qPrintable(query_categories.lastError().text()));
|
||||||
|
}
|
||||||
|
|
||||||
|
while (query_categories.next()) {
|
||||||
|
AssignmentItem pair;
|
||||||
|
pair.first = query_categories.value(CAT_DB_PARENT_ID_INDEX).toInt();
|
||||||
|
pair.second = new OwnCloudCategory(query_categories.record());
|
||||||
|
|
||||||
|
categories << pair;
|
||||||
|
}
|
||||||
|
|
||||||
|
// All categories are now loaded.
|
||||||
|
QSqlQuery query_feeds(database);
|
||||||
|
query_feeds.setForwardOnly(true);
|
||||||
|
query_feeds.prepare(QSL("SELECT * FROM Feeds WHERE account_id = :account_id;"));
|
||||||
|
query_feeds.bindValue(QSL(":account_id"), accountId());
|
||||||
|
|
||||||
|
if (!query_feeds.exec()) {
|
||||||
|
qFatal("Query for obtaining feeds failed. Error message: '%s'.", qPrintable(query_feeds.lastError().text()));
|
||||||
|
}
|
||||||
|
|
||||||
|
while (query_feeds.next()) {
|
||||||
|
AssignmentItem pair;
|
||||||
|
pair.first = query_feeds.value(FDS_DB_CATEGORY_INDEX).toInt();
|
||||||
|
pair.second = new OwnCloudFeed(query_feeds.record());
|
||||||
|
|
||||||
|
feeds << pair;
|
||||||
|
}
|
||||||
|
|
||||||
|
// All data are now obtained, lets create the hierarchy.
|
||||||
|
assembleCategories(categories);
|
||||||
|
assembleFeeds(feeds);
|
||||||
|
|
||||||
// As the last item, add recycle bin, which is needed.
|
// As the last item, add recycle bin, which is needed.
|
||||||
appendChild(m_recycleBin);
|
appendChild(m_recycleBin);
|
||||||
m_recycleBin->updateCounts(true);
|
m_recycleBin->updateCounts(true);
|
||||||
|
@ -35,19 +35,14 @@ class OwnCloudServiceRoot : public ServiceRoot {
|
|||||||
bool canBeDeleted() const;
|
bool canBeDeleted() const;
|
||||||
bool editViaGui();
|
bool editViaGui();
|
||||||
bool deleteViaGui();
|
bool deleteViaGui();
|
||||||
|
|
||||||
bool supportsFeedAdding() const;
|
bool supportsFeedAdding() const;
|
||||||
bool supportsCategoryAdding() const;
|
bool supportsCategoryAdding() const;
|
||||||
QList<QAction*> serviceMenu();
|
QList<QAction*> serviceMenu();
|
||||||
|
|
||||||
RecycleBin *recycleBin() const;
|
RecycleBin *recycleBin() const;
|
||||||
|
|
||||||
void start(bool freshly_activated);
|
void start(bool freshly_activated);
|
||||||
void stop();
|
void stop();
|
||||||
QString code() const;
|
QString code() const;
|
||||||
|
|
||||||
bool loadMessagesForItem(RootItem *item, QSqlTableModel *model);
|
|
||||||
|
|
||||||
OwnCloudNetworkFactory *network() const;
|
OwnCloudNetworkFactory *network() const;
|
||||||
|
|
||||||
void updateTitle();
|
void updateTitle();
|
||||||
|
@ -73,7 +73,7 @@ ServiceRoot *StandardServiceEntryPoint::createNewRoot() const {
|
|||||||
|
|
||||||
query.prepare(QSL("INSERT INTO Accounts (id, type) VALUES (:id, :type);"));
|
query.prepare(QSL("INSERT INTO Accounts (id, type) VALUES (:id, :type);"));
|
||||||
query.bindValue(QSL(":id"), id_to_assign);
|
query.bindValue(QSL(":id"), id_to_assign);
|
||||||
query.bindValue(QSL(":type"), SERVICE_CODE_STD_RSS);
|
query.bindValue(QSL(":type"), code());
|
||||||
|
|
||||||
if (query.exec()) {
|
if (query.exec()) {
|
||||||
StandardServiceRoot *root = new StandardServiceRoot();
|
StandardServiceRoot *root = new StandardServiceRoot();
|
||||||
@ -94,7 +94,7 @@ QList<ServiceRoot*> StandardServiceEntryPoint::initializeSubtree() const {
|
|||||||
|
|
||||||
query.setForwardOnly(true);
|
query.setForwardOnly(true);
|
||||||
query.prepare(QSL("SELECT id FROM Accounts WHERE type = :type;"));
|
query.prepare(QSL("SELECT id FROM Accounts WHERE type = :type;"));
|
||||||
query.bindValue(QSL(":type"), SERVICE_CODE_STD_RSS);
|
query.bindValue(QSL(":type"), code());
|
||||||
|
|
||||||
if (query.exec()) {
|
if (query.exec()) {
|
||||||
while (query.next()) {
|
while (query.next()) {
|
||||||
|
@ -103,7 +103,7 @@ void StandardServiceRoot::stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString StandardServiceRoot::code() const {
|
QString StandardServiceRoot::code() const {
|
||||||
return SERVICE_CODE_STD_RSS;
|
return StandardServiceEntryPoint().code();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StandardServiceRoot::canBeEdited() const {
|
bool StandardServiceRoot::canBeEdited() const {
|
||||||
|
@ -31,7 +31,6 @@ class TtRssRecycleBin : public RecycleBin {
|
|||||||
virtual ~TtRssRecycleBin();
|
virtual ~TtRssRecycleBin();
|
||||||
|
|
||||||
TtRssServiceRoot *serviceRoot();
|
TtRssServiceRoot *serviceRoot();
|
||||||
|
|
||||||
bool markAsReadUnread(ReadStatus status);
|
bool markAsReadUnread(ReadStatus status);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ void TtRssServiceRoot::stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString TtRssServiceRoot::code() const {
|
QString TtRssServiceRoot::code() const {
|
||||||
return SERVICE_CODE_TT_RSS;
|
return TtRssServiceEntryPoint().code();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TtRssServiceRoot::editViaGui() {
|
bool TtRssServiceRoot::editViaGui() {
|
||||||
@ -406,7 +406,7 @@ void TtRssServiceRoot::saveAccountDataToDatabase() {
|
|||||||
|
|
||||||
query.prepare(QSL("INSERT INTO Accounts (id, type) VALUES (:id, :type);"));
|
query.prepare(QSL("INSERT INTO Accounts (id, type) VALUES (:id, :type);"));
|
||||||
query.bindValue(QSL(":id"), id_to_assign);
|
query.bindValue(QSL(":id"), id_to_assign);
|
||||||
query.bindValue(QSL(":type"), SERVICE_CODE_TT_RSS);
|
query.bindValue(QSL(":type"), code());
|
||||||
|
|
||||||
saved &= query.exec();
|
saved &= query.exec();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user