gnome-terminal r2599 - trunk/src



Author: chpe
Date: Thu May 29 19:37:21 2008
New Revision: 2599
URL: http://svn.gnome.org/viewvc/gnome-terminal?rev=2599&view=rev

Log:
Move profile list management to TerminalApp.


Modified:
   trunk/src/terminal-app.c
   trunk/src/terminal-app.h
   trunk/src/terminal-profile.c
   trunk/src/terminal-profile.h
   trunk/src/terminal-screen.c
   trunk/src/terminal-window.c
   trunk/src/terminal.c

Modified: trunk/src/terminal-app.c
==============================================================================
--- trunk/src/terminal-app.c	(original)
+++ trunk/src/terminal-app.c	Thu May 29 19:37:21 2008
@@ -93,7 +93,13 @@
   GtkWidget *manage_profiles_delete_button;
   GtkWidget *manage_profiles_default_menu;
 
+  GHashTable *profiles;
+  char* default_profile_id;
+  TerminalProfile *default_profile;
+  gboolean default_profile_locked;
+
   guint profile_list_notify_id;
+  guint default_profile_notify_id;
 };
 
 enum {
@@ -116,6 +122,7 @@
 
 #define TERMINAL_STOCK_EDIT "terminal-edit"
 #define PROFILE_LIST_KEY CONF_GLOBAL_PREFIX "/profile_list"
+#define DEFAULT_PROFILE_KEY CONF_GLOBAL_PREFIX "/default_profile"
 
 static void refill_profile_treeview (GtkWidget *tree_view);
 
@@ -127,6 +134,40 @@
 
 /* Helper functions */
 
+static int
+profiles_alphabetic_cmp (gconstpointer pa,
+                         gconstpointer pb)
+{
+  TerminalProfile *a = (TerminalProfile *) pa;
+  TerminalProfile *b = (TerminalProfile *) pb;
+  int result;
+
+  result =  g_utf8_collate (terminal_profile_get_visible_name (a),
+			    terminal_profile_get_visible_name (b));
+  if (result == 0)
+    result = strcmp (terminal_profile_get_name (a),
+		     terminal_profile_get_name (b));
+
+  return result;
+}
+
+typedef struct
+{
+  TerminalProfile *result;
+  const char *target;
+} LookupInfo;
+
+static void
+profiles_lookup_by_visible_name_foreach (gpointer key,
+                                         gpointer value,
+                                         gpointer data)
+{
+  LookupInfo *info = data;
+
+  if (strcmp (info->target, terminal_profile_get_visible_name (value)) == 0)
+    info->result = value;
+}
+
 static void
 terminal_window_destroyed (TerminalWindow *window,
                            TerminalApp    *app)
@@ -141,6 +182,50 @@
     gtk_main_quit ();
 }
 
+static void
+terminal_app_profile_forgotten_cb (TerminalProfile *profile,
+                                   TerminalApp *app)
+{
+  g_hash_table_remove (app->profiles, terminal_profile_get_name (profile));
+
+  if (profile == app->default_profile)
+    app->default_profile = NULL;
+    /* FIXMEchpe update default profile! */
+
+  /* FIXMEchpe emit profiles-list-changed signal */
+}
+      
+static TerminalProfile *
+terminal_app_create_profile (TerminalApp *app,
+                             const char *name)
+{
+  TerminalProfile *profile;
+
+  profile = terminal_app_get_profile_by_name (app, name);
+  g_return_val_if_fail (profile == NULL, profile); /* FIXMEchpe can this happen? */
+
+  profile = _terminal_profile_new (name);
+  terminal_profile_update (profile);
+
+  g_signal_connect (profile, "forgotten",
+                    G_CALLBACK (terminal_app_profile_forgotten_cb), app);
+
+  g_hash_table_insert (app->profiles,
+                       g_strdup (terminal_profile_get_name (profile)),
+                       profile /* adopts the refcount */);
+
+  if (app->default_profile == NULL &&
+      app->default_profile_id != NULL &&
+      strcmp (app->default_profile_id,
+              terminal_profile_get_name (profile)) == 0)
+    {
+      /* We are the default profile */
+      app->default_profile = profile;
+    }
+  
+  return profile;
+}
+
 static GdkScreen*
 find_screen_by_display_name (const char *display_name,
                              int         screen_number)
@@ -258,7 +343,7 @@
   gboolean need_new_default;
   TerminalProfile *fallback;
   
-  known = terminal_profile_get_list ();
+  known = terminal_app_get_profile_list (app);
 
   val = gconf_entry_get_value (entry);
 
@@ -289,19 +374,15 @@
         }
       else
         {
-          TerminalProfile *profile;
-          
-          profile = terminal_profile_new (profile_name);
-
-          terminal_profile_update (profile);
+          terminal_app_create_profile (app, profile_name);
         }
     }
 
 ensure_one_profile:
 
   fallback = NULL;
-  if (terminal_profile_get_count () == 0 ||
-      terminal_profile_get_count () <= g_list_length (known))
+  if (terminal_app_get_profile_count (app) == 0 ||
+      terminal_app_get_profile_count (app) <= g_list_length (known))
     {
       /* We are going to run out, so create the fallback
        * to be sure we always have one. Must be done
@@ -314,7 +395,7 @@
        * all profiles, the FALLBACK_ID profile returns as
        * the living dead.
        */
-      fallback = terminal_profile_ensure_fallback (conf);
+      fallback = terminal_app_ensure_profile_fallback (app);
     }
   
   /* Forget no-longer-existing profiles */
@@ -331,7 +412,8 @@
         {
           if (terminal_profile_get_is_default (forgotten))
             need_new_default = TRUE;
-          
+
+          /* FIXMEchpe make this out of this loop! */
           terminal_profile_forget (forgotten);
         }
       
@@ -344,7 +426,7 @@
     {
       TerminalProfile *new_default;
 
-      known = terminal_profile_get_list ();
+      known = terminal_app_get_profile_list (app);
       
       g_assert (known);
       new_default = known->data;
@@ -352,9 +434,11 @@
       g_list_free (known);
 
       terminal_profile_set_is_default (new_default, TRUE);
+
+      /* FIXMEchpe emit default-profile-changed signal */
     }
 
-  g_assert (terminal_profile_get_count () > 0);  
+  g_assert (terminal_app_get_profile_count (app) > 0);
 
   if (app->new_profile_dialog)
     {
@@ -378,6 +462,175 @@
 }
 
 static void
+terminal_app_default_profile_notify_cb (GConfClient *client,
+                                        guint        cnxn_id,
+                                        GConfEntry  *entry,
+                                        gpointer     user_data)
+{
+  TerminalApp *app = TERMINAL_APP (user_data);
+  TerminalProfile *profile;
+  TerminalProfile *old_default;
+  GConfValue *val;
+  gboolean changed = FALSE;
+  gboolean locked;
+  const char *name;
+  
+  val = gconf_entry_get_value (entry);  
+  if (val == NULL ||
+      val->type != GCONF_VALUE_STRING)
+    return;
+  
+  name = gconf_value_get_string (val);
+  if (!name)
+    return; /* FIXMEchpe? */
+
+  locked = !gconf_entry_get_is_writable (entry);
+
+  g_free (app->default_profile_id);
+  app->default_profile_id = g_strdup (name);
+
+  old_default = app->default_profile;
+
+  profile = terminal_app_get_profile_by_name (app, name);
+  /* FIXMEchpe: what if |profile| is NULL here? */
+
+  if (profile != NULL &&
+      profile != app->default_profile)
+    {
+      app->default_profile = profile;
+      changed = TRUE;
+    }
+
+  if (locked != app->default_profile_locked)
+    {
+      /* Need to emit changed on all profiles */
+      GList *all_profiles;
+      GList *tmp;
+      TerminalSettingMask mask;
+
+      terminal_setting_mask_clear (&mask);
+      mask.is_default = TRUE;
+      
+      app->default_profile_locked = locked;
+      
+      all_profiles = terminal_app_get_profile_list (app);
+      for (tmp = all_profiles; tmp != NULL; tmp = tmp->next)
+        {
+//           TerminalProfile *p = tmp->data;
+          
+//           emit_changed (p, &mask);
+        }
+
+      g_list_free (all_profiles);
+    }
+  else if (changed)
+    {
+      TerminalSettingMask mask;
+      
+      terminal_setting_mask_clear (&mask);
+      mask.is_default = TRUE;
+
+//       if (old_default)
+//         emit_changed (old_default, &mask);
+
+//       emit_changed (profile, &mask);
+    }
+
+  /* FIXMEchpe: emit default-profile-changed signal */
+}
+
+static void
+terminal_app_profile_delete_list (TerminalApp *app,
+                                  GList       *deleted_profiles,
+                                  GtkWindow   *transient_parent)
+{
+  GList *current_profiles;
+  GList *tmp;
+  GSList *name_list;
+  GError *err = NULL;
+
+  /* reentrancy paranoia */
+  g_object_ref (G_OBJECT (transient_parent));
+  
+  current_profiles = terminal_app_get_profile_list (app);
+
+  /* remove deleted profiles from list */
+  tmp = deleted_profiles;
+  while (tmp != NULL)
+    {
+      gchar *dir;
+      TerminalProfile *profile = tmp->data;
+
+      dir = g_strdup_printf (CONF_PREFIX"/profiles/%s",
+			     terminal_profile_get_name (profile));
+      gconf_client_recursive_unset (conf, dir,
+				    GCONF_UNSET_INCLUDING_SCHEMA_NAMES,
+				    &err);
+      g_free (dir);
+
+      if (err)
+	break;
+
+      current_profiles = g_list_remove (current_profiles, profile);
+
+      tmp = tmp->next;
+    }
+
+  if (!err)
+    {
+      /* make list of profile names */
+      name_list = NULL;
+      tmp = current_profiles;
+      while (tmp != NULL)
+	{
+	  name_list = g_slist_prepend (name_list,
+				       g_strdup (terminal_profile_get_name (tmp->data)));
+	  tmp = tmp->next;
+	}
+
+      g_list_free (current_profiles);
+
+      gconf_client_set_list (conf,
+			     CONF_GLOBAL_PREFIX"/profile_list",
+			     GCONF_VALUE_STRING,
+			     name_list,
+			     &err);
+
+      g_slist_foreach (name_list, (GFunc) g_free, NULL);
+      g_slist_free (name_list);
+    }
+
+  else
+    {
+      if (GTK_WIDGET_VISIBLE (transient_parent))
+        {
+          GtkWidget *dialog;
+
+          dialog = gtk_message_dialog_new (GTK_WINDOW (transient_parent),
+                                           GTK_DIALOG_DESTROY_WITH_PARENT,
+                                           GTK_MESSAGE_ERROR,
+                                           GTK_BUTTONS_CLOSE,
+                                           _("There was an error deleting the profiles"));
+          gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+                                                    "%s", err->message);
+          g_error_free (err);
+
+          g_signal_connect (G_OBJECT (dialog), "response",
+                            G_CALLBACK (gtk_widget_destroy),
+                            NULL);
+
+          gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+
+          gtk_widget_show (dialog);
+        }
+
+      g_error_free (err);
+    }
+
+  g_object_unref (G_OBJECT (transient_parent));
+}
+
+static void
 new_profile_response_callback (GtkWidget *new_profile_dialog,
                                int        response_id,
                                TerminalApp *app)
@@ -395,12 +648,13 @@
       GtkWindow *transient_parent;
       GtkWidget *confirm_dialog;
       gint retval;
