[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r19701 - gnunet-gtk/src/fs
From: |
gnunet |
Subject: |
[GNUnet-SVN] r19701 - gnunet-gtk/src/fs |
Date: |
Sun, 5 Feb 2012 19:08:04 +0100 |
Author: grothoff
Date: 2012-02-05 19:08:04 +0100 (Sun, 05 Feb 2012)
New Revision: 19701
Modified:
gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c
Log:
-moving globals into struct for the menu shell
Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c 2012-02-05 16:06:26 UTC
(rev 19700)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c 2012-02-05 18:08:04 UTC
(rev 19701)
@@ -110,20 +110,7 @@
*/
static struct PublishTab *publish_tab;
-/**
- * Row reference for the current search context menu.
- * FIXME-UNCLEAN: de-globalize?
- */
-static GtkTreeRowReference *current_context_row_reference;
-/**
- * Search tab used for the current search context menu.
- * FIXME-UNCLEAN: de-globalize?
- */
-static struct SearchTab *current_context_search_tab;
-
-
-
/* ***************** Search event handling ****************** */
@@ -412,19 +399,43 @@
/**
+ * Context for the search list popup menu.
+ */
+struct SearchListPopupContext
+{
+ /**
+ * Tab where the search list popup was created.
+ */
+ struct SearchTab *tab;
+
+ /**
+ * Row where the search list popup was created.
+ */
+ GtkTreeRowReference *rr;
+
+ /**
+ * Search result at the respective row.
+ */
+ struct SearchResult *sr;
+
+};
+
+
+/**
* An item was selected from the context menu; destroy the menu shell.
*
* @param menushell menu to destroy
- * @parma user_data the 'struct DownloadEntry' for the menu (unused)
+ * @param user_data the 'struct SearchListPopupContext' of the menu
*/
static void
search_list_popup_selection_done (GtkMenuShell *menushell,
gpointer user_data)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Item selected in menu shell %p, destroying it.\n",
- menushell);
+ struct SearchListPopupContext *spc = user_data;
+
gtk_widget_destroy (GTK_WIDGET (menushell));
+ gtk_tree_row_reference_free (spc->rr);
+ GNUNET_free (spc);
}
@@ -453,32 +464,26 @@
/**
* "Download" was selected in the current search context menu.
*
+ * @param spc the 'struct SearchListPopupContext' of the menu
* @param is_recursive was this the 'recursive' option?
* @parma save_as was this the 'save as' option?
*/
static void
-start_download_ctx_menu_helper (int is_recursive,
+start_download_ctx_menu_helper (struct SearchListPopupContext *spc,
+ int is_recursive,
int save_as)
{
GtkTreePath *path;
GtkTreeView *tv;
- if (current_context_row_reference == NULL)
- {
- GNUNET_break (0);
- return;
- }
- path = gtk_tree_row_reference_get_path (current_context_row_reference);
- gtk_tree_row_reference_free (current_context_row_reference);
- current_context_row_reference = NULL;
+ path = gtk_tree_row_reference_get_path (spc->rr);
tv = GTK_TREE_VIEW (gtk_builder_get_object
- (current_context_search_tab->builder,
+ (spc->tab->builder,
"_search_result_frame"));
- start_download (tv, path, current_context_search_tab,
+ start_download (tv, path, spc->tab,
is_recursive,
save_as);
gtk_tree_path_free (path);
- current_context_search_tab = NULL;
}
@@ -486,12 +491,14 @@
* "Download" was selected in the current search context menu.
*
* @param item the 'download' menu item
- * @parma user_data FIXME
+ * @param user_data the 'struct SearchListPopupContext' of the menu
*/
static void
start_download_ctx_menu (GtkMenuItem *item, gpointer user_data)
{
- start_download_ctx_menu_helper (GNUNET_NO, GNUNET_NO);
+ struct SearchListPopupContext *spc = user_data;
+
+ start_download_ctx_menu_helper (spc, GNUNET_NO, GNUNET_NO);
}
@@ -499,12 +506,14 @@
* "Download recursively" was selected in the current search context menu.
*
* @param item the 'download recursively' menu item
- * @parma user_data FIXME
+ * @param user_data the 'struct SearchListPopupContext' of the menu
*/
static void
start_download_recursively_ctx_menu (GtkMenuItem *item, gpointer user_data)
{
- start_download_ctx_menu_helper (GNUNET_YES, GNUNET_NO);
+ struct SearchListPopupContext *spc = user_data;
+
+ start_download_ctx_menu_helper (spc, GNUNET_YES, GNUNET_NO);
}
@@ -512,12 +521,14 @@
* "Download as..." was selected in the current search context menu.
*
* @param item the 'download as...' menu item
- * @parma user_data FIXME
+ * @param user_data the 'struct SearchListPopupContext' of the menu
*/
static void
start_download_as_ctx_menu (GtkMenuItem *item, gpointer user_data)
{
- start_download_ctx_menu_helper (GNUNET_NO, GNUNET_YES);
+ struct SearchListPopupContext *spc = user_data;
+
+ start_download_ctx_menu_helper (spc, GNUNET_NO, GNUNET_YES);
}
@@ -525,19 +536,16 @@
* Download "abort" was selected in the current search context menu.
*
* @param item the 'abort' menu item
- * @parma user_data the 'struct DownloadEntry' to abort.
+ * @parma user_data the 'struct SearchListPopupContext' with the download to
abort.
*/
static void
abort_download_ctx_menu (GtkMenuItem *item, gpointer user_data)
{
- struct DownloadEntry *de = user_data;
+ struct SearchListPopupContext *spc = user_data;
+ struct DownloadEntry *de = spc->sr->download;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Aborting download DE=%p\n",
- de);
GNUNET_assert (de->dc != NULL);
GNUNET_FS_download_stop (de->dc, GNUNET_YES);
- current_context_search_tab = NULL;
}
@@ -546,10 +554,12 @@
*
* @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)
{
+ struct SearchListPopupContext *spc = user_data;
GtkTreePath *path;
GtkTreeView *tv;
GtkTreeModel *tm;
@@ -558,16 +568,9 @@
char *uris;
GtkClipboard *cb;
- if (NULL == current_context_row_reference)
- {
- GNUNET_break (0);
- return;
- }
- path = gtk_tree_row_reference_get_path (current_context_row_reference);
- gtk_tree_row_reference_free (current_context_row_reference);
- current_context_row_reference = NULL;
+ path = gtk_tree_row_reference_get_path (spc->rr);
tv = GTK_TREE_VIEW (gtk_builder_get_object
- (current_context_search_tab->builder,
+ (spc->tab->builder,
"_search_result_frame"));
tm = gtk_tree_view_get_model (tv);
if (! gtk_tree_model_get_iter (tm, &iter, path))
@@ -578,7 +581,6 @@
}
gtk_tree_model_get (tm, &iter, 1, &uri, -1);
gtk_tree_path_free (path);
- current_context_search_tab = NULL;
if (uri == NULL)
{
GNUNET_break (0);
@@ -615,27 +617,17 @@
GtkTreePath *path;
struct SearchResult *sr;
struct GNUNET_FS_Uri *uri;
+ struct SearchListPopupContext *spc;
/* FIXME-UNCLEAN: move these to some menu context struct
(de-globalize) */
- current_context_search_tab = tab;
- if (current_context_row_reference != NULL)
- {
- gtk_tree_row_reference_free (current_context_row_reference);
- current_context_row_reference = NULL;
- }
+ spc = GNUNET_malloc (sizeof (struct SearchListPopupContext));
+ spc->tab = tab;
path = gtk_tree_model_get_path (tm, iter);
- current_context_row_reference = gtk_tree_row_reference_new (tm, path);
+ spc->rr = gtk_tree_row_reference_new (tm, path);
gtk_tree_path_free (path);
-
gtk_tree_model_get (tm, iter, 1, &uri, 9, &sr, -1);
- /* FIXME-BUG: 'sr' can be NULL here, somehow some code fails to setup the
record.. */
- if (NULL == sr)
- {
- /* FIXME-BUG: this prevents the crash for now, but does not solve the
problem */
- GNUNET_break (0);
- return FALSE;
- }
+ spc->sr = sr;
menu = GTK_MENU (gtk_menu_new ());
if ( (NULL == sr->download) &&
(NULL != uri) )
@@ -643,7 +635,7 @@
/* only display download menus if there is a URI */
child = gtk_menu_item_new_with_label (_("_Download"));
g_signal_connect (child, "activate",
- G_CALLBACK (start_download_ctx_menu), NULL);
+ G_CALLBACK (start_download_ctx_menu), spc);
gtk_label_set_use_underline (GTK_LABEL
(gtk_bin_get_child (GTK_BIN (child))),
TRUE);
@@ -652,7 +644,7 @@
child = gtk_menu_item_new_with_label (_("Download _recursively"));
g_signal_connect (child, "activate",
- G_CALLBACK (start_download_recursively_ctx_menu), NULL);
+ G_CALLBACK (start_download_recursively_ctx_menu), spc);
gtk_label_set_use_underline (GTK_LABEL
(gtk_bin_get_child (GTK_BIN (child))),
TRUE);
@@ -662,7 +654,7 @@
child = gtk_menu_item_new_with_label (_("Download _as..."));
g_signal_connect (child, "activate",
- G_CALLBACK (start_download_as_ctx_menu), NULL);
+ G_CALLBACK (start_download_as_ctx_menu), spc);
gtk_label_set_use_underline (GTK_LABEL
(gtk_bin_get_child (GTK_BIN (child))),
TRUE);
@@ -674,7 +666,7 @@
{
child = gtk_menu_item_new_with_label (_("_Abort download"));
g_signal_connect (child, "activate",
- G_CALLBACK (abort_download_ctx_menu), sr->download);
+ G_CALLBACK (abort_download_ctx_menu), spc);
gtk_label_set_use_underline (GTK_LABEL
(gtk_bin_get_child (GTK_BIN (child))),
TRUE);
@@ -685,13 +677,13 @@
{
child = gtk_menu_item_new_with_label (_("_Copy URI to Clipboard"));
g_signal_connect (child, "activate",
- G_CALLBACK (copy_uri_to_clipboard_ctx_menu), NULL);
+ G_CALLBACK (copy_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);
}
g_signal_connect (menu, "selection-done",
- G_CALLBACK (search_list_popup_selection_done), NULL);
+ 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;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r19701 - gnunet-gtk/src/fs,
gnunet <=