gnome-desktop r4996 - in trunk/libgnome-desktop: . libgnome
- From: vuntz svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-desktop r4996 - in trunk/libgnome-desktop: . libgnome
- Date: Mon, 11 Feb 2008 18:00:06 +0000 (GMT)
Author: vuntz
Date: Mon Feb 11 18:00:05 2008
New Revision: 4996
URL: http://svn.gnome.org/viewvc/gnome-desktop?rev=4996&view=rev
Log:
2008-02-11 Vincent Untz <vuntz gnome org>
Port to gio. Fix bug #510870
* gnome-desktop-item.c: (readbuf_getc): straight gio port
(readbuf_open): ditto, we keep a GFileInputStream instead of a handle
(readbuf_new_from_string): updated
(readbuf_rewind): gio port, without any difficulty
(readbuf_close): updated
(read_sort_order): easy
(make_fake_directory): ditto
(gnome_desktop_item_new_from_file): I love gio
(get_dirname): killed
(gnome_desktop_item_new_from_uri): gio is my friend
(gnome_desktop_item_new_from_gfile): new, nothing hard here
(make_args): we use GFile instead of GnomeVFSURI now
(free_args): updated
(convert_uri): GFile makes this easy
(gnome_desktop_item_launch_on_screen_with_env): no need to make the
uri canonical
(gnome_desktop_item_drop_uri_list): just call
gnome_desktop_item_drop_uri_list_with_env()
(gnome_desktop_item_drop_uri_list_with_env): use
g_uri_list_extract_uris() instead of gnome-vfs things
(gnome_desktop_item_get_file_status): easy gio update
(gnome_desktop_item_set_location): ditto
(gnome_desktop_item_set_location_file): ditto
(gnome_desktop_item_set_location_gfile): new, easy
(stream_printf): renamed from vfs_printf, GOutputStream is my friend
(dump_section): updated
(ditem_save): easy gio update
* gnome-ditem-edit.c: (gnome_ditem_edit_sync_ditem): get rid of
gnome-vfs, it wasn't needed anyway
* libgnome/gnome-desktop-item.h: get rid of a comment about gnome-vfs
* test-ditem.c: (test_ditem): get rid of gnome-vfs
Modified:
trunk/libgnome-desktop/ChangeLog
trunk/libgnome-desktop/gnome-desktop-item.c
trunk/libgnome-desktop/gnome-ditem-edit.c
trunk/libgnome-desktop/libgnome/gnome-desktop-item.h
trunk/libgnome-desktop/test-ditem.c
Modified: trunk/libgnome-desktop/gnome-desktop-item.c
==============================================================================
--- trunk/libgnome-desktop/gnome-desktop-item.c (original)
+++ trunk/libgnome-desktop/gnome-desktop-item.c Mon Feb 11 18:00:05 2008
@@ -45,9 +45,7 @@
#include <locale.h>
#include <popt.h>
-#include <libgnomevfs/gnome-vfs-uri.h>
-#include <libgnomevfs/gnome-vfs-ops.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
+#include <gio/gio.h>
#ifdef HAVE_STARTUP_NOTIFICATION
#define SN_API_NOT_YET_FROZEN
@@ -106,13 +104,14 @@
} Encoding;
/*
- * GnomeVFS reading utils, that look like the libc buffered io stuff
+ * IO reading utils, that look like the libc buffered io stuff
*/
#define READ_BUF_SIZE (32 * 1024)
typedef struct {
- GnomeVFSHandle *handle;
+ GFile *file;
+ GFileInputStream *stream;
char *uri;
char *buf;
gboolean buf_needs_free;
@@ -129,6 +128,13 @@
const char *uri,
GError **error);
+static void gnome_desktop_item_set_location_gfile (GnomeDesktopItem *item,
+ GFile *file);
+
+static GnomeDesktopItem *gnome_desktop_item_new_from_gfile (GFile *file,
+ GnomeDesktopItemLoadFlags flags,
+ GError **error);
+
static int
readbuf_getc (ReadBuf *rb)
{
@@ -137,18 +143,18 @@
if (rb->size == 0 ||
rb->pos == rb->size) {
- GnomeVFSFileSize bytes_read;
+ gssize bytes_read;
- /* FIXME: handle errors other than EOF */
- if (rb->handle == NULL
- || gnome_vfs_read (rb->handle,
- rb->buf,
- READ_BUF_SIZE,
- &bytes_read) != GNOME_VFS_OK) {
+ if (rb->stream == NULL)
bytes_read = 0;
- }
+ else
+ bytes_read = g_input_stream_read (G_INPUT_STREAM (rb->stream),
+ rb->buf,
+ READ_BUF_SIZE,
+ NULL, NULL);
- if (bytes_read == 0) {
+ /* FIXME: handle errors other than EOF */
+ if (bytes_read <= 0) {
rb->eof = TRUE;
return EOF;
}
@@ -192,29 +198,35 @@
}
static ReadBuf *
-readbuf_open (const char *uri, GError **error)
+readbuf_open (GFile *file, GError **error)
{
- GnomeVFSResult result;
- GnomeVFSHandle *handle;
+ GError *local_error;
+ GFileInputStream *stream;
+ char *uri;
ReadBuf *rb;
- g_return_val_if_fail (uri != NULL, NULL);
+ g_return_val_if_fail (file != NULL, NULL);
+
+ uri = g_file_get_uri (file);
+ local_error = NULL;
+ stream = g_file_read (file, NULL, &local_error);
- result = gnome_vfs_open (&handle, uri,
- GNOME_VFS_OPEN_READ);
- if (result != GNOME_VFS_OK) {
+ if (stream == NULL) {
g_set_error (error,
/* FIXME: better errors */
GNOME_DESKTOP_ITEM_ERROR,
GNOME_DESKTOP_ITEM_ERROR_CANNOT_OPEN,
_("Error reading file '%s': %s"),
- uri, gnome_vfs_result_to_string (result));
+ uri, local_error->message);
+ g_error_free (local_error);
+ g_free (uri);
return NULL;
}
rb = g_new0 (ReadBuf, 1);
- rb->handle = handle;
- rb->uri = g_strdup (uri);
+ rb->stream = stream;
+ rb->file = g_file_dup (file);
+ rb->uri = uri;
rb->buf = g_malloc (READ_BUF_SIZE);
rb->buf_needs_free = TRUE;
/* rb->past_first_read = FALSE; */
@@ -234,7 +246,8 @@
g_return_val_if_fail (length >= 0, NULL);
rb = g_new0 (ReadBuf, 1);
- /* rb->handle = NULL; */
+ /* rb->file = NULL; */
+ /* rb->stream = NULL; */
rb->uri = g_strdup (uri);
rb->buf = (char *) string;
/* rb->buf_needs_free = FALSE; */
@@ -249,7 +262,7 @@
static gboolean
readbuf_rewind (ReadBuf *rb, GError **error)
{
- GnomeVFSResult result;
+ GError *local_error;
rb->eof = FALSE;
rb->pos = 0;
@@ -259,24 +272,21 @@
rb->size = 0;
- if (rb->handle) {
- result = gnome_vfs_seek (
- rb->handle, GNOME_VFS_SEEK_START, 0);
- if (result == GNOME_VFS_OK)
- return TRUE;
+ if (g_seekable_seek (G_SEEKABLE (rb->stream),
+ 0, G_SEEK_SET, NULL, NULL))
+ return TRUE;
- gnome_vfs_close (rb->handle);
- rb->handle = NULL;
- }
+ g_object_unref (rb->stream);
+ local_error = NULL;
+ rb->stream = g_file_read (rb->file, NULL, &local_error);
- result = gnome_vfs_open (
- &rb->handle, rb->uri, GNOME_VFS_OPEN_READ);
- if (result != GNOME_VFS_OK) {
+ if (rb->stream == NULL) {
g_set_error (
error, GNOME_DESKTOP_ITEM_ERROR,
GNOME_DESKTOP_ITEM_ERROR_CANNOT_OPEN,
_("Error rewinding file '%s': %s"),
- rb->uri, gnome_vfs_result_to_string (result));
+ rb->uri, local_error->message);
+ g_error_free (local_error);
return FALSE;
}
@@ -287,8 +297,10 @@
static void
readbuf_close (ReadBuf *rb)
{
- if (rb->handle != NULL)
- gnome_vfs_close (rb->handle);
+ if (rb->stream != NULL)
+ g_object_unref (rb->stream);
+ if (rb->file != NULL)
+ g_object_unref (rb->file);
g_free (rb->uri);
if (rb->buf_needs_free)
g_free (rb->buf);
@@ -465,16 +477,17 @@
}
static void
-read_sort_order (GnomeDesktopItem *item, const char *dir)
+read_sort_order (GnomeDesktopItem *item, GFile *dir)
{
- char *file;
+ GFile *child;
char buf[BUFSIZ];
GString *str;
ReadBuf *rb;
- file = g_build_filename (dir, ".order", NULL);
- rb = readbuf_open (file, NULL);
- g_free (file);
+ child = g_file_get_child (dir, ".order");
+
+ rb = readbuf_open (child, NULL);
+ g_object_unref (child);
if (rb == NULL)
return;
@@ -496,19 +509,21 @@
}
static GnomeDesktopItem *
-make_fake_directory (const char *dir)
+make_fake_directory (GFile *dir)
{
GnomeDesktopItem *item;
- char *file;
+ GFile *child;
item = gnome_desktop_item_new ();
gnome_desktop_item_set_entry_type (item,
GNOME_DESKTOP_ITEM_TYPE_DIRECTORY);
- file = g_build_filename (dir, ".directory", NULL);
+
+
item->mtime = DONT_UPDATE_MTIME; /* it doesn't exist, we know that */
- gnome_desktop_item_set_location (item, file);
+ child = g_file_get_child (dir, ".directory");
+ gnome_desktop_item_set_location_gfile (item, child);
item->mtime = 0;
- g_free (file);
+ g_object_unref (child);
read_sort_order (item, dir);
@@ -530,42 +545,20 @@
GError **error)
{
GnomeDesktopItem *retval;
- char *uri;
+ GFile *gfile;
g_return_val_if_fail (file != NULL, NULL);
- if (g_path_is_absolute (file)) {
- uri = gnome_vfs_get_uri_from_local_path (file);
- } else {
- char *cur = g_get_current_dir ();
- char *full = g_build_filename (cur, file, NULL);
- g_free (cur);
- uri = gnome_vfs_get_uri_from_local_path (full);
- g_free (full);
- }
- retval = gnome_desktop_item_new_from_uri (uri, flags, error);
-
- g_free (uri);
+ gfile = g_file_new_for_path (file);
+ retval = gnome_desktop_item_new_from_gfile (gfile, flags, error);
+ g_object_unref (gfile);
return retval;
}
-static char *
-get_dirname (const char *uri)
-{
- GnomeVFSURI *vfsuri = gnome_vfs_uri_new (uri);
- char *dirname;
-
- if (vfsuri == NULL)
- return NULL;
- dirname = gnome_vfs_uri_extract_dirname (vfsuri);
- gnome_vfs_uri_unref (vfsuri);
- return dirname;
-}
-
/**
* gnome_desktop_item_new_from_uri:
- * @uri: GnomeVFSURI to load the GnomeDesktopItem from
+ * @uri: URI to load the GnomeDesktopItem from
* @flags: Flags to influence the loading process
*
* This function loads 'uri' and turns it into a GnomeDesktopItem.
@@ -578,34 +571,44 @@
GError **error)
{
GnomeDesktopItem *retval;
- char *subfn, *dir;
- GnomeVFSFileInfo *info;
- time_t mtime = 0;
- ReadBuf *rb;
- GnomeVFSResult result;
+ GFile *file;
g_return_val_if_fail (uri != NULL, NULL);
- info = gnome_vfs_file_info_new ();
+ file = g_file_new_for_uri (uri);
+ retval = gnome_desktop_item_new_from_gfile (file, flags, error);
+ g_object_unref (file);
- result = gnome_vfs_get_file_info (uri, info,
- GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
- if (result != GNOME_VFS_OK) {
- g_set_error (error,
- /* FIXME: better errors */
- GNOME_DESKTOP_ITEM_ERROR,
- GNOME_DESKTOP_ITEM_ERROR_CANNOT_OPEN,
- _("Error reading file '%s': %s"),
- uri, gnome_vfs_result_to_string (result));
+ return retval;
+}
- gnome_vfs_file_info_unref (info);
+static GnomeDesktopItem *
+gnome_desktop_item_new_from_gfile (GFile *file,
+ GnomeDesktopItemLoadFlags flags,
+ GError **error)
+{
+ GnomeDesktopItem *retval;
+ GFile *subfn;
+ GFileInfo *info;
+ GFileType type;
+ GFile *parent;
+ time_t mtime = 0;
+ ReadBuf *rb;
+ g_return_val_if_fail (file != NULL, NULL);
+
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_TYPE","G_FILE_ATTRIBUTE_TIME_MODIFIED,
+ G_FILE_QUERY_INFO_NONE, NULL, error);
+ if (info == NULL)
return NULL;
- }
-
- if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE &&
- info->type != GNOME_VFS_FILE_TYPE_REGULAR &&
- info->type != GNOME_VFS_FILE_TYPE_DIRECTORY) {
+
+ type = g_file_info_get_file_type (info);
+
+ if (type != G_FILE_TYPE_REGULAR && type != G_FILE_TYPE_DIRECTORY) {
+ char *uri;
+
+ uri = g_file_get_uri (file);
g_set_error (error,
/* FIXME: better errors */
GNOME_DESKTOP_ITEM_ERROR,
@@ -613,46 +616,50 @@
_("File '%s' is not a regular file or directory."),
uri);
- gnome_vfs_file_info_unref (info);
+ g_free (uri);
+ g_object_unref (info);
return NULL;
}
- if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MTIME)
- mtime = info->mtime;
- else
- mtime = 0;
+ mtime = g_file_info_get_attribute_uint64 (info,
+ G_FILE_ATTRIBUTE_TIME_MODIFIED);
- if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE &&
- info->type == GNOME_VFS_FILE_TYPE_DIRECTORY) {
- subfn = g_build_filename (uri, ".directory", NULL);
- gnome_vfs_file_info_clear (info);
- if (gnome_vfs_get_file_info (subfn, info,
- GNOME_VFS_FILE_INFO_FOLLOW_LINKS) != GNOME_VFS_OK) {
- gnome_vfs_file_info_unref (info);
- g_free (subfn);
+ g_object_unref (info);
+
+ if (type == G_FILE_TYPE_DIRECTORY) {
+ GFile *child;
+ GFileInfo *child_info;
+
+ child = g_file_get_child (file, ".directory");
+ child_info = g_file_query_info (child,
+ G_FILE_ATTRIBUTE_TIME_MODIFIED,
+ G_FILE_QUERY_INFO_NONE,
+ NULL, NULL);
+
+ if (child_info == NULL) {
+ g_object_unref (child);
if (flags & GNOME_DESKTOP_ITEM_LOAD_ONLY_IF_EXISTS) {
return NULL;
} else {
- return make_fake_directory (uri);
+ return make_fake_directory (file);
}
}
- if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MTIME)
- mtime = info->mtime;
- else
- mtime = 0;
+ mtime = g_file_info_get_attribute_uint64 (child_info,
+ G_FILE_ATTRIBUTE_TIME_MODIFIED);
+ g_object_unref (child_info);
+
+ subfn = child;
} else {
- subfn = g_strdup (uri);
+ subfn = g_file_dup (file);
}
- gnome_vfs_file_info_unref (info);
-
rb = readbuf_open (subfn, error);
if (rb == NULL) {
- g_free (subfn);
+ g_object_unref (subfn);
return NULL;
}
@@ -661,28 +668,28 @@
error);
if (retval == NULL) {
- g_free (subfn);
+ g_object_unref (subfn);
return NULL;
}
if (flags & GNOME_DESKTOP_ITEM_LOAD_ONLY_IF_EXISTS &&
! gnome_desktop_item_exists (retval)) {
gnome_desktop_item_unref (retval);
- g_free (subfn);
+ g_object_unref (subfn);
return NULL;
}
retval->mtime = DONT_UPDATE_MTIME;
- gnome_desktop_item_set_location (retval, subfn);
+ gnome_desktop_item_set_location_gfile (retval, subfn);
retval->mtime = mtime;
- dir = get_dirname (retval->location);
- if (dir != NULL) {
- read_sort_order (retval, dir);
- g_free (dir);
+ parent = g_file_get_parent (file);
+ if (parent != NULL) {
+ read_sort_order (retval, parent);
+ g_object_unref (parent);
}
- g_free (subfn);
+ g_object_unref (subfn);
return retval;
}
@@ -1115,13 +1122,12 @@
GList *li;
for (li = files; li != NULL; li = li->next) {
- GnomeVFSURI *uri;
+ GFile *gfile;
const char *file = li->data;
if (file == NULL)
- continue;;
- uri = gnome_vfs_uri_new (file);
- if (uri)
- list = g_slist_prepend (list, uri);
+ continue;
+ gfile = g_file_new_for_uri (file);
+ list = g_slist_prepend (list, gfile);
}
return g_slist_reverse (list);
@@ -1133,9 +1139,8 @@
GSList *li;
for (li = list; li != NULL; li = li->next) {
- GnomeVFSURI *uri = li->data;
+ g_object_unref (G_FILE (li->data));
li->data = NULL;
- gnome_vfs_uri_unref (uri);
}
g_slist_free (list);
}
@@ -1184,35 +1189,29 @@
} ConversionType;
static char *
-convert_uri (GnomeVFSURI *uri,
+convert_uri (GFile *file,
ConversionType conversion)
{
- char *uri_str;
- char *local_path;
char *retval = NULL;
- uri_str = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE);
-
- if (conversion == URI_TO_STRING)
- return uri_str;
-
- local_path = gnome_vfs_get_local_path_from_uri (uri_str);
- g_free (uri_str);
-
- if (!local_path)
- return NULL;
-
switch (conversion) {
+ case URI_TO_STRING:
+ retval = g_file_get_uri (file);
+ break;
case URI_TO_LOCAL_PATH:
- retval = local_path;
+ retval = g_file_get_path (file);
break;
case URI_TO_LOCAL_DIRNAME:
- retval = g_path_get_dirname (local_path);
- g_free (local_path);
+ {
+ char *local_path;
+
+ local_path = g_file_get_path (file);
+ retval = g_path_get_dirname (local_path);
+ g_free (local_path);
+ }
break;
case URI_TO_LOCAL_BASENAME:
- retval = g_path_get_basename (local_path);
- g_free (local_path);
+ retval = g_file_get_basename (file);
break;
default:
g_assert_not_reached ();
@@ -2050,16 +2049,14 @@
/* This is a URL, so launch it as a url */
if (item->type == GNOME_DESKTOP_ITEM_TYPE_LINK) {
const char *url;
- char *free_url;
gboolean retval;
url = gnome_desktop_item_get_string (item, GNOME_DESKTOP_ITEM_URL);
- if (url && url[0] != '\0')
- free_url = gnome_vfs_make_uri_canonical (url);
/* Gnome panel used to put this in Exec */
- else if (exec && exec[0] != '\0')
- free_url = gnome_vfs_make_uri_canonical (exec);
- else {
+ if (!(url && url[0] != '\0'))
+ url = exec;
+
+ if (!(url && url[0] != '\0')) {
g_set_error (error,
GNOME_DESKTOP_ITEM_ERROR,
GNOME_DESKTOP_ITEM_ERROR_NO_URL,
@@ -2067,8 +2064,7 @@
return -1;
}
- retval = gnome_url_show (free_url, error);
- g_free (free_url);
+ retval = gnome_url_show (url, error);
return retval ? 0 : -1;
}
@@ -2224,22 +2220,8 @@
GnomeDesktopItemLaunchFlags flags,
GError **error)
{
- GList *li;
- int ret;
- GList *list = gnome_vfs_uri_list_parse (uri_list);
-
- for (li = list; li != NULL; li = li->next) {
- GnomeVFSURI *uri = li->data;
- li->data = gnome_vfs_uri_to_string (uri, 0 /* hide_options */);
- gnome_vfs_uri_unref (uri);
- }
-
- ret = gnome_desktop_item_launch (item, list, flags, error);
-
- g_list_foreach (list, (GFunc)g_free, NULL);
- g_list_free (list);
-
- return ret;
+ return gnome_desktop_item_drop_uri_list_with_env (item, uri_list,
+ flags, NULL, error);
}
/**
@@ -2265,20 +2247,22 @@
char **envp,
GError **error)
{
- GList *li;
int ret;
- GList *list = gnome_vfs_uri_list_parse (uri_list);
+ char *uri;
+ char **uris;
+ GList *list = NULL;
- for (li = list; li != NULL; li = li->next) {
- GnomeVFSURI *uri = li->data;
- li->data = gnome_vfs_uri_to_string (uri, 0 /* hide_options */);
- gnome_vfs_uri_unref (uri);
+ uris = g_uri_list_extract_uris (uri_list);
+
+ for (uri = uris[0]; uri != NULL; uri++) {
+ list = g_list_prepend (list, uri);
}
+ list = g_list_reverse (list);
ret = gnome_desktop_item_launch_with_env (
item, list, flags, envp, error);
- g_list_foreach (list, (GFunc)g_free, NULL);
+ g_strfreev (uris);
g_list_free (list);
return ret;
@@ -2435,26 +2419,28 @@
gnome_desktop_item_get_file_status (const GnomeDesktopItem *item)
{
GnomeDesktopItemStatus retval;
- GnomeVFSFileInfo *info;
+ GFile *file;
+ GFileInfo *info;
g_return_val_if_fail (item != NULL, GNOME_DESKTOP_ITEM_DISAPPEARED);
g_return_val_if_fail (item->refcount > 0, GNOME_DESKTOP_ITEM_DISAPPEARED);
- info = gnome_vfs_file_info_new ();
-
- if (item->location == NULL ||
- gnome_vfs_get_file_info (item->location, info,
- GNOME_VFS_FILE_INFO_FOLLOW_LINKS) != GNOME_VFS_OK) {
- gnome_vfs_file_info_unref (info);
+ if (item->location == NULL)
return GNOME_DESKTOP_ITEM_DISAPPEARED;
- }
+
+ file = g_file_new_for_uri (item->location);
+ info = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED,
+ G_FILE_QUERY_INFO_NONE, NULL, NULL);
retval = GNOME_DESKTOP_ITEM_UNCHANGED;
- if ((info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MTIME) &&
- info->mtime > item->mtime)
+
+ if (!g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED))
+ retval = GNOME_DESKTOP_ITEM_DISAPPEARED;
+ else if (item->mtime < g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED))
retval = GNOME_DESKTOP_ITEM_CHANGED;
- gnome_vfs_file_info_unref (info);
+ g_object_unref (info);
+ g_object_unref (file);
return retval;
}
@@ -2829,19 +2815,23 @@
item->mtime = 0;
if (item->location) {
- GnomeVFSFileInfo *info;
- GnomeVFSResult res;
+ GFile *file;
+ GFileInfo *info;
- info = gnome_vfs_file_info_new ();
+ file = g_file_new_for_uri (item->location);
- res = gnome_vfs_get_file_info (item->location, info,
- GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
-
- if (res == GNOME_VFS_OK &&
- info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MTIME)
- item->mtime = info->mtime;
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_TIME_MODIFIED,
+ G_FILE_QUERY_INFO_NONE,
+ NULL, NULL);
+ if (info) {
+ if (g_file_info_has_attribute (info,
+ G_FILE_ATTRIBUTE_TIME_MODIFIED))
+ item->mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
+ g_object_unref (info);
+ }
- gnome_vfs_file_info_unref (info);
+ g_object_unref (file);
}
}
@@ -2863,8 +2853,26 @@
g_return_if_fail (item->refcount > 0);
if (file != NULL) {
+ GFile *gfile;
+
+ gfile = g_file_new_for_path (file);
+ gnome_desktop_item_set_location_gfile (item, gfile);
+ g_object_unref (gfile);
+ } else {
+ gnome_desktop_item_set_location (item, NULL);
+ }
+}
+
+static void
+gnome_desktop_item_set_location_gfile (GnomeDesktopItem *item, GFile *file)
+{
+ g_return_if_fail (item != NULL);
+ g_return_if_fail (item->refcount > 0);
+
+ if (file != NULL) {
char *uri;
- uri = gnome_vfs_get_uri_from_local_path (file);
+
+ uri = g_file_get_uri (file);
gnome_desktop_item_set_location (item, uri);
g_free (uri);
} else {
@@ -3975,38 +3983,38 @@
return item;
}
-static void vfs_printf (GnomeVFSHandle *handle,
- const char *format, ...) G_GNUC_PRINTF (2, 3);
+static void stream_printf (GFileOutputStream *stream,
+ const char *format, ...) G_GNUC_PRINTF (2, 3);
static void
-vfs_printf (GnomeVFSHandle *handle, const char *format, ...)
+stream_printf (GFileOutputStream *stream, const char *format, ...)
{
va_list args;
gchar *s;
- GnomeVFSFileSize bytes_written;
va_start (args, format);
s = g_strdup_vprintf (format, args);
va_end (args);
/* FIXME: what about errors */
- gnome_vfs_write (handle, s, strlen (s), &bytes_written);
+ g_output_stream_write (G_OUTPUT_STREAM (stream), s, strlen (s),
+ NULL, NULL);
g_free (s);
}
static void
-dump_section (GnomeDesktopItem *item, GnomeVFSHandle *handle, Section *section)
+dump_section (GnomeDesktopItem *item, GFileOutputStream *stream, Section *section)
{
GList *li;
- vfs_printf (handle, "[%s]\n", section->name);
+ stream_printf (stream, "[%s]\n", section->name);
for (li = section->keys; li != NULL; li = li->next) {
const char *key = li->data;
char *full = g_strdup_printf ("%s/%s", section->name, key);
const char *value = g_hash_table_lookup (item->main_hash, full);
if (value != NULL) {
char *val = escape_string_and_dup (value);
- vfs_printf (handle, "%s=%s\n", key, val);
+ stream_printf (stream, "%s=%s\n", key, val);
g_free (val);
}
g_free (full);
@@ -4017,41 +4025,28 @@
ditem_save (GnomeDesktopItem *item, const char *uri, GError **error)
{
GList *li;
- GnomeVFSHandle *handle;
- GnomeVFSResult result;
-
- handle = NULL;
- result = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_WRITE);
- if (result == GNOME_VFS_ERROR_NOT_FOUND) {
- result = gnome_vfs_create (&handle, uri, GNOME_VFS_OPEN_WRITE, TRUE, GNOME_VFS_PERM_USER_ALL);
- } else if (result == GNOME_VFS_OK) {
- result = gnome_vfs_truncate_handle (handle, 0);
- }
-
- if (result != GNOME_VFS_OK) {
- g_set_error (error,
- /* FIXME: better errors */
- GNOME_DESKTOP_ITEM_ERROR,
- GNOME_DESKTOP_ITEM_ERROR_CANNOT_OPEN,
- _("Error writing file '%s': %s"),
- uri, gnome_vfs_result_to_string (result));
+ GFile *file;
+ GFileOutputStream *stream;
+ file = g_file_new_for_uri (uri);
+ stream = g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE,
+ NULL, error);
+ if (stream == NULL)
return FALSE;
- }
- vfs_printf (handle, "[Desktop Entry]\n");
+ stream_printf (stream, "[Desktop Entry]\n");
for (li = item->keys; li != NULL; li = li->next) {
const char *key = li->data;
const char *value = g_hash_table_lookup (item->main_hash, key);
if (value != NULL) {
char *val = escape_string_and_dup (value);
- vfs_printf (handle, "%s=%s\n", key, val);
+ stream_printf (stream, "%s=%s\n", key, val);
g_free (val);
}
}
if (item->sections != NULL)
- vfs_printf (handle, "\n");
+ stream_printf (stream, "\n");
for (li = item->sections; li != NULL; li = li->next) {
Section *section = li->data;
@@ -4060,13 +4055,14 @@
if (section->keys == NULL)
continue;
- dump_section (item, handle, section);
+ dump_section (item, stream, section);
if (li->next != NULL)
- vfs_printf (handle, "\n");
+ stream_printf (stream, "\n");
}
- gnome_vfs_close (handle);
+ g_object_unref (stream);
+ g_object_unref (file);
return TRUE;
}
Modified: trunk/libgnome-desktop/gnome-ditem-edit.c
==============================================================================
--- trunk/libgnome-desktop/gnome-ditem-edit.c (original)
+++ trunk/libgnome-desktop/gnome-ditem-edit.c Mon Feb 11 18:00:05 2008
@@ -31,6 +31,7 @@
#include <ctype.h>
#include <string.h>
#include <glib/gi18n-lib.h>
+#include <gio/gio.h>
#undef GTK_DISABLE_DEPRECATED /* for GtkOptionMenu */
#include <gtk/gtk.h>
@@ -39,8 +40,6 @@
#include <libgnomeui/gnome-uidefs.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
-
#undef GNOME_DISABLE_DEPRECATED
#include <libgnomeui/gnome-icon-entry.h>
@@ -1064,7 +1063,6 @@
GtkWidget *entry;
const char *type;
const char *uri;
- char *free_uri;
const char *attr;
char *file;
gboolean ret;
@@ -1085,18 +1083,12 @@
gnome_desktop_item_set_string (ditem, GNOME_DESKTOP_ITEM_TYPE, type);
/* hack really */
- free_uri = NULL;
- if (type && !strcmp (type, "Link")) {
- free_uri = gnome_vfs_make_uri_canonical (uri);
- uri = free_uri;
-
+ if (type && !strcmp (type, "Link"))
attr = GNOME_DESKTOP_ITEM_URL;
- } else
+ else
attr = GNOME_DESKTOP_ITEM_EXEC;
gnome_desktop_item_set_string (ditem, attr, uri);
- if (free_uri)
- g_free (free_uri);
gnome_desktop_item_set_string (
ditem, GNOME_DESKTOP_ITEM_TRY_EXEC,
Modified: trunk/libgnome-desktop/libgnome/gnome-desktop-item.h
==============================================================================
--- trunk/libgnome-desktop/libgnome/gnome-desktop-item.h (original)
+++ trunk/libgnome-desktop/libgnome/gnome-desktop-item.h Mon Feb 11 18:00:05 2008
@@ -186,8 +186,7 @@
int workspace,
GError **error);
-/* A list of files or urls dropped onto an icon This is the output
- * of gnome_vfs_uri_list_parse */
+/* A list of files or urls dropped onto an icon */
int gnome_desktop_item_drop_uri_list (const GnomeDesktopItem *item,
const char *uri_list,
GnomeDesktopItemLaunchFlags flags,
Modified: trunk/libgnome-desktop/test-ditem.c
==============================================================================
--- trunk/libgnome-desktop/test-ditem.c (original)
+++ trunk/libgnome-desktop/test-ditem.c Mon Feb 11 18:00:05 2008
@@ -22,7 +22,6 @@
#include <libgnomeui/libgnomeui.h>
#include <libgnome/gnome-desktop-item.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
/*
#include <libgnomeui/gnome-ditem-edit.h>
*/
@@ -99,7 +98,7 @@
strcat (path, "/foo.desktop");
g_print ("Saving to foo.desktop\n");
- uri = gnome_vfs_get_uri_from_local_path (path);
+ uri = g_filename_to_uri (path, NULL, NULL);
g_print ("URI: %s\n", uri);
gnome_desktop_item_save (ditem, uri, FALSE, NULL);
g_free (uri);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]