summary refs log tree commit diff stats
path: root/src/fe-gtk
diff options
context:
space:
mode:
authorTingPing <tngpng@gmail.com>2013-06-04 12:25:12 -0300
committerTingPing <tngpng@gmail.com>2013-06-04 12:25:12 -0300
commitc45cc78548cb66fde513b8b2554afd84e49829e8 (patch)
tree604a59e3a9f9416e15baf26b5ea4701e519d7632 /src/fe-gtk
parentd16aedf6c45f5701e05208e4543eb4b3e321f666 (diff)
Add copy option to right click in banlist
Closes #626
Diffstat (limited to 'src/fe-gtk')
-rw-r--r--src/fe-gtk/banlist.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/fe-gtk/banlist.c b/src/fe-gtk/banlist.c
index 8c396d14..897e61d6 100644
--- a/src/fe-gtk/banlist.c
+++ b/src/fe-gtk/banlist.c
@@ -318,6 +318,80 @@ fe_ban_list_end (struct session *sess, int rplcode)
 }
 
 static void
+banlist_copyentry (GtkWidget *menuitem, GtkTreeView *view)
+{
+	GtkTreeModel *model;
+	GtkTreeSelection *sel;
+	GtkTreeIter iter;
+	GValue mask = G_VALUE_INIT;
+	GValue from = G_VALUE_INIT;
+	GValue date = G_VALUE_INIT;
+	char *str;
+	
+	/* get selection (which should have been set on click)
+	 * and temporarily switch to single mode to get selected iter */
+	sel = gtk_tree_view_get_selection (view);
+	gtk_tree_selection_set_mode (sel, GTK_SELECTION_SINGLE);
+	if (gtk_tree_selection_get_selected (sel, &model, &iter))
+	{
+		gtk_tree_model_get_value (model, &iter, MASK_COLUMN, &mask);
+		gtk_tree_model_get_value (model, &iter, FROM_COLUMN, &from);
+		gtk_tree_model_get_value (model, &iter, DATE_COLUMN, &date);
+
+		/* poor way to get which is selected but it works */
+		if (strcmp (_("Copy mask"), gtk_menu_item_get_label (GTK_MENU_ITEM(menuitem))) == 0)
+			str = g_value_dup_string (&mask);
+		else
+			str = g_strdup_printf (_("%s on %s by %s"), g_value_get_string (&mask),
+								g_value_get_string (&date), g_value_get_string (&from));
+
+		if (str[0] != 0)
+			gtkutil_copy_to_clipboard (menuitem, NULL, str);
+			
+		g_value_unset (&mask);
+		g_value_unset (&from);
+		g_value_unset (&date);
+		g_free (str);
+	}
+	gtk_tree_selection_set_mode (sel, GTK_SELECTION_MULTIPLE);
+}
+
+static gboolean
+banlist_button_pressed (GtkWidget *wid, GdkEventButton *event, gpointer userdata)
+{
+	GtkTreePath *path;
+	GtkWidget *menu, *maskitem, *allitem;
+
+	/* Check for right click */
+	if (event->type == GDK_BUTTON_PRESS && event->button == 3)
+	{
+		if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (wid), event->x, event->y,
+												&path, NULL, NULL, NULL))
+		{
+			/* Must set the row active for use in callback */
+			gtk_tree_view_set_cursor (GTK_TREE_VIEW(wid), path, NULL, FALSE);
+			gtk_tree_path_free (path);
+			
+			menu = gtk_menu_new ();
+			maskitem = gtk_menu_item_new_with_label (_("Copy mask"));
+			allitem = gtk_menu_item_new_with_label (_("Copy entry"));
+			g_signal_connect (maskitem, "activate", G_CALLBACK(banlist_copyentry), wid);
+			g_signal_connect (allitem, "activate", G_CALLBACK(banlist_copyentry), wid);
+			gtk_menu_shell_append (GTK_MENU_SHELL(menu), maskitem);
+			gtk_menu_shell_append (GTK_MENU_SHELL(menu), allitem);
+			gtk_widget_show_all (menu);
+			
+			gtk_menu_popup (GTK_MENU(menu), NULL, NULL, NULL, NULL, 
+							event->button, gtk_get_current_event_time ());
+		}
+		
+		return TRUE;
+	}
+	
+	return FALSE;
+}
+
+static void
 banlist_select_changed (GtkWidget *item, banlist_info *banl)
 {
 	GList *list;
@@ -644,6 +718,7 @@ banlist_treeview_new (GtkWidget *box, banlist_info *banl)
 										  MASK_COLUMN, _("Mask"),
 										  FROM_COLUMN, _("From"),
 										  DATE_COLUMN, _("Date"), -1);
+	g_signal_connect (G_OBJECT (view), "button-press-event", G_CALLBACK (banlist_button_pressed), NULL);
 
 	col = gtk_tree_view_get_column (GTK_TREE_VIEW (view), MASK_COLUMN);
 	gtk_tree_view_column_set_alignment (col, 0.5);