diff --git a/scripts/change-system-language b/scripts/change-system-language new file mode 100755 index 0000000..9300b6c --- /dev/null +++ b/scripts/change-system-language @@ -0,0 +1,9 @@ +#!/bin/bash + +LANGUAGE_CODE=$1 +COUNTRY_CODE=$2 +LOCALE="${LANGUAGE_CODE}_${COUNTRY_CODE}.UTF-8" + +apt-get -y install language-pack-gnome-$LANGUAGE_CODE language-pack-kde-$LANGUAGE_CODE +update-locale LANGUAGE=$LOCALE LANG=$LOCALE LC_ALL=$LOCALE +systemctl restart sddm diff --git a/src/installerprompt.cpp b/src/installerprompt.cpp index 3fad66a..c17ecb2 100644 --- a/src/installerprompt.cpp +++ b/src/installerprompt.cpp @@ -50,6 +50,9 @@ InstallerPrompt::InstallerPrompt(QWidget *parent) // Set up the language combo box with available languages initLanguageComboBox(); + // Connect the language combo box to the onLanguageChanged slot + connect(ui->languageComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onLanguageChanged(int))); + // Check initial network status and update UI updateConnectionStatus(); @@ -340,8 +343,11 @@ void InstallerPrompt::refreshNetworkList() { } void InstallerPrompt::initLanguageComboBox() { + languageLocaleMap.clear(); QStringList languages = getAvailableLanguages(); - ui->languageComboBox->addItems(languages); + for (const auto &language : languages) { + ui->languageComboBox->addItem(language); + } QString defaultLanguage = "English (United States)"; int defaultIndex = ui->languageComboBox->findText(defaultLanguage); @@ -350,7 +356,7 @@ void InstallerPrompt::initLanguageComboBox() { } } -QStringList InstallerPrompt::getAvailableLanguages() const { +QStringList InstallerPrompt::getAvailableLanguages() { QMap languageMap; // Default sorting by QString is case-sensitive auto sanitize = [](QString s) -> QString { @@ -384,17 +390,38 @@ QStringList InstallerPrompt::getAvailableLanguages() const { languageMap.insert(displayName, locale.name()); } } - + // Sort the language display names QStringList sortedLanguages = languageMap.keys(); std::sort(sortedLanguages.begin(), sortedLanguages.end(), [](const QString &a, const QString &b) { return a.compare(b, Qt::CaseInsensitive) < 0; }); + // Clear the existing languageLocaleMap and repopulate it based on sortedLanguages + languageLocaleMap.clear(); + for (const QString &languageName : sortedLanguages) { + languageLocaleMap.insert(languageName, languageMap[languageName]); + } + return sortedLanguages; } void InstallerPrompt::onLanguageChanged(int index) { - // Placeholder for handling language change + QString selectedLanguage = ui->languageComboBox->itemText(index); + QString localeName = languageLocaleMap.value(selectedLanguage); + qDebug() << selectedLanguage; + qDebug() << index << languageLocaleMap; + + // Split the locale name to get language and country code + QStringList localeParts = localeName.split('_'); + QString languageCode = localeParts.value(0); + QString countryCode = localeParts.value(1); + + // Construct the command to run the script with parameters + QString scriptPath = "/usr/libexec/change-system-language"; // Update with the actual path + QStringList arguments; + arguments << languageCode << countryCode; + + QProcess::execute(scriptPath, arguments); } void InstallerPrompt::tryLubuntu() diff --git a/src/installerprompt.h b/src/installerprompt.h index 9e17b87..1c1bb64 100644 --- a/src/installerprompt.h +++ b/src/installerprompt.h @@ -40,12 +40,13 @@ private: NetworkManager::Connection::Ptr findConnectionBySsid(const QString &ssid); bool wifiWrongHandling = false; QLineEdit *passwordLineEdit; + QMap languageLocaleMap; void handleWifiConnection(const QString &ssid, bool recoverFromWrongPassword = false); QString promptForWifiPassword(const QString &ssid, bool isWrongPassword = false); void connectToWifi(const QString &ssid, const QString &password, bool recoverFromWrongPassword = false); void initLanguageComboBox(); - QStringList getAvailableLanguages() const; + QStringList getAvailableLanguages(); void showWifiOptions(); NMVariantMapMap createSettingsBySSID(const QString &ssid); };