From 38a8231ae2db2ba917978e2d2c001d5b603f3f90 Mon Sep 17 00:00:00 2001 From: Simon Quigley Date: Sat, 9 Dec 2023 12:05:49 -0600 Subject: [PATCH] Add some enhanced UX around the language update. --- scripts/change-system-language | 6 +- src/installerprompt.cpp | 54 ++++++++-- src/installerprompt.h | 6 ++ src/installerprompt.ui | 192 +++++++++++++++++++++------------ 4 files changed, 181 insertions(+), 77 deletions(-) diff --git a/scripts/change-system-language b/scripts/change-system-language index 9300b6c..8e46206 100755 --- a/scripts/change-system-language +++ b/scripts/change-system-language @@ -3,7 +3,11 @@ LANGUAGE_CODE=$1 COUNTRY_CODE=$2 LOCALE="${LANGUAGE_CODE}_${COUNTRY_CODE}.UTF-8" +ONLY_LXQT=$3 + +if [ -z "$ONLY_LXQT" ]; then + apt-get -y install language-pack-gnome-$LANGUAGE_CODE language-pack-kde-$LANGUAGE_CODE +fi -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 08d6473..3a4740c 100644 --- a/src/installerprompt.cpp +++ b/src/installerprompt.cpp @@ -1,3 +1,5 @@ +#include +#include #include #include #include @@ -13,7 +15,6 @@ #include #include #include -#include #include "installerprompt.h" #include "./ui_installerprompt.h" @@ -22,8 +23,10 @@ InstallerPrompt::InstallerPrompt(QWidget *parent) , ui(new Ui::InstallerPrompt) { ui->setupUi(this); - // Hide the Incorrect Password text + // Hide the Incorrect Password and loading text ui->incorrectPassword->setVisible(false); + ui->changingLanguageLabel->setVisible(false); + ui->changingLanguageLoader->setVisible(false); // Set the background image and scale it QPixmap bg(":/background"); @@ -47,11 +50,12 @@ InstallerPrompt::InstallerPrompt(QWidget *parent) connect(ui->tryLubuntu, &QAbstractButton::clicked, this, &InstallerPrompt::tryLubuntu); connect(ui->installLubuntu, &QAbstractButton::clicked, this, &InstallerPrompt::installLubuntu); connect(ui->connectWiFiButton, &QAbstractButton::clicked, this, &InstallerPrompt::onConnectWifiClicked); + connect(ui->confirmButton, &QAbstractButton::clicked, this, &InstallerPrompt::onLanguageConfirm); // Set up the language combo box with available languages initLanguageComboBox(); - // Connect the language combo box to the onLanguageChanged slot + // Connect the appropriate language slots connect(ui->languageComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onLanguageChanged(int))); // Check initial network status and update UI @@ -414,22 +418,54 @@ QStringList InstallerPrompt::getAvailableLanguages() { } void InstallerPrompt::onLanguageChanged(int index) { - QString selectedLanguage = ui->languageComboBox->itemText(index); - QString localeName = languageLocaleMap.value(selectedLanguage); - qDebug() << selectedLanguage; - qDebug() << index << languageLocaleMap; + selectedLanguage = ui->languageComboBox->itemText(index); +} + +void InstallerPrompt::onLanguageConfirm() { + ui->changingLanguageLabel->setVisible(true); + ui->changingLanguageLoader->setVisible(true); + + localeName = languageLocaleMap.value(selectedLanguage); + qDebug() << selectedLanguage << localeName; // Split the locale name to get language and country code QStringList localeParts = localeName.split('_'); QString languageCode = localeParts.value(0); QString countryCode = localeParts.value(1); + // If there is no internet connection and we don't ship the langpack, tell them + //QStringList allowedLanguages = {"zh-hans", "hi", "es", "fr", "ar", "en"}; + QStringList allowedLanguages = {"zh-hans", "hi", "fr", "ar", "en"}; + bool only_lxqt = false; + if (!allowedLanguages.contains(languageCode) && NetworkManager::status() != NetworkManager::Status::Connected) { + ui->changingLanguageLabel->setText(tr("Unable to download full language support, changing anyway...")); + only_lxqt = true; + } else { + ui->changingLanguageLabel->setText(tr("Changing language...")); + } + // Construct the command to run the script with parameters - QString scriptPath = "/usr/libexec/change-system-language"; // Update with the actual path + QProcess *process = new QProcess(this); QStringList arguments; + + process->setProgram("/usr/libexec/change-system-language"); arguments << languageCode << countryCode; + if (only_lxqt) arguments << "1"; + process->setArguments(arguments); + + connect(process, static_cast(&QProcess::finished), this, &InstallerPrompt::languageProcessFinished); + connect(process, &QProcess::errorOccurred, this, &InstallerPrompt::languageProcessError); + process->start(); +} + +void InstallerPrompt::languageProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) { + qDebug() << "Process finished. Exit code:" << exitCode << "Exit status:" << exitStatus; + ui->changingLanguageLabel->setVisible(false); + ui->changingLanguageLoader->setVisible(false); +} - QProcess::execute(scriptPath, arguments); +void InstallerPrompt::languageProcessError(QProcess::ProcessError error) { + qDebug() << "Process failed with error:" << error; } void InstallerPrompt::tryLubuntu() diff --git a/src/installerprompt.h b/src/installerprompt.h index 1c1bb64..53324fd 100644 --- a/src/installerprompt.h +++ b/src/installerprompt.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -25,11 +26,14 @@ public: private slots: void refreshNetworkList(); void onLanguageChanged(int index); + void onLanguageConfirm(); void onConnectWifiClicked(); void updateConnectionStatus(); void handleWiFiConnectionChange(NetworkManager::Device::State newstate, NetworkManager::Device::State oldstate, NetworkManager::Device::StateChangeReason reason); void tryLubuntu(); void installLubuntu(); + void languageProcessFinished(int exitCode, QProcess::ExitStatus exitStatus); + void languageProcessError(QProcess::ProcessError error); private: Ui::InstallerPrompt *ui; @@ -41,6 +45,8 @@ private: bool wifiWrongHandling = false; QLineEdit *passwordLineEdit; QMap languageLocaleMap; + QString selectedLanguage = "English (United States)"; + QString localeName = "en_US"; void handleWifiConnection(const QString &ssid, bool recoverFromWrongPassword = false); QString promptForWifiPassword(const QString &ssid, bool isWrongPassword = false); diff --git a/src/installerprompt.ui b/src/installerprompt.ui index 3920835..d2f85b4 100644 --- a/src/installerprompt.ui +++ b/src/installerprompt.ui @@ -62,6 +62,10 @@ QLabel#logoLabel { QLabel#incorrectPassword { color: red; +} + +KBusyIndicatorWidget { + color: blue; } @@ -171,6 +175,19 @@ QLabel#incorrectPassword { + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -186,54 +203,68 @@ QLabel#incorrectPassword { - - + + - 175 - 65 + 352 + 50 - 175 - 65 + 550 + 50 - 14 + 16 + + + + + + + + + 18 75 true - ✅ Confirm + Select Your Language: - - + + - 352 - 50 + 175 + 65 - 550 - 50 + 175 + 65 - 16 + 14 + 75 + true + + ✅ Confirm + - + true @@ -250,7 +281,33 @@ QLabel#incorrectPassword { - + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + @@ -264,7 +321,7 @@ QLabel#incorrectPassword { - + Qt::Horizontal @@ -277,33 +334,28 @@ QLabel#incorrectPassword { - - + + - 175 - 65 + 352 + 50 - 175 - 65 + 550 + 50 - 14 - 75 - true + 16 - - ✅ Connect - - + Qt::Horizontal @@ -316,21 +368,20 @@ QLabel#incorrectPassword { - - + + - 18 75 true - Select Your Language: + (For advanced network configuration, select "Try Lubuntu") - + Qt::Horizontal @@ -343,65 +394,67 @@ QLabel#incorrectPassword { - - - - Qt::Vertical - - - - 20 - 40 - - - - - - + + - 352 - 50 + 175 + 65 - 550 - 50 + 175 + 65 - 16 + 14 + 75 + true + + ✅ Connect + - - + + + 16 75 true - (For advanced network configuration, select "Try Lubuntu") + Changing language... - - - - Qt::Horizontal + + + + + 0 + 0 + - + - 40 - 20 + 35 + 35 - + + + 35 + 35 + + + @@ -710,6 +763,11 @@ QToolTip { + + KBusyIndicatorWidget + QWidget +
kbusyindicatorwidget.h
+
KLed QWidget