1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Add option to make qTox portable

This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-07-12 22:58:58 +02:00
parent 171c1f0a3f
commit ed0616dd91
4 changed files with 42 additions and 2 deletions

View File

@ -24,6 +24,7 @@
#include <QDebug> #include <QDebug>
const QString Settings::FILENAME = "settings.ini"; const QString Settings::FILENAME = "settings.ini";
bool Settings::makeToxPortable{false};
Settings::Settings() : Settings::Settings() :
loaded(false) loaded(false)
@ -48,6 +49,10 @@ void Settings::load()
return; return;
} }
QFile portableSettings(FILENAME);
if (portableSettings.exists())
makeToxPortable=true;
QString filePath = getSettingsDirPath() + '/' + FILENAME; QString filePath = getSettingsDirPath() + '/' + FILENAME;
//if no settings file exist -- use the default one //if no settings file exist -- use the default one
@ -75,6 +80,7 @@ void Settings::load()
s.beginGroup("General"); s.beginGroup("General");
enableIPv6 = s.value("enableIPv6", true).toBool(); enableIPv6 = s.value("enableIPv6", true).toBool();
useTranslations = s.value("useTranslations", true).toBool(); useTranslations = s.value("useTranslations", true).toBool();
makeToxPortable = s.value("makeToxPortable", false).toBool();
s.endGroup(); s.endGroup();
s.beginGroup("Widgets"); s.beginGroup("Widgets");
@ -106,8 +112,12 @@ void Settings::load()
void Settings::save() void Settings::save()
{ {
QString filePath = getSettingsDirPath() + '/' + FILENAME; QString filePath = getSettingsDirPath() + '/' + FILENAME;
save(filePath);
}
QSettings s(filePath, QSettings::IniFormat); void Settings::save(QString path)
{
QSettings s(path, QSettings::IniFormat);
s.clear(); s.clear();
@ -126,6 +136,7 @@ void Settings::save()
s.beginGroup("General"); s.beginGroup("General");
s.setValue("enableIPv6", enableIPv6); s.setValue("enableIPv6", enableIPv6);
s.setValue("useTranslations",useTranslations); s.setValue("useTranslations",useTranslations);
s.setValue("makeToxPortable",makeToxPortable);
s.endGroup(); s.endGroup();
s.beginGroup("Widgets"); s.beginGroup("Widgets");
@ -154,6 +165,9 @@ void Settings::save()
QString Settings::getSettingsDirPath() QString Settings::getSettingsDirPath()
{ {
if (makeToxPortable)
return ".";
// workaround for https://bugreports.qt-project.org/browse/QTBUG-38845 // workaround for https://bugreports.qt-project.org/browse/QTBUG-38845
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
return QStandardPaths::writableLocation(QStandardPaths::ConfigLocation); return QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
@ -183,6 +197,17 @@ void Settings::setEnableIPv6(bool newValue)
enableIPv6 = 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 bool Settings::getUseTranslations() const
{ {
return useTranslations; return useTranslations;

View File

@ -46,6 +46,9 @@ public:
bool getEnableIPv6() const; bool getEnableIPv6() const;
void setEnableIPv6(bool newValue); void setEnableIPv6(bool newValue);
bool getMakeToxPortable() const;
void setMakeToxPortable(bool newValue);
bool getUseTranslations() const; bool getUseTranslations() const;
void setUseTranslations(bool newValue); void setUseTranslations(bool newValue);
@ -115,6 +118,7 @@ private:
Settings& operator=(const Settings&) = delete; Settings& operator=(const Settings&) = delete;
void save(); void save();
void save(QString path);
void load(); void load();
@ -129,6 +133,7 @@ private:
bool enableIPv6; bool enableIPv6;
bool useTranslations; bool useTranslations;
static bool makeToxPortable;
bool enableLogging; bool enableLogging;
bool encryptLogs; bool encryptLogs;

View File

@ -46,6 +46,8 @@ SettingsForm::SettingsForm()
enableIPv6.setChecked(Settings::getInstance().getEnableIPv6()); enableIPv6.setChecked(Settings::getInstance().getEnableIPv6());
useTranslations.setText(tr("Use translations","Text on a checkbox to enable translations")); useTranslations.setText(tr("Use translations","Text on a checkbox to enable translations"));
useTranslations.setChecked(Settings::getInstance().getUseTranslations()); 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); main->setLayout(&layout);
layout.addWidget(&nameLabel); layout.addWidget(&nameLabel);
@ -57,6 +59,7 @@ SettingsForm::SettingsForm()
layout.addWidget(&videoTest); layout.addWidget(&videoTest);
layout.addWidget(&enableIPv6); layout.addWidget(&enableIPv6);
layout.addWidget(&useTranslations); layout.addWidget(&useTranslations);
layout.addWidget(&makeToxPortable);
layout.addStretch(); layout.addStretch();
head->setLayout(&headLayout); head->setLayout(&headLayout);
@ -65,6 +68,7 @@ SettingsForm::SettingsForm()
connect(&videoTest, SIGNAL(clicked()), this, SLOT(onTestVideoClicked())); connect(&videoTest, SIGNAL(clicked()), this, SLOT(onTestVideoClicked()));
connect(&enableIPv6, SIGNAL(stateChanged(int)), this, SLOT(onEnableIPv6Updated())); connect(&enableIPv6, SIGNAL(stateChanged(int)), this, SLOT(onEnableIPv6Updated()));
connect(&useTranslations, SIGNAL(stateChanged(int)), this, SLOT(onUseTranslationUpdated())); connect(&useTranslations, SIGNAL(stateChanged(int)), this, SLOT(onUseTranslationUpdated()));
connect(&makeToxPortable, SIGNAL(stateChanged(int)), this, SLOT(onMakeToxPortableUpdated()));
connect(&idLabel, SIGNAL(clicked()), this, SLOT(copyIdClicked())); connect(&idLabel, SIGNAL(clicked()), this, SLOT(copyIdClicked()));
} }
@ -107,3 +111,8 @@ void SettingsForm::onUseTranslationUpdated()
{ {
Settings::getInstance().setUseTranslations(useTranslations.isChecked()); Settings::getInstance().setUseTranslations(useTranslations.isChecked());
} }
void SettingsForm::onMakeToxPortableUpdated()
{
Settings::getInstance().setMakeToxPortable(makeToxPortable.isChecked());
}

View File

@ -46,6 +46,7 @@ private slots:
void onTestVideoClicked(); void onTestVideoClicked();
void onEnableIPv6Updated(); void onEnableIPv6Updated();
void onUseTranslationUpdated(); void onUseTranslationUpdated();
void onMakeToxPortableUpdated();
void copyIdClicked(); void copyIdClicked();
private: private:
@ -53,7 +54,7 @@ private:
QTextEdit id; QTextEdit id;
ClickableLabel idLabel; ClickableLabel idLabel;
QPushButton videoTest; QPushButton videoTest;
QCheckBox enableIPv6, useTranslations; QCheckBox enableIPv6, useTranslations, makeToxPortable;
QVBoxLayout layout, headLayout; QVBoxLayout layout, headLayout;
QWidget *main, *head; QWidget *main, *head;