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);
48
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();
55
#endif //HAVE_APPSTREAM
58
AppStream::~AppStream()
61
g_object_unref(m_asDB);
62
g_object_unref(m_asScreenshots);
66
bool AppStream::open()
69
bool ret = appstream_database_open(m_asDB);
71
qWarning("Unable to open AppStream Xapian database!");
75
// cache application data (we might use the db directly, later (making use of AppstreamSearchQuery))
77
appArray = appstream_database_get_all_applications(m_asDB);
78
if (appArray == NULL) {
79
qWarning("AppStream application array way NULL! (This should never happen)");
83
for (uint i = 0; i < appArray->len; i++) {
84
AppstreamAppInfo *appInfo;
85
appInfo = (AppstreamAppInfo*) g_ptr_array_index(appArray, i);
89
app.name = QString::fromUtf8(appstream_app_info_get_name(appInfo));
92
QString pkgName = QString::fromUtf8(appstream_app_info_get_pkgname(appInfo));
95
app.id = QString::fromUtf8(appstream_app_info_get_desktop_file(appInfo));
98
app.summary = QString::fromUtf8(appstream_app_info_get_summary(appInfo));
100
// Application stock icon
101
app.icon = QString::fromUtf8(appstream_app_info_get_icon(appInfo));
103
// Application categories
105
gchar **cats = appstream_app_info_get_categories(appInfo, &clen);
107
app.categories = QStringList();
108
for (int j = 0; j < clen; j++) {
109
app.categories << QString::fromUtf8(cats[j]);
114
m_appInfo.insertMulti(pkgName, app);
116
g_ptr_array_unref(appArray);
124
QList<AppStream::Application> AppStream::applications(const QString &pkgName) const
126
return m_appInfo.values(pkgName);;
129
QString AppStream::genericIcon(const QString &pkgName) const
131
if (m_appInfo.contains(pkgName)) {
132
foreach (const Application &app, applications(pkgName)) {
133
if (!app.icon.isEmpty()) {
142
QStringList AppStream::findPkgNames(const CategoryMatcher &parser) const
144
QStringList packages;
146
QHash<QString, Application>::const_iterator i = m_appInfo.constBegin();
147
while (i != m_appInfo.constEnd()) {
148
if (parser.match(i.value().categories)) {
149
// kDebug() << i.key() << categories;
158
QString AppStream::thumbnail(const QString &pkgName) const
160
#ifdef HAVE_APPSTREAM
161
const gchar *url = appstream_screenshot_service_get_thumbnail_url(m_asScreenshots, pkgName.toLatin1().data());
162
return QLatin1String(url);
166
#endif //HAVE_APPSTREAM
169
QString AppStream::screenshot(const QString &pkgName) const
171
#ifdef HAVE_APPSTREAM
172
const gchar *url = appstream_screenshot_service_get_screenshot_url(m_asScreenshots, pkgName.toLatin1().data());
173
return QLatin1String(url);
177
#endif //HAVE_APPSTREAM