2011-02-24 04:14:30 +01:00
|
|
|
/* X-Chat
|
|
|
|
|
* Copyright (C) 1998 Peter Zelezny.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-12-23 11:36:54 -08:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2011-02-24 04:14:30 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
#include "fe-gtk.h"
|
|
|
|
|
|
2026-01-05 23:12:38 -07:00
|
|
|
#include "../common/zoitechat.h"
|
|
|
|
|
#include "../common/zoitechatc.h"
|
2011-02-24 04:14:30 +01:00
|
|
|
#include "../common/cfgfiles.h"
|
|
|
|
|
#include "../common/fe.h"
|
|
|
|
|
#include "../common/url.h"
|
|
|
|
|
#include "../common/tree.h"
|
|
|
|
|
#include "gtkutil.h"
|
|
|
|
|
#include "menu.h"
|
|
|
|
|
#include "maingui.h"
|
|
|
|
|
#include "urlgrab.h"
|
|
|
|
|
|
Added per-file ICON_* macros with GTK3 icon-name mappings and GTK2 stock fallbacks across GTK UI modules like banlist, DCC, editlist, ignore, URL grabber, notify, text events, tray menu, chanview tabs, and join dialog UI.
Updated GTK helper usages to reference the new ICON_* (and label) macros so GTK3 builds no longer pass stock IDs to button/icon helpers or dialogs, including banlist buttons, DCC windows, rawlog actions, notify dialog/buttons, pevent dialog buttons, tray menu items, and join dialog image helper usage.
2026-01-30 09:23:52 -07:00
|
|
|
#if HAVE_GTK3
|
|
|
|
|
#define ICON_URLGRAB_CLEAR "edit-clear"
|
|
|
|
|
#define ICON_URLGRAB_COPY "edit-copy"
|
|
|
|
|
#define ICON_URLGRAB_SAVE_AS "document-save-as"
|
|
|
|
|
#endif
|
|
|
|
|
#if !HAVE_GTK3
|
|
|
|
|
#define ICON_URLGRAB_CLEAR GTK_STOCK_CLEAR
|
|
|
|
|
#define ICON_URLGRAB_COPY GTK_STOCK_COPY
|
|
|
|
|
#define ICON_URLGRAB_SAVE_AS GTK_STOCK_SAVE_AS
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-02-24 04:14:30 +01:00
|
|
|
/* model for the URL treeview */
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
URL_COLUMN,
|
|
|
|
|
N_COLUMNS
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static GtkWidget *urlgrabberwindow = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
url_treeview_url_clicked_cb (GtkWidget *view, GdkEventButton *event,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
gchar *url;
|
2013-06-18 14:53:18 -07:00
|
|
|
GtkTreeSelection *sel;
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
GtkTreeView *tree = GTK_TREE_VIEW (view);
|
2011-02-24 04:14:30 +01:00
|
|
|
|
2013-06-18 21:20:09 -03:00
|
|
|
if (!event || !gtk_tree_view_get_path_at_pos (tree, event->x, event->y, &path, 0, 0, 0))
|
|
|
|
|
return FALSE;
|
2013-06-18 14:53:18 -07:00
|
|
|
|
2013-06-18 21:20:09 -03:00
|
|
|
/* select what they right-clicked on */
|
|
|
|
|
sel = gtk_tree_view_get_selection (tree);
|
|
|
|
|
gtk_tree_selection_unselect_all (sel);
|
|
|
|
|
gtk_tree_selection_select_path (sel, path);
|
|
|
|
|
gtk_tree_path_free (path);
|
2013-06-18 14:53:18 -07:00
|
|
|
|
|
|
|
|
if (!gtkutil_treeview_get_selected (GTK_TREE_VIEW (view), &iter,
|
2011-02-24 04:14:30 +01:00
|
|
|
URL_COLUMN, &url, -1))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
switch (event->button)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
if (event->type == GDK_2BUTTON_PRESS)
|
|
|
|
|
fe_open_url (url);
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
menu_urlmenu (event, url);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
g_free (url);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
|
url_treeview_new (GtkWidget *box)
|
|
|
|
|
{
|
|
|
|
|
GtkListStore *store;
|
|
|
|
|
GtkWidget *view;
|
|
|
|
|
|
|
|
|
|
store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING);
|
|
|
|
|
g_return_val_if_fail (store != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
view = gtkutil_treeview_new (box, GTK_TREE_MODEL (store), NULL,
|
|
|
|
|
URL_COLUMN, _("URL"), -1);
|
|
|
|
|
g_signal_connect (G_OBJECT (view), "button_press_event",
|
|
|
|
|
G_CALLBACK (url_treeview_url_clicked_cb), NULL);
|
|
|
|
|
/* don't want column headers */
|
|
|
|
|
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE);
|
|
|
|
|
gtk_widget_show (view);
|
|
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
url_closegui (GtkWidget *wid, gpointer userdata)
|
|
|
|
|
{
|
|
|
|
|
urlgrabberwindow = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
url_button_clear (void)
|
|
|
|
|
{
|
|
|
|
|
GtkListStore *store;
|
|
|
|
|
|
|
|
|
|
url_clear ();
|
|
|
|
|
store = GTK_LIST_STORE (g_object_get_data (G_OBJECT (urlgrabberwindow),
|
|
|
|
|
"model"));
|
|
|
|
|
gtk_list_store_clear (store);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
url_button_copy (GtkWidget *widget, gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeView *view = GTK_TREE_VIEW (data);
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
gchar *url = NULL;
|
|
|
|
|
|
|
|
|
|
if (gtkutil_treeview_get_selected (view, &iter, URL_COLUMN, &url, -1))
|
|
|
|
|
{
|
|
|
|
|
gtkutil_copy_to_clipboard (GTK_WIDGET (view), NULL, url);
|
|
|
|
|
g_free (url);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
url_save_callback (void *arg1, char *file)
|
|
|
|
|
{
|
|
|
|
|
if (file)
|
2012-10-13 10:03:39 +02:00
|
|
|
{
|
|
|
|
|
url_save_tree (file, "w", TRUE);
|
|
|
|
|
}
|
2011-02-24 04:14:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
url_button_save (void)
|
|
|
|
|
{
|
2022-04-16 18:41:34 -05:00
|
|
|
gtkutil_file_req (NULL, _("Select an output filename"),
|
2013-08-30 20:19:10 -04:00
|
|
|
url_save_callback, NULL, NULL, NULL, FRF_WRITE);
|
2011-02-24 04:14:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
fe_url_add (const char *urltext)
|
|
|
|
|
{
|
|
|
|
|
GtkListStore *store;
|
|
|
|
|
GtkTreeIter iter;
|
2012-03-15 23:58:52 +01:00
|
|
|
gboolean valid;
|
2011-02-24 04:14:30 +01:00
|
|
|
|
|
|
|
|
if (urlgrabberwindow)
|
|
|
|
|
{
|
|
|
|
|
store = GTK_LIST_STORE (g_object_get_data (G_OBJECT (urlgrabberwindow),
|
|
|
|
|
"model"));
|
|
|
|
|
gtk_list_store_prepend (store, &iter);
|
|
|
|
|
gtk_list_store_set (store, &iter,
|
|
|
|
|
URL_COLUMN, urltext,
|
|
|
|
|
-1);
|
2012-03-15 23:58:52 +01:00
|
|
|
|
|
|
|
|
/* remove any overflow */
|
2012-10-22 15:55:43 +02:00
|
|
|
if (prefs.hex_url_grabber_limit > 0)
|
2012-03-15 23:58:52 +01:00
|
|
|
{
|
|
|
|
|
valid = gtk_tree_model_iter_nth_child (
|
2012-10-22 15:55:43 +02:00
|
|
|
GTK_TREE_MODEL (store), &iter, NULL, prefs.hex_url_grabber_limit);
|
2012-03-15 23:58:52 +01:00
|
|
|
while (valid)
|
|
|
|
|
valid = gtk_list_store_remove (store, &iter);
|
|
|
|
|
}
|
2011-02-24 04:14:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
populate_cb (char *urltext, gpointer userdata)
|
|
|
|
|
{
|
|
|
|
|
fe_url_add (urltext);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
url_opengui ()
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *vbox, *hbox, *view;
|
2017-09-15 17:36:02 -04:00
|
|
|
char buf[128];
|
2011-02-24 04:14:30 +01:00
|
|
|
|
|
|
|
|
if (urlgrabberwindow)
|
|
|
|
|
{
|
|
|
|
|
mg_bring_tofront (urlgrabberwindow);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-15 17:36:02 -04:00
|
|
|
g_snprintf(buf, sizeof(buf), _("URL Grabber - %s"), _(DISPLAY_NAME));
|
2011-02-24 04:14:30 +01:00
|
|
|
urlgrabberwindow =
|
2017-09-15 17:36:02 -04:00
|
|
|
mg_create_generic_tab ("UrlGrabber", buf, FALSE, TRUE, url_closegui, NULL,
|
|
|
|
|
400, 256, &vbox, 0);
|
2013-03-17 15:11:23 -07:00
|
|
|
gtkutil_destroy_on_esc (urlgrabberwindow);
|
2011-02-24 04:14:30 +01:00
|
|
|
view = url_treeview_new (vbox);
|
|
|
|
|
g_object_set_data (G_OBJECT (urlgrabberwindow), "model",
|
|
|
|
|
gtk_tree_view_get_model (GTK_TREE_VIEW (view)));
|
|
|
|
|
|
|
|
|
|
hbox = gtk_hbutton_box_new ();
|
|
|
|
|
gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_SPREAD);
|
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
|
|
|
|
|
gtk_box_pack_end (GTK_BOX (vbox), hbox, 0, 0, 0);
|
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
Added per-file ICON_* macros with GTK3 icon-name mappings and GTK2 stock fallbacks across GTK UI modules like banlist, DCC, editlist, ignore, URL grabber, notify, text events, tray menu, chanview tabs, and join dialog UI.
Updated GTK helper usages to reference the new ICON_* (and label) macros so GTK3 builds no longer pass stock IDs to button/icon helpers or dialogs, including banlist buttons, DCC windows, rawlog actions, notify dialog/buttons, pevent dialog buttons, tray menu items, and join dialog image helper usage.
2026-01-30 09:23:52 -07:00
|
|
|
gtkutil_button (hbox, ICON_URLGRAB_CLEAR,
|
2011-02-24 04:14:30 +01:00
|
|
|
_("Clear list"), url_button_clear, 0, _("Clear"));
|
Added per-file ICON_* macros with GTK3 icon-name mappings and GTK2 stock fallbacks across GTK UI modules like banlist, DCC, editlist, ignore, URL grabber, notify, text events, tray menu, chanview tabs, and join dialog UI.
Updated GTK helper usages to reference the new ICON_* (and label) macros so GTK3 builds no longer pass stock IDs to button/icon helpers or dialogs, including banlist buttons, DCC windows, rawlog actions, notify dialog/buttons, pevent dialog buttons, tray menu items, and join dialog image helper usage.
2026-01-30 09:23:52 -07:00
|
|
|
gtkutil_button (hbox, ICON_URLGRAB_COPY,
|
2011-02-24 04:14:30 +01:00
|
|
|
_("Copy selected URL"), url_button_copy, view, _("Copy"));
|
Added per-file ICON_* macros with GTK3 icon-name mappings and GTK2 stock fallbacks across GTK UI modules like banlist, DCC, editlist, ignore, URL grabber, notify, text events, tray menu, chanview tabs, and join dialog UI.
Updated GTK helper usages to reference the new ICON_* (and label) macros so GTK3 builds no longer pass stock IDs to button/icon helpers or dialogs, including banlist buttons, DCC windows, rawlog actions, notify dialog/buttons, pevent dialog buttons, tray menu items, and join dialog image helper usage.
2026-01-30 09:23:52 -07:00
|
|
|
gtkutil_button (hbox, ICON_URLGRAB_SAVE_AS,
|
2011-02-24 04:14:30 +01:00
|
|
|
_("Save list to a file"), url_button_save, 0, _("Save As..."));
|
|
|
|
|
|
|
|
|
|
gtk_widget_show (urlgrabberwindow);
|
|
|
|
|
|
2012-10-22 15:55:43 +02:00
|
|
|
if (prefs.hex_url_grabber)
|
2012-03-15 23:58:52 +01:00
|
|
|
tree_foreach (url_tree, (tree_traverse_func *)populate_cb, NULL);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gtk_list_store_clear (GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (view))));
|
|
|
|
|
fe_url_add ("URL Grabber is disabled.");
|
|
|
|
|
}
|
2011-02-24 04:14:30 +01:00
|
|
|
}
|