Commit 954a5c32 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

fix clazy warnings that make sense

Some issues are already quite relevant and could have potentially run
into crashes, like the 3-parameter connects.
parent 3dfd7cbc
......@@ -138,7 +138,8 @@ DiscoverObject::DiscoverObject(CompactMode mode)
auto action = new OneTimeAction(
[this]() {
bool found = DiscoverBackendsFactory::hasRequestedBackends();
for (auto b : ResourcesModel::global()->backends())
const auto backends = ResourcesModel::global()->backends();
for (auto b : backends)
found |= b->hasApplications();
if (!found)
......
......@@ -208,6 +208,8 @@ void PaginateModel::setStaticRowCount(bool src)
beginResetModel();
m_hasStaticRowCount = src;
endResetModel();
Q_EMIT staticRowCountChanged();
}
//////////////////////////////
......
......@@ -40,7 +40,7 @@ class PaginateModel : public QAbstractListModel
Q_PROPERTY(int pageCount READ pageCount NOTIFY pageCountChanged)
/** If enabled, ensures that pageCount and pageSize are the same. */
Q_PROPERTY(bool staticRowCount READ hasStaticRowCount WRITE setStaticRowCount)
Q_PROPERTY(bool staticRowCount READ hasStaticRowCount WRITE setStaticRowCount NOTIFY staticRowCountChanged)
public:
explicit PaginateModel(QObject* object = nullptr);
......@@ -105,6 +105,7 @@ class PaginateModel : public QAbstractListModel
void firstItemChanged();
void sourceModelChanged();
void pageCountChanged();
void staticRowCountChanged();
private:
bool canSizeChange() const;
......
......@@ -89,5 +89,6 @@ void ActionsModel::setFilterPriority(int p)
if (m_priority != p) {
m_priority = p;
reload();
Q_EMIT filterPriorityChanged();
}
}
......@@ -31,7 +31,7 @@ class DISCOVERCOMMON_EXPORT ActionsModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(QVariant actions READ actions WRITE setActions NOTIFY actionsChanged)
Q_PROPERTY(int filterPriority READ filterPriority WRITE setFilterPriority)
Q_PROPERTY(int filterPriority READ filterPriority WRITE setFilterPriority NOTIFY filterPriorityChanged)
public:
explicit ActionsModel(QObject* parent = nullptr);
......@@ -47,6 +47,7 @@ class DISCOVERCOMMON_EXPORT ActionsModel : public QAbstractListModel
Q_SIGNALS:
void actionsChanged(const QVariant& actions);
void filterPriorityChanged();
private:
void reload();
......
......@@ -103,7 +103,7 @@ FlatpakBackend::~FlatpakBackend()
g_cancellable_cancel(m_cancellable);
m_threadPool.waitForDone(200);
m_threadPool.clear();
for(auto inst : m_installations)
for(auto inst : qAsConst(m_installations))
g_object_unref(inst);
g_object_unref(m_cancellable);
......@@ -121,7 +121,7 @@ void FlatpakBackend::announceRatingsReady()
const auto ids = m_reviews->appstreamIds().toSet();
foreach(AbstractResource* res, m_resources) {
if (ids.contains(res->appstreamId())) {
res->ratingFetched();
Q_EMIT res->ratingFetched();
}
}
}
......@@ -1113,7 +1113,7 @@ ResultsStream * FlatpakBackend::search(const AbstractResourcesBackend::Filters &
FlatpakFetchRemoteResourceJob *fetchResourceJob = new FlatpakFetchRemoteResourceJob(filter.resourceUrl, this);
connect(fetchResourceJob, &FlatpakFetchRemoteResourceJob::jobFinished, this, [fetchResourceJob, stream] (bool success, FlatpakResource *resource) {
if (success) {
stream->resourcesFound({resource});
Q_EMIT stream->resourcesFound({resource});
}
stream->finish();
fetchResourceJob->deleteLater();
......@@ -1175,7 +1175,7 @@ ResultsStream * FlatpakBackend::findResourceByPackageName(const QUrl &url)
{
if (url.scheme() == QLatin1String("appstream")) {
if (url.host().isEmpty())
passiveMessage(i18n("Malformed appstream url '%1'", url.toDisplayString()));
Q_EMIT passiveMessage(i18n("Malformed appstream url '%1'", url.toDisplayString()));
else {
auto stream = new ResultsStream(QStringLiteral("FlatpakStream"));
auto f = [this, stream, url] () {
......@@ -1226,7 +1226,7 @@ Transaction* FlatpakBackend::installApplication(AbstractResource *app, const Add
}
FlatpakJobTransaction *transaction = new FlatpakJobTransaction(resource, Transaction::InstallRole);
connect(transaction, &FlatpakJobTransaction::statusChanged, [this, resource] (Transaction::Status status) {
connect(transaction, &FlatpakJobTransaction::statusChanged, this, [this, resource] (Transaction::Status status) {
if (status == Transaction::Status::DoneStatus) {
FlatpakInstallation *installation = resource->installation();
updateAppState(installation, resource);
......@@ -1255,7 +1255,7 @@ Transaction* FlatpakBackend::removeApplication(AbstractResource *app)
FlatpakInstallation *installation = resource->installation();
FlatpakJobTransaction *transaction = new FlatpakJobTransaction(resource, Transaction::RemoveRole);
connect(transaction, &FlatpakJobTransaction::statusChanged, [this, installation, resource] (Transaction::Status status) {
connect(transaction, &FlatpakJobTransaction::statusChanged, this, [this, installation, resource] (Transaction::Status status) {
if (status == Transaction::Status::DoneStatus) {
updateAppSize(installation, resource);
}
......
......@@ -48,7 +48,7 @@
static QString iconCachePath(const AppStream::Icon &icon)
{
Q_ASSERT(icon.kind() == AppStream::Icon::KindRemote);
return QStringLiteral("%1/icons/%2").arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)).arg(icon.url().fileName());
return QStringLiteral("%1/icons/%2").arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation), icon.url().fileName());
}
FlatpakResource::FlatpakResource(const AppStream::Component &component, FlatpakInstallation* installation, FlatpakBackend *parent)
......@@ -73,7 +73,7 @@ FlatpakResource::FlatpakResource(const AppStream::Component &component, FlatpakI
// Create $HOME/.cache/discover/icons folder
cacheDir.mkdir(QStringLiteral("icons"));
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, &QNetworkAccessManager::finished, [this, icon, fileName, manager] (QNetworkReply *reply) {
connect(manager, &QNetworkAccessManager::finished, this, [this, icon, fileName, manager] (QNetworkReply *reply) {
if (reply->error() == QNetworkReply::NoError) {
QByteArray iconData = reply->readAll();
QFile file(fileName);
......@@ -549,7 +549,7 @@ QString FlatpakResource::installationPath(FlatpakInstallation* flatpakInstallati
QString FlatpakResource::installPath() const
{
return installationPath() + QStringLiteral("/app/%1/%2/%3/active").arg(flatpakName()).arg(arch()).arg(branch());
return installationPath() + QStringLiteral("/app/%1/%2/%3/active").arg(flatpakName(), arch(), branch());
}
QUrl FlatpakResource::url() const
......
......@@ -156,7 +156,7 @@ public:
QString installPath() const;
Q_SIGNALS:
void propertyStateChanged(PropertyKind kind, PropertyState state);
void propertyStateChanged(FlatpakResource::PropertyKind kind, FlatpakResource::PropertyState state);
private:
void setArch(const QString &arch);
......
......@@ -100,7 +100,7 @@ bool FlatpakSourcesBackend::addSource(const QString &id)
if (res)
backend->installApplication(res);
else
backend->passiveMessage(i18n("Could not add the source %1", flatpakrepoUrl.toDisplayString()));
Q_EMIT backend->passiveMessage(i18n("Could not add the source %1", flatpakrepoUrl.toDisplayString()));
} else {
AbstractResourcesBackend::Filters filter;
filter.resourceUrl = flatpakrepoUrl;
......@@ -111,7 +111,7 @@ bool FlatpakSourcesBackend::addSource(const QString &id)
Q_ASSERT(res.count() == 1);
backend->installApplication(res.first());
} else {
backend->passiveMessage(i18n("Could not add the source %1", flatpakrepoUrl.toDisplayString()));
Q_EMIT backend->passiveMessage(i18n("Could not add the source %1", flatpakrepoUrl.toDisplayString()));
}
});
}
......@@ -247,7 +247,8 @@ void FlatpakSourcesBackend::addRemote(FlatpakRemote *remote, FlatpakInstallation
const QString title = QString::fromUtf8(flatpak_remote_get_title(remote));
const QUrl remoteUrl(QString::fromUtf8(flatpak_remote_get_url(remote)));
for(QAction *action: actions()) {
const auto theActions = actions();
for(QAction *action: theActions) {
if (action->toolTip() == id) {
action->setEnabled(false);
action->setVisible(false);
......
......@@ -54,7 +54,6 @@ class FwupdBackend : public AbstractResourcesBackend
{
Q_OBJECT
Q_PROPERTY(int startElements MEMBER m_startElements)
Q_ENUMS(Modes)
public:
explicit FwupdBackend(QObject* parent = nullptr);
~FwupdBackend();
......
......@@ -147,7 +147,6 @@ KNSBackend::KNSBackend(QObject* parent, const QString& iconName, const QString &
const QStringList cats = group.readEntry<QStringList>("Categories", QStringList{});
QVector<Category*> categories;
if (cats.count() > 1) {
QHash<QString, QVector<Category*> > subCategories;
m_categories += cats;
for(const auto &cat: cats)
categories << new Category(cat, {}, { {CategoryFilter, cat } }, backendName, {}, {}, true);
......@@ -375,7 +374,8 @@ public:
};
else
actionFunction = [res, engine]() {
for(auto i : res->linkIds())
const auto links = res->linkIds();
for(auto i : links)
engine->install(res->entry(), i);
};
QTimer::singleShot(0, res, actionFunction);
......
......@@ -245,7 +245,8 @@ QDate KNSResource::releaseDate() const
QVector<int> KNSResource::linkIds() const
{
QVector<int> ids;
for(const auto &e : m_entry.downloadLinkInformationList()) {
const auto linkInfo = m_entry.downloadLinkInformationList();
for(const auto &e : linkInfo) {
if (e.isDownloadtypeLink)
ids << e.id;
}
......
......@@ -65,7 +65,7 @@ QVector<AbstractResource*> KNSBackendTest::getResources(ResultsStream* stream, b
QVector<AbstractResource*> resources;
connect(stream, &ResultsStream::resourcesFound, this, [&resources, stream](const QVector<AbstractResource*>& res) {
resources += res;
stream->fetchMore();
Q_EMIT stream->fetchMore();
});
Q_ASSERT(spyResources.wait(10000));
Q_ASSERT(!resources.isEmpty() || canBeEmpty);
......
......@@ -231,7 +231,7 @@ void AppPackageKitResource::invokeApplication() const
return;
}
}
backend()->passiveMessage(i18n("Cannot launch %1", name()));
Q_EMIT backend()->passiveMessage(i18n("Cannot launch %1", name()));
}
});
}
......
......@@ -326,7 +326,8 @@ void PackageKitBackend::includePackagesToAdd()
auto res = m_packages.packages.take(pkg);
if (res) {
if (AppPackageKitResource* ares = qobject_cast<AppPackageKitResource*>(res)) {
for(const auto &ext: res->extends())
const auto extends = res->extends();
for(const auto &ext: extends)
m_packages.extendedBy[ext].removeAll(ares);
}
......@@ -502,7 +503,8 @@ int PackageKitBackend::updatesCount() const
int ret = 0;
QSet<QString> packages;
for(auto res: upgradeablePackages()) {
const auto toUpgrade = upgradeablePackages();
for(auto res: toUpgrade) {
const auto packageName = res->packageName();
if (packages.contains(packageName)) {
continue;
......
......@@ -256,7 +256,7 @@ static QStringList urlToLinks(const QStringList& urls)
return ret;
}
void PackageKitResource::updateDetail(const QString& packageID, const QStringList& updates, const QStringList& obsoletes, const QStringList& vendorUrls,
void PackageKitResource::updateDetail(const QString& packageID, const QStringList& /*updates*/, const QStringList& obsoletes, const QStringList& vendorUrls,
const QStringList& /*bugzillaUrls*/, const QStringList& /*cveUrls*/, PackageKit::Transaction::Restart restart, const QString &_updateText,
const QString& /*changelog*/, PackageKit::Transaction::UpdateState state, const QDateTime& /*issued*/, const QDateTime& /*updated*/)
{
......
......@@ -146,7 +146,7 @@ void SnapResource::gotIcon()
auto theIcon = QVariant::fromValue<QImage>(reader.read());
if (theIcon != m_icon) {
m_icon = theIcon;
iconChanged();
Q_EMIT iconChanged();
}
}
......@@ -279,7 +279,8 @@ public:
if (plug->interface() == QLatin1String("content"))
continue;
for (auto slot: slotsForInterface[plug->interface()]) {
const auto theSlots = slotsForInterface.value(plug->interface());
for (auto slot: theSlots) {
auto item = new QStandardItem;
if (plug->label().isEmpty())
item->setText(plug->name());
......@@ -320,7 +321,7 @@ private:
req->runSync();
if (req->error()) {
qWarning() << "snapd error" << req->errorString();
m_res->backend()->passiveMessage(req->errorString());
Q_EMIT m_res->backend()->passiveMessage(req->errorString());
}
return req->error() == QSnapdRequest::NoError;
}
......
......@@ -41,7 +41,7 @@ public:
}
public Q_SLOTS:
ActionReply login(const QVariantMap &args)
KAuth::ActionReply login(const QVariantMap &args)
{
const QString user = args[QStringLiteral("user")].toString()
, pass = args[QStringLiteral("password")].toString()
......
......@@ -39,7 +39,7 @@ public:
QString name() const { return m_name; }
QString description() const { return m_description; }
void trigger() { triggered(m_name); }
void trigger() { Q_EMIT triggered(m_name); }
Q_SIGNALS:
void triggered(const QString & name);
......
......@@ -44,7 +44,7 @@ void AbstractBackendUpdater::enableNeedsReboot()
return;
m_needsReboot = true;
needsRebootChanged();
Q_EMIT needsRebootChanged();
}
bool AbstractBackendUpdater::needsReboot() const
......
......@@ -198,7 +198,7 @@ class DISCOVERCOMMON_EXPORT AbstractBackendUpdater : public QObject
/**
* Provides the @p progress of a specific @p resource in a percentage.
*/
void resourceProgressed(AbstractResource* resource, qreal progress, State state);
void resourceProgressed(AbstractResource* resource, qreal progress, AbstractBackendUpdater::State state);
void passiveMessage(const QString &message);
......
......@@ -592,7 +592,7 @@ void ResourcesProxyModel::fetchMore(const QModelIndex& parent)
Q_ASSERT(!parent.isValid());
if (!m_currentStream)
return;
m_currentStream->fetchMore();
Q_EMIT m_currentStream->fetchMore();
}
bool ResourcesProxyModel::sortByRelevancy() const
......
......@@ -263,7 +263,8 @@ double StandardBackendUpdater::updateSize() const
quint64 StandardBackendUpdater::downloadSpeed() const
{
quint64 ret = 0;
for(Transaction* t: TransactionModel::global()->transactions()) {
const auto trans = TransactionModel::global()->transactions();
for(Transaction* t: trans) {
if (t->property("updater").value<QObject*>() == this)
ret += t->downloadSpeed();
}
......
Markdown is supported
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