gnome-mud r821 - in trunk: . doc src ui



Author: lharris
Date: Sat Mar 21 09:37:44 2009
New Revision: 821
URL: http://svn.gnome.org/viewvc/gnome-mud?rev=821&view=rev

Log:
Lots of MudLog features added.

Modified:
   trunk/ChangeLog
   trunk/doc/Makefile.am
   trunk/src/mud-connection-view.c
   trunk/src/mud-line-buffer.c
   trunk/src/mud-log.c
   trunk/src/mud-window.c
   trunk/src/mud-window.h
   trunk/ui/main.glade

Modified: trunk/doc/Makefile.am
==============================================================================
--- trunk/doc/Makefile.am	(original)
+++ trunk/doc/Makefile.am	Sat Mar 21 09:37:44 2009
@@ -1,4 +1,4 @@
-SUBDIRS = 
+SUBDIRS =
 
 man_MANS = gnome-mud.6
 

Modified: trunk/src/mud-connection-view.c
==============================================================================
--- trunk/src/mud-connection-view.c	(original)
+++ trunk/src/mud-connection-view.c	Sat Mar 21 09:37:44 2009
@@ -289,7 +289,7 @@
                 "logging",
                 "are we currently logging",
                 FALSE,
-                G_PARAM_READABLE));
+                G_PARAM_READWRITE));
 
     g_object_class_install_property(object_class,
             PROP_CONNECT_HOOK,
@@ -549,6 +549,8 @@
 
     self->log = g_object_new(MUD_TYPE_LOG,
                              "mud-name", self->mud_name,
+                             "window", self->window,
+                             "parent", self,
                               NULL);
 
     buf = g_strdup_printf(_("*** Making connection to %s, port %d.\n"),
@@ -820,6 +822,13 @@
             g_free(new_string);
             break;
 
+        case PROP_LOGGING:
+            new_boolean = g_value_get_boolean(value);
+
+            if(new_boolean != self->logging)
+                self->logging = new_boolean;
+            break;
+
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
             break;
@@ -1215,7 +1224,8 @@
 
                         }
 
-                        mud_log_write_hook(view->log, buf, length);
+                        if(view->logging)
+                            mud_log_write_hook(view->log, buf, length);
                     }
 
                     if (view->connect_hook) {
@@ -2061,8 +2071,10 @@
 {
     g_return_if_fail(IS_MUD_CONNECTION_VIEW(view));
 
-    view->logging = TRUE;
     mud_log_open(view->log);
+
+    if(mud_log_islogging(view->log))
+        view->logging = TRUE;
 }
 
 void

Modified: trunk/src/mud-line-buffer.c
==============================================================================
--- trunk/src/mud-line-buffer.c	(original)
+++ trunk/src/mud-line-buffer.c	Sat Mar 21 09:37:44 2009
@@ -297,8 +297,8 @@
 
                 self->priv->line_buffer = g_list_remove(self->priv->line_buffer,
                                                         kill_line);
-
-                g_free(kill_line);
+                if(kill_line)
+                    g_free(kill_line);
 
                 --self->priv->length;
 

Modified: trunk/src/mud-log.c
==============================================================================
--- trunk/src/mud-log.c	(original)
+++ trunk/src/mud-log.c	Sat Mar 21 09:37:44 2009
@@ -28,26 +28,61 @@
 #include <time.h>
 #include <unistd.h>
 #include <string.h>
+#include <glade/glade-xml.h>
 
 #include "gnome-mud.h"
 #include "mud-log.h"
+#include "mud-window.h"
+#include "mud-connection-view.h"
+#include "mud-line-buffer.h"
 #include "utils.h"
 
 struct _MudLogPrivate
 {
+    GtkWidget *window;
+    GtkWidget *spin_log_next;
+    GtkWidget *spin_log_prev;
+    GtkWidget *check_log_next;
+    GtkWidget *check_log_prev;
+    GtkWidget *check_append;
+    GtkWidget *check_buffer;
+    GtkWidget *check_color;
+    GtkWidget *entry_file;
+    GtkWidget *btn_select;
+
     gboolean active;
+    gboolean append;
+    gboolean color;
+    gboolean buffer;
+    gboolean include_next;
+    gboolean include_prev;
+
+    gboolean done;
+    gboolean finalizing;
+
+    gint next_count;
+    gint prev_count;
+
+    gint count;
 
-    gchar *filename;
     gchar *dir;
+    gchar *filename;
 
     FILE *logfile;
+
+    MudLineBuffer *line_buffer;
+
+    MudWindow *parent_window;
+    MudConnectionView *parent;
 };
 
 /* Property Identifiers */
 enum
 {
     PROP_MUD_LOG_0,
-    PROP_MUD_NAME
+    PROP_MUD_NAME,
+    PROP_PARENT,
+    PROP_WINDOW
 };
 
 /* Define the Type */
@@ -69,8 +104,22 @@
                                  GValue *value,
                                  GParamSpec *pspec);
 
+/* Callbacks */
+static void mud_log_next_toggled_cb(GtkToggleButton *button, MudLog *self);
+static void mud_log_prev_toggled_cb(GtkToggleButton *button, MudLog *self);
+static void mud_log_append_toggled_cb(GtkToggleButton *button, MudLog *self);
+static void mud_log_buffer_toggled_cb(GtkToggleButton *button, MudLog *self);
+static void mud_log_color_toggled_cb(GtkToggleButton *button, MudLog *self);
+static void mud_log_select_clicked_cb(GtkWidget *widget, MudLog *self);
+static void mud_log_next_spin_changed_cb(GtkSpinButton *button, MudLog *self);
+static void mud_log_prev_spin_changed_cb(GtkSpinButton *button, MudLog *self);
+static gboolean mud_log_keypress_cb(GtkWidget *widget,
+                                    GdkEventKey *event,
+                                    MudLog *self);
+static void mud_log_line_added_cb(MudLineBuffer *buffer, MudLog *self);
+
 /* Private Methods */
-static void mud_log_write(MudLog *log, gchar *data, gsize size);
+static void mud_log_write(MudLog *log, const gchar *data, gsize size);
 static void mud_log_remove(MudLog *log);
 
 // MudLog class functions
@@ -100,6 +149,22 @@
                 "name of mud we are logging",
                 "Unnamed",
                 G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
+
+    g_object_class_install_property(object_class,
+            PROP_WINDOW,
+            g_param_spec_object("window",
+                "window",
+                "Parent MudWindow",
+                MUD_TYPE_WINDOW,
+                G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
+
+    g_object_class_install_property(object_class,
+            PROP_PARENT,
+            g_param_spec_object("parent",
+                "parent",
+                "Parent MudConnectionView",
+                MUD_TYPE_CONNECTION_VIEW,
+                G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
 }
 
 static void
@@ -113,6 +178,21 @@
     /* Set defaults for Private Members */
     log->priv->active = FALSE;
     log->priv->logfile = NULL;
+    log->priv->parent_window = NULL;
+    log->priv->parent = NULL;
+    log->priv->filename = NULL;
+
+    log->priv->append = TRUE;
+    log->priv->buffer = FALSE;
+    log->priv->color = FALSE;
+    log->priv->include_next = FALSE;
+    log->priv->include_prev = FALSE;
+    log->priv->done = FALSE;
+    log->priv->finalizing = FALSE;
+
+    log->priv->count = 0; 
+    log->priv->next_count = 0;
+    log->priv->prev_count = 0;
 }
 
 static GObject *
@@ -127,7 +207,7 @@
     MudLogClass *klass;
     GObjectClass *parent_class;
 
-    /* Chain up to parent constructor */
+    /* Chain up to window constructor */
     klass = MUD_LOG_CLASS( g_type_class_peek(MUD_TYPE_LOG) );
     parent_class = G_OBJECT_CLASS( g_type_class_peek_parent(klass) );
     obj = parent_class->constructor(gtype, n_properties, properties);
@@ -137,7 +217,19 @@
     if(!self->mud_name)
     {
         g_printf("ERROR: Tried to instantiate MudLog without passing mud name.\n");
-        g_error("Tried to instantiate MudLog without passing mud name.\n");
+        g_error("Tried to instantiate MudLog without passing mud name.");
+    }
+
+    if(!self->priv->parent_window)
+    {
+        g_printf("ERROR: Tried to instantiate MudLog without passing MudWindow.\n");
+        g_error("Tried to instantiate MudLog without passing MudWindow.");    
+    }
+
+    if(!self->priv->parent)
+    {
+        g_printf("ERROR: Tried to instantiate MudLog without passing MudConnectionView.\n");
+        g_error("Tried to instantiate MudLog without passing MudConnectionView.");    
     }
 
     return obj;
@@ -151,6 +243,8 @@
 
     MLog = MUD_LOG(object);
 
+    MLog->priv->finalizing = TRUE;
+
     if(MLog->priv->active)
         mud_log_close(MLog);
 
@@ -175,7 +269,6 @@
 
     switch(prop_id)
     {
-        /* Parent is Construct Only */
         case PROP_MUD_NAME:
             new_mud_name = g_value_dup_string(value);
 
@@ -191,6 +284,14 @@
 
             break;
 
+        case PROP_WINDOW:
+            self->priv->parent_window = MUD_WINDOW(g_value_get_object(value));
+            break;
+
+        case PROP_PARENT:
+            self->priv->parent = MUD_CONNECTION_VIEW(g_value_get_object(value));
+            break;
+
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
             break;
@@ -213,45 +314,411 @@
             g_value_set_string(value, self->mud_name);
             break;
 
+        case PROP_WINDOW:
+            g_value_take_object(value, self->priv->parent_window);
+            break;
+
+        case PROP_PARENT:
+            g_value_take_object(value, self->priv->parent);
+            break;
+
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
             break;
     }
 }
 
+/* Callbacks */
+static void
+mud_log_select_clicked_cb(GtkWidget *widget,
+                          MudLog *self)
+{
+    gchar *filename;
+    GladeXML *glade;
+    GtkWidget *dialog;
+    gint result;
+
+    glade = glade_xml_new(GLADEDIR "/main.glade", "save_dialog", NULL);
+    dialog = glade_xml_get_widget(glade, "save_dialog");
+    g_object_unref(glade);
+
+    g_object_set(dialog, "title", _("Save log as..."), NULL);
+
+    if(strlen(gtk_entry_get_text(GTK_ENTRY(self->priv->entry_file))) != 0)
+    {
+        const gchar *text = gtk_entry_get_text(GTK_ENTRY(self->priv->entry_file));
+        gchar *dir = g_path_get_dirname(text);
+        gchar *file = g_path_get_basename(text);
+
+        gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),
+                                            dir);
+        gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog),
+                                           file);
+
+        g_free(dir);
+        g_free(file);
+    }
+    else
+    {
+        gchar *name = g_strdup_printf("%s.log", self->mud_name);
+
+        gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),
+                                            g_get_home_dir());
+        gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(dialog),
+                                           name);
+
+        g_free(name);
+    }
+
+    result = gtk_dialog_run(GTK_DIALOG(dialog));
+
+    if(result == GTK_RESPONSE_OK)
+    {
+        if(self->priv->filename)
+        {
+            g_free(self->priv->filename);
+            self->priv->filename = NULL;
+        }
+
+        self->priv->filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
+
+        gtk_entry_set_text(GTK_ENTRY(self->priv->entry_file), self->priv->filename);
+    }
+
+    gtk_widget_destroy(dialog);
+}
+
+static void
+mud_log_next_toggled_cb(GtkToggleButton *button,
+                        MudLog *self)
+{
+    gboolean active;
+
+    g_object_get(button, "active", &active, NULL);
+
+    self->priv->include_next = active;
+
+    if(self->priv->include_next)
+    {
+        self->priv->next_count = gtk_spin_button_get_value_as_int(
+                GTK_SPIN_BUTTON(self->priv->spin_log_next));
+
+        gtk_widget_set_sensitive(self->priv->spin_log_next, TRUE);
+    }
+    else
+    {
+        gtk_widget_set_sensitive(self->priv->spin_log_next, FALSE);
+        self->priv->next_count = 0;
+    }
+}
+
+static void
+mud_log_prev_toggled_cb(GtkToggleButton *button,
+                        MudLog *self)
+{
+    gboolean active;
+
+    g_object_get(button, "active", &active, NULL);
+
+    self->priv->include_prev = active;
+
+    if(self->priv->include_prev)
+    {
+        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(self->priv->check_buffer),
+                                     FALSE);
+
+        self->priv->prev_count = gtk_spin_button_get_value_as_int(
+                GTK_SPIN_BUTTON(self->priv->spin_log_prev));
+
+        gtk_widget_set_sensitive(self->priv->spin_log_prev, TRUE);
+    }
+    else
+    {
+        gtk_widget_set_sensitive(self->priv->spin_log_prev, FALSE);
+        self->priv->prev_count = 0;
+    }
+}
+
+
+static void
+mud_log_append_toggled_cb(GtkToggleButton *button,
+                          MudLog *self)
+{
+    gboolean active;
+
+    g_object_get(button, "active", &active, NULL);
+
+    self->priv->append = active;
+}
+
+static void
+mud_log_buffer_toggled_cb(GtkToggleButton *button,
+                          MudLog *self)
+{
+    gboolean active;
+
+    g_object_get(button, "active", &active, NULL);
+
+    self->priv->buffer = active;
+
+    if(self->priv->buffer)
+        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(self->priv->check_log_prev),
+                                     FALSE);
+}
+
+static void
+mud_log_color_toggled_cb(GtkToggleButton *button,
+                         MudLog *self)
+{
+    gboolean active;
+
+    g_object_get(button, "active", &active, NULL);
+
+    self->priv->color = active;
+}
+
+static gboolean
+mud_log_keypress_cb(GtkWidget *widget,
+                    GdkEventKey *event,
+                    MudLog *self)
+{
+    if(self->priv->filename)
+    {
+        g_free(self->priv->filename);
+        self->priv->filename = NULL;
+    }
+
+    self->priv->filename = g_strdup(
+            gtk_entry_get_text(GTK_ENTRY(self->priv->entry_file)));
+
+    return FALSE;
+}
+
+static void
+mud_log_next_spin_changed_cb(GtkSpinButton *button,
+                             MudLog *self)
+{
+    self->priv->next_count = gtk_spin_button_get_value_as_int(
+                                GTK_SPIN_BUTTON(button));
+}
+
+static void
+mud_log_prev_spin_changed_cb(GtkSpinButton *button,
+                             MudLog *self)
+{
+    self->priv->prev_count = gtk_spin_button_get_value_as_int(
+                                GTK_SPIN_BUTTON(button));
+}
+
+static void
+mud_log_line_added_cb(MudLineBuffer *buffer,
+                      MudLog *self)
+{
+    gulong length;
+    const gchar *line;
+
+    if(!self->priv->done)
+    {
+        g_object_get(buffer, "length", &length, NULL);
+
+        line = mud_line_buffer_get_line(buffer, length - 1);
+
+        if(line && strlen(line) != 0) 
+            mud_log_write(self, line, strlen(line));
+
+        if(self->priv->include_next)
+        {
+            self->priv->count++;
+
+            if(self->priv->count == self->priv->next_count)
+            {
+                self->priv->count = 0;
+                self->priv->next_count = 0;
+
+                self->priv->done = TRUE;
+            }
+        }
+    }
+}
+
 /* Public Methods */
 void
-mud_log_open(MudLog *log)
+mud_log_open(MudLog *self)
 {
+    GladeXML *glade;
+    GtkWidget *main_window;
     gchar buf[1024];
     gchar nameBuf[1024];
     time_t t;
+    gint result;
 
-    g_return_if_fail(MUD_IS_LOG(log));
+    g_return_if_fail(MUD_IS_LOG(self));
 
-    g_snprintf(buf, 1024, "%s/.gnome-mud/logs/%s", g_get_home_dir(), log->mud_name);
+    /* start glading */
+    glade = glade_xml_new(GLADEDIR "/main.glade", "log_config_window", NULL);
 
-    log->priv->dir = g_strdup(buf);
+    self->priv->window = glade_xml_get_widget(glade, "log_config_window");
+    self->priv->check_log_next = glade_xml_get_widget(glade, "inc_next_check_btn");
+    self->priv->spin_log_next = glade_xml_get_widget(glade, "next_spin_btn");
+    self->priv->check_log_prev = glade_xml_get_widget(glade, "inc_prev_check_btn");
+    self->priv->spin_log_prev = glade_xml_get_widget(glade, "prev_spin_btn");
+    self->priv->check_append = glade_xml_get_widget(glade, "append_check_btn");
+    self->priv->check_buffer = glade_xml_get_widget(glade, "buffer_check_btn");
+    self->priv->check_color = glade_xml_get_widget(glade, "color_check_btn");
+    self->priv->btn_select = glade_xml_get_widget(glade, "select_btn");
+    self->priv->entry_file = glade_xml_get_widget(glade, "file_entry");
+
+    g_object_get(self->priv->parent_window, "window", &main_window, NULL);
+
+    gtk_window_set_transient_for(GTK_WINDOW(self->priv->window),
+                                 GTK_WINDOW(main_window));
+
+    g_signal_connect(self->priv->spin_log_next,
+                     "value-changed",
+                     G_CALLBACK(mud_log_next_spin_changed_cb),
+                     self);
+
+    g_signal_connect(self->priv->spin_log_prev,
+                     "value-changed",
+                     G_CALLBACK(mud_log_prev_spin_changed_cb),
+                     self);
+
+    g_signal_connect(self->priv->entry_file,
+                     "key-press-event",
+                     G_CALLBACK(mud_log_keypress_cb),
+                     self);
+
+    g_signal_connect(self->priv->btn_select,
+                     "clicked",
+                     G_CALLBACK(mud_log_select_clicked_cb),
+                     self);
+
+    g_signal_connect(self->priv->check_log_next,
+                     "toggled",
+                     G_CALLBACK(mud_log_next_toggled_cb),
+                     self);
+
+    g_signal_connect(self->priv->check_log_prev,
+                     "toggled",
+                     G_CALLBACK(mud_log_prev_toggled_cb),
+                     self);
+
+    g_signal_connect(self->priv->check_append,
+                     "toggled",
+                     G_CALLBACK(mud_log_append_toggled_cb),
+                     self);
+
+    g_signal_connect(self->priv->check_buffer,
+                     "toggled",
+                     G_CALLBACK(mud_log_buffer_toggled_cb),
+                     self);
+
+    g_signal_connect(self->priv->check_color,
+                     "toggled",
+                     G_CALLBACK(mud_log_color_toggled_cb),
+                     self);
 
-    if(!g_file_test(buf, G_FILE_TEST_IS_DIR))
-        if(mkdir(buf, 0777 ) == -1)
-            return;
+    g_object_unref(glade);
 
-    g_snprintf(nameBuf, 1024, "%s.log", log->mud_name);
+    result = gtk_dialog_run(GTK_DIALOG(self->priv->window));
+    
+    if(result == GTK_RESPONSE_OK)
+    {
+        self->priv->logfile = fopen(self->priv->filename,
+                                    (self->priv->append) ? "a" : "w");
+        if (self->priv->logfile)
+        {
+            time(&t);
+            strftime(buf, 1024,
+                    _("\n*** Log starts *** %d/%m/%Y %H:%M:%S\n"),
+                    localtime(&t));
+            fprintf(self->priv->logfile, "%s", buf);
 
-    log->priv->filename = g_build_path( G_DIR_SEPARATOR_S, log->priv->dir, nameBuf, NULL);
-    log->priv->logfile = fopen(log->priv->filename, "a");
+            if(self->priv->buffer)
+            {
+                VteTerminal *term;
+                GtkClipboard *clipboard;
+                GError *err = NULL;
+                gchar *term_text;
+
+                g_object_get(self->priv->parent, "terminal", &term, NULL);
+
+                clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
+                vte_terminal_select_all(term);
+                vte_terminal_copy_primary(term);
+                term_text = gtk_clipboard_wait_for_text(clipboard);
+                vte_terminal_select_none(term);
+
+                if(term_text)
+                {
+                    fprintf(self->priv->logfile, "%s", term_text);
+                    g_free(term_text);
+                }
+            }
 
-    if (log->priv->logfile)
-    {
-        time(&t);
-        strftime(buf, 1024,
-                _("\n*** Log starts *** %d/%m/%Y %H:%M:%S\n"),
-                localtime(&t));
-        fprintf(log->priv->logfile, "%s", buf);
+            if(self->priv->include_prev)
+            {
+                VteTerminal *term;
+                GtkClipboard *clipboard;
+                GError *err = NULL;
+                gchar *term_text;
+                gchar *buf_text;
+
+                MudLineBuffer *buffer = g_object_new(MUD_TYPE_LINE_BUFFER,
+                                                     "maximum-line-count", self->priv->prev_count,
+                                                     NULL);
+
+                g_object_get(self->priv->parent, "terminal", &term, NULL);
+
+                clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
+                vte_terminal_select_all(term);
+                vte_terminal_copy_primary(term);
+                term_text = gtk_clipboard_wait_for_text(clipboard);
+                vte_terminal_select_none(term);
+
+                if(term_text)
+                {
+                    mud_line_buffer_add_data(buffer, term_text, strlen(term_text));
+                    g_free(term_text);
+
+                    buf_text = mud_line_buffer_get_lines(buffer);
+
+                    fprintf(self->priv->logfile, "%s", buf_text);
+
+                    g_free(buf_text);
+                }
+
+                g_object_unref(buffer);
+            }
+
+            if(self->priv->include_next)
+                self->priv->count = 0;
+
+            self->priv->line_buffer = g_object_new(MUD_TYPE_LINE_BUFFER,
+                                                   "maximum-line-count", 5,
+                                                   NULL);
+
+            g_signal_connect(self->priv->line_buffer,
+                             "line-added",
+                             G_CALLBACK(mud_log_line_added_cb),
+                             self);
+        }
+        else
+        {
+            GtkWidget *main_window;
+
+            g_object_get(self->priv->window, "window", &main_window, NULL);
+
+            utils_error_message(main_window,
+                                _("Log Error"),
+                                _("Could not open \"%s\" for writing."),
+                                self->priv->filename);
+        }
+
+        self->priv->active = TRUE;
     }
 
-    log->priv->active = TRUE;
+    gtk_widget_destroy(self->priv->window);
 }
 
 void
@@ -261,7 +728,6 @@
     time_t t;
 
     g_return_if_fail(MUD_IS_LOG(log));
-    g_return_if_fail(log->priv->logfile != NULL);
 
     time(&t);
     strftime(buf, 255,
@@ -271,7 +737,22 @@
     fprintf(log->priv->logfile, "%s", buf);
     fclose(log->priv->logfile);
 
+    if(log->priv->filename)
+    {
+        g_free(log->priv->filename);
+        log->priv->filename = NULL;
+    }
+
+    g_object_unref(log->priv->line_buffer);
     log->priv->active = FALSE;
+
+    if(!log->priv->finalizing)
+    {
+        g_object_set(log->priv->parent, "logging", FALSE, NULL);
+        mud_window_update_logging_ui(log->priv->parent_window,
+                log->priv->parent,
+                FALSE);
+    }
 }
 
 gboolean
@@ -288,8 +769,15 @@
 {
     g_return_if_fail(MUD_IS_LOG(log));
 
-    if(log->priv->active)
-        mud_log_write(log, data, length);
+    if(log->priv->done)
+    {
+        log->priv->done = FALSE;
+        mud_log_close(log);
+    }
+    else if(log->priv->active)
+    {
+        mud_line_buffer_add_data(log->priv->line_buffer, data, length);
+    }
 }
 
 /* Private Methods */
@@ -305,7 +793,7 @@
 }
 
 static void
