gmail now fills in address when test setup is made, also date/time headers of gmails articles are more correctly parsed
This commit is contained in:
parent
c762f7bf4f
commit
d395f9d36c
@ -30,7 +30,7 @@
|
||||
<url type="donation">https://martinrotter.github.io/donate/</url>
|
||||
<content_rating type="oars-1.1" />
|
||||
<releases>
|
||||
<release version="3.9.0" date="2021-04-09"/>
|
||||
<release version="3.9.0" date="2021-04-12"/>
|
||||
</releases>
|
||||
<content_rating type="oars-1.0">
|
||||
<content_attribute id="violence-cartoon">none</content_attribute>
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 9c10723bfbaf6cb85107d6ee16e0324e9e487749
|
||||
Subproject commit 47f4125753452eff8800dbd6600c5a05540b15d9
|
@ -538,7 +538,7 @@ void FeedsModel::loadActivatedServiceAccounts() {
|
||||
}
|
||||
|
||||
if (serviceRoots().isEmpty()) {
|
||||
QTimer::singleShot(3000, qApp->mainForm(), []() {
|
||||
QTimer::singleShot(2000, qApp->mainForm(), []() {
|
||||
qApp->mainForm()->showAddAccountDialog();
|
||||
});
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ QDateTime TextFactory::parseDateTime(const QString& date_time) {
|
||||
QSL("MMM d yyyy hh:mm:ss") << QSL("ddd, dd MMM yyyy HH:mm:ss") << QSL("ddd, d MMM yyyy HH:mm:ss") <<
|
||||
QSL("dd MMM yyyy") << QSL("yyyy-MM-dd HH:mm:ss.z") << QSL("yyyy-MM-dd") <<
|
||||
QSL("yyyy") << QSL("yyyy-MM") << QSL("yyyy-MM-dd") << QSL("yyyy-MM-ddThh:mm") <<
|
||||
QSL("yyyy-MM-ddThh:mm:ss");
|
||||
QSL("yyyy-MM-ddThh:mm:ss") << QSL("d MMM yyyy HH:mm:ss");
|
||||
QStringList timezone_offset_patterns;
|
||||
|
||||
timezone_offset_patterns << QSL("+hh:mm") << QSL("-hh:mm") << QSL("+hhmm")
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
#include "services/feedly/feedlyentrypoint.h"
|
||||
|
||||
#include "database/databasequeries.h"
|
||||
#include "definitions/definitions.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "database/databasequeries.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
#include "services/feedly/definitions.h"
|
||||
#include "services/feedly/feedlyserviceroot.h"
|
||||
@ -31,7 +31,7 @@ QString FeedlyEntryPoint::code() const {
|
||||
}
|
||||
|
||||
QString FeedlyEntryPoint::description() const {
|
||||
return QObject::tr("Keep up with the topics and trends you care about, without the overwhelm. "
|
||||
return QObject::tr("Keep up with the topics and trends you care about, without the overwhelm.\n\n"
|
||||
"Feedly is a secure space where you can privately organize and research the "
|
||||
"topics and trends that matter to you.");
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#define GMAIL_API_SEND_MESSAGE "https://www.googleapis.com/upload/gmail/v1/users/me/messages/send?uploadType=media"
|
||||
#define GMAIL_API_BATCH_UPD_LABELS "https://www.googleapis.com/gmail/v1/users/me/messages/batchModify"
|
||||
#define GMAIL_API_GET_PROFILE "https://gmail.googleapis.com/gmail/v1/users/me/profile"
|
||||
#define GMAIL_API_GET_ATTACHMENT "https://www.googleapis.com/gmail/v1/users/me/messages/%1/attachments/%2"
|
||||
#define GMAIL_API_LABELS_LIST "https://www.googleapis.com/gmail/v1/users/me/labels"
|
||||
#define GMAIL_API_MSGS_LIST "https://www.googleapis.com/gmail/v1/users/me/messages"
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "database/databasequeries.h"
|
||||
#include "definitions/definitions.h"
|
||||
#include "exceptions/applicationexception.h"
|
||||
#include "exceptions/networkexception.h"
|
||||
#include "gui/dialogs/formmain.h"
|
||||
#include "gui/tabwidget.h"
|
||||
#include "miscellaneous/application.h"
|
||||
@ -380,6 +381,41 @@ QNetworkReply::NetworkError GmailNetworkFactory::markMessagesStarred(RootItem::I
|
||||
return QNetworkReply::NetworkError::NoError;
|
||||
}
|
||||
|
||||
QVariantHash GmailNetworkFactory::getProfile(const QNetworkProxy& custom_proxy) {
|
||||
QString bearer = m_oauth2->bearer().toLocal8Bit();
|
||||
|
||||
if (bearer.isEmpty()) {
|
||||
throw ApplicationException(tr("you are not logged in"));
|
||||
}
|
||||
|
||||
QList<QPair<QByteArray, QByteArray>> headers;
|
||||
|
||||
headers.append(QPair<QByteArray, QByteArray>(QString(HTTP_HEADERS_AUTHORIZATION).toLocal8Bit(),
|
||||
m_oauth2->bearer().toLocal8Bit()));
|
||||
|
||||
int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
||||
QByteArray output;
|
||||
auto result = NetworkFactory::performNetworkOperation(GMAIL_API_GET_PROFILE,
|
||||
timeout,
|
||||
{},
|
||||
output,
|
||||
QNetworkAccessManager::Operation::GetOperation,
|
||||
headers,
|
||||
false,
|
||||
{},
|
||||
{},
|
||||
custom_proxy).first;
|
||||
|
||||
if (result != QNetworkReply::NetworkError::NoError) {
|
||||
throw NetworkException(result, output);
|
||||
}
|
||||
else {
|
||||
QJsonDocument doc = QJsonDocument::fromJson(output);
|
||||
|
||||
return doc.object().toVariantHash();
|
||||
}
|
||||
}
|
||||
|
||||
void GmailNetworkFactory::onTokensError(const QString& error, const QString& error_description) {
|
||||
Q_UNUSED(error)
|
||||
|
||||
|
@ -48,6 +48,7 @@ class GmailNetworkFactory : public QObject {
|
||||
QNetworkReply::NetworkError markMessagesStarred(RootItem::Importance importance,
|
||||
const QStringList& custom_ids,
|
||||
const QNetworkProxy& custom_proxy);
|
||||
QVariantHash getProfile(const QNetworkProxy& custom_proxy);
|
||||
|
||||
private slots:
|
||||
void onTokensError(const QString& error, const QString& error_description);
|
||||
|
@ -17,6 +17,9 @@ FormEditGmailAccount::FormEditGmailAccount(QWidget* parent)
|
||||
activateTab(0);
|
||||
|
||||
m_details->m_ui.m_txtUsername->setFocus();
|
||||
connect(m_details->m_ui.m_btnTestSetup, &QPushButton::clicked, this, [this]() {
|
||||
m_details->testSetup(m_proxyDetails->proxy());
|
||||
});
|
||||
}
|
||||
|
||||
void FormEditGmailAccount::apply() {
|
||||
|
@ -2,14 +2,16 @@
|
||||
|
||||
#include "services/gmail/gui/gmailaccountdetails.h"
|
||||
|
||||
#include "exceptions/applicationexception.h"
|
||||
#include "gui/guiutilities.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "network-web/oauth2service.h"
|
||||
#include "network-web/webfactory.h"
|
||||
#include "services/gmail/definitions.h"
|
||||
#include "services/gmail/gmailnetworkfactory.h"
|
||||
|
||||
GmailAccountDetails::GmailAccountDetails(QWidget* parent)
|
||||
: QWidget(parent), m_oauth(nullptr) {
|
||||
: QWidget(parent), m_oauth(nullptr), m_lastProxy({}) {
|
||||
m_ui.setupUi(this);
|
||||
|
||||
GuiUtilities::setLabelAsNotice(*m_ui.m_lblInfo, true);
|
||||
@ -40,7 +42,6 @@ GmailAccountDetails::GmailAccountDetails(QWidget* parent)
|
||||
connect(m_ui.m_txtAppKey->lineEdit(), &BaseLineEdit::textChanged, this, &GmailAccountDetails::checkOAuthValue);
|
||||
connect(m_ui.m_txtRedirectUrl->lineEdit(), &BaseLineEdit::textChanged, this, &GmailAccountDetails::checkOAuthValue);
|
||||
connect(m_ui.m_txtUsername->lineEdit(), &BaseLineEdit::textChanged, this, &GmailAccountDetails::checkUsername);
|
||||
connect(m_ui.m_btnTestSetup, &QPushButton::clicked, this, &GmailAccountDetails::testSetup);
|
||||
connect(m_ui.m_btnRegisterApi, &QPushButton::clicked, this, &GmailAccountDetails::registerApi);
|
||||
|
||||
emit m_ui.m_txtUsername->lineEdit()->textChanged(m_ui.m_txtUsername->lineEdit()->text());
|
||||
@ -51,12 +52,13 @@ GmailAccountDetails::GmailAccountDetails(QWidget* parent)
|
||||
hookNetwork();
|
||||
}
|
||||
|
||||
void GmailAccountDetails::testSetup() {
|
||||
void GmailAccountDetails::testSetup(const QNetworkProxy& custom_proxy) {
|
||||
m_oauth->logout();
|
||||
m_oauth->setClientId(m_ui.m_txtAppId->lineEdit()->text());
|
||||
m_oauth->setClientSecret(m_ui.m_txtAppKey->lineEdit()->text());
|
||||
m_oauth->setRedirectUrl(m_ui.m_txtRedirectUrl->lineEdit()->text());
|
||||
|
||||
m_lastProxy = custom_proxy;
|
||||
m_oauth->login();
|
||||
}
|
||||
|
||||
@ -87,6 +89,21 @@ void GmailAccountDetails::onAuthGranted() {
|
||||
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Ok,
|
||||
tr("Tested successfully. You may be prompted to login once more."),
|
||||
tr("Your access was approved."));
|
||||
|
||||
GmailNetworkFactory fac;
|
||||
|
||||
fac.setOauth(m_oauth);
|
||||
|
||||
try {
|
||||
auto resp = fac.getProfile(m_lastProxy);
|
||||
|
||||
m_ui.m_txtUsername->lineEdit()->setText(resp["emailAddress"].toString());
|
||||
}
|
||||
catch (const ApplicationException& ex) {
|
||||
qCriticalNN << LOGSEC_GMAIL
|
||||
<< "Failed to obtain profile with error:"
|
||||
<< QUOTE_W_SPACE_DOT(ex.message());
|
||||
}
|
||||
}
|
||||
|
||||
void GmailAccountDetails::hookNetwork() {
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
#include "ui_gmailaccountdetails.h"
|
||||
|
||||
#include <QNetworkProxy>
|
||||
|
||||
class OAuth2Service;
|
||||
|
||||
class GmailAccountDetails : public QWidget {
|
||||
@ -17,9 +19,11 @@ class GmailAccountDetails : public QWidget {
|
||||
public:
|
||||
explicit GmailAccountDetails(QWidget* parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void testSetup(const QNetworkProxy& custom_proxy);
|
||||
|
||||
private slots:
|
||||
void registerApi();
|
||||
void testSetup();
|
||||
void checkOAuthValue(const QString& value);
|
||||
void checkUsername(const QString& username);
|
||||
void onAuthFailed();
|
||||
@ -34,6 +38,7 @@ class GmailAccountDetails : public QWidget {
|
||||
|
||||
// Pointer to live OAuth.
|
||||
OAuth2Service* m_oauth;
|
||||
QNetworkProxy m_lastProxy;
|
||||
};
|
||||
|
||||
#endif // GMAILACCOUNTDETAILS_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user