1 /* gdict-database-chooser-button.c - display widget for database names
2 *
3 * Copyright (C) 2015 Juan R. García Blanco <juanrgar@gmail.com>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20 * SECTION:gdict-database-chooser-button
21 * @short_description: Display the list of available databases in a popover
22 *
23 * Each #GdictContext has a list of databases, that is dictionaries that
24 * can be queried. #GdictDatabaseChooserButton is a button widget that,
25 * when clicked, loads all available databases in the associated
26 * #GdictContext, and displays them in a #GdictDatabaseChooser contained
27 * in a #GtkPopover.
28 *
29 * #GdictDatabaseChooserButton is available since Gdict 0.10
30 */
31
32 #include "config.h"
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <stdarg.h>
38
39 #include <gdk/gdkkeysyms.h>
40 #include <gtk/gtk.h>
41 #include <glib/gi18n-lib.h>
42
43 #include "gdict-database-chooser-button.h"
44 #include "gdict-database-chooser.h"
45 #include "gdict-utils.h"
46 #include "gdict-debug.h"
47 #include "gdict-private.h"
48 #include "gdict-enum-types.h"
49 #include "gdict-marshal.h"
50
51 #define GDICT_DATABASE_CHOOSER_BUTTON_GET_PRIVATE(obj) \
52 gdict_database_chooser_button_get_instance_private ((GdictDatabaseChooserButton *) (obj))
53
54 struct _GdictDatabaseChooserButtonPrivate
55 {
56 GtkWidget *db_chooser;
57 GtkWidget *stack;
58 GtkWidget *spinner;
59 GtkWidget *popover;
60
61 GdkCursor *busy_cursor;
62
63 guint start_id;
64 guint end_id;
65 guint error_id;
66
67 guint is_loaded : 1;
68 };
69
70 enum
71 {
72 PROP_0,
73
74 PROP_CONTEXT,
75 PROP_COUNT
76 };
77
78 enum
79 {
80 DATABASE_ACTIVATED,
81 SELECTION_CHANGED,
82
83 LAST_SIGNAL
84 };
85
86 static guint db_chooser_button_signals[LAST_SIGNAL] = { 0 };
87
G_DEFINE_TYPE_WITH_PRIVATE(GdictDatabaseChooserButton,gdict_database_chooser_button,GTK_TYPE_MENU_BUTTON)88 G_DEFINE_TYPE_WITH_PRIVATE (GdictDatabaseChooserButton,
89 gdict_database_chooser_button,
90 GTK_TYPE_MENU_BUTTON)
91
92 static void
93 set_gdict_context (GdictDatabaseChooserButton *chooser_button,
94 GdictContext *context)
95 {
96 GdictDatabaseChooserButtonPrivate *priv =
97 GDICT_DATABASE_CHOOSER_BUTTON_GET_PRIVATE (chooser_button);
98 GdictContext *old_context;
99
100 g_assert (GDICT_IS_DATABASE_CHOOSER_BUTTON (chooser_button));
101
102 old_context = gdict_database_chooser_get_context (GDICT_DATABASE_CHOOSER (priv->db_chooser));
103 if (context == old_context)
104 return;
105
106 if (old_context)
107 {
108 if (priv->start_id)
109 {
110 g_signal_handler_disconnect (old_context, priv->start_id);
111 g_signal_handler_disconnect (old_context, priv->end_id);
112
113 priv->start_id = 0;
114 priv->end_id = 0;
115 }
116
117 if (priv->error_id)
118 {
119 g_signal_handler_disconnect (old_context, priv->error_id);
120
121 priv->error_id = 0;
122 }
123
124 priv->is_loaded = FALSE;
125 }
126
127 gdict_database_chooser_set_context (GDICT_DATABASE_CHOOSER (priv->db_chooser), context);
128 }
129
130 static void
get_gdict_context(GdictDatabaseChooserButton * chooser_button,GValue * value)131 get_gdict_context (GdictDatabaseChooserButton *chooser_button,
132 GValue *value)
133 {
134 GdictDatabaseChooserButtonPrivate *priv =
135 GDICT_DATABASE_CHOOSER_BUTTON_GET_PRIVATE (chooser_button);
136
137 g_assert (GDICT_IS_DATABASE_CHOOSER_BUTTON (chooser_button));
138
139 g_object_get (G_OBJECT (priv->db_chooser),
140 "context", value,
141 NULL);
142 }
143
144 static void
get_results_count(GdictDatabaseChooserButton * chooser_button,GValue * value)145 get_results_count (GdictDatabaseChooserButton *chooser_button,
146 GValue *value)
147 {
148 GdictDatabaseChooserButtonPrivate *priv =
149 GDICT_DATABASE_CHOOSER_BUTTON_GET_PRIVATE (chooser_button);
150
151 g_assert (GDICT_IS_DATABASE_CHOOSER_BUTTON (chooser_button));
152
153 g_object_get (G_OBJECT (priv->db_chooser),
154 "count", value,
155 NULL);
156 }
157
158 static void
gdict_database_chooser_button_finalize(GObject * gobject)159 gdict_database_chooser_button_finalize (GObject *gobject)
160 {
161 G_OBJECT_CLASS (gdict_database_chooser_button_parent_class)->finalize (gobject);
162 }
163
164 static void
gdict_database_chooser_button_dispose(GObject * gobject)165 gdict_database_chooser_button_dispose (GObject *gobject)
166 {
167 GdictDatabaseChooserButton *chooser_button = GDICT_DATABASE_CHOOSER_BUTTON (gobject);
168 GdictDatabaseChooserButtonPrivate *priv = chooser_button->priv;
169
170 g_clear_object (&priv->busy_cursor);
171
172 G_OBJECT_CLASS (gdict_database_chooser_button_parent_class)->dispose (gobject);
173 }
174
175 static void
gdict_database_chooser_button_set_property(GObject * gobject,guint prop_id,const GValue * value,GParamSpec * pspec)176 gdict_database_chooser_button_set_property (GObject *gobject,
177 guint prop_id,
178 const GValue *value,
179 GParamSpec *pspec)
180 {
181 GdictDatabaseChooserButton *chooser_button = GDICT_DATABASE_CHOOSER_BUTTON (gobject);
182
183 switch (prop_id)
184 {
185 case PROP_CONTEXT:
186 set_gdict_context (chooser_button, g_value_get_object (value));
187 break;
188 default:
189 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
190 break;
191 }
192 }
193
194 static void
gdict_database_chooser_button_get_property(GObject * gobject,guint prop_id,GValue * value,GParamSpec * pspec)195 gdict_database_chooser_button_get_property (GObject *gobject,
196 guint prop_id,
197 GValue *value,
198 GParamSpec *pspec)
199 {
200 GdictDatabaseChooserButton *chooser_button = GDICT_DATABASE_CHOOSER_BUTTON (gobject);
201
202 switch (prop_id)
203 {
204 case PROP_CONTEXT:
205 get_gdict_context (chooser_button, value);
206 break;
207 case PROP_COUNT:
208 get_results_count (chooser_button, value);
209 break;
210 default:
211 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
212 break;
213 }
214 }
215
216 static void
selection_changed_cb(GdictDatabaseChooser * chooser,gpointer user_data)217 selection_changed_cb (GdictDatabaseChooser *chooser,
218 gpointer user_data)
219 {
220 g_signal_emit (user_data, db_chooser_button_signals[SELECTION_CHANGED], 0);
221 }
222
223 static void
database_activated_cb(GdictDatabaseChooser * chooser,const gchar * name,const gchar * description,gpointer user_data)224 database_activated_cb (GdictDatabaseChooser *chooser,
225 const gchar *name,
226 const gchar *description,
227 gpointer user_data)
228 {
229 GdictDatabaseChooserButton *chooser_button = user_data;
230
231 gtk_widget_set_tooltip_text (GTK_WIDGET (chooser_button), description);
232
233 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (chooser_button), FALSE);
234
235 g_signal_emit (user_data, db_chooser_button_signals[DATABASE_ACTIVATED], 0,
236 name, description);
237 }
238
239 static void
lookup_start_cb(GdictContext * context,gpointer user_data)240 lookup_start_cb (GdictContext *context,
241 gpointer user_data)
242 {
243 GdictDatabaseChooserButton *chooser_button = user_data;
244 GdictDatabaseChooserButtonPrivate *priv =
245 GDICT_DATABASE_CHOOSER_BUTTON_GET_PRIVATE (chooser_button);
246
247 if (!priv->busy_cursor)
248 {
249 GdkDisplay *display = gtk_widget_get_display (GTK_WIDGET (chooser_button));
250
251 priv->busy_cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
252 }
253
254 if (gtk_widget_get_window (GTK_WIDGET (chooser_button)))
255 gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (chooser_button)),
256 priv->busy_cursor);
257
258 gtk_spinner_start (GTK_SPINNER (priv->spinner));
259 }
260
261 static void
lookup_end_cb(GdictContext * context,gpointer user_data)262 lookup_end_cb (GdictContext *context,
263 gpointer user_data)
264 {
265 GdictDatabaseChooserButton *chooser_button = user_data;
266 GdictDatabaseChooserButtonPrivate *priv =
267 GDICT_DATABASE_CHOOSER_BUTTON_GET_PRIVATE (chooser_button);
268
269 if (gtk_widget_get_window (GTK_WIDGET (chooser_button)))
270 gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (chooser_button)),
271 NULL);
272
273 gtk_spinner_stop (GTK_SPINNER (priv->spinner));
274 gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "chooser");
275
276 priv->is_loaded = TRUE;
277 }
278
279 static void
error_cb(GdictContext * context,const GError * error,gpointer user_data)280 error_cb (GdictContext *context,
281 const GError *error,
282 gpointer user_data)
283 {
284 GdictDatabaseChooserButtonPrivate *priv =
285 GDICT_DATABASE_CHOOSER_BUTTON_GET_PRIVATE (user_data);
286
287 gtk_spinner_stop (GTK_SPINNER (priv->spinner));
288
289 priv->is_loaded = FALSE;
290 }
291
292 static void
gdict_database_chooser_button_clicked(GtkButton * button)293 gdict_database_chooser_button_clicked (GtkButton *button)
294 {
295 GtkButtonClass *button_class = GTK_BUTTON_CLASS (gdict_database_chooser_button_parent_class);
296 GdictDatabaseChooserButton *chooser_button;
297 GdictDatabaseChooserButtonPrivate *priv;
298 GtkToggleButton *toggle;
299 GdictContext *context;
300 gboolean active;
301
302 button_class->clicked (button);
303
304 toggle = GTK_TOGGLE_BUTTON (button);
305 active = gtk_toggle_button_get_active (toggle);
306
307 GDICT_NOTE (CHOOSER, "Button clicked: %s", active ? "active" : "inactive");
308
309 chooser_button = GDICT_DATABASE_CHOOSER_BUTTON (button);
310 priv = GDICT_DATABASE_CHOOSER_BUTTON_GET_PRIVATE (chooser_button);
311
312 if (active && !priv->is_loaded)
313 {
314 context = gdict_database_chooser_get_context (GDICT_DATABASE_CHOOSER (priv->db_chooser));
315
316 gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "spinner");
317
318 if (priv->start_id == 0)
319 {
320 priv->start_id = g_signal_connect (context, "database-lookup-start",
321 G_CALLBACK (lookup_start_cb),
322 chooser_button);
323 priv->end_id = g_signal_connect (context, "database-lookup-end",
324 G_CALLBACK (lookup_end_cb),
325 chooser_button);
326 }
327
328 if (priv->error_id == 0)
329 priv->error_id = g_signal_connect (context, "error",
330 G_CALLBACK (error_cb),
331 chooser_button);
332
333 gdict_database_chooser_refresh (GDICT_DATABASE_CHOOSER (priv->db_chooser));
334 }
335 }
336
337 static void
gdict_database_chooser_button_class_init(GdictDatabaseChooserButtonClass * klass)338 gdict_database_chooser_button_class_init (GdictDatabaseChooserButtonClass *klass)
339 {
340 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
341 GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
342
343 gobject_class->finalize = gdict_database_chooser_button_finalize;
344 gobject_class->dispose = gdict_database_chooser_button_dispose;
345 gobject_class->set_property = gdict_database_chooser_button_set_property;
346 gobject_class->get_property = gdict_database_chooser_button_get_property;
347 button_class->clicked = gdict_database_chooser_button_clicked;
348
349 /**
350 * GdictDatabaseChooserButton:context:
351 *
352 * The #GdictContext used to retrieve the list of available databases.
353 *
354 * Since: 0.10
355 */
356 g_object_class_install_property (gobject_class,
357 PROP_CONTEXT,
358 g_param_spec_object ("context",
359 "Context",
360 "The GdictContext object used to get the list of databases",
361 GDICT_TYPE_CONTEXT,
362 (G_PARAM_READWRITE | G_PARAM_CONSTRUCT)));
363 /**
364 * GdictDatabaseChooserButton:count:
365 *
366 * The number of displayed databases or, if no #GdictContext is set, -1.
367 *
368 * Since: 0.12
369 */
370 g_object_class_install_property (gobject_class,
371 PROP_COUNT,
372 g_param_spec_int ("count",
373 "Count",
374 "The number of available databases",
375 -1, G_MAXINT, -1,
376 G_PARAM_READABLE));
377
378 /**
379 * GdictDatabaseChooserButton::database-activated:
380 * @chooser: the database chooser button that received the signal
381 * @name: the name of the activated database
382 * @description: the description of the activated database
383 *
384 * The ::database-activated signal is emitted each time the user
385 * activated a row in the database chooser widget, either by double
386 * clicking on it or by a keyboard event.
387 *
388 * Since: 0.10
389 */
390 db_chooser_button_signals[DATABASE_ACTIVATED] =
391 g_signal_new ("database-activated",
392 G_OBJECT_CLASS_TYPE (gobject_class),
393 G_SIGNAL_RUN_LAST,
394 G_STRUCT_OFFSET (GdictDatabaseChooserButtonClass, database_activated),
395 NULL, NULL,
396 gdict_marshal_VOID__STRING_STRING,
397 G_TYPE_NONE, 2,
398 G_TYPE_STRING,
399 G_TYPE_STRING);
400 /**
401 * GdictDatabaseChooserButton::selection-changed:
402 * @chooser: the database chooser button that received the signal
403 *
404 * The ::selection-changed signal is emitted each time the selection
405 * inside the database chooser has been changed.
406 *
407 * Since: 0.12
408 */
409 db_chooser_button_signals[SELECTION_CHANGED] =
410 g_signal_new ("selection-changed",
411 G_OBJECT_CLASS_TYPE (gobject_class),
412 G_SIGNAL_RUN_LAST,
413 G_STRUCT_OFFSET (GdictDatabaseChooserButtonClass, selection_changed),
414 NULL, NULL,
415 gdict_marshal_VOID__VOID,
416 G_TYPE_NONE, 0);
417 }
418
419 static void
gdict_database_chooser_button_init(GdictDatabaseChooserButton * chooser_button)420 gdict_database_chooser_button_init (GdictDatabaseChooserButton *chooser_button)
421 {
422 GdictDatabaseChooserButtonPrivate *priv;
423
424 chooser_button->priv = priv =
425 gdict_database_chooser_button_get_instance_private (chooser_button);
426
427 priv->start_id = 0;
428 priv->end_id = 0;
429 priv->error_id = 0;
430
431 gtk_button_set_image (GTK_BUTTON (chooser_button),
432 gtk_image_new_from_icon_name ("view-list-symbolic",
433 GTK_ICON_SIZE_BUTTON));
434
435 priv->popover = gtk_popover_new (GTK_WIDGET (chooser_button));
436 gtk_menu_button_set_direction (GTK_MENU_BUTTON (chooser_button), GTK_ARROW_NONE);
437 gtk_menu_button_set_popover (GTK_MENU_BUTTON (chooser_button), priv->popover);
438
439 priv->stack = gtk_stack_new ();
440 gtk_container_add (GTK_CONTAINER (priv->popover), priv->stack);
441 gtk_widget_show (priv->stack);
442
443 priv->spinner = gtk_spinner_new ();
444 gtk_stack_add_named (GTK_STACK (priv->stack), priv->spinner, "spinner");
445 gtk_widget_show (priv->spinner);
446
447 priv->db_chooser = gdict_database_chooser_new ();
448 gtk_stack_add_named (GTK_STACK (priv->stack), priv->db_chooser, "chooser");
449 gtk_widget_show (priv->db_chooser);
450
451 g_signal_connect (priv->db_chooser,
452 "selection-changed", G_CALLBACK (selection_changed_cb),
453 chooser_button);
454
455 g_signal_connect (priv->db_chooser,
456 "database-activated", G_CALLBACK (database_activated_cb),
457 chooser_button);
458
459 priv->is_loaded = FALSE;
460 }
461
462 /**
463 * gdict_database_chooser_button_new:
464 *
465 * Creates a new #GdictDatabaseChooserButton widget. A Database chooser button
466 * widget can be used to display the list of available databases on a dictionary
467 * source using the #GdictContext representing it. After creation, the
468 * #GdictContext can be set using gdict_database_chooser_button_set_context().
469 *
470 * Return value: the newly created #GdictDatabaseChooserButton widget.
471 *
472 * Since: 0.10
473 */
474 GtkWidget *
gdict_database_chooser_button_new(void)475 gdict_database_chooser_button_new (void)
476 {
477 return g_object_new (GDICT_TYPE_DATABASE_CHOOSER_BUTTON, NULL);
478 }
479
480 /**
481 * gdict_database_chooser_button_new_with_context: (constructor)
482 * @context: a #GdictContext
483 *
484 * Creates a new #GdictDatabaseChooserButton, using @context as the representation
485 * of the dictionary source to query for the list of available databases.
486 *
487 * Return value: the newly created #GdictDatabaseChooserButton widget.
488 *
489 * Since: 0.10
490 */
491 GtkWidget *
gdict_database_chooser_button_new_with_context(GdictContext * context)492 gdict_database_chooser_button_new_with_context (GdictContext *context)
493 {
494 g_return_val_if_fail (GDICT_IS_CONTEXT (context), NULL);
495
496 return g_object_new (GDICT_TYPE_DATABASE_CHOOSER_BUTTON,
497 "context", context,
498 NULL);
499 }
500
501 /**
502 * gdict_database_chooser_button_get_context:
503 * @chooser: a #GdictDatabaseChooserButton
504 *
505 * Retrieves the #GdictContext used by @chooser.
506 *
507 * Return value: (transfer none): a #GdictContext or %NULL
508 *
509 * Since: 0.10
510 */
511 GdictContext *
gdict_database_chooser_button_get_context(GdictDatabaseChooserButton * chooser)512 gdict_database_chooser_button_get_context (GdictDatabaseChooserButton *chooser)
513 {
514 GdictDatabaseChooserButtonPrivate *priv =
515 gdict_database_chooser_button_get_instance_private (chooser);
516
517 g_return_val_if_fail (GDICT_IS_DATABASE_CHOOSER_BUTTON (chooser), NULL);
518
519 return gdict_database_chooser_get_context (GDICT_DATABASE_CHOOSER (priv->db_chooser));
520 }
521
522 /**
523 * gdict_database_chooser_button_set_context:
524 * @chooser: a #GdictDatabaseChooserButton
525 * @context: a #GdictContext
526 *
527 * Sets the #GdictContext to be used to query a dictionary source
528 * for the list of available databases.
529 *
530 * Since: 0.10
531 */
532 void
gdict_database_chooser_button_set_context(GdictDatabaseChooserButton * chooser,GdictContext * context)533 gdict_database_chooser_button_set_context (GdictDatabaseChooserButton *chooser,
534 GdictContext *context)
535 {
536 g_return_if_fail (GDICT_IS_DATABASE_CHOOSER_BUTTON (chooser));
537 g_return_if_fail (context == NULL || GDICT_IS_CONTEXT (context));
538
539 set_gdict_context (chooser, context);
540
541 g_object_notify (G_OBJECT (chooser), "context");
542 }
543
544 /**
545 * gdict_database_chooser_button_get_databases:
546 * @chooser: a #GdictDatabaseChooserButton
547 * @length: (out): return location for the length of the returned vector
548 *
549 * Gets the list of available database names.
550 *
551 * Return value: (transfer full) (array zero-terminated=1): a newly allocated
552 * string vector containing database names.
553 *
554 * Since: 0.10
555 */
556 gchar **
gdict_database_chooser_button_get_databases(GdictDatabaseChooserButton * chooser,gsize * length)557 gdict_database_chooser_button_get_databases (GdictDatabaseChooserButton *chooser,
558 gsize *length)
559 {
560 GdictDatabaseChooserButtonPrivate *priv =
561 gdict_database_chooser_button_get_instance_private (chooser);
562
563 g_return_val_if_fail (GDICT_IS_DATABASE_CHOOSER_BUTTON (chooser), NULL);
564
565 return gdict_database_chooser_get_databases (GDICT_DATABASE_CHOOSER (priv->db_chooser),
566 length);
567 }
568
569 /**
570 * gdict_database_chooser_button_has_database:
571 * @chooser: a #GdictDatabaseChooserButton
572 * @database: the name of a database
573 *
574 * Checks whether the @chooser displays @database
575 *
576 * Return value: %TRUE if the search database name is present
577 *
578 * Since: 0.10
579 */
580 gboolean
gdict_database_chooser_button_has_database(GdictDatabaseChooserButton * chooser,const gchar * database)581 gdict_database_chooser_button_has_database (GdictDatabaseChooserButton *chooser,
582 const gchar *database)
583 {
584 GdictDatabaseChooserButtonPrivate *priv =
585 gdict_database_chooser_button_get_instance_private (chooser);
586
587 g_return_val_if_fail (GDICT_IS_DATABASE_CHOOSER_BUTTON (chooser), FALSE);
588
589 return gdict_database_chooser_has_database (GDICT_DATABASE_CHOOSER (priv->db_chooser), database);
590 }
591
592 /**
593 * gdict_database_chooser_button_count_databases:
594 * @chooser: a #GdictDatabaseChooserButton
595 *
596 * Returns the number of databases found.
597 *
598 * Return value: the number of databases or -1 if no context is set
599 *
600 * Since: 0.10
601 */
602 gint
gdict_database_chooser_button_count_databases(GdictDatabaseChooserButton * chooser)603 gdict_database_chooser_button_count_databases (GdictDatabaseChooserButton *chooser)
604 {
605 GdictDatabaseChooserButtonPrivate *priv =
606 gdict_database_chooser_button_get_instance_private (chooser);
607
608 g_return_val_if_fail (GDICT_IS_DATABASE_CHOOSER_BUTTON (chooser), -1);
609
610 return gdict_database_chooser_count_databases (GDICT_DATABASE_CHOOSER (priv->db_chooser));
611 }
612
613 /**
614 * gdict_database_chooser_button_clear:
615 * @chooser: a #GdictDatabaseChooserButton
616 *
617 * Clears @chooser.
618 *
619 * Since: 0.10
620 */
621 void
gdict_database_chooser_button_clear(GdictDatabaseChooserButton * chooser)622 gdict_database_chooser_button_clear (GdictDatabaseChooserButton *chooser)
623 {
624 GdictDatabaseChooserButtonPrivate *priv =
625 gdict_database_chooser_button_get_instance_private (chooser);
626
627 g_return_if_fail (GDICT_IS_DATABASE_CHOOSER_BUTTON (chooser));
628
629 gdict_database_chooser_clear (GDICT_DATABASE_CHOOSER (priv->db_chooser));
630
631 priv->is_loaded = FALSE;
632 }
633
634 /**
635 * gdict_database_chooser_button_select_database:
636 * @chooser: a #GdictDatabaseChooserButton
637 * @db_name: name of the database to select
638 *
639 * Selects the database with @db_name inside the @chooser widget.
640 *
641 * Return value: %TRUE if the database was found and selected
642 *
643 * Since: 0.10
644 */
645 gboolean
gdict_database_chooser_button_select_database(GdictDatabaseChooserButton * chooser,const gchar * db_name)646 gdict_database_chooser_button_select_database (GdictDatabaseChooserButton *chooser,
647 const gchar *db_name)
648 {
649 GdictDatabaseChooserButtonPrivate *priv =
650 gdict_database_chooser_button_get_instance_private (chooser);
651
652 g_return_val_if_fail (GDICT_IS_DATABASE_CHOOSER_BUTTON (chooser), FALSE);
653
654 return gdict_database_chooser_select_database (GDICT_DATABASE_CHOOSER (priv->db_chooser), db_name);
655 }
656
657 /**
658 * gdict_database_chooser_button_unselect_database:
659 * @chooser: a #GdictDatabaseChooserButton
660 * @db_name: name of the database to unselect
661 *
662 * Unselects the database @db_name inside the @chooser widget
663 *
664 * Return value: %TRUE if the database was found and unselected
665 *
666 * Since: 0.10
667 */
668 gboolean
gdict_database_chooser_button_unselect_database(GdictDatabaseChooserButton * chooser,const gchar * db_name)669 gdict_database_chooser_button_unselect_database (GdictDatabaseChooserButton *chooser,
670 const gchar *db_name)
671 {
672 GdictDatabaseChooserButtonPrivate *priv =
673 gdict_database_chooser_button_get_instance_private (chooser);
674
675 g_return_val_if_fail (GDICT_IS_DATABASE_CHOOSER_BUTTON (chooser), FALSE);
676
677 return gdict_database_chooser_unselect_database (GDICT_DATABASE_CHOOSER (priv->db_chooser),
678 db_name);
679 }
680
681 /**
682 * gdict_database_chooser_button_set_current_database:
683 * @chooser: a #GdictDatabaseChooserButton
684 * @db_name: the name of the database
685 *
686 * Sets @db_name as the current database. This function will select
687 * and activate the corresponding row, if the database is found.
688 *
689 * Return value: %TRUE if the database was found and set
690 *
691 * Since: 0.10
692 */
693 gboolean
gdict_database_chooser_button_set_current_database(GdictDatabaseChooserButton * chooser,const gchar * db_name)694 gdict_database_chooser_button_set_current_database (GdictDatabaseChooserButton *chooser,
695 const gchar *db_name)
696 {
697 GdictDatabaseChooserButtonPrivate *priv =
698 gdict_database_chooser_button_get_instance_private (chooser);
699
700 g_return_val_if_fail (GDICT_IS_DATABASE_CHOOSER_BUTTON (chooser), FALSE);
701
702 return gdict_database_chooser_set_current_database (GDICT_DATABASE_CHOOSER (priv->db_chooser), db_name);
703 }
704
705 /**
706 * gdict_database_chooser_button_get_current_database:
707 * @chooser: a #GdictDatabaseChooserButton
708 *
709 * Retrieves the name of the currently selected database inside @chooser
710 *
711 * Return value: (transfer full): the name of the selected database.
712 *
713 * Since: 0.10
714 */
715 gchar *
gdict_database_chooser_button_get_current_database(GdictDatabaseChooserButton * chooser)716 gdict_database_chooser_button_get_current_database (GdictDatabaseChooserButton *chooser)
717 {
718 GdictDatabaseChooserButtonPrivate *priv =
719 gdict_database_chooser_button_get_instance_private (chooser);
720
721 g_return_val_if_fail (GDICT_IS_DATABASE_CHOOSER_BUTTON (chooser), NULL);
722
723 return gdict_database_chooser_get_current_database (GDICT_DATABASE_CHOOSER (priv->db_chooser));
724 }
725