A failure only opened a dialog whose text runs past the screen, and unlike the success path nothing wrote the build output anywhere, so the line that names the error was lost as soon as the box was closed.
1692 lines
71 KiB
C++
1692 lines
71 KiB
C++
#include "main-window.h"
|
|
|
|
#include <QAction>
|
|
#include <QActionGroup>
|
|
#include <QButtonGroup>
|
|
#include <QCoreApplication>
|
|
#include <QDesktopServices>
|
|
#include <QDragEnterEvent>
|
|
#include <QDropEvent>
|
|
#include <QFileInfo>
|
|
#include <QFrame>
|
|
#include <QMimeData>
|
|
#include <QHBoxLayout>
|
|
#include <QIcon>
|
|
#include <QInputDialog>
|
|
#include <QLabel>
|
|
#include <QLineEdit>
|
|
#include <QMenu>
|
|
#include <QMenuBar>
|
|
#include <QMessageBox>
|
|
#include <QPixmap>
|
|
#include <QProcess>
|
|
#include <QProgressBar>
|
|
#include <QPushButton>
|
|
#include <QShortcut>
|
|
#include <QStackedWidget>
|
|
#include <QStatusBar>
|
|
#include <QStyle>
|
|
#include <QSystemTrayIcon>
|
|
#include <QTimer>
|
|
#include <QUrl>
|
|
#include <QVBoxLayout>
|
|
|
|
#include "app-logging.h"
|
|
#include "log-manager.h"
|
|
#include "browse-page.h"
|
|
#include "cleanup-page.h"
|
|
#include "dashboard-page.h"
|
|
#include "history-page.h"
|
|
#include "language-manager.h"
|
|
#include "logs-page.h"
|
|
#include "page.h"
|
|
#include "plugins-page.h"
|
|
#include "settings-page.h"
|
|
|
|
// How long a wait reads best in the status bar: "45 s", "2 min 05", "1 h 03".
|
|
static QString formatElapsed(qint64 ms) {
|
|
const qint64 seconds = ms / 1000;
|
|
const qint64 minutes = seconds / 60;
|
|
if (minutes >= 60) {
|
|
return QStringLiteral("%1 h %2").arg(minutes / 60)
|
|
.arg(minutes % 60, 2, 10, QLatin1Char('0'));
|
|
}
|
|
if (minutes > 0) {
|
|
return QStringLiteral("%1 min %2").arg(minutes)
|
|
.arg(seconds % 60, 2, 10, QLatin1Char('0'));
|
|
}
|
|
return QStringLiteral("%1 s").arg(seconds);
|
|
}
|
|
|
|
// Load one of the embedded SVG icons (see resources/resources.qrc).
|
|
static QIcon loadIcon(const QString& name) {
|
|
return QIcon(QString(":/icons/%1.svg").arg(name));
|
|
}
|
|
|
|
// Render an SVG icon as a pixmap for use in QLabel, sizing it to the requested
|
|
// resolution.
|
|
static QPixmap iconPixmap(const QString& name, int size) {
|
|
return loadIcon(name).pixmap(QSize(size, size));
|
|
}
|
|
|
|
// Dialog title of a failed action: naming what failed is the frame's job (the
|
|
// core reports which action failed, not how to phrase it).
|
|
static QString actionErrorTitle(const QString& action) {
|
|
if (action == QLatin1String("install")) return QCoreApplication::translate("MainWindow", "Échec de l'installation");
|
|
if (action == QLatin1String("install-file")) {
|
|
return QCoreApplication::translate("MainWindow", "Échec de l'installation du fichier");
|
|
}
|
|
if (action == QLatin1String("remove")) return QCoreApplication::translate("MainWindow", "Échec de la suppression");
|
|
if (action == QLatin1String("update")) return QCoreApplication::translate("MainWindow", "Échec de la mise à jour");
|
|
if (action == QLatin1String("update-all")) {
|
|
return QCoreApplication::translate("MainWindow", "Erreur lors de la mise à jour globale");
|
|
}
|
|
if (action == QLatin1String("refresh")) {
|
|
return QCoreApplication::translate("MainWindow", "Erreur lors du rafraîchissement");
|
|
}
|
|
if (action == QLatin1String("clean-caches")) {
|
|
return QCoreApplication::translate("MainWindow", "Échec du nettoyage des caches");
|
|
}
|
|
if (action == QLatin1String("cleanup")) return QCoreApplication::translate("MainWindow", "Échec du nettoyage");
|
|
if (action == QLatin1String("install-plugin-tool")) {
|
|
return QCoreApplication::translate("MainWindow", "Échec de l'installation de l'outil");
|
|
}
|
|
if (action == QLatin1String("release-lock")) {
|
|
return QCoreApplication::translate("MainWindow", "Base de données verrouillée");
|
|
}
|
|
return QCoreApplication::translate("MainWindow", "Échec de l'opération");
|
|
}
|
|
|
|
// Everything the screens draw with. The look of the application is a single
|
|
// stylesheet applied to the window, so a screen file only describes its layout
|
|
// and its wording (see pages/ui-kit.h for the shared widgets).
|
|
//
|
|
// The palette and the shapes mirror the FWS website's stylesheets
|
|
// (p/assets/styles/var.css, styles.css and paquets.css): slate surfaces on a
|
|
// #0f172a page, a sky-blue accent, serif headings, pill-shaped badges and
|
|
// 8-16px radii. The site draws its borders and tints with rgba() over the
|
|
// surface below; a Qt stylesheet only takes a solid colour, so those values are
|
|
// pre-blended here onto the surface they sit on (#232c3f is the site's border
|
|
// over the page, #303b4e the same border over a card).
|
|
static QString appStyleSheet() {
|
|
return QStringLiteral(
|
|
// ---- Base ----
|
|
// Widgets stay transparent like in CSS: only real surfaces declare a
|
|
// background, so the page glow below shows through the layouts. The
|
|
// dialogs are listed explicitly because they are windows of their own
|
|
// and would otherwise fall back to the light system palette.
|
|
"QMainWindow, QDialog { background: #0f172a; }"
|
|
"QWidget { color: #e2e8f0; }"
|
|
// The site tints its dark page with a soft accent glow from the top
|
|
// left; Qt has no radial gradient, so a diagonal one stands in for it.
|
|
"QWidget#content {"
|
|
" background: qlineargradient(x1:0, y1:0, x2:0.85, y2:1,"
|
|
" stop:0 #13243b, stop:0.55 #0f172a, stop:1 #0f172a);"
|
|
"}"
|
|
// ---- Sidebar ----
|
|
// A raised surface, like the site's header and footer.
|
|
"QFrame#sidebar { background: #1e293b; border-right: 1px solid #232c3f; }"
|
|
"QWidget#logo { padding: 4px 0; }"
|
|
"QLabel#logoText { font-family: serif; font-size: 19px; font-weight: 700; color: #e2e8f0; }"
|
|
"QLabel#tagline { font-size: 11px; color: #64748b; padding: 0 8px 8px 8px; }"
|
|
// Navigation entries use the site's navigation idiom: a rounded shape
|
|
// that fills with the accent tint, the label turning accent.
|
|
"QPushButton[nav=\"true\"] {"
|
|
" text-align: left;"
|
|
" background: transparent;"
|
|
" border: 1px solid transparent;"
|
|
" border-radius: 8px;"
|
|
" padding: 9px 12px;"
|
|
" font-size: 13px;"
|
|
" font-weight: 600;"
|
|
" color: #94a3b8;"
|
|
"}"
|
|
"QPushButton[nav=\"true\"]:hover { background: #21384e; color: #7dd3fc; }"
|
|
"QPushButton[nav=\"true\"]:checked { background: #21384e; color: #38bdf8; }"
|
|
"QPushButton[nav=\"true\"]:disabled { color: #475569; }"
|
|
// ---- Header ----
|
|
"QWidget#header { background: #1e293b; border-bottom: 1px solid #232c3f; }"
|
|
"QLabel#headerTitle { font-family: serif; font-size: 21px; font-weight: 700; color: #e2e8f0; }"
|
|
"QLabel#headerSubtitle { font-size: 12px; color: #94a3b8; }"
|
|
// ---- Cards ----
|
|
// Cards read as raised surfaces: the site's slightly lighter slate, a
|
|
// hair line border and a rounded corner separate them from the page
|
|
// without adding shadows Qt cannot render consistently across
|
|
// platforms.
|
|
"QFrame#card {"
|
|
" background: #1e293b;"
|
|
" border: 1px solid #232c3f;"
|
|
" border-radius: 12px;"
|
|
"}"
|
|
// Stat cards carry a coloured left edge so the four metrics are told
|
|
// apart at a glance. The colours are the site's status and accent ones.
|
|
"QFrame#card[accent=\"blue\"] { border-left: 3px solid #38bdf8; }"
|
|
"QFrame#card[accent=\"amber\"] { border-left: 3px solid #fbbf24; }"
|
|
"QFrame#card[accent=\"cyan\"] { border-left: 3px solid #7dd3fc; }"
|
|
"QFrame#card[accent=\"green\"] { border-left: 3px solid #34d399; }"
|
|
// Small uppercase labels, as the site's section headings.
|
|
"QLabel#cardTitle { font-size: 11px; font-weight: 700; color: #64748b; letter-spacing: 1px; }"
|
|
"QLabel#statValue { font-size: 30px; font-weight: 800; color: #e2e8f0; }"
|
|
"QLabel#statTitle { font-size: 12px; color: #94a3b8; font-weight: 600; }"
|
|
// ---- Sidebar extras ----
|
|
"QLabel#sectionTitle {"
|
|
" font-size: 10px;"
|
|
" font-weight: 800;"
|
|
" color: #64748b;"
|
|
" letter-spacing: 1.2px;"
|
|
" padding: 14px 10px 2px 10px;"
|
|
"}"
|
|
"QLabel#versionLabel { font-size: 11px; color: #64748b; padding: 8px 10px; }"
|
|
"QPushButton[nav=\"true\"][highlighted=\"true\"] { color: #fbbf24; }"
|
|
// ---- Buttons ----
|
|
// Mirrors the site's .button: rounded, 1px transparent border that
|
|
// takes the accent when hovered, and a darker fill on hover.
|
|
"QPushButton {"
|
|
" background: #273449;"
|
|
" color: #94a3b8;"
|
|
" border: 1px solid #303b4e;"
|
|
" border-radius: 8px;"
|
|
" padding: 8px 16px;"
|
|
" font-size: 13px;"
|
|
" font-weight: 600;"
|
|
"}"
|
|
"QPushButton:hover { background: #29445e; border-color: #7dd3fc; color: #38bdf8; }"
|
|
"QPushButton:pressed { background: #22384d; color: #7dd3fc; }"
|
|
"QPushButton:disabled { background: #232c3f; border-color: transparent; color: #64748b; }"
|
|
"QPushButton[variant=\"primary\"] { background: #38bdf8; border-color: transparent; color: #0f172a; }"
|
|
"QPushButton[variant=\"primary\"]:hover { background: #0ea5e9; color: #0f172a; }"
|
|
"QPushButton[variant=\"primary\"]:pressed { background: #0284c7; color: #0f172a; }"
|
|
"QPushButton[variant=\"success\"] { background: #34d399; border-color: transparent; color: #0f172a; }"
|
|
"QPushButton[variant=\"success\"]:hover { background: #10b981; color: #0f172a; }"
|
|
"QPushButton[variant=\"success\"]:pressed { background: #059669; color: #0f172a; }"
|
|
"QPushButton[variant=\"danger\"] { background: #f87171; border-color: transparent; color: #0f172a; }"
|
|
"QPushButton[variant=\"danger\"]:hover { background: #ef4444; color: #0f172a; }"
|
|
"QPushButton[variant=\"danger\"]:pressed { background: #dc2626; color: #0f172a; }"
|
|
"QPushButton[variant=\"warning\"] { background: #fbbf24; border-color: transparent; color: #0f172a; }"
|
|
"QPushButton[variant=\"warning\"]:hover { background: #f59e0b; color: #0f172a; }"
|
|
"QPushButton[variant=\"warning\"]:pressed { background: #d97706; color: #0f172a; }"
|
|
"QPushButton[variant=\"info\"] { background: #7dd3fc; border-color: transparent; color: #0f172a; }"
|
|
"QPushButton[variant=\"info\"]:hover { background: #38bdf8; color: #0f172a; }"
|
|
"QPushButton[variant=\"info\"]:pressed { background: #0ea5e9; color: #0f172a; }"
|
|
// A disabled button keeps the muted fill of the site's :disabled rule,
|
|
// whatever its variant.
|
|
"QPushButton[variant=\"primary\"]:disabled, QPushButton[variant=\"success\"]:disabled,"
|
|
"QPushButton[variant=\"danger\"]:disabled, QPushButton[variant=\"warning\"]:disabled,"
|
|
"QPushButton[variant=\"info\"]:disabled {"
|
|
" background: #232c3f; border-color: transparent; color: #64748b;"
|
|
"}"
|
|
// ---- Inputs ----
|
|
"QLineEdit {"
|
|
" background: #1e293b;"
|
|
" border: 1px solid #303b4e;"
|
|
" border-radius: 8px;"
|
|
" padding: 9px 14px;"
|
|
" font-size: 13px;"
|
|
" color: #e2e8f0;"
|
|
" selection-background-color: #38bdf8;"
|
|
" selection-color: #0f172a;"
|
|
"}"
|
|
"QLineEdit:hover { border-color: #475569; }"
|
|
"QLineEdit:focus { border: 1px solid #38bdf8; }"
|
|
"QLineEdit:disabled { color: #64748b; }"
|
|
"QComboBox {"
|
|
" background: #1e293b;"
|
|
" border: 1px solid #303b4e;"
|
|
" border-radius: 8px;"
|
|
" padding: 7px 12px;"
|
|
" font-size: 13px;"
|
|
" color: #e2e8f0;"
|
|
"}"
|
|
"QComboBox:hover { border-color: #7dd3fc; }"
|
|
// ---- Settings screen ----
|
|
// The cards scroll as a whole: the area itself must not paint, or the
|
|
// page gradient would be cut off at its edges.
|
|
"QScrollArea { background: transparent; border: none; }"
|
|
"QScrollArea > QWidget > QWidget { background: transparent; }"
|
|
// Explanatory text under each control, in the site's secondary colour.
|
|
"QLabel#settingHint { font-size: 12px; color: #94a3b8; }"
|
|
"QCheckBox { font-size: 13px; color: #e2e8f0; spacing: 8px; }"
|
|
"QCheckBox::indicator {"
|
|
" width: 18px; height: 18px;"
|
|
" border: 1px solid #475569; border-radius: 5px; background: #1e293b;"
|
|
"}"
|
|
"QCheckBox::indicator:hover { border-color: #7dd3fc; }"
|
|
"QCheckBox::indicator:checked {"
|
|
" background: #38bdf8; border-color: #38bdf8;"
|
|
" image: url(:/icons/check-dark.svg);"
|
|
"}"
|
|
"QComboBox::drop-down { border: none; width: 26px; }"
|
|
"QComboBox QAbstractItemView {"
|
|
" background: #273449;"
|
|
" border: 1px solid #303b4e;"
|
|
" selection-background-color: #21384e;"
|
|
" selection-color: #38bdf8;"
|
|
" color: #e2e8f0;"
|
|
"}"
|
|
// ---- Progress bar ----
|
|
// The value is spelled out beside the bar rather than inside it: the
|
|
// label Qt centres on the bar would sit half on the fill and half on
|
|
// the track, where no single colour stays readable.
|
|
"QLabel#progressLabel { color: #7dd3fc; font-size: 11px; font-weight: 700; padding-right: 8px; }"
|
|
"QProgressBar { background: #273449; border: none; border-radius: 4px; }"
|
|
"QProgressBar::chunk { background: #38bdf8; border-radius: 4px; }"
|
|
// ---- Package table ----
|
|
// No outer frame: the table blends with the card it sits in, keeping
|
|
// only the column header and alternating rows as visual separators.
|
|
"QTableWidget {"
|
|
" background: transparent;"
|
|
" alternate-background-color: #223044;"
|
|
" border: none;"
|
|
" gridline-color: transparent;"
|
|
" outline: 0;"
|
|
"}"
|
|
"QTableWidget::item { border: none; padding: 4px 8px; }"
|
|
"QTableWidget::item:selected { background: #21384e; color: #e2e8f0; }"
|
|
// Hover stays below the selection tint, so a hovered row is never
|
|
// mistaken for the selected one.
|
|
"QTableWidget::item:hover { background: #1b2b40; }"
|
|
"QHeaderView { background: transparent; }"
|
|
"QHeaderView::section {"
|
|
" background: transparent;"
|
|
" color: #64748b;"
|
|
" border: none;"
|
|
" border-bottom: 1px solid #303b4e;"
|
|
" padding: 8px;"
|
|
" font-size: 11px;"
|
|
" font-weight: 700;"
|
|
" letter-spacing: 1px;"
|
|
"}"
|
|
// ---- Recent activity list ----
|
|
"QListWidget#recentList { background: transparent; border: none; outline: 0; }"
|
|
"QListWidget#recentList::item { border-radius: 8px; margin: 1px 2px; }"
|
|
"QListWidget#recentList::item:hover { background: #21384e; }"
|
|
// ---- Logs editor ----
|
|
// Recessed like the site's inline code: the page colour, not a card.
|
|
"QTextEdit {"
|
|
" background: #0f172a;"
|
|
" color: #e2e8f0;"
|
|
" border: 1px solid #303b4e;"
|
|
" border-radius: 12px;"
|
|
" padding: 10px;"
|
|
" font-family: monospace;"
|
|
" font-size: 13px;"
|
|
"}"
|
|
// ---- Menus ----
|
|
// The menu strip shares the header's surface, so the two read as the
|
|
// site's single top band.
|
|
"QMenuBar { background: #1e293b; color: #94a3b8; padding: 2px 4px; }"
|
|
"QMenuBar::item { padding: 6px 10px; border-radius: 6px; background: transparent; }"
|
|
"QMenuBar::item:selected { background: #21384e; color: #38bdf8; }"
|
|
"QMenu {"
|
|
" background: #1e293b;"
|
|
" color: #e2e8f0;"
|
|
" border: 1px solid #303b4e;"
|
|
" border-radius: 8px;"
|
|
" padding: 6px;"
|
|
"}"
|
|
// The popup's own margin (the shadow the platform draws around it) is
|
|
// not part of this widget: it is filled from the application palette,
|
|
// which is why appPalette() has to carry the same surface colour. Left
|
|
// alone it is the desktop's default, i.e. a light band above and below
|
|
// the menu on a light theme.
|
|
"QMenu::item { padding: 7px 24px 7px 14px; border-radius: 6px; }"
|
|
"QMenu::item:selected { background: #21384e; color: #38bdf8; }"
|
|
"QMenu::item:disabled { color: #64748b; }"
|
|
"QMenu::separator { height: 1px; background: #303b4e; margin: 6px 8px; }"
|
|
// ---- Scrollbars ----
|
|
"QScrollBar:vertical { background: transparent; width: 10px; margin: 2px; }"
|
|
"QScrollBar::handle:vertical { background: #273449; border-radius: 5px; min-height: 30px; }"
|
|
"QScrollBar::handle:vertical:hover { background: #38bdf8; }"
|
|
"QScrollBar:horizontal { background: transparent; height: 10px; margin: 2px; }"
|
|
"QScrollBar::handle:horizontal { background: #273449; border-radius: 5px; min-width: 30px; }"
|
|
"QScrollBar::handle:horizontal:hover { background: #38bdf8; }"
|
|
"QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical,"
|
|
"QScrollBar::add-line:horizontal, QScrollBar::sub-line:horizontal { height: 0; width: 0; }"
|
|
"QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical,"
|
|
"QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal { background: transparent; }"
|
|
// ---- Status bar ----
|
|
"QStatusBar {"
|
|
" background: #1e293b;"
|
|
" color: #94a3b8;"
|
|
" border-top: 1px solid #232c3f;"
|
|
" font-size: 12px;"
|
|
"}"
|
|
// ---- Splitter ----
|
|
"QSplitter::handle { background: transparent; }"
|
|
// ---- Tooltips ----
|
|
"QToolTip {"
|
|
" background: #273449;"
|
|
" color: #e2e8f0;"
|
|
" border: 1px solid #303b4e;"
|
|
" border-radius: 8px;"
|
|
" padding: 4px 8px;"
|
|
"}");
|
|
}
|
|
|
|
// Colours the stylesheet cannot reach.
|
|
//
|
|
// A QMenu is a separate native popup: only its inner widget is drawn by the
|
|
// stylesheet, while the margin the platform leaves around it — the shadow — is
|
|
// filled from the application palette. On a light desktop theme that margin is
|
|
// white, which shows up as a light band above and below the menu. Giving the
|
|
// palette the window's own surface colour makes the whole popup one colour.
|
|
//
|
|
// The values repeat appStyleSheet()'s on purpose: a palette is a set of roles,
|
|
// not CSS, and there is no way to point one at a stylesheet. They must be kept
|
|
// in step with the token table in doc/interface.md.
|
|
QPalette MainWindow::appPalette() {
|
|
const QColor window(0x1e, 0x29, 0x3b); // surface
|
|
const QColor raised(0x27, 0x34, 0x49); // raised surface
|
|
const QColor text(0xe2, 0xe8, 0xf0); // text
|
|
const QColor muted(0x94, 0xa3, 0xb8); // secondary text
|
|
const QColor accent(0x38, 0xbd, 0xf8); // accent
|
|
|
|
// Qt 6 has no separate Menu role, and that is exactly the point: the margin
|
|
// a QMenu popup is drawn with is filled from Window, so this is the colour
|
|
// that removes the light band.
|
|
QPalette palette;
|
|
palette.setColor(QPalette::Window, window);
|
|
palette.setColor(QPalette::WindowText, text);
|
|
palette.setColor(QPalette::Base, raised);
|
|
palette.setColor(QPalette::AlternateBase, window);
|
|
palette.setColor(QPalette::Text, text);
|
|
palette.setColor(QPalette::Button, raised);
|
|
palette.setColor(QPalette::ButtonText, text);
|
|
palette.setColor(QPalette::BrightText, Qt::white);
|
|
palette.setColor(QPalette::ToolTipBase, raised);
|
|
palette.setColor(QPalette::ToolTipText, text);
|
|
palette.setColor(QPalette::Highlight, accent);
|
|
palette.setColor(QPalette::HighlightedText, QColor(0x0f, 0x17, 0x2a));
|
|
palette.setColor(QPalette::PlaceholderText, muted);
|
|
return palette;
|
|
}
|
|
|
|
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
|
|
m_core = new AppCore(this);
|
|
|
|
connect(m_core, &AppCore::listFinished, this, &MainWindow::onCoreListFinished);
|
|
connect(m_core, &AppCore::actionProgress, this, &MainWindow::onCoreActionProgress);
|
|
connect(m_core, &AppCore::actionFinished, this, &MainWindow::onCoreActionFinished);
|
|
connect(m_core, &AppCore::busyChanged, this, &MainWindow::onCoreBusyChanged);
|
|
connect(m_core, &AppCore::statusMessage, this, &MainWindow::onCoreStatusMessage);
|
|
connect(m_core, &AppCore::historyChanged, this, &MainWindow::onCoreHistoryChanged);
|
|
connect(m_core, &AppCore::updateCheckFinished, this,
|
|
&MainWindow::onCoreUpdateCheckFinished);
|
|
connect(m_core, &AppCore::selfUpdateFinished, this,
|
|
&MainWindow::onCoreSelfUpdateFinished);
|
|
|
|
// The preferences the window reacts to rather than merely reads: dropping a
|
|
// file and switching language are both things the user does on the Settings
|
|
// screen and expects to see take effect at once.
|
|
AppSettings& preferences = AppSettings::instance();
|
|
connect(&preferences, &AppSettings::dragDropEnabledChanged, this,
|
|
&MainWindow::onDragDropEnabledChanged);
|
|
connect(&preferences, &AppSettings::languageChanged, this,
|
|
&MainWindow::onLanguageChanged);
|
|
|
|
setupUI();
|
|
setupMenuBar();
|
|
setupTray();
|
|
setupShortcuts();
|
|
|
|
// Addon plugins get the main window so they can attach their own UI
|
|
// (status-bar widgets, toolbar buttons, ...). Only enabled+available
|
|
// addons receive it: that part is pure UI, so it stays on this side.
|
|
for (IPlugin* addon : m_core->plugins()->availableAddons()) {
|
|
addon->onUiReady(this);
|
|
}
|
|
|
|
if (!m_core->hasAvailableProvider()) {
|
|
statusBar()->showMessage(tr("Aucun gestionnaire de paquets disponible sur ce système."));
|
|
// Nothing to search, list, install or clean: grey out the screens that
|
|
// need a provider rather than letting each of them fail.
|
|
for (int navId : {NavSearch, NavInstalled, NavUpdates, NavCleanup}) {
|
|
if (QAbstractButton* button = m_navGroup->button(navId)) {
|
|
button->setEnabled(false);
|
|
}
|
|
}
|
|
m_refreshButton->setEnabled(false);
|
|
m_headerUpdateAllButton->setEnabled(false);
|
|
m_dashboard->refresh();
|
|
return;
|
|
}
|
|
|
|
// "Tout mettre à jour" is only meaningful with a provider that can update;
|
|
// without this it stayed greyed out even when pacman was available.
|
|
m_headerUpdateAllButton->setEnabled(false);
|
|
for (IPackageManager* pm : m_core->availableProviders()) {
|
|
if (pm->canUpdate()) {
|
|
m_headerUpdateAllButton->setEnabled(true);
|
|
break;
|
|
}
|
|
}
|
|
|
|
m_dashboard->refresh();
|
|
updateStatusBar();
|
|
|
|
// With per-session credentials, ask for the sudo password once, right
|
|
// after the window is shown (so the dialog has a visible parent).
|
|
if (m_core->credentialMode() == AppCore::CredentialMode::AtLaunch) {
|
|
QTimer::singleShot(0, this, [this] { promptForSudoPassword(); });
|
|
}
|
|
|
|
// Check for app updates once per day (or on first launch). The delay lets
|
|
// the window appear first so the status bar message is visible.
|
|
if (m_core->shouldCheckForAppUpdate()) {
|
|
QTimer::singleShot(1500, this, &MainWindow::onCheckForUpdates);
|
|
}
|
|
}
|
|
|
|
MainWindow::~MainWindow() = default;
|
|
|
|
void MainWindow::setupUI() {
|
|
QWidget* centralWidget = new QWidget(this);
|
|
QHBoxLayout* rootLayout = new QHBoxLayout(centralWidget);
|
|
rootLayout->setContentsMargins(0, 0, 0, 0);
|
|
rootLayout->setSpacing(0);
|
|
|
|
setupSidebar();
|
|
rootLayout->addWidget(m_sidebar);
|
|
|
|
// Right column: header + stacked screens
|
|
QWidget* content = new QWidget();
|
|
content->setObjectName("content");
|
|
QVBoxLayout* contentLayout = new QVBoxLayout(content);
|
|
contentLayout->setContentsMargins(0, 0, 0, 0);
|
|
contentLayout->setSpacing(0);
|
|
|
|
setupHeader();
|
|
contentLayout->addWidget(m_headerWidget);
|
|
|
|
setupPages();
|
|
contentLayout->addWidget(m_pages, 1);
|
|
|
|
rootLayout->addWidget(content, 1);
|
|
setCentralWidget(centralWidget);
|
|
|
|
statusBar()->showMessage(tr("Prêt"));
|
|
|
|
// Flatpak files can be dropped anywhere on the window (see dragEnterEvent),
|
|
// unless the user turned that off on the Settings screen.
|
|
setAcceptDrops(AppSettings::instance().dragDropEnabled());
|
|
|
|
// Progress of the running operation, anchored at the bottom of the window
|
|
// so it takes no space on the screens. It appears while install/update/
|
|
// remove/search operations run: indeterminate at first, then filled to the
|
|
// real percentage reported by the provider (see onCoreActionProgress).
|
|
m_progressLabel = new QLabel();
|
|
m_progressLabel->setObjectName("progressLabel");
|
|
m_progressLabel->setVisible(false);
|
|
statusBar()->addPermanentWidget(m_progressLabel);
|
|
|
|
m_installProgressBar = new QProgressBar();
|
|
m_installProgressBar->setRange(0, 0);
|
|
m_installProgressBar->setTextVisible(false);
|
|
m_installProgressBar->setFixedHeight(8);
|
|
m_installProgressBar->setFixedWidth(160);
|
|
m_installProgressBar->setVisible(false);
|
|
statusBar()->addPermanentWidget(m_installProgressBar);
|
|
|
|
// Watchdog of the running operation: it is what tells a two-minute download
|
|
// from a frozen app (see onActivityTick).
|
|
m_activityTimer = new QTimer(this);
|
|
m_activityTimer->setInterval(1000);
|
|
connect(m_activityTimer, &QTimer::timeout, this, &MainWindow::onActivityTick);
|
|
|
|
setStyleSheet(appStyleSheet());
|
|
}
|
|
|
|
void MainWindow::setupSidebar() {
|
|
m_sidebar = new QFrame();
|
|
m_sidebar->setObjectName("sidebar");
|
|
m_sidebar->setFixedWidth(210);
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout(m_sidebar);
|
|
layout->setContentsMargins(12, 16, 12, 12);
|
|
layout->setSpacing(4);
|
|
|
|
QWidget* logoRow = new QWidget();
|
|
logoRow->setObjectName("logo");
|
|
QHBoxLayout* logoLayout = new QHBoxLayout(logoRow);
|
|
logoLayout->setContentsMargins(8, 2, 8, 2);
|
|
logoLayout->setSpacing(8);
|
|
|
|
QLabel* logoIcon = new QLabel();
|
|
logoIcon->setPixmap(iconPixmap("package", 20));
|
|
logoLayout->addWidget(logoIcon);
|
|
|
|
QLabel* appTitle = new QLabel("PacManager");
|
|
appTitle->setObjectName("logoText");
|
|
logoLayout->addWidget(appTitle);
|
|
logoLayout->addStretch();
|
|
layout->addWidget(logoRow);
|
|
|
|
QLabel* appSubtitle = new QLabel(tr("Gestionnaire de paquets Arch Linux"));
|
|
appSubtitle->setObjectName("tagline");
|
|
appSubtitle->setWordWrap(true);
|
|
layout->addWidget(appSubtitle);
|
|
|
|
layout->addSpacing(14);
|
|
|
|
m_navGroup = new QButtonGroup(this);
|
|
m_navGroup->setExclusive(true);
|
|
|
|
auto addSection = [&](const QString& title) {
|
|
QLabel* label = new QLabel(title);
|
|
label->setObjectName("sectionTitle");
|
|
layout->addWidget(label);
|
|
};
|
|
|
|
auto addNavButton = [&](int id, const QString& iconName,
|
|
const QString& text, const QString& tip) {
|
|
QPushButton* btn = new QPushButton(text);
|
|
btn->setProperty("nav", true);
|
|
btn->setCheckable(true);
|
|
btn->setToolTip(tip);
|
|
btn->setCursor(Qt::PointingHandCursor);
|
|
btn->setIcon(loadIcon(iconName));
|
|
btn->setIconSize(QSize(17, 17));
|
|
m_navGroup->addButton(btn, id);
|
|
m_navButtons.insert(id, btn);
|
|
layout->addWidget(btn);
|
|
return btn;
|
|
};
|
|
|
|
addSection("GESTION");
|
|
addNavButton(NavDashboard, "home", tr("Tableau de bord"), tr("Vue d'ensemble du système"));
|
|
addNavButton(NavSearch, "search", "Recherche", tr("Rechercher des paquets"));
|
|
addNavButton(NavInstalled, "package", tr("Installés"), tr("Voir les paquets installés"));
|
|
m_navUpdatesButton = addNavButton(NavUpdates, "arrow-up", tr("Mises à jour"),
|
|
tr("Voir les mises à jour disponibles"));
|
|
|
|
addSection(tr("SYSTÈME"));
|
|
addNavButton(NavCleanup, "broom", tr("Nettoyage"),
|
|
tr("Purger les paquets inutilisés ou legacy et vider les caches"));
|
|
addNavButton(NavHistory, "history", tr("Historique"), tr("Historique des actions"));
|
|
addNavButton(NavLogs, "logs", tr("Logs"), tr("Logs pacman"));
|
|
addNavButton(NavPlugins, "plugin", tr("Plugins"), tr("Gestionnaires de paquets et extensions"));
|
|
// No entry for the settings screen: it is not a place to browse from, and
|
|
// the menu bar is the one way in (see openSettingsPage).
|
|
|
|
connect(m_navGroup, &QButtonGroup::idClicked, this, &MainWindow::onNavChanged);
|
|
m_navGroup->button(NavDashboard)->setChecked(true);
|
|
|
|
layout->addStretch();
|
|
|
|
m_refreshButton = new QPushButton(tr("Rafraîchir les sources"));
|
|
m_refreshButton->setProperty("nav", true);
|
|
m_refreshButton->setIcon(loadIcon("refresh"));
|
|
m_refreshButton->setIconSize(QSize(17, 17));
|
|
m_refreshButton->setToolTip(tr("Rafraîchir les bases de données (pacman -Sy)"));
|
|
connect(m_refreshButton, &QPushButton::clicked, this, &MainWindow::onRefresh);
|
|
layout->addWidget(m_refreshButton);
|
|
|
|
// The version actually installed, right where the user looks for it.
|
|
m_versionLabel = new QLabel(QString("v%1").arg(UpdateManager::currentVersion()));
|
|
m_versionLabel->setObjectName("versionLabel");
|
|
m_versionLabel->setAlignment(Qt::AlignCenter);
|
|
m_versionLabel->setToolTip(tr("Version installée de PacManager"));
|
|
layout->addWidget(m_versionLabel);
|
|
}
|
|
|
|
void MainWindow::setupHeader() {
|
|
m_headerWidget = new QWidget();
|
|
m_headerWidget->setObjectName("header");
|
|
m_headerWidget->setFixedHeight(74);
|
|
|
|
QHBoxLayout* layout = new QHBoxLayout(m_headerWidget);
|
|
layout->setContentsMargins(24, 0, 24, 0);
|
|
layout->setSpacing(6);
|
|
|
|
QVBoxLayout* textLayout = new QVBoxLayout();
|
|
textLayout->setSpacing(2);
|
|
|
|
m_headerTitle = new QLabel(tr("Tableau de bord"));
|
|
m_headerTitle->setObjectName("headerTitle");
|
|
textLayout->addWidget(m_headerTitle);
|
|
|
|
m_headerSubtitle = new QLabel(tr("Vue d'ensemble de votre système"));
|
|
m_headerSubtitle->setObjectName("headerSubtitle");
|
|
textLayout->addWidget(m_headerSubtitle);
|
|
|
|
layout->addLayout(textLayout);
|
|
layout->addStretch();
|
|
|
|
// The two actions used most often stay reachable from every screen instead
|
|
// of only from the dashboard.
|
|
QPushButton* refreshBtn = new QPushButton(tr("Rafraîchir"));
|
|
refreshBtn->setIcon(loadIcon("refresh"));
|
|
refreshBtn->setToolTip(tr("Rafraîchir les bases de données (Ctrl+R)"));
|
|
connect(refreshBtn, &QPushButton::clicked, this, &MainWindow::onRefresh);
|
|
layout->addWidget(refreshBtn);
|
|
|
|
m_headerUpdateAllButton = new QPushButton(tr("Tout mettre à jour"));
|
|
m_headerUpdateAllButton->setProperty("variant", "warning");
|
|
m_headerUpdateAllButton->setIcon(loadIcon("arrow-up"));
|
|
m_headerUpdateAllButton->setToolTip(
|
|
tr("Mettre à jour tous les paquets (Ctrl+U affiche la liste)"));
|
|
connect(m_headerUpdateAllButton, &QPushButton::clicked, this, &MainWindow::onUpdateAll);
|
|
layout->addWidget(m_headerUpdateAllButton);
|
|
}
|
|
|
|
// One screen per file under pages/: the frame only stacks them and answers
|
|
// their requests.
|
|
void MainWindow::setupPages() {
|
|
m_pages = new QStackedWidget();
|
|
|
|
m_dashboard = new DashboardPage(m_core);
|
|
registerPage("dashboard", NavDashboard, m_dashboard);
|
|
connect(m_dashboard, &DashboardPage::openPackage, this, &MainWindow::onOpenPackage);
|
|
|
|
// Search, installed and updates are three sidebar entries landing on the
|
|
// same screen with a different query behind it.
|
|
m_browse = new BrowsePage(m_core);
|
|
registerPage("search", NavSearch, m_browse);
|
|
m_navIdByPage.insert("installed", NavInstalled);
|
|
m_navIdByPage.insert("updates", NavUpdates);
|
|
|
|
m_cleanup = new CleanupPage(m_core);
|
|
registerPage("cleanup", NavCleanup, m_cleanup);
|
|
|
|
m_history = new HistoryPage(m_core);
|
|
registerPage("history", NavHistory, m_history);
|
|
|
|
m_logs = new LogsPage(m_core);
|
|
registerPage("logs", NavLogs, m_logs);
|
|
|
|
m_plugins = new PluginsPage(m_core);
|
|
registerPage("plugins", NavPlugins, m_plugins);
|
|
|
|
m_settings = new SettingsPage(m_core);
|
|
registerPage("settings", NavSettings, m_settings);
|
|
connect(m_settings, &Page::credentialModeRequested, this,
|
|
&MainWindow::onCredentialModeRequested);
|
|
}
|
|
|
|
void MainWindow::registerPage(const QString& id, int navId, Page* page) {
|
|
m_pageById.insert(id, page);
|
|
m_navIdByPage.insert(id, navId);
|
|
m_pages->addWidget(page);
|
|
|
|
connect(page, &Page::requestStart, this, &MainWindow::onStartRequested);
|
|
connect(page, &Page::message, this, &MainWindow::onPageMessage);
|
|
connect(page, &Page::goToPage, this, &MainWindow::onOpenPage);
|
|
}
|
|
|
|
Page* MainWindow::currentPage() const {
|
|
return qobject_cast<Page*>(m_pages->currentWidget());
|
|
}
|
|
|
|
void MainWindow::updatePageTitle() {
|
|
Page* page = currentPage();
|
|
if (!page) return;
|
|
m_headerTitle->setText(page->navTitle());
|
|
m_headerSubtitle->setText(page->navSubtitle());
|
|
}
|
|
|
|
void MainWindow::updateStatusBar() {
|
|
const int providers = static_cast<int>(m_core->availableProviders().size());
|
|
if (providers == 0) {
|
|
statusBar()->showMessage(tr("Aucun gestionnaire de paquets disponible."));
|
|
return;
|
|
}
|
|
QString info = QString(
|
|
tr("%1 gestionnaire(s) actif(s) | Paquets affichés : %2 | Actions enregistrées : %3"))
|
|
.arg(providers)
|
|
.arg(m_browse->resultCount())
|
|
.arg(m_core->historyCount());
|
|
statusBar()->showMessage(info);
|
|
}
|
|
|
|
void MainWindow::setUpdatesBadge(int count) {
|
|
if (!m_navUpdatesButton) return;
|
|
m_updatesBadgeCount = count;
|
|
|
|
m_navUpdatesButton->setText(count > 0
|
|
? QString(tr("Mises à jour · %1")).arg(count)
|
|
: QString(tr("Mises à jour")));
|
|
|
|
// A dynamic property only takes effect once the style is re-applied, so it
|
|
// is only touched when it actually changes.
|
|
const bool highlighted = count > 0;
|
|
if (m_navUpdatesButton->property("highlighted").toBool() == highlighted) return;
|
|
m_navUpdatesButton->setProperty("highlighted", highlighted);
|
|
m_navUpdatesButton->style()->unpolish(m_navUpdatesButton);
|
|
m_navUpdatesButton->style()->polish(m_navUpdatesButton);
|
|
}
|
|
|
|
void MainWindow::notifyUpdatesAvailable(int count) {
|
|
if (!m_tray || count <= 0) return;
|
|
m_tray->showMessage("PacManager",
|
|
QString(tr("%1 mise(s) à jour disponible(s)")).arg(count),
|
|
QSystemTrayIcon::Information, 5000);
|
|
}
|
|
|
|
void MainWindow::setupMenuBar() {
|
|
// The menu bar and its menus are styled by the window stylesheet
|
|
// (appStyleSheet), which also covers the tray menu.
|
|
QMenuBar* menuBar = this->menuBar();
|
|
|
|
auto goTo = [this](int navId) {
|
|
if (QAbstractButton* button = m_navGroup->button(navId)) button->click();
|
|
};
|
|
|
|
QMenu* fileMenu = menuBar->addMenu(tr("Fichier"));
|
|
fileMenu->addAction(tr("Exporter la liste affichée..."), this, [this] {
|
|
LogManager::instance().logEvent(QStringLiteral("ui"),
|
|
tr("export de la liste affichée"));
|
|
m_browse->exportCsv();
|
|
});
|
|
fileMenu->addAction(tr("Exporter l'historique..."), this, [this] {
|
|
LogManager::instance().logEvent(QStringLiteral("ui"),
|
|
tr("export de l'historique"));
|
|
m_history->exportCsv();
|
|
});
|
|
fileMenu->addSeparator();
|
|
fileMenu->addAction(tr("Quitter"), this, &QWidget::close);
|
|
|
|
QMenu* toolsMenu = menuBar->addMenu(tr("Outils"));
|
|
toolsMenu->addAction(tr("Tableau de bord"), this, [this, goTo] { goTo(NavDashboard); });
|
|
toolsMenu->addAction(tr("Rechercher"), this, [this] {
|
|
m_navGroup->button(NavSearch)->click();
|
|
m_browse->focusSearch();
|
|
});
|
|
toolsMenu->addAction(tr("Paquets installés"), this, [this, goTo] { goTo(NavInstalled); });
|
|
toolsMenu->addAction(tr("Mises à jour"), this, [this, goTo] { goTo(NavUpdates); });
|
|
toolsMenu->addAction(tr("Nettoyage"), this, [this, goTo] { goTo(NavCleanup); });
|
|
toolsMenu->addAction(tr("Historique"), this, [this, goTo] { goTo(NavHistory); });
|
|
toolsMenu->addAction(tr("Logs pacman"), this, [this, goTo] { goTo(NavLogs); });
|
|
toolsMenu->addAction(tr("Plugins"), this, [this, goTo] { goTo(NavPlugins); });
|
|
toolsMenu->addSeparator();
|
|
toolsMenu->addAction(tr("Prévisualiser les mises à jour"), this, [this, goTo] {
|
|
goTo(NavUpdates);
|
|
statusBar()->showMessage(tr("Prévisualisation des mises à jour disponibles"));
|
|
});
|
|
toolsMenu->addAction(tr("Rafraîchir les sources"), this, &MainWindow::onRefresh);
|
|
|
|
QMenu* settingsMenu = menuBar->addMenu(tr("Paramètres"));
|
|
|
|
// The dedicated screen holds every preference; the two entries below are
|
|
// shortcuts to the one that would otherwise be a menu of its own.
|
|
settingsMenu->addAction(tr("Ouvrir les paramètres"), this,
|
|
&MainWindow::openSettingsPage);
|
|
settingsMenu->addSeparator();
|
|
|
|
QActionGroup* credGroup = new QActionGroup(this);
|
|
credGroup->setExclusive(true);
|
|
|
|
QAction* credTitle = settingsMenu->addAction(tr("Identifiants sudo"));
|
|
credTitle->setEnabled(false);
|
|
|
|
m_credEachTimeAction = settingsMenu->addAction(tr("Demander à chaque fois"));
|
|
m_credEachTimeAction->setCheckable(true);
|
|
m_credEachTimeAction->setToolTip(tr("Demande le mot de passe avant chaque opération"));
|
|
credGroup->addAction(m_credEachTimeAction);
|
|
|
|
m_credLaunchAction = settingsMenu->addAction(tr("Demander au lancement"));
|
|
m_credLaunchAction->setCheckable(true);
|
|
m_credLaunchAction->setToolTip(tr("Demande le mot de passe une seule fois, au lancement"));
|
|
credGroup->addAction(m_credLaunchAction);
|
|
|
|
const bool atLaunch =
|
|
m_core->credentialMode() == AppCore::CredentialMode::AtLaunch;
|
|
(atLaunch ? m_credLaunchAction : m_credEachTimeAction)->setChecked(true);
|
|
|
|
connect(m_credEachTimeAction, &QAction::triggered, this,
|
|
[this]() { onCredentialModeRequested(false); });
|
|
connect(m_credLaunchAction, &QAction::triggered, this,
|
|
[this]() { onCredentialModeRequested(true); });
|
|
|
|
QMenu* helpMenu = menuBar->addMenu(tr("Aide"));
|
|
helpMenu->addAction(tr("Vérifier les mises à jour"), this, &MainWindow::onCheckForUpdates);
|
|
helpMenu->addSeparator();
|
|
helpMenu->addAction(tr("À propos"), [this]() {
|
|
QMessageBox::about(this, "PacManager",
|
|
QString(tr("<h2>PacManager v%1</h2>"
|
|
"<p>Gestionnaire de paquets pour Arch Linux (pacman).</p>"))
|
|
.arg(UpdateManager::currentVersion()));
|
|
});
|
|
}
|
|
|
|
// System tray: optional, only created when the desktop actually provides one.
|
|
// Offers quick access to the pending updates from outside the window.
|
|
void MainWindow::setupTray() {
|
|
if (!QSystemTrayIcon::isSystemTrayAvailable()) return;
|
|
|
|
m_tray = new QSystemTrayIcon(loadIcon("package"), this);
|
|
m_tray->setToolTip("PacManager");
|
|
|
|
QMenu* menu = new QMenu(this);
|
|
menu->addAction(tr("Afficher PacManager"), this, [this]() {
|
|
showNormal();
|
|
raise();
|
|
activateWindow();
|
|
});
|
|
menu->addSeparator();
|
|
menu->addAction(tr("Vérifier les mises à jour"), this, &MainWindow::onCheckForUpdates);
|
|
menu->addAction(tr("Prévisualiser les mises à jour"), this, [this]() {
|
|
m_navGroup->button(NavUpdates)->click();
|
|
});
|
|
menu->addAction(tr("Tout mettre à jour"), this, &MainWindow::onUpdateAll);
|
|
menu->addSeparator();
|
|
menu->addAction(tr("Quitter"), this, &QWidget::close);
|
|
m_tray->setContextMenu(menu);
|
|
|
|
connect(m_tray, &QSystemTrayIcon::activated, this, &MainWindow::onTrayActivated);
|
|
m_tray->show();
|
|
}
|
|
|
|
// Keyboard shortcuts for the actions used most often.
|
|
void MainWindow::setupShortcuts() {
|
|
auto bind = [this](const QKeySequence& key, const std::function<void()>& action) {
|
|
QShortcut* shortcut = new QShortcut(key, this);
|
|
shortcut->setContext(Qt::WindowShortcut);
|
|
connect(shortcut, &QShortcut::activated, this, action);
|
|
};
|
|
|
|
bind(QKeySequence::Find, [this]() {
|
|
m_navGroup->button(NavSearch)->click();
|
|
m_browse->focusSearch();
|
|
});
|
|
bind(QKeySequence::Refresh, [this]() { onRefresh(); });
|
|
bind(QKeySequence(Qt::Key_F5), [this]() { onRefresh(); });
|
|
bind(QKeySequence(QStringLiteral("Ctrl+U")), [this]() {
|
|
m_navGroup->button(NavUpdates)->click();
|
|
});
|
|
// The convention every other application uses for its own settings.
|
|
bind(QKeySequence(QStringLiteral("Ctrl+,")), [this]() { openSettingsPage(); });
|
|
bind(QKeySequence(QStringLiteral("Ctrl+E")), [this]() {
|
|
LogManager::instance().logEvent(QStringLiteral("ui"),
|
|
tr("export de la liste affichée"));
|
|
m_browse->exportCsv();
|
|
});
|
|
bind(QKeySequence::Quit, [this]() { close(); });
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Navigation and page requests
|
|
// ---------------------------------------------------------------------------
|
|
|
|
void MainWindow::onNavChanged(int id) {
|
|
// Navigating is not something the journal narrates: changing screen is not
|
|
// an operation, and a line per click buries the ones that are.
|
|
switch (id) {
|
|
case NavDashboard:
|
|
m_pages->setCurrentWidget(m_dashboard);
|
|
m_dashboard->refresh();
|
|
break;
|
|
case NavSearch:
|
|
m_pages->setCurrentWidget(m_browse);
|
|
m_browse->showSearch();
|
|
break;
|
|
case NavInstalled:
|
|
m_pages->setCurrentWidget(m_browse);
|
|
m_browse->showInstalled();
|
|
break;
|
|
case NavUpdates:
|
|
m_pages->setCurrentWidget(m_browse);
|
|
m_browse->showUpdates();
|
|
break;
|
|
case NavCleanup:
|
|
m_pages->setCurrentWidget(m_cleanup);
|
|
m_cleanup->refresh();
|
|
break;
|
|
case NavHistory:
|
|
m_pages->setCurrentWidget(m_history);
|
|
m_history->refresh();
|
|
break;
|
|
case NavLogs:
|
|
m_pages->setCurrentWidget(m_logs);
|
|
m_logs->refresh();
|
|
break;
|
|
case NavPlugins:
|
|
m_pages->setCurrentWidget(m_plugins);
|
|
m_plugins->refresh();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
updatePageTitle();
|
|
}
|
|
|
|
void MainWindow::onOpenPage(const QString& pageId) {
|
|
const int navId = m_navIdByPage.value(pageId, -1);
|
|
if (navId < 0) return;
|
|
// The settings screen has no navigation button to click, so it is opened
|
|
// directly; every other screen is reached by clicking its own button.
|
|
if (pageId == QLatin1String("settings")) {
|
|
openSettingsPage();
|
|
return;
|
|
}
|
|
if (QAbstractButton* button = m_navGroup->button(navId)) button->click();
|
|
}
|
|
|
|
// The settings screen is the one screen without a sidebar entry: it is not a
|
|
// destination to browse from, so the Paramètres menu and Ctrl+, are the only
|
|
// ways in. Everything a navigation button does for free — switching the stacked
|
|
// widget, reloading, retitling, journalling — is done here instead.
|
|
void MainWindow::openSettingsPage() {
|
|
// Nothing stays selected in the sidebar: the settings screen is not one of
|
|
// the places it lists, and leaving the previous entry highlighted would
|
|
// point at the wrong screen. The group has to stop being exclusive first,
|
|
// otherwise it puts one of its buttons back as soon as none is checked.
|
|
m_navGroup->setExclusive(false);
|
|
for (QAbstractButton* button : m_navGroup->buttons()) button->setChecked(false);
|
|
m_navGroup->setExclusive(true);
|
|
|
|
m_pages->setCurrentWidget(m_settings);
|
|
m_settings->refresh();
|
|
updatePageTitle();
|
|
}
|
|
|
|
// Navigates to the Installed screen and opens the package the user clicked in
|
|
// the dashboard activity list.
|
|
void MainWindow::onOpenPackage(const QString& name) {
|
|
if (name.isEmpty()) return;
|
|
|
|
LogManager::instance().logEvent(
|
|
QStringLiteral("ui"),
|
|
tr("ouverture des détails de %1").arg(name));
|
|
m_browse->selectOnNextLoad(name);
|
|
if (QAbstractButton* button = m_navGroup->button(NavInstalled)) button->click();
|
|
statusBar()->showMessage(QString(tr("Ouverture des détails de %1...")).arg(name));
|
|
}
|
|
|
|
void MainWindow::onPageMessage(const QString& text) {
|
|
statusBar()->showMessage(text);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Installing files (drag & drop, "Ouvrir avec PacManager")
|
|
// ---------------------------------------------------------------------------
|
|
|
|
QStringList MainWindow::installableDroppedFiles(const QMimeData* mimeData) const {
|
|
QStringList files;
|
|
if (!AppSettings::instance().dragDropEnabled()) return files;
|
|
if (!mimeData || !mimeData->hasUrls()) return files;
|
|
|
|
for (const QUrl& url : mimeData->urls()) {
|
|
// Only local files: a URL would have to be downloaded by the provider
|
|
// first, and a remote .flatpakref is better opened from a browser.
|
|
if (!url.isLocalFile()) continue;
|
|
const QString path = url.toLocalFile();
|
|
if (m_core->canInstallFile(path) || m_core->isPluginPackage(path)) files << path;
|
|
}
|
|
return files;
|
|
}
|
|
|
|
void MainWindow::dragEnterEvent(QDragEnterEvent* event) {
|
|
if (installableDroppedFiles(event->mimeData()).isEmpty()) {
|
|
event->ignore();
|
|
return;
|
|
}
|
|
event->acceptProposedAction();
|
|
}
|
|
|
|
void MainWindow::dragMoveEvent(QDragMoveEvent* event) {
|
|
// Desktop environments send move events all along the drag: ignoring them
|
|
// would leave the drop cursor on "forbidden" even though the drop itself is
|
|
// accepted.
|
|
if (installableDroppedFiles(event->mimeData()).isEmpty()) {
|
|
event->ignore();
|
|
return;
|
|
}
|
|
event->acceptProposedAction();
|
|
}
|
|
|
|
void MainWindow::dropEvent(QDropEvent* event) {
|
|
const QStringList files = installableDroppedFiles(event->mimeData());
|
|
if (files.isEmpty()) {
|
|
event->ignore();
|
|
return;
|
|
}
|
|
event->acceptProposedAction();
|
|
|
|
LogManager::instance().logEvent(
|
|
QStringLiteral("fichier"),
|
|
tr("%1 fichier(s) déposé(s)").arg(files.size()));
|
|
installLocalFiles(files);
|
|
}
|
|
|
|
void MainWindow::installLocalFiles(const QStringList& paths) {
|
|
if (paths.isEmpty()) return;
|
|
|
|
QStringList files;
|
|
QStringList rejected;
|
|
for (const QString& path : paths) {
|
|
// A plugin package is installed by the core straight away: it needs no
|
|
// provider, no password and no queue, and the registry is reloaded when
|
|
// it lands (see AppCore::installPluginPackage).
|
|
if (m_core->isPluginPackage(path)) {
|
|
m_core->installPluginPackage(path);
|
|
continue;
|
|
}
|
|
if (m_core->canInstallFile(path)) files << path;
|
|
else rejected << path;
|
|
}
|
|
|
|
// A file opened with the wrong application is worth a one-line explanation
|
|
// rather than a silent no-op.
|
|
if (!rejected.isEmpty()) {
|
|
statusBar()->showMessage(
|
|
tr("%1 : format non reconnu (PacManager installe les fichiers "
|
|
".flatpakref, .flatpakrepo, .flatpak et les paquets de plugin "
|
|
".fwspacm).")
|
|
.arg(QFileInfo(rejected.first()).fileName()));
|
|
}
|
|
|
|
if (files.isEmpty()) return;
|
|
|
|
LogManager::instance().logEvent(
|
|
QStringLiteral("fichier"),
|
|
tr("installation de %1").arg(files.join(QStringLiteral(", "))));
|
|
m_pendingFileInstalls << files;
|
|
if (!m_fileInstallRunning) startNextFileInstall();
|
|
}
|
|
|
|
void MainWindow::startNextFileInstall() {
|
|
if (m_pendingFileInstalls.isEmpty()) {
|
|
m_fileInstallRunning = false;
|
|
return;
|
|
}
|
|
|
|
const QString path = m_pendingFileInstalls.first();
|
|
m_fileInstallRunning = true;
|
|
|
|
const AppCore::StartResult result = m_core->installFile(path);
|
|
if (!result.started) {
|
|
if (result.needsPassword) {
|
|
// Flatpak installs need no password, but a provider that does gets
|
|
// the same prompt as every other operation. The file leaves the
|
|
// queue once the replay really started; a cancelled prompt drops it
|
|
// rather than blocking the ones behind it.
|
|
handleStartResult(result, tr("Installation du fichier"));
|
|
m_pendingFileInstalls.removeFirst();
|
|
if (m_core->busy()) return;
|
|
m_fileInstallRunning = false;
|
|
startNextFileInstall();
|
|
return;
|
|
}
|
|
if (m_core->busy()) {
|
|
// Another operation owns the core: leave the file queued and try
|
|
// again once it has finished (see onCoreActionFinished).
|
|
m_fileInstallRunning = false;
|
|
return;
|
|
}
|
|
m_pendingFileInstalls.removeFirst();
|
|
m_fileInstallRunning = false;
|
|
statusBar()->showMessage(result.error);
|
|
startNextFileInstall();
|
|
return;
|
|
}
|
|
|
|
m_pendingFileInstalls.removeFirst();
|
|
statusBar()->showMessage(tr("Installation de %1...")
|
|
.arg(QFileInfo(path).fileName()));
|
|
}
|
|
|
|
void MainWindow::onStartRequested(const AppCore::StartResult& result, const QString& title) {
|
|
handleStartResult(result, title);
|
|
}
|
|
|
|
void MainWindow::onRefresh() {
|
|
LogManager::instance().logEvent(QStringLiteral("ui"),
|
|
tr("clic rafraîchir les sources"));
|
|
handleStartResult(m_core->refresh(), tr("Rafraîchissement des sources"));
|
|
}
|
|
|
|
void MainWindow::onUpdateAll() {
|
|
LogManager::instance().logEvent(QStringLiteral("ui"),
|
|
tr("clic tout mettre à jour"));
|
|
handleStartResult(m_core->updateAll(), tr("Mise à jour globale"));
|
|
}
|
|
|
|
void MainWindow::onTrayActivated(QSystemTrayIcon::ActivationReason reason) {
|
|
// A click on the icon brings the window back from the background.
|
|
if (reason != QSystemTrayIcon::Trigger && reason != QSystemTrayIcon::DoubleClick) {
|
|
return;
|
|
}
|
|
showNormal();
|
|
raise();
|
|
activateWindow();
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Credentials, database lock and failure reporting
|
|
// ---------------------------------------------------------------------------
|
|
|
|
void MainWindow::applyCredentialMode(AppCore::CredentialMode mode) {
|
|
LogManager::instance().logEvent(
|
|
QStringLiteral("ui"),
|
|
tr("mode d'identifiants → %1")
|
|
.arg(mode == AppCore::CredentialMode::AtLaunch ? tr("au lancement")
|
|
: tr("à chaque fois")));
|
|
m_core->setCredentialMode(mode);
|
|
// Per-session credentials: prompt once now so operations don't re-ask. The
|
|
// core reports the mode change in the status bar itself.
|
|
if (mode == AppCore::CredentialMode::AtLaunch) promptForSudoPassword();
|
|
}
|
|
|
|
// One place answers a change of mode, whichever of the two entry points (the
|
|
// menu bar, the Settings screen) asked for it, so both end up in step.
|
|
void MainWindow::onCredentialModeRequested(bool atLaunch) {
|
|
applyCredentialMode(atLaunch ? AppCore::CredentialMode::AtLaunch
|
|
: AppCore::CredentialMode::EachTime);
|
|
(atLaunch ? m_credLaunchAction : m_credEachTimeAction)->setChecked(true);
|
|
}
|
|
|
|
void MainWindow::onLanguageChanged(const QString& code) {
|
|
LogManager::instance().logEvent(QStringLiteral("config"),
|
|
tr("langue → %1").arg(code));
|
|
// Qt asks every widget to retranslate itself through the LanguageChange
|
|
// event, which this window answers in changeEvent().
|
|
LanguageManager::apply(code);
|
|
}
|
|
|
|
void MainWindow::onDragDropEnabledChanged(bool enabled) {
|
|
// The preference governs the window's own drop target only: files handed
|
|
// over by the desktop ("Ouvrir avec PacManager") keep working either way.
|
|
setAcceptDrops(enabled);
|
|
LogManager::instance().logEvent(
|
|
QStringLiteral("config"),
|
|
tr("glisser-déposer → %1")
|
|
.arg(enabled ? tr("activé") : tr("désactivé")));
|
|
}
|
|
|
|
void MainWindow::retranslateUI() {
|
|
// The screens provide their own title, so the header follows them.
|
|
updatePageTitle();
|
|
|
|
if (m_versionLabel) {
|
|
m_versionLabel->setText(QStringLiteral("v%1").arg(UpdateManager::currentVersion()));
|
|
}
|
|
|
|
struct NavLabel { int id; const char* text; const char* tip; };
|
|
// Kept next to the sidebar: those strings are the frame's, and the screens
|
|
// below retranslate themselves.
|
|
static const NavLabel kNavLabels[] = {
|
|
{NavDashboard, QT_TRANSLATE_NOOP("MainWindow", ("Tableau de bord")),
|
|
QT_TRANSLATE_NOOP("MainWindow", ("Vue d'ensemble du système"))},
|
|
{NavSearch, QT_TRANSLATE_NOOP("MainWindow", "Recherche"),
|
|
QT_TRANSLATE_NOOP("MainWindow", ("Rechercher des paquets"))},
|
|
{NavInstalled, QT_TRANSLATE_NOOP("MainWindow", ("Installés")),
|
|
QT_TRANSLATE_NOOP("MainWindow", ("Voir les paquets installés"))},
|
|
{NavUpdates, QT_TRANSLATE_NOOP("MainWindow", ("Mises à jour")),
|
|
QT_TRANSLATE_NOOP("MainWindow", ("Voir les mises à jour disponibles"))},
|
|
{NavCleanup, QT_TRANSLATE_NOOP("MainWindow", ("Nettoyage")),
|
|
QT_TRANSLATE_NOOP("MainWindow", ("Purger les paquets inutilisés ou legacy et vider les caches"))},
|
|
{NavHistory, QT_TRANSLATE_NOOP("MainWindow", ("Historique")),
|
|
QT_TRANSLATE_NOOP("MainWindow", ("Historique des actions"))},
|
|
{NavLogs, QT_TRANSLATE_NOOP("MainWindow", ("Logs")),
|
|
QT_TRANSLATE_NOOP("MainWindow", ("Logs pacman"))},
|
|
{NavPlugins, QT_TRANSLATE_NOOP("MainWindow", ("Plugins")),
|
|
QT_TRANSLATE_NOOP("MainWindow", ("Gestionnaires de paquets et extensions"))},
|
|
};
|
|
|
|
for (const NavLabel& label : kNavLabels) {
|
|
auto it = m_navButtons.find(label.id);
|
|
if (it == m_navButtons.end()) continue;
|
|
// The updates entry carries its pending count in its label, which
|
|
// setUpdatesBadge() is the one to rebuild.
|
|
if (label.id != NavUpdates) it.value()->setText(tr(label.text));
|
|
it.value()->setToolTip(tr(label.tip));
|
|
}
|
|
setUpdatesBadge(m_updatesBadgeCount);
|
|
|
|
if (m_refreshButton) m_refreshButton->setText(tr("Rafraîchir les sources"));
|
|
if (m_headerUpdateAllButton) {
|
|
m_headerUpdateAllButton->setText(tr("Tout mettre à jour"));
|
|
}
|
|
}
|
|
|
|
void MainWindow::changeEvent(QEvent* event) {
|
|
if (event->type() == QEvent::LanguageChange) {
|
|
retranslateUI();
|
|
}
|
|
QMainWindow::changeEvent(event);
|
|
}
|
|
|
|
// The core knows *when* a password is needed (it owns the credential state and
|
|
// the sudo pipeline); the frame only owns the dialog.
|
|
bool MainWindow::promptForSudoPassword() {
|
|
if (m_core->hasSudoPassword()) return true;
|
|
|
|
LogManager::instance().logEvent(
|
|
QStringLiteral("ui"),
|
|
tr("demande du mot de passe administrateur"));
|
|
|
|
bool ok = false;
|
|
const QString password = QInputDialog::getText(
|
|
this, "Authentification",
|
|
tr("Mot de passe administrateur (sudo) :"),
|
|
QLineEdit::Password, QString(), &ok);
|
|
if (!ok) {
|
|
LogManager::instance().logEvent(
|
|
QStringLiteral("ui"),
|
|
tr("mot de passe refusé par l'utilisateur"));
|
|
statusBar()->showMessage(tr("Opération annulée : identifiants requis."));
|
|
return false;
|
|
}
|
|
|
|
LogManager::instance().logEvent(QStringLiteral("ui"),
|
|
tr("mot de passe fourni"));
|
|
m_core->setSudoPassword(password);
|
|
return true;
|
|
}
|
|
|
|
void MainWindow::showActionError(const QString& title, const QString& error, bool locked) {
|
|
LogManager::instance().logEvent(
|
|
QStringLiteral("erreur"),
|
|
tr("%1 : %2").arg(title, error.isEmpty() ? tr("sans détail") : error));
|
|
|
|
// A locked database is the one failure the app can resolve on its own, so it
|
|
// gets its own dialog instead of a message the user has to act on by hand.
|
|
if (locked) {
|
|
handleDatabaseLock(title);
|
|
return;
|
|
}
|
|
if (!error.isEmpty()) QMessageBox::warning(this, title, error);
|
|
}
|
|
|
|
// A page refused to start: ask for the password, free pacman's lock, or report
|
|
// the reason — then replay the request.
|
|
void MainWindow::handleStartResult(const AppCore::StartResult& result,
|
|
const QString& title) {
|
|
if (result.started) return;
|
|
|
|
if (result.needsPassword) {
|
|
if (!promptForSudoPassword()) {
|
|
statusBar()->showMessage(tr("Opération annulée : identifiants requis."));
|
|
m_core->cancelPendingRequest();
|
|
return;
|
|
}
|
|
// The core kept the request pending: replay it with the password now
|
|
// available. A second refusal is reported like the first one.
|
|
handleStartResult(m_core->retryPendingRequest(), title);
|
|
return;
|
|
}
|
|
|
|
if (result.locked) {
|
|
handleDatabaseLock(title);
|
|
return;
|
|
}
|
|
|
|
if (!result.error.isEmpty()) statusBar()->showMessage(result.error);
|
|
}
|
|
|
|
void MainWindow::handleDatabaseLock(const QString& title) {
|
|
LogManager::instance().logEvent(
|
|
QStringLiteral("verrou"),
|
|
tr("%1 : %2").arg(title, m_core->databaseLockDescription()));
|
|
|
|
// The other manager frequently finishes while the failed operation was
|
|
// unwinding: retry straight away rather than announcing a lock that is gone.
|
|
if (!m_core->databaseLocked()) {
|
|
statusBar()->showMessage(tr("Base pacman libérée, nouvelle tentative..."));
|
|
QTimer::singleShot(0, this, [this, title] {
|
|
handleStartResult(m_core->retryPendingRequest(), title);
|
|
});
|
|
return;
|
|
}
|
|
|
|
const PacmanManager::LockHolder holder = m_core->lockHolder();
|
|
const QString holderName = m_core->databaseLockDescription();
|
|
|
|
QMessageBox box(this);
|
|
box.setWindowTitle(title);
|
|
box.setIcon(QMessageBox::Warning);
|
|
box.setTextFormat(Qt::RichText);
|
|
// The action only promises a resume when there is one to replay: a lock hit
|
|
// by an operation with no pending retry just needs the database freed.
|
|
const bool canRetry = m_core->hasPendingRequest();
|
|
const QString resume = canRetry
|
|
? tr(" PacManager reprendra ensuite l'opération automatiquement.")
|
|
: QString();
|
|
|
|
if (holder.pid > 0) {
|
|
box.setText(QString(tr("<b>%1</b> utilise déjà la base pacman.")).arg(holderName));
|
|
box.setInformativeText(
|
|
tr("Le fermer libère la base ; une transaction en cours sera "
|
|
"interrompue.") + resume);
|
|
} else {
|
|
box.setText(QString(tr("La base pacman est verrouillée par %1.")).arg(holderName));
|
|
box.setInformativeText(
|
|
tr("Aucun gestionnaire ne tourne : le verrou peut être supprimé sans "
|
|
"risque.") + resume);
|
|
}
|
|
|
|
QPushButton* resolveBtn = box.addButton(
|
|
holder.pid > 0 ? (canRetry ? tr("Fermer et réessayer")
|
|
: tr("Fermer le gestionnaire"))
|
|
: (canRetry ? tr("Supprimer et réessayer")
|
|
: tr("Supprimer le verrou")),
|
|
QMessageBox::AcceptRole);
|
|
QPushButton* retryBtn =
|
|
box.addButton(tr("Réessayer"), QMessageBox::ActionRole);
|
|
box.addButton(tr("Plus tard"), QMessageBox::RejectRole);
|
|
box.exec();
|
|
|
|
if (box.clickedButton() == retryBtn) {
|
|
QTimer::singleShot(0, this, [this, title] {
|
|
handleStartResult(m_core->retryPendingRequest(), title);
|
|
});
|
|
return;
|
|
}
|
|
if (box.clickedButton() != resolveBtn) {
|
|
m_core->cancelPendingRequest();
|
|
return;
|
|
}
|
|
|
|
// Stopping another user's manager (or removing a root-owned lock file) needs
|
|
// the sudo password, which the session may not hold yet.
|
|
if (!promptForSudoPassword()) {
|
|
m_core->cancelPendingRequest();
|
|
return;
|
|
}
|
|
|
|
// The core replays the pending action itself once the lock is gone.
|
|
handleStartResult(m_core->releaseDatabaseLock(), title);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Results reported by the core
|
|
// ---------------------------------------------------------------------------
|
|
|
|
void MainWindow::onCoreListFinished(AppCore::ListMode mode,
|
|
std::vector<PackageInfo> results) {
|
|
if (mode != AppCore::ListMode::Updates) return;
|
|
|
|
const int count = static_cast<int>(results.size());
|
|
setUpdatesBadge(count);
|
|
// Notify once per distinct count, so the periodic dashboard refresh does not
|
|
// re-pop the tray message.
|
|
if (count != m_lastNotifiedUpdates) {
|
|
m_lastNotifiedUpdates = count;
|
|
notifyUpdatesAvailable(count);
|
|
}
|
|
}
|
|
|
|
void MainWindow::onCoreActionProgress(const QString& message, int percent) {
|
|
if (!message.isEmpty()) statusBar()->showMessage(message);
|
|
noteOperationOutput(message);
|
|
if (percent < 0) return;
|
|
|
|
// A provider running several commands (or a second provider after the
|
|
// first) starts its own count at 0: within one operation the bar only ever
|
|
// moves forward, so a retry or a second command never sends it backwards.
|
|
if (percent > m_progressValue) m_progressValue = percent;
|
|
|
|
m_installProgressBar->setVisible(true);
|
|
m_installProgressBar->setRange(0, 100);
|
|
m_installProgressBar->setValue(m_progressValue);
|
|
|
|
m_progressLabel->setText(QString("%1 %").arg(m_progressValue));
|
|
m_progressLabel->setVisible(true);
|
|
}
|
|
|
|
void MainWindow::onCoreActionFinished(const QString& action, const QString& name,
|
|
bool success, const QString& error, bool locked) {
|
|
if (!success) showActionError(actionErrorTitle(action), error, locked);
|
|
|
|
// The screens refresh themselves through the core signals they subscribe to
|
|
// (a listing reload for the browse page, and so on); the frame only keeps
|
|
// the dashboard figures fresh.
|
|
if (action == QLatin1String("install") || action == QLatin1String("remove")
|
|
|| action == QLatin1String("update") || action == QLatin1String("update-all")
|
|
|| action == QLatin1String("refresh") || action == QLatin1String("clean-caches")
|
|
|| action == QLatin1String("install-file")
|
|
|| action == QLatin1String("install-plugin-tool")) {
|
|
m_dashboard->refresh();
|
|
}
|
|
|
|
// Queued files run one after the other: this is where the next one starts,
|
|
// whether the previous install succeeded or failed. It also picks the queue
|
|
// up when a file had to wait for a core that was busy with another action.
|
|
if (!m_pendingFileInstalls.isEmpty() && !m_fileInstallRunning) {
|
|
QTimer::singleShot(0, this, [this] { startNextFileInstall(); });
|
|
}
|
|
|
|
Q_UNUSED(name);
|
|
}
|
|
|
|
void MainWindow::onCoreBusyChanged(bool busy) {
|
|
// Any pending "hide the finished bar" timer belongs to the previous
|
|
// operation and must not touch the new one.
|
|
++m_progressGeneration;
|
|
|
|
if (busy) {
|
|
m_operationClock.start();
|
|
m_operationStep.clear();
|
|
m_lastOutputAtMs = 0;
|
|
m_lastWaitNoteMs = 0;
|
|
m_activityTimer->start();
|
|
} else {
|
|
m_activityTimer->stop();
|
|
m_operationClock.invalidate();
|
|
}
|
|
|
|
if (!busy) {
|
|
if (m_installProgressBar->isVisible() && m_installProgressBar->maximum() > 0) {
|
|
// Real progress was shown: complete it and let it be seen. A bar
|
|
// that disappears at 97 % looks like a failure.
|
|
m_installProgressBar->setValue(100);
|
|
m_progressLabel->setText(QStringLiteral("100 %"));
|
|
const int generation = m_progressGeneration;
|
|
QTimer::singleShot(500, this, [this, generation] {
|
|
if (generation != m_progressGeneration) return;
|
|
m_installProgressBar->setVisible(false);
|
|
m_progressLabel->setVisible(false);
|
|
});
|
|
return;
|
|
}
|
|
m_installProgressBar->setVisible(false);
|
|
m_progressLabel->setVisible(false);
|
|
return;
|
|
}
|
|
|
|
// Start indeterminate; the first real percentage (onCoreActionProgress)
|
|
// switches the bar to a determinate fill.
|
|
m_progressValue = 0;
|
|
m_installProgressBar->setRange(0, 0);
|
|
m_installProgressBar->setValue(0);
|
|
m_installProgressBar->setVisible(true);
|
|
m_progressLabel->setVisible(false);
|
|
}
|
|
|
|
void MainWindow::onCoreStatusMessage(const QString& message) {
|
|
statusBar()->showMessage(message);
|
|
noteOperationOutput(message);
|
|
}
|
|
|
|
void MainWindow::noteOperationOutput(const QString& step) {
|
|
if (!step.isEmpty()) m_operationStep = step;
|
|
if (m_operationClock.isValid()) m_lastOutputAtMs = m_operationClock.elapsed();
|
|
}
|
|
|
|
// A long operation is not always a talkative one: flatpak prints nothing while
|
|
// a 1 Go runtime downloads, which left the window repeating the same sentence
|
|
// over a frozen bar. After a few seconds of silence the elapsed time joins the
|
|
// status bar, and every half-minute of waiting the journal says so too — the
|
|
// Logs screen then shows the operation is alive instead of stopped.
|
|
void MainWindow::onActivityTick() {
|
|
if (!m_operationClock.isValid()) return;
|
|
|
|
// Five seconds of silence is a download; anything shorter is just a tool
|
|
// thinking, and rewriting the message then would only make it flicker.
|
|
constexpr qint64 kSilenceBeforeNotice = 5000;
|
|
constexpr qint64 kWaitNoteInterval = 30000;
|
|
|
|
const qint64 elapsed = m_operationClock.elapsed();
|
|
if (elapsed - m_lastOutputAtMs < kSilenceBeforeNotice) return;
|
|
|
|
const QString elapsedText = formatElapsed(elapsed);
|
|
const QString step = m_operationStep.isEmpty() ? tr("en cours") : m_operationStep;
|
|
statusBar()->showMessage(QStringLiteral("%1 — %2").arg(step, elapsedText));
|
|
|
|
if (elapsed - m_lastWaitNoteMs < kWaitNoteInterval) return;
|
|
m_lastWaitNoteMs = elapsed;
|
|
LogManager::instance().logEvent(
|
|
QStringLiteral("opération"),
|
|
tr("toujours en cours après %1 — %2").arg(elapsedText, step));
|
|
}
|
|
|
|
void MainWindow::onCoreHistoryChanged() {
|
|
// The dashboard and history screens refresh themselves through the same
|
|
// signal; only the frame's summary line is updated here.
|
|
updateStatusBar();
|
|
}
|
|
|
|
void MainWindow::onCheckForUpdates() {
|
|
LogManager::instance().logEvent(QStringLiteral("ui"),
|
|
tr("clic vérifier les mises à jour"));
|
|
m_core->checkForAppUpdate();
|
|
}
|
|
|
|
// Handles the result of a release check: offers to self-update when a newer
|
|
// version exists, otherwise a status bar confirmation. Errors are reported
|
|
// silently in the status bar so a network failure never blocks the app.
|
|
void MainWindow::onCoreUpdateCheckFinished(bool hasUpdate, const QString& latestVersion,
|
|
const QString& errorMessage) {
|
|
if (!errorMessage.isEmpty()) {
|
|
statusBar()->showMessage(errorMessage);
|
|
return;
|
|
}
|
|
|
|
if (!hasUpdate) {
|
|
statusBar()->showMessage(
|
|
QString(tr("PacManager est à jour (v%1)")).arg(UpdateManager::currentVersion()));
|
|
return;
|
|
}
|
|
|
|
// Ask the user whether to update now or skip. The update runs in the
|
|
// background (git pull from a checkout, clone + rebuild, prebuilt unpack,
|
|
// or tarball rebuild); the running binary stays untouched and the app
|
|
// hands over to the new build once the update succeeds.
|
|
const UpdateManager::UpdateMethod method = m_core->updateMethod();
|
|
const QString targetDir = m_core->binDir();
|
|
|
|
QMessageBox box(this);
|
|
box.setWindowTitle(tr("Mise à jour disponible"));
|
|
box.setIcon(QMessageBox::Information);
|
|
box.setTextFormat(Qt::RichText);
|
|
box.setText(QString(tr("<h3>PacManager v%1 est disponible</h3>"
|
|
"<p>Vous utilisez actuellement la version %2.</p>"))
|
|
.arg(latestVersion, UpdateManager::currentVersion()));
|
|
|
|
QPushButton* updateBtn = box.addButton(tr("Mettre à jour"), QMessageBox::AcceptRole);
|
|
box.addButton(tr("Plus tard"), QMessageBox::RejectRole);
|
|
if (method == UpdateManager::UpdateMethod::None) {
|
|
// No local way to update: offer the releases page instead of a button
|
|
// that would immediately fail.
|
|
updateBtn->setText(tr("Ouvrir la page des releases"));
|
|
}
|
|
box.setInformativeText(UpdateManager::methodDescription(method, targetDir));
|
|
box.exec();
|
|
|
|
if (box.clickedButton() != updateBtn) {
|
|
// "Plus tard" (or closing the dialog) simply skips the update.
|
|
return;
|
|
}
|
|
|
|
if (method == UpdateManager::UpdateMethod::None) {
|
|
QDesktopServices::openUrl(QUrl(m_core->releasePageUrl()));
|
|
return;
|
|
}
|
|
|
|
// Prompt for the sudo password when the update needs privileges: either the
|
|
// final install writes into a root-owned directory (e.g. /usr/bin), or the
|
|
// build dependencies (qt6-base, cmake, gcc/base-devel, git) are missing and
|
|
// the update script must install them first — on a minimal Arch system both
|
|
// are why the update cannot run unprivileged. The password is consumed by
|
|
// `sudo -S` inside the update script itself (install of the dependencies,
|
|
// then the final copy).
|
|
QString sudoPassword;
|
|
const bool needsDeps = !UpdateManager::missingBuildDependencies().isEmpty();
|
|
if (!m_core->binDirWritable() || needsDeps) {
|
|
QString reason;
|
|
if (needsDeps) {
|
|
reason = tr("Des dépendances de compilation manquent (%1).\n")
|
|
.arg(UpdateManager::missingBuildDependencies().join(", "));
|
|
} else {
|
|
reason = tr("L'installation doit écrire dans %1.\n").arg(targetDir);
|
|
}
|
|
bool ok = false;
|
|
sudoPassword = QInputDialog::getText(
|
|
this, tr("Mise à jour"),
|
|
QString(tr("%1Mot de passe sudo pour mettre à jour PacManager :\n"))
|
|
.arg(reason),
|
|
QLineEdit::Password, QString(), &ok);
|
|
if (!ok) {
|
|
statusBar()->showMessage(tr("Mise à jour annulée."));
|
|
return;
|
|
}
|
|
if (!sudoPassword.isEmpty()) {
|
|
// The update pipeline also serves the other privileged flows, and
|
|
// it drops the password after each use: priming it here avoids a
|
|
// second prompt when the update itself was started from one.
|
|
m_core->setSudoPassword(sudoPassword);
|
|
}
|
|
}
|
|
|
|
qCInfo(pacmgrUpdate) << "applying update, method" << static_cast<int>(method)
|
|
<< "target" << targetDir;
|
|
statusBar()->showMessage(tr("Mise à jour en cours en arrière-plan..."));
|
|
|
|
QString error;
|
|
if (!m_core->applySelfUpdate(sudoPassword, &error)) {
|
|
QMessageBox::warning(this, tr("Mise à jour"), error);
|
|
return;
|
|
}
|
|
// onCoreSelfUpdateFinished reports the outcome once the build is done.
|
|
}
|
|
|
|
// Called when the background git pull + build finishes. A success hands over to
|
|
// the freshly installed binary right away; a failure is reported in a dialog and
|
|
// kept whole in the journal.
|
|
void MainWindow::onCoreSelfUpdateFinished(bool success, const QString& message) {
|
|
if (!success) {
|
|
// A failing build prints far more than a dialog can hold, and the part
|
|
// that gets cut is precisely the error line. The journal keeps the whole
|
|
// output as a command block, so the Logs screen shows it and the file can
|
|
// be sent as it is — without it, a failed update leaves no trace at all
|
|
// (the outcome is not a provider command, so nothing else records it).
|
|
LogManager& journal = LogManager::instance();
|
|
journal.beginCommand(QStringLiteral("maj-app"),
|
|
QStringLiteral("mise à jour de l'application"));
|
|
journal.endCommand(false, message);
|
|
qCWarning(pacmgrUpdate) << "self-update failed, output in" << journal.filePath();
|
|
|
|
QMessageBox::warning(this, tr("Échec de la mise à jour"),
|
|
QString(tr("<p>La mise à jour a échoué :</p><pre>%1</pre>"
|
|
"<p>Le journal complet est dans <code>%2</code>.</p>"))
|
|
.arg(message.toHtmlEscaped(), journal.filePath().toHtmlEscaped()));
|
|
return;
|
|
}
|
|
|
|
// The build log is no longer shown to the user, so keep it in the app log
|
|
// for troubleshooting.
|
|
qCInfo(pacmgrUpdate) << "self-update output:" << message;
|
|
|
|
// Restarting is the only way to run the new build: this process still maps
|
|
// the inode that was replaced on disk. Ask for a manual restart only when
|
|
// no runnable binary is there to hand over to.
|
|
const QString program = UpdateManager::restartProgram(m_core->binDir());
|
|
if (!program.isEmpty()
|
|
&& QProcess::startDetached(program, QCoreApplication::arguments().mid(1))) {
|
|
qCInfo(pacmgrUpdate) << "update installed, relaunching" << program;
|
|
statusBar()->showMessage(tr("Mise à jour terminée, redémarrage de PacManager..."));
|
|
// Quit on the next event-loop pass so the message paints first. The new
|
|
// process is detached and outlives this one.
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
return;
|
|
}
|
|
|
|
qCWarning(pacmgrUpdate) << "could not relaunch" << program;
|
|
QMessageBox::information(this, tr("Mise à jour terminée"),
|
|
QString(tr("<h3>PacManager a été mis à jour</h3>"
|
|
"<p>La nouvelle version sera active au prochain démarrage.</p>"
|
|
"<pre>%1</pre>"))
|
|
.arg(message.toHtmlEscaped()));
|
|
}
|