gth-browser.c 193 KB
Newer Older
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/*
 *  GThumb
 *
 *  Copyright (C) 2005-2009 Free Software Foundation, Inc.
 *
 *  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
19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
Paolo Bacchilega's avatar
Paolo Bacchilega committed
20 21 22
 */

#include <config.h>
23
#include <math.h>
Paolo Bacchilega's avatar
Paolo Bacchilega committed
24
#include <gtk/gtk.h>
25
#include <gdk/gdkkeysyms.h>
Paolo Bacchilega's avatar
Paolo Bacchilega committed
26 27 28
#include "dlg-personalize-filters.h"
#include "glib-utils.h"
#include "gtk-utils.h"
29
#include "gth-auto-paned.h"
Paolo Bacchilega's avatar
Paolo Bacchilega committed
30 31 32 33 34
#include "gth-browser.h"
#include "gth-browser-actions-callbacks.h"
#include "gth-browser-actions-entries.h"
#include "gth-browser-ui.h"
#include "gth-duplicable.h"
35
#include "gth-embedded-dialog.h"
Paolo Bacchilega's avatar
Paolo Bacchilega committed
36
#include "gth-enum-types.h"
37
#include "gth-error.h"
Paolo Bacchilega's avatar
Paolo Bacchilega committed
38 39 40 41 42 43
#include "gth-file-list.h"
#include "gth-file-view.h"
#include "gth-file-selection.h"
#include "gth-filter.h"
#include "gth-filterbar.h"
#include "gth-folder-tree.h"
44
#include "gth-grid-view.h"
Paolo Bacchilega's avatar
Paolo Bacchilega committed
45
#include "gth-icon-cache.h"
46
#include "gth-info-bar.h"
Paolo Bacchilega's avatar
Paolo Bacchilega committed
47 48 49 50
#include "gth-image-preloader.h"
#include "gth-location-chooser.h"
#include "gth-main.h"
#include "gth-marshal.h"
51
#include "gth-menu-action.h"
Paolo Bacchilega's avatar
Paolo Bacchilega committed
52
#include "gth-metadata-provider.h"
53
#include "gth-paned.h"
Paolo Bacchilega's avatar
Paolo Bacchilega committed
54
#include "gth-preferences.h"
55
#include "gth-progress-dialog.h"
Paolo Bacchilega's avatar
Paolo Bacchilega committed
56 57
#include "gth-sidebar.h"
#include "gth-statusbar.h"
58
#include "gth-toggle-menu-tool-button.h"
59
#include "gth-user-dir.h"
Paolo Bacchilega's avatar
Paolo Bacchilega committed
60 61 62 63
#include "gth-viewer-page.h"
#include "gth-window.h"
#include "gth-window-actions-callbacks.h"
#include "gth-window-actions-entries.h"
64
#include "main.h"
Paolo Bacchilega's avatar
Paolo Bacchilega committed
65 66 67

#define GTH_BROWSER_CALLBACK(f) ((GthBrowserCallback) (f))
#define MAX_HISTORY_LENGTH 15
68
#define LOAD_FILE_DELAY 150
69 70
#define HIDE_MOUSE_DELAY 1000
#define MOTION_THRESHOLD 0
71
#define UPDATE_SELECTION_DELAY 200
72
#define MIN_SIDEBAR_SIZE 100
73
#define MIN_VIEWER_SIZE 256
74
#define STATUSBAR_SEPARATOR " · "
75 76
#define SHIRNK_WRAP_WIDTH_OFFSET 100
#define SHIRNK_WRAP_HEIGHT_OFFSET 125
77
#define FILE_PROPERTIES_MINIMUM_HEIGHT 100
78
#define HISTORY_FILE "history.xbel"
Paolo Bacchilega's avatar
Paolo Bacchilega committed
79

80 81 82
G_DEFINE_TYPE (GthBrowser, gth_browser, GTH_TYPE_WINDOW)


Paolo Bacchilega's avatar
Paolo Bacchilega committed
83 84 85 86 87
enum {
	LOCATION_READY,
	LAST_SIGNAL
};

88

89 90 91 92 93 94 95 96 97 98
typedef struct {
	gboolean        saved;
	GthBrowserPage  page;
	GFile          *location;
	GFile          *current_file;
	GList          *selected;
	double          vscroll;
} BrowserState;


Paolo Bacchilega's avatar
Paolo Bacchilega committed
99
struct _GthBrowserPrivate {
Paolo Bacchilega's avatar
Paolo Bacchilega committed
100 101 102 103
	/* UI staff */

	GtkUIManager      *ui;
	GtkActionGroup    *actions;
104
	GtkWidget         *infobar;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
105 106
	GtkWidget         *statusbar;
	GtkWidget         *browser_toolbar;
107 108
	GtkWidget         *browser_right_container;
	GtkWidget         *browser_left_container;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
109 110 111 112 113
	GtkWidget         *browser_sidebar;
	GtkWidget         *folder_tree;
	GtkWidget         *history_list_popup_menu;
	GtkWidget         *folder_popup;
	GtkWidget         *file_list_popup;
114
	GtkWidget         *file_popup;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
115 116 117 118 119 120
	GtkWidget         *filterbar;
	GtkWidget         *file_list;
	GtkWidget         *list_extra_widget_container;
	GtkWidget         *list_extra_widget;
	GtkWidget         *file_properties;

121 122
	GtkWidget         *thumbnail_list;

123
	GList             *viewer_pages;
124 125
	GtkWidget         *viewer_thumbnails_pane;
	GtkWidget         *viewer_sidebar_pane;
126
	GtkWidget         *viewer_sidebar_alignment;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
127 128 129 130 131
	GtkWidget         *viewer_container;
	GtkWidget         *viewer_toolbar;
	GthViewerPage     *viewer_page;
	GthImagePreloader *image_preloader;

132 133
	GtkWidget         *progress_dialog;

Paolo Bacchilega's avatar
Paolo Bacchilega committed
134 135 136 137 138 139 140 141 142 143 144 145
	GHashTable        *named_dialogs;
	GList             *toolbar_menu_buttons[GTH_BROWSER_N_PAGES];

