~jbicha/hud/build-depend-on-valac-not-gir

« back to all changes in this revision

Viewing changes to libhud-client/query.c

  • Committer: Tarmac
  • Author(s): Ted Gould, Pete Woods, Antti Kaijanmäki, Ted Gould, Albert Astals, Ryan Lortie, Łukasz 'sil2100' Zemczak, Albert Astals Cid, Mathieu Trudel-Lapierre, Kaleo, Tarmac, Ricardo Salveti de Araujo, Michael Terry, Automatic PS uploader
  • Date: 2013-04-10 16:04:51 UTC
  • mfrom: (227.3.148 phablet)
  • Revision ID: tarmac-20130410160451-o3owpv3zaxulm5of
HUD 2.0 Merge.

Approved by PS Jenkins bot, Mathieu Trudel-Lapierre.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2012 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License version 3, as
 
6
 * published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
11
 * PURPOSE.  See the GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License along
 
14
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Author: Ted Gould <ted@canonical.com>
 
17
 */
 
18
 
 
19
#ifdef HAVE_CONFIG_H
 
20
#include "config.h"
 
21
#endif
 
22
 
 
23
#include <dee.h>
 
24
 
 
25
#include "query.h"
 
26
#include "connection.h"
 
27
#include "query-iface.h"
 
28
#include "enum-types.h"
 
29
#include "query-columns.h"
 
30
 
 
31
struct _HudClientQueryPrivate {
 
32
        _HudQueryComCanonicalHudQuery * proxy;
 
33
        HudClientConnection * connection;
 
34
        guint connection_changed_sig;
 
35
        gchar * query;
 
36
        DeeModel * results;
 
37
        DeeModel * appstack;
 
38
};
 
39
 
 
40
#define HUD_CLIENT_QUERY_GET_PRIVATE(o) \
 
41
(G_TYPE_INSTANCE_GET_PRIVATE ((o), HUD_CLIENT_TYPE_QUERY, HudClientQueryPrivate))
 
42
 
 
43
enum {
 
44
        PROP_0 = 0,
 
45
        PROP_CONNECTION,
 
46
        PROP_QUERY,
 
47
};
 
48
 
 
49
#define PROP_CONNECTION_S  "connection"
 
50
#define PROP_QUERY_S       "query"
 
51
 
 
52
static void hud_client_query_class_init  (HudClientQueryClass *klass);
 
53
static void hud_client_query_init        (HudClientQuery *self);
 
54
static void hud_client_query_constructed (GObject *object);
 
55
static void hud_client_query_dispose     (GObject *object);
 
56
static void hud_client_query_finalize    (GObject *object);
 
57
static void set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec);
 
58
static void get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec);
 
59
static void connection_status (HudClientConnection * connection, gboolean connected, HudClientQuery * query);
 
60
static void new_query_cb (HudClientConnection * connection, const gchar * path, const gchar * results, const gchar * appstack, gpointer user_data);
 
61
 
 
62
G_DEFINE_TYPE (HudClientQuery, hud_client_query, G_TYPE_OBJECT);
 
63
 
 
64
static guint signal_toolbar_updated = 0;
 
65
static guint hud_client_query_signal_voice_query_loading;
 
66
static guint hud_client_query_signal_voice_query_failed;
 
67
static guint hud_client_query_signal_voice_query_listening;
 
68
static guint hud_client_query_signal_voice_query_heard_something;
 
69
static guint hud_client_query_signal_voice_query_finished;
 
70
static guint hud_client_query_signal_models_changed = 0;
 
71
 
 
72
static void
 
73
hud_client_query_class_init (HudClientQueryClass *klass)
 
