gnome-mud r829 - in trunk: . src



Author: lharris
Date: Mon Mar 23 13:25:20 2009
New Revision: 829
URL: http://svn.gnome.org/viewvc/gnome-mud?rev=829&view=rev

Log:
Introduced MudProfileManager

Added:
   trunk/src/mud-profile-manager.c
   trunk/src/mud-profile-manager.h
Removed:
   trunk/src/gconf-helper.c
   trunk/src/gconf-helper.h
Modified:
   trunk/ChangeLog
   trunk/src/Makefile.am
   trunk/src/gnome-mud.c
   trunk/src/mud-connection-view.c
   trunk/src/mud-connections.c
   trunk/src/mud-log.c
   trunk/src/mud-preferences-window.c
   trunk/src/mud-preferences-window.h
   trunk/src/mud-profile.c
   trunk/src/mud-profile.h
   trunk/src/mud-window-profile.c
   trunk/src/mud-window.c
   trunk/src/mud-window.h

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Mon Mar 23 13:25:20 2009
@@ -27,8 +27,6 @@
 	$(MSP_LIBS)
 
 gnome_mud_SOURCES =				\
-	gconf-helper.c				\
-	gconf-helper.h				\
 	debug-logger.c				\
 	debug-logger.h				\
 	gnome-mud.c				\
@@ -54,6 +52,8 @@
 	mud-preferences-window.h		\
 	mud-profile.c				\
 	mud-profile.h				\
+	mud-profile-manager.c			\
+	mud-profile-manager.h			\
 	mud-regex.c				\
 	mud-regex.h				\
 	mud-subwindow.c				\

Modified: trunk/src/gnome-mud.c
==============================================================================
--- trunk/src/gnome-mud.c	(original)
+++ trunk/src/gnome-mud.c	Mon Mar 23 13:25:20 2009
@@ -37,7 +37,6 @@
 #include "gnome-mud-icons.h"
 #include "mud-connection-view.h"
 #include "mud-window.h"
-#include "mud-profile.h"
 #include "utils.h"
 #include "debug-logger.h"
 
@@ -99,8 +98,6 @@
 
     gtk_about_dialog_set_url_hook(utils_activate_url, NULL, NULL);
 
-    mud_profile_load_profiles();
-
     gtk_window_set_default_icon_name(GMUD_STOCK_ICON);
 
     /* Setup debug logging */
@@ -117,6 +114,8 @@
     debug_logger_create_window(logger);
 #endif
 
+    g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL|G_LOG_LEVEL_WARNING);
+
     /* Let 'er rip */
     window = g_object_new(MUD_TYPE_WINDOW, NULL);
 

Modified: trunk/src/mud-connection-view.c
==============================================================================
--- trunk/src/mud-connection-view.c	(original)
+++ trunk/src/mud-connection-view.c	Mon Mar 23 13:25:20 2009
@@ -117,9 +117,6 @@
                                              GParamSpec *pspec);
 
 /* Callbacks */
-static void mud_connection_view_profile_changed_cb (MudProfile *profile, 
-                                                    MudProfileMask *mask,
-                                                    MudConnectionView *view);
 static gboolean mud_connection_view_button_press_event(GtkWidget *widget, 
                                                        GdkEventButton *event,
                                                        MudConnectionView *view);
@@ -415,6 +412,7 @@
     gchar *proxy_host;
     gchar *version;
     gboolean use_proxy;
+    MudProfile *profile;
     
     MudConnectionView *self;
     GObject *obj;
@@ -539,7 +537,10 @@
                                 "parent-view", self,
                                 NULL);
 
-    mud_connection_view_set_profile(self, mud_profile_new(self->profile_name));
+    profile =
+        mud_profile_manager_get_profile_by_name(self->window->profile_manager,
+                                                self->profile_name);
+    mud_connection_view_set_profile(self, profile);
 
     self->tray = tray;
 
@@ -1001,8 +1002,8 @@
     GtkWidget *im_menu;
     GtkWidget *menu_item;
     GtkWidget *profile_menu;
-    const GList *profiles;
-    const GList *profile;
+    const GSList *profiles;
+    const GSList *profile;
     GSList *group;
 
     if (view->priv->popup_menu)
@@ -1041,7 +1042,7 @@
     gtk_menu_shell_append(GTK_MENU_SHELL(view->priv->popup_menu), menu_item);
 
     group = NULL;
-    profiles = mud_profile_get_profiles();
+    profiles = mud_profile_manager_get_profiles(view->window->profile_manager);
     profile = profiles;
     while (profile != NULL)
     {
@@ -1068,7 +1069,7 @@
                 "profile",
                 prof,
                 (GDestroyNotify) g_object_unref);
-        profile = profile->next;
+        profile = g_slist_next(profile);
     }
 
     menu_item = gtk_separator_menu_item_new();
@@ -1746,15 +1747,16 @@
         encoding = view->remote_encoding;
     else
     {
-        profile_name = mud_profile_get_name(view->profile);
+        g_object_get(view->profile,
+                     "name", &profile_name, NULL);
 
-        if (strcmp(profile_name, "Default"))
-        {
+        if (!g_str_equal(profile_name, "Default"))
             g_snprintf(extra_path, 512, "profiles/%s/", profile_name);
-        }
 
         g_snprintf(key, 2048, "/apps/gnome-mud/%s%s", extra_path, "functionality/encoding");
         encoding = gconf_client_get_string(client, key, NULL);
+
+        g_free(profile_name);
     }
 
     g_get_charset(&local_codeset);
@@ -1891,12 +1893,12 @@
     gnet_conn_ref(view->connection);
     gnet_conn_set_watch_error(view->connection, TRUE);
 
-    profile_name = mud_profile_get_name(view->profile);
+    g_object_get(view->profile, "name", &profile_name, NULL);
 
-    if (strcmp(profile_name, "Default") != 0)
-    {
+    if (!g_str_equal(profile_name, "Default"))
         g_snprintf(extra_path, 512, "profiles/%s/", profile_name);
-    }
+    
+    g_free(profile_name);
 
     g_snprintf(key, 2048, "/apps/gnome-mud/%s%s", extra_path, "functionality/use_proxy");
     client = gconf_client_get_default();
@@ -1999,21 +2001,37 @@
             encoding = view->remote_encoding;
         else
         {
-            profile_name = mud_profile_get_name(view->profile);
+            g_object_get(view->profile, "name", &profile_name, NULL);
 
             if (!g_str_equal(profile_name, "Default"))
                 g_snprintf(extra_path, 512, "profiles/%s/", profile_name);
 
             g_snprintf(key, 2048, "/apps/gnome-mud/%s%s", extra_path, "functionality/encoding");
             encoding = gconf_client_get_string(client, key, NULL);
+
+            g_free(profile_name);
         }
 
         g_get_charset(&local_codeset);
 
+        commands = NULL;
+
         if(strlen(view->profile->preferences->CommDev) == 0)
             commands = g_list_append(commands, g_strdup(data));
         else
-            commands = mud_profile_process_commands(view->profile, data);
+        {
+            gint i;
+            gint command_array_length;
+            gchar **command_array =
+                g_strsplit(data, view->profile->preferences->CommDev, -1);
+
+            command_array_length = g_strv_length(command_array);
+
+            for(i = 0; i < command_array_length; ++i)
+                commands = g_list_append(commands, g_strdup(command_array[i]));
+
+            g_strfreev(command_array);
+        }
 
         for (command = g_list_first(commands); command != NULL; command = command->next)
         {

Modified: trunk/src/mud-connections.c
==============================================================================
--- trunk/src/mud-connections.c	(original)
+++ trunk/src/mud-connections.c	Mon Mar 23 13:25:20 2009
@@ -419,7 +419,7 @@
 	break;
 
     case 2:
-	char_name = utils_remove_whitespace(mud_tuple[0]);
+	char_name = gconf_escape_key(mud_tuple[0], -1);
 	mud_name = g_strdup(mud_tuple[1]);
 	break;
 
@@ -431,7 +431,7 @@
     g_strfreev(mud_tuple);
     g_free(buf);
 
-    strip_name = utils_remove_whitespace(mud_name);
+    strip_name = gconf_escape_key(mud_name, -1);
 
     key = g_strdup_printf("/apps/gnome-mud/muds/%s/host", strip_name);
     host = gconf_client_get_string(client, key, NULL);
@@ -466,7 +466,9 @@
                         NULL);
 
     mud_window_add_connection_view(conn->parent_window, G_OBJECT(view), mud_name);
-    mud_connection_view_set_profile(view, get_profile(profile));
+    mud_connection_view_set_profile(view,
+                                    mud_profile_manager_get_profile_by_name(conn->parent_window->profile_manager,
+                                                                            profile));
     mud_window_profile_menu_set_active(conn->parent_window, profile);
 
     g_free(mud_name);
@@ -579,7 +581,7 @@
 
     if(len == 1)
     {
-        strip_name = utils_remove_whitespace(mud_name);
+        strip_name = gconf_escape_key(mud_name, -1);
         
         key = g_strdup_printf("/apps/gnome-mud/muds/%s", strip_name);
         gconf_client_recursive_unset(client, key, 0, NULL);
@@ -590,8 +592,8 @@
     }
     else if(len == 2)
     {
-        strip_name = utils_remove_whitespace(mud_name);
-        strip_char_name = utils_remove_whitespace(char_name);
+        strip_name = gconf_escape_key(mud_name, -1);
+        strip_char_name = gconf_escape_key(char_name, -1);
 
         key = g_strdup_printf("/apps/gnome-mud/muds/%s/characters/%s",
                 strip_name, strip_char_name);
@@ -991,7 +993,7 @@
     } else
 	return;
 
-    name_strip = utils_remove_whitespace(conn->priv->original_name);
+    name_strip = gconf_escape_key(conn->priv->original_name, -1);
 
     gtk_entry_set_text(
 	GTK_ENTRY(conn->priv->name_entry), conn->priv->original_name);