+      GError *err;
       
       name_entry = g_object_get_data (G_OBJECT (new_profile_dialog), "name_entry");
       name = gtk_editable_get_chars (GTK_EDITABLE (name_entry), 0, -1);
       g_strstrip (name); /* name will be non empty after stripping */
       
-      profiles = terminal_profile_get_list ();
+      profiles = terminal_app_get_profile_list (app);
       for (tmp = profiles; tmp != NULL; tmp = tmp->next)
         {
           TerminalProfile *profile = tmp->data;
@@ -436,9 +690,33 @@
       
       gtk_widget_destroy (new_profile_dialog);
       
-      escaped_name = terminal_profile_create (base_profile, name, transient_parent);
-      new_profile = terminal_profile_new (escaped_name);
-      terminal_profile_update (new_profile);
+      err = NULL;
+      escaped_name = terminal_profile_clone (base_profile, name, &err);
+      if (err)
+        {
+          GtkWidget *dialog;
+
+          dialog = gtk_message_dialog_new (GTK_WINDOW (transient_parent),
+                                           GTK_DIALOG_DESTROY_WITH_PARENT,
+                                           GTK_MESSAGE_ERROR,
+                                           GTK_BUTTONS_CLOSE,
+                                           _("There was an error creating the profile \"%s\""),
+                                           name);
+          gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+                                                    "%s", err->message);
+          g_error_free (err);
+
+          g_signal_connect (G_OBJECT (dialog), "response",
+                            G_CALLBACK (gtk_widget_destroy),
+                            NULL);
+
+          gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+          
+          gtk_window_present (GTK_WINDOW (dialog));
+        }
+      
+      /* FIXMEchpe: we should have the profile in our list by now! */
+      new_profile = terminal_app_create_profile (app, escaped_name);
 
       /* FIXMEchpe: should be obsolete due to gconf notification */
       gconf_client_notify (conf, PROFILE_LIST_KEY);
@@ -603,13 +881,14 @@
 static void
 refill_profile_treeview (GtkWidget *tree_view)
 {
+  TerminalApp *app = terminal_app_get ();
   GList *profiles;
   GList *tmp;
   GtkTreeSelection *selection;
   GtkListStore *model;
   GList *selected_profiles;
   GtkTreeIter iter;
-  
+
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
   model = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)));
 
@@ -620,7 +899,7 @@
 
   gtk_list_store_clear (model);
   
-  profiles = terminal_profile_get_list ();
+  profiles = terminal_app_get_profile_list (app);
   tmp = profiles;
   while (tmp != NULL)
     {
@@ -714,7 +993,7 @@
   
   if (response_id == GTK_RESPONSE_ACCEPT)
     {
-      terminal_profile_delete_list (conf, deleted_profiles, transient_parent);
+      terminal_app_profile_delete_list (terminal_app_get (), deleted_profiles, transient_parent);
     }
 
   gtk_widget_destroy (dialog);
@@ -747,7 +1026,7 @@
   
   count = g_list_length (deleted_profiles);
 
-  if (count == terminal_profile_get_count ())
+  if (count == terminal_app_get_profile_count (app))
     {
       free_profiles_list (deleted_profiles);
 
@@ -878,6 +1157,8 @@
 
   if (!terminal_profile_get_is_default (p))
     terminal_profile_set_is_default (p, TRUE);
+
+  /* FIXMEchpe */
 }
 
 static void
@@ -899,7 +1180,7 @@
   GList *profiles;
   GList *tmp;
   
-  profiles = terminal_profile_get_list ();
+  profiles = terminal_app_get_profile_list (terminal_app_get ());
 
   tmp = profiles;
   while (tmp != NULL)
@@ -1175,9 +1456,9 @@
             
       app->manage_profiles_default_menu = profile_optionmenu_new ();
       gtk_label_set_mnemonic_widget (GTK_LABEL (label), app->manage_profiles_default_menu);
-      if (terminal_profile_get_default ())
+      if (terminal_app_get_default_profile (app))
         {
-          profile_optionmenu_set_selected (app->manage_profiles_default_menu, terminal_profile_get_default ());
+          profile_optionmenu_set_selected (app->manage_profiles_default_menu, terminal_app_get_default_profile (app));
         }
       g_signal_connect (G_OBJECT (app->manage_profiles_default_menu), "changed", 
                         G_CALLBACK (default_menu_changed), app);
@@ -1248,7 +1529,7 @@
   
   menu = gtk_menu_new ();
   
-  profiles = terminal_profile_get_list ();
+  profiles = terminal_app_get_profile_list (terminal_app_get ());
 
   history = 0;
   i = 0;
@@ -1339,6 +1620,9 @@
 
   global_app = app;
 
+  /* FIXMEchpe leaks */
+  app->profiles = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+  
   conf = gconf_client_get_default ();
 
   gconf_client_add_dir (conf, CONF_GLOBAL_PREFIX,
@@ -1351,12 +1635,19 @@
                              app,
                              NULL, NULL);
 
+  app->default_profile_notify_id =
+    gconf_client_notify_add (conf,
+                             DEFAULT_PROFILE_KEY,
+                             terminal_app_default_profile_notify_cb,
+                             app,
+                             NULL, NULL);
+  
   terminal_accels_init ();
   terminal_encoding_init ();
   
-  terminal_profile_initialize (conf);
   /* And now read the profile list */
   gconf_client_notify (conf, PROFILE_LIST_KEY);
+  gconf_client_notify (conf, DEFAULT_PROFILE_KEY);
 
   g_object_unref (conf);
 }
@@ -1376,6 +1667,10 @@
 
   g_object_unref (conf);
 
+  g_free (app->default_profile_id);
+
+  g_hash_table_destroy (app->profiles);
+
   G_OBJECT_CLASS (terminal_app_parent_class)->finalize (object);
 
   global_app = NULL;
@@ -1618,3 +1913,105 @@
 {
   return g_list_last (app->windows)->data;
 }