	guint              browser_ui_merge_id;
	guint              viewer_ui_merge_id;

	/* Browser data */

	guint              help_message_cid;
	gulong             folder_changed_id;
	gulong             file_renamed_id;
	gulong             metadata_changed_id;
146
	gulong             emblems_changed_id;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
147
	gulong             entry_points_changed_id;
148
	gulong             order_changed_id;
149
	GthFileData       *location;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
150 151
	GthFileData       *current_file;
	GthFileSource     *location_source;
152 153
	int                n_visibles;
	int                current_file_position;
154
	GFile             *monitor_location;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
155 156
	gboolean           activity_ref;
	GthIconCache      *menu_icon_cache;
157 158 159 160
	GthFileDataSort   *current_sort_type;
	gboolean           current_sort_inverse;
	GthFileDataSort   *default_sort_type;
	gboolean           default_sort_inverse;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
161 162 163 164 165
	gboolean           show_hidden_files;
	gboolean           fast_file_type;
	gboolean           closing;
	GthTask           *task;
	gulong             task_completed;
166
	gulong             task_progress;
167
	GList             *background_tasks;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
168
	GList             *load_data_queue;
169
	GList             *load_file_data_queue;
170
	guint              load_file_timeout;
171
	char              *list_attributes;
172
	gboolean           constructed;
173
	guint              construct_step2_event;
174
	guint              selection_changed_event;
175
	GthFileData       *folder_popup_file_data;
176
	gboolean           properties_on_screen;
177 178
	char              *location_free_space;
	gboolean           recalc_location_free_space;
179
	gboolean           shrink_wrap_viewer;
180
	gboolean           file_properties_on_the_right;
181
	GthSidebarState    viewer_sidebar;
182
	BrowserState       state;
183

184 185 186 187 188 189
	/* settings */

	GSettings         *browser_settings;
	GSettings         *messages_settings;
	GSettings         *desktop_interface_settings;

190 191
	/* fulscreen */

Paolo Bacchilega's avatar
Paolo Bacchilega committed
192
	gboolean           fullscreen;
193
	GtkWidget         *fullscreen_toolbar;
194
	GList             *fullscreen_controls;
195 196 197 198
	guint              hide_mouse_timeout;
	guint              motion_signal;
	gdouble            last_mouse_x;
	gdouble            last_mouse_y;
199 200 201 202 203 204
	struct {
		int      page;
		gboolean viewer_properties;
		gboolean viewer_tools;
		gboolean thumbnail_list;
	} before_fullscreen;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
205 206 207 208 209

	/* history */

	GList             *history;
	GList             *history_current;
210 211 212
	GtkWidget         *back_history_menu;
	GtkWidget         *forward_history_menu;
	GtkWidget         *go_parent_menu;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
213 214 215 216 217 218
};


static guint gth_browser_signals[LAST_SIGNAL] = { 0 };


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
/* -- browser_state -- */


static void
browser_state_init (BrowserState *state)
{
	state->saved = FALSE;
	state->page = 0;
	state->location = NULL;
	state->current_file = NULL;
	state->selected = NULL;
}


static void
browser_state_free (BrowserState *state)
{
	if (! state->saved)
		return;

	_g_object_unref (state->location);
	_g_object_unref (state->current_file);
	g_list_foreach (state->selected, (GFunc) gtk_tree_path_free, NULL);
	g_list_free (state->selected);

	state->location = NULL;
	state->current_file = NULL;
	state->selected = NULL;
	state->saved = FALSE;
}


Paolo Bacchilega's avatar
Paolo Bacchilega committed
251 252 253 254 255 256 257
/* -- monitor_event_data -- */


typedef struct {
	int              ref;
	GthFileSource   *file_source;
	GFile           *parent;
258
	int              position;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
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
	GthMonitorEvent  event;
	GthBrowser      *browser;
	gboolean         update_file_list;
	gboolean         update_folder_tree;
} MonitorEventData;


static MonitorEventData *
monitor_event_data_new (void)
{
	MonitorEventData *monitor_data;

	monitor_data = g_new0 (MonitorEventData, 1);
	monitor_data->ref = 1;

	return monitor_data;
}


G_GNUC_UNUSED
static MonitorEventData *
monitor_event_data_ref (MonitorEventData *monitor_data)
{
	monitor_data->ref++;
	return monitor_data;
}


static void
monitor_event_data_unref (MonitorEventData *monitor_data)
{
	monitor_data->ref--;

	if (monitor_data->ref > 0)
		return;

	g_object_unref (monitor_data->file_source);
	g_object_unref (monitor_data->parent);
	g_free (monitor_data);
}


/* -- gth_browser -- */


static void
_gth_browser_set_action_sensitive (GthBrowser  *browser,
				   const char  *action_name,
				   gboolean     sensitive)
{
	GtkAction *action;

	action = gtk_action_group_get_action (browser->priv->actions, action_name);
	g_object_set (action, "sensitive", sensitive, NULL);
}


