Merge branch 'drop-file-system' into 'master'

Drop file system

See merge request GNOME/gtk!2229
This commit is contained in:
Matthias Clasen 2020-07-12 14:41:01 +00:00
commit 7ddbbb50ff
21 changed files with 1264 additions and 2015 deletions

View File

@ -540,24 +540,6 @@ gtk_file_chooser_get_file (GtkFileChooser *chooser)
return result;
}
/*< private >
* _gtk_file_chooser_get_file_system:
* @chooser: a #GtkFileChooser
*
* Gets the #GtkFileSystem of @chooser; this is an internal
* implementation detail, used for conversion between paths
* and filenames and URIs.
*
* Returns: the file system for @chooser.
**/
GtkFileSystem *
_gtk_file_chooser_get_file_system (GtkFileChooser *chooser)
{
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_file_system (chooser);
}
/**
* gtk_file_chooser_add_shortcut_folder:
* @chooser: a #GtkFileChooser

File diff suppressed because it is too large Load Diff

View File

@ -26,7 +26,6 @@
#include "gtkfilechooserwidgetprivate.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooserembed.h"
#include "gtkfilesystem.h"
#include "gtksizerequest.h"
#include "gtktypebuiltins.h"
#include "gtkintl.h"

View File

@ -25,7 +25,7 @@
#include "gtkcelllayout.h"
#include "gtkcellrenderertext.h"
#include "gtkentryprivate.h"
#include "gtkfilesystemmodel.h"
#include "gtkfilechooserutils.h"
#include "gtklabel.h"
#include "gtkmain.h"
#include "gtksizerequest.h"

View File

@ -19,7 +19,6 @@
#ifndef __GTK_FILE_CHOOSER_ENTRY_H__
#define __GTK_FILE_CHOOSER_ENTRY_H__
#include "gtkfilesystem.h"
#include "gtkfilechooser.h"
G_BEGIN_DECLS

View File

@ -29,7 +29,6 @@
#include "gtkfilechooserwidgetprivate.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooserembed.h"
#include "gtkfilesystem.h"
#include "gtksizerequest.h"
#include "gtktypebuiltins.h"
#include "gtkintl.h"

View File

@ -29,7 +29,6 @@
#include "gtkfilechooserwidgetprivate.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooserembed.h"
#include "gtkfilesystem.h"
#include "gtksizerequest.h"
#include "gtktypebuiltins.h"
#include "gtkintl.h"

View File

@ -29,7 +29,6 @@
#include "gtkfilechooserwidgetprivate.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooserembed.h"
#include "gtkfilesystem.h"
#include "gtksizerequest.h"
#include "gtktypebuiltins.h"
#include "gtkintl.h"

View File

@ -35,7 +35,6 @@
#include "gtkfilechooserwidgetprivate.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooserembed.h"
#include "gtkfilesystem.h"
#include "gtksizerequest.h"
#include "gtktypebuiltins.h"
#include "gtkintl.h"

View File

@ -20,7 +20,6 @@
#define __GTK_FILE_CHOOSER_PRIVATE_H__
#include "gtkfilechooser.h"
#include "gtkfilesystem.h"
#include "gtkfilesystemmodel.h"
#include "gtkliststore.h"
#include "gtkrecentmanager.h"
@ -73,7 +72,6 @@ struct _GtkFileChooserIface
void (*select_all) (GtkFileChooser *chooser);
void (*unselect_all) (GtkFileChooser *chooser);
GListModel * (*get_files) (GtkFileChooser *chooser);
GtkFileSystem *(*get_file_system) (GtkFileChooser *chooser);
void (*add_filter) (GtkFileChooser *chooser,
GtkFileFilter *filter);
void (*remove_filter) (GtkFileChooser *chooser,
@ -109,8 +107,6 @@ struct _GtkFileChooserIface
const char *id);
};
GtkFileSystem *_gtk_file_chooser_get_file_system (GtkFileChooser *chooser);
void gtk_file_chooser_select_all (GtkFileChooser *chooser);
void gtk_file_chooser_unselect_all (GtkFileChooser *chooser);
gboolean gtk_file_chooser_select_file (GtkFileChooser *chooser,

View File

@ -20,7 +20,6 @@
#include "config.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooser.h"
#include "gtkfilesystem.h"
#include "gtktypebuiltins.h"
#include "gtkintl.h"
@ -40,7 +39,6 @@ static void delegate_unselect_file (GtkFileChooser *choose
static void delegate_select_all (GtkFileChooser *chooser);
static void delegate_unselect_all (GtkFileChooser *chooser);
static GListModel * delegate_get_files (GtkFileChooser *chooser);
static GtkFileSystem *delegate_get_file_system (GtkFileChooser *chooser);
static void delegate_add_filter (GtkFileChooser *chooser,
GtkFileFilter *filter);
static void delegate_remove_filter (GtkFileChooser *chooser,
@ -128,7 +126,6 @@ _gtk_file_chooser_delegate_iface_init (GtkFileChooserIface *iface)
iface->select_all = delegate_select_all;
iface->unselect_all = delegate_unselect_all;
iface->get_files = delegate_get_files;
iface->get_file_system = delegate_get_file_system;
iface->add_filter = delegate_add_filter;
iface->remove_filter = delegate_remove_filter;
iface->get_filters = delegate_get_filters;
@ -215,12 +212,6 @@ delegate_get_files (GtkFileChooser *chooser)
return gtk_file_chooser_get_files (get_delegate (chooser));
}
static GtkFileSystem *
delegate_get_file_system (GtkFileChooser *chooser)
{
return _gtk_file_chooser_get_file_system (get_delegate (chooser));
}
static void
delegate_add_filter (GtkFileChooser *chooser,
GtkFileFilter *filter)
@ -411,3 +402,76 @@ delegate_get_choice (GtkFileChooser *chooser,
{
return gtk_file_chooser_get_choice (get_delegate (chooser), id);
}
gboolean
_gtk_file_info_consider_as_directory (GFileInfo *info)
{
GFileType type = g_file_info_get_file_type (info);
return (type == G_FILE_TYPE_DIRECTORY ||
type == G_FILE_TYPE_MOUNTABLE ||
type == G_FILE_TYPE_SHORTCUT);
}
gboolean
_gtk_file_has_native_path (GFile *file)
{
char *local_file_path;
gboolean has_native_path;
/* Don't use g_file_is_native(), as we want to support FUSE paths if available */
local_file_path = g_file_get_path (file);
has_native_path = (local_file_path != NULL);
g_free (local_file_path);
return has_native_path;
}
gboolean
_gtk_file_consider_as_remote (GFile *file)
{
GFileInfo *info;
gboolean is_remote;
info = g_file_query_filesystem_info (file, G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE, NULL, NULL);
if (info)
{
is_remote = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE);
g_object_unref (info);
}
else
is_remote = FALSE;
return is_remote;
}
GIcon *
_gtk_file_info_get_icon (GFileInfo *info,
int icon_size,
int scale)
{
GIcon *icon;
GdkPixbuf *pixbuf;
const gchar *thumbnail_path;
thumbnail_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
if (thumbnail_path)
{
pixbuf = gdk_pixbuf_new_from_file_at_size (thumbnail_path,
icon_size*scale, icon_size*scale,
NULL);
if (pixbuf != NULL)
return G_ICON (pixbuf);
}
icon = g_file_info_get_icon (info);
if (icon)
return g_object_ref (icon);
/* Use general fallback for all files without icon */
icon = g_themed_icon_new ("text-x-generic");
return icon;
}

