Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 1c2edcd9 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Fix clazy warnings

parent fcc1bdf9
......@@ -80,7 +80,7 @@ class DiscoverObject : public QObject
void listMimeInternal(const QString& mime);
void listCategoryInternal(Category* cat);
void compactModeChanged(CompactMode compactMode);
void compactModeChanged(DiscoverObject::CompactMode compactMode);
void preventedClose();
void unableToFind(const QString &resid);
void openErrorPage(const QString &errorMessage);
......
......@@ -79,7 +79,7 @@ void processArgs(QCommandLineParser* parser, DiscoverObject* mainWindow)
if (url.isLocalFile())
mainWindow->openLocalPackage(url);
else if (url.scheme() == QLatin1String("apt") || url.scheme() == QLatin1String("snap"))
mainWindow->openSearch(url.host());
Q_EMIT mainWindow->openSearch(url.host());
else
mainWindow->openApplication(url);
}
......
......@@ -269,7 +269,7 @@ bool Category::contains(Category* cat) const
bool Category::contains(const QVariantList& cats) const
{
bool ret = false;
for(auto itCat : cats) {
for(const auto &itCat : cats) {
if (contains(qobject_cast<Category*>(itCat.value<QObject*>()))) {
ret = true;
break;
......
......@@ -43,6 +43,8 @@ class DISCOVERCOMMON_EXPORT AbstractReviewsBackend : public QObject
Q_SCRIPTABLE virtual Rating *ratingForApplication(AbstractResource *app) const = 0;
Q_INVOKABLE virtual QString errorMessage() const;
Q_INVOKABLE virtual bool isResourceSupported(AbstractResource *res) const = 0;
virtual bool isFetching() const = 0;
virtual bool isReviewable() const;
public Q_SLOTS:
virtual void login() = 0;
......@@ -53,9 +55,7 @@ class DISCOVERCOMMON_EXPORT AbstractReviewsBackend : public QObject
const QString& review_text, const QString& rating) = 0;
virtual void deleteReview(Review* r) = 0;
virtual void flagReview(Review* r, const QString& reason, const QString &text) = 0;
virtual bool isFetching() const = 0;
virtual void fetchReviews(AbstractResource* app, int page=1) = 0;
virtual bool isReviewable() const;
Q_SIGNALS:
void reviewsReady(AbstractResource *app, const QVector<ReviewPtr> &reviews, bool canFetchMore);
......
......@@ -45,6 +45,7 @@ void ScreenshotsModel::setResource(AbstractResource* res)
disconnect(m_resource, &AbstractResource::screenshotsFetched, this, &ScreenshotsModel::screenshotsFetched);
}
m_resource = res;
Q_EMIT resourceChanged(res);
if(res) {
connect(m_resource, &AbstractResource::screenshotsFetched, this, &ScreenshotsModel::screenshotsFetched);
......
......@@ -30,7 +30,7 @@ class AbstractResource;
class DISCOVERCOMMON_EXPORT ScreenshotsModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(AbstractResource* application READ resource WRITE setResource)
Q_PROPERTY(AbstractResource* application READ resource WRITE setResource NOTIFY resourceChanged)
Q_PROPERTY(int count READ count NOTIFY countChanged)
public:
enum Roles { ThumbnailUrl=Qt::UserRole+1, ScreenshotUrl };
......@@ -51,6 +51,7 @@ class DISCOVERCOMMON_EXPORT ScreenshotsModel : public QAbstractListModel
Q_SIGNALS:
void countChanged();
void resourceChanged(const AbstractResource* resource);
private:
AbstractResource* m_resource;
......
......@@ -97,7 +97,7 @@ void UpdateModel::activityChanged()
m_updates->prepare();
setResources(m_updates->toUpdate());
for(auto item : m_updateItems) {
for(auto item : qAsConst(m_updateItems)) {
item->setProgress(0);
}
} else
......@@ -314,9 +314,9 @@ void UpdateModel::resourceDataChanged(AbstractResource* res, const QVector<QByte
const auto index = indexFromItem(item);
if (properties.contains("state"))
dataChanged(index, index, {SizeRole, VersionRole});
Q_EMIT dataChanged(index, index, {SizeRole, VersionRole});
else if (properties.contains("size")) {
dataChanged(index, index, {SizeRole});
Q_EMIT dataChanged(index, index, {SizeRole});
m_updateSizeTimer->start();
}
}
......@@ -132,7 +132,7 @@ static QString userHash()
return QString();
}
QString salted = QStringLiteral("gnome-software[%1:%2]").arg(KUser().loginName()).arg(machineId);
QString salted = QStringLiteral("gnome-software[%1:%2]").arg(KUser().loginName(), machineId);
return QString::fromUtf8(QCryptographicHash::hash(salted.toUtf8(), QCryptographicHash::Sha1).toHex());
}
......
......@@ -60,7 +60,7 @@ void DummyReviewsBackend::initialize()
Rating* rating = new Rating(app->packageName(), ++i, {{QStringLiteral("star5"), randomRating}});
rating->setParent(this);
m_ratings.insert(app, rating);
app->ratingFetched();
Q_EMIT app->ratingFetched();
}
emit ratingsReady();
}
......
......@@ -125,7 +125,7 @@ KNSBackend::KNSBackend(QObject* parent, const QString& iconName, const QString &
this->setFetching(false);
qWarning() << "kns error" << objectName() << error;
if (!invalidFile)
passiveMessage(i18n("%1: %2", name(), error));
Q_EMIT passiveMessage(i18n("%1: %2", name(), error));
});
connect(m_engine, &KNSCore::Engine::signalEntriesLoaded, this, &KNSBackend::receivedEntries, Qt::QueuedConnection);
connect(m_engine, &KNSCore::Engine::signalEntryChanged, this, &KNSBackend::statusChanged, Qt::QueuedConnection);
......@@ -347,7 +347,7 @@ ResultsStream* KNSBackend::search(const AbstractResourcesBackend::Filters& filte
const auto ret = kFilter<QVector<AbstractResource*>>(m_resourcesByName, filterFunction);
if (!ret.isEmpty())
stream->resourcesFound(ret);
Q_EMIT stream->resourcesFound(ret);
}
stream->finish();
};
......@@ -402,7 +402,7 @@ ResultsStream * KNSBackend::findResourceByPackageName(const QUrl& search)
const auto pathParts = search.path().split(QLatin1Char('/'), QString::SkipEmptyParts);
if (pathParts.size() != 2) {
passiveMessage(i18n("Wrong KNewStuff URI: %1", search.toString()));
Q_EMIT passiveMessage(i18n("Wrong KNewStuff URI: %1", search.toString()));
return voidStream();
}
const auto providerid = pathParts.at(0);
......@@ -416,7 +416,7 @@ ResultsStream * KNSBackend::findResourceByPackageName(const QUrl& search)
connect(m_engine, &KNSCore::Engine::signalError, stream, &ResultsStream::finish);
connect(m_engine, &KNSCore::Engine::signalEntryDetailsLoaded, stream, [this, stream, entryid, providerid](const KNSCore::EntryInternal &entry) {
if (entry.uniqueId() == entryid && providerid == QUrl(entry.providerId()).host()) {
stream->resourcesFound({resourceForEntry(entry)});
Q_EMIT stream->resourcesFound({resourceForEntry(entry)});
} else
qWarning() << "found invalid" << entryid << entry.uniqueId() << providerid << QUrl(entry.providerId()).host();
m_responsePending = false;
......
......@@ -238,7 +238,7 @@ QDate KNSResource::releaseDate() const
QVector<int> KNSResource::linkIds() const
{
QVector<int> ids;
for(auto e : m_entry.downloadLinkInformationList()) {
for(const auto &e : m_entry.downloadLinkInformationList()) {
if (e.isDownloadtypeLink)
ids << e.id;
}
......
......@@ -165,7 +165,7 @@ void PKTransaction::cleanup(PackageKit::Transaction::Exit exit, uint runtime)
i.remove();
}
}
removedResources.subtract(m_apps.toList().toSet());
removedResources.subtract(kVectorToSet(m_apps));
if (!packagesToRemove.isEmpty() || !removedResources.isEmpty()) {
QString msg = QStringLiteral("<ul><li>") + PackageKitResource::joinPackages(packagesToRemove, QStringLiteral("</li><li>"));
......
......@@ -393,7 +393,7 @@ ResultsStream* PackageKitBackend::search(const AbstractResourcesBackend::Filters
if (!ids.isEmpty()) {
const auto resources = resourcesByPackageNames<QVector<AbstractResource*>>(ids);
QTimer::singleShot(0, this, [stream, resources] () {
stream->resourcesFound(resources);
Q_EMIT stream->resourcesFound(resources);
});
}
......@@ -408,7 +408,7 @@ ResultsStream* PackageKitBackend::search(const AbstractResourcesBackend::Filters
const auto packageId = stream->property("packageId");
if (!packageId.isNull()) {
const auto res = resourcesByPackageNames<QVector<AbstractResource*>>({PackageKit::Daemon::packageName(packageId.toString())});
stream->resourcesFound(kFilter<QVector<AbstractResource*>>(res, [ids](AbstractResource* res){ return !ids.contains(res->appstreamId()); }));
Q_EMIT stream->resourcesFound(kFilter<QVector<AbstractResource*>>(res, [ids](AbstractResource* res){ return !ids.contains(res->appstreamId()); }));
}
}
stream->finish();
......@@ -421,7 +421,7 @@ ResultsStream * PackageKitBackend::findResourceByPackageName(const QUrl& url)
{
AbstractResource* pkg = nullptr;
if (url.host().isEmpty())
passiveMessage(i18n("Malformed appstream url '%1'", url.toDisplayString()));
Q_EMIT passiveMessage(i18n("Malformed appstream url '%1'", url.toDisplayString()));
else if (url.scheme() == QLatin1String("appstream")) {
static const QMap<QString, QString> deprecatedAppstreamIds = {
{ QStringLiteral("org.kde.krita.desktop"), QStringLiteral("krita.desktop") },
......@@ -435,7 +435,7 @@ ResultsStream * PackageKitBackend::findResourceByPackageName(const QUrl& url)
const auto host = url.host();
if (host.isEmpty())
passiveMessage(i18n("Malformed appstream url '%1'", url.toDisplayString()));
Q_EMIT passiveMessage(i18n("Malformed appstream url '%1'", url.toDisplayString()));
else {
const auto deprecatedHost = deprecatedAppstreamIds.value(url.host()); //try this as fallback
for (auto it = m_packages.packages.constBegin(), itEnd = m_packages.packages.constEnd(); it != itEnd; ++it) {
......
......@@ -199,7 +199,7 @@ void PackageKitResource::setDetails(const PackageKit::Details & details)
emit stateChanged();
if (!backend()->isFetching())
backend()->resourcesChanged(this, {"size", "homepage", "license"});
Q_EMIT backend()->resourcesChanged(this, {"size", "homepage", "license"});
}
}
......
......@@ -32,7 +32,7 @@ int main(int argc, char** argv)
if (app.arguments().size() != 2)
return 1;
KService _service(app.arguments().last());
KService _service(app.arguments().constLast());
if (!_service.isValid())
return 2;
......
......@@ -127,7 +127,7 @@ ResultsStream* SnapBackend::populate(T* job)
m_resources[res->packageName()] = res;
if (!ret.isEmpty())
stream->resourcesFound(ret);
Q_EMIT stream->resourcesFound(ret);
stream->finish();
});
job->runAsync();
......@@ -181,7 +181,7 @@ void SnapBackend::refreshStates()
{
auto ret = new StoredResultsStream({populate(m_client.list())});
connect(ret, &StoredResultsStream::finished, this, [this, ret](){
for (auto res: m_resources) {
for (auto res: qAsConst(m_resources)) {
if (ret->resources().contains(res))
res->setState(AbstractResource::Installed);
else
......
......@@ -220,7 +220,8 @@ void ResourcesModel::registerAllBackends()
void ResourcesModel::registerBackendByName(const QString& name)
{
DiscoverBackendsFactory f;
for(auto b : f.backend(name))
const auto backends = f.backend(name);
for(auto b : backends)
addResourcesBackend(b);
emit backendsChanged();
......
......@@ -165,7 +165,7 @@ void ResourcesProxyModel::removeDuplicates(QVector<AbstractResource *>& resource
if ((*it)->backend() == cab) {
**at = *it;
auto pos = index(*at - m_displayedResources.begin(), 0);
dataChanged(pos, pos);
Q_EMIT dataChanged(pos, pos);
}
it = resources.erase(it);
}
......@@ -231,13 +231,13 @@ void ResourcesProxyModel::setFiltersFromCategory(Category *category)
void ResourcesProxyModel::fetchSubcategories()
{
auto cats = (m_filters.category ? m_filters.category->subCategories() : CategoryModel::global()->rootCategories()).toList().toSet();
auto cats = kVectorToSet(m_filters.category ? m_filters.category->subCategories() : CategoryModel::global()->rootCategories());
const int count = rowCount();
QSet<Category*> done;
for (int i=0; i<count && !cats.isEmpty(); ++i) {
AbstractResource* res = m_displayedResources[i];
const auto found = res->categoryObjects(cats.toList().toVector());
const auto found = res->categoryObjects(kSetToVector(cats));
done.unite(found);
cats.subtract(found);
}
......@@ -468,7 +468,7 @@ void ResourcesProxyModel::sortedInsertion(const QVector<AbstractResource*> & _re
return;
}
for(auto resource: resources) {
for(auto resource: qAsConst(resources)) {
const auto finder = [this](AbstractResource* resource, AbstractResource* res){ return lessThan(resource, res); };
const auto it = std::upper_bound(m_displayedResources.constBegin(), m_displayedResources.constEnd(), resource, finder);
const auto newIdx = it == m_displayedResources.constEnd() ? m_displayedResources.count() : (it - m_displayedResources.constBegin());
......
......@@ -73,6 +73,26 @@ static int kIndexOf(const Q& list, W func)
return -1;
}
template <typename T>
static QVector<T> kSetToVector(const QSet<T> & set)
{
QVector<T> ret;
ret.reserve(set.size());
for(auto &x: set)
ret.append(x);
return ret;
}
template <typename T>
static QSet<T> kVectorToSet(const QVector<T> & set)
{
QSet<T> ret;
ret.reserve(set.size());
for(auto &x: set)
ret.insert(x);
return ret;
}
class ElapsedDebug : private QElapsedTimer
{
public:
......
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