@@ -1053,7 +1055,7 @@
 
     if(conn->priv->original_char_name != NULL)
     {
-	char_strip = utils_remove_whitespace(conn->priv->original_char_name);
+	char_strip = gconf_escape_key(conn->priv->original_char_name, -1);
 		
 	key = g_strdup_printf("/apps/gnome-mud/muds/%s/characters/%s/logon",
 			      name_strip, char_strip);
@@ -1218,8 +1220,8 @@
     if(conn->priv->original_name &&
        strcmp(conn->priv->original_name, name) != 0)
     {
-	stripped_name = utils_remove_whitespace(conn->priv->original_name);
-	strip_name_new = utils_remove_whitespace(name);
+	stripped_name = gconf_escape_key(conn->priv->original_name, -1);
+	strip_name_new = gconf_escape_key(name, -1);
 
 	key = g_strdup_printf("/apps/gnome-mud/muds/%s/characters",
 			      stripped_name);
@@ -1260,7 +1262,7 @@
 	g_free(strip_name_new);
     }
 
-    stripped_name = utils_remove_whitespace(name);
+    stripped_name = gconf_escape_key(name, -1);
     key = g_strdup_printf("/apps/gnome-mud/muds/%s/name", stripped_name);
     gconf_client_set_string(client, key, name, NULL);
     g_free(key);
@@ -1292,7 +1294,7 @@
     if(conn->priv->original_char_name && 
        strcmp(conn->priv->original_char_name, character_name) != 0)
     {
-	strip_name_new = utils_remove_whitespace(conn->priv->original_char_name);
+	strip_name_new = gconf_escape_key(conn->priv->original_char_name, -1);
 	key = g_strdup_printf("/apps/gnome-mud/muds/%s/characters/%s",
 			      stripped_name, strip_name_new);
 	gconf_client_recursive_unset(client, key, 0, NULL);
@@ -1300,7 +1302,7 @@
 	g_free(strip_name_new);
     }
 
-    strip_name_new = utils_remove_whitespace(character_name);
+    strip_name_new = gconf_escape_key(character_name, -1);
 
     if(strlen(strip_name_new) > 0)
     {

Modified: trunk/src/mud-log.c
==============================================================================
--- trunk/src/mud-log.c	(original)
+++ trunk/src/mud-log.c	Mon Mar 23 13:25:20 2009
@@ -804,6 +804,9 @@
                              "line-added",
                              G_CALLBACK(mud_log_line_added_cb),
                              self);
+
+
+            self->priv->active = TRUE;
         }
         else
         {
@@ -816,8 +819,6 @@
                                 _("Could not open \"%s\" for writing."),
                                 self->priv->filename);
         }
-
-        self->priv->active = TRUE;
     }
 
     gtk_widget_destroy(self->priv->window);
@@ -1061,8 +1062,8 @@
                         // Dont' display it.
                         break;
 
-                    /* Skip forecolor state for xterm colors,
-                     * always 5. */
+                        /* Skip forecolor state for xterm colors,
+                         * always 5. */
                     case XTERM_FORECOLOR:
                         i = 1;
                         xterm_forecolor = TRUE;
@@ -1075,126 +1076,117 @@
                         xterm_color = TRUE;
                         break;
 
-                    /* Some MUDs dont' send the attribute with the
-                     * ECMA color.  This picks those up here */
-                    default:
-                        byte = (gint)atol(argv[0]);
+                    case ECMA_FORECOLOR_BLACK:
+                        mud_log_write_html_foreground_span(self,
+                                output,
+                                self->priv->bold,
+                                ECMA_FORECOLOR_BLACK);
+                        break;
 
-                        switch(byte)
-                        {
-                            case ECMA_FORECOLOR_BLACK:
-                                mud_log_write_html_foreground_span(self,
-                                        output,
-                                        self->priv->bold,
-                                        ECMA_FORECOLOR_BLACK);
-                                break;
-
-                            case ECMA_FORECOLOR_RED:
-                                mud_log_write_html_foreground_span(self,
-                                        output,
-                                        self->priv->bold,
-                                        ECMA_FORECOLOR_RED);
-                                break;
-
-                            case ECMA_FORECOLOR_GREEN:
-                                mud_log_write_html_foreground_span(self,
-                                        output,
-                                        self->priv->bold,
-                                        ECMA_FORECOLOR_GREEN);
-                                break;
-
-                            case ECMA_FORECOLOR_YELLOW:
-                                mud_log_write_html_foreground_span(self,
-                                        output,
-                                        self->priv->bold,
-                                        ECMA_FORECOLOR_YELLOW);
-                                break;
-
-                            case ECMA_FORECOLOR_BLUE:
-                                mud_log_write_html_foreground_span(self,
-                                        output,
-                                        self->priv->bold,
-                                        ECMA_FORECOLOR_BLUE);
-                                break;
-
-                            case ECMA_FORECOLOR_MAGENTA:
-                                mud_log_write_html_foreground_span(self,
-                                        output,
-                                        self->priv->bold,
-                                        ECMA_FORECOLOR_MAGENTA);
-                                break;
-
-                            case ECMA_FORECOLOR_CYAN:
-                                mud_log_write_html_foreground_span(self,
-                                        output,
-                                        self->priv->bold,
-                                        ECMA_FORECOLOR_CYAN);
-                                break;
-
-                            case ECMA_FORECOLOR_WHITE:
-                                mud_log_write_html_foreground_span(self,
-                                        output,
-                                        self->priv->bold,
-                                        ECMA_FORECOLOR_WHITE);
-
-                            case ECMA_BACKCOLOR_BLACK:
-                                mud_log_write_html_background_span(self,
-                                        output,
-                                        FALSE,
-                                        ECMA_BACKCOLOR_BLACK);
-                                break;
-
-                            case ECMA_BACKCOLOR_RED:
-                                mud_log_write_html_background_span(self,
-                                        output,
-                                        FALSE,
-                                        ECMA_BACKCOLOR_RED);
-                                break;
-
-                            case ECMA_BACKCOLOR_GREEN:
-                                mud_log_write_html_background_span(self,
-                                        output,
-                                        FALSE,
-                                        ECMA_BACKCOLOR_GREEN);
-                                break;
-
-                            case ECMA_BACKCOLOR_YELLOW:
-                                mud_log_write_html_background_span(self,
-                                        output,
-                                        FALSE,
-                                        ECMA_BACKCOLOR_YELLOW);
-                                break;
-
-                            case ECMA_BACKCOLOR_BLUE:
-                                mud_log_write_html_background_span(self,
-                                        output,
-                                        FALSE,
-                                        ECMA_BACKCOLOR_BLUE);
-                                break;
-
-                            case ECMA_BACKCOLOR_MAGENTA:
-                                mud_log_write_html_background_span(self,
-                                        output,
-                                        FALSE,
-                                        ECMA_BACKCOLOR_MAGENTA);
-                                break;
-
-                            case ECMA_BACKCOLOR_CYAN:
-                                mud_log_write_html_background_span(self,
-                                        output,
-                                        FALSE,
-                                        ECMA_BACKCOLOR_CYAN);
-                                break;
-
-                            case ECMA_BACKCOLOR_WHITE:
-                                mud_log_write_html_background_span(self,
-                                        output,
-                                        FALSE,
-                                        ECMA_BACKCOLOR_WHITE);
-                                break;
+                    case ECMA_FORECOLOR_RED:
+                        mud_log_write_html_foreground_span(self,
+                                output,
+                                self->priv->bold,
+                                ECMA_FORECOLOR_RED);
+                        break;
 
-                        }
+                    case ECMA_FORECOLOR_GREEN:
+                        mud_log_write_html_foreground_span(self,
+                                output,
+                                self->priv->bold,
+                                ECMA_FORECOLOR_GREEN);
+                        break;
+
+                    case ECMA_FORECOLOR_YELLOW:
+                        mud_log_write_html_foreground_span(self,
+                                output,
+                                self->priv->bold,
+                                ECMA_FORECOLOR_YELLOW);
+                        break;
+
+                    case ECMA_FORECOLOR_BLUE:
+                        mud_log_write_html_foreground_span(self,
+                                output,
+                                self->priv->bold,
+                                ECMA_FORECOLOR_BLUE);
+                        break;
+
+                    case ECMA_FORECOLOR_MAGENTA:
+                        mud_log_write_html_foreground_span(self,
+                                output,
+                                self->priv->bold,
+                                ECMA_FORECOLOR_MAGENTA);
                         break;
+
+                    case ECMA_FORECOLOR_CYAN:
+                        mud_log_write_html_foreground_span(self,
+                                output,
+                                self->priv->bold,
+                                ECMA_FORECOLOR_CYAN);
+                        break;
+
+                    case ECMA_FORECOLOR_WHITE:
+                        mud_log_write_html_foreground_span(self,
+                                output,
+                                self->priv->bold,
+                                ECMA_FORECOLOR_WHITE);
+
+                    case ECMA_BACKCOLOR_BLACK:
+                        mud_log_write_html_background_span(self,
+                                output,
+                                FALSE,
+                                ECMA_BACKCOLOR_BLACK);
+                        break;
+
+                    case ECMA_BACKCOLOR_RED:
+                        mud_log_write_html_background_span(self,
+                                output,
+                                FALSE,
+                                ECMA_BACKCOLOR_RED);
+                        break;
+
+                    case ECMA_BACKCOLOR_GREEN:
+                        mud_log_write_html_background_span(self,
+                                output,
+                                FALSE,
+                                ECMA_BACKCOLOR_GREEN);
+                        break;
+
+                    case ECMA_BACKCOLOR_YELLOW:
+                        mud_log_write_html_background_span(self,
+                                output,
+                                FALSE,
+                                ECMA_BACKCOLOR_YELLOW);
+                        break;
+
+                    case ECMA_BACKCOLOR_BLUE:
+                        mud_log_write_html_background_span(self,
+                                output,
+                                FALSE,
+                                ECMA_BACKCOLOR_BLUE);
+                        break;
+
+                    case ECMA_BACKCOLOR_MAGENTA:
+                        mud_log_write_html_background_span(self,
+                                output,
+                                FALSE,
+                                ECMA_BACKCOLOR_MAGENTA);
+                        break;
+
+                    case ECMA_BACKCOLOR_CYAN:
+                        mud_log_write_html_background_span(self,
+                                output,
+                                FALSE,
+                                ECMA_BACKCOLOR_CYAN);
+                        break;
+
+                    case ECMA_BACKCOLOR_WHITE:
+                        mud_log_write_html_background_span(self,
+                                output,
+                                FALSE,
+                                ECMA_BACKCOLOR_WHITE);
+                        break;
+
                 }
                 break;
 

