Skip to content

Commit

Permalink
GUI - Fix restartApp() on Windows; change the language setting value …
Browse files Browse the repository at this point in the history
…'system_locale' to 'system_language'; remove some verbose/unnecessary logging and comments
  • Loading branch information
SunderB committed Feb 14, 2021
1 parent 47b34e1 commit de8e03d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 58 deletions.
14 changes: 6 additions & 8 deletions app/gui/qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2206,16 +2206,12 @@ void MainWindow::changeUILanguage(QString lang) {

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

// Load previously set language
//sonicPii18n->loadTranslations(ui_language);
}
}

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

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

piSettings->show_buttons = settings.value("prefs/show-buttons", true).toBool();
piSettings->show_tabs = settings.value("prefs/show-tabs", true).toBool();
Expand Down Expand Up @@ -3778,13 +3774,14 @@ void MainWindow::onExitCleanup()
void MainWindow::restartApp() {
QApplication* app = dynamic_cast<QApplication*>(parent());
statusBar()->showMessage(tr("Restarting Sonic Pi..."), 10000);

// Save settings and perform some cleanup
writeSettings();
onExitCleanup();
sleep(1);
std::cout << "Performing application restart... please wait..." << std::endl;
//this->hide(); // So it doesn't look like the app's frozen or crashed
sleep(4); // Allow cleanup to complete
// Allow cleanup to complete
std::this_thread::sleep_for(2s);

// Create new process
QStringList args = qApp->arguments();
args.removeFirst();
Expand All @@ -3795,6 +3792,7 @@ void MainWindow::restartApp() {
} else {
std::cout << "Failed to restart sonic-pi" << std::endl;
}

// Quit
app->exit(0);
exit(0);
Expand Down
22 changes: 5 additions & 17 deletions app/gui/qt/utils/sonic_pi_i18n.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,9 @@
SonicPii18n::SonicPii18n(QString rootpath) {
this->root_path = rootpath;
this->available_languages = findAvailableLanguages();

// Set to true unless we can't load the system language
this->system_language_available = true;

// // Print all Qt's language codes for debugging
// QList<QLocale> allLocales = QLocale::matchingLocales(
// QLocale::AnyLanguage,
// QLocale::AnyScript,
// QLocale::AnyCountry);
// QStringList iso639LanguageCodes;
//
// for(const QLocale &locale : allLocales) {
// iso639LanguageCodes << locale.name();
// }
//
// std::cout << iso639LanguageCodes.join("\n").toUtf8().constData() << std::endl;
}

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

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

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

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

Expand Down Expand Up @@ -137,7 +125,7 @@ QString SonicPii18n::getNativeLanguageName(QString lang) {
if(it != native_language_names.end()) {
// language found
return native_language_names[lang];
} else if (lang == "system_locale") {
} else if (lang == "system_language") {
return tr("System language");
} else {
std::cout << "Warning: Predefined language name not found'" << lang.toUtf8().constData() << "'" << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions app/gui/qt/widgets/settingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SettingsWidget::SettingsWidget(int port, bool i18n, SonicPiSettings *piSettings,
this->sonicPii18n = sonicPii18n;
this->localeNames = sonicPii18n->getNativeLanguageNameList();
this->available_languages = sonicPii18n->getAvailableLanguages();
available_languages.prepend("system_locale");
available_languages.prepend("system_language");
server_osc_cues_port = port;

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

for (auto const &language : available_languages) {
std::cout << "[Debug] Adding language " << language.toUtf8().data() << " to the combo box" << std::endl;
if (language != "system_locale") {
if (language != "system_language") {
// Add the language's name to the combo box
combo->addItem(sonicPii18n->getNativeLanguageName(language));
} else {
Expand Down
36 changes: 5 additions & 31 deletions app/server/ruby/bin/qt-doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,49 +319,23 @@
end

def generate_ui_lang_names
# Make a function to define the locale list map -----
# Define the language list map -----
ui_languages = @lang_names.keys
ui_languages = ui_languages.sort_by {|l| l.downcase}
locale_arrays = []
locale_arrays << "std::map<QString, QString> SonicPii18n::native_language_names = {\n"

# # Add each language
# locale_arrays << "{0, \"system_locale\"}"
# i = 1
# ui_languages.each do |lang|
# locale_arrays << ",\n"
# locale_arrays << "{#{i.to_s}, \"#{lang}\"}"
# i += 1
# end
# # End the map
# locale_arrays << "\n};\n"
#
# # Create a map of the locales to their indices in availableLocales, called localeIndex
# locale_arrays << "localeIndex = {\n"
# # Add each language
# locale_arrays << "{\"system_locale\", 0}"
# i = 1
# ui_languages.each do |lang|
# locale_arrays << ",\n"
# locale_arrays << "{\"#{lang}\", #{i.to_s}}"
# i += 1
# end
# # End the map
# locale_arrays << "\n};\n"
#
# # Create a map of the locales to their native names, called localeNames
# locale_arrays << "localeNames = {\n"
# Add each language
locale_arrays << "{\"system_locale\", \"\"}"
locale_arrays << "{\"system_language\", \"\"}"
ui_languages.each do |lang|
locale_arrays << ",\n"
locale_arrays << "{\"#{lang}\", \"#{@lang_names[lang]}\"}"
end

# End the map
locale_arrays << "\n};\n"

# End the function
#locale_arrays << "};\n"

# Write the map to lang_list.h
content = File.readlines("#{qt_gui_path}/utils/lang_list.tmpl")
lang_names_generated = content.take_while { |line| !line.start_with?("// AUTO-GENERATED")}
lang_names_generated << "// AUTO-GENERATED HEADER FILE\n"
Expand Down

0 comments on commit de8e03d

Please sign in to comment.