Commit 9b59d777 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

fwupd: Use constructors to create objects

Mark things that won't change as const.
parent aee1ead3
......@@ -69,24 +69,10 @@ void FwupdBackend::addResourceToList(FwupdResource* res)
Q_ASSERT(m_resources.value(res->packageName()) == res);
}
FwupdResource * FwupdBackend::createDevice(FwupdDevice *device)
{
const QString name = QString::fromUtf8(fwupd_device_get_name(device));
FwupdResource* res = new FwupdResource(name, this);
const QString deviceID = QString::fromUtf8(fwupd_device_get_id(device));
res->setId(QStringLiteral("org.fwupd.%1.device").arg(QString(deviceID).replace(QLatin1Char('/'),QLatin1Char('_'))));
res->setDeviceId(deviceID);
res->setDeviceDetails(device);
return res;
}
FwupdResource * FwupdBackend::createRelease(FwupdDevice *device)
{
FwupdResource* res = createDevice(device);
FwupdRelease *release = fwupd_device_get_release_default(device);
res->setId(QString::fromUtf8(fwupd_release_get_appstream_id(release)));
FwupdResource* res = new FwupdResource(device, QString::fromUtf8(fwupd_release_get_appstream_id(release)), this);
res->setReleaseDetails(release);
/* the same as we have already */
......@@ -390,7 +376,7 @@ void FwupdBackend::checkForUpdates()
handleError(error);
}
auto res = createDevice(device);
auto res = new FwupdResource(device, this);
for (uint i=0; releases && i<releases->len; ++i) {
FwupdRelease *release = (FwupdRelease *)g_ptr_array_index(releases, i);
if (res->installedVersion().toUtf8() == fwupd_release_get_version(release)) {
......
......@@ -79,7 +79,6 @@ private:
static QByteArray getChecksum(const QString &filename, QCryptographicHash::Algorithm hashAlgorithm);
static bool downloadFile(const QUrl &uri, const QString &filename);
FwupdResource * createDevice(FwupdDevice *device);
FwupdResource * createRelease(FwupdDevice *device);
FwupdResource * createApp(FwupdDevice *device);
......
......@@ -13,9 +13,15 @@
#include <QStringList>
#include <QTimer>
FwupdResource::FwupdResource(QString name, AbstractResourcesBackend* parent)
FwupdResource::FwupdResource(FwupdDevice* device, AbstractResourcesBackend* parent)
: FwupdResource(device, QStringLiteral("org.fwupd.%1.device").arg(QString::fromUtf8(fwupd_device_get_id(device)).replace(QLatin1Char('/'),QLatin1Char('_'))), parent)
{}
FwupdResource::FwupdResource(FwupdDevice* device, const QString &id, AbstractResourcesBackend* parent)
: AbstractResource(parent)
, m_name(std::move(name))
, m_id(id)
, m_name(QString::fromUtf8(fwupd_device_get_name(device)))
, m_deviceID(QString::fromUtf8(fwupd_device_get_id(device)))
{
Q_ASSERT(!m_name.isEmpty());
setObjectName(m_name);
......
......@@ -17,7 +17,8 @@ class FwupdResource : public AbstractResource
{
Q_OBJECT
public:
explicit FwupdResource(QString name, AbstractResourcesBackend* parent);
explicit FwupdResource(FwupdDevice *device, AbstractResourcesBackend* parent);
explicit FwupdResource(FwupdDevice *device, const QString &id, AbstractResourcesBackend* parent);
QList<PackageState> addonsInformation() override { return {}; }
QString section() override;
......@@ -48,10 +49,8 @@ public:
QString sourceIcon() const override { return {}; }
QString author() const override { return {}; }
void setDeviceId(const QString &deviceId) { m_deviceID = deviceId; }
void setIsDeviceLocked(bool locked) { m_isDeviceLocked = locked; }
void setDescription(const QString &description) { m_description = description; }
void setId(const QString &id) { m_id = id; }
void setState(AbstractResource::State state);
void setReleaseDetails(FwupdRelease *release);
......@@ -68,8 +67,9 @@ public:
QString cacheFile() const;
private:
QString m_id;
const QString m_id;
const QString m_name;
const QString m_deviceID;
QString m_summary;
QString m_description;
QString m_version;
......@@ -84,7 +84,6 @@ private:
QString m_iconName;
int m_size = 0;
QString m_deviceID;
QString m_updateURI;
bool m_isDeviceLocked = false; // True if device is locked!
bool m_isOnlyOffline = false; // True if only offline updates
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment