2 * Copyright (C) 2012, 2013 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17#include <hud-client.h>
19#include "libhud_client_stub.h"
21/* Schema that is used in the DeeModel representing
23static const gchar * results_model_schema[] = {
25 "s", /* Command Name */
26 "a(ii)", /* Highlights in command name */
27 "s", /* Description */
28 "a(ii)", /* Highlights in description */
31 "b", /* Parameterized */
34DeeModel *resultsModel = 0;
35GMenuModel *parametrizedActionModel = 0;
36GActionGroup *parametrizedActionGroup = 0;
38static void hud_client_query_class_init(HudClientQueryClass *klass);
39static void hud_client_query_init(HudClientQuery *self);
40G_DEFINE_TYPE(HudClientQuery, hud_client_query, G_TYPE_OBJECT)
42static void hud_client_query_init(HudClientQuery * /*self*/)
45static void hud_client_query_class_init(HudClientQueryClass * /*klass*/)
47 HudClientStub::m_querySignalToolbarUpdated = g_signal_new (HUD_CLIENT_QUERY_SIGNAL_TOOLBAR_UPDATED,
48 HUD_CLIENT_TYPE_QUERY,
51 NULL, NULL, /* Accumulator */
52 g_cclosure_marshal_VOID__VOID,
53 G_TYPE_NONE, 0, G_TYPE_NONE);
56HudClientQuery *hud_client_query_new(const gchar *query)
58 HudClientStub::m_lastSetQuery = QString::fromUtf8(query);
59 HudClientStub::m_query = HUD_CLIENT_QUERY(g_object_new(HUD_CLIENT_TYPE_QUERY, NULL));
60 return HudClientStub::m_query;
63DeeModel *hud_client_query_get_results_model(HudClientQuery *cquery)
65 Q_ASSERT(cquery == HudClientStub::m_query);
67 resultsModel = dee_sequence_model_new();
68 dee_model_set_schema_full(resultsModel, results_model_schema, G_N_ELEMENTS(results_model_schema));
70 GVariant * columns[G_N_ELEMENTS(results_model_schema) + 1];
71 columns[0] = g_variant_new_variant(g_variant_new_uint64(0));
72 columns[1] = g_variant_new_string("Help");
73 columns[2] = g_variant_new_array(G_VARIANT_TYPE("(ii)"), NULL, 0);
74 columns[3] = g_variant_new_string("Get Help");
75 columns[4] = g_variant_new_array(G_VARIANT_TYPE("(ii)"), NULL, 0);
76 columns[5] = g_variant_new_string("");
77 columns[6] = g_variant_new_uint32(3);
78 columns[7] = g_variant_new_boolean(false);
80 dee_model_append_row(resultsModel, columns);
82 columns[0] = g_variant_new_variant(g_variant_new_uint64(1));
83 columns[1] = g_variant_new_string("About");
84 columns[3] = g_variant_new_string("Show About");
85 dee_model_append_row(resultsModel, columns);
87 columns[0] = g_variant_new_variant(g_variant_new_uint64(2));
88 columns[1] = g_variant_new_string("Foo");
89 columns[3] = g_variant_new_string("Show Foo");
90 columns[7] = g_variant_new_boolean(true);
91 dee_model_append_row(resultsModel, columns);
93 columns[0] = g_variant_new_variant(g_variant_new_uint64(3));
94 columns[1] = g_variant_new_string("Bar");
95 columns[3] = g_variant_new_string("Show Bar");
96 columns[7] = g_variant_new_boolean(false);
97 dee_model_append_row(resultsModel, columns);
99 columns[0] = g_variant_new_variant(g_variant_new_uint64(4));
100 columns[1] = g_variant_new_string("FooBar");
101 columns[3] = g_variant_new_string("Show FooBar");
102 dee_model_append_row(resultsModel, columns);
104 columns[0] = g_variant_new_variant(g_variant_new_uint64(5));
105 columns[1] = g_variant_new_string("UltraFooBar");
106 columns[3] = g_variant_new_string("Show UltraFooBar");
107 dee_model_append_row(resultsModel, columns);
112void hud_client_query_execute_toolbar_item(HudClientQuery *cquery, HudClientQueryToolbarItems item, guint timestamp)
114 Q_ASSERT(cquery == HudClientStub::m_query);
116 HudClientStub::m_lastExecutedToolbarItem = item;
119void hud_client_query_set_query(HudClientQuery *cquery, const char *query)
121 Q_ASSERT(cquery == HudClientStub::m_query);
122 HudClientStub::m_lastSetQuery = QString::fromUtf8(query);
125void hud_client_query_execute_command(HudClientQuery *cquery, GVariant *command_key, guint timestamp)
127 Q_ASSERT(cquery == HudClientStub::m_query);
129 for (uint i = 0; i < dee_model_get_n_rows(resultsModel); ++i) {
130 DeeModelIter *iter = dee_model_get_iter_at_row(resultsModel, i);
131 if (!dee_model_get_bool(resultsModel, iter, 7)) {
132 GVariant *it_command = dee_model_get_value(resultsModel, iter, 0);
133 if (g_variant_equal (command_key, it_command)) {
134 HudClientStub::m_lastExecutedCommandRow = i;
135 g_variant_unref(it_command);
138 g_variant_unref(it_command);
141 HudClientStub::m_lastExecutedCommandRow = -1;
144HudClientParam *hud_client_query_execute_param_command(HudClientQuery *cquery, GVariant *command_key, guint timestamp)
146 Q_ASSERT(cquery == HudClientStub::m_query);
148 for (uint i = 0; i < dee_model_get_n_rows(resultsModel); ++i) {
149 DeeModelIter *iter = dee_model_get_iter_at_row(resultsModel, i);
150 if (dee_model_get_bool(resultsModel, iter, 7)) {
151 GVariant *it_command = dee_model_get_value(resultsModel, iter, 0);
152 if (g_variant_equal (command_key, it_command)) {
153 HudClientStub::m_lastExecutedParametrizedCommandRow = i;
154 g_variant_unref(it_command);
155 // No need to create a real HudClientParam since it's always passed down to us
156 return (HudClientParam *)g_object_new(G_TYPE_OBJECT, NULL);
158 g_variant_unref(it_command);
161 HudClientStub::m_lastExecutedParametrizedCommandRow = -1;
165void hud_client_query_voice_query(HudClientQuery *cquery)
167 Q_ASSERT(cquery == HudClientStub::m_query);
168 // TODO We are not testing voice queries yet
171gboolean hud_client_query_toolbar_item_active(HudClientQuery *cquery, HudClientQueryToolbarItems item)
173 Q_ASSERT(cquery == HudClientStub::m_query);
174 if (item == HUD_CLIENT_QUERY_TOOLBAR_HELP)
175 return HudClientStub::m_helpToolbarItemEnabled;
180GMenuModel *hud_client_param_get_model(HudClientParam *param)
184 if (!parametrizedActionModel) {
185 GMenu *menu = g_menu_new();
186 GMenuItem *item = g_menu_item_new("Item1Label", NULL);
187 g_menu_item_set_attribute_value(item, "parameter-type", g_variant_new_string("slider"));
188 g_menu_item_set_attribute_value(item, "min", g_variant_new_double(10));
189 g_menu_item_set_attribute_value(item, "max", g_variant_new_double(80));
190 g_menu_item_set_attribute_value(item, "live", g_variant_new_boolean(true));
191 g_menu_item_set_attribute_value(item, "value", g_variant_new_double(75));
192 g_menu_item_set_attribute_value(item, "action", g_variant_new_string("costAction"));
193 g_menu_append_item (menu, item);
195 parametrizedActionModel = G_MENU_MODEL(menu);
198 return parametrizedActionModel;
201void hud_client_param_send_cancel(HudClientParam *param)
204 g_clear_object(¶metrizedActionModel);
205 parametrizedActionModel = 0;
206 HudClientStub::m_lastParametrizedCommandCommited = false;
209static void on_signal_activated (GSimpleAction *action, GVariant *parameter, gpointer /*user_data*/)
211 // Only double for the moment
212 HudClientStub::m_activatedActions.insert(g_action_get_name(G_ACTION(action)), QVariant(g_variant_get_double(parameter)));
215GActionGroup *hud_client_param_get_actions(HudClientParam *param)
218 if (!parametrizedActionGroup) {
219 GSimpleActionGroup *actionGroup = g_simple_action_group_new();
220 GSimpleAction *action = g_simple_action_new("costAction", G_VARIANT_TYPE_DOUBLE);
221 g_simple_action_group_insert(actionGroup, G_ACTION(action));
223 g_signal_connect (action, "activate", G_CALLBACK (on_signal_activated), NULL);
226 parametrizedActionGroup = G_ACTION_GROUP(actionGroup);
229 return parametrizedActionGroup;
232void hud_client_param_send_commit(HudClientParam *param)
235 g_object_unref(parametrizedActionGroup);
236 parametrizedActionGroup = 0;
237 g_clear_object(¶metrizedActionModel);
238 parametrizedActionModel = 0;
239 HudClientStub::m_lastParametrizedCommandCommited = true;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list