-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Implement a method of retrieving the package update time #155
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -18,6 +18,13 @@ Page { | |||||
|
||||||
allowedOrientations: Orientation.All | ||||||
|
||||||
BusyIndicator { | ||||||
size: BusyIndicatorSize.Large | ||||||
anchors.centerIn: parent | ||||||
running: chumModel.busy == true | ||||||
visible: running | ||||||
} | ||||||
|
||||||
SilicaListView { | ||||||
id: view | ||||||
anchors.fill: parent | ||||||
|
@@ -78,7 +85,7 @@ Page { | |||||
} | ||||||
|
||||||
onClicked: pageStack.push(Qt.resolvedUrl("../pages/PackagePage.qml"), { | ||||||
pkg: Chum.package(model.packageId) | ||||||
pkg: Chum.package(model.packageId), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}) | ||||||
|
||||||
onDownChanged: { | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,13 @@ | |
|
||
#include <QDebug> | ||
#include <QSettings> | ||
#include <QtNetwork/QNetworkAccessManager> | ||
#include <QtNetwork/QNetworkReply> | ||
#include <QtNetwork/QNetworkRequest> | ||
#include <QJsonObject> | ||
#include <QJsonArray> | ||
|
||
static char* apiUrl = "http://piggz.co.uk:8081"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest to add that as MACRO and set it in CMakeLists.txt |
||
|
||
using namespace PackageKit; | ||
|
||
|
@@ -37,10 +44,7 @@ Chum::Chum(QObject *parent) | |
m_show_apps_by_default = (settings.value(s_config_showapps, 1).toInt() != 0); | ||
m_manualVersion = (settings.value(s_config_manualversion, QString()).toString()); | ||
|
||
m_busy = true; | ||
//% "Loading SailfishOS:Chum repository" | ||
setStatus(qtTrId("chum-load-repositories")); | ||
m_ssu.loadRepos(); | ||
getChumCache(); | ||
} | ||
|
||
Chum* Chum::instance() { | ||
|
@@ -450,3 +454,86 @@ void Chum::setStatus(QString status) { | |
m_status = status; | ||
emit statusChanged(); | ||
} | ||
|
||
void Chum::getChumCache() | ||
{ | ||
if (!m_busy) { | ||
m_busy = true; | ||
emit busyChanged(); | ||
} | ||
|
||
//% "Receiving the chum package cache" | ||
setStatus(qtTrId("chum-update-cache")); | ||
|
||
QNetworkAccessManager *netManager = new QNetworkAccessManager(); | ||
|
||
QObject::connect(netManager,&QNetworkAccessManager::finished,[=](QNetworkReply *reply) { | ||
if (reply->error()){ | ||
qDebug() << "Unable to get package build times" << reply->errorString(); | ||
} | ||
else { | ||
m_chumPackageCache = QJsonDocument::fromJson(reply->readAll()); | ||
qDebug() << "Received chum package cache"; | ||
} | ||
m_busy = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should stay on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In addition, aren't we expected to call |
||
//% "Loading SailfishOS:Chum repository" | ||
setStatus(qtTrId("chum-load-repositories")); | ||
m_ssu.loadRepos(); | ||
}); | ||
|
||
// Start the network request | ||
QNetworkRequest request=QNetworkRequest(QUrl(apiUrl)); | ||
m_busy = true; | ||
emit busyChanged(); | ||
netManager->get(request); | ||
} | ||
|
||
QDateTime Chum::findPackageMTime(const QString &rpm) const | ||
{ | ||
qDebug() << Q_FUNC_INFO << rpm << Chum::instance()->repoName() << Chum::instance()->repoVersion(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why use Chum::instance if we have it in |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder whether there is a better way of doing it. In principle, we have for each package its name (ex 'harbour-advanced-camera' or 'libscrypt-devel'). At the same time, we can expose URL of active Chum repository. For exposing Chum repo URL, we would have We would just need to add one more property (repoUrl?) to SSU and fill it up based on m_repos (see https://github.com/sailfishos-chum/sailfishos-chum-gui/blob/main/src/ssu.cpp#L60 and below). Thus, we could get current repo using m_ssu.repoUrl() and get https://repo.sailfishos.org/obs/sailfishos:/chum:/testing/4.5.0.16_aarch64/ After that, it is possible to condition URL into When generating JSON, we can actually forget about "projects" and immediately link those to "packages". So, that would be a task of backend solution. Ideally, we should have JSON as follows: {
"testing/4.5.0.16_aarch64": {
"harbour-advanced-camera": { "mtime": "1634426517" },
"libscrypt-devel": { "mtime": "1634426517" }
}
} That way it can be extended by more details if needed and would ensure that we have data accessible easily from GUI. |
||
QString repo = Chum::instance()->repoVersion() + "_aarch64"; //TODO need to determine device architecture | ||
QString projectName = Chum::instance()->repoName().replace("-", ":"); | ||
QString packageName; | ||
QDateTime mtime = QDateTime::fromMSecsSinceEpoch(0); | ||
bool found = false; | ||
|
||
QJsonArray projects = m_chumPackageCache.object().value("projects").toArray(); | ||
|
||
for (auto project : projects) { | ||
//qDebug() << project.toObject()["name"]; | ||
if (project.toObject()["name"].toString() == projectName) { | ||
QJsonArray repos = project.toObject()["repositories"].toArray(); | ||
for (auto repo : repos) { | ||
//qDebug() << repo.toObject()["name"]; | ||
QJsonArray packages = repo.toObject()["packages"].toArray(); | ||
for (auto package : packages) { | ||
//qDebug() << package.toObject()["name"].toString(); | ||
QJsonArray binaries = package.toObject()["binaries"].toArray(); | ||
for (auto binary : binaries) { | ||
//qDebug() << binary.toString(); | ||
if (binary.toString().startsWith(rpm)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I suggested a bit different way of doing it, it could be irrelevant. We can get false positives with libscrypt-devel and libscrypt comparison. In this case it would be OK (same package), but what if we have osmscout and osmscout-server ? |
||
packageName = package.toObject()["name"].toString(); | ||
found = true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (found) { | ||
//loop the source projects | ||
QJsonArray packages = project.toObject()["packages"].toArray(); | ||
for (auto package : packages) { | ||
//qDebug() << package.toObject()["name"]; | ||
if (package.toObject()["name"].toString() == packageName) { | ||
int mt = package.toObject()["mtime"].toString().toInt(); | ||
mtime = QDateTime::fromMSecsSinceEpoch(1000L * mt); | ||
qDebug() << "Found binary " << rpm << " in source package " << packageName << mt << mtime; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return mtime; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
#include <QHash> | ||
#include <QObject> | ||
#include <QSet> | ||
#include <QJsonDocument> | ||
|
||
#include "chumpackage.h" | ||
#include "ssu.h" | ||
|
@@ -45,10 +46,14 @@ class Chum : public QObject { | |
void setRepoTesting(bool testing); | ||
void setShowAppsByDefault(bool v); | ||
void setManualVersion(const QString &v); | ||
QString repoName() { return m_ssu.repoName();} | ||
QString repoVersion() { return m_manualVersion.isEmpty() ? m_ssu.deviceVersion() : m_manualVersion; } | ||
Comment on lines
+49
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess those are not needed anymore |
||
|
||
const QList<ChumPackage*> packages() const { return m_packages.values(); } | ||
Q_INVOKABLE ChumPackage* package(const QString &id) const { return m_packages.value(id, nullptr); } | ||
|
||
QDateTime findPackageMTime(const QString &rpm) const; | ||
|
||
// static public methods | ||
static Chum* instance(); | ||
|
||
|
@@ -92,6 +97,8 @@ public slots: | |
void startOperation(PackageKit::Transaction *pktr, const QString &pkg_id); | ||
void setStatus(QString status); | ||
|
||
void getChumCache(); | ||
|
||
private: | ||
Ssu m_ssu; | ||
bool m_busy{false}; | ||
|
@@ -100,6 +107,7 @@ public slots: | |
quint32 m_updates_count{0}; | ||
bool m_show_apps_by_default{false}; | ||
QString m_manualVersion; | ||
QJsonDocument m_chumPackageCache; | ||
|
||
QHash<QString, ChumPackage*> m_packages; | ||
QSet<QString> m_packages_last_refresh; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#include "chumpackage.h" | ||
#include "chum.h" | ||
|
||
#include "projectgithub.h" | ||
#include "projectgitlab.h" | ||
|
@@ -122,6 +123,8 @@ void ChumPackage::setDetails(const PackageKit::Details &v) { | |
// derive name | ||
QString pname = Daemon::packageName(m_pkid_latest); | ||
m_package_name = pname; | ||
m_package_mtime = Chum::instance()->findPackageMTime(m_package_name); | ||
|
||
m_name = QString{}; | ||
QStringList nparts = pname.split('-'); | ||
bool is_app = false; | ||
|
@@ -261,6 +264,12 @@ void ChumPackage::setPackagerLogin(const QString &login) { | |
SET_IF_EMPTY(m_packager_login, PackagePackagerRole, login); | ||
} | ||
|
||
void ChumPackage::setPackageMTime(const QDateTime &mtime) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not called anymore |
||
{ | ||
m_package_mtime = mtime; | ||
emit updated(m_id, PackageMTime); | ||
} | ||
|
||
void ChumPackage::setPackagerName(const QString &name) { | ||
SET_IF_EMPTY(m_packager_name, PackagePackagerRole, name); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ class ChumPackage : public QObject { | |
Q_PROPERTY(int issuesCount READ issuesCount NOTIFY updated) | ||
Q_PROPERTY(QString license READ license NOTIFY updated) | ||
Q_PROPERTY(QString name READ name NOTIFY updated) | ||
Q_PROPERTY(QDateTime packageMTime READ packageMTime NOTIFY updated) | ||
Q_PROPERTY(QString packageName READ packageName NOTIFY updated) | ||
Q_PROPERTY(QString packager READ packager NOTIFY updated) | ||
Q_PROPERTY(QString packagingUrl READ packagingUrl NOTIFY updated) | ||
|
@@ -55,6 +56,7 @@ class ChumPackage : public QObject { | |
PackageSummaryRole, | ||
PackageTypeRole, | ||
PackageUpdateAvailableRole, | ||
PackageMTime, | ||
|
||
PackageOtherRole, | ||
PackageRefreshRole // used for updates of many parameters | ||
|
@@ -93,6 +95,7 @@ class ChumPackage : public QObject { | |
int issuesCount() const { return m_issues_count; } | ||
QString license() const { return m_license; } | ||
QString name() const { return m_name; } | ||
QDateTime packageMTime() const { return m_package_mtime; } | ||
QString packageName() const { return m_package_name; } | ||
QString packager() const; | ||
QString packagingUrl() const { return m_packaging_repo_url; } | ||
|
@@ -119,6 +122,7 @@ class ChumPackage : public QObject { | |
void setForksCount(int count); | ||
void setIssuesCount(int count); | ||
void setPackagerLogin(const QString &login); | ||
void setPackageMTime(const QDateTime &mtime); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed |
||
void setPackagerName(const QString &name); | ||
void setReleasesCount(int count); | ||
void setStarsCount(int count); | ||
|
@@ -161,6 +165,7 @@ class ChumPackage : public QObject { | |
int m_issues_count{-1}; | ||
QString m_license; | ||
QString m_name; | ||
QDateTime m_package_mtime; | ||
QString m_package_name; | ||
QString m_packager_login; | ||
QString m_packager_name; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ class ChumPackagesModel | |
void filterUpdatesOnlyChanged(); | ||
void searchChanged(); | ||
void showCategoryChanged(); | ||
void busyChanged(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed |
||
|
||
private: | ||
void updatePackage(QString packageId, ChumPackage::Role role); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
#include <QDBusPendingCall> | ||
#include <QDBusPendingReply> | ||
#include <QDBusReply> | ||
#include <QDebug> | ||
|
||
static QString s_repo_regular( | ||
|
@@ -25,6 +26,9 @@ Ssu::Ssu(QObject *parent) : | |
QDBusConnection::systemBus(), | ||
parent ) | ||
{ | ||
QDBusReply<QString> version = call(QStringLiteral("release"), false); | ||
m_device_version = version; | ||
qDebug() << "Device version:" << m_device_version; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Users can override repo version. We should get real URL and use that, as described above |
||
} | ||
|
||
void Ssu::loadRepos() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be needed - whole BusyIndicator - as we have busy state in Chum