qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
advancedform.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 "advancedform.h"
21 #include "ui_advancedsettings.h"
22 
23 #include <QApplication>
24 #include <QClipboard>
25 #include <QDir>
26 #include <QFileDialog>
27 #include <QMessageBox>
28 #include <QProcess>
29 
30 #include "src/model/status.h"
33 #include "src/widget/gui.h"
35 #include "src/widget/translator.h"
36 
45  : GenericForm(QPixmap(":/img/settings/general.png"))
46  , bodyUI(new Ui::AdvancedSettings)
47 {
48  bodyUI->setupUi(this);
49 
50  // block all child signals during initialization
51  const RecursiveSignalBlocker signalBlocker(this);
52 
54  bodyUI->cbEnableIPv6->setChecked(s.getEnableIPv6());
55  bodyUI->cbMakeToxPortable->setChecked(Settings::getInstance().getMakeToxPortable());
56  bodyUI->proxyAddr->setText(s.getProxyAddr());
57  quint16 port = s.getProxyPort();
58  if (port > 0) {
59  bodyUI->proxyPort->setValue(port);
60  }
61 
62  int index = static_cast<int>(s.getProxyType());
63  bodyUI->proxyType->setCurrentIndex(index);
65  const bool udpEnabled = !s.getForceTCP() && (s.getProxyType() == Settings::ProxyType::ptNone);
66  bodyUI->cbEnableUDP->setChecked(udpEnabled);
67  bodyUI->cbEnableLanDiscovery->setChecked(s.getEnableLanDiscovery() && udpEnabled);
68  bodyUI->cbEnableLanDiscovery->setEnabled(udpEnabled);
69 
70  QString warningBody = tr("Unless you %1 know what you are doing, "
71  "please do %2 change anything here. Changes "
72  "made here may lead to problems with qTox, and even "
73  "to loss of your data, e.g. history."
74  "%3")
75  .arg(QString("<b>%1</b>").arg(tr("really")))
76  .arg(QString("<b>%1</b>").arg(tr("not")))
77  .arg(QString("<p>%1</p>").arg(tr("Changes here are applied only after restarting qTox.")));
78 
79  QString warning = QString("<div style=\"color:#ff0000;\">"
80  "<p><b>%1</b></p><p>%2</p></div>")
81  .arg(tr("IMPORTANT NOTE"))
82  .arg(warningBody);
83 
84  bodyUI->warningLabel->setText(warning);
85 
86  eventsInit();
88 }
89 
91 {
93  delete bodyUI;
94 }
95 
97 {
98  Settings::getInstance().setMakeToxPortable(bodyUI->cbMakeToxPortable->isChecked());
99 }
101 {
102  QString savefile =
103  QFileDialog::getSaveFileName(Q_NULLPTR, tr("Save file"), QString{}, tr("Logs (*.log)"));
104 
105  if (savefile.isNull() || savefile.isEmpty()) {
106  qDebug() << "Debug log save file was not properly chosen";
107  return;
108  }
109 
110  QString logFileDir = Settings::getInstance().getPaths().getAppCacheDirPath();
111  QString logfile = logFileDir + "qtox.log";
112 
113  QFile file(logfile);
114  if (file.exists()) {
115  qDebug() << "Found debug log for copying";
116  } else {
117  qDebug() << "No debug file found";
118  return;
119  }
120 
121  if (QFile::copy(logfile, savefile))
122  qDebug() << "Successfully copied to: " << savefile;
123  else
124  qDebug() << "File was not copied";
125 }
126 
128 {
129  QString logFileDir = Settings::getInstance().getPaths().getAppCacheDirPath();
130  QString logfile = logFileDir + "qtox.log";
131 
132  QFile file(logfile);
133  if (!file.exists()) {
134  qDebug() << "No debug file found";
135  return;
136  }
137 
138  QClipboard* clipboard = QApplication::clipboard();
139  if (clipboard) {
140  QString debugtext;
141  if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
142  QTextStream in(&file);
143  debugtext = in.readAll();
144  file.close();
145  } else {
146  qDebug() << "Unable to open file for copying to clipboard";
147  return;
148  }
149 
150  clipboard->setText(debugtext, QClipboard::Clipboard);
151  qDebug() << "Debug log copied to clipboard";
152  } else {
153  qDebug() << "Unable to access clipboard";
154  }
155 }
156 
158 {
159  const QString titile = tr("Reset settings");
160  bool result = GUI::askQuestion(titile, tr("All settings will be reset to default. Are you sure?"),
161  tr("Yes"), tr("No"));
162 
163  if (!result)
164  return;
165 
167  GUI::showInfo(titile, "Changes will take effect after restart");
168 }
169 
171 {
172  Settings::getInstance().setEnableIPv6(bodyUI->cbEnableIPv6->isChecked());
173 }
174 
176 {
177  const bool enableUdp = bodyUI->cbEnableUDP->isChecked();
178  Settings::getInstance().setForceTCP(!enableUdp);
179  const bool enableLanDiscovery = Settings::getInstance().getEnableLanDiscovery();
180  bodyUI->cbEnableLanDiscovery->setEnabled(enableUdp);
181  bodyUI->cbEnableLanDiscovery->setChecked(enableUdp && enableLanDiscovery);
182 }
183 
185 {
186  Settings::getInstance().setEnableLanDiscovery(bodyUI->cbEnableLanDiscovery->isChecked());
187 }
188 
190 {
191  Settings::getInstance().setProxyAddr(bodyUI->proxyAddr->text());
192 }
193 
195 {
196  if (port <= 0) {
197  port = 0;
198  }
199 
201 }
202 
204 {
205  Settings::ProxyType proxytype = static_cast<Settings::ProxyType>(index);
206  const bool proxyEnabled = proxytype != Settings::ProxyType::ptNone;
207 
208  bodyUI->proxyAddr->setEnabled(proxyEnabled);
209  bodyUI->proxyPort->setEnabled(proxyEnabled);
210  // enabling UDP and proxy can be a privacy issue
211  bodyUI->cbEnableUDP->setEnabled(!proxyEnabled);
212  bodyUI->cbEnableUDP->setChecked(!proxyEnabled);
213 
214  Settings::getInstance().setProxyType(proxytype);
215 }
216 
221 {
222  int proxyType = bodyUI->proxyType->currentIndex();
223  bodyUI->retranslateUi(this);
224  bodyUI->proxyType->setCurrentIndex(proxyType);
225 }
Settings::setProxyType
void setProxyType(ICoreSettings::ProxyType type) override
Definition: settings.cpp:1177
profile.h
Settings
Definition: settings.h:51
recursivesignalblocker.h
AdvancedForm::on_proxyPort_valueChanged
void on_proxyPort_valueChanged(int port)
Definition: advancedform.cpp:194
settings.h
ICoreSettings::ProxyType
ProxyType
Definition: icoresettings.h:30
Settings::getEnableLanDiscovery
bool getEnableLanDiscovery() const override
Definition: settings.cpp:1132
Settings::setProxyPort
void setProxyPort(quint16 port) override
Definition: settings.cpp:1203
AdvancedForm::on_cbEnableIPv6_stateChanged
void on_cbEnableIPv6_stateChanged()
Definition: advancedform.cpp:170
AdvancedForm::on_proxyType_currentIndexChanged
void on_proxyType_currentIndexChanged(int index)
Definition: advancedform.cpp:203
HistMessageContentType::file
@ file
AdvancedForm::on_cbMakeToxPortable_stateChanged
void on_cbMakeToxPortable_stateChanged()
Definition: advancedform.cpp:96
AdvancedForm::~AdvancedForm
~AdvancedForm()
Definition: advancedform.cpp:90
Settings::getForceTCP
bool getForceTCP() const override
Definition: settings.cpp:1119
Translator::unregister
static void unregister(void *owner)
Unregisters all handlers of an owner.
Definition: translator.cpp:103
Settings::setForceTCP
void setForceTCP(bool enabled) override
Definition: settings.cpp:1125
AdvancedForm::on_cbEnableLanDiscovery_stateChanged
void on_cbEnableLanDiscovery_stateChanged()
Definition: advancedform.cpp:184
AdvancedForm::on_cbEnableUDP_stateChanged
void on_cbEnableUDP_stateChanged()
Definition: advancedform.cpp:175
GUI::askQuestion
static bool askQuestion(const QString &title, const QString &msg, bool defaultAns=false, bool warning=true, bool yesno=true)
Asks the user a question with Ok/Cancel or Yes/No buttons.
Definition: gui.cpp:169
advancedform.h
Settings::resetToDefault
void resetToDefault()
Definition: settings.cpp:565
AdvancedForm::bodyUI
Ui::AdvancedSettings * bodyUI
Definition: advancedform.h:60
AdvancedForm::retranslateUi
void retranslateUi()
Retranslate all elements in the form.
Definition: advancedform.cpp:220
Settings::setEnableIPv6
void setEnableIPv6(bool enabled) override
Definition: settings.cpp:858
Settings::setProxyAddr
void setProxyAddr(const QString &address) override
Definition: settings.cpp:1190
Ui
Definition: filetransferwidget.h:30
AdvancedForm::on_btnExportLog_clicked
void on_btnExportLog_clicked()
Definition: advancedform.cpp:100
GUI::showInfo
static void showInfo(const QString &title, const QString &msg)
Show some text to the user.
Definition: gui.cpp:115
Settings::getProxyPort
quint16 getProxyPort() const override
Definition: settings.cpp:1197
Settings::setEnableLanDiscovery
void setEnableLanDiscovery(bool enabled) override
Definition: settings.cpp:1138
Settings::getPaths
Paths & getPaths()
Definition: settings.cpp:834
AdvancedForm::on_resetButton_clicked
void on_resetButton_clicked()
Definition: advancedform.cpp:157
AdvancedForm::on_proxyAddr_editingFinished
void on_proxyAddr_editingFinished()
Definition: advancedform.cpp:189
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
ICoreSettings::ProxyType::ptNone
@ ptNone
Settings::getInstance
static Settings & getInstance()
Returns the singleton instance.
Definition: settings.cpp:88
AdvancedForm::AdvancedForm
AdvancedForm()
Definition: advancedform.cpp:44
Settings::getProxyAddr
QString getProxyAddr() const override
Definition: settings.cpp:1184
Paths::getAppCacheDirPath
QString getAppCacheDirPath() const
Get path to directory, where the application cache are stored.
Definition: paths.cpp:346
AdvancedForm::on_btnCopyDebug_clicked
void on_btnCopyDebug_clicked()
Definition: advancedform.cpp:127
Settings::getEnableIPv6
bool getEnableIPv6() const override
Definition: settings.cpp:852
gui.h
GenericForm::eventsInit
void eventsInit()
Prevent stealing mouse wheel scroll.
Definition: genericsettings.cpp:54
translator.h
RecursiveSignalBlocker
Recursively blocks all signals from an object and its children.
Definition: recursivesignalblocker.h:27
Settings::getProxyType
ICoreSettings::ProxyType getProxyType() const override
Definition: settings.cpp:1171
GenericForm
Definition: genericsettings.h:24
Settings::setMakeToxPortable
void setMakeToxPortable(bool newValue)
Definition: settings.cpp:871
status.h