diff options
Diffstat (limited to 'src/identity/gnunet-identity-gtk.c')
-rw-r--r-- | src/identity/gnunet-identity-gtk.c | 238 |
1 files changed, 214 insertions, 24 deletions
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); |