View File

@ -49,6 +49,13 @@ GSettings *_gtk_file_chooser_get_settings_for_widget (GtkWidget *widget);
gchar * _gtk_file_chooser_label_for_file (GFile *file);
gboolean _gtk_file_info_consider_as_directory (GFileInfo *info);
gboolean _gtk_file_has_native_path (GFile *file);
gboolean _gtk_file_consider_as_remote (GFile *file);
GIcon * _gtk_file_info_get_icon (GFileInfo *info,
int icon_size,
int scale);
G_END_DECLS
#endif /* __GTK_FILE_CHOOSER_UTILS_H__ */

View File

@ -38,7 +38,6 @@
#include "gtkfilechooserentry.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooser.h"
#include "gtkfilesystem.h"
#include "gtkfilesystemmodel.h"
#include "gtkgrid.h"
#include "gtkicontheme.h"
@ -227,8 +226,6 @@ struct _GtkFileChooserWidget
GtkFileChooserAction action;
GtkFileSystem *file_system;
GtkWidget *box;
GActionGroup *item_actions;
@ -480,7 +477,6 @@ static void gtk_file_chooser_widget_unselect_file (GtkF
static void gtk_file_chooser_widget_select_all (GtkFileChooser *chooser);
static void gtk_file_chooser_widget_unselect_all (GtkFileChooser *chooser);
static GListModel * gtk_file_chooser_widget_get_files (GtkFileChooser *chooser);
static GtkFileSystem *gtk_file_chooser_widget_get_file_system (GtkFileChooser *chooser);
static void gtk_file_chooser_widget_add_filter (GtkFileChooser *chooser,
GtkFileFilter *filter);
static void gtk_file_chooser_widget_remove_filter (GtkFileChooser *chooser,
@ -612,7 +608,6 @@ gtk_file_chooser_widget_iface_init (GtkFileChooserIface *iface)
iface->select_all = gtk_file_chooser_widget_select_all;
iface->unselect_all = gtk_file_chooser_widget_unselect_all;
iface->get_files = gtk_file_chooser_widget_get_files;
iface->get_file_system = gtk_file_chooser_widget_get_file_system;
iface->set_current_folder = gtk_file_chooser_widget_set_current_folder;
iface->get_current_folder = gtk_file_chooser_widget_get_current_folder;
iface->set_current_name = gtk_file_chooser_widget_set_current_name;
@ -663,8 +658,6 @@ gtk_file_chooser_widget_finalize (GObject *object)
if (impl->location_changed_id > 0)
g_source_remove (impl->location_changed_id);
g_clear_object (&impl->file_system);
g_free (impl->browse_files_last_selected_name);
g_clear_object (&impl->filters);
@ -919,22 +912,18 @@ struct FileExistsData
};
static void
name_exists_get_info_cb (GCancellable *cancellable,
GFileInfo *info,
const GError *error,
name_exists_get_info_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
GFile *file = G_FILE (source);
struct FileExistsData *data = user_data;
GFileInfo *info;
GtkFileChooserWidget *impl = data->impl;
if (cancellable != impl->file_exists_get_info_cancellable)
goto out;
impl->file_exists_get_info_cancellable = NULL;
if (g_cancellable_is_cancelled (cancellable))
goto out;
g_clear_object (&impl->file_exists_get_info_cancellable);
info = g_file_query_info_finish (file, result, NULL);
if (info != NULL)
{
gtk_widget_set_sensitive (data->button, FALSE);
@ -948,11 +937,10 @@ name_exists_get_info_cb (GCancellable *cancellable,
/* Don't clear the label here, it may contain a warning */
}
out:
g_object_unref (impl);
g_object_unref (data->file);
g_free (data);
g_object_unref (cancellable);
g_clear_object (&info);
}
static void
@ -1014,13 +1002,16 @@ check_valid_child_name (GtkFileChooserWidget *impl,
if (impl->file_exists_get_info_cancellable)
g_cancellable_cancel (impl->file_exists_get_info_cancellable);
g_clear_object (&impl->file_exists_get_info_cancellable);
impl->file_exists_get_info_cancellable =
_gtk_file_system_get_info (impl->file_system,
file,
"standard::type",
name_exists_get_info_cb,
data);
impl->file_exists_get_info_cancellable = g_cancellable_new ();
g_file_query_info_async (file,
"standard::type",
G_FILE_QUERY_INFO_NONE,
G_PRIORITY_DEFAULT,
impl->file_exists_get_info_cancellable,
name_exists_get_info_cb,
data);
g_object_unref (file);
}
@ -1694,27 +1685,25 @@ typedef struct
} FileListDragData;
static void
file_list_drag_data_received_get_info_cb (GCancellable *cancellable,
GFileInfo *info,
const GError *error,
file_list_drag_data_received_get_info_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
gboolean cancelled = g_cancellable_is_cancelled (cancellable);
GFile *file = G_FILE (source);
FileListDragData *data = user_data;
GFileInfo *info;
GtkFileChooserWidget *impl = data->impl;
GtkFileChooser *chooser = GTK_FILE_CHOOSER (impl);
if (cancellable != impl->file_list_drag_data_received_cancellable)
goto out;
g_clear_object (&impl->file_list_drag_data_received_cancellable);
impl->file_list_drag_data_received_cancellable = NULL;
if (cancelled || error)
info = g_file_query_info_finish (file, result, NULL);
if (!info)
goto out;
if ((impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
impl->action == GTK_FILE_CHOOSER_ACTION_SAVE) &&
data->files->next == NULL && !error && _gtk_file_info_consider_as_directory (info))
data->files->next == NULL && _gtk_file_info_consider_as_directory (info))
change_folder_and_display_error (data->impl, data->files->data, FALSE);
else
{
@ -1736,7 +1725,7 @@ out:
g_slist_free_full (data->files, g_object_unref);
g_free (data);
g_object_unref (cancellable);
g_clear_object (&info);
}
static gboolean
@ -1757,12 +1746,16 @@ file_list_drag_drop_cb (GtkDropTarget *dest,
if (impl->file_list_drag_data_received_cancellable)
g_cancellable_cancel (impl->file_list_drag_data_received_cancellable);
g_clear_object (&impl->file_list_drag_data_received_cancellable);
impl->file_list_drag_data_received_cancellable =
_gtk_file_system_get_info (impl->file_system, data->files->data,
"standard::type",
file_list_drag_data_received_get_info_cb,
data);
impl->file_list_drag_data_received_cancellable = g_cancellable_new ();
g_file_query_info_async (data->files->data,
"standard::type",
G_FILE_QUERY_INFO_NONE,
G_PRIORITY_DEFAULT,
impl->file_list_drag_data_received_cancellable,
file_list_drag_data_received_get_info_cb,
data);
return TRUE;
}
@ -2593,8 +2586,6 @@ gtk_file_chooser_widget_constructed (GObject *object)
G_OBJECT_CLASS (gtk_file_chooser_widget_parent_class)->constructed (object);
g_assert (impl->file_system);
update_appearance (impl);
profile_end ("end", NULL);
@ -3144,10 +3135,18 @@ cancel_all_operations (GtkFileChooserWidget *impl)
{
pending_select_files_free (impl);
g_clear_pointer (&impl->file_list_drag_data_received_cancellable, g_cancellable_cancel);
g_clear_pointer (&impl->update_current_folder_cancellable, g_cancellable_cancel);
g_clear_pointer (&impl->should_respond_get_info_cancellable, g_cancellable_cancel);
g_clear_pointer (&impl->file_exists_get_info_cancellable, g_cancellable_cancel);
if (impl->file_list_drag_data_received_cancellable)
g_cancellable_cancel (impl->file_list_drag_data_received_cancellable);
g_clear_object (&impl->file_list_drag_data_received_cancellable);
if (impl->update_current_folder_cancellable)
g_cancellable_cancel (impl->update_current_folder_cancellable);
g_clear_object (&impl->update_current_folder_cancellable);
if (impl->should_respond_get_info_cancellable)
g_cancellable_cancel (impl->should_respond_get_info_cancellable);
g_clear_object (&impl->should_respond_get_info_cancellable);
if (impl->file_exists_get_info_cancellable)
g_cancellable_cancel (impl->file_exists_get_info_cancellable);
g_clear_object (&impl->file_exists_get_info_cancellable);
search_stop_searching (impl, TRUE);
}
@ -4959,24 +4958,19 @@ struct UpdateCurrentFolderData
};
static void
update_current_folder_mount_enclosing_volume_cb (GCancellable *cancellable,
GtkFileSystemVolume *volume,
const GError *error,
gpointer user_data)
update_current_folder_mount_enclosing_volume_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
GFile *file = G_FILE (source);
struct UpdateCurrentFolderData *data = user_data;
GtkFileChooserWidget *impl = data->impl;
gboolean cancelled = g_cancellable_is_cancelled (cancellable);
GError *error = NULL;
if (cancellable != impl->update_current_folder_cancellable)
goto out;
impl->update_current_folder_cancellable = NULL;
g_clear_object (&impl->update_current_folder_cancellable);
set_busy_cursor (impl, FALSE);
if (cancelled)
goto out;
g_file_mount_enclosing_volume_finish (file, result, &error);
if (error)
{
error_changing_folder_dialog (data->impl, data->file, g_error_copy (error));
@ -4991,30 +4985,26 @@ out:
g_object_unref (data->file);
g_free (data);
g_object_unref (cancellable);
g_clear_error (&error);
}
static void
update_current_folder_get_info_cb (GCancellable *cancellable,
GFileInfo *info,
const GError *error,
update_current_folder_get_info_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
gboolean cancelled = g_cancellable_is_cancelled (cancellable);
GFile *file = G_FILE (source);
struct UpdateCurrentFolderData *data = user_data;
GFileInfo *info;
GError *error = NULL;
GtkFileChooserWidget *impl = data->impl;
if (cancellable != impl->update_current_folder_cancellable)
goto out;
impl->update_current_folder_cancellable = NULL;
g_clear_object (&impl->update_current_folder_cancellable);
impl->reload_state = RELOAD_EMPTY;
set_busy_cursor (impl, FALSE);
if (cancelled)
goto out;
info = g_file_query_info_finish (file, result, &error);
if (error)
{
GFile *parent_file;
@ -5024,18 +5014,20 @@ update_current_folder_get_info_cb (GCancellable *cancellable,
GMountOperation *mount_operation;
GtkWidget *toplevel;
g_object_unref (cancellable);
g_clear_error (&error);
toplevel = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (impl)));
mount_operation = gtk_mount_operation_new (GTK_WINDOW (toplevel));
set_busy_cursor (impl, TRUE);
impl->update_current_folder_cancellable =
_gtk_file_system_mount_enclosing_volume (impl->file_system, data->file,
mount_operation,
update_current_folder_mount_enclosing_volume_cb,
data);
impl->update_current_folder_cancellable = g_cancellable_new ();
g_file_mount_enclosing_volume (data->file,
G_MOUNT_MOUNT_NONE,
mount_operation,
impl->update_current_folder_cancellable,
update_current_folder_mount_enclosing_volume_cb,
data);
return;
}
@ -5054,16 +5046,19 @@ update_current_folder_get_info_cb (GCancellable *cancellable,
g_object_unref (data->file);
data->file = parent_file;
g_object_unref (cancellable);
g_clear_error (&error);
/* restart the update current folder operation */
impl->reload_state = RELOAD_HAS_FOLDER;
impl->update_current_folder_cancellable =
_gtk_file_system_get_info (impl->file_system, data->file,
"standard::type",
update_current_folder_get_info_cb,
data);
impl->update_current_folder_cancellable = g_cancellable_new ();
g_file_query_info_async (data->file,
"standard::type",
G_FILE_QUERY_INFO_NONE,
G_PRIORITY_DEFAULT,
impl->update_current_folder_cancellable,
update_current_folder_get_info_cb,
data);
set_busy_cursor (impl, TRUE);
@ -5079,6 +5074,7 @@ update_current_folder_get_info_cb (GCancellable *cancellable,
else
g_error_free (data->original_error);
g_clear_error (&error);
g_object_unref (data->original_file);
goto out;
@ -5143,7 +5139,7 @@ out:
g_object_unref (data->file);
g_free (data);
g_object_unref (cancellable);
g_clear_object (&info);
}
static gboolean
@ -5164,6 +5160,7 @@ gtk_file_chooser_widget_update_current_folder (GtkFileChooser *chooser,
if (impl->update_current_folder_cancellable)
g_cancellable_cancel (impl->update_current_folder_cancellable);
g_clear_object (&impl->update_current_folder_cancellable);
/* Test validity of path here. */
data = g_new0 (struct UpdateCurrentFolderData, 1);
@ -5174,11 +5171,14 @@ gtk_file_chooser_widget_update_current_folder (GtkFileChooser *chooser,
impl->reload_state = RELOAD_HAS_FOLDER;
impl->update_current_folder_cancellable =
_gtk_file_system_get_info (impl->file_system, file,
"standard::type",
update_current_folder_get_info_cb,
data);
impl->update_current_folder_cancellable = g_cancellable_new ();
g_file_query_info_async (file,
"standard::type",
G_FILE_QUERY_INFO_NONE,
G_PRIORITY_DEFAULT,
impl->update_current_folder_cancellable,
update_current_folder_get_info_cb,
data);
set_busy_cursor (impl, TRUE);
g_object_unref (file);
@ -5601,14 +5601,6 @@ gtk_file_chooser_widget_get_files (GtkFileChooser *chooser)
return G_LIST_MODEL (info.result);
}
static GtkFileSystem *
gtk_file_chooser_widget_get_file_system (GtkFileChooser *chooser)
{
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
return impl->file_system;
}
/* Shows or hides the filter widgets */
static void
show_filters (GtkFileChooserWidget *impl,
@ -5892,23 +5884,18 @@ struct GetDisplayNameData
};
static void
confirmation_confirm_get_info_cb (GCancellable *cancellable,
GFileInfo *info,
const GError *error,
confirmation_confirm_get_info_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
gboolean cancelled = g_cancellable_is_cancelled (cancellable);
GFile *file = G_FILE (source);
struct GetDisplayNameData *data = user_data;
GFileInfo *info;
if (cancellable != data->impl->should_respond_get_info_cancellable)
goto out;
g_clear_object (&data->impl->should_respond_get_info_cancellable);
data->impl->should_respond_get_info_cancellable = NULL;
if (cancelled)
goto out;
if (error)
info = g_file_query_info_finish (file, result, NULL);
if (!info)
goto out;
confirm_dialog_should_accept_filename (data->impl, data->file_part,
@ -5921,7 +5908,7 @@ out:
g_free (data->file_part);
g_free (data);
g_object_unref (cancellable);
g_clear_object (&info);
}
/* Does overwrite confirmation if appropriate, and returns whether the dialog
@ -5942,38 +5929,38 @@ should_respond_after_confirm_overwrite (GtkFileChooserWidget *impl,
if (impl->should_respond_get_info_cancellable)
g_cancellable_cancel (impl->should_respond_get_info_cancellable);
g_clear_object (&impl->should_respond_get_info_cancellable);
impl->should_respond_get_info_cancellable =
_gtk_file_system_get_info (impl->file_system, parent_file,
"standard::display-name",
confirmation_confirm_get_info_cb,
data);
impl->should_respond_get_info_cancellable = g_cancellable_new ();
g_file_query_info_async (parent_file,
"standard::display-name",
G_FILE_QUERY_INFO_NONE,
G_PRIORITY_DEFAULT,
impl->should_respond_get_info_cancellable,
confirmation_confirm_get_info_cb,
data);
set_busy_cursor (data->impl, TRUE);
return FALSE;
}
static void
name_entry_get_parent_info_cb (GCancellable *cancellable,
GFileInfo *info,
const GError *error,
name_entry_get_parent_info_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
GFile *file = G_FILE (source);
struct FileExistsData *data = user_data;
GFileInfo *info;
gboolean parent_is_folder = FALSE;
gboolean parent_is_accessible = FALSE;
gboolean cancelled = g_cancellable_is_cancelled (cancellable);
struct FileExistsData *data = user_data;
GtkFileChooserWidget *impl = data->impl;
GError *error = NULL;
if (cancellable != impl->should_respond_get_info_cancellable)
goto out;
impl->should_respond_get_info_cancellable = NULL;
g_clear_object (&impl->should_respond_get_info_cancellable);
set_busy_cursor (impl, FALSE);
if (cancelled)
goto out;
info = g_file_query_info_finish (file, result, &error);
if (info)
{
parent_is_folder = _gtk_file_info_consider_as_directory (info);
@ -6059,39 +6046,35 @@ name_entry_get_parent_info_cb (GCancellable *cancellable,
error_changing_folder_dialog (impl, data->parent_file, error_copy);
}
out:
g_object_unref (data->impl);
g_object_unref (data->file);
g_object_unref (data->parent_file);
g_free (data);
g_object_unref (cancellable);
g_clear_error (&error);
g_clear_object (&info);
}
static void
file_exists_get_info_cb (GCancellable *cancellable,
GFileInfo *info,
const GError *error,
file_exists_get_info_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
GFile *file = G_FILE (source);
struct FileExistsData *data = user_data;
GFileInfo *info;
gboolean data_ownership_taken = FALSE;
gboolean cancelled = g_cancellable_is_cancelled (cancellable);
gboolean file_exists;
gboolean is_folder;
gboolean needs_parent_check = FALSE;
struct FileExistsData *data = user_data;
GtkFileChooserWidget *impl = data->impl;
GError *error = NULL;
if (cancellable != impl->file_exists_get_info_cancellable)
goto out;
impl->file_exists_get_info_cancellable = NULL;
g_clear_object (&impl->file_exists_get_info_cancellable);
set_busy_cursor (impl, FALSE);
if (cancelled)
goto out;
info = g_file_query_info_finish (file, result, &error);
file_exists = (info != NULL);
is_folder = (file_exists && _gtk_file_info_consider_as_directory (info));
@ -6148,17 +6131,19 @@ file_exists_get_info_cb (GCancellable *cancellable,
if (impl->should_respond_get_info_cancellable)
g_cancellable_cancel (impl->should_respond_get_info_cancellable);
g_clear_object (&impl->should_respond_get_info_cancellable);
impl->should_respond_get_info_cancellable =
_gtk_file_system_get_info (impl->file_system,
data->parent_file,
"standard::type,access::can-execute",
name_entry_get_parent_info_cb,
data);
impl->should_respond_get_info_cancellable = g_cancellable_new ();
g_file_query_info_async (data->parent_file,
"standard::type,access::can-execute",
G_FILE_QUERY_INFO_NONE,
G_PRIORITY_DEFAULT,
impl->should_respond_get_info_cancellable,
name_entry_get_parent_info_cb,
data);
set_busy_cursor (impl, TRUE);
}
out:
if (!data_ownership_taken)
{
g_object_unref (impl);
@ -6167,7 +6152,8 @@ out:
g_free (data);
}
g_object_unref (cancellable);
g_clear_error (&error);
g_clear_object (&info);
}
static void
@ -6434,12 +6420,16 @@ gtk_file_chooser_widget_should_respond (GtkFileChooserEmbed *chooser_embed)
if (impl->file_exists_get_info_cancellable)
g_cancellable_cancel (impl->file_exists_get_info_cancellable);
g_clear_object (&impl->file_exists_get_info_cancellable);
impl->file_exists_get_info_cancellable =
_gtk_file_system_get_info (impl->file_system, file,
"standard::type",
file_exists_get_info_cb,
data);
impl->file_exists_get_info_cancellable = g_cancellable_new ();
g_file_query_info_async (file,
"standard::type",
G_FILE_QUERY_INFO_NONE,
G_PRIORITY_DEFAULT,
impl->file_exists_get_info_cancellable,
file_exists_get_info_cb,
data);
set_busy_cursor (impl, TRUE);
}
@ -7863,8 +7853,6 @@ post_process_ui (GtkFileChooserWidget *impl)
file_list_set_sort_column_ids (impl);
update_cell_renderer_attributes (impl);
/* Set the GtkPathBar file system backend */
_gtk_path_bar_set_file_system (GTK_PATH_BAR (impl->browse_path_bar), impl->file_system);
file = g_file_new_for_path ("/");
_gtk_path_bar_set_file (GTK_PATH_BAR (impl->browse_path_bar), file, FALSE);
g_object_unref (file);
@ -7994,7 +7982,6 @@ gtk_file_chooser_widget_init (GtkFileChooserWidget *impl)
g_signal_connect (impl, "notify::display,", G_CALLBACK (display_changed_cb), impl);
check_icon_theme (impl);
impl->file_system = _gtk_file_system_new ();
impl->bookmarks_manager = _gtk_bookmarks_manager_new (NULL, NULL);
impl->filters = g_list_store_new (GTK_TYPE_FILE_FILTER);

View File

@ -1,823 +0,0 @@
/* GTK - The GIMP Toolkit
* gtkfilesystem.c: Filesystem abstraction functions.
* Copyright (C) 2003, Red Hat, Inc.
* Copyright (C) 2007-2008 Carlos Garnacho
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Carlos Garnacho <carlos@imendio.com>
*/
#include "config.h"
#include "gtkfilesystem.h"
#include <string.h>
#include <glib/gi18n-lib.h>
#include "gtkfilechooser.h"
#include "gtkintl.h"
#include "gtkprivate.h"
#include "gtkstylecontextprivate.h"
/* #define DEBUG_MODE */
#ifdef DEBUG_MODE
#define DEBUG(x) g_debug (x);
#else
#define DEBUG(x)
#endif
#define FILES_PER_QUERY 100
/* The pointers we return for a GtkFileSystemVolume are opaque tokens; they are
* really pointers to GDrive, GVolume or GMount objects. We need an extra
* token for the fake File System volume. So, well return a pointer to
* this particular string.
*/
static const gchar *root_volume_token = N_("File System");
#define IS_ROOT_VOLUME(volume) ((gpointer) (volume) == (gpointer) root_volume_token)
enum {
PROP_0,
PROP_FILE,
PROP_ENUMERATOR,
PROP_ATTRIBUTES
};
enum {
VOLUMES_CHANGED,
FS_LAST_SIGNAL
};
enum {
FILES_ADDED,
FILES_REMOVED,
FILES_CHANGED,
FINISHED_LOADING,
DELETED,
FOLDER_LAST_SIGNAL
};
static guint fs_signals [FS_LAST_SIGNAL] = { 0, };
typedef struct AsyncFuncData AsyncFuncData;
struct GtkFileSystemPrivate
{
GVolumeMonitor *volume_monitor;
/* This list contains elements that can be
* of type GDrive, GVolume and GMount
*/
GSList *volumes;
};
struct AsyncFuncData
{
GtkFileSystem *file_system;
GFile *file;
GCancellable *cancellable;
gpointer callback;
gpointer data;
};
G_DEFINE_TYPE_WITH_PRIVATE (GtkFileSystem, _gtk_file_system, G_TYPE_OBJECT)
/* GtkFileSystem methods */
static void
volumes_changed (GVolumeMonitor *volume_monitor,
gpointer volume,
gpointer user_data)
{
GtkFileSystem *file_system = user_data;
g_signal_emit (file_system, fs_signals[VOLUMES_CHANGED], 0, volume);
}
static void
gtk_file_system_dispose (GObject *object)
{
GtkFileSystem *file_system = GTK_FILE_SYSTEM (object);
GtkFileSystemPrivate *priv = file_system->priv;
DEBUG ("dispose");
if (priv->volumes)
{
g_slist_free_full (priv->volumes, g_object_unref);
priv->volumes = NULL;
}
if (priv->volume_monitor)
{
g_signal_handlers_disconnect_by_func (priv->volume_monitor, volumes_changed, object);
g_object_unref (priv->volume_monitor);
priv->volume_monitor = NULL;
}
G_OBJECT_CLASS (_gtk_file_system_parent_class)->dispose (object);
}
static void
_gtk_file_system_class_init (GtkFileSystemClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->dispose = gtk_file_system_dispose;
fs_signals[VOLUMES_CHANGED] =
g_signal_new (I_("volumes-changed"),
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkFileSystemClass, volumes_changed),
NULL, NULL,
NULL,
G_TYPE_NONE, 0);
}
static gboolean
mount_referenced_by_volume_activation_root (GList *volumes, GMount *mount)
{
GList *l;
GFile *mount_root;
gboolean ret;
ret = FALSE;
mount_root = g_mount_get_root (mount);
for (l = volumes; l != NULL; l = l->next)
{
GVolume *volume = G_VOLUME (l->data);
GFile *volume_activation_root;
volume_activation_root = g_volume_get_activation_root (volume);
if (volume_activation_root != NULL)
{
if (g_file_has_prefix (volume_activation_root, mount_root))
{
ret = TRUE;
g_object_unref (volume_activation_root);
break;
}
g_object_unref (volume_activation_root);
}
}
g_object_unref (mount_root);
return ret;
}
static void
get_volumes_list (GtkFileSystem *file_system)
{
GtkFileSystemPrivate *priv = file_system->priv;
GList *l, *ll;
GList *drives;
GList *volumes;
GList *mounts;
GDrive *drive;
GVolume *volume;
GMount *mount;
if (priv->volumes)
{
g_slist_free_full (priv->volumes, g_object_unref);
priv->volumes = NULL;
}
/* first go through all connected drives */
drives = g_volume_monitor_get_connected_drives (priv->volume_monitor);
for (l = drives; l != NULL; l = l->next)
{
drive = l->data;
volumes = g_drive_get_volumes (drive);
if (volumes)
{
for (ll = volumes; ll != NULL; ll = ll->next)
{
volume = ll->data;
mount = g_volume_get_mount (volume);
if (mount)
{
/* Show mounted volume */
priv->volumes = g_slist_prepend (priv->volumes, g_object_ref (mount));
g_object_unref (mount);
}
else
{
/* Do show the unmounted volumes in the sidebar;
* this is so the user can mount it (in case automounting
* is off).
*
* Also, even if automounting is enabled, this gives a visual
* cue that the user should remember to yank out the media if
* he just unmounted it.
*/
priv->volumes = g_slist_prepend (priv->volumes, g_object_ref (volume));
}
g_object_unref (volume);
}
g_list_free (volumes);
}
else if (g_drive_is_media_removable (drive) && !g_drive_is_media_check_automatic (drive))
{
/* If the drive has no mountable volumes and we cannot detect media change.. we
* display the drive in the sidebar so the user can manually poll the drive by
* right clicking and selecting "Rescan..."
*
* This is mainly for drives like floppies where media detection doesn't
* work.. but it's also for human beings who like to turn off media detection
* in the OS to save battery juice.
*/
priv->volumes = g_slist_prepend (priv->volumes, g_object_ref (drive));
}
g_object_unref (drive);
}
g_list_free (drives);
/* add all volumes that is not associated with a drive */
volumes = g_volume_monitor_get_volumes (priv->volume_monitor);
for (l = volumes; l != NULL; l = l->next)
{
volume = l->data;
drive = g_volume_get_drive (volume);
if (drive)
{
g_object_unref (drive);
continue;
}
mount = g_volume_get_mount (volume);
if (mount)
{
/* show this mount */
priv->volumes = g_slist_prepend (priv->volumes, g_object_ref (mount));
g_object_unref (mount);
}
else
{
/* see comment above in why we add an icon for a volume */
priv->volumes = g_slist_prepend (priv->volumes, g_object_ref (volume));
}
g_object_unref (volume);
}
/* add mounts that has no volume (/etc/mtab mounts, ftp, sftp,...) */
mounts = g_volume_monitor_get_mounts (priv->volume_monitor);
for (l = mounts; l != NULL; l = l->next)
{
mount = l->data;
volume = g_mount_get_volume (mount);
if (volume)
{
g_object_unref (volume);
continue;
}
/* if there's exists one or more volumes with an activation root inside the mount,
* don't display the mount
*/
if (mount_referenced_by_volume_activation_root (volumes, mount))
{
g_object_unref (mount);
continue;
}
/* show this mount */
priv->volumes = g_slist_prepend (priv->volumes, g_object_ref (mount));
g_object_unref (mount);
}
g_list_free (volumes);
g_list_free (mounts);
}
static void
_gtk_file_system_init (GtkFileSystem *file_system)
{
GtkFileSystemPrivate *priv;
DEBUG ("init");
file_system->priv = priv = _gtk_file_system_get_instance_private (file_system);
/* Volumes */
priv->volume_monitor = g_volume_monitor_get ();
g_signal_connect (priv->volume_monitor, "mount-added",
G_CALLBACK (volumes_changed), file_system);
g_signal_connect (priv->volume_monitor, "mount-removed",
G_CALLBACK (volumes_changed), file_system);
g_signal_connect (priv->volume_monitor, "mount-changed",
G_CALLBACK (volumes_changed), file_system);
g_signal_connect (priv->volume_monitor, "volume-added",
G_CALLBACK (volumes_changed), file_system);
g_signal_connect (priv->volume_monitor, "volume-removed",
G_CALLBACK (volumes_changed), file_system);
g_signal_connect (priv->volume_monitor, "volume-changed",
G_CALLBACK (volumes_changed), file_system);
g_signal_connect (priv->volume_monitor, "drive-connected",
G_CALLBACK (volumes_changed), file_system);
g_signal_connect (priv->volume_monitor, "drive-disconnected",
G_CALLBACK (volumes_changed), file_system);
g_signal_connect (priv->volume_monitor, "drive-changed",
G_CALLBACK (volumes_changed), file_system);
}
/* GtkFileSystem public methods */
GtkFileSystem *
_gtk_file_system_new (void)
{
return g_object_new (GTK_TYPE_FILE_SYSTEM, NULL);
}
GSList *
_gtk_file_system_list_volumes (GtkFileSystem *file_system)
{
GtkFileSystemPrivate *priv = file_system->priv;
GSList *list;
DEBUG ("list_volumes");
get_volumes_list (file_system);
list = g_slist_copy (priv->volumes);
#ifndef G_OS_WIN32
/* Prepend root volume */
list = g_slist_prepend (list, (gpointer) root_volume_token);
#endif
return list;
}
static void
free_async_data (AsyncFuncData *async_data)
{
g_object_unref (async_data->file_system);
g_object_unref (async_data->file);
g_object_unref (async_data->cancellable);
g_free (async_data);
}
static void
query_info_callback (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
AsyncFuncData *async_data;
GError *error = NULL;
GFileInfo *file_info;
GFile *file;
DEBUG ("query_info_callback");
file = G_FILE (source_object);
async_data = (AsyncFuncData *) user_data;
file_info = g_file_query_info_finish (file, result, &error);
if (async_data->callback)
{
((GtkFileSystemGetInfoCallback) async_data->callback) (async_data->cancellable,
file_info, error, async_data->data);
}
if (file_info)
g_object_unref (file_info);
if (error)
g_error_free (error);
free_async_data (async_data);
}
GCancellable *
_gtk_file_system_get_info (GtkFileSystem *file_system,
GFile *file,
const gchar *attributes,
GtkFileSystemGetInfoCallback callback,
gpointer data)
{
GCancellable *cancellable;
AsyncFuncData *async_data;
g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
g_return_val_if_fail (G_IS_FILE (file), NULL);
cancellable = g_cancellable_new ();
async_data = g_new0 (AsyncFuncData, 1);
async_data->file_system = g_object_ref (file_system);
async_data->file = g_object_ref (file);
async_data->cancellable = g_object_ref (cancellable);
async_data->callback = callback;
async_data->data = data;
g_file_query_info_async (file,
attributes,
G_FILE_QUERY_INFO_NONE,
G_PRIORITY_DEFAULT,
cancellable,
query_info_callback,
async_data);
return cancellable;
}
static void
drive_poll_for_media_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
AsyncFuncData *async_data;
GError *error = NULL;
g_drive_poll_for_media_finish (G_DRIVE (source_object), result, &error);
async_data = (AsyncFuncData *) user_data;
((GtkFileSystemVolumeMountCallback) async_data->callback) (async_data->cancellable,
(GtkFileSystemVolume *) source_object,
error, async_data->data);
if (error)
g_error_free (error);
}
static void
volume_mount_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
AsyncFuncData *async_data;
GError *error = NULL;
g_volume_mount_finish (G_VOLUME (source_object), result, &error);
async_data = (AsyncFuncData *) user_data;
((GtkFileSystemVolumeMountCallback) async_data->callback) (async_data->cancellable,
(GtkFileSystemVolume *) source_object,
error, async_data->data);
if (error)
g_error_free (error);
}
GCancellable *
_gtk_file_system_mount_volume (GtkFileSystem *file_system,
GtkFileSystemVolume *volume,
GMountOperation *mount_operation,
GtkFileSystemVolumeMountCallback callback,
gpointer data)
{
GCancellable *cancellable;
AsyncFuncData *async_data;
gboolean handled = FALSE;
DEBUG ("volume_mount");
cancellable = g_cancellable_new ();
async_data = g_new0 (AsyncFuncData, 1);
async_data->file_system = g_object_ref (file_system);
async_data->cancellable = g_object_ref (cancellable);
async_data->callback = callback;
async_data->data = data;
if (G_IS_DRIVE (volume))
{
/* this path happens for drives that are not polled by the OS and where the last media
* check indicated that no media was available. So the thing to do here is to
* invoke poll_for_media() on the drive
*/
g_drive_poll_for_media (G_DRIVE (volume), cancellable, drive_poll_for_media_cb, async_data);
handled = TRUE;
}
else if (G_IS_VOLUME (volume))
{
g_volume_mount (G_VOLUME (volume), G_MOUNT_MOUNT_NONE, mount_operation, cancellable, volume_mount_cb, async_data);
handled = TRUE;
}
if (!handled)
free_async_data (async_data);
return cancellable;
}
static void
enclosing_volume_mount_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
GtkFileSystemVolume *volume;
AsyncFuncData *async_data;
GError *error = NULL;
async_data = (AsyncFuncData *) user_data;
g_file_mount_enclosing_volume_finish (G_FILE (source_object), result, &error);
volume = _gtk_file_system_get_volume_for_file (async_data->file_system, G_FILE (source_object));
/* Silently drop G_IO_ERROR_ALREADY_MOUNTED error for gvfs backends without visible mounts. */
/* Better than doing query_info with additional I/O every time. */
if (error && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_ALREADY_MOUNTED))
g_clear_error (&error);
((GtkFileSystemVolumeMountCallback) async_data->callback) (async_data->cancellable, volume,
error, async_data->data);
if (error)
g_error_free (error);
_gtk_file_system_volume_unref (volume);
}
GCancellable *
_gtk_file_system_mount_enclosing_volume (GtkFileSystem *file_system,
GFile *file,
GMountOperation *mount_operation,
GtkFileSystemVolumeMountCallback callback,
gpointer data)
{
GCancellable *cancellable;
AsyncFuncData *async_data;
g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
g_return_val_if_fail (G_IS_FILE (file), NULL);
DEBUG ("mount_enclosing_volume");
cancellable = g_cancellable_new ();
async_data = g_new0 (AsyncFuncData, 1);
async_data->file_system = g_object_ref (file_system);
async_data->file = g_object_ref (file);
async_data->cancellable = g_object_ref (cancellable);
async_data->callback = callback;
async_data->data = data;
g_file_mount_enclosing_volume (file,
G_MOUNT_MOUNT_NONE,
mount_operation,
cancellable,
enclosing_volume_mount_cb,
async_data);
return cancellable;
}
GtkFileSystemVolume *
_gtk_file_system_get_volume_for_file (GtkFileSystem *file_system,
GFile *file)
{
GMount *mount;
DEBUG ("get_volume_for_file");
mount = g_file_find_enclosing_mount (file, NULL, NULL);
if (!mount && g_file_is_native (file))
return (GtkFileSystemVolume *) root_volume_token;
return (GtkFileSystemVolume *) mount;
}
/* GtkFileSystemVolume public methods */
gchar *
_gtk_file_system_volume_get_display_name (GtkFileSystemVolume *volume)
{
DEBUG ("volume_get_display_name");
if (IS_ROOT_VOLUME (volume))
return g_strdup (_(root_volume_token));
if (G_IS_DRIVE (volume))
return g_drive_get_name (G_DRIVE (volume));
else if (G_IS_MOUNT (volume))
return g_mount_get_name (G_MOUNT (volume));
else if (G_IS_VOLUME (volume))
return g_volume_get_name (G_VOLUME (volume));
return NULL;
}
gboolean
_gtk_file_system_volume_is_mounted (GtkFileSystemVolume *volume)
{
gboolean mounted;
DEBUG ("volume_is_mounted");
if (IS_ROOT_VOLUME (volume))
return TRUE;
mounted = FALSE;
if (G_IS_MOUNT (volume))
mounted = TRUE;
else if (G_IS_VOLUME (volume))
{
GMount *mount;
mount = g_volume_get_mount (G_VOLUME (volume));
if (mount)
{
mounted = TRUE;
g_object_unref (mount);
}
}
return mounted;
}
GFile *
_gtk_file_system_volume_get_root (GtkFileSystemVolume *volume)
{
GFile *file = NULL;
DEBUG ("volume_get_base");
if (IS_ROOT_VOLUME (volume))
return g_file_new_for_uri ("file:///");
if (G_IS_MOUNT (volume))
file = g_mount_get_root (G_MOUNT (volume));
else if (G_IS_VOLUME (volume))
{
GMount *mount;
mount = g_volume_get_mount (G_VOLUME (volume));
if (mount)
{
file = g_mount_get_root (mount);
g_object_unref (mount);
}
}
return file;
}
GIcon *
_gtk_file_system_volume_get_icon (GtkFileSystemVolume *volume)
{
GIcon *icon = NULL;
if (IS_ROOT_VOLUME (volume))
icon = g_themed_icon_new ("drive-harddisk");
else if (G_IS_DRIVE (volume))
icon = g_drive_get_icon (G_DRIVE (volume));
else if (G_IS_VOLUME (volume))
icon = g_volume_get_icon (G_VOLUME (volume));
else if (G_IS_MOUNT (volume))
icon = g_mount_get_icon (G_MOUNT (volume));
return icon;
}
GIcon *
_gtk_file_system_volume_get_symbolic_icon (GtkFileSystemVolume *volume)
{
if (IS_ROOT_VOLUME (volume))
return g_themed_icon_new ("drive-harddisk-symbolic");
else if (G_IS_DRIVE (volume))
return g_drive_get_symbolic_icon (G_DRIVE (volume));
else if (G_IS_VOLUME (volume))
return g_volume_get_symbolic_icon (G_VOLUME (volume));
else if (G_IS_MOUNT (volume))
return g_mount_get_symbolic_icon (G_MOUNT (volume));
else
return NULL;
}
GtkFileSystemVolume *
_gtk_file_system_volume_ref (GtkFileSystemVolume *volume)
{
if (IS_ROOT_VOLUME (volume))
return volume;
if (G_IS_MOUNT (volume) ||
G_IS_VOLUME (volume) ||
G_IS_DRIVE (volume))
g_object_ref (volume);
return volume;
}
void
_gtk_file_system_volume_unref (GtkFileSystemVolume *volume)
{
/* Root volume doesn't need to be freed */
if (IS_ROOT_VOLUME (volume))
return;
if (G_IS_MOUNT (volume) ||
G_IS_VOLUME (volume) ||
G_IS_DRIVE (volume))
g_object_unref (volume);
}
/* GFileInfo helper functions */
GIcon *
_gtk_file_info_get_icon (GFileInfo *info,
int icon_size,
int scale)
{
GIcon *icon;
GdkPixbuf *pixbuf;
const gchar *thumbnail_path;
thumbnail_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
if (thumbnail_path)
{
pixbuf = gdk_pixbuf_new_from_file_at_size (thumbnail_path,
icon_size*scale, icon_size*scale,
NULL);
if (pixbuf != NULL)
return G_ICON (pixbuf);
}
icon = g_file_info_get_icon (info);
if (icon)
return g_object_ref (icon);
/* Use general fallback for all files without icon */
icon = g_themed_icon_new ("text-x-generic");
return icon;
}
gboolean
_gtk_file_info_consider_as_directory (GFileInfo *info)
{
GFileType type = g_file_info_get_file_type (info);
return (type == G_FILE_TYPE_DIRECTORY ||
type == G_FILE_TYPE_MOUNTABLE ||
type == G_FILE_TYPE_SHORTCUT);
}
gboolean
_gtk_file_has_native_path (GFile *file)
{
char *local_file_path;
gboolean has_native_path;
/* Don't use g_file_is_native(), as we want to support FUSE paths if available */
local_file_path = g_file_get_path (file);
has_native_path = (local_file_path != NULL);
g_free (local_file_path);
return has_native_path;
}
gboolean
_gtk_file_consider_as_remote (GFile *file)
{
GFileInfo *info;
gboolean is_remote;
info = g_file_query_filesystem_info (file, G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE, NULL, NULL);
if (info)
{
is_remote = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE);
g_object_unref (info);
}
else
is_remote = FALSE;
return is_remote;
}

