Skip to content

Commit

Permalink
Metadata: parse new names (#181)
Browse files Browse the repository at this point in the history
* parse new names:

 - PackageName  || Title
 - PackagerName || PackagedBy
 - Icon         || PackageIcon
 - Url          || Links

* handle undefined name fallback

---------

Co-authored-by: nephros <nemo@pgxperiiia10>
  • Loading branch information
nephros and nephros authored Apr 2, 2023
1 parent 884507d commit 2de3d79
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/chumpackage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ void ChumPackage::setDetails(const PackageKit::Details &v) {
// Parse metadata
QJsonObject json{QJsonDocument::fromJson(metainjson).object()};

m_name = json.value("PackageName").toString(m_name);
if (json.value("PackageName").isUndefined()) {
m_name = json.value("Title").toString(m_name);
} else {
m_name = json.value("PackageName").toString(m_name); // spec v0 legacy
}

QString typestr = json.value("Type").toString(is_app ?
QStringLiteral("desktop-application") :
Expand All @@ -192,7 +196,9 @@ void ChumPackage::setDetails(const PackageKit::Details &v) {

m_developer_name = json.value("DeveloperName").toString();
m_developer_name_from_spec = !m_developer_name.isEmpty();
m_packager_name = json.value("PackagerName").toString();
m_packager_name = json.value("PackagedBy").toString();
if (m_packager_name.isEmpty()
m_packager_name = json.value("PackagerName").toString(); // spec v0 legacy
m_packager_name_from_spec = !m_packager_name.isEmpty();
m_categories = json.value("Categories").toVariant().toStringList();
// guess category only if it is empty
Expand All @@ -204,13 +210,22 @@ void ChumPackage::setDetails(const PackageKit::Details &v) {
m_packaging_repo_url = json.value("Custom").toObject().value("PackagingRepo").toString();
m_description_md_url = json.value("Custom").toObject().value("DescriptionMD").toString();

m_icon = json.value("Icon").toString();
m_icon = json.value("PackageIcon").toString();
if (m_icon.isEmpty()) m_icon = json.value("Icon").toString(); // spec v0 legacy

m_screenshots = json.value("Screenshots").toVariant().toStringList();

m_url = json.value("Url").toObject().value("Homepage").toString(m_url);
m_url_forum = json.value("Url").toObject().value("Help").toString();
m_url_issues = json.value("Url").toObject().value("Bugtracker").toString();
m_donation = json.value("Url").toObject().value("Donation").toString();
if (json.value("Url").isEmpty() { // spec v0 legacy
m_url = json.value("Links").toObject().value("Homepage").toString(m_url);
m_url_forum = json.value("Links").toObject().value("Help").toString();
m_url_issues = json.value("Links").toObject().value("Bugtracker").toString();
m_donation = json.value("Links").toObject().value("Donation").toString();
} else {
m_url = json.value("Url").toObject().value("Homepage").toString(m_url);
m_url_forum = json.value("Url").toObject().value("Help").toString();
m_url_issues = json.value("Url").toObject().value("Bugtracker").toString();
m_donation = json.value("Url").toObject().value("Donation").toString();
}

for (const QString &u: {m_repo_url, m_url, m_packaging_repo_url}) {
if (ProjectGitHub::isProject(u))
Expand Down

0 comments on commit 2de3d79

Please sign in to comment.