1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
/**
* Copyright (C) 2021 Saturneric
*
* This file is part of GpgFrontend.
*
* GpgFrontend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GpgFrontend is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
*
* The initial version of the source code is inherited from
* the gpg4usb project, which is under GPL-3.0-or-later.
*
* All the source code of GpgFrontend was modified and released by
* Saturneric<[email protected]> starting on May 12, 2021.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#include "SettingsDialog.h"
#include "ui/settings/GlobalSettingStation.h"
#include "ui/settings/SettingsAdvanced.h"
#include "ui/settings/SettingsAppearance.h"
#include "ui/settings/SettingsGeneral.h"
#include "ui/settings/SettingsKeyServer.h"
#include "ui/settings/SettingsNetwork.h"
#include "ui/main_window/MainWindow.h"
#ifdef SMTP_SUPPORT
#include "ui/settings/SettingsSendMail.h"
#endif
namespace GpgFrontend::UI {
SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent) {
tab_widget_ = new QTabWidget();
general_tab_ = new GeneralTab();
appearance_tab_ = new AppearanceTab();
#ifdef SMTP_SUPPORT
send_mail_tab_ = new SendMailTab();
#endif
key_server_tab_ = new KeyserverTab();
network_tab_ = new NetworkTab();
#ifdef ADVANCED_SUPPORT
advancedTab = new AdvancedTab;
#endif
tab_widget_->addTab(general_tab_, _("General"));
tab_widget_->addTab(appearance_tab_, _("Appearance"));
#ifdef SMTP_SUPPORT
tab_widget_->addTab(send_mail_tab_, _("Send Mail"));
#endif
tab_widget_->addTab(key_server_tab_, _("Key Server"));
// tabWidget->addTab(gpgPathsTab, _("Gpg paths"));
tab_widget_->addTab(network_tab_, _("Network"));
#ifdef ADVANCED_SUPPORT
tabWidget->addTab(advancedTab, _("Advanced"));
#endif
button_box_ =
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(button_box_, &QDialogButtonBox::accepted, this, &SettingsDialog::SlotAccept);
connect(button_box_, &QDialogButtonBox::rejected, this, &SettingsDialog::reject);
auto* mainLayout = new QVBoxLayout;
mainLayout->addWidget(tab_widget_);
mainLayout->stretch(0);
mainLayout->addWidget(button_box_);
mainLayout->stretch(0);
setLayout(mainLayout);
setWindowTitle(_("Settings"));
// slots for handling the restart needed member
this->slot_set_restart_needed(false);
connect(general_tab_, &GeneralTab::SignalRestartNeeded, this,
&SettingsDialog::slot_set_restart_needed);
connect(this, &SettingsDialog::SignalRestartNeeded, qobject_cast<MainWindow *>(parent), &MainWindow::SlotSetRestartNeeded);
this->setMinimumSize(480, 680);
this->adjustSize();
this->show();
}
bool SettingsDialog::get_restart_needed() const {
return this->restart_needed_;
}
void SettingsDialog::slot_set_restart_needed(bool needed) {
this->restart_needed_ = needed;
}
void SettingsDialog::SlotAccept() {
LOG(INFO) << "Called";
general_tab_->ApplySettings();
#ifdef SMTP_SUPPORT
send_mail_tab_->ApplySettings();
#endif
appearance_tab_->ApplySettings();
key_server_tab_->ApplySettings();
network_tab_->ApplySettings();
#ifdef ADVANCED_SUPPORT
advancedTab->applySettings();
#endif
LOG(INFO) << "apply done";
// write settings to filesystem
GlobalSettingStation::GetInstance().SyncSettings();
LOG(INFO) << "restart needed" << get_restart_needed();
if (get_restart_needed()) {
emit SignalRestartNeeded(true);
}
close();
}
QHash<QString, QString> SettingsDialog::ListLanguages() {
QHash<QString, QString> languages;
languages.insert(QString(), _("System Default"));
auto locale_path = GlobalSettingStation::GetInstance().GetLocaleDir();
auto locale_dir = QDir(QString::fromStdString(locale_path.string()));
QStringList file_names = locale_dir.entryList(QStringList("*"));
for (int i = 0; i < file_names.size(); ++i) {
QString locale = file_names[i];
LOG(INFO) << "locale" << locale.toStdString();
if (locale == "." || locale == "..") continue;
// this works in qt 4.8
QLocale q_locale(locale);
if (q_locale.nativeCountryName().isEmpty()) continue;
#if QT_VERSION < 0x040800
QString language =
QLocale::languageToString(q_locale.language()) + " (" + locale +
")"; //+ " (" + QLocale::languageToString(q_locale.language()) + ")";
#else
auto language = q_locale.nativeLanguageName() + " (" + locale + ")";
#endif
languages.insert(locale, language);
}
return languages;
}
} // namespace GpgFrontend::UI
|