gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r19703 - gnunet-gtk/src/fs


From: gnunet
Subject: [GNUnet-SVN] r19703 - gnunet-gtk/src/fs
Date: Sun, 5 Feb 2012 19:52:38 +0100

Author: grothoff
Date: 2012-02-05 19:52:38 +0100 (Sun, 05 Feb 2012)
New Revision: 19703

Modified:
   gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c
Log:
-adding context menu for publish tab, allowing abort and copying of URI

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c     2012-02-05 18:48:20 UTC 
(rev 19702)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c     2012-02-05 18:52:38 UTC 
(rev 19703)
@@ -553,11 +553,10 @@
  * Copy current URI to clipboard was selected in the current context menu.
  * 
  * @param item the 'copy-to-clipboard' menu item
- * @parma user_data NULL
  * @parma user_data the 'struct SearchListPopupContext' of the menu
  */
 static void
-copy_uri_to_clipboard_ctx_menu (GtkMenuItem *item, gpointer user_data)
+copy_search_uri_to_clipboard_ctx_menu (GtkMenuItem *item, gpointer user_data)
 {
   struct SearchListPopupContext *spc = user_data;
   GtkTreePath *path;
@@ -619,8 +618,6 @@
   struct GNUNET_FS_Uri *uri;
   struct SearchListPopupContext *spc;
 
-  /* FIXME-UNCLEAN: move these to some menu context struct
-     (de-globalize) */
   spc = GNUNET_malloc (sizeof (struct SearchListPopupContext));
   spc->tab = tab;
   path = gtk_tree_model_get_path (tm, iter);
@@ -651,7 +648,6 @@
     gtk_widget_show (child);
     gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
 
-
     child = gtk_menu_item_new_with_label (_("Download _as..."));
     g_signal_connect (child, "activate",
                      G_CALLBACK (start_download_as_ctx_menu), spc);
@@ -677,14 +673,14 @@
   {
     child = gtk_menu_item_new_with_label (_("_Copy URI to Clipboard"));
     g_signal_connect (child, "activate",
-                     G_CALLBACK (copy_uri_to_clipboard_ctx_menu), spc);
+                     G_CALLBACK (copy_search_uri_to_clipboard_ctx_menu), spc);
     gtk_label_set_use_underline (GTK_LABEL
                                 (gtk_bin_get_child (GTK_BIN (child))), TRUE);
     gtk_widget_show (child);
+    gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
   }
   g_signal_connect (menu, "selection-done",
                    G_CALLBACK (search_list_popup_selection_done), spc);
-  gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
   gtk_menu_popup (menu, NULL, NULL, NULL, NULL, init_button, event_time);
   return TRUE;
 }