+
+/* FIXMEchpe: make this list contain ref'd objects */
+/**
+ * terminal_profile_get_list:
+ *
+ * Returns: a #GList containing all #TerminalProfile objects.
+ *   The content of the list is owned by the backend and
+ *   should not be modified or freed. Use g_list_free() when done
+ *   using the list.
+ */
+GList*
+terminal_app_get_profile_list (TerminalApp *app)
+{
+  g_return_val_if_fail (TERMINAL_IS_APP (app), NULL);
+
+  return g_list_sort (g_hash_table_get_values (app->profiles), profiles_alphabetic_cmp);
+}
+
+guint
+terminal_app_get_profile_count (TerminalApp *app)
+{
+  g_return_val_if_fail (TERMINAL_IS_APP (app), 0);
+
+  return g_hash_table_size (app->profiles);
+}
+
+TerminalProfile*
+terminal_app_get_profile_by_name (TerminalApp *app,
+                                  const char *name)
+{
+  g_return_val_if_fail (TERMINAL_IS_APP (app), NULL);
+  g_return_val_if_fail (name != NULL, NULL);
+
+  return g_hash_table_lookup (app->profiles, name);
+}
+
+TerminalProfile*
+terminal_app_get_profile_by_visible_name (TerminalApp *app,
+                                          const char *name)
+{
+  LookupInfo info;
+
+  g_return_val_if_fail (TERMINAL_IS_APP (app), NULL);
+  g_return_val_if_fail (name != NULL, NULL);
+
+  info.result = NULL;
+  info.target = name;
+
+  g_hash_table_foreach (app->profiles,
+                        profiles_lookup_by_visible_name_foreach,
+                        &info);
+  return info.result;
+}
+
+
+TerminalProfile*
+terminal_app_ensure_profile_fallback (TerminalApp *app)
+{
+  TerminalProfile *profile;
+
+  g_return_val_if_fail (TERMINAL_IS_APP (app), NULL);
+
+  profile = terminal_app_get_profile_by_name (app, FALLBACK_PROFILE_ID);
+  if (profile == NULL)
+    profile = terminal_app_create_profile (app, FALLBACK_PROFILE_ID);
+  
+  return profile;
+}
+
+TerminalProfile*
+terminal_app_get_default_profile (TerminalApp *app)
+{
+  g_return_val_if_fail (TERMINAL_IS_APP (app), NULL);
+
+  return app->default_profile;
+}
+
+TerminalProfile*
+terminal_app_get_profile_for_new_term (TerminalApp *app,
+                                       TerminalProfile *current)
+{
+  GList *list;
+  TerminalProfile *profile;
+
+  g_return_val_if_fail (TERMINAL_IS_APP (app), NULL);
+
+  if (current)
+    return current;
+  
+  if (app->default_profile)
+    return app->default_profile;	
+
+  list = terminal_app_get_profile_list (app);
+  if (list)
+    profile = list->data;
+  else
+    profile = NULL;
+
+  g_list_free (list);
+
+  return profile;
+}

Modified: trunk/src/terminal-app.h
==============================================================================
--- trunk/src/terminal-app.h	(original)
+++ trunk/src/terminal-app.h	Thu May 29 19:37:21 2008
@@ -87,6 +87,26 @@
 void terminal_app_edit_encodings   (TerminalApp     *app,
                                     GtkWindow       *transient_parent);
 
+
+GList* terminal_app_get_profile_list (TerminalApp *app);
+
+guint  terminal_app_get_profile_count (TerminalApp *app);
+
+TerminalProfile* terminal_app_ensure_profile_fallback (TerminalApp *app);
+
+TerminalProfile* terminal_app_get_profile_by_name         (TerminalApp *app,
+                                                           const char      *name);
+
+TerminalProfile* terminal_app_get_profile_by_visible_name (TerminalApp *app,
+                                                           const char      *name);
+
+/* may return NULL */
+TerminalProfile* terminal_app_get_default_profile (TerminalApp *app);
+
+/* never returns NULL if any profiles exist, one is always supposed to */
+TerminalProfile* terminal_app_get_profile_for_new_term (TerminalApp *app,
+                                                        TerminalProfile *current);
+
 G_END_DECLS
 
 #endif /* !TERMINAL_APP_H */

Modified: trunk/src/terminal-profile.c
==============================================================================
--- trunk/src/terminal-profile.c	(original)
+++ trunk/src/terminal-profile.c	Thu May 29 19:37:21 2008
@@ -31,6 +31,7 @@
 
 #include "terminal-intl.h"
 #include "terminal-profile.h"
+#include "terminal-app.h"
 #include "terminal-type-builtins.h"
 
 /* If you add a key, you need to update code:
@@ -133,6 +134,7 @@
   guint no_aa_without_render : 1;
   guint use_skey : 1;
   guint forgotten : 1;
+  guint is_default : 1;
 };
 
 enum {
@@ -265,11 +267,6 @@
   { -1, NULL }
 };
 
-static GHashTable *profiles = NULL;
-static char* default_profile_id = NULL;
-static TerminalProfile *default_profile = NULL;
-static gboolean default_profile_locked = FALSE;
-
 #define RETURN_IF_NOTIFYING(profile) if ((profile)->priv->in_notification_count) return
 
 enum {
@@ -287,14 +284,6 @@
                                           GConfEntry  *entry,
                                           gpointer     user_data);
 
-static void default_change_notify        (GConfClient *client,
-                                          guint        cnxn_id,
-                                          GConfEntry  *entry,
-                                          gpointer     user_data);
-
-static void update_default_profile       (const char  *name,
-                                          gboolean     locked);
-
 static void emit_changed (TerminalProfile           *profile,
                           const TerminalSettingMask *mask);
 
@@ -396,18 +385,7 @@
                   err->message);
       g_error_free (err);
     }
-  
-  g_hash_table_insert (profiles, priv->name, profile);
 
-  if (default_profile == NULL &&
-      default_profile_id &&
-      strcmp (default_profile_id,
-              terminal_profile_get_name (profile)) == 0)
-    {
-      /* We are the default profile */
-      default_profile = profile;
-    }
-  
   return object;
 }
 
