Commit 91f453e0 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

List addons in a separate section

They're not really technical elements also not applications.

CCBUG: 398078
parent c087ee92
......@@ -36,13 +36,6 @@ public:
~UpdateItem();
enum Section {
ApplicationSection,
SystemSection
};
void setSection(const Section &section) { m_section = section; }
Section section() const { return m_section; }
void setProgress(qreal progress);
qreal progress() const;
......@@ -65,7 +58,6 @@ private:
const QIcon m_categoryIcon;
qreal m_progress;
QString m_changelog;
Section m_section;
};
#endif // UPDATEITEM_H
......@@ -137,14 +137,16 @@ QVariant UpdateModel::data(const QModelIndex &index, int role) const
case SectionRole: {
static const QString appUpdatesSection = i18nc("@item:inlistbox", "Application Updates");
static const QString systemUpdateSection = i18nc("@item:inlistbox", "System Updates");
switch(item->section()) {
case UpdateItem::ApplicationSection: return appUpdatesSection;
case UpdateItem::SystemSection: return systemUpdateSection;
static const QString addonsSection = i18nc("@item:inlistbox", "Addons");
switch(item->resource()->type()) {
case AbstractResource::Application: return appUpdatesSection;
case AbstractResource::Technical: return systemUpdateSection;
case AbstractResource::Addon: return addonsSection;
}
return {};
Q_UNREACHABLE();
}
case SectionResourceProgressRole:
return (100-item->progress()) + (101 * item->section());
return (100-item->progress()) + (101 * item->resource()->type());
default:
break;
}
......@@ -229,24 +231,29 @@ void UpdateModel::setResources(const QList<AbstractResource*>& resources)
qDeleteAll(m_updateItems);
m_updateItems.clear();
QVector<UpdateItem*> appItems, systemItems;
QVector<UpdateItem*> appItems, systemItems, addonItems;
foreach(AbstractResource* res, resources) {
connect(res, &AbstractResource::changelogFetched, this, &UpdateModel::integrateChangelog, Qt::UniqueConnection);
UpdateItem *updateItem = new UpdateItem(res);
if(!res->isTechnical()) {
updateItem->setSection(UpdateItem::ApplicationSection);
appItems += updateItem;
} else {
updateItem->setSection(UpdateItem::SystemSection);
systemItems += updateItem;
switch(res->type()) {
case AbstractResource::Technical:
systemItems += updateItem;
break;
case AbstractResource::Application:
appItems += updateItem;
break;
case AbstractResource::Addon:
addonItems += updateItem;
break;
}
}
const auto sortUpdateItems = [](UpdateItem *a, UpdateItem *b) { return a->name() < b->name(); };
qSort(appItems.begin(), appItems.end(), sortUpdateItems);
qSort(systemItems.begin(), systemItems.end(), sortUpdateItems);
m_updateItems = (QVector<UpdateItem*>() << appItems << systemItems);
qSort(addonItems.begin(), addonItems.end(), sortUpdateItems);
m_updateItems = (QVector<UpdateItem*>() << appItems << addonItems << systemItems);
endResetModel();
Q_EMIT hasUpdatesChanged(!resources.isEmpty());
......
......@@ -62,16 +62,25 @@ void DummyBackend::populate(const QString& n)
const int start = m_resources.count();
for(int i=start; i<start+m_startElements; i++) {
const QString name = n+QLatin1Char(' ')+QString::number(i);
DummyResource* res = new DummyResource(name, false, this);
DummyResource* res = new DummyResource(name, AbstractResource::Application, this);
res->setSize(100+(m_startElements-i));
res->setState(AbstractResource::State(1+(i%3)));
m_resources.insert(name.toLower(), res);
connect(res, &DummyResource::stateChanged, this, &DummyBackend::updatesCountChanged);
}
for(int i=start; i<start+m_startElements; i++) {
const QString name = QStringLiteral("addon")+QString::number(i);
DummyResource* res = new DummyResource(name, AbstractResource::Addon, this);
res->setState(AbstractResource::State(1+(i%3)));
res->setSize(300+(m_startElements-i));
m_resources.insert(name, res);
connect(res, &DummyResource::stateChanged, this, &DummyBackend::updatesCountChanged);
}
for(int i=start; i<start+m_startElements; i++) {
const QString name = QStringLiteral("techie")+QString::number(i);
DummyResource* res = new DummyResource(name, true, this);
DummyResource* res = new DummyResource(name, AbstractResource::Technical, this);
res->setState(AbstractResource::State(1+(i%3)));
res->setSize(300+(m_startElements-i));
m_resources.insert(name, res);
......@@ -99,7 +108,7 @@ ResultsStream* DummyBackend::search(const AbstractResourcesBackend::Filters& fil
if (!filter.resourceUrl.isEmpty())
return findResourceByPackageName(filter.resourceUrl);
else foreach(AbstractResource* r, m_resources) {
if (r->isTechnical() && filter.state != AbstractResource::Upgradeable) {
if (r->type() == AbstractResource::Technical && filter.state != AbstractResource::Upgradeable) {
continue;
}
......@@ -158,7 +167,7 @@ void DummyBackend::checkForUpdates()
AbstractResource * DummyBackend::resourceForFile(const QUrl& path)
{
DummyResource* res = new DummyResource(path.fileName(), true, this);
DummyResource* res = new DummyResource(path.fileName(), AbstractResource::Technical, this);
res->setSize(666);
res->setState(AbstractResource::None);
m_resources.insert(res->packageName(), res);
......
......@@ -27,13 +27,13 @@
Q_GLOBAL_STATIC_WITH_ARGS(QVector<QString>, s_icons, ({ QLatin1String("kdevelop"), QLatin1String("kalgebra"), QLatin1String("kmail"), QLatin1String("akregator"), QLatin1String("korganizer") }))
DummyResource::DummyResource(QString name, bool isTechnical, AbstractResourcesBackend* parent)
DummyResource::DummyResource(QString name, AbstractResource::Type type, AbstractResourcesBackend* parent)
: AbstractResource(parent)
, m_name(std::move(name))
, m_state(State::Broken)
, m_iconName((*s_icons)[KRandom::random() % s_icons->size()])
, m_addons({ PackageState(QStringLiteral("a"), QStringLiteral("aaaaaa"), false), PackageState(QStringLiteral("b"), QStringLiteral("aaaaaa"), false), PackageState(QStringLiteral("c"), QStringLiteral("aaaaaa"), false)})
, m_isTechnical(isTechnical)
, m_type(type)
{
const int nofScreenshots = KRandom::random() % 5;
m_screenshots = QList<QUrl>{
......@@ -93,7 +93,8 @@ QUrl DummyResource::donationURL()
QVariant DummyResource::icon() const
{
return isTechnical() ? QStringLiteral("kalarm") : m_iconName;
static const QVector<QVariant> icons = { QStringLiteral("device-notifier"), QStringLiteral("media-floppy"), QStringLiteral("drink-beer") };
return icons[type()];
}
QString DummyResource::installedVersion() const
......
......@@ -28,7 +28,7 @@ class DummyResource : public AbstractResource
{
Q_OBJECT
public:
explicit DummyResource(QString name, bool isTechnical, AbstractResourcesBackend* parent);
explicit DummyResource(QString name, AbstractResource::Type type, AbstractResourcesBackend* parent);
QList<PackageState> addonsInformation() override;
QString section() override;
......@@ -48,7 +48,7 @@ public:
QString comment() override;
QString name() const override;
QString packageName() const override;
bool isTechnical() const override { return m_isTechnical; }
AbstractResource::Type type() const override { return m_type; }
bool canExecute() const override { return true; }
void invokeApplication() const override;
void fetchChangelog() override;
......@@ -63,13 +63,13 @@ public:
QDate releaseDate() const override { return {}; }
public:
QString m_name;
const QString m_name;
AbstractResource::State m_state;
QList<QUrl> m_screenshots;
QList<QUrl> m_screenshotThumbnails;
QString m_iconName;
QList<PackageState> m_addons;
bool m_isTechnical;
const AbstractResource::Type m_type;
int m_size;
};
......
......@@ -206,7 +206,7 @@ FlatpakInstalledRef * FlatpakBackend::getInstalledRefForApp(FlatpakInstallation
return ref;
}
const auto type = resource->type() == FlatpakResource::DesktopApp ? FLATPAK_REF_KIND_APP : FLATPAK_REF_KIND_RUNTIME;
const auto type = resource->resourceType() == FlatpakResource::DesktopApp ? FLATPAK_REF_KIND_APP : FLATPAK_REF_KIND_RUNTIME;
return flatpak_installation_get_installed_ref(flatpakInstallation,
type,
......@@ -891,7 +891,7 @@ bool FlatpakBackend::updateAppMetadata(FlatpakInstallation* flatpakInstallation,
{
g_autoptr(GFile) installationPath = nullptr;
if (resource->type() != FlatpakResource::DesktopApp) {
if (resource->resourceType() != FlatpakResource::DesktopApp) {
return true;
}
......@@ -979,7 +979,7 @@ bool FlatpakBackend::updateAppSize(FlatpakInstallation *flatpakInstallation, Fla
bool FlatpakBackend::updateAppSizeFromRemote(FlatpakInstallation *flatpakInstallation, FlatpakResource *resource)
{
// Calculate the runtime size
if (resource->state() == AbstractResource::None && resource->type() == FlatpakResource::DesktopApp) {
if (resource->state() == AbstractResource::None && resource->resourceType() == FlatpakResource::DesktopApp) {
auto runtime = getRuntimeForApp(resource);
if (runtime) {
// Re-check runtime state if case a new one was created
......@@ -1031,7 +1031,7 @@ bool FlatpakBackend::updateAppSizeFromRemote(FlatpakInstallation *flatpakInstall
void FlatpakBackend::onFetchSizeFinished(FlatpakResource *resource, guint64 downloadSize, guint64 installedSize)
{
FlatpakResource *runtime = nullptr;
if (resource->state() == AbstractResource::None && resource->type() == FlatpakResource::DesktopApp) {
if (resource->state() == AbstractResource::None && resource->resourceType() == FlatpakResource::DesktopApp) {
runtime = getRuntimeForApp(resource);
}
......@@ -1108,7 +1108,7 @@ ResultsStream * FlatpakBackend::search(const AbstractResourcesBackend::Filters &
auto f = [this, stream, filter] () {
QVector<AbstractResource*> ret;
foreach(AbstractResource* r, m_resources) {
if (r->isTechnical() && filter.state != AbstractResource::Upgradeable) {
if (r->type() == AbstractResource::Technical && filter.state != AbstractResource::Upgradeable) {
continue;
}
......@@ -1186,7 +1186,7 @@ Transaction* FlatpakBackend::installApplication(AbstractResource *app, const Add
FlatpakResource *resource = qobject_cast<FlatpakResource*>(app);
if (resource->type() == FlatpakResource::Source) {
if (resource->resourceType() == FlatpakResource::Source) {
// Let source backend handle this
FlatpakRemote *remote = m_sources->installSource(resource);
if (remote) {
......@@ -1202,7 +1202,7 @@ Transaction* FlatpakBackend::installApplication(AbstractResource *app, const Add
FlatpakJobTransaction *transaction = nullptr;
FlatpakInstallation *installation = resource->installation();
if (resource->propertyState(FlatpakResource::RequiredRuntime) == FlatpakResource::NotKnownYet && resource->type() == FlatpakResource::DesktopApp) {
if (resource->propertyState(FlatpakResource::RequiredRuntime) == FlatpakResource::NotKnownYet && resource->resourceType() == FlatpakResource::DesktopApp) {
transaction = new FlatpakJobTransaction(resource, Transaction::InstallRole, true);
connect(resource, &FlatpakResource::propertyStateChanged, [resource, transaction, this] (FlatpakResource::PropertyKind kind, FlatpakResource::PropertyState state) {
if (kind != FlatpakResource::RequiredRuntime) {
......@@ -1243,7 +1243,7 @@ Transaction* FlatpakBackend::removeApplication(AbstractResource *app)
{
FlatpakResource *resource = qobject_cast<FlatpakResource*>(app);
if (resource->type() == FlatpakResource::Source) {
if (resource->resourceType() == FlatpakResource::Source) {
// Let source backend handle this
if (m_sources->removeSource(resource->flatpakName())) {
resource->setState(AbstractResource::None);
......
......@@ -237,9 +237,9 @@ int FlatpakResource::installedSize() const
return m_installedSize;
}
bool FlatpakResource::isTechnical() const
AbstractResource::Type FlatpakResource::type() const
{
return m_id.type == FlatpakResource::Runtime;
return m_id.type == FlatpakResource::Runtime ? Technical : Application;
}
QUrl FlatpakResource::homepage()
......@@ -368,7 +368,7 @@ AbstractResource::State FlatpakResource::state()
return m_state;
}
FlatpakResource::ResourceType FlatpakResource::type() const
FlatpakResource::ResourceType FlatpakResource::resourceType() const
{
return m_id.type;
}
......
......@@ -100,7 +100,7 @@ public:
QVariant icon() const override;
QString installedVersion() const override;
int installedSize() const;
bool isTechnical() const override;
AbstractResource::Type type() const override;
QUrl homepage() override;
QUrl helpURL() override;
QUrl bugURL() override;
......@@ -119,7 +119,7 @@ public:
int size() override;
QString sizeDescription() override;
AbstractResource::State state() override;
ResourceType type() const;
ResourceType resourceType() const;
QString typeAsString() const;
FlatpakResource::Id uniqueId() const;
QUrl url() const override;
......
......@@ -64,7 +64,7 @@ void FlatpakTransactionThread::run()
g_autoptr(FlatpakInstalledRef) ref = nullptr;
const QString refName = m_relatedRef.isEmpty() ? m_app->flatpakName() : m_relatedRef;
const uint kind = m_relatedRef.isEmpty() ? (uint)m_app->type() : m_relatedRefKind;
const uint kind = m_relatedRef.isEmpty() ? (uint)m_app->resourceType() : m_relatedRefKind;
if (m_role == Transaction::Role::InstallRole) {
bool installRelatedRef = false;
......
......@@ -53,7 +53,7 @@ public:
QString name() const override;
QString packageName() const override;
QString vendor() const;
bool isTechnical() const override { return true; }
AbstractResource::Type type() const override { return Technical; }
bool canExecute() const override { return false; }
void invokeApplication() const override;
void fetchChangelog() override;
......
......@@ -54,6 +54,7 @@ public:
int size() override;
void fetchChangelog() override;
QStringList extends() const override;
AbstractResource::Type type() const override { return Addon; }
KNSBackend* knsBackend() const;
......
......@@ -153,11 +153,13 @@ QUrl AppPackageKitResource::donationURL()
return m_appdata.url(AppStream::Component::UrlKindDonation);
}
bool AppPackageKitResource::isTechnical() const
AbstractResource::Type AppPackageKitResource::type() const
{
static QString desktop = QString::fromUtf8(qgetenv("XDG_CURRENT_DESKTOP"));
const auto desktops = m_appdata.compulsoryForDesktops();
return (!desktops.isEmpty() && !desktops.contains(desktop)) || m_appdata.kind() == AppStream::Component::KindAddon;
return (!desktops.isEmpty() && !desktops.contains(desktop)) ? Application
: m_appdata.kind() == AppStream::Component::KindAddon ? Addon
: Technical;
}
void AppPackageKitResource::fetchScreenshots()
......
......@@ -32,7 +32,7 @@ class AppPackageKitResource : public PackageKitResource
QString appstreamId() const override;
bool isTechnical() const override;
AbstractResource::Type type() const override;
QString name() const override;
QVariant icon() const override;
QStringList mimetypes() const override;
......
......@@ -412,7 +412,7 @@ ResultsStream* PackageKitBackend::search(const AbstractResourcesBackend::Filters
const auto ext = kTransform<QVector<AbstractResource*>>(m_packages.extendedBy[filter.extends], [](AppPackageKitResource* a){ return a; });
return new ResultsStream(QStringLiteral("PackageKitStream-extends"), ext);
} else if (filter.search.isEmpty()) {
return new ResultsStream(QStringLiteral("PackageKitStream-all"), kFilter<QVector<AbstractResource*>>(m_packages.packages, [](AbstractResource* res) { return !res->isTechnical(); }));
return new ResultsStream(QStringLiteral("PackageKitStream-all"), kFilter<QVector<AbstractResource*>>(m_packages.packages, [](AbstractResource* res) { return res->type() != AbstractResource::Technical; }));
} else {
const QList<AppStream::Component> components = m_appdata->search(filter.search);
const QStringList ids = kTransform<QStringList>(components, [](const AppStream::Component& comp) { return comp.id(); });
......
......@@ -160,9 +160,9 @@ QStringList PackageKitResource::categories()
return { QStringLiteral("Unknown") };
}
bool PackageKitResource::isTechnical() const
AbstractResource::Type PackageKitResource::type() const
{
return true;
return Technical;
}
void PackageKitResource::fetchDetails()
......
......@@ -43,7 +43,7 @@ class PackageKitResource : public AbstractResource
QString license() override;
QString origin() const override;
QString section() override;
bool isTechnical() const override;
AbstractResource::Type type() const override;
int size() override;
void fetchChangelog() override;
......
......@@ -220,9 +220,9 @@ void SnapResource::invokeApplication() const
QProcess::startDetached(QStringLiteral("snap"), {QStringLiteral("run"), packageName()});
}
bool SnapResource::isTechnical() const
AbstractResource::Type SnapResource::type() const
{
return m_snap->snapType() != QLatin1String("app");
return m_snap->snapType() != QLatin1String("app") ? Application : Technical;
}
void SnapResource::setSnap(const QSharedPointer<QSnapdSnap>& snap)
......
......@@ -53,7 +53,7 @@ public:
QString comment() override;
QString name() const override;
QString packageName() const override;
bool isTechnical() const override;
AbstractResource::Type type() const override;
bool canExecute() const override { return true; }
void invokeApplication() const override;
void fetchChangelog() override;
......
......@@ -58,11 +58,6 @@ QUrl AbstractResource::donationURL()
return QUrl();
}
bool AbstractResource::isTechnical() const
{
return false;
}
void AbstractResource::addMetadata(const QString &key, const QJsonValue &value)
{
m_metadata.insert(key, value);
......
......@@ -55,7 +55,6 @@ class DISCOVERCOMMON_EXPORT AbstractResource : public QObject
Q_PROPERTY(State state READ state NOTIFY stateChanged)
Q_PROPERTY(QString status READ status NOTIFY stateChanged)
Q_PROPERTY(QStringList category READ categories CONSTANT)
Q_PROPERTY(bool isTechnical READ isTechnical CONSTANT)
Q_PROPERTY(QUrl homepage READ homepage CONSTANT)
Q_PROPERTY(QUrl helpURL READ helpURL CONSTANT)
Q_PROPERTY(QUrl bugURL READ bugURL CONSTANT)
......@@ -141,7 +140,9 @@ class DISCOVERCOMMON_EXPORT AbstractResource : public QObject
///@returns a URL that points to the place where you can donate money to the app developer
virtual QUrl donationURL();
virtual bool isTechnical() const;
enum Type { Application, Addon, Technical };
Q_ENUM(Type);
virtual Type type() const = 0;
virtual int size() = 0;
virtual QString sizeDescription();
......
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