View File

@ -1,116 +0,0 @@
/* GTK - The GIMP Toolkit
* gtkfilesystem.h: Filesystem abstraction functions.
* Copyright (C) 2003, Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GTK_FILE_SYSTEM_H__
#define __GTK_FILE_SYSTEM_H__
#include <gio/gio.h>
#include <gtk/gtkwidget.h> /* For icon handling */
G_BEGIN_DECLS
#define GTK_TYPE_FILE_SYSTEM (_gtk_file_system_get_type ())
#define GTK_FILE_SYSTEM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_FILE_SYSTEM, GtkFileSystem))
#define GTK_FILE_SYSTEM_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), GTK_TYPE_FILE_SYSTEM, GtkFileSystemClass))
#define GTK_IS_FILE_SYSTEM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_FILE_SYSTEM))
#define GTK_IS_FILE_SYSTEM_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), GTK_TYPE_FILE_SYSTEM))
#define GTK_FILE_SYSTEM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_FILE_SYSTEM, GtkFileSystemClass))
typedef struct GtkFileSystem GtkFileSystem;
typedef struct GtkFileSystemPrivate GtkFileSystemPrivate;
typedef struct GtkFileSystemClass GtkFileSystemClass;
typedef struct GtkFileSystemVolume GtkFileSystemVolume; /* opaque struct */
struct GtkFileSystem
{
GObject parent_object;
GtkFileSystemPrivate *priv;
};
struct GtkFileSystemClass
{
GObjectClass parent_class;
void (*volumes_changed) (GtkFileSystem *file_system);
};
typedef void (* GtkFileSystemGetInfoCallback) (GCancellable *cancellable,
GFileInfo *file_info,
const GError *error,
gpointer data);
typedef void (* GtkFileSystemVolumeMountCallback) (GCancellable *cancellable,
GtkFileSystemVolume *volume,
const GError *error,
gpointer data);
/* GtkFileSystem methods */
GType _gtk_file_system_get_type (void) G_GNUC_CONST;
GtkFileSystem * _gtk_file_system_new (void);
GSList * _gtk_file_system_list_volumes (GtkFileSystem *file_system);
GCancellable * _gtk_file_system_get_info (GtkFileSystem *file_system,
GFile *file,
const gchar *attributes,
GtkFileSystemGetInfoCallback callback,
gpointer data);
GCancellable * _gtk_file_system_mount_volume (GtkFileSystem *file_system,
GtkFileSystemVolume *volume,
GMountOperation *mount_operation,
GtkFileSystemVolumeMountCallback callback,
gpointer data);
GCancellable * _gtk_file_system_mount_enclosing_volume (GtkFileSystem *file_system,
GFile *file,
GMountOperation *mount_operation,
GtkFileSystemVolumeMountCallback callback,
gpointer data);
GtkFileSystemVolume * _gtk_file_system_get_volume_for_file (GtkFileSystem *file_system,
GFile *file);
/* GtkFileSystemVolume methods */
gchar * _gtk_file_system_volume_get_display_name (GtkFileSystemVolume *volume);
gboolean _gtk_file_system_volume_is_mounted (GtkFileSystemVolume *volume);
GFile * _gtk_file_system_volume_get_root (GtkFileSystemVolume *volume);
GIcon * _gtk_file_system_volume_get_symbolic_icon (GtkFileSystemVolume *volume);
GIcon * _gtk_file_system_volume_get_icon (GtkFileSystemVolume *volume);
GtkFileSystemVolume *_gtk_file_system_volume_ref (GtkFileSystemVolume *volume);
void _gtk_file_system_volume_unref (GtkFileSystemVolume *volume);
/* GFileInfo helper functions */
GIcon * _gtk_file_info_get_icon (GFileInfo *info,
int icon_size,
int scale);
gboolean _gtk_file_info_consider_as_directory (GFileInfo *info);
/* GFile helper functions */
gboolean _gtk_file_has_native_path (GFile *file);
gboolean _gtk_file_consider_as_remote (GFile *file);
G_END_DECLS
#endif /* __GTK_FILE_SYSTEM_H__ */

