Skip to content

Commit 7c663da

Browse files
committed
GUI - Fix restartApp() on Windows; neaten and clean up changes made in the previous commit
* Change the language setting value 'system_locale' to 'system_language' * Remove some verbose/unnecessary logging and comments * Remove the entry for system_language from SonicPii18n::native_language_names (we use tr("System language") instead)
1 parent c078ecb commit 7c663da

File tree

4 files changed

+27
-64
lines changed

4 files changed

+27
-64
lines changed

app/gui/qt/mainwindow.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ MainWindow::MainWindow(QApplication& app, QSplashScreen* splash)
162162

163163
bool startupOK = false;
164164
this->sonicPii18n = new SonicPii18n(rootPath());
165+
std::cout << "Language setting: " << piSettings->language.toUtf8().constData() << std::endl;
165166
this->ui_language = sonicPii18n->determineUILanguage(piSettings->language);
166167
std::cout << "Using language: " << ui_language.toUtf8().constData() << std::endl;
167168
this->i18n = sonicPii18n->loadTranslations(ui_language);
@@ -182,8 +183,8 @@ MainWindow::MainWindow(QApplication& app, QSplashScreen* splash)
182183
std::cout << "[GUI] - ===========================" << std::endl;
183184
std::cout << "[GUI] - " << std::endl;
184185
std::cout << "[GUI] - " << guiID.toStdString() << std::endl;
185-
std::cout << "[GUI] - ui locale: " << QLocale::system().uiLanguages()[0].toStdString() << std::endl;
186-
std::cout << "[GUI] - sys locale: " << QLocale::system().name().toStdString() << std::endl;
186+
std::cout << "[GUI] - ui locale: " << ui_language.toUtf8().constData() << std::endl;
187+
std::cout << "[GUI] - sys locale: " << QLocale::system().name().toStdString() << std::endl;
187188

188189

189190
if(i18n) {
@@ -2206,16 +2207,12 @@ void MainWindow::changeUILanguage(QString lang) {
22062207

22072208
if (msgBox.clickedButton() == (QAbstractButton*)restartButton) {
22082209
piSettings->language = lang;
2209-
writeSettings();
22102210
restartApp();
2211-
//statusBar()->showMessage(tr("Updated UI language setting, please restart Sonic Pi to apply it"), 2000);
22122211
} else if (msgBox.clickedButton() == (QAbstractButton*)dismissButton) {
22132212
// Don't apply the new language settings
22142213
settingsWidget->updateSelectedUILanguage(piSettings->language);
22152214
}
22162215

2217-
// Load previously set language
2218-
//sonicPii18n->loadTranslations(ui_language);
22192216
}
22202217
}
22212218

@@ -3540,7 +3537,7 @@ void MainWindow::readSettings()
35403537
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "sonic-pi.net", "gui-settings");
35413538

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

35453542
piSettings->show_buttons = settings.value("prefs/show-buttons", true).toBool();
35463543
piSettings->show_tabs = settings.value("prefs/show-tabs", true).toBool();
@@ -3778,13 +3775,14 @@ void MainWindow::onExitCleanup()
37783775
void MainWindow::restartApp() {
37793776
QApplication* app = dynamic_cast<QApplication*>(parent());
37803777
statusBar()->showMessage(tr("Restarting Sonic Pi..."), 10000);
3778+
37813779
// Save settings and perform some cleanup
37823780
writeSettings();
37833781
onExitCleanup();
3784-
sleep(1);
37853782
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
3783+
// Allow cleanup to complete
3784+
std::this_thread::sleep_for(2s);
3785+
37883786
// Create new process
37893787
QStringList args = qApp->arguments();
37903788
args.removeFirst();
@@ -3795,6 +3793,7 @@ void MainWindow::restartApp() {
37953793
} else {
37963794
std::cout << "Failed to restart sonic-pi" << std::endl;
37973795
}
3796+
37983797
// Quit
37993798
app->exit(0);
38003799
exit(0);
@@ -4373,7 +4372,7 @@ SonicPiLog* MainWindow::GetIncomingPane() const
43734372
{
43744373
return incomingPane;
43754374
}
4376-
4375+
43774376
SonicPiTheme* MainWindow::GetTheme() const
43784377
{
43794378
return theme;

app/gui/qt/utils/sonic_pi_i18n.cpp

Lines changed: 8 additions & 18 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

@@ -133,12 +121,14 @@ std::map<QString, QString> SonicPii18n::getNativeLanguageNameList() {
133121
}
134122

135123
QString SonicPii18n::getNativeLanguageName(QString lang) {
124+
if (lang == "system_language") {
125+
return tr("System language");
126+
}
127+
136128
std::map<QString, QString>::iterator it = native_language_names.find(lang);
137129
if(it != native_language_names.end()) {
138130
// language found
139131
return native_language_names[lang];
140-
} else if (lang == "system_locale") {
141-
return tr("System language");
142132
} else {
143133
std::cout << "Warning: Predefined language name not found'" << lang.toUtf8().constData() << "'" << std::endl;
144134
// Try using QLocale to find the native language name

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: 7 additions & 33 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\", \"\"}"
355-
ui_languages.each do |lang|
356-
locale_arrays << ",\n"
329+
for i in 0..(ui_languages.length()-1) do
330+
lang = ui_languages[i]
331+
locale_arrays << ",\n" if i != 0
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)