Changeset View
Changeset View
Standalone View
Standalone View
libdiscover/backends/FlatpakBackend/FlatpakTransactionJob.cpp
Show All 27 Lines | 27 | { | |||
---|---|---|---|---|---|
28 | Q_UNUSED(estimating); | 28 | Q_UNUSED(estimating); | ||
29 | Q_UNUSED(stats); | 29 | Q_UNUSED(stats); | ||
30 | 30 | | |||
31 | FlatpakTransactionJob *transactionJob = (FlatpakTransactionJob*)userData; | 31 | FlatpakTransactionJob *transactionJob = (FlatpakTransactionJob*)userData; | ||
32 | if (!transactionJob) { | 32 | if (!transactionJob) { | ||
33 | return; | 33 | return; | ||
34 | } | 34 | } | ||
35 | 35 | | |||
36 | transactionJob->setProgress(progress); | ||||
37 | | ||||
36 | Q_EMIT transactionJob->progressChanged(progress); | 38 | Q_EMIT transactionJob->progressChanged(progress); | ||
37 | } | 39 | } | ||
38 | 40 | | |||
39 | FlatpakTransactionJob::FlatpakTransactionJob(FlatpakInstallation *installation, FlatpakResource *app, Transaction::Role role, QObject *parent) | 41 | FlatpakTransactionJob::FlatpakTransactionJob(FlatpakResource *app, const QPair<QString, uint> &relatedRef, Transaction::Role role, QObject *parent) | ||
40 | : QThread(parent) | 42 | : QThread(parent) | ||
41 | , m_result(false) | 43 | , m_result(false) | ||
44 | , m_progress(0) | ||||
45 | , m_relatedRef(relatedRef.first) | ||||
46 | , m_relatedRefKind(relatedRef.second) | ||||
42 | , m_app(app) | 47 | , m_app(app) | ||
43 | , m_installation(installation) | | |||
44 | , m_role(role) | 48 | , m_role(role) | ||
45 | { | 49 | { | ||
46 | m_cancellable = g_cancellable_new(); | 50 | m_cancellable = g_cancellable_new(); | ||
47 | } | 51 | } | ||
48 | 52 | | |||
49 | FlatpakTransactionJob::~FlatpakTransactionJob() | 53 | FlatpakTransactionJob::~FlatpakTransactionJob() | ||
50 | { | 54 | { | ||
51 | g_object_unref(m_cancellable); | 55 | g_object_unref(m_cancellable); | ||
52 | } | 56 | } | ||
53 | 57 | | |||
54 | void FlatpakTransactionJob::cancel() | 58 | void FlatpakTransactionJob::cancel() | ||
55 | { | 59 | { | ||
56 | g_cancellable_cancel(m_cancellable); | 60 | g_cancellable_cancel(m_cancellable); | ||
57 | } | 61 | } | ||
58 | 62 | | |||
59 | void FlatpakTransactionJob::run() | 63 | void FlatpakTransactionJob::run() | ||
60 | { | 64 | { | ||
61 | g_autoptr(GError) localError = nullptr; | 65 | g_autoptr(GError) localError = nullptr; | ||
62 | g_autoptr(FlatpakInstalledRef) ref = nullptr; | 66 | g_autoptr(FlatpakInstalledRef) ref = nullptr; | ||
63 | 67 | | |||
68 | const QString refName = m_relatedRef.isEmpty() ? m_app->flatpakName() : m_relatedRef; | ||||
69 | const uint kind = m_relatedRef.isEmpty() ? (uint)m_app->type() : m_relatedRefKind; | ||||
70 | | ||||
64 | if (m_role == Transaction::Role::InstallRole) { | 71 | if (m_role == Transaction::Role::InstallRole) { | ||
65 | if (m_app->state() == AbstractResource::Upgradeable) { | 72 | if (m_app->state() == AbstractResource::Upgradeable) { | ||
66 | ref = flatpak_installation_update(m_installation, | 73 | ref = flatpak_installation_update(m_app->installation(), | ||
67 | FLATPAK_UPDATE_FLAGS_NONE, | 74 | FLATPAK_UPDATE_FLAGS_NONE, | ||
68 | m_app->type() == FlatpakResource::DesktopApp ? FLATPAK_REF_KIND_APP : FLATPAK_REF_KIND_RUNTIME, | 75 | kind == FlatpakResource::DesktopApp ? FLATPAK_REF_KIND_APP : FLATPAK_REF_KIND_RUNTIME, | ||
69 | m_app->flatpakName().toUtf8().constData(), | 76 | refName.toUtf8().constData(), | ||
70 | m_app->arch().toUtf8().constData(), | 77 | m_app->arch().toUtf8().constData(), | ||
71 | m_app->branch().toUtf8().constData(), | 78 | m_app->branch().toUtf8().constData(), | ||
72 | flatpakInstallationProgressCallback, | 79 | flatpakInstallationProgressCallback, | ||
73 | this, | 80 | this, | ||
74 | m_cancellable, &localError); | 81 | m_cancellable, &localError); | ||
75 | } else { | 82 | } else { | ||
76 | if (m_app->flatpakFileType() == QStringLiteral("flatpak")) { | 83 | if (m_app->flatpakFileType() == QStringLiteral("flatpak")) { | ||
77 | g_autoptr(GFile) file = g_file_new_for_path(m_app->resourceFile().toLocalFile().toUtf8().constData()); | 84 | g_autoptr(GFile) file = g_file_new_for_path(m_app->resourceFile().toLocalFile().toUtf8().constData()); | ||
78 | if (!file) { | 85 | if (!file) { | ||
79 | qWarning() << "Failed to install bundled application" << m_app->name(); | 86 | qWarning() << "Failed to install bundled application" << refName; | ||
80 | } | 87 | } | ||
81 | ref = flatpak_installation_install_bundle(m_installation, file, flatpakInstallationProgressCallback, this, m_cancellable, &localError); | 88 | ref = flatpak_installation_install_bundle(m_app->installation(), file, flatpakInstallationProgressCallback, this, m_cancellable, &localError); | ||
82 | } else { | 89 | } else { | ||
83 | ref = flatpak_installation_install(m_installation, | 90 | ref = flatpak_installation_install(m_app->installation(), | ||
84 | m_app->origin().toUtf8().constData(), | 91 | m_app->origin().toUtf8().constData(), | ||
85 | m_app->type() == FlatpakResource::DesktopApp ? FLATPAK_REF_KIND_APP : FLATPAK_REF_KIND_RUNTIME, | 92 | kind == FlatpakResource::DesktopApp ? FLATPAK_REF_KIND_APP : FLATPAK_REF_KIND_RUNTIME, | ||
86 | m_app->flatpakName().toUtf8().constData(), | 93 | refName.toUtf8().constData(), | ||
87 | m_app->arch().toUtf8().constData(), | 94 | m_app->arch().toUtf8().constData(), | ||
88 | m_app->branch().toUtf8().constData(), | 95 | m_app->branch().toUtf8().constData(), | ||
89 | flatpakInstallationProgressCallback, | 96 | flatpakInstallationProgressCallback, | ||
90 | this, | 97 | this, | ||
91 | m_cancellable, &localError); | 98 | m_cancellable, &localError); | ||
92 | } | 99 | } | ||
93 | } | 100 | } | ||
94 | 101 | | |||
95 | if (!ref) { | 102 | if (!ref) { | ||
96 | m_result = false; | 103 | m_result = false; | ||
97 | m_errorMessage = QString::fromUtf8(localError->message); | 104 | m_errorMessage = QString::fromUtf8(localError->message); | ||
98 | qWarning() << "Failed to install" << m_app->name() << ':' << m_errorMessage; | 105 | // We are done so we can set the progress to 100 | ||
106 | m_progress = 100; | ||||
107 | qWarning() << "Failed to install" << refName << ':' << m_errorMessage; | ||||
99 | return; | 108 | return; | ||
100 | } | 109 | } | ||
101 | } else if (m_role == Transaction::Role::RemoveRole) { | 110 | } else if (m_role == Transaction::Role::RemoveRole) { | ||
102 | if (!flatpak_installation_uninstall(m_installation, | 111 | if (!flatpak_installation_uninstall(m_app->installation(), | ||
103 | m_app->type() == FlatpakResource::DesktopApp ? FLATPAK_REF_KIND_APP : FLATPAK_REF_KIND_RUNTIME, | 112 | kind == FlatpakResource::DesktopApp ? FLATPAK_REF_KIND_APP : FLATPAK_REF_KIND_RUNTIME, | ||
104 | m_app->flatpakName().toUtf8().constData(), | 113 | refName.toUtf8().constData(), | ||
105 | m_app->arch().toUtf8().constData(), | 114 | m_app->arch().toUtf8().constData(), | ||
106 | m_app->branch().toUtf8().constData(), | 115 | m_app->branch().toUtf8().constData(), | ||
107 | flatpakInstallationProgressCallback, | 116 | flatpakInstallationProgressCallback, | ||
108 | this, | 117 | this, | ||
109 | m_cancellable, &localError)) { | 118 | m_cancellable, &localError)) { | ||
110 | m_result = false; | 119 | m_result = false; | ||
111 | m_errorMessage = QString::fromUtf8(localError->message); | 120 | m_errorMessage = QString::fromUtf8(localError->message); | ||
112 | qWarning() << "Failed to uninstall" << m_app->name() << ':' << m_errorMessage; | 121 | // We are done so we can set the progress to 100 | ||
122 | m_progress = 100; | ||||
123 | qWarning() << "Failed to uninstall" << refName << ':' << m_errorMessage; | ||||
113 | return; | 124 | return; | ||
114 | } | 125 | } | ||
115 | } | 126 | } | ||
116 | 127 | | |||
128 | // We are done so we can set the progress to 100 | ||||
129 | m_progress = 100; | ||||
117 | m_result = true; | 130 | m_result = true; | ||
131 | | ||||
132 | Q_EMIT progressChanged(m_progress); | ||||
133 | } | ||||
134 | | ||||
135 | FlatpakResource * FlatpakTransactionJob::app() const | ||||
136 | { | ||||
137 | return m_app; | ||||
138 | } | ||||
139 | | ||||
140 | bool FlatpakTransactionJob::isRelated() const | ||||
141 | { | ||||
142 | return !m_relatedRef.isEmpty(); | ||||
143 | } | ||||
144 | | ||||
145 | int FlatpakTransactionJob::progress() const | ||||
146 | { | ||||
147 | return m_progress; | ||||
148 | } | ||||
149 | | ||||
150 | void FlatpakTransactionJob::setProgress(int progress) | ||||
151 | { | ||||
152 | m_progress = progress; | ||||
118 | } | 153 | } | ||
119 | 154 | | |||
120 | QString FlatpakTransactionJob::errorMessage() const | 155 | QString FlatpakTransactionJob::errorMessage() const | ||
121 | { | 156 | { | ||
122 | return m_errorMessage; | 157 | return m_errorMessage; | ||
123 | } | 158 | } | ||
124 | 159 | | |||
125 | bool FlatpakTransactionJob::result() const | 160 | bool FlatpakTransactionJob::result() const | ||
126 | { | 161 | { | ||
127 | return m_result; | 162 | return m_result; | ||
128 | } | 163 | } | ||
129 | 164 | |