@@ -1059,11 +1037,8 @@
 }
 
 TerminalProfile*
-terminal_profile_new (const char *name)
+_terminal_profile_new (const char *name)
 {
-  g_return_val_if_fail (terminal_profile_lookup (name) == NULL,
-                        NULL);
-  
   return g_object_new (TERMINAL_TYPE_PROFILE,
                        "name", name,
                        NULL);
@@ -1719,7 +1694,7 @@
 {
   g_return_val_if_fail (TERMINAL_IS_PROFILE (profile), FALSE);
   
-  return profile == default_profile;
+  return profile->priv->is_default;
 }
 
 void
@@ -1739,10 +1714,13 @@
    * In some cases, the default profile changes twice in quick succession,
    * and update_default_profile must be called in sync with those changes.
    */
-  update_default_profile (terminal_profile_get_name (profile),
+  priv->is_default = setting != FALSE;
+
+  /* FIXMEchpe */
+/*  update_default_profile (terminal_profile_get_name (profile),
                           !gconf_client_key_is_writable (priv->conf,
                                                          CONF_GLOBAL_PREFIX"/default_profile",
-                                                         NULL));
+                                                         NULL));*/
 }
 
 void
@@ -2875,177 +2853,6 @@
   set_key_to_default (profile, KEY_BACKSPACE_BINDING);
 }
 
-static void
-update_default_profile (const char *name,
-                        gboolean    locked)
-{
-  TerminalProfile *profile;
-  gboolean changed;
-  TerminalProfile *old_default;
-  
-  changed = FALSE;
-  
-  g_free (default_profile_id);
-  default_profile_id = g_strdup (name);
-
-  old_default = default_profile;
-  profile = terminal_profile_lookup (name);
-  
-  if (profile)
-    {
-      if (profile != default_profile)
-        {
-          default_profile = profile;
-          changed = TRUE;
-        }
-    }
-
-  if (locked != default_profile_locked)
-    {
-      /* Need to emit changed on all profiles */
-      GList *all_profiles;
-      GList *tmp;
-      TerminalSettingMask mask;
-
-      terminal_setting_mask_clear (&mask);
-      mask.is_default = TRUE;
-      
-      default_profile_locked = locked;
-      
-      all_profiles = terminal_profile_get_list ();
-      tmp = all_profiles;
-      while (tmp != NULL)
-        {
-          TerminalProfile *p = tmp->data;
-          
-          emit_changed (p, &mask);
-          tmp = tmp->next;
-        }
-
-      g_list_free (all_profiles);
-    }
-  else if (changed)
-    {
-      TerminalSettingMask mask;
-      
-      terminal_setting_mask_clear (&mask);
-      mask.is_default = TRUE;
-
-      if (old_default)
-        emit_changed (old_default, &mask);
-
-      emit_changed (profile, &mask);
-    }
-}
-
-static void
-default_change_notify (GConfClient *client,
-                       guint        cnxn_id,
-                       GConfEntry  *entry,
-                       gpointer     user_data)
-{
-  GConfValue *val;
-  gboolean locked;
-  const char *name;
-  
-  val = gconf_entry_get_value (entry);  
-
-  if (val == NULL || val->type != GCONF_VALUE_STRING)
-    return;
-  
-  if (gconf_entry_get_is_writable (entry))  
-    locked = FALSE;
-  else
-    locked = TRUE;
-  
-  name = gconf_value_get_string (val);
-
-  update_default_profile (name, locked);
-}
-
-static int
-alphabetic_cmp (gconstpointer a,
-                gconstpointer b)
-{
-  TerminalProfile *ap = (TerminalProfile*) a;
-  TerminalProfile *bp = (TerminalProfile*) b;
-  int result;
-
-  result =  g_utf8_collate (terminal_profile_get_visible_name (ap),
-			    terminal_profile_get_visible_name (bp));
-  if (result == 0)
-    result = strcmp (terminal_profile_get_name (ap),
-		     terminal_profile_get_name (bp));
-
-  return result;
-}
-
-/* FIXMEchpe: make this list contain ref'd objects */
-/**
- * terminal_profile_get_list:
- *
- * Returns: a #GList containing all #TerminalProfile objects.
- *   The content of the list is owned by the backend and
- *   should not be modified or freed. Use g_list_free() when done
- *   using the list.
- */
-GList*
-terminal_profile_get_list (void)
-{
-  return g_list_sort (g_hash_table_get_values (profiles), alphabetic_cmp);
-}
-
-int
-terminal_profile_get_count (void)
-{
-  return g_hash_table_size (profiles);
-}
-
-TerminalProfile*
-terminal_profile_lookup (const char *name)
-{
-  g_return_val_if_fail (name != NULL, NULL);
-
-  if (profiles)
-    return g_hash_table_lookup (profiles, name);
-    
-  return NULL;
-}
-
-typedef struct
-{
-  TerminalProfile *result;
-  const char *target;
-} LookupInfo;
-
-static void
-lookup_by_visible_name_foreach (gpointer key,
-                                gpointer value,
-                                gpointer data)
-{
-  LookupInfo *info = data;
-
-  if (strcmp (info->target, terminal_profile_get_visible_name (value)) == 0)
-    info->result = value;
-}
-
-TerminalProfile*
-terminal_profile_lookup_by_visible_name (const char *name)
-{
-  LookupInfo info;
-
-  info.result = NULL;
-  info.target = name;
-
-  if (profiles)
-    {
-      g_hash_table_foreach (profiles, lookup_by_visible_name_foreach, &info);
-      return info.result;
-    }
-    
-  return NULL;
-}
-
 void
 terminal_profile_forget (TerminalProfile *profile)
 {
@@ -3066,12 +2873,8 @@
           g_error_free (err);
         }
 
