aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2009-04-23 19:20:47 +0800
committerJonny Lamb <jonny.lamb@collabora.co.uk>2009-04-24 08:52:50 +0800
commit6cc716c326a27cc4db993a3384ec73bd9bb0aa3d (patch)
tree7426fb5db3d70fa44adb79335f1fbda826576d8e /src
parent74f912543dcd2d78aee3e6ab15bf60a29e08074a (diff)
downloadgsoc2013-empathy-6cc716c326a27cc4db993a3384ec73bd9bb0aa3d.tar
gsoc2013-empathy-6cc716c326a27cc4db993a3384ec73bd9bb0aa3d.tar.gz
gsoc2013-empathy-6cc716c326a27cc4db993a3384ec73bd9bb0aa3d.tar.bz2
gsoc2013-empathy-6cc716c326a27cc4db993a3384ec73bd9bb0aa3d.tar.lz
gsoc2013-empathy-6cc716c326a27cc4db993a3384ec73bd9bb0aa3d.tar.xz
gsoc2013-empathy-6cc716c326a27cc4db993a3384ec73bd9bb0aa3d.tar.zst
gsoc2013-empathy-6cc716c326a27cc4db993a3384ec73bd9bb0aa3d.zip
Use GFile and GFileOutputStream instead of fopen and fprintf.
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
Diffstat (limited to 'src')
-rw-r--r--src/empathy-debug-dialog.c48
1 files changed, 35 insertions, 13 deletions
diff --git a/src/empathy-debug-dialog.c b/src/empathy-debug-dialog.c
index 37c88254b..b2019548d 100644
--- a/src/empathy-debug-dialog.c
+++ b/src/empathy-debug-dialog.c
@@ -20,11 +20,9 @@
#include "config.h"
-#include <stdio.h>
-#include <errno.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
-#include <glib/gstdio.h>
+#include <gio/gio.h>
#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
#include <libempathy/empathy-debug.h>
@@ -513,9 +511,12 @@ debug_dialog_store_filter_foreach (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer user_data)
{
- FILE *file = (FILE *) user_data;
+ GFileOutputStream *output_stream = (GFileOutputStream *) user_data;
gchar *domain, *category, *message, *level_str, *level_upper;
gdouble timestamp;
+ gchar *line;
+ GError *error = NULL;
+ gboolean out = FALSE;
gtk_tree_model_get (model, iter,
COL_DEBUG_TIMESTAMP, &timestamp,
@@ -527,17 +528,28 @@ debug_dialog_store_filter_foreach (GtkTreeModel *model,
level_upper = g_ascii_strup (level_str, -1);
- g_fprintf (file, "%s%s%s-%s: %e: %s\n",
+ line = g_strdup_printf ("%s%s%s-%s: %e: %s\n",
domain, EMP_STR_EMPTY (category) ? "" : "/",
category, level_upper, timestamp, message);
+ g_output_stream_write (G_OUTPUT_STREAM (output_stream), line,
+ strlen (line), NULL, &error);
+
+ if (error != NULL)
+ {
+ DEBUG ("Failed to write to file: %s", error->message);
+ g_error_free (error);
+ out = TRUE;
+ }
+
+ g_free (line);
g_free (level_upper);
g_free (level_str);
g_free (domain);
g_free (category);
g_free (message);
- return FALSE;
+ return out;
}
static void
@@ -547,7 +559,9 @@ debug_dialog_save_file_chooser_response_cb (GtkDialog *dialog,
{
EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
gchar *filename = NULL;
- FILE *file;
+ GFile *gfile = NULL;
+ GFileOutputStream *output_stream = NULL;
+ GError *error = NULL;
if (response_id != GTK_RESPONSE_ACCEPT)
goto OUT;
@@ -556,19 +570,27 @@ debug_dialog_save_file_chooser_response_cb (GtkDialog *dialog,
DEBUG ("Saving log as %s", filename);
- file = g_fopen (filename, "w");
- if (file == NULL)
+ gfile = g_file_new_for_path (filename);
+ output_stream = g_file_replace (gfile, NULL, FALSE,
+ G_FILE_CREATE_NONE, NULL, &error);
+
+ if (error != NULL)
{
- DEBUG ("Failed to open file: %s", g_strerror (errno));
+ DEBUG ("Failed to open file for writing: %s", error->message);
+ g_error_free (error);
goto OUT;
}
gtk_tree_model_foreach (priv->store_filter,
- debug_dialog_store_filter_foreach, file);
-
- fclose (file);
+ debug_dialog_store_filter_foreach, output_stream);
OUT:
+ if (gfile != NULL)
+ g_object_unref (gfile);
+
+ if (output_stream != NULL)
+ g_object_unref (output_stream);
+
if (filename != NULL)
g_free (filename);