~ubuntu-branches/ubuntu/precise/libgnomekbd/precise

« back to all changes in this revision

Viewing changes to libgnomekbd/gkbd-status.c

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville
  • Date: 2011-03-21 13:22:31 UTC
  • mfrom: (1.3.6 upstream) (3.2.13 experimental)
  • Revision ID: james.westby@ubuntu.com-20110321132231-zoay06noilk1thky
Tags: 2.91.91-2
* debian/libgnomekbd-common.install:
  - Install /usr/share/GConf/gsettings and /usr/share/libgnomekbd/icons
  - Add libatk1.0-dev (>= 1.32.0-2~) build-dep to be sure we have .gir file

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
17
 * Boston, MA 02111-1307, USA.
18
18
 */
 
19
#include <config.h>
19
20
 
20
21
#include <memory.h>
21
22
 
23
24
 
24
25
#include <gdk/gdkkeysyms.h>
25
26
#include <gdk/gdkx.h>
26
 
#include <glib/gi18n.h>
27
 
#include <glib/gprintf.h>
 
27
#include <glib/gi18n-lib.h>
28
28
 
29
29
#include <gkbd-status.h>
30
30
 
31
31
#include <gkbd-desktop-config.h>
32
32
#include <gkbd-indicator-config.h>
 
33
#include <gkbd-configuration.h>
33
34
 
34
35
typedef struct _gki_globals {
35
 
        XklEngine *engine;
36
 
        XklConfigRegistry *registry;
37
 
 
38
 
        GkbdDesktopConfig cfg;
39
 
        GkbdIndicatorConfig ind_cfg;
40
 
        GkbdKeyboardConfig kbd_cfg;
41
 
 
42
 
        const gchar *tooltips_format;
43
 
        gchar **full_group_names;
44
 
        gchar **short_group_names;
 
36
        GkbdConfiguration *config;
45
37
 
46
38
        gint current_width;
47
39
        gint current_height;
48
40
        int real_width;
49
41
 
50
42
        GSList *icons;          /* list of GdkPixbuf */
51
 
        GSList *widget_instances;       /* list of GkbdStatus */
52
 
        gulong state_changed_handler;
53
 
        gulong config_changed_handler;
54
43
} gki_globals;
55
44
 
56
45
static gchar *settings_signal_names[] = {
61
50
};
62
51
 
63
52
struct _GkbdStatusPrivate {
64
 
        gdouble angle;
65
53
        gulong settings_signal_handlers[sizeof (settings_signal_names) /
66
54
                                        sizeof (settings_signal_names[0])];
67
55
};
69
57
/* one instance for ALL widgets */
70
58
static gki_globals globals;
71
59
 
72
 
#define ForAllIndicators() \
73
 
        { \
74
 
                GSList* cur; \
75
 
                for (cur = globals.widget_instances; cur != NULL; cur = cur->next) { \
76
 
                        GkbdStatus * gki = (GkbdStatus*)cur->data;
77
 
#define NextIndicator() \
78
 
                } \
79
 
        }
80
 
 
81
60
G_DEFINE_TYPE (GkbdStatus, gkbd_status, GTK_TYPE_STATUS_ICON)
 
61
 
82
62
static void
83
63
gkbd_status_global_init (void);
84
64
static void
85
65
gkbd_status_global_term (void);
86
66
static GdkPixbuf *
87
 
gkbd_status_prepare_drawing (GkbdStatus * gki, int group);
 
67
gkbd_status_prepare_drawing (int group);
88
68
static void
89
69
gkbd_status_set_current_page_for_group (GkbdStatus * gki, int group);
90
70
static void
91
71
gkbd_status_set_current_page (GkbdStatus * gki);
92
72
static void
93
 
gkbd_status_global_cleanup (GkbdStatus * gki);
94
 
static void
95
 
gkbd_status_global_fill (GkbdStatus * gki);
 
73
gkbd_status_reinit_globals (void);
 
74
static void
 
75
gkbd_status_cleanup_icons (void);
 
76
static void
 
77
gkbd_status_fill_icons (void);
96
78
static void
97
79
gkbd_status_set_tooltips (GkbdStatus * gki, const char *str);
98
80
 
105
87
}
106
88
 
107
89
void
108
 
