1 // For license of this file, see <project-root-folder>/LICENSE.md.
2 
3 #include "services/feedly/gui/formeditfeedlyaccount.h"
4 
5 #include "gui/guiutilities.h"
6 #include "miscellaneous/iconfactory.h"
7 #include "network-web/networkfactory.h"
8 #include "services/feedly/definitions.h"
9 #include "services/feedly/feedlynetwork.h"
10 #include "services/feedly/feedlyserviceroot.h"
11 #include "services/feedly/gui/feedlyaccountdetails.h"
12 
13 #if defined(FEEDLY_OFFICIAL_SUPPORT)
14 #include "network-web/oauth2service.h"
15 #endif
16 
FormEditFeedlyAccount(QWidget * parent)17 FormEditFeedlyAccount::FormEditFeedlyAccount(QWidget* parent)
18   : FormAccountDetails(qApp->icons()->miscIcon(QSL("feedly")), parent), m_details(new FeedlyAccountDetails(this)) {
19   insertCustomTab(m_details, tr("Service setup"), 0);
20   activateTab(0);
21 
22   connect(m_details->m_ui.m_btnTestSetup, &QPushButton::clicked, this, &FormEditFeedlyAccount::performTest);
23   m_details->m_ui.m_txtUsername->setFocus();
24 }
25 
apply()26 void FormEditFeedlyAccount::apply() {
27   FormAccountDetails::apply();
28 
29 #if defined(FEEDLY_OFFICIAL_SUPPORT)
30   account<FeedlyServiceRoot>()->network()->oauth()->logout(false);
31 #endif
32 
33   bool using_another_acc =
34     m_details->m_ui.m_txtUsername->lineEdit()->text() !=account<FeedlyServiceRoot>()->network()->username();
35 
36   account<FeedlyServiceRoot>()->network()->setUsername(m_details->m_ui.m_txtUsername->lineEdit()->text());
37   account<FeedlyServiceRoot>()->network()->setDownloadOnlyUnreadMessages(m_details->m_ui.m_checkDownloadOnlyUnreadMessages->isChecked());
38   account<FeedlyServiceRoot>()->network()->setBatchSize(m_details->m_ui.m_spinLimitMessages->value());
39   account<FeedlyServiceRoot>()->network()->setDeveloperAccessToken(m_details->m_ui.m_txtDeveloperAccessToken->lineEdit()->text());
40 
41   account<FeedlyServiceRoot>()->saveAccountDataToDatabase();
42   accept();
43 
44   if (!m_creatingNew) {
45     if (using_another_acc) {
46       account<FeedlyServiceRoot>()->completelyRemoveAllData();
47     }
48 
49     account<FeedlyServiceRoot>()->start(true);
50   }
51 }
52 
loadAccountData()53 void FormEditFeedlyAccount::loadAccountData() {
54   FormAccountDetails::loadAccountData();
55 
56 #if defined(FEEDLY_OFFICIAL_SUPPORT)
57   m_details->m_oauth = account<FeedlyServiceRoot>()->network()->oauth();
58   m_details->hookNetwork();
59 #endif
60 
61   m_details->m_ui.m_txtUsername->lineEdit()->setText(account<FeedlyServiceRoot>()->network()->username());
62   m_details->m_ui.m_txtDeveloperAccessToken->lineEdit()->setText(account<FeedlyServiceRoot>()->network()->developerAccessToken());
63   m_details->m_ui.m_checkDownloadOnlyUnreadMessages->setChecked(account<FeedlyServiceRoot>()->network()->downloadOnlyUnreadMessages());
64   m_details->m_ui.m_spinLimitMessages->setValue(account<FeedlyServiceRoot>()->network()->batchSize());
65 }
66 
performTest()67 void FormEditFeedlyAccount::performTest() {
68   m_details->performTest(m_proxyDetails->proxy());
69 }
70