qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
generalform.cpp
Go to the documentation of this file.
1 /*
2  Copyright © 2014-2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "generalform.h"
21 #include "ui_generalsettings.h"
22 
23 #include <QFileDialog>
24 #include <cmath>
25 
26 #include "src/core/core.h"
27 #include "src/core/coreav.h"
32 #include "src/widget/style.h"
34 #include "src/widget/translator.h"
35 #include "src/widget/widget.h"
36 
37 // clang-format off
38 static QStringList locales = {
39  "ar",
40  "be",
41  "ber",
42  "bg",
43  "cs",
44  "da",
45  "de",
46  "el",
47  "en",
48  "eo",
49  "es",
50  "et",
51  "fa",
52  "fi",
53  "fr",
54  "gl",
55  "he",
56  "hr",
57  "hu",
58  "is",
59  "it",
60  "ja",
61  "jbo",
62  "kn",
63  "ko",
64  "lt",
65  "mk",
66  "nl",
67  "no_nb",
68  "pl",
69  "pr",
70  "pt",
71  "pt_BR",
72  "ro",
73  "ru",
74  "si",
75  "sk",
76  "sl",
77  "sq",
78  "sr",
79  "sr_Latn",
80  "sv",
81  "sw",
82  "ta",
83  "tr",
84  "ug",
85  "uk",
86  "ur",
87  "zh_CN",
88  "zh_TW"
89 };
90 // clang-format on
91 
98  : GenericForm(QPixmap(":/img/settings/general.png"))
99  , bodyUI(new Ui::GeneralSettings)
100 {
101  parent = myParent;
102 
103  bodyUI->setupUi(this);
104 
105  // block all child signals during initialization
106  const RecursiveSignalBlocker signalBlocker(this);
107 
109 
110 #ifndef UPDATE_CHECK_ENABLED
111  bodyUI->checkUpdates->setVisible(false);
112 #endif
113 
114 #ifndef SPELL_CHECKING
115  bodyUI->cbSpellChecking->setVisible(false);
116 #endif
117 
118  bodyUI->checkUpdates->setChecked(s.getCheckUpdates());
119 
120  for (int i = 0; i < locales.size(); ++i) {
121  QString langName;
122 
123  if (locales[i].startsWith(QLatin1String("eo"))) // QTBUG-57802
124  langName = QLocale::languageToString(QLocale::Esperanto);
125  else if (locales[i].startsWith(QLatin1String("jbo")))
126  langName = QLatin1String("Lojban");
127  else if (locales[i].startsWith(QLatin1String("pr")))
128  langName = QLatin1String("Pirate");
129  else if (locales[i] == (QLatin1String("pt"))) // QTBUG-47891
130  langName = QStringLiteral("português");
131  else
132  langName = QLocale(locales[i]).nativeLanguageName();
133 
134  bodyUI->transComboBox->insertItem(i, langName);
135  }
136 
137  bodyUI->transComboBox->setCurrentIndex(locales.indexOf(s.getTranslation()));
138 
139  bodyUI->cbAutorun->setChecked(s.getAutorun());
140 
141  bodyUI->cbSpellChecking->setChecked(s.getSpellCheckingEnabled());
142  bodyUI->lightTrayIcon->setChecked(s.getLightTrayIcon());
143  bool showSystemTray = s.getShowSystemTray();
144 
145  bodyUI->showSystemTray->setChecked(showSystemTray);
146  bodyUI->startInTray->setChecked(s.getAutostartInTray());
147  bodyUI->startInTray->setEnabled(showSystemTray);
148  bodyUI->minimizeToTray->setChecked(s.getMinimizeToTray());
149  bodyUI->minimizeToTray->setEnabled(showSystemTray);
150  bodyUI->closeToTray->setChecked(s.getCloseToTray());
151  bodyUI->closeToTray->setEnabled(showSystemTray);
152 
153  bodyUI->statusChanges->setChecked(s.getStatusChangeNotificationEnabled());
154  bodyUI->groupJoinLeaveMessages->setChecked(s.getShowGroupJoinLeaveMessages());
155 
156  bodyUI->autoAwaySpinBox->setValue(s.getAutoAwayTime());
157  bodyUI->autoSaveFilesDir->setText(s.getGlobalAutoAcceptDir());
158  bodyUI->maxAutoAcceptSizeMB->setValue(static_cast<double>(s.getMaxAutoAcceptSize()) / 1024 / 1024);
159  bodyUI->autoacceptFiles->setChecked(s.getAutoSaveEnabled());
160 
161 
162 #ifndef QTOX_PLATFORM_EXT
163  bodyUI->autoAwayLabel->setEnabled(false); // these don't seem to change the appearance of the widgets,
164  bodyUI->autoAwaySpinBox->setEnabled(false); // though they are unusable
165 #endif
166 
167  eventsInit();
169 }
170 
172 {
174  delete bodyUI;
175 }
176 
178 {
179  const QString& locale = locales[index];
181  Translator::translate(locale);
182 }
183 
185 {
186  Settings::getInstance().setAutorun(bodyUI->cbAutorun->isChecked());
187 }
188 
190 {
191  Settings::getInstance().setSpellCheckingEnabled(bodyUI->cbSpellChecking->isChecked());
192 }
193 
195 {
196  Settings::getInstance().setShowSystemTray(bodyUI->showSystemTray->isChecked());
198 }
199 
201 {
202  Settings::getInstance().setAutostartInTray(bodyUI->startInTray->isChecked());
203 }
204 
206 {
207  Settings::getInstance().setCloseToTray(bodyUI->closeToTray->isChecked());
208 }
209 
211 {
212  Settings::getInstance().setLightTrayIcon(bodyUI->lightTrayIcon->isChecked());
213  emit updateIcons();
214 }
215 
217 {
218  Settings::getInstance().setMinimizeToTray(bodyUI->minimizeToTray->isChecked());
219 }
220 
222 {
223  Settings::getInstance().setStatusChangeNotificationEnabled(bodyUI->statusChanges->isChecked());
224 }
225 
227 {
228  Settings::getInstance().setShowGroupJoinLeaveMessages(bodyUI->groupJoinLeaveMessages->isChecked());
229 }
230 
232 {
233  int minutes = bodyUI->autoAwaySpinBox->value();
235 }
236 
238 {
239  Settings::getInstance().setAutoSaveEnabled(bodyUI->autoacceptFiles->isChecked());
240 }
241 
243 {
244  QString previousDir = Settings::getInstance().getGlobalAutoAcceptDir();
245  QString directory =
246  QFileDialog::getExistingDirectory(Q_NULLPTR,
247  tr("Choose an auto accept directory", "popup title"),
248  QDir::homePath());
249  if (directory.isEmpty()) // cancel was pressed
250  directory = previousDir;
251 
253  bodyUI->autoSaveFilesDir->setText(directory);
254 }
255 
257 {
258  auto newMaxSizeMB = bodyUI->maxAutoAcceptSizeMB->value();
259  auto newMaxSizeB = std::lround(newMaxSizeMB * 1024 * 1024);
260 
262 }
263 
265 {
266  Settings::getInstance().setCheckUpdates(bodyUI->checkUpdates->isChecked());
267 }
268 
273 {
274  bodyUI->retranslateUi(this);
275 }
Settings::setGlobalAutoAcceptDir
void setGlobalAutoAcceptDir(const QString &dir)
Definition: settings.cpp:1400
profile.h
Settings
Definition: settings.h:51
GeneralForm::parent
SettingsWidget * parent
Definition: generalform.h:65
style.h
Settings::getCheckUpdates
bool getCheckUpdates() const
Definition: settings.cpp:1546
GeneralForm::on_autoAwaySpinBox_editingFinished
void on_autoAwaySpinBox_editingFinished()
Definition: generalform.cpp:231
GeneralForm::on_groupJoinLeaveMessages_stateChanged
void on_groupJoinLeaveMessages_stateChanged()
Definition: generalform.cpp:226
GeneralForm::retranslateUi
void retranslateUi()
Retranslate all elements in the form.
Definition: generalform.cpp:272
GeneralForm::on_statusChanges_stateChanged
void on_statusChanges_stateChanged()
Definition: generalform.cpp:221
recursivesignalblocker.h
Settings::getAutostartInTray
bool getAutostartInTray() const
Definition: settings.cpp:911
settings.h
GeneralForm::on_autoacceptFiles_stateChanged
void on_autoacceptFiles_stateChanged()
Definition: generalform.cpp:237
GeneralForm::on_transComboBox_currentIndexChanged
void on_transComboBox_currentIndexChanged(int index)
Definition: generalform.cpp:177
Settings::getMinimizeToTray
bool getMinimizeToTray() const
Definition: settings.cpp:989
GeneralForm::on_cbSpellChecking_stateChanged
void on_cbSpellChecking_stateChanged()
Definition: generalform.cpp:189
Settings::getAutoAwayTime
int getAutoAwayTime() const
Definition: settings.cpp:1254
Settings::setMinimizeToTray
void setMinimizeToTray(bool newValue)
Definition: settings.cpp:995
Translator::translate
static void translate(const QString &localeName)
Loads the translations according to the settings or locale.
Definition: translator.cpp:39
Translator::unregister
static void unregister(void *owner)
Unregisters all handlers of an owner.
Definition: translator.cpp:103
Settings::getStatusChangeNotificationEnabled
bool getStatusChangeNotificationEnabled() const
Definition: settings.cpp:1015
GeneralForm::on_checkUpdates_stateChanged
void on_checkUpdates_stateChanged()
Definition: generalform.cpp:264
Settings::setAutostartInTray
void setAutostartInTray(bool newValue)
Definition: settings.cpp:969
Settings::setMaxAutoAcceptSize
void setMaxAutoAcceptSize(size_t size)
Definition: settings.cpp:1413
GeneralForm::on_minimizeToTray_stateChanged
void on_minimizeToTray_stateChanged()
Definition: generalform.cpp:216
Settings::getSpellCheckingEnabled
bool getSpellCheckingEnabled() const
Definition: settings.cpp:1041
Settings::setShowGroupJoinLeaveMessages
void setShowGroupJoinLeaveMessages(bool newValue) override
Definition: settings.cpp:1034
Settings::getShowSystemTray
bool getShowSystemTray() const
Definition: settings.cpp:930
Settings::getAutorun
bool getAutorun() const
Definition: settings.cpp:886
SettingsWidget
Definition: settingswidget.h:42
coreav.h
GeneralForm::on_startInTray_stateChanged
void on_startInTray_stateChanged()
Definition: generalform.cpp:200
GeneralForm::GeneralForm
GeneralForm(SettingsWidget *parent)
Definition: generalform.cpp:97
Ui
Definition: filetransferwidget.h:30
Settings::getGlobalAutoAcceptDir
QString getGlobalAutoAcceptDir() const
Definition: settings.cpp:1394
smileypack.h
GeneralForm::bodyUI
Ui::GeneralSettings * bodyUI
Definition: generalform.h:64
GeneralForm::on_lightTrayIcon_stateChanged
void on_lightTrayIcon_stateChanged()
Definition: generalform.cpp:210
Settings::setAutorun
void setAutorun(bool newValue)
Definition: settings.cpp:897
Settings::setShowSystemTray
void setShowSystemTray(bool newValue)
Definition: settings.cpp:936
Settings::getShowGroupJoinLeaveMessages
bool getShowGroupJoinLeaveMessages() const override
Definition: settings.cpp:1028
GeneralForm::on_maxAutoAcceptSizeMB_editingFinished
void on_maxAutoAcceptSizeMB_editingFinished()
Definition: generalform.cpp:256
widget.h
Settings::setLightTrayIcon
void setLightTrayIcon(bool newValue)
Definition: settings.cpp:1008
Settings::setAutoSaveEnabled
void setAutoSaveEnabled(bool newValue)
Definition: settings.cpp:956
Settings::saveGlobal
void saveGlobal()
Asynchronous, saves the global settings.
Definition: settings.cpp:582
Translator::registerHandler
static void registerHandler(const std::function< void()> &, void *owner)
Register a function to be called when the UI needs to be retranslated.
Definition: translator.cpp:93
Settings::setCheckUpdates
void setCheckUpdates(bool newValue)
Definition: settings.cpp:1552
Settings::getInstance
static Settings & getInstance()
Returns the singleton instance.
Definition: settings.cpp:88
GeneralForm::~GeneralForm
~GeneralForm()
Definition: generalform.cpp:171
GeneralForm::updateIcons
void updateIcons()
GeneralForm::on_cbAutorun_stateChanged
void on_cbAutorun_stateChanged()
Definition: generalform.cpp:184
Settings::getCloseToTray
bool getCloseToTray() const
Definition: settings.cpp:976
settingswidget.h
Settings::setCloseToTray
void setCloseToTray(bool newValue)
Definition: settings.cpp:982
core.h
Settings::getTranslation
QString getTranslation() const
Definition: settings.cpp:1106
GeneralForm::on_showSystemTray_stateChanged
void on_showSystemTray_stateChanged()
Definition: generalform.cpp:194
Settings::setStatusChangeNotificationEnabled
void setStatusChangeNotificationEnabled(bool newValue)
Definition: settings.cpp:1021
GeneralForm::on_autoSaveFilesDir_clicked
void on_autoSaveFilesDir_clicked()
Definition: generalform.cpp:242
GenericForm::eventsInit
void eventsInit()
Prevent stealing mouse wheel scroll.
Definition: genericsettings.cpp:54
generalform.h
translator.h
Settings::getAutoSaveEnabled
bool getAutoSaveEnabled() const
Definition: settings.cpp:963
RecursiveSignalBlocker
Recursively blocks all signals from an object and its children.
Definition: recursivesignalblocker.h:27
GeneralForm::on_closeToTray_stateChanged
void on_closeToTray_stateChanged()
Definition: generalform.cpp:205
GenericForm
Definition: genericsettings.h:24
Settings::setTranslation
void setTranslation(const QString &newValue)
Definition: settings.cpp:1112
Settings::getMaxAutoAcceptSize
size_t getMaxAutoAcceptSize() const
Definition: settings.cpp:1407
Settings::setSpellCheckingEnabled
void setSpellCheckingEnabled(bool newValue)
Definition: settings.cpp:1047
Settings::setAutoAwayTime
void setAutoAwayTime(int newValue)
Sets how long the user may stay idle, before online status is set to "away".
Definition: settings.cpp:1265
Settings::getLightTrayIcon
bool getLightTrayIcon() const
Definition: settings.cpp:1002