1 // For license of this file, see <project-root-folder>/LICENSE.md.
2
3 #include "gui/dialogs/formaddaccount.h"
4
5 #include "core/feedsmodel.h"
6 #include "gui/guiutilities.h"
7 #include "miscellaneous/application.h"
8 #include "miscellaneous/iconfactory.h"
9 #include "services/standard/standardserviceentrypoint.h"
10
11 #include <QDialogButtonBox>
12 #include <QListWidget>
13 #include <QSize>
14
FormAddAccount(const QList<ServiceEntryPoint * > & entry_points,FeedsModel * model,QWidget * parent)15 FormAddAccount::FormAddAccount(const QList<ServiceEntryPoint*>& entry_points, FeedsModel* model, QWidget* parent)
16 : QDialog(parent), m_ui(new Ui::FormAddAccount), m_model(model), m_entryPoints(entry_points) {
17 m_ui->setupUi(this);
18
19 GuiUtilities::applyResponsiveDialogResize(*this);
20
21 // Set flags and attributes.
22 GuiUtilities::applyDialogProperties(*this, qApp->icons()->fromTheme(QSL("list-add")));
23
24 connect(m_ui->m_listEntryPoints, &QListWidget::itemDoubleClicked, this, &FormAddAccount::addSelectedAccount);
25 connect(m_ui->m_buttonBox, &QDialogButtonBox::accepted, this, &FormAddAccount::addSelectedAccount);
26 connect(m_ui->m_listEntryPoints, &QListWidget::currentRowChanged, this, &FormAddAccount::showAccountDetails);
27
28 loadEntryPoints();
29 }
30
~FormAddAccount()31 FormAddAccount::~FormAddAccount() {
32 qDebugNN << LOGSEC_GUI << "Destroying FormAddAccount instance.";
33 }
34
addSelectedAccount()35 void FormAddAccount::addSelectedAccount() {
36 accept();
37 ServiceEntryPoint* point = selectedEntryPoint();
38 ServiceRoot* new_root = point->createNewRoot();
39
40 if (new_root != nullptr) {
41 m_model->addServiceAccount(new_root, true);
42 }
43 else {
44 qDebugNN << LOGSEC_CORE << "Cannot create new account.";
45 }
46 }
47
showAccountDetails()48 void FormAddAccount::showAccountDetails() {
49 ServiceEntryPoint* point = selectedEntryPoint();
50
51 if (point != nullptr) {
52 m_ui->m_lblDetails->setText(point->description());
53 }
54 }
55
selectedEntryPoint() const56 ServiceEntryPoint* FormAddAccount::selectedEntryPoint() const {
57 return m_entryPoints.at(m_ui->m_listEntryPoints->currentRow());
58 }
59
loadEntryPoints()60 void FormAddAccount::loadEntryPoints() {
61 int classic_row = 0, i = 0;
62
63 for (const ServiceEntryPoint* entry_point : qAsConst(m_entryPoints)) {
64 if (entry_point->code() == QSL(SERVICE_CODE_STD_RSS)) {
65 classic_row = i;
66 }
67
68 QListWidgetItem* item = new QListWidgetItem(entry_point->icon(), entry_point->name(), m_ui->m_listEntryPoints);
69
70 item->setToolTip(entry_point->description());
71 i++;
72 }
73
74 m_ui->m_listEntryPoints->setCurrentRow(classic_row);
75 }
76