Commit d414f0a3 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

flatpak: First approach to supporting webflow

Will show it on the web browser for now, it could make sense to embed it
into Discover's window, depends on what kind of interaction we end up
getting there, which I am not sure.

~~Draft because it's untested.~~ It's as tested as possible for me.
parent 60f9e919
Pipeline #227616 passed with stage
in 1 minute and 52 seconds
......@@ -4,5 +4,7 @@
include:
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/linux.yml
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/freebsd.yml
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/linux-qt6.yml
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/freebsd-qt6.yml
# Commented out Qt 6 CI since Qt Web View is still not available there
# - https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/linux-qt6.yml
# - https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/freebsd-qt6.yml
......@@ -22,7 +22,7 @@ include(GenerateExportHeader)
include(ECMQtDeclareLoggingCategory)
include(KDEClangFormat)
include(KDEGitCommitHooks)
find_package(Qt${QT_MAJOR_VERSION} ${QT_MIN_VERSION} REQUIRED CONFIG COMPONENTS Widgets Test Network Xml Concurrent DBus Quick)
find_package(Qt${QT_MAJOR_VERSION} ${QT_MIN_VERSION} REQUIRED CONFIG COMPONENTS Widgets Test Network Xml Concurrent DBus Quick WebView)
find_package(PkgConfig REQUIRED)
......
......@@ -48,6 +48,7 @@ target_link_libraries(plasma-discover PUBLIC
KF5::JobWidgets
Qt::Widgets
Qt::Quick
Qt::WebView
Discover::Common
)
......
......@@ -20,6 +20,7 @@
#include <QStandardPaths>
#include <QTextStream>
#include <QWindow>
#include <QtWebView>
#include <QProcessEnvironment>
......@@ -95,6 +96,7 @@ int main(int argc, char **argv)
{
// needs to be set before we create the QGuiApplication
QCoreApplication::setAttribute(Qt::AA_DisableSessionManager, true);
QtWebView::initialize();
QApplication app(argc, argv);
app.setWindowIcon(QIcon::fromTheme(QStringLiteral("plasmadiscover")));
......
......@@ -337,6 +337,15 @@ Kirigami.ApplicationWindow
dialog.open()
app.restore()
}
function onWebflowStarted(url) {
var component = Qt.createComponent("WebflowDialog.qml");
if (component.status == Component.Error) {
console.error("Webflow Error", component.errorString())
} else if (component.status == Component.Ready) {
const sheet = component.createObject(window, {transaction: transaction, url: url });
sheet.open()
}
}
}
}
......
/*
* SPDX-FileCopyrightText: 2022 Aleix Pol Gonzalez <aleixpol@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
import org.kde.kirigami 2.19 as Kirigami
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import QtWebView 1.15
Kirigami.OverlaySheet {
id: sheet
showCloseButton: false
property QtObject transaction
property bool acted: false
property alias url: view.url
readonly property var p0: Connections {
target: transaction
function onWebflowDone() {
acted = true
sheet.close()
}
}
contentItem: WebView {
id: view
Layout.preferredWidth: Math.round(window.width * 0.75)
height: Math.round(window.height * 0.75)
}
footer: RowLayout {
Item { Layout.fillWidth : true }
Button {
Layout.alignment: Qt.AlignRight
text: i18n("Cancel")
icon.name: "dialog-cancel"
onClicked: {
transaction.cancel()
sheet.acted = true
sheet.close()
}
Keys.onEscapePressed: clicked()
}
}
onSheetOpenChanged: if(!sheetOpen) {
sheet.destroy(1000)
if (!sheet.acted)
transaction.cancel()
}
}
......@@ -34,6 +34,7 @@
<file>qml/AboutPage.qml</file>
<file>qml/Feedback.qml</file>
<file>qml/ConvertDiscoverAction.qml</file>
<file>qml/WebflowDialog.qml</file>
<file>qml/navigation.js</file>
</qresource>
......
......@@ -201,6 +201,9 @@ Q_SIGNALS:
void downloadSpeedChanged(quint64 downloadSpeed);
void remainingTimeChanged(uint remainingTime);
void webflowStarted(const QUrl &url, int id);
void webflowDone(int id);
};
#endif // TRANSACTION_H
......@@ -49,6 +49,8 @@ void FlatpakJobTransaction::start()
connect(m_appJob, &FlatpakTransactionThread::progressChanged, this, &FlatpakJobTransaction::setProgress);
connect(m_appJob, &FlatpakTransactionThread::speedChanged, this, &FlatpakJobTransaction::setDownloadSpeed);
connect(m_appJob, &FlatpakTransactionThread::passiveMessage, this, &FlatpakJobTransaction::passiveMessage);
connect(m_appJob, &FlatpakTransactionThread::webflowStarted, this, &FlatpakJobTransaction::webflowStarted);
connect(m_appJob, &FlatpakTransactionThread::webflowDone, this, &FlatpakJobTransaction::webflowDone);
m_appJob->start();
}
......
......@@ -9,6 +9,7 @@
#include <KLocalizedString>
#include <QDebug>
#include <QDesktopServices>
static int FLATPAK_CLI_UPDATE_FREQUENCY = 150;
......@@ -58,6 +59,30 @@ void operation_error_cb(FlatpakTransaction * /*object*/, FlatpakTransactionOpera
obj->addErrorMessage(QString::fromUtf8(error->message));
}
gboolean
FlatpakTransactionThread::webflowStart(FlatpakTransaction *transaction, const char *remote, const char *url, GVariant *options, guint id, gpointer user_data)
{
Q_UNUSED(transaction);
Q_UNUSED(options);
QUrl webflowUrl(QString::fromUtf8(url));
qDebug() << "starting web flow" << webflowUrl << remote << id;
FlatpakTransactionThread *obj = (FlatpakTransactionThread *)user_data;
obj->m_webflows << id;
Q_EMIT obj->webflowStarted(webflowUrl, id);
return true;
}
void FlatpakTransactionThread::webflowDoneCallback(FlatpakTransaction *transaction, GVariant *options, guint id, gpointer user_data)
{
Q_UNUSED(transaction);
Q_UNUSED(options);
FlatpakTransactionThread *obj = (FlatpakTransactionThread *)user_data;
obj->m_webflows << id;
Q_EMIT obj->webflowDone(id);
qDebug() << "webflow done" << id;
}
FlatpakTransactionThread::FlatpakTransactionThread(FlatpakResource *app, Transaction::Role role)
: QThread()
, m_result(false)
......@@ -75,6 +100,11 @@ FlatpakTransactionThread::FlatpakTransactionThread(FlatpakResource *app, Transac
g_signal_connect(m_transaction, "add-new-remote", G_CALLBACK(add_new_remote_cb), this);
g_signal_connect(m_transaction, "new-operation", G_CALLBACK(new_operation_cb), this);
g_signal_connect(m_transaction, "operation-error", G_CALLBACK(operation_error_cb), this);
if (qEnvironmentVariableIntValue("DISCOVER_FLATPAK_WEBFLOW")) {
g_signal_connect(m_transaction, "webflow-start", G_CALLBACK(webflowStart), this);
g_signal_connect(m_transaction, "webflow-done", G_CALLBACK(webflowDoneCallback), this);
}
}
}
......@@ -86,6 +116,8 @@ FlatpakTransactionThread::~FlatpakTransactionThread()
void FlatpakTransactionThread::cancel()
{
for (int id : m_webflows)
flatpak_transaction_abort_webflow(m_transaction, id);
g_cancellable_cancel(m_cancellable);
}
......
......@@ -51,11 +51,16 @@ Q_SIGNALS:
void progressChanged(int progress);
void speedChanged(quint64 speed);
void passiveMessage(const QString &msg);
void webflowStarted(const QUrl &url, int id);
void webflowDone(int id);
private:
static gboolean
add_new_remote_cb(FlatpakTransaction * /*object*/, gint /*reason*/, gchar *from_id, gchar *suggested_remote_name, gchar *url, gpointer user_data);
static gboolean webflowStart(FlatpakTransaction *transaction, const char *remote, const char *url, GVariant *options, guint id, gpointer user_data);
static void webflowDoneCallback(FlatpakTransaction *transaction, GVariant *options, guint id, gpointer user_data);
FlatpakTransaction *m_transaction;
bool m_result = false;
bool m_cancelled = false;
......@@ -66,6 +71,8 @@ private:
FlatpakResource *const m_app;
const Transaction::Role m_role;
QMap<QString, QStringList> m_addedRepositories;
QVector<int> m_webflows;
};
#endif // FLATPAKTRANSACTIONJOB_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment