~vcs-imports/xneur/xneur

« back to all changes in this revision

Viewing changes to gxneur/src/trayicon.c

  • Committer: clr
  • Date: 2011-08-12 11:41:34 UTC
  • Revision ID: svn-v4:8587809b-efde-dc11-b4c0-001320bd50b9::954
Зависимость gxneur от gconf сделана опциональной.
Добавлена возможность передавать настройки gxneur через аргументы вызова.
Для значений настроек rendering_engine и show_in_the_tray используются case insensetive сравнения.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#endif
23
23
 
24
24
#include <gtk/gtk.h>
25
 
#include <gconf/gconf-client.h>
 
25
#ifdef HAVE_GCONF
 
26
#    include <gconf/gconf-client.h>
 
27
#endif
26
28
 
27
29
#include <stdlib.h>
28
30
#include <ctype.h>
37
39
 
38
40
#include "trayicon.h"
39
41
 
 
42
extern const char* arg_show_in_the_tray;
 
43
extern const char* arg_rendering_engine;
 
44
 
40
45
extern struct _xneur_config *xconfig;
41
46
 
42
47
struct _tray_icon *tray;
43
 
 
 
48
#ifdef HAVE_GCONF
44
49
GConfClient* gconfClient = NULL;
 
50
#endif
45
51
gchar *show_in_the_tray = NULL;
46
52
gchar *rendering_engine = NULL;
47
53
 