static void
_gth_browser_set_action_active (GthBrowser  *browser,
				const char  *action_name,
				gboolean     active)
{
	GtkAction *action;

	action = gtk_action_group_get_action (browser->priv->actions, action_name);
	g_object_set (action, "active", active, NULL);
}


328 329 330 331 332 333 334 335 336 337 338 339 340 341
static gboolean
_gth_browser_get_action_active (GthBrowser  *browser,
				const char  *action_name)
{
	GtkAction *action;
	gboolean   active;

	action = gtk_action_group_get_action (browser->priv->actions, action_name);
	g_object_get (action, "active", &active, NULL);

	return active;
}


Paolo Bacchilega's avatar
Paolo Bacchilega committed
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
static void
activate_go_back_menu_item (GtkMenuItem *menuitem,
			    gpointer     data)
{
	GthBrowser *browser = data;

	gth_browser_go_back (browser, GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menuitem), "steps")));
}


static void
activate_go_forward_menu_item (GtkMenuItem *menuitem,
			       gpointer     data)
{
	GthBrowser *browser = data;

	gth_browser_go_forward (browser, GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menuitem), "steps")));
}


static void
activate_go_up_menu_item (GtkMenuItem *menuitem,
			  gpointer     data)
{
	GthBrowser *browser = data;

	gth_browser_go_up (browser, GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menuitem), "steps")));
}


static void
activate_go_to_menu_item (GtkMenuItem *menuitem,
			  gpointer     data)
{
	GthBrowser *browser = data;
	GFile      *location;

	location = g_file_new_for_uri (g_object_get_data (G_OBJECT (menuitem), "uri"));
380
	gth_browser_go_to (browser, location, NULL);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
381 382 383 384 385

	g_object_unref (location);
}


386
void
Paolo Bacchilega's avatar
Paolo Bacchilega committed
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
_gth_browser_add_file_menu_item_full (GthBrowser *browser,
				      GtkWidget  *menu,
				      GFile      *file,
				      GIcon      *icon,
				      const char *display_name,
				      GthAction   action,
				      int         steps,
				      int         position)
{
	GdkPixbuf *pixbuf;
	GtkWidget *menu_item;

	pixbuf = gth_icon_cache_get_pixbuf (browser->priv->menu_icon_cache, icon);

	menu_item = gtk_image_menu_item_new_with_label (display_name);
402
	gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menu_item), TRUE);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
403 404 405 406 407 408 409 410 411 412 413
	if (pixbuf != NULL)
		gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), gtk_image_new_from_pixbuf (pixbuf));
	else
		gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), gtk_image_new_from_stock (GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU));
	gtk_widget_show (menu_item);
	if (position == -1)
		gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
	else
		gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menu_item, position);

	if (action == GTH_ACTION_GO_TO) {
414
		char *parse_name;
415
		char *tooltip;
416 417

		parse_name = g_file_get_parse_name (file);
418 419
		tooltip = g_strdup_printf (_("Open %s"), parse_name);
		gtk_widget_set_tooltip_text (GTK_WIDGET (menu_item), tooltip);
420

Paolo Bacchilega's avatar
Paolo Bacchilega committed
421 422
		g_object_set_data_full (G_OBJECT (menu_item),
					"uri",
423
					g_file_get_uri (file),
Paolo Bacchilega's avatar
Paolo Bacchilega committed
424 425 426 427 428
					(GDestroyNotify) g_free);
		g_signal_connect (menu_item,
				  "activate",
				  G_CALLBACK (activate_go_to_menu_item),
			  	  browser);
429

430
		g_free (tooltip);
431
		g_free (parse_name);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
	}
	else {
		g_object_set_data (G_OBJECT (menu_item),
				   "steps",
				   GINT_TO_POINTER (steps));
		if (action == GTH_ACTION_GO_BACK)
			g_signal_connect (menu_item,
					  "activate",
					  G_CALLBACK (activate_go_back_menu_item),
			  	  	  browser);
		else if (action == GTH_ACTION_GO_FORWARD)
			g_signal_connect (menu_item,
					  "activate",
					  G_CALLBACK (activate_go_forward_menu_item),
			  	  	  browser);
		else if (action == GTH_ACTION_GO_UP)
			g_signal_connect (menu_item,
					  "activate",
					  G_CALLBACK (activate_go_up_menu_item),
			  	  	  browser);
	}

	if (pixbuf != NULL)
		g_object_unref (pixbuf);
}


459
void
Paolo Bacchilega's avatar
Paolo Bacchilega committed
460 461 462
_gth_browser_add_file_menu_item (GthBrowser *browser,
				 GtkWidget  *menu,
			 	 GFile      *file,
463
			 	 const char *display_name,
Paolo Bacchilega's avatar
Paolo Bacchilega committed
464 465 466 467 468 469 470
			 	 GthAction   action,
				 int         steps)
{
	GthFileSource *file_source;
	GFileInfo     *info;

	file_source = gth_main_get_file_source (file);
471
	info = gth_file_source_get_file_info (file_source, file, GFILE_DISPLAY_ATTRIBUTES);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
472 473 474 475 476
	if (info != NULL) {
		_gth_browser_add_file_menu_item_full (browser,
						      menu,
						      file,
						      g_file_info_get_icon (info),
477
						      (display_name != NULL) ? display_name : g_file_info_get_display_name (info),
Paolo Bacchilega's avatar
Paolo Bacchilega committed
478 479 480 481 482
						      action,
						      steps,
						      -1);
		g_object_unref (info);
	}
483 484 485 486 487 488 489 490 491 492
	else {
		GIcon *icon;
		char  *name;

		icon = _g_file_get_icon (file);
		name = _g_file_get_display_name (file);
		_gth_browser_add_file_menu_item_full (browser,
						      menu,
						      file,
						      icon,
493
						      (display_name != NULL) ? display_name : name,
494 495 496 497 498 499 500 501
						      action,
						      steps,
						      -1);

		g_free (name);
		g_object_unref (icon);
	}

Paolo Bacchilega's avatar
Paolo Bacchilega committed
502 503 504 505 506 507 508 509 510 511 512
	g_object_unref (file_source);
}


