parent
d16aedf6c4
commit
c45cc78548
@ -317,6 +317,80 @@ fe_ban_list_end (struct session *sess, int rplcode)
|
||||
else return FALSE;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user