File indexing completed on 2024-11-17 04:55:39

0001 /*
0002  *   SPDX-FileCopyrightText: 2017 Jan Grulich <jgrulich@redhat.com>
0003  *   SPDX-FileCopyrightText: 2023 Harald Sitter <sitter@kde.org>
0004  *
0005  *   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006  */
0007 
0008 #pragma once
0009 
0010 #include "flatpak-helper.h"
0011 #include <gio/gio.h>
0012 #include <glib.h>
0013 
0014 #include <QMap>
0015 #include <QRunnable>
0016 #include <QStringList>
0017 #include <QThread>
0018 #include <Transaction/Transaction.h>
0019 
0020 class FlatpakResource;
0021 class FlatpakTransactionThread : public QObject, public QRunnable
0022 {
0023     Q_OBJECT
0024 public:
0025     FlatpakTransactionThread(FlatpakResource *app, Transaction::Role role);
0026     ~FlatpakTransactionThread() override;
0027 
0028     void cancel();
0029     void run() override;
0030 
0031     int progress() const
0032     {
0033         return m_progress;
0034     }
0035     void setProgress(int progress);
0036     void setSpeed(quint64 speed);
0037 
0038     QString errorMessage() const;
0039     bool result() const;
0040     bool cancelled() const;
0041 
0042     void addErrorMessage(const QString &error);
0043     QMap<QString, QStringList> addedRepositories() const
0044     {
0045         return m_addedRepositories;
0046     }
0047 
0048 Q_SIGNALS:
0049     void progressChanged(int progress);
0050     void speedChanged(quint64 speed);
0051     void passiveMessage(const QString &msg);
0052     void webflowStarted(const QUrl &url, int id);
0053     void webflowDone(int id);
0054     void finished();
0055 
0056 private:
0057     static gboolean
0058     add_new_remote_cb(FlatpakTransaction * /*object*/, gint /*reason*/, gchar *from_id, gchar *suggested_remote_name, gchar *url, gpointer user_data);
0059     static void progress_changed_cb(FlatpakTransactionProgress *progress, gpointer user_data);
0060     static void
0061     new_operation_cb(FlatpakTransaction * /*object*/, FlatpakTransactionOperation *operation, FlatpakTransactionProgress *progress, gpointer user_data);
0062 
0063     static gboolean webflowStart(FlatpakTransaction *transaction, const char *remote, const char *url, GVariant *options, guint id, gpointer user_data);
0064     static void webflowDoneCallback(FlatpakTransaction *transaction, GVariant *options, guint id, gpointer user_data);
0065 
0066     FlatpakTransaction *m_transaction;
0067     bool m_result = false;
0068     int m_progress = 0;
0069     quint64 m_speed = 0;
0070     QString m_errorMessage;
0071     GCancellable *m_cancellable;
0072     FlatpakResource *const m_app;
0073     const Transaction::Role m_role;
0074     QMap<QString, QStringList> m_addedRepositories;
0075 
0076     QVector<int> m_webflows;
0077 };