From ed0616dd910c926d387ec5286db7f6b09a06d770 Mon Sep 17 00:00:00 2001 From: "Tux3 / Mlkj / !Lev.uXFMLA" Date: Sat, 12 Jul 2014 22:58:58 +0200 Subject: [PATCH] Add option to make qTox portable --- settings.cpp | 27 ++++++++++++++++++++++++++- settings.h | 5 +++++ widget/form/settingsform.cpp | 9 +++++++++ widget/form/settingsform.h | 3 ++- 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/settings.cpp b/settings.cpp index 8461e205c..888d840a5 100644 --- a/settings.cpp +++ b/settings.cpp @@ -24,6 +24,7 @@ #include const QString Settings::FILENAME = "settings.ini"; +bool Settings::makeToxPortable{false}; Settings::Settings() : loaded(false) @@ -48,6 +49,10 @@ void Settings::load() return; } + QFile portableSettings(FILENAME); + if (portableSettings.exists()) + makeToxPortable=true; + QString filePath = getSettingsDirPath() + '/' + FILENAME; //if no settings file exist -- use the default one @@ -75,6 +80,7 @@ void Settings::load() s.beginGroup("General"); enableIPv6 = s.value("enableIPv6", true).toBool(); useTranslations = s.value("useTranslations", true).toBool(); + makeToxPortable = s.value("makeToxPortable", false).toBool(); s.endGroup(); s.beginGroup("Widgets"); @@ -106,8 +112,12 @@ void Settings::load() void Settings::save() { QString filePath = getSettingsDirPath() + '/' + FILENAME; + save(filePath); +} - QSettings s(filePath, QSettings::IniFormat); +void Settings::save(QString path) +{ + QSettings s(path, QSettings::IniFormat); s.clear(); @@ -126,6 +136,7 @@ void Settings::save() s.beginGroup("General"); s.setValue("enableIPv6", enableIPv6); s.setValue("useTranslations",useTranslations); + s.setValue("makeToxPortable",makeToxPortable); s.endGroup(); s.beginGroup("Widgets"); @@ -154,6 +165,9 @@ void Settings::save() QString Settings::getSettingsDirPath() { + if (makeToxPortable) + return "."; + // workaround for https://bugreports.qt-project.org/browse/QTBUG-38845 #ifdef Q_OS_WIN return QStandardPaths::writableLocation(QStandardPaths::ConfigLocation); @@ -183,6 +197,17 @@ void Settings::setEnableIPv6(bool newValue) enableIPv6 = newValue; } +bool Settings::getMakeToxPortable() const +{ + return makeToxPortable; +} + +void Settings::setMakeToxPortable(bool newValue) +{ + makeToxPortable = newValue; + save(FILENAME); // Commit to the portable file that we don't want to use it +} + bool Settings::getUseTranslations() const { return useTranslations; diff --git a/settings.h b/settings.h index 275451f43..d4f015635 100644 --- a/settings.h +++ b/settings.h @@ -46,6 +46,9 @@ public: bool getEnableIPv6() const; void setEnableIPv6(bool newValue); + bool getMakeToxPortable() const; + void setMakeToxPortable(bool newValue); + bool getUseTranslations() const; void setUseTranslations(bool newValue); @@ -115,6 +118,7 @@ private: Settings& operator=(const Settings&) = delete; void save(); + void save(QString path); void load(); @@ -129,6 +133,7 @@ private: bool enableIPv6; bool useTranslations; + static bool makeToxPortable; bool enableLogging; bool encryptLogs; diff --git a/widget/form/settingsform.cpp b/widget/form/settingsform.cpp index c79a75a8c..1179497c5 100644 --- a/widget/form/settingsform.cpp +++ b/widget/form/settingsform.cpp @@ -46,6 +46,8 @@ SettingsForm::SettingsForm() enableIPv6.setChecked(Settings::getInstance().getEnableIPv6()); useTranslations.setText(tr("Use translations","Text on a checkbox to enable translations")); useTranslations.setChecked(Settings::getInstance().getUseTranslations()); + makeToxPortable.setText(tr("Make Tox portable","Text on a checkbox to make qTox a portable application")); + makeToxPortable.setChecked(Settings::getInstance().getMakeToxPortable()); main->setLayout(&layout); layout.addWidget(&nameLabel); @@ -57,6 +59,7 @@ SettingsForm::SettingsForm() layout.addWidget(&videoTest); layout.addWidget(&enableIPv6); layout.addWidget(&useTranslations); + layout.addWidget(&makeToxPortable); layout.addStretch(); head->setLayout(&headLayout); @@ -65,6 +68,7 @@ SettingsForm::SettingsForm() connect(&videoTest, SIGNAL(clicked()), this, SLOT(onTestVideoClicked())); connect(&enableIPv6, SIGNAL(stateChanged(int)), this, SLOT(onEnableIPv6Updated())); connect(&useTranslations, SIGNAL(stateChanged(int)), this, SLOT(onUseTranslationUpdated())); + connect(&makeToxPortable, SIGNAL(stateChanged(int)), this, SLOT(onMakeToxPortableUpdated())); connect(&idLabel, SIGNAL(clicked()), this, SLOT(copyIdClicked())); } @@ -107,3 +111,8 @@ void SettingsForm::onUseTranslationUpdated() { Settings::getInstance().setUseTranslations(useTranslations.isChecked()); } + +void SettingsForm::onMakeToxPortableUpdated() +{ + Settings::getInstance().setMakeToxPortable(makeToxPortable.isChecked()); +} diff --git a/widget/form/settingsform.h b/widget/form/settingsform.h index db66a410a..3342c5667 100644 --- a/widget/form/settingsform.h +++ b/widget/form/settingsform.h @@ -46,6 +46,7 @@ private slots: void onTestVideoClicked(); void onEnableIPv6Updated(); void onUseTranslationUpdated(); + void onMakeToxPortableUpdated(); void copyIdClicked(); private: @@ -53,7 +54,7 @@ private: QTextEdit id; ClickableLabel idLabel; QPushButton videoTest; - QCheckBox enableIPv6, useTranslations; + QCheckBox enableIPv6, useTranslations, makeToxPortable; QVBoxLayout layout, headLayout; QWidget *main, *head;