Files
iDescriptor/src/welcomewidget.cpp
T
uncor3 3c5fe6787b Refactor and enhance service management
- Updated CMakeLists.txt to set CPACK_WIX_UPGRADE_GUID directly.
- Enhanced DependencyItem and DiagnoseWidget to manage service availability states.
- Implemented service management functions for Windows, including starting services and checking their status.
- Improved UI responsiveness in WelcomeWidget and NetworkDevicesToConnectWidget.
- Introduced SERVICE_AVAILABILITY enum to standardize service state representation.
- Cleaned up unnecessary code and comments across various files.
2026-04-07 11:30:27 +03:00

161 lines
5.7 KiB
C++

/*
* iDescriptor: A free and open-source idevice management tool.
*
* Copyright (C) 2025 Uncore <https://github.com/uncor3>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "welcomewidget.h"
#include "diagnosewidget.h"
#include "iDescriptor-ui.h"
#include "iDescriptor.h"
#include "networkdevicestoconnectwidget.h"
#include "responsiveqlabel.h"
#include <QApplication>
#include <QDesktopServices>
#include <QEvent>
#include <QFont>
#include <QMouseEvent>
#include <QPalette>
#include <QUrl>
WelcomeWidget::WelcomeWidget(QWidget *parent) : QWidget(parent) { setupUI(); }
void WelcomeWidget::setupUI()
{
// Main layout with proper spacing and margins
m_mainLayout = new QVBoxLayout(this);
m_mainLayout->setContentsMargins(0, 10, 0, 0);
m_mainLayout->setSpacing(0);
// Add top stretch
m_mainLayout->addStretch(1);
// Welcome title
m_titleLabel = createStyledLabel("Welcome to iDescriptor", 28, true);
m_titleLabel->setAlignment(Qt::AlignCenter);
m_mainLayout->addWidget(m_titleLabel);
// Subtitle
m_subtitleLabel = createStyledLabel("Open-Source & Free", 10, false);
m_subtitleLabel->setAlignment(Qt::AlignCenter);
QPalette palette = m_subtitleLabel->palette();
m_mainLayout->addWidget(m_subtitleLabel);
QHBoxLayout *imageAndWirelessDevicesLayout = new QHBoxLayout();
m_imageLabel = new ResponsiveQLabel();
m_imageLabel->setPixmap(QPixmap(":/resources/connect.png"));
m_imageLabel->setMinimumWidth(200);
m_imageLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
m_imageLabel->setStyleSheet("background: transparent; border: none;");
m_imageLabel->setAlignment(Qt::AlignCenter);
imageAndWirelessDevicesLayout->addSpacing(40);
imageAndWirelessDevicesLayout->addWidget(m_imageLabel, 0, Qt::AlignHCenter);
imageAndWirelessDevicesLayout->addSpacing(40);
QVBoxLayout *explorerWithIntructionLayout = new QVBoxLayout();
NetworkDevicesToConnectWidget *networkDevicesWidget =
new NetworkDevicesToConnectWidget();
m_howToConnectLabel = createStyledLabel("How to connect a wireless device?",
12, true, COLOR_HYPERLINK);
m_howToConnectLabel->setWordWrap(false);
QPalette howToConnectLabelPalette = m_howToConnectLabel->palette();
howToConnectLabelPalette.setColor(QPalette::WindowText, COLOR_HYPERLINK);
m_howToConnectLabel->setPalette(howToConnectLabelPalette);
m_howToConnectLabel->setCursor(Qt::PointingHandCursor);
connect(m_howToConnectLabel, &ZLabel::clicked, this,
&WelcomeWidget::showHowToConnectDialog);
explorerWithIntructionLayout->addWidget(networkDevicesWidget);
explorerWithIntructionLayout->addWidget(m_howToConnectLabel, 0,
Qt::AlignCenter);
imageAndWirelessDevicesLayout->addLayout(explorerWithIntructionLayout);
m_mainLayout->addLayout(imageAndWirelessDevicesLayout);
m_mainLayout->addSpacing(10);
m_instructionLabel =
createStyledLabel("Connect an iDevice to get started", 14, false);
m_instructionLabel->setAlignment(Qt::AlignCenter);
m_mainLayout->addWidget(m_instructionLabel);
m_mainLayout->addSpacing(10);
// GitHub link
m_githubLabel = createStyledLabel("Found an issue? Report it on GitHub", 12,
true, COLOR_HYPERLINK);
m_githubLabel->setWordWrap(false);
m_githubLabel->setMaximumWidth(m_imageLabel->sizeHint().width());
m_githubLabel->setCursor(Qt::PointingHandCursor);
connect(m_githubLabel, &ZLabel::clicked, this,
[]() { QDesktopServices::openUrl(QUrl(REPO_URL)); });
QPalette githubPalette = m_githubLabel->palette();
githubPalette.setColor(QPalette::WindowText, COLOR_HYPERLINK);
m_githubLabel->setPalette(githubPalette);
m_mainLayout->addWidget(m_githubLabel, 0, Qt::AlignCenter);
// no additional deps needed on macOS
#ifndef __APPLE__
DiagnoseWidget *diagnoseWidget = new DiagnoseWidget();
m_mainLayout->addWidget(diagnoseWidget);
#endif
m_mainLayout->addStretch(1);
}
// FIXME: color param is only respected in Windows build
ZLabel *WelcomeWidget::createStyledLabel(const QString &text, int fontSize,
bool isBold, QColor color)
{
ZLabel *label = new ZLabel(text);
#ifndef WIN32
QFont font = label->font();
if (fontSize > 0) {
font.setPointSize(fontSize);
}
if (isBold) {
font.setWeight(QFont::Medium);
}
label->setFont(font);
label->setWordWrap(true);
#else
label->setStyleSheet(mergeStyles(
label,
QString("QLabel {"
" font-size: %1px;"
" font-weight: %2;"
"%3"
"}")
.arg(fontSize > 0 ? QString::number(fontSize) : "inherit")
.arg(isBold ? "bold" : "normal")
// FIXME: handle this better
.arg(color != Qt::black ? QString("color: %1;").arg(color.name())
: "")));
#endif
return label;
}
void WelcomeWidget::showHowToConnectDialog()
{
HowToConnectDialog(this).exec();
}