gthumb r2395 - in trunk: . libgthumb
- From: mjc svn gnome org
- To: svn-commits-list gnome org
- Subject: gthumb r2395 - in trunk: . libgthumb
- Date: Tue, 12 Aug 2008 17:23:40 +0000 (UTC)
Author: mjc
Date: Tue Aug 12 17:23:39 2008
New Revision: 2395
URL: http://svn.gnome.org/viewvc/gthumb?rev=2395&view=rev
Log:
2008-08-12 Michael J. Chudobiak <mjc svn gnome org>
* libgthumb/bookmarks.c: (bookmarks_load_from_disk),
(bookmarks_write_to_disk):
* libgthumb/gfile-utils.c: (gfile_output_stream_write_line):
* libgthumb/gfile-utils.h:
gfile migration. Bug #525482. Purged gnome_vfs from bookmark code.
Modified:
trunk/ChangeLog
trunk/libgthumb/bookmarks.c
trunk/libgthumb/gfile-utils.c
trunk/libgthumb/gfile-utils.h
Modified: trunk/libgthumb/bookmarks.c
==============================================================================
--- trunk/libgthumb/bookmarks.c (original)
+++ trunk/libgthumb/bookmarks.c Tue Aug 12 17:23:39 2008
@@ -26,13 +26,12 @@
#include <errno.h>
#include <glib/gi18n.h>
-#include <libgnomevfs/gnome-vfs-ops.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
#include "typedefs.h"
#include "bookmarks.h"
#include "catalog.h"
#include "file-utils.h"
+#include "gfile-utils.h"
#include "preferences.h"
#define MAX_LINE_LENGTH 4096
@@ -299,10 +298,13 @@
void
bookmarks_load_from_disk (Bookmarks *bookmarks)
{
- GnomeVFSResult result;
- GnomeVFSHandle *handle;
- char *uri;
- char line [MAX_LINE_LENGTH];
+ GFileInputStream *istream;
+ GDataInputStream *dstream;
+ GError *error = NULL;
+ GFile *gfile;
+ GFile *home_dir;
+ char *line;
+ gsize length;
g_return_if_fail (bookmarks != NULL);
@@ -310,20 +312,23 @@
if (bookmarks->rc_filename == NULL)
return;
- uri = g_strconcat (get_home_uri (),
- "/",
- bookmarks->rc_filename,
- NULL);
- result = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ);
- g_free (uri);
-
- if (result != GNOME_VFS_OK)
+ home_dir = gfile_get_home_dir ();
+ gfile = gfile_append_path (home_dir, bookmarks->rc_filename, NULL);
+ g_object_unref (home_dir);
+
+ istream = g_file_read (gfile, NULL, &error);
+
+ if (error != NULL) {
+ gfile_warning ("Cannot load bookmark file",
+ gfile,
+ error);
+ g_error_free (error);
return;
+ }
+
+ dstream = g_data_input_stream_new (G_INPUT_STREAM(istream));
- while (_gnome_vfs_read_line (handle,
- line,
- MAX_LINE_LENGTH,
- NULL) == GNOME_VFS_OK) {
+ while ((line = g_data_input_stream_read_line (dstream, &length, NULL, &error))) {
char *path;
if (line[0] != '"')
@@ -341,7 +346,9 @@
get_menu_item_tip (path));
}
- gnome_vfs_close (handle);
+ g_object_unref (dstream);
+ g_object_unref (istream);
+ g_object_unref (gfile);
bookmarks->list = g_list_reverse (bookmarks->list);
}
@@ -350,26 +357,31 @@
void
bookmarks_write_to_disk (Bookmarks *bookmarks)
{
- GnomeVFSResult result;
- GnomeVFSHandle *handle;
- char *uri;
- int lines;
- GList *scan;
+ GFileOutputStream *ostream;
+ GError *error = NULL;
+ GFile *gfile;
+ GFile *home_dir;
+ int lines;
+ GList *scan;
g_return_if_fail (bookmarks != NULL);
if (bookmarks->rc_filename == NULL)
return;
- uri = g_strconcat (get_home_uri (),
- "/",
- bookmarks->rc_filename,
- NULL);
- result = gnome_vfs_create (&handle, uri, GNOME_VFS_OPEN_WRITE, FALSE, FILE_PERMISSIONS);
- g_free (uri);
-
- if (result != GNOME_VFS_OK)
- return;
+ home_dir = gfile_get_home_dir ();
+ gfile = gfile_append_path (home_dir, bookmarks->rc_filename, NULL);
+ g_object_unref (home_dir);
+
+ ostream = g_file_replace (gfile, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &error);
+
+ if (error) {
+ gfile_warning ("Cannot write to bookmark file",
+ gfile,
+ error);
+ g_error_free (error);
+ return;
+ }
/* write the file list. */
@@ -377,17 +389,22 @@
scan = bookmarks->list;
while (((bookmarks->max_lines < 0) || (lines < bookmarks->max_lines))
&& (scan != NULL)) {
- if (_gnome_vfs_write_line (handle,
- "\"%s\"",
- (char*) scan->data) != GNOME_VFS_OK) {
- g_print ("ERROR saving to bookmark file\n");
+ gfile_output_stream_write_line (ostream, error, "\"%s\"", scan->data);
+
+ if (error) {
+ gfile_warning ("Cannot write line to bookmark file",
+ gfile,
+ error);
+ g_error_free (error);
break;
- }
+ }
lines++;
scan = scan->next;
}
- gnome_vfs_close (handle);
+ g_output_stream_close (G_OUTPUT_STREAM(ostream), NULL, NULL);
+ g_object_unref (ostream);
+ g_object_unref (gfile);
}
Modified: trunk/libgthumb/gfile-utils.c
==============================================================================
--- trunk/libgthumb/gfile-utils.c (original)
+++ trunk/libgthumb/gfile-utils.c Tue Aug 12 17:23:39 2008
@@ -582,3 +582,36 @@
{
return gfile_xfer (sfile, dfile, TRUE);
}
+
+
+void
+gfile_output_stream_write_line (GFileOutputStream *ostream,
+ GError *error,
+ const char *format,
+ ...)
+{
+ va_list args;
+ char *str;
+
+ g_assert (format != NULL);
+
+ va_start (args, format);
+ str = g_strdup_vprintf (format, args);
+ va_end (args);
+
+ g_output_stream_write (G_OUTPUT_STREAM(ostream),
+ str,
+ strlen (str),
+ NULL,
+ &error);
+ g_free (str);
+
+ if (error != NULL)
+ return;
+
+ g_output_stream_write (G_OUTPUT_STREAM(ostream),
+ "\n",
+ 1,
+ NULL,
+ &error);
+}
Modified: trunk/libgthumb/gfile-utils.h
==============================================================================
--- trunk/libgthumb/gfile-utils.h (original)
+++ trunk/libgthumb/gfile-utils.h Tue Aug 12 17:23:39 2008
@@ -91,4 +91,10 @@
gboolean gfile_move (GFile *sfile,
GFile *dfile);
+/* line-based read/write */
+void gfile_output_stream_write_line (GFileOutputStream *ostream,
+ GError *error,
+ const char *format,
+ ...);
+
#endif /* GFILE_UTILS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]