[discover] /: Use AppStream instead of appinstall-data in the QApt backend
Aleix Pol
aleixpol at kde.org
Tue Jan 5 15:09:06 UTC 2016
Git commit 97f1426d5806beae0456566e1cf6653341d64afa by Aleix Pol.
Committed on 05/01/2016 at 15:08.
Pushed by apol into branch 'master'.
Use AppStream instead of appinstall-data in the QApt backend
It was deprecated and only available on Ubuntu. AppStream is available on
Debian as well.
The current version of AppStream in Ubuntu Willy is outdated and needs
love.
CCMAIL: Kubuntu Developer Discussion <kubuntu-devel at lists.ubuntu.com>
M +1 -4 CMakeLists.txt
M +49 -61 libdiscover/backends/ApplicationBackend/Application.cpp
M +6 -7 libdiscover/backends/ApplicationBackend/Application.h
M +7 -6 libdiscover/backends/ApplicationBackend/ApplicationBackend.cpp
M +1 -1 libdiscover/backends/ApplicationBackend/CMakeLists.txt
http://commits.kde.org/discover/97f1426d5806beae0456566e1cf6653341d64afa
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4fd12f3..c5f29b9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -31,11 +31,8 @@ else()
if(NOT AkabeiClient_FOUND)
find_package(packagekitqt5)
endif()
-
- if(packagekitqt5_FOUND OR AkabeiClient_FOUND)
- find_package(AppstreamQt 0.8.4)
- endif()
endif()
+find_package(AppstreamQt 0.8.4)
find_package(KF5Attica)
find_package(KF5NewStuff)
# find_package(BODEGA QUIET)
diff --git a/libdiscover/backends/ApplicationBackend/Application.cpp b/libdiscover/backends/ApplicationBackend/Application.cpp
index 303f736..bf457bc 100644
--- a/libdiscover/backends/ApplicationBackend/Application.cpp
+++ b/libdiscover/backends/ApplicationBackend/Application.cpp
@@ -49,39 +49,36 @@
#include "ApplicationBackend.h"
#include "resources/PackageState.h"
-Application::Application(const QString& fileName, QApt::Backend* backend)
+Application::Application(const Appstream::Component &component, QApt::Backend* backend)
: AbstractResource(0)
- , m_data(new KConfig(fileName, KConfig::SimpleConfig))
- , m_backend(backend)
+ , m_data(component)
, m_package(0)
, m_isValid(true)
- , m_isTechnical(false)
+ , m_isTechnical(component.kind() != Appstream::Component::KindDesktop)
, m_isExtrasApp(false)
, m_sourceHasScreenshot(true)
{
static QByteArray currentDesktop = qgetenv("XDG_CURRENT_DESKTOP");
- m_isTechnical = getField("NoDisplay").toLower() == "true"
- || !hasField("Exec")
- || getField("NotShowIn", QByteArray()).contains(currentDesktop)
- || !getField("OnlyShowIn", currentDesktop).contains(currentDesktop);
- m_packageName = getField("X-AppInstall-Package");
+ Q_ASSERT(component.packageNames().count() == 1);
+ m_packageName = component.packageNames().at(0);
+
+ m_package = backend->package(packageName());
+ m_isValid = bool(m_package);
}
Application::Application(QApt::Package* package, QApt::Backend* backend)
: AbstractResource(0)
- , m_backend(backend)
, m_package(package)
+ , m_packageName(m_package->name())
, m_isValid(true)
, m_isTechnical(true)
, m_isExtrasApp(false)
{
- m_packageName = m_package->name().latin1();
-
QString arch = m_package->architecture();
- if (arch != m_backend->nativeArchitecture() && arch != QLatin1String("all")) {
- m_packageName.append(':');
- m_packageName.append(m_package->architecture().toLatin1());
+ if (arch != backend->nativeArchitecture() && arch != QLatin1String("all")) {
+ m_packageName.append(QLatin1Char(':'));
+ m_packageName.append(arch);
}
if (m_package->origin() == QLatin1String("LP-PPA-app-review-board")) {
@@ -94,20 +91,7 @@ Application::Application(QApt::Package* package, QApt::Backend* backend)
QString Application::name()
{
- QString name;
- if (!m_isTechnical)
- name = i18n(untranslatedName().toUtf8().constData());
- else
- name = untranslatedName();
-
- if (package() && m_package->isForeignArch())
- name = i18n("%1 (%2)", name, m_package->architecture());
- return name;
-}
-
-QString Application::untranslatedName()
-{
- QString name = QString::fromUtf8(getField("Name")).trimmed();
+ QString name = m_data.isValid() ? m_data.name() : QString();
if (name.isEmpty() && package()) {
// extras.ubuntu.com packages can have this
if (m_isExtrasApp)
@@ -116,18 +100,17 @@ QString Application::untranslatedName()
name = m_package->name();
}
+ if (package() && m_package->isForeignArch())
+ name = i18n("%1 (%2)", name, m_package->architecture());
+
return name;
}
QString Application::comment()
{
- QString comment = QString::fromLatin1(getField("Comment"));
+ QString comment = m_data.isValid() ? m_data.description() : QString();
if (comment.isEmpty()) {
- // Sometimes GenericName is used instead of Comment
- comment = QString::fromLatin1(getField("GenericName"));
- if (comment.isEmpty()) {
- return package()->shortDescription();
- }
+ return package()->shortDescription();
}
return i18n(comment.toUtf8().constData());
@@ -135,13 +118,13 @@ QString Application::comment()
QString Application::packageName() const
{
- return QString::fromLatin1(m_packageName);
+ return m_packageName;
}
QApt::Package *Application::package()
{
- if (!m_package && m_backend) {
- m_package = m_backend->package(packageName());
+ if (!m_package && parent()) {
+ m_package = backend()->package(packageName());
Q_EMIT stateChanged();
}
@@ -156,12 +139,27 @@ QApt::Package *Application::package()
QString Application::icon() const
{
- return QString::fromLatin1(getField("Icon", "applications-other"));
+ QString anIcon = m_data.icon();
+ if (anIcon.isEmpty()) {
+ QUrl iconUrl = m_data.iconUrl(QSize());
+ if (iconUrl.isLocalFile())
+ anIcon = iconUrl.toLocalFile();
+ }
+ return anIcon;
+}
+
+QStringList Application::findProvides(Appstream::Provides::Kind kind) const
+{
+ QStringList ret;
+ Q_FOREACH (Appstream::Provides p, m_data.provides())
+ if (p.kind() == kind)
+ ret += p.value();
+ return ret;
}
QStringList Application::mimetypes() const
{
- return QString::fromLatin1(getField("MimeType")).split(QLatin1Char(';'));
+ return findProvides(Appstream::Provides::KindMimetype);
}
QString Application::menuPath()
@@ -259,7 +257,7 @@ QVector<QPair<QString, QString> > Application::locateApplication(const QString &
QStringList Application::categories()
{
- QStringList categories = QString::fromLatin1(getField("Categories")).split(QLatin1Char(';'), QString::SkipEmptyParts);
+ QStringList categories = m_data.isValid() ? m_data.categories() : QStringList();
if (categories.isEmpty()) {
// extras.ubuntu.com packages can have this field
@@ -311,10 +309,10 @@ QApt::PackageList Application::addons()
QStringList tempList;
// Only add recommends or suggests to the list if they aren't already going to be
// installed
- if (!m_backend->config()->readEntry(QStringLiteral("APT::Install-Recommends"), true)) {
+ if (!backend()->config()->readEntry(QStringLiteral("APT::Install-Recommends"), true)) {
tempList << m_package->recommendsList();
}
- if (!m_backend->config()->readEntry(QStringLiteral("APT::Install-Suggests"), false)) {
+ if (!backend()->config()->readEntry(QStringLiteral("APT::Install-Suggests"), false)) {
tempList << m_package->suggestsList();
}
tempList << m_package->enhancedByList();
@@ -337,7 +335,7 @@ QApt::PackageList Application::addons()
foreach (const QString &addon, tempList) {
bool shouldShow = true;
- QApt::Package *package = m_backend->package(addon);
+ QApt::Package *package = backend()->package(addon);
if (!package || QString(package->section()).contains(QLatin1String("lib")) || addons.contains(package)) {
continue;
@@ -378,21 +376,6 @@ bool Application::isTechnical() const
return m_isTechnical;
}
-QByteArray Application::getField(const char* field, const QByteArray& defaultvalue) const
-{
- if(m_data) {
- KConfigGroup group = m_data->group(QStringLiteral("Desktop Entry"));
- return group.readEntry(field, defaultvalue);
- } else
- return defaultvalue;
-
-}
-
-bool Application::hasField(const char* field) const
-{
- return m_data && m_data->group(QStringLiteral("Desktop Entry")).hasKey(field);
-}
-
QUrl Application::homepage()
{
if(!m_package) return QUrl();
@@ -520,8 +503,8 @@ void Application::fetchScreenshots()
if(!m_sourceHasScreenshot)
return;
- QString dest = QStandardPaths::locate(QStandardPaths::TempLocation, QStringLiteral("screenshots.")+QString::fromLatin1(m_packageName));
- const QUrl packageUrl(MuonDataSources::screenshotsSource().toString() + QStringLiteral("/json/package/")+QString::fromLatin1(m_packageName));
+ QString dest = QStandardPaths::locate(QStandardPaths::TempLocation, QStringLiteral("screenshots.")+m_packageName);
+ const QUrl packageUrl(MuonDataSources::screenshotsSource().toString() + QStringLiteral("/json/package/")+m_packageName);
KIO::StoredTransferJob* job = KIO::storedGet(packageUrl, KIO::NoReload, KIO::HideProgressInfo);
connect(job, &KIO::StoredTransferJob::finished, this, &Application::downloadingScreenshotsFinished);
}
@@ -640,3 +623,8 @@ QString Application::buildDescription(const QByteArray& data, const QString& sou
return description;
}
+
+QApt::Backend *Application::backend() const
+{
+ return qobject_cast<ApplicationBackend*>(parent())->backend();
+}
diff --git a/libdiscover/backends/ApplicationBackend/Application.h b/libdiscover/backends/ApplicationBackend/Application.h
index ff62564..01e1dbe 100644
--- a/libdiscover/backends/ApplicationBackend/Application.h
+++ b/libdiscover/backends/ApplicationBackend/Application.h
@@ -27,6 +27,7 @@
#include <KService>
+#include <AppstreamQt/component.h>
#include <QApt/Package>
#include "discovercommon_export.h"
@@ -43,11 +44,10 @@ class DISCOVERCOMMON_EXPORT Application : public AbstractResource
Q_OBJECT
Q_PROPERTY(QString menuPath READ menuPath CONSTANT)
public:
- explicit Application(const QString &fileName, QApt::Backend *backend);
+ explicit Application(const Appstream::Component &component, QApt::Backend *backend);
explicit Application(QApt::Package *package, QApt::Backend *backend);
QString name();
- QString untranslatedName();
QString comment();
QApt::Package *package();
QString icon() const;
@@ -91,19 +91,19 @@ public:
virtual void fetchChangelog();
bool isFromSecureOrigin() const;
- QByteArray getField(const char* field, const QByteArray& defaultvalue = QByteArray()) const;
private Q_SLOTS:
void processChangelog(KJob*);
void downloadingScreenshotsFinished(KJob*);
private:
+ QApt::Backend *backend() const;
+ QStringList findProvides(Appstream::Provides::Kind kind) const;
QString buildDescription(const QByteArray& data, const QString& source);
- QSharedPointer<KConfig> m_data;
- QApt::Backend *m_backend;
+ const Appstream::Component m_data;
QApt::Package *m_package;
- QByteArray m_packageName;
+ QString m_packageName;
bool m_isValid;
bool m_isTechnical;
@@ -112,7 +112,6 @@ private:
QApt::PackageList addons();
QVector<QPair<QString, QString> > locateApplication(const QString &_relPath, const QString &menuId) const;
- bool hasField(const char* field) const;
};
#endif
diff --git a/libdiscover/backends/ApplicationBackend/ApplicationBackend.cpp b/libdiscover/backends/ApplicationBackend/ApplicationBackend.cpp
index af4f88a..42c6a93 100644
--- a/libdiscover/backends/ApplicationBackend/ApplicationBackend.cpp
+++ b/libdiscover/backends/ApplicationBackend/ApplicationBackend.cpp
@@ -41,6 +41,8 @@
#include <KIconLoader>
#include <KXmlGuiWindow>
+#include <AppstreamQt/database.h>
+
// QApt/DebconfKDE includes
#include <QApt/Backend>
#include <QApt/Transaction>
@@ -61,8 +63,6 @@
#include <resources/SourcesModel.h>
#include <MuonDataSources.h>
-// static const KCatalogLoader loader("app-install-data"); //FIXME port
-
MUON_BACKEND_PLUGIN(ApplicationBackend)
ApplicationBackend::ApplicationBackend(QObject* parent)
@@ -91,13 +91,14 @@ ApplicationBackend::~ApplicationBackend()
QVector<Application *> init(QApt::Backend *backend, QThread* thread)
{
- QDir appDir(QStringLiteral("/usr/share/app-install/desktop/"));
- QStringList fileList = appDir.entryList(QStringList(QStringLiteral("*.desktop")), QDir::Files);
+ Appstream::Database appdata;
+ bool opened = appdata.open();
+ Q_ASSERT(opened);
QVector<Application *> tempList;
QSet<QString> packages;
- foreach(const QString &fileName, fileList) {
- Application *app = new Application(appDir.filePath(fileName), backend);
+ foreach(const Appstream::Component &component, appdata.allComponents()) {
+ Application *app = new Application(component, backend);
packages.insert(app->packageName());
tempList << app;
}
diff --git a/libdiscover/backends/ApplicationBackend/CMakeLists.txt b/libdiscover/backends/ApplicationBackend/CMakeLists.txt
index 0262137..0c0eda6 100644
--- a/libdiscover/backends/ApplicationBackend/CMakeLists.txt
+++ b/libdiscover/backends/ApplicationBackend/CMakeLists.txt
@@ -20,7 +20,7 @@ qt5_add_dbus_interface(appsbackend_SRCS ubuntu_sso_dbus_interface.xml ubuntu_sso
add_library(qapt-backend MODULE ${appsbackend_SRCS})
target_link_libraries(qapt-backend Qt5::Widgets Qt5::DBus Qt5::Concurrent
- KF5::Archive KF5::KIOWidgets KF5::XmlGui DebconfKDE::Main KF5::IconThemes
+ KF5::Archive KF5::KIOWidgets KF5::XmlGui DebconfKDE::Main KF5::IconThemes AppstreamQt
Muon::QOAuth QApt::Main Discover::Common MuonApt
)
target_include_directories(qapt-backend PRIVATE /usr/include/Qca-qt5/QtCrypto)
More information about the kubuntu-devel
mailing list