Work on inoreader plugin.

This commit is contained in:
Martin Rotter 2017-09-21 09:09:07 +02:00
parent 0a8332a3de
commit 843795fd88
8 changed files with 102 additions and 6 deletions

View File

@ -44,6 +44,9 @@ sp_assign_default = force # ignore/add/remove/force
# Add or remove space around assignment '=' in enum
sp_enum_assign = force # ignore/add/remove/force
# Add or remove space between ')' and '{' of function
sp_fparen_brace = force # ignore/add/remove/force
# Add or remove space before pointer star '*'
sp_before_ptr_star = remove # ignore/add/remove/force

View File

@ -334,7 +334,8 @@ HEADERS += src/core/feeddownloader.h \
src/miscellaneous/externaltool.h \
src/services/inoreader/definitions.h \
src/services/inoreader/inoreaderentrypoint.h \
src/services/inoreader/network/inoreadernetworkfactory.h
src/services/inoreader/network/inoreadernetworkfactory.h \
src/services/inoreader/inoreaderserviceroot.h
SOURCES += src/core/feeddownloader.cpp \
src/core/feedsmodel.cpp \
@ -458,7 +459,8 @@ SOURCES += src/core/feeddownloader.cpp \
src/services/abstract/label.cpp \
src/miscellaneous/externaltool.cpp \
src/services/inoreader/inoreaderentrypoint.cpp \
src/services/inoreader/network/inoreadernetworkfactory.cpp
src/services/inoreader/network/inoreadernetworkfactory.cpp \
src/services/inoreader/inoreaderserviceroot.cpp
OBJECTIVE_SOURCES += src/miscellaneous/disablewindowtabbing.mm

View File

@ -53,9 +53,6 @@ class RootItem : public QObject {
Q_OBJECT
public:
// Holds statuses for feeds/messages
// to be marked read/unread.
enum ReadStatus {
Unread = 0,
Read = 1

View File

@ -19,7 +19,8 @@
#ifndef INOREADER_DEFINITIONS_H
#define INOREADER_DEFINITIONS_H
#define INOREADER_OAUTH_PORT "8080"
#define INOREADER_OAUTH_PORT 8080
#define INOREADER_OAUTH_SCOPE "read write"
#define INOREADER_OAUTH_TOKEN_URL "https://www.inoreader.com/oauth2/token"
#define INOREADER_OAUTH_AUTH_URL "https://www.inoreader.com/oauth2/auth"
#define INOREADER_OAUTH_CLI_ID "1000000604"

View File

@ -0,0 +1,24 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
// Copyright (C) 2010-2014 by David Rosca <nowrep@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/inoreaderserviceroot.h"
InoreaderServiceRoot::InoreaderServiceRoot(RootItem* parent) : ServiceRoot(parent) {}
InoreaderServiceRoot::~InoreaderServiceRoot() {}

View File

@ -0,0 +1,38 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
// Copyright (C) 2010-2014 by David Rosca <nowrep@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 INOREADERSERVICEROOT_H
#define INOREADERSERVICEROOT_H
#include "services/abstract/serviceroot.h"
#include "services/inoreader/network/inoreadernetworkfactory.h"
class InoreaderServiceRoot : public ServiceRoot {
Q_OBJECT
public:
explicit InoreaderServiceRoot(RootItem* parent = nullptr);
virtual ~InoreaderServiceRoot();
private:
InoreaderNetworkFactory m_network;
};
#endif // INOREADERSERVICEROOT_H

View File

@ -18,7 +18,12 @@
#include "services/inoreader/network/inoreadernetworkfactory.h"
#include "definitions/definitions.h"
#include "gui/dialogs/formmain.h"
#include "gui/tabwidget.h"
#include "miscellaneous/application.h"
#include "network-web/silentnetworkaccessmanager.h"
#include "network-web/webfactory.h"
#include "services/inoreader/definitions.h"
#include <QOAuthHttpServerReplyHandler>
@ -28,6 +33,14 @@ InoreaderNetworkFactory::InoreaderNetworkFactory(QObject* parent) : QObject(pare
initializeOauth();
}
bool InoreaderNetworkFactory::isLoggedIn() const {
return m_oauth2.expirationAt() > QDateTime::currentDateTime() && m_oauth2.status() == QAbstractOAuth::Status::Granted;
}
void InoreaderNetworkFactory::logIn() {
m_oauth2.grant();
}
void InoreaderNetworkFactory::initializeOauth() {
auto oauth_reply_handler = new QOAuthHttpServerReplyHandler(INOREADER_OAUTH_PORT, this);
@ -41,6 +54,19 @@ void InoreaderNetworkFactory::initializeOauth() {
m_oauth2.setContentType(QAbstractOAuth::ContentType::Json);
m_oauth2.setNetworkAccessManager(new SilentNetworkAccessManager(this));
m_oauth2.setReplyHandler(oauth_reply_handler);
m_oauth2.setUserAgent(APP_USERAGENT);
m_oauth2.setScope(INOREADER_OAUTH_SCOPE);
connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::statusChanged, [=](QAbstractOAuth::Status status) {});
m_oauth2.setModifyParametersFunction([&](QAbstractOAuth::Stage stage, QVariantMap* parameters) {});
connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::granted, [=]() {
int a = 5;
});
connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::error, [](const QString& error, const QString& errorDescription, const QUrl& uri) {});
connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, [](const QUrl& url) {
qApp->web()->openUrlInExternalBrowser(url.toString());
});
}
/*

View File

@ -29,6 +29,11 @@ class InoreaderNetworkFactory : public QObject {
public:
explicit InoreaderNetworkFactory(QObject* parent = nullptr);
bool isLoggedIn() const;
public slots:
void logIn();
private:
void initializeOauth();