static void
_gth_browser_update_parent_list (GthBrowser *browser)
{
	GtkWidget *menu;
	int        i;
	GFile     *parent;

513
	menu = browser->priv->go_parent_menu;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
514 515 516 517 518 519 520 521
	_gtk_container_remove_children (GTK_CONTAINER (menu), NULL, NULL);

	if (browser->priv->location == NULL)
		return;

	/* Update the parent list menu. */

	i = 0;
522
	parent = g_file_get_parent (browser->priv->location->file);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
523 524 525 526 527 528
	while (parent != NULL) {
		GFile *parent_parent;

		_gth_browser_add_file_menu_item (browser,
						 menu,
						 parent,
529
						 NULL,
Paolo Bacchilega's avatar
Paolo Bacchilega committed
530 531 532 533 534 535 536 537 538 539 540 541 542
						 GTH_ACTION_GO_UP,
						 ++i);

		parent_parent = g_file_get_parent (parent);
		g_object_unref (parent);
		parent = parent_parent;
	}
}


void
gth_browser_update_title (GthBrowser *browser)
{
543 544 545
	GString      *title;
	const char   *name = NULL;
	GthFileStore *file_store;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
546

547
	title = g_string_new (NULL);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
548

549 550 551 552
	if (browser->priv->current_file != NULL)
		name = g_file_info_get_display_name (browser->priv->current_file->info);
	else if (browser->priv->location != NULL)
		name = g_file_info_get_display_name (browser->priv->location->info);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
553

554 555
	if (name != NULL) {
		g_string_append (title, name);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
556 557 558 559 560 561
		if (gth_browser_get_file_modified (browser)) {
			g_string_append (title, " ");
			g_string_append (title, _("[modified]"));
		}
	}

562 563 564 565
	file_store = gth_browser_get_file_store (browser);
	browser->priv->n_visibles = gth_file_store_n_visibles (file_store);
	browser->priv->current_file_position = -1;

566
	if (browser->priv->current_file != NULL) {
567
		int pos;
568

569
		pos = gth_file_store_get_pos (file_store, browser->priv->current_file->file);
570 571
		if (pos >= 0) {
			browser->priv->current_file_position = pos;
572
			g_string_append_printf (title, " - %d/%d", browser->priv->current_file_position + 1, browser->priv->n_visibles);
573
		}
574 575
	}

576 577
	if (title->len > 0)
		g_string_append (title, " - ");
578
	g_string_append (title, _("gThumb"));
579

Paolo Bacchilega's avatar
Paolo Bacchilega committed
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
	gtk_window_set_title (GTK_WINDOW (browser), title->str);

	g_string_free (title, TRUE);
}


void
gth_browser_update_sensitivity (GthBrowser *browser)
{
	GFile    *parent;
	gboolean  parent_available;
	gboolean  viewer_can_save;
	gboolean  modified;
	int       current_file_pos;
	int       n_files;
	int       n_selected;

	if (browser->priv->location != NULL)
598
		parent = g_file_get_parent (browser->priv->location->file);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
599 600 601 602 603 604 605 606 607
	else
		parent = NULL;
	parent_available = (parent != NULL);
	_g_object_unref (parent);

	viewer_can_save = (browser->priv->location != NULL) && (browser->priv->viewer_page != NULL) && gth_viewer_page_can_save (GTH_VIEWER_PAGE (browser->priv->viewer_page));
	modified = gth_browser_get_file_modified (browser);

	if (browser->priv->current_file != NULL)
608
		current_file_pos = gth_file_store_get_pos (gth_browser_get_file_store (browser), browser->priv->current_file->file);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
609 610 611 612 613
	else
		current_file_pos = -1;
	n_files = gth_file_store_n_visibles (gth_browser_get_file_store (browser));
	n_selected = gth_file_selection_get_n_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));

614
	_gth_browser_set_action_sensitive (browser, "File_Open", n_selected == 1);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
615 616 617 618 619
	_gth_browser_set_action_sensitive (browser, "File_Save", viewer_can_save && modified);
	_gth_browser_set_action_sensitive (browser, "File_SaveAs", viewer_can_save);
	_gth_browser_set_action_sensitive (browser, "File_Revert", viewer_can_save && modified);
	_gth_browser_set_action_sensitive (browser, "Go_Up", parent_available);
	_gth_browser_set_action_sensitive (browser, "Toolbar_Go_Up", parent_available);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
620
	_gth_browser_set_action_sensitive (browser, "View_Stop", browser->priv->fullscreen || (browser->priv->activity_ref > 0));
Paolo Bacchilega's avatar
Paolo Bacchilega committed
621 622
	_gth_browser_set_action_sensitive (browser, "View_Prev", current_file_pos > 0);
	_gth_browser_set_action_sensitive (browser, "View_Next", (current_file_pos != -1) && (current_file_pos < n_files - 1));
623
	_gth_browser_set_action_sensitive (browser, "View_Thumbnail_List", gth_window_get_current_page (GTH_WINDOW (browser)) == GTH_BROWSER_PAGE_VIEWER);
