2
* Copyright (C) 2013 Canonical, Ltd.
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.
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
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/>.
16
* Author: Pete Woods <pete.woods@canonical.com>
19
#include <common/query-columns.h>
20
#include <common/AppstackModel.h>
25
using namespace hud::common;
27
const QString APPSTACK_FORMAT_STRING("com.canonical.hud.query%1.appstack");
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));
34
AppstackModel::~AppstackModel() {
37
static gint appstack_sort(GVariant **row1, GVariant **row2,
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]);
44
/* If the types are the same, we'll sort by ID */
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);
51
return g_strcmp0(app_id1, app_id2);
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;
67
insertRowSorted(columns, appstack_sort);