~ubuntu-branches/debian/stretch/apper/stretch

« back to all changes in this revision

Viewing changes to .pc/01_appstream-0.6.patch/libapper/AppStream.cpp

  • Committer: Package Import Robot
  • Author(s): Matthias Klumpp
  • Date: 2014-04-20 14:42:30 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140420144230-6qghsh10mvw17o87
Tags: 0.8.2-1
* New upstream bugfix release: 0.8.2
* Update debian/watch file
* Drop all patches: Applied upstream
* Build with autoremove enabled
* Bump standards version: No changes needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2010 by Daniel Nicoletti <dantti12@gmail.com>           *
3
 
 *   Copyright (C) 2012-2013 by Matthias Klumpp <matthias@tenstral.net>    *
4
 
 *                                                                         *
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.                    *
12
 
 *                                                                         *
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.                          *
17
 
 *                                                                         *
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
 
 ***************************************************************************/
21
 
 
22
 
#include <config.h>
23
 
 
24
 
#include <appstream.h>
25
 
 
26
 
#include "AppStream.h"
27
 
 
28
 
#include <QApplication>
29
 
#include <QVariant>
30
 
#include <QStringBuilder>
31
 
 
32
 
#include <KLocale>
33
 
#include <KGlobal>
34
 
#include <KDebug>
35
 
 
36
 
AppStream* AppStream::m_instance = 0;
37
 
 
38
 
AppStream* AppStream::instance()
39
 
{
40
 
    if(!m_instance)
41
 
        m_instance = new AppStream(qApp);
42
 
 
43
 
    return m_instance;
44
 
}
45
 
 
46
 
AppStream::AppStream(QObject *parent)
47
 
 : QObject(parent)
48
 
{
49
 
#ifdef HAVE_APPSTREAM
50
 
    bool ret;
51
 
 
52
 
    // create new AppStream database and screenshot service
53
 
    m_asDB = appstream_database_new();
54
 
    m_asScreenshots = appstream_screenshot_service_new();
55
 
 
56
 
    ret = appstream_database_open(m_asDB);
57
 
    if (!ret) {
58
 
        qWarning("Unable to open AppStream Xapian database!");
59
 
        return;
60
 
    }
61
 
 
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);
65
 
 
66
 
    for (uint i = 0; i < appArray->len; i++) {
67
 
        AppstreamAppInfo *appInfo;
68
 
        appInfo = (AppstreamAppInfo*) g_ptr_array_index(appArray, i);
69
 
 
70
 
        Application app;
71
 
        // Application name
72
 
        app.name = QString::fromUtf8(appstream_app_info_get_name(appInfo));
73
 
 
74
 
        // Package name
75
 
        QString pkgName = QString::fromUtf8(appstream_app_info_get_pkgname(appInfo));
76
 
 
77
 
        // Desktop file
78
 
        app.id = QString::fromUtf8(appstream_app_info_get_desktop_file(appInfo));
79
 
 
80
 
        // Summary
81
 
        app.summary = QString::fromUtf8(appstream_app_info_get_summary(appInfo));
82
 
 
83
 
        // Application stock icon
84
 
        app.icon = QString::fromUtf8(appstream_app_info_get_icon(appInfo));
85
 
 
86
 
        // Application categories
87
 
        int clen;
88
 
        gchar **cats = appstream_app_info_get_categories(appInfo, &clen);
89
 
        if (cats != NULL) {
90
 
            app.categories = QStringList();
91
 
            for (int j = 0; j < clen; j++) {
92
 
                app.categories << QString::fromUtf8(cats[j]);
93
 
            }
94
 
        }
95
 
        g_strfreev(cats);
96
 
 
97
 
        m_appInfo.insertMulti(pkgName, app);
98
 
    }
99
 
    g_ptr_array_unref(appArray);
100
 
 
101
 
#endif //HAVE_APPSTREAM
102
 
}
103
 
 
104
 
AppStream::~AppStream()
105
 
{
106
 
#ifdef HAVE_APPSTREAM
107
 
    g_object_unref(m_asDB);
108
 
    g_object_unref(m_asScreenshots);
109
 
#endif
110
 
}
111
 
 
112
 
QList<AppStream::Application> AppStream::applications(const QString &pkgName) const
113
 
{
114
 
    return m_appInfo.values(pkgName);;
115
 
}
116
 
 
117
 
QString AppStream::genericIcon(const QString &pkgName) const
118
 
{
119
 
    if (m_appInfo.contains(pkgName)) {
120
 
        foreach (const Application &app, applications(pkgName)) {
121
 
            if (!app.icon.isEmpty()) {
122
 
                return app.icon;
123
 
            }
124
 
        }
125
 
    }
126
 
 
127
 
    return QString();
128
 
}
129
 
 
130
 
QStringList AppStream::findPkgNames(const CategoryMatcher &parser) const
131
 
{
132
 
    QStringList packages;
133
 
 
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;
138
 
            packages << i.key();
139
 
        }
140
 
        ++i;
141
 
    }
142
 
 
143
 
    return packages;
144
 
}
145
 
 
146
 
QString AppStream::thumbnail(const QString &pkgName) const
147
 
{
148
 
#ifdef HAVE_APPSTREAM
149
 
    const gchar *url = appstream_screenshot_service_get_thumbnail_url(m_asScreenshots, pkgName.toLatin1().data());
150
 
    return QLatin1String(url);
151
 
#else
152
 
    Q_UNUSED(pkgName)
153
 
    return QString();
154
 
#endif //HAVE_APPSTREAM
155
 
}
156
 
 
157
 
QString AppStream::screenshot(const QString &pkgName) const
158
 
{
159
 
#ifdef HAVE_APPSTREAM
160
 
    const gchar *url = appstream_screenshot_service_get_screenshot_url(m_asScreenshots, pkgName.toLatin1().data());
161
 
    return QLatin1String(url);
162
 
#else
163
 
    Q_UNUSED(pkgName)
164
 
    return QString();
165
 
#endif //HAVE_APPSTREAM
166
 
}