summary refs log tree commit diff stats
path: root/src/fe-gtk
AgeCommit message (Expand)Author
2012-10-02Change platform toolset to Visual Studio 2012Berke Viktor
2012-10-02Add XP (WDK) solution as a fallback optionBerke Viktor
2012-09-29Limit the number of URLs to keep and add GUI options for itBerke Viktor
2012-09-28KISS!Berke Viktor
2012-09-28Save URL lists in config dir by defaultBerke Viktor
2012-09-20Some rebranding work leftBerke Viktor
2012-09-16Force 5.x subsystem globallyBerke Viktor
2012-09-15Update solution to Visual Studio 2012 Express and get rid of mpcInfoBerke Viktor
2012-09-02Don't make a numeric equation between chars (openSUSE)Berke Viktor
2012-09-02Consistency for the other Advanced pane tooBerke Viktor
2012-09-01Merge pull request #68 from RichardHitt/masterbviktor
2012-09-01Be consistent in PreferencesBerke Viktor
2012-09-01Consolidate color stripping for messages, topic and scrollbackBerke Viktor
2012-08-28Enhance LASTLOG to use gtk_xtext_search_textentry()RichardHitt
2012-08-01Avoid inline declarationsBerke Viktor
2012-08-01Load custom icons from <config>/iconsBerke Viktor
2012-07-30Add missing includeBerke Viktor
2012-07-30Use a more appropriate icon in a more appropriate sizeBerke Viktor
2012-07-27Remember last search pattern during sessionsRichard Hitt
2012-07-26Auto-load user plugins and scripts from <config>/addonsBerke Viktor
2012-07-26Fix memory leak in lastlogRichard Hitt
2012-07-25Initial support for lastlog -r on win32 (Richard)Richard Hitt
2012-07-24No idea why I put 2011 hereBerke Viktor
2012-07-23Make HexChat remember minimum and maximum users set in channel listBerke Viktor
2012-07-21GtkFileFilter shouldn't be g_freedBerke Viktor
2012-07-21Add extension filter for file dialogs, specify filters and starting folder fo...Berke Viktor
2012-07-21Get rid of yet another implicit declarationBerke Viktor
2012-07-21Add _AMD64_ definition for x64 builds, make Visual Studio even happierBerke Viktor
2012-07-21Add trailing backslashes to Output and Intermediate directories, make Visual ...Berke Viktor
2012-07-21More unused variablesBerke Viktor
2012-07-21Some aid for compiler warningsBerke Viktor
2012-07-20Some XChat string left outBerke Viktor
2012-07-20Restructure the preferences window which in turn fixes the marker line toggle...Berke Viktor
2012-07-19Add option to retain colors in scrollbackBerke Viktor
2012-07-18Rebrand the manifest file tooBerke Viktor
2012-07-18Use GTK+ file dialogs on Windows too, the Win32 dialogs are too buggyBerke Viktor
2012-07-18Use hardcoded string for this one instance, otherwise it may be untranslatabl...Berke Viktor
2012-07-18Don't use hardcoded string for quit windowBerke Viktor
2012-07-18Update quit window stringBerke Viktor
2012-07-17For private messages, use message icon instead of hightlight iconBerke Viktor
2012-07-14Update XChat to r1516Berke Viktor
2012-07-14remove a few more *.user filesxhmikosr
2012-07-13Rename X-Tray to HexTrayBerke Viktor
2012-07-13Remove the last remnants of XChat-WDKBerke Viktor
2012-07-13Some cosmetic and compilation fixes for the about screenBerke Viktor
2012-07-13Make the About screen and CTCP VERSION consistent and remove the license text...Berke Viktor
2012-07-13Fix frontend compilation on LinuxBerke Viktor
2012-07-13Another bunch of rebranding stuffBerke Viktor
2012-07-13Rename files, delete old windows makefilesBerke Viktor
2012-07-12Even more rebrandingBerke Viktor
/fe-gtk/urlgrab.c?h=feature/fork-branding&id=51ae33cbe8a29c6502f16cd1bc57e5535e0b4e64'>51ae33cb ^
1012be5e ^


4a6ceffb ^













18b74180 ^
4a6ceffb ^






18b74180 ^
4a6ceffb ^
18b74180 ^

ecdcc992 ^
4a6ceffb ^


















51ae33cb ^
1012be5e ^





4a6ceffb ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229














                                                                       
                                                                            







                   

                               
























                                                                    


                                                 
 

                                                                                                
 




                                                   

                                                                        
                                                                  
                             







































































                                                                               


                                                





                                                         
                                                                                                        






                                
                       








                                                                                       

                                         
                                                    

                                                               
                                                                                                  


                                                                             













                                              
                      






                                                    
                                                                             
                          

                                                                                          
                                                  


















                                                                                                                
                                  





                                                                                                       
 
/* 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
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "fe-gtk.h"

#include "../common/hexchat.h"
#include "../common/hexchatc.h"
#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"

/* 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;
	GtkTreeSelection *sel;
	GtkTreePath *path;
	GtkTreeView *tree = GTK_TREE_VIEW (view);

	if (!event || !gtk_tree_view_get_path_at_pos (tree, event->x, event->y, &path, 0, 0, 0))
		return FALSE;

	/* 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); 

	if (!gtkutil_treeview_get_selected (GTK_TREE_VIEW (view), &iter,
	                                    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)
	{
		url_save_tree (file, "w", TRUE);
	}
}

static void
url_button_save (void)
{
	gtkutil_file_req (_("Select an output filename"),
							url_save_callback, NULL, NULL, NULL, FRF_WRITE);
}

void
fe_url_add (const char *urltext)
{
	GtkListStore *store;
	GtkTreeIter iter;
	gboolean valid;
	
	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);

		/* remove any overflow */
		if (prefs.hex_url_grabber_limit > 0)
		{
			valid = gtk_tree_model_iter_nth_child (
				GTK_TREE_MODEL (store), &iter, NULL, prefs.hex_url_grabber_limit);
			while (valid)
				valid = gtk_list_store_remove (store, &iter);
		}
	}
}

static int
populate_cb (char *urltext, gpointer userdata)
{
	fe_url_add (urltext);
	return TRUE;
}

void
url_opengui ()
{
	GtkWidget *vbox, *hbox, *view;
	char buf[128];

	if (urlgrabberwindow)
	{
		mg_bring_tofront (urlgrabberwindow);
		return;
	}

	g_snprintf(buf, sizeof(buf), _("URL Grabber - %s"), _(DISPLAY_NAME));
	urlgrabberwindow =
		mg_create_generic_tab ("UrlGrabber", buf, FALSE, TRUE, url_closegui, NULL,
							 400, 256, &vbox, 0);
	gtkutil_destroy_on_esc (urlgrabberwindow);
	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);

	gtkutil_button (hbox, GTK_STOCK_CLEAR,
						 _("Clear list"), url_button_clear, 0, _("Clear"));
	gtkutil_button (hbox, GTK_STOCK_COPY,
						 _("Copy selected URL"), url_button_copy, view, _("Copy"));
	gtkutil_button (hbox, GTK_STOCK_SAVE_AS,
						 _("Save list to a file"), url_button_save, 0, _("Save As..."));

	gtk_widget_show (urlgrabberwindow);

	if (prefs.hex_url_grabber)
		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.");
	}
}