-mud_log_write(MudLog *log, gchar *data, gsize size)
+mud_log_write(MudLog *log, const gchar *data, gsize size)
 {
     gchar *stripData;
     gint stripSize = 0;
@@ -315,14 +803,25 @@
     g_return_if_fail(log->priv->logfile != NULL);
     g_return_if_fail(data != NULL);
 
-    stripData = utils_strip_ansi((const gchar *)data);
-    stripSize = strlen(stripData);
+    if(!log->priv->color)
+    {
+        stripData = utils_strip_ansi(data);
+        stripSize = strlen(stripData);
+
+        write_size = fwrite(stripData, 1, stripSize, log->priv->logfile);
 
-    write_size = fwrite(stripData, 1, stripSize, log->priv->logfile);
+        if(write_size != stripSize)
+            g_critical(_("Could not write data to log file!"));
 
-    if(write_size != stripSize)
-        g_critical(_("Could not write data to log file!"));
+        g_free(stripData);
+    }
+    else
+    {
+        write_size = fwrite(data, 1, size, log->priv->logfile);
 
-    g_free(stripData);
+        if(write_size != size)
+            g_critical(_("Could not write data to log file!"));
+
+    }
 }
 

Modified: trunk/src/mud-window.c
==============================================================================
--- trunk/src/mud-window.c	(original)
+++ trunk/src/mud-window.c	Sat Mar 21 09:37:44 2009
@@ -224,7 +224,7 @@
                               "parent-window", self->window,
                               NULL); 
 
