diff --git a/cmake/FindLIBFWUPD.cmake b/cmake/FindLIBFWUPD.cmake --- a/cmake/FindLIBFWUPD.cmake +++ b/cmake/FindLIBFWUPD.cmake @@ -1,35 +1,33 @@ -# - Try to find the Fwupd library +# CMake support for Fwupd library # Once done this will define # # LIBFWUPD_FOUND - system has the fwupd library # LIBFWUPD_INCLUDE_DIR - the Fwupd include directory # LIBFWUPD_LIBRARY - Link this to use the fwupd # -# Copyright © 2018, Abhijeet Sharma +# License: # -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. Neither the name of the University nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. +# Copyright © 2018, Abhijeet Sharma # -# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, copy, +# modify, merge, publish, distribute, sublicense, and/or sell copies +# of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. if(LIBFWUPD_INCLUDE_DIRS AND LIBFWUPD_LIBRARIES) set(LIBFWUPD_FOUND TRUE) diff --git a/libdiscover/backends/FwupdBackend/FwupdBackend.h b/libdiscover/backends/FwupdBackend/FwupdBackend.h --- a/libdiscover/backends/FwupdBackend/FwupdBackend.h +++ b/libdiscover/backends/FwupdBackend/FwupdBackend.h @@ -89,7 +89,7 @@ void addUpdates(); void addResourceToList(FwupdResource *res); void addHistoricalUpdates(); - void setReleaseDetails(FwupdResource *res, FwupdRelease *rel); + void setReleaseDetails(FwupdResource *res, FwupdRelease *release); void setDeviceDetails(FwupdResource *res, FwupdDevice *device); void handleError(GError **perror); QSet getAllUpdates(); diff --git a/libdiscover/backends/FwupdBackend/FwupdBackend.cpp b/libdiscover/backends/FwupdBackend/FwupdBackend.cpp --- a/libdiscover/backends/FwupdBackend/FwupdBackend.cpp +++ b/libdiscover/backends/FwupdBackend/FwupdBackend.cpp @@ -44,7 +44,7 @@ QTimer::singleShot(500, this, &FwupdBackend::toggleFetching); connect(m_updater, &StandardBackendUpdater::updatesCountChanged, this, &FwupdBackend::updatesCountChanged); - client = fwupd_client_new (); + client = fwupd_client_new(); populate(QStringLiteral("Releases")); SourcesModel::global()->addSourcesBackend(new FwupdSourcesBackend(this)); @@ -64,12 +64,12 @@ FwupdBackend::~FwupdBackend() { - g_object_unref (client); + g_object_unref(client); } QString FwupdBackend::buildDeviceID(FwupdDevice* device) { - QString DeviceID = QString::fromUtf8(fwupd_device_get_id (device)); + QString DeviceID = QString::fromUtf8(fwupd_device_get_id(device)); DeviceID.replace(QLatin1Char('/'),QLatin1Char('_')); return QStringLiteral("org.fwupd.%1.device").arg(DeviceID); } @@ -86,7 +86,7 @@ FwupdResource* res = new FwupdResource(name, true, this); res->setId(buildDeviceID(device)); res->addCategories(QStringLiteral("Releases")); - res->setIconName(QString::fromUtf8((const gchar *)g_ptr_array_index (fwupd_device_get_icons(device),0)));// Implement a Better way to decide icon + res->setIconName(QString::fromUtf8((const gchar *)g_ptr_array_index(fwupd_device_get_icons(device),0)));// Implement a Better way to decide icon setDeviceDetails(res,device); return res; @@ -94,19 +94,19 @@ FwupdResource * FwupdBackend::createRelease(FwupdDevice *device) { - FwupdRelease *rel = fwupd_device_get_release_default (device); - const QString name = QString::fromUtf8(fwupd_release_get_name(rel)); + FwupdRelease *release = fwupd_device_get_release_default(device); + const QString name = QString::fromUtf8(fwupd_release_get_name(release)); FwupdResource* res = new FwupdResource(name, true, this); - res->setDeviceID(QString::fromUtf8(fwupd_device_get_id (device))); - setReleaseDetails(res,rel); + res->setDeviceID(QString::fromUtf8(fwupd_device_get_id(device))); + setReleaseDetails(res,release); setDeviceDetails(res,device); - if (fwupd_release_get_appstream_id (rel)) - res->setId(QString::fromUtf8(fwupd_release_get_appstream_id (rel))); + if(fwupd_release_get_appstream_id(release)) + res->setId(QString::fromUtf8(fwupd_release_get_appstream_id(release))); /* the same as we have already */ - if(QLatin1Literal(fwupd_device_get_version (device)) == QLatin1Literal(fwupd_release_get_version (rel))) + if(QLatin1Literal(fwupd_device_get_version(device)) == QLatin1Literal(fwupd_release_get_version(release))) { qWarning() << "Fwupd Error: same firmware version as installed"; } @@ -114,51 +114,51 @@ return res; } -void FwupdBackend::setReleaseDetails(FwupdResource *res, FwupdRelease *rel) +void FwupdBackend::setReleaseDetails(FwupdResource *res, FwupdRelease *release) { res->addCategories(QLatin1String("Releases")); - if(fwupd_release_get_summary(rel)) - res->setSummary(QString::fromUtf8(fwupd_release_get_summary(rel))); - if(fwupd_release_get_vendor(rel)) - res->setVendor(QString::fromUtf8(fwupd_release_get_vendor(rel))); - if(fwupd_release_get_version(rel)) - res->setVersion(QString::fromUtf8(fwupd_release_get_version(rel))); - if(fwupd_release_get_description(rel)) - res->setDescription(QString::fromUtf8((fwupd_release_get_description (rel)))); - if(fwupd_release_get_homepage(rel)) - res->setHomePage(QUrl(QString::fromUtf8(fwupd_release_get_homepage(rel)))); - if(fwupd_release_get_license(rel)) - res->setLicense(QString::fromUtf8(fwupd_release_get_license(rel))); - if (fwupd_release_get_uri (rel)) - res->m_updateURI = QString::fromUtf8(fwupd_release_get_uri (rel)); + if(fwupd_release_get_summary(release)) + res->setSummary(QString::fromUtf8(fwupd_release_get_summary(release))); + if(fwupd_release_get_vendor(release)) + res->setVendor(QString::fromUtf8(fwupd_release_get_vendor(release))); + if(fwupd_release_get_version(release)) + res->setVersion(QString::fromUtf8(fwupd_release_get_version(release))); + if(fwupd_release_get_description(release)) + res->setDescription(QString::fromUtf8((fwupd_release_get_description(release)))); + if(fwupd_release_get_homepage(release)) + res->setHomePage(QUrl(QString::fromUtf8(fwupd_release_get_homepage(release)))); + if(fwupd_release_get_license(release)) + res->setLicense(QString::fromUtf8(fwupd_release_get_license(release))); + if(fwupd_release_get_uri(release)) + res->m_updateURI = QString::fromUtf8(fwupd_release_get_uri(release)); } void FwupdBackend::setDeviceDetails(FwupdResource *res, FwupdDevice *dev) { - res->isLiveUpdatable = fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_UPDATABLE); - res->isOnlyOffline = fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_ONLY_OFFLINE); - res->needsReboot = fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_NEEDS_REBOOT); - res->isDeviceRemoval = !fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_INTERNAL); + res->isLiveUpdatable = fwupd_device_has_flag(dev, FWUPD_DEVICE_FLAG_UPDATABLE); + res->isOnlyOffline = fwupd_device_has_flag(dev, FWUPD_DEVICE_FLAG_ONLY_OFFLINE); + res->needsReboot = fwupd_device_has_flag(dev, FWUPD_DEVICE_FLAG_NEEDS_REBOOT); + res->isDeviceRemoval = !fwupd_device_has_flag(dev, FWUPD_DEVICE_FLAG_INTERNAL); - GPtrArray *guids = fwupd_device_get_guids (dev); + GPtrArray *guids = fwupd_device_get_guids(dev); if(guids->len > 0) { - QString guidStr = QString::fromUtf8((char *)g_ptr_array_index (guids, 0)); - for (uint i = 1; i < guids->len; i++) + QString guidStr = QString::fromUtf8((char *)g_ptr_array_index(guids, 0)); + for(uint i = 1; i < guids->len; i++) { - guidStr += QLatin1Char(',') + QString::fromUtf8((char *)g_ptr_array_index (guids, i)); + guidStr += QLatin1Char(',') + QString::fromUtf8((char *)g_ptr_array_index(guids, i)); } res->guidString = guidStr; } - if(fwupd_device_get_name (dev)) + if(fwupd_device_get_name(dev)) { QString vendorName; - vendorName.sprintf("%s",fwupd_device_get_name (dev)); + vendorName.sprintf("%s",fwupd_device_get_name(dev)); - if(vendorName.indexOf(QString::fromUtf8(fwupd_device_get_vendor (dev))) == 0) - vendorName.sprintf("%s %s",fwupd_device_get_vendor (dev), fwupd_device_get_name (dev)); + if(vendorName.indexOf(QString::fromUtf8(fwupd_device_get_vendor(dev))) == 0) + vendorName.sprintf("%s %s",fwupd_device_get_vendor(dev), fwupd_device_get_name(dev)); res->setName(vendorName); } - if(fwupd_device_get_summary (dev)) + if(fwupd_device_get_summary(dev)) res->setSummary(QString::fromUtf8(fwupd_device_get_summary(dev))); if(fwupd_device_get_vendor(dev)) res->setVendor(QString::fromUtf8(fwupd_device_get_vendor(dev))); @@ -171,16 +171,16 @@ void FwupdBackend::populate(const QString& n) { /* get devices */ - g_autoptr(GPtrArray) devices = fwupd_client_get_devices (client, nullptr, nullptr); + g_autoptr(GPtrArray) devices = fwupd_client_get_devices(client, nullptr, nullptr); - if (devices) + if(devices) { - for (uint i = 0; i < devices->len; i++) + for(uint i = 0; i < devices->len; i++) { - FwupdDevice *device = (FwupdDevice *)g_ptr_array_index (devices, i); + FwupdDevice *device = (FwupdDevice *)g_ptr_array_index(devices, i); /* Devices Which are not updatable */ - if (!fwupd_device_has_flag (device, FWUPD_DEVICE_FLAG_UPDATABLE)) + if(!fwupd_device_has_flag(device, FWUPD_DEVICE_FLAG_UPDATABLE)) continue; /* add releases */ @@ -188,16 +188,16 @@ res->addCategories(n); - g_autoptr(GPtrArray) releases = fwupd_client_get_releases (client, res->m_deviceID.toUtf8().constData(), nullptr, nullptr); + g_autoptr(GPtrArray) releases = fwupd_client_get_releases(client, res->m_deviceID.toUtf8().constData(), nullptr, nullptr); - if (releases) + if(releases) { - for (uint j = 0; j < releases->len; j++) + for(uint j = 0; j < releases->len; j++) { - FwupdRelease *rel = (FwupdRelease *)g_ptr_array_index (releases, j); - const QString name = QString::fromUtf8(fwupd_release_get_name(rel)); + FwupdRelease *release = (FwupdRelease *)g_ptr_array_index(releases, j); + const QString name = QString::fromUtf8(fwupd_release_get_name(release)); FwupdResource* res_ = new FwupdResource(name, true, this); - setReleaseDetails (res_, rel); + setReleaseDetails(res_, release); res->m_releases.append(res_); } } @@ -212,27 +212,27 @@ { g_autoptr(GError) error = nullptr; g_autoptr(GError) error2 = nullptr; - g_autoptr(GPtrArray) devices = fwupd_client_get_devices (client, nullptr, &error); + g_autoptr(GPtrArray) devices = fwupd_client_get_devices(client, nullptr, &error); if(!devices) { - if (g_error_matches (error, FWUPD_ERROR, FWUPD_ERROR_NOTHING_TO_DO)) + if(g_error_matches(error, FWUPD_ERROR, FWUPD_ERROR_NOTHING_TO_DO)) { qDebug() << "Fwupd Info: No Devices Found"; handleError(&error); } } else{ - for (uint i = 0; i < devices->len; i++) + for(uint i = 0; i < devices->len; i++) { - FwupdDevice *device = (FwupdDevice *)g_ptr_array_index (devices, i); + FwupdDevice *device = (FwupdDevice *)g_ptr_array_index(devices, i); FwupdResource* res; - if (!fwupd_device_has_flag (device, FWUPD_DEVICE_FLAG_SUPPORTED)) + if(!fwupd_device_has_flag(device, FWUPD_DEVICE_FLAG_SUPPORTED)) continue; /*Device is Locked Needs Unlocking*/ - if (fwupd_device_has_flag (device, FWUPD_DEVICE_FLAG_LOCKED)) + if(fwupd_device_has_flag(device, FWUPD_DEVICE_FLAG_LOCKED)) { res = createDevice(device); res->setIsDeviceLocked(true); @@ -242,11 +242,11 @@ } - g_autoptr(GPtrArray) rels = fwupd_client_get_upgrades (client, fwupd_device_get_id(device), nullptr, &error2); + g_autoptr(GPtrArray) rels = fwupd_client_get_upgrades(client, fwupd_device_get_id(device), nullptr, &error2); - if (!rels) + if(!rels) { - if (g_error_matches (error2, FWUPD_ERROR, FWUPD_ERROR_NOTHING_TO_DO)) + if(g_error_matches(error2, FWUPD_ERROR, FWUPD_ERROR_NOTHING_TO_DO)) { qWarning() << "Fwupd Error: No Packages Found for "<< fwupd_device_get_id(device); handleError(&error2); @@ -255,7 +255,7 @@ } else { - fwupd_device_add_release(device, (FwupdRelease *)g_ptr_array_index(rels, 0)); + fwupd_device_add_release(device,(FwupdRelease *)g_ptr_array_index(rels, 0)); res = createApp(device); if(res == nullptr) { @@ -268,11 +268,11 @@ QString longdescription; for(uint j = 0; j < rels->len; j++) { - FwupdRelease *rel = (FwupdRelease *)g_ptr_array_index (rels, j); - if (fwupd_release_get_description (rel) == nullptr) + FwupdRelease *release = (FwupdRelease *)g_ptr_array_index(rels, j); + if(fwupd_release_get_description(release) == nullptr) continue; - longdescription += QStringLiteral("Version %1\n").arg(QString::fromUtf8(fwupd_release_get_version (rel))); - longdescription += QString::fromUtf8(fwupd_release_get_description (rel)) + QLatin1Char('\n'); + longdescription += QStringLiteral("Version %1\n").arg(QString::fromUtf8(fwupd_release_get_version(release))); + longdescription += QString::fromUtf8(fwupd_release_get_description(release)) + QLatin1Char('\n'); } res->setDescription(longdescription); } @@ -286,7 +286,7 @@ void FwupdBackend::addHistoricalUpdates() { g_autoptr(GError) error = nullptr; - g_autoptr(FwupdDevice) device = fwupd_client_get_results (client, FWUPD_DEVICE_ID_ANY, nullptr, &error); + g_autoptr(FwupdDevice) device = fwupd_client_get_results(client, FWUPD_DEVICE_ID_ANY, nullptr, &error); if(!device) { handleError(&error); @@ -307,10 +307,10 @@ QByteArray FwupdBackend::getChecksum(const QUrl filename, QCryptographicHash::Algorithm hashAlgorithm) { QFile f(filename.toString()); - if (f.open(QFile::ReadOnly)) + if(f.open(QFile::ReadOnly)) { QCryptographicHash hash(hashAlgorithm); - if (hash.addData(&f)) + if(hash.addData(&f)) { return hash.result().toHex(); } @@ -320,42 +320,42 @@ FwupdResource* FwupdBackend::createApp(FwupdDevice *device) { - FwupdRelease *rel = fwupd_device_get_release_default (device); + FwupdRelease *release = fwupd_device_get_release_default(device); GPtrArray *checksums; FwupdResource* app = createRelease(device); /* update unsupported */ - if (!app->isLiveUpdatable) + if(!app->isLiveUpdatable) { qWarning() << "Fwupd Error: " << app->m_name << "[" << app->m_id << "]" << "cannot be updated "; return nullptr; } /* Important Attributes missing */ - if (app->m_id.isNull()) + if(app->m_id.isNull()) { qWarning() << "Fwupd Error: No id for firmware"; return nullptr; } - if (app->m_version.isNull()) + if(app->m_version.isNull()) { qWarning() << "Fwupd Error: No version! for " << app->m_id; return nullptr; } - if (app->m_updateVersion.isNull()) + if(app->m_updateVersion.isNull()) { qWarning() << "Fwupd Error: No update-version! for " << app->m_id; return nullptr; } - checksums = fwupd_release_get_checksums (rel); - if (checksums->len == 0) + checksums = fwupd_release_get_checksums(release); + if(checksums->len == 0) { qWarning() << "Fwupd Error: " << app->m_name << "[" << app->m_id << "]" << "(" << app->m_updateVersion << ")" "has no checksums, ignoring as unsafe"; return nullptr; } - const QUrl update_uri(QString::fromUtf8(fwupd_release_get_uri(rel))); + const QUrl update_uri(QString::fromUtf8(fwupd_release_get_uri(release))); - if (!update_uri.isValid()) + if(!update_uri.isValid()) { qWarning() << "Fwupd Error: No Update URI available for" << app->m_name << "[" << app->m_id << "]"; return nullptr; @@ -364,22 +364,22 @@ /* Checking for firmware in the cache? */ QFileInfo basename = QFileInfo(update_uri.path()); const QUrl filename_cache = cacheFile(QStringLiteral("fwupd"), basename); - if (filename_cache.isEmpty()) + if(filename_cache.isEmpty()) return nullptr; - if (filename_cache.isLocalFile()) + if(filename_cache.isLocalFile()) { - QByteArray checksum_tmp = QByteArray(fwupd_checksum_get_by_kind (checksums, G_CHECKSUM_SHA1)); + QByteArray checksum_tmp = QByteArray(fwupd_checksum_get_by_kind(checksums, G_CHECKSUM_SHA1)); /* Currently LVFS supports SHA1 only*/ - if (checksum_tmp.isNull()) + if(checksum_tmp.isNull()) { qWarning() << "Fwupd Error: No valid checksum for" << filename_cache; } QByteArray checksum = getChecksum(filename_cache, QCryptographicHash::Sha1); - if (checksum.isNull() || checksum_tmp.isNull()) + if(checksum.isNull() || checksum_tmp.isNull()) return nullptr; - if (checksum_tmp != checksum) + if(checksum_tmp != checksum) { qWarning() << "Fwupd Error: " << filename_cache << " does not match checksum, expected" << checksum_tmp << "got" << checksum; QFile::remove((filename_cache.toString())); @@ -395,11 +395,11 @@ void FwupdBackend::saveFile(QNetworkReply *reply) { QString filename = this->m_downloadFile[reply->url()]; - if (reply->error() == QNetworkReply::NoError) + if(reply->error() == QNetworkReply::NoError) { QByteArray Data = reply->readAll(); QFile file(filename); - if (file.open(QIODevice::WriteOnly)) + if(file.open(QIODevice::WriteOnly)) { file.write(Data); } @@ -427,7 +427,7 @@ { return false; } - else if( QNetworkReply::NoError != reply->error() ) + else if(QNetworkReply::NoError != reply->error() ) { return false; } @@ -442,20 +442,20 @@ bool FwupdBackend::refreshRemotes(uint cacheAge) { g_autoptr(GError) error = nullptr; - g_autoptr(GPtrArray) remotes = fwupd_client_get_remotes(client, nullptr, &error); - if (!remotes) + g_autoptr(GPtrArray) remotes = fwupd_client_get_remotes(client, nullptr, &error); + if(!remotes) return false; - for (uint i = 0; i < remotes->len; i++) + for(uint i = 0; i < remotes->len; i++) { FwupdRemote *remote = (FwupdRemote *)g_ptr_array_index(remotes, i); /*Remotes disabled by user so ignore*/ - if (!fwupd_remote_get_enabled (remote)) + if(!fwupd_remote_get_enabled(remote)) continue; /*Local Remotes Ignore*/ - if (fwupd_remote_get_kind (remote) == FWUPD_REMOTE_KIND_LOCAL) + if(fwupd_remote_get_kind(remote) == FWUPD_REMOTE_KIND_LOCAL) continue; /*Refresh the left ones*/ - if (!refreshRemote(remote, cacheAge)) + if(!refreshRemote(remote, cacheAge)) return false; } return true; @@ -465,29 +465,29 @@ { g_autoptr(GError) error = nullptr; - if (fwupd_remote_get_filename_cache_sig(remote) == nullptr) + if(fwupd_remote_get_filename_cache_sig(remote) == nullptr) { - qWarning() << "Fwupd Error: " << "Remote " << fwupd_remote_get_id (remote) << "has no cache signature!"; + qWarning() << "Fwupd Error: " << "Remote " << fwupd_remote_get_id(remote) << "has no cache signature!"; return false; } /* check cache age */ - if (cacheAge > 0) + if(cacheAge > 0) { quint64 age = fwupd_remote_get_age(remote); uint tmp = age < std::numeric_limits::max() ? (uint) age : std::numeric_limits::max(); - if (tmp < cacheAge) + if(tmp < cacheAge) { - qDebug() << "Fwupd Info:" << fwupd_remote_get_id (remote) << "is only" << tmp << "seconds old, so ignoring refresh! "; + qDebug() << "Fwupd Info:" << fwupd_remote_get_id(remote) << "is only" << tmp << "seconds old, so ignoring refresh! "; return true; } } - QString cacheId = QStringLiteral("fwupd/remotes.d/%1").arg(QString::fromUtf8(fwupd_remote_get_id (remote))); - QFileInfo basenameSig = QFileInfo(QString::fromUtf8(g_path_get_basename(fwupd_remote_get_filename_cache_sig (remote)))); + QString cacheId = QStringLiteral("fwupd/remotes.d/%1").arg(QString::fromUtf8(fwupd_remote_get_id(remote))); + QFileInfo basenameSig = QFileInfo(QString::fromUtf8(g_path_get_basename(fwupd_remote_get_filename_cache_sig(remote)))); const QUrl filenameSig = cacheFile(cacheId, basenameSig); - if (filenameSig.isEmpty()) + if(filenameSig.isEmpty()) return false; /* download the signature first*/ @@ -507,7 +507,7 @@ QCryptographicHash::Algorithm hashAlgorithm = map[(fwupd_checksum_guess_kind(fwupd_remote_get_checksum(remote)))]; QByteArray hash = getChecksum(filenameSig_,hashAlgorithm); - if ((fwupd_remote_get_checksum(remote) == hash) && filenameSig.isLocalFile()) + if((fwupd_remote_get_checksum(remote) == hash) && filenameSig.isLocalFile()) { qDebug() << "Fwupd Info: signature of" << urlSig.toString() << "is unchanged"; return true; @@ -518,7 +518,7 @@ /* save to a file */ qDebug() << "Fwupd Info: saving new remote signature to:" << filenameSig.toString(); - if (!(QFile::copy(filenameSig_.toString(), filenameSig.toString()))) + if(!(QFile::copy(filenameSig_.toString(), filenameSig.toString()))) { QFile::remove(filenameSig_.toString()); qWarning() << "Fwupd Error: cannot save remote signature"; @@ -529,19 +529,19 @@ QFileInfo basename = QFileInfo(QString::fromUtf8(g_path_get_basename(fwupd_remote_get_filename_cache(remote)))); const QUrl filename = cacheFile(cacheId, basename); - if (filename.isEmpty()) + if(filename.isEmpty()) return false; qDebug() << "Fwupd Info: saving new firmware metadata to:" << filename.toString(); const QUrl url(QString::fromUtf8(fwupd_remote_get_metadata_uri(remote))); - if (!downloadFile (url, filename.toString())) + if(!downloadFile(url, filename.toString())) { qWarning() << "Fwupd Error: cannot download file : " << filename.toString() ; return false; } /* Sending Metadata to fwupd Daemon*/ - if (!fwupd_client_update_metadata (client, fwupd_remote_get_id(remote), filename.toString().toUtf8().constData(), filenameSig.toString().toUtf8().constData(), nullptr, &error)) + if(!fwupd_client_update_metadata(client, fwupd_remote_get_id(remote), filename.toString().toUtf8().constData(), filenameSig.toString().toUtf8().constData(), nullptr, &error)) { handleError(&error); return false; @@ -555,7 +555,7 @@ if(!error) return; - switch (error->code) + switch(error->code) { case FWUPD_ERROR_ALREADY_PENDING: qWarning() << "Fwupd Error: FWUPD_ERROR_ALREADY_PENDING"; @@ -619,7 +619,7 @@ ResultsStream* FwupdBackend::search(const AbstractResourcesBackend::Filters& filter) { QVector ret; - if (!filter.resourceUrl.isEmpty() && filter.resourceUrl.scheme() == QLatin1String("fwupd")) + if(!filter.resourceUrl.isEmpty() && filter.resourceUrl.scheme() == QLatin1String("fwupd")) { return findResourceByPackageName(filter.resourceUrl); } @@ -637,9 +637,11 @@ ResultsStream * FwupdBackend::findResourceByPackageName(const QUrl& search) { auto res = search.scheme() == QLatin1String("fwupd") ? m_resources.value(search.host().replace(QLatin1Char('.'), QLatin1Char(' '))) : nullptr; - if (!res) { + if(!res) + { return new ResultsStream(QStringLiteral("FwupdStream"), {}); - } else + } + else return new ResultsStream(QStringLiteral("FwupdStream"), { res }); } @@ -691,15 +693,15 @@ g_autofree gchar *filename = path.fileName().toUtf8().data(); g_autoptr(GPtrArray) devices = fwupd_client_get_details(client, filename, nullptr, &error); - if (devices) + if(devices) { - FwupdDevice *dev = (FwupdDevice *)g_ptr_array_index(devices, 0); - app = createRelease(dev); + FwupdDevice *device = (FwupdDevice *)g_ptr_array_index(devices, 0); + app = createRelease(device); app->setState(AbstractResource::None); - for (uint i = 1; i < devices->len; i++) + for(uint i = 1; i < devices->len; i++) { - FwupdDevice *dev = (FwupdDevice *)g_ptr_array_index(devices, i); - FwupdResource* app_ = createRelease(dev); + FwupdDevice *device = (FwupdDevice *)g_ptr_array_index(devices, i); + FwupdResource* app_ = createRelease(device); app_->setState(AbstractResource::None); if(!app->m_releases.contains(app_)) app->m_releases.append(app_); diff --git a/libdiscover/backends/FwupdBackend/FwupdResource.cpp b/libdiscover/backends/FwupdBackend/FwupdResource.cpp --- a/libdiscover/backends/FwupdBackend/FwupdResource.cpp +++ b/libdiscover/backends/FwupdBackend/FwupdResource.cpp @@ -160,11 +160,11 @@ void FwupdResource::setAddons(const AddonList& addons) { - Q_FOREACH (const QString& toInstall, addons.addonsToInstall()) + Q_FOREACH(const QString& toInstall, addons.addonsToInstall()) { setAddonInstalled(toInstall, true); } - Q_FOREACH (const QString& toRemove, addons.addonsToRemove()) + Q_FOREACH(const QString& toRemove, addons.addonsToRemove()) { setAddonInstalled(toRemove, false); } diff --git a/libdiscover/backends/FwupdBackend/FwupdSourcesBackend.cpp b/libdiscover/backends/FwupdBackend/FwupdSourcesBackend.cpp --- a/libdiscover/backends/FwupdBackend/FwupdSourcesBackend.cpp +++ b/libdiscover/backends/FwupdBackend/FwupdSourcesBackend.cpp @@ -43,7 +43,7 @@ bool setData(const QModelIndex & index, const QVariant & value, int role) override { auto item = itemFromIndex(index); - if (!item) + if(!item) return false; remote = fwupd_client_get_remote_by_id(m_backend->backend->client,item->data(AbstractSourcesBackend::IdRole).toString().toUtf8().constData(),nullptr,nullptr); status = fwupd_remote_get_enabled(remote); @@ -101,21 +101,21 @@ void FwupdSourcesBackend::populateSources() { /* find all remotes */ - g_autoptr(GPtrArray) remotes = fwupd_client_get_remotes (backend->client,nullptr,nullptr); + g_autoptr(GPtrArray) remotes = fwupd_client_get_remotes(backend->client,nullptr,nullptr); if(remotes != nullptr) { - for (uint i = 0; i < remotes->len; i++) + for(uint i = 0; i < remotes->len; i++) { - FwupdRemote *remote = (FwupdRemote *)g_ptr_array_index (remotes, i); - if (fwupd_remote_get_kind (remote) == FWUPD_REMOTE_KIND_LOCAL) + FwupdRemote *remote = (FwupdRemote *)g_ptr_array_index(remotes, i); + if(fwupd_remote_get_kind(remote) == FWUPD_REMOTE_KIND_LOCAL) continue; - const QString id = QString::fromUtf8(fwupd_remote_get_id (remote)); - if (id.isEmpty()) + const QString id = QString::fromUtf8(fwupd_remote_get_id(remote)); + if(id.isEmpty()) continue; bool status = !fwupd_remote_get_enabled(remote); QStandardItem* it = new QStandardItem(id); it->setData(id, AbstractSourcesBackend::IdRole); - it->setData(QVariant(QString::fromUtf8(fwupd_remote_get_title (remote))), Qt::ToolTipRole); + it->setData(QVariant(QString::fromUtf8(fwupd_remote_get_title(remote))), Qt::ToolTipRole); it->setCheckable(true); it->setCheckState(status ? Qt::Unchecked : Qt::Checked); m_sources->appendRow(it); diff --git a/libdiscover/backends/FwupdBackend/FwupdTransaction.cpp b/libdiscover/backends/FwupdBackend/FwupdTransaction.cpp --- a/libdiscover/backends/FwupdBackend/FwupdTransaction.cpp +++ b/libdiscover/backends/FwupdBackend/FwupdTransaction.cpp @@ -64,7 +64,7 @@ qWarning("Fwupd Error: No Device ID set, cannot unlock device "); return false; } - if (!fwupd_client_unlock (m_backend->client, device_id.toUtf8().constData(),nullptr, &error)) + if(!fwupd_client_unlock(m_backend->client, device_id.toUtf8().constData(),nullptr, &error)) { m_backend->handleError(&error); return false; @@ -89,7 +89,7 @@ return false; } - if (!(QFileInfo::exists(localFile))) + if(!(QFileInfo::exists(localFile))) { const QUrl uri(m_app->m_updateURI); setStatus(DownloadingStatus); @@ -109,11 +109,11 @@ if(reply) { QString filename = m_app->m_file; - if (reply->error() == QNetworkReply::NoError) + if(reply->error() == QNetworkReply::NoError) { QByteArray Data = reply->readAll(); QFile file(filename); - if (file.open(QIODevice::WriteOnly)) + if(file.open(QIODevice::WriteOnly)) { file.write(Data); } @@ -131,16 +131,16 @@ QString localFile = m_app->m_file; QString deviceId = m_app->m_deviceID; /* limit to single device? */ - if (deviceId.isNull()) + if(deviceId.isNull()) deviceId = QStringLiteral(FWUPD_DEVICE_ID_ANY); /* only offline supported */ - if (m_app->isOnlyOffline) + if(m_app->isOnlyOffline) install_flags = static_cast(install_flags | FWUPD_INSTALL_FLAG_OFFLINE); m_iterate = true; QTimer::singleShot(100, this, &FwupdTransaction::updateProgress); - if (!fwupd_client_install (m_backend->client, deviceId.toUtf8().constData(), localFile.toUtf8().constData(), install_flags, nullptr, &error)) + if(!fwupd_client_install(m_backend->client, deviceId.toUtf8().constData(), localFile.toUtf8().constData(), install_flags, nullptr, &error)) { m_backend->handleError(&error); m_iterate = false; @@ -158,13 +158,13 @@ void FwupdTransaction::updateProgress() { - if (!m_iterate) + if(!m_iterate) return; setStatus(CommittingStatus); if(progress()<100) { - setProgress(fwupd_client_get_percentage (m_backend->client)); + setProgress(fwupd_client_get_percentage(m_backend->client)); QTimer::singleShot(100, this, &FwupdTransaction::updateProgress); } }