Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
Discover
Commits
9b59d777
Commit
9b59d777
authored
Nov 19, 2020
by
Aleix Pol Gonzalez
🐧
Browse files
fwupd: Use constructors to create objects
Mark things that won't change as const.
parent
aee1ead3
Changes
4
Hide whitespace changes
Inline
Side-by-side
libdiscover/backends/FwupdBackend/FwupdBackend.cpp
View file @
9b59d777
...
...
@@ -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
=
createDevi
ce
(
device
);
auto
res
=
new
FwupdResour
ce
(
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
))
{
...
...
libdiscover/backends/FwupdBackend/FwupdBackend.h
View file @
9b59d777
...
...
@@ -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
);
...
...
libdiscover/backends/FwupdBackend/FwupdResource.cpp
View file @
9b59d777
...
...
@@ -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
);
...
...
libdiscover/backends/FwupdBackend/FwupdResource.h
View file @
9b59d777
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment