Commit 42083fa8 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Sort update items by completion

Summary:
Sort update items by completion.

BUG: 390911

Test Plan: Tested locally with dummy and packagekit@alpm (because I already had the rest up to date, needs more testing)

Reviewers: ngraham

Reviewed By: ngraham

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D14250
parent 43ab6b12
......@@ -151,7 +151,10 @@ DiscoverPage
}
}
model: updateModel
model: QSortFilterProxyModel {
sourceModel: updateModel
sortRole: UpdateModel.SectionResourceProgressRole
}
section {
property: "section"
......
......@@ -36,9 +36,13 @@ public:
~UpdateItem();
enum Section {
ApplicationSection,
SystemSection
};
void setSection(const QString &section) { m_section = section; }
QString section() const { return m_section; }
void setSection(const Section &section) { m_section = section; }
Section section() const { return m_section; }
void setProgress(qreal progress);
qreal progress() const;
......@@ -61,7 +65,7 @@ private:
const QIcon m_categoryIcon;
qreal m_progress;
QString m_changelog;
QString m_section;
Section m_section;
};
#endif // UPDATEITEM_H
......@@ -87,7 +87,7 @@ void UpdateModel::resourceHasProgressed(AbstractResource* res, qreal progress)
item->setProgress(progress);
const QModelIndex idx = indexFromItem(item);
Q_EMIT dataChanged(idx, idx, { ResourceProgressRole });
Q_EMIT dataChanged(idx, idx, { ResourceProgressRole, SectionResourceProgressRole });
}
void UpdateModel::activityChanged()
......@@ -130,8 +130,15 @@ QVariant UpdateModel::data(const QModelIndex &index, int role) const
return item->progress();
case ChangelogRole:
return item->changelog();
case SectionRole:
return item->section();
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;
}
} case SectionResourceProgressRole:
return (100-item->progress()) + (101 * item->section());
default:
break;
}
......@@ -216,8 +223,6 @@ void UpdateModel::setResources(const QList<AbstractResource*>& resources)
qDeleteAll(m_updateItems);
m_updateItems.clear();
const QString appUpdatesSection = i18nc("@item:inlistbox", "Application Updates");
const QString systemUpdateSection = i18nc("@item:inlistbox", "System Updates");
QVector<UpdateItem*> appItems, systemItems;
foreach(AbstractResource* res, resources) {
connect(res, &AbstractResource::changelogFetched, this, &UpdateModel::integrateChangelog, Qt::UniqueConnection);
......@@ -225,10 +230,10 @@ void UpdateModel::setResources(const QList<AbstractResource*>& resources)
UpdateItem *updateItem = new UpdateItem(res);
if(!res->isTechnical()) {
updateItem->setSection(appUpdatesSection);
updateItem->setSection(UpdateItem::ApplicationSection);
appItems += updateItem;
} else {
updateItem->setSection(systemUpdateSection);
updateItem->setSection(UpdateItem::SystemSection);
systemItems += updateItem;
}
}
......
......@@ -44,9 +44,11 @@ public:
SizeRole,
ResourceRole,
ResourceProgressRole,
SectionResourceProgressRole,
ChangelogRole,
SectionRole
};
Q_ENUM(Roles)
explicit UpdateModel(QObject *parent = nullptr);
~UpdateModel() override;
......
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