1
/***************************************************************************
2
* Copyright (C) 2010 by Daniel Nicoletti <dantti12@gmail.com> *
3
* Copyright (C) 2012-2013 by Matthias Klumpp <matthias@tenstral.net> *
5
* This program is free software; you can redistribute it and/or *
6
* modify it under the terms of the GNU General Public License as *
7
* published by the Free Software Foundation; either version 2 of *
8
* the License or (at your option) version 3 or any later version *
9
* accepted by the membership of KDE e.V. (or its successor approved *
10
* by the membership of KDE e.V.), which shall act as a proxy *
11
* defined in Section 14 of version 3 of the license. *
13
* This program is distributed in the hope that it will be useful, *
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16
* GNU General Public License for more details. *
18
* You should have received a copy of the GNU General Public License *
19
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
20
***************************************************************************/
24
#include <appstream.h>
26
#include "AppStream.h"
28
#include <QApplication>
30
#include <QStringBuilder>
36
AppStream* AppStream::m_instance = 0;
38
AppStream* AppStream::instance()
41
m_instance = new AppStream(qApp);
46
AppStream::AppStream(QObject *parent)
52
// create new AppStream database and screenshot service
53
m_asDB = appstream_database_new();
54
m_asScreenshots = appstream_screenshot_service_new();
56
ret = appstream_database_open(m_asDB);
58
qWarning("Unable to open AppStream Xapian database!");
62
// cache application data (we might use the db directly, later (making use of AppstreamSearchQuery))
63
GPtrArray *appArray = NULL;
64
appArray = appstream_database_get_all_applications(m_asDB);
66
for (uint i = 0; i < appArray->len; i++) {
67
AppstreamAppInfo *appInfo;
68
appInfo = (AppstreamAppInfo*) g_ptr_array_index(appArray, i);
72
app.name = QString::fromUtf8(appstream_app_info_get_name(appInfo));
75
QString pkgName = QString::fromUtf8(appstream_app_info_get_pkgname(appInfo));
78
app.id = QString::fromUtf8(appstream_app_info_get_desktop_file(appInfo));
81
app.summary = QString::fromUtf8(appstream_app_info_get_summary(appInfo));
83
// Application stock icon
84
app.icon = QString::fromUtf8(appstream_app_info_get_icon(appInfo));
86
// Application categories
88
gchar **cats = appstream_app_info_get_categories(appInfo, &clen);
90
app.categories = QStringList();
91
for (int j = 0; j < clen; j++) {
92
app.categories << QString::fromUtf8(cats[j]);
97
m_appInfo.insertMulti(pkgName, app);
99
g_ptr_array_unref(appArray);
101
#endif //HAVE_APPSTREAM
104
AppStream::~AppStream()
106
#ifdef HAVE_APPSTREAM
107
g_object_unref(m_asDB);
108
g_object_unref(m_asScreenshots);
112
QList<AppStream::Application> AppStream::applications(const QString &pkgName) const
114
return m_appInfo.values(pkgName);;
117
QString AppStream::genericIcon(const QString &pkgName) const
119
if (m_appInfo.contains(pkgName)) {
120
foreach (const Application &app, applications(pkgName)) {
121
if (!app.icon.isEmpty()) {
130
QStringList AppStream::findPkgNames(const CategoryMatcher &parser) const
132
QStringList packages;
134
QHash<QString, Application>::const_iterator i = m_appInfo.constBegin();
135
while (i != m_appInfo.constEnd()) {
136
if (parser.match(i.value().categories)) {
137
// kDebug() << i.key() << categories;
146
QString AppStream::thumbnail(const QString &pkgName) const
148
#ifdef HAVE_APPSTREAM
149
const gchar *url = appstream_screenshot_service_get_thumbnail_url(m_asScreenshots, pkgName.toLatin1().data());
150
return QLatin1String(url);
154
#endif //HAVE_APPSTREAM
157
QString AppStream::screenshot(const QString &pkgName) const
159
#ifdef HAVE_APPSTREAM
160
const gchar *url = appstream_screenshot_service_get_screenshot_url(m_asScreenshots, pkgName.toLatin1().data());
161
return QLatin1String(url);
165
#endif //HAVE_APPSTREAM