File indexing completed on 2024-11-17 04:55:38
0001 /* 0002 * SPDX-FileCopyrightText: 2013 Aleix Pol Gonzalez <aleixpol@blue-systems.com> 0003 * SPDX-FileCopyrightText: 2017 Jan Grulich <jgrulich@redhat.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #include "FlatpakRefreshAppstreamMetadataJob.h" 0009 #include <QDebug> 0010 0011 FlatpakRefreshAppstreamMetadataJob::FlatpakRefreshAppstreamMetadataJob(FlatpakInstallation *installation, FlatpakRemote *remote) 0012 : QThread() 0013 , m_cancellable(g_cancellable_new()) 0014 , m_installation(installation) 0015 , m_remote(remote) 0016 { 0017 g_object_ref(m_remote); 0018 connect(this, &FlatpakRefreshAppstreamMetadataJob::finished, this, &QObject::deleteLater); 0019 } 0020 0021 FlatpakRefreshAppstreamMetadataJob::~FlatpakRefreshAppstreamMetadataJob() 0022 { 0023 g_object_unref(m_remote); 0024 g_object_unref(m_cancellable); 0025 } 0026 0027 void FlatpakRefreshAppstreamMetadataJob::cancel() 0028 { 0029 g_cancellable_cancel(m_cancellable); 0030 } 0031 0032 void FlatpakRefreshAppstreamMetadataJob::run() 0033 { 0034 g_autoptr(GError) localError = nullptr; 0035 0036 #if FLATPAK_CHECK_VERSION(0, 9, 4) 0037 // With Flatpak 0.9.4 we can use flatpak_installation_update_appstream_full_sync() providing progress reporting which we don't use at this moment, but 0038 // still better to use newer function in case the previous one gets deprecated 0039 if (!flatpak_installation_update_appstream_full_sync(m_installation, 0040 flatpak_remote_get_name(m_remote), 0041 nullptr, 0042 nullptr, 0043 nullptr, 0044 nullptr, 0045 m_cancellable, 0046 &localError)) { 0047 #else 0048 if (!flatpak_installation_update_appstream_sync(m_installation, flatpak_remote_get_name(m_remote), nullptr, nullptr, m_cancellable, &localError)) { 0049 #endif 0050 const QString error = localError ? QString::fromUtf8(localError->message) : QStringLiteral("<no error>"); 0051 qWarning() << "Failed to refresh appstream metadata for " << flatpak_remote_get_name(m_remote) << ": " << error; 0052 } 0053 Q_EMIT jobRefreshAppstreamMetadataFinished(m_installation, m_remote); 0054 }