-      g_hash_table_remove (profiles, priv->name);
       priv->forgotten = TRUE;
 
-      if (profile == default_profile)          
-        default_profile = NULL;
-      
       g_signal_emit (G_OBJECT (profile), signals[FORGOTTEN], 0);
     }
 }
@@ -3083,60 +2886,6 @@
   return &priv->locked;
 }
 
-TerminalProfile*
-terminal_profile_ensure_fallback (GConfClient *conf)
-{
-  TerminalProfile *profile;
-
-  profile = terminal_profile_lookup (FALLBACK_PROFILE_ID);
-
-  if (profile == NULL)
-    {
-      profile = terminal_profile_new (FALLBACK_PROFILE_ID);
-      
-      terminal_profile_update (profile);
-    }
-  
-  return profile;
-}
-
-void
-terminal_profile_initialize (GConfClient *conf)
-{
-  GError *err;
-  char *str;
-
-  g_return_if_fail (profiles == NULL);
-  
-  profiles = g_hash_table_new (g_str_hash, g_str_equal);
-  
-  err = NULL;
-  gconf_client_notify_add (conf,
-                           CONF_GLOBAL_PREFIX"/default_profile",
-                           default_change_notify,
-                           NULL,
-                           NULL, &err);
-  
-  if (err)
-    {
-      g_printerr (_("There was an error subscribing to notification of changes to default profile. (%s)\n"),
-                  err->message);
-      g_error_free (err);
-    }
-
-  str = gconf_client_get_string (conf,
-                                 CONF_GLOBAL_PREFIX"/default_profile",
-                                 NULL);
-  if (str)
-    {
-      update_default_profile (str,
-                              !gconf_client_key_is_writable (conf,
-                                                             CONF_GLOBAL_PREFIX"/default_profile",
-                                                             NULL));
-      g_free (str);
-    }
-}
-
 static void
 emit_changed (TerminalProfile           *profile,
               const TerminalSettingMask *mask)
@@ -3148,66 +2897,13 @@
   priv->in_notification_count -= 1;
 }
 
-/* Function I'm cut-and-pasting everywhere, this is from msm */
-static void
-dialog_add_details (GtkDialog  *dialog,
-                    const char *details)
-{
-  GtkWidget *hbox;
-  GtkWidget *button;
-  GtkWidget *label;
-  GtkRequisition req;
-  
-  hbox = gtk_hbox_new (FALSE, 0);
-
-  gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
-  
-  gtk_box_pack_start (GTK_BOX (dialog->vbox),
-                      hbox,
-                      FALSE, FALSE, 0);
-
-  button = gtk_button_new_with_mnemonic (_("_Details"));
-  
-  gtk_box_pack_end (GTK_BOX (hbox), button,
-                    FALSE, FALSE, 0);
-  
-  label = gtk_label_new (details);
-
-  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
-  gtk_label_set_selectable (GTK_LABEL (label), TRUE);
-  
-  gtk_box_pack_start (GTK_BOX (hbox), label,
-                      TRUE, TRUE, 0);
-
-  /* show the label on click */
-  g_signal_connect_swapped (G_OBJECT (button),
-                            "clicked",
-                            G_CALLBACK (gtk_widget_show),
-                            label);
-  
-  /* second callback destroys the button (note disconnects first callback) */
-  g_signal_connect (G_OBJECT (button), "clicked",
-                    G_CALLBACK (gtk_widget_destroy),
-                    NULL);
-
-  /* Set default dialog size to size with the label,
-   * and without the button, but then rehide the label
-   */
-  gtk_widget_show_all (hbox);
-
-  gtk_widget_size_request (GTK_WIDGET (dialog), &req);
-
-  gtk_window_set_default_size (GTK_WINDOW (dialog), req.width, req.height);
-  
-  gtk_widget_hide (label);
-}
-
 /* returns actual name used for created profile */
 char *