View File

@ -23,7 +23,7 @@
#include <stdlib.h>
#include <string.h>
#include "gtkfilesystem.h"
#include "gtkfilechooserutils.h"
#include "gtkintl.h"
#include "gtkmarshalers.h"
#include "gtktreedatalist.h"

View File

@ -28,7 +28,6 @@
#include "gtkfilechooserwidgetprivate.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooserembed.h"
#include "gtkfilesystem.h"
#include "gtksizerequest.h"
#include "gtktypebuiltins.h"
#include "gtkintl.h"

File diff suppressed because it is too large Load Diff

View File

@ -19,43 +19,20 @@
#define __GTK_PATH_BAR_H__
#include "gtkwidget.h"
#include "gtkfilesystem.h"
G_BEGIN_DECLS
typedef struct _GtkPathBar GtkPathBar;
typedef struct _GtkPathBarClass GtkPathBarClass;
#define GTK_TYPE_PATH_BAR (gtk_path_bar_get_type ())
#define GTK_PATH_BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_PATH_BAR, GtkPathBar))
#define GTK_IS_PATH_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_PATH_BAR))
#define GTK_TYPE_PATH_BAR (gtk_path_bar_get_type ())
#define GTK_PATH_BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_PATH_BAR, GtkPathBar))
#define GTK_PATH_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_PATH_BAR, GtkPathBarClass))
#define GTK_IS_PATH_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_PATH_BAR))
#define GTK_IS_PATH_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_PATH_BAR))
#define GTK_PATH_BAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_PATH_BAR, GtkPathBarClass))
struct _GtkPathBar
{
GtkWidget parent_instance;
};
struct _GtkPathBarClass
{
GtkWidgetClass parent_class;
void (* path_clicked) (GtkPathBar *path_bar,
GFile *file,
GFile *child_file,
gboolean child_is_hidden);
};
typedef struct _GtkPathBar GtkPathBar;
GDK_AVAILABLE_IN_ALL
GType gtk_path_bar_get_type (void) G_GNUC_CONST;
void _gtk_path_bar_set_file_system (GtkPathBar *path_bar,
GtkFileSystem *file_system);
void _gtk_path_bar_set_file (GtkPathBar *path_bar,
GFile *file,
gboolean keep_trail);
GFile *file,
gboolean keep_trail);
void _gtk_path_bar_up (GtkPathBar *path_bar);
void _gtk_path_bar_down (GtkPathBar *path_bar);

View File

@ -33,7 +33,7 @@
#include "gdk/gdkkeysyms.h"
#include "gtkbookmarksmanagerprivate.h"
#include "gtkcelllayout.h"
#include "gtkfilesystem.h"
#include "gtkfilechooserutils.h"
#include "gtkicontheme.h"
#include "gtkintl.h"
#include "gtkmain.h"

View File

@ -105,7 +105,6 @@ gtk_private_sources = files([
'gtkfilechoosererrorstack.c',
'gtkfilechoosernativeportal.c',
'gtkfilechooserutils.c',
'gtkfilesystem.c',
'gtkfilesystemmodel.c',
'gtkgizmo.c',
'gtkgladecatalog.c',