Commit 7fc483f0 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

pk: Display the state of the dependencies

In the "Show Dependencies" dialog, show their respective state.
parent 5fddda9b
......@@ -314,4 +314,62 @@ QString updateStateMessage(PackageKit::Transaction::UpdateState state)
return QString();
}
QString info(PackageKit::Transaction::Info info)
{
switch (info) {
case PackageKit::Transaction::InfoUnknown:
return i18n("Unknown");
case PackageKit::Transaction::InfoInstalled:
return i18n("Installed");
case PackageKit::Transaction::InfoAvailable:
return i18n("Not Installed");
case PackageKit::Transaction::InfoLow:
return i18n("Low");
case PackageKit::Transaction::InfoEnhancement:
return i18n("Enhancement");
case PackageKit::Transaction::InfoNormal:
return i18n("Normal");
case PackageKit::Transaction::InfoBugfix:
return i18n("Bugfix");
case PackageKit::Transaction::InfoImportant:
return i18n("Important");
case PackageKit::Transaction::InfoSecurity:
return i18n("Security");
case PackageKit::Transaction::InfoBlocked:
return i18n("Blocked");
case PackageKit::Transaction::InfoDownloading:
return i18n("Downloading");
case PackageKit::Transaction::InfoUpdating:
return i18n("Updating");
case PackageKit::Transaction::InfoInstalling:
return i18n("Installing");
case PackageKit::Transaction::InfoRemoving:
return i18n("Removing");
case PackageKit::Transaction::InfoCleanup:
return i18n("Cleanup");
case PackageKit::Transaction::InfoObsoleting:
return i18n("Obsoleting");
case PackageKit::Transaction::InfoCollectionInstalled:
return i18n("Collection Installed");
case PackageKit::Transaction::InfoCollectionAvailable:
return i18n("Collection Available");
case PackageKit::Transaction::InfoFinished:
return i18n("Finished");
case PackageKit::Transaction::InfoReinstalling:
return i18n("Reinstalling");
case PackageKit::Transaction::InfoDowngrading:
return i18n("Downgrading");
case PackageKit::Transaction::InfoPreparing:
return i18n("Preparing");
case PackageKit::Transaction::InfoDecompressing:
return i18n("Decompressing");
case PackageKit::Transaction::InfoUntrusted:
return i18n("Untrusted");
case PackageKit::Transaction::InfoTrusted:
return i18n("Trusted");
case PackageKit::Transaction::InfoUnavailable:
return i18n("Unavailable");
}
return {};
}
}
......@@ -17,6 +17,7 @@ QString restartMessage(PackageKit::Transaction::Restart restart);
QString statusMessage(PackageKit::Transaction::Status status);
QString statusDetail(PackageKit::Transaction::Status status);
QString updateStateMessage(PackageKit::Transaction::UpdateState state);
QString info(PackageKit::Transaction::Info info);
}
#endif // PACKAGEKITMESSAGES_H
......@@ -343,7 +343,7 @@ void PackageKitResource::fetchDependencies()
return;
m_dependenciesCount = 0;
QSharedPointer<QJsonObject> packageDependencies(new QJsonObject);
auto packageDependencies = QSharedPointer<QJsonArray>::create();
auto trans = PackageKit::Daemon::dependsOn(id);
connect(trans, &PackageKit::Transaction::errorCode, this, [this](PackageKit::Transaction::Error, const QString &message) {
......@@ -352,10 +352,20 @@ void PackageKitResource::fetchDependencies()
connect(trans,
&PackageKit::Transaction::package,
this,
[packageDependencies](PackageKit::Transaction::Info /*info*/, const QString &packageID, const QString &summary) {
(*packageDependencies)[PackageKit::Daemon::packageName(packageID)] = summary;
[packageDependencies](PackageKit::Transaction::Info info, const QString &packageID, const QString &summary) {
(*packageDependencies)
.append(QJsonObject{{QStringLiteral("packageName"), PackageKit::Daemon::packageName(packageID)},
{QStringLiteral("packageInfo"), PackageKitMessages::info(info)},
{QStringLiteral("packageDescription"), summary}});
});
connect(trans, &PackageKit::Transaction::finished, this, [this, packageDependencies](PackageKit::Transaction::Exit /*status*/) {
std::sort(packageDependencies->begin(), packageDependencies->end(), [](QJsonValue a, QJsonValue b) {
const auto objA = a.toObject(), objB = b.toObject();
return objA[QLatin1String("packageInfo")].toString() < objB[QLatin1String("packageInfo")].toString()
|| (objA[QLatin1String("packageInfo")].toString() == objB[QLatin1String("packageInfo")].toString()
&& objA[QLatin1String("packageName")].toString() < objB[QLatin1String("packageName")].toString());
});
Q_EMIT dependenciesFound(*packageDependencies);
setDependenciesCount(packageDependencies->size());
});
......
......@@ -84,7 +84,7 @@ public:
void runService(const QStringList &desktopFilePaths) const;
Q_SIGNALS:
void dependenciesFound(const QJsonObject &dependencies);
void dependenciesFound(const QJsonArray &dependencies);
public Q_SLOTS:
void addPackageId(PackageKit::Transaction::Info info, const QString &packageId, bool arch);
......
......@@ -19,10 +19,7 @@ Kirigami.LinkButton {
onDependenciesFound: {
view.model.clear()
for (var v in dependencies) {
view.model.append({
"packageName": v,
"packageDescription": dependencies[v]
})
view.model.append(dependencies[v])
}
}
}
......@@ -36,12 +33,17 @@ Kirigami.LinkButton {
ListView {
id: view
implicitWidth: Kirigami.Units.gridUnit * 25
clip: true
headerPositioning: ListView.OverlayHeader
model: ListModel {}
section.property: "packageInfo"
section.delegate: Kirigami.ListSectionHeader {
width: view.width
height: Kirigami.Units.fontMetrics.xHeight * 4
label: section
}
delegate: Kirigami.BasicListItem {
width: view.width
text: model.packageName
......
......@@ -8,6 +8,7 @@
#define UTILS_H
#include <QElapsedTimer>
#include <QJsonValue>
#include <QScopeGuard>
#include <QString>
#include <functional>
......@@ -141,4 +142,11 @@ public:
QString m_name;
};
inline void swap(QJsonValueRef v1, QJsonValueRef v2)
{
QJsonValue temp(v1);
v1 = QJsonValue(v2);
v2 = temp;
}
#endif
Supports Markdown
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