From 67254d209c071ce529ff0b3eb1ce2e2ca5ebe680 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Mon, 16 Oct 2017 14:36:53 +0200 Subject: [PATCH] Added empty gmail entry point. --- rssguard.pro | 7 ++- src/definitions/definitions.h | 1 + src/main.cpp | 80 +++++++++++++------------- src/miscellaneous/feedreader.cpp | 2 + src/network-web/oauth2service.cpp | 7 ++- src/services/gmail/definitions.h | 22 +++++++ src/services/gmail/gmailentrypoint.cpp | 61 ++++++++++++++++++++ src/services/gmail/gmailentrypoint.h | 37 ++++++++++++ 8 files changed, 172 insertions(+), 45 deletions(-) create mode 100755 src/services/gmail/definitions.h create mode 100755 src/services/gmail/gmailentrypoint.cpp create mode 100755 src/services/gmail/gmailentrypoint.h diff --git a/rssguard.pro b/rssguard.pro index 35c33261c..c1461bf4e 100755 --- a/rssguard.pro +++ b/rssguard.pro @@ -497,7 +497,9 @@ equals(USE_WEBENGINE, true) { src/services/inoreader/gui/formeditinoreaderaccount.h \ src/services/inoreader/inoreaderfeed.h \ src/network-web/oauth2service.h \ - src/gui/dialogs/oauthlogin.h + src/gui/dialogs/oauthlogin.h \ + src/services/gmail/definitions.h \ + src/services/gmail/gmailentrypoint.h SOURCES += src/gui/locationlineedit.cpp \ src/gui/webviewer.cpp \ @@ -512,7 +514,8 @@ equals(USE_WEBENGINE, true) { src/services/inoreader/gui/formeditinoreaderaccount.cpp \ src/services/inoreader/inoreaderfeed.cpp \ src/network-web/oauth2service.cpp \ - src/gui/dialogs/oauthlogin.cpp + src/gui/dialogs/oauthlogin.cpp \ + src/services/gmail/gmailentrypoint.cpp # Add AdBlock sources. HEADERS += src/network-web/adblock/adblockaddsubscriptiondialog.h \ diff --git a/src/definitions/definitions.h b/src/definitions/definitions.h index e59cc4170..38d71afff 100755 --- a/src/definitions/definitions.h +++ b/src/definitions/definitions.h @@ -25,6 +25,7 @@ #define SERVICE_CODE_TT_RSS "tt-rss" #define SERVICE_CODE_OWNCLOUD "owncloud" #define SERVICE_CODE_INOREADER "inoreader" +#define SERVICE_CODE_GMAIL "gmail" #define ARGUMENTS_LIST_SEPARATOR "\n" diff --git a/src/main.cpp b/src/main.cpp index fbee19bc9..9aa4d2977 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -175,58 +175,58 @@ int main(int argc, char* argv[]) { qApp->showPolls(); qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->loadAllExpandStates(); - /* - OAuth2Service * srv = new OAuth2Service( - "https://accounts.google.com/o/oauth2/auth", - "https://accounts.google.com/o/oauth2/token", - "369069180494-j66bgeciouinec1eem7fhvj6qm0as7q3.apps.googleusercontent.com", - "vppQtxrEeBkImiXcjGYl9NxZ", - "https://mail.google.com/"); +/* + OAuth2Service* srv = new OAuth2Service( + "https://accounts.google.com/o/oauth2/auth", + "https://accounts.google.com/o/oauth2/token", + "369069180494-j66bgeciouinec1eem7fhvj6qm0as7q3.apps.googleusercontent.com", + "vppQtxrEeBkImiXcjGYl9NxZ", + "https://mail.google.com/"); - srv->setRefreshToken("1/RKE3oohSoTHE54L0IPflvndK-DcI7l0of3lVdLa1Q9Q"); - QObject::connect(srv, &OAuth2Service::authCodeObtained, [](QString auth_code) { - int a = 5; - }); - QObject::connect(srv, &OAuth2Service::authFailed, []() { - int a = 5; - }); - QObject::connect(srv, &OAuth2Service::tokensReceived, [srv](QString acc, QString ref, int exp) { + srv->setRefreshToken("1/RKE3oohSoTHE54L0IPflvndK-DcI7l0of3lVdLa1Q9Q"); + QObject::connect(srv, &OAuth2Service::authCodeObtained, [](QString auth_code) { + int a = 5; + }); + QObject::connect(srv, &OAuth2Service::authFailed, []() { + int a = 5; + }); + QObject::connect(srv, &OAuth2Service::tokensReceived, [srv](QString acc, QString ref, int exp) { - QHttpMultiPart* multi = new QHttpMultiPart(srv); - QHttpPart p1; - QHttpPart p2; + QHttpMultiPart* multi = new QHttpMultiPart(srv); + QHttpPart p1; + QHttpPart p2; - multi->setContentType(QHttpMultiPart::ContentType::MixedType); - p1.setRawHeader("Content-Type", "application/http"); - p2.setRawHeader("Content-Type", "application/http"); - p1.setBody("GET /gmail/v1/users/me/messages\r\n"); - p2.setBody("GET /gmail/v1/users/me/labels\r\n"); - multi->append(p1); - multi->append(p2); - QNetworkRequest req; + multi->setContentType(QHttpMultiPart::ContentType::MixedType); + p1.setRawHeader("Content-Type", "application/http"); + p2.setRawHeader("Content-Type", "application/http"); + p1.setBody("GET /gmail/v1/users/me/messages\r\n"); + p2.setBody("GET /gmail/v1/users/me/labels\r\n"); + multi->append(p1); + multi->append(p2); + QNetworkRequest req; - auto bearer = srv->bearer(); - req.setRawHeader(QString("Authorization").toLocal8Bit(), bearer.toLocal8Bit()); + auto bearer = srv->bearer(); + req.setRawHeader(QString("Authorization").toLocal8Bit(), bearer.toLocal8Bit()); - req.setUrl(QUrl::fromUserInput("https://www.googleapis.com/batch")); - auto* repl = SilentNetworkAccessManager::instance()->post(req, multi); + req.setUrl(QUrl::fromUserInput("https://www.googleapis.com/batch")); + auto* repl = SilentNetworkAccessManager::instance()->post(req, multi); - //req.setUrl(QUrl::fromUserInput("https://www.googleapis.com/gmail/v1/users/me/labels")); - //auto* repl = SilentNetworkAccessManager::instance()->get(req); + //req.setUrl(QUrl::fromUserInput("https://www.googleapis.com/gmail/v1/users/me/labels")); + //auto* repl = SilentNetworkAccessManager::instance()->get(req); - QObject::connect(repl, &QNetworkReply::finished, [repl]() { + QObject::connect(repl, &QNetworkReply::finished, [repl]() { auto resp = repl->readAll(); auto a = 8; IOFactory::writeTextFile("b.html", resp); - }); + }); - int a = 5; - }); - QObject::connect(srv, &OAuth2Service::tokensRetrieveError, [](QString err, QString desc) { - int a = 5; - }); - srv->login(); */ + int a = 5; + }); + QObject::connect(srv, &OAuth2Service::tokensRetrieveError, [](QString err, QString desc) { + int a = 5; + }); + srv->login();*/ // Enter global event loop. return Application::exec(); diff --git a/src/miscellaneous/feedreader.cpp b/src/miscellaneous/feedreader.cpp index ac3b618ed..9e65476bc 100755 --- a/src/miscellaneous/feedreader.cpp +++ b/src/miscellaneous/feedreader.cpp @@ -21,6 +21,7 @@ #include "services/abstract/serviceroot.h" #if defined(USE_WEBENGINE) +#include "services/gmail/gmailentrypoint.h" #include "services/inoreader/inoreaderentrypoint.h" #endif @@ -70,6 +71,7 @@ QList FeedReader::feedServices() { if (m_feedServices.isEmpty()) { // NOTE: All installed services create their entry points here. #if defined(USE_WEBENGINE) + m_feedServices.append(new GmailEntryPoint()); m_feedServices.append(new InoreaderEntryPoint()); #endif m_feedServices.append(new OwnCloudServiceEntryPoint()); diff --git a/src/network-web/oauth2service.cpp b/src/network-web/oauth2service.cpp index cf99ce36e..4ca6a50c3 100755 --- a/src/network-web/oauth2service.cpp +++ b/src/network-web/oauth2service.cpp @@ -289,9 +289,10 @@ void OAuth2Service::killRefreshTimer() { void OAuth2Service::retrieveAuthCode() { QString auth_url = m_authUrl + QString("?client_id=%1&scope=%2&" - "redirect_uri=%3&response_type=code&state=abcdef").arg(m_clientId, - m_scope, - m_redirectUrl); + "redirect_uri=%3&response_type=code&state=abcdef&" + "prompt=consent&access_type=offline").arg(m_clientId, + m_scope, + m_redirectUrl); OAuthLogin login_page(qApp->mainFormWidget()); connect(&login_page, &OAuthLogin::authGranted, this, &OAuth2Service::authCodeObtained); diff --git a/src/services/gmail/definitions.h b/src/services/gmail/definitions.h new file mode 100755 index 000000000..97c5e034e --- /dev/null +++ b/src/services/gmail/definitions.h @@ -0,0 +1,22 @@ +// This file is part of RSS Guard. + +// +// Copyright (C) 2011-2017 by Martin Rotter +// +// 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 . + +#ifndef GMAIL_DEFINITIONS_H +#define GMAIL_DEFINITIONS_H + +#endif // GMAIL_DEFINITIONS_H diff --git a/src/services/gmail/gmailentrypoint.cpp b/src/services/gmail/gmailentrypoint.cpp new file mode 100755 index 000000000..02199a9ff --- /dev/null +++ b/src/services/gmail/gmailentrypoint.cpp @@ -0,0 +1,61 @@ +// This file is part of RSS Guard. + +// +// Copyright (C) 2011-2017 by Martin Rotter +// +// 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 . + +#include "services/gmail/gmailentrypoint.h" + +#include "definitions/definitions.h" +#include "miscellaneous/application.h" +#include "miscellaneous/databasequeries.h" +#include "miscellaneous/iconfactory.h" +#include "services/gmail/definitions.h" + +ServiceRoot* GmailEntryPoint::createNewRoot() const { + return nullptr; +} + +QList GmailEntryPoint::initializeSubtree() const { + QSqlDatabase database = qApp->database()->connection(QSL("GmailEntryPoint"), DatabaseFactory::FromSettings); + + return QList(); + + //return DatabaseQueries::getInoreaderAccounts(database); +} + +bool GmailEntryPoint::isSingleInstanceService() const { + return false; +} + +QString GmailEntryPoint::name() const { + return QSL("Gmail (not yet implemented)"); +} + +QString GmailEntryPoint::code() const { + return SERVICE_CODE_GMAIL; +} + +QString GmailEntryPoint::description() const { + return QObject::tr("Simple Gmail integration via JSON API. Allows sending e-mails too."); +} + +QString GmailEntryPoint::author() const { + return APP_AUTHOR; +} + +QIcon GmailEntryPoint::icon() const { + return qApp->icons()->miscIcon(QSL("gmail")); +} diff --git a/src/services/gmail/gmailentrypoint.h b/src/services/gmail/gmailentrypoint.h new file mode 100755 index 000000000..da8d79b64 --- /dev/null +++ b/src/services/gmail/gmailentrypoint.h @@ -0,0 +1,37 @@ +// This file is part of RSS Guard. + +// +// Copyright (C) 2011-2017 by Martin Rotter +// +// 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 . + +#ifndef GMAILENTRYPOINT_H +#define GMAILENTRYPOINT_H + +#include "services/abstract/serviceentrypoint.h" + +class GmailEntryPoint : public ServiceEntryPoint { + public: + ServiceRoot* createNewRoot() const; + + QList initializeSubtree() const; + bool isSingleInstanceService() const; + QString name() const; + QString code() const; + QString description() const; + QString author() const; + QIcon icon() const; +}; + +#endif // GMAILENTRYPOINT_H