]> jfr.im git - irc/hexchat/hexchat.git/commitdiff
Use Gio for url logger origin/wip/file-handling
authorTingPing <redacted>
Wed, 27 Aug 2014 03:09:55 +0000 (23:09 -0400)
committerPatrick Griffis <redacted>
Sun, 31 Jan 2016 21:20:10 +0000 (16:20 -0500)
src/common/cfgfiles.c
src/common/url.c
src/common/url.h
src/fe-gtk/urlgrab.c

index f3271ef16f14fbbb8e1610b5a6b2802e0b0313c5..db32076c1d366a688c0913e1370acec0b908bd29 100644 (file)
@@ -1332,7 +1332,10 @@ hexchat_open_gfile (const char *filename)
        GFile *file;
        gchar *full_path, *full_path_fs;
 
-       full_path = g_build_filename (get_xdir(), filename, NULL);
+       if (g_path_is_absolute (filename))
+               full_path = g_strdup (filename);
+       else
+               full_path = g_build_filename (get_xdir(), filename, NULL);
        full_path_fs = g_filename_from_utf8 (full_path, -1, NULL, NULL, NULL);
 
        file = g_file_new_for_path (full_path_fs);
index 0354d98c9b65c1f1783b6a35c794f55bae140975..c983d0e69f7893158949da4320e0bea0e34220af 100644 (file)
@@ -68,42 +68,47 @@ url_clear (void)
 }
 
 static int
-url_save_cb (char *url, FILE *fd)
+url_save_cb (char *url, GOutputStream *ostream)
 {
-       fprintf (fd, "%s\n", url);
+       stream_writef (ostream, "%s\n", url);
        return TRUE;
 }
 
 void
-url_save_tree (const char *fname, const char *mode, gboolean fullpath)
+url_save_tree (const char *fname)
 {
-       FILE *fd;
+       GFile *file;
+       GOutputStream *ostream;
 
-       if (fullpath)
-               fd = hexchat_fopen_file (fname, mode, XOF_FULLPATH);
-       else
-               fd = hexchat_fopen_file (fname, mode, 0);
-       if (fd == NULL)
-               return;
+       file = hexchat_open_gfile (fname);
 
-       tree_foreach (url_tree, (tree_traverse_func *)url_save_cb, fd);
-       fclose (fd);
+       ostream = G_OUTPUT_STREAM(g_file_append_to (file, G_FILE_CREATE_NONE, NULL, NULL));
+       if (ostream)
+       {
+               tree_foreach (url_tree, (tree_traverse_func *)url_save_cb, ostream);
+               g_object_unref (ostream);
+       }
+       
+       g_object_unref (file);
 }
 
 static void
 url_save_node (char* url)
 {
-       FILE *fd;
+       GFile *file;
+       GOutputStream *ostream;
 
        /* open <config>/url.log in append mode */
-       fd = hexchat_fopen_file ("url.log", "a", 0);
-       if (fd == NULL)
+       file = hexchat_open_gfile ("url.log");
+
+       ostream = G_OUTPUT_STREAM(g_file_append_to (file, G_FILE_CREATE_NONE, NULL, NULL));
+       if (ostream)
        {
-               return;
+               stream_writef (ostream, "%s\n", url);
+               g_object_unref (ostream);
        }
 
-       fprintf (fd, "%s\n", url);
-       fclose (fd);    
+       g_object_unref (file);
 }
 
 static int
index 1b1deb3d86b875dfb49b87c26be7a6bcaabbf94e..d59818d6436a78f87c6b74c1f459d453b0924543 100644 (file)
@@ -33,7 +33,7 @@ extern void *url_tree;
 #define WORD_PATH    -2
 
 void url_clear (void);
-void url_save_tree (const char *fname, const char *mode, gboolean fullpath);
+void url_save_tree (const char *fname);
 int url_last (int *, int *);
 int url_check_word (const char *word);
 void url_check_line (char *buf);
index 79a6d5f575d74f0e7955e644c13bde0d2ee81a8e..a23eb562d7a0182af7b0cb8b35be0f4d30979be7 100644 (file)
@@ -138,7 +138,7 @@ url_save_callback (void *arg1, char *file)
 {
        if (file)
        {
-               url_save_tree (file, "w", TRUE);
+               url_save_tree (file);
        }
 }