feat(ui): install the Flatpak files dropped or opened with PacManager
The window accepts a drop and the desktop entry's %U hands over the file the user picked, so both gestures end up as the same request. The frame asks the core which files it can install and never names a format itself; dropped files queue up because the core runs one operation at a time, and the search and log fields stop swallowing drops so a file dropped on them reaches the window. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
5 files changed
+187
No files matched your search
@@ -3,6 +3,7 @@
|
||||
#include <QHash>
|
||||
#include <QMainWindow>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
#include <vector>
|
||||
@@ -12,8 +13,12 @@
|
||||
|
||||
class QAction;
|
||||
class QButtonGroup;
|
||||
class QDragEnterEvent;
|
||||
class QDragMoveEvent;
|
||||
class QDropEvent;
|
||||
class QFrame;
|
||||
class QLabel;
|
||||
class QMimeData;
|
||||
class QProgressBar;
|
||||
class QPushButton;
|
||||
class QStackedWidget;
|
||||
@@ -43,6 +48,19 @@ public:
|
||||
explicit MainWindow(QWidget* parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
// Installs the Flatpak files handed over by the desktop: dropped on the
|
||||
// window, or opened from the file manager ("Ouvrir avec PacManager", which
|
||||
// passes them on the command line). One install runs at a time; the rest
|
||||
// wait in line. Paths the core does not recognise are reported and skipped.
|
||||
void installLocalFiles(const QStringList& paths);
|
||||
|
||||
protected:
|
||||
// Dragging a .flatpakref / .flatpakrepo / .flatpak onto the window is the
|
||||
// same request as opening it from the file manager.
|
||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||
void dragMoveEvent(QDragMoveEvent* event) override;
|
||||
void dropEvent(QDropEvent* event) override;
|
||||
|
||||
private slots:
|
||||
void onNavChanged(int id);
|
||||
void onRefresh();
|
||||
@@ -117,6 +135,13 @@ private:
|
||||
void showActionError(const QString& title, const QString& error, bool locked);
|
||||
void applyCredentialMode(AppCore::CredentialMode mode);
|
||||
|
||||
// The files a drag carries that the core can install; empty when the drop is
|
||||
// nothing the app handles (which is also how dragEnterEvent refuses it).
|
||||
QStringList installableDroppedFiles(const QMimeData* mimeData) const;
|
||||
// Takes the next queued file and asks the core to install it. A core busy
|
||||
// with another operation leaves it queued: onCoreActionFinished calls back.
|
||||
void startNextFileInstall();
|
||||
|
||||
// Logic layer: it owns the providers, the workers, the history, the
|
||||
// credentials and the self-updater. The frame never talks to them directly.
|
||||
AppCore* m_core = nullptr;
|
||||
@@ -155,6 +180,11 @@ private:
|
||||
int m_progressValue = 0;
|
||||
int m_progressGeneration = 0;
|
||||
|
||||
// Files waiting to be installed (dropped or opened), and whether one is
|
||||
// being installed right now.
|
||||
QStringList m_pendingFileInstalls;
|
||||
bool m_fileInstallRunning = false;
|
||||
|
||||
// Tray (optional: hidden when the desktop has no system tray)
|
||||
QSystemTrayIcon* m_tray = nullptr;
|
||||
// Last update count already announced in a tray notification, so repeated
|
||||
|
||||
@@ -32,6 +32,9 @@ BrowsePage::BrowsePage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
||||
searchRow->setSpacing(10);
|
||||
|
||||
m_searchBar = new QLineEdit();
|
||||
// Drops belong to the window: a .flatpakref let go over the search field
|
||||
// must install, not paste its path (see MainWindow::dragEnterEvent).
|
||||
m_searchBar->setAcceptDrops(false);
|
||||
m_searchBar->setPlaceholderText("Rechercher un paquet (ex : firefox)...");
|
||||
m_searchBar->setMinimumHeight(40);
|
||||
m_searchBar->addAction(ui::icon("search"), QLineEdit::LeadingPosition);
|
||||
@@ -54,6 +57,7 @@ BrowsePage::BrowsePage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
||||
filterRow->setSpacing(10);
|
||||
|
||||
m_filterBar = new QLineEdit();
|
||||
m_filterBar->setAcceptDrops(false); // drops go to the window (see above)
|
||||
m_filterBar->setPlaceholderText("Filtrer par nom...");
|
||||
m_filterBar->setMinimumHeight(36);
|
||||
m_filterBar->addAction(ui::icon("filter"), QLineEdit::LeadingPosition);
|
||||
|
||||
@@ -28,6 +28,9 @@ LogsPage::LogsPage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
||||
filterRow->addWidget(m_source);
|
||||
|
||||
m_filter = new QLineEdit();
|
||||
// Drops go to the window, which installs Flatpak files (see
|
||||
// MainWindow::dragEnterEvent) rather than pasting a path here.
|
||||
m_filter->setAcceptDrops(false);
|
||||
m_filter->setPlaceholderText("Filtrer les logs (paquet, action, date)...");
|
||||
m_filter->setMinimumHeight(36);
|
||||
m_filter->setClearButtonEnabled(true);
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
#include <QButtonGroup>
|
||||
#include <QCoreApplication>
|
||||
#include <QDesktopServices>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QDropEvent>
|
||||
#include <QFileInfo>
|
||||
#include <QFrame>
|
||||
#include <QMimeData>
|
||||
#include <QHBoxLayout>
|
||||
#include <QIcon>
|
||||
#include <QInputDialog>
|
||||
@@ -52,6 +56,9 @@ static QPixmap iconPixmap(const QString& name, int size) {
|
||||
// core reports which action failed, not how to phrase it).
|
||||
static QString actionErrorTitle(const QString& action) {
|
||||
if (action == QLatin1String("install")) return QStringLiteral("Échec de l'installation");
|
||||
if (action == QLatin1String("install-file")) {
|
||||
return QStringLiteral("Échec de l'installation du fichier");
|
||||
}
|
||||
if (action == QLatin1String("remove")) return QStringLiteral("Échec de la suppression");
|
||||
if (action == QLatin1String("update")) return QStringLiteral("Échec de la mise à jour");
|
||||
if (action == QLatin1String("update-all")) {
|
||||
@@ -413,6 +420,9 @@ void MainWindow::setupUI() {
|
||||
|
||||
statusBar()->showMessage("Prêt");
|
||||
|
||||
// Flatpak files can be dropped anywhere on the window (see dragEnterEvent).
|
||||
setAcceptDrops(true);
|
||||
|
||||
// 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
|
||||
@@ -870,6 +880,126 @@ 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 (!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)) 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"),
|
||||
QStringLiteral("%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) {
|
||||
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(
|
||||
QStringLiteral("%1 : format non reconnu (PacManager installe les fichiers "
|
||||
".flatpakref, .flatpakrepo et .flatpak).")
|
||||
.arg(QFileInfo(rejected.first()).fileName()));
|
||||
}
|
||||
|
||||
if (files.isEmpty()) return;
|
||||
|
||||
LogManager::instance().logEvent(
|
||||
QStringLiteral("fichier"),
|
||||
QStringLiteral("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, QStringLiteral("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(QStringLiteral("Installation de %1...")
|
||||
.arg(QFileInfo(path).fileName()));
|
||||
}
|
||||
|
||||
void MainWindow::onStartRequested(const AppCore::StartResult& result, const QString& title) {
|
||||
handleStartResult(result, title);
|
||||
}
|
||||
@@ -1099,10 +1229,18 @@ void MainWindow::onCoreActionFinished(const QString& action, const QString& name
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include <QApplication>
|
||||
#include <QLoggingCategory>
|
||||
#include <QStringList>
|
||||
#include <QTimer>
|
||||
|
||||
#include "log-manager.h"
|
||||
#include "main-window.h"
|
||||
@@ -26,6 +28,16 @@ int main(int argc, char* argv[]) {
|
||||
window.setMinimumSize(960, 600);
|
||||
window.show();
|
||||
|
||||
// Files the desktop handed over ("Ouvrir avec PacManager", the desktop
|
||||
// entry declares %U): installed once the event loop runs, so the window is
|
||||
// visible and any dialog has a parent.
|
||||
const QStringList fileArgs = app.arguments().mid(1);
|
||||
if (!fileArgs.isEmpty()) {
|
||||
QTimer::singleShot(0, &window, [&window, fileArgs] {
|
||||
window.installLocalFiles(fileArgs);
|
||||
});
|
||||
}
|
||||
|
||||
const int code = app.exec();
|
||||
|
||||
LogManager::instance().logEvent(QStringLiteral("app"),
|
||||
|
||||
Reference in new issue
Block a user