mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
feat(settings): Added reset settings button
This commit is contained in:
parent
fb4aa4c8f6
commit
9c9f1c11d1
1
qtox.pro
1
qtox.pro
|
@ -432,6 +432,7 @@ SOURCES += \
|
|||
src/widget/form/settings/privacyform.cpp \
|
||||
src/widget/form/settings/avform.cpp \
|
||||
src/widget/form/settings/userinterfaceform.cpp \
|
||||
src/widget/form/settings/genericsettings.cpp \
|
||||
src/widget/form/profileform.cpp \
|
||||
src/widget/form/filesform.cpp \
|
||||
src/widget/tool/chattextedit.cpp \
|
||||
|
|
|
@ -391,6 +391,20 @@ void Settings::loadPersonal(Profile* profile)
|
|||
ps.endGroup();
|
||||
}
|
||||
|
||||
void Settings::resetToDefault()
|
||||
{
|
||||
// To stop saving
|
||||
loaded = false;
|
||||
|
||||
// Remove file with profile settings
|
||||
QDir dir(getSettingsDirPath());
|
||||
Profile *profile = Nexus::getProfile();
|
||||
QString localPath = dir.filePath(profile->getName() + ".ini");
|
||||
QFile local(localPath);
|
||||
if (local.exists())
|
||||
local.remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Asynchronous, saves the global settings.
|
||||
*/
|
||||
|
@ -400,6 +414,9 @@ void Settings::saveGlobal()
|
|||
return (void) QMetaObject::invokeMethod(&getInstance(), "saveGlobal");
|
||||
|
||||
QMutexLocker locker{&bigLock};
|
||||
if (!loaded)
|
||||
return;
|
||||
|
||||
QString path = getSettingsDirPath() + globalSettingsFile;
|
||||
qDebug() << "Saving global settings at " + path;
|
||||
|
||||
|
@ -542,6 +559,8 @@ void Settings::savePersonal(QString profileName, const QString &password)
|
|||
Q_ARG(QString, profileName), Q_ARG(QString, password));
|
||||
|
||||
QMutexLocker locker{&bigLock};
|
||||
if (!loaded)
|
||||
return;
|
||||
|
||||
QString path = getSettingsDirPath() + profileName + ".ini";
|
||||
|
||||
|
|
|
@ -149,6 +149,8 @@ public:
|
|||
void loadPersonal();
|
||||
void loadPersonal(Profile *profile);
|
||||
|
||||
void resetToDefault();
|
||||
|
||||
struct Request
|
||||
{
|
||||
QString address;
|
||||
|
|
|
@ -47,6 +47,7 @@ AboutForm::AboutForm()
|
|||
progressTimer->setSingleShot(false);
|
||||
connect(progressTimer, &QTimer::timeout, this, &AboutForm::showUpdateProgress);
|
||||
|
||||
eventsInit();
|
||||
Translator::registerHandler(std::bind(&AboutForm::retranslateUi, this), this);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,10 @@
|
|||
#include "advancedform.h"
|
||||
#include "ui_advancedsettings.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QMessageBox>
|
||||
#include <QProcess>
|
||||
#include <QApplication>
|
||||
|
||||
#include "src/core/core.h"
|
||||
#include "src/core/coreav.h"
|
||||
|
@ -29,6 +32,7 @@
|
|||
#include "src/persistence/settings.h"
|
||||
#include "src/persistence/db/plaindb.h"
|
||||
#include "src/persistence/profile.h"
|
||||
#include "src/widget/gui.h"
|
||||
#include "src/widget/translator.h"
|
||||
|
||||
AdvancedForm::AdvancedForm()
|
||||
|
@ -65,9 +69,7 @@ AdvancedForm::AdvancedForm()
|
|||
connect(bodyUI->proxyPort, valueChanged, this, &AdvancedForm::onProxyPortEdited);
|
||||
connect(bodyUI->reconnectButton, &QPushButton::clicked, this, &AdvancedForm::onReconnectClicked);
|
||||
|
||||
for (QCheckBox *cb : findChildren<QCheckBox*>()) // this one is to allow scrolling on checkboxes
|
||||
cb->installEventFilter(this);
|
||||
|
||||
eventsInit();
|
||||
Translator::registerHandler(std::bind(&AdvancedForm::retranslateUi, this), this);
|
||||
}
|
||||
|
||||
|
@ -84,6 +86,16 @@ void AdvancedForm::onMakeToxPortableUpdated()
|
|||
|
||||
void AdvancedForm::resetToDefault()
|
||||
{
|
||||
const QString titile = tr("Reset settings");
|
||||
bool result = GUI::askQuestion(titile,
|
||||
tr("All settings will be reset to default. Are you sure?"),
|
||||
tr("Yes"), tr("No"));
|
||||
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
Settings::getInstance().resetToDefault();
|
||||
GUI::showInfo(titile, "Changes will take effect after restart");
|
||||
}
|
||||
|
||||
void AdvancedForm::onEnableIPv6Updated()
|
||||
|
|
|
@ -78,11 +78,7 @@ AVForm::AVForm()
|
|||
microphoneSlider->setTracking(false);
|
||||
microphoneSlider->installEventFilter(this);
|
||||
|
||||
for (QComboBox* cb : findChildren<QComboBox*>())
|
||||
{
|
||||
cb->installEventFilter(this);
|
||||
cb->setFocusPolicy(Qt::StrongFocus);
|
||||
}
|
||||
eventsInit();
|
||||
|
||||
QDesktopWidget *desktop = QApplication::desktop();
|
||||
connect(desktop, &QDesktopWidget::resized, this, &AVForm::rescanDevices);
|
||||
|
@ -567,18 +563,6 @@ void AVForm::killVideoSurface()
|
|||
camVideoSurface = nullptr;
|
||||
}
|
||||
|
||||
bool AVForm::eventFilter(QObject *o, QEvent *e)
|
||||
{
|
||||
if ((e->type() == QEvent::Wheel) &&
|
||||
(qobject_cast<QComboBox*>(o) || qobject_cast<QAbstractSpinBox*>(o) ||
|
||||
qobject_cast<QSlider*>(o)))
|
||||
{
|
||||
e->ignore();
|
||||
return true;
|
||||
}
|
||||
return QWidget::eventFilter(o, e);
|
||||
}
|
||||
|
||||
void AVForm::retranslateUi()
|
||||
{
|
||||
Ui::AVForm::retranslateUi(this);
|
||||
|
|
|
@ -74,7 +74,6 @@ protected:
|
|||
void updateVideoModes(int curIndex);
|
||||
|
||||
private:
|
||||
bool eventFilter(QObject *o, QEvent *e) final override;
|
||||
void hideEvent(QHideEvent* event) final override;
|
||||
void showEvent(QShowEvent*event) final override;
|
||||
void open(const QString &devName, const VideoMode &mode);
|
||||
|
|
|
@ -164,30 +164,12 @@ GeneralForm::GeneralForm(SettingsWidget *myParent)
|
|||
connect(bodyUI->autoSaveFilesDir, &QPushButton::clicked, this, &GeneralForm::onAutoSaveDirChange);
|
||||
connect(bodyUI->autoacceptFiles, &QCheckBox::stateChanged, this, &GeneralForm::onAutoAcceptFileChange);
|
||||
|
||||
// prevent stealing mouse wheel scroll
|
||||
// scrolling event won't be transmitted to comboboxes or qspinboxes when scrolling
|
||||
// you can scroll through general settings without accidentially changing theme/skin/icons etc.
|
||||
// @see GeneralForm::eventFilter(QObject *o, QEvent *e) at the bottom of this file for more
|
||||
for (QComboBox *cb : findChildren<QComboBox*>())
|
||||
{
|
||||
cb->installEventFilter(this);
|
||||
cb->setFocusPolicy(Qt::StrongFocus);
|
||||
}
|
||||
|
||||
for (QSpinBox *sp : findChildren<QSpinBox*>())
|
||||
{
|
||||
sp->installEventFilter(this);
|
||||
sp->setFocusPolicy(Qt::WheelFocus);
|
||||
}
|
||||
|
||||
for (QCheckBox *cb : findChildren<QCheckBox*>()) // this one is to allow scrolling on checkboxes
|
||||
cb->installEventFilter(this);
|
||||
|
||||
#ifndef QTOX_PLATFORM_EXT
|
||||
bodyUI->autoAwayLabel->setEnabled(false); // these don't seem to change the appearance of the widgets,
|
||||
bodyUI->autoAwaySpinBox->setEnabled(false); // though they are unusable
|
||||
#endif
|
||||
|
||||
eventsInit();
|
||||
Translator::registerHandler(std::bind(&GeneralForm::retranslateUi, this), this);
|
||||
}
|
||||
|
||||
|
@ -287,17 +269,6 @@ void GeneralForm::onCheckUpdateChanged()
|
|||
Settings::getInstance().setCheckUpdates(bodyUI->checkUpdates->isChecked());
|
||||
}
|
||||
|
||||
bool GeneralForm::eventFilter(QObject *o, QEvent *e)
|
||||
{
|
||||
if ((e->type() == QEvent::Wheel) &&
|
||||
(qobject_cast<QComboBox*>(o) || qobject_cast<QAbstractSpinBox*>(o) || qobject_cast<QCheckBox*>(o)))
|
||||
{
|
||||
e->ignore();
|
||||
return true;
|
||||
}
|
||||
return QWidget::eventFilter(o, e);
|
||||
}
|
||||
|
||||
void GeneralForm::retranslateUi()
|
||||
{
|
||||
bodyUI->retranslateUi(this);
|
||||
|
|
|
@ -63,9 +63,6 @@ private:
|
|||
private:
|
||||
Ui::GeneralSettings *bodyUI;
|
||||
SettingsWidget *parent;
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *o, QEvent *e) final override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
51
src/widget/form/settings/genericsettings.cpp
Normal file
51
src/widget/form/settings/genericsettings.cpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
#include "genericsettings.h"
|
||||
|
||||
#include <QEvent>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QSpinBox>
|
||||
|
||||
GenericForm::GenericForm(const QPixmap &icon)
|
||||
: formIcon(icon)
|
||||
{
|
||||
}
|
||||
|
||||
QPixmap GenericForm::getFormIcon()
|
||||
{
|
||||
return formIcon;
|
||||
}
|
||||
|
||||
void GenericForm::eventsInit()
|
||||
{
|
||||
// prevent stealing mouse wheel scroll
|
||||
// scrolling event won't be transmitted to comboboxes or qspinboxes when scrolling
|
||||
// you can scroll through general settings without accidentially changing theme/skin/icons etc.
|
||||
// @see GenericForm::eventFilter(QObject *o, QEvent *e) at the bottom of this file for more
|
||||
for (QComboBox *cb : findChildren<QComboBox*>())
|
||||
{
|
||||
cb->installEventFilter(this);
|
||||
cb->setFocusPolicy(Qt::StrongFocus);
|
||||
}
|
||||
|
||||
for (QSpinBox *sp : findChildren<QSpinBox*>())
|
||||
{
|
||||
sp->installEventFilter(this);
|
||||
sp->setFocusPolicy(Qt::WheelFocus);
|
||||
}
|
||||
|
||||
for (QCheckBox *cb : findChildren<QCheckBox*>()) // this one is to allow scrolling on checkboxes
|
||||
cb->installEventFilter(this);
|
||||
}
|
||||
|
||||
bool GenericForm::eventFilter(QObject *o, QEvent *e)
|
||||
{
|
||||
if ((e->type() == QEvent::Wheel) &&
|
||||
(qobject_cast<QComboBox*>(o) ||
|
||||
qobject_cast<QAbstractSpinBox*>(o) ||
|
||||
qobject_cast<QCheckBox*>(o)))
|
||||
{
|
||||
e->ignore();
|
||||
return true;
|
||||
}
|
||||
return QWidget::eventFilter(o, e);
|
||||
}
|
|
@ -24,14 +24,15 @@ class GenericForm : public QWidget
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GenericForm(const QPixmap &icon) : formIcon(icon) {;}
|
||||
explicit GenericForm(const QPixmap &icon);
|
||||
virtual ~GenericForm() {}
|
||||
|
||||
virtual QString getFormName() = 0;
|
||||
QPixmap getFormIcon()
|
||||
{
|
||||
return formIcon;
|
||||
}
|
||||
QPixmap getFormIcon();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *o, QEvent *e) final override;
|
||||
void eventsInit();
|
||||
|
||||
protected:
|
||||
QPixmap formIcon;
|
||||
|
|
|
@ -51,6 +51,7 @@ PrivacyForm::PrivacyForm()
|
|||
connect(bodyUI->randomNosapamButton, SIGNAL(clicked()), this, SLOT(generateRandomNospam()));
|
||||
connect(bodyUI->nospamLineEdit, SIGNAL(textChanged(QString)), this, SLOT(onNospamEdit()));
|
||||
|
||||
eventsInit();
|
||||
Translator::registerHandler(std::bind(&PrivacyForm::retranslateUi, this), this);
|
||||
}
|
||||
|
||||
|
|
|
@ -167,27 +167,7 @@ UserInterfaceForm::UserInterfaceForm(SettingsWidget* myParent) :
|
|||
connect(bodyUI->dateFormats, currentIndexChanged, this, &UserInterfaceForm::onDateFormatSelected);
|
||||
|
||||
|
||||
// prevent stealing mouse wheel scroll
|
||||
// scrolling event won't be transmitted to comboboxes or qspinboxes when scrolling
|
||||
// you can scroll through general settings without accidentially changing theme/skin/icons etc.
|
||||
// @see UserInterfaceForm::eventFilter(QObject *o, QEvent *e) at the bottom of this file for more
|
||||
for (QComboBox *cb : findChildren<QComboBox*>())
|
||||
{
|
||||
cb->installEventFilter(this);
|
||||
cb->setFocusPolicy(Qt::StrongFocus);
|
||||
}
|
||||
|
||||
for (QSpinBox *sp : findChildren<QSpinBox*>())
|
||||
{
|
||||
sp->installEventFilter(this);
|
||||
sp->setFocusPolicy(Qt::WheelFocus);
|
||||
}
|
||||
|
||||
for (QCheckBox *cb : findChildren<QCheckBox*>()) // this one is to allow scrolling on checkboxes
|
||||
{
|
||||
cb->installEventFilter(this);
|
||||
}
|
||||
|
||||
eventsInit();
|
||||
Translator::registerHandler(std::bind(&UserInterfaceForm::retranslateUi, this), this);
|
||||
}
|
||||
|
||||
|
@ -368,14 +348,3 @@ void UserInterfaceForm::on_txtChatFontSize_valueChanged(int px)
|
|||
s.setChatMessageFont(tmpFont);
|
||||
}
|
||||
}
|
||||
|
||||
bool UserInterfaceForm::eventFilter(QObject *o, QEvent *e)
|
||||
{
|
||||
if ((e->type() == QEvent::Wheel) &&
|
||||
(qobject_cast<QComboBox*>(o) || qobject_cast<QAbstractSpinBox*>(o) || qobject_cast<QCheckBox*>(o)))
|
||||
{
|
||||
e->ignore();
|
||||
return true;
|
||||
}
|
||||
return QWidget::eventFilter(o, e);
|
||||
}
|
||||
|
|
|
@ -63,9 +63,6 @@ private:
|
|||
QList<QLabel*> smileLabels;
|
||||
SettingsWidget* parent;
|
||||
Ui::UserInterfaceSettings *bodyUI;
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *o, QEvent *e) final override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user