624
	_gth_browser_set_action_sensitive (browser, "View_Sidebar", gth_window_get_current_page (GTH_WINDOW (browser)) == GTH_BROWSER_PAGE_BROWSER);
625
	_gth_browser_set_action_sensitive (browser, "View_Reload", gth_window_get_current_page (GTH_WINDOW (browser)) == GTH_BROWSER_PAGE_BROWSER);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
626

627 628
	gth_sidebar_update_sensitivity (GTH_SIDEBAR (browser->priv->file_properties));

Paolo Bacchilega's avatar
Paolo Bacchilega committed
629 630 631 632 633 634 635
	if (browser->priv->viewer_page != NULL)
		gth_viewer_page_update_sensitivity (browser->priv->viewer_page);

	gth_hook_invoke ("gth-browser-update-sensitivity", browser);
}


636
void
637
gth_browser_update_extra_widget (GthBrowser *browser)
638 639
{
	gedit_message_area_clear_action_area (GEDIT_MESSAGE_AREA (browser->priv->list_extra_widget));
640
	gth_embedded_dialog_set_from_file (GTH_EMBEDDED_DIALOG (browser->priv->list_extra_widget), browser->priv->location->file);
641
	gth_hook_invoke ("gth-browser-update-extra-widget", browser);
642 643 644
}


Paolo Bacchilega's avatar
Paolo Bacchilega committed
645
static void
646 647
_gth_browser_set_location (GthBrowser  *browser,
			   GthFileData *location)
Paolo Bacchilega's avatar
Paolo Bacchilega committed
648
{
649 650
	GtkWidget *location_chooser;

Paolo Bacchilega's avatar
Paolo Bacchilega committed
651 652 653 654 655
	if (location == NULL)
		return;

	if (browser->priv->location != NULL)
		g_object_unref (browser->priv->location);
656
	browser->priv->location = gth_file_data_dup (location);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
657 658 659 660

	gth_browser_update_title (browser);
	_gth_browser_update_parent_list (browser);
	gth_browser_update_sensitivity (browser);
661 662 663

	location_chooser = gth_embedded_dialog_get_chooser (GTH_EMBEDDED_DIALOG (browser->priv->list_extra_widget));
	g_signal_handlers_block_by_data (location_chooser, browser);
664
	gth_browser_update_extra_widget (browser);
665
	g_signal_handlers_unblock_by_data (location_chooser, browser);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
666 667 668
}


669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687
static void
_gth_browser_set_location_from_file (GthBrowser *browser,
				     GFile      *file)
{
	GthFileSource *file_source;
	GthFileData   *file_data;
	GFileInfo     *info;

	file_source = gth_main_get_file_source (file);
	info = gth_file_source_get_file_info (file_source, file, GFILE_DISPLAY_ATTRIBUTES);
	file_data = gth_file_data_new (file, info);
	_gth_browser_set_location (browser, file_data);

	g_object_unref (file_data);
	_g_object_unref (info);
	g_object_unref (file_source);
}


Paolo Bacchilega's avatar
Paolo Bacchilega committed
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
static void
_gth_browser_update_go_sensitivity (GthBrowser *browser)
{
	gboolean  sensitive;

	sensitive = (browser->priv->history_current != NULL) && (browser->priv->history_current->next != NULL);
	_gth_browser_set_action_sensitive (browser, "Go_Back", sensitive);
	_gth_browser_set_action_sensitive (browser, "Toolbar_Go_Back", sensitive);

	sensitive = (browser->priv->history_current != NULL) && (browser->priv->history_current->prev != NULL);
	_gth_browser_set_action_sensitive (browser, "Go_Forward", sensitive);
	_gth_browser_set_action_sensitive (browser, "Toolbar_Go_Forward", sensitive);
}


static void
activate_clear_history_menu_item (GtkMenuItem *menuitem,
				  gpointer     data)
{
	gth_browser_clear_history ((GthBrowser *)data);
}


static void
_gth_browser_add_clear_history_menu_item (GthBrowser *browser,
					  GtkWidget  *menu)
{
	GtkWidget *menu_item;

	menu_item = gtk_separator_menu_item_new ();
	gtk_widget_show (menu_item);
	gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);

	menu_item = gtk_image_menu_item_new_with_mnemonic (_("_Delete History"));
	gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU));
	gtk_widget_show (menu_item);
	gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);

	g_signal_connect (menu_item,
			  "activate",
			  G_CALLBACK (activate_clear_history_menu_item),
		  	  browser);
}


733 734
#if 0
static void
735
_gth_browser_history_print (GthBrowser *browser)
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752
{
	GList *scan;

	g_print ("history:\n");
	for (scan = browser->priv->history; scan; scan = scan->next) {
		GFile *file = scan->data;
		char  *uri;

		uri = g_file_get_uri (file);
		g_print (" %s%s\n", (browser->priv->history_current == scan) ? "*" : " ", uri);

		g_free (uri);
	}
}
#endif


