diff --git a/src/gui/dialogs/formmain.cpp b/src/gui/dialogs/formmain.cpp index fc7d85e3d..a638f7ed2 100755 --- a/src/gui/dialogs/formmain.cpp +++ b/src/gui/dialogs/formmain.cpp @@ -85,20 +85,6 @@ FormMain::FormMain(QWidget *parent, Qt::WindowFlags f) // Initialize the web factory. WebFactory::instance()->loadState(); - - - - OwnCloudNetworkFactory fac; - - fac.setUrl("https://cloud.yarpen.cz"); - fac.setAuthPassword("rssguard135"); - fac.setAuthUsername("rssguard"); - - OwnCloudStatusResponse user = fac.status(); - - QString ver = user.version(); - - int aaaa = 0; } FormMain::~FormMain() { diff --git a/src/services/owncloud/network/owncloudnetworkfactory.cpp b/src/services/owncloud/network/owncloudnetworkfactory.cpp index 09b3b65ee..bd7cb0b2a 100755 --- a/src/services/owncloud/network/owncloudnetworkfactory.cpp +++ b/src/services/owncloud/network/owncloudnetworkfactory.cpp @@ -21,6 +21,9 @@ #include "network-web/networkfactory.h" #include "miscellaneous/application.h" #include "miscellaneous/settings.h" +#include "services/abstract/rootitem.h" +#include "services/owncloud/owncloudcategory.h" +#include "services/owncloud/owncloudfeed.h" #include @@ -179,7 +182,6 @@ QString OwnCloudResponse::toString() const { return QtJson::serializeStr(m_rawContent); } - OwnCloudUserResponse::OwnCloudUserResponse(const QString &raw_content) : OwnCloudResponse(raw_content) { } @@ -255,13 +257,58 @@ bool OwnCloudStatusResponse::misconfiguredCron() const { OwnCloudGetFeedsCategoriesResponse::OwnCloudGetFeedsCategoriesResponse(const QString &raw_categories, const QString &raw_feeds) - : m_contentCategories(QString()), m_contentFeeds(QString()) { + : m_contentCategories(raw_categories), m_contentFeeds(raw_feeds) { } OwnCloudGetFeedsCategoriesResponse::~OwnCloudGetFeedsCategoriesResponse() { } RootItem *OwnCloudGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons) const { - // TODO: TODO - return NULL; + RootItem *parent = new RootItem(); + QMap cats; + + cats.insert(0, parent); + + // Process categories first, then process feeds. + foreach (QVariant cat, QtJson::parse(m_contentCategories).toMap()["folders"].toList()) { + QMap item = cat.toMap(); + OwnCloudCategory *category = new OwnCloudCategory(); + + category->setTitle(item["name"].toString()); + category->setCustomId(item["id"].toInt()); + + cats.insert(category->customId(), category); + + // All categories in ownCloud are top-level. + parent->appendChild(category); + } + + // We have categories added, now add all feeds. + foreach (QVariant fed, QtJson::parse(m_contentFeeds).toMap()["feeds"].toList()) { + QMap item = fed.toMap(); + OwnCloudFeed *feed = new OwnCloudFeed(); + + if (obtain_icons) { + QString icon_path = item["faviconLink"].toString(); + + if (!icon_path.isEmpty()) { + QByteArray icon_data; + + if (NetworkFactory::downloadFile(icon_path, DOWNLOAD_TIMEOUT, icon_data).first == QNetworkReply::NoError) { + // Icon downloaded, set it up. + QPixmap icon_pixmap; + icon_pixmap.loadFromData(icon_data); + feed->setIcon(QIcon(icon_pixmap)); + } + } + } + + feed->setUrl(item["link"].toString()); + feed->setTitle(item["title"].toString()); + feed->setCustomId(item["id"].toInt()); + + cats.value(item["folderId"].toInt())->appendChild(feed); + } + + return parent; } diff --git a/src/services/owncloud/owncloudcategory.cpp b/src/services/owncloud/owncloudcategory.cpp index de718e6c7..47306abed 100755 --- a/src/services/owncloud/owncloudcategory.cpp +++ b/src/services/owncloud/owncloudcategory.cpp @@ -21,10 +21,10 @@ #include "miscellaneous/iconfactory.h" -OwnCloudServiceCategory::OwnCloudServiceCategory(RootItem *parent) : Category(parent) { +OwnCloudCategory::OwnCloudCategory(RootItem *parent) : Category(parent) { // Categories in ownCloud have now icons etc. They just have titles. setIcon(qApp->icons()->fromTheme(QSL("folder-category"))); } -OwnCloudServiceCategory::~OwnCloudServiceCategory() { +OwnCloudCategory::~OwnCloudCategory() { } diff --git a/src/services/owncloud/owncloudcategory.h b/src/services/owncloud/owncloudcategory.h index 24062d3f7..6bbbbb3c5 100755 --- a/src/services/owncloud/owncloudcategory.h +++ b/src/services/owncloud/owncloudcategory.h @@ -21,10 +21,10 @@ #include "services/abstract/category.h" -class OwnCloudServiceCategory : public Category { +class OwnCloudCategory : public Category { public: - explicit OwnCloudServiceCategory(RootItem *parent = NULL); - virtual ~OwnCloudServiceCategory(); + explicit OwnCloudCategory(RootItem *parent = NULL); + virtual ~OwnCloudCategory(); }; #endif // OWNCLOUDSERVICECATEGORY_H diff --git a/src/services/owncloud/owncloudfeed.cpp b/src/services/owncloud/owncloudfeed.cpp index b335a2ee9..2a26a047e 100755 --- a/src/services/owncloud/owncloudfeed.cpp +++ b/src/services/owncloud/owncloudfeed.cpp @@ -23,3 +23,12 @@ OwnCloudFeed::OwnCloudFeed(RootItem *parent) : Feed(parent) { OwnCloudFeed::~OwnCloudFeed() { } + +int OwnCloudFeed::update() { + // TODO: TODO + return 0; +} + +int OwnCloudFeed::messageForeignKeyId() const { + return customId(); +} diff --git a/src/services/owncloud/owncloudfeed.h b/src/services/owncloud/owncloudfeed.h index c9a9be186..6375cda85 100755 --- a/src/services/owncloud/owncloudfeed.h +++ b/src/services/owncloud/owncloudfeed.h @@ -25,6 +25,9 @@ class OwnCloudFeed : public Feed { public: explicit OwnCloudFeed(RootItem *parent = NULL); virtual ~OwnCloudFeed(); + + int update(); + int messageForeignKeyId() const; }; #endif // OWNCLOUDFEED_H diff --git a/src/services/owncloud/owncloudserviceroot.cpp b/src/services/owncloud/owncloudserviceroot.cpp index 25989d532..f4fa9439e 100755 --- a/src/services/owncloud/owncloudserviceroot.cpp +++ b/src/services/owncloud/owncloudserviceroot.cpp @@ -31,7 +31,8 @@ OwnCloudServiceRoot::OwnCloudServiceRoot(RootItem *parent) - : ServiceRoot(parent), m_recycleBin(new OwnCloudRecycleBin(this)), m_network(new OwnCloudNetworkFactory()) { + : ServiceRoot(parent), m_recycleBin(new OwnCloudRecycleBin(this)), + m_actionSyncIn(NULL), m_serviceMenu(QList()), m_network(new OwnCloudNetworkFactory()) { setIcon(OwnCloudServiceEntryPoint().icon()); } @@ -65,24 +66,23 @@ bool OwnCloudServiceRoot::supportsCategoryAdding() const { return false; } -QList OwnCloudServiceRoot::addItemMenu() { - // TODO: TODO - return QList(); -} - QList OwnCloudServiceRoot::serviceMenu() { - // TODO: TODO - return QList(); + if (m_serviceMenu.isEmpty()) { + m_actionSyncIn = new QAction(qApp->icons()->fromTheme(QSL("item-sync")), tr("Sync in"), this); + + connect(m_actionSyncIn, SIGNAL(triggered()), this, SLOT(syncIn())); + m_serviceMenu.append(m_actionSyncIn); + } + + return m_serviceMenu; } RecycleBin *OwnCloudServiceRoot::recycleBin() const { - // TODO: TODO - return NULL; + return m_recycleBin; } void OwnCloudServiceRoot::start(bool freshly_activated) { - // TODO: TODO - //loadFromDatabase(); + loadFromDatabase(); if (childCount() == 1 && child(0)->kind() == RootItemKind::Bin) { syncIn(); @@ -244,3 +244,9 @@ void OwnCloudServiceRoot::syncIn() { setIcon(original_icon); itemChanged(QList() << this); } + +void OwnCloudServiceRoot::loadFromDatabase() { + // As the last item, add recycle bin, which is needed. + appendChild(m_recycleBin); + m_recycleBin->updateCounts(true); +} diff --git a/src/services/owncloud/owncloudserviceroot.h b/src/services/owncloud/owncloudserviceroot.h index fa81d073f..59e263eed 100755 --- a/src/services/owncloud/owncloudserviceroot.h +++ b/src/services/owncloud/owncloudserviceroot.h @@ -38,8 +38,6 @@ class OwnCloudServiceRoot : public ServiceRoot { bool supportsFeedAdding() const; bool supportsCategoryAdding() const; - - QList addItemMenu(); QList serviceMenu(); RecycleBin *recycleBin() const; @@ -62,7 +60,11 @@ class OwnCloudServiceRoot : public ServiceRoot { void syncIn(); private: + void loadFromDatabase(); + OwnCloudRecycleBin *m_recycleBin; + QAction *m_actionSyncIn; + QList m_serviceMenu; OwnCloudNetworkFactory *m_network; };