Modified: trunk/src/mud-preferences-window.c
==============================================================================
--- trunk/src/mud-preferences-window.c	(original)
+++ trunk/src/mud-preferences-window.c	Mon Mar 23 13:25:20 2009
@@ -33,6 +33,7 @@
 #include "mud-preferences-window.h"
 #include "mud-profile.h"
 #include "mud-regex.h"
+#include "mud-window.h"
 #include "utils.h"
 
 typedef struct TTreeViewRowInfo {
@@ -126,6 +127,8 @@
     gint notification_count;
 
     gchar *current_encoding;
+
+    MudWindow *parent;
 };
 
 enum
@@ -494,8 +497,8 @@
 void
 mud_preferences_window_fill_profiles (MudPreferencesWindow *window)
 {
-    const GList *list;
-    GList *entry;
+    const GSList *list;
+    GSList *entry;
     GtkTreeStore *store;
     GtkTreeIter iter;
     GtkCellRenderer *renderer;
@@ -533,8 +536,8 @@
             TYPE_COLUMN, GINT_TO_POINTER(COLUMN_TRIGGERS),
             -1);
 
-    list = mud_profile_get_profiles();
-    for (entry = (GList *) list; entry != NULL; entry = g_list_next(entry))
+    list = mud_profile_manager_get_profiles(window->priv->parent->profile_manager);
+    for (entry = (GSList *) list; entry != NULL; entry = g_slist_next(entry))
     {
         GtkTreeIter iter_child;
         MudProfile *profile = (MudProfile *) entry->data;
@@ -598,7 +601,8 @@
     GtkTextBuffer *action_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(prefs->priv->trigger_action_textview));
 
     client = gconf_client_get_default();
-    profile_name = mud_profile_get_name(prefs->priv->profile);
+
+    g_object_get(prefs->priv->profile, "name", &profile_name, NULL);
 
     if (gtk_tree_model_get_iter(model, &iter, path))
     {
@@ -635,6 +639,8 @@
         gtk_widget_set_sensitive(prefs->priv->trigger_del, TRUE);
     }
 
+    g_free(profile_name);
+
     g_object_unref(client);
 
     return TRUE;
@@ -659,7 +665,8 @@
     GtkTextBuffer *regex_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(prefs->priv->alias_regex_textview));
 
     client = gconf_client_get_default();
-    profile_name = mud_profile_get_name(prefs->priv->profile);
+
+    g_object_get(prefs->priv->profile, "name", &profile_name, NULL);
 
     if (gtk_tree_model_get_iter(model, &iter, path))
     {
@@ -693,6 +700,7 @@
         gtk_widget_set_sensitive(prefs->priv->alias_del, TRUE);
     }
 
+    g_free(profile_name);
     g_object_unref(client);
 
     return TRUE;
@@ -714,7 +722,9 @@
     GError *error = NULL;
 
     client = gconf_client_get_default();
-    profile_name = mud_profile_get_name(prefs->priv->profile);
+
+    g_object_get(prefs->priv->profile, "name", &profile_name, NULL);
+
     intval = gconf_value_new(GCONF_VALUE_INT);
 
     gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(model), &iter, path);
@@ -727,6 +737,7 @@
 
     gtk_tree_store_set(model, &iter, TRIGGER_ENABLED_COLUMN, !active, -1);
 
+    g_free(profile_name);
     g_free(name);
     gconf_value_free(intval);
     g_object_unref(client);
@@ -748,7 +759,9 @@
     GError *error = NULL;
 
     client = gconf_client_get_default();
-    profile_name = mud_profile_get_name(prefs->priv->profile);
+
+    g_object_get(prefs->priv->profile, "name", &profile_name, NULL);
+
     intval = gconf_value_new(GCONF_VALUE_INT);
 
     gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(model), &iter, path);
@@ -761,6 +774,7 @@
 
     gtk_tree_store_set(model, &iter, TRIGGER_GAG_COLUMN, !active, -1);
 
+    g_free(profile_name);
     g_free(name);
     gconf_value_free(intval);
     g_object_unref(client);
@@ -782,7 +796,9 @@
     GError *error = NULL;
 
     client = gconf_client_get_default();
-    profile_name = mud_profile_get_name(prefs->priv->profile);
+
+    g_object_get(prefs->priv->profile, "name", &profile_name, NULL);
+
     intval = gconf_value_new(GCONF_VALUE_INT);
 
     gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(model), &iter, path);
@@ -796,6 +812,7 @@
     gtk_tree_store_set(model, &iter, ALIAS_ENABLED_COLUMN, !active, -1);
 
     gconf_value_free(intval);
+    g_free(profile_name);
     g_free(name);
     g_object_unref(client);
 }
@@ -878,7 +895,7 @@
 {
     MudProfile *profile;
 
-    profile = mud_profile_new(name);
+    profile = mud_profile_manager_get_profile_by_name(window->priv->parent->profile_manager, name);
     mud_preferences_window_change_profile(window, profile);
 }
 
@@ -1168,7 +1185,7 @@
     rementry = NULL;
     rementry = g_slist_append(rementry, NULL);
 
-    profile_name = mud_profile_get_name(window->priv->profile);
+    g_object_get(window->priv->profile, "name", &profile_name, NULL);
 
     client = gconf_client_get_default();
 
@@ -1183,13 +1200,13 @@
         }
     }
 
-
     triggers = g_slist_remove(triggers, rementry->data);
 
     gconf_client_set_list(client, keyname, GCONF_VALUE_STRING, triggers, &error);
 
     mud_preferences_window_populate_trigger_treeview(window);
 
+    g_free(profile_name);
     g_object_unref(client);
 }
 
@@ -1205,7 +1222,7 @@
     rementry = NULL;
     rementry = g_slist_append(rementry, NULL);
 
-    profile_name = mud_profile_get_name(window->priv->profile);
+    g_object_get(window->priv->profile, "name", &profile_name, NULL);
 
     client = gconf_client_get_default();
 
@@ -1227,6 +1244,7 @@
 
     mud_preferences_window_populate_alias_treeview(window);
 
+    g_free(profile_name);
     g_free(aliases);
     g_object_unref(client);
 }
@@ -1259,7 +1277,7 @@
 
     name = utils_remove_whitespace(text);
 
-    profile_name = mud_profile_get_name(MUD_PROFILE(window->priv->profile));
+    g_object_get(window->priv->profile, "name", &profile_name, NULL);
 
     g_snprintf(keyname, 2048, "/apps/gnome-mud/profiles/%s/triggers/list",profile_name);
     triggers = gconf_client_get_list(client, keyname, GCONF_VALUE_STRING, NULL);
@@ -1305,6 +1323,8 @@
 
     mud_preferences_window_populate_trigger_treeview(window);
 
+    g_free(profile_name);
+
     g_object_unref(client);
 }
 
@@ -1336,7 +1356,7 @@
 
     name = utils_remove_whitespace(text);
 
-    profile_name = mud_profile_get_name(MUD_PROFILE(window->priv->profile));
+    g_object_get(window->priv->profile, "name", &profile_name, NULL);
 
     g_snprintf(keyname, 2048, "/apps/gnome-mud/profiles/%s/aliases/list",profile_name);
     aliases = gconf_client_get_list(client, keyname, GCONF_VALUE_STRING, NULL);
@@ -1378,6 +1398,7 @@
 
     mud_preferences_window_populate_alias_treeview(window);
 
+    g_free(profile_name);
     g_object_unref(client);
 }
 
@@ -1397,7 +1418,7 @@
     GtkTextBuffer *buffer_action = gtk_text_view_get_buffer(GTK_TEXT_VIEW(window->priv->trigger_action_textview));
 
     client = gconf_client_get_default();
-    profile_name = mud_profile_get_name(window->priv->profile);
+    g_object_get(window->priv->profile, "name", &profile_name, NULL);
 
     gtk_entry_set_text(GTK_ENTRY(window->priv->trigger_match_entry), "");
     gtk_entry_set_text(GTK_ENTRY(window->priv->trigger_name_entry), "");
@@ -1437,6 +1458,7 @@
                 -1);
     }
 
+    g_free(profile_name);
     g_object_unref(client);
 }
 
@@ -1455,7 +1477,8 @@
     GtkTextBuffer *buffer_regex = gtk_text_view_get_buffer(GTK_TEXT_VIEW(window->priv->alias_regex_textview));
 
     client = gconf_client_get_default();
-    profile_name = mud_profile_get_name(window->priv->profile);
+
+    g_object_get(window->priv->profile, "name", &profile_name, NULL);
 
     gtk_entry_set_text(GTK_ENTRY(window->priv->alias_entry), "");
     gtk_entry_set_text(GTK_ENTRY(window->priv->alias_match_entry), "");
@@ -1491,6 +1514,7 @@
                 -1);
     }
 
+    g_free(profile_name);
     g_object_unref(client);
 }
 
@@ -1576,12 +1600,11 @@
     gint active;
     gint current;
 
-    profile_name = mud_profile_get_name(window->priv->profile);
+    g_object_get(window->priv->profile, "name", &profile_name, NULL);
 
-    if (strcmp(profile_name, "Default"))
-    {
+    if (!g_str_equal(profile_name, "Default"))
         g_snprintf(extra_path, 512, "profiles/%s/", profile_name);
-    }
+    g_free(profile_name);
 
     g_snprintf(buf, 2048, "/apps/gnome-mud/%s%s", extra_path, "functionality/proxy_version");
     client = gconf_client_get_default();
@@ -1930,14 +1953,16 @@
 }
 
 MudPreferencesWindow*
-mud_preferences_window_new (const gchar *profile)
+mud_preferences_window_new (const gchar *profile, MudWindow *window)
 {
     MudPreferencesWindow *prefs;
 
     prefs = g_object_new(MUD_TYPE_PREFERENCES_WINDOW, NULL);
 
+    prefs->priv->parent = window;
     mud_preferences_window_change_profile_from_name(prefs, profile);
     mud_preferences_window_fill_profiles(prefs);
 
     return prefs;
 }
