Work on loading feeds.
This commit is contained in:
parent
2360b4ba9d
commit
25fa981a91
1708
rssguard.pro
1708
rssguard.pro
File diff suppressed because it is too large
Load Diff
@ -22,6 +22,7 @@
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
#include "miscellaneous/textfactory.h"
|
||||
#include "services/abstract/category.h"
|
||||
#include "services/inoreader/inoreaderfeed.h"
|
||||
#include "services/inoreader/inoreaderserviceroot.h"
|
||||
#include "services/inoreader/network/inoreadernetworkfactory.h"
|
||||
#include "services/owncloud/definitions.h"
|
||||
@ -1482,6 +1483,37 @@ Assignment DatabaseQueries::getCategories(QSqlDatabase db, int account_id, bool*
|
||||
return categories;
|
||||
}
|
||||
|
||||
Assignment DatabaseQueries::getInoreaderFeeds(QSqlDatabase db, int account_id, bool* ok) {
|
||||
Assignment feeds;
|
||||
QSqlQuery q(db);
|
||||
|
||||
q.setForwardOnly(true);
|
||||
q.prepare(QSL("SELECT * FROM Feeds WHERE account_id = :account_id;"));
|
||||
q.bindValue(QSL(":account_id"), account_id);
|
||||
|
||||
if (!q.exec()) {
|
||||
qFatal("Inoreader: Query for obtaining feeds failed. Error message: '%s'.", qPrintable(q.lastError().text()));
|
||||
|
||||
if (ok != nullptr) {
|
||||
*ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
while (q.next()) {
|
||||
AssignmentItem pair;
|
||||
|
||||
pair.first = q.value(FDS_DB_CATEGORY_INDEX).toInt();
|
||||
pair.second = new InoreaderFeed(q.record());
|
||||
feeds << pair;
|
||||
}
|
||||
|
||||
if (ok != nullptr) {
|
||||
*ok = true;
|
||||
}
|
||||
|
||||
return feeds;
|
||||
}
|
||||
|
||||
QList<ServiceRoot*> DatabaseQueries::getInoreaderAccounts(QSqlDatabase db, bool* ok) {
|
||||
QSqlQuery query(db);
|
||||
|
||||
|
@ -79,6 +79,7 @@ class DatabaseQueries {
|
||||
static Assignment getCategories(QSqlDatabase db, int account_id, bool* ok = nullptr);
|
||||
|
||||
// Inoreader account.
|
||||
static Assignment getInoreaderFeeds(QSqlDatabase db, int account_id, bool* ok = nullptr);
|
||||
static QList<ServiceRoot*> getInoreaderAccounts(QSqlDatabase db, bool* ok = nullptr);
|
||||
static bool overwriteInoreaderAccount(QSqlDatabase db, const QString& username, const QString& access_token,
|
||||
const QString& refresh_token, int batch_size, int account_id);
|
||||
|
43
src/services/inoreader/inoreaderfeed.cpp
Normal file
43
src/services/inoreader/inoreaderfeed.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
// This file is part of RSS Guard.
|
||||
|
||||
//
|
||||
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
|
||||
//
|
||||
// RSS Guard is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// RSS Guard is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "services/inoreader/inoreaderfeed.h"
|
||||
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
#include "services/inoreader/inoreaderserviceroot.h"
|
||||
|
||||
InoreaderFeed::InoreaderFeed(RootItem* parent) : Feed(parent) {}
|
||||
|
||||
InoreaderFeed::InoreaderFeed(const QSqlRecord& record) : InoreaderFeed(nullptr) {
|
||||
setTitle(record.value(FDS_DB_TITLE_INDEX).toString());
|
||||
setId(record.value(FDS_DB_ID_INDEX).toInt());
|
||||
setCustomId(record.value(FDS_DB_CUSTOM_ID_INDEX).toString());
|
||||
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());
|
||||
qDebug("Custom ID of Inoreader feed when loading from DB is '%s'.", qPrintable(customId()));
|
||||
}
|
||||
|
||||
InoreaderServiceRoot* InoreaderFeed::serviceRoot() const {
|
||||
return qobject_cast<InoreaderServiceRoot*>(getParentServiceRoot());
|
||||
}
|
||||
|
||||
QList<Message> InoreaderFeed::obtainNewMessages(bool* error_during_obtaining) {
|
||||
return QList<Message>();
|
||||
}
|
37
src/services/inoreader/inoreaderfeed.h
Normal file
37
src/services/inoreader/inoreaderfeed.h
Normal file
@ -0,0 +1,37 @@
|
||||
// This file is part of RSS Guard.
|
||||
|
||||
//
|
||||
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
|
||||
//
|
||||
// RSS Guard is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// RSS Guard is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef INOREADERFEED_H
|
||||
#define INOREADERFEED_H
|
||||
|
||||
#include "services/abstract/feed.h"
|
||||
|
||||
class InoreaderServiceRoot;
|
||||
|
||||
class InoreaderFeed : public Feed {
|
||||
public:
|
||||
explicit InoreaderFeed(RootItem* parent = nullptr);
|
||||
explicit InoreaderFeed(const QSqlRecord& record);
|
||||
|
||||
InoreaderServiceRoot* serviceRoot() const;
|
||||
|
||||
private:
|
||||
QList<Message> obtainNewMessages(bool* error_during_obtaining);
|
||||
};
|
||||
|
||||
#endif // INOREADERFEED_H
|
@ -44,6 +44,20 @@ void InoreaderServiceRoot::updateTitle() {
|
||||
setTitle(m_network->userName() + QSL(" (Inoreader)"));
|
||||
}
|
||||
|
||||
void InoreaderServiceRoot::loadFromDatabase() {
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
Assignment categories = DatabaseQueries::getCategories(database, accountId());
|
||||
Assignment feeds = DatabaseQueries::getInoreaderFeeds(database, accountId());
|
||||
|
||||
// All data are now obtained, lets create the hierarchy.
|
||||
assembleCategories(categories);
|
||||
assembleFeeds(feeds);
|
||||
|
||||
// As the last item, add recycle bin, which is needed.
|
||||
appendChild(recycleBin());
|
||||
updateCounts(true);
|
||||
}
|
||||
|
||||
void InoreaderServiceRoot::saveAccountDataToDatabase() {
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
|
||||
@ -93,7 +107,8 @@ bool InoreaderServiceRoot::supportsCategoryAdding() const {
|
||||
void InoreaderServiceRoot::start(bool freshly_activated) {
|
||||
Q_UNUSED(freshly_activated)
|
||||
|
||||
//loadFromDatabase();
|
||||
loadFromDatabase();
|
||||
|
||||
//loadCacheFromFile(accountId());
|
||||
|
||||
m_network->logInIfNeeded();
|
||||
|
@ -51,7 +51,8 @@ class InoreaderServiceRoot : public ServiceRoot {
|
||||
void addNewCategory();
|
||||
void updateTitle();
|
||||
|
||||
protected:
|
||||
private:
|
||||
void loadFromDatabase();
|
||||
QList<QAction*> serviceMenu();
|
||||
|
||||
private:
|
||||
|
@ -179,8 +179,7 @@ RootItem* InoreaderNetworkFactory::feedsCategories(bool obtain_icons) {
|
||||
|
||||
if (NetworkFactory::performNetworkOperation(icon_url, DOWNLOAD_TIMEOUT,
|
||||
QByteArray(), QString(), icon_data,
|
||||
QNetworkAccessManager::GetOperation).first ==
|
||||
QNetworkReply::NoError) {
|
||||
QNetworkAccessManager::GetOperation).first == QNetworkReply::NoError) {
|
||||
// Icon downloaded, set it up.
|
||||
QPixmap icon_pixmap;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user