Merge lp:~mterry/indicator-datetime/live-location-updates into lp:indicator-datetime/0.3

Proposed by Michael Terry on 2011-03-24
Status: Merged
Merged at revision: 86
Proposed branch: lp:~mterry/indicator-datetime/live-location-updates
Merge into: lp:indicator-datetime/0.3
Prerequisite: lp:~mterry/indicator-datetime/bevel+utc
Diff against target: 159 lines (+58/-18)
1 file modified
src/datetime-prefs-locations.c (+58/-18)
To merge this branch: bzr merge lp:~mterry/indicator-datetime/live-location-updates
Reviewer Review Type Date Requested Status
Indicator Applet Developers 2011-03-24 Pending
Review via email: mp+54756@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/datetime-prefs-locations.c'
2--- src/datetime-prefs-locations.c 2011-03-24 18:19:24 +0000
3+++ src/datetime-prefs-locations.c 2011-03-24 18:19:24 +0000
4@@ -39,7 +39,8 @@
5 #define COL_TIME 1
6 #define COL_ZONE 2
7
8-static gboolean update_times (TimezoneCompletion * completion);
9+static gboolean update_times (GtkWidget * dlg);
10+static void save_when_idle (GtkWidget * dlg);
11
12 static void
13 handle_add (GtkWidget * button, GtkTreeView * tree)
14@@ -96,7 +97,7 @@
15
16 static gboolean
17 timezone_selected (GtkEntryCompletion * widget, GtkTreeModel * model,
18- GtkTreeIter * iter, gpointer user_data)
19+ GtkTreeIter * iter, GtkWidget * dlg)
20 {
21 const gchar * zone, * name;
22
23@@ -132,7 +133,7 @@
24 gtk_list_store_set (store, store_iter, COL_NAME, name, COL_ZONE, zone, -1);
25 }
26
27- update_times (TIMEZONE_COMPLETION (widget));
28+ update_times (dlg);
29
30 return FALSE; // Do normal action too
31 }
32@@ -155,9 +156,10 @@
33 }
34
35 static gboolean
36-update_times (TimezoneCompletion * completion)
37+update_times (GtkWidget * dlg)
38 {
39 /* For each entry, check zone in column 2 and set column 1 to it's time */
40+ TimezoneCompletion * completion = TIMEZONE_COMPLETION (g_object_get_data (G_OBJECT (dlg), "completion"));
41 GtkListStore * store = GTK_LIST_STORE (g_object_get_data (G_OBJECT (completion), "store"));
42 GObject * cell = G_OBJECT (g_object_get_data (G_OBJECT (completion), "name-cell"));
43
44@@ -167,6 +169,8 @@
45 return TRUE;
46 }
47
48+ g_signal_handlers_block_by_func (store, save_when_idle, dlg);
49+
50 GDateTime * now = g_date_time_new_now_local ();
51
52 GtkTreeIter iter;
53@@ -193,6 +197,9 @@
54 }
55
56 g_date_time_unref (now);
57+
58+ g_signal_handlers_unblock_by_func (store, save_when_idle, dlg);
59+
60 return TRUE;
61 }
62
63@@ -220,13 +227,8 @@
64 }
65
66 static void
67-dialog_closed (GtkWidget * dlg, GObject * store)
68+save_to_settings (GObject * store, GSettings * conf)
69 {
70- /* Cleanup a tad */
71- guint time_id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dlg), "time-id"));
72- g_source_remove (time_id);
73-
74- /* Now save to settings */
75 GVariantBuilder builder;
76 g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
77
78@@ -249,13 +251,47 @@
79 }
80
81 GVariant * locations = g_variant_builder_end (&builder);
82-
83- GSettings * conf = G_SETTINGS (g_object_get_data (G_OBJECT (dlg), "conf"));
84 g_settings_set_strv (conf, SETTINGS_LOCATIONS_S, g_variant_get_strv (locations, NULL));
85-
86 g_variant_unref (locations);
87 }
88
89+static gboolean
90+save_now (GtkWidget *dlg)
91+{
92+ GSettings * conf = G_SETTINGS (g_object_get_data (G_OBJECT (dlg), "conf"));
93+ GObject * completion = G_OBJECT (g_object_get_data (G_OBJECT (dlg), "completion"));
94+ GObject * store = G_OBJECT (g_object_get_data (completion, "store"));
95+
96+ save_to_settings (store, conf);
97+
98+ g_object_set_data (G_OBJECT (dlg), "save-id", GINT_TO_POINTER(0));
99+
100+ return FALSE;
101+}
102+
103+static void
104+save_when_idle (GtkWidget *dlg)
105+{
106+ guint save_id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dlg), "save-id"));
107+
108+ if (save_id == 0) {
109+ save_id = g_idle_add ((GSourceFunc)save_now, dlg);
110+ g_object_set_data (G_OBJECT (dlg), "save-id", GINT_TO_POINTER(save_id));
111+ }
112+}
113+
114+static void
115+dialog_closed (GtkWidget * dlg, GObject * store)
116+{
117+ /* Cleanup a tad */
118+ guint time_id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dlg), "time-id"));
119+ g_source_remove (time_id);
120+
121+ guint save_id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dlg), "save-id"));
122+ if (save_id > 0)
123+ g_source_remove (save_id);
124+}
125+
126 static void
127 selection_changed (GtkTreeSelection * selection, GtkWidget * remove_button)
128 {
129@@ -290,7 +326,7 @@
130 TimezoneCompletion * completion = timezone_completion_new ();
131 g_object_set_data (G_OBJECT (completion), "tzmap", map);
132 g_object_set_data (G_OBJECT (completion), "store", store);
133- g_signal_connect (completion, "match-selected", G_CALLBACK (timezone_selected), NULL);
134+ g_signal_connect (completion, "match-selected", G_CALLBACK (timezone_selected), dlg);
135
136 GtkCellRenderer * cell = gtk_cell_renderer_text_new ();
137 g_object_set (cell, "editable", TRUE, NULL);
138@@ -317,14 +353,18 @@
139 g_signal_connect (WIG ("removeButton"), "clicked", G_CALLBACK (handle_remove), tree);
140
141 fill_from_settings (store, conf);
142-
143- guint time_id = g_timeout_add_seconds (2, (GSourceFunc)update_times, completion);
144- update_times (completion);
145+ g_signal_connect_swapped (store, "row-deleted", G_CALLBACK (save_when_idle), dlg);
146+ g_signal_connect_swapped (store, "row-inserted", G_CALLBACK (save_when_idle), dlg);
147+ g_signal_connect_swapped (store, "row-changed", G_CALLBACK (save_when_idle), dlg);
148+ g_signal_connect_swapped (store, "rows-reordered", G_CALLBACK (save_when_idle), dlg);
149
150 g_object_set_data_full (G_OBJECT (dlg), "conf", g_object_ref (conf), g_object_unref);
151 g_object_set_data_full (G_OBJECT (dlg), "completion", completion, g_object_unref);
152+ g_signal_connect (dlg, "destroy", G_CALLBACK (dialog_closed), store);
153+
154+ guint time_id = g_timeout_add_seconds (2, (GSourceFunc)update_times, dlg);
155 g_object_set_data (G_OBJECT (dlg), "time-id", GINT_TO_POINTER(time_id));
156- g_signal_connect (dlg, "destroy", G_CALLBACK (dialog_closed), store);
157+ update_times (dlg);
158
159 gtk_window_set_transient_for (GTK_WINDOW (dlg), parent);
160

Subscribers

People subscribed via source and target branches