Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
feat(settings): Added reset settings button
Browse files Browse the repository at this point in the history
  • Loading branch information
Diadlo committed Aug 26, 2016
1 parent fb4aa4c commit 9c9f1c1
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 94 deletions.
1 change: 1 addition & 0 deletions qtox.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
19 changes: 19 additions & 0 deletions src/persistence/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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;

Expand Down Expand Up @@ -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";

Expand Down
2 changes: 2 additions & 0 deletions src/persistence/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ class Settings : public QObject
void loadPersonal();
void loadPersonal(Profile *profile);

void resetToDefault();

struct Request
{
QString address;
Expand Down
1 change: 1 addition & 0 deletions src/widget/form/settings/aboutform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
18 changes: 15 additions & 3 deletions src/widget/form/settings/advancedform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()
Expand Down Expand Up @@ -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);
}

Expand All @@ -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()
Expand Down
18 changes: 1 addition & 17 deletions src/widget/form/settings/avform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/widget/form/settings/avform.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ private slots:
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);
Expand Down
31 changes: 1 addition & 30 deletions src/widget/form/settings/generalform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions src/widget/form/settings/generalform.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ private slots:
private:
Ui::GeneralSettings *bodyUI;
SettingsWidget *parent;

protected:
bool eventFilter(QObject *o, QEvent *e) final override;
};

#endif
51 changes: 51 additions & 0 deletions src/widget/form/settings/genericsettings.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
11 changes: 6 additions & 5 deletions src/widget/form/settings/genericsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/widget/form/settings/privacyform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
33 changes: 1 addition & 32 deletions src/widget/form/settings/userinterfaceform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
3 changes: 0 additions & 3 deletions src/widget/form/settings/userinterfaceform.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ private slots:
QList<QLabel*> smileLabels;
SettingsWidget* parent;
Ui::UserInterfaceSettings *bodyUI;

protected:
bool eventFilter(QObject *o, QEvent *e) final override;
};

#endif

0 comments on commit 9c9f1c1

Please sign in to comment.