aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-fs-gtk-event_handler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-fs-gtk-event_handler.c')
-rw-r--r--src/fs/gnunet-fs-gtk-event_handler.c176
1 files changed, 176 insertions, 0 deletions
diff --git a/src/fs/gnunet-fs-gtk-event_handler.c b/src/fs/gnunet-fs-gtk-event_handler.c
index 74c3ab5d..8565bd05 100644
--- a/src/fs/gnunet-fs-gtk-event_handler.c
+++ b/src/fs/gnunet-fs-gtk-event_handler.c
@@ -1934,6 +1934,182 @@ GNUNET_GTK_main_window_notebook_switch_page_cb (GtkWidget * dummy,
1934 gtk_list_store_clear (ms); 1934 gtk_list_store_clear (ms);
1935} 1935}
1936 1936
1937static void
1938copy_metadata_to_clipboard (GtkTreeModel *model, GtkTreePath *path,
1939 GtkTreeIter *iter, gpointer user_data)
1940{
1941 gchar *type, *value;
1942 GList **l = (GList **) user_data;
1943
1944 gtk_tree_model_get (model, iter, 2, &type, 3, &value, -1);
1945
1946 *l = g_list_prepend (*l, type);
1947 *l = g_list_prepend (*l, value);
1948}
1949
1950void
1951metadata_copy_selection_activated (GtkMenuItem *menuitem, gpointer user_data)
1952{
1953 GtkBuilder *builder;
1954 GtkTreeView *tree;
1955 GtkClipboard *cb;
1956 GList *pairs = NULL, *l, *next, *value, *type;
1957 guint total_len;
1958 gchar *s, *p;
1959
1960 builder = GTK_BUILDER (user_data);
1961 tree = GTK_TREE_VIEW (gtk_builder_get_object (builder,
1962 "GNUNET_GTK_main_window_metadata_treeview"));
1963
1964 gtk_tree_selection_selected_foreach (gtk_tree_view_get_selection (tree),
1965 copy_metadata_to_clipboard, &pairs);
1966
1967 total_len = 0;
1968 pairs = g_list_reverse (pairs);
1969 for (l = pairs; l; l = next)
1970 {
1971 type = l;
1972 value = l->next;
1973 if (!value)
1974 break;
1975 next = value->next;
1976 total_len += strlen ((gchar *) type->data)
1977 + strlen ((gchar *) value->data) + 2 /* ": " */ + (next ? 1 : 0) /* "\n" */;
1978 }
1979 if (total_len > 0)
1980 {
1981 total_len += 1; /* "\0" */
1982 s = g_new0 (gchar, total_len);
1983 p = s;
1984 for (l = pairs; l; l = next)
1985 {
1986 type = l;
1987 value = l->next;
1988 if (value)
1989 {
1990 next = value->next;
1991 p = g_stpcpy (p, (gchar *) type->data);
1992 p = g_stpcpy (p, ": ");
1993 p = g_stpcpy (p, (gchar *) value->data);
1994 if (next)
1995 p = g_stpcpy (p, "\n");
1996 }
1997 else
1998 next = NULL;
1999 }
2000 }
2001 g_list_foreach (pairs, (GFunc) g_free, NULL);
2002 g_list_free (pairs);
2003 pairs = NULL;
2004
2005 if (total_len > 0)
2006 {
2007 cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2008 gtk_clipboard_set_text (cb, s, -1);
2009 gtk_clipboard_store (cb);
2010 g_free (s);
2011 }
2012}
2013
2014void
2015metadata_menu_popup_position (GtkMenu *menu, gint *x, gint *y, gboolean *push_in,
2016 gpointer user_data)
2017{
2018 GtkBuilder *builder;
2019 GtkTreeView *tree;
2020 GtkTreeSelection *sel;
2021 GList *rows;
2022 GtkTreePath *p;
2023 GtkAllocation tree_allocation;
2024 GdkWindow *main_window_gdk;
2025 gint mwg_x, mwg_y, t_x, t_y, popup_x, popup_y;
2026
2027 builder = GTK_BUILDER (user_data);
2028
2029 tree = GTK_TREE_VIEW (gtk_builder_get_object (builder,
2030 "GNUNET_GTK_main_window_metadata_treeview"));
2031
2032 gtk_widget_get_allocation (GTK_WIDGET (tree), &tree_allocation);
2033
2034 main_window_gdk = gtk_widget_get_window (GTK_WIDGET (tree));
2035
2036 gdk_window_get_origin (main_window_gdk, &mwg_x, &mwg_y);
2037
2038 t_x = mwg_x + tree_allocation.x;
2039 t_y = mwg_y + tree_allocation.y;
2040 popup_x = t_x;
2041 popup_y = t_y;
2042
2043 sel = gtk_tree_view_get_selection (tree);
2044
2045 rows = gtk_tree_selection_get_selected_rows (sel, NULL);
2046
2047 if (rows->data)
2048 {
2049 GdkRectangle r;
2050 p = (GtkTreePath *) rows->data;
2051 gtk_tree_view_get_cell_area (tree, p, NULL, &r);
2052 popup_x += r.x;
2053 popup_y += r.y;
2054 }
2055
2056 g_list_foreach (rows, (GFunc) gtk_tree_path_free, NULL);
2057 g_list_free (rows);
2058 *x = popup_x;
2059 *y = popup_y;
2060 *push_in = FALSE;
2061}
2062
2063static void
2064do_metadata_popup_menu (GtkWidget *widget, GdkEventButton *event,
2065 gpointer user_data)
2066{
2067 GtkMenu *menu;
2068 GtkBuilder *builder;
2069 int button, event_time;
2070 GtkMenuPositionFunc mpf = NULL;
2071
2072 builder = GTK_BUILDER (user_data);
2073
2074 menu = GTK_MENU (gtk_builder_get_object (builder, "metadata_popup_menu"));
2075
2076 if (event)
2077 {
2078 button = event->button;
2079 event_time = event->time;
2080 }
2081 else
2082 {
2083 button = 0;
2084 event_time = gtk_get_current_event_time ();
2085 }
2086
2087 gtk_menu_attach_to_widget (menu, widget, NULL);
2088 gtk_menu_popup (menu, NULL, NULL, mpf, user_data,
2089 button, event_time);
2090}
2091
2092gboolean
2093GNUNET_GTK_main_window_metadata_treeview_button_press_event_cb (GtkWidget *widget,
2094 GdkEventButton *event, gpointer user_data)
2095{
2096 /* Ignore double-clicks and triple-clicks */
2097 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
2098 {
2099 do_metadata_popup_menu (widget, event, user_data);
2100 return TRUE;
2101 }
2102
2103 return FALSE;
2104}
2105
2106gboolean
2107GNUNET_GTK_main_window_metadata_treeview_popup_menu_cb (GtkWidget *widget,
2108 gpointer user_data)
2109{
2110 do_metadata_popup_menu (widget, NULL, user_data);
2111 return TRUE;
2112}
1937 2113
1938 2114
1939/* end of gnunet-fs-gtk-event_handler.c */ 2115/* end of gnunet-fs-gtk-event_handler.c */