summaryrefslogtreecommitdiff
path: root/src/nautilus-window-toolbars.c
blob: fdbe029b59ca1814f838112406fc5e9ee95819aa (plain)
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/*
 * Nautilus
 *
 * Copyright (C) 2000 Eazel, Inc.
 *
 * Nautilus 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.
 *
 * Nautilus 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * Author: John Sullivan <sullivan@eazel.com> 
 */

/* nautilus-window-toolbars.c - implementation of nautilus window toolbar operations,
 * split into separate file just for convenience.
 */

#include <config.h>

#include "nautilus-application.h"
#include "nautilus-throbber.h"
#include "nautilus-toolbar.h"
#include "nautilus-window-manage-views.h"
#include "nautilus-window-private.h"
#include "nautilus-window.h"
#include <bonobo.h>
#include <gtk/gtkframe.h>
#include <gtk/gtktogglebutton.h>
#include <libgnome/gnome-i18n.h>
#include <libgnomeui/gnome-app.h>
#include <libgnomeui/gnome-app-helper.h>
#include <libnautilus-extensions/nautilus-bookmark.h>
#include <libnautilus-extensions/nautilus-file-utilities.h>
#include <libnautilus-extensions/nautilus-global-preferences.h>
#include <libnautilus-extensions/nautilus-gnome-extensions.h>
#include <libnautilus-extensions/nautilus-gtk-extensions.h>
#include <libnautilus-extensions/nautilus-string.h>
#include <libnautilus-extensions/nautilus-theme.h>

/* forward declarations */
#ifdef EAZEL_SERVICES
/*
static void toolbar_services_callback (GtkWidget *widget, NautilusWindow *window);
*/
#endif

/* toolbar definitions */

#define TOOLBAR_BACK_BUTTON_INDEX		0
#define TOOLBAR_FORWARD_BUTTON_INDEX		1
#define TOOLBAR_UP_BUTTON_INDEX			2
#define TOOLBAR_RELOAD_BUTTON_INDEX		3
/* separator */
#define TOOLBAR_HOME_BUTTON_INDEX		5
#define TOOLBAR_SEARCH_LOCAL_BUTTON_INDEX	6
#define TOOLBAR_SEARCH_WEB_BUTTON_INDEX		7
/* separator */
#define TOOLBAR_STOP_BUTTON_INDEX		9
#define TOOLBAR_SERVICES_INDEX			10

#define GNOME_STOCK_PIXMAP_WEBSEARCH "SearchWeb"

/*
static void
activate_back_or_forward_menu_item (GtkMenuItem *menu_item, 
				    NautilusWindow *window,
				    gboolean back)
{
	int index;
	
	g_assert (GTK_IS_MENU_ITEM (menu_item));
	g_assert (NAUTILUS_IS_WINDOW (window));

	index = GPOINTER_TO_INT (gtk_object_get_user_data (GTK_OBJECT (menu_item)));
	nautilus_window_back_or_forward (window, back, index);
}

static void
activate_back_menu_item_callback (GtkMenuItem *menu_item, NautilusWindow *window)
{
	activate_back_or_forward_menu_item (menu_item, window, TRUE);
}

static void
activate_forward_menu_item_callback (GtkMenuItem *menu_item, NautilusWindow *window)
{
	activate_back_or_forward_menu_item (menu_item, window, FALSE);
}

static GtkMenu *
create_back_or_forward_menu (NautilusWindow *window, gboolean back)
{
	GtkMenu *menu;
	GtkWidget *menu_item;
	GList *list_link;
	int index;

	g_assert (NAUTILUS_IS_WINDOW (window));
	
	menu = GTK_MENU (gtk_menu_new ());

	list_link = back ? window->back_list : window->forward_list;
	index = 0;
	while (list_link != NULL)
	{
		menu_item = nautilus_bookmark_menu_item_new (NAUTILUS_BOOKMARK (list_link->data));		
		gtk_object_set_user_data (GTK_OBJECT (menu_item), GINT_TO_POINTER (index));
		gtk_widget_show (GTK_WIDGET (menu_item));
  		gtk_signal_connect
			(GTK_OBJECT(menu_item), 
			 "activate",
			 back ? activate_back_menu_item_callback : activate_forward_menu_item_callback, 
			 window);
		
		gtk_menu_append (menu, menu_item);
		list_link = g_list_next (list_link);
		++index;
	}

	return menu;
}

static int
back_or_forward_button_clicked_callback (GtkWidget *widget, 
				   GdkEventButton *event, 
				   gpointer *user_data)
{
	gboolean back;

	g_return_val_if_fail (GTK_IS_BUTTON (widget), FALSE);
	g_return_val_if_fail (NAUTILUS_IS_WINDOW (user_data), FALSE);
	g_return_val_if_fail (event != NULL, FALSE);

	back = NAUTILUS_WINDOW (user_data)->back_button == widget;
	g_assert (back || NAUTILUS_WINDOW (user_data)->forward_button == widget);

	if (event->button == 3) {
		nautilus_pop_up_context_menu (
			create_back_or_forward_menu (NAUTILUS_WINDOW (user_data),
						     back),
                        NAUTILUS_DEFAULT_POPUP_MENU_DISPLACEMENT,
                        NAUTILUS_DEFAULT_POPUP_MENU_DISPLACEMENT,
                        event->button);

		return TRUE;
	}

	return FALSE;
	
}
*/

/* set up the toolbar info based on the current theme selection from preferences */