gkbd_status_global_cleanup (GkbdStatus * gki)
 
90
gkbd_status_cleanup_icons ()
109
91
{
110
92
        while (globals.icons) {
111
93
                if (globals.icons->data)
116
98
}
117
99
 
118
100
void
119
 
gkbd_status_global_fill (GkbdStatus * gki)
 
101
gkbd_status_fill_icons ()
120
102
{
121
103
        int grp;
122
 
        int total_groups = xkl_engine_get_num_groups (globals.engine);
 
104
        int total_groups =
 
105
            xkl_engine_get_num_groups (gkbd_configuration_get_xkl_engine
 
106
                                       (globals.config));
123
107
 
124
108
        for (grp = 0; grp < total_groups; grp++) {
125
 
                GdkPixbuf *page = gkbd_status_prepare_drawing (gki, grp);
 
109
                GdkPixbuf *page = gkbd_status_prepare_drawing (grp);
126
110
                globals.icons = g_slist_append (globals.icons, page);
127
111
        }
128
112
}
131
115
gkbd_status_activate (GkbdStatus * gki)
132
116
{
133
117
        xkl_debug (150, "Mouse button pressed on applet\n");
134
 
        gkbd_desktop_config_lock_next_group (&globals.cfg);
 
118
        gkbd_configuration_lock_next_group (globals.config);
135
119
}
136
120
 
137
 
/* hackish xref */
138
 
extern gchar *gkbd_indicator_extract_layout_name (int group,
139
 
                                                  XklEngine * engine,
140
 
                                                  GkbdKeyboardConfig *
141
 
                                                  kbd_cfg,
142
 
                                                  gchar **
143
 
                                                  short_group_names,
144
 
                                                  gchar **
145
 
                                                  full_group_names);
146
 
 
147
 
extern gchar *gkbd_indicator_create_label_title (int group,
148
 
                                                 GHashTable **
149
 
                                                 ln2cnt_map,
150
 
                                                 gchar * layout_name);
151
 
 
152
121
static void
153
122
gkbd_status_render_cairo (cairo_t * cr, int group)
154
123
{
161
130
        cairo_font_options_t *fo;
162
131
        static GHashTable *ln2cnt_map = NULL;
163
132
 
 
133
        GkbdIndicatorConfig *ind_cfg =
 
134
            gkbd_configuration_get_indicator_config (globals.config);
 
135
 
164
136
        xkl_debug (160, "Rendering cairo for group %d\n", group);
165
 
        if (globals.ind_cfg.background_color != NULL &&
166
 
            globals.ind_cfg.background_color[0] != 0) {
 
137
        if (ind_cfg->background_color != NULL &&
 
138
            ind_cfg->background_color[0] != 0) {
167
139
                if (sscanf
168
 
                    (globals.ind_cfg.background_color, "%lg %lg %lg", &r,
 
140
                    (ind_cfg->background_color, "%lg %lg %lg", &r,
169
141
                     &g, &b) == 3) {
170
142
                        cairo_set_source_rgb (cr, r, g, b);
171
143
                        cairo_rectangle (cr, 0, 0, globals.current_width,
174
146
                }
175
147
        }
176
148
 
177
 
        if (globals.ind_cfg.foreground_color != NULL &&
178
 
            globals.ind_cfg.foreground_color[0] != 0) {
 
149
        if (ind_cfg->foreground_color != NULL &&
 
150
            ind_cfg->foreground_color[0] != 0) {
179
151
                if (sscanf
180
 
                    (globals.ind_cfg.foreground_color, "%lg %lg %lg", &r,
 
152
                    (ind_cfg->foreground_color, "%lg %lg %lg", &r,
181
153
                     &g, &b) == 3) {
182
154
                        cairo_set_source_rgb (cr, r, g, b);
183
155
                }
184
156
        }
185
157
 
186
 
        if (globals.ind_cfg.font_family != NULL &&
187
 
            globals.ind_cfg.font_family[0] != 0) {
188
 
                cairo_select_font_face (cr, globals.ind_cfg.font_family,
 
158
        if (ind_cfg->font_family != NULL && ind_cfg->font_family[0] != 0) {
 
159
                cairo_select_font_face (cr, ind_cfg->font_family,
189
160
                                        CAIRO_FONT_SLANT_NORMAL,
190
161
                                        CAIRO_FONT_WEIGHT_NORMAL);
191
162
        }
192
163
 
193
164
        pfd = pango_font_description_new ();
194
 
        pango_font_description_set_family (pfd,
195
 
                                           globals.ind_cfg.font_family);
 
165
        pango_font_description_set_family (pfd, ind_cfg->font_family);
196
166
        pango_font_description_set_style (pfd, PANGO_STYLE_NORMAL);
197
167
        pango_font_description_set_weight (pfd, PANGO_WEIGHT_NORMAL);
198
168
        pango_font_description_set_size (pfd,
199
 
                                         globals.ind_cfg.font_size *
200
 
                                         PANGO_SCALE);
 
169
                                         ind_cfg->font_size * PANGO_SCALE);
201
170
 
202
171
        pcc = pango_cairo_create_context (cr);
203
172
 
212
181
 
213
182
        pl = pango_layout_new (pcc);
214
183
 
215
 
        layout_name = gkbd_indicator_extract_layout_name (group,
216
 
                                                          globals.engine,
217
 
                                                          &globals.kbd_cfg,
218
 
                                                          globals.short_group_names,
219
 
                                                          globals.full_group_names);
 
184
        layout_name =
 
185
            gkbd_configuration_extract_layout_name (globals.config, group);
220
186
        lbl_title =
221
 
            gkbd_indicator_create_label_title (group, &ln2cnt_map,
222
 
                                               layout_name);
 
187
            gkbd_configuration_create_label_title (group, &ln2cnt_map,
 
188
                                                   layout_name);
223
189
 
224
 
        if (group + 1 == xkl_engine_get_num_groups (globals.engine)) {
 
190
        if (group + 1 ==
 
191
            xkl_engine_get_num_groups (gkbd_configuration_get_xkl_engine
 
192
                                       (globals.config))) {
225
193
                g_hash_table_destroy (ln2cnt_map);
226
194
                ln2cnt_map = NULL;
227
195
        }
293
261
}
294
262
 
295
263
static GdkPixbuf *
296
 
gkbd_status_prepare_drawing (GkbdStatus * gki, int group)
 
264
gkbd_status_prepare_drawing (int group)
297
265
{
298
266
        GError *gerror = NULL;
299
267
        char *image_filename;
302
270
        if (globals.current_width == 0)
303
271
                return NULL;
304
272
 
305
 
        if (globals.ind_cfg.show_flags) {
 
273
        if (gkbd_configuration_if_flags_shown (globals.config)) {
306
274
 
307
275
                image_filename =
308
 
                    (char *) g_slist_nth_data (globals.
309
 
                                               ind_cfg.image_filenames,
310
 
                                               group);
 
276
                    gkbd_configuration_get_image_filename (globals.config,
 
277
                                                           group);
311
278
 
312
279
                image = gdk_pixbuf_new_from_file_at_size (image_filename,
313
280
                                                          globals.current_width,
360
327
                char pngfilename[20];
361
328
                g_sprintf (pngfilename, "label%d.png", group);
362
329
                cairo_surface_write_to_png (cs, pngfilename);
 
330
                xkl_debug (150, "file %s is created\n", pngfilename);
363
331
#endif
364
332
                pixbuf_data =
365
333
                    g_new0 (guchar,
396
364
static void
397
365
gkbd_status_update_tooltips (GkbdStatus * gki)
398
366
{
399
 
        XklState *state = xkl_engine_get_current_state (globals.engine);
400
 
        gchar *buf;
401
 
        if (state == NULL || state->group < 0
402
 
            || state->group >= g_strv_length (globals.full_group_names))
403
 
                return;
404
 
 
405
 
        buf = g_strdup_printf (globals.tooltips_format,
406
 
                               globals.full_group_names[state->group]);
407
 
 
408
 
        gkbd_status_set_tooltips (gki, buf);
409
 
        g_free (buf);
 
367
        gchar *buf =
 
368
            gkbd_configuration_get_current_tooltip (globals.config);
 
369
        if (buf != NULL) {
 
370
                gkbd_status_set_tooltips (gki, buf);
 
371
                g_free (buf);
 
372
        }
 
373
}
 
374
 
 
375
void
 
376
gkbd_status_reinit_globals ()
 
377
{
 
378
        gkbd_status_cleanup_icons ();
 
379
        gkbd_status_fill_icons ();
410
380
}
411
381
 
412
382
void
413
383
gkbd_status_reinit_ui (GkbdStatus * gki)
414
384
{
415
 
        gkbd_status_global_cleanup (gki);
416
 
        gkbd_status_global_fill (gki);
417
 
 
418
385
        gkbd_status_set_current_page (gki);
419
386
}
420
387
 
421
388
/* Should be called once for all widgets */
422
389
static void
423
 
gkbd_status_cfg_changed (GConfClient * client,
424
 
                         guint cnxn_id, GConfEntry * entry)
425
 
{
426
 
        xkl_debug (100,
427
 
                   "General configuration changed in GConf - reiniting...\n");
428
 
        gkbd_desktop_config_load_from_gconf (&globals.cfg);
429
 
        gkbd_desktop_config_activate (&globals.cfg);
430
 
        ForAllIndicators () {
431
 
                gkbd_status_reinit_ui (gki);
432
 
        } NextIndicator ();
433
 
}
434
 
 
435
 
/* Should be called once for all widgets */
436
 
static void
437
 
gkbd_status_ind_cfg_changed (GConfClient * client,
438
 
                             guint cnxn_id, GConfEntry * entry)
439
 
{
440
 
        xkl_debug (100,
441
 
                   "Applet configuration changed in GConf - reiniting...\n");
442
 
        gkbd_indicator_config_load_from_gconf (&globals.ind_cfg);
443
 
 
444
 
        gkbd_indicator_config_free_image_filenames (&globals.ind_cfg);
445
 
        gkbd_indicator_config_load_image_filenames (&globals.ind_cfg,
446
 
                                                    &globals.kbd_cfg);
447
 
 
448
 
        gkbd_indicator_config_activate (&globals.ind_cfg);
449
 
 
450
 
        ForAllIndicators () {
451
 
                gkbd_status_reinit_ui (gki);
452
 
        } NextIndicator ();
453
 
}
454
 
 
455
 
static void
456
 
gkbd_status_load_group_names (const gchar ** layout_ids,
457
 
                              const gchar ** variant_ids)
458
 
{
459
 
        if (!gkbd_desktop_config_load_group_descriptions
460
 
            (&globals.cfg, globals.registry, layout_ids, variant_ids,
461
 
             &globals.short_group_names, &globals.full_group_names)) {
462
 
                /* We just populate no short names (remain NULL) - 
463
 
                 * full names are going to be used anyway */
464
 
                gint i, total_groups =
465
 
                    xkl_engine_get_num_groups (globals.engine);
466
 
                xkl_debug (150, "group descriptions loaded: %d!\n",
467
 
                           total_groups);
468
 
                globals.full_group_names =
469
 
                    g_new0 (char *, total_groups + 1);
470
 
 
471
 
                if (xkl_engine_get_features (globals.engine) &
472
 
                    XKLF_MULTIPLE_LAYOUTS_SUPPORTED) {
473
 
                        GSList *lst = globals.kbd_cfg.layouts_variants;
474
 
                        for (i = 0; lst; lst = lst->next, i++) {
475
 
                                globals.full_group_names[i] =
476
 
                                    g_strdup ((char *) lst->data);
477
 
                        }
478
 
                } else {
479
 
                        for (i = total_groups; --i >= 0;) {
480
 
                                globals.full_group_names[i] =
481
 
                                    g_strdup_printf ("Group %d", i);
482
 
                        }
483
 
                }
484
 
        }
485
 
}
486
 
 
487
 
/* Should be called once for all widgets */
488
 
static void
489
 
gkbd_status_kbd_cfg_callback (GkbdStatus * gki)
490
 
{
491
 
        XklConfigRec *xklrec = xkl_config_rec_new ();
492
 
        xkl_debug (100,
493
 
                   "XKB configuration changed on X Server - reiniting...\n");
494
 
 
495
 
        gkbd_keyboard_config_load_from_x_current (&globals.kbd_cfg,
496
 
                                                  xklrec);
497
 
 
498
 
        gkbd_indicator_config_free_image_filenames (&globals.ind_cfg);
499
 
        gkbd_indicator_config_load_image_filenames (&globals.ind_cfg,
500
 
                                                    &globals.kbd_cfg);
501
 
 
502
 
        g_strfreev (globals.full_group_names);
503
 
        globals.full_group_names = NULL;
504
 
 
505
 
        if (globals.short_group_names != NULL) {
506
 
                g_strfreev (globals.short_group_names);
507
 
                globals.short_group_names = NULL;
508
 
        }
509
 
 
510
 
        gkbd_status_load_group_names ((const gchar **) xklrec->layouts,
511
 
                                      (const gchar **) xklrec->variants);
512
 
 
513
 
        ForAllIndicators () {
514
 
                gkbd_status_reinit_ui (gki);
515
 
        } NextIndicator ();
516
 
        g_object_unref (G_OBJECT (xklrec));
 
390
gkbd_status_cfg_callback (GkbdConfiguration * configuration)
 
391
{
 
392
        xkl_debug (150, "Config changed: reinit ui\n");
 
393
        gkbd_status_reinit_globals ();
 
394
        ForAllObjects (configuration) {
 
395
                gkbd_status_reinit_ui (GKBD_STATUS (gki));
 
396
        } NextObject ()
517
397
}
518
398
 
519
399
/* Should be called once for all applets */
520
400
static void
521
 
gkbd_status_state_callback (XklEngine * engine,
522
 
                            XklEngineStateChange changeType,
523
 
                            gint group, gboolean restore)
 
401
gkbd_status_state_callback (GkbdConfiguration * configuration, gint group)
524
402
{
525
 
        xkl_debug (150, "group is now %d, restore: %d\n", group, restore);
526
 
 
527
 
        if (changeType == GROUP_CHANGED) {
528
 
                ForAllIndicators () {
529
 
                        xkl_debug (200, "do repaint\n");
530
 
                        gkbd_status_set_current_page_for_group (gki,
531
 
                                                                group);
532
 
                }
533
 
                NextIndicator ();
 
403
        xkl_debug (150, "Set page to group %d\n", group);
 
404
        ForAllObjects (configuration) {
 
405
                xkl_debug (150, "do repaint for icon %p\n", gki);
 
406
                gkbd_status_set_current_page_for_group (GKBD_STATUS (gki),
 
407
                                                        group);
534
408
        }
 
409
        NextObject ()
535
410
}
536
411
 
537
 
 
538
412
void
539
413
gkbd_status_set_current_page (GkbdStatus * gki)
540
414
{
541
 
        XklState *cur_state;
542
 
        cur_state = xkl_engine_get_current_state (globals.engine);
 
415
        XklEngine *engine =
 
416
            gkbd_configuration_get_xkl_engine (globals.config);
 
417
        XklState *cur_state = xkl_engine_get_current_state (engine);
543
418
        if (cur_state->group >= 0)
544
419
                gkbd_status_set_current_page_for_group (gki,
545
420
                                                        cur_state->group);
548
423
void
549
424
gkbd_status_set_current_page_for_group (GkbdStatus * gki, int group)
550
425
{
551
 
        xkl_debug (200, "Revalidating for group %d\n", group);
552
 
 
553
 
        gtk_status_icon_set_from_pixbuf (GTK_STATUS_ICON (gki),
554
 
                                         GDK_PIXBUF (g_slist_nth_data
555
 
                                                     (globals.icons,
556
 
                                                      group)));
 
426
        GdkPixbuf *page =
 
427
            GDK_PIXBUF (g_slist_nth_data (globals.icons, group));
 
428
        xkl_debug (150, "Revalidating for group %d: %p\n", group, page);
 
429
 
 
430
        if (page == NULL) {
 
431
                xkl_debug (0, "Page for group %d is not ready\n", group);
 
432
                return;
 
433
        }
 
434
 
 
435
        gtk_status_icon_set_from_pixbuf (GTK_STATUS_ICON (gki), page);
557
436
 
558
437
        gkbd_status_update_tooltips (gki);
559
438
}
563
442
gkbd_status_filter_x_evt (GdkXEvent * xev, GdkEvent * event)
564
443
{
565
444
        XEvent *xevent = (XEvent *) xev;
 
445
        XklEngine *engine =
 
446
            gkbd_configuration_get_xkl_engine (globals.config);
566
447
 
567
 
        xkl_engine_filter_events (globals.engine, xevent);
 
448
        xkl_engine_filter_events (engine, xevent);
568
449
        switch (xevent->type) {
569
450
        case ReparentNotify:
570
451
                {
571
452
                        XReparentEvent *rne = (XReparentEvent *) xev;
572
453
 
573
 
                        ForAllIndicators () {
 
454
                        ForAllObjects (globals.config) {
574
455
                                guint32 xid =
575
456
                                    gtk_status_icon_get_x11_window_id
576
457
                                    (GTK_STATUS_ICON (gki));
579
460
                                if (xid == rne->window) {
580
461
                                        /* if so - make it transparent... */
581
462
                                        xkl_engine_set_window_transparent
582
 
                                            (globals.engine, rne->window,
583
 
                                             TRUE);
 
463
                                            (engine, rne->window, TRUE);
584
464
                                }
585
465
                        }
586
 
                NextIndicator ()}
 
466
                NextObject ()}
587
467
                break;
588
468
        }
589
469
        return GDK_FILTER_CONTINUE;
599
479
        gdk_window_add_filter (gdk_get_default_root_window (),
600
480
                               (GdkFilterFunc) gkbd_status_filter_x_evt,
601
481
                               NULL);
602
 
 
603
 
        xkl_engine_start_listen (globals.engine,
604
 
                                 XKLL_TRACK_KEYBOARD_STATE);
605
482
}
606
483
 
607
484
/* Should be called once for all widgets */
608
485
static void
609
486
gkbd_status_stop_listen (void)
610
487
{
611
 
        xkl_engine_stop_listen (globals.engine, XKLL_TRACK_KEYBOARD_STATE);
612
 
 
613
488
        gdk_window_remove_filter (NULL, (GdkFilterFunc)
614
489
                                  gkbd_status_filter_x_evt, NULL);
615
490
        gdk_window_remove_filter
620
495
static void
621
496
gkbd_status_size_changed (GkbdStatus * gki, gint size)
622
497
{
 
498
        xkl_debug (150, "Size changed to %d\n", size);
623
499
        if (globals.current_height != size) {
624
500
                globals.current_height = size;
625
501
                globals.current_width = size * 3 / 2;
 
502
                gkbd_status_reinit_globals ();
626
503
                gkbd_status_reinit_ui (gki);
627
504
        }
628
505
}
631
508
gkbd_status_theme_changed (GtkSettings * settings, GParamSpec * pspec,
632
509
                           GkbdStatus * gki)
633
510
{
634
 
        gkbd_indicator_config_refresh_style (&globals.ind_cfg);
 
511
        xkl_debug (150, "Theme changed\n");
 
512
        gkbd_indicator_config_refresh_style
 
513
            (gkbd_configuration_get_indicator_config (globals.config));
 
514
        gkbd_status_reinit_globals ();
635
515
        gkbd_status_reinit_ui (gki);
636
516
}
637
517
 
640
520
{
641
521
        int i;
642
522
 
643
 
        if (!g_slist_length (globals.widget_instances))
 
523
        if (!gkbd_configuration_if_any_object_exists (globals.config))
644
524
                gkbd_status_global_init ();
645
525
 
646
526
        gki->priv = g_new0 (GkbdStatusPrivate, 1);
647
527
 
648
 
        /* This should give NA a hint about the order */
 
528
        /* This should give Notification Area a hint about the order of icons */
649
529
        gtk_status_icon_set_name (GTK_STATUS_ICON (gki), "keyboard");
650
530
 
651
 
        xkl_debug (100, "Initiating the widget startup process for %p\n",
 
531
        xkl_debug (100, "The status icon startup process for %p started\n",
652
532
                   gki);
653
533
 
654
 
        if (globals.engine == NULL) {
 
534
        if (gkbd_configuration_get_xkl_engine (globals.config) == NULL) {
655
535
                gkbd_status_set_tooltips (gki,
656
536
                                          _("XKB initialization error"));
657
537
                return;
658
538
        }
659
539
 
660
 
        gkbd_status_set_tooltips (gki, NULL);
661
 
 
662
 
        gkbd_status_global_fill (gki);
663
 
        gkbd_status_set_current_page (gki);
664
 
 
665
540
        /* append AFTER all initialization work is finished */
666
 
        globals.widget_instances =
667
 
            g_slist_append (globals.widget_instances, gki);
 
541
        gkbd_configuration_append_object (globals.config, G_OBJECT (gki));
668
542
 
669
543
        g_signal_connect (gki, "size-changed",
670
544
                          G_CALLBACK (gkbd_status_size_changed), NULL);
679
553
                                            G_CALLBACK
680
554
                                            (gkbd_status_theme_changed),
681
555
                                            gki);
 
556
 
 
557
        xkl_debug (100,
 
558
                   "The status icon startup process for %p completed\n",
 
559
                   gki);
682
560
}
683
561
 
684
562
static void
698
576
                                             [i]);
699
577
 
700
578
        /* remove BEFORE all termination work is finished */
701
 
        globals.widget_instances =
702
 
            g_slist_remove (globals.widget_instances, gki);
 
579
        gkbd_configuration_remove_object (globals.config, G_OBJECT (gki));
703
580
 
704
 
        gkbd_status_global_cleanup (gki);
 
581
        gkbd_status_cleanup_icons ();
705
582
 
706
583
        xkl_debug (100,
707
584
                   "The instance of gnome-kbd-status successfully finalized\n");
710
587
 
711
588
        G_OBJECT_CLASS (gkbd_status_parent_class)->finalize (obj);
712
589
 
713
 
        if (!g_slist_length (globals.widget_instances))
 
590
        if (!gkbd_configuration_if_any_object_exists (globals.config))
714
591
                gkbd_status_global_term ();
715
592
}
716
593
 
720
597
        xkl_debug (100, "*** Last  GkbdStatus instance *** \n");
721
598
        gkbd_status_stop_listen ();
722
599
 
723
 
        gkbd_desktop_config_stop_listen (&globals.cfg);
724
 
        gkbd_indicator_config_stop_listen (&globals.ind_cfg);
725
 
 
726
 
        gkbd_indicator_config_term (&globals.ind_cfg);
727
 
        gkbd_keyboard_config_term (&globals.kbd_cfg);
728
 
        gkbd_desktop_config_term (&globals.cfg);
729
 
 
730
 
        if (g_signal_handler_is_connected
731
 
            (globals.engine, globals.state_changed_handler)) {
732
 
                g_signal_handler_disconnect (globals.engine,
733
 
                                             globals.state_changed_handler);
734
 
                globals.state_changed_handler = 0;
735
 
        }
736
 
        if (g_signal_handler_is_connected
737
 
            (globals.engine, globals.config_changed_handler)) {
738
 
                g_signal_handler_disconnect (globals.engine,
739
 
                                             globals.config_changed_handler);
740
 
                globals.config_changed_handler = 0;
741
 
        }
742
 
 
743
 
        g_object_unref (G_OBJECT (globals.registry));
744
 
        globals.registry = NULL;
745
 
        g_object_unref (G_OBJECT (globals.engine));
746
 
        globals.engine = NULL;
 
600
        g_object_unref (globals.config);
 
601
        globals.config = NULL;
 
602
 
747
603
        xkl_debug (100, "*** Terminated globals *** \n");
748
604
}
749
605
 
756
612
 
757
613
        memset (&globals, 0, sizeof (globals));
758
614
 
759
 
        /* Initing some global vars */
760
 
        globals.tooltips_format = "%s";
761
 
 
762
615
        /* Initing vtable */
763
616
        object_class->finalize = gkbd_status_finalize;
764
 
 
765
 
        /* Signals */
766
617
}
767
618
 
768
619
static void
769
620
gkbd_status_global_init (void)
770
621
{
771
 
        GConfClient *gconf_client;
772
 
        XklConfigRec *xklrec = xkl_config_rec_new ();
773
 
 
774
 
        globals.engine = xkl_engine_get_instance (GDK_DISPLAY ());
775
 
        if (globals.engine == NULL) {
776
 
                xkl_debug (0, "Libxklavier initialization error");
777
 
                return;
778
 
        }
779
 
 
780
 
        gconf_client = gconf_client_get_default ();
781
 
 
782
 
        globals.state_changed_handler =
783
 
            g_signal_connect (globals.engine, "X-state-changed",
784
 
                              G_CALLBACK (gkbd_status_state_callback),
785
 
                              NULL);
786
 
        globals.config_changed_handler =
787
 
            g_signal_connect (globals.engine, "X-config-changed",
788
 
                              G_CALLBACK (gkbd_status_kbd_cfg_callback),
789
 
                              NULL);
790
 
 
791
 
        gkbd_desktop_config_init (&globals.cfg, gconf_client,
792
 
                                  globals.engine);
793
 
        gkbd_keyboard_config_init (&globals.kbd_cfg, gconf_client,
794
 
                                   globals.engine);
795
 
        gkbd_indicator_config_init (&globals.ind_cfg, gconf_client,
796
 
                                    globals.engine);
797
 
 
798
 
        g_object_unref (gconf_client);
799
 
 
800
 
        gkbd_desktop_config_load_from_gconf (&globals.cfg);
801
 
        gkbd_desktop_config_activate (&globals.cfg);
802
 
 
803
 
        globals.registry =
804
 
            xkl_config_registry_get_instance (globals.engine);
805
 
        xkl_config_registry_load (globals.registry,
806
 
                                  globals.cfg.load_extra_items);
807
 
 
808
 
        gkbd_keyboard_config_load_from_x_current (&globals.kbd_cfg,
809
 
                                                  xklrec);
810
 
 
811
 
        gkbd_indicator_config_load_from_gconf (&globals.ind_cfg);
812
 
 
813
 
        gkbd_indicator_config_load_image_filenames (&globals.ind_cfg,
814
 
                                                    &globals.kbd_cfg);
815
 
 
816
 
        gkbd_indicator_config_activate (&globals.ind_cfg);
817
 
 
818
 
        gkbd_status_load_group_names ((const gchar **) xklrec->layouts,
819
 
                                      (const gchar **) xklrec->variants);
820
 
        g_object_unref (G_OBJECT (xklrec));
821
 
 
822
 
        gkbd_desktop_config_start_listen (&globals.cfg,
823
 
                                          (GConfClientNotifyFunc)
824
 
                                          gkbd_status_cfg_changed, NULL);
825
 
        gkbd_indicator_config_start_listen (&globals.ind_cfg,
826
 
                                            (GConfClientNotifyFunc)
827
 
                                            gkbd_status_ind_cfg_changed,
828
 
                                            NULL);
 
622
        globals.config = gkbd_configuration_get ();
 
623
 
 
624
        g_signal_connect (globals.config, "group-changed",
 
625
                          G_CALLBACK (gkbd_status_state_callback), NULL);
 
626
        g_signal_connect (globals.config, "changed",
 
627
                          G_CALLBACK (gkbd_status_cfg_callback), NULL);
 
628
 
829
629
        gkbd_status_start_listen ();
830
630
 
831
631
        xkl_debug (100, "*** Inited globals *** \n");
841
641
XklEngine *
842
642
gkbd_status_get_xkl_engine ()
843
643
{
844
 
        return globals.engine;
 
644
        return gkbd_configuration_get_xkl_engine (globals.config);
845
645
}
846
646
 
 
647
/**
 
648
 * gkbd_status_get_group_names:
 
649
 * Returns: (transfer none) (array zero-terminated=1): List of group names
 
650
 */
847
651
gchar **
848
652
gkbd_status_get_group_names ()
849
653
{
850
 
        return globals.full_group_names;
 
654
        return (gchar **)
 
655
            gkbd_configuration_get_group_names (globals.config);
851
656
}
852
657
 
853
658
gchar *
854
659
gkbd_status_get_image_filename (guint group)
855
660
{
856
 
        if (!globals.ind_cfg.show_flags)
857
 
                return NULL;
858
 
        return gkbd_indicator_config_get_images_file (&globals.ind_cfg,
859
 
                                                      &globals.kbd_cfg,
 
661
        return gkbd_configuration_get_image_filename (globals.config,
860
662
                                                      group);
861
663
}
862
 
 
863
 
void
864
 
gkbd_status_set_angle (GkbdStatus * gki, gdouble angle)
865
 
{
866
 
        gki->priv->angle = angle;
867
 
}