-    /* set priate members */
+    /* set private members */
     self->priv->nr_of_tabs = 0;
     self->priv->current_view = NULL;
     self->priv->mud_views_list = NULL;
@@ -699,7 +699,6 @@
         else
             gtk_widget_grab_focus(self->priv->password_entry);
 
-
         g_object_get(self->priv->current_view,
                 "ui-vbox", &viewport,
                 NULL);
@@ -801,9 +800,7 @@
 static gboolean
 mud_window_configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer user_data)
 {
-    gint i;
-    GSList *view;
-    MudWindow *self = (MudWindow *)user_data;
+    MudWindow *self = MUD_WINDOW(user_data);
 
     if (self->priv->nr_of_tabs == 0)
     {
@@ -811,7 +808,10 @@
         GdkPixbuf *buf;
 
         buf = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(),
-                "gnome-mud", event->width >> 1, GTK_ICON_LOOKUP_FORCE_SVG, &err);
+                                       GMUD_STOCK_ICON,
+                                       event->width >> 1,
+                                       GTK_ICON_LOOKUP_FORCE_SVG,
+                                       &err);
 
         gtk_image_set_from_pixbuf(GTK_IMAGE(self->priv->image), buf);
 
@@ -834,16 +834,16 @@
     if(GTK_WIDGET_MAPPED(self->window))
     {
         if(self->priv->width != allocation->width ||
-                self->priv->height != allocation->height)
+           self->priv->height != allocation->height)
         {
             self->priv->width = allocation->width;
             self->priv->height = allocation->height;
 
             g_signal_emit(self,
-                    mud_window_signal[RESIZED],
-                    0,
-                    self->priv->width,
-                    self->priv->height);
+                          mud_window_signal[RESIZED],
+                          0,
+                          self->priv->width,
+                          self->priv->height);
         }
     }
 }
@@ -859,40 +859,40 @@
     dialog = glade_xml_get_widget(glade, "save_dialog");
 
     gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "buffer.txt");
+
     result = gtk_dialog_run(GTK_DIALOG(dialog));
+
     if(result == GTK_RESPONSE_OK)
     {
         gchar *filename;
-        FILE *file;
+        gchar *buffer_text;
+        VteTerminal *term;
+        GtkClipboard *clipboard;
+        GError *err = NULL;
 
         filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
-        file = fopen(filename, "w");
-
-        if(!file)
-            utils_error_message(self->window, _("Error Saving Buffer"),
-                    "%s", _("Could not save the file in specified location!"));
-        else
-        {
-            gchar *bufferText;
-            VteTerminal *term;
 
-            g_object_get(self->priv->current_view,
-                         "terminal", &term,
-                         NULL);
-
-            bufferText = vte_terminal_get_text_range(term,0,0,
-                    vte_terminal_get_row_count(term),
-                    vte_terminal_get_column_count(term),
-                    NULL,
-                    NULL,
-                    NULL);
-
-            if(!fwrite(bufferText, 1, strlen(bufferText), file))
-                g_critical(_("Could not write buffer to disk!"));
+        g_object_get(self->priv->current_view,
+                "terminal", &term,
+                NULL);
 
-            fclose(file);
-        }
+        /* This is really hackish but the only alternative,
+         * vte_terminal_get_text_range, is just broken. */
 
+        clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
+        vte_terminal_select_all(term);
+        vte_terminal_copy_primary(term);
+        vte_terminal_select_none(term);
+        buffer_text = gtk_clipboard_wait_for_text(clipboard);
+
+        if(buffer_text)
+            if(!g_file_set_contents(filename, buffer_text, -1, &err))
+                utils_error_message(self->window,
+                                    _("Error Saving Buffer"),
+                                    "%s",
+                                    err->message);
+        if(buffer_text)
+            g_free(buffer_text);
         g_free(filename);
     }
 