+

Modified: trunk/src/mud-preferences-window.h
==============================================================================
--- trunk/src/mud-preferences-window.h	(original)
+++ trunk/src/mud-preferences-window.h	Mon Mar 23 13:25:20 2009
@@ -23,6 +23,7 @@
 
 G_BEGIN_DECLS
 
+#include <glib.h>
 #include <gconf/gconf-client.h>
 
 #define MUD_TYPE_PREFERENCES_WINDOW              (mud_preferences_window_get_type ())
@@ -36,6 +37,8 @@
 typedef struct _MudPreferencesWindowClass       MudPreferencesWindowClass;
 typedef struct _MudPreferencesWindowPrivate     MudPreferencesWindowPrivate;
 
+#include "mud-window.h"
+
 struct _MudPreferencesWindow
 {
     GObject parent_instance;
@@ -50,7 +53,7 @@
 
 GType mud_preferences_window_get_type (void) G_GNUC_CONST;
 
-MudPreferencesWindow* mud_preferences_window_new ();
+MudPreferencesWindow* mud_preferences_window_new (const gchar *profile, MudWindow *window);
 
 G_END_DECLS
 

Added: trunk/src/mud-profile-manager.c
==============================================================================
--- (empty file)
+++ trunk/src/mud-profile-manager.c	Mon Mar 23 13:25:20 2009
@@ -0,0 +1,388 @@
+/* GNOME-Mud - A simple Mud Client
+ * mud-profile-manager.c
+ * Copyright (C) 2005-2009 Les Harris <lharris gnome org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include "gnome-mud.h"
+#include "mud-window.h"
+#include "mud-profile-manager.h"
+#include "mud-connection-view.h"
+
+struct _MudProfileManagerPrivate
+{
+    GSList *profiles;
+    MudWindow *parent;
+};
+
+/* Property Identifiers */
+enum
+{
+    PROP_MUD_PROFILE_MANAGER_0,
+    PROP_PARENT
+};
+
+/* Create the Type */
+G_DEFINE_TYPE(MudProfileManager, mud_profile_manager, G_TYPE_OBJECT);
+
+/* Class Functions */
+static void mud_profile_manager_init (MudProfileManager *profile_manager);
+static void mud_profile_manager_class_init (MudProfileManagerClass *klass);
+static void mud_profile_manager_finalize (GObject *object);
+static GObject *mud_profile_manager_constructor (GType gtype,
+                                                 guint n_properties,
+                                                 GObjectConstructParam *properties);
+static void mud_profile_manager_set_property(GObject *object,
+                                             guint prop_id,
+                                             const GValue *value,
+                                             GParamSpec *pspec);
+static void mud_profile_manager_get_property(GObject *object,
+                                             guint prop_id,
+                                             GValue *value,
+                                             GParamSpec *pspec);
+
+/* Private Methods */
+static void mud_profile_manager_load_profiles (MudProfileManager *self);
+
+/* MudProfileManager class functions */
+static void
+mud_profile_manager_class_init (MudProfileManagerClass *klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    /* Override base object constructor */
+    object_class->constructor = mud_profile_manager_constructor;
+
+    /* Override base object's finalize */
+    object_class->finalize = mud_profile_manager_finalize;
+
+    /* Override base object property methods */
+    object_class->set_property = mud_profile_manager_set_property;
+    object_class->get_property = mud_profile_manager_get_property;
+
+    /* Add private data to class */
+    g_type_class_add_private(klass, sizeof(MudProfileManagerPrivate));
+
+    /* Install Properties */
+    g_object_class_install_property(object_class,
+            PROP_PARENT,
+            g_param_spec_object("parent-window",
+                "parent MudWindow",
+                "The parent MudWindow",
+                MUD_TYPE_WINDOW,
+                G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
+
+}
+
+static void
+mud_profile_manager_init (MudProfileManager *self)
+{
+    /* Get our private data */
+    self->priv = MUD_PROFILE_MANAGER_GET_PRIVATE(self);
+
+    /* set private members to defaults */
+    self->priv->profiles = NULL;
+}
+
+static GObject *
+mud_profile_manager_constructor (GType gtype,
+                                 guint n_properties,
+                                 GObjectConstructParam *properties)
+{
+    MudProfileManager *self;
+    GObject *obj;
+    MudProfileManagerClass *klass;
+    GObjectClass *parent_class;
+
+    /* Chain up to parent constructor */
+    klass = MUD_PROFILE_MANAGER_CLASS( g_type_class_peek(MUD_TYPE_PROFILE_MANAGER) );
+    parent_class = G_OBJECT_CLASS( g_type_class_peek_parent(klass) );
+    obj = parent_class->constructor(gtype, n_properties, properties);
+
+    self = MUD_PROFILE_MANAGER(obj);
+
+    if(!self->priv->parent)
+    {
+        g_printf("ERROR: Tried to instantiate MudProfileManager without passing parent MudWindow\n");
+        g_error("Tried to instantiate MudProfileManager without passing parent MudWindow");
+    }
+
+    mud_profile_manager_load_profiles(self);
+    
+    return obj;
+}
+
+static void
+mud_profile_manager_finalize (GObject *object)
+{
+    MudProfileManager *profile_manager;
+    GObjectClass *parent_class;
+    GSList *entry;
+
+    profile_manager = MUD_PROFILE_MANAGER(object);
+
+    entry = profile_manager->priv->profiles;
+
+    while(entry)
+    {
+        MudProfile *profile = MUD_PROFILE(entry->data);
+        g_object_unref(profile);
+
+        entry = g_slist_next(entry);
+    }
+
+    parent_class = g_type_class_peek_parent(G_OBJECT_GET_CLASS(object));
+    parent_class->finalize(object);
+}
+
+static void
+mud_profile_manager_set_property(GObject *object,
+                                 guint prop_id,
+                                 const GValue *value,
+                                 GParamSpec *pspec)
+{
+    MudProfileManager *self;
+
+    self = MUD_PROFILE_MANAGER(object);
+
+    switch(prop_id)
+    {
+        case PROP_PARENT:
+            self->priv->parent = MUD_WINDOW(g_value_get_object(value));
+            break;
+
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+            break;
+    }
+}
+
+static void
+mud_profile_manager_get_property(GObject *object,
+                                 guint prop_id,
+                                 GValue *value,
+                                 GParamSpec *pspec)
+{
+    MudProfileManager *self;
+
+    self = MUD_PROFILE_MANAGER(object);
+
+    switch(prop_id)
+    {
+        case PROP_PARENT:
+            g_value_take_object(value, self->priv->parent);
+            break;
+
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+            break;
+    }
+}
+
+/* Private Methods */
+static void
+mud_profile_manager_load_profiles (MudProfileManager *self)
+{
+    GSList *entry;
+    GSList *profiles;
+    MudProfile *profile;
+    GConfClient *client;
+
+    g_return_if_fail(MUD_IS_PROFILE_MANAGER(self));
+    g_return_if_fail(self->priv->profiles == NULL);
+
+    client = gconf_client_get_default();
+
+    profiles = gconf_client_all_dirs(client,
+                                     "/apps/gnome-mud/profiles",
+                                     NULL);
+
+    profile = g_object_new(MUD_TYPE_PROFILE,
+                           "name", "Default",
+                           "parent", self,
+                           NULL);
+
+    self->priv->profiles = g_slist_append(self->priv->profiles,
+                                          profile);
+
+    entry = profiles;
+    
+    while(entry)
+    {
+        gchar *name = g_path_get_basename((gchar *)entry->data);
+
+        if(!g_str_equal(name, "Default"))
+        {
+            profile = g_object_new(MUD_TYPE_PROFILE,
+                    "name", g_strdup(name),
+                    "parent", self,
+                    NULL);
+
+            self->priv->profiles = g_slist_append(self->priv->profiles,
+                                                  profile);
+        }
+
+        g_free(name);
+        g_free(entry->data);
+
+        entry = g_slist_next(entry);
+    }
+
+    g_slist_free(profiles);
+
+    g_object_unref(client);
+}
+
+/* Public Methods */
+void
+mud_profile_manager_add_profile(MudProfileManager *self,
+                                const gchar *name)
+{
+    MudProfile *profile, *default_profile;
+    gchar *escaped_name;
+    GConfClient *client;
+
+    g_return_if_fail(MUD_IS_PROFILE_MANAGER(self));
+
+    client = gconf_client_get_default();
+    default_profile = mud_profile_manager_get_profile_by_name(self,
+                                                              "Default");
+
+    escaped_name = gconf_escape_key(name, -1);
+
+    profile = g_object_new(MUD_TYPE_PROFILE,
+                           "name", escaped_name,
+                           "parent", self,
+                           NULL);
+
+    g_free(escaped_name);
+
+    mud_profile_copy_preferences(default_profile, profile);
+
+    gconf_client_suggest_sync(client, NULL);
+
+    self->priv->profiles = g_slist_append(self->priv->profiles,
+                                          profile);
+
+    mud_window_populate_profiles_menu(self->priv->parent);
+
+    g_object_unref(client);
+}
+
+void
+mud_profile_manager_delete_profile(MudProfileManager *self,
+                                   const gchar *name)
+{
+    MudProfile *profile, *default_profile;
+    GError *error = NULL;
+    gchar *key, *pname;
+    const GSList *views, *view_entry;
+    GSList *connections, *entry;
+    GConfClient *client;
+
+    g_return_if_fail(MUD_IS_PROFILE_MANAGER(self));
+
+    client = gconf_client_get_default();
+
+    profile = mud_profile_manager_get_profile_by_name(self, name);
+    default_profile = mud_profile_manager_get_profile_by_name(self, "Default");
+
+    if (profile)
+    {
+        self->priv->profiles = g_slist_remove(self->priv->profiles,
+                                              profile);
+
+        key = g_strdup_printf("/apps/gnome-mud/profiles/%s", name);
+        gconf_client_recursive_unset(client, key, 0, NULL);
+        g_free(key);
+
+       /* If the user deletes a profile we need to switch
+        * any connections using that profile to Default to prevent
+        * mass breakage */
+       connections = gconf_client_all_dirs(client,
+                                           "/apps/gnome-mud/muds",
+                                           NULL);
+
+       entry = connections;
+
+       while(entry)
+       {
+           gchar *base = g_path_get_basename((gchar *)entry->data);
+           key = g_strdup_printf("/apps/gnome-mud/muds/%s/profile",
+                                 base);
+           g_free(base);
+
+           pname = gconf_client_get_string(client, key, NULL);
+
+           if(g_str_equal(pname, name))
+               gconf_client_set_string(client, key, "Default", NULL);
+
+           g_free(key);
+           g_free(entry->data);
+           entry = g_slist_next(entry);
+       }
+
+       g_slist_free(connections);
+
+       gconf_client_suggest_sync(client, NULL);
+
+       /* Update the profiles menu */
+       mud_window_populate_profiles_menu(self->priv->parent);
+    }
+
+    g_object_unref(client);
+}
+
+const GSList*
+mud_profile_manager_get_profiles (MudProfileManager *self)
+{
+    if(!MUD_IS_PROFILE_MANAGER(self))
+        return NULL;
+
+    return self->priv->profiles;
+}
+
+MudProfile*
+mud_profile_manager_get_profile_by_name(MudProfileManager *self,
+                                        const gchar *name)
+{
+    GSList *entry = NULL;
+    MudProfile *profile;
+
+    g_return_if_fail(MUD_IS_PROFILE_MANAGER(self));
+
+    entry = self->priv->profiles;
+
+    while(entry)
+    {
+        profile = MUD_PROFILE(entry->data);
+
+        if(g_str_equal(profile->name, name))
+            return profile;
+
+        entry = g_slist_next(entry);
+    }
+
+    return NULL;
+}
+

Added: trunk/src/mud-profile-manager.h
==============================================================================
--- (empty file)
+++ trunk/src/mud-profile-manager.h	Mon Mar 23 13:25:20 2009
@@ -0,0 +1,64 @@
+/* GNOME-Mud - A simple Mud Client
+ * mud-profile-manager.h
+ * Copyright (C) 2005-2009 Les Harris <lharris gnome org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef MUD_PROFILE_MANAGER_H
+#define MUD_PROFILE_MANAGER_H
+
+G_BEGIN_DECLS
+
+#include <glib.h>
+
+#define MUD_TYPE_PROFILE_MANAGER              (mud_profile_manager_get_type ())
+#define MUD_PROFILE_MANAGER(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), MUD_TYPE_PROFILE_MANAGER, MudProfileManager))
+#define MUD_PROFILE_MANAGER_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), MUD_TYPE_PROFILE_MANAGER, MudProfileManagerClass))
+#define MUD_IS_PROFILE_MANAGER(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), MUD_TYPE_PROFILE_MANAGER))
+#define MUD_IS_PROFILE_MANAGER_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), MUD_TYPE_PROFILE_MANAGER))
+#define MUD_PROFILE_MANAGER_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), MUD_TYPE_PROFILE_MANAGER, MudProfileManagerClass))
+#define MUD_PROFILE_MANAGER_GET_PRIVATE(obj)  (G_TYPE_INSTANCE_GET_PRIVATE ((obj), MUD_TYPE_PROFILE_MANAGER, MudProfileManagerPrivate))
+
+typedef struct _MudProfileManager            MudProfileManager;
+typedef struct _MudProfileManagerClass       MudProfileManagerClass;
+typedef struct _MudProfileManagerPrivate     MudProfileManagerPrivate;
+
+#include "mud-profile.h"
+
+struct _MudProfileManagerClass
+{
+    GObjectClass parent_class;
+};
+
+struct _MudProfileManager
+{
+    GObject parent_instance;
+
+    /*< private >*/
+    MudProfileManagerPrivate *priv;
+};
+
+GType mud_profile_manager_get_type (void);
+
+void mud_profile_manager_add_profile(MudProfileManager *self, const gchar *name);
+void mud_profile_manager_delete_profile(MudProfileManager *self, const gchar *name);
+const GSList* mud_profile_manager_get_profiles (MudProfileManager *self);
+MudProfile* mud_profile_manager_get_profile_by_name(MudProfileManager *self, const gchar *name);
+
+G_END_DECLS
+
+#endif // MUD_PROFILE_MANAGER_H
+

Modified: trunk/src/mud-profile.c
==============================================================================
--- trunk/src/mud-profile.c	(original)
+++ trunk/src/mud-profile.c	Mon Mar 23 13:25:20 2009
@@ -28,28 +28,66 @@
 #include <glib-object.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
+#include <gdk/gdk.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <string.h>
 
-#include "gconf-helper.h"
+#include "mud-profile-manager.h"
 #include "mud-profile.h"
 #include "utils.h"
 
-gulong signal_changed;
-GList *profile_list = NULL;
-
 struct _MudProfilePrivate
 {
     GConfClient *gconf_client;
 
     MudPrefs preferences;
     gint in_notification_count;
+    guint gconf_signal;
+
+    MudProfileManager *parent;
+};
+
+/* Create the Type */
+G_DEFINE_TYPE(MudProfile, mud_profile, G_TYPE_OBJECT);
+
+/* Property Identifiers */
+enum
+{
+    PROP_MUD_PROFILE_0,
+    PROP_NAME,
+    PROP_PARENT
+};
 
+/* Signal Indices */
+enum
+{
+    CHANGED,
+    LAST_SIGNAL
 };
 
+/* Signal Identifier Map */
+static guint mud_profile_signal[LAST_SIGNAL] = { 0 };
+
 #define RETURN_IF_NOTIFYING(profile)  if ((profile)->priv->in_notification_count) return
 
+/* Class Functions */
 static void mud_profile_init          (MudProfile *profile);
 static void mud_profile_class_init    (MudProfileClass *profile);
 static void mud_profile_finalize      (GObject *object);
+static GObject *mud_profile_constructor (GType gtype,
+                                         guint n_properties,
+                                         GObjectConstructParam *properties);
+static void mud_profile_set_property(GObject *object,
+                                     guint prop_id,
+                                     const GValue *value,
+                                     GParamSpec *pspec);
+static void mud_profile_get_property(GObject *object,
+                                     guint prop_id,
+                                     GValue *value,
+                                     GParamSpec *pspec);
+
+/* Callbacks */
 static void mud_profile_gconf_changed (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data);
 
 /* Profile Set Functions */
@@ -64,72 +102,50 @@
 static gboolean set_Foreground(MudProfile *profile, const gchar *candidate);
 static gboolean set_Background(MudProfile *profile, const gchar *candidate);
 static gboolean set_Colors(MudProfile *profile, const gchar *candidate);
-static void mud_profile_set_proxy_combo_full(MudProfile *profile, gchar *version);
 
-void mud_profile_set_scrolloutput (MudProfile *profile, gboolean value);
-void mud_profile_set_disablekeys (MudProfile *profile, gboolean value);
-void mud_profile_set_keeptext (MudProfile *profile, gboolean value);
-void mud_profile_set_echotext (MudProfile *profile, gboolean value);
-void mud_profile_set_commdev (MudProfile *profile, const gchar *value);
-void mud_profile_set_terminal (MudProfile *profile, const gchar *value);
-void mud_profile_set_encoding_combo(MudProfile *profile, const gchar *e);
-void mud_profile_set_encoding_check (MudProfile *profile, const gint value);
-void mud_profile_set_proxy_check (MudProfile *profile, const gint value);
-void mud_profile_set_msp_check (MudProfile *profile, const gint value);
-void mud_profile_set_proxy_combo(MudProfile *profile, GtkComboBox *combo);
-void mud_profile_set_proxy_entry (MudProfile *profile, const gchar *value);
-void mud_profile_set_font (MudProfile *profile, const gchar *value);
-void mud_profile_set_foreground (MudProfile *profile, guint r, guint g, guint b);
-void mud_profile_set_background (MudProfile *profile, guint r, guint g, guint b);
-void mud_profile_set_colors (MudProfile *profile, gint nr, guint r, guint g, guint b);
-void mud_profile_set_history(MudProfile *profile, const gint value);
-void mud_profile_set_scrollback(MudProfile *profile, const gint value);
+/* Private Methods */
+static void mud_profile_set_proxy_combo_full(MudProfile *profile, gchar *version);
+static void mud_profile_load_preferences(MudProfile *profile);
+static const gchar *mud_profile_gconf_get_key(MudProfile *profile, const gchar *key);
 
 /* MudProfile Class Functions */
-GType
-mud_profile_get_type (void)
-{
-    static GType object_type = 0;
-
-    g_type_init();
-
-    if (!object_type)
-    {
-        static const GTypeInfo object_info =
-        {
-            sizeof (MudProfileClass),
-            NULL,
-            NULL,
-            (GClassInitFunc) mud_profile_class_init,
-            NULL,
-            NULL,
-            sizeof (MudProfile),
-            0,
-            (GInstanceInitFunc) mud_profile_init,
-        };
-
-        object_type = g_type_register_static(G_TYPE_OBJECT, "MudProfile", &object_info, 0);
-    }
-
-    return object_type;
-}
-
-static void
-mud_profile_init (MudProfile *profile)
-{
-    profile->priv = g_new0(MudProfilePrivate, 1);
-    profile->priv->in_notification_count = 0;
-
-    profile->priv->gconf_client = gconf_client_get_default();
-}
-
 static void
 mud_profile_class_init (MudProfileClass *klass)
 {
     GObjectClass *object_class = G_OBJECT_CLASS(klass);
 
+    /* Override base object constructor */
+    object_class->constructor = mud_profile_constructor;
+
+    /* Override base object finalize */
     object_class->finalize = mud_profile_finalize;
-    signal_changed =
+
+    /* Override base object property methods */
+    object_class->set_property = mud_profile_set_property;
+    object_class->get_property = mud_profile_get_property;
+
+    /* Add private data to class */
+    g_type_class_add_private(klass, sizeof(MudProfilePrivate));
+
+    /* Create and Install Properties */
+    g_object_class_install_property(object_class,
+            PROP_NAME,
+            g_param_spec_string("name",
+                "Name",
+                "The name of the profile.",
+                NULL,
+                G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
+
+    g_object_class_install_property(object_class,
+            PROP_PARENT,
+            g_param_spec_object("parent",
+                "Parent",
+                "The parent MudProfileManager",
+                MUD_TYPE_PROFILE_MANAGER,
+                G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
+
+    /* Register Signals */
+    mud_profile_signal[CHANGED] =
         g_signal_new("changed",
                 G_OBJECT_CLASS_TYPE(object_class),
                 G_SIGNAL_RUN_LAST,
@@ -140,180 +156,180 @@
 }
 
 static void
-mud_profile_finalize (GObject *object)
+mud_profile_init (MudProfile *profile)
 {
-    MudProfile *profile;
-    GObjectClass *parent_class;
-
-    profile = MUD_PROFILE(object);
+    /* Set private data */
+    profile->priv = MUD_PROFILE_GET_PRIVATE(profile);
 
-    g_free(profile->priv->preferences.FontName);
-    g_free(profile->priv->preferences.CommDev);
-    g_free(profile->priv->preferences.LastLogDir);
-    g_free(profile->priv->preferences.Encoding);
-    g_free(profile->priv->preferences.ProxyVersion);
-    g_free(profile->priv->preferences.ProxyHostname);
-
-    g_object_unref(profile->priv->gconf_client);
-
-    g_free(profile->priv);
-    g_free(profile->name);
+    /* Set defaults */ 
+    profile->name = NULL;
 
-    parent_class = g_type_class_peek_parent(G_OBJECT_GET_CLASS(object));
-    parent_class->finalize(object);
+    profile->priv->parent = NULL;
+    
+    profile->priv->in_notification_count = 0;
+    profile->priv->gconf_client = gconf_client_get_default();
+    profile->preferences = &profile->priv->preferences;
 }
 
-/* MudProfile Public Methods */
-MudProfile*
-mud_profile_new (const gchar *name)
+static GObject *
+mud_profile_constructor (GType gtype,
+                         guint n_properties,
+                         GObjectConstructParam *properties)
 {
-    MudProfile *profile;
+    MudProfile *self;
+    GObject *obj;
+    MudProfileClass *klass;
+    GObjectClass *parent_class;
+
     GSList *profiles, *entry;
     GError *error = NULL;
     gint newflag;
 
-    g_assert(name != NULL);
-
-    profile = get_profile(name);
-    if (profile == NULL)
-    {
-        profile = g_object_new(MUD_TYPE_PROFILE, NULL);
-        profile->name = g_strdup(name);
-        profile->preferences = &profile->priv->preferences;
+    /* Chain up to parent constructor */
+    klass = MUD_PROFILE_CLASS( g_type_class_peek(MUD_TYPE_PROFILE) );
+    parent_class = G_OBJECT_CLASS( g_type_class_peek_parent(klass) );
+    obj = parent_class->constructor(gtype, n_properties, properties);
 
-        gm_gconf_load_preferences(profile);
+    self = MUD_PROFILE(obj);
 
-        profile_list = g_list_append(profile_list, profile);
-
-        if (!strcmp(name, "Default"))
-        {
-            gconf_client_notify_add(profile->priv->gconf_client,
-                    "/apps/gnome-mud",
-                    mud_profile_gconf_changed,
-                    profile, NULL, NULL);
-        }
-        else
-        {
-            gchar buf[512];
+    if(!self->name)
+    {
+        g_printf("ERROR: Tried to instantiate MudProfile without passing name.\n");
+        g_error("Tried to instantiate MudProfile without passing name.");
+    }
 
-            newflag = 1;
+    if(!self->priv->parent || !MUD_IS_PROFILE_MANAGER(self->priv->parent))
+    {
+        g_printf("ERROR: Tried to instantiate MudProfile without passing parent manager.\n");
+        g_error("Tried to instantiate MudProfile without passing parent manager.");
+    }
 
-            g_snprintf(buf, 512, "/apps/gnome-mud/profiles/list");
-            profiles = gconf_client_get_list(profile->priv->gconf_client, buf, GCONF_VALUE_STRING, &error);
+    mud_profile_load_preferences(self);
 
-            for (entry = profiles; entry != NULL; entry = g_slist_next(entry))
-            {
-                if(!strcmp((gchar *)entry->data,name))
-                {
-                    newflag = 0;
-                }
-            }
-
-            if (newflag)
-            {
-                profiles = g_slist_append(profiles, (void *)g_strdup(name));
-                gconf_client_set_list(profile->priv->gconf_client, buf, GCONF_VALUE_STRING, profiles, &error);
-            }
+    if (g_str_equal(self->name, "Default"))
+    {
+        self->priv->gconf_signal = gconf_client_notify_add(self->priv->gconf_client,
+                                            "/apps/gnome-mud",
+                                            mud_profile_gconf_changed,
+                                            self,
+                                            NULL,
+                                            NULL);
+    }
+    else
+    {
+        gchar buf[512];
 
-            g_snprintf(buf, 512, "/apps/gnome-mud/profiles/%s", name);
-            gconf_client_notify_add(profile->priv->gconf_client,
-                    buf,
-                    mud_profile_gconf_changed,
-                    profile, NULL, NULL);
-        }
+        g_snprintf(buf, 512, "/apps/gnome-mud/profiles/%s", self->name);
+        self->priv->gconf_signal = gconf_client_notify_add(self->priv->gconf_client,
+                                    buf,
+                                    mud_profile_gconf_changed,
+                                    self,
+                                    NULL,
+                                    NULL);
     }
 
-    return profile;
+    return obj;
 }
 
-void
-mud_profile_delete(const gchar *name)
+static void
+mud_profile_finalize (GObject *object)
 {
     MudProfile *profile;
-    GSList *profiles, *entry, *rementry;
-    GError *error = NULL;
-    gchar buf[512];
-    GConfClient *client;
+    GObjectClass *parent_class;
+    GConfClient *client = gconf_client_get_default();
 
-    client = gconf_client_get_default();
+    profile = MUD_PROFILE(object);
 
-    rementry = NULL;
-    rementry = g_slist_append(rementry, NULL);
-    profile = get_profile(name);
+    gconf_client_notify_remove(client, profile->priv->gconf_signal);
 
-    if (profile)
-    {
-        profile_list = g_list_remove(profile_list, profile);
+    g_free(profile->priv->preferences.FontName);
+    g_free(profile->priv->preferences.CommDev);
+    g_free(profile->priv->preferences.LastLogDir);
+    g_free(profile->priv->preferences.Encoding);
+    g_free(profile->priv->preferences.ProxyVersion);
+    g_free(profile->priv->preferences.ProxyHostname);
 
-        g_snprintf(buf, 512, "/apps/gnome-mud/profiles/list");
-        profiles = gconf_client_get_list(client, buf, GCONF_VALUE_STRING, &error);
-        for (entry = profiles; entry != NULL; entry = g_slist_next(entry))
-        {
-            if (strcmp((gchar *)entry->data, name) == 0)
-            {
-                rementry->data = entry->data;
-            }
-        }
+    g_object_unref(profile->priv->gconf_client);
 
-        profiles = g_slist_remove(profiles, rementry->data);
-        gconf_client_set_list(client, buf, GCONF_VALUE_STRING, profiles, &error);
-    }
+    g_free(profile->name);
 
-    g_object_unref(client);
+    parent_class = g_type_class_peek_parent(G_OBJECT_GET_CLASS(object));
+    parent_class->finalize(object);
 }
 
-MudProfile*
-get_profile(const gchar *name)
+static void
+mud_profile_set_property(GObject *object,
+                         guint prop_id,
+                         const GValue *value,
+                         GParamSpec *pspec)
 {
-    GList *entry = NULL;
-    MudProfile *profile;
+    MudProfile *self;
+    gchar *new_string;
 
-    entry = profile_list;
+    self = MUD_PROFILE(object);
 
-    for (entry = profile_list; entry != NULL; entry = entry->next)
+    switch(prop_id)
     {
-        profile = MUD_PROFILE(entry->data);
+        case PROP_NAME:
+            new_string = g_value_dup_string(value);
 
-        if (!strcmp(profile->name, name))
-            return profile;
-    }
+            if(!self->name)
+                self->name = g_strdup(new_string);
+            else if( !g_str_equal(self->name, new_string) )
+            {
+                g_free(self->name);
+                self->name = g_strdup(new_string);
+            }
+
+            g_free(new_string);
+            break;
 
-    return NULL;
+        case PROP_PARENT:
+            self->priv->parent = MUD_PROFILE_MANAGER(g_value_get_object(value));
+            break;
+
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+            break;
+    }
 }
 
-void
-mud_profile_load_profiles ()
+static void
+mud_profile_get_property(GObject *object,
+                         guint prop_id,
+                         GValue *value,
+                         GParamSpec *pspec)
 {
-    GSList *profiles, *entry;
-    GConfClient *client;
-
-    g_return_if_fail(profile_list == NULL);
+    MudProfile *self;
 
-    client = gconf_client_get_default();
+    self = MUD_PROFILE(object);
 
-    profiles = gconf_client_get_list(client, "/apps/gnome-mud/profiles/list", GCONF_VALUE_STRING, NULL);
-
-    for (entry = profiles; entry != NULL; entry = g_slist_next(entry))
+    switch(prop_id)
     {
-        MudProfile *profile;
-        gchar *pname, *epname;
-
-        pname = g_strdup((gchar *) entry->data);
-        epname = gconf_escape_key(pname, -1);
+        case PROP_NAME:
+            g_value_set_string(value, self->name);
+            break;
 
-        profile = mud_profile_new(pname);
+        case PROP_PARENT:
+            g_value_take_object(value, self->priv->parent);
+            break;
 
-        g_free(epname);
-        g_free(pname);
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+            break;
     }
-
-    g_object_unref(client);
 }
 
+/* MudProfile Public Methods */
 void
 mud_profile_copy_preferences(MudProfile *from, MudProfile *to)
 {
     gint i;
+    gchar *s;
+    const gchar *key;
+
+    g_return_if_fail(IS_MUD_PROFILE(from));
+    g_return_if_fail(IS_MUD_PROFILE(to));
 
     mud_profile_set_echotext(to, from->preferences->EchoText);
     mud_profile_set_keeptext(to, from->preferences->KeepText);
@@ -331,10 +347,13 @@
 
     for (i = 0; i < C_MAX; i++)
     {
-        mud_profile_set_colors(to, i, from->preferences->Colors[i].red,
-                from->preferences->Colors[i].green,
-                from->preferences->Colors[i].blue);
-    }
+        to->preferences->Colors[i].red = from->preferences->Colors[i].red;
+        to->preferences->Colors[i].blue = from->preferences->Colors[i].blue;
+        to->preferences->Colors[i].green = from->preferences->Colors[i].green;
+    }
+    key = mud_profile_gconf_get_key(to, "ui/palette");
+    s = gtk_color_selection_palette_to_string(to->preferences->Colors, C_MAX);
+    gconf_client_set_string(from->priv->gconf_client, key, s, NULL);
 
     mud_profile_set_encoding_combo(to, from->preferences->Encoding);
     mud_profile_set_encoding_check(to, from->preferences->UseRemoteEncoding);
@@ -344,79 +363,114 @@
     mud_profile_set_proxy_entry(to, from->preferences->ProxyHostname);
 }
 
-GList *
-mud_profile_process_command(MudProfile *profile, const gchar *data, GList *commandlist)
+/* MudProfile Private Methods */
+static void
+mud_profile_load_preferences(MudProfile *profile)
 {
-    gint i;
-    gchar **commands = g_strsplit(data, profile->preferences->CommDev, -1);
-
-    if(commands[0])
-    {
-        commandlist = g_list_append(commandlist, g_strdup(commands[0]));
-
-        for (i = 1; commands[i] != NULL; i++)
-            commandlist =
-                mud_profile_process_command(profile, commands[i], commandlist);
-    }
-
-    g_strfreev(commands);
+    GConfClient *gconf_client;
+    MudPrefs *prefs;
+    GdkColor  color;
+    GdkColor *colors;
+    gint      n_colors;
+    struct    stat file_stat;
+    gchar     dirname[256], buf[256];
+    gchar     extra_path[512] = "", keyname[2048];
+    gchar *p;
+    MudProfile *default_profile;
 
-    return commandlist;
-}
+    g_return_if_fail(IS_MUD_PROFILE(profile));
 
-GList *
-mud_profile_process_commands(MudProfile *profile, const gchar *data)
-{
-    return mud_profile_process_command(profile, data, NULL);
-}
+    gconf_client = gconf_client_get_default();
+    prefs = profile->preferences;
 
-gchar *
-mud_profile_from_number(gint num)
-{
-    GList *entry;
-    gint counter = 0;
+    if (!g_str_equal(profile->name, "Default"))
+        g_snprintf(extra_path, 512, "profiles/%s/", profile->name);
 
-    for (entry = (GList *)profile_list; entry != NULL; entry = g_list_next(entry))
+    if(!g_str_equal(profile->name, "Default"))
     {
-        if (counter == num)
-            return (gchar *)MUD_PROFILE(entry->data)->name;
+        default_profile = mud_profile_manager_get_profile_by_name(profile->priv->parent,
+                                                                  "Default");
+        mud_profile_copy_preferences(default_profile, profile);
+    }
+
+#define	GCONF_GET_STRING(entry, subdir, variable)                                          \
+    if(prefs->variable) g_free(prefs->variable);                                    \
+    g_snprintf(keyname, 2048, "/apps/gnome-mud/%s" #subdir "/" #entry, extra_path); \
+    p = gconf_client_get_string(gconf_client, keyname, NULL);\
+    prefs->variable = g_strdup(p);
+
+#define GCONF_GET_BOOLEAN(entry, subdir, variable)                                         \
+    g_snprintf(keyname, 2048, "/apps/gnome-mud/%s" #subdir "/" #entry, extra_path); \
+    prefs->variable = gconf_client_get_bool(gconf_client, keyname, NULL);
+
+#define GCONF_GET_INT(entry, subdir, variable)                                             \
+    g_snprintf(keyname, 2048, "/apps/gnome-mud/%s" #subdir "/" #entry, extra_path); \
+    prefs->variable = gconf_client_get_int(gconf_client, keyname, NULL);
+
+#define GCONF_GET_COLOR(entry, subdir, variable)                                           \
+    g_snprintf(keyname, 2048, "/apps/gnome-mud/%s" #subdir "/" #entry, extra_path); \
+    p = gconf_client_get_string(gconf_client, keyname, NULL);\
+    if (p && gdk_color_parse(p, &color))                                                   \
+    {                                                                                      \
+        prefs->variable = color;                                                            \
+    }
+
+    GCONF_GET_STRING(font, 				ui,				FontName);
+    GCONF_GET_COLOR(foreground_color,	ui,				Foreground);
+    GCONF_GET_COLOR(background_color,	ui,				Background);
+    GCONF_GET_INT(scrollback_lines,		ui,				Scrollback);
+    GCONF_GET_STRING(commdev, 			functionality,	CommDev);
+    GCONF_GET_BOOLEAN(echo,     		functionality,	EchoText);
+    GCONF_GET_BOOLEAN(keeptext,			functionality,	KeepText);
+    GCONF_GET_BOOLEAN(system_keys,		functionality,	DisableKeys);
+    GCONF_GET_BOOLEAN(scroll_on_output,	functionality,	ScrollOnOutput);
+    GCONF_GET_INT(flush_interval,		functionality,	FlushInterval);
+    GCONF_GET_STRING(encoding,          functionality,  Encoding);
+    GCONF_GET_STRING(proxy_version,     functionality,  ProxyVersion);
+    GCONF_GET_BOOLEAN(use_proxy,        functionality,  UseProxy);
+    GCONF_GET_BOOLEAN(remote_encoding,  functionality,  UseRemoteEncoding);
+    GCONF_GET_STRING(proxy_hostname,    functionality,  ProxyHostname);
+    GCONF_GET_BOOLEAN(remote_download,  functionality,  UseRemoteDownload);
+
+    /* palette */
+    g_snprintf(keyname, 2048, "/apps/gnome-mud/%sui/palette", extra_path);
+    p = gconf_client_get_string(gconf_client, keyname, NULL);
 
-        counter++;
+    if (p)
+    {
+        gtk_color_selection_palette_from_string(p, &colors, &n_colors);
+        if (n_colors < C_MAX)
+        {
+            g_printerr(ngettext("Palette had %d entry instead of %d\n",
+                        "Palette had %d entries instead of %d\n",
+                        n_colors),
+                    n_colors, C_MAX);
+        }
+        memcpy(prefs->Colors, colors, C_MAX * sizeof(GdkColor));
+        g_free(colors);
     }
 
-    return NULL;
-}
+    /* last log dir */
+    g_snprintf(keyname, 2048, "/apps/gnome-mud/%sfunctionality/last_log_dir", extra_path);
+    p = gconf_client_get_string(gconf_client, keyname, NULL);
 
-gint
-mud_profile_num_from_name(gchar *name)
-{
-    GList *entry;
-    gint counter = 0;
-
-    for (entry = (GList *)profile_list; entry != NULL; entry = g_list_next(entry))
+    if (p == NULL || !g_ascii_strncasecmp(p, "", sizeof("")))
     {
-        if (strcmp((gchar *)MUD_PROFILE(entry->data)->name, name) == 0)
-            return counter;
-
-        counter++;
+        prefs->LastLogDir = g_strdup(g_get_home_dir());
+    }
+    else
+    {
+        prefs->LastLogDir = g_strdup(p);
     }
 
-    return -1;
-}
+    g_object_unref(gconf_client);
 
-gchar *
-mud_profile_get_name(MudProfile *profile)
-{
-    return profile->name;
+#undef GCONF_GET_BOOLEAN
+#undef GCONF_GET_COLOR
+#undef GCONF_GET_INT
+#undef GCONF_GET_STRING
 }
 
-const GList*
-mud_profile_get_profiles ()
-{
-    return profile_list;
-}
-
-/* MudProfile Private Methods */
 static gchar *
 color_to_string(const GdkColor *c)
 {
@@ -648,7 +702,7 @@
     if(key)
         g_free(key);
 
-    g_signal_emit(G_OBJECT(profile), signal_changed, 0, &mask);
+    g_signal_emit(profile, mud_profile_signal[CHANGED], 0, &mask);
 }
 
 

Modified: trunk/src/mud-profile.h
==============================================================================
--- trunk/src/mud-profile.h	(original)
+++ trunk/src/mud-profile.h	Mon Mar 23 13:25:20 2009
@@ -28,7 +28,7 @@
 
 #define MUD_TYPE_PROFILE              (mud_profile_get_type ())
 #define MUD_PROFILE(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), MUD_TYPE_PROFILE, MudProfile))
-#define MUD_PROFILE_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), MUD_TYPE_PROFILE, MudProfile))
+#define MUD_PROFILE_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), MUD_TYPE_PROFILE, MudProfileClass))
 #define IS_MUD_PROFILE(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), MUD_TYPE_PROFILE))
 #define IS_MUD_PROFILE_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), MUD_TYPE_PROFILE))
 #define MUD_PROFILE_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), MUD_TYPE_PROFILE, MudProfileClass))
@@ -48,15 +48,18 @@
     gboolean   AutoSave;
     gboolean   DisableKeys;
     gboolean   ScrollOnOutput;
+
     gchar     *FontName;
     gchar     *CommDev;
     gchar     *LastLogDir;
     gchar     *Encoding;
     gchar     *ProxyVersion;
     gchar     *ProxyHostname;
+
     gint       History;
     gint       Scrollback;
     gint       FlushInterval;
+
     GdkColor   Foreground;
     GdkColor   Background;
 
@@ -111,14 +114,7 @@
 
 GType mud_profile_get_type (void);
 
-MudProfile* mud_profile_new (const gchar *name);
-void mud_profile_delete(const gchar *name);
-void mud_profile_load_profiles ();
-const GList* mud_profile_get_profiles ();
-MudProfile* get_profile(const gchar *name);
-
 void mud_profile_copy_preferences (MudProfile *from, MudProfile *to);
-GList* mud_profile_process_commands (MudProfile *profile, const gchar *data);
 
 void mud_profile_set_echotext (MudProfile *profile, gboolean value);
 void mud_profile_set_keeptext (MudProfile *profile, gboolean value);
@@ -139,10 +135,7 @@
 void mud_profile_set_proxy_entry (MudProfile *profile, const gchar *value);
 void mud_profile_set_msp_check (MudProfile *profile, const gint value);
 
-gchar *mud_profile_from_number(gint num);
-gint mud_profile_num_from_name(gchar *name);
-gchar *mud_profile_get_name(MudProfile *profile);
-
 G_END_DECLS
 
 #endif // MUD_PROFILE_H
+

Modified: trunk/src/mud-window-profile.c
==============================================================================
--- trunk/src/mud-window-profile.c	(original)
+++ trunk/src/mud-window-profile.c	Mon Mar 23 13:25:20 2009
@@ -31,6 +31,7 @@
 #include "mud-window.h"
 #include "mud-window-profile.h"
 #include "utils.h"
+#include "mud-profile-manager.h"
 
 struct _MudProfileWindowPrivate
 {
@@ -293,6 +294,9 @@
     glade = glade_xml_new(GLADEDIR "/prefs.glade", "newprofile_dialog", NULL);
     window = glade_xml_get_widget(glade, "newprofile_dialog");
 
+    def = mud_profile_manager_get_profile_by_name(profwin->parent_window->profile_manager,
+                                                  "Default");
+
     gtk_window_set_transient_for(
             GTK_WINDOW(window),
             GTK_WINDOW(profwin->priv->window));
@@ -302,15 +306,17 @@
     result = gtk_dialog_run(GTK_DIALOG(window));
     if (result == GTK_RESPONSE_OK)
     {
-        profile = utils_remove_whitespace((gchar *)gtk_entry_get_text(GTK_ENTRY(entry_profile)));
+        profile = gconf_escape_key(gtk_entry_get_text(GTK_ENTRY(entry_profile)),
+                                   -1);
 
-        def = get_profile("Default");
-        prof = mud_profile_new((const gchar *)profile);
+        mud_profile_manager_add_profile(profwin->parent_window->profile_manager,
+                                        profile);
 
-        mud_profile_copy_preferences(def, prof);
+        prof = mud_profile_manager_get_profile_by_name(profwin->parent_window->profile_manager,
+                                                       profile);
 
+        mud_profile_copy_preferences(def, prof);
         mud_profile_window_populate_treeview(profwin);
-        mud_window_populate_profiles_menu(profwin->parent_window);
     }
 
     gtk_widget_destroy(window);
@@ -323,10 +329,10 @@
 
     if(strcmp("Default", profwin->priv->CurrSelRowText) != 0)
     {
-        mud_profile_delete(profwin->priv->CurrSelRowText);
+        mud_profile_manager_delete_profile(profwin->parent_window->profile_manager,
+                                           profwin->priv->CurrSelRowText);
 
         mud_profile_window_populate_treeview(profwin);
-        mud_window_populate_profiles_menu(profwin->parent_window);
     }
 }
 
@@ -354,8 +360,10 @@
 
         profwin->priv->CurrSelRow = (gtk_tree_path_get_indices(path))[0];
 
-        gtk_widget_set_sensitive(profwin->priv->btnDelete, TRUE);
-
+        if(g_str_equal(profwin->priv->CurrSelRowText, "Default"))
+            gtk_widget_set_sensitive(profwin->priv->btnDelete, FALSE);
+        else
+            gtk_widget_set_sensitive(profwin->priv->btnDelete, TRUE);
     }
 
     return TRUE;
@@ -365,7 +373,7 @@
 static void
 mud_profile_window_populate_treeview(MudProfileWindow *profwin)
 {
-    const GList *profiles, *entry;
+    const GSList *profiles, *entry;
     GtkTreeStore* store;
     GtkTreeIter iter;
 
@@ -377,7 +385,7 @@
 
     gtk_widget_set_sensitive(profwin->priv->btnDelete, FALSE);
 
-    profiles = mud_profile_get_profiles();
+    profiles = mud_profile_manager_get_profiles(profwin->parent_window->profile_manager);
 
     entry = profiles;
     while(entry)
@@ -389,7 +397,7 @@
                            NAME_COLUMN, profile->name,
                            -1);
 
-        entry = g_list_next(entry);
+        entry = g_slist_next(entry);
     }
 }
 

Modified: trunk/src/mud-window.c
==============================================================================
--- trunk/src/mud-window.c	(original)
+++ trunk/src/mud-window.c	Mon Mar 23 13:25:20 2009
@@ -104,6 +104,9 @@
 static void mud_window_init       (MudWindow *self);
 static void mud_window_class_init (MudWindowClass *klass);
 static void mud_window_finalize   (GObject *object);
+static GObject *mud_window_constructor (GType gtype,
+                                        guint n_properties,
+                                        GObjectConstructParam *properties);
 static void mud_window_set_property(GObject *object,
                                     guint prop_id,
                                     const GValue *value,
@@ -162,6 +165,9 @@
 {
     GObjectClass *object_class = G_OBJECT_CLASS(klass);
 
+    /* Override base object constructor */
+    object_class->constructor = mud_window_constructor;
+
     /* Override parent's finalize */
     object_class->finalize = mud_window_finalize;
 
@@ -375,15 +381,40 @@
     if (GTK_WIDGET_VISIBLE(self->priv->textviewscroll))
         gtk_widget_queue_resize(self->priv->textviewscroll);
 
-    mud_window_populate_profiles_menu(self);
-
     gtk_window_get_size(GTK_WINDOW(self->window),
                         &self->priv->width,
                         &self->priv->height);
 
+
+
     g_object_unref(glade);
 }
 
+static GObject *
+mud_window_constructor (GType gtype,
+                        guint n_properties,
+                        GObjectConstructParam *properties)
+{
+    MudWindow *self;
+    GObject *obj;
+    MudWindowClass *klass;
+    GObjectClass *parent_class;
+
+    /* Chain up to parent constructor */
+    klass = MUD_WINDOW_CLASS( g_type_class_peek(MUD_TYPE_WINDOW) );
+    parent_class = G_OBJECT_CLASS( g_type_class_peek_parent(klass) );
+    obj = parent_class->constructor(gtype, n_properties, properties);
+
+    self = MUD_WINDOW(obj);
+
+    self->profile_manager = g_object_new(MUD_TYPE_PROFILE_MANAGER,
+                                         "parent-window", self,
+                                        NULL);
+    mud_window_populate_profiles_menu(self);
+
+    return obj;
+}
+
 static void
 mud_window_finalize (GObject *object)
 {
@@ -403,6 +434,8 @@
         entry = g_slist_next(entry);
     }
 
+    g_object_unref(self->profile_manager);
+
     g_slist_free(self->priv->mud_views_list);
     
     g_object_unref(self->tray);
@@ -728,7 +761,7 @@
 static void
 mud_window_preferences_cb(GtkWidget *widget, MudWindow *self)
 {
-    mud_preferences_window_new("Default");
+    mud_preferences_window_new("Default", self);
 }
 
 static void
@@ -910,7 +943,8 @@
 
     if (self->priv->current_view)
     {
-        profile = get_profile(gtk_label_get_text(GTK_LABEL(profileLabel)));
+        profile = mud_profile_manager_get_profile_by_name
+            (self->profile_manager, gtk_label_get_text(GTK_LABEL(profileLabel)));
 
         if (profile)
             mud_connection_view_set_profile(MUD_CONNECTION_VIEW(self->priv->current_view), profile);
@@ -1033,6 +1067,12 @@
 }
 
 /* Public Methods */
+const GSList *
+mud_window_get_views(MudWindow *window)
+{
+    return window->priv->mud_views_list;
+}
+
 void
 mud_window_toggle_input_mode(MudWindow *self,
                              MudConnectionView *view)
@@ -1128,26 +1168,31 @@
 void
 mud_window_populate_profiles_menu(MudWindow *self)
 {
-    const GList *profiles;
-    GList *entry;
+    const GSList *profiles, *entry;
     GtkWidget *profile;
     GtkWidget *sep;
     GtkWidget *manage;
     GtkWidget *icon;
+    MudProfile *prof;
 
     g_return_if_fail(IS_MUD_WINDOW(self));
 
-    profiles = mud_profile_get_profiles();
+    self->priv->profile_menu_list = NULL;
+
+    profiles = mud_profile_manager_get_profiles(self->profile_manager);
 
     gtk_container_foreach(GTK_CONTAINER(self->priv->mi_profiles),
                           mud_window_clear_profiles_menu,
                           NULL);
 
-    for (entry = (GList *)profiles; entry != NULL; entry = g_list_next(entry))
+    entry = profiles;
+    while(entry)
     {
+        prof = MUD_PROFILE(entry->data);
+
         profile = gtk_radio_menu_item_new_with_label(
                 self->priv->profile_menu_list,
-                (gchar *)MUD_PROFILE(entry->data)->name);
+                g_strdup(prof->name));
 
         gtk_widget_show(profile);
         
@@ -1160,6 +1205,8 @@
                          "activate",
                          G_CALLBACK(mud_window_select_profile),
                         self);
+
+        entry = g_slist_next(entry);
     }
 
     sep = gtk_separator_menu_item_new();
@@ -1178,6 +1225,9 @@
                      "activate",
                      G_CALLBACK(mud_window_profiles_cb),
                      self);
+
+    if(self->priv->current_view)
+        mud_window_profile_menu_set_active(self, self->priv->current_view->profile->name);
 }
     
 void

Modified: trunk/src/mud-window.h
==============================================================================
--- trunk/src/mud-window.h	(original)
+++ trunk/src/mud-window.h	Mon Mar 23 13:25:20 2009
@@ -39,6 +39,7 @@
 
 #include "mud-connection-view.h"
 #include "mud-tray.h"
+#include "mud-profile-manager.h"
 
 struct _MudWindowClass
 {
@@ -55,6 +56,7 @@
     /*< public >*/
     GtkWindow *window;
     MudTray *tray;
+    MudProfileManager *profile_manager;
 };
 
 GType mud_window_get_type (void);
@@ -67,7 +69,9 @@
 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);
+const GSList *mud_window_get_views(MudWindow *window);
 
 G_END_DECLS
 
 #endif /* MUD_WINDOW_H */
+



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