~ubuntu-branches/ubuntu/oneiric/gnome-panel/oneiric

« back to all changes in this revision

Viewing changes to applets/clock/clock.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-01-14 22:20:05 UTC
  • mto: (2.1.6 squeeze) (1.3.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 171.
  • Revision ID: james.westby@ubuntu.com-20100114222005-rll7tw9fojl3ac6z
Tags: upstream-2.29.5.1
ImportĀ upstreamĀ versionĀ 2.29.5.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
 
76
76
#define NEVER_SENSITIVE "never_sensitive"
77
77
 
78
 
#define N_GCONF_PREFS 12 /* Keep this in sync with the number of keys below! */
 
78
#define N_GCONF_PREFS 11 /* Keep this in sync with the number of keys below! */
79
79
#define KEY_FORMAT              "format"
80
80
#define KEY_SHOW_SECONDS        "show_seconds"
81
81
#define KEY_SHOW_DATE           "show_date"
82
82
#define KEY_SHOW_WEATHER        "show_weather"
83
83
#define KEY_SHOW_TEMPERATURE    "show_temperature"
84
 
#define KEY_GMT_TIME            "gmt_time"
85
84
#define KEY_CUSTOM_FORMAT       "custom_format"
86
85
#define KEY_SHOW_WEEK           "show_week_numbers"
87
86
#define KEY_CITIES              "cities"
161
160
        char        *custom_format;
162
161
        gboolean     showseconds;
163
162
        gboolean     showdate;
164
 
        gboolean     gmt_time;
165
163
        gboolean     showweek;
166
164
        gboolean     show_weather;
167
165
        gboolean     show_temperature;
178
176
        /* runtime data */
179
177
        time_t             current_time;
180
178
        char              *timeformat;
181
 
        char              *fallback_timeformat;
182
179
        guint              timeout;
183
180
        PanelAppletOrient  orient;
184
181
        int                size;
191
188
 
192
189
        GtkWidget *showseconds_check;
193
190
        GtkWidget *showdate_check;
194
 
        GtkWidget *gmt_time_check;
195
191
        GtkWidget *custom_hbox;
196
192
        GtkWidget *custom_label;
197
193
        GtkWidget *custom_entry;
432
428
}
433
429
 
434
430
static char *
435
 
get_updated_timeformat (ClockData *cd,
436
 
                        gboolean   safe)
 
431
get_updated_timeformat (ClockData *cd)
437
432
{
438
433
 /* Show date in another line if panel is vertical, or
439
434
  * horizontal but large enough to hold two lines of text
440
435
  */
441
436
        char       *result;
442
437
        const char *time_format;
443
 
        char       *time_gravity_format;
444
438
        const char *date_format;
445
439
        char       *clock_format;
446
440
 
455
449
                 * in France: 20:10). */
456
450
                time_format = cd->showseconds ? _("%H:%M:%S") : _("%H:%M");
457
451
 
458
 
        if (!safe) {
459
 
                /* FIXME: we need this for bug #410169 in pango. We'll be able
460
 
                 * to remove this at a later stage. */
461
 
                time_gravity_format = g_strdup_printf ("<span gravity=\"south\">%s</span>",
462
 
                                                       time_format);
463
 
        } else {
464
 
                time_gravity_format = g_strdup (time_format);
465
 
        }
466
 
 
467
452
        if (!cd->showdate)
468
 
                clock_format = g_strdup (time_gravity_format);
 
453
                clock_format = g_strdup (time_format);
469
454
 
470
455
        else {
471
456
                /* Translators: This is a strftime format string.
482
467
                         */
483
468
                        clock_format = g_strdup_printf (_("%1$s\n%2$s"),
484
469
                                                        date_format,
485
 
                                                        time_gravity_format);
 
470
                                                        time_format);
486
471
                else
487
472
                        /* translators: reverse the order of these arguments
488
473
                         *              if the time should come before the
490
475
                         */
491
476
                        clock_format = g_strdup_printf (_("%1$s, %2$s"),
492
477
                                                        date_format,
493
 
                                                        time_gravity_format);
 
478
                                                        time_format);
494
479
        }
495
480
 
496
 
        g_free (time_gravity_format);
497
 
 
498
481
        result = g_locale_from_utf8 (clock_format, -1, NULL, NULL, NULL);
499
482
        g_free (clock_format);
