Debian Codegraph @

src/librssguard/services/abstract/gui/formaccountdetails.cpp

raw symbols SCIP
1 // For license of this file, see <project-root-folder>/LICENSE.md.
2
3 #include "services/abstract/gui/formaccountdetails.h"
4
5 #include "gui/guiutilities.h"
6 #include "miscellaneous/application.h"
7 #include "miscellaneous/iconfactory.h"
8 #include "services/abstract/importantnode.h"
9 #include "services/abstract/labelsnode.h"
10 #include "services/abstract/searchsnode.h"
11 #include "services/abstract/serviceroot.h"
12 #include "services/abstract/unreadnode.h"
13
14 #include "ui_accountdetails.h"
15 #include "ui_formaccountdetails.h"
16
17 FormAccountDetails::FormAccountDetails(const QIcon& icon, QWidget* parent)
18 : QDialog(parent), m_proxyDetails(new NetworkProxyDetails(this)), m_accountDetails(new AccountDetails(this)),
19 m_account(nullptr), m_creatingNew(false), m_ui(new Ui::FormAccountDetails()) {
20 m_ui->setupUi(this);
21
22 insertCustomTab(m_accountDetails, tr("Miscellaneous"), 0);
23 insertCustomTab(m_proxyDetails, tr("Network proxy"), 1);
24
25 GuiUtilities::applyDialogProperties(*this, icon.isNull() ? qApp->icons()->fromTheme(QSL("emblem-system")) : icon);
26 createConnections();
27 }
28
29 FormAccountDetails::~FormAccountDetails() = default;
30
31 void FormAccountDetails::apply() {
32 m_account->setNodeShowImportant(m_accountDetails->m_ui->m_cbImportant->isChecked());
33 m_account->setNodeShowLabels(m_accountDetails->m_ui->m_cbLabels->isChecked());
34 m_account->setNodeShowProbes(m_accountDetails->m_ui->m_cbProbes->isChecked());
35 m_account->setNodeShowUnread(m_accountDetails->m_ui->m_cbUnread->isChecked());
36
37 m_account->setNetworkProxy(m_proxyDetails->proxy());
38
39 if (!m_creatingNew) {
40 m_account->itemChanged({m_account->importantNode(),
41 m_account->labelsNode(),
42 m_account->unreadNode(),
43 m_account->probesNode()});
44 }
45 }
46
47 void FormAccountDetails::insertCustomTab(QWidget* custom_tab, const QString& title, int index) {
48 m_ui->m_tabWidget->insertTab(index, custom_tab, title);
49 }
50
51 void FormAccountDetails::activateTab(int index) {
52 m_ui->m_tabWidget->setCurrentIndex(index);
53 }
54
55 void FormAccountDetails::clearTabs() {
56 m_ui->m_tabWidget->clear();
57 }
58
59 void FormAccountDetails::loadAccountData() {
60 if (m_creatingNew) {
61 setWindowTitle(tr("Add new account"));
62 }
63 else {
64 setWindowTitle(tr("Edit account \"%1\"").arg(m_account->title()));
65
66 // Perform last-time operations before account is changed.
67 auto* cached_account = dynamic_cast<CacheForServiceRoot*>(m_account);
68
69 if (cached_account != nullptr) {
70 qWarningNN << LOGSEC_CORE << "Last-time account cache saving before account could be edited.";
71 cached_account->saveAllCachedData(true);
72 }
73 }
74
75 m_accountDetails->m_ui->m_cbImportant->setChecked(m_account->nodeShowImportant());
76 m_accountDetails->m_ui->m_cbLabels->setChecked(m_account->nodeShowLabels());
77 m_accountDetails->m_ui->m_cbProbes->setChecked(m_account->nodeShowProbes());
78 m_accountDetails->m_ui->m_cbUnread->setChecked(m_account->nodeShowUnread());
79
80 m_proxyDetails->setProxy(m_account->networkProxy());
81 }
82
83 void FormAccountDetails::createConnections() {
84 connect(m_ui->m_buttonBox, &QDialogButtonBox::accepted, this, &FormAccountDetails::apply);
85 }