257
263
{
258
264
    const char * icon_name;
259
265
 
260
 
        if (strcmp(show_in_the_tray, "Icon") == 0)
 
266
        if (strcasecmp(show_in_the_tray, "Icon") == 0)
261
267
        {
262
268
                icon_name = PACKAGE;
263
269
                return icon_name;
341
347
 
342
348
 
343
349
        const char *icon_name = get_tray_icon_name(tray->images[kbd_gr]);
344
 
        if (strcmp(rendering_engine, "Built-in") == 0)
 
350
        if (strcasecmp(rendering_engine, "Built-in") == 0)
345
351
        {
346
352
                gtk_widget_destroy (tray->image);
347
 
                if (strcmp(show_in_the_tray, "Text") == 0)
 
353
                if (strcasecmp(show_in_the_tray, "Text") == 0)
348
354
                {
349
355
                        char *layout_name = strdup(xconfig->handle->languages[kbd_gr].dir);
350
356
                        for (unsigned int i=0; i < strlen(layout_name); i++)
360
366
                gtk_container_add(GTK_CONTAINER(tray->evbox), tray->image);
361
367
                gtk_widget_show_all(GTK_WIDGET(tray->tray_icon));
362
368
        }
363
 
        else if (strcmp(rendering_engine, "StatusIcon") == 0)
 
369
        else if (strcasecmp(rendering_engine, "StatusIcon") == 0)
364
370
        {
365
371
                if (gtk_status_icon_is_embedded(tray->status_icon))
366
372
                {                                       
367
 
                        if (strcmp(show_in_the_tray, "Text") == 0)
 
373
                        if (strcasecmp(show_in_the_tray, "Text") == 0)
368
374
                        {
369
375
                                char *layout_name = strdup(xconfig->handle->languages[kbd_gr].dir);
370
376
                                for (unsigned int i=0; i < strlen(layout_name); i++)
387
393
                        gtk_status_icon_set_tooltip(tray->status_icon, hint);
388
394
                }       
389
395
        }
390
 
        else if (strcmp(rendering_engine, "AppIndicator") == 0)
 
396
        else if (strcasecmp(rendering_engine, "AppIndicator") == 0)
391
397
        {
392
398
#ifdef HAVE_APP_INDICATOR
393
399
                char *layout_name = strdup(xconfig->handle->languages[kbd_gr].dir);
394
 
                if (strcmp(show_in_the_tray, "Text") == 0)
 
400
                if (strcasecmp(show_in_the_tray, "Text") == 0)
395
401
                {
396
402
                        for (unsigned int i=0; i < strlen(layout_name); i++)
397
403
                                layout_name[i] = toupper(layout_name[i]);
454
460
        gtk_main_quit();
455
461
}
456
462
 
 
463
#ifdef HAVE_GCONF
 
464
 
457
465
void gconf_key_show_in_the_tray_callback(GConfClient* client,
458
466
                            guint cnxn_id,
459
467
                            GConfEntry* entry,
460
468
                            gpointer user_data)
461
469
{
462
470
        if (client || cnxn_id || user_data) {};
 
471
 
 
472
        if (arg_show_in_the_tray)
 
473
                return;
463
474
        
464
475
        if (gconf_entry_get_value (entry) != NULL && gconf_entry_get_value (entry)->type == GCONF_VALUE_STRING)
465
476
                show_in_the_tray = strdup(gconf_value_get_string (gconf_entry_get_value (entry)));
474
485
{
475
486
        if (client || cnxn_id || user_data) {};
476
487
 
 
488
        if (arg_rendering_engine)
 
489
                return;
 
490
 
477
491
        const char *new_engine = rendering_engine;
478
492
        if (gconf_entry_get_value (entry) != NULL && gconf_entry_get_value (entry)->type == GCONF_VALUE_STRING)
479
493
                new_engine = strdup(gconf_value_get_string (gconf_entry_get_value (entry)));
480
494
 
481
 
        if (strcmp(new_engine, rendering_engine) == 0)
 
495
        if (strcasecmp(new_engine, rendering_engine) == 0)
482
496
                return;
483
497
        
484
498
        for (int i = 0; i < MAX_LAYOUTS; i++)
495
509
        gtk_main_quit();
496
510
}
497
511
 
 
512
#endif
 
513
 
498
514
void create_tray_icon (void)
499
515
{
500
516
        dpy = XOpenDisplay(NULL);
501
 
        
 
517
#ifdef HAVE_GCONF
502
518
        GConfClient* gconfClient = gconf_client_get_default();
503
519
 
504
520
        GConfValue* gcValue = NULL;
508
524
        {
509
525
                if(!gconf_client_set_string(gconfClient, PACKAGE_GCONF_DIR "show_in_the_tray", "Flag", NULL)) 
510
526
                    g_warning("Failed to set %s (%s)\n", PACKAGE_GCONF_DIR "show_in_the_tray", "Flag");
511
 
                show_in_the_tray = "Flag";
512
527
        }
513
528
        else
514
529
        {
534
549
                // 3. AppIndicator
535
550
                if(!gconf_client_set_string(gconfClient, PACKAGE_GCONF_DIR "rendering_engine", "StatusIcon", NULL)) 
536
551
                    g_warning("Failed to set %s (%s)\n", PACKAGE_GCONF_DIR "rendering_engine", "StatusIcon");
537
 
                rendering_engine = "StatusIcon";
538
552
        }
539
553
        else
540
554
        {
551
565
                          NULL,
552
566
                          NULL);
553
567
        //g_object_unref(gconfClient);
554
 
        
 
568
#endif
 
569
        if (arg_show_in_the_tray)
 
570
                show_in_the_tray = strdup(arg_show_in_the_tray);
 
571
        if (arg_rendering_engine)
 
572
                rendering_engine = strdup(arg_rendering_engine);
 
573
        if (!show_in_the_tray)
 
574
                show_in_the_tray = strdup("Flag");
 
575
        if (!rendering_engine)
 
576
                rendering_engine = strdup("StatusIcon");
 
577
 
 
578
 
555
579
        tray = g_new0(struct _tray_icon, 1);
556
580
#ifdef HAVE_APP_INDICATOR
557
581
        tray->app_indicator = NULL;
576
600
        
577
601
        tray->menu = create_menu(tray, xconfig->is_manual_mode(xconfig));
578
602
 
579
 
        if (strcmp(rendering_engine, "AppIndicator") == 0)
 
603
        if (strcasecmp(rendering_engine, "AppIndicator") == 0)
580
604
        {
581
605
#ifdef HAVE_APP_INDICATOR
582
606
                // App indicator
593
617
        gint kbd_gr = get_active_kbd_group(dpy);
594
618
        
595
619
        // Status Icon
596
 
        if (strcmp(rendering_engine, "StatusIcon") == 0)
 
620
        if (strcasecmp(rendering_engine, "StatusIcon") == 0)
597
621
        {
598
622
                tray->status_icon = gtk_status_icon_new();
599
623
 
604
628
                gtk_status_icon_set_tooltip_text(tray->status_icon, "X Neural Switcher");
605
629
                gtk_status_icon_set_visible(tray->status_icon, TRUE);
606
630
 
607
 
                if (strcmp(show_in_the_tray, "Text") == 0)
 
631
                if (strcasecmp(show_in_the_tray, "Text") == 0)
608
632
                {
609
633
                        char *layout_name = strdup(xconfig->handle->languages[kbd_gr].dir);
610
634
                        for (unsigned int i=0; i < strlen(layout_name); i++)
626
650
        }
627
651
        
628
652
        // Tray icon
629
 
        if (strcmp(rendering_engine, "Built-in") == 0)
 
653
        if (strcasecmp(rendering_engine, "Built-in") == 0)
630
654
        {
631
655
                tray->tray_icon = _gtk_tray_icon_new(_("X Neural Switcher"));
632
656
 
634
658
                
635
659
                tray->evbox             = gtk_event_box_new();
636
660
                gtk_event_box_set_visible_window(GTK_EVENT_BOX(tray->evbox), 0);
637
 
                if (strcmp(show_in_the_tray, "Text") == 0)
 
661
                if (strcasecmp(show_in_the_tray, "Text") == 0)
638
662
                {
639
663
                        char *layout_name = strdup(xconfig->handle->languages[kbd_gr].dir);
640
664
                        for (unsigned int i=0; i < strlen(layout_name); i++)