gnome-terminal r2672 - trunk/src
- From: chpe svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-terminal r2672 - trunk/src
- Date: Thu, 29 May 2008 19:43:56 +0000 (UTC)
Author: chpe
Date: Thu May 29 19:43:56 2008
New Revision: 2672
URL: http://svn.gnome.org/viewvc/gnome-terminal?rev=2672&view=rev
Log:
Decruftify the code that loads the profile list and the default profile name.
Remove the "is-default" property from TerminalProfile, it's unused.
Modified:
trunk/src/terminal-app.c
trunk/src/terminal-profile.c
trunk/src/terminal-profile.h
trunk/src/terminal-window.c
trunk/src/terminal-window.h
Modified: trunk/src/terminal-app.c
==============================================================================
--- trunk/src/terminal-app.c (original)
+++ trunk/src/terminal-app.c Thu May 29 19:43:56 2008
@@ -74,7 +74,6 @@
void (* quit) (TerminalApp *app);
void (* profile_list_changed) (TerminalApp *app);
- void (* default_profile_changed) (TerminalApp *app);
};
struct _TerminalApp
@@ -109,14 +108,14 @@
enum
{
PROP_0,
- PROP_SYSTEM_FONT
+ PROP_DEFAULT_PROFILE,
+ PROP_SYSTEM_FONT,
};
enum
{
QUIT,
- PROFILES_LIST_CHANGED,
- DEFAULT_PROFILE_CHANGED,
+ PROFILE_LIST_CHANGED,
LAST_SIGNAL
};
@@ -196,47 +195,6 @@
gtk_main_quit ();
}
-static void
-terminal_app_profile_forgotten_cb (TerminalProfile *profile,
- TerminalApp *app)
-{
- g_hash_table_remove (app->profiles, terminal_profile_get_property_string (profile, TERMINAL_PROFILE_NAME));
-
- if (profile == app->default_profile)
- app->default_profile = NULL;
- /* FIXMEchpe update default profile! */
-
- /* FIXMEchpe emit profiles-list-changed signal */
-}
-
-static void
-terminal_app_set_default_profile (TerminalApp *app,
- TerminalProfile *new_default)
-{
- if (app->default_profile)
- g_object_set (app->default_profile, TERMINAL_PROFILE_IS_DEFAULT, FALSE, NULL);
-
- gconf_client_set_string (app->conf,
- CONF_GLOBAL_PREFIX "/default_profile",
- terminal_profile_get_property_string (new_default, TERMINAL_PROFILE_NAME),
- NULL);
-
- /* Even though the gconf change notification does this, it happens too late.
- * In some cases, the default profile changes twice in quick succession,
- * and update_default_profile must be called in sync with those changes.
- */
- g_object_set (new_default, TERMINAL_PROFILE_IS_DEFAULT, TRUE, NULL);
-
- /* FIXMEchpe */
-/* update_default_profile (terminal_profile_get_name (profile),
- !gconf_client_key_is_writable (priv->conf,
- CONF_GLOBAL_PREFIX"/default_profile",
- NULL));*/
-
- /* FIXMEchpe emit default-profile-changed signal */
-}
-
-
static TerminalProfile *
terminal_app_create_profile (TerminalApp *app,
const char *name)
@@ -248,9 +206,6 @@
profile = _terminal_profile_new (name);
- g_signal_connect (profile, "forgotten",
- G_CALLBACK (terminal_app_profile_forgotten_cb), app);
-
g_hash_table_insert (app->profiles,
g_strdup (terminal_profile_get_property_string (profile, TERMINAL_PROFILE_NAME)),
profile /* adopts the refcount */);
@@ -620,12 +575,20 @@
if (!profile)
return;
- if (!terminal_profile_get_property_boolean (profile, TERMINAL_PROFILE_IS_DEFAULT))
- terminal_app_set_default_profile (app, profile);
+ gconf_client_set_string (app->conf,
+ CONF_GLOBAL_PREFIX "/default_profile",
+ terminal_profile_get_property_string (profile, TERMINAL_PROFILE_NAME),
+ NULL);
+
+ /* Even though the gconf change notification does this, it happens too late.
+ * In some cases, the default profile changes twice in quick succession,
+ * and update_default_profile must be called in sync with those changes.
+ */
+ app->default_profile = profile;
+
+ g_object_notify (G_OBJECT (app), "default-profile");
g_object_unref (profile);
-
- /* FIXMEchpe */
}
static void
@@ -834,21 +797,18 @@
find_profile_link (GList *profiles,
const char *name)
{
- GList *tmp;
+ GList *l;
- tmp = profiles;
- while (tmp != NULL)
+ for (l = profiles; l != NULL; l = l->next)
{
const char *profile_name;
- profile_name = terminal_profile_get_property_string (TERMINAL_PROFILE (tmp->data), TERMINAL_PROFILE_NAME);
+ profile_name = terminal_profile_get_property_string (TERMINAL_PROFILE (l->data), TERMINAL_PROFILE_NAME);
if (profile_name && strcmp (profile_name, name) == 0)
- return tmp;
-
- tmp = tmp->next;
+ break;
}
- return NULL;
+ return l;
}
static void
@@ -858,16 +818,18 @@
gpointer user_data)
{
TerminalApp *app = TERMINAL_APP (user_data);
+ GObject *object = G_OBJECT (app);
GConfValue *val;
- GSList *value_list, *tmp_slist;
- GList *known, *tmp_list;
+ GSList *value_list, *sl;
+ GList *profiles_to_delete, *l;
gboolean need_new_default;
TerminalProfile *fallback;
- known = terminal_app_get_profile_list (app);
+ g_object_freeze_notify (object);
- val = gconf_entry_get_value (entry);
+ profiles_to_delete = terminal_app_get_profile_list (app);
+ val = gconf_entry_get_value (entry);
if (val == NULL ||
val->type != GCONF_VALUE_LIST ||
gconf_value_get_list_type (val) != GCONF_VALUE_STRING)
@@ -876,9 +838,9 @@
value_list = gconf_value_get_list (val);
/* Add any new ones */
- for (tmp_slist = value_list; tmp_slist != NULL; tmp_slist = tmp_slist->next)
+ for (sl = value_list; sl != NULL; sl = sl->next)
{
- GConfValue *listvalue = (GConfValue *) (tmp_slist->data);
+ GConfValue *listvalue = (GConfValue *) (sl->data);
const char *profile_name;
GList *link;
@@ -886,24 +848,19 @@
if (!profile_name)
continue;
- link = find_profile_link (known, profile_name);
-
+ link = find_profile_link (profiles_to_delete, profile_name);
if (link)
- {
- /* make known point to profiles we didn't find in the list */
- known = g_list_delete_link (known, link);
- }
+ /* make profiles_to_delete point to profiles we didn't find in the list */
+ profiles_to_delete = g_list_delete_link (profiles_to_delete, link);
else
- {
- terminal_app_create_profile (app, profile_name);
- }
+ terminal_app_create_profile (app, profile_name);
}
ensure_one_profile:
fallback = NULL;
if (terminal_app_get_profile_count (app) == 0 ||
- terminal_app_get_profile_count (app) <= g_list_length (known))
+ terminal_app_get_profile_count (app) <= g_list_length (profiles_to_delete))
{
/* We are going to run out, so create the fallback
* to be sure we always have one. Must be done
@@ -916,45 +873,58 @@
* all profiles, the FALLBACK_ID profile returns as
* the living dead.
*/
- fallback = terminal_app_ensure_profile_fallback (app);
+ fallback = terminal_app_get_profile_by_name (app, FALLBACK_PROFILE_ID);
+ if (fallback == NULL)
+ fallback = terminal_app_create_profile (app, FALLBACK_PROFILE_ID);
+ g_assert (fallback != NULL);
}
/* Forget no-longer-existing profiles */
need_new_default = FALSE;
- tmp_list = known;
- while (tmp_list != NULL)
+ for (l = profiles_to_delete; l != NULL; l = l->next)
{
- TerminalProfile *forgotten;
+ TerminalProfile *profile = TERMINAL_PROFILE (l->data);
+ const char *name;
- forgotten = TERMINAL_PROFILE (tmp_list->data);
+ name = terminal_profile_get_property_string (profile, TERMINAL_PROFILE_NAME);
+ if (strcmp (name, FALLBACK_PROFILE_ID) == 0)
+ continue;
- /* don't allow deleting the fallback if appropriate. */
- if (forgotten != fallback)
+ if (profile == app->default_profile)
{
- if (terminal_profile_get_property_boolean (forgotten, TERMINAL_PROFILE_IS_DEFAULT))
- need_new_default = TRUE;
-
- /* FIXMEchpe make this out of this loop! */
- _terminal_profile_forget (forgotten);
+ app->default_profile = NULL;
+ need_new_default = TRUE;
}
-
- tmp_list = tmp_list->next;
- }
- g_list_free (known);
+ g_object_add_weak_pointer (G_OBJECT (profile), (gpointer*)&profile);
+
+ _terminal_profile_forget (profile);
+ g_hash_table_remove (app->profiles, name);
+
+ /* |profile| should now be dead */
+ g_assert (profile == NULL);
+ }
+ g_list_free (profiles_to_delete);
if (need_new_default)
{
TerminalProfile *new_default;
- known = terminal_app_get_profile_list (app);
-
- g_assert (known);
- new_default = known->data;
+ new_default = terminal_app_get_profile_by_name (app, FALLBACK_PROFILE_ID);
+ if (new_default == NULL)
+ {
+ GHashTableIter iter;
- g_list_free (known);
+ g_hash_table_iter_init (&iter, app->profiles);
+ if (!g_hash_table_iter_next (&iter, NULL, (gpointer *) &new_default))
+ /* shouldn't really happen ever, but just to be safe */
+ new_default = terminal_app_create_profile (app, FALLBACK_PROFILE_ID);
+ }
+ g_assert (new_default != NULL);
- terminal_app_set_default_profile (app, new_default);
+ app->default_profile = new_default;
+
+ g_object_notify (object, "default-profile");
}
g_assert (terminal_app_get_profile_count (app) > 0);
@@ -971,13 +941,9 @@
if (app->manage_profiles_default_menu)
profile_combo_box_refill (app->manage_profiles_default_menu);
- tmp_list = app->windows;
- while (tmp_list != NULL)
- {
- terminal_window_reread_profile_list (TERMINAL_WINDOW (tmp_list->data));
+ g_signal_emit (app, signals[PROFILE_LIST_CHANGED], 0);
- tmp_list = tmp_list->next;
- }
+ g_object_thaw_notify (object);
}
static void
@@ -987,13 +953,11 @@
gpointer user_data)
{
TerminalApp *app = TERMINAL_APP (user_data);
- TerminalProfile *profile;
- TerminalProfile *old_default;
GConfValue *val;
- gboolean changed = FALSE;
- gboolean locked;
const char *name;
+ app->default_profile_locked = !gconf_entry_get_is_writable (entry);
+
val = gconf_entry_get_value (entry);
if (val == NULL ||
val->type != GCONF_VALUE_STRING)
@@ -1001,61 +965,14 @@
name = gconf_value_get_string (val);
if (!name)
- return; /* FIXMEchpe? */
-
- locked = !gconf_entry_get_is_writable (entry);
+ name = FALLBACK_PROFILE_ID; /* FIXMEchpe? */
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);
- }
+ app->default_profile = terminal_app_get_profile_by_name (app, name);
- 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 */
+ g_object_notify (G_OBJECT (app), "default-profile");
}
static void
@@ -1723,12 +1640,29 @@
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
+ signals[PROFILE_LIST_CHANGED] =
+ g_signal_new (I_("profile-list-changed"),
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (TerminalAppClass, profile_list_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
g_object_class_install_property
(object_class,
PROP_SYSTEM_FONT,
g_param_spec_boxed ("system-font", NULL, NULL,
PANGO_TYPE_FONT_DESCRIPTION,
G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+
+ /* FIMXEchpe make rw prop */
+ g_object_class_install_property
+ (object_class,
+ PROP_DEFAULT_PROFILE,
+ g_param_spec_object ("default-profile", NULL, NULL,
+ TERMINAL_TYPE_PROFILE,
+ G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
}
/* Public API */
@@ -2004,21 +1938,6 @@
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)
{
Modified: trunk/src/terminal-profile.c
==============================================================================
--- trunk/src/terminal-profile.c (original)
+++ trunk/src/terminal-profile.c Thu May 29 19:43:56 2008
@@ -59,7 +59,6 @@
PROP_EXIT_ACTION,
PROP_FONT,
PROP_FOREGROUND_COLOR,
- PROP_IS_DEFAULT,
PROP_LOGIN_SHELL,
PROP_NAME,
PROP_NO_AA_WITHOUT_RENDER,
@@ -127,7 +126,6 @@
#define DEFAULT_EXIT_ACTION (TERMINAL_EXIT_CLOSE)
#define DEFAULT_FONT ("Monospace 12")
#define DEFAULT_FOREGROUND_COLOR ("#000000")
-#define DEFAULT_IS_DEFAULT (FALSE)
#define DEFAULT_LOGIN_SHELL (FALSE)
#define DEFAULT_NAME (NULL)
#define DEFAULT_NO_AA_WITHOUT_RENDER (TRUE)
@@ -148,8 +146,6 @@
#define DEFAULT_VISIBLE_NAME (N_("Unnamed"))
#define DEFAULT_WORD_CHARS ("-A-Za-z0-9,./?%&#:_")
-#define PSPEC_GCONF_KEY_DATA "GT::GConfKey"
-
struct _TerminalProfilePrivate
{
GValueArray *properties;
@@ -278,6 +274,7 @@
static void terminal_profile_finalize (GObject *object);
static guint signals[LAST_SIGNAL];
+static GQuark gconf_key_quark;
G_DEFINE_TYPE (TerminalProfile, terminal_profile, G_TYPE_OBJECT);
@@ -711,7 +708,7 @@
return;
#endif
- gconf_key = g_param_spec_get_qdata (pspec, g_quark_from_static_string (PSPEC_GCONF_KEY_DATA));
+ gconf_key = g_param_spec_get_qdata (pspec, gconf_key_quark);
if (!gconf_key)
return;
@@ -991,7 +988,7 @@
if (is_construct)
continue;
- gconf_key = g_param_spec_get_qdata (pspec, g_quark_from_static_string (PSPEC_GCONF_KEY_DATA));
+ gconf_key = g_param_spec_get_qdata (pspec, gconf_key_quark);
if (!gconf_key)
continue;
@@ -1150,7 +1147,8 @@
notify (object, pspec);
if (pspec->owner_type == TERMINAL_TYPE_PROFILE &&
- (pspec->flags & G_PARAM_WRITABLE))
+ (pspec->flags & G_PARAM_WRITABLE) &&
+ g_param_spec_get_qdata (pspec, gconf_key_quark) != NULL)
terminal_profile_schedule_save (TERMINAL_PROFILE (object), pspec);
}
@@ -1159,6 +1157,8 @@
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ gconf_key_quark = g_quark_from_static_string ("GT::GConfKey");
+
g_type_class_add_private (object_class, sizeof (TerminalProfilePrivate));
object_class->constructor = terminal_profile_constructor;
@@ -1188,7 +1188,7 @@
\
if (propGConf)\
{\
- g_param_spec_set_qdata (pspec, g_quark_from_static_string (PSPEC_GCONF_KEY_DATA), propGConf);\
+ g_param_spec_set_qdata (pspec, gconf_key_quark, propGConf);\
g_hash_table_insert (klass->gconf_keys, propGConf, pspec);\
}\
}
@@ -1261,7 +1261,6 @@
TERMINAL_PROFILE_PROPERTY_BOOLEAN (ALLOW_BOLD, DEFAULT_ALLOW_BOLD, KEY_ALLOW_BOLD);
TERMINAL_PROFILE_PROPERTY_BOOLEAN (DEFAULT_SHOW_MENUBAR, DEFAULT_DEFAULT_SHOW_MENUBAR, KEY_DEFAULT_SHOW_MENUBAR);
- TERMINAL_PROFILE_PROPERTY_BOOLEAN (IS_DEFAULT, DEFAULT_IS_DEFAULT, NULL);
TERMINAL_PROFILE_PROPERTY_BOOLEAN (LOGIN_SHELL, DEFAULT_LOGIN_SHELL, KEY_LOGIN_SHELL);
TERMINAL_PROFILE_PROPERTY_BOOLEAN (NO_AA_WITHOUT_RENDER, DEFAULT_NO_AA_WITHOUT_RENDER, KEY_NO_AA_WITHOUT_RENDER);
TERMINAL_PROFILE_PROPERTY_BOOLEAN (SCROLL_BACKGROUND, DEFAULT_SCROLL_BACKGROUND, KEY_SCROLL_BACKGROUND);
Modified: trunk/src/terminal-profile.h
==============================================================================
--- trunk/src/terminal-profile.h (original)
+++ trunk/src/terminal-profile.h Thu May 29 19:43:56 2008
@@ -80,7 +80,6 @@
#define TERMINAL_PROFILE_EXIT_ACTION "exit-action"
#define TERMINAL_PROFILE_FONT "font"
#define TERMINAL_PROFILE_FOREGROUND_COLOR "foreground-color"
-#define TERMINAL_PROFILE_IS_DEFAULT "is-default"
#define TERMINAL_PROFILE_LOGIN_SHELL "login-shell"
#define TERMINAL_PROFILE_NAME "name"
#define TERMINAL_PROFILE_NO_AA_WITHOUT_RENDER "no-aa-without-render"
Modified: trunk/src/terminal-window.c
==============================================================================
--- trunk/src/terminal-window.c (original)
+++ trunk/src/terminal-window.c Thu May 29 19:43:56 2008
@@ -1070,6 +1070,14 @@
}
static void
+terminal_window_profile_list_changed_cb (TerminalApp *app,
+ TerminalWindow *window)
+{
+ terminal_window_update_set_profile_menu (window);
+ terminal_window_update_new_terminal_menus (window);
+}
+
+static void
terminal_window_init (TerminalWindow *window)
{
const GtkActionEntry menu_entries[] =
@@ -1220,6 +1228,7 @@
FALSE }
};
TerminalWindowPrivate *priv;
+ TerminalApp *app;
GtkActionGroup *action_group;
GtkAction *action;
GtkUIManager *manager;
@@ -1323,7 +1332,10 @@
/* Add tabs menu */
priv->tabs_menu = terminal_tabs_menu_new (window);
- terminal_window_reread_profile_list (window);
+ app = terminal_app_get ();
+ terminal_window_profile_list_changed_cb (app, window);
+ g_signal_connect (app, "profile-list-changed",
+ G_CALLBACK (terminal_window_profile_list_changed_cb), window);
terminal_window_set_menubar_visible (window, TRUE);
priv->use_default_menubar_visibility = TRUE;
@@ -1378,6 +1390,10 @@
priv->tabs_menu = NULL;
}
+ g_signal_handlers_disconnect_by_func (terminal_app_get (),
+ G_CALLBACK (terminal_window_profile_list_changed_cb),
+ window);
+
G_OBJECT_CLASS (terminal_window_parent_class)->dispose (object);
}
@@ -2670,74 +2686,6 @@
g_free (license_text);
}
-#if 0
-static void
-default_profile_changed (TerminalProfile *profile,
- const TerminalSettingMask *mask,
- void *data)
-{
- /* This no longer applies, since our "new window" item
- * is based on the current profile, not the default profile
- */
-#if 0
- TerminalWindowPrivate *priv = window->priv;
-
- if (mask & TERMINAL_SETTING_IS_DEFAULT)
- {
- TerminalWindow *window;
-
- window = TERMINAL_WINDOW (data);
-
- /* When the default changes, we get a settings change
- * on the old default and the new. We only rebuild
- * the menu on the notify for the new default.
- */
- if (terminal_profile_get_is_default (profile))
- fill_in_new_term_submenus (window);
- }
-#endif
-}
-
-/* FIXMEchpe */
-static void
-monitor_profiles_for_is_default_change (TerminalWindow *window)
-{
- GList *profiles;
- GList *tmp;
-
- profiles = terminal_app_get_profile_list (terminal_app_get ());
-
- tmp = profiles;
- while (tmp != NULL)
- {
- TerminalProfile *profile = tmp->data;
-
- g_signal_handlers_disconnect_by_func (G_OBJECT (profile),
- G_CALLBACK (default_profile_changed),
- window);
-
- g_signal_connect_object (G_OBJECT (profile),
- "changed",
- G_CALLBACK (default_profile_changed),
- G_OBJECT (window),
- 0);
-
- tmp = tmp->next;
- }
-
- g_list_free (profiles);
-}
-#endif
-
-void
-terminal_window_reread_profile_list (TerminalWindow *window)
-{
-// monitor_profiles_for_is_default_change (window);
-
- terminal_window_update_set_profile_menu (window);
- terminal_window_update_new_terminal_menus (window);
-}
-
void
terminal_window_set_startup_id (TerminalWindow *window,
const char *startup_id)
Modified: trunk/src/terminal-window.h
==============================================================================
--- trunk/src/terminal-window.h (original)
+++ trunk/src/terminal-window.h Thu May 29 19:43:56 2008
@@ -90,8 +90,6 @@
GtkWidget* terminal_window_get_notebook (TerminalWindow *window);
-void terminal_window_reread_profile_list (TerminalWindow *window);
-
void terminal_window_set_startup_id (TerminalWindow *window,
const char *startup_id);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]