@@ -935,10 +935,16 @@
 static void
 mud_window_startlog_cb(GtkWidget *widget, MudWindow *self)
 {
+    MudLog *log;
     mud_connection_view_start_logging(MUD_CONNECTION_VIEW(self->priv->current_view));
-    gtk_widget_set_sensitive(self->priv->startlog, FALSE);
-    gtk_widget_set_sensitive(self->priv->stoplog, TRUE);
 
+    g_object_get(self->priv->current_view, "log", &log, NULL);
+
+    if(mud_log_islogging(log))
+    {
+        gtk_widget_set_sensitive(self->priv->startlog, FALSE);
+        gtk_widget_set_sensitive(self->priv->stoplog, TRUE);
+    }
 }
 
 static void
@@ -1262,3 +1268,26 @@
     }
 }
 
+void
+mud_window_update_logging_ui(MudWindow *window,
+                             MudConnectionView *view,
+                             gboolean enabled)
+{
+    g_return_if_fail(IS_MUD_WINDOW(window));
+    g_return_if_fail(IS_MUD_CONNECTION_VIEW(view));
+
+    if(g_direct_equal(window->priv->current_view, view))
+    {
+        if(enabled)
+        {
+            gtk_widget_set_sensitive(window->priv->startlog, FALSE);
+            gtk_widget_set_sensitive(window->priv->stoplog, TRUE);
+        }
+        else
+        {
+            gtk_widget_set_sensitive(window->priv->startlog, TRUE);
+            gtk_widget_set_sensitive(window->priv->stoplog, FALSE);
+        }
+    }
+}
+

Modified: trunk/src/mud-window.h
==============================================================================
--- trunk/src/mud-window.h	(original)
+++ trunk/src/mud-window.h	Sat Mar 21 09:37:44 2009
@@ -66,6 +66,7 @@
 void mud_window_disconnected(MudWindow *window);
 void mud_window_toggle_input_mode(MudWindow *window, MudConnectionView *view);
 void mud_window_toggle_tab_icon(MudWindow *window, MudConnectionView *view);
+void mud_window_update_logging_ui(MudWindow *window, MudConnectionView *view, gboolean enabled);
 
 G_END_DECLS
 

Modified: trunk/ui/main.glade
==============================================================================
--- trunk/ui/main.glade	(original)
+++ trunk/ui/main.glade	Sat Mar 21 09:37:44 2009
@@ -533,4 +533,436 @@
       <placeholder/>
     </child>
   </widget>
