gedit r6259 - in branches/gnome-2-22: . gedit plugins/filebrowser
- From: jessevdk svn gnome org
- To: svn-commits-list gnome org
- Subject: gedit r6259 - in branches/gnome-2-22: . gedit plugins/filebrowser
- Date: Mon, 5 May 2008 10:24:33 +0100 (BST)
Author: jessevdk
Date: Mon May 5 09:24:33 2008
New Revision: 6259
URL: http://svn.gnome.org/viewvc/gedit?rev=6259&view=rev
Log:
Branch for 2.22
Added:
branches/gnome-2-22/
- copied from r6257, /trunk/
Modified:
branches/gnome-2-22/gedit/gedit.c
branches/gnome-2-22/plugins/filebrowser/gedit-file-bookmarks-store.c
branches/gnome-2-22/plugins/filebrowser/gedit-file-bookmarks-store.h
branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-marshal.list
branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-plugin.c
branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-store.c
branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-store.h
branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-utils.c
branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-utils.h
branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-view.c
branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-widget.c
branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-widget.h
Modified: branches/gnome-2-22/gedit/gedit.c
==============================================================================
--- /trunk/gedit/gedit.c (original)
+++ branches/gnome-2-22/gedit/gedit.c Mon May 5 09:24:33 2008
@@ -480,7 +480,7 @@
gedit_debug_message (DEBUG_APP, "Create bacon connection");
- connection = bacon_message_connection_new ("gedit");
+ connection = bacon_message_connection_new ("gedit-svn");
if (connection != NULL)
{
Modified: branches/gnome-2-22/plugins/filebrowser/gedit-file-bookmarks-store.c
==============================================================================
--- /trunk/plugins/filebrowser/gedit-file-bookmarks-store.c (original)
+++ branches/gnome-2-22/plugins/filebrowser/gedit-file-bookmarks-store.c Mon May 5 09:24:33 2008
@@ -21,7 +21,7 @@
#include <string.h>
#include <glib/gi18n.h>
-#include <libgnomevfs/gnome-vfs.h>
+#include <gio/gio.h>
#include <gedit/gedit-utils.h>
#include <gedit/gedit-plugin.h>
@@ -34,24 +34,23 @@
struct _GeditFileBookmarksStorePrivate
{
- GnomeVFSVolumeMonitor *volume_monitor;
- GnomeVFSMonitorHandle *bookmarks_monitor;
+ GVolumeMonitor * volume_monitor;
+ GFileMonitor * bookmarks_monitor;
};
static void remove_node (GtkTreeModel * model,
- GtkTreeIter * iter,
- gboolean fromtree);
+ GtkTreeIter * iter);
-static void on_volume_mounted (GnomeVFSVolumeMonitor * monitor,
- GnomeVFSVolume * volume,
+static void on_mount_added (GVolumeMonitor * monitor,
+ GMount * mount,
GeditFileBookmarksStore * model);
-static void on_volume_unmounted (GnomeVFSVolumeMonitor * monitor,
- GnomeVFSVolume * volume,
+static void on_mount_removed (GVolumeMonitor * monitor,
+ GMount * mount,
GeditFileBookmarksStore * model);
-static void on_bookmarks_file_changed (GnomeVFSMonitorHandle * handle,
- gchar const *monitor_uri,
- gchar const *info_uri,
- GnomeVFSMonitorEventType event_type,
+static void on_bookmarks_file_changed (GFileMonitor * monitor,
+ GFile * file,
+ GFile * other_file,
+ GFileMonitorEvent event_type,
GeditFileBookmarksStore * model);
static gboolean find_with_flags (GtkTreeModel * model,
GtkTreeIter * iter,
@@ -68,36 +67,24 @@
if (obj->priv->volume_monitor != NULL) {
g_signal_handlers_disconnect_by_func (obj->priv->volume_monitor,
- on_volume_mounted,
+ on_mount_added,
obj);
g_signal_handlers_disconnect_by_func (obj->priv->volume_monitor,
- on_volume_unmounted,
+ on_mount_removed,
obj);
- obj->priv->volume_monitor = NULL;
+ g_object_unref (obj->priv->volume_monitor);
}
if (obj->priv->bookmarks_monitor != NULL) {
- gnome_vfs_monitor_cancel (obj->priv->bookmarks_monitor);
+ g_object_unref (obj->priv->bookmarks_monitor);
}
G_OBJECT_CLASS (gedit_file_bookmarks_store_parent_class)->dispose (object);
}
-static gboolean
-foreach_remove_node (GtkTreeModel * model, GtkTreePath * path,
- GtkTreeIter * iter, gpointer user_data)
-{
- remove_node (model, iter, FALSE);
- return FALSE;
-}
-
static void
gedit_file_bookmarks_store_finalize (GObject * object)
{
- GeditFileBookmarksStore *obj = GEDIT_FILE_BOOKMARKS_STORE (object);
-
- gtk_tree_model_foreach (GTK_TREE_MODEL (obj), foreach_remove_node, NULL);
-
G_OBJECT_CLASS (gedit_file_bookmarks_store_parent_class)->finalize (object);
}
@@ -119,13 +106,6 @@
}
/* Private */
-static GdkPixbuf *
-pixbuf_from_stock (const gchar * stock)
-{
- return gedit_file_browser_utils_pixbuf_from_theme(stock,
- GTK_ICON_SIZE_MENU);
-}
-
static void
add_node (GeditFileBookmarksStore * model, GdkPixbuf * pixbuf,
gchar const *name, gpointer obj, guint flags, GtkTreeIter * iter)
@@ -146,236 +126,219 @@
}
static gboolean
-add_uri (GeditFileBookmarksStore * model, const gchar * uri,
- gchar * name, guint flags, GtkTreeIter * iter)
+add_file (GeditFileBookmarksStore * model, GFile * file,
+ gchar const * name, guint flags, GtkTreeIter * iter)
{
- GnomeVFSURI *vfs_uri;
- GdkPixbuf *pixbuf = NULL;
- gchar *mime;
- gchar *path;
- gchar *tmp;
- gboolean free_name = FALSE;
- gboolean local;
+ GdkPixbuf * pixbuf = NULL;
+ gboolean native;
+ gchar * newname;
- vfs_uri = gnome_vfs_uri_new (uri);
- if (vfs_uri == NULL)
- return FALSE;
-
- path = gnome_vfs_uri_to_string (vfs_uri, GNOME_VFS_URI_HIDE_NONE);
- local = gedit_utils_uri_has_file_scheme (path);
+ native = g_file_is_native (file);
- if (local && !gnome_vfs_uri_exists (vfs_uri)) {
- gnome_vfs_uri_unref (vfs_uri);
- g_free (path);
+ if (native && !g_file_query_exists (file, NULL)) {
return FALSE;
}
if (flags & GEDIT_FILE_BOOKMARKS_STORE_IS_HOME)
- pixbuf = pixbuf_from_stock ("gnome-fs-home");
+ pixbuf = gedit_file_browser_utils_pixbuf_from_theme ("gnome-fs-home", GTK_ICON_SIZE_MENU);
else if (flags & GEDIT_FILE_BOOKMARKS_STORE_IS_DESKTOP)
- pixbuf = pixbuf_from_stock ("gnome-fs-desktop");
+ pixbuf = gedit_file_browser_utils_pixbuf_from_theme ("gnome-fs-desktop", GTK_ICON_SIZE_MENU);
+ else if (flags & GEDIT_FILE_BOOKMARKS_STORE_IS_ROOT)
+ pixbuf = gedit_file_browser_utils_pixbuf_from_theme ("drive-harddisk", GTK_ICON_SIZE_MENU);
if (pixbuf == NULL) {
- if (local)
- mime = gnome_vfs_get_mime_type (path);
- else
- mime = g_strdup ("x-directory/normal");
-
- pixbuf = gedit_file_browser_utils_pixbuf_from_mime_type (path,
- mime,
- GTK_ICON_SIZE_MENU);
- g_free (mime);
+ pixbuf = gedit_file_browser_utils_pixbuf_from_file (file, GTK_ICON_SIZE_MENU);
}
- g_free (path);
-
if (name == NULL) {
- tmp = gedit_file_browser_utils_uri_basename (gnome_vfs_uri_get_path (vfs_uri));
-
- if (local)
- name = tmp;
- else {
- /* Translators: this is used in "file on host", e.g. "/foo/bar on ftp.baz.org" */
- name = g_strconcat(tmp, " ", _("on"), " ", gnome_vfs_uri_get_host_name (vfs_uri), NULL);
- g_free (tmp);
- }
-
- free_name = TRUE;
+ newname = gedit_file_browser_utils_file_basename (file);
+ } else {
+ newname = g_strdup (name);
}
- add_node (model, pixbuf, name, vfs_uri, flags, iter);
+ add_node (model, pixbuf, newname, file, flags, iter);
if (pixbuf)
g_object_unref (pixbuf);
- if (free_name)
- g_free (name);
+ g_free (newname);
return TRUE;
}
static void
+check_mount_separator (GeditFileBookmarksStore * model, guint flags,
+ gboolean added)
+{
+ GtkTreeIter iter;
+ gboolean found;
+
+ found =
+ find_with_flags (GTK_TREE_MODEL (model), &iter, NULL,
+ flags |
+ GEDIT_FILE_BOOKMARKS_STORE_IS_SEPARATOR, 0);
+
+ if (added && !found) {
+ /* Add the separator */
+ add_node (model, NULL, NULL, NULL,
+ flags | GEDIT_FILE_BOOKMARKS_STORE_IS_SEPARATOR,
+ NULL);
+ } else if (!added && found) {
+ remove_node (GTK_TREE_MODEL (model), &iter);
+ }
+}
+
+static void
init_special_directories (GeditFileBookmarksStore * model)
{
gchar const *path;
- gchar *uri;
+ GFile * file;
path = g_get_home_dir ();
if (path != NULL)
{
- uri = gnome_vfs_get_uri_from_local_path (path);
- add_uri (model, uri, NULL, GEDIT_FILE_BOOKMARKS_STORE_IS_HOME |
+ file = g_file_new_for_path (path);
+ add_file (model, file, NULL, GEDIT_FILE_BOOKMARKS_STORE_IS_HOME |
GEDIT_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, NULL);
- g_free (uri);
+ g_object_unref (file);
}
path = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
if (path != NULL)
{
- uri = gnome_vfs_get_uri_from_local_path (path);
- add_uri (model, uri, NULL, GEDIT_FILE_BOOKMARKS_STORE_IS_DESKTOP |
- GEDIT_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, NULL);
- g_free (uri);
+ file = g_file_new_for_path (path);
+ add_file (model, file, NULL, GEDIT_FILE_BOOKMARKS_STORE_IS_DESKTOP |
+ GEDIT_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, NULL);
+ g_object_unref (file);
}
path = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
if (path != NULL)
{
- uri = gnome_vfs_get_uri_from_local_path (path);
- add_uri (model, uri, NULL, GEDIT_FILE_BOOKMARKS_STORE_IS_DOCUMENTS |
+ file = g_file_new_for_path (path);
+ add_file (model, file, NULL, GEDIT_FILE_BOOKMARKS_STORE_IS_DOCUMENTS |
GEDIT_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, NULL);
- g_free (uri);
+ g_object_unref (file);
}
+
+ file = g_file_new_for_uri ("file:///");
+ add_file (model, file, _("File System"), GEDIT_FILE_BOOKMARKS_STORE_IS_ROOT, NULL);
+ g_object_unref (file);
+
+ check_mount_separator (model, GEDIT_FILE_BOOKMARKS_STORE_IS_ROOT, TRUE);
}
static void
-check_volume_separator (GeditFileBookmarksStore * model, guint flags,
- gboolean added)
+add_mount (GeditFileBookmarksStore * model, GMount * mount,
+ const gchar * name, guint flags, GtkTreeIter * iter)
{
- GtkTreeIter iter;
- gboolean found;
-
- found =
- find_with_flags (GTK_TREE_MODEL (model), &iter, NULL,
- flags |
- GEDIT_FILE_BOOKMARKS_STORE_IS_SEPARATOR, 0);
+ GdkPixbuf *pixbuf = NULL;
+ GIcon *icon;
- if (added && !found) {
- /* Add the separator */
- add_node (model, NULL, NULL, NULL,
- flags | GEDIT_FILE_BOOKMARKS_STORE_IS_SEPARATOR,
- NULL);
- } else if (!added && found) {
- remove_node (GTK_TREE_MODEL (model), &iter, TRUE);
+ icon = g_mount_get_icon (mount);
+
+ if (icon) {
+ pixbuf = gedit_file_browser_utils_pixbuf_from_icon (icon, GTK_ICON_SIZE_MENU);
+ g_object_unref (icon);
}
-}
-
-static void
-add_volume (GeditFileBookmarksStore * model, GnomeVFSVolume * volume,
- const gchar * name, guint flags, GtkTreeIter * iter)
-{
- GdkPixbuf *pixbuf;
- gchar *icon;
-
- icon = gnome_vfs_volume_get_icon (volume);
- pixbuf = pixbuf_from_stock (icon);
- g_free (icon);
- add_node (model, pixbuf, name, volume,
- flags | GEDIT_FILE_BOOKMARKS_STORE_IS_VOLUME, iter);
+ add_node (model, pixbuf, name, mount,
+ flags | GEDIT_FILE_BOOKMARKS_STORE_IS_MOUNT, iter);
if (pixbuf)
g_object_unref (pixbuf);
- flags = flags & (GEDIT_FILE_BOOKMARKS_STORE_IS_DRIVE |
- GEDIT_FILE_BOOKMARKS_STORE_IS_MOUNT |
- GEDIT_FILE_BOOKMARKS_STORE_IS_REMOTE_MOUNT);
-
- if (flags)
- check_volume_separator (model, flags, TRUE);
+ check_mount_separator (model, GEDIT_FILE_BOOKMARKS_STORE_IS_MOUNT, TRUE);
}
-static gboolean
-process_volume (GeditFileBookmarksStore * model, GnomeVFSVolume * volume,
- gboolean * root)
+static void
+process_mount (GeditFileBookmarksStore * model, GMount * mount,
+ gboolean * isroot)
{
- GnomeVFSVolumeType vtype;
- guint flags;
-
- vtype = gnome_vfs_volume_get_volume_type (volume);
-
- if (gnome_vfs_volume_get_device_type (volume) ==
- GNOME_VFS_DEVICE_TYPE_AUDIO_CD)
- return FALSE;
-
- if (gnome_vfs_volume_is_user_visible (volume)) {
- gchar *name;
-
- if (vtype == GNOME_VFS_VOLUME_TYPE_VFS_MOUNT)
- flags = GEDIT_FILE_BOOKMARKS_STORE_IS_DRIVE;
- else if (vtype == GNOME_VFS_VOLUME_TYPE_MOUNTPOINT)
- flags = GEDIT_FILE_BOOKMARKS_STORE_IS_MOUNT;
- else
- flags = GEDIT_FILE_BOOKMARKS_STORE_IS_REMOTE_MOUNT;
-
- name = gnome_vfs_volume_get_display_name (volume);
-
- add_volume (model, volume, name, flags, NULL);
-
- g_free (name);
- } else if (root && !*root) {
- gchar *uri;
-
- uri = gnome_vfs_volume_get_activation_uri (volume);
-
- if (strcmp (uri, "file:///") == 0) {
- *root = TRUE;
+ guint flags = GEDIT_FILE_BOOKMARKS_STORE_NONE;
+ GFile * root;
+ GFileInfo * info;
+ gchar * name;
+ gboolean local;
- add_volume (model, volume, _("File System"),
- GEDIT_FILE_BOOKMARKS_STORE_IS_ROOT |
- GEDIT_FILE_BOOKMARKS_STORE_IS_DRIVE,
- NULL);
+ root = g_mount_get_root (mount);
+
+ if (!root)
+ return;
+
+ info = g_file_query_info (root, G_FILE_ATTRIBUTE_ACCESS_CAN_READ, G_FILE_QUERY_INFO_NONE, NULL, NULL);
+
+ /* Is this mount actually readable by the user */
+ if (info && g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ)) {
+ /* Here we set up the flags for the mount */
+ local = g_file_is_native (root);
+
+ if (local) {
+ flags |= GEDIT_FILE_BOOKMARKS_STORE_IS_LOCAL_MOUNT;
+ } else {
+ flags |= GEDIT_FILE_BOOKMARKS_STORE_IS_REMOTE_MOUNT;
}
-
- g_free (uri);
- } else {
- return FALSE;
+
+ name = g_mount_get_name (mount);
+ add_mount (model, mount, name, flags, NULL);
+ g_free (name);
}
-
- return TRUE;
+
+ if (info)
+ g_object_unref (info);
+
+ g_object_unref (root);
}
static void
-init_volumes (GeditFileBookmarksStore * model)
+init_mounts (GeditFileBookmarksStore * model)
{
- GList *volumes;
- GList *item;
- GnomeVFSVolume *volume;
+ GList * mounts;
+ GList * item;
gboolean root = FALSE;
if (model->priv->volume_monitor == NULL) {
- model->priv->volume_monitor =
- gnome_vfs_get_volume_monitor ();
+ model->priv->volume_monitor = g_volume_monitor_get ();
/* Connect signals */
g_signal_connect (model->priv->volume_monitor,
- "volume-mounted",
- G_CALLBACK (on_volume_mounted), model);
+ "mount-added",
+ G_CALLBACK (on_mount_added), model);
g_signal_connect (model->priv->volume_monitor,
- "volume-unmounted",
- G_CALLBACK (on_volume_unmounted), model);
+ "mount-removed",
+ G_CALLBACK (on_mount_removed), model);
}
- volumes =
- gnome_vfs_volume_monitor_get_mounted_volumes (model->priv->
- volume_monitor);
+ mounts = g_volume_monitor_get_mounts (model->priv->volume_monitor);
+
+ for (item = mounts; item; item = item->next)
+ process_mount (model, G_MOUNT(item->data), &root);
- for (item = volumes; item; item = item->next) {
- volume = GNOME_VFS_VOLUME (item->data);
- process_volume (model, volume, &root);
+ g_list_foreach (mounts, (GFunc)g_object_unref, NULL);
+ g_list_free (mounts);
+}
+
+static gboolean
+add_bookmark (GeditFileBookmarksStore * model,
+ gchar const * name,
+ gchar const * uri)
+{
+ GFile * file;
+ gboolean ret;
+ guint flags = GEDIT_FILE_BOOKMARKS_STORE_IS_BOOKMARK;
+
+ file = g_file_new_for_uri (uri);
+
+ if (g_file_is_native (file)) {
+ flags |= GEDIT_FILE_BOOKMARKS_STORE_IS_LOCAL_BOOKMARK;
+ } else {
+ flags |= GEDIT_FILE_BOOKMARKS_STORE_IS_REMOTE_BOOKMARK;
}
- g_list_free (volumes);
+ ret = add_file (model, file, name, flags, NULL);
+ g_object_unref (file);
+
+ return ret;
}
static void
@@ -387,6 +350,7 @@
gchar **lines;
gchar **line;
gboolean added = FALSE;
+ GFile * file;
/* Read the bookmarks file */
bookmarks = g_build_filename (g_get_home_dir (),
@@ -401,7 +365,7 @@
gchar *pos;
gchar *name;
- /* Check, is this really utf8? */
+ /* CHECK: is this really utf8? */
pos = g_utf8_strchr (*line, -1, ' ');
if (pos != NULL) {
@@ -414,11 +378,7 @@
/* the bookmarks file should contain valid
* URIs, but paranoia is good */
if (gedit_utils_is_valid_uri (*line)) {
- added = add_uri (model,
- *line,
- name,
- GEDIT_FILE_BOOKMARKS_STORE_IS_BOOKMARK,
- NULL);
+ added |= add_bookmark (model, name, *line);
}
}
}
@@ -428,11 +388,12 @@
/* Add a watch */
if (model->priv->bookmarks_monitor == NULL) {
- gnome_vfs_monitor_add (&model->priv->bookmarks_monitor,
- bookmarks,
- GNOME_VFS_MONITOR_FILE,
- (GnomeVFSMonitorCallback)on_bookmarks_file_changed,
- model);
+ file = g_file_new_for_path (bookmarks);
+ model->priv->bookmarks_monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL);
+ g_signal_connect (model->priv->bookmarks_monitor,
+ "changed",
+ (GCallback)on_bookmarks_file_changed,
+ model);
}
} else {
/* The bookmarks file doesn't exist (which is perfectly fine) */
@@ -453,11 +414,10 @@
GEDIT_FILE_BOOKMARKS_STORE_IS_HOME,
GEDIT_FILE_BOOKMARKS_STORE_IS_DESKTOP,
GEDIT_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR,
- GEDIT_FILE_BOOKMARKS_STORE_IS_DRIVE,
GEDIT_FILE_BOOKMARKS_STORE_IS_ROOT,
GEDIT_FILE_BOOKMARKS_STORE_IS_MOUNT,
- GEDIT_FILE_BOOKMARKS_STORE_IS_REMOTE_MOUNT,
- GEDIT_FILE_BOOKMARKS_STORE_IS_VOLUME,
+ GEDIT_FILE_BOOKMARKS_STORE_IS_LOCAL_MOUNT,
+ GEDIT_FILE_BOOKMARKS_STORE_IS_BOOKMARK,
-1
};
@@ -565,8 +525,9 @@
{
GtkTreeIter child;
guint childflags = 0;
- gpointer childobj;
-
+ GObject * childobj;
+ gboolean fequal;
+
if (!gtk_tree_model_get_iter_first (model, &child))
return FALSE;
@@ -576,8 +537,13 @@
&childobj,
GEDIT_FILE_BOOKMARKS_STORE_COLUMN_FLAGS,
&childflags, -1);
-
- if ((obj == NULL || childobj == obj) &&
+
+ fequal = (obj == childobj);
+
+ if (childobj)
+ g_object_unref (childobj);
+
+ if ((obj == NULL || fequal) &&
(childflags & flags) == flags
&& !(childflags & notflags)) {
*iter = child;
@@ -589,38 +555,23 @@
}
static void
-remove_node (GtkTreeModel * model, GtkTreeIter * iter, gboolean fromtree)
+remove_node (GtkTreeModel * model, GtkTreeIter * iter)
{
- gpointer obj;
guint flags;
gtk_tree_model_get (model, iter,
- GEDIT_FILE_BOOKMARKS_STORE_COLUMN_FLAGS,
- &flags,
- GEDIT_FILE_BOOKMARKS_STORE_COLUMN_OBJECT, &obj,
+ GEDIT_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, &flags,
-1);
if (!(flags & GEDIT_FILE_BOOKMARKS_STORE_IS_SEPARATOR)) {
- if (flags & GEDIT_FILE_BOOKMARKS_STORE_IS_VOLUME) {
- gnome_vfs_volume_unref (GNOME_VFS_VOLUME (obj));
-
- if (fromtree)
- check_volume_separator
- (GEDIT_FILE_BOOKMARKS_STORE (model),
- flags &
- (GEDIT_FILE_BOOKMARKS_STORE_IS_DRIVE |
- GEDIT_FILE_BOOKMARKS_STORE_IS_MOUNT),
- FALSE);
- } else if ((flags &
- GEDIT_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR) ||
- (flags &
- GEDIT_FILE_BOOKMARKS_STORE_IS_BOOKMARK)) {
- gnome_vfs_uri_unref ((GnomeVFSURI *) obj);
+ if (flags & GEDIT_FILE_BOOKMARKS_STORE_IS_MOUNT) {
+ check_mount_separator (GEDIT_FILE_BOOKMARKS_STORE (model),
+ flags & GEDIT_FILE_BOOKMARKS_STORE_IS_MOUNT,
+ FALSE);
}
}
- if (fromtree)
- gtk_tree_store_remove (GTK_TREE_STORE (model), iter);
+ gtk_tree_store_remove (GTK_TREE_STORE (model), iter);
}
static void
@@ -631,7 +582,7 @@
while (find_with_flags (GTK_TREE_MODEL (model), &iter, NULL,
GEDIT_FILE_BOOKMARKS_STORE_IS_BOOKMARK,
0)) {
- remove_node (GTK_TREE_MODEL (model), &iter, TRUE);
+ remove_node (GTK_TREE_MODEL (model), &iter);
}
}
@@ -639,7 +590,7 @@
initialize_fill (GeditFileBookmarksStore * model)
{
init_special_directories (model);
- init_volumes (model);
+ init_mounts (model);
init_bookmarks (model);
}
@@ -651,7 +602,7 @@
GType column_types[] = {
GDK_TYPE_PIXBUF,
G_TYPE_STRING,
- G_TYPE_POINTER,
+ G_TYPE_OBJECT,
G_TYPE_UINT
};
@@ -676,9 +627,11 @@
gedit_file_bookmarks_store_get_uri (GeditFileBookmarksStore * model,
GtkTreeIter * iter)
{
- gpointer obj;
+ GObject * obj;
+ GFile * file = NULL;
guint flags;
-
+ gchar * ret = NULL;
+
g_return_val_if_fail (GEDIT_IS_FILE_BOOKMARKS_STORE (model), NULL);
g_return_val_if_fail (iter != NULL, NULL);
@@ -691,73 +644,70 @@
if (obj == NULL)
return NULL;
- if (!(flags & GEDIT_FILE_BOOKMARKS_STORE_IS_SEPARATOR)) {
- if (flags & GEDIT_FILE_BOOKMARKS_STORE_IS_VOLUME) {
- return
- gnome_vfs_volume_get_activation_uri
- (GNOME_VFS_VOLUME (obj));
- } else
- if ((flags & GEDIT_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR)
- || (flags &
- GEDIT_FILE_BOOKMARKS_STORE_IS_BOOKMARK)) {
- return gnome_vfs_uri_to_string ((GnomeVFSURI *)
- obj,
- GNOME_VFS_URI_HIDE_NONE);
- }
+ if (flags & GEDIT_FILE_BOOKMARKS_STORE_IS_MOUNT) {
+ file = g_mount_get_root (G_MOUNT (obj));
+ } else {
+ file = g_object_ref (obj);
}
-
- return NULL;
+
+ g_object_unref (obj);
+
+ if (file) {
+ ret = g_file_get_uri (file);
+ g_object_unref (file);
+ }
+
+ return ret;
}
void
gedit_file_bookmarks_store_refresh (GeditFileBookmarksStore * model)
{
- gtk_tree_model_foreach (GTK_TREE_MODEL (model), foreach_remove_node,
- NULL);
-
gtk_tree_store_clear (GTK_TREE_STORE (model));
initialize_fill (model);
}
/* Signal handlers */
static void
-on_volume_mounted (GnomeVFSVolumeMonitor * monitor,
- GnomeVFSVolume * volume,
- GeditFileBookmarksStore * model)
+on_mount_added (GVolumeMonitor * monitor,
+ GMount * mount,
+ GeditFileBookmarksStore * model)
{
- if (process_volume (model, volume, NULL))
- gnome_vfs_volume_ref (volume);
+ process_mount (model, mount, NULL);
}
static void
-on_volume_unmounted (GnomeVFSVolumeMonitor * monitor,
- GnomeVFSVolume * volume,
- GeditFileBookmarksStore * model)
+on_mount_removed (GVolumeMonitor * monitor,
+ GMount * mount,
+ GeditFileBookmarksStore * model)
{
GtkTreeIter iter;
- /* Find the volume and remove it */
- if (find_with_flags (GTK_TREE_MODEL (model), &iter, volume,
- GEDIT_FILE_BOOKMARKS_STORE_IS_VOLUME,
+ /* Find the mount and remove it */
+ if (find_with_flags (GTK_TREE_MODEL (model), &iter, mount,
+ GEDIT_FILE_BOOKMARKS_STORE_IS_MOUNT,
GEDIT_FILE_BOOKMARKS_STORE_IS_SEPARATOR))
- remove_node (GTK_TREE_MODEL (model), &iter, TRUE);
+ remove_node (GTK_TREE_MODEL (model), &iter);
}
static void
-on_bookmarks_file_changed (GnomeVFSMonitorHandle * handle,
- gchar const *monitor_uri, gchar const *info_uri,
- GnomeVFSMonitorEventType event_type,
+on_bookmarks_file_changed (GFileMonitor * monitor,
+ GFile * file,
+ GFile * other_file,
+ GFileMonitorEvent event_type,
GeditFileBookmarksStore * model)
{
switch (event_type) {
- case GNOME_VFS_MONITOR_EVENT_CHANGED:
- case GNOME_VFS_MONITOR_EVENT_CREATED:
+ case G_FILE_MONITOR_EVENT_CHANGED:
+ case G_FILE_MONITOR_EVENT_CREATED:
+ /* Re-initialize bookmarks */
remove_bookmarks (model);
init_bookmarks (model);
break;
- case GNOME_VFS_MONITOR_EVENT_DELETED:
+ case G_FILE_MONITOR_EVENT_DELETED: // FIXME: shouldn't we also monitor the directory?
+ /* Remove bookmarks */
remove_bookmarks (model);
- gnome_vfs_monitor_cancel (handle);
+ g_object_unref (monitor);
model->priv->bookmarks_monitor = NULL;
break;
default:
Modified: branches/gnome-2-22/plugins/filebrowser/gedit-file-bookmarks-store.h
==============================================================================
--- /trunk/plugins/filebrowser/gedit-file-bookmarks-store.h (original)
+++ branches/gnome-2-22/plugins/filebrowser/gedit-file-bookmarks-store.h Mon May 5 09:24:33 2008
@@ -48,18 +48,19 @@
enum
{
- GEDIT_FILE_BOOKMARKS_STORE_NONE = 0,
- GEDIT_FILE_BOOKMARKS_STORE_IS_SEPARATOR = 1 << 0,
- GEDIT_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR = 1 << 1,
- GEDIT_FILE_BOOKMARKS_STORE_IS_HOME = 1 << 2,
- GEDIT_FILE_BOOKMARKS_STORE_IS_DESKTOP = 1 << 3,
- GEDIT_FILE_BOOKMARKS_STORE_IS_DOCUMENTS = 1 << 4,
- GEDIT_FILE_BOOKMARKS_STORE_IS_VOLUME = 1 << 5,
- GEDIT_FILE_BOOKMARKS_STORE_IS_ROOT = 1 << 6,
- GEDIT_FILE_BOOKMARKS_STORE_IS_DRIVE = 1 << 7,
- GEDIT_FILE_BOOKMARKS_STORE_IS_MOUNT = 1 << 8,
- GEDIT_FILE_BOOKMARKS_STORE_IS_REMOTE_MOUNT = 1 << 9,
- GEDIT_FILE_BOOKMARKS_STORE_IS_BOOKMARK = 1 << 10
+ GEDIT_FILE_BOOKMARKS_STORE_NONE = 0,
+ GEDIT_FILE_BOOKMARKS_STORE_IS_SEPARATOR = 1 << 0, /* Separator item */
+ GEDIT_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR = 1 << 1, /* Special user dir */
+ GEDIT_FILE_BOOKMARKS_STORE_IS_HOME = 1 << 2, /* The special Home user directory */
+ GEDIT_FILE_BOOKMARKS_STORE_IS_DESKTOP = 1 << 3, /* The special Desktop user directory */
+ GEDIT_FILE_BOOKMARKS_STORE_IS_DOCUMENTS = 1 << 4, /* The special Documents user directory */
+ GEDIT_FILE_BOOKMARKS_STORE_IS_MOUNT = 1 << 5, /* A mount point on file:// */
+ GEDIT_FILE_BOOKMARKS_STORE_IS_REMOTE_MOUNT = 1 << 6, /* A remote mount point (ssh://) */
+ GEDIT_FILE_BOOKMARKS_STORE_IS_LOCAL_MOUNT = 1 << 7, /* A remote mount point (ssh://) */
+ GEDIT_FILE_BOOKMARKS_STORE_IS_ROOT = 1 << 8, /* The root file system (file:///) */
+ GEDIT_FILE_BOOKMARKS_STORE_IS_BOOKMARK = 1 << 9, /* A gtk bookmark */
+ GEDIT_FILE_BOOKMARKS_STORE_IS_REMOTE_BOOKMARK = 1 << 10, /* A remote gtk bookmark */
+ GEDIT_FILE_BOOKMARKS_STORE_IS_LOCAL_BOOKMARK = 1 << 11 /* A local gtk bookmark */
};
struct _GeditFileBookmarksStore
Modified: branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-marshal.list
==============================================================================
--- /trunk/plugins/filebrowser/gedit-file-browser-marshal.list (original)
+++ branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-marshal.list Mon May 5 09:24:33 2008
@@ -1,2 +1,4 @@
VOID:UINT,STRING
BOOL:OBJECT,POINTER
+BOOL:POINTER
+BOOL:VOID
Modified: branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-plugin.c
==============================================================================
--- /trunk/plugins/filebrowser/gedit-file-browser-plugin.c (original)
+++ branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-plugin.c Mon May 5 09:24:33 2008
@@ -94,8 +94,7 @@
GList * rows,
GeditWindow * window);
static gboolean on_confirm_no_trash_cb (GeditFileBrowserWidget * widget,
- GeditFileBrowserStore * store,
- GList * rows,
+ GList * files,
GeditWindow * window);
static void on_end_loading_cb (GeditFileBrowserStore * store,
GtkTreeIter * iter,
@@ -159,7 +158,7 @@
gboolean bookmarks;
gboolean remote;
GConfClient * client;
- GnomeVFSURI * uri = NULL;
+ GFile * file = NULL;
client = gconf_client_get_default ();
@@ -188,9 +187,9 @@
NULL);
if (root != NULL && *root != '\0') {
- uri = gnome_vfs_uri_new (root);
+ file = g_file_new_for_uri (root);
- if (uri == NULL || (!remote && !gedit_utils_uri_has_file_scheme (root))) {
+ if (!remote && !g_file_is_native (file)) {
} else if (virtual_root != NULL && virtual_root != '\0') {
prepare_auto_root(data);
gedit_file_browser_widget_set_root_and_virtual_root (data->tree_widget,
@@ -204,9 +203,6 @@
}
}
- if (uri)
- gnome_vfs_uri_unref (uri);
-
g_object_unref (client);
g_free (root);
g_free (virtual_root);
@@ -412,9 +408,10 @@
set_root_from_doc (GeditFileBrowserPluginData * data,
GeditDocument * doc)
{
- gchar *uri;
- gchar *root;
- GnomeVFSURI *guri;
+ gchar * uri;
+ gchar * root;
+ GFile * parent;
+ GFile * file;
if (doc == NULL)
return;
@@ -423,28 +420,25 @@
if (uri == NULL)
return;
- guri = gnome_vfs_uri_new (uri);
+ file = g_file_new_for_uri (uri);
- if (guri == NULL) {
+ if (file == NULL) {
g_free (uri);
return;
}
- if (gnome_vfs_uri_has_parent (guri)) {
- GnomeVFSURI *parent;
-
- parent = gnome_vfs_uri_get_parent (guri);
- gnome_vfs_uri_unref (guri);
- guri = parent;
+ if ((parent = g_file_get_parent (file))) {
+ g_object_unref (file);
+ file = parent;
}
- root = gnome_vfs_uri_to_string (guri, GNOME_VFS_URI_HIDE_NONE);
+ root = g_file_get_uri (file);
gedit_file_browser_widget_set_root (data->tree_widget,
root,
TRUE);
- gnome_vfs_uri_unref (guri);
+ g_object_unref (file);
g_free (root);
g_free (uri);
}
@@ -493,6 +487,7 @@
gchar * wd = NULL;
gchar * local;
gchar * argv[2];
+ GFile * file;
GtkTreeIter iter;
GeditFileBrowserStore * store;
@@ -514,7 +509,10 @@
return;
terminal = get_terminal ();
- local = gnome_vfs_get_local_path_from_uri (wd);
+
+ file = g_file_new_for_uri (wd);
+ local = g_file_get_path (file);
+ g_object_unref (file);
argv[0] = terminal;
argv[1] = NULL;
@@ -537,13 +535,12 @@
on_selection_changed_cb (GtkTreeSelection *selection,
GeditWindow *window)
{
- GeditFileBrowserPluginData *data;
- GtkTreeView *tree_view;
- GtkTreeModel *model;
+ GeditFileBrowserPluginData * data;
+ GtkTreeView * tree_view;
+ GtkTreeModel * model;
GtkTreeIter iter;
gboolean sensitive;
- GnomeVFSURI *guri;
- gchar *uri;
+ gchar * uri;
data = get_plugin_data (window);
@@ -565,13 +562,7 @@
GEDIT_FILE_BROWSER_STORE_COLUMN_URI,
&uri, -1);
- guri = gnome_vfs_uri_new (uri);
-
- sensitive = guri != NULL && gedit_utils_uri_has_file_scheme (uri);
-
- if (guri)
- gnome_vfs_uri_unref (guri);
-
+ sensitive = gedit_utils_uri_has_file_scheme (uri);
g_free (uri);
}
@@ -1108,8 +1099,7 @@
static gboolean
on_confirm_no_trash_cb (GeditFileBrowserWidget * widget,
- GeditFileBrowserStore * store,
- GList *paths,
+ GList * files,
GeditWindow * window)
{
gchar *normal;
@@ -1122,8 +1112,8 @@
message = _("Cannot move file to trash, do you\nwant to delete permanently?");
- if (paths->next == NULL) {
- normal = get_filename_from_path (GTK_TREE_MODEL (store), (GtkTreePath *)(paths->data));
+ if (files->next == NULL) {
+ normal = gedit_file_browser_utils_file_basename (G_FILE (files->data));
secondary = g_strdup_printf (_("The file \"%s\" cannot be moved to the trash."), normal);
g_free (normal);
} else {
Modified: branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-store.c
==============================================================================
--- /trunk/plugins/filebrowser/gedit-file-browser-store.c (original)
+++ branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-store.c Mon May 5 09:24:33 2008
@@ -25,6 +25,7 @@
#include <string.h>
#include <glib/gi18n-lib.h>
+#include <gio/gio.h>
#include <gedit/gedit-plugin.h>
#include <gedit/gedit-utils.h>
@@ -45,25 +46,33 @@
#define FILE_BROWSER_NODE_DIR(node) ((FileBrowserNodeDir *)(node))
+#define DIRECTORY_LOAD_ITEMS_PER_CALLBACK 100
+#define STANDARD_ATTRIBUTE_TYPES G_FILE_ATTRIBUTE_STANDARD_TYPE "," \
+ G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN "," \
+ G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP "," \
+ G_FILE_ATTRIBUTE_STANDARD_NAME "," \
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE
+
typedef struct _FileBrowserNode FileBrowserNode;
typedef struct _FileBrowserNodeDir FileBrowserNodeDir;
+typedef struct _AsyncData AsyncData;
typedef gint (*SortFunc) (FileBrowserNode * node1,
FileBrowserNode * node2);
-typedef struct
+struct _AsyncData
{
- GnomeVFSAsyncHandle *handle;
- GeditFileBrowserStore *model;
- gpointer user_data;
-
- gboolean alive;
-} AsyncHandle;
+ GeditFileBrowserStore * model;
+ GCancellable * cancellable;
+ gboolean trash;
+ GList * files;
+ GList * iter;
+ gboolean removed;
+};
struct _FileBrowserNode
{
- GnomeVFSURI *uri;
- gchar *mime_type;
+ GFile *file;
guint flags;
gchar *name;
@@ -80,8 +89,8 @@
GSList *children;
GHashTable *hidden_file_hash;
- GnomeVFSAsyncHandle *load_handle;
- GnomeVFSMonitorHandle *monitor_handle;
+ GCancellable *cancellable;
+ GFileMonitor *monitor;
GeditFileBrowserStore *model;
};
@@ -102,7 +111,7 @@
static FileBrowserNode *model_find_node (GeditFileBrowserStore *model,
FileBrowserNode *node,
- GnomeVFSURI *uri);
+ GFile *uri);
static void model_remove_node (GeditFileBrowserStore * model,
FileBrowserNode * node,
GtkTreePath * path,
@@ -165,11 +174,13 @@
gchar * prefix);
static void model_check_dummy (GeditFileBrowserStore * model,
FileBrowserNode * node);
+static void next_files_async (GFileEnumerator * enumerator,
+ FileBrowserNodeDir * dir);
-static void on_directory_monitor_event (GnomeVFSMonitorHandle * handle,
- gchar const *monitor_uri,
- const gchar * info_uri,
- GnomeVFSMonitorEventType event_type,
+static void on_directory_monitor_event (GFileMonitor * handle,
+ GFile *monitor_file,
+ GFile * info_file,
+ guint event_type,
FileBrowserNode * parent);
GEDIT_PLUGIN_DEFINE_TYPE_WITH_CODE (GeditFileBrowserStore, gedit_file_browser_store,
@@ -194,6 +205,7 @@
BEGIN_LOADING,
END_LOADING,
ERROR,
+ NO_TRASH,
NUM_SIGNALS
};
@@ -208,8 +220,14 @@
// Free all the nodes
file_browser_node_free (obj, obj->priv->root);
+ // Cancel any asynchronous operations
for (item = obj->priv->async_handles; item; item = item->next)
- ((AsyncHandle *) (item->data))->alive = FALSE;
+ {
+ AsyncData *data = (AsyncData *) (item->data);
+ g_cancellable_cancel (data->cancellable);
+
+ data->removed = TRUE;
+ }
g_slist_free (obj->priv->async_handles);
G_OBJECT_CLASS (gedit_file_browser_store_parent_class)->
@@ -222,11 +240,10 @@
{
gchar * uri;
- if (node == NULL || node->uri)
+ if (node == NULL || !node->file)
g_value_set_string (value, NULL);
else {
- uri = gnome_vfs_uri_to_string (node->uri,
- GNOME_VFS_URI_HIDE_NONE);
+ uri = g_file_get_uri (node->file);
g_value_take_string (value, uri);
}
}
@@ -331,6 +348,13 @@
error), NULL, NULL,
gedit_file_browser_marshal_VOID__UINT_STRING,
G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING);
+ model_signals[NO_TRASH] =
+ g_signal_new ("no-trash", G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GeditFileBrowserStoreClass,
+ no_trash), g_signal_accumulator_true_handled, NULL,
+ gedit_file_browser_marshal_BOOL__POINTER,
+ G_TYPE_BOOLEAN, 1, G_TYPE_POINTER);
g_type_class_add_private (object_class,
sizeof (GeditFileBrowserStorePrivate));
@@ -574,7 +598,6 @@
GValue * value)
{
FileBrowserNode *node;
- gchar *uri;
g_return_if_fail (GEDIT_IS_FILE_BROWSER_STORE (tree_model));
g_return_if_fail (iter != NULL);
@@ -588,14 +611,7 @@
switch (column) {
case GEDIT_FILE_BROWSER_STORE_COLUMN_URI:
- if (node->uri == NULL)
- uri = NULL;
- else
- uri =
- gnome_vfs_uri_to_string (node->uri,
- GNOME_VFS_URI_HIDE_NONE);
-
- g_value_take_string (value, uri);
+ set_gvalue_from_node (value, node);
break;
case GEDIT_FILE_BROWSER_STORE_COLUMN_NAME:
g_value_set_string (value, node->name);
@@ -1187,14 +1203,14 @@
row_deleted (model, path);
} else {
row_inserted (model, path, &iter);
-
- model_check_dummy (model, node);
gtk_tree_path_next (path);
}
} else if (old_visible) {
gtk_tree_path_next (path);
}
}
+
+ model_check_dummy (model, node);
if (free_path)
gtk_tree_path_free (path);
@@ -1211,19 +1227,19 @@
{
g_free (node->name);
- if (node->uri) {
- node->name = gedit_file_browser_utils_uri_basename (gnome_vfs_uri_get_path (node->uri));
+ if (node->file) {
+ node->name = gedit_file_browser_utils_file_basename (node->file);
} else {
node->name = NULL;
}
}
static void
-file_browser_node_init (FileBrowserNode * node, GnomeVFSURI * uri,
+file_browser_node_init (FileBrowserNode * node, GFile * file,
FileBrowserNode * parent)
{
- if (uri != NULL) {
- node->uri = gnome_vfs_uri_ref (uri);
+ if (file != NULL) {
+ node->file = g_object_ref (file);
file_browser_node_set_name (node);
}
@@ -1231,25 +1247,24 @@
}
static FileBrowserNode *
-file_browser_node_new (GnomeVFSURI * uri, FileBrowserNode * parent)
+file_browser_node_new (GFile * file, FileBrowserNode * parent)
{
FileBrowserNode *node = g_new0 (FileBrowserNode, 1);
- file_browser_node_init (node, uri, parent);
+ file_browser_node_init (node, file, parent);
return node;
}
static FileBrowserNode *
file_browser_node_dir_new (GeditFileBrowserStore * model,
- GnomeVFSURI * uri, FileBrowserNode * parent)
+ GFile * file, FileBrowserNode * parent)
{
FileBrowserNode *node =
(FileBrowserNode *) g_new0 (FileBrowserNodeDir, 1);
- file_browser_node_init (node, uri, parent);
+ file_browser_node_init (node, file, parent);
node->flags |= GEDIT_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY;
- node->mime_type = g_strdup ("text/directory");
FILE_BROWSER_NODE_DIR (node)->model = model;
@@ -1292,22 +1307,26 @@
if (NODE_IS_DIR (node)) {
dir = FILE_BROWSER_NODE_DIR (node);
- if (dir->load_handle) {
- gnome_vfs_async_cancel (dir->load_handle);
+ if (dir->cancellable) {
+ g_cancellable_cancel (dir->cancellable);
+ g_object_unref (dir->cancellable);
+
model_end_loading (model, node);
}
file_browser_node_free_children (model, node);
- if (dir->monitor_handle)
- gnome_vfs_monitor_cancel (dir->monitor_handle);
+ if (dir->monitor) {
+ g_file_monitor_cancel (dir->monitor);
+ g_object_unref (dir->monitor);
+ }
if (dir->hidden_file_hash)
g_hash_table_destroy (dir->hidden_file_hash);
}
- if (node->uri)
- gnome_vfs_uri_unref (node->uri);
+ if (node->file)
+ g_object_unref (node->file);
if (node->icon)
g_object_unref (node->icon);
@@ -1316,7 +1335,6 @@
g_object_unref (node->emblem);
g_free (node->name);
- g_free (node->mime_type);
g_free (node);
}
@@ -1491,15 +1509,19 @@
if (remove_children)
model_remove_node_children (model, node, NULL, TRUE);
- if (dir->load_handle) {
- gnome_vfs_async_cancel (dir->load_handle);
+ if (dir->cancellable) {
+ g_cancellable_cancel (dir->cancellable);
+ g_object_unref (dir->cancellable);
+
model_end_loading (model, node);
- dir->load_handle = NULL;
+ dir->cancellable = NULL;
}
- if (dir->monitor_handle) {
- gnome_vfs_monitor_cancel (dir->monitor_handle);
- dir->monitor_handle = NULL;
+ if (dir->monitor) {
+ g_file_monitor_cancel (dir->monitor);
+ g_object_unref (dir->monitor);
+
+ dir->monitor = NULL;
}
node->flags &= ~GEDIT_FILE_BROWSER_STORE_FLAG_LOADED;
@@ -1511,21 +1533,15 @@
{
GtkIconTheme *theme;
GdkPixbuf *icon;
- gchar *uri;
g_return_if_fail (GEDIT_IS_FILE_BROWSER_STORE (tree_model));
g_return_if_fail (node != NULL);
- if (node->uri == NULL)
+ if (node->file == NULL)
return;
theme = gtk_icon_theme_get_default ();
-
- uri = gnome_vfs_uri_to_string (node->uri, GNOME_VFS_URI_HIDE_NONE);
-
- icon = gedit_file_browser_utils_pixbuf_from_mime_type (uri,
- node->mime_type,
- GTK_ICON_SIZE_MENU);
+ icon = gedit_file_browser_utils_pixbuf_from_file (node->file, GTK_ICON_SIZE_MENU);
if (node->icon)
g_object_unref (node->icon);
@@ -1556,8 +1572,6 @@
} else {
node->icon = icon;
}
-
- g_free (uri);
}
static void
@@ -1717,68 +1731,83 @@
model_check_dummy (model, child);
}
+static gchar const *
+backup_content_type (GFileInfo * info)
+{
+ gchar const * content;
+
+ if (!g_file_info_get_is_backup (info))
+ return NULL;
+
+ content = g_file_info_get_content_type (info);
+
+ if (!content || g_content_type_equals (content, "application/x-trash"))
+ return "text/plain";
+
+ return content;
+}
+
static void
file_browser_node_set_from_info (GeditFileBrowserStore * model,
FileBrowserNode * node,
- GnomeVFSFileInfo * info)
+ GFileInfo * info,
+ gboolean isadded)
{
FileBrowserNodeDir * dir;
- gchar * filename;
- gchar const * mime;
-
- dir = FILE_BROWSER_NODE_DIR (node->parent);
-
- g_free (node->mime_type);
- node->mime_type = NULL;
+ gchar const * content;
+ gchar const * name;
+ gboolean free_info = FALSE;
+ GtkTreePath * path;
- if (info->name) {
- if (*(info->name) == '.') {
- node->flags |= GEDIT_FILE_BROWSER_STORE_FLAG_IS_HIDDEN;
- }
- else if (g_utf8_get_char (g_utf8_offset_to_pointer
- (&(info->name[strlen(info->name)]), -1)) == '~') {
- node->flags |= GEDIT_FILE_BROWSER_STORE_FLAG_IS_HIDDEN;
-
- /* FIXME: this isn't totally correct. We need this
- though because the mime type system somehow says that
- files ending on ~ are application/x-trash. Don't
- ask why. The fact is that most ~ files are backup
- files and are text. Therefore we will try to guess
- the mime type from the filename (minus ~) and default
- to text/plain. Eat that, mime type system! */
- filename = g_strndup (info->name, strlen(info->name) - 1);
- mime = gnome_vfs_get_mime_type_for_name (filename);
- g_free (filename);
-
- if (strcmp(mime, GNOME_VFS_MIME_TYPE_UNKNOWN) == 0)
- node->mime_type = g_strdup("text/plain");
- else
- node->mime_type = g_strdup(mime);
- }
- else if (dir != NULL && dir->hidden_file_hash != NULL &&
- g_hash_table_lookup (dir->hidden_file_hash, info->name) != NULL) {
- node->flags |= GEDIT_FILE_BROWSER_STORE_FLAG_IS_HIDDEN;
- }
+ if (info == NULL) {
+ info = g_file_query_info (node->file,
+ STANDARD_ATTRIBUTE_TYPES,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ NULL);
+ free_info = TRUE;
}
- if (node->mime_type == NULL)
- node->mime_type = g_strdup (info->mime_type);
+ dir = FILE_BROWSER_NODE_DIR (node->parent);
+ name = g_file_info_get_name (info);
+
+ if (g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info))
+ node->flags |= GEDIT_FILE_BROWSER_STORE_FLAG_IS_HIDDEN;
+ else if (dir != NULL && dir->hidden_file_hash != NULL &&
+ g_hash_table_lookup (dir->hidden_file_hash, name) != NULL)
+ node->flags |= GEDIT_FILE_BROWSER_STORE_FLAG_IS_HIDDEN;
- if (info->type == GNOME_VFS_FILE_TYPE_DIRECTORY)
+ if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
node->flags |= GEDIT_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY;
- else if (node->mime_type &&
- gnome_vfs_mime_type_get_equivalence (node->mime_type,
- "text/plain") !=
- GNOME_VFS_MIME_UNRELATED)
- node->flags |= GEDIT_FILE_BROWSER_STORE_FLAG_IS_TEXT;
+ else {
+ if (!(content = backup_content_type (info)))
+ content = g_file_info_get_content_type (info);
+
+ if (!content ||
+ g_content_type_is_unknown (content) ||
+ g_content_type_is_a (content, "text/plain"))
+ node->flags |= GEDIT_FILE_BROWSER_STORE_FLAG_IS_TEXT;
+ }
+
+ if (free_info)
+ g_object_unref (info);
- model_node_update_visibility (model, node);
model_recomposite_icon_real (model, node);
+
+ if (isadded) {
+ path = gedit_file_browser_store_get_path_real (model, node);
+ model_refilter_node (model, node, path);
+ gtk_tree_path_free (path);
+
+ model_check_dummy (model, node->parent);
+ } else {
+ model_node_update_visibility (model, node);
+ }
}
static FileBrowserNode *
-model_uri_exists (GeditFileBrowserStore * model, FileBrowserNode * parent,
- GnomeVFSURI * uri)
+model_file_exists (GeditFileBrowserStore * model, FileBrowserNode * parent,
+ GFile * file)
{
GSList *item;
FileBrowserNode *node;
@@ -1790,8 +1819,8 @@
item = item->next) {
node = (FileBrowserNode *) (item->data);
- if (node->uri != NULL
- && gnome_vfs_uri_equal (node->uri, uri))
+ if (node->file != NULL
+ && g_file_equal (node->file, file))
return node;
}
@@ -1799,110 +1828,89 @@
}
static FileBrowserNode *
-model_add_node_from_uri (GeditFileBrowserStore * model,
- FileBrowserNode * parent,
- GnomeVFSURI * uri,
- GnomeVFSFileInfo * info)
+model_add_node_from_file (GeditFileBrowserStore * model,
+ FileBrowserNode * parent,
+ GFile * file,
+ GFileInfo * info)
{
FileBrowserNode *node;
gboolean free_info = FALSE;
-
+
+ if (!info)
+ {
+ info = g_file_query_info (file,
+ STANDARD_ATTRIBUTE_TYPES,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ NULL);
+ free_info = TRUE;
+ }
+
// Check if it already exists
- if ((node = model_uri_exists (model, parent, uri)) == NULL) {
- if (info == NULL) {
- info = gnome_vfs_file_info_new ();
- free_info = TRUE;
- gnome_vfs_get_file_info_uri (uri, info,
- GNOME_VFS_FILE_INFO_DEFAULT
- |
- GNOME_VFS_FILE_INFO_GET_MIME_TYPE);
- }
-
- if (info->type == GNOME_VFS_FILE_TYPE_DIRECTORY) {
- node = file_browser_node_dir_new (model, uri, parent);
+ if ((node = model_file_exists (model, parent, file)) == NULL) {
+ if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
+ node = file_browser_node_dir_new (model, file, parent);
} else {
- node = file_browser_node_new (uri, parent);
+ node = file_browser_node_new (file, parent);
}
- file_browser_node_set_from_info (model, node, info);
+ file_browser_node_set_from_info (model, node, info, FALSE);
model_add_node (model, node, parent);
-
- if (free_info)
- gnome_vfs_file_info_unref (info);
}
+
+ if (free_info)
+ g_object_unref (info);
return node;
}
/* Read is sync, but we only do it for local files */
static void
-parse_dot_hidden_file (FileBrowserNode *parent)
+parse_dot_hidden_file (FileBrowserNode *directory)
{
- FileBrowserNodeDir *dir;
- GnomeVFSURI *vfs_uri;
- gchar *uri;
- GnomeVFSFileInfo *file_info;
- GnomeVFSResult res;
- gint i, file_size;
- gchar *file_contents;
-
- vfs_uri = gnome_vfs_uri_append_path (parent->uri, ".hidden");
-
- uri = gnome_vfs_uri_to_string (vfs_uri, GNOME_VFS_URI_HIDE_NONE);
- if (!gedit_utils_uri_has_file_scheme (uri) ||
- !gnome_vfs_uri_exists (vfs_uri)) {
- gnome_vfs_uri_unref (vfs_uri);
- g_free (uri);
- return;
- }
-
- file_info = gnome_vfs_file_info_new ();
- if (!file_info) {
- gnome_vfs_uri_unref (vfs_uri);
- g_free (uri);
+ gsize file_size;
+ char *file_contents;
+ GFile *child;
+ GFileInfo *info;
+ GFileType type;
+ int i;
+ FileBrowserNodeDir * dir = FILE_BROWSER_NODE_DIR (directory);
+
+
+ /* FIXME: We only support .hidden on file: uri's for the moment.
+ * Need to figure out if we should do this async or sync to extend
+ * it to all types of uris.
+ */
+ if (directory->file == NULL || !g_file_is_native (directory->file)) {
return;
}
+
+ child = g_file_get_child (directory->file, ".hidden");
+ info = g_file_query_info (child, G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL);
- res = gnome_vfs_get_file_info_uri (vfs_uri,
- file_info,
- GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
- if (res != GNOME_VFS_OK) {
- gnome_vfs_file_info_unref (file_info);
- gnome_vfs_uri_unref (vfs_uri);
- g_free (uri);
- return;
- }
+ type = info ? g_file_info_get_file_type (info) : G_FILE_TYPE_UNKNOWN;
+
+ if (info)
+ g_object_unref (info);
+
+ if (type != G_FILE_TYPE_REGULAR) {
+ g_object_unref (child);
- if ((file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE) &&
- (file_info->type != GNOME_VFS_FILE_TYPE_REGULAR)) {
- gnome_vfs_file_info_unref (file_info);
- gnome_vfs_uri_unref (vfs_uri);
- g_free (uri);
return;
}
- gnome_vfs_file_info_unref (file_info);
-
- res = gnome_vfs_read_entire_file (uri, &file_size, &file_contents);
-
- gnome_vfs_uri_unref (vfs_uri);
- g_free (uri);
-
- if (res != GNOME_VFS_OK) {
+ if (!g_file_load_contents (child, NULL, &file_contents, &file_size, NULL, NULL)) {
+ g_object_unref (child);
return;
}
- dir = FILE_BROWSER_NODE_DIR (parent);
+ g_object_unref (child);
- if (dir->hidden_file_hash) {
- g_hash_table_destroy (dir->hidden_file_hash);
+ if (dir->hidden_file_hash == NULL) {
+ dir->hidden_file_hash =
+ g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
}
-
- dir->hidden_file_hash = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- NULL);
-
+
/* Now parse the data */
i = 0;
while (i < file_size) {
@@ -1914,84 +1922,142 @@
}
if (i > start) {
- gchar *tmp, *tmp2;
-
- tmp = g_strndup (file_contents + start, i - start);
- tmp2 = gnome_vfs_escape_string (tmp);
- g_free (tmp);
-
+ char *hidden_filename;
+
+ hidden_filename = g_strndup (file_contents + start, i - start);
g_hash_table_insert (dir->hidden_file_hash,
- tmp2, tmp2);
+ hidden_filename, hidden_filename);
}
i++;
+
}
g_free (file_contents);
}
static void
-model_load_directory_cb (GnomeVFSAsyncHandle * handle,
- GnomeVFSResult result, GList * list,
- guint entries_read, gpointer user_data)
-{
- FileBrowserNode *parent = (FileBrowserNode *) user_data;
- GeditFileBrowserStore *model;
-
- model = FILE_BROWSER_NODE_DIR (parent)->model;
-
- if (result == GNOME_VFS_OK || result == GNOME_VFS_ERROR_EOF) {
- GList *item;
+model_iterate_next_files_cb (GFileEnumerator * enumerator,
+ GAsyncResult * result,
+ FileBrowserNode * parent)
+{
+ GList * files;
+ GList * item;
+ GError * error = NULL;
+ GFileInfo * info;
+ GFileType type;
+ gchar const * name;
+ GFile * file;
+ FileBrowserNodeDir * dir = FILE_BROWSER_NODE_DIR (parent);
+
+ files = g_file_enumerator_next_files_finish (enumerator, result, &error);
- for (item = list; item; item = item->next) {
- GnomeVFSFileInfo *info;
- GnomeVFSURI *uri;
+ if (files == NULL) {
+ g_file_enumerator_close (enumerator, NULL, NULL);
+
+ if (!error)
+ {
+ /* We're done loading */
+ g_object_unref (dir->cancellable);
+ dir->cancellable = NULL;
+
+ if (g_file_is_native (parent->file) && dir->monitor == NULL) {
+ dir->monitor = g_file_monitor_directory (parent->file,
+ G_FILE_MONITOR_NONE,
+ NULL,
+ NULL);
+ g_signal_connect (dir->monitor,
+ "changed",
+ G_CALLBACK (on_directory_monitor_event),
+ parent);
+ }
- info = (GnomeVFSFileInfo *) (item->data);
+ model_check_dummy (dir->model, parent);
+ model_end_loading (dir->model, parent);
+ } else {
+ /* Simply return if we were cancelled */
+ if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_CANCELLED)
+ return;
+
+ /* Otherwise handle the error appropriately */
+ g_signal_emit (dir->model,
+ model_signals[ERROR],
+ 0,
+ GEDIT_FILE_BROWSER_ERROR_LOAD_DIRECTORY,
+ error->message);
+ file_browser_node_unload (dir->model, (FileBrowserNode *)parent, TRUE);
+ g_error_free (error);
+ }
+ } else {
+ for (item = files; item; item = item->next) {
+ info = G_FILE_INFO (item->data);
+ type = g_file_info_get_file_type (info);
+
/* Skip all non regular, non directory files */
- if (info->type != GNOME_VFS_FILE_TYPE_REGULAR &&
- info->type != GNOME_VFS_FILE_TYPE_DIRECTORY &&
- info->type != GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK)
+ if (type != G_FILE_TYPE_REGULAR &&
+ type != G_FILE_TYPE_DIRECTORY &&
+ type != G_FILE_TYPE_SYMBOLIC_LINK)
continue;
+ name = g_file_info_get_name (info);
+
/* Skip '.' and '..' directories */
- if (info->type == GNOME_VFS_FILE_TYPE_DIRECTORY &&
- (strcmp (info->name, ".") == 0 ||
- strcmp (info->name, "..") == 0))
+ if (type == G_FILE_TYPE_DIRECTORY &&
+ (strcmp (name, ".") == 0 ||
+ strcmp (name, "..") == 0))
continue;
- uri = gnome_vfs_uri_append_path (parent->uri,
- info->name);
- model_add_node_from_uri (model, parent, uri, info);
- gnome_vfs_uri_unref (uri);
- }
-
- if (result == GNOME_VFS_ERROR_EOF) {
- FileBrowserNodeDir *dir;
-
- dir = FILE_BROWSER_NODE_DIR (parent);
- dir->load_handle = NULL;
-
- if (gnome_vfs_uri_is_local (parent->uri)
- && dir->monitor_handle == NULL) {
- gnome_vfs_monitor_add (&(dir->monitor_handle),
- gnome_vfs_uri_get_path (parent->uri),
- GNOME_VFS_MONITOR_DIRECTORY,
- (GnomeVFSMonitorCallback)on_directory_monitor_event, parent);
- }
+ file = g_file_get_child (parent->file, name);
+ model_add_node_from_file (dir->model, parent, file, info);
- model_end_loading (model, parent);
- model_check_dummy (model, parent);
+ g_object_unref (file);
+ g_object_unref (info);
}
- } else {
- g_signal_emit (model,
- model_signals[ERROR],
- 0,
- GEDIT_FILE_BROWSER_ERROR_LOAD_DIRECTORY,
- gnome_vfs_result_to_string (result));
+
+ g_list_free (files);
+ next_files_async (enumerator, dir);
+ }
+}
+
+static void
+next_files_async (GFileEnumerator * enumerator,
+ FileBrowserNodeDir * dir)
+{
+ g_file_enumerator_next_files_async (enumerator,
+ DIRECTORY_LOAD_ITEMS_PER_CALLBACK,
+ G_PRIORITY_DEFAULT,
+ dir->cancellable,
+ (GAsyncReadyCallback)model_iterate_next_files_cb,
+ dir);
+}
- file_browser_node_unload (model, parent, TRUE);
+static void
+model_iterate_children_cb (GFile * file,
+ GAsyncResult * result,
+ FileBrowserNodeDir * dir)
+{
+ GError * error = NULL;
+ GFileEnumerator * enumerator;
+
+ enumerator = g_file_enumerate_children_finish (file, result, &error);
+
+ if (enumerator == NULL) {
+ /* Simply return if we were cancelled */
+ if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_CANCELLED)
+ return;
+
+ /* Otherwise handle the error appropriately */
+ g_signal_emit (dir->model,
+ model_signals[ERROR],
+ 0,
+ GEDIT_FILE_BROWSER_ERROR_LOAD_DIRECTORY,
+ error->message);
+
+ file_browser_node_unload (dir->model, (FileBrowserNode *)dir, TRUE);
+ g_error_free (error);
+ } else {
+ next_files_async (enumerator, dir);
}
}
@@ -2006,9 +2072,8 @@
dir = FILE_BROWSER_NODE_DIR (node);
/* Cancel a previous load */
- if (dir->load_handle != NULL) {
- gnome_vfs_async_cancel (dir->load_handle);
- dir->load_handle = NULL;
+ if (dir->cancellable != NULL) {
+ file_browser_node_unload (dir->model, node, TRUE);
}
node->flags |= GEDIT_FILE_BROWSER_STORE_FLAG_LOADED;
@@ -2016,32 +2081,33 @@
/* Read the '.hidden' file first (if any) */
parse_dot_hidden_file (node);
+
+ dir->cancellable = g_cancellable_new ();
/* Start loading async */
- gnome_vfs_async_load_directory_uri (&(dir->load_handle), node->uri,
- GNOME_VFS_FILE_INFO_GET_MIME_TYPE |
- GNOME_VFS_FILE_INFO_FOLLOW_LINKS,
- 100,
- GNOME_VFS_PRIORITY_DEFAULT,
- model_load_directory_cb, node);
+ g_file_enumerate_children_async (node->file,
+ STANDARD_ATTRIBUTE_TYPES,
+ G_FILE_QUERY_INFO_NONE,
+ G_PRIORITY_DEFAULT,
+ dir->cancellable,
+ (GAsyncReadyCallback)model_iterate_children_cb,
+ dir);
}
static GList *
-get_parent_uris (GeditFileBrowserStore * model, GnomeVFSURI * uri)
+get_parent_files (GeditFileBrowserStore * model, GFile * file)
{
- GList *result = NULL;
-
- result = g_list_prepend (result, gnome_vfs_uri_ref (uri));
-
- while (gnome_vfs_uri_has_parent (uri)) {
- uri = gnome_vfs_uri_get_parent (uri);
+ GList * result = NULL;
+
+ result = g_list_prepend (result, g_object_ref (file));
- if (gnome_vfs_uri_equal (uri, model->priv->root->uri)) {
- gnome_vfs_uri_unref (uri);
+ while ((file = g_file_get_parent (file))) {
+ if (g_file_equal (file, model->priv->root->file)) {
+ g_object_unref (file);
break;
}
- result = g_list_prepend (result, uri);
+ result = g_list_prepend (result, file);
}
return result;
@@ -2224,102 +2290,36 @@
}
static void
-set_virtual_root_from_uri (GeditFileBrowserStore * model,
- GnomeVFSURI * uri)
+set_virtual_root_from_file (GeditFileBrowserStore * model,
+ GFile * file)
{
- GList *uris;
- GList *item;
- FileBrowserNode *node;
- FileBrowserNode *parent;
- GnomeVFSURI *check;
- gboolean created = FALSE;
- GnomeVFSFileInfo *info;
+ GList * files;
+ GList * item;
+ FileBrowserNode * parent;
+ GFile * check;
/* Always clear the model before altering the nodes */
model_clear (model, FALSE);
/* Create the node path, get all the uri's */
- uris = get_parent_uris (model, uri);
+ files = get_parent_files (model, file);
parent = model->priv->root;
- node = NULL;
-
- for (item = uris; item; item = item->next) {
- check = (GnomeVFSURI *) (item->data);
- node = NULL;
-
- if (!created)
- node = model_uri_exists (model, parent, check);
-
- if (node == NULL) {
- // Create the node
- node = file_browser_node_dir_new (model, check, parent);
-
- info = gnome_vfs_file_info_new ();
- gnome_vfs_get_file_info_uri (check, info,
- GNOME_VFS_FILE_INFO_DEFAULT |
- GNOME_VFS_FILE_INFO_GET_MIME_TYPE);
- file_browser_node_set_from_info (model, node, info);
- gnome_vfs_file_info_unref (info);
- model_add_node (model, node, parent);
- created = TRUE;
- }
-
- parent = node;
- gnome_vfs_uri_unref (check);
+ for (item = files; item; item = item->next) {
+ check = G_FILE (item->data);
+
+ parent = model_add_node_from_file (model, parent, check, NULL);
+ g_object_unref (check);
}
- g_list_free (uris);
-
+ g_list_free (files);
set_virtual_root_from_node (model, parent);
}
-static int
-progress_update_callback (GnomeVFSAsyncHandle * handle,
- GnomeVFSXferProgressInfo * progress_info,
- gpointer data)
-{
- AsyncHandle *ahandle;
-
- ahandle = (AsyncHandle *) (data);
-
- switch (progress_info->status) {
- case GNOME_VFS_XFER_PROGRESS_STATUS_VFSERROR:
- if (ahandle->alive)
- g_signal_emit (ahandle->model,
- model_signals[ERROR], 0,
- GEDIT_FILE_BROWSER_ERROR_DELETE,
- gnome_vfs_result_to_string
- (progress_info->vfs_status));
-
- return GNOME_VFS_XFER_ERROR_ACTION_ABORT;
- break;
- case GNOME_VFS_XFER_PROGRESS_STATUS_OK:
- switch (progress_info->phase) {
- case GNOME_VFS_XFER_PHASE_COMPLETED:
- if (ahandle->alive) {
- ahandle->model->priv->async_handles =
- g_slist_remove (ahandle->model->priv->
- async_handles,
- ahandle);
- }
-
- g_free (ahandle);
- break;
- default:
- break;
- }
- default:
- break;
- }
-
- return 1;
-}
-
static FileBrowserNode *
-model_find_node_children (GeditFileBrowserStore *model,
- FileBrowserNode *parent,
- GnomeVFSURI *uri)
+model_find_node_children (GeditFileBrowserStore * model,
+ FileBrowserNode * parent,
+ GFile * file)
{
FileBrowserNodeDir *dir;
FileBrowserNode *child;
@@ -2334,7 +2334,7 @@
for (children = dir->children; children; children = children->next) {
child = (FileBrowserNode *)(children->data);
- result = model_find_node (model, child, uri);
+ result = model_find_node (model, child, file);
if (result)
return result;
@@ -2344,101 +2344,20 @@
}
static FileBrowserNode *
-model_find_node (GeditFileBrowserStore *model,
- FileBrowserNode *node,
- GnomeVFSURI *uri)
+model_find_node (GeditFileBrowserStore * model,
+ FileBrowserNode * node,
+ GFile * file)
{
if (node == NULL)
node = model->priv->root;
- if (node->uri && gnome_vfs_uri_equal (node->uri, uri))
+ if (node->file && g_file_equal (node->file, file))
return node;
-
- if (NODE_IS_DIR (node) && gnome_vfs_uri_is_parent (node->uri, uri, TRUE))
- return model_find_node_children (model, node, uri);
-
- return NULL;
-}
-
-typedef struct {
- GeditFileBrowserStore *model;
- gchar *uri;
-} IdleDelete;
-
-static void
-idle_delete_free (IdleDelete *data)
-{
- g_free (data->uri);
- g_free (data);
-}
-
-static gboolean
-uri_deleted (IdleDelete *data)
-{
- GnomeVFSURI *guri;
- FileBrowserNode *node;
- guri = gnome_vfs_uri_new (data->uri);
- node = model_find_node (data->model, NULL, guri);
-
- if (node)
- model_remove_node (data->model, node, NULL, TRUE);
-
- gnome_vfs_uri_unref (guri);
+ if (NODE_IS_DIR (node) && g_file_has_prefix (file, node->file))
+ return model_find_node_children (model, node, file);
- return FALSE;
-}
-
-static int
-progress_sync_callback_trash (GnomeVFSXferProgressInfo * progress_info,
- gpointer data)
-{
- AsyncHandle *ahandle = (AsyncHandle *) (data);
- IdleDelete *delete;
-
- if (!ahandle->alive)
- return 1;
-
- if (progress_info->status == GNOME_VFS_XFER_PROGRESS_STATUS_OK &&
- (progress_info->phase == GNOME_VFS_XFER_PHASE_DELETESOURCE ||
- progress_info->phase == GNOME_VFS_XFER_PHASE_MOVING)) {
- delete = g_new(IdleDelete, 1);
- delete->model = ahandle->model;
- delete->uri = g_strdup (progress_info->source_name);
-
- g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
- (GSourceFunc)uri_deleted,
- delete,
- (GDestroyNotify)idle_delete_free);
- }
-
- return 1;
-}
-
-
-static int
-progress_sync_callback_delete (GnomeVFSXferProgressInfo * progress_info,
- gpointer data)
-{
- AsyncHandle *ahandle = (AsyncHandle *) (data);
- IdleDelete *delete;
-
- if (!ahandle->alive)
- return 1;
-
- if (progress_info->status == GNOME_VFS_XFER_PROGRESS_STATUS_OK &&
- progress_info->phase == GNOME_VFS_XFER_PHASE_DELETESOURCE) {
- delete = g_new(IdleDelete, 1);
- delete->model = ahandle->model;
- delete->uri = g_strdup (progress_info->source_name);
-
- g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
- (GSourceFunc)uri_deleted,
- delete,
- (GDestroyNotify)idle_delete_free);
- }
-
- return 1;
+ return NULL;
}
static GQuark
@@ -2454,25 +2373,23 @@
return quark;
}
-static GnomeVFSURI *
-unique_new_name (GnomeVFSURI * uri, gchar const *name)
+static GFile *
+unique_new_name (GFile * directory, gchar const * name)
{
- GnomeVFSURI *newuri = NULL;
+ GFile * newuri = NULL;
guint num = 0;
+ gchar * newname;
- while (newuri == NULL || gnome_vfs_uri_exists (newuri)) {
- gchar *newname;
-
+ while (newuri == NULL || g_file_query_exists (newuri, NULL)) {
if (newuri != NULL)
- gnome_vfs_uri_unref (newuri);
+ g_object_unref (newuri);
if (num == 0)
newname = g_strdup (name);
else
newname = g_strdup_printf ("%s(%d)", name, num);
- newuri = gnome_vfs_uri_append_file_name (uri, newname);
-
+ newuri = g_file_get_child (directory, newname);
g_free (newname);
++num;
@@ -2481,19 +2398,6 @@
return newuri;
}
-static GnomeVFSURI *
-append_basename (GnomeVFSURI * target_uri, GnomeVFSURI * uri)
-{
- gchar *basename;
- GnomeVFSURI *ret;
-
- basename = gnome_vfs_uri_extract_short_name (uri);
- ret = gnome_vfs_uri_append_file_name (target_uri, basename);
- g_free (basename);
-
- return ret;
-}
-
/* Public */
GeditFileBrowserStore *
gedit_file_browser_store_new (gchar const *root)
@@ -2571,27 +2475,27 @@
GeditFileBrowserStoreResult
gedit_file_browser_store_set_virtual_root_from_string
(GeditFileBrowserStore * model, gchar const *root) {
- GnomeVFSURI *uri = gnome_vfs_uri_new (root);
+ GFile * file = g_file_new_for_uri (root);
gchar *str, *str1;
g_return_val_if_fail (GEDIT_IS_FILE_BROWSER_STORE (model),
GEDIT_FILE_BROWSER_STORE_RESULT_NO_CHANGE);
- if (uri == NULL) {
+ if (file == NULL) {
g_warning ("Invalid uri (%s)", root);
return GEDIT_FILE_BROWSER_STORE_RESULT_NO_CHANGE;
}
/* Check if uri is already the virtual root */
if (model->priv->virtual_root &&
- gnome_vfs_uri_equal (model->priv->virtual_root->uri, uri)) {
- gnome_vfs_uri_unref (uri);
+ g_file_equal (model->priv->virtual_root->file, file)) {
+ g_object_unref (file);
return GEDIT_FILE_BROWSER_STORE_RESULT_NO_CHANGE;
}
/* Check if uri is the root itself */
- if (gnome_vfs_uri_equal (model->priv->root->uri, uri)) {
- gnome_vfs_uri_unref (uri);
+ if (g_file_equal (model->priv->root->file, file)) {
+ g_object_unref (file);
/* Always clear the model before altering the nodes */
model_clear (model, FALSE);
@@ -2599,25 +2503,23 @@
return GEDIT_FILE_BROWSER_STORE_RESULT_OK;
}
- if (!gnome_vfs_uri_is_parent (model->priv->root->uri, uri, TRUE)) {
- str =
- gnome_vfs_uri_to_string (model->priv->root->uri,
- GNOME_VFS_URI_HIDE_PASSWORD);
- str1 =
- gnome_vfs_uri_to_string (uri,
- GNOME_VFS_URI_HIDE_PASSWORD);
+ if (!g_file_has_prefix (file, model->priv->root->file)) {
+ str = gedit_file_browser_utils_file_display (model->priv->root->file);
+ str1 = gedit_file_browser_utils_file_display (file);
+
g_warning
("Virtual root (%s) is not below actual root (%s)",
str1, str);
+
g_free (str);
g_free (str1);
- gnome_vfs_uri_unref (uri);
+ g_object_unref (file);
return GEDIT_FILE_BROWSER_STORE_RESULT_ERROR;
}
- set_virtual_root_from_uri (model, uri);
- gnome_vfs_uri_unref (uri);
+ set_virtual_root_from_file (model, file);
+ g_object_unref (file);
return GEDIT_FILE_BROWSER_STORE_RESULT_OK;
}
@@ -2703,9 +2605,9 @@
gchar const *root,
gchar const *virtual_root)
{
- GnomeVFSURI *uri = NULL;
- GnomeVFSURI *vuri = NULL;
- FileBrowserNode *node;
+ GFile * file = NULL;
+ GFile * vfile = NULL;
+ FileBrowserNode * node;
gboolean equal = FALSE;
g_return_val_if_fail (GEDIT_IS_FILE_BROWSER_STORE (model),
@@ -2715,9 +2617,9 @@
return GEDIT_FILE_BROWSER_STORE_RESULT_NO_CHANGE;
if (root != NULL) {
- uri = gnome_vfs_uri_new (root);
+ file = g_file_new_for_uri (root);
- if (uri == NULL) {
+ if (file == NULL) {
g_signal_emit (model, model_signals[ERROR], 0,
GEDIT_FILE_BROWSER_ERROR_SET_ROOT,
_("Invalid uri"));
@@ -2726,28 +2628,27 @@
}
if (root != NULL && model->priv->root != NULL) {
- equal = gnome_vfs_uri_equal (uri, model->priv->root->uri);
+ equal = g_file_equal (file, model->priv->root->file);
if (equal && virtual_root == NULL) {
- gnome_vfs_uri_unref (uri);
+ g_object_unref (file);
return GEDIT_FILE_BROWSER_STORE_RESULT_NO_CHANGE;
}
}
if (virtual_root) {
- vuri = gnome_vfs_uri_new (virtual_root);
+ vfile = g_file_new_for_uri (virtual_root);
if (equal && model->priv->virtual_root &&
- gnome_vfs_uri_equal (vuri,
- model->priv->virtual_root->uri)) {
- if (uri)
- gnome_vfs_uri_unref (uri);
+ g_file_equal (vfile, model->priv->virtual_root->file)) {
+ if (file)
+ g_object_unref (file);
- gnome_vfs_uri_unref (vuri);
+ g_object_unref (vfile);
return GEDIT_FILE_BROWSER_STORE_RESULT_NO_CHANGE;
}
- gnome_vfs_uri_unref (vuri);
+ g_object_unref (vfile);
}
/* Always clear the model before altering the nodes */
@@ -2757,10 +2658,10 @@
model->priv->root = NULL;
model->priv->virtual_root = NULL;
- if (uri != NULL) {
+ if (file != NULL) {
/* Create the root node */
- node = file_browser_node_dir_new (model, uri, NULL);
- gnome_vfs_uri_unref (uri);
+ node = file_browser_node_dir_new (model, file, NULL);
+ g_object_unref (file);
model->priv->root = node;
model_check_dummy (model, node);
@@ -2797,18 +2698,20 @@
gedit_file_browser_store_get_root (GeditFileBrowserStore * model)
{
g_return_val_if_fail (GEDIT_IS_FILE_BROWSER_STORE (model), NULL);
+ g_return_val_if_fail (model->priv->root != NULL, NULL);
+ g_return_val_if_fail (model->priv->root->file != NULL, NULL);
- return gnome_vfs_uri_to_string (model->priv->root->uri,
- GNOME_VFS_URI_HIDE_NONE);
+ return g_file_get_uri (model->priv->root->file);
}
gchar *
gedit_file_browser_store_get_virtual_root (GeditFileBrowserStore * model)
{
g_return_val_if_fail (GEDIT_IS_FILE_BROWSER_STORE (model), NULL);
+ g_return_val_if_fail (model->priv->virtual_root != NULL, NULL);
+ g_return_val_if_fail (model->priv->virtual_root->file != NULL, NULL);
- return gnome_vfs_uri_to_string (model->priv->virtual_root->uri,
- GNOME_VFS_URI_HIDE_NONE);
+ return g_file_get_uri (model->priv->virtual_root->file);
}
void
@@ -2924,11 +2827,10 @@
GError ** error)
{
FileBrowserNode *node;
- GnomeVFSURI *uri;
- GnomeVFSURI *parent;
- GnomeVFSResult ret;
-
- *error = NULL;
+ GFile * file;
+ GFile * parent;
+ GError * err = NULL;
+ GtkTreePath *path;
g_return_val_if_fail (GEDIT_IS_FILE_BROWSER_STORE (model), FALSE);
g_return_val_if_fail (iter != NULL, FALSE);
@@ -2936,82 +2838,180 @@
node = (FileBrowserNode *) (iter->user_data);
- parent = gnome_vfs_uri_get_parent (node->uri);
- uri = gnome_vfs_uri_append_file_name (parent, new_name);
- gnome_vfs_uri_unref (parent);
+ parent = g_file_get_parent (node->file);
+ g_return_val_if_fail (parent != NULL, FALSE);
+
+ file = g_file_get_child (parent, new_name);
+ g_object_unref (parent);
- if (gnome_vfs_uri_equal (node->uri, uri)) {
- gnome_vfs_uri_unref (uri);
+ if (g_file_equal (node->file, file)) {
+ g_object_unref (file);
return TRUE;
}
- ret = gnome_vfs_move_uri (node->uri, uri, FALSE);
+ if (g_file_move (node->file, file, G_FILE_COPY_NONE, NULL, NULL, NULL, &err)) {
+ /* TODO: make sure to also re'path all the child nodes that
+ might be there! */
+ parent = node->file;
+ node->file = file;
- if (ret == GNOME_VFS_OK) {
- GnomeVFSFileInfo *info;
- GtkTreePath *path;
-
- parent = node->uri;
- node->uri = uri;
- info = gnome_vfs_file_info_new ();
- gnome_vfs_get_file_info_uri (uri, info,
- GNOME_VFS_FILE_INFO_DEFAULT |
- GNOME_VFS_FILE_INFO_GET_MIME_TYPE);
- file_browser_node_set_from_info (model, node, info);
+ /* This makes sure the actual info for the node is requeried */
file_browser_node_set_name (node);
- gnome_vfs_file_info_unref (info);
- gnome_vfs_uri_unref (parent);
+ file_browser_node_set_from_info (model, node, NULL, TRUE);
- path = gedit_file_browser_store_get_path_real (model, node);
- gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, iter);
- gtk_tree_path_free (path);
+ /* Free the old nodes' GFile */
+ g_object_unref (parent);
+
+ if (model_node_visibility (model, node)) {
+ path = gedit_file_browser_store_get_path_real (model, node);
+ gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, iter);
+ gtk_tree_path_free (path);
- /* Reorder this item */
- model_resort_node (model, node);
+ /* Reorder this item */
+ model_resort_node (model, node);
+ } else {
+ if (error != NULL)
+ *error = g_error_new_literal (gedit_file_browser_store_error_quark (),
+ GEDIT_FILE_BROWSER_ERROR_RENAME,
+ _("The renamed file is currently filtered out. You need to adjust your filter settings to make the file visible"));
+ return FALSE;
+ }
return TRUE;
} else {
- gnome_vfs_uri_unref (uri);
+ g_object_unref (file);
- if (error != NULL) {
- *error =
- g_error_new_literal
- (gedit_file_browser_store_error_quark (),
- GEDIT_FILE_BROWSER_ERROR_RENAME,
- gnome_vfs_result_to_string (ret));
+ if (err) {
+ if (error != NULL) {
+ *error =
+ g_error_new_literal
+ (gedit_file_browser_store_error_quark (),
+ GEDIT_FILE_BROWSER_ERROR_RENAME,
+ err->message);
+ }
+
+ g_error_free (err);
}
return FALSE;
}
}
+static void
+async_data_free (AsyncData * data)
+{
+ g_object_unref (data->cancellable);
+
+ g_list_foreach (data->files, (GFunc)g_object_unref, NULL);
+ g_list_free (data->files);
+
+ if (!data->removed)
+ data->model->priv->async_handles = g_slist_remove (data->model->priv->async_handles, data);
+
+ g_free (data);
+}
+
+static gboolean
+emit_no_trash (AsyncData * data)
+{
+ /* Emit the no trash error */
+ gboolean ret;
+
+ g_signal_emit (data->model, model_signals[NO_TRASH], 0, data->files, &ret);
+ return ret;
+}
+
+typedef struct {
+ GeditFileBrowserStore * model;
+ GFile * file;
+} IdleDelete;
+
+static gboolean
+file_deleted (IdleDelete * data)
+{
+ FileBrowserNode * node;
+ node = model_find_node (data->model, NULL, data->file);
+
+ if (node)
+ model_remove_node (data->model, node, NULL, TRUE);
+
+ return FALSE;
+}
+
+static gboolean
+delete_files (GIOSchedulerJob * job,
+ GCancellable * cancellable,
+ AsyncData * data)
+{
+ GFile * file;
+ GError * error = NULL;
+ gboolean ret;
+ gint code;
+ IdleDelete delete;
+
+ /* Check if our job is done */
+ if (!data->iter)
+ return FALSE;
+
+ /* Move a file to the trash */
+ file = G_FILE (data->iter->data);
+
+ if (data->trash)
+ ret = g_file_trash (file, cancellable, &error);
+ else
+ ret = g_file_delete (file, cancellable, &error);
+
+ if (ret) {
+ delete.model = data->model;
+ delete.file = file;
+
+ /* Remove the file from the model in the main loop */
+ g_io_scheduler_job_send_to_mainloop (job, (GSourceFunc)file_deleted, &delete, NULL);
+ } else if (!ret && error) {
+ code = error->code;
+ g_error_free (error);
+
+ if (data->trash && code == G_IO_ERROR_NOT_SUPPORTED) {
+ /* Trash is not supported on this system ... */
+ if (g_io_scheduler_job_send_to_mainloop (job, (GSourceFunc)emit_no_trash, data, NULL))
+ {
+ /* Changes this into a delete job */
+ data->trash = FALSE;
+ data->iter = data->files;
+
+ return TRUE;
+ }
+
+ /* End the job */
+ return FALSE;
+ } else if (code == G_IO_ERROR_CANCELLED) {
+ /* Job has been cancelled, just let the job end */
+ return FALSE;
+ }
+ }
+
+ /* Process the next item */
+ data->iter = data->iter->next;
+ return TRUE;
+}
+
GeditFileBrowserStoreResult
gedit_file_browser_store_delete_all (GeditFileBrowserStore *model,
GList *rows, gboolean trash)
{
- FileBrowserNode *node;
- AsyncHandle *handle;
- GList *uris = NULL;
- GList *row;
- GList *target = NULL;
- GnomeVFSURI *trash_uri;
- GnomeVFSResult ret;
- GnomeVFSXferOptions options;
+ FileBrowserNode * node;
+ AsyncData * data;
+ GList * files = NULL;
+ GList * row;
GtkTreeIter iter;
- GeditFileBrowserStoreResult result = GEDIT_FILE_BROWSER_STORE_RESULT_OK;
- GtkTreePath *prev = NULL;
- GtkTreePath *path;
- GnomeVFSXferProgressCallback sync_cb;
+ GtkTreePath * prev = NULL;
+ GtkTreePath * path;
g_return_val_if_fail (GEDIT_IS_FILE_BROWSER_STORE (model), GEDIT_FILE_BROWSER_STORE_RESULT_NO_CHANGE);
if (rows == NULL)
return GEDIT_FILE_BROWSER_STORE_RESULT_NO_CHANGE;
- handle = g_new (AsyncHandle, 1);
- handle->model = model;
- handle->alive = TRUE;
-
/* First we sort the paths so that we can later on remove any
files/directories that are actually subfiles/directories of
a directory that's also deleted */
@@ -3030,76 +3030,26 @@
prev = path;
node = (FileBrowserNode *)(iter.user_data);
-
- if (trash) {
- /* Find the trash */
- ret =
- gnome_vfs_find_directory (node->uri,
- GNOME_VFS_DIRECTORY_KIND_TRASH,
- &trash_uri, FALSE, TRUE,
- 0777);
-
- if (ret == GNOME_VFS_ERROR_NOT_FOUND || trash_uri == NULL) {
- if (trash_uri != NULL)
- gnome_vfs_uri_unref (trash_uri);
-
- result = GEDIT_FILE_BROWSER_STORE_RESULT_NO_TRASH;
- break;
- } else {
- uris = g_list_append (uris, node->uri);
- target =
- g_list_append (target,
- append_basename (trash_uri,
- node->uri));
- gnome_vfs_uri_unref (trash_uri);
- }
- } else {
- uris = g_list_append (uris, node->uri);
- }
+ files = g_list_prepend (files, g_object_ref (node->file));
}
- if (result != GEDIT_FILE_BROWSER_STORE_RESULT_OK) {
- if (target) {
- g_list_foreach (target, (GFunc)gnome_vfs_uri_unref, NULL);
- g_list_free (target);
- }
-
- g_list_free (uris);
- g_free (handle);
- g_list_free (rows);
+ data = g_new (AsyncData, 1);
- return result;
- }
+ data->model = model;
+ data->cancellable = g_cancellable_new ();
+ data->files = files;
+ data->trash = trash;
+ data->iter = files;
+ data->removed = FALSE;
- if (trash) {
- options =
- GNOME_VFS_XFER_RECURSIVE |
- GNOME_VFS_XFER_REMOVESOURCE;
- sync_cb = progress_sync_callback_trash;
- } else {
- options =
- GNOME_VFS_XFER_DELETE_ITEMS | GNOME_VFS_XFER_RECURSIVE;
- sync_cb = progress_sync_callback_delete;
- }
-
- gnome_vfs_async_xfer (&(handle->handle), uris, target,
- options,
- GNOME_VFS_XFER_ERROR_MODE_QUERY,
- GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
- GNOME_VFS_PRIORITY_DEFAULT,
- progress_update_callback,
- handle, sync_cb, handle);
-
model->priv->async_handles =
- g_slist_prepend (model->priv->async_handles, handle);
+ g_slist_prepend (model->priv->async_handles, data);
- g_list_free (uris);
-
- if (target) {
- g_list_foreach (target, (GFunc)gnome_vfs_uri_unref, NULL);
- g_list_free (target);
- }
-
+ g_io_scheduler_push_job ((GIOSchedulerJobFunc)delete_files,
+ data,
+ (GDestroyNotify)async_data_free,
+ G_PRIORITY_DEFAULT,
+ data->cancellable);
g_list_free (rows);
return GEDIT_FILE_BROWSER_STORE_RESULT_OK;
@@ -3136,12 +3086,12 @@
GtkTreeIter * parent,
GtkTreeIter * iter)
{
- GnomeVFSURI *uri;
- GnomeVFSHandle *handle;
- GnomeVFSResult ret;
+ GFile * file;
+ GFileOutputStream * stream;
FileBrowserNodeDir *parent_node;
gboolean result = FALSE;
FileBrowserNode *node;
+ GError * error = NULL;
g_return_val_if_fail (GEDIT_IS_FILE_BROWSER_STORE (model), FALSE);
g_return_val_if_fail (parent != NULL, FALSE);
@@ -3152,19 +3102,22 @@
g_return_val_if_fail (iter != NULL, FALSE);
parent_node = FILE_BROWSER_NODE_DIR (parent->user_data);
- uri = unique_new_name (((FileBrowserNode *) parent_node)->uri, _("file"));
-
- ret = gnome_vfs_create_uri (&handle, uri,
- GNOME_VFS_OPEN_NONE |
- GNOME_VFS_OPEN_WRITE, FALSE, 0644);
+ file = unique_new_name (((FileBrowserNode *) parent_node)->file, _("file"));
- if (ret != GNOME_VFS_OK) {
+ stream = g_file_create (file, G_FILE_CREATE_NONE, NULL, &error);
+
+ if (!stream)
+ {
g_signal_emit (model, model_signals[ERROR], 0,
GEDIT_FILE_BROWSER_ERROR_NEW_FILE,
- gnome_vfs_result_to_string (ret));
+ error->message);
+ g_error_free (error);
} else {
- node = model_add_node_from_uri (model, (FileBrowserNode *)
- parent_node, uri, NULL);
+ g_object_unref (stream);
+ node = model_add_node_from_file (model,
+ (FileBrowserNode *)parent_node,
+ file,
+ NULL);
if (model_node_visibility (model, node)) {
iter->user_data = node;
@@ -3177,7 +3130,7 @@
}
}
- gnome_vfs_uri_unref (uri);
+ g_object_unref (file);
return result;
}
@@ -3186,11 +3139,11 @@
GtkTreeIter * parent,
GtkTreeIter * iter)
{
- GnomeVFSURI *uri;
- GnomeVFSResult ret;
+ GFile * file;
FileBrowserNodeDir *parent_node;
- gboolean result = FALSE;
+ GError * error = NULL;
FileBrowserNode *node;
+ gboolean result = FALSE;
g_return_val_if_fail (GEDIT_IS_FILE_BROWSER_STORE (model), FALSE);
g_return_val_if_fail (parent != NULL, FALSE);
@@ -3201,17 +3154,18 @@
g_return_val_if_fail (iter != NULL, FALSE);
parent_node = FILE_BROWSER_NODE_DIR (parent->user_data);
- uri = unique_new_name (((FileBrowserNode *) parent_node)->uri, _("directory"));
-
- ret = gnome_vfs_make_directory_for_uri (uri, 0755);
+ file = unique_new_name (((FileBrowserNode *) parent_node)->file, _("directory"));
- if (ret != GNOME_VFS_OK) {
+ if (!g_file_make_directory (file, NULL, &error)) {
g_signal_emit (model, model_signals[ERROR], 0,
GEDIT_FILE_BROWSER_ERROR_NEW_DIRECTORY,
- gnome_vfs_result_to_string (ret));
+ error->message);
+ g_error_free (error);
} else {
- node = model_add_node_from_uri (model, (FileBrowserNode *)
- parent_node, uri, NULL);
+ node = model_add_node_from_file (model,
+ (FileBrowserNode *)parent_node,
+ file,
+ NULL);
if (model_node_visibility (model, node)) {
iter->user_data = node;
@@ -3220,42 +3174,39 @@
g_signal_emit (model, model_signals[ERROR], 0,
GEDIT_FILE_BROWSER_ERROR_NEW_FILE,
_
- ("The new file is currently filtered out. You need to adjust your filter settings to make the file visible"));
+ ("The new directory is currently filtered out. You need to adjust your filter settings to make the directory visible"));
}
}
- gnome_vfs_uri_unref (uri);
+ g_object_unref (file);
return result;
}
/* Signal handlers */
static void
-on_directory_monitor_event (GnomeVFSMonitorHandle * handle,
- gchar const *monitor_uri,
- const gchar * info_uri,
- GnomeVFSMonitorEventType event_type,
+on_directory_monitor_event (GFileMonitor * monitor,
+ GFile * file,
+ GFile * other_file,
+ GFileMonitorEvent event_type,
FileBrowserNode * parent)
{
FileBrowserNode *node;
FileBrowserNodeDir *dir = FILE_BROWSER_NODE_DIR (parent);
- GnomeVFSURI *uri;
switch (event_type) {
- case GNOME_VFS_MONITOR_EVENT_DELETED:
- uri = gnome_vfs_uri_new (info_uri);
- node = model_uri_exists (dir->model, parent, uri);
- gnome_vfs_uri_unref (uri);
+ case G_FILE_MONITOR_EVENT_DELETED:
+ node = model_file_exists (dir->model, parent, file);
if (node != NULL) {
// Remove the node
model_remove_node (dir->model, node, NULL, TRUE);
}
break;
- case GNOME_VFS_MONITOR_EVENT_CREATED:
- uri = gnome_vfs_uri_new (info_uri);
-
- model_add_node_from_uri (dir->model, parent, uri, NULL);
- gnome_vfs_uri_unref (uri);
+ case G_FILE_MONITOR_EVENT_CREATED:
+ if (g_file_query_exists (file, NULL)) {
+ model_add_node_from_file (dir->model, parent, file, NULL);
+ }
+
break;
default:
break;
Modified: branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-store.h
==============================================================================
--- /trunk/plugins/filebrowser/gedit-file-browser-store.h (original)
+++ branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-store.h Mon May 5 09:24:33 2008
@@ -23,7 +23,6 @@
#define __GEDIT_FILE_BROWSER_STORE_H__
#include <gtk/gtk.h>
-#include <libgnomevfs/gnome-vfs.h>
G_BEGIN_DECLS
#define GEDIT_TYPE_FILE_BROWSER_STORE (gedit_file_browser_store_get_type ())
@@ -104,6 +103,8 @@
void (*error) (GeditFileBrowserStore * model,
guint code,
gchar * message);
+ gboolean (*no_trash) (GeditFileBrowserStore * model,
+ GList * files);
};
GType gedit_file_browser_store_get_type (void) G_GNUC_CONST;
Modified: branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-utils.c
==============================================================================
--- /trunk/plugins/filebrowser/gedit-file-browser-utils.c (original)
+++ branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-utils.c Mon May 5 09:24:33 2008
@@ -1,33 +1,26 @@
#include <libgnomeui/libgnomeui.h>
-#include <libgnomevfs/gnome-vfs.h>
#include "gedit-file-browser-utils.h"
-GdkPixbuf *
-gedit_file_browser_utils_pixbuf_from_theme (gchar const *name,
- GtkIconSize size)
+static GdkPixbuf *
+process_icon_pixbuf (GdkPixbuf * pixbuf,
+ gchar const * name,
+ gint size,
+ GError * error)
{
- GtkIconTheme *theme;
- gint width;
- GError *error = NULL;
- GdkPixbuf *scale;
- GdkPixbuf *pixbuf;
-
- theme = gtk_icon_theme_get_default ();
- gtk_icon_size_lookup (size, &width, NULL);
-
- pixbuf = gtk_icon_theme_load_icon (theme, name, width, 0, &error);
+ GdkPixbuf * scale;
if (error != NULL) {
- g_warning ("Could not load theme icon %s: %s", name,
+ g_warning ("Could not load theme icon %s: %s",
+ name,
error->message);
g_error_free (error);
}
- if (pixbuf && gdk_pixbuf_get_width (pixbuf) > width) {
+ if (pixbuf && gdk_pixbuf_get_width (pixbuf) > size) {
scale = gdk_pixbuf_scale_simple (pixbuf,
- width,
- width,
+ size,
+ size,
GDK_INTERP_BILINEAR);
g_object_unref (pixbuf);
pixbuf = scale;
@@ -37,39 +30,149 @@
}
GdkPixbuf *
-gedit_file_browser_utils_pixbuf_from_mime_type (gchar const *uri,
- gchar const *mime,
- GtkIconSize size)
+gedit_file_browser_utils_pixbuf_from_theme (gchar const * name,
+ GtkIconSize size)
{
- GtkIconTheme *theme;
+ gint width;
+ GError *error = NULL;
GdkPixbuf *pixbuf;
- gchar *name;
- theme = gtk_icon_theme_get_default ();
+ gtk_icon_size_lookup (size, &width, NULL);
+
+ pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+ name,
+ width,
+ 0,
+ &error);
+
+ pixbuf = process_icon_pixbuf (pixbuf, name, width, error);
- name =
- gnome_icon_lookup (theme, NULL, uri, NULL, NULL, mime,
- GNOME_ICON_LOOKUP_FLAGS_NONE,
- GNOME_ICON_LOOKUP_RESULT_FLAGS_NONE);
+ return pixbuf;
+}
+
+static GdkPixbuf *
+pixbuf_from_theme_icon (GThemedIcon * icon, gint size)
+{
+ gchar **names;
+ GtkIconInfo * info;
+ GdkPixbuf * pixbuf;
+ GError * error = NULL;
+ gchar * name;
+
+ // Get the icon theme names
+ g_object_get (icon, "names", &names, NULL);
+ info = gtk_icon_theme_choose_icon (gtk_icon_theme_get_default (),
+ (gchar const **)names,
+ size,
+ 0);
+
+ pixbuf = gtk_icon_info_load_icon (info, &error);
+ gtk_icon_info_free (info);
+
+ name = g_strjoinv (", ", names);
+ pixbuf = process_icon_pixbuf (pixbuf, name, size, error);
- pixbuf = gedit_file_browser_utils_pixbuf_from_theme (name, size);
g_free (name);
+ g_strfreev (names);
+
+ return pixbuf;
+}
+
+static GdkPixbuf *
+pixbuf_from_loadable_icon (GLoadableIcon * icon, gint size)
+{
+ // TODO: actual implement this
+ return NULL;
+}
+
+GdkPixbuf *
+gedit_file_browser_utils_pixbuf_from_icon (GIcon * icon,
+ GtkIconSize size)
+{
+ GdkPixbuf * ret = NULL;
+ gint width;
- return pixbuf;
+ if (!icon)
+ return NULL;
+
+ gtk_icon_size_lookup (size, &width, NULL);
+
+ if (G_IS_THEMED_ICON (icon))
+ ret = pixbuf_from_theme_icon (G_THEMED_ICON (icon), width);
+ else if (G_IS_LOADABLE_ICON (icon))
+ ret = pixbuf_from_loadable_icon (G_LOADABLE_ICON (icon), width);
+
+ return ret;
+}
+
+GdkPixbuf *
+gedit_file_browser_utils_pixbuf_from_file (GFile * file,
+ GtkIconSize size)
+{
+ GIcon * icon;
+ GFileInfo * info;
+ GdkPixbuf * ret = NULL;
+
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_ICON,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ NULL);
+
+ if (!info)
+ return NULL;
+
+ icon = g_file_info_get_icon (info);
+ ret = gedit_file_browser_utils_pixbuf_from_icon (icon, size);
+ g_object_unref (info);
+
+ return ret;
}
gchar *
-gedit_file_browser_utils_uri_basename (gchar const * uri)
+gedit_file_browser_utils_file_display (GFile * file)
{
- gchar * basename;
- gchar * normal;
+ gchar * ret;
- basename = g_filename_display_basename (uri);
- normal = gnome_vfs_unescape_string_for_display (basename);
+ GFileInfo * info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ NULL);
- g_free (basename);
+ if (!info)
+ return NULL;
+
+ ret = g_strdup(g_file_info_get_display_name (info));
+ g_object_unref (info);
- return normal;
+ return ret;
+}
+
+gchar *
+gedit_file_browser_utils_file_basename (GFile * file)
+{
+ gchar * display = gedit_file_browser_utils_file_display (file);
+ gchar * ret;
+
+ if (!display)
+ return NULL;
+
+ ret = g_path_get_basename (display);
+
+ g_free (display);
+ return ret;
+}
+
+gchar *
+gedit_file_browser_utils_uri_basename (gchar const * uri)
+{
+ GFile * file = g_file_new_for_uri (uri);
+ gchar * ret = gedit_file_browser_utils_file_basename (file);
+
+ g_object_unref (file);
+
+ return ret;
}
gboolean
@@ -122,3 +225,17 @@
return (ret == GTK_RESPONSE_OK);
}
+
+gboolean
+_gedit_file_browser_utils_file_has_parent (GFile * file)
+{
+ GFile * parent = g_file_get_parent (file);
+
+ if (!parent)
+ return FALSE;
+
+ g_object_unref (parent);
+ return TRUE;
+}
+
+// ex:ts=8:noet:
Modified: branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-utils.h
==============================================================================
--- /trunk/plugins/filebrowser/gedit-file-browser-utils.h (original)
+++ branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-utils.h Mon May 5 09:24:33 2008
@@ -2,18 +2,29 @@
#define __GEDIT_FILE_BROWSER_UTILS_H__
#include <gedit/gedit-window.h>
+#include <gio/gio.h>
GdkPixbuf *gedit_file_browser_utils_pixbuf_from_theme (gchar const *name,
GtkIconSize size);
-GdkPixbuf *gedit_file_browser_utils_pixbuf_from_mime_type (gchar const *uri,
- gchar const *mime,
+GdkPixbuf *gedit_file_browser_utils_pixbuf_from_icon (GIcon * icon,
GtkIconSize size);
+GdkPixbuf *gedit_file_browser_utils_pixbuf_from_file (GFile * file,
+ GtkIconSize size);
+
+gchar * gedit_file_browser_utils_file_display (GFile * file);
+gchar * gedit_file_browser_utils_file_basename (GFile * file);
gchar * gedit_file_browser_utils_uri_basename (gchar const * uri);
+
gboolean gedit_file_browser_utils_confirmation_dialog (GeditWindow * window,
GtkMessageType type,
gchar const *message,
gchar const *secondary,
gchar const * button_stock,
gchar const * button_label);
+
+gboolean _gedit_file_browser_utils_file_has_parent (GFile * file);
+
#endif /* __GEDIT_FILE_BROWSER_UTILS_H__ */
+
+// ex:ts=8:noet:
Modified: branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-view.c
==============================================================================
--- /trunk/plugins/filebrowser/gedit-file-browser-view.c (original)
+++ branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-view.c Mon May 5 09:24:33 2008
@@ -937,28 +937,30 @@
on_cell_edited (GtkCellRendererText * cell, gchar * path, gchar * new_text,
GeditFileBrowserView * tree_view)
{
- GtkTreePath *treepath;
+ GtkTreePath * treepath;
GtkTreeIter iter;
- GError *error = NULL;
-
+ gboolean ret;
+ GError * error = NULL;
+
gtk_tree_path_free (tree_view->priv->editable);
tree_view->priv->editable = NULL;
if (new_text == NULL || *new_text == '\0')
return;
-
+
treepath = gtk_tree_path_new_from_string (path);
- gtk_tree_model_get_iter (GTK_TREE_MODEL (tree_view->priv->model),
- &iter, treepath);
+ ret = gtk_tree_model_get_iter (GTK_TREE_MODEL (tree_view->priv->model), &iter, treepath);
gtk_tree_path_free (treepath);
- if (!gedit_file_browser_store_rename
- (GEDIT_FILE_BROWSER_STORE (tree_view->priv->model), &iter,
- new_text, &error)) {
- if (error) {
- g_signal_emit (tree_view, signals[ERROR], 0,
- error->code, error->message);
- g_error_free (error);
+ if (ret) {
+ if (!gedit_file_browser_store_rename
+ (GEDIT_FILE_BROWSER_STORE (tree_view->priv->model), &iter,
+ new_text, &error)) {
+ if (error) {
+ g_signal_emit (tree_view, signals[ERROR], 0,
+ error->code, error->message);
+ g_error_free (error);
+ }
}
}
}
Modified: branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-widget.c
==============================================================================
--- /trunk/plugins/filebrowser/gedit-file-browser-widget.c (original)
+++ branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-widget.c Mon May 5 09:24:33 2008
@@ -26,10 +26,10 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
+#include <glib.h>
#include <glib/gi18n-lib.h>
+#include <libgnome/gnome-url.h>
#include <gdk/gdkkeysyms.h>
-#include <libgnomevfs/gnome-vfs.h>
-#include <libgnomeui/libgnomeui.h>
#include <gedit/gedit-utils.h>
#include <gedit/gedit-plugin.h>
@@ -60,7 +60,7 @@
COLUMN_INDENT,
COLUMN_ICON,
COLUMN_NAME,
- COLUMN_OBJECT,
+ COLUMN_FILE,
COLUMN_ID,
N_COLUMNS
};
@@ -101,8 +101,8 @@
typedef struct
{
- gchar *root;
- gchar *virtual_root;
+ GFile *root;
+ GFile *virtual_root;
} Location;
typedef struct
@@ -163,6 +163,9 @@
guint code,
gchar * message,
GeditFileBrowserWidget * obj);
+static gboolean on_file_store_no_trash (GeditFileBrowserStore * store,
+ GList * files,
+ GeditFileBrowserWidget * obj);
static void on_combo_changed (GtkComboBox * combo,
GeditFileBrowserWidget * obj);
static gboolean on_treeview_popup_menu (GeditFileBrowserView * treeview,
@@ -187,6 +190,9 @@
GtkTreePath * path,
GtkTreeIter * iter,
GeditFileBrowserWidget * obj);
+static void on_bookmarks_row_deleted (GtkTreeModel * model,
+ GtkTreePath * path,
+ GeditFileBrowserWidget * obj);
static void on_filter_mode_changed (GeditFileBrowserStore * model,
GParamSpec * param,
GeditFileBrowserWidget * obj);
@@ -255,8 +261,12 @@
static void
location_free (Location * loc)
{
- g_free (loc->root);
- g_free (loc->virtual_root);
+ if (loc->root)
+ g_object_unref (loc->root);
+
+ if (loc->virtual_root)
+ g_object_unref (loc->virtual_root);
+
g_free (loc);
}
@@ -287,16 +297,9 @@
remove_path_items (GeditFileBrowserWidget * obj)
{
GtkTreeIter iter;
- gchar *uri;
-
- while (combo_find_by_id (obj, PATH_ID, &iter)) {
- gtk_tree_model_get (GTK_TREE_MODEL
- (obj->priv->combo_model), &iter,
- COLUMN_OBJECT, &uri, -1);
- g_free (uri);
+ while (combo_find_by_id (obj, PATH_ID, &iter))
gtk_tree_store_remove (obj->priv->combo_model, &iter);
- }
}
static void
@@ -326,7 +329,6 @@
g_list_free (obj->priv->locations);
g_hash_table_destroy (obj->priv->bookmarks_hash);
-
G_OBJECT_CLASS (gedit_file_browser_widget_parent_class)->finalize (object);
}
@@ -435,10 +437,9 @@
confirm_no_trash),
g_signal_accumulator_true_handled,
NULL,
- gedit_file_browser_marshal_BOOL__OBJECT_POINTER,
+ gedit_file_browser_marshal_BOOL__POINTER,
G_TYPE_BOOLEAN,
- 2,
- G_TYPE_OBJECT,
+ 1,
GTK_TYPE_POINTER);
g_type_class_add_private (object_class,
@@ -457,33 +458,6 @@
g_slist_prepend (obj->priv->signal_pool, node);
}
-/*static void
-remove_signal_by_func(GeditFileBrowserWidget *obj, gpointer object, gpointer func,
- gpointer data) {
- gulong id;
- GSList *item;
- SignalNode *node;
-
- id = g_signal_handler_find(object,
- G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA,
- 0, 0, NULL, func, data);
-
- if (id != 0) {
- for (item = obj->priv->signal_pool; item; item = item->next) {
- node = (SignalNode *)(item->data);
-
- if (node->id == id) {
- g_signal_handler_disconnect(node->object, node->id);
-
- obj->priv->signal_pool = g_slist_remove_link(
- obj->priv->signal_pool, item);
- g_free(node);
- break;
- }
- }
- }
-}*/
-
static void
clear_signals (GeditFileBrowserWidget * obj)
{
@@ -512,13 +486,13 @@
}
static gboolean
-get_from_bookmark_uri (GeditFileBrowserWidget * obj, GnomeVFSURI * guri,
+get_from_bookmark_file (GeditFileBrowserWidget * obj, GFile * file,
gchar ** name, GdkPixbuf ** icon)
{
gpointer data;
NameIcon * item;
- data = g_hash_table_lookup (obj->priv->bookmarks_hash, GUINT_TO_POINTER (gnome_vfs_uri_hash (guri)));
+ data = g_hash_table_lookup (obj->priv->bookmarks_hash, file);
if (data == NULL)
return FALSE;
@@ -531,63 +505,34 @@
return TRUE;
}
-static gboolean
-get_from_bookmark (GeditFileBrowserWidget * obj, gchar const *uri,
- gchar ** name, GdkPixbuf ** icon)
-{
- GnomeVFSURI *guri;
- gboolean result;
-
- guri = gnome_vfs_uri_new (uri);
-
- if (guri == NULL)
- return FALSE;
-
- result = get_from_bookmark_uri (obj, guri, name, icon);
- gnome_vfs_uri_unref (guri);
-
- return result;
-}
-
static void
insert_path_item (GeditFileBrowserWidget * obj,
- GnomeVFSURI * uri,
+ GFile * file,
GtkTreeIter * after,
GtkTreeIter * iter,
guint indent)
{
- gchar *str2;
- gchar *unescape;
- gchar *str;
+ gchar * unescape;
GdkPixbuf * icon = NULL;
- if (!get_from_bookmark_uri (obj, uri, &unescape, &icon)) {
- str = gnome_vfs_uri_to_string (uri,
- GNOME_VFS_URI_HIDE_PASSWORD |
- GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD |
- GNOME_VFS_URI_HIDE_FRAGMENT_IDENTIFIER);
- unescape = gedit_file_browser_utils_uri_basename (str);
- g_free (str);
+ /* Try to get the icon and name from the bookmarks hash */
+ if (!get_from_bookmark_file (obj, file, &unescape, &icon)) {
+ /* It's not a bookmark, fetch the name and the icon ourselves */
+ unescape = gedit_file_browser_utils_file_basename (file);
/* Get the icon */
- str = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE);
- str2 = gnome_vfs_get_mime_type (str);
- icon = gedit_file_browser_utils_pixbuf_from_mime_type (str,
- str2,
- GTK_ICON_SIZE_MENU);
-
- g_free (str);
- g_free (str2);
+ icon = gedit_file_browser_utils_pixbuf_from_file (file, GTK_ICON_SIZE_MENU);
}
gtk_tree_store_insert_after (obj->priv->combo_model, iter, NULL,
after);
+
gtk_tree_store_set (obj->priv->combo_model,
iter,
COLUMN_INDENT, indent,
COLUMN_ICON, icon,
COLUMN_NAME, unescape,
- COLUMN_OBJECT, gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE),
+ COLUMN_FILE, file,
COLUMN_ID, PATH_ID,
-1);
@@ -620,27 +565,25 @@
}
static guint
-uri_num_parents (GnomeVFSURI * from, GnomeVFSURI * to)
+uri_num_parents (GFile * from, GFile * to)
{
+ /* Determine the number of 'levels' to get from #from to #to. */
guint parents = 0;
- GnomeVFSURI * tmp;
+ GFile * parent;
if (from == NULL)
return 0;
+
+ g_object_ref (from);
- from = gnome_vfs_uri_dup (from);
-
- while (gnome_vfs_uri_has_parent (from) &&
- !(to && gnome_vfs_uri_equal (from, to))) {
- tmp = gnome_vfs_uri_get_parent (from);
- gnome_vfs_uri_unref (from);
- from = tmp;
+ while ((parent = g_file_get_parent (from)) && !(to && g_file_equal (from, to))) {
+ g_object_unref (from);
+ from = parent;
++parents;
}
- gnome_vfs_uri_unref (from);
-
+ g_object_unref (from);
return parents;
}
@@ -648,10 +591,8 @@
insert_location_path (GeditFileBrowserWidget * obj)
{
Location *loc;
- GnomeVFSURI *virtual_root;
- GnomeVFSURI *root;
- GnomeVFSURI *current = NULL;
- GnomeVFSURI * tmp;
+ GFile *current = NULL;
+ GFile * tmp;
GtkTreeIter separator;
GtkTreeIter iter;
guint indent;
@@ -663,18 +604,15 @@
loc = (Location *) (obj->priv->current_location->data);
- virtual_root = gnome_vfs_uri_new (loc->virtual_root);
- root = gnome_vfs_uri_new (loc->root);
- current = virtual_root;
-
+ current = loc->virtual_root;
combo_find_by_id (obj, SEPARATOR_ID, &separator);
- indent = uri_num_parents (virtual_root, root);
+ indent = uri_num_parents (loc->virtual_root, loc->root);
while (current != NULL) {
insert_path_item (obj, current, &separator, &iter, indent--);
- if (current == virtual_root) {
+ if (current == loc->virtual_root) {
g_signal_handlers_block_by_func (obj->priv->combo,
on_combo_changed,
obj);
@@ -687,22 +625,19 @@
obj);
}
- if (gnome_vfs_uri_equal (current, root) || !gnome_vfs_uri_has_parent (current)) {
- if (current != virtual_root)
- gnome_vfs_uri_unref (current);
+ if (g_file_equal (current, loc->root) || !_gedit_file_browser_utils_file_has_parent (current)) {
+ if (current != loc->virtual_root)
+ g_object_unref (current);
break;
}
- tmp = gnome_vfs_uri_get_parent (current);
+ tmp = g_file_get_parent (current);
- if (current != virtual_root)
- gnome_vfs_uri_unref (current);
+ if (current != loc->virtual_root)
+ g_object_unref (current);
current = tmp;
}
-
- gnome_vfs_uri_unref (virtual_root);
- gnome_vfs_uri_unref (root);
}
static void
@@ -739,17 +674,6 @@
COLUMN_ID, BOOKMARKS_ID, -1);
g_object_unref (icon);
-#if 0
- icon = gedit_file_browser_utils_pixbuf_from_theme (GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU);
-
- gtk_tree_store_append (store, &iter, NULL);
- gtk_tree_store_set (store, &iter,
- COLUMN_ICON, icon,
- COLUMN_NAME, _("Recent Files"),
- COLUMN_ID, RECENTS_ID, -1);
- g_object_unref (icon);
-#endif
-
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (obj->priv->combo),
separator_func, obj, NULL);
gtk_combo_box_set_active (GTK_COMBO_BOX (obj->priv->combo), 0);
@@ -786,7 +710,7 @@
G_TYPE_UINT,
GDK_TYPE_PIXBUF,
G_TYPE_STRING,
- G_TYPE_POINTER,
+ G_TYPE_FILE,
G_TYPE_UINT);
obj->priv->combo =
gtk_combo_box_new_with_model (GTK_TREE_MODEL
@@ -1082,28 +1006,25 @@
GdkPixbuf * pixbuf;
gchar * name;
gchar * uri;
- GnomeVFSURI * guri;
+ GFile * file;
NameIcon * item;
model = GTK_TREE_MODEL (obj->priv->bookmarks_store);
uri = gedit_file_bookmarks_store_get_uri (obj->priv->
- bookmarks_store,
- iter);
+ bookmarks_store,
+ iter);
if (uri == NULL)
return;
- guri = gnome_vfs_uri_new (uri);
+ file = g_file_new_for_uri (uri);
g_free (uri);
-
- if (guri == NULL)
- return;
gtk_tree_model_get (model, iter,
- GEDIT_FILE_BROWSER_STORE_COLUMN_ICON,
+ GEDIT_FILE_BOOKMARKS_STORE_COLUMN_ICON,
&pixbuf,
- GEDIT_FILE_BROWSER_STORE_COLUMN_NAME,
+ GEDIT_FILE_BOOKMARKS_STORE_COLUMN_NAME,
&name, -1);
item = g_new (NameIcon, 1);
@@ -1111,10 +1032,8 @@
item->icon = pixbuf;
g_hash_table_insert (obj->priv->bookmarks_hash,
- GUINT_TO_POINTER (gnome_vfs_uri_hash (guri)),
+ file,
item);
-
- gnome_vfs_uri_unref (guri);
}
static void
@@ -1136,6 +1055,11 @@
"row-inserted",
G_CALLBACK (on_bookmarks_row_inserted),
obj);
+
+ g_signal_connect (obj->priv->bookmarks_store,
+ "row-deleted",
+ G_CALLBACK (on_bookmarks_row_deleted),
+ obj);
}
static void
@@ -1223,26 +1147,14 @@
gtk_container_add (GTK_CONTAINER (expander), vbox);
}
-static guint
-uint_hash (gconstpointer key)
-{
- return GPOINTER_TO_UINT (key);
-}
-
-static gboolean
-uint_equal (gconstpointer a, gconstpointer b)
-{
- return GPOINTER_TO_UINT (a) == GPOINTER_TO_UINT (b);
-}
-
static void
gedit_file_browser_widget_init (GeditFileBrowserWidget * obj)
{
obj->priv = GEDIT_FILE_BROWSER_WIDGET_GET_PRIVATE (obj);
- obj->priv->bookmarks_hash = g_hash_table_new_full (uint_hash,
- uint_equal,
- NULL,
+ obj->priv->bookmarks_hash = g_hash_table_new_full (g_file_hash,
+ (GEqualFunc)g_file_equal,
+ g_object_unref,
free_name_icon);
create_toolbar (obj);
@@ -1448,14 +1360,6 @@
result = gedit_file_browser_store_delete_all (GEDIT_FILE_BROWSER_STORE (model),
rows, trash);
-
- if (result == GEDIT_FILE_BROWSER_STORE_RESULT_NO_TRASH) {
- g_signal_emit (obj, signals[CONFIRM_NO_TRASH], 0, model, rows, &confirm);
-
- if (confirm)
- result = gedit_file_browser_store_delete_all (GEDIT_FILE_BROWSER_STORE (model),
- rows, FALSE);
- }
g_list_foreach (rows, (GFunc)gtk_tree_path_free, NULL);
g_list_free (rows);
@@ -1463,17 +1367,28 @@
return result == GEDIT_FILE_BROWSER_STORE_RESULT_OK;
}
-static GnomeVFSURI *
-get_topmost_uri (GnomeVFSURI const *uri)
+static gboolean
+on_file_store_no_trash (GeditFileBrowserStore * store,
+ GList * files,
+ GeditFileBrowserWidget * obj)
+{
+ gboolean confirm = FALSE;
+
+ g_signal_emit (obj, signals[CONFIRM_NO_TRASH], 0, files, &confirm);
+
+ return confirm;
+}
+
+static GFile *
+get_topmost_file (GFile * file)
{
- GnomeVFSURI * tmp;
- GnomeVFSURI * current;
+ GFile * tmp;
+ GFile * current;
- current = gnome_vfs_uri_dup (uri);
+ current = g_object_ref (file);
- while (gnome_vfs_uri_has_parent (current)) {
- tmp = gnome_vfs_uri_get_parent (current);
- gnome_vfs_uri_unref (current);
+ while ((tmp = g_file_get_parent (current)) != NULL) {
+ g_object_unref (current);
current = tmp;
}
@@ -1486,29 +1401,14 @@
{
GtkWidget *result;
GtkWidget *image;
- gchar *base;
gchar *unescape;
GdkPixbuf *pixbuf;
Location *loc;
loc = (Location *) (item->data);
- if (!get_from_bookmark (obj, loc->virtual_root,
- &unescape, &pixbuf)) {
-
- if (gedit_utils_uri_has_file_scheme (loc->virtual_root)) {
- unescape =
- gnome_vfs_get_local_path_from_uri (loc->
- virtual_root);
- base = g_path_get_basename (unescape);
- g_free (unescape);
- } else {
- base = g_path_get_basename (loc->virtual_root);
- }
-
- unescape = gnome_vfs_unescape_string_for_display (base);
- g_free (base);
-
+ if (!get_from_bookmark_file (obj, loc->virtual_root, &unescape, &pixbuf)) {
+ unescape = gedit_file_browser_utils_file_basename (loc->virtual_root);
pixbuf = g_object_ref (icon);
}
@@ -1560,6 +1460,8 @@
GList *(*iter_func) (GList *);
GtkWidget *menu_from;
GtkWidget *menu_to;
+ gchar *root;
+ gchar *virtual_root;
if (!obj->priv->locations)
return;
@@ -1618,11 +1520,16 @@
loc = (Location *) (obj->priv->current_location->data);
/* Set the new root + virtual root */
+ root = g_file_get_uri (loc->root);
+ virtual_root = g_file_get_uri (loc->virtual_root);
+
gedit_file_browser_widget_set_root_and_virtual_root (obj,
- loc->root,
- loc->
+ root,
virtual_root);
+ g_free (root);
+ g_free (virtual_root);
+
obj->priv->changing_location = FALSE;
}
@@ -1783,8 +1690,7 @@
}
void
-gedit_file_browser_widget_set_root_and_virtual_root (GeditFileBrowserWidget
- * obj,
+gedit_file_browser_widget_set_root_and_virtual_root (GeditFileBrowserWidget *obj,
gchar const *root,
gchar const *virtual_root)
{
@@ -1812,39 +1718,31 @@
gchar const *root,
gboolean virtual_root)
{
- GnomeVFSURI *uri;
- GnomeVFSURI *parent;
+ GFile *file;
+ GFile *parent;
gchar *str;
if (!virtual_root) {
gedit_file_browser_widget_set_root_and_virtual_root (obj,
root,
NULL);
- } else {
- uri = gnome_vfs_uri_new (root);
-
- if (uri) {
- parent = get_topmost_uri (uri);
- str =
- gnome_vfs_uri_to_string (parent,
- GNOME_VFS_URI_HIDE_NONE);
-
- gedit_file_browser_widget_set_root_and_virtual_root
- (obj, str, root);
-
- g_free (str);
- gnome_vfs_uri_unref (uri);
- gnome_vfs_uri_unref (parent);
- } else {
- str =
- g_strconcat (_("Invalid uri"), ": ", root,
- NULL);
- g_signal_emit (obj, signals[ERROR], 0,
- GEDIT_FILE_BROWSER_ERROR_SET_ROOT,
- str);
- g_free (str);
- }
+ return;
}
+
+ if (!root)
+ return;
+
+ file = g_file_new_for_uri (root);
+ parent = get_topmost_file (file);
+ str = g_file_get_uri (parent);
+
+ gedit_file_browser_widget_set_root_and_virtual_root
+ (obj, str, root);
+
+ g_free (str);
+
+ g_object_unref (file);
+ g_object_unref (parent);
}
GeditFileBrowserStore *
@@ -1956,7 +1854,7 @@
}
guint
-gedit_file_browser_widget_get_num_selected_files_or_directories(GeditFileBrowserWidget *obj) {
+gedit_file_browser_widget_get_num_selected_files_or_directories (GeditFileBrowserWidget *obj) {
GList *rows, *row;
GtkTreePath *path;
GtkTreeIter iter;
@@ -2091,8 +1989,9 @@
(model);
loc = g_new (Location, 1);
- loc->root = root_uri;
- loc->virtual_root = g_strdup (uri);
+ loc->root = g_file_new_for_uri (root_uri);
+ loc->virtual_root = g_file_new_for_uri (uri);
+ g_free (root_uri);
if (obj->priv->current_location) {
/* Add current location to the menu so we can go back
@@ -2220,6 +2119,12 @@
g_signal_connect (model, "error",
G_CALLBACK
(on_file_store_error), obj));
+
+ add_signal (obj, model,
+ g_signal_connect (model, "no-trash",
+ G_CALLBACK
+ (on_file_store_no_trash), obj));
+
gtk_widget_set_sensitive (obj->priv->filter_expander, TRUE);
}
@@ -2245,7 +2150,8 @@
{
GtkTreeIter iter;
guint id;
- gchar *uri;
+ gchar * uri;
+ GFile * file;
if (!gtk_combo_box_get_active_iter (combo, &iter))
return;
@@ -2261,9 +2167,14 @@
case PATH_ID:
gtk_tree_model_get (GTK_TREE_MODEL
(obj->priv->combo_model), &iter,
- COLUMN_OBJECT, &uri, -1);
+ COLUMN_FILE, &file, -1);
+
+ uri = g_file_get_uri (file);
gedit_file_browser_store_set_virtual_root_from_string
(obj->priv->file_store, uri);
+
+ g_free (uri);
+ g_object_unref (file);
break;
}
}
@@ -2437,6 +2348,30 @@
add_bookmark_hash (obj, iter);
}
+static void
+on_bookmarks_row_deleted (GtkTreeModel * model,
+ GtkTreePath * path,
+ GeditFileBrowserWidget *obj)
+{
+ GtkTreeIter iter;
+ gchar * uri;
+ GFile * file;
+
+ if (!gtk_tree_model_get_iter (model, &iter, path))
+ return;
+
+ uri = gedit_file_bookmarks_store_get_uri (obj->priv->bookmarks_store, &iter);
+
+ if (!uri)
+ return;
+
+ file = g_file_new_for_uri (uri);
+ g_hash_table_remove (obj->priv->bookmarks_hash, file);
+
+ g_object_unref (file);
+ g_free (uri);
+}
+
static void
on_filter_mode_changed (GeditFileBrowserStore * model,
GParamSpec * param,
@@ -2615,7 +2550,8 @@
{
GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview));
GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (obj->priv->treeview));
- GList *rows, *row;
+ GList *rows;
+ GList *row;
gboolean directory_opened = FALSE;
GtkTreeIter iter;
GtkTreePath *path;
Modified: branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-widget.h
==============================================================================
--- /trunk/plugins/filebrowser/gedit-file-browser-widget.h (original)
+++ branches/gnome-2-22/plugins/filebrowser/gedit-file-browser-widget.h Mon May 5 09:24:33 2008
@@ -23,7 +23,6 @@
#define __GEDIT_FILE_BROWSER_WIDGET_H__
#include <gtk/gtk.h>
-#include <libgnomevfs/gnome-vfs.h>
#include "gedit-file-browser-store.h"
#include "gedit-file-bookmarks-store.h"
#include "gedit-file-browser-view.h"
@@ -68,7 +67,6 @@
GeditFileBrowserStore * model,
GList *list);
gboolean (*confirm_no_trash) (GeditFileBrowserWidget * widget,
- GeditFileBrowserStore * model,
GList *list);
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]