diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2009-04-22 00:51:35 +0800 |
---|---|---|
committer | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2009-04-24 08:52:49 +0800 |
commit | a3c76f11316e9db645767ea79ae12302db6c4274 (patch) | |
tree | 86e4f56ebb8ed3dc471481ba4fb434ed67ded5bf /src/empathy-debug-dialog.c | |
parent | 9114490a86ba3fc5003158d8c32d4d4a7358583b (diff) | |
download | gsoc2013-empathy-a3c76f11316e9db645767ea79ae12302db6c4274.tar gsoc2013-empathy-a3c76f11316e9db645767ea79ae12302db6c4274.tar.gz gsoc2013-empathy-a3c76f11316e9db645767ea79ae12302db6c4274.tar.bz2 gsoc2013-empathy-a3c76f11316e9db645767ea79ae12302db6c4274.tar.lz gsoc2013-empathy-a3c76f11316e9db645767ea79ae12302db6c4274.tar.xz gsoc2013-empathy-a3c76f11316e9db645767ea79ae12302db6c4274.tar.zst gsoc2013-empathy-a3c76f11316e9db645767ea79ae12302db6c4274.zip |
Implement save button.
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
Diffstat (limited to 'src/empathy-debug-dialog.c')
-rw-r--r-- | src/empathy-debug-dialog.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/empathy-debug-dialog.c b/src/empathy-debug-dialog.c index ca926c990..13ffca9fa 100644 --- a/src/empathy-debug-dialog.c +++ b/src/empathy-debug-dialog.c @@ -20,8 +20,11 @@ #include "config.h" +#include <stdio.h> +#include <errno.h> #include <glib/gi18n.h> #include <gtk/gtk.h> +#include <glib/gstdio.h> #define DEBUG_FLAG EMPATHY_DEBUG_OTHER #include <libempathy/empathy-debug.h> @@ -500,6 +503,97 @@ debug_dialog_button_press_event_cb (GtkTreeView *view, return FALSE; } +static gboolean +debug_dialog_store_filter_foreach (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + gpointer user_data) +{ + FILE *file = (FILE *) user_data; + gchar *domain, *category, *message, *level_str, *level_upper; + gdouble timestamp; + + gtk_tree_model_get (model, iter, + COL_DEBUG_TIMESTAMP, ×tamp, + COL_DEBUG_DOMAIN, &domain, + COL_DEBUG_CATEGORY, &category, + COL_DEBUG_LEVEL_STRING, &level_str, + COL_DEBUG_MESSAGE, &message, + -1); + + level_upper = g_ascii_strup (level_str, -1); + + g_fprintf (file, "%s%s%s-%s: %e: %s\n", + domain, EMP_STR_EMPTY (category) ? "" : "/", + category, level_upper, timestamp, message); + + g_free (level_upper); + g_free (level_str); + g_free (domain); + g_free (category); + g_free (message); + + return FALSE; +} + +static void +debug_dialog_save_file_chooser_response_cb (GtkDialog *dialog, + gint response_id, + EmpathyDebugDialog *debug_dialog) +{ + EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog); + gchar *filename = NULL; + FILE *file; + + if (response_id != GTK_RESPONSE_ACCEPT) + goto OUT; + + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); + + DEBUG ("Saving log as %s", filename); + + file = g_fopen (filename, "w"); + if (file == NULL) + { + DEBUG ("Failed to open file: %s", g_strerror (errno)); + goto OUT; + } + + gtk_tree_model_foreach (priv->store_filter, + debug_dialog_store_filter_foreach, file); + + fclose (file); + +OUT: + if (filename != NULL) + g_free (filename); + + gtk_widget_destroy (GTK_WIDGET (dialog)); +} + +static void +debug_dialog_save_clicked_cb (GtkToolButton *tool_button, + EmpathyDebugDialog *debug_dialog) +{ + GtkWidget *file_chooser; + + file_chooser = gtk_file_chooser_dialog_new (_("Save"), + GTK_WINDOW (debug_dialog), GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, + NULL); + + gtk_window_set_modal (GTK_WINDOW (file_chooser), TRUE); + gtk_file_chooser_set_do_overwrite_confirmation ( + GTK_FILE_CHOOSER (file_chooser), TRUE); + + g_signal_connect (file_chooser, "response", + G_CALLBACK (debug_dialog_save_file_chooser_response_cb), + debug_dialog); + + gtk_widget_show (file_chooser); +} + static GObject * debug_dialog_constructor (GType type, guint n_construct_params, @@ -557,6 +651,8 @@ debug_dialog_constructor (GType type, /* Save */ item = gtk_tool_button_new_from_stock (GTK_STOCK_SAVE); + g_signal_connect (item, "clicked", + G_CALLBACK (debug_dialog_save_clicked_cb), object); gtk_widget_show (GTK_WIDGET (item)); gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); |