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

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.
parent f2a950b6
......@@ -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)
......
......@@ -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();
}
......@@ -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
......@@ -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;
}
......
......@@ -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)
......
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