public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
From: Jan Grulich <jgrulich@redhat.com>
To: git-commits@fedoraproject.org
Subject: [rpms/mediawriter] epel10: Use portal file dialog when possible
Date: Tue, 29 Sep 2026 15:27:49 GMT	[thread overview]
Message-ID: <179069566961.1.863137451809500445.rpms-mediawriter-879587dc9716@fedoraproject.org> (raw)

A new commit has been pushed.

Repo   : rpms/mediawriter
Branch : epel10
Commit : 879587dc97167f99ee42afdf13df0285b144c70f
Author : Jan Grulich <jgrulich@redhat.com>
Date   : 2021-07-14T09:41:17+02:00
Stats  : +365/-1 in 2 file(s)
URL    : https://src.fedoraproject.org/rpms/mediawriter/c/879587dc97167f99ee42afdf13df0285b144c70f?branch=epel10

Log:
Use portal file dialog when possible

---
diff --git a/mediawriter-use-filechooser-portal.patch b/mediawriter-use-filechooser-portal.patch
new file mode 100644
index 0000000..3a67964
--- /dev/null
+++ b/mediawriter-use-filechooser-portal.patch
@@ -0,0 +1,359 @@
+diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt
+index 764767d..16a3461 100644
+--- a/app/CMakeLists.txt
++++ b/app/CMakeLists.txt
+@@ -12,6 +12,7 @@ set(MEDIAWRITER_SRCS
+     fakedrivemanager.cpp
+     main.cpp
+     notifications.cpp
++    portalfiledialog.cpp
+     releasemanager.cpp
+     units.cpp
+     utilities.cpp
+diff --git a/app/main.cpp b/app/main.cpp
+index 5a3c08f..e37f371 100644
+--- a/app/main.cpp
++++ b/app/main.cpp
+@@ -32,6 +32,7 @@
+ #include "crashhandler.h"
+ #include "drivemanager.h"
+ #include "icon.h"
++#include "portalfiledialog.h"
+ #include "releasemanager.h"
+ #include "units.h"
+ #include "versionchecker.h"
+@@ -51,8 +52,6 @@ Q_IMPORT_PLUGIN(QmlFolderListModelPlugin);
+ Q_IMPORT_PLUGIN(QmlSettingsPlugin);
+ #endif
+ 
+-#include <QDebug>
+-
+ int main(int argc, char **argv)
+ {
+     MessageHandler::install();
+@@ -96,8 +95,10 @@ int main(int argc, char **argv)
+ 
+     mDebug() << "Injecting QML context properties";
+     QQmlApplicationEngine engine;
++
+     engine.rootContext()->setContextProperty("downloadManager", DownloadManager::instance());
+     engine.rootContext()->setContextProperty("drives", DriveManager::instance());
++    engine.rootContext()->setContextProperty("portalFileDialog", new PortalFileDialog(&app));
+     engine.rootContext()->setContextProperty("mediawriterVersion", MEDIAWRITER_VERSION);
+     engine.rootContext()->setContextProperty("releases", new ReleaseManager());
+     engine.rootContext()->setContextProperty("units", Units::instance());
+diff --git a/app/portalfiledialog.cpp b/app/portalfiledialog.cpp
+new file mode 100644
+index 0000000..a368abb
+--- /dev/null
++++ b/app/portalfiledialog.cpp
+@@ -0,0 +1,195 @@
++/*
++ * Fedora Media Writer
++ * Copyright (C) 2021 Jan Grulich <jgrulich@redhat.com>
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License
++ * as published by the Free Software Foundation; either version 2
++ * of the License, or (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
++ */
++
++#include "portalfiledialog.h"
++#include "utilities.h"
++
++#include <QGuiApplication>
++#include <QRandomGenerator>
++#include <QFileDialog>
++#include <QStandardPaths>
++
++#ifdef __linux
++#include <QtDBus/QtDBus>
++#include <QDBusConnection>
++#include <QDBusConnectionInterface>
++#include <QDBusMessage>
++#include <QDBusPendingCall>
++#include <QDBusPendingCallWatcher>
++#include <QDBusPendingReply>
++
++// Copied from PortalFileDialog
++QDBusArgument &operator <<(QDBusArgument &arg, const PortalFileDialog::FilterCondition &filterCondition)
++{
++    arg.beginStructure();
++    arg << filterCondition.type << filterCondition.pattern;
++    arg.endStructure();
++    return arg;
++}
++const QDBusArgument &operator >>(const QDBusArgument &arg, PortalFileDialog::FilterCondition &filterCondition)
++{
++    uint type;
++    QString filterPattern;
++    arg.beginStructure();
++    arg >> type >> filterPattern;
++    filterCondition.type = (PortalFileDialog::ConditionType)type;
++    filterCondition.pattern = filterPattern;
++    arg.endStructure();
++    return arg;
++}
++QDBusArgument &operator <<(QDBusArgument &arg, const PortalFileDialog::Filter filter)
++{
++    arg.beginStructure();
++    arg << filter.name << filter.filterConditions;
++    arg.endStructure();
++    return arg;
++}
++const QDBusArgument &operator >>(const QDBusArgument &arg, PortalFileDialog::Filter &filter)
++{
++    QString name;
++    PortalFileDialog::FilterConditionList filterConditions;
++    arg.beginStructure();
++    arg >> name >> filterConditions;
++    filter.name = name;
++    filter.filterConditions = filterConditions;
++    arg.endStructure();
++    return arg;
++}
++#endif
++
++static inline bool checkSandboxEnvironment()
++{
++    return !QStandardPaths::locate(QStandardPaths::RuntimeLocation, QStringLiteral("flatpak-info")).isEmpty() || qEnvironmentVariableIsSet("SNAP");
++}
++
++PortalFileDialog::PortalFileDialog(QObject *parent, WId winId)
++    : QObject(parent)
++    , m_winId(winId)
++{
++#ifdef __linux
++    QDBusConnectionInterface *interface = QDBusConnection::sessionBus().interface();
++    m_available = interface->isServiceRegistered(QStringLiteral("org.freedesktop.portal.Desktop"));
++
++    // In case we are in sandbox we can use native dialog which will already use portals
++    if (m_available) {
++        m_available = !checkSandboxEnvironment();
++    }
++#endif
++}
++
++PortalFileDialog::~PortalFileDialog()
++{
++}
++
++bool PortalFileDialog::isAvailable() const
++{
++#ifdef __linux
++    return m_available;
++#else
++    return false;
++#endif
++}
++
++void PortalFileDialog::open()
++{
++    if (!m_available) {
++        return;
++    }
++
++#ifdef __linux
++    QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.portal.Desktop"),
++                                                          QStringLiteral("/org/freedesktop/portal/desktop"),
++                                                          QStringLiteral("org.freedesktop.portal.FileChooser"),
++                                                          QStringLiteral("OpenFile"));
++    QVariantMap options;
++    options.insert(QStringLiteral("modal"), true);
++    options.insert(QStringLiteral("handle_token"), QStringLiteral("qt%1").arg(QRandomGenerator::global()->generate()));
++    options.insert(QStringLiteral("multiple"), false);
++
++    qDBusRegisterMetaType<FilterCondition>();
++    qDBusRegisterMetaType<FilterConditionList>();
++    qDBusRegisterMetaType<Filter>();
++    qDBusRegisterMetaType<FilterList>();
++
++    FilterList filterList;
++
++    FilterConditionList filterConditions1;
++    FilterCondition filterCondition1;
++    filterCondition1.type = GlobalPattern;
++    filterCondition1.pattern = QStringLiteral("*.iso");
++    FilterCondition filterCondition2;
++    filterCondition2.type = GlobalPattern;
++    filterCondition2.pattern = QStringLiteral("*.raw");
++    FilterCondition filterCondition3;
++    filterCondition3.type = GlobalPattern;
++    filterCondition3.pattern = QStringLiteral("*.xz");
++    filterConditions1 << filterCondition1 << filterCondition2 << filterCondition3;
++
++    Filter filter1;
++    filter1.name = tr("Image files");
++    filter1.filterConditions = filterConditions1;
++
++    FilterConditionList filterConditions2;
++    FilterCondition filterCondition4;
++    filterCondition4.type = GlobalPattern;
++    filterCondition4.pattern = QStringLiteral("*");
++    filterConditions2 << filterCondition4;
++
++    Filter filter2;
++    filter2.name = tr("All files");
++    filter2.filterConditions = filterConditions2;
++
++    filterList << filter1 << filter2;
++
++    options.insert(QLatin1String("filters"), QVariant::fromValue(filterList));
++
++    const QString parentWindow = QGuiApplication::platformName() == QStringLiteral("xcb") ? QStringLiteral("x11:%1").arg(QString::number(m_winId)) :
++                                                                                            QStringLiteral("wayland:%1").arg(QString::number(m_winId));
++
++    message << parentWindow << tr("Open File") << options;
++
++    QDBusPendingCall pendingCall = QDBusConnection::sessionBus().asyncCall(message);
++    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingCall);
++    connect(watcher, &QDBusPendingCallWatcher::finished, this, [this] (QDBusPendingCallWatcher *watcher) {
++        QDBusPendingReply<QDBusObjectPath> reply = *watcher;
++        if (!reply.isError()) {
++            QDBusConnection::sessionBus().connect(nullptr,
++                                                  reply.value().path(),
++                                                  QStringLiteral("org.freedesktop.portal.Request"),
++                                                  QStringLiteral("Response"),
++                                                  this,
++                                                  SLOT(gotResponse(uint,QVariantMap)));
++        } else {
++            mWarning() << "Failed to open portal file dialog: " << reply.error().message();
++        }
++    });
++#endif
++}
++
++void PortalFileDialog::gotResponse(uint response, const QVariantMap &results)
++{
++    if (!response) {
++        if (results.contains(QLatin1String("uris"))) {
++            const QStringList selectedFiles = results.value(QLatin1String("uris")).toStringList();
++            Q_EMIT fileSelected(selectedFiles.first());
++        }
++    } else {
++        mWarning() << "Portal file dialog cancelled or failed to open";
++    }
++}
+diff --git a/app/portalfiledialog.h b/app/portalfiledialog.h
+new file mode 100644
+index 0000000..a7358f0
+--- /dev/null
++++ b/app/portalfiledialog.h
+@@ -0,0 +1,73 @@
++/*
++ * Fedora Media Writer
++ * Copyright (C) 2021 Jan Grulich <jgrulich@redhat.com>
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License
++ * as published by the Free Software Foundation; either version 2
++ * of the License, or (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
++ */
++
++#ifndef PORTALPortalFileDialog_H
++#define PORTALPortalFileDialog_H
++
++#include <QObject>
++#include <QWindow>
++
++class PortalFileDialog : public QObject
++{
++    Q_OBJECT
++    Q_PROPERTY(bool isAvailable READ isAvailable)
++public:
++    // Copied from QXdgDesktopPortalFileDialog
++    enum ConditionType : uint {
++        GlobalPattern = 0,
++        MimeType = 1
++    };
++    // Filters a(sa(us))
++    // Example: [('Images', [(0, '*.ico'), (1, 'image/png')]), ('Text', [(0, '*.txt')])]
++    struct FilterCondition {
++        ConditionType type;
++        QString pattern; // E.g. '*ico' or 'image/png'
++    };
++    typedef QVector<FilterCondition> FilterConditionList;
++    struct Filter {
++        QString name; // E.g. 'Images' or 'Text
++        FilterConditionList filterConditions;; // E.g. [(0, '*.ico'), (1, 'image/png')] or [(0, '*.txt')]
++    };
++    typedef QVector<Filter> FilterList;
++
++    PortalFileDialog(QObject *parent = nullptr, WId winId = 0);
++    virtual ~PortalFileDialog() override;
++
++    bool isAvailable() const;
++
++public Q_SLOTS:
++    void open();
++
++private Q_SLOTS:
++    void gotResponse(uint response, const QVariantMap &results);
++
++Q_SIGNALS:
++    void fileSelected(const QUrl &fileName);
++
++private:
++    bool m_available;
++    WId m_winId;
++};
++
++Q_DECLARE_METATYPE(PortalFileDialog::FilterCondition);
++Q_DECLARE_METATYPE(PortalFileDialog::FilterConditionList);
++Q_DECLARE_METATYPE(PortalFileDialog::Filter);
++Q_DECLARE_METATYPE(PortalFileDialog::FilterList);
++
++#endif // PORTALPortalFileDialog_H
+diff --git a/app/qml/DelegateImage.qml b/app/qml/DelegateImage.qml
+index de32e55..214924c 100644
+--- a/app/qml/DelegateImage.qml
++++ b/app/qml/DelegateImage.qml
+@@ -175,7 +175,10 @@ Item {
+         function action() {
+             if (release.isLocal) {
+                 releases.selectedIndex = index
+-                fileDialog.visible = true
++                if (portalFileDialog.isAvailable)
++                    portalFileDialog.open()
++                else
++                    fileDialog.open()
+             }
+             else {
+                 imageList.currentIndex = index
+diff --git a/app/qml/main.qml b/app/qml/main.qml
+index efc803e..e7a714d 100644
+--- a/app/qml/main.qml
++++ b/app/qml/main.qml
+@@ -162,6 +162,14 @@ ApplicationWindow {
+         }
+     }
+ 
++    Connections {
++        target: portalFileDialog
++        function onFileSelected(fileName) {
++            releases.setLocalFile(fileName)
++            dlDialog.visible = true
++        }
++    }
++
+     FullscreenViewer {
+         id: fullscreenViewer
+     }

diff --git a/mediawriter.spec b/mediawriter.spec
index f86fd93..0a0d01f 100644
--- a/mediawriter.spec
+++ b/mediawriter.spec
@@ -1,12 +1,14 @@
 Name:           mediawriter
 Version:        4.2.2
-Release:        1%{?dist}
+Release:        2%{?dist}
 Summary:        Fedora Media Writer
 
 License:        GPLv2+
 URL:            https://github.com/FedoraQt/MediaWriter
 Source0:        https://github.com/FedoraQt/MediaWriter/archive/MediaWriter-%{version}.tar.gz
 
+Patch0:         mediawriter-use-filechooser-portal.patch
+
 Provides:       liveusb-creator = %{version}-%{release}
 Obsoletes:      liveusb-creator <= 3.95.4-2
 
@@ -82,6 +84,9 @@ appstream-util validate-relax --nonet %{buildroot}/%{_datadir}/metainfo/org.fedo
 
 
 %changelog
+* Tue Jul 13 2021 Jan Grulich <jgrulich@redhat.com> - 4.2.2-2
+- Use portal file dialog when possible
+
 * Fri May 14 2021 Jan Grulich <jgrulich@redhat.com> - 4.2.2-1
 - 4.2.2
 

                 reply	other threads:[~2026-09-29 15:27 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179069566961.1.863137451809500445.rpms-mediawriter-879587dc9716@fedoraproject.org \
    --to=jgrulich@redhat.com \
    --cc=git-commits@fedoraproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox