~mterry/indicator-datetime/fix-show-clock

« back to all changes in this revision

Viewing changes to src/datetime-service.c

  • Committer: David Barth
  • Date: 2011-02-25 17:01:20 UTC
  • mfrom: (28.6.40 clock-prefs)
  • Revision ID: david.barth@canonical.com-20110225170120-10376wecmiat132u
merging in mterry's branch with the new preferences dialog

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
 
53
53
#include "datetime-interface.h"
54
54
#include "dbus-shared.h"
55
 
 
56
 
 
57
 
#define SETTINGS_INTERFACE "com.canonical.indicator.datetime"
58
 
#define SETTINGS_LOCATIONS "locations"
 
55
#include "settings-shared.h"
 
56
#include "utils.h"
 
57
 
59
58
 
60
59
static void geo_create_client (GeoclueMaster * master, GeoclueMasterClient * client, gchar * path, GError * error, gpointer user_data);
61
60
static gboolean update_appointment_menu_items (gpointer user_data);
92
91
static gchar                    * current_timezone = NULL;
93
92
static gchar                    * geo_timezone = NULL;
94
93
 
 
94
static void
 
95
set_timezone_label (DbusmenuMenuitem * mi, const gchar * location)
 
96
{
 
97
        gchar * zone, * name;
 
98
        split_settings_location (location, &zone, &name);
 
99
 
 
100
        dbusmenu_menuitem_property_set (mi, TIMEZONE_MENUITEM_PROP_NAME, name);
 
101
        dbusmenu_menuitem_property_set (mi, TIMEZONE_MENUITEM_PROP_ZONE, zone);
 
102
 
 
103
        g_free (zone);
 
104
        g_free (name);
 
105
}
 
106
 
95
107
/* Check to see if our timezones are the same */
96
108
static void
97
109
check_timezone_sync (void) {
116
128
                g_debug("Timezones are different");
117
129
        }
118
130
 
 
131
        gboolean show = g_settings_get_boolean (conf, SETTINGS_SHOW_LOCATIONS_S);
 
132
 
119
133
        if (geo_location != NULL && current_location != NULL) {
120
134
                g_debug("Got timezone %s", current_timezone);
121
135
                g_debug("Got timezone %s", geo_timezone);
144
158
                        
145
159
                        if (label != NULL) {
146
160
                                // TODO work out the current location name in a nice way
147
 
                                dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_ZONE, label);
 
161
                                set_timezone_label (current_location, label);
148
162
                                // TODO work out the current time at that location 
149
 
                                dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
 
163
                                dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, show);
150
164
                                dbusmenu_menuitem_property_set_bool(current_location, TIMEZONE_MENUITEM_PROP_RADIO, TRUE);
151
165
                        } else {
152
166
                                g_debug("Label for current location is null, this shouldn't happen");
153
167
                        }
154
168
                        if (geo_timezone != NULL) {     
155
169
                                // TODO work out the geo location name in a nice way
156
 
                                dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_ZONE, geo_timezone);
 
170
                                set_timezone_label (geo_location, geo_timezone);
157
171
                                // TODO work out the current time at that location 
158
 
                                dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
 
172
                                dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, show);
159
173
                        }
160
174
                } else {
161
175
                        // TODO work out the geo location name in a nice way
162
 
                        dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_ZONE, geo_timezone);
 
176
                        set_timezone_label (geo_location, geo_timezone);
163
177
                        // TODO work out the current time at that location 
164
 
                        dbusmenu_menuitem_property_set_bool(geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
 
178
                        dbusmenu_menuitem_property_set_bool(geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, show);
165
179
                        
166
180
                        // TODO work out the current location name in a nice way
167
 
                        dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_ZONE, current_timezone);
 
181
                        set_timezone_label (current_location, current_timezone);
168
182
                        // TODO work out the current time at that location 
169
183
                        dbusmenu_menuitem_property_set_bool(current_location, TIMEZONE_MENUITEM_PROP_RADIO, TRUE);
170
 
                        dbusmenu_menuitem_property_set_bool(current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
171
 
                        dbusmenu_menuitem_property_set_bool(locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
 
184
                        dbusmenu_menuitem_property_set_bool(current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, show);
 
185
                        dbusmenu_menuitem_property_set_bool(locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, show);
172
186
                }
173
187
        }
174
188
        g_debug("Finished checking timezone sync");
211
225
        return;
212
226
}
213
227
 
214
 
/* See how our timezone setting went */
215
 
static void
216
 
quick_set_tz_cb (OobsObject * obj, OobsResult result, gpointer user_data)
217
 
{
218
 
        if (result == OOBS_RESULT_OK) {
219
 
                g_debug("Timezone set");
220
 
        } else {
221
 
                g_warning("Unable to quick set timezone");
222
 
        }
223
 
        return;
224
 
}
225
 
 
226
 
/* Set the timezone to the Geoclue discovered one */
227
 
static void
228
 
quick_set_tz (DbusmenuMenuitem * menuitem, guint timestamp, gpointer user_data)
229
 
{
230
 
        const gchar * tz = dbusmenu_menuitem_property_get(menuitem, TIMEZONE_MENUITEM_PROP_ZONE);
231
 
 
232
 
        g_debug("Quick setting timezone to: %s", tz);
233
 
 
234
 
        g_return_if_fail(tz != NULL);
235
 
 
236
 
        if (g_strcmp0(tz, current_timezone) == 0)
237
 
                return;
238
 
 
239
 
        OobsObject * obj = oobs_time_config_get();
240
 
        g_return_if_fail(obj != NULL);
241
 
 
242
 
        OobsTimeConfig * timeconfig = OOBS_TIME_CONFIG(obj);
243
 
        oobs_time_config_set_timezone(timeconfig, tz);
244
 
 
245
 
        oobs_object_commit_async(obj, quick_set_tz_cb, NULL);
246
 
 
247
 
        return;
248
 
}
249
 
 
250
228
/* Updates the label in the date menuitem */
251
229
static gboolean
252
230
update_datetime (gpointer user_data)
359
337
static gboolean
360
338
update_timezone_menu_items(gpointer user_data) {
361
339
        g_debug("Updating timezone menu items");
362
 
        gchar ** locations = g_settings_get_strv(conf, SETTINGS_LOCATIONS);
 
340
        gchar ** locations = g_settings_get_strv(conf, SETTINGS_LOCATIONS_S);
363
341
        if (locations == NULL) { 
364
342
                g_debug("No locations configured (NULL)");
365
343
                return FALSE;
370
348
        
371
349
        /* Remove all of the previous locations */
372
350
        if (dconflocations != NULL) {
373
 
                g_debug("Freeing old locations");
374
351
                while (dconflocations != NULL) {
375
352
                        DbusmenuMenuitem * litem =  DBUSMENU_MENUITEM(dconflocations->data);
376
 
                        g_debug("Freeing old location: %p", litem);
377
353
                        // Remove all the existing menu items which are in dconflocations.
378
354
                        dconflocations = g_list_remove(dconflocations, litem);
379
355
                        dbusmenu_menuitem_child_delete(root, DBUSMENU_MENUITEM(litem));
381
357
                }
382
358
        }
383
359
        
 
360
        gboolean show = g_settings_get_boolean (conf, SETTINGS_SHOW_LOCATIONS_S);
 
361
 
384
362
        // TODO: Remove items from the dconflocations at the end of the iteration
385
363
        // Make sure if there are multiple locations, our current location is shown
386
364
        if (len > 0) {
387
 
                dbusmenu_menuitem_property_set_bool (locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
388
 
                dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
 
365
                dbusmenu_menuitem_property_set_bool (locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, show);
 
366
                dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, show);
389
367
                dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE);
390
368
        } else {
391
369
                g_debug("No locations configured (Empty List)");
400
378
                        g_debug("Adding timezone in update_timezones %s", locations[i]);
401
379
                        item = dbusmenu_menuitem_new();
402
380
                        dbusmenu_menuitem_property_set      (item, DBUSMENU_MENUITEM_PROP_TYPE, TIMEZONE_MENUITEM_TYPE);
403
 
                        dbusmenu_menuitem_property_set          (item, TIMEZONE_MENUITEM_PROP_ZONE, locations[i]);
 
381
                        set_timezone_label (item, locations[i]);
404
382
                        dbusmenu_menuitem_property_set_bool (item, TIMEZONE_MENUITEM_PROP_RADIO, FALSE);
405
383
                        dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE);
406
 
                        dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
 
384
                        dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_VISIBLE, show);
407
385
                        dbusmenu_menuitem_child_add_position (root, item, offset++);
408
 
                        g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL);
409
386
                        dconflocations = g_list_append(dconflocations, item);
410
387
                }
411
388
        }
716
693
{
717
694
        g_return_val_if_fail (settings != NULL, FALSE);
718
695
 
719
 
        gchar * timeadmin = g_find_program_in_path("time-admin");
 
696
        gchar * timeadmin = g_find_program_in_path("indicator-datetime-preferences");
720
697
        if (timeadmin != NULL) {
721
 
                g_debug("Found the time-admin application: %s", timeadmin);
 
698
                g_debug("Found the indicator-datetime-preferences application: %s", timeadmin);
722
699
                dbusmenu_menuitem_property_set_bool(settings, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE);
723
700
                g_free(timeadmin);
724
701
        } else {
725
 
                g_debug("Unable to find time-admin app.");
 
702
                g_debug("Unable to find indicator-datetime-preferences app.");
726
703
                dbusmenu_menuitem_property_set_bool(settings, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE);
727
704
        }
728
705
 
729
706
        return FALSE;
730
707
}
731
708
 
 
709
static void
 
710
show_locations_changed (void)
 
711
{
 
712
        /* Re-calculate */
 
713
        check_timezone_sync();
 
714
}
 
715
 
732
716
/* Does the work to build the default menu, really calls out
733
717
   to other functions but this is the core to clean up the
734
718
   main function. */
759
743
        
760
744
        locations_separator = dbusmenu_menuitem_new();
761
745
        dbusmenu_menuitem_property_set(locations_separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR);
762
 
        dbusmenu_menuitem_property_set_bool (locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
 
746
        dbusmenu_menuitem_property_set_bool (locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
763
747
        dbusmenu_menuitem_child_append(root, locations_separator);
764
748
 
765
749
        geo_location = dbusmenu_menuitem_new();
766
750
        dbusmenu_menuitem_property_set      (geo_location, DBUSMENU_MENUITEM_PROP_TYPE, TIMEZONE_MENUITEM_TYPE);
767
 
        dbusmenu_menuitem_property_set          (geo_location, TIMEZONE_MENUITEM_PROP_ZONE, "");
 
751
        set_timezone_label (geo_location, "");
768
752
        dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE);
769
753
        dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
770
 
        g_signal_connect(G_OBJECT(geo_location), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL);
771
754
        dbusmenu_menuitem_child_append(root, geo_location);
772
755
 
773
756
        current_location = dbusmenu_menuitem_new();
774
757
        dbusmenu_menuitem_property_set      (current_location, DBUSMENU_MENUITEM_PROP_TYPE, TIMEZONE_MENUITEM_TYPE);
775
 
        dbusmenu_menuitem_property_set          (current_location, TIMEZONE_MENUITEM_PROP_ZONE, "");
 
758
        set_timezone_label (current_location, "");
776
759
        dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE);
777
760
        dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
778
 
        g_signal_connect(G_OBJECT(current_location), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL);
779
761
        dbusmenu_menuitem_child_append(root, current_location);
780
762
        
781
763
        check_timezone_sync();
782
764
        
 
765
        g_signal_connect (conf, "changed::" SETTINGS_SHOW_LOCATIONS_S, G_CALLBACK (show_locations_changed), NULL);
 
766
 
783
767
        DbusmenuMenuitem * separator = dbusmenu_menuitem_new();
784
768
        dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR);
785
769
        dbusmenu_menuitem_child_append(root, separator);
788
772
        dbusmenu_menuitem_property_set     (settings, DBUSMENU_MENUITEM_PROP_LABEL, _("Time & Date Settings..."));
789
773
        /* insensitive until we check for available apps */
790
774
        dbusmenu_menuitem_property_set_bool(settings, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE);
791
 
        g_signal_connect(G_OBJECT(settings), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_cb), "time-admin");
 
775
        g_signal_connect(G_OBJECT(settings), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_cb), "indicator-datetime-preferences");
792
776
        dbusmenu_menuitem_child_append(root, settings);
793
777
        g_idle_add(check_for_timeadmin, NULL);
794
778