@@ -2439,7 +2435,7 @@
                                                  gpointer user_data)
 {
   struct PublishTab *tab = user_data;
-  struct PublishEntry *ent;
+  struct PublishEntry *pe;
   GtkTreeIter iter;
   GtkTreeModel *tm;
   GtkNotebook *notebook;
@@ -2453,9 +2449,9 @@
   {
     do
     {
-      gtk_tree_model_get (tm, &iter, 4, &ent, -1);
-      GNUNET_FS_publish_stop (ent->pc);
-      ent->pc = NULL;
+      gtk_tree_model_get (tm, &iter, 4, &pe, -1);
+      GNUNET_FS_publish_stop (pe->pc);
+      pe->pc = NULL;
     }
     while (TRUE == gtk_tree_model_iter_next (tm, &iter));
   }
@@ -2574,6 +2570,227 @@
 
 
 
+/**
+ * Context for the publish list popup menu.
+ */
+struct PublishListPopupContext
+{
+  /**
+   * Tab where the publish list popup was created.
+   */
+  struct PublishTab *tab;
+                 
+  /**
+   * Row where the publish list popup was created.
+   */
+  GtkTreeRowReference *rr;
+
+
+  /**
+   * Publishing entry at the respective row.
+   */
+  struct PublishEntry *pe;
+ 
+};
+
+
+/**
+ * An item was selected from the context menu; destroy the menu shell.
+ *
+ * @param menushell menu to destroy
+ * @param user_data the 'struct PublishListPopupContext' of the menu 
+ */
+static void
+publish_list_popup_selection_done (GtkMenuShell *menushell,
+                                  gpointer user_data)
+{
+  struct PublishListPopupContext *ppc = user_data;
+
+  gtk_widget_destroy (GTK_WIDGET (menushell));
+  gtk_tree_row_reference_free (ppc->rr);
+  GNUNET_free (ppc);
+}
+
+
+/**
+ * Publish "abort" was selected in the current publish context menu.
+ * 
+ * @param item the 'abort' menu item
+ * @parma user_data the 'struct PublishListPopupContext' with the operation to 
abort.
+ */
+static void
+abort_publish_ctx_menu (GtkMenuItem *item, gpointer user_data)
+{
+  struct PublishListPopupContext *ppc = user_data;
+  struct PublishEntry *pe = ppc->pe;
+  
+  if (NULL != pe->pc)
+    GNUNET_FS_publish_stop (pe->pc);
+}
+
+
+/**
+ * Copy current URI to clipboard was selected in the current context menu.
+ * 
+ * @param item the 'copy-to-clipboard' menu item
+ * @parma user_data the 'struct DownloadListPopupContext' of the menu
+ */
+static void
+copy_publish_uri_to_clipboard_ctx_menu (GtkMenuItem *item, gpointer user_data)
+{
+  struct PublishListPopupContext *ppc = user_data;
+  struct GNUNET_FS_Uri *uri;
+  char *uris;
+  GtkClipboard *cb;
+
+  uri = ppc->pe->uri;
+  if (uri == NULL)
+  {
+    GNUNET_break (0);
+    return;
+  }
+  uris = GNUNET_FS_uri_to_string (uri);
+  cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
+  gtk_clipboard_set_text (cb, uris, -1);
+  gtk_clipboard_store (cb);
+  GNUNET_free (uris);
+}
+
+
+/**
+ * Context menu was requested for a publish result list.
+ * Compute which menu items are applicable and display
+ * an appropriate menu.
+ *
+ * @param tm tree model underlying the tree view where the event happened
+ * @param tab tab where the event happened
+ * @param event_button the event
+ * @return FALSE if no menu could be popped up,
+ *         TRUE if there is now a pop-up menu
+ */
+static gboolean
+publish_list_popup (GtkTreeModel *tm, 
+                   struct PublishTab *tab, 
+                   gint init_button,
+                   guint32 event_time,
+                   GtkTreeIter *iter)
+{
+  GtkMenu *menu;
+  GtkWidget *child;
+  GtkTreePath *path;
+  struct PublishEntry *pe;
+  struct PublishListPopupContext *ppc;
+
+  gtk_tree_model_get (tm, iter, 4, &pe, -1);
+  if ( (NULL == pe->uri) &&
+       ( (NULL == pe->pc) ||
+        (GNUNET_NO == pe->is_top) ) )
+  {
+    /* no actions available, refuse to pop up */
+    return FALSE;
+  }
+
+  ppc = GNUNET_malloc (sizeof (struct PublishListPopupContext));
+  ppc->tab = tab;
+  path = gtk_tree_model_get_path (tm, iter);
+  ppc->rr = gtk_tree_row_reference_new (tm, path);
+  gtk_tree_path_free (path);
+  ppc->pe = pe;
+  menu = GTK_MENU (gtk_menu_new ());
+  if (NULL != pe->uri)
+  {
+    child = gtk_menu_item_new_with_label (_("_Copy URI to Clipboard"));
+    g_signal_connect (child, "activate",
+                     G_CALLBACK (copy_publish_uri_to_clipboard_ctx_menu), ppc);
+    gtk_label_set_use_underline (GTK_LABEL
+                                (gtk_bin_get_child (GTK_BIN (child))), TRUE);
+    gtk_widget_show (child);
+    gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
+  }
+  else if (NULL != pe->pc)
+  {
+    child = gtk_menu_item_new_with_label (_("_Abort publishing"));
+    g_signal_connect (child, "activate",
+                      G_CALLBACK (abort_publish_ctx_menu), ppc);
+    gtk_label_set_use_underline (GTK_LABEL
+                                 (gtk_bin_get_child (GTK_BIN (child))),
+                                 TRUE);
+    gtk_widget_show (child);
+    gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
+  } 
+  g_signal_connect (menu, "selection-done",
+                   G_CALLBACK (publish_list_popup_selection_done), ppc);
+  gtk_menu_popup (menu, NULL, NULL, NULL, NULL, init_button, event_time);
+  return TRUE;
+}
+
+
+/**
+ * We got a 'popup-menu' event, display the context menu.
+ *
+ * @param widget the tree view where the event happened
+ * @param user_data the 'struct PublishTab' of the tree view
+ * @return FALSE if no menu could be popped up,
+ *         TRUE if there is now a pop-up menu
+ */
+gboolean
+GNUNET_FS_GTK_publish_treeview_popup_menu (GtkWidget *widget, 
+                                          gpointer user_data)
+{
+  GtkTreeView *tv = GTK_TREE_VIEW (widget);
+  struct PublishTab *tab = user_data;
+  GtkTreeSelection *sel;
+  GtkTreeIter iter;
+  GtkTreeModel *tm;
+
+  sel = gtk_tree_view_get_selection (tv);
+  if (! gtk_tree_selection_get_selected (sel, &tm, &iter))
+    return FALSE; /* nothing selected */
+  return publish_list_popup (tm, tab, 0, gtk_get_current_event_time (), &iter);
+}
+
+
+/**
+ * We got a right-click on the search result list. Display the context
+ * menu.
+ *
+ * @param widget the GtkTreeView with the search result list
+ * @param event the event, we only care about button events
+ * @param user_data the 'struct SearchTab' the widget is in
+ * @return FALSE if no menu could be popped up,
+ *         TRUE if there is now a pop-up menu
+ */
+gboolean
+GNUNET_FS_GTK_publish_treeview_button_press_event (GtkWidget * widget, 
+                                                  GdkEvent * event,
+                                                  gpointer user_data)
+{
+  GtkTreeView *tv = GTK_TREE_VIEW (widget);
+  GdkEventButton *event_button = (GdkEventButton *) event;
+  struct PublishTab *tab = user_data;
+  GtkTreeModel *tm;
+  GtkTreePath *path;
+  GtkTreeIter iter;
+
+  if ( (event->type != GDK_BUTTON_PRESS) ||
+       (event_button->button != 3) )
+    return FALSE; /* not a right-click */
+  if (! gtk_tree_view_get_path_at_pos (tv,
+                                      event_button->x, event_button->y,
+                                       &path, NULL, NULL, NULL))
+    return FALSE; /* click outside of area with values, ignore */    
+  tm = gtk_tree_view_get_model (tv);
+  if (! gtk_tree_model_get_iter (tm, &iter, path))
+    return FALSE; /* not sure how we got a path but no iter... */  
+  gtk_tree_path_free (path);
+  return publish_list_popup (tm, tab, 
+                            event_button->button,
+                            event_button->time,
+                            &iter);
+}
+
+
+
 /* ***************** Master event handler ****************** */
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]