Skip to content

Commit de8e03d

Browse files
committed
GUI - Fix restartApp() on Windows; change the language setting value 'system_locale' to 'system_language'; remove some verbose/unnecessary logging and comments
1 parent 47b34e1 commit de8e03d

File tree

4 files changed

+18
-58
lines changed

4 files changed

+18
-58
lines changed

app/gui/qt/mainwindow.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,16 +2206,12 @@ void MainWindow::changeUILanguage(QString lang) {
22062206

22072207
if (msgBox.clickedButton() == (QAbstractButton*)restartButton) {
22082208
piSettings->language = lang;
2209-
writeSettings();
22102209
restartApp();
2211-
//statusBar()->showMessage(tr("Updated UI language setting, please restart Sonic Pi to apply it"), 2000);
22122210
} else if (msgBox.clickedButton() == (QAbstractButton*)dismissButton) {
22132211
// Don't apply the new language settings
22142212
settingsWidget->updateSelectedUILanguage(piSettings->language);
22152213
}
22162214

2217-
// Load previously set language
2218-
//sonicPii18n->loadTranslations(ui_language);
22192215
}
22202216
}
22212217

@@ -3540,7 +3536,7 @@ void MainWindow::readSettings()
35403536
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "sonic-pi.net", "gui-settings");
35413537

35423538
// Read in preferences from previous session
3543-
piSettings->language = settings.value("prefs/language", "system_locale").toString();
3539+
piSettings->language = settings.value("prefs/language", "system_language").toString();
35443540

