2 * Copyright (C) 1998 Peter Zelezny.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
25 #include <gtk/gtkhbox.h>
26 #include <gtk/gtkstock.h>
27 #include <gtk/gtkhbbox.h>
28 #include <gtk/gtkscrolledwindow.h>
30 #include <gtk/gtkliststore.h>
31 #include <gtk/gtktreeview.h>
32 #include <gtk/gtktreeselection.h>
33 #include <gtk/gtkcellrenderertext.h>
35 #include "../common/xchat.h"
36 #include "../common/xchatc.h"
37 #include "../common/cfgfiles.h"
38 #include "../common/fe.h"
39 #include "../common/url.h"
40 #include "../common/tree.h"
46 /* model for the URL treeview */
53 static GtkWidget
*urlgrabberwindow
= 0;
57 url_treeview_url_clicked_cb (GtkWidget
*view
, GdkEventButton
*event
,
64 !gtkutil_treeview_get_selected (GTK_TREE_VIEW (view
), &iter
,
65 URL_COLUMN
, &url
, -1))
70 switch (event
->button
)
73 if (event
->type
== GDK_2BUTTON_PRESS
)
77 menu_urlmenu (event
, url
);
88 url_treeview_new (GtkWidget
*box
)
93 store
= gtk_list_store_new (N_COLUMNS
, G_TYPE_STRING
);
94 g_return_val_if_fail (store
!= NULL
, NULL
);
96 view
= gtkutil_treeview_new (box
, GTK_TREE_MODEL (store
), NULL
,
97 URL_COLUMN
, _("URL"), -1);
98 g_signal_connect (G_OBJECT (view
), "button_press_event",
99 G_CALLBACK (url_treeview_url_clicked_cb
), NULL
);
100 /* don't want column headers */
101 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view
), FALSE
);
102 gtk_widget_show (view
);
107 url_closegui (GtkWidget
*wid
, gpointer userdata
)
109 urlgrabberwindow
= 0;
113 url_button_clear (void)
118 store
= GTK_LIST_STORE (g_object_get_data (G_OBJECT (urlgrabberwindow
),
120 gtk_list_store_clear (store
);
124 url_button_copy (GtkWidget
*widget
, gpointer data
)
126 GtkTreeView
*view
= GTK_TREE_VIEW (data
);
130 if (gtkutil_treeview_get_selected (view
, &iter
, URL_COLUMN
, &url
, -1))
132 gtkutil_copy_to_clipboard (GTK_WIDGET (view
), NULL
, url
);
138 url_save_callback (void *arg1
, char *file
)
141 url_save (file
, "w", TRUE
);
145 url_button_save (void)
147 gtkutil_file_req (_("Select an output filename"),
148 url_save_callback
, NULL
, NULL
, FRF_WRITE
);
152 fe_url_add (const char *urltext
)
158 if (urlgrabberwindow
)
160 store
= GTK_LIST_STORE (g_object_get_data (G_OBJECT (urlgrabberwindow
),
162 gtk_list_store_prepend (store
, &iter
);
163 gtk_list_store_set (store
, &iter
,
167 /* remove any overflow */
168 if (prefs
.url_grabber_limit
> 0)
170 valid
= gtk_tree_model_iter_nth_child (
171 GTK_TREE_MODEL (store
), &iter
, NULL
, prefs
.url_grabber_limit
);
173 valid
= gtk_list_store_remove (store
, &iter
);
179 populate_cb (char *urltext
, gpointer userdata
)
181 fe_url_add (urltext
);
188 GtkWidget
*vbox
, *hbox
, *view
;
190 if (urlgrabberwindow
)
192 mg_bring_tofront (urlgrabberwindow
);
197 mg_create_generic_tab ("UrlGrabber", _("XChat: URL Grabber"), FALSE
,
198 TRUE
, url_closegui
, NULL
, 400, 256, &vbox
, 0);
199 view
= url_treeview_new (vbox
);
200 g_object_set_data (G_OBJECT (urlgrabberwindow
), "model",
201 gtk_tree_view_get_model (GTK_TREE_VIEW (view
)));
203 hbox
= gtk_hbutton_box_new ();
204 gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox
), GTK_BUTTONBOX_SPREAD
);
205 gtk_container_set_border_width (GTK_CONTAINER (hbox
), 5);
206 gtk_box_pack_end (GTK_BOX (vbox
), hbox
, 0, 0, 0);
207 gtk_widget_show (hbox
);
209 gtkutil_button (hbox
, GTK_STOCK_CLEAR
,
210 _("Clear list"), url_button_clear
, 0, _("Clear"));
211 gtkutil_button (hbox
, GTK_STOCK_COPY
,
212 _("Copy selected URL"), url_button_copy
, view
, _("Copy"));
213 gtkutil_button (hbox
, GTK_STOCK_SAVE_AS
,
214 _("Save list to a file"), url_button_save
, 0, _("Save As..."));
216 gtk_widget_show (urlgrabberwindow
);
218 if (prefs
.url_grabber
)
219 tree_foreach (url_tree
, (tree_traverse_func
*)populate_cb
, NULL
);
222 gtk_list_store_clear (GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (view
))));
223 fe_url_add ("URL Grabber is disabled.");