Paolo Bacchilega's avatar
Paolo Bacchilega committed
753
static void
754
_gth_browser_history_menu (GthBrowser *browser)
Paolo Bacchilega's avatar
Paolo Bacchilega committed
755 756 757 758 759 760 761 762 763
{
	GtkWidget *menu;
	GList     *scan;
	GtkWidget *separator;

	_gth_browser_update_go_sensitivity (browser);

	/* Update the back history menu. */

764
	menu = browser->priv->back_history_menu;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
765 766 767 768 769 770 771 772 773 774 775 776 777 778
	_gtk_container_remove_children (GTK_CONTAINER (menu), NULL, NULL);

	if ((browser->priv->history != NULL)
	    && (browser->priv->history_current->next != NULL))
	{
		int i;

		for (i = 0, scan = browser->priv->history_current->next;
		     scan && (i < MAX_HISTORY_LENGTH);
		     scan = scan->next)
		{
			_gth_browser_add_file_menu_item (browser,
							 menu,
							 scan->data,
779
							 NULL,
Paolo Bacchilega's avatar
Paolo Bacchilega committed
780 781 782 783 784 785 786 787 788
							 GTH_ACTION_GO_BACK,
							 ++i);
		}
		if (i > 0)
			_gth_browser_add_clear_history_menu_item (browser, menu);
	}

	/* Update the forward history menu. */

789
	menu = browser->priv->forward_history_menu;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
790 791 792 793 794 795 796 797 798 799 800 801 802 803
	_gtk_container_remove_children (GTK_CONTAINER (menu), NULL, NULL);

	if ((browser->priv->history != NULL)
	    && (browser->priv->history_current->prev != NULL))
	{
		int i;

		for (i = 0, scan = browser->priv->history_current->prev;
		     scan && (i < MAX_HISTORY_LENGTH);
		     scan = scan->prev)
		{
			_gth_browser_add_file_menu_item (browser,
							 menu,
							 scan->data,
804
							 NULL,
Paolo Bacchilega's avatar
Paolo Bacchilega committed
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828
							 GTH_ACTION_GO_FORWARD,
							 ++i);
		}
		if (i > 0)
			_gth_browser_add_clear_history_menu_item (browser, menu);
	}

	/* Update the history list in the go menu */

	separator = gtk_ui_manager_get_widget (browser->priv->ui, "/MenuBar/Go/HistoryList");
	menu = gtk_widget_get_parent (separator);

	_gtk_container_remove_children (GTK_CONTAINER (menu), separator, NULL);

	if (browser->priv->history != NULL) {
		int i;

		for (i = 0, scan = browser->priv->history;
		     scan && (i < MAX_HISTORY_LENGTH);
		     scan = scan->next)
		{
			_gth_browser_add_file_menu_item (browser,
							 menu,
							 scan->data,
829
							 NULL,
Paolo Bacchilega's avatar
Paolo Bacchilega committed
830 831 832 833 834 835 836 837 838 839 840
							 GTH_ACTION_GO_TO,
							 ++i);
		}
	}

	separator = gtk_ui_manager_get_widget (browser->priv->ui, "/MenuBar/Go/BeforeHistoryList");
	gtk_widget_show (separator);
}


static void
841 842
_gth_browser_history_add (GthBrowser *browser,
			  GFile      *file)
Paolo Bacchilega's avatar
Paolo Bacchilega committed
843 844 845 846
{
	if (file == NULL)
		return;

847
	if ((browser->priv->history_current == NULL) || ! _g_file_equal_uris (file, browser->priv->history_current->data)) {
848 849
		GList *scan;

850 851 852 853 854 855 856 857 858 859 860
		/* remove all files after the current position */
		for (scan = browser->priv->history; scan && (scan != browser->priv->history_current); /* void */) {
			GList *next = scan->next;

			browser->priv->history = g_list_remove_link (browser->priv->history, scan);
			_g_object_list_unref (scan);

			scan = next;
		}

		/* remove all the occurrences of 'file' from the history */
861
		for (scan = browser->priv->history; scan; /* void */) {
862 863 864
			GList *next = scan->next;
			GFile *file_in_history = scan->data;

865 866
			if (_g_file_equal_uris (file, file_in_history)) {
				browser->priv->history = g_list_remove_link (browser->priv->history, scan);
867 868 869 870 871 872
				_g_object_list_unref (scan);
			}

			scan = next;
		}

Paolo Bacchilega's avatar
Paolo Bacchilega committed
873 874 875 876 877 878
		browser->priv->history = g_list_prepend (browser->priv->history, g_object_ref (file));
		browser->priv->history_current = browser->priv->history;
	}
}


879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940
static void
_gth_browser_history_save (GthBrowser *browser)
{
	GBookmarkFile *bookmarks;
	GFile         *file;
	char          *filename;
	GList         *scan;
	int            n;

	bookmarks = g_bookmark_file_new ();
	for (scan = browser->priv->history, n = 0; scan && (n < MAX_HISTORY_LENGTH); scan = scan->next, n++) {
		GFile *location = scan->data;
		char  *uri;

		uri = g_file_get_uri (location);
		_g_bookmark_file_add_uri (bookmarks, uri);

		g_free (uri);
	}
	file = gth_user_dir_get_file_for_write (GTH_DIR_CONFIG, GTHUMB_DIR, HISTORY_FILE, NULL);
	filename = g_file_get_path (file);
	g_bookmark_file_to_file (bookmarks, filename, NULL);

	g_free (filename);
	g_object_unref (file);
	g_bookmark_file_free (bookmarks);
}


static void
_gth_browser_history_load (GthBrowser *browser)
{
	GBookmarkFile *bookmarks;
	GFile         *file;
	char          *filename;

	_g_object_list_unref (browser->priv->history);
	browser->priv->history = NULL;

	bookmarks = g_bookmark_file_new ();
	file = gth_user_dir_get_file_for_read (GTH_DIR_CONFIG, GTHUMB_DIR, HISTORY_FILE, NULL);
	filename = g_file_get_path (file);
	if (g_bookmark_file_load_from_file (bookmarks, filename, NULL)) {
		char **uris;
		int    i;

		uris = g_bookmark_file_get_uris (bookmarks, NULL);
		for (i = 0; (uris[i] != NULL) && (i < MAX_HISTORY_LENGTH); i++)
			browser->priv->history = g_list_prepend (browser->priv->history, g_file_new_for_uri (uris[i]));
		browser->priv->history = g_list_reverse (browser->priv->history);

		g_strfreev (uris);
	}

	browser->priv->history_current = browser->priv->history;

	g_free (filename);
	g_object_unref (file);
	g_bookmark_file_free (bookmarks);
}


