Skip to content

Commit bc490a2

Browse files
committed
GUI - store qsettings ini file in ~/.sonic-pi/config rather than in QT's system default location
1 parent 87de19a commit bc490a2

File tree

2 files changed

+95
-95
lines changed

2 files changed

+95
-95
lines changed

app/gui/qt/mainwindow.cpp

Lines changed: 92 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ MainWindow::MainWindow(QApplication& app, bool i18n, QSplashScreen* splash)
127127
latest_version_num = 0;
128128
this->splash = splash;
129129
this->i18n = i18n;
130+
QString settings_path = sonicPiConfigPath() + QDir::separator() + "gui-settings.ini";
130131

131-
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "sonic-pi.net", "gui-settings");
132+
gui_settings = new QSettings(settings_path, QSettings::IniFormat);
132133

133134
readSettings();
134135
initPaths();
@@ -277,8 +278,7 @@ void MainWindow::checkForStudioMode()
277278

278279
void MainWindow::showWelcomeScreen()
279280
{
280-
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "sonic-pi.net", "gui-settings");
281-
if (settings.value("first_time", 1).toInt() == 1)
281+
if (gui_settings->value("first_time", 1).toInt() == 1)
282282
{
283283
QTextBrowser* startupPane = new QTextBrowser;
284284
startupPane->setFixedSize(ScaleHeightForDPI(600), ScaleHeightForDPI(650));
@@ -1070,8 +1070,7 @@ void MainWindow::splashClose()
10701070

10711071
void MainWindow::showWindow()
10721072
{
1073-
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "sonic-pi.net", "gui-settings");
1074-
if (settings.value("first_time", 1).toInt() == 1)
1073+
if (gui_settings->value("first_time", 1).toInt() == 1)
10751074
{
10761075
showMaximized();
10771076
}
@@ -1324,13 +1323,12 @@ QString MainWindow::currentTabLabel()
13241323
bool MainWindow::loadFile()
13251324
{
13261325
QString selfilter = QString("%1 (*.rb *.txt)").arg(tr("Buffer files"));
1327-
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "sonic-pi.net", "gui-settings");
1328-
QString lastDir = settings.value("lastDir", QDir::homePath() + "/Desktop").toString();
1326+
QString lastDir = gui_settings->value("lastDir", QDir::homePath() + "/Desktop").toString();
13291327
QString fileName = QFileDialog::getOpenFileName(this, tr("Load Sonic Pi Buffer"), lastDir, QString("%1 (*.rb *.txt);;%2 (*.txt);;%3 (*.rb);;%4 (*.*)").arg(tr("Buffer files")).arg(tr("Text files")).arg(tr("Ruby files")).arg(tr("All files")), &selfilter);
13301328
if (!fileName.isEmpty())
13311329
{
13321330
QFileInfo fi = fileName;
1333-
settings.setValue("lastDir", fi.dir().absolutePath());
1331+
gui_settings->setValue("lastDir", fi.dir().absolutePath());
13341332
SonicPiScintilla* p = (SonicPiScintilla*)tabs->currentWidget();
13351333
loadFile(fileName, p);
13361334
return true;
@@ -1344,14 +1342,13 @@ bool MainWindow::loadFile()
13441342
bool MainWindow::saveAs()
13451343
{
13461344
QString selfilter = QString("%1 (*.rb *.txt)").arg(tr("Buffer files"));
1347-
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "sonic-pi.net", "gui-settings");
1348-
QString lastDir = settings.value("lastDir", QDir::homePath() + "/Desktop").toString();
1345+
QString lastDir = gui_settings->value("lastDir", QDir::homePath() + "/Desktop").toString();
13491346
QString fileName = QFileDialog::getSaveFileName(this, tr("Save Current Buffer"), lastDir, QString("%1 (*.rb *.txt);;%2 (*.txt);;%3 (*.rb);;%4 (*.*)").arg(tr("Buffer files")).arg(tr("Text files")).arg(tr("Ruby files")).arg(tr("All files")), &selfilter);
13501347

13511348
if (!fileName.isEmpty())
13521349
{
13531350
QFileInfo fi = fileName;
1354-
settings.setValue("lastDir", fi.dir().absolutePath());
1351+
gui_settings->setValue("lastDir", fi.dir().absolutePath());
13551352
if (!fileName.contains(QRegExp("\\.[a-z]+$")))
13561353
{
13571354
fileName = fileName + ".txt";
@@ -2999,13 +2996,12 @@ void MainWindow::toggleRecording()
29992996
Message msg("/stop-recording");
30002997
msg.pushStr(guiID.toStdString());
30012998
sendOSC(msg);
3002-
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "sonic-pi.net", "gui-settings");
3003-
QString lastDir = settings.value("lastDir", QDir::homePath() + "/Desktop").toString();
2999+
QString lastDir = gui_settings->value("lastDir", QDir::homePath() + "/Desktop").toString();
30043000
QString fileName = QFileDialog::getSaveFileName(this, tr("Save Recording"), lastDir, tr("Wavefile (*.wav)"));
30053001
if (!fileName.isEmpty())
30063002
{
30073003
QFileInfo fi = fileName;
3008-
settings.setValue("lastDir", fi.dir().absolutePath());
3004+
gui_settings->setValue("lastDir", fi.dir().absolutePath());
30093005
Message msg("/save-recording");
30103006
msg.pushStr(guiID.toStdString());
30113007
msg.pushStr(fileName.toStdString());
@@ -3035,19 +3031,18 @@ void MainWindow::createStatusBar()
30353031
*/
30363032
void MainWindow::restoreWindows()
30373033
{
3038-
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "sonic-pi.net", "gui-settings");
30393034
QRect rec = QGuiApplication::primaryScreen()->geometry();
3040-
QPoint pos = settings.value("pos", QPoint(0, 0)).toPoint();
3041-
QSize size = settings.value("size", QSize(rec.width(), rec.height())).toSize();
3035+
QPoint pos = gui_settings->value("pos", QPoint(0, 0)).toPoint();
3036+
QSize size = gui_settings->value("size", QSize(rec.width(), rec.height())).toSize();
30423037

3043-
int index = settings.value("workspace", 0).toInt();
3038+
int index = gui_settings->value("workspace", 0).toInt();
30443039
if (index < tabs->count())
30453040
tabs->setCurrentIndex(index);
30463041

30473042
for (int w = 0; w < workspace_max; w++)
30483043
{
30493044
// default zoom is 13
3050-
int zoom = settings.value(QString("workspace%1zoom").arg(w), 2)
3045+
int zoom = gui_settings->value(QString("workspace%1zoom").arg(w), 2)
30513046
.toInt();
30523047
if (zoom < -5)
30533048
zoom = -5;
@@ -3058,9 +3053,9 @@ void MainWindow::restoreWindows()
30583053
workspaces[w]->zoomTo(zoom);
30593054
}
30603055

3061-
docsplit->restoreState(settings.value("docsplitState").toByteArray());
3056+
docsplit->restoreState(gui_settings->value("docsplitState").toByteArray());
30623057
//bool visualizer = piSettings->show_scopes;
3063-
restoreState(settings.value("windowState").toByteArray());
3058+
restoreState(gui_settings->value("windowState").toByteArray());
30643059
// restoreGeometry(settings.value("windowGeom").toByteArray());
30653060

30663061
// if (visualizer != piSettings->show_scopes) {
@@ -3079,109 +3074,106 @@ void MainWindow::restoreWindows()
30793074
void MainWindow::readSettings()
30803075
{
30813076
std::cout << "[GUI] - reading settings" << std::endl;
3082-
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "sonic-pi.net", "gui-settings");
30833077

30843078
// Read in preferences from previous session
3085-
piSettings->show_buttons = settings.value("prefs/show-buttons", true).toBool();
3086-
piSettings->show_tabs = settings.value("prefs/show-tabs", true).toBool();
3087-
piSettings->show_log = settings.value("prefs/show-log", true).toBool();
3088-
piSettings->osc_public = settings.value("prefs/osc-public", false).toBool();
3089-
piSettings->osc_server_enabled = settings.value("prefs/osc-enabled", true).toBool();
3090-
piSettings->midi_enabled = settings.value("prefs/midi-enable", true).toBool();
3091-
piSettings->midi_default_channel = settings.value("prefs/midi-default-channel", 0).toInt();
3092-
piSettings->check_args = settings.value("prefs/check-args", true).toBool();
3093-
piSettings->log_synths = settings.value("prefs/log-synths", true).toBool();
3094-
piSettings->clear_output_on_run = settings.value("prefs/clear-output-on-run", true).toBool();
3095-
piSettings->log_cues = settings.value("prefs/log-cues", false).toBool();
3096-
piSettings->log_auto_scroll = settings.value("prefs/log-auto-scroll", true).toBool();
3097-
piSettings->show_line_numbers = settings.value("prefs/show-line-numbers", true).toBool();
3098-
piSettings->enable_external_synths = settings.value("prefs/enable-external-synths", false).toBool();
3099-
piSettings->synth_trigger_timing_guarantees = settings.value("prefs/synth-trigger-timing-guarantees", false).toBool();
3100-
3101-
piSettings->main_volume = settings.value("prefs/system-vol", 80).toInt();
3102-
piSettings->mixer_force_mono = settings.value("prefs/mixer-force-mono", false).toBool();
3103-
piSettings->mixer_invert_stereo = settings.value("prefs/mixer-invert-stereo", false).toBool();
3104-
piSettings->check_updates = settings.value("prefs/rp/check-updates", true).toBool();
3105-
piSettings->auto_indent_on_run = settings.value("prefs/auto-indent-on-run", true).toBool();
3106-
piSettings->gui_transparency = settings.value("prefs/gui_transparency", 0).toInt();
3107-
piSettings->show_scopes = settings.value("prefs/scope/show-scopes", true).toBool();
3108-
piSettings->show_scope_labels = settings.value("prefs/scope/show-labels", false).toBool();
3109-
piSettings->show_cues = settings.value("prefs/show_cues", true).toBool();
3110-
QString styleName = settings.value("prefs/theme", "").toString();
3079+
piSettings->show_buttons = gui_settings->value("prefs/show-buttons", true).toBool();
3080+
piSettings->show_tabs = gui_settings->value("prefs/show-tabs", true).toBool();
3081+
piSettings->show_log = gui_settings->value("prefs/show-log", true).toBool();
3082+
piSettings->osc_public = gui_settings->value("prefs/osc-public", false).toBool();
3083+
piSettings->osc_server_enabled = gui_settings->value("prefs/osc-enabled", true).toBool();
3084+
piSettings->midi_enabled = gui_settings->value("prefs/midi-enable", true).toBool();
3085+
piSettings->midi_default_channel = gui_settings->value("prefs/midi-default-channel", 0).toInt();
3086+
piSettings->check_args = gui_settings->value("prefs/check-args", true).toBool();
3087+
piSettings->log_synths = gui_settings->value("prefs/log-synths", true).toBool();
3088+
piSettings->clear_output_on_run = gui_settings->value("prefs/clear-output-on-run", true).toBool();
3089+
piSettings->log_cues = gui_settings->value("prefs/log-cues", false).toBool();
3090+
piSettings->log_auto_scroll = gui_settings->value("prefs/log-auto-scroll", true).toBool();
3091+
piSettings->show_line_numbers = gui_settings->value("prefs/show-line-numbers", true).toBool();
3092+
piSettings->enable_external_synths = gui_settings->value("prefs/enable-external-synths", false).toBool();
3093+
piSettings->synth_trigger_timing_guarantees = gui_settings->value("prefs/synth-trigger-timing-guarantees", false).toBool();
3094+
3095+
piSettings->main_volume = gui_settings->value("prefs/system-vol", 80).toInt();
3096+
piSettings->mixer_force_mono = gui_settings->value("prefs/mixer-force-mono", false).toBool();
3097+
piSettings->mixer_invert_stereo = gui_settings->value("prefs/mixer-invert-stereo", false).toBool();
3098+
piSettings->check_updates = gui_settings->value("prefs/rp/check-updates", true).toBool();
3099+
piSettings->auto_indent_on_run = gui_settings->value("prefs/auto-indent-on-run", true).toBool();
3100+
piSettings->gui_transparency = gui_settings->value("prefs/gui_transparency", 0).toInt();
3101+
piSettings->show_scopes = gui_settings->value("prefs/scope/show-scopes", true).toBool();
3102+
piSettings->show_scope_labels = gui_settings->value("prefs/scope/show-labels", false).toBool();
3103+
piSettings->show_cues = gui_settings->value("prefs/show_cues", true).toBool();
3104+
QString styleName = gui_settings->value("prefs/theme", "").toString();
31113105
piSettings->themeStyle = theme->themeNameToStyle(styleName);
3112-
piSettings->show_autocompletion = settings.value("prefs/show-autocompletion", true).toBool();
3113-
piSettings->show_context = settings.value("prefs/show-context", true).toBool();
3106+
piSettings->show_autocompletion = gui_settings->value("prefs/show-autocompletion", true).toBool();
3107+
piSettings->show_context = gui_settings->value("prefs/show-context", true).toBool();
31143108

31153109
emit settingsChanged();
31163110
}
31173111

31183112
void MainWindow::restoreScopeState(std::vector<QString> names)
31193113
{
31203114
std::cout << "[GUI] - restoring scope states " << std::endl;
3121-
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "sonic-pi.net", "gui-settings");
31223115

31233116
for (auto name : names)
31243117
{
31253118
bool def = (name.toLower() == "spectrum");
3126-
piSettings->setScopeState(name, settings.value("prefs/scope/show-" + name.toLower(), def).toBool());
3119+
piSettings->setScopeState(name, gui_settings->value("prefs/scope/show-" + name.toLower(), def).toBool());
31273120
}
31283121
}
31293122

31303123
void MainWindow::writeSettings()
31313124
{
31323125
std::cout << "[GUI] - writing settings" << std::endl;
3133-
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "sonic-pi.net", "gui-settings");
3134-
settings.setValue("pos", pos());
3135-
settings.setValue("size", size());
3136-
settings.setValue("first_time", 0);
3137-
3138-
settings.setValue("prefs/midi-default-channel", piSettings->midi_default_channel);
3139-
settings.setValue("prefs/midi-enable", piSettings->midi_enabled);
3140-
settings.setValue("prefs/osc-public", piSettings->osc_public);
3141-
settings.setValue("prefs/osc-enabled", piSettings->osc_server_enabled);
3142-
3143-
settings.setValue("prefs/check-args", piSettings->check_args);
3144-
settings.setValue("prefs/log-synths", piSettings->log_synths);
3145-
settings.setValue("prefs/clear-output-on-run", piSettings->clear_output_on_run);
3146-
settings.setValue("prefs/log-cues", piSettings->log_cues);
3147-
settings.setValue("prefs/log-auto-scroll", piSettings->log_auto_scroll);
3148-
settings.setValue("prefs/show-line-numbers", piSettings->show_line_numbers);
3149-
settings.setValue("prefs/enable-external-synths", piSettings->enable_external_synths);
3150-
settings.setValue("prefs/synth-trigger-timing-guarantees", piSettings->synth_trigger_timing_guarantees);
3151-
settings.setValue("prefs/mixer-force-mono", piSettings->mixer_force_mono);
3152-
settings.setValue("prefs/mixer-invert-stereo", piSettings->mixer_invert_stereo);
3153-
settings.setValue("prefs/system-vol", piSettings->main_volume);
3154-
settings.setValue("prefs/rp/check-updates", piSettings->check_updates);
3155-
settings.setValue("prefs/auto-indent-on-run", piSettings->auto_indent_on_run);
3156-
settings.setValue("prefs/gui_transparency", piSettings->gui_transparency);
3157-
settings.setValue("prefs/scope/show-labels", piSettings->show_scope_labels);
3158-
settings.setValue("prefs/scope/show-scopes", piSettings->show_scopes);
3159-
settings.setValue("prefs/show_cues", piSettings->show_cues);
3160-
settings.setValue("prefs/theme", theme->themeStyleToName(piSettings->themeStyle));
3161-
3162-
settings.setValue("prefs/show-autocompletion", piSettings->show_autocompletion);
3163-
3164-
settings.setValue("prefs/show-buttons", piSettings->show_buttons);
3165-
settings.setValue("prefs/show-tabs", piSettings->show_tabs);
3166-
settings.setValue("prefs/show-log", piSettings->show_log);
3167-
settings.setValue("prefs/show-context", piSettings->show_context);
3126+
gui_settings->setValue("pos", pos());
3127+
gui_settings->setValue("size", size());
3128+
gui_settings->setValue("first_time", 0);
3129+
3130+
gui_settings->setValue("prefs/midi-default-channel", piSettings->midi_default_channel);
3131+
gui_settings->setValue("prefs/midi-enable", piSettings->midi_enabled);
3132+
gui_settings->setValue("prefs/osc-public", piSettings->osc_public);
3133+
gui_settings->setValue("prefs/osc-enabled", piSettings->osc_server_enabled);
3134+
3135+
gui_settings->setValue("prefs/check-args", piSettings->check_args);
3136+
gui_settings->setValue("prefs/log-synths", piSettings->log_synths);
3137+
gui_settings->setValue("prefs/clear-output-on-run", piSettings->clear_output_on_run);
3138+
gui_settings->setValue("prefs/log-cues", piSettings->log_cues);
3139+
gui_settings->setValue("prefs/log-auto-scroll", piSettings->log_auto_scroll);
3140+
gui_settings->setValue("prefs/show-line-numbers", piSettings->show_line_numbers);
3141+
gui_settings->setValue("prefs/enable-external-synths", piSettings->enable_external_synths);
3142+
gui_settings->setValue("prefs/synth-trigger-timing-guarantees", piSettings->synth_trigger_timing_guarantees);
3143+
gui_settings->setValue("prefs/mixer-force-mono", piSettings->mixer_force_mono);
3144+
gui_settings->setValue("prefs/mixer-invert-stereo", piSettings->mixer_invert_stereo);
3145+
gui_settings->setValue("prefs/system-vol", piSettings->main_volume);
3146+
gui_settings->setValue("prefs/rp/check-updates", piSettings->check_updates);
3147+
gui_settings->setValue("prefs/auto-indent-on-run", piSettings->auto_indent_on_run);
3148+
gui_settings->setValue("prefs/gui_transparency", piSettings->gui_transparency);
3149+
gui_settings->setValue("prefs/scope/show-labels", piSettings->show_scope_labels);
3150+
gui_settings->setValue("prefs/scope/show-scopes", piSettings->show_scopes);
3151+
gui_settings->setValue("prefs/show_cues", piSettings->show_cues);
3152+
gui_settings->setValue("prefs/theme", theme->themeStyleToName(piSettings->themeStyle));
3153+
3154+
gui_settings->setValue("prefs/show-autocompletion", piSettings->show_autocompletion);
3155+
3156+
gui_settings->setValue("prefs/show-buttons", piSettings->show_buttons);
3157+
gui_settings->setValue("prefs/show-tabs", piSettings->show_tabs);
3158+
gui_settings->setValue("prefs/show-log", piSettings->show_log);
3159+
gui_settings->setValue("prefs/show-context", piSettings->show_context);
31683160

31693161
for (auto name : piSettings->scope_names)
31703162
{
3171-
settings.setValue("prefs/scope/show-" + name.toLower(), piSettings->isScopeActive(name));
3163+
gui_settings->setValue("prefs/scope/show-" + name.toLower(), piSettings->isScopeActive(name));
31723164
}
31733165

3174-
settings.setValue("workspace", tabs->currentIndex());
3166+
gui_settings->setValue("workspace", tabs->currentIndex());
31753167

31763168
for (int w = 0; w < workspace_max; w++)
31773169
{
3178-
settings.setValue(QString("workspace%1zoom").arg(w),
3170+
gui_settings->setValue(QString("workspace%1zoom").arg(w),
31793171
workspaces[w]->property("zoom"));
31803172
}
31813173

3182-
settings.setValue("docsplitState", docsplit->saveState());
3183-
settings.setValue("windowState", saveState());
3184-
settings.setValue("windowGeom", saveGeometry());
3174+
gui_settings->setValue("docsplitState", docsplit->saveState());
3175+
gui_settings->setValue("windowState", saveState());
3176+
gui_settings->setValue("windowGeom", saveGeometry());
31853177
}
31863178

31873179
void MainWindow::loadFile(const QString& fileName, SonicPiScintilla*& text)
@@ -3646,14 +3638,19 @@ QString MainWindow::sonicPiHomePath()
36463638
QString path = qgetenv("SONIC_PI_HOME").constData();
36473639
if (path.isEmpty())
36483640
{
3649-
return QDir::homePath();
3641+
return QDir::homePath() + QDir::separator() + ".sonic-pi";
36503642
}
36513643
else
36523644
{
3653-
return path;
3645+
return path;
36543646
}
36553647
}
36563648

3649+
QString MainWindow::sonicPiConfigPath()
3650+
{
3651+
return sonicPiHomePath() + QDir::separator() + "config";
3652+
}
3653+
36573654
void MainWindow::zoomInLogs()
36583655
{
36593656
outputPane->zoomIn();

app/gui/qt/mainwindow.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <QFuture>
2323
#include <QSet>
2424
#include <QIcon>
25+
#include <QSettings>
2526

2627
// On windows, we need to include winsock2 before other instances of winsock
2728
#ifdef WIN32
@@ -138,6 +139,7 @@ class MainWindow : public QMainWindow
138139
void zoomInLogs();
139140
void zoomOutLogs();
140141
QString sonicPiHomePath();
142+
QString sonicPiConfigPath();
141143
void updateLogAutoScroll();
142144
bool eventFilter(QObject *obj, QEvent *evt);
143145
void changeTab(int id);
@@ -328,6 +330,7 @@ class MainWindow : public QMainWindow
328330

329331
QMenu *liveMenu, *codeMenu, *audioMenu, *displayMenu, *viewMenu, *ioMenu, *ioMidiInMenu, *ioMidiOutMenu, *ioMidiOutChannelMenu, *localIpAddressesMenu, *themeMenu, *scopeKindVisibilityMenu;
330332

333+
QSettings *gui_settings;
331334
SonicPiSettings *piSettings;
332335

333336
int server_osc_cues_port;

0 commit comments

Comments
 (0)