static void
set_up_button (NautilusWindow *window, const char *item_name, const char* icon_name)
{
	char *full_name, *icon_theme, *path_name, *bonobo_path;

	/* look in the theme to see if there's a redirection found */
	icon_theme = nautilus_theme_get_theme_data ("toolbar", "ICON_THEME");
	if (icon_theme) {
		path_name = g_strdup_printf ("%s/%s.png", icon_theme, icon_name);
		full_name = nautilus_pixmap_file (path_name);
		g_free (path_name);
		g_free (icon_theme);
	} else {
		full_name = nautilus_theme_get_image_path (icon_name);
	}
		
	bonobo_path = g_strdup_printf ("/Tool Bar/%s", item_name);	

	/* set up the toolbar component with the new image */

	bonobo_ui_component_freeze (window->details->shell_ui, NULL);
		
	bonobo_ui_component_set_prop (window->details->shell_ui, 
				      bonobo_path,
				      "pixtype",
				      full_name == NULL ? "stock" : "filename",
			      	      NULL);
	
	bonobo_ui_component_set_prop (window->details->shell_ui, 
				      bonobo_path,
				      "pixname",
				      full_name == NULL ? icon_name : full_name,
			      	      NULL);
	
	bonobo_ui_component_thaw (window->details->shell_ui, NULL);

	g_free (bonobo_path);
	g_free (full_name);
}


static void
set_up_toolbar_images (NautilusWindow *window)
{
	set_up_button (window, "Back", "Back");
	set_up_button (window, "Forward", "Forward");
	set_up_button (window, "Up", "Up");
	set_up_button (window, "Home", "Home");
	set_up_button (window, "Reload", "Refresh");
	set_up_button (window, "Toggle Find Mode", "Search");
	set_up_button (window, "Go to Web Search", "SearchWeb");
	set_up_button (window, "Stop", "Stop");
}

static GtkWidget *
set_up_throbber_frame_type (NautilusWindow *window)
{
	GtkWidget *frame;
	char *frame_type;
	GtkShadowType shadow_type;
	
	frame = window->throbber->parent;
	
	frame_type = nautilus_theme_get_theme_data ("toolbar", "FRAME_TYPE");
	shadow_type = GTK_SHADOW_NONE;
	
	if (nautilus_strcmp (frame_type, "in") == 0) {
		shadow_type = GTK_SHADOW_IN;
	} else if (nautilus_strcmp (frame_type, "out") == 0) {
		shadow_type = GTK_SHADOW_OUT;	
	} else if (nautilus_strcmp (frame_type, "none") == 0) {
		shadow_type = GTK_SHADOW_NONE;	
	} else {
		shadow_type = GTK_SHADOW_NONE;
	}
	
	g_free (frame_type);	
	gtk_frame_set_shadow_type (GTK_FRAME (frame), shadow_type);
	
	return frame;
}

static GtkWidget*
allocate_throbber (void)
{
	GtkWidget *throbber, *frame;
	gboolean small_mode;
	
	throbber = nautilus_throbber_new ();
	gtk_widget_show (throbber);
	
	frame = gtk_frame_new (NULL);
	gtk_widget_show (frame);
	gtk_container_add (GTK_CONTAINER (frame), throbber);
			
	small_mode = FALSE; /* for now - want to query the toolbar's style soon */
	nautilus_throbber_set_small_mode (NAUTILUS_THROBBER (throbber), small_mode);
	
	return throbber;
}

/* handle theme changes */
static void
theme_changed_callback (gpointer callback_data)
{
	set_up_toolbar_images (NAUTILUS_WINDOW (callback_data));
	set_up_throbber_frame_type (NAUTILUS_WINDOW (callback_data));
}

/* initialize the toolbar */
void
nautilus_window_initialize_toolbars (NautilusWindow *window)
{
	GtkWidget *frame;
	BonoboControl *throbber_wrapper;
	
	set_up_toolbar_images (window);
	
	window->throbber = allocate_throbber ();	
	frame = set_up_throbber_frame_type (window);
	
	throbber_wrapper = bonobo_control_new (frame);
	
	bonobo_ui_component_object_set (window->details->shell_ui,
					"/Tool Bar/ThrobberWrapper",
					bonobo_object_corba_objref (BONOBO_OBJECT (throbber_wrapper)),
					NULL);
	
	bonobo_object_unref (BONOBO_OBJECT (throbber_wrapper));


	/*
	gtk_signal_connect (GTK_OBJECT (window->back_button),
			    "button_press_event",
			    GTK_SIGNAL_FUNC (back_or_forward_button_clicked_callback), 
			    window);

	gtk_signal_connect (GTK_OBJECT (window->forward_button),
			    "button_press_event",
			    GTK_SIGNAL_FUNC (back_or_forward_button_clicked_callback), 
			    window);
	*/
	
	/* add callback for preference changes */
	nautilus_preferences_add_callback
		(NAUTILUS_PREFERENCES_THEME, 
		 theme_changed_callback,
		 window);
}
 
void
nautilus_window_toolbar_remove_theme_callback (NautilusWindow *window)
{
	nautilus_preferences_remove_callback
		(NAUTILUS_PREFERENCES_THEME,
		 theme_changed_callback,
		 window);
}


#ifdef EAZEL_SERVICES
/*
static void
toolbar_services_callback (GtkWidget *widget, NautilusWindow *window)
{
	nautilus_window_goto_uri (window, "eazel:");
}
*/
#endif