Add a backend for the language selection menu

Assuming you're running this at root, immediately when the dropdown box has a changed value, it installs the required language packs, updates the system locale, then kicks off an SDDM reboot.

This needs lots of error handling and UX to ensure the user doesn't just hold down the down arrow and crash their computer.
pull/2/head
Simon Quigley 1 year ago
parent a757d52244
commit 24a20939a6

@ -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

@ -50,6 +50,9 @@ InstallerPrompt::InstallerPrompt(QWidget *parent)
// Set up the language combo box with available languages // Set up the language combo box with available languages
initLanguageComboBox(); 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 // Check initial network status and update UI
updateConnectionStatus(); updateConnectionStatus();
@ -340,8 +343,11 @@ void InstallerPrompt::refreshNetworkList() {
} }
void InstallerPrompt::initLanguageComboBox() { void InstallerPrompt::initLanguageComboBox() {
languageLocaleMap.clear();
QStringList languages = getAvailableLanguages(); QStringList languages = getAvailableLanguages();
ui->languageComboBox->addItems(languages); for (const auto &language : languages) {
ui->languageComboBox->addItem(language);
}
QString defaultLanguage = "English (United States)"; QString defaultLanguage = "English (United States)";
int defaultIndex = ui->languageComboBox->findText(defaultLanguage); int defaultIndex = ui->languageComboBox->findText(defaultLanguage);
@ -350,7 +356,7 @@ void InstallerPrompt::initLanguageComboBox() {
} }
} }
QStringList InstallerPrompt::getAvailableLanguages() const { QStringList InstallerPrompt::getAvailableLanguages() {
QMap<QString, QString> languageMap; // Default sorting by QString is case-sensitive QMap<QString, QString> languageMap; // Default sorting by QString is case-sensitive
auto sanitize = [](QString s) -> QString { auto sanitize = [](QString s) -> QString {
@ -384,17 +390,38 @@ QStringList InstallerPrompt::getAvailableLanguages() const {
languageMap.insert(displayName, locale.name()); languageMap.insert(displayName, locale.name());
} }
} }
// Sort the language display names
QStringList sortedLanguages = languageMap.keys(); QStringList sortedLanguages = languageMap.keys();
std::sort(sortedLanguages.begin(), sortedLanguages.end(), [](const QString &a, const QString &b) { std::sort(sortedLanguages.begin(), sortedLanguages.end(), [](const QString &a, const QString &b) {
return a.compare(b, Qt::CaseInsensitive) < 0; 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; return sortedLanguages;
} }
void InstallerPrompt::onLanguageChanged(int index) { 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() void InstallerPrompt::tryLubuntu()

@ -40,12 +40,13 @@ private:
NetworkManager::Connection::Ptr findConnectionBySsid(const QString &ssid); NetworkManager::Connection::Ptr findConnectionBySsid(const QString &ssid);
bool wifiWrongHandling = false; bool wifiWrongHandling = false;
QLineEdit *passwordLineEdit; QLineEdit *passwordLineEdit;
QMap<QString, QString> languageLocaleMap;
void handleWifiConnection(const QString &ssid, bool recoverFromWrongPassword = false); void handleWifiConnection(const QString &ssid, bool recoverFromWrongPassword = false);
QString promptForWifiPassword(const QString &ssid, bool isWrongPassword = false); QString promptForWifiPassword(const QString &ssid, bool isWrongPassword = false);
void connectToWifi(const QString &ssid, const QString &password, bool recoverFromWrongPassword = false); void connectToWifi(const QString &ssid, const QString &password, bool recoverFromWrongPassword = false);
void initLanguageComboBox(); void initLanguageComboBox();
QStringList getAvailableLanguages() const; QStringList getAvailableLanguages();
void showWifiOptions(); void showWifiOptions();
NMVariantMapMap createSettingsBySSID(const QString &ssid); NMVariantMapMap createSettingsBySSID(const QString &ssid);
}; };

Loading…
Cancel
Save