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
@@ -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