diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-08-10 21:06:01 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-08-10 21:06:01 +0000 |
commit | 9520082e85a60735dd0cea1776a49ef9682359d9 (patch) | |
tree | 2457760d78ede359c0f53a1733c0b958a8abb3ed | |
parent | ac493b4f502987343bae691996a89635d4a5a58e (diff) | |
download | gnunet-gtk-9520082e85a60735dd0cea1776a49ef9682359d9.tar.gz gnunet-gtk-9520082e85a60735dd0cea1776a49ef9682359d9.zip |
-more work on identity event handling
-rw-r--r-- | contrib/gnunet_identity_gtk_main_window.glade | 4 | ||||
-rw-r--r-- | src/fs/gnunet-fs-gtk.c | 4 | ||||
-rw-r--r-- | src/fs/gnunet-fs-gtk_event-handler.c | 11 | ||||
-rw-r--r-- | src/identity/gnunet-identity-gtk.c | 238 |
4 files changed, 225 insertions, 32 deletions
diff --git a/contrib/gnunet_identity_gtk_main_window.glade b/contrib/gnunet_identity_gtk_main_window.glade index 2e19a3b7..098b6af1 100644 --- a/contrib/gnunet_identity_gtk_main_window.glade +++ b/contrib/gnunet_identity_gtk_main_window.glade | |||
@@ -14,7 +14,9 @@ | |||
14 | </object> | 14 | </object> |
15 | <object class="GtkWindow" id="GNUNET_GTK_identity_window"> | 15 | <object class="GtkWindow" id="GNUNET_GTK_identity_window"> |
16 | <property name="can_focus">False</property> | 16 | <property name="can_focus">False</property> |
17 | <property name="events">GDK_BUTTON_PRESS_MASK | GDK_STRUCTURE_MASK</property> | ||
17 | <property name="icon_name">contact-new</property> | 18 | <property name="icon_name">contact-new</property> |
19 | <signal name="delete-event" handler="GNUNET_GTK_identity_quit_cb" swapped="no"/> | ||
18 | <child> | 20 | <child> |
19 | <object class="GtkVBox" id="GNUNET_GTK_identityvbox"> | 21 | <object class="GtkVBox" id="GNUNET_GTK_identityvbox"> |
20 | <property name="visible">True</property> | 22 | <property name="visible">True</property> |
@@ -44,7 +46,7 @@ | |||
44 | </object> | 46 | </object> |
45 | </child> | 47 | </child> |
46 | </object> | 48 | </object> |
47 | </child>_ | 49 | </child> |
48 | </object> | 50 | </object> |
49 | </child> | 51 | </child> |
50 | <child> | 52 | <child> |
diff --git a/src/fs/gnunet-fs-gtk.c b/src/fs/gnunet-fs-gtk.c index 2ce26bf0..a05486e8 100644 --- a/src/fs/gnunet-fs-gtk.c +++ b/src/fs/gnunet-fs-gtk.c | |||
@@ -342,8 +342,8 @@ GNUNET_FS_GTK_main_window_button_press_event (GtkWidget * widget, | |||
342 | GdkEventButton *event_button = (GdkEventButton *) event; | 342 | GdkEventButton *event_button = (GdkEventButton *) event; |
343 | GtkClipboard *cb; | 343 | GtkClipboard *cb; |
344 | 344 | ||
345 | if ( (event->type != GDK_BUTTON_PRESS) || | 345 | if ( (GDK_BUTTON_PRESS != event->type) || |
346 | (event_button->button != 2) ) | 346 | (2 != event_button->button) ) |
347 | return FALSE; | 347 | return FALSE; |
348 | cb = gtk_clipboard_get (gdk_atom_intern ("PRIMARY", FALSE)); | 348 | cb = gtk_clipboard_get (gdk_atom_intern ("PRIMARY", FALSE)); |
349 | gtk_clipboard_request_text (cb, &process_paste, NULL); | 349 | gtk_clipboard_request_text (cb, &process_paste, NULL); |
diff --git a/src/fs/gnunet-fs-gtk_event-handler.c b/src/fs/gnunet-fs-gtk_event-handler.c index bbe7772d..4b28903b 100644 --- a/src/fs/gnunet-fs-gtk_event-handler.c +++ b/src/fs/gnunet-fs-gtk_event-handler.c | |||
@@ -657,6 +657,7 @@ search_list_popup_selection_done (GtkMenuShell *menushell, | |||
657 | GNUNET_free (spc); | 657 | GNUNET_free (spc); |
658 | } | 658 | } |
659 | 659 | ||
660 | |||
660 | /** | 661 | /** |
661 | * Selected row has changed in search result tree view, update preview | 662 | * Selected row has changed in search result tree view, update preview |
662 | * and metadata areas. | 663 | * and metadata areas. |
@@ -1273,8 +1274,8 @@ GNUNET_FS_GTK_search_treeview_button_press_event (GtkWidget * widget, | |||
1273 | GtkTreePath *path; | 1274 | GtkTreePath *path; |
1274 | GtkTreeIter iter; | 1275 | GtkTreeIter iter; |
1275 | 1276 | ||
1276 | if ( (event->type != GDK_BUTTON_PRESS) || | 1277 | if ( (GDK_BUTTON_PRESS != event->type) || |
1277 | (event_button->button != 3) ) | 1278 | (3 != event_button->button) ) |
1278 | return FALSE; /* not a right-click */ | 1279 | return FALSE; /* not a right-click */ |
1279 | if (! gtk_tree_view_get_path_at_pos (tv, | 1280 | if (! gtk_tree_view_get_path_at_pos (tv, |
1280 | event_button->x, event_button->y, | 1281 | event_button->x, event_button->y, |
@@ -1285,9 +1286,9 @@ GNUNET_FS_GTK_search_treeview_button_press_event (GtkWidget * widget, | |||
1285 | return FALSE; /* not sure how we got a path but no iter... */ | 1286 | return FALSE; /* not sure how we got a path but no iter... */ |
1286 | gtk_tree_path_free (path); | 1287 | gtk_tree_path_free (path); |
1287 | search_list_popup (tm, tab, | 1288 | search_list_popup (tm, tab, |
1288 | event_button->button, | 1289 | event_button->button, |
1289 | event_button->time, | 1290 | event_button->time, |
1290 | &iter); | 1291 | &iter); |
1291 | return FALSE; | 1292 | return FALSE; |
1292 | } | 1293 | } |
1293 | 1294 | ||
diff --git a/src/identity/gnunet-identity-gtk.c b/src/identity/gnunet-identity-gtk.c index 6b87e812..69db7e65 100644 --- a/src/identity/gnunet-identity-gtk.c +++ b/src/identity/gnunet-identity-gtk.c | |||
@@ -96,6 +96,40 @@ struct OperationContext | |||
96 | 96 | ||
97 | 97 | ||
98 | /** | 98 | /** |
99 | * Head of operations. | ||
100 | */ | ||
101 | static struct OperationContext *oc_head; | ||
102 | |||
103 | /** | ||
104 | * Tail of operations. | ||
105 | */ | ||
106 | static struct OperationContext *oc_tail; | ||
107 | |||
108 | |||
109 | /** | ||
110 | * Get cfg. | ||
111 | */ | ||
112 | static const struct GNUNET_CONFIGURATION_Handle * | ||
113 | get_configuration () | ||
114 | { | ||
115 | return GNUNET_GTK_main_loop_get_configuration (ml); | ||
116 | } | ||
117 | |||
118 | |||
119 | /** | ||
120 | * Get an object from the main window. | ||
121 | * | ||
122 | * @param name name of the object | ||
123 | * @return NULL on error | ||
124 | */ | ||
125 | static GObject * | ||
126 | get_object (const char *name) | ||
127 | { | ||
128 | return GNUNET_GTK_main_loop_get_object (ml, name); | ||
129 | } | ||
130 | |||
131 | |||
132 | /** | ||
99 | * Identity operation was finished, clean up. | 133 | * Identity operation was finished, clean up. |
100 | * | 134 | * |
101 | * @param cls the 'struct OperationContext' | 135 | * @param cls the 'struct OperationContext' |
@@ -107,11 +141,173 @@ operation_finished (void *cls, | |||
107 | { | 141 | { |
108 | struct OperationContext *oc = cls; | 142 | struct OperationContext *oc = cls; |
109 | 143 | ||
144 | GNUNET_CONTAINER_DLL_remove (oc_head, | ||
145 | oc_tail, | ||
146 | oc); | ||
147 | gtk_widget_set_sensitive (GTK_WIDGET (get_object ("GNUNET_GTK_identity_treeview")), | ||
148 | TRUE); | ||
110 | GNUNET_free (oc); | 149 | GNUNET_free (oc); |
111 | } | 150 | } |
112 | 151 | ||
113 | 152 | ||
114 | /** | 153 | /** |
154 | * Context for the advertise popup menu. | ||
155 | */ | ||
156 | struct AdvertisePopupContext | ||
157 | { | ||
158 | /** | ||
159 | * Ego to advertise. | ||
160 | */ | ||
161 | struct GNUNET_IDENTITY_Ego *ego; | ||
162 | |||
163 | /** | ||
164 | * Row where the search list popup was created. | ||
165 | */ | ||
166 | GtkTreeRowReference *rr; | ||
167 | |||
168 | }; | ||
169 | |||
170 | |||
171 | /** | ||
172 | * "Advertise" was selected in the current context menu. | ||
173 | * | ||
174 | * @param item the 'advertise' menu item | ||
175 | * @param user_data the 'struct AdvertisePopupContext' of the menu | ||
176 | */ | ||
177 | static void | ||
178 | advertise_ctx_menu (GtkMenuItem *item, | ||
179 | gpointer user_data) | ||
180 | { | ||
181 | struct AdvertisePopupContext *apc = user_data; | ||
182 | |||
183 | fprintf (stderr, "ADVERTISE TIME!\n"); | ||
184 | } | ||
185 | |||
186 | |||
187 | /** | ||
188 | * An item was selected from the context menu; destroy the menu shell. | ||
189 | * | ||
190 | * @param menushell menu to destroy | ||
191 | * @param user_data the 'struct AdvertisePopupContext' of the menu | ||
192 | */ | ||
193 | static void | ||
194 | advertise_popup_selection_done (GtkMenuShell *menushell, | ||
195 | gpointer user_data) | ||
196 | { | ||
197 | struct AdvertisePopupContext *apc = user_data; | ||
198 | |||
199 | gtk_widget_destroy (GTK_WIDGET (menushell)); | ||
200 | gtk_tree_row_reference_free (apc->rr); | ||
201 | GNUNET_free (apc); | ||
202 | } | ||
203 | |||
204 | |||
205 | /** | ||
206 | * User clicked in the treeview widget. Check for right button | ||
207 | * to possibly launch advertise window. | ||
208 | * | ||
209 | * @param widget the treeview widget | ||
210 | * @param event the event, we only care about button events | ||
211 | * @param user_data unused | ||
212 | * @return FALSE if no menu could be popped up, | ||
213 | * TRUE if there is now a pop-up menu | ||
214 | */ | ||
215 | gboolean | ||
216 | GNUNET_GTK_identity_treeview_button_press_event_cb (GtkWidget *widget, | ||
217 | GdkEvent *event, | ||
218 | gpointer user_data) | ||
219 | { | ||
220 | GtkTreeView *tv = GTK_TREE_VIEW (widget); | ||
221 | GdkEventButton *event_button = (GdkEventButton *) event; | ||
222 | GtkTreeModel *tm; | ||
223 | GtkTreePath *path; | ||
224 | GtkTreeIter iter; | ||
225 | GtkMenu *menu; | ||
226 | GtkWidget *child; | ||
227 | struct AdvertisePopupContext *apc; | ||
228 | struct GNUNET_IDENTITY_Ego *ego; | ||
229 | |||
230 | if ( (GDK_BUTTON_PRESS != event->type) || | ||
231 | (3 != event_button->button) ) | ||
232 | return FALSE; | ||
233 | if (! gtk_tree_view_get_path_at_pos (tv, | ||
234 | event_button->x, event_button->y, | ||
235 | &path, NULL, NULL, NULL)) | ||
236 | return FALSE; /* click outside of area with values, ignore */ | ||
237 | tm = gtk_tree_view_get_model (tv); | ||
238 | if (! gtk_tree_model_get_iter (tm, &iter, path)) | ||
239 | { | ||
240 | gtk_tree_path_free (path); | ||
241 | return FALSE; /* not sure how we got a path but no iter... */ | ||
242 | } | ||
243 | gtk_tree_model_get (GTK_TREE_MODEL (ls), &iter, | ||
244 | IDENTITY_MC_EGO, &ego, | ||
245 | -1); | ||
246 | if (NULL == ego) | ||
247 | return FALSE; | ||
248 | apc = GNUNET_new (struct AdvertisePopupContext); | ||
249 | apc->ego = ego; | ||
250 | apc->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (ls), path); | ||
251 | gtk_tree_path_free (path); | ||
252 | menu = GTK_MENU (gtk_menu_new ()); | ||
253 | child = gtk_menu_item_new_with_label (_("_Advertise")); | ||
254 | g_signal_connect (child, "activate", | ||
255 | G_CALLBACK (advertise_ctx_menu), apc); | ||
256 | gtk_label_set_use_underline (GTK_LABEL | ||
257 | (gtk_bin_get_child (GTK_BIN (child))), | ||
258 | TRUE); | ||
259 | gtk_widget_show (child); | ||
260 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), child); | ||
261 | g_signal_connect (menu, "selection-done", | ||
262 | G_CALLBACK (advertise_popup_selection_done), apc); | ||
263 | gtk_menu_popup (menu, NULL, NULL, NULL, NULL, | ||
264 | event_button->button, | ||
265 | event_button->time); | ||
266 | return FALSE; | ||
267 | } | ||
268 | |||
269 | |||
270 | /** | ||
271 | * User pushed a key (possibly DEL) in the treeview widget. | ||
272 | * Delete the selected entry if the key was DEL. | ||
273 | * | ||
274 | * @param widget the entry widget | ||
275 | * @param event the key stroke | ||
276 | * @param user_data the main window context | ||
277 | * @return FALSE if this was not ENTER, TRUE if it was | ||
278 | */ | ||
279 | gboolean | ||
280 | GNUNET_GTK_identity_treeview_key_press_event_cb (GtkWidget * widget, | ||
281 | GdkEventKey * event, | ||
282 | gpointer user_data) | ||
283 | { | ||
284 | gchar *old; | ||
285 | struct OperationContext *oc; | ||
286 | GtkTreeSelection *sel; | ||
287 | GtkTreeIter iter; | ||
288 | |||
289 | if (GDK_KEY_Delete != event->keyval) | ||
290 | return FALSE; | ||
291 | sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (get_object ("GNUNET_GTK_identity_treeview"))); | ||
292 | if (! gtk_tree_selection_get_selected (sel, NULL, &iter)) | ||
293 | return FALSE; | ||
294 | gtk_tree_model_get (GTK_TREE_MODEL (ls), | ||
295 | &iter, | ||
296 | IDENTITY_MC_NAME, &old, | ||
297 | -1); | ||
298 | oc = GNUNET_new (struct OperationContext); | ||
299 | GNUNET_CONTAINER_DLL_insert (oc_head, | ||
300 | oc_tail, | ||
301 | oc); | ||
302 | oc->op = GNUNET_IDENTITY_delete (identity, | ||
303 | old, | ||
304 | &operation_finished, | ||
305 | oc); | ||
306 | return TRUE; | ||
307 | } | ||
308 | |||
309 | |||
310 | /** | ||
115 | * The user edited one of the names of the egos. Change it | 311 | * The user edited one of the names of the egos. Change it |
116 | * in the IDENTITY service. | 312 | * in the IDENTITY service. |
117 | * | 313 | * |
@@ -148,7 +344,12 @@ GNUNET_GTK_namespace_organizer_namespaces_treeview_column_name_text_edited_cb | |||
148 | IDENTITY_MC_NAME, &old, | 344 | IDENTITY_MC_NAME, &old, |
149 | IDENTITY_MC_EGO, &ego, | 345 | IDENTITY_MC_EGO, &ego, |
150 | -1); | 346 | -1); |
347 | gtk_widget_set_sensitive (GTK_WIDGET (get_object ("GNUNET_GTK_identity_treeview")), | ||
348 | FALSE); | ||
151 | oc = GNUNET_new (struct OperationContext); | 349 | oc = GNUNET_new (struct OperationContext); |
350 | GNUNET_CONTAINER_DLL_insert (oc_head, | ||
351 | oc_tail, | ||
352 | oc); | ||
152 | if (NULL == ego) | 353 | if (NULL == ego) |
153 | { | 354 | { |
154 | /* create operation */ | 355 | /* create operation */ |
@@ -177,29 +378,6 @@ GNUNET_GTK_namespace_organizer_namespaces_treeview_column_name_text_edited_cb | |||
177 | 378 | ||
178 | 379 | ||
179 | /** | 380 | /** |
180 | * Get cfg. | ||
181 | */ | ||
182 | static const struct GNUNET_CONFIGURATION_Handle * | ||
183 | get_configuration () | ||
184 | { | ||
185 | return GNUNET_GTK_main_loop_get_configuration (ml); | ||
186 | } | ||
187 | |||
188 | |||
189 | /** | ||
190 | * Get an object from the main window. | ||
191 | * | ||
192 | * @param name name of the object | ||
193 | * @return NULL on error | ||
194 | */ | ||
195 | static GObject * | ||
196 | get_object (const char *name) | ||
197 | { | ||
198 | return GNUNET_GTK_main_loop_get_object (ml, name); | ||
199 | } | ||
200 | |||
201 | |||
202 | /** | ||
203 | * Task run on shutdown. | 381 | * Task run on shutdown. |
204 | * | 382 | * |
205 | * @param cls unused | 383 | * @param cls unused |
@@ -208,6 +386,18 @@ get_object (const char *name) | |||
208 | static void | 386 | static void |
209 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 387 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
210 | { | 388 | { |
389 | struct OperationContext *oc; | ||
390 | |||
391 | while (NULL != (oc = oc_head)) | ||
392 | { | ||
393 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
394 | _("Operation not completed due to shutdown\n")); | ||
395 | GNUNET_IDENTITY_cancel (oc->op); | ||
396 | GNUNET_CONTAINER_DLL_remove (oc_head, | ||
397 | oc_tail, | ||
398 | oc); | ||
399 | GNUNET_free (oc); | ||
400 | } | ||
211 | if (NULL != identity) | 401 | if (NULL != identity) |
212 | { | 402 | { |
213 | GNUNET_IDENTITY_disconnect (identity); | 403 | GNUNET_IDENTITY_disconnect (identity); |
@@ -294,7 +484,7 @@ add_ego (void *cls, | |||
294 | GNUNET_assert (gtk_tree_model_get_iter (GTK_TREE_MODEL (ls), | 484 | GNUNET_assert (gtk_tree_model_get_iter (GTK_TREE_MODEL (ls), |
295 | &iter, path)); | 485 | &iter, path)); |
296 | gtk_list_store_set (ls, | 486 | gtk_list_store_set (ls, |
297 | &iter, G_MAXINT, | 487 | &iter, |
298 | IDENTITY_MC_NAME, name, | 488 | IDENTITY_MC_NAME, name, |
299 | -1); | 489 | -1); |
300 | gtk_tree_path_free (path); | 490 | gtk_tree_path_free (path); |