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 nullptr, nullptr, /* 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, nullptr));
60 return HudClientStub::m_query;
63DeeModel *hud_client_query_get_results_model(HudClientQuery *cquery)
65 Q_ASSERT(cquery == HudClientStub::m_query);
68 resultsModel = dee_sequence_model_new();
69 dee_model_set_schema_full(resultsModel, results_model_schema, G_N_ELEMENTS(results_model_schema));
71 GVariant * columns[G_N_ELEMENTS(results_model_schema) + 1];
72 columns[0] = g_variant_new_variant(g_variant_new_uint64(0));
73 columns[1] = g_variant_new_string("Help");
74 columns[2] = g_variant_new_array(G_VARIANT_TYPE("(ii)"), nullptr, 0);
75 columns[3] = g_variant_new_string("Get Help");
76 columns[4] = g_variant_new_array(G_VARIANT_TYPE("(ii)"), nullptr, 0);
77 columns[5] = g_variant_new_string("");
78 columns[6] = g_variant_new_uint32(3);
79 columns[7] = g_variant_new_boolean(false);
81 dee_model_append_row(resultsModel, columns);
83 columns[0] = g_variant_new_variant(g_variant_new_uint64(1));
84 columns[1] = g_variant_new_string("About");
85 columns[3] = g_variant_new_string("Show About");
86 dee_model_append_row(resultsModel, columns);
88 columns[0] = g_variant_new_variant(g_variant_new_uint64(2));
89 columns[1] = g_variant_new_string("Foo");
90 columns[3] = g_variant_new_string("Show Foo");
91 columns[7] = g_variant_new_boolean(true);
92 dee_model_append_row(resultsModel, columns);
94 columns[0] = g_variant_new_variant(g_variant_new_uint64(3));
95 columns[1] = g_variant_new_string("Bar");
96 columns[3] = g_variant_new_string("Show Bar");
97 columns[7] = g_variant_new_boolean(false);
98 dee_model_append_row(resultsModel, columns);
100 columns[0] = g_variant_new_variant(g_variant_new_uint64(4));
101 columns[1] = g_variant_new_string("FooBar");
102 columns[3] = g_variant_new_string("Show FooBar");
103 dee_model_append_row(resultsModel, columns);
105 columns[0] = g_variant_new_variant(g_variant_new_uint64(5));
106 columns[1] = g_variant_new_string("UltraFooBar");
107 columns[3] = g_variant_new_string("Show UltraFooBar");
108 dee_model_append_row(resultsModel, columns);
113void hud_client_query_execute_toolbar_item(HudClientQuery *cquery, HudClientQueryToolbarItems item, guint timestamp)
115 Q_ASSERT(cquery == HudClientStub::m_query);
118 HudClientStub::m_lastExecutedToolbarItem = item;
121void hud_client_query_set_query(HudClientQuery *cquery, const char *query)
123 Q_ASSERT(cquery == HudClientStub::m_query);
125 HudClientStub::m_lastSetQuery = QString::fromUtf8(query);
128void hud_client_query_execute_command(HudClientQuery *cquery, GVariant *command_key, guint timestamp)
130 Q_ASSERT(cquery == HudClientStub::m_query);
133 for (uint i = 0; i < dee_model_get_n_rows(resultsModel); ++i) {
134 DeeModelIter *iter = dee_model_get_iter_at_row(resultsModel, i);
135 if (!dee_model_get_bool(resultsModel, iter, 7)) {
136 GVariant *it_command = dee_model_get_value(resultsModel, iter, 0);
137 if (g_variant_equal (command_key, it_command)) {
138 HudClientStub::m_lastExecutedCommandRow = i;
139 g_variant_unref(it_command);
142 g_variant_unref(it_command);
145 HudClientStub::m_lastExecutedCommandRow = -1;
148HudClientParam *hud_client_query_execute_param_command(HudClientQuery *cquery, GVariant *command_key, guint timestamp)
150 Q_ASSERT(cquery == HudClientStub::m_query);
153 for (uint i = 0; i < dee_model_get_n_rows(resultsModel); ++i) {
154 DeeModelIter *iter = dee_model_get_iter_at_row(resultsModel, i);
155 if (dee_model_get_bool(resultsModel, iter, 7)) {
156 GVariant *it_command = dee_model_get_value(resultsModel, iter, 0);
157 if (g_variant_equal (command_key, it_command)) {
158 HudClientStub::m_lastExecutedParametrizedCommandRow = i;
159 g_variant_unref(it_command);
160 // No need to create a real HudClientParam since it's always passed down to us
161 return (HudClientParam *)g_object_new(G_TYPE_OBJECT, nullptr);
163 g_variant_unref(it_command);
166 HudClientStub::m_lastExecutedParametrizedCommandRow = -1;
170void hud_client_query_voice_query(HudClientQuery *cquery)
172 Q_ASSERT(cquery == HudClientStub::m_query);
174 // TODO We are not testing voice queries yet
177gboolean hud_client_query_toolbar_item_active(HudClientQuery *cquery, HudClientQueryToolbarItems item)
179 Q_ASSERT(cquery == HudClientStub::m_query);
181 if (item == HUD_CLIENT_QUERY_TOOLBAR_HELP)
182 return HudClientStub::m_helpToolbarItemEnabled;
187GMenuModel *hud_client_param_get_model(HudClientParam *param)
191 if (!parametrizedActionModel) {
192 GMenu *menu = g_menu_new();
193 GMenuItem *item = g_menu_item_new("Item1Label", nullptr);
194 g_menu_item_set_attribute_value(item, "parameter-type", g_variant_new_string("slider"));
195 g_menu_item_set_attribute_value(item, "min", g_variant_new_double(10));
196 g_menu_item_set_attribute_value(item, "max", g_variant_new_double(80));
197 g_menu_item_set_attribute_value(item, "live", g_variant_new_boolean(true));
198 g_menu_item_set_attribute_value(item, "value", g_variant_new_double(75));
199 g_menu_item_set_attribute_value(item, "action", g_variant_new_string("costAction"));
200 g_menu_append_item (menu, item);
202 parametrizedActionModel = G_MENU_MODEL(menu);
205 return parametrizedActionModel;
208void hud_client_param_send_cancel(HudClientParam *param)
211 g_clear_object(¶metrizedActionModel);
212 parametrizedActionModel = 0;
213 HudClientStub::m_lastParametrizedCommandCommited = false;
216static void on_signal_activated (GSimpleAction *action, GVariant *parameter, gpointer /*user_data*/)
218 // Only double for the moment
219 HudClientStub::m_activatedActions.insert(g_action_get_name(G_ACTION(action)), QVariant(g_variant_get_double(parameter)));
222GActionGroup *hud_client_param_get_actions(HudClientParam *param)
225 if (!parametrizedActionGroup) {
226 GSimpleActionGroup *actionGroup = g_simple_action_group_new();
227 GSimpleAction *action = g_simple_action_new("costAction", G_VARIANT_TYPE_DOUBLE);
228 g_action_map_add_action(G_ACTION_MAP(actionGroup), G_ACTION(action));
230 g_signal_connect (action, "activate", G_CALLBACK (on_signal_activated), nullptr);
233 parametrizedActionGroup = G_ACTION_GROUP(actionGroup);
236 return parametrizedActionGroup;
239void hud_client_param_send_commit(HudClientParam *param)
242 g_object_unref(parametrizedActionGroup);
243 parametrizedActionGroup = 0;
244 g_clear_object(¶metrizedActionModel);
245 parametrizedActionModel = 0;
246 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