Debian Codegraph @

src/librssguard/gui/settings/settingsgeneral.cpp

raw symbols SCIP
1 // For license of this file, see <project-root-folder>/LICENSE.md.
2
3 #include "gui/settings/settingsgeneral.h"
4
5 #include "miscellaneous/application.h"
6 #include "miscellaneous/iconfactory.h"
7 #include "miscellaneous/settings.h"
8 #include "miscellaneous/systemfactory.h"
9
10 SettingsGeneral::SettingsGeneral(Settings* settings, QWidget* parent)
11 : SettingsPanel(settings, parent), m_ui(new Ui::SettingsGeneral) {
12 m_ui->setupUi(this);
13 m_ui->m_checkAutostart->setText(m_ui->m_checkAutostart->text().arg(QSL(APP_NAME)));
14 m_ui->m_checkForUpdatesOnStart->setText(m_ui->m_checkForUpdatesOnStart->text().arg(QSL(APP_NAME)));
15
16 #if defined(NO_UPDATE_CHECK)
17 m_ui->m_checkForUpdatesOnStart->setVisible(false);
18 #endif
19
20 connect(m_ui->m_checkAutostart, &QCheckBox::stateChanged, this, &SettingsGeneral::dirtifySettings);
21 connect(m_ui->m_checkForUpdatesOnStart, &QCheckBox::stateChanged, this, &SettingsGeneral::dirtifySettings);
22 }
23
24 SettingsGeneral::~SettingsGeneral() {
25 delete m_ui;
26 }
27
28 QIcon SettingsGeneral::icon() const {
29 return qApp->icons()->fromTheme(QSL("applications-system"), QSL("emblem-system"));
30 }
31
32 void SettingsGeneral::loadSettings() {
33 onBeginLoadSettings();
34 m_ui->m_checkForUpdatesOnStart
35 ->setChecked(settings()->value(GROUP(General), SETTING(General::UpdateOnStartup)).toBool());
36
37 // Load auto-start status.
38 const SystemFactory::AutoStartStatus autostart_status = qApp->system()->autoStartStatus();
39
40 switch (autostart_status) {
41 case SystemFactory::AutoStartStatus::Enabled:
42 m_ui->m_checkAutostart->setChecked(true);
43 break;
44
45 case SystemFactory::AutoStartStatus::Disabled:
46 m_ui->m_checkAutostart->setChecked(false);
47 break;
48
49 default:
50 m_ui->m_checkAutostart->setEnabled(false);
51 m_ui->m_checkAutostart->setText(m_ui->m_checkAutostart->text() + tr(" (not supported on this platform)"));
52 break;
53 }
54
55 onEndLoadSettings();
56 }
57
58 void SettingsGeneral::saveSettings() {
59 onBeginSaveSettings();
60
61 // If auto-start feature is available and user wants to turn it on, then turn it on.
62 if (m_ui->m_checkAutostart->isChecked()) {
63 qApp->system()->setAutoStartStatus(SystemFactory::AutoStartStatus::Enabled);
64 }
65 else {
66 qApp->system()->setAutoStartStatus(SystemFactory::AutoStartStatus::Disabled);
67 }
68
69 settings()->setValue(GROUP(General), General::UpdateOnStartup, m_ui->m_checkForUpdatesOnStart->isChecked());
70 onEndSaveSettings();
71 }