File indexing completed on 2024-11-17 04:55:40
0001 /* 0002 * SPDX-FileCopyrightText: 2013 Aleix Pol Gonzalez <aleixpol@blue-systems.com> 0003 * SPDX-FileCopyrightText: 2018 Abhijeet Sharma <sharma.abhijeet2096@gmail.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #include "FwupdResource.h" 0009 0010 #include <KLocalizedString> 0011 #include <QDesktopServices> 0012 #include <QStringList> 0013 #include <QTimer> 0014 #include <Transaction/AddonList.h> 0015 0016 FwupdResource::FwupdResource(FwupdDevice *device, AbstractResourcesBackend *parent) 0017 : FwupdResource(device, 0018 QStringLiteral("org.fwupd.%1.device").arg(QString::fromUtf8(fwupd_device_get_id(device)).replace(QLatin1Char('/'), QLatin1Char('_'))), 0019 parent) 0020 { 0021 } 0022 0023 FwupdResource::FwupdResource(FwupdDevice *device, const QString &id, AbstractResourcesBackend *parent) 0024 : AbstractResource(parent) 0025 , m_id(id) 0026 , m_name(QString::fromUtf8(fwupd_device_get_name(device))) 0027 , m_deviceID(QString::fromUtf8(fwupd_device_get_id(device))) 0028 { 0029 Q_ASSERT(!m_name.isEmpty()); 0030 setObjectName(m_name); 0031 setDeviceDetails(device); 0032 } 0033 0034 QString FwupdResource::availableVersion() const 0035 { 0036 return m_availableVersion; 0037 } 0038 0039 QStringList FwupdResource::categories() 0040 { 0041 return m_categories; 0042 } 0043 0044 QString FwupdResource::comment() 0045 { 0046 return m_summary; 0047 } 0048 0049 quint64 FwupdResource::size() 0050 { 0051 return m_size; 0052 } 0053 0054 QUrl FwupdResource::homepage() 0055 { 0056 return m_homepage; 0057 } 0058 0059 QUrl FwupdResource::helpURL() 0060 { 0061 return {}; 0062 } 0063 0064 QUrl FwupdResource::bugURL() 0065 { 0066 return {}; 0067 } 0068 0069 QUrl FwupdResource::donationURL() 0070 { 0071 return {}; 0072 } 0073 0074 QVariant FwupdResource::icon() const 0075 { 0076 return m_iconName; 0077 } 0078 0079 QString FwupdResource::installedVersion() const 0080 { 0081 return m_installedVersion; 0082 } 0083 0084 QJsonArray FwupdResource::licenses() 0085 { 0086 return {QJsonObject{{QStringLiteral("name"), m_license}}}; 0087 } 0088 0089 QString FwupdResource::longDescription() 0090 { 0091 return m_description; 0092 } 0093 0094 QString FwupdResource::name() const 0095 { 0096 return m_displayName.isEmpty() ? m_name : m_displayName; 0097 } 0098 0099 QString FwupdResource::vendor() const 0100 { 0101 return m_vendor; 0102 } 0103 0104 QString FwupdResource::origin() const 0105 { 0106 return m_origin; 0107 } 0108 0109 QString FwupdResource::packageName() const 0110 { 0111 return m_name; 0112 } 0113 0114 QString FwupdResource::section() 0115 { 0116 return i18n("Firmware Updates"); 0117 } 0118 0119 AbstractResource::State FwupdResource::state() 0120 { 0121 return m_state; 0122 } 0123 0124 void FwupdResource::fetchChangelog() 0125 { 0126 QString log = longDescription(); 0127 log.replace(QLatin1Char('\n'), QLatin1String("<br />")); 0128 0129 Q_EMIT changelogFetched(log); 0130 } 0131 0132 void FwupdResource::setState(AbstractResource::State state) 0133 { 0134 if (m_state != state) { 0135 m_state = state; 0136 Q_EMIT stateChanged(); 0137 } 0138 } 0139 0140 void FwupdResource::invokeApplication() const 0141 { 0142 qWarning() << "Not Launchable"; 0143 } 0144 0145 QUrl FwupdResource::url() const 0146 { 0147 return m_homepage; 0148 } 0149 0150 QString FwupdResource::executeLabel() const 0151 { 0152 return QStringLiteral("Not Invokable"); 0153 } 0154 0155 void FwupdResource::setReleaseDetails(FwupdRelease *release) 0156 { 0157 m_origin = QString::fromUtf8(fwupd_release_get_remote_id(release)); 0158 m_summary = QString::fromUtf8(fwupd_release_get_summary(release)); 0159 m_vendor = QString::fromUtf8(fwupd_release_get_vendor(release)); 0160 m_size = fwupd_release_get_size(release); 0161 m_availableVersion = QString::fromUtf8(fwupd_release_get_version(release)); 0162 m_description = QString::fromUtf8((fwupd_release_get_description(release))); 0163 m_homepage = QUrl(QString::fromUtf8(fwupd_release_get_homepage(release))); 0164 m_license = QString::fromUtf8(fwupd_release_get_license(release)); 0165 #if FWUPD_CHECK_VERSION(1, 5, 6) 0166 GPtrArray *locations = fwupd_release_get_locations(release); 0167 m_updateURI = locations->len == 0 ? QString::fromUtf8("") : QString::fromUtf8((const gchar *)g_ptr_array_index(locations, 0)); 0168 #else 0169 m_updateURI = QString::fromUtf8(fwupd_release_get_uri(release)); 0170 #endif 0171 } 0172 0173 void FwupdResource::setDeviceDetails(FwupdDevice *dev) 0174 { 0175 m_isLiveUpdatable = fwupd_device_has_flag(dev, FWUPD_DEVICE_FLAG_UPDATABLE); 0176 m_isOnlyOffline = fwupd_device_has_flag(dev, FWUPD_DEVICE_FLAG_ONLY_OFFLINE); 0177 m_needsReboot = fwupd_device_has_flag(dev, FWUPD_DEVICE_FLAG_NEEDS_REBOOT); 0178 0179 if (fwupd_device_get_name(dev)) { 0180 QString vendorDesc = QString::fromUtf8(fwupd_device_get_name(dev)); 0181 const QString vendorName = QString::fromUtf8(fwupd_device_get_vendor(dev)); 0182 0183 if (!vendorDesc.startsWith(vendorName)) 0184 vendorDesc = vendorName + QLatin1Char(' ') + vendorDesc; 0185 m_displayName = vendorDesc; 0186 } 0187 m_summary = QString::fromUtf8(fwupd_device_get_summary(dev)); 0188 m_vendor = QString::fromUtf8(fwupd_device_get_vendor(dev)); 0189 m_releaseDate = QDateTime::fromSecsSinceEpoch(fwupd_device_get_created(dev)).date(); 0190 m_availableVersion = QString::fromUtf8(fwupd_device_get_version(dev)); 0191 m_description = QString::fromUtf8((fwupd_device_get_description(dev))); 0192 0193 if (fwupd_device_get_icons(dev)->len >= 1) 0194 m_iconName = QString::fromUtf8((const gchar *)g_ptr_array_index(fwupd_device_get_icons(dev), 0)); // Check whether given icon exists or not! 0195 else 0196 m_iconName = QStringLiteral("device-notifier"); 0197 } 0198 0199 QString FwupdResource::cacheFile() const 0200 { 0201 const auto filename_cache = FwupdBackend::cacheFile(QStringLiteral("fwupd"), QFileInfo(QUrl(m_updateURI).path()).fileName()); 0202 Q_ASSERT(!filename_cache.isEmpty()); 0203 return filename_cache; 0204 }