35453541
piSettings->show_buttons = settings.value("prefs/show-buttons", true).toBool();
35463542
piSettings->show_tabs = settings.value("prefs/show-tabs", true).toBool();
@@ -3778,13 +3774,14 @@ void MainWindow::onExitCleanup()
37783774
void MainWindow::restartApp() {
37793775
QApplication* app = dynamic_cast<QApplication*>(parent());
37803776
statusBar()->showMessage(tr("Restarting Sonic Pi..."), 10000);
3777+
37813778
// Save settings and perform some cleanup
37823779
writeSettings();
37833780
onExitCleanup();
3784-
sleep(1);
37853781
std::cout << "Performing application restart... please wait..." << std::endl;
3786-
//this->hide(); // So it doesn't look like the app's frozen or crashed
3787-
sleep(4); // Allow cleanup to complete
3782+
// Allow cleanup to complete
3783+
std::this_thread::sleep_for(2s);
3784+
37883785
// Create new process
37893786
QStringList args = qApp->arguments();
37903787
args.removeFirst();
@@ -3795,6 +3792,7 @@ void MainWindow::restartApp() {
37953792
} else {
37963793
std::cout << "Failed to restart sonic-pi" << std::endl;
37973794
}
3795+
37983796
// Quit
37993797
app->exit(0);
38003798
exit(0);

app/gui/qt/utils/sonic_pi_i18n.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,9 @@
1414
SonicPii18n::SonicPii18n(QString rootpath) {
1515
this->root_path = rootpath;
1616
this->available_languages = findAvailableLanguages();
17+
1718
// Set to true unless we can't load the system language
1819
this->system_language_available = true;
19-
20-
// // Print all Qt's language codes for debugging
21-
// QList<QLocale> allLocales = QLocale::matchingLocales(
22-
// QLocale::AnyLanguage,
23-
// QLocale::AnyScript,
24-
// QLocale::AnyCountry);
25-
// QStringList iso639LanguageCodes;
26-
//
27-
// for(const QLocale &locale : allLocales) {
28-
// iso639LanguageCodes << locale.name();
29-
// }
30-
//
31-
// std::cout << iso639LanguageCodes.join("\n").toUtf8().constData() << std::endl;
3220
}
3321

3422
SonicPii18n::~SonicPii18n() {
@@ -39,7 +27,7 @@ QString SonicPii18n::determineUILanguage(QString lang_pref) {
3927
//std::cout << available_languages.join("\n").toUtf8().constData() << std::endl;
4028
QLocale locale;
4129

42-
if (lang_pref != "system_locale") {
30+
if (lang_pref != "system_language") {
4331
if (available_languages.contains(lang_pref)) {
4432
return lang_pref;
4533
}
@@ -54,7 +42,7 @@ QString SonicPii18n::determineUILanguage(QString lang_pref) {
5442
}
5543
} else {
5644
QStringList preferred_languages = locale.uiLanguages();
57-
// If the specified language isn't available, or if the setting is set to system_locale...
45+
// If the specified language isn't available, or if the setting is set to system_language...
5846
// ...run through the list of preferred languages
5947
std::cout << "Looping through preferred ui languages" << std::endl;
6048

@@ -80,7 +68,7 @@ QStringList SonicPii18n::findAvailableLanguages() {
8068
QLocale locale;
8169

8270
QString m_langPath = root_path + "/app/gui/qt/lang";
83-
std::cout << m_langPath.toUtf8().constData() << "\n";
71+
//std::cout << m_langPath.toUtf8().constData() << "\n";
8472
QDir dir(m_langPath);
8573
QStringList fileNames = dir.entryList(QStringList("sonic-pi_*.qm"));
8674

@@ -137,7 +125,7 @@ QString SonicPii18n::getNativeLanguageName(QString lang) {
137125
if(it != native_language_names.end()) {
138126
// language found
139127
return native_language_names[lang];
140-
} else if (lang == "system_locale") {
128+
} else if (lang == "system_language") {
141129
return tr("System language");
142130
} else {
143131
std::cout << "Warning: Predefined language name not found'" << lang.toUtf8().constData() << "'" << std::endl;

app/gui/qt/widgets/settingswidget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ SettingsWidget::SettingsWidget(int port, bool i18n, SonicPiSettings *piSettings,
2727
this->sonicPii18n = sonicPii18n;
2828
this->localeNames = sonicPii18n->getNativeLanguageNameList();
2929
this->available_languages = sonicPii18n->getAvailableLanguages();
30-
available_languages.prepend("system_locale");
30+
available_languages.prepend("system_language");
3131
server_osc_cues_port = port;
3232

3333
prefTabs = new QTabWidget();
@@ -850,7 +850,7 @@ void SettingsWidget::add_language_combo_box_entries(QComboBox* combo) {
850850

851851
for (auto const &language : available_languages) {
852852
std::cout << "[Debug] Adding language " << language.toUtf8().data() << " to the combo box" << std::endl;
853-
if (language != "system_locale") {
853+
if (language != "system_language") {
854854
// Add the language's name to the combo box
855855
combo->addItem(sonicPii18n->getNativeLanguageName(language));
856856
} else {

app/server/ruby/bin/qt-doc.rb

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -319,49 +319,23 @@
319319
end
320320

321321
def generate_ui_lang_names
322-
# Make a function to define the locale list map -----
322+
# Define the language list map -----
323323
ui_languages = @lang_names.keys
324324
ui_languages = ui_languages.sort_by {|l| l.downcase}
325325
locale_arrays = []
326326
locale_arrays << "std::map<QString, QString> SonicPii18n::native_language_names = {\n"
327+
327328
# # Add each language
328-
# locale_arrays << "{0, \"system_locale\"}"
329-
# i = 1
330-
# ui_languages.each do |lang|
331-
# locale_arrays << ",\n"
332-
# locale_arrays << "{#{i.to_s}, \"#{lang}\"}"
333-
# i += 1
334-
# end
335-
# # End the map
336-
# locale_arrays << "\n};\n"
337-
#
338-
# # Create a map of the locales to their indices in availableLocales, called localeIndex
339-
# locale_arrays << "localeIndex = {\n"
340-
# # Add each language
341-
# locale_arrays << "{\"system_locale\", 0}"
342-
# i = 1
343-
# ui_languages.each do |lang|
344-
# locale_arrays << ",\n"
345-
# locale_arrays << "{\"#{lang}\", #{i.to_s}}"
346-
# i += 1
347-
# end
348-
# # End the map
349-
# locale_arrays << "\n};\n"
350-
#
351-
# # Create a map of the locales to their native names, called localeNames
352-
# locale_arrays << "localeNames = {\n"
353-
# Add each language
354-
locale_arrays << "{\"system_locale\", \"\"}"
329+
locale_arrays << "{\"system_language\", \"\"}"
355330
ui_languages.each do |lang|
356331
locale_arrays << ",\n"
357332
locale_arrays << "{\"#{lang}\", \"#{@lang_names[lang]}\"}"
358333
end
334+
359335
# End the map
360336
locale_arrays << "\n};\n"
361337

362-
# End the function
363-
#locale_arrays << "};\n"
364-
338+
# Write the map to lang_list.h
365339
content = File.readlines("#{qt_gui_path}/utils/lang_list.tmpl")
366340
lang_names_generated = content.take_while { |line| !line.start_with?("// AUTO-GENERATED")}
367341
lang_names_generated << "// AUTO-GENERATED HEADER FILE\n"

0 commit comments

Comments
 (0)