Add Language and WiFi dropdown boxes, plus, update the background image - builds but doesn't run

pull/2/head
Simon Quigley 1 year ago
parent ca33c24096
commit 5e616be3a4

@ -11,7 +11,10 @@ set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 REQUIRED COMPONENTS Core Widgets)
find_package(ECM REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
find_package(Qt5 REQUIRED COMPONENTS Core Widgets Network)
find_package(KF5 REQUIRED COMPONENTS NetworkManagerQt Notifications)
include_directories(${PROJECT_SOURCE_DIR}/src)
@ -23,7 +26,7 @@ file(GLOB PROJECT_SOURCES
add_executable(lubuntu-installer-prompt ${PROJECT_SOURCES})
target_link_libraries(lubuntu-installer-prompt Qt5::Widgets)
target_link_libraries(lubuntu-installer-prompt Qt5::Widgets KF5::NetworkManagerQt KF5::Notifications)
install(TARGETS lubuntu-installer-prompt DESTINATION bin)
install(PROGRAMS "scripts/lubuntu-installer" DESTINATION libexec)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 MiB

After

Width:  |  Height:  |  Size: 1.9 MiB

@ -1,37 +1,181 @@
#include <NetworkManagerQt/Manager>
#include <NetworkManagerQt/Device>
#include <NetworkManagerQt/WirelessDevice>
#include <NetworkManagerQt/WirelessNetwork>
#include <QProcess>
#include <QScreen>
#include <QMessageBox>
#include <QLineEdit>
#include "installerprompt.h"
#include "./ui_installerprompt.h"
InstallerPrompt::InstallerPrompt(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::InstallerPrompt)
{
, ui(new Ui::InstallerPrompt) {
ui->setupUi(this);
// Set the background image and scale it
QPixmap bg("/usr/share/lubuntu/installer-prompt/background.png");
if (bg.isNull()) {
QMessageBox::warning(this, tr("Error"), tr("Background image cannot be loaded."));
return;
}
QScreen *screen = QGuiApplication::primaryScreen();
QRect screenGeometry = screen->geometry();
int height = screenGeometry.height();
int width = screenGeometry.width();
bg = bg.scaled(width, height, Qt::IgnoreAspectRatio);
bg = bg.scaled(screenGeometry.size(), Qt::IgnoreAspectRatio);
QPalette palette;
palette.setBrush(QPalette::Window, bg);
this->setPalette(palette);
// Resize the layout widget to the screen size.
ui->gridLayoutWidget->resize(width, height);
// Resize the layout widget to the screen size
ui->gridLayoutWidget->resize(screenGeometry.size());
// Set the buttons to be translucent
ui->tryLubuntu->setAttribute(Qt::WA_TranslucentBackground);
ui->installLubuntu->setAttribute(Qt::WA_TranslucentBackground);
// Initialize process for external app launch
process = new QProcess(this);
// Slots and signals
// Set up signal-slot connections for buttons
connect(ui->tryLubuntu, &QAbstractButton::clicked, this, &InstallerPrompt::tryLubuntu);
connect(ui->installLubuntu, &QAbstractButton::clicked, this, &InstallerPrompt::installLubuntu);
// Set up the language combo box with available languages
initLanguageComboBox();
// Check initial network status and update UI
updateConnectionStatus(checkInternetConnection());
// Set up network manager signals for dynamic updates
auto nm = NetworkManager::notifier();
connect(nm, &NetworkManager::Notifier::deviceAdded, this, &InstallerPrompt::refreshNetworkList);
connect(nm, &NetworkManager::Notifier::deviceRemoved, this, &InstallerPrompt::refreshNetworkList);
connect(nm, &NetworkManager::Notifier::networkingEnabledChanged, this, &InstallerPrompt::refreshNetworkList);
}
bool InstallerPrompt::checkInternetConnection() {
for (const NetworkManager::Device::Ptr &device : NetworkManager::networkInterfaces()) {
if (device->type() == NetworkManager::Device::Wifi) {
auto wifiDevice = device.staticCast<NetworkManager::WirelessDevice>();
if (!wifiDevice->isActive()) {
showWifiOptions();
}
return wifiDevice->isActive();
}
}
return false;
}
void InstallerPrompt::updateConnectionStatus(bool online) {
if (online) {
connectionStatusLabel->setText(tr("Connected to the internet"));
connectWifiButton->setVisible(false);
} else {
connectionStatusLabel->setText(tr("Not connected to the internet"));
connectWifiButton->setVisible(true);
}
}
void InstallerPrompt::onConnectWifiClicked() {
QDialog *passwordDialog = new QDialog(this, Qt::Window | Qt::WindowStaysOnTopHint);
QVBoxLayout *layout = new QVBoxLayout(passwordDialog);
QLabel *label = new QLabel(tr("Enter Wi-Fi Password:"), passwordDialog);
QLineEdit *lineEdit = new QLineEdit(passwordDialog);
lineEdit->setEchoMode(QLineEdit::Password);
QPushButton *button = new QPushButton(tr("Connect"), passwordDialog);
layout->addWidget(label);
layout->addWidget(lineEdit);
layout->addWidget(button);
passwordDialog->setLayout(layout);
connect(button, &QPushButton::clicked, this, [this, lineEdit, passwordDialog]() {
QString password = lineEdit->text();
// Use the password to connect to the selected Wi-Fi network
// Make sure to handle the password securely and do not store it in plain text
passwordDialog->accept();
});
passwordDialog->exec();
}
void InstallerPrompt::showWifiOptions() {
bool foundWifiDevice = false;
for (const NetworkManager::Device::Ptr &device : NetworkManager::networkInterfaces()) {
if (device->type() == NetworkManager::Device::Wifi) {
foundWifiDevice = true;
auto wifiDevice = device.staticCast<NetworkManager::WirelessDevice>();
ui->networkComboBox->clear(); // Use the combo box from the UI file, clear existing items
for (const NetworkManager::WirelessNetwork::Ptr &network : wifiDevice->networks()) {
ui->networkComboBox->addItem(network->ssid()); // Add Wi-Fi networks to the combo box
}
break; // Handle the first Wi-Fi device
}
}
if (!foundWifiDevice) {
QMessageBox::information(this, tr("WiFi Not Available"), tr("No WiFi devices were found on this system."));
}
}
void InstallerPrompt::refreshNetworkList() {
NetworkManager::WirelessDevice::Ptr wirelessDevice;
// Iterate over network interfaces to find a wireless device
const auto devices = NetworkManager::networkInterfaces();
for (const auto &device : devices) {
if (device->type() == NetworkManager::Device::Wifi) {
wirelessDevice = device.staticCast<NetworkManager::WirelessDevice>();
break; // Break after finding the first wireless device
}
}
if (!wirelessDevice) {
// No wireless device found, handle appropriately
ui->networkComboBox->setVisible(false);
connectWifiButton->setVisible(false);
return;
}
// Get the list of available networks
const auto networks = wirelessDevice->networks();
ui->networkComboBox->clear();
for (const auto &network : networks) {
ui->networkComboBox->addItem(network->ssid());
}
// Adjust visibility based on whether any networks are found
ui->networkComboBox->setVisible(!networks.isEmpty());
connectWifiButton->setVisible(!networks.isEmpty());
}
void InstallerPrompt::initLanguageComboBox() {
// This should populate the language combo box from the UI file, not create a new one
QStringList languages = getAvailableLanguages();
ui->languageComboBox->addItems(languages); // Add items to the combo box
int defaultIndex = ui->languageComboBox->findText(QLocale(QLocale::English, QLocale::UnitedStates).nativeLanguageName());
if (defaultIndex != -1) {
ui->languageComboBox->setCurrentIndex(defaultIndex);
}
}
QStringList InstallerPrompt::getAvailableLanguages() const {
QStringList languageList;
for (int language = QLocale::Abkhazian; language <= QLocale::LastLanguage; ++language) {
QLocale locale(static_cast<QLocale::Language>(language));
QString languageName = locale.languageToString(locale.language());
if (!languageName.isEmpty() && !languageList.contains(languageName)) {
languageList.append(languageName);
}
}
languageList.sort(Qt::CaseInsensitive);
return languageList;
}
void InstallerPrompt::onLanguageChanged(int index) {
// Placeholder for handling language change
}
void InstallerPrompt::tryLubuntu()

@ -2,24 +2,46 @@
#define INSTALLERPROMPT_H
#include <QMainWindow>
#include <QComboBox>
#include <QProcess>
#include <QPushButton>
#include <QLabel>
#include <QDialog>
namespace NetworkManager {
class Device;
class WirelessDevice;
class WirelessNetwork;
}
QT_BEGIN_NAMESPACE
namespace Ui { class InstallerPrompt; }
QT_END_NAMESPACE
class InstallerPrompt : public QMainWindow
{
Q_OBJECT
public:
InstallerPrompt(QWidget *parent = nullptr);
~InstallerPrompt();
explicit InstallerPrompt(QWidget *parent = nullptr);
~InstallerPrompt() override;
public slots:
private slots:
void refreshNetworkList(); // Slot to handle network list refreshes
void onLanguageChanged(int index);
void onConnectWifiClicked();
void tryLubuntu();
void installLubuntu();
private:
Ui::InstallerPrompt *ui;
QProcess *process;
QPushButton *connectWifiButton;
QLabel *connectionStatusLabel;
void initLanguageComboBox();
QStringList getAvailableLanguages() const;
bool checkInternetConnection();
void showWifiOptions();
void updateConnectionStatus(bool online);
};
#endif
#endif // INSTALLERPROMPT_H

@ -19,6 +19,42 @@
<property name="windowTitle">
<string>Try or Install Lubuntu</string>
</property>
<property name="styleSheet">
<string notr="true">QWidget {
color: #000000; /* Set text color to black */
}
QPushButton {
background-color: rgba(30, 144, 255, 0.8);
color: #ffffff;
border: 2px solid #ffffff;
border-radius: 15px;
padding: 10px 20px;
margin: 10px;
}
QPushButton:hover {
background-color: rgba(30, 144, 255, 1);
}
QPushButton:disabled {
background-color: rgba(169, 169, 169, 0.8);
color: #ffffff;
}
QComboBox, QLineEdit {
background-color: rgba(255, 255, 255, 0.5);
color: #000000;
border: 1px solid #ffffff;
border-radius: 5px;
padding: 5px;
margin: 5px;
}
QLabel {
qproperty-alignment: 'AlignCenter';
}</string>
</property>
<widget class="QWidget" name="centralwidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
@ -94,6 +130,7 @@
<font>
<family>Ubuntu</family>
<pointsize>25</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
@ -151,6 +188,235 @@
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="comboBoxLayout">
<item>
<spacer name="comboSpacer1">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label">
<property name="font">
<font>
<pointsize>20</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Select Your Language:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="languageComboBox">
<property name="minimumSize">
<size>
<width>400</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>400</width>
<height>50</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="comboSpacer2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_11">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="WiFiLayout">
<item>
<spacer name="networkSpacer1">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<pointsize>20</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Select a WiFi Network:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="networkComboBox">
<property name="minimumSize">
<size>
<width>400</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>400</width>
<height>50</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="connectWifiButton">
<property name="minimumSize">
<size>
<width>100</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>50</height>
</size>
</property>
<property name="font">
<font>
<pointsize>14</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Connect</string>
</property>
</widget>
</item>
<item>
<spacer name="networkSpacer2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="WiFiLayout_2">
<item>
<spacer name="advancedSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<pointsize>14</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>(For advanced network configuration, select &quot;Try Lubuntu&quot;)</string>
</property>
</widget>
</item>
<item>
<spacer name="advancedSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_10">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="buttonLayout">
<item>
@ -219,7 +485,7 @@ QToolTip {
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -232,23 +498,7 @@ QToolTip {
</spacer>
</item>
<item>
<spacer name="titleStabilizer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>80</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="horizontalSpacer_4">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -324,19 +574,6 @@ QToolTip {
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
@ -402,6 +639,48 @@ QToolTip {
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="connectionStatusLayout">
<item>
<spacer name="networkSpacer1_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="connectionStatusLabel">
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="text">
<string>Connection Status: </string>
</property>
</widget>
</item>
<item>
<spacer name="networkSpacer2_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">

Loading…
Cancel
Save