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.
This commit is contained in:
parent
a757d52244
commit
24a20939a6
9
scripts/change-system-language
Executable file
9
scripts/change-system-language
Executable file
@ -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
|
||||
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<QString, QString> 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()
|
||||
|
@ -40,12 +40,13 @@ private:
|
||||
NetworkManager::Connection::Ptr findConnectionBySsid(const QString &ssid);
|
||||
bool wifiWrongHandling = false;
|
||||
QLineEdit *passwordLineEdit;
|
||||
QMap<QString, QString> 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);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user