~ubuntu-branches/ubuntu/trusty/hud/trusty-updates

« back to all changes in this revision

Viewing changes to common/AppstackModel.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-01-20 19:43:59 UTC
  • mfrom: (1.1.26)
  • Revision ID: package-import@ubuntu.com-20140120194359-jxxxqtd4ql9elvpf
Tags: 13.10.1+14.04.20140120-0ubuntu1
* New rebuild forced
* Automatic snapshot from revision 362

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Canonical, Ltd.
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or modify it under
 
5
 * the terms of version 3 of the GNU Lesser General Public License as published
 
6
 * by the Free Software Foundation.
 
7
 *
 
8
 * This library is distributed in the hope that it will be useful, but WITHOUT
 
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
10
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 
11
 * details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Author: Pete Woods <pete.woods@canonical.com>
 
17
 */
 
18
 
 
19
#include <common/query-columns.h>
 
20
#include <common/AppstackModel.h>
 
21
 
 
22
#include <QString>
 
23
#include <glib.h>
 
24
 
 
25
using namespace hud::common;
 
26
 
 
27
const QString APPSTACK_FORMAT_STRING("com.canonical.hud.query%1.appstack");
 
28
 
 
29
AppstackModel::AppstackModel(unsigned int id) :
 
30
                HudDee(APPSTACK_FORMAT_STRING.arg(id).toStdString()) {
 
31
        setSchema(appstack_model_schema, G_N_ELEMENTS(appstack_model_schema));
 
32
}
 
33
 
 
34
AppstackModel::~AppstackModel() {
 
35
}
 
36
 
 
37
static gint appstack_sort(GVariant **row1, GVariant **row2,
 
38
                gpointer user_data) {
 
39
        Q_UNUSED(user_data);
 
40
 
 
41
        gint32 type1 = g_variant_get_int32(row1[HUD_QUERY_APPSTACK_ITEM_TYPE]);
 
42
        gint32 type2 = g_variant_get_int32(row2[HUD_QUERY_APPSTACK_ITEM_TYPE]);
 
43
 
 
44
        /* If the types are the same, we'll sort by ID */
 
45
        if (type1 == type2) {
 
46
                const gchar * app_id1 = g_variant_get_string(
 
47
                                row1[HUD_QUERY_APPSTACK_APPLICATION_ID], NULL);
 
48
                const gchar * app_id2 = g_variant_get_string(
 
49
                                row2[HUD_QUERY_APPSTACK_APPLICATION_ID], NULL);
 
50
 
 
51
                return g_strcmp0(app_id1, app_id2);
 
52
        }
 
53
 
 
54
        return type1 - type2;
 
55
}
 
56
 
 
57
void AppstackModel::addApplication(const QString &applicationId,
 
58
                const QString &iconName, ItemType itemType) {
 
59
        GVariant * columns[HUD_QUERY_APPSTACK_COUNT + 1];
 
60
        columns[HUD_QUERY_APPSTACK_APPLICATION_ID] = g_variant_new_string(
 
61
                        applicationId.toUtf8().data());
 
62
        columns[HUD_QUERY_APPSTACK_ICON_NAME] = g_variant_new_string(
 
63
                        iconName.toUtf8().data());
 
64
        columns[HUD_QUERY_APPSTACK_ITEM_TYPE] = g_variant_new_int32(itemType);
 
65
        columns[HUD_QUERY_APPSTACK_COUNT] = NULL;
 
66
 
 
67
        insertRowSorted(columns, appstack_sort);
 
68
}