Changeset View
Changeset View
Standalone View
Standalone View
libdiscover/backends/FlatpakBackend/FlatpakNotifier.cpp
Show All 14 Lines | |||||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
16 | * GNU General Public License for more details. * | 16 | * GNU General Public License for more details. * | ||
17 | * * | 17 | * * | ||
18 | * You should have received a copy of the GNU General Public License * | 18 | * You should have received a copy of the GNU General Public License * | ||
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. * | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. * | ||
20 | ***************************************************************************/ | 20 | ***************************************************************************/ | ||
21 | 21 | | |||
22 | #include "FlatpakNotifier.h" | 22 | #include "FlatpakNotifier.h" | ||
23 | #include "FlatpakFetchUpdatesJob.h" | | |||
24 | 23 | | |||
25 | #include <glib.h> | 24 | #include <glib.h> | ||
26 | 25 | | |||
27 | #include <QDebug> | 26 | #include <QDebug> | ||
28 | #include <QTimer> | 27 | #include <QTimer> | ||
28 | #include <QtConcurrentRun> | ||||
29 | #include <QFutureWatcher> | ||||
29 | 30 | | |||
30 | static void installationChanged(GFileMonitor *monitor, GFile *child, GFile *other_file, GFileMonitorEvent event_type, gpointer self) | 31 | static void installationChanged(GFileMonitor *monitor, GFile *child, GFile *other_file, GFileMonitorEvent event_type, gpointer self) | ||
31 | { | 32 | { | ||
32 | Q_UNUSED(monitor); | 33 | Q_UNUSED(monitor); | ||
33 | Q_UNUSED(child); | 34 | Q_UNUSED(child); | ||
34 | Q_UNUSED(other_file); | 35 | Q_UNUSED(other_file); | ||
35 | Q_UNUSED(event_type); | 36 | Q_UNUSED(event_type); | ||
36 | 37 | | |||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Line(s) | 125 | } else { | |||
126 | m_systemInstallationUpdates = validUpdates; | 127 | m_systemInstallationUpdates = validUpdates; | ||
127 | } | 128 | } | ||
128 | 129 | | |||
129 | if (changed) { | 130 | if (changed) { | ||
130 | Q_EMIT foundUpdates(); | 131 | Q_EMIT foundUpdates(); | ||
131 | } | 132 | } | ||
132 | } | 133 | } | ||
133 | 134 | | |||
134 | void FlatpakNotifier::loadRemoteUpdates(FlatpakInstallation *flatpakInstallation) | 135 | void FlatpakNotifier::loadRemoteUpdates(FlatpakInstallation *installation) | ||
135 | { | 136 | { | ||
136 | FlatpakFetchUpdatesJob *job = new FlatpakFetchUpdatesJob(flatpakInstallation); | 137 | auto fw = new QFutureWatcher<GPtrArray *>(this); | ||
137 | connect(job, &FlatpakFetchUpdatesJob::finished, job, &FlatpakFetchUpdatesJob::deleteLater); | 138 | fw->setFuture(QtConcurrent::run( [installation]() -> GPtrArray * { | ||
138 | connect(job, &FlatpakFetchUpdatesJob::jobFetchUpdatesFinished, this, &FlatpakNotifier::onFetchUpdatesFinished); | 139 | g_autoptr(GCancellable) cancellable = g_cancellable_new(); | ||
139 | job->start(); | 140 | g_autoptr(GError) localError = nullptr; | ||
141 | GPtrArray *refs = flatpak_installation_list_installed_refs_for_update(installation, cancellable, &localError); | ||||
142 | if (!refs) { | ||||
143 | qWarning() << "Failed to get list of installed refs for listing updates: " << localError->message; | ||||
144 | } | ||||
145 | return refs; | ||||
146 | })); | ||||
147 | connect(fw, &QFutureWatcher<GPtrArray *>::finished, this, [this, installation, fw](){ | ||||
148 | auto refs = fw->result(); | ||||
149 | onFetchUpdatesFinished(installation, refs); | ||||
150 | fw->deleteLater(); | ||||
151 | }); | ||||
140 | } | 152 | } | ||
141 | 153 | | |||
142 | bool FlatpakNotifier::setupFlatpakInstallations(GError **error) | 154 | bool FlatpakNotifier::setupFlatpakInstallations(GError **error) | ||
143 | { | 155 | { | ||
144 | if (!m_flatpakInstallationSystem) { | 156 | if (!m_flatpakInstallationSystem) { | ||
145 | m_flatpakInstallationSystem = flatpak_installation_new_system(m_cancellable, error); | 157 | m_flatpakInstallationSystem = flatpak_installation_new_system(m_cancellable, error); | ||
146 | if (!m_flatpakInstallationSystem) { | 158 | if (!m_flatpakInstallationSystem) { | ||
147 | return false; | 159 | return false; | ||
Show All 32 Lines |