-terminal_profile_create (TerminalProfile *base_profile,
+terminal_profile_clone (TerminalProfile *base_profile,
                          const char      *visible_name,
-                         GtkWindow       *transient_parent)
+                         GError **error)
 {
+  TerminalApp *app = terminal_app_get ();
   TerminalProfilePrivate *base_priv = base_profile->priv;
   char *profile_name = NULL;
   char *profile_dir = NULL;
@@ -3215,28 +2911,28 @@
   char *s;
   const char *cs;
   char *key = NULL;
-  GError *err = NULL;
   GList *profiles = NULL;
   GSList *name_list = NULL;
-  GList *tmp;  
+  GList *tmp;
+  GError *err = NULL;
 
   /* This is for extra bonus paranoia against CORBA reentrancy */
-  g_object_ref (G_OBJECT (base_profile));
-  g_object_ref (G_OBJECT (transient_parent));
+  /* FIXMEchpe more like bogus paranoia */
+  g_object_ref (base_profile);
 
 #define BAIL_OUT_CHECK() do {                           \
-    if (!GTK_WIDGET_VISIBLE (transient_parent) ||       \
-        base_priv->forgotten ||                \
+    if (base_priv->forgotten ||                         \
         err != NULL)                                    \
        goto cleanup;                                    \
   } while (0) 
-  
+
+  /* FIXMEchpe justf use "profileN" */
   /* Pick a unique name for storing in gconf (based on visible name) */
   profile_name = gconf_escape_key (visible_name, -1);
 
   s = g_strdup (profile_name);
   i = 0;
-  while (terminal_profile_lookup (s))
+  while (terminal_app_get_profile_by_name (app, s))
     {
       g_free (s);
       
@@ -3550,7 +3246,7 @@
    * a race condition where we and someone else set at the same time,
    * but I am just going to punt on this issue.
    */
-  profiles = terminal_profile_get_list ();
+  profiles = terminal_app_get_profile_list (terminal_app_get ());
   tmp = profiles;
   while (tmp != NULL)
     {
@@ -3584,159 +3280,17 @@
   
   if (err)
     {
-      if (GTK_WIDGET_VISIBLE (transient_parent))
-        {
-          GtkWidget *dialog;
-
-          dialog = gtk_message_dialog_new (GTK_WINDOW (transient_parent),
-                                           GTK_DIALOG_DESTROY_WITH_PARENT,
-                                           GTK_MESSAGE_ERROR,
-                                           GTK_BUTTONS_CLOSE,
-                                           _("There was an error creating the profile \"%s\""),
-                                           visible_name);
-          g_signal_connect (G_OBJECT (dialog), "response",
-                            G_CALLBACK (gtk_widget_destroy),
-                            NULL);
-
-          dialog_add_details (GTK_DIALOG (dialog),
-                              err->message);
-          
-          gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
-          
-          gtk_widget_show (dialog);
-        }
-
-      g_error_free (err);
-
       g_free (profile_name);
       profile_name = NULL;
-    }
 
-  g_object_unref (G_OBJECT (base_profile));
-  g_object_unref (G_OBJECT (transient_parent));
-  return profile_name;
-}
-
-void
-terminal_profile_delete_list (GConfClient *conf,
-                              GList       *deleted_profiles,
-                              GtkWindow   *transient_parent)
-{
-  GList *current_profiles;
-  GList *tmp;
-  GSList *name_list;
-  GError *err = NULL;
-
-  /* reentrancy paranoia */
-  g_object_ref (G_OBJECT (transient_parent));
-  
-  current_profiles = terminal_profile_get_list ();  
-
-  /* remove deleted profiles from list */
-  tmp = deleted_profiles;
-  while (tmp != NULL)
-    {
-      gchar *dir;
-      TerminalProfile *profile = tmp->data;
-
-      dir = g_strdup_printf (CONF_PREFIX"/profiles/%s",
-			     terminal_profile_get_name (profile));
-      gconf_client_recursive_unset (conf, dir,
-				    GCONF_UNSET_INCLUDING_SCHEMA_NAMES,
-				    &err);
-      g_free (dir);
-
-      if (err)
-	break;
-
-      current_profiles = g_list_remove (current_profiles, profile);
-
-      tmp = tmp->next;
-    }
-
-  if (!err)
-    {
-      /* make list of profile names */
-      name_list = NULL;
-      tmp = current_profiles;
-      while (tmp != NULL)
-	{
-	  name_list = g_slist_prepend (name_list,
-				       g_strdup (terminal_profile_get_name (tmp->data)));
-	  tmp = tmp->next;
-	}
-
-      g_list_free (current_profiles);
-
-      gconf_client_set_list (conf,
-			     CONF_GLOBAL_PREFIX"/profile_list",
-			     GCONF_VALUE_STRING,
-			     name_list,
-			     &err);
-
-      g_slist_foreach (name_list, (GFunc) g_free, NULL);
-      g_slist_free (name_list);
-    }
-
-  else
-    {
-      if (GTK_WIDGET_VISIBLE (transient_parent))
-        {
-          GtkWidget *dialog;
-
-          dialog = gtk_message_dialog_new (GTK_WINDOW (transient_parent),
-                                           GTK_DIALOG_DESTROY_WITH_PARENT,
-                                           GTK_MESSAGE_ERROR,
-                                           GTK_BUTTONS_CLOSE,
-                                           _("There was an error deleting the profiles"));
-          g_signal_connect (G_OBJECT (dialog), "response",
-                            G_CALLBACK (gtk_widget_destroy),
-                            NULL);
-
-          dialog_add_details (GTK_DIALOG (dialog),
-                              err->message);
-
-          gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
-
-          gtk_widget_show (dialog);
-        }
-
-      g_error_free (err);
+      *error = err;
     }
 
-  g_object_unref (G_OBJECT (transient_parent));
-}
-
-TerminalProfile*
-terminal_profile_get_default (void)
-{
-  return default_profile;
-}
-
-TerminalProfile*
-terminal_profile_get_for_new_term (TerminalProfile *current)
-{
-  GList *list;
-  TerminalProfile *profile;
-
-  if (current)
-    return current;
-  
-  if (default_profile)
-    return default_profile;	
-
-  list = terminal_profile_get_list ();
-  if (list)
-    profile = list->data;
-  else
-    profile = NULL;
-
-  g_list_free (list);
-
-  return profile;
+  g_object_unref (base_profile);
+  return profile_name;
 }
 
-/* We need to do this ourselves, because the gtk_color_selection_palette_to_string 
+/* We need to do this ourselves, because the gtk_color_selection_palette_to_string
  * does not carry all the bytes, and xterm's palette is messed up...
  */
 

Modified: trunk/src/terminal-profile.h
==============================================================================
--- trunk/src/terminal-profile.h	(original)
+++ trunk/src/terminal-profile.h	Thu May 29 19:37:21 2008
@@ -133,7 +133,7 @@
 
 GType terminal_profile_get_type (void) G_GNUC_CONST;
 
-TerminalProfile* terminal_profile_new (const char  *name);
+TerminalProfile* _terminal_profile_new (const char  *name);
 
 const char*               terminal_profile_get_name                 (TerminalProfile *profile);
 const char*               terminal_profile_get_visible_name         (TerminalProfile *profile);
@@ -251,36 +251,21 @@
 
 void terminal_profile_reset_compat_defaults     (TerminalProfile        *profile);
 
-TerminalProfile* terminal_profile_ensure_fallback        (GConfClient     *conf);
-void             terminal_profile_initialize             (GConfClient     *conf);
-GList*           terminal_profile_get_list               (void);
-int              terminal_profile_get_count              (void);
-/* may return NULL */
-TerminalProfile* terminal_profile_get_default            (void);
-/* never returns NULL if any profiles exist, one is always supposed to */
-TerminalProfile* terminal_profile_get_for_new_term       (TerminalProfile *current);
-TerminalProfile* terminal_profile_lookup                 (const char      *name);
-TerminalProfile* terminal_profile_lookup_by_visible_name (const char      *name);
-void             terminal_profile_forget                 (TerminalProfile *profile);
-
 const TerminalSettingMask* terminal_profile_get_locked_settings (TerminalProfile *profile);
 
 void terminal_profile_update (TerminalProfile *profile);
 
-char* terminal_profile_create (TerminalProfile *base_profile,
-                               const char      *visible_name,
-                               GtkWindow       *transient_parent);
-
-void terminal_profile_delete_list (GConfClient *conf,
-                                   GList      *list,
-                                   GtkWindow  *transient_parent);
+void             terminal_profile_forget                 (TerminalProfile *profile);
+
+char* terminal_profile_clone (TerminalProfile *base_profile,
+                              const char      *visible_name,
+                              GError **err);
 
 gboolean terminal_setting_mask_is_empty (const TerminalSettingMask *mask);
 void     terminal_setting_mask_clear    (TerminalSettingMask       *mask);
 gboolean terminal_setting_mask_equal    (const TerminalSettingMask *a,
                                          const TerminalSettingMask *b);
 
-
 extern const GdkColor terminal_palette_linux[TERMINAL_PALETTE_SIZE];
 extern const GdkColor terminal_palette_xterm[TERMINAL_PALETTE_SIZE];
 extern const GdkColor terminal_palette_rxvt[TERMINAL_PALETTE_SIZE];

Modified: trunk/src/terminal-screen.c
==============================================================================
--- trunk/src/terminal-screen.c	(original)
+++ trunk/src/terminal-screen.c	Thu May 29 19:37:21 2008
@@ -35,6 +35,7 @@
 
 #include <gdk/gdkx.h>
 
+#include "terminal-app.h"
 #include "terminal-accels.h"
 #include "terminal-window.h"
 #include "terminal-profile.h"
@@ -917,7 +918,7 @@
   TerminalProfile *new_profile;
 
   /* Revert to the new term profile if any */
-  new_profile = terminal_profile_get_for_new_term (NULL);
+  new_profile = terminal_app_get_profile_for_new_term (terminal_app_get (), NULL);
 
   if (new_profile)
     terminal_screen_set_profile (screen, new_profile);

Modified: trunk/src/terminal-window.c
==============================================================================
--- trunk/src/terminal-window.c	(original)
+++ trunk/src/terminal-window.c	Thu May 29 19:37:21 2008
@@ -313,7 +313,7 @@
   if (priv->active_term == NULL)
     return;
 
-  profiles = terminal_profile_get_list ();
+  profiles = terminal_app_get_profile_list (terminal_app_get ());
 
   action = gtk_action_group_get_action (priv->action_group, "TerminalProfiles");
   gtk_action_set_sensitive (action, profiles && profiles->next != NULL /* list length >= 2 */);
@@ -443,7 +443,7 @@
       priv->new_terminal_action_group = NULL;
     }
 
-  profiles = terminal_profile_get_list ();
+  profiles = terminal_app_get_profile_list (terminal_app_get ());
   have_single_profile = !profiles || !profiles->next;
 
   action = gtk_action_group_get_action (priv->action_group, "FileNewTab");
@@ -2144,7 +2144,7 @@
 
   profile = g_object_get_data (G_OBJECT (action), PROFILE_DATA_KEY);
   if (!profile)
-    profile = terminal_profile_get_default ();
+    profile = terminal_app_get_default_profile (terminal_app_get ());
   if (!profile)
     return;
 
@@ -2201,7 +2201,7 @@
 
   profile = g_object_get_data (G_OBJECT (action), PROFILE_DATA_KEY);
   if (!profile)
-    profile = terminal_profile_get_default ();
+    profile = terminal_app_get_default_profile (terminal_app_get ());
   if (!profile)
     return;
 
@@ -2690,13 +2690,14 @@
 #endif
 }
 