500
483
 
509
492
update_timeformat (ClockData *cd)
510
493
{
511
494
        g_free (cd->timeformat);
512
 
        cd->timeformat = get_updated_timeformat (cd, FALSE);
513
 
        g_free (cd->fallback_timeformat);
514
 
        cd->fallback_timeformat = get_updated_timeformat (cd, TRUE);
 
495
        cd->timeformat = get_updated_timeformat (cd);
515
496
}
516
497
 
517
498
/* sets accessible name and description for the widget */
555
536
 
556
537
        utf8 = NULL;
557
538
 
558
 
        if (cd->gmt_time)
559
 
                tm = gmtime (&cd->current_time);
560
 
        else
561
 
                tm = localtime (&cd->current_time);
 
539
        tm = localtime (&cd->current_time);
562
540
 
563
541
        if (cd->format == CLOCK_FORMAT_UNIX) {
564
542
                if (use_two_line_format (cd)) {
660
638
                struct tm now;
661
639
                char *tip;
662
640
 
663
 
                if (cd->gmt_time)
664
 
                        tm = gmtime (&cd->current_time);
665
 
                else
666
 
                        tm = localtime (&cd->current_time);
 
641
                tm = localtime (&cd->current_time);
667
642
 
668
643
                utf8 = NULL;
669
644
 
793
768
        cd->calendar_popup = NULL;
794
769
 
795
770
        g_free (cd->timeformat);
796
 
        g_free (cd->fallback_timeformat);
797
771
        g_free (cd->custom_format);
798
772
 
799
773
        free_locations (cd);
870
844
                                      cd->orient == PANEL_APPLET_ORIENT_UP);
871
845
        g_free (prefs_dir);
872
846
 
873
 
        calendar_window_set_utc_time (CALENDAR_WINDOW (window),
874
 
                                      cd->gmt_time);
875
847
        calendar_window_set_show_weeks (CALENDAR_WINDOW (window),
876
848
                                        cd->showweek);
877
849
        calendar_window_set_time_format (CALENDAR_WINDOW (window),
1616
1588
                                format = g_locale_from_utf8 (_("%H:%M"), -1, NULL, NULL, NULL);
1617
1589
                }
1618
1590
 
1619
 
                if (cd->gmt_time)
1620
 
                        tm = gmtime (&cd->current_time);
1621
 
                else
1622
 
                        tm = localtime (&cd->current_time);
 
1591
                tm = localtime (&cd->current_time);
1623
1592
 
1624
1593
                if (!format)
1625
1594
                        strcpy (string, "???");
1645
1614
        char string[256];
1646
1615
        char *utf8, *loc;
1647
1616
 
1648
 
        if (cd->gmt_time)
1649
 
                tm = gmtime (&cd->current_time);
1650
 
        else
1651
 
                tm = localtime (&cd->current_time);
 
1617
        tm = localtime (&cd->current_time);
1652
1618
 
1653
1619
        /* Translators: This is a strftime format string.
1654
1620
         * It is used to display a date in the full format (so that people can
2416
2382
}
2417
2383
 
2418
2384
static void
2419
 
gmt_time_changed (GConfClient  *client,
2420
 
                  guint         cnxn_id,
2421
 
                  GConfEntry   *entry,
2422
 
                  ClockData    *clock)
2423
 
{
2424
 
        gboolean value;
2425
 
 
2426
 
        if (!entry->value || entry->value->type != GCONF_VALUE_BOOL)
2427
 
                return;
2428
 
 
2429
 
        value = gconf_value_get_bool (entry->value);
2430
 
 
2431
 
        clock->gmt_time = (value != 0);
2432
 
 
2433
 
        refresh_clock_timeout (clock);
2434
 
 
2435
 
        if (clock->calendar_popup != NULL) {
2436
 
                calendar_window_set_utc_time (CALENDAR_WINDOW (clock->calendar_popup), clock->gmt_time);
2437
 
                position_calendar_popup (clock);
2438
 
        }
2439
 
}
2440
 
 
2441
 
static void
2442
2385
custom_format_changed (GConfClient  *client,
2443
2386
                       guint         cnxn_id,
2444
2387
                       GConfEntry   *entry,
2510
2453
                { KEY_SHOW_DATE,        (GConfClientNotifyFunc) show_date_changed },
2511
2454
                { KEY_SHOW_WEATHER,     (GConfClientNotifyFunc) show_weather_changed },
2512
2455
                { KEY_SHOW_TEMPERATURE, (GConfClientNotifyFunc) show_temperature_changed },
2513
 
                { KEY_GMT_TIME,         (GConfClientNotifyFunc) gmt_time_changed },
2514
2456
                { KEY_CUSTOM_FORMAT,    (GConfClientNotifyFunc) custom_format_changed },
2515
2457
                { KEY_SHOW_WEEK,        (GConfClientNotifyFunc) show_week_changed },
2516
2458
                { KEY_CITIES,           (GConfClientNotifyFunc) cities_changed },
2597
2539
 
2598
2540
        cd->show_weather = panel_applet_gconf_get_bool (applet, KEY_SHOW_WEATHER, NULL);
2599
2541
        cd->show_temperature = panel_applet_gconf_get_bool (applet, KEY_SHOW_TEMPERATURE, NULL);
2600
 
        cd->gmt_time = panel_applet_gconf_get_bool (applet, KEY_GMT_TIME, NULL);
2601
2542
        cd->showweek = panel_applet_gconf_get_bool (applet, KEY_SHOW_WEEK, NULL);
2602
2543
        cd->timeformat = NULL;
2603
 
        cd->fallback_timeformat = NULL;
2604
2544
 
2605
2545
        cd->can_handle_format_12 = (clock_locale_format () == CLOCK_FORMAT_12);
2606
2546
        if (!cd->can_handle_format_12 && cd->format == CLOCK_FORMAT_12)
2774
2714
        case CLOCK_FORMAT_24:
2775
2715
                gtk_widget_set_sensitive (cd->showseconds_check, TRUE);
2776
2716
                gtk_widget_set_sensitive (cd->showdate_check, TRUE);
2777
 
                gtk_widget_set_sensitive (cd->gmt_time_check, TRUE);
2778
2717
                gtk_widget_set_sensitive (cd->custom_entry, FALSE);
2779
2718
                gtk_widget_set_sensitive (cd->custom_label, FALSE);
2780
2719
                break;
2781
2720
        case CLOCK_FORMAT_UNIX:
2782
2721
                gtk_widget_set_sensitive (cd->showseconds_check, FALSE);
2783
2722
                gtk_widget_set_sensitive (cd->showdate_check, FALSE);
2784
 
                gtk_widget_set_sensitive (cd->gmt_time_check, FALSE);
2785
2723
                gtk_widget_set_sensitive (cd->custom_entry, FALSE);
2786
2724
                gtk_widget_set_sensitive (cd->custom_label, FALSE);
2787
2725
                break;
2788
2726
        case CLOCK_FORMAT_INTERNET:
2789
2727
                gtk_widget_set_sensitive (cd->showseconds_check, TRUE);
2790
2728
                gtk_widget_set_sensitive (cd->showdate_check, FALSE);
2791
 
                gtk_widget_set_sensitive (cd->gmt_time_check, FALSE);
2792
2729
                gtk_widget_set_sensitive (cd->custom_entry, FALSE);
2793
2730
                gtk_widget_set_sensitive (cd->custom_label, FALSE);
2794
2731
                break;
2795
2732
        case CLOCK_FORMAT_CUSTOM:
2796
2733
                gtk_widget_set_sensitive (cd->showseconds_check, FALSE);
2797
2734
                gtk_widget_set_sensitive (cd->showdate_check, FALSE);
2798
 
                gtk_widget_set_sensitive (cd->gmt_time_check, TRUE);
2799
2735
                gtk_widget_set_sensitive (cd->custom_entry, TRUE);
2800
2736
                gtk_widget_set_sensitive (cd->custom_label, TRUE);
2801
2737
                break;
3682
3618
                                       KEY_CUSTOM_FORMAT);
3683
3619
        setup_writability_sensitivity (cd, cd->showseconds_check, NULL, KEY_SHOW_SECONDS);
3684
3620
        setup_writability_sensitivity (cd, cd->showdate_check, NULL, KEY_SHOW_DATE);
3685
 
        setup_writability_sensitivity (cd, cd->gmt_time_check, NULL, KEY_GMT_TIME);
3686
3621
 
3687
3622
        gtk_widget_show (cd->props);
3688
3623
#endif