74
{
 
75
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
76
 
 
77
        g_type_class_add_private (klass, sizeof (HudClientQueryPrivate));
 
78
 
 
79
        object_class->dispose = hud_client_query_dispose;
 
80
        object_class->finalize = hud_client_query_finalize;
 
81
        object_class->constructed = hud_client_query_constructed;
 
82
        object_class->set_property = set_property;
 
83
        object_class->get_property = get_property;
 
84
 
 
85
        g_object_class_install_property (object_class, PROP_CONNECTION,
 
86
                                         g_param_spec_object(PROP_CONNECTION_S, "Connection to the HUD service",
 
87
                                                      "HUD service connection",
 
88
                                                      HUD_CLIENT_TYPE_CONNECTION,
 
89
                                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
 
90
        g_object_class_install_property (object_class, PROP_QUERY,
 
91
                                         g_param_spec_string(PROP_QUERY_S, "Query to the HUD service",
 
92
                                                      "HUD query",
 
93
                                                      NULL,
 
94
                                                      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
95
 
 
96
        /**
 
97
         * HudClientQuery::toolbar-updated:
 
98
         *
 
99
         * The active items in the toolbar changed.  Please requery.
 
100
         */
 
101
        signal_toolbar_updated = g_signal_new (HUD_CLIENT_QUERY_SIGNAL_TOOLBAR_UPDATED,
 
102
                                               HUD_CLIENT_TYPE_QUERY,
 
103
                                               G_SIGNAL_RUN_LAST,
 
104
                                               0, /* offset */
 
105
                                               NULL, NULL, /* Accumulator */
 
106
                                               g_cclosure_marshal_VOID__VOID,
 
107
                                               G_TYPE_NONE, 0, G_TYPE_NONE);
 
108
 
 
109
        /**
 
110
         * HudClientQuery::voice-query-loading:
 
111
         *
 
112
         * The voice recognition toolkit is loading, and not ready for speech yet.
 
113
         */
 
114
        hud_client_query_signal_voice_query_loading = g_signal_new (
 
115
                "voice-query-loading", HUD_CLIENT_TYPE_QUERY, G_SIGNAL_RUN_LAST, 0, NULL,
 
116
                NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
 
117
 
 
118
        /**
 
119
   * HudClientQuery::voice-query-failed:
 
120
   *
 
121
   * The voice recognition toolkit has failed to connect to the audio device.
 
122
   * The specific cause is provided as an argument.
 
123
   */
 
124
  hud_client_query_signal_voice_query_failed = g_signal_new (
 
125
    "voice-query-failed", HUD_CLIENT_TYPE_QUERY, G_SIGNAL_RUN_LAST, 0, NULL,
 
126
    NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING );
 
127
 
 
128
        /**
 
129
   * HudClientQuery::voice-query-listening:
 
130
   *
 
131
   * The voice recognition toolkit is active and listening for speech.
 
132
   */
 
133
        hud_client_query_signal_voice_query_listening = g_signal_new (
 
134
                "voice-query-listening", HUD_CLIENT_TYPE_QUERY, G_SIGNAL_RUN_LAST, 0,
 
135
                NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
 
136
 
 
137
        /**
 
138
   * HudClientQuery::voice-query-heard-something:
 
139
   *
 
140
   * The voice recognition toolkit has heard an utterance.
 
141
   */
 
142
  hud_client_query_signal_voice_query_heard_something = g_signal_new (
 
143
    "voice-query-heard-something", HUD_CLIENT_TYPE_QUERY, G_SIGNAL_RUN_LAST,
 
144
    0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
 
145
 
 
146
        /**
 
147
   * HudClientQuery::voice-query-finished:
 
148
   *
 
149
   * The voice recognition toolkit has completed and has a (possibly empty) result.
 
150
   */
 
151
        hud_client_query_signal_voice_query_finished = g_signal_new (
 
152
                "voice-query-finished", HUD_CLIENT_TYPE_QUERY, G_SIGNAL_RUN_LAST, 0, NULL,
 
153
                NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING );
 
154
 
 
155
        /**
 
156
         * HudClientQuery::models-changed:
 
157
         *
 
158
         * Something has caused the models to be changed, you should probably
 
159
         * figure out their state again.
 
160
         */
 
161
        hud_client_query_signal_models_changed = g_signal_new (
 
162
                HUD_CLIENT_QUERY_SIGNAL_MODELS_CHANGED, HUD_CLIENT_TYPE_QUERY, G_SIGNAL_RUN_LAST, 0, NULL,
 
163
                NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, G_TYPE_NONE );
 
164
 
 
165
        return;
 
166
}
 
167
 
 
168
static void
 
169
hud_client_query_init (HudClientQuery *self)
 
170
{
 
171
        self->priv = HUD_CLIENT_QUERY_GET_PRIVATE(self);
 
172
 
 
173
        return;
 
174
}
 
175
 
 
176
static void
 
177
set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec)
 
178
{
 
179
        HudClientQuery * self = HUD_CLIENT_QUERY(obj);
 
180
 
 
181
        switch (id) {
 
182
        case PROP_CONNECTION:
 
183
                g_clear_object(&self->priv->connection);
 
184
                self->priv->connection = g_value_dup_object(value);
 
185
                break;
 
186
        case PROP_QUERY:
 
187
                hud_client_query_set_query(self, g_value_get_string(value));
 
188
                break;
 
189
        default:
 
190
                g_warning("Unknown property %d.", id);
 
191
                return;
 
192
        }
 
193
 
 
194
        return;
 
195
}
 
196
 
 
197
static void
 
198
get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec)
 
199
{
 
200
        HudClientQuery * self = HUD_CLIENT_QUERY(obj);
 
201
 
 
202
        switch (id) {
 
203
        case PROP_CONNECTION:
 
204
                g_value_set_object(value, self->priv->connection);
 
205
                break;
 
206
        case PROP_QUERY:
 
207
                g_value_set_string(value, self->priv->query);
 
208
                break;
 
209
        default:
 
210
                g_warning("Unknown property %d.", id);
 
211
                return;
 
212
        }
 
213
 
 
214
        return;
 
215
}
 
216
 
 
217
static void
 
218
hud_client_query_voice_query_loading (_HudQueryComCanonicalHudQuery *object, gpointer user_data)
 
219
{
 
220
        g_signal_emit(user_data, hud_client_query_signal_voice_query_loading, 0);
 
221
}
 
222
 
 
223
static void
 
224
hud_client_query_voice_query_listening (_HudQueryComCanonicalHudQuery *object, gpointer user_data)
 
225
{
 
226
        g_signal_emit(user_data, hud_client_query_signal_voice_query_listening, 0);
 
227
}
 
228
 
 
229
static void
 
230
hud_client_query_voice_query_heard_something (_HudQueryComCanonicalHudQuery *object, gpointer user_data)
 
231
{
 
232
  g_signal_emit(user_data, hud_client_query_signal_voice_query_heard_something, 0);
 
233
}
 
234
 
 
235
static void
 
236
hud_client_query_constructed (GObject *object)
 
237
{
 
238
        HudClientQuery * cquery = HUD_CLIENT_QUERY(object);
 
239
 
 
240
        G_OBJECT_CLASS (hud_client_query_parent_class)->constructed (object);
 
241
 
 
242
        if (cquery->priv->connection == NULL) {
 
243
                cquery->priv->connection = hud_client_connection_get_ref();
 
244
        }
 
245
 
 
246
        cquery->priv->connection_changed_sig = g_signal_connect(cquery->priv->connection, HUD_CLIENT_CONNECTION_SIGNAL_CONNECTION_STATUS, G_CALLBACK(connection_status), cquery);
 
247
 
 
248
        if(cquery->priv->query == NULL) {
 
249
                cquery->priv->query = g_strdup("");
 
250
        }
 
251
 
 
252
        connection_status(cquery->priv->connection, hud_client_connection_connected(cquery->priv->connection), cquery);
 
253
        
 
254
        return;
 
255
}
 
256
 
 
257
/* Handles the connection status of the HUD service, once
 
258
   we're connected we can do all kinds of fun stuff */
 
259
static void
 
260
connection_status (HudClientConnection * connection, gboolean connected, HudClientQuery * cquery)
 
261
{
 
262
        g_clear_object(&cquery->priv->results);
 
263
        g_clear_object(&cquery->priv->appstack);
 
264
        g_clear_object(&cquery->priv->proxy);
 
265
 
 
266
        g_signal_emit(G_OBJECT(cquery), hud_client_query_signal_models_changed, 0);
 
267
 
 
268
        if (!connected) {
 
269
                return;
 
270
        }
 
271
 
 
272
        hud_client_connection_new_query(cquery->priv->connection, cquery->priv->query, new_query_cb, g_object_ref(cquery));
 
273
        return;
 
274
}
 
275
 
 
276
static void
 
277
new_query_cb (HudClientConnection * connection, const gchar * path, const gchar * results, const gchar * appstack, gpointer user_data)
 
278
{
 
279
        if (path == NULL || results == NULL || appstack == NULL) {
 
280
                g_object_unref(user_data);
 
281
                return;
 
282
        }
 
283
 
 
284
        HudClientQuery * cquery = HUD_CLIENT_QUERY(user_data);
 
285
        GError * error = NULL;
 
286
 
 
287
        cquery->priv->proxy = _hud_query_com_canonical_hud_query_proxy_new_for_bus_sync(
 
288
                G_BUS_TYPE_SESSION,
 
289
                G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
 
290
                hud_client_connection_get_address(cquery->priv->connection),
 
291
                path,
 
292
                NULL, /* GCancellable */
 
293
                &error  /* GError */
 
294
        );
 
295
 
 
296
        if (cquery->priv->proxy == NULL) {
 
297
                g_debug("Unable to get proxy after getting query path: %s", error->message);
 
298
                g_error_free(error);
 
299
                g_object_unref(cquery);
 
300
                return;
 
301
        }
 
302
 
 
303
        /* Set up our models */
 
304
        cquery->priv->results = dee_shared_model_new(results);
 
305
        cquery->priv->appstack = dee_shared_model_new(appstack);
 
306
 
 
307
        /* Watch for voice signals */
 
308
        g_signal_connect_object (cquery->priv->proxy, "voice-query-loading",
 
309
                G_CALLBACK (hud_client_query_voice_query_loading), G_OBJECT(cquery), 0);
 
310
        g_signal_connect_object (cquery->priv->proxy, "voice-query-listening",
 
311
                G_CALLBACK (hud_client_query_voice_query_listening), G_OBJECT(cquery), 0);
 
312
        g_signal_connect_object (cquery->priv->proxy, "voice-query-heard-something",
 
313
            G_CALLBACK (hud_client_query_voice_query_heard_something), G_OBJECT(cquery), 0);
 
314
 
 
315
        g_signal_emit(G_OBJECT(cquery), hud_client_query_signal_models_changed, 0);
 
316
 
 
317
        g_object_unref(cquery);
 
318
 
 
319
        return;
 
320
}
 
321
 
 
322
static void
 
323
hud_client_query_dispose (GObject *object)
 
324
{
 
325
        HudClientQuery * self = HUD_CLIENT_QUERY(object);
 
326
 
 
327
        /* We don't care anymore, we're dying! */
 
328
        if (self->priv->connection_changed_sig != 0) {
 
329
                g_signal_handler_disconnect(self->priv->connection, self->priv->connection_changed_sig);
 
330
                self->priv->connection_changed_sig = 0;
 
331
        }
 
332
 
 
333
        if (self->priv->proxy != NULL) {
 
334
                _hud_query_com_canonical_hud_query_call_close_query_sync(self->priv->proxy, NULL, NULL);
 
335
        }
 
336
 
 
337
        g_clear_object(&self->priv->results);
 
338
        g_clear_object(&self->priv->appstack);
 
339
        g_clear_object(&self->priv->proxy);
 
340
        g_clear_object(&self->priv->connection);
 
341
 
 
342
        G_OBJECT_CLASS (hud_client_query_parent_class)->dispose (object);
 
343
        return;
 
344
}
 
345
 
 
346
static void
 
347
hud_client_query_finalize (GObject *object)
 
348
{
 
349
        HudClientQuery * self = HUD_CLIENT_QUERY(object);
 
350
 
 
351
        g_clear_pointer(&self->priv->query, g_free);
 
352
 
 
353
        G_OBJECT_CLASS (hud_client_query_parent_class)->finalize (object);
 
354
        return;
 
355
}
 
356
 
 
357
/**
 
358
 * hud_client_query_new:
 
359
 * @query: String to build the initial set of results from
 
360
 *
 
361
 * Startes a query with the HUD using a specific string.  This
 
362
 * will block until the query is created.
 
363
 *
 
364
 * Return value: (transfer full): A new #HudClientQuery object
 
365
 */
 
366
HudClientQuery *
 
367
hud_client_query_new (const gchar * query)
 
368
{
 
369
        return HUD_CLIENT_QUERY(g_object_new(HUD_CLIENT_TYPE_QUERY,
 
370
                PROP_QUERY_S, query,
 
371
                NULL
 
372
        ));
 
373
}
 
374
 
 
375
/**
 
376
 * hud_client_query_new_for_connection:
 
377
 * @query: String to build the initial set of results from
 
378
 * @connection: A custom #HudClientConnection to a non-default HUD service
 
379
 *
 
380
 * Very similar to hud_client_query_new() except that it uses a
 
381
 * custom connection.  This is mostly for testing, though it is
 
382
 * available if you need it.
 
383
 *
 
384
 * Return value: (transfer full): A new #HudClientQuery object
 
385
 */
 
386
HudClientQuery *
 
387
hud_client_query_new_for_connection (const gchar * query, HudClientConnection * connection)
 
388
{
 
389
        return HUD_CLIENT_QUERY(g_object_new(HUD_CLIENT_TYPE_QUERY,
 
390
                PROP_CONNECTION_S, connection,
 
391
                PROP_QUERY_S, query,
 
392
                NULL
 
393
        ));
 
394
}
 
395
 
 
396
/**
 
397
 * hud_client_query_set_query:
 
398
 * @cquery: A #HudClientQuery
 
399
 * @query: New query string
 
400
 *
 
401
 * This revises the query to be the new query string.  Updates can
 
402
 * be seen through the #DeeModel's.
 
403
 */
 
404
void
 
405
hud_client_query_set_query (HudClientQuery * cquery, const gchar * query)
 
406
{
 
407
        g_return_if_fail(HUD_CLIENT_IS_QUERY(cquery));
 
408
 
 
409
        g_clear_pointer(&cquery->priv->query, g_free);
 
410
        cquery->priv->query = g_strdup(query);
 
411
 
 
412
        if (cquery->priv->proxy != NULL) {
 
413
                gint revision = 0;
 
414
                _hud_query_com_canonical_hud_query_call_update_query_sync(cquery->priv->proxy, cquery->priv->query, &revision, NULL, NULL);
 
415
        }
 
416
 
 
417
        g_object_notify(G_OBJECT(cquery), PROP_QUERY_S);
 
418
 
 
419
        return;
 
420
}
 
421
 
 
422
/**
 
423
 * hud_client_query_get_query:
 
424
 * @cquery: A #HudClientQuery
 
425
 * 
 
426
 * Accessor for the current query string.
 
427
 *
 
428
 * Return value: (transfer none): Query string
 
429
 */
 
430
const gchar *
 
431
hud_client_query_get_query (HudClientQuery * cquery)
 
432
{
 
433
        g_return_val_if_fail(HUD_CLIENT_IS_QUERY(cquery), NULL);
 
434
 
 
435
        return cquery->priv->query;
 
436
}
 
437
 
 
438
static void
 
439
hud_client_query_voice_query_callback (GObject *source, GAsyncResult *result, gpointer user_data)
 
440
{
 
441
        g_assert(HUD_CLIENT_IS_QUERY(user_data));
 
442
        HudClientQuery *cquery = HUD_CLIENT_QUERY(user_data);
 
443
        gint revision = 0;
 
444
        gchar *query = NULL;
 
445
        GError *error = NULL;
 
446
        if (!_hud_query_com_canonical_hud_query_call_voice_query_finish (cquery->priv->proxy, &revision, &query, result, &error))
 
447
        {
 
448
                g_warning("Voice query failed to finish: [%s]", error->message);
 
449
                g_signal_emit (user_data, hud_client_query_signal_voice_query_failed,
 
450
                      0 /* details */, error->message);
 
451
                g_error_free(error);
 
452
                return;
 
453
        }
 
454
 
 
455
        g_clear_pointer(&cquery->priv->query, g_free);
 
456
        cquery->priv->query = query;
 
457
        g_object_notify (G_OBJECT(cquery), PROP_QUERY_S);
 
458
 
 
459
        g_signal_emit (user_data, hud_client_query_signal_voice_query_finished,
 
460
      0 /* details */, query);
 
461
}
 
462
 
 
463
/**
 
464
 * hud_client_query_voice_query:
 
465
 * @cquery: A #HudClientQuery
 
466
 *
 
467
 * Execute a HUD query using voice recognition.
 
468
 *
 
469
 * Will cause a series of signals to be emitted indicating progress:
 
470
 * - voice-query-loading - the voice recognition toolkit is loading.
 
471
 * - voice-query-failed - the voice recognition toolkit has failed to initialize.
 
472
 * - voice-query-listening - the voice recognition toolkit is listening to speech.
 
473
 * - voice-query-heard-something - the voice recognition toolkit has heard a complete utterance.
 
474
 * - voice-query-finished - the voice recognition toolkit has completed, and has a (possibly empty) result.
 
475
 */
 
476
void
 
477
hud_client_query_voice_query (HudClientQuery * cquery)
 
478
{
 
479
        g_return_if_fail(HUD_CLIENT_IS_QUERY(cquery));
 
480
 
 
481
        if (cquery->priv->proxy != NULL) {
 
482
                g_debug("Running voice query");
 
483
                _hud_query_com_canonical_hud_query_call_voice_query (cquery->priv->proxy, NULL, hud_client_query_voice_query_callback, cquery);
 
484
        }
 
485
}
 
486
 
 
487
/**
 
488
 * hud_client_query_get_results_model:
 
489
 * @cquery: A #HudClientQuery
 
490
 *
 
491
 * Accessor for the current results model.
 
492
 *
 
493
 * Return value: (transfer none): Results Model
 
494
 */
 
495
DeeModel *
 
496
hud_client_query_get_results_model (HudClientQuery * cquery)
 
497
{
 
498
        g_return_val_if_fail(HUD_CLIENT_IS_QUERY(cquery), NULL);
 
499
 
 
500
        return cquery->priv->results;
 
501
}
 
502
 
 
503
/**
 
504
 * hud_client_query_get_appstack_model:
 
505
 * @cquery: A #HudClientQuery
 
506
 *
 
507
 * Accessor for the current appstack model.
 
508
 *
 
509
 * Return value: (transfer none): Appstack Model
 
510
 */
 
511
DeeModel *
 
512
hud_client_query_get_appstack_model (HudClientQuery * cquery)
 
513
{
 
514
        g_return_val_if_fail(HUD_CLIENT_IS_QUERY(cquery), NULL);
 
515
 
 
516
        return cquery->priv->appstack;
 
517
}
 
518
 
 
519
/**
 
520
 * hud_client_query_toolbar_item_active:
 
521
 * @cquery: A #HudClientQuery
 
522
 * @item: Item to check for
 
523
 *
 
524
 * Checks to see if a particular toolbar item is implemented by the
 
525
 * application and should be shown to the user as available for use.
 
526
 *
 
527
 * Return value: Whether this @item is active.
 
528
 */
 
529
gboolean
 
530
hud_client_query_toolbar_item_active (HudClientQuery * cquery, HudClientQueryToolbarItems item)
 
531
{
 
532
        g_return_val_if_fail(HUD_CLIENT_IS_QUERY(cquery), FALSE);
 
533
 
 
534
 
 
535
        return FALSE;
 
536
}
 
537
 
 
538
/**
 
539
 * hud_client_query_get_active_toolbar:
 
540
 * @cquery: A #HudClientQuery
 
541
 *
 
542
 * Gets a list of all the active toolbar items as an array.  Array should be
 
543
 * free'd after use.
 
544
 *
 
545
 * Return value: (transfer full) (element-type HudClientQueryToolbarItems): A
 
546
 * list of the active toolbar items.
 
547
 */
 
548
GArray *
 
549
hud_client_query_get_active_toolbar (HudClientQuery * cquery)
 
550
{
 
551
        g_return_val_if_fail(HUD_CLIENT_IS_QUERY(cquery), NULL);
 
552
 
 
553
 
 
554
        return NULL;
 
555
}
 
556
 
 
557
/**
 
558
 * hud_client_query_set_appstack_app:
 
559
 * @cquery: A #HudClientQuery
 
560
 * @application_id: New application to get results from
 
561
 *
 
562
 * This revises the query application to be application_id.  Updates can
 
563
 * be seen through the #DeeModel's.
 
564
 */
 
565
void
 
566
hud_client_query_set_appstack_app (HudClientQuery *        cquery,
 
567
                                   const gchar *           application_id)
 
568
{
 
569
        g_return_if_fail(HUD_CLIENT_IS_QUERY(cquery));
 
570
 
 
571
        if (cquery->priv->proxy != NULL) {
 
572
                gint revision = 0;
 
573
                _hud_query_com_canonical_hud_query_call_update_app_sync(cquery->priv->proxy, application_id, &revision, NULL, NULL);
 
574
        }
 
575
 
 
576
        return;
 
577
}
 
578
 
 
579
/**
 
580
 * hud_client_query_execute_command:
 
581
 * @cquery: A #HudClientQuery
 
582
 * @command_key: The key from the results model for the entry to activate
 
583
 * @timestamp: Timestamp for the user event
 
584
 *
 
585
 * Executes a particular entry from the results model.  The @command_key
 
586
 * should be grabbed from the table and passed to this function to activate
 
587
 * it.  This function will block until the command is activated.
 
588
 */
 
589
void
 
590
hud_client_query_execute_command (HudClientQuery * cquery, GVariant * command_key, guint timestamp)
 
591
{
 
592
        g_return_if_fail(HUD_CLIENT_IS_QUERY(cquery));
 
593
        g_return_if_fail(command_key != NULL);
 
594
 
 
595
        GError *error = NULL;
 
596
        if (!_hud_query_com_canonical_hud_query_call_execute_command_sync(cquery->priv->proxy, command_key, timestamp, NULL, &error))
 
597
  {
 
598
          g_warning("Error executing command [%s]", error->message);
 
599
          g_error_free(error);
 
600
  }
 
601
 
 
602
        return;
 
603
}
 
604
 
 
605
/**
 
606
 * hud_client_query_execute_param_command:
 
607
 * @cquery: A #HudClientQuery
 
608
 * @command_key: The key from the results model for the entry to activate
 
609
 * @timestamp: Timestamp for the user event
 
610
 *
 
611
 * Executes a command that results in a parameterized dialog
 
612
 * which is controlled using the returned #HudClientParam object.
 
613
 * When created this sends the "opened" event to the application.
 
614
 *
 
615
 * Return Value: (transfer full): Object to control the parameterized dialog.
 
616
 */
 
617
HudClientParam *
 
618
hud_client_query_execute_param_command (HudClientQuery * cquery, GVariant * command_key, guint timestamp)
 
619
{
 
620
        g_return_val_if_fail(HUD_CLIENT_IS_QUERY(cquery), NULL);
 
621
        g_return_val_if_fail(command_key != NULL, NULL);
 
622
 
 
623
        gchar * sender = g_dbus_proxy_get_name_owner(G_DBUS_PROXY(cquery->priv->proxy));
 
624
        gchar * base_action = NULL;
 
625
        gchar * action_path = NULL;
 
626
        gchar * model_path = NULL;
 
627
        gint section = 0;
 
628
        GError * error = NULL;
 
629
 
 
630
        _hud_query_com_canonical_hud_query_call_execute_parameterized_sync(cquery->priv->proxy, command_key, timestamp, &base_action, &action_path, &model_path, &section, NULL, &error);
 
631
 
 
632
        if (error != NULL) {
 
633
                g_warning("Unable to execute paramereterized action: %s", error->message);
 
634
                g_error_free(error);
 
635
                return NULL;
 
636
        }
 
637
 
 
638
        HudClientParam * param = hud_client_param_new(sender, base_action, action_path, model_path, section);
 
639
 
 
640
        g_free(sender);
 
641
        g_free(base_action);
 
642
        g_free(action_path);
 
643
        g_free(model_path);
 
644
 
 
645
        return param;
 
646
}
 
647
 
 
648
/**
 
649
 * hud_client_query_execute_toolbar_item:
 
650
 * @cquery: A #HudClientQuery
 
651
 * @item: Which toolbar item is being activated
 
652
 * @timestamp: Timestamp for the user event
 
653
 *
 
654
 * Executes a particular item in the tool bar.  The item should
 
655
 * be active before passing this.
 
656
 */
 
657
void
 
658
hud_client_query_execute_toolbar_item (HudClientQuery * cquery, HudClientQueryToolbarItems item, guint timestamp)
 
659
{
 
660
        g_return_if_fail(HUD_CLIENT_IS_QUERY(cquery));
 
661
 
 
662
        _hud_query_com_canonical_hud_query_call_execute_toolbar_sync(cquery->priv->proxy, hud_client_query_toolbar_items_get_nick(item), timestamp, NULL, NULL);
 
663
 
 
664
        return;
 
665
}
 
666
 
 
667
/**
 
668
 * hud_client_query_appstack_get_app_id:
 
669
 * @cquery: A #HudClientQuery
 
670
 * @row: Which row in the table to grab the ID from
 
671
 *
 
672
 * Get the application ID for a given row in the appstack table.
 
673
 *
 
674
 * Return value: The application ID
 
675
 */
 
676
const gchar *
 
677
hud_client_query_appstack_get_app_id (HudClientQuery * cquery, DeeModelIter * row)
 
678
{
 
679
        g_return_val_if_fail(HUD_CLIENT_IS_QUERY(cquery), NULL);
 
680
        g_return_val_if_fail(row != NULL, NULL);
 
681
 
 
682
        return dee_model_get_string(cquery->priv->appstack, row, HUD_QUERY_APPSTACK_APPLICATION_ID);
 
683
}
 
684
 
 
685
/**
 
686
 * hud_client_query_appstack_get_app_icon:
 
687
 * @cquery: A #HudClientQuery
 
688
 * @row: Which row in the table to grab the icon from
 
689
 *
 
690
 * Get the application icon for a given row in the appstack table.
 
691
 *
 
692
 * Return value: The application icon
 
693
 */
 
694
const gchar *
 
695
hud_client_query_appstack_get_app_icon (HudClientQuery * cquery, DeeModelIter * row)
 
696
{
 
697
        g_return_val_if_fail(HUD_CLIENT_IS_QUERY(cquery), NULL);
 
698
        g_return_val_if_fail(row != NULL, NULL);
 
699
 
 
700
        return dee_model_get_string(cquery->priv->appstack, row, HUD_QUERY_APPSTACK_ICON_NAME);
 
701
}
 
702
 
 
703
/**
 
704
 * hud_client_query_results_get_command_id:
 
705
 * @cquery: A #HudClientQuery
 
706
 * @row: Which row in the table to grab the ID from
 
707
 *
 
708
 * Get the command ID for a given row in the results table.
 
709
 *
 
710
 * Return value: (transfer full): The command ID
 
711
 */
 
712
GVariant *
 
713
hud_client_query_results_get_command_id (HudClientQuery * cquery, DeeModelIter * row)
 
714
{
 
715
        g_return_val_if_fail(HUD_CLIENT_IS_QUERY(cquery), NULL);
 
716
        g_return_val_if_fail(row != NULL, NULL);
 
717
 
 
718
        return dee_model_get_value(cquery->priv->results, row, HUD_QUERY_RESULTS_COMMAND_ID);
 
719
}
 
720
 
 
721
/**
 
722
 * hud_client_query_results_get_command_name:
 
723
 * @cquery: A #HudClientQuery
 
724
 * @row: Which row in the table to grab the name from
 
725
 *
 
726
 * Get the human readable command name for a given row in the results table.
 
727
 *
 
728
 * Return value: The command name
 
729
 */
 
730
const gchar *
 
731
hud_client_query_results_get_command_name (HudClientQuery * cquery, DeeModelIter * row)
 
732
{
 
733
        g_return_val_if_fail(HUD_CLIENT_IS_QUERY(cquery), NULL);
 
734
        g_return_val_if_fail(row != NULL, NULL);
 
735
 
 
736
        return dee_model_get_string(cquery->priv->results, row, HUD_QUERY_RESULTS_COMMAND_NAME);
 
737
}
 
738
 
 
739
/**
 
740
 * hud_client_query_results_get_command_highlights:
 
741
 * @cquery: A #HudClientQuery
 
742
 * @row: Which row in the table to grab the highlights from
 
743
 *
 
744
 * Get the command highlights for a row in the table with start and
 
745
 * stop characters in an array.
 
746
 *
 
747
 * Return value: (transfer full): The command highlights as a variant of type "a(ii)"
 
748
 */
 
749
GVariant *
 
750
hud_client_query_results_get_command_highlights (HudClientQuery * cquery, DeeModelIter * row)
 
751
{
 
752
        g_return_val_if_fail(HUD_CLIENT_IS_QUERY(cquery), NULL);
 
753
        g_return_val_if_fail(row != NULL, NULL);
 
754
 
 
755
        return dee_model_get_value(cquery->priv->results, row, HUD_QUERY_RESULTS_COMMAND_HIGHLIGHTS);
 
756
}
 
757
 
 
758
/**
 
759
 * hud_client_query_results_get_description:
 
760
 * @cquery: A #HudClientQuery
 
761
 * @row: Which row in the table to grab the description from
 
762
 *
 
763
 * Get the human readable description for the command in the given row in the results table.
 
764
 *
 
765
 * Return value: The description
 
766
 */
 
767
const gchar *
 
768
hud_client_query_results_get_description (HudClientQuery * cquery, DeeModelIter * row)
 
769
{
 
770
        g_return_val_if_fail(HUD_CLIENT_IS_QUERY(cquery), NULL);
 
771
        g_return_val_if_fail(row != NULL, NULL);
 
772
 
 
773
        return dee_model_get_string(cquery->priv->results, row, HUD_QUERY_RESULTS_DESCRIPTION);
 
774
}
 
775
 
 
776
/**
 
777
 * hud_client_query_results_get_description_highlights:
 
778
 * @cquery: A #HudClientQuery
 
779
 * @row: Which row in the table to grab the highlights from
 
780
 *
 
781
 * Get the description highlights for a row in the table with start and
 
782
 * stop characters in an array.
 
783
 *
 
784
 * Return value: (transfer full): The description highlights as a variant of type "a(ii)"
 
785
 */
 
786
GVariant *
 
787
hud_client_query_results_get_description_highlights (HudClientQuery * cquery, DeeModelIter * row)
 
788
{
 
789
        g_return_val_if_fail(HUD_CLIENT_IS_QUERY(cquery), NULL);
 
790
        g_return_val_if_fail(row != NULL, NULL);
 
791
 
 
792
        return dee_model_get_value(cquery->priv->results, row, HUD_QUERY_RESULTS_DESCRIPTION_HIGHLIGHTS);
 
793
}
 
794
 
 
795
/**
 
796
 * hud_client_query_results_get_shortcut:
 
797
 * @cquery: A #HudClientQuery
 
798
 * @row: Which row in the table to grab the shortcut from
 
799
 *
 
800
 * Get the human readable shortcut for the command in the given row in the results table.
 
801
 *
 
802
 * Return value: The shortcut
 
803
 */
 
804
const gchar *
 
805
hud_client_query_results_get_shortcut (HudClientQuery * cquery, DeeModelIter * row)
 
806
{
 
807
        g_return_val_if_fail(HUD_CLIENT_IS_QUERY(cquery), NULL);
 
808
        g_return_val_if_fail(row != NULL, NULL);
 
809
 
 
810
        return dee_model_get_string(cquery->priv->results, row, HUD_QUERY_RESULTS_SHORTCUT);
 
811
}
 
812
 
 
813
/**
 
814
 * hud_client_query_results_is_parameterized:
 
815
 * @cquery: A #HudClientQuery
 
816
 * @row: Which row in the table to check if the command is parameterized
 
817
 *
 
818
 * Check to see if the given command is parameterized
 
819
 *
 
820
 * Return value: Whether the command in the row is parameterized
 
821
 */
 
822
gboolean
 
823
hud_client_query_results_is_parameterized (HudClientQuery * cquery, DeeModelIter * row)
 
824
{
 
825
        g_return_val_if_fail(HUD_CLIENT_IS_QUERY(cquery), FALSE);
 
826
        g_return_val_if_fail(row != NULL, FALSE);
 
827
 
 
828
        return dee_model_get_bool(cquery->priv->results, row, HUD_QUERY_RESULTS_PARAMETERIZED);
 
829
}