+/* FIXMEchpe */
 static void
 monitor_profiles_for_is_default_change (TerminalWindow *window)
 {
   GList *profiles;
   GList *tmp;
   
-  profiles = terminal_profile_get_list ();
+  profiles = terminal_app_get_profile_list (terminal_app_get ());
 
   tmp = profiles;
   while (tmp != NULL)

Modified: trunk/src/terminal.c
==============================================================================
--- trunk/src/terminal.c	(original)
+++ trunk/src/terminal.c	Thu May 29 19:37:21 2008
@@ -929,8 +929,11 @@
 static int
 new_terminal_with_options (OptionParsingResults *results)
 {
+  TerminalApp *app;
   GList *tmp;
-  
+
+  app = terminal_app_get ();
+
   tmp = results->initial_windows;
   while (tmp != NULL)
     {
@@ -954,13 +957,13 @@
           if (it->profile)
             {
               if (it->profile_is_id)
-                profile = terminal_profile_lookup (it->profile);
+                profile = terminal_app_get_profile_by_name (app, it->profile);
               else                
-                profile = terminal_profile_lookup_by_visible_name (it->profile);
+                profile = terminal_app_get_profile_by_visible_name (app, it->profile);
             }
           else if (it->profile == NULL)
             {
-              profile = terminal_profile_get_for_new_term (NULL);
+              profile = terminal_app_get_profile_for_new_term (app, NULL);
             }
           
           if (profile == NULL)
@@ -968,7 +971,7 @@
               if (it->profile)
                 g_printerr (_("No such profile '%s', using default profile\n"),
                             it->profile);
-              profile = terminal_profile_get_for_new_term (NULL);
+              profile = terminal_app_get_profile_for_new_term (app, NULL);
             }
           
           g_assert (profile);



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