Paolo Bacchilega's avatar
Paolo Bacchilega committed
941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972
static void
_gth_browser_monitor_entry_points (GthBrowser *browser)
{
	GList *scan;

	for (scan = gth_main_get_all_file_sources (); scan; scan = scan->next) {
		GthFileSource *file_source = scan->data;
		gth_file_source_monitor_entry_points (file_source);
	}
}


static void
_gth_browser_update_entry_point_list (GthBrowser *browser)
{
	GtkWidget *separator1;
	GtkWidget *separator2;
	GtkWidget *menu;
	GList     *entry_points;
	GList     *scan;
	int        position;
	GFile     *root;

	separator1 = gtk_ui_manager_get_widget (browser->priv->ui, "/MenuBar/Go/BeforeEntryPointList");
	separator2 = gtk_ui_manager_get_widget (browser->priv->ui, "/MenuBar/Go/EntryPointList");
	menu = gtk_widget_get_parent (separator1);
	_gtk_container_remove_children (GTK_CONTAINER (menu), separator1, separator2);

	separator1 = separator2;
	separator2 = gtk_ui_manager_get_widget (browser->priv->ui, "/MenuBar/Go/EntryPointListSeparator");
	_gtk_container_remove_children (GTK_CONTAINER (menu), separator1, separator2);

973
	position = 6;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
974 975
	entry_points = gth_main_get_all_entry_points ();
	for (scan = entry_points; scan; scan = scan->next) {
976
		GthFileData *file_data = scan->data;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002

		g_file_info_set_attribute_boolean (file_data->info, "gthumb::entry-point", TRUE);
		g_file_info_set_sort_order (file_data->info, position);
		_gth_browser_add_file_menu_item_full (browser,
						      menu,
						      file_data->file,
						      g_file_info_get_icon (file_data->info),
						      g_file_info_get_display_name (file_data->info),
						      GTH_ACTION_GO_TO,
						      0,
						      position++);
	}
	root = g_file_new_for_uri ("gthumb-vfs:///");
	gth_folder_tree_set_children (GTH_FOLDER_TREE (browser->priv->folder_tree), root, entry_points);

	g_object_unref (root);
	_g_object_list_unref (entry_points);
}


static GthTest *
_gth_browser_get_file_filter (GthBrowser *browser)
{
	GthTest *filterbar_test;
	GthTest *test;

1003 1004 1005
	if (browser->priv->filterbar == NULL)
		return NULL;

Paolo Bacchilega's avatar
Paolo Bacchilega committed
1006 1007 1008 1009 1010 1011 1012 1013 1014
	filterbar_test = gth_filterbar_get_test (GTH_FILTERBAR (browser->priv->filterbar));
	test = gth_main_add_general_filter (filterbar_test);

	_g_object_unref (filterbar_test);

	return test;
}


1015 1016 1017 1018 1019 1020 1021 1022
static gboolean
_gth_browser_get_fast_file_type (GthBrowser *browser,
				 GFile      *file)
{
	gboolean fast_file_type;

	fast_file_type = browser->priv->fast_file_type;

1023 1024 1025 1026 1027
	/* Force the value to FALSE when browsing a cache or a temporary files
	 * directory.
	 * This is mainly used to browse the Firefox cache without changing the
	 * general preference each time, but can be useful for other caches
	 * as well. */
1028 1029
	if (g_file_has_uri_scheme (file, "file")) {
		char  *uri;
1030
		char  *tmp_uri;
1031 1032 1033 1034
		char **uri_v;
		int    i;

		uri = g_file_get_uri (file);
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048

		tmp_uri = g_filename_to_uri (g_get_tmp_dir (), NULL, NULL);
		if (tmp_uri != NULL) {
			gboolean is_tmp_dir;

			is_tmp_dir = (strcmp (uri, tmp_uri) == 0);
			g_free (tmp_uri);

			if (is_tmp_dir) {
				g_free (uri);
				return FALSE;
			}
		}

1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
		uri_v = g_strsplit (uri, "/", -1);
		for (i = 0; uri_v[i] != NULL; i++)
			if (strstr (uri_v[i], "cache")
			    || strstr (uri_v[i], "CACHE")
			    || strstr (uri_v[i], "Cache"))
			{
				fast_file_type = FALSE;
				break;
			}

		 g_strfreev (uri_v);
		 g_free (uri);
	}

	return fast_file_type;
}


Paolo Bacchilega's avatar
Paolo Bacchilega committed
1067
static void
1068
_update_statusbar_list_info (GthBrowser *browser)
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1069
{
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
	GList   *file_list;
	int      n_total;
	goffset  size_total;
	GList   *scan;
	int      n_selected;
	goffset  size_selected;
	GList   *selected;
	char    *size_total_formatted;
	char    *size_selected_formatted;
	char    *text_total;
	char    *text_selected;
	GString *text;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113

	/* total */

	file_list = gth_file_store_get_visibles (gth_browser_get_file_store (browser));
	n_total = 0;
	size_total = 0;
	for (scan = file_list; scan; scan = scan->next) {
		GthFileData *file_data = scan->data;

		n_total++;
		size_total += g_file_info_get_size (file_data->info);
	}
	_g_object_list_unref (file_list);

	/* selected */

	selected = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
	file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), selected);

	n_selected = 0;
	size_selected = 0;
	for (scan = file_list; scan; scan = scan->next) {
		GthFileData *file_data = scan->data;

		n_selected++;
		size_selected += g_file_info_get_size (file_data->info);
	}
	_g_object_list_unref (file_list);
	_gtk_tree_path_list_free (selected);

	/**/