+  <widget class="GtkDialog" id="log_config_window">
+    <property name="width_request">500</property>
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Start Logging...</property>
+    <property name="resizable">False</property>
+    <property name="window_position">center-on-parent</property>
+    <property name="destroy_with_parent">True</property>
+    <property name="type_hint">dialog</property>
+    <property name="has_separator">False</property>
+    <child internal-child="vbox">
+      <widget class="GtkVBox" id="dialog-vbox2">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child>
+          <widget class="GtkVBox" id="vbox1">
+            <property name="visible">True</property>
+            <property name="orientation">vertical</property>
+            <child>
+              <widget class="GtkLabel" id="label1">
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">&lt;b&gt;_Log to File:&lt;/b&gt;</property>
+                <property name="use_markup">True</property>
+                <property name="use_underline">True</property>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkHBox" id="hbox1">
+                <property name="visible">True</property>
+                <child>
+                  <widget class="GtkLabel" id="label2">
+                    <property name="visible">True</property>
+                    <property name="width_chars">5</property>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkEntry" id="file_entry">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="invisible_char">&#x25CF;</property>
+                  </widget>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkButton" id="select_btn">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <child>
+                      <widget class="GtkHBox" id="hbox7">
+                        <property name="visible">True</property>
+                        <child>
+                          <widget class="GtkImage" id="image1">
+                            <property name="visible">True</property>
+                            <property name="stock">gtk-file</property>
+                            <property name="icon-size">4</property>
+                          </widget>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <widget class="GtkLabel" id="label13">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">_Select File</property>
+                            <property name="use_underline">True</property>
+                          </widget>
+                          <packing>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </widget>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkHSeparator" id="hseparator1">
+                <property name="visible">True</property>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="padding">10</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkLabel" id="label3">
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">&lt;b&gt;Logging Options:&lt;/b&gt;</property>
+                <property name="use_markup">True</property>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="position">3</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkHBox" id="hbox2">
+                <property name="visible">True</property>
+                <child>
+                  <widget class="GtkLabel" id="label4">
+                    <property name="visible">True</property>
+                    <property name="width_chars">5</property>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkCheckButton" id="inc_next_check_btn">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="draw_indicator">True</property>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="padding">5</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label8">
+                    <property name="visible">True</property>
+                    <property name="xalign">1</property>
+                    <property name="label" translatable="yes">Log _next</property>
+                    <property name="use_underline">True</property>
+                    <property name="mnemonic_widget">inc_next_check_btn</property>
+                    <property name="width_chars">14</property>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="padding">5</property>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkSpinButton" id="next_spin_btn">
+                    <property name="visible">True</property>
+                    <property name="sensitive">False</property>
+                    <property name="can_focus">True</property>
+                    <property name="invisible_char">&#x25CF;</property>
+                    <property name="adjustment">100 1 100000 1 10 10</property>
+                  </widget>
+                  <packing>
+                    <property name="position">3</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label5">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">lines.</property>
+                  </widget>
+                  <packing>
+                    <property name="position">4</property>
+                  </packing>
+                </child>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="position">4</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkHBox" id="hbox3">
+                <property name="visible">True</property>
+                <child>
+                  <widget class="GtkLabel" id="label6">
+                    <property name="visible">True</property>
+                    <property name="width_chars">5</property>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkCheckButton" id="inc_prev_check_btn">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="draw_indicator">True</property>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="padding">5</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label9">
+                    <property name="visible">True</property>
+                    <property name="xalign">1</property>
+                    <property name="label" translatable="yes">Include _previous</property>
+                    <property name="use_underline">True</property>
+                    <property name="mnemonic_widget">inc_prev_check_btn</property>
+                    <property name="width_chars">14</property>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="padding">5</property>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkSpinButton" id="prev_spin_btn">
+                    <property name="visible">True</property>
+                    <property name="sensitive">False</property>
+                    <property name="can_focus">True</property>
+                    <property name="invisible_char">&#x25CF;</property>
+                    <property name="adjustment">100 1 100000 1 10 10</property>
+                    <property name="numeric">True</property>
+                  </widget>
+                  <packing>
+                    <property name="position">3</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label7">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">lines.</property>
+                  </widget>
+                  <packing>
+                    <property name="position">4</property>
+                  </packing>
+                </child>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="position">5</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkHSeparator" id="hseparator2">
+                <property name="visible">True</property>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="padding">10</property>
+                <property name="position">6</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkHBox" id="hbox4">
+                <property name="visible">True</property>
+                <child>
+                  <widget class="GtkLabel" id="label10">
+                    <property name="visible">True</property>
+                    <property name="width_chars">5</property>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkCheckButton" id="append_check_btn">
+                    <property name="label" translatable="yes">_Append to file</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="use_underline">True</property>
+                    <property name="active">True</property>
+                    <property name="draw_indicator">True</property>
+                  </widget>
+                  <packing>
+                    <property name="padding">5</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="position">7</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkHBox" id="hbox5">
+                <property name="visible">True</property>
+                <child>
+                  <widget class="GtkLabel" id="label11">
+                    <property name="visible">True</property>
+                    <property name="width_chars">5</property>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkCheckButton" id="buffer_check_btn">
+                    <property name="label" translatable="yes">_Include entire buffer</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="use_underline">True</property>
+                    <property name="draw_indicator">True</property>
+                  </widget>
+                  <packing>
+                    <property name="padding">5</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="padding">5</property>
+                <property name="position">8</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkHBox" id="hbox6">
+                <property name="visible">True</property>
+                <child>
+                  <widget class="GtkLabel" id="label12">
+                    <property name="visible">True</property>
+                    <property name="width_chars">5</property>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkCheckButton" id="color_check_btn">
+                    <property name="label" translatable="yes">Include C_olor</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="use_underline">True</property>
+                    <property name="draw_indicator">True</property>
+                  </widget>
+                  <packing>
+                    <property name="padding">5</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="position">9</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkHSeparator" id="hseparator3">
+                <property name="visible">True</property>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="padding">5</property>
+                <property name="position">10</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <widget class="GtkHButtonBox" id="dialog-action_area2">
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+            <child>
+              <widget class="GtkButton" id="cancel_btn">
+                <property name="label" translatable="yes">gtk-cancel</property>
+                <property name="response_id">-6</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkButton" id="ok_btn">
+                <property name="label" translatable="yes">gtk-ok</property>
+                <property name="response_id">-5</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
 </glade-interface>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]