Beispiel #1
0
static void
file_manager_update_ui (BrowserData *data,
			GthBrowser  *browser)
{
	if (GTH_IS_FILE_SOURCE_VFS (gth_browser_get_location_source (browser))) {
		if (data->vfs_merge_id == 0) {
			GError *local_error = NULL;

			data->vfs_merge_id = gtk_ui_manager_add_ui_from_string (gth_browser_get_ui_manager (browser), vfs_ui_info, -1, &local_error);
			if (data->vfs_merge_id == 0) {
				g_warning ("building ui failed: %s", local_error->message);
				g_error_free (local_error);
			}
		}
	}
	else if (data->vfs_merge_id != 0) {
			gtk_ui_manager_remove_ui (gth_browser_get_ui_manager (browser), data->vfs_merge_id);
			data->vfs_merge_id = 0;
	}

	if (gth_window_get_current_page (GTH_WINDOW (browser)) == GTH_BROWSER_PAGE_BROWSER) {
		if (data->browser_merge_id == 0) {
			GError *local_error = NULL;

			data->browser_merge_id = gtk_ui_manager_add_ui_from_string (gth_browser_get_ui_manager (browser), browser_ui_info, -1, &local_error);
			if (data->browser_merge_id == 0) {
				g_warning ("building ui failed: %s", local_error->message);
				g_error_free (local_error);
			}
		}
	}
	else if (data->browser_merge_id != 0) {
		gtk_ui_manager_remove_ui (gth_browser_get_ui_manager (browser), data->browser_merge_id);
		data->browser_merge_id = 0;
	}

	if (GTH_IS_FILE_SOURCE_VFS (gth_browser_get_location_source (browser))
	    && (gth_window_get_current_page (GTH_WINDOW (browser)) == GTH_BROWSER_PAGE_BROWSER))
	{
		if (data->browser_vfs_merge_id == 0) {
			GError *local_error = NULL;

			data->browser_vfs_merge_id = gtk_ui_manager_add_ui_from_string (gth_browser_get_ui_manager (browser), browser_vfs_ui_info, -1, &local_error);
			if (data->browser_vfs_merge_id == 0) {
				g_warning ("building ui failed: %s", local_error->message);
				g_error_free (local_error);
			}
		}
	}
	else if (data->browser_vfs_merge_id != 0) {
		gtk_ui_manager_remove_ui (gth_browser_get_ui_manager (browser), data->browser_vfs_merge_id);
		data->browser_vfs_merge_id = 0;
	}
}
Beispiel #2
0
void
catalogs__gth_browser_update_extra_widget_cb (GthBrowser *browser)
{
	BrowserData *data;
	GthFileData *location_data;

	data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);

	location_data = gth_browser_get_location_data (browser);
	if (GTH_IS_FILE_SOURCE_CATALOGS (gth_browser_get_location_source (browser))
	    && ! _g_content_type_is_a (g_file_info_get_content_type (location_data->info), "gthumb/library"))
	{
		if (data->properties_button == NULL) {
			data->properties_button = gtk_button_new ();
			gtk_container_add (GTK_CONTAINER (data->properties_button), gtk_image_new_from_icon_name ("document-properties-symbolic", GTK_ICON_SIZE_MENU));
			g_object_add_weak_pointer (G_OBJECT (data->properties_button), (gpointer *)&data->properties_button);
			gtk_button_set_relief (GTK_BUTTON (data->properties_button), GTK_RELIEF_NONE);
			gtk_widget_set_tooltip_text (data->properties_button, _("Catalog Properties"));
			gtk_widget_show_all (data->properties_button);
			gtk_box_pack_start (GTK_BOX (gth_location_bar_get_action_area (GTH_LOCATION_BAR (gth_browser_get_location_bar (browser)))),
					    data->properties_button,
					    FALSE,
					    FALSE,
					    0);
			g_signal_connect (data->properties_button,
					  "clicked",
					  G_CALLBACK (properties_button_clicked_cb),
					  browser);
		}
	}
	else if (GTH_IS_FILE_SOURCE_VFS (gth_browser_get_location_source (browser))) {
		if (data->organize_button == NULL) {
			data->organize_button = gtk_button_new ();
			gtk_container_add (GTK_CONTAINER (data->organize_button), gtk_label_new (_("Organize")));
			gtk_widget_set_tooltip_text (data->organize_button, _("Automatically organize files by date"));
			g_object_add_weak_pointer (G_OBJECT (data->organize_button), (gpointer *)&data->organize_button);
			gtk_button_set_relief (GTK_BUTTON (data->organize_button), GTK_RELIEF_NONE);
			gtk_widget_show_all (data->organize_button);
			gtk_box_pack_start (GTK_BOX (gth_location_bar_get_action_area (GTH_LOCATION_BAR (gth_browser_get_location_bar (browser)))),
					    data->organize_button,
					    FALSE,
					    FALSE,
					    0);
			g_signal_connect (data->organize_button,
					  "clicked",
					  G_CALLBACK (organize_button_clicked_cb),
					  browser);
		}
	}
}
Beispiel #3
0
static gboolean
gth_file_list_drag_motion (GtkWidget      *file_view,
			   GdkDragContext *context,
			   gint            x,
			   gint            y,
			   guint           time,
			   gpointer        extra_data)
{
	GthBrowser  *browser = extra_data;
	BrowserData *data;
	GthFileData *location_data;

	data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
	data->drop_pos = -1;

	if ((gtk_drag_get_source_widget (context) == file_view) && ! gth_file_source_is_reorderable (gth_browser_get_location_source (browser))) {
		gdk_drag_status (context, 0, time);
		return FALSE;
	}

	location_data = gth_browser_get_location_data (browser);
	if (! g_file_info_get_attribute_boolean (location_data->info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) {
		gdk_drag_status (context, 0, time);
		return FALSE;
	}

	if (gth_file_source_is_reorderable (gth_browser_get_location_source (browser))) {
		GtkAllocation allocation;

		if (gtk_drag_get_source_widget (context) == file_view)
			gdk_drag_status (context, GDK_ACTION_MOVE, time);
		else
			gdk_drag_status (context, GDK_ACTION_COPY, time);
		gth_file_view_set_drag_dest_pos (GTH_FILE_VIEW (file_view), context, x, y, time, &data->drop_pos);

		gtk_widget_get_allocation (file_view, &allocation);

		if (y < 10)
			data->scroll_diff = - (10 - y);
		else if (y > allocation.height - 10)
			data->scroll_diff = (10 - (allocation.height - y));
		else
			data->scroll_diff = 0;

		if (data->scroll_diff != 0) {
			if (data->scroll_event == 0)
				data->scroll_event = gdk_threads_add_timeout (SCROLL_TIMEOUT, drag_motion_autoscroll_cb, browser);
		}
		else if (data->scroll_event != 0) {
			g_source_remove (data->scroll_event);
			data->scroll_event = 0;
		}
	}
	else if (gdk_drag_context_get_suggested_action (context) == GDK_ACTION_ASK)
		gdk_drag_status (context, GDK_ACTION_ASK, time);
	else
		gdk_drag_status (context, GDK_ACTION_COPY, time);

	return TRUE;
}
Beispiel #4
0
void
gth_browser_activate_import_folder (GSimpleAction	*action,
				    GVariant		*parameter,
				    gpointer		 user_data)
{
	GthBrowser *browser = GTH_BROWSER (user_data);
	GtkWidget  *chooser;
	GFile      *folder;

	chooser = gtk_file_chooser_dialog_new (_("Choose a folder"),
					       GTK_WINDOW (browser),
					       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
					       _GTK_LABEL_CANCEL, GTK_RESPONSE_CANCEL,
					       _("Import"), GTK_RESPONSE_OK,
					       NULL);
	_gtk_dialog_add_class_to_response (GTK_DIALOG (chooser), GTK_RESPONSE_OK, GTK_STYLE_CLASS_SUGGESTED_ACTION);
	gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), FALSE);

	folder = NULL;
	if (GTH_IS_FILE_SOURCE_VFS (gth_browser_get_location_source (browser)))
		folder = _g_object_ref (gth_browser_get_location (browser));
	if (folder == NULL)
		folder = g_file_new_for_uri (get_home_uri ());
	gtk_file_chooser_set_file (GTK_FILE_CHOOSER (chooser), folder, NULL);

	g_signal_connect (chooser,
			  "response",
			  G_CALLBACK (folder_chooser_response_cb),
			  browser);
	gtk_widget_show (chooser);

	_g_object_unref (folder);
}
Beispiel #5
0
void
catalogs__gth_browser_load_location_after_cb (GthBrowser   *browser,
					      GthFileData  *location_data,
					      const GError *error)
{
	BrowserData *data;

	if ((location_data == NULL) || (error != NULL))
		return;

	data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);

	if (GTH_IS_FILE_SOURCE_CATALOGS (gth_browser_get_location_source (browser))) {
		if (data->vfs_open_actions_merge_id == 0)
			data->vfs_open_actions_merge_id =
					gth_menu_manager_append_entries (gth_browser_get_menu_manager (browser, GTH_BROWSER_MENU_MANAGER_FILE_LIST_OPEN_ACTIONS),
									 vfs_open_actions_entries,
									 G_N_ELEMENTS (vfs_open_actions_entries));
		if (data->vfs_other_actions_merge_id == 0)
			data->vfs_other_actions_merge_id =
					gth_menu_manager_append_entries (gth_browser_get_menu_manager (browser, GTH_BROWSER_MENU_MANAGER_FILE_LIST_OTHER_ACTIONS),
									 vfs_other_actions_entries,
									 G_N_ELEMENTS (vfs_other_actions_entries));
	}
	else {
		gth_menu_manager_remove_entries (gth_browser_get_menu_manager (browser, GTH_BROWSER_MENU_MANAGER_FILE_LIST_OPEN_ACTIONS), data->vfs_open_actions_merge_id);
		data->vfs_open_actions_merge_id = 0;

		gth_menu_manager_remove_entries (gth_browser_get_menu_manager (browser, GTH_BROWSER_MENU_MANAGER_FILE_LIST_OTHER_ACTIONS), data->vfs_other_actions_merge_id);
		data->vfs_other_actions_merge_id = 0;
	}
}
Beispiel #6
0
static gboolean
gth_file_list_drag_drop (GtkWidget      *widget,
			 GdkDragContext *context,
			 gint            x,
			 gint            y,
			 guint           time,
			 gpointer        user_data)
{
	GthBrowser *browser = user_data;
	int         filename_len;
	char       *filename;

	g_signal_stop_emission_by_name (widget, "drag-drop");

	if (gdk_property_get (gdk_drag_context_get_source_window (context),
			      XDND_ACTION_DIRECT_SAVE_ATOM,
			      TEXT_PLAIN_ATOM,
			      0,
			      1024,
			      FALSE,
			      NULL,
			      NULL,
			      &filename_len,
			      (guchar **) &filename)
	    && GTH_IS_FILE_SOURCE_VFS (gth_browser_get_location_source (browser)))
	{
		GFile *file;
		char  *uri;

		filename = g_realloc (filename, filename_len + 1);
		filename[filename_len] = '\0';

		file = _g_file_append_path (gth_browser_get_location (browser), filename);
		uri = g_file_get_uri (file);
		gdk_property_change (gdk_drag_context_get_source_window (context),
				     XDND_ACTION_DIRECT_SAVE_ATOM,
				     TEXT_PLAIN_ATOM,
				     8,
				     GDK_PROP_MODE_REPLACE,
				     (const guchar *) uri,
				     strlen (uri));

		g_free (uri);
		g_object_unref (file);
		g_free (filename);

		gtk_drag_get_data (widget,
		                   context,
		                   XDND_ACTION_DIRECT_SAVE_ATOM,
		                   time);
	}
	else
		gtk_drag_get_data (widget,
				   context,
				   URI_LIST_ATOM,
				   time);

	return TRUE;
}
Beispiel #7
0
void
fm__gth_browser_load_location_after_cb (GthBrowser   *browser,
					GthFileData  *location_data,
					const GError *error)
{
	BrowserData *data;
	GtkWidget   *file_view;

	if ((location_data == NULL) || (error != NULL))
		return;

	data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
	file_manager_update_ui (data, browser);

	if (! g_file_info_get_attribute_boolean (location_data->info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) {
		file_view = gth_file_list_get_view (GTH_FILE_LIST (gth_browser_get_file_list (browser)));
		gth_file_view_unset_drag_dest (GTH_FILE_VIEW (file_view));
		file_view = gth_file_list_get_empty_view (GTH_FILE_LIST (gth_browser_get_file_list (browser)));
		gtk_drag_dest_unset (file_view);
	}
	else if (gth_file_source_is_reorderable (gth_browser_get_location_source (browser))) {
		file_view = gth_file_list_get_view (GTH_FILE_LIST (gth_browser_get_file_list (browser)));
		gth_file_view_enable_drag_dest (GTH_FILE_VIEW (file_view),
						reorderable_drag_dest_targets,
						G_N_ELEMENTS (reorderable_drag_dest_targets),
						GDK_ACTION_COPY | GDK_ACTION_MOVE);
		file_view = gth_file_list_get_empty_view (GTH_FILE_LIST (gth_browser_get_file_list (browser)));
		gtk_drag_dest_set (file_view,
				   0,
				   reorderable_drag_dest_targets,
				   G_N_ELEMENTS (reorderable_drag_dest_targets),
				   GDK_ACTION_COPY | GDK_ACTION_MOVE);
	}
	else {
		file_view = gth_file_list_get_view (GTH_FILE_LIST (gth_browser_get_file_list (browser)));
		gth_file_view_enable_drag_dest (GTH_FILE_VIEW (file_view),
						non_reorderable_drag_dest_targets,
						G_N_ELEMENTS (non_reorderable_drag_dest_targets),
						GDK_ACTION_COPY);
		file_view = gth_file_list_get_empty_view (GTH_FILE_LIST (gth_browser_get_file_list (browser)));
		gtk_drag_dest_set (file_view,
				   0,
				   non_reorderable_drag_dest_targets,
				   G_N_ELEMENTS (non_reorderable_drag_dest_targets),
				   GDK_ACTION_COPY);
	}
}
Beispiel #8
0
void
catalogs__gth_browser_file_renamed_cb (GthBrowser *browser,
				       GFile      *file,
				       GFile      *new_file)
{
	GthFileStore *file_store;
	BrowserData  *data;
	GFile        *location;
	GList        *scan;
	RenameData   *rename_data;

	if (! GTH_IS_FILE_SOURCE_CATALOGS (gth_browser_get_location_source (browser)))
		return;

	file_store = gth_browser_get_file_store (browser);
	if (! gth_file_store_find (file_store, file, NULL))
		return;

	location = gth_browser_get_location (browser);
	if (location == NULL)
		return;

	data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);

	rename_data = NULL;
	for (scan = data->rename_data_list; scan; scan = scan->next) {
		RenameData *rename_data_scan = scan->data;
		if (g_file_equal (rename_data_scan->location, location)) {
			rename_data = rename_data_scan;
			break;
		}
	}

	if (rename_data == NULL) {
		rename_data = rename_data_new (location);
		data->rename_data_list = g_list_prepend (data->rename_data_list, rename_data);
	}

	rename_data->files = g_list_prepend (rename_data->files, g_file_dup (file));
	rename_data->new_files = g_list_prepend (rename_data->new_files, g_file_dup (new_file));

	if (data->update_renamed_files_id != 0)
		g_source_remove (data->update_renamed_files_id);
	data->update_renamed_files_id = g_timeout_add (UPDATE_RENAMED_FILES_DELAY,
						       process_rename_data_list,
						       data);
}
Beispiel #9
0
void
fm__gth_browser_update_sensitivity_cb (GthBrowser *browser)
{
	BrowserData   *data;
	GthFileSource *file_source;
	int            n_selected;
	GthFileData   *location_data;
	gboolean       sensitive;
	GthFileData   *folder;

	data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
	g_return_if_fail (data != NULL);

	file_source = gth_browser_get_location_source (browser);
	n_selected = gth_file_selection_get_n_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));

	location_data = gth_browser_get_location_data (browser);
	sensitive = (n_selected > 0) && (file_source != NULL) && (location_data != NULL) && gth_file_source_can_cut (file_source, location_data->file);
	set_action_sensitive (data, "Edit_CutFiles", sensitive);

	sensitive = (n_selected > 0) && (file_source != NULL);
	set_action_sensitive (data, "Edit_CopyFiles", sensitive);
	set_action_sensitive (data, "Edit_Trash", sensitive);
	set_action_sensitive (data, "Edit_Delete", sensitive);
	set_action_sensitive (data, "Edit_Duplicate", sensitive);
	set_action_sensitive (data, "Tool_MoveToFolder", sensitive);
	set_action_sensitive (data, "Tool_CopyToFolder", sensitive);

	folder = gth_browser_get_folder_popup_file_data (browser);
	set_action_sensitive (data, "Folder_Create", (folder != NULL) && g_file_info_get_attribute_boolean (folder->info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE));
	set_action_sensitive (data, "Folder_Rename", (folder != NULL) && g_file_info_get_attribute_boolean (folder->info, G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME));
	set_action_sensitive (data, "Folder_Delete", (folder != NULL) && g_file_info_get_attribute_boolean (folder->info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE));
	set_action_sensitive (data, "Folder_Trash", (folder != NULL) && g_file_info_get_attribute_boolean (folder->info, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH));
	set_action_sensitive (data, "Folder_Cut", (folder != NULL) && g_file_info_get_attribute_boolean (folder->info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE));

	/*
	folder = gth_browser_get_location_data (browser);
	set_action_sensitive (data, "File_NewFolder", (folder != NULL) && g_file_info_get_attribute_boolean (folder->info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE));
	*/

	_g_object_unref (folder);

	_gth_browser_update_paste_command_sensitivity (browser, NULL);
}
Beispiel #10
0
static void
gth_file_list_drag_data_received (GtkWidget        *file_view,
				  GdkDragContext   *context,
				  int               x,
				  int               y,
				  GtkSelectionData *selection_data,
				  guint             info,
				  guint             time,
				  gpointer          user_data)
{
	GthBrowser     *browser = user_data;
	gboolean        success = FALSE;
	char          **uris;
	GList          *selected_files;
	GdkDragAction   action;

	g_signal_stop_emission_by_name (file_view, "drag-data-received");

	action = gdk_drag_context_get_suggested_action (context);
	if (action == GDK_ACTION_COPY || action == GDK_ACTION_MOVE) {
		success = TRUE;
	}

	if (action == GDK_ACTION_ASK) {
		GdkDragAction actions =
			_gtk_menu_ask_drag_drop_action (file_view,
							gdk_drag_context_get_actions (context),
							time);
		gdk_drag_status (context, actions, time);
		success = gdk_drag_context_get_selected_action (context) != 0;
	}

	if (gtk_selection_data_get_data_type (selection_data) == XDND_ACTION_DIRECT_SAVE_ATOM) {
		const guchar *data;
		int           format;
		int           length;

		data = gtk_selection_data_get_data (selection_data);
		format = gtk_selection_data_get_format (selection_data);
		length = gtk_selection_data_get_length (selection_data);

		if ((format == 8) && (length == 1) && (data[0] == 'S')) {
			success = TRUE;
		}
		else {
			gdk_property_change (gdk_drag_context_get_dest_window (context),
					     XDND_ACTION_DIRECT_SAVE_ATOM,
					     TEXT_PLAIN_ATOM,
					     8,
					     GDK_PROP_MODE_REPLACE,
					     (const guchar *) "",
					     0);
			success = FALSE;
		}

		gtk_drag_finish (context, success, FALSE, time);
		return;
	}

	gtk_drag_finish (context, success, FALSE, time);
	if (! success)
		return;

	uris = gtk_selection_data_get_uris (selection_data);
	selected_files = _g_file_list_new_from_uriv (uris);
	if (selected_files != NULL) {
		if (gtk_drag_get_source_widget (context) == file_view) {
			GList       *file_data_list;
			GList       *visible_files;
			BrowserData *data;
			GthTask     *task;

			file_data_list = gth_file_store_get_visibles (gth_browser_get_file_store (browser));
			visible_files = gth_file_data_list_to_file_list (file_data_list);

			data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
			task = gth_reorder_task_new (gth_browser_get_location_source (browser),
						     gth_browser_get_location_data (browser),
						     visible_files,
						     selected_files,
						     data->drop_pos);
			gth_browser_exec_task (browser, task, FALSE);

			g_object_unref (task);
			_g_object_list_unref (visible_files);
			_g_object_list_unref (file_data_list);
		}
		else {
			GthFileSource *file_source;
			gboolean       cancel = FALSE;
			gboolean       move;

			file_source = gth_browser_get_location_source (browser);
			move = gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE;
			if (move && ! gth_file_source_can_cut (file_source, (GFile *) selected_files->data)) {
				GtkWidget *dialog;
				int        response;

				dialog = _gtk_message_dialog_new (GTK_WINDOW (browser),
								  GTK_DIALOG_MODAL,
								  GTK_STOCK_DIALOG_QUESTION,
								  _("Could not move the files"),
								  _("Files cannot be moved to the current location, as alternative you can choose to copy them."),
								  GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
								  GTK_STOCK_COPY, GTK_RESPONSE_OK,
								  NULL);
				response = gtk_dialog_run (GTK_DIALOG (dialog));
				gtk_widget_destroy (dialog);

				if (response == GTK_RESPONSE_CANCEL)
					cancel = TRUE;

				move = FALSE;
			}

			if (! cancel) {
				GthFileSource *location_source;
				BrowserData   *data;
				GthTask       *task;

				location_source = gth_main_get_file_source (gth_browser_get_location (browser));
				data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
				task = gth_copy_task_new (location_source,
							  gth_browser_get_location_data (browser),
							  move,
							  selected_files,
							  data->drop_pos);
				gth_browser_exec_task (browser, task, FALSE);

				g_object_unref (task);
				g_object_unref (location_source);
			}
		}
	}

	_g_object_list_unref (selected_files);
	g_strfreev (uris);
}
Beispiel #11
0
gpointer
fm__gth_browser_file_list_key_press_cb (GthBrowser  *browser,
					GdkEventKey *event)
{
	gpointer  result = NULL;
	guint     modifiers;
	GList    *items;
	GList    *file_data_list;
	GList    *file_list;

	modifiers = gtk_accelerator_get_default_mod_mask ();

	switch (event->keyval) {
	case GDK_KEY_g:
		if ((event->state & modifiers) == 0) {
			items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
			file_data_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
			file_list = gth_file_data_list_to_file_list (file_data_list);
			_g_launch_command (GTK_WIDGET (browser), "gimp %U", "Gimp", file_list);

			_g_object_list_unref (file_list);
			_g_object_list_unref (file_data_list);
			_gtk_tree_path_list_free (items);
			result = GINT_TO_POINTER (1);
		}
		break;

	case GDK_KEY_Delete:
		if (((event->state & modifiers) == 0)
		    || ((event->state & modifiers) == GDK_SHIFT_MASK)
		    || ((event->state & modifiers) == GDK_CONTROL_MASK))
		{
			GthFileSource *source;
			GthFileData   *location;

			if ((event->state & modifiers) == 0) {
				/* Removes the files from the current location,
				 * for example: when viewing a catalog removes
				 * the files from the catalog; when viewing a
				 * folder removes the files from the folder. */
				source = gth_browser_get_location_source (browser);
				location = gth_browser_get_location_data (browser);
			}
			else {
				/* When a key modifier is active, use the VFS
				 * file source to delete the files from the
				 * disk. */
				source = gth_main_get_file_source_for_uri ("file:///");
				location = NULL;
			}

			if (source == NULL)
				return result;

			items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
			if (items == NULL)
				return result;

			file_data_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
			gth_file_source_remove (source,
						location,
						file_data_list,
						(event->state & modifiers) == GDK_SHIFT_MASK,
						GTK_WINDOW (browser));
			result = GINT_TO_POINTER (1);

			_g_object_list_unref (file_data_list);
			_gtk_tree_path_list_free (items);
		}
		break;
	}

	return result;
}
Beispiel #12
0
void
catalogs__gth_browser_update_sensitivity_cb (GthBrowser *browser)
{
	BrowserData *data;
	int          n_selected;

	data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
	g_return_if_fail (data != NULL);

	n_selected = gth_file_selection_get_n_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));

	gth_window_enable_action (GTH_WINDOW (browser), "add-to-catalog", n_selected > 0);
	gth_window_enable_action (GTH_WINDOW (browser), "remove-from-catalog", (n_selected > 0) && GTH_IS_FILE_SOURCE_CATALOGS (gth_browser_get_location_source (browser)));
	gth_window_enable_action (GTH_WINDOW (browser), "go-to-container-from-catalog", n_selected == 1);
}
Beispiel #13
0
static void
dlg_photo_importer (GthBrowser            *browser,
		    GFile                 *source,
		    DlgImporterSourceType  selector_type)
{
	DialogData       *data;
	GtkCellRenderer  *renderer;
	GthFileDataSort  *sort_type;
	GList            *tests, *scan;
	char             *general_filter;
	int               i, active_filter;
	int               i_general;

	if (gth_browser_get_dialog (browser, "photo_importer") != NULL) {
		gtk_window_present (GTK_WINDOW (gth_browser_get_dialog (browser, "photo_importer")));
		return;
	}

	data = g_new0 (DialogData, 1);
	data->browser = browser;
	data->builder = gtk_builder_new_from_resource ("/org/gnome/gThumb/photo_importer/data/ui/photo-importer.ui");
	data->settings = g_settings_new (GTHUMB_PHOTO_IMPORTER_SCHEMA);
	data->selector_type = selector_type;
	data->source = _g_object_ref (source);
	data->cancellable = g_cancellable_new ();
	data->vfs_source = g_object_new (GTH_TYPE_FILE_SOURCE_VFS, NULL);
	gth_file_source_monitor_entry_points (GTH_FILE_SOURCE (data->vfs_source));

	/* Get the widgets. */

	data->dialog = _gtk_builder_get_widget (data->builder, "photo_importer_dialog");
	_gtk_window_resize_to_fit_screen_height (data->dialog, 580);
	gth_browser_set_dialog (browser, "photo_importer", data->dialog);
	g_object_set_data (G_OBJECT (data->dialog), "dialog_data", data);

	if (data->selector_type == DLG_IMPORTER_SOURCE_TYPE_DEVICE) {
		gtk_window_set_title (GTK_WINDOW (data->dialog), _("Import from Removable Device"));

		data->device_list_store = gtk_list_store_new (SOURCE_LIST_COLUMNS, G_TYPE_OBJECT, G_TYPE_ICON, G_TYPE_STRING);
		data->device_chooser = gtk_combo_box_new_with_model (GTK_TREE_MODEL (data->device_list_store));
		gtk_widget_show (data->device_chooser);
		gtk_box_pack_start (GTK_BOX (GET_WIDGET ("source_box")), data->device_chooser, TRUE, TRUE, 0);
		gtk_label_set_mnemonic_widget (GTK_LABEL (GET_WIDGET ("source_label")), data->device_chooser);

		renderer = gtk_cell_renderer_pixbuf_new ();
		gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (data->device_chooser), renderer, FALSE);
		gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (data->device_chooser),
						renderer,
						"gicon", SOURCE_LIST_COLUMN_ICON,
						NULL);

		renderer = gtk_cell_renderer_text_new ();
		gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (data->device_chooser), renderer, TRUE);
		gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (data->device_chooser),
						renderer,
						"text", SOURCE_LIST_COLUMN_NAME,
						NULL);

		g_object_unref (data->device_list_store);
	}
	else {
		if (data->source == NULL) {
			if (GTH_IS_FILE_SOURCE_VFS (gth_browser_get_location_source (browser)))
				data->source = _g_object_ref (gth_browser_get_location (browser));
			if (data->source == NULL)
				data->source = g_file_new_for_uri (get_home_uri ());
		}

		gtk_window_set_title (GTK_WINDOW (data->dialog), _("Import from Folder"));

		data->folder_chooser = gtk_file_chooser_button_new (_("Choose a folder"), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
		gtk_label_set_mnemonic_widget (GTK_LABEL (GET_WIDGET ("source_label")), data->folder_chooser);
		gtk_file_chooser_set_file (GTK_FILE_CHOOSER (data->folder_chooser), data->source, NULL);
		gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (data->folder_chooser), FALSE);
		gtk_widget_show (data->folder_chooser);
		gtk_box_pack_start (GTK_BOX (GET_WIDGET ("source_box")), data->folder_chooser, TRUE, TRUE, 0);
	}

	data->file_list = gth_file_list_new (gth_grid_view_new (), GTH_FILE_LIST_MODE_NORMAL, FALSE);
	sort_type = gth_main_get_sort_type ("file::mtime");
	gth_file_list_set_sort_func (GTH_FILE_LIST (data->file_list), sort_type->cmp_func, FALSE);
	gth_file_list_enable_thumbs (GTH_FILE_LIST (data->file_list), TRUE);
	gth_file_list_set_ignore_hidden (GTH_FILE_LIST (data->file_list), TRUE);
	gth_file_list_set_thumb_size (GTH_FILE_LIST (data->file_list), 128);
	gth_file_list_set_caption (GTH_FILE_LIST (data->file_list), "standard::display-name,gth::file::display-size");

	gtk_widget_show (data->file_list);
	gtk_box_pack_start (GTK_BOX (GET_WIDGET ("filelist_box")), data->file_list, TRUE, TRUE, 0);

	tests = gth_main_get_registered_objects_id (GTH_TYPE_TEST);
	general_filter = "file::type::is_media"; /* default value */
	active_filter = 0;

	data->filter_combobox = gtk_combo_box_text_new ();
	for (i = 0, i_general = -1, scan = tests; scan; scan = scan->next, i++) {
		const char *registered_test_id = scan->data;
		GthTest    *test;

		if (strncmp (registered_test_id, "file::type::", 12) != 0)
			continue;

		i_general += 1;
		test = gth_main_get_registered_object (GTH_TYPE_TEST, registered_test_id);
		if (strcmp (registered_test_id, general_filter) == 0) {
			active_filter = i_general;
			gth_file_list_set_filter (GTH_FILE_LIST (data->file_list), test);
		}

		data->general_tests = g_list_prepend (data->general_tests, g_strdup (gth_test_get_id (test)));
		gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (data->filter_combobox),
						gth_test_get_display_name (test));
		g_object_unref (test);
	}
	data->general_tests = g_list_reverse (data->general_tests);

	gtk_combo_box_set_active (GTK_COMBO_BOX (data->filter_combobox), active_filter);
	gtk_widget_show (data->filter_combobox);
	gtk_container_add (GTK_CONTAINER (GET_WIDGET ("filter_box")), data->filter_combobox);

	gtk_label_set_mnemonic_widget (GTK_LABEL (GET_WIDGET ("filter_label")), data->filter_combobox);
	gtk_label_set_use_underline (GTK_LABEL (GET_WIDGET ("filter_label")), TRUE);

	_g_string_list_free (tests);

	data->tags_entry = gth_tags_entry_new (GTH_TAGS_ENTRY_MODE_POPUP);
	gtk_widget_show (data->tags_entry);
	gtk_box_pack_start (GTK_BOX (GET_WIDGET ("tags_entry_box")), data->tags_entry, TRUE, TRUE, 0);
	gtk_label_set_mnemonic_widget (GTK_LABEL (GET_WIDGET ("tags_label")), data->tags_entry);

	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("delete_checkbutton")),
				      g_settings_get_boolean (data->settings, PREF_PHOTO_IMPORTER_DELETE_FROM_DEVICE));

	data->preferences_dialog = gth_import_preferences_dialog_new ();
	gtk_window_set_transient_for (GTK_WINDOW (data->preferences_dialog), GTK_WINDOW (data->dialog));

	gtk_box_pack_start (GTK_BOX (GET_WIDGET ("destination_button_box")),
			    gth_import_destination_button_new (GTH_IMPORT_PREFERENCES_DIALOG (data->preferences_dialog)),
			    TRUE,
			    TRUE,
			    0);
	gtk_widget_show_all (GET_WIDGET ("destination_button_box"));

	/* Set the signals handlers. */

	g_signal_connect (G_OBJECT (data->dialog),
			  "delete-event",
			  G_CALLBACK (dialog_delete_event_cb),
			  data);
	g_signal_connect (GET_WIDGET ("ok_button"),
			  "clicked",
			  G_CALLBACK (ok_clicked_cb),
			  data);
	g_signal_connect (GET_WIDGET ("cancel_button"),
			  "clicked",
			  G_CALLBACK (close_dialog),
			  data);
        if (data->selector_type == DLG_IMPORTER_SOURCE_TYPE_DEVICE)
		g_signal_connect (data->device_chooser,
				  "changed",
				  G_CALLBACK (device_chooser_changed_cb),
				  data);
        else
		g_signal_connect (data->folder_chooser,
				  "selection-changed",
				  G_CALLBACK (folder_chooser_file_set_cb),
				  data);
	g_signal_connect (data->filter_combobox,
			  "changed",
			  G_CALLBACK (filter_combobox_changed_cb),
			  data);
	g_signal_connect (gth_file_view_get_model (GTH_FILE_VIEW (gth_file_list_get_view (GTH_FILE_LIST (data->file_list)))),
			  "visibility_changed",
			  G_CALLBACK (file_store_changed_cb),
			  data);
	g_signal_connect (gth_file_list_get_view (GTH_FILE_LIST (data->file_list)),
			  "file-selection-changed",
			  G_CALLBACK (file_view_selection_changed_cb),
			  data);
	data->entry_points_changed_id = g_signal_connect (gth_main_get_default_monitor (),
							  "entry-points-changed",
							  G_CALLBACK (entry_points_changed_cb),
							  data);
	g_signal_connect_after (GET_WIDGET ("event_entry"),
				"changed",
				G_CALLBACK (event_entry_changed_cb),
				data);

	/* Run dialog. */

	gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (browser));
	gtk_window_set_modal (GTK_WINDOW (data->dialog), FALSE);
	gtk_widget_show (data->dialog);

	gth_import_preferences_dialog_set_event (GTH_IMPORT_PREFERENCES_DIALOG (data->preferences_dialog),
						 gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("event_entry"))));

	if (data->selector_type == DLG_IMPORTER_SOURCE_TYPE_DEVICE)
		update_device_source_list (data);
	else
		load_file_list (data);
}
Beispiel #14
0
void
dlg_resize_images (GthBrowser *browser,
		   GList      *file_list)
{
	DialogData  *data;
	GArray      *savers;
	GthFileData *first_file_data;
	GthUnit      unit;
	int          default_width_in_pixels;
	int          default_height_in_pixels;

	if (gth_browser_get_dialog (browser, "resize_images") != NULL) {
		gtk_window_present (GTK_WINDOW (gth_browser_get_dialog (browser, "resize_images")));
		return;
	}

	data = g_new0 (DialogData, 1);
	data->browser = browser;
	data->builder = _gtk_builder_new_from_file ("resize-images.ui", "resize_images");
	data->settings = g_settings_new (GTHUMB_RESIZE_IMAGES_SCHEMA);
	data->file_list = gth_file_data_list_dup (file_list);
	data->use_destination = TRUE;

	/* Get the widgets. */

	data->dialog = _gtk_builder_get_widget (data->builder, "resize_images_dialog");
	gth_browser_set_dialog (browser, "resize_images", data->dialog);
	g_object_set_data (G_OBJECT (data->dialog), "dialog_data", data);

	/* Set widgets data. */

	first_file_data = (GthFileData *) data->file_list->data;
	_gtk_file_chooser_set_file_parent (GTK_FILE_CHOOSER (GET_WIDGET ("destination_filechooserbutton")),
				   	   first_file_data->file,
				   	   NULL);

	unit = g_settings_get_enum (data->settings, PREF_RESIZE_IMAGES_UNIT);
	gtk_combo_box_set_active (GTK_COMBO_BOX (GET_WIDGET ("unit_combobox")), unit);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("keep_ratio_checkbutton")),
				      g_settings_get_boolean (data->settings, PREF_RESIZE_IMAGES_KEEP_RATIO));

	default_width_in_pixels = DEFAULT_WIDTH_PIXELS;
	default_height_in_pixels = DEFAULT_HEIGHT_PIXELS;

	if (data->file_list->next == NULL) {
		GthMetadataProvider *provider;
		int                  width;
		int                  height;

		provider = g_object_new (GTH_TYPE_METADATA_PROVIDER_IMAGE, NULL);
		gth_metadata_provider_read (provider,
					    first_file_data,
					    "image::width,image::height",
					    NULL);
		width = g_file_info_get_attribute_int32 (first_file_data->info, "image::width");
		height = g_file_info_get_attribute_int32 (first_file_data->info, "image::height");

		if ((width > 0) && (height > 0)) {
			data->known_ratio = TRUE;
			data->ratio = (double) width / height;
			default_width_in_pixels = width;
			default_height_in_pixels = height;
		}

		g_object_unref (provider);
	}

	if (unit == GTH_UNIT_PERCENTAGE) {
		data->latest_width_in_pixel = default_width_in_pixels;
		data->latest_height_in_pixel = default_height_in_pixels;
		data->latest_width_in_percentage = g_settings_get_int (data->settings, PREF_RESIZE_IMAGES_SERIES_WIDTH);
		data->latest_height_in_percentage = g_settings_get_int (data->settings, PREF_RESIZE_IMAGES_SERIES_HEIGHT);
		gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("width_spinbutton")), data->latest_width_in_percentage);
		gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("height_spinbutton")), data->latest_height_in_percentage);
	}
	else if (unit == GTH_UNIT_PIXELS) {
		data->latest_width_in_percentage = DEFAULT_WIDTH_PERCENTAGE;
		data->latest_height_in_percentage = DEFAULT_HEIGHT_PERCENTAGE;
		data->latest_width_in_pixel = g_settings_get_int (data->settings, PREF_RESIZE_IMAGES_SERIES_WIDTH);
		data->latest_height_in_pixel = g_settings_get_int (data->settings, PREF_RESIZE_IMAGES_SERIES_HEIGHT);
		gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("width_spinbutton")), data->latest_width_in_pixel);
		gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("height_spinbutton")), data->latest_height_in_pixel);
	}

	savers = gth_main_get_type_set ("image-saver");
	if (savers != NULL) {
		GtkListStore *list_store;
		GtkTreeIter   iter;
		char         *default_mime_type;
		GthIconCache *icon_cache;
		int           i;

		list_store = (GtkListStore *) GET_WIDGET ("mime_type_liststore");
		gtk_list_store_append (list_store, &iter);
		gtk_list_store_set (list_store, &iter,
				    MIME_TYPE_COLUMN_ICON, NULL,
				    MIME_TYPE_COLUMN_TYPE, NULL,
				    MIME_TYPE_COLUMN_DESCRIPTION, _("Keep the original format"),
				    -1);
		gtk_combo_box_set_active_iter (GTK_COMBO_BOX (GET_WIDGET ("mime_type_combobox")), &iter);

		default_mime_type = g_settings_get_string (data->settings, PREF_RESIZE_IMAGES_MIME_TYPE);
		icon_cache = gth_icon_cache_new_for_widget (data->dialog, GTK_ICON_SIZE_MENU);

		for (i = 0; i < savers->len; i++) {
			GType           saver_type;
			GthImageSaver *saver;
			const char     *mime_type;
			GdkPixbuf      *pixbuf;

			saver_type = g_array_index (savers, GType, i);
			saver = g_object_new (saver_type, NULL);
			mime_type = gth_image_saver_get_mime_type (saver);
			pixbuf = gth_icon_cache_get_pixbuf (icon_cache, g_content_type_get_icon (mime_type));
			gtk_list_store_append (list_store, &iter);
			gtk_list_store_set (list_store, &iter,
					    MIME_TYPE_COLUMN_ICON, pixbuf,
					    MIME_TYPE_COLUMN_TYPE, mime_type,
					    MIME_TYPE_COLUMN_DESCRIPTION, g_content_type_get_description (mime_type),
					    -1);

			if (strcmp (default_mime_type, mime_type) == 0)
				gtk_combo_box_set_active_iter (GTK_COMBO_BOX (GET_WIDGET ("mime_type_combobox")), &iter);

			g_object_unref (pixbuf);
			g_object_unref (saver);
		}

		gth_icon_cache_free (icon_cache);
		g_free (default_mime_type);
	}

	/* Set the signals handlers. */

	g_signal_connect (G_OBJECT (data->dialog),
			  "destroy",
			  G_CALLBACK (destroy_cb),
			  data);
	g_signal_connect (GET_WIDGET ("ok_button"),
			  "clicked",
			  G_CALLBACK (ok_clicked_cb),
			  data);
        g_signal_connect (GET_WIDGET ("help_button"),
                          "clicked",
                          G_CALLBACK (help_clicked_cb),
                          data);
	g_signal_connect_swapped (GET_WIDGET ("cancel_button"),
				  "clicked",
				  G_CALLBACK (gtk_widget_destroy),
				  G_OBJECT (data->dialog));
	g_signal_connect (GET_WIDGET ("unit_combobox"),
			  "changed",
			  G_CALLBACK (unit_combobox_changed_cb),
			  data);
	g_signal_connect (GET_WIDGET ("use_destination_checkbutton"),
			  "toggled",
			  G_CALLBACK (use_destination_checkbutton_toggled_cb),
			  data);

	data->width_spinbutton_event = g_signal_connect (GET_WIDGET ("width_spinbutton"),
							 "value-changed",
							 G_CALLBACK (width_spinbutton_value_changed_cb),
							 data);
	data->height_spinbutton_event = g_signal_connect (GET_WIDGET ("height_spinbutton"),
							  "value-changed",
							  G_CALLBACK (height_spinbutton_value_changed_cb),
							  data);

	/* Run dialog. */

	update_width_height_properties (data);
	width_spinbutton_value_changed_cb (NULL, data);

        if (GTH_IS_FILE_SOURCE_VFS (gth_browser_get_location_source (browser)))
        	gtk_widget_hide (GET_WIDGET ("use_destination_checkbutton"));

	gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (browser));
	gtk_window_set_modal (GTK_WINDOW (data->dialog), FALSE);
	gtk_widget_show (data->dialog);
}