1114 1115
	size_total_formatted = g_format_size (size_total);
	size_selected_formatted = g_format_size (size_selected);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1116
	text_total = g_strdup_printf (g_dngettext (NULL, "%d file (%s)", "%d files (%s)", n_total), n_total, size_total_formatted);
1117
	text_selected = g_strdup_printf (g_dngettext (NULL, "%d file selected (%s)", "%d files selected (%s)", n_selected), n_selected, size_selected_formatted);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1118

1119 1120 1121 1122 1123
	text = g_string_new (text_total);
	if (n_selected > 0) {
		g_string_append (text, STATUSBAR_SEPARATOR);
		g_string_append (text, text_selected);
	}
1124
	if (browser->priv->location_free_space != NULL) {
1125
		g_string_append (text, STATUSBAR_SEPARATOR);
1126
		g_string_append (text, browser->priv->location_free_space);
1127 1128 1129 1130
	}
	gth_statusbar_set_list_info (GTH_STATUSBAR (browser->priv->statusbar), text->str);

	g_string_free (text, TRUE);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1131 1132 1133 1134 1135 1136 1137
	g_free (text_selected);
	g_free (text_total);
	g_free (size_selected_formatted);
	g_free (size_total_formatted);
}


1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150
static void
get_free_space_ready_cb (GthFileSource *file_source,
			 guint64        total_size,
			 guint64        free_space,
			 GError        *error,
			 gpointer       data)
{
	GthBrowser *browser = data;
	char       *free_space_text;

	if (error == NULL) {
		char *free_space_formatted;

1151
		free_space_formatted = g_format_size (free_space);
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170
		free_space_text = g_strdup_printf (_("%s of free space"), free_space_formatted);

		g_free (free_space_formatted);
	}
	else
		free_space_text = NULL;

	g_free (browser->priv->location_free_space);
	browser->priv->location_free_space = NULL;
	if (free_space_text != NULL)
		browser->priv->location_free_space = g_strdup (free_space_text);
	g_free (free_space_text);

	browser->priv->recalc_location_free_space = FALSE;

	_update_statusbar_list_info (browser);
}


1171 1172 1173
static void
_gth_browser_update_statusbar_list_info (GthBrowser *browser)
{
1174 1175 1176 1177
	if (browser->priv->recalc_location_free_space
	    && (browser->priv->location_source != NULL)
	    && (browser->priv->location != NULL))
	{
1178 1179 1180 1181
		gth_file_source_get_free_space (browser->priv->location_source,
						browser->priv->location->file,
						get_free_space_ready_cb,
						browser);
1182 1183 1184 1185 1186 1187 1188 1189
	}
	else {
		if ((browser->priv->location_source == NULL)
		    || (browser->priv->location == NULL))
		{
			g_free (browser->priv->location_free_space);
			browser->priv->location_free_space = NULL;
		}
1190
		_update_statusbar_list_info (browser);
1191
	}
1192 1193 1194
}


Paolo Bacchilega's avatar
Paolo Bacchilega committed
1195 1196
typedef struct {
	GthBrowser    *browser;
1197
	GthFileData   *requested_folder;
1198
	GFile         *requested_folder_parent;
1199
	GFile         *file_to_select;
1200 1201
	GList         *selected;
	double         vscroll;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1202
	GthAction      action;
1203
	gboolean       automatic;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214
	GList         *list;
	GList         *current;
	GFile         *entry_point;
	GthFileSource *file_source;
	GCancellable  *cancellable;
} LoadData;


static LoadData *
load_data_new (GthBrowser *browser,
	       GFile      *location,
1215
	       GFile      *file_to_select,
1216 1217
	       GList      *selected,
	       double      vscroll,
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1218
	       GthAction   action,
1219
	       gboolean    automatic,
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1220 1221 1222 1223 1224 1225 1226
	       GFile      *entry_point)
{
	LoadData *load_data;
	GFile    *file;

	load_data = g_new0 (LoadData, 1);
	load_data->browser = browser;
1227 1228
	load_data->requested_folder = gth_file_data_new (location, NULL);
	load_data->requested_folder_parent = g_file_get_parent (load_data->requested_folder->file);
1229 1230
	if (file_to_select != NULL)
		load_data->file_to_select = g_file_dup (file_to_select);
1231
	else if (browser->priv->current_file != NULL)
1232
		load_data->file_to_select = g_file_dup (browser->priv->current_file->file);
1233 1234
	load_data->selected = g_list_copy_deep (selected, (GCopyFunc) gtk_tree_path_copy, NULL);
	load_data->vscroll = vscroll;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1235
	load_data->action = action;
1236
	load_data->automatic = automatic;
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1237 1238 1239 1240 1241 1242
	load_data->cancellable = g_cancellable_new ();

	if (entry_point == NULL)
		return load_data;

	load_data->entry_point = g_object_ref (entry_point);
1243
	load_data->file_source = gth_main_get_file_source (load_data->requested_folder->file);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1244

1245
	file = g_object_ref (load_data->requested_folder->file);
Paolo Bacchilega's avatar
Paolo Bacchilega committed
1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269
	load_data