Use correct qt repo.

This commit is contained in:
Martin Rotter 2017-10-03 08:44:53 +02:00
parent ec70e94c7d
commit 27faa7dfc5
10 changed files with 85 additions and 21 deletions

View File

@ -11,7 +11,7 @@ if test "$TRAVIS_OS_NAME" = "osx"; then
brew link --force curl
else
# Linux.
sudo add-apt-repository ppa:beineri/opt-qt59-trusty -y
sudo add-apt-repository ppa:beineri/opt-qt591-trusty -y
sudo apt-get update
sudo apt-get -y install qt59tools qt59base qt59webengine qt59networkauth-no-lgpl
sudo apt-get -y install qt59tools qt59base qt59webengine
fi

View File

@ -68,12 +68,13 @@ OAuth2Service::OAuth2Service(QString authUrl, QString tokenUrl, QString clientId
connect(this, &OAuth2Service::authCodeObtained, this, &OAuth2Service::retrieveAccessToken);
}
QString OAuth2Service::bearer() const {
return QString("Bearer %1").arg(m_accessToken);
}
void OAuth2Service::attachBearerHeader(QNetworkRequest& req) {
req.setRawHeader(QString("Authorization").toLocal8Bit(), bearer().toLocal8Bit());
QString OAuth2Service::bearer() {
if (login()) {
return QString("Bearer %1").arg(m_accessToken);
}
else {
return QString();
}
}
void OAuth2Service::setOAuthTokenGrantType(QString grant_type) {

View File

@ -52,9 +52,7 @@ class OAuth2Service : public QObject {
explicit OAuth2Service(QString authUrl, QString tokenUrl, QString clientId,
QString clientSecret, QString scope, QObject* parent = 0);
QString bearer() const;
void attachBearerHeader(QNetworkRequest& req);
QString bearer();
void setOAuthTokenGrantType(QString grant_type);
QString oAuthTokenGrantType();

View File

@ -74,11 +74,11 @@ void CacheForServiceRoot::addMessageStatesToCache(const QStringList& ids_of_mess
m_cacheSaveMutex->unlock();
}
void CacheForServiceRoot::saveCacheToFile(int accId) {
void CacheForServiceRoot::saveCacheToFile(int acc_id) {
m_cacheSaveMutex->lock();
// Save to file.
const QString file_cache = qApp->userDataFolder() + QDir::separator() + QString::number(accId) + "-cached-msgs.dat";
const QString file_cache = qApp->userDataFolder() + QDir::separator() + QString::number(acc_id) + "-cached-msgs.dat";
if (isEmpty()) {
QFile::remove(file_cache);
@ -105,12 +105,12 @@ void CacheForServiceRoot::clearCache() {
m_cachedStatesImportant.clear();
}
void CacheForServiceRoot::loadCacheFromFile(int accId) {
void CacheForServiceRoot::loadCacheFromFile(int acc_id) {
m_cacheSaveMutex->lock();
clearCache();
// Load from file.
const QString file_cache = qApp->userDataFolder() + QDir::separator() + QString::number(accId) + "-cached-msgs.dat";
const QString file_cache = qApp->userDataFolder() + QDir::separator() + QString::number(acc_id) + "-cached-msgs.dat";
QFile file(file_cache);
if (file.exists()) {

View File

@ -37,8 +37,10 @@ class CacheForServiceRoot {
// Persistently saves/loads cached changes to/from file.
// NOTE: The whole cache is cleared after save is done and before load is done.
void saveCacheToFile(int accId);
void loadCacheFromFile(int accId);
void saveCacheToFile(int acc_id);
void loadCacheFromFile(int acc_id);
virtual void saveAllCachedData() = 0;
protected:
QPair<QMap<RootItem::ReadStatus, QStringList>, QMap<RootItem::Importance, QList<Message>>> takeMessageCache();

View File

@ -41,5 +41,6 @@
#define INOREADER_API_FEED_CONTENTS "https://www.inoreader.com/reader/api/0/stream/contents"
#define INOREADER_API_LIST_LABELS "https://www.inoreader.com/reader/api/0/tag/list"
#define INOREADER_API_LIST_FEEDS "https://www.inoreader.com/reader/api/0/subscription/list"
#define INOREADER_API_EDIT_TAG "https://www.inoreader.com/reader/api/0/edit-tag"
#endif // INOREADER_DEFINITIONS_H

View File

@ -30,7 +30,7 @@
#include "services/inoreader/network/inoreadernetworkfactory.h"
InoreaderServiceRoot::InoreaderServiceRoot(InoreaderNetworkFactory* network, RootItem* parent) : ServiceRoot(parent),
m_serviceMenu(QList<QAction*>()), m_network(network) {
CacheForServiceRoot(), m_serviceMenu(QList<QAction*>()), m_network(network) {
if (network == nullptr) {
m_network = new InoreaderNetworkFactory(this);
}
@ -121,6 +121,11 @@ void InoreaderServiceRoot::start(bool freshly_activated) {
loadFromDatabase();
m_network->oauth()->login();
loadCacheFromFile(accountId());
if (childCount() <= 1) {
syncIn();
}
}
void InoreaderServiceRoot::stop() {}
@ -149,3 +154,39 @@ void InoreaderServiceRoot::addNewFeed(const QString& url) {
}
void InoreaderServiceRoot::addNewCategory() {}
void InoreaderServiceRoot::saveAllCachedData() {
QPair<QMap<RootItem::ReadStatus, QStringList>, QMap<RootItem::Importance, QList<Message>>> msgCache = takeMessageCache();
QMapIterator<RootItem::ReadStatus, QStringList> i(msgCache.first);
// Save the actual data read/unread.
while (i.hasNext()) {
i.next();
auto key = i.key();
QStringList ids = i.value();
if (!ids.isEmpty()) {
network()->markMessagesRead(key, ids);
}
}
QMapIterator<RootItem::Importance, QList<Message>> j(msgCache.second);
// Save the actual data important/not important.
while (j.hasNext()) {
j.next();
auto key = j.key();
QList<Message> messages = j.value();
if (!messages.isEmpty()) {
QStringList custom_ids;
foreach (const Message& msg, messages) {
custom_ids.append(msg.m_customId);
}
network()->markMessagesStarred(key, custom_ids);
}
}
}

View File

@ -20,11 +20,12 @@
#ifndef INOREADERSERVICEROOT_H
#define INOREADERSERVICEROOT_H
#include "services/abstract/cacheforserviceroot.h"
#include "services/abstract/serviceroot.h"
class InoreaderNetworkFactory;
class InoreaderServiceRoot : public ServiceRoot {
class InoreaderServiceRoot : public ServiceRoot, public CacheForServiceRoot {
Q_OBJECT
public:
@ -46,6 +47,8 @@ class InoreaderServiceRoot : public ServiceRoot {
RootItem* obtainNewTreeForSyncIn() const;
void saveAllCachedData();
public slots:
void addNewFeed(const QString& url);
void addNewCategory();

View File

@ -89,8 +89,13 @@ void InoreaderNetworkFactory::setUsername(const QString& username) {
RootItem* InoreaderNetworkFactory::feedsCategories(bool obtain_icons) {
Downloader downloader;
QEventLoop loop;
QString bearer = m_oauth2->bearer().toLocal8Bit();
downloader.appendRawHeader(QString("Authorization").toLocal8Bit(), m_oauth2->bearer().toLocal8Bit());
if (bearer.isEmpty()) {
return nullptr;
}
downloader.appendRawHeader(QString("Authorization").toLocal8Bit(), bearer.toLocal8Bit());
// We need to quit event loop when the download finishes.
connect(&downloader, &Downloader::completed, &loop, &QEventLoop::quit);
@ -119,9 +124,14 @@ QList<Message> InoreaderNetworkFactory::messages(const QString& stream_id, bool*
Downloader downloader;
QEventLoop loop;
QString target_url = INOREADER_API_FEED_CONTENTS;
QString bearer = m_oauth2->bearer().toLocal8Bit();
if (bearer.isEmpty()) {
return QList<Message>();
}
target_url += QSL("/") + QUrl::toPercentEncoding(stream_id) + QString("?n=%1").arg(batchSize());
downloader.appendRawHeader(QString("Authorization").toLocal8Bit(), m_oauth2->bearer().toLocal8Bit());
downloader.appendRawHeader(QString("Authorization").toLocal8Bit(), bearer.toLocal8Bit());
IOFactory::writeTextFile("aa.bb", target_url.toUtf8());
@ -141,6 +151,10 @@ QList<Message> InoreaderNetworkFactory::messages(const QString& stream_id, bool*
}
}
void InoreaderNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids) {}
void InoreaderNetworkFactory::markMessagesStarred(RootItem::Importance importance, const QStringList& custom_ids) {}
QList<Message> InoreaderNetworkFactory::decodeMessages(const QString& messages_json_data, const QString& stream_id) {
QList<Message> messages;
QJsonArray json = QJsonDocument::fromJson(messages_json_data.toUtf8()).object()["items"].toArray();

View File

@ -23,6 +23,8 @@
#include "core/message.h"
#include "services/abstract/rootitem.h"
#include <QNetworkReply>
class RootItem;
@ -52,6 +54,8 @@ class InoreaderNetworkFactory : public QObject {
RootItem* feedsCategories(bool obtain_icons);
QList<Message> messages(const QString& stream_id, bool* is_error);
void markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids);
void markMessagesStarred(RootItem::Importance importance, const QStringList& custom_ids);
private:
QList<Message> decodeMessages(const QString& messages_json_data, const QString& stream_id);