Commit 67357bfc authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Run clang-format

If you want git blame to ignore formatting revisions run:
git config blame.ignoreRevsFile .git-blame-ignore-revs
parent b8d35b0a
......@@ -6,31 +6,31 @@
#include "DiscoverDeclarativePlugin.h"
#include "ReadFile.h"
#include <Category/CategoryModel.h>
#include <ApplicationAddonsModel.h>
#include <Category/Category.h>
#include <Category/CategoryModel.h>
#include <QAction>
#include <QQmlContext>
#include <QQmlEngine>
#include <ReviewsBackend/AbstractReviewsBackend.h>
#include <ReviewsBackend/Rating.h>
#include <ReviewsBackend/ReviewsModel.h>
#include <ScreenshotsModel.h>
#include <Transaction/Transaction.h>
#include <Transaction/TransactionListener.h>
#include <Transaction/TransactionModel.h>
#include <Transaction/Transaction.h>
#include <resources/DiscoverAction.h>
#include <resources/ResourcesUpdatesModel.h>
#include <UpdateModel/UpdateModel.h>
#include <qqml.h>
#include <resources/AbstractBackendUpdater.h>
#include <resources/AbstractResource.h>
#include <resources/ResourcesModel.h>
#include <resources/SourcesModel.h>
#include <resources/AbstractSourcesBackend.h>
#include <resources/AbstractBackendUpdater.h>
#include <resources/DiscoverAction.h>
#include <resources/ResourcesModel.h>
#include <resources/ResourcesProxyModel.h>
#include <ReviewsBackend/Rating.h>
#include <ReviewsBackend/AbstractReviewsBackend.h>
#include <ReviewsBackend/ReviewsModel.h>
#include <UpdateModel/UpdateModel.h>
#include <ScreenshotsModel.h>
#include <ApplicationAddonsModel.h>
#include <qqml.h>
#include <QQmlEngine>
#include <QQmlContext>
#include <QAction>
#include <resources/ResourcesUpdatesModel.h>
#include <resources/SourcesModel.h>
void DiscoverDeclarativePlugin::initializeEngine(QQmlEngine* engine, const char* uri)
void DiscoverDeclarativePlugin::initializeEngine(QQmlEngine *engine, const char *uri)
{
engine->rootContext()->setContextProperty(QStringLiteral("ResourcesModel"), ResourcesModel::global());
engine->rootContext()->setContextProperty(QStringLiteral("TransactionModel"), TransactionModel::global());
......@@ -39,7 +39,7 @@ void DiscoverDeclarativePlugin::initializeEngine(QQmlEngine* engine, const char*
QQmlExtensionPlugin::initializeEngine(engine, uri);
}
void DiscoverDeclarativePlugin::registerTypes(const char* /*uri*/)
void DiscoverDeclarativePlugin::registerTypes(const char * /*uri*/)
{
qmlRegisterType<TransactionListener>("org.kde.discover", 2, 0, "TransactionListener");
qmlRegisterType<ResourcesUpdatesModel>("org.kde.discover", 2, 0, "ResourcesUpdatesModel");
......@@ -65,5 +65,5 @@ void DiscoverDeclarativePlugin::registerTypes(const char* /*uri*/)
qmlRegisterAnonymousType<Category>("org.kde.discover", 1);
qmlRegisterAnonymousType<ResourcesModel>("org.kde.discover", 1);
qmlProtectModule("org.kde.discover", 2);
qRegisterMetaType<QList<QAction*>>();
qRegisterMetaType<QList<QAction *>>();
}
......@@ -13,9 +13,9 @@ class DiscoverDeclarativePlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
public:
void initializeEngine(QQmlEngine* engine, const char* uri) override;
void registerTypes(const char* uri) override;
public:
void initializeEngine(QQmlEngine *engine, const char *uri) override;
void registerTypes(const char *uri) override;
};
#endif
This diff is collapsed.
......@@ -24,72 +24,78 @@ class DiscoverObject : public QObject
Q_PROPERTY(bool isRoot READ isRoot CONSTANT)
Q_PROPERTY(QRect initialGeometry READ initialGeometry CONSTANT)
public:
enum CompactMode {
Auto,
Compact,
Full,
};
Q_ENUM(CompactMode)
explicit DiscoverObject(CompactMode mode, const QVariantMap &initialProperties);
~DiscoverObject() override;
QStringList modes() const;
void setupActions();
CompactMode compactMode() const { return m_mode; }
void setCompactMode(CompactMode mode);
bool eventFilter(QObject * object, QEvent * event) override;
Q_SCRIPTABLE QAction * action(const QString& name) const;
Q_SCRIPTABLE static QString iconName(const QIcon& icon);
void loadTest(const QUrl& url);
static bool isRoot();
QQuickWindow* rootObject() const;
void showPassiveNotification(const QString &msg);
QRect initialGeometry() const;
QString describeSources() const;
public Q_SLOTS:
void openApplication(const QUrl& app);
void openMimeType(const QString& mime);
void openCategory(const QString& category);
void openMode(const QString& mode);
void openLocalPackage(const QUrl &localfile);
void reboot();
private Q_SLOTS:
void reportBug();
void switchApplicationLanguage();
void aboutApplication();
Q_SIGNALS:
void openSearch(const QString &search);
void openApplicationInternal(AbstractResource* app);
void listMimeInternal(const QString& mime);
void listCategoryInternal(Category* cat);
void compactModeChanged(DiscoverObject::CompactMode compactMode);
void preventedClose();
void unableToFind(const QString &resid);
void openErrorPage(const QString &errorMessage);
private:
void showLoadingPage();
void integrateObject(QObject* object);
QQmlApplicationEngine* engine() const { return m_engine; }
QMap<QString, QAction*> m_collection;
QQmlApplicationEngine * const m_engine;
CompactMode m_mode;
QScopedPointer<CachedNetworkAccessManagerFactory> m_networkAccessManagerFactory;
public:
enum CompactMode {
Auto,
Compact,
Full,
};
Q_ENUM(CompactMode)
explicit DiscoverObject(CompactMode mode, const QVariantMap &initialProperties);
~DiscoverObject() override;
QStringList modes() const;
void setupActions();
CompactMode compactMode() const
{
return m_mode;
}
void setCompactMode(CompactMode mode);
bool eventFilter(QObject *object, QEvent *event) override;
Q_SCRIPTABLE QAction *action(const QString &name) const;
Q_SCRIPTABLE static QString iconName(const QIcon &icon);
void loadTest(const QUrl &url);
static bool isRoot();
QQuickWindow *rootObject() const;
void showPassiveNotification(const QString &msg);
QRect initialGeometry() const;
QString describeSources() const;
public Q_SLOTS:
void openApplication(const QUrl &app);
void openMimeType(const QString &mime);
void openCategory(const QString &category);
void openMode(const QString &mode);
void openLocalPackage(const QUrl &localfile);
void reboot();
private Q_SLOTS:
void reportBug();
void switchApplicationLanguage();
void aboutApplication();
Q_SIGNALS:
void openSearch(const QString &search);
void openApplicationInternal(AbstractResource *app);
void listMimeInternal(const QString &mime);
void listCategoryInternal(Category *cat);
void compactModeChanged(DiscoverObject::CompactMode compactMode);
void preventedClose();
void unableToFind(const QString &resid);
void openErrorPage(const QString &errorMessage);
private:
void showLoadingPage();
void integrateObject(QObject *object);
QQmlApplicationEngine *engine() const
{
return m_engine;
}
QMap<QString, QAction *> m_collection;
QQmlApplicationEngine *const m_engine;
CompactMode m_mode;
QScopedPointer<CachedNetworkAccessManagerFactory> m_networkAccessManagerFactory;
};
#endif // DISCOVEROBJECT_H
......@@ -7,17 +7,17 @@
#include "FeaturedModel.h"
#include "discover_debug.h"
#include <QStandardPaths>
#include <KIO/StoredTransferJob>
#include <QDir>
#include <QFile>
#include <QJsonDocument>
#include <QJsonArray>
#include <QDir>
#include <QJsonDocument>
#include <QStandardPaths>
#include <QtGlobal>
#include <KIO/StoredTransferJob>
#include <utils.h>
#include <resources/ResourcesModel.h>
#include <resources/StoredResultsStream.h>
#include <utils.h>
Q_GLOBAL_STATIC(QString, featuredCache)
......@@ -76,12 +76,14 @@ void FeaturedModel::refreshCurrentApplicationBackend()
void FeaturedModel::refresh()
{
//usually only useful if launching just fwupd or kns backends
// usually only useful if launching just fwupd or kns backends
if (!m_backend)
return;
acquireFetching(true);
const auto dest = qScopeGuard([this] { acquireFetching(false); });
const auto dest = qScopeGuard([this] {
acquireFetching(false);
});
QFile f(*featuredCache);
if (!f.open(QIODevice::ReadOnly)) {
qCWarning(DISCOVER_LOG) << "couldn't open file" << *featuredCache << f.errorString();
......@@ -94,17 +96,19 @@ void FeaturedModel::refresh()
return;
}
const auto uris = kTransform<QVector<QUrl>>(array, [](const QJsonValue& uri) { return QUrl(uri.toString()); });
const auto uris = kTransform<QVector<QUrl>>(array, [](const QJsonValue &uri) {
return QUrl(uri.toString());
});
setUris(uris);
}
void FeaturedModel::setUris(const QVector<QUrl>& uris)
void FeaturedModel::setUris(const QVector<QUrl> &uris)
{
if (!m_backend)
return;
QSet<ResultsStream*> streams;
foreach(const auto &uri, uris) {
QSet<ResultsStream *> streams;
foreach (const auto &uri, uris) {
AbstractResourcesBackend::Filters filter;
filter.resourceUrl = uri;
streams << m_backend->search(filter);
......@@ -119,7 +123,7 @@ void FeaturedModel::setUris(const QVector<QUrl>& uris)
static void filterDupes(QVector<AbstractResource *> &resources)
{
QSet<QString> found;
for(auto it = resources.begin(); it!=resources.end(); ) {
for (auto it = resources.begin(); it != resources.end();) {
auto id = (*it)->appstreamId();
if (found.contains(id)) {
it = resources.erase(it);
......@@ -137,19 +141,19 @@ void FeaturedModel::acquireFetching(bool f)
else
m_isFetching--;
if ((!f && m_isFetching==0) || (f && m_isFetching==1)) {
if ((!f && m_isFetching == 0) || (f && m_isFetching == 1)) {
emit isFetchingChanged();
}
Q_ASSERT(m_isFetching>=0);
Q_ASSERT(m_isFetching >= 0);
}
void FeaturedModel::setResources(const QVector<AbstractResource *>& _resources)
void FeaturedModel::setResources(const QVector<AbstractResource *> &_resources)
{
auto resources = _resources;
filterDupes(resources);
if (m_resources != resources) {
//TODO: sort like in the json files
// TODO: sort like in the json files
beginResetModel();
m_resources = resources;
endResetModel();
......@@ -158,10 +162,10 @@ void FeaturedModel::setResources(const QVector<AbstractResource *>& _resources)
acquireFetching(false);
}
void FeaturedModel::removeResource(AbstractResource* resource)
void FeaturedModel::removeResource(AbstractResource *resource)
{
int index = m_resources.indexOf(resource);
if (index<0)
if (index < 0)
return;
beginRemoveRows({}, index, index);
......@@ -169,19 +173,19 @@ void FeaturedModel::removeResource(AbstractResource* resource)
endRemoveRows();
}
QVariant FeaturedModel::data(const QModelIndex& index, int role) const
QVariant FeaturedModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || role!=Qt::UserRole)
if (!index.isValid() || role != Qt::UserRole)
return {};
auto res = m_resources.value(index.row());
if (!res)
return {};
return QVariant::fromValue<QObject*>(res);
return QVariant::fromValue<QObject *>(res);
}
int FeaturedModel::rowCount(const QModelIndex& parent) const
int FeaturedModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : m_resources.count();
}
......
......@@ -10,7 +10,10 @@
#include <QAbstractListModel>
#include <QPointer>
namespace KIO { class StoredTransferJob; }
namespace KIO
{
class StoredTransferJob;
}
class AbstractResource;
class AbstractResourcesBackend;
......@@ -18,31 +21,36 @@ class FeaturedModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(bool isFetching READ isFetching NOTIFY isFetchingChanged)
public:
FeaturedModel();
~FeaturedModel() override {}
void setResources(const QVector<AbstractResource*>& resources);
QVariant data(const QModelIndex & index, int role) const override;
int rowCount(const QModelIndex & parent) const override;
QHash<int, QByteArray> roleNames() const override;
bool isFetching() const { return m_isFetching != 0; }
Q_SIGNALS:
void isFetchingChanged();
private:
void refreshCurrentApplicationBackend();
void setUris(const QVector<QUrl> &uris);
void refresh();
void removeResource(AbstractResource* resource);
void acquireFetching(bool f);
QVector<AbstractResource*> m_resources;
int m_isFetching = 0;
AbstractResourcesBackend* m_backend = nullptr;
public:
FeaturedModel();
~FeaturedModel() override
{
}
void setResources(const QVector<AbstractResource *> &resources);
QVariant data(const QModelIndex &index, int role) const override;
int rowCount(const QModelIndex &parent) const override;
QHash<int, QByteArray> roleNames() const override;
bool isFetching() const
{
return m_isFetching != 0;
}
Q_SIGNALS:
void isFetchingChanged();
private:
void refreshCurrentApplicationBackend();
void setUris(const QVector<QUrl> &uris);
void refresh();
void removeResource(AbstractResource *resource);
void acquireFetching(bool f);
QVector<AbstractResource *> m_resources;
int m_isFetching = 0;
AbstractResourcesBackend *m_backend = nullptr;
};
#endif // FEATUREDMODEL_H
......@@ -5,19 +5,19 @@
*/
#include "PaginateModel.h"
#include <QtMath>
#include "discover_debug.h"
#include <QtMath>
class PaginateModel::PaginateModelPrivate
{
public:
int m_firstItem = 0;
int m_pageSize = 0;
QAbstractItemModel* m_sourceModel = nullptr;
QAbstractItemModel *m_sourceModel = nullptr;
bool m_hasStaticRowCount = false;
};
PaginateModel::PaginateModel(QObject* object)
PaginateModel::PaginateModel(QObject *object)
: QAbstractListModel(object)
, d(new PaginateModelPrivate)
{
......@@ -52,9 +52,9 @@ void PaginateModel::setPageSize(int count)
const int oldSize = rowsByPageSize(d->m_pageSize);
const int newSize = rowsByPageSize(count);
const int difference = newSize - oldSize;
if (difference==0) {
if (difference == 0) {
d->m_pageSize = count;
} else if (difference>0) {
} else if (difference > 0) {
beginInsertRows(QModelIndex(), d->m_pageSize, d->m_pageSize + difference - 1);
d->m_pageSize = count;
endInsertRows();
......@@ -67,12 +67,12 @@ void PaginateModel::setPageSize(int count)
}
}
QAbstractItemModel* PaginateModel::sourceModel() const
QAbstractItemModel *PaginateModel::sourceModel() const
{
return d->m_sourceModel;
}
void PaginateModel::setSourceModel(QAbstractItemModel* model)
void PaginateModel::setSourceModel(QAbstractItemModel *model)
{
if (d->m_sourceModel) {
disconnect(d->m_sourceModel, nullptr, this, nullptr);
......@@ -111,31 +111,29 @@ void PaginateModel::setSourceModel(QAbstractItemModel* model)
}
}
QHash< int, QByteArray > PaginateModel::roleNames() const
QHash<int, QByteArray> PaginateModel::roleNames() const
{
return d->m_sourceModel ? d->m_sourceModel->roleNames() : QAbstractItemModel::roleNames();
}
int PaginateModel::rowsByPageSize(int size) const
{
return d->m_hasStaticRowCount ? size
: !d->m_sourceModel ? 0
: qMin(d->m_sourceModel->rowCount() - d->m_firstItem, size);
return d->m_hasStaticRowCount ? size : !d->m_sourceModel ? 0 : qMin(d->m_sourceModel->rowCount() - d->m_firstItem, size);
}
int PaginateModel::rowCount(const QModelIndex& parent) const
int PaginateModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : rowsByPageSize(d->m_pageSize);
}
QModelIndex PaginateModel::mapToSource(const QModelIndex& idx) const
QModelIndex PaginateModel::mapToSource(const QModelIndex &idx) const
{
if (!d->m_sourceModel)
return QModelIndex();
return d->m_sourceModel->index(idx.row() + d->m_firstItem, idx.column());
}
QModelIndex PaginateModel::mapFromSource(const QModelIndex& idx) const
QModelIndex PaginateModel::mapFromSource(const QModelIndex &idx) const
{
Q_ASSERT(idx.model() == d->m_sourceModel);
if (!d->m_sourceModel)
......@@ -143,7 +141,7 @@ QModelIndex PaginateModel::mapFromSource(const QModelIndex& idx) const
return index(idx.row() - d->m_firstItem, idx.column());
}
QVariant PaginateModel::data(const QModelIndex& index, int role) const
QVariant PaginateModel::data(const QModelIndex &index, int role) const
{
if (!d->m_sourceModel)
return QVariant();
......@@ -205,16 +203,16 @@ void PaginateModel::setStaticRowCount(bool src)
//////////////////////////////
void PaginateModel::_k_sourceColumnsAboutToBeInserted(const QModelIndex& parent, int start, int end)
void PaginateModel::_k_sourceColumnsAboutToBeInserted(const QModelIndex &parent, int start, int end)
{
Q_UNUSED(end)
if (parent.isValid() || start!=0) {
if (parent.isValid() || start != 0) {
return;
}
beginResetModel();
}
void PaginateModel::_k_sourceColumnsAboutToBeMoved(const QModelIndex& sourceParent, int sourceStart, int sourceEnd, const QModelIndex& destParent, int dest)
void PaginateModel::_k_sourceColumnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
{
Q_UNUSED(sourceParent)
Q_UNUSED(sourceStart)
......@@ -224,25 +222,25 @@ void PaginateModel::_k_sourceColumnsAboutToBeMoved(const QModelIndex& sourcePare
beginResetModel();
}
void PaginateModel::_k_sourceColumnsAboutToBeRemoved(const QModelIndex& parent, int start, int end)
void PaginateModel::_k_sourceColumnsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
{
Q_UNUSED(end)
if (parent.isValid() || start!=0) {
if (parent.isValid() || start != 0) {
return;
}
beginResetModel();
}
void PaginateModel::_k_sourceColumnsInserted(const QModelIndex& parent, int start, int end)
void PaginateModel::_k_sourceColumnsInserted(const QModelIndex &parent, int start, int end)
{
Q_UNUSED(end)
if (parent.isValid() || start!=0) {
if (parent.isValid() || start != 0) {
return;
}
endResetModel();
}
void PaginateModel::_k_sourceColumnsMoved(const QModelIndex& sourceParent, int sourceStart, int sourceEnd, const QModelIndex& destParent, int dest)
void PaginateModel::_k_sourceColumnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destParent, int dest)
{
Q_UNUSED(sourceParent)
Q_UNUSED(sourceStart)
......@@ -252,18 +250,18 @@ void PaginateModel::_k_sourceColumnsMoved(const QModelIndex& sourceParent, int s
endResetModel();
}
void PaginateModel::_k_sourceColumnsRemoved(const QModelIndex& parent, int start, int end)
void PaginateModel::_k_sourceColumnsRemoved(const QModelIndex &parent, int start, int end)
{
Q_UNUSED(end)
if (parent.isValid() || start!=0) {
if (parent.isValid() || start != 0) {
return;
}
endResetModel();
}
void PaginateModel::_k_sourceDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int> &roles)
void PaginateModel::_k_sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
{
if (topLeft.parent().isValid() || bottomRight.row() < d->m_firstItem || topLeft.row()>lastItem()) {
if (topLeft.parent().isValid() || bottomRight.row() < d->m_firstItem || topLeft.row() > lastItem()) {
return;
}
......@@ -272,7 +270,7 @@ void PaginateModel::_k_sourceDataChanged(const QModelIndex& topLeft, const QMode
if (!idxTop.isValid())
idxTop = index(0);
if (!idxBottom.isValid())
idxBottom = index(rowCount()-1);
idxBottom = index(rowCount() - 1);
emit dataChanged(idxTop, idxBottom, roles);
}
......@@ -294,17 +292,17 @@ void PaginateModel::_k_sourceModelReset()
endResetModel();
}
bool PaginateModel::isIntervalValid(const QModelIndex& parent, int start, int /*end*/) const