terminal-window: avoid to make new GSettings in every new window

use GSettings app instead
Pablo Barciela 2019-12-26 17:38:17 +01:00 committed by ZenWalker
parent 5cd597b040
commit 2aeda2e522
3 changed files with 31 additions and 38 deletions

View File

@ -90,7 +90,6 @@ struct _TerminalApp
GtkWidget *manage_profiles_delete_button; GtkWidget *manage_profiles_delete_button;
GtkWidget *manage_profiles_default_menu; GtkWidget *manage_profiles_default_menu;
GSettings *settings_global;
GSettings *settings_font; GSettings *settings_font;
GHashTable *profiles; GHashTable *profiles;
@ -360,8 +359,7 @@ terminal_app_create_profile (TerminalApp *app,
} }
static void static void
terminal_app_delete_profile (TerminalApp *app, terminal_app_delete_profile (TerminalProfile *profile)
TerminalProfile *profile)
{ {
const char *profile_name; const char *profile_name;
char *profile_dir; char *profile_dir;
@ -370,7 +368,7 @@ terminal_app_delete_profile (TerminalApp *app,
profile_name = terminal_profile_get_property_string (profile, TERMINAL_PROFILE_NAME); profile_name = terminal_profile_get_property_string (profile, TERMINAL_PROFILE_NAME);
profile_dir = g_strconcat (CONF_PROFILE_PREFIX, profile_name, "/", NULL); profile_dir = g_strconcat (CONF_PROFILE_PREFIX, profile_name, "/", NULL);
gsettings_remove_all_from_strv (app->settings_global, PROFILE_LIST_KEY, profile_name); gsettings_remove_all_from_strv (settings_global, PROFILE_LIST_KEY, profile_name);
/* And remove the profile directory */ /* And remove the profile directory */
DConfClient *client = dconf_client_new (); DConfClient *client = dconf_client_new ();
@ -548,7 +546,7 @@ profile_combo_box_changed_cb (GtkWidget *widget,
if (!profile) if (!profile)
return; return;
g_settings_set_string (app->settings_global, DEFAULT_PROFILE_KEY, g_settings_set_string (settings_global, DEFAULT_PROFILE_KEY,
terminal_profile_get_property_string (profile, TERMINAL_PROFILE_NAME)); terminal_profile_get_property_string (profile, TERMINAL_PROFILE_NAME));
/* Even though the GSettings change notification does this, it happens too late. /* Even though the GSettings change notification does this, it happens too late.
@ -626,8 +624,7 @@ profile_list_treeview_create (TerminalApp *app)
static void static void
profile_list_delete_confirm_response_cb (GtkWidget *dialog, profile_list_delete_confirm_response_cb (GtkWidget *dialog,
int response, int response)
TerminalApp *app)
{ {
TerminalProfile *profile; TerminalProfile *profile;
@ -635,7 +632,7 @@ profile_list_delete_confirm_response_cb (GtkWidget *dialog,
g_assert (profile != NULL); g_assert (profile != NULL);
if (response == GTK_RESPONSE_ACCEPT) if (response == GTK_RESPONSE_ACCEPT)
terminal_app_delete_profile (app, profile); terminal_app_delete_profile (profile);
gtk_widget_destroy (dialog); gtk_widget_destroy (dialog);
} }
@ -663,7 +660,6 @@ profile_list_delete_button_clicked_cb (GtkWidget *button,
GtkWidget *widget) GtkWidget *widget)
{ {
GtkTreeView *tree_view = GTK_TREE_VIEW (widget); GtkTreeView *tree_view = GTK_TREE_VIEW (widget);
TerminalApp *app = terminal_app_get ();
GtkTreeSelection *selection; GtkTreeSelection *selection;
GtkWidget *dialog; GtkWidget *dialog;
GtkTreeIter iter; GtkTreeIter iter;
@ -708,7 +704,7 @@ profile_list_delete_button_clicked_cb (GtkWidget *button,
g_signal_connect (dialog, "response", g_signal_connect (dialog, "response",
G_CALLBACK (profile_list_delete_confirm_response_cb), G_CALLBACK (profile_list_delete_confirm_response_cb),
app); NULL);
gtk_window_present (GTK_WINDOW (dialog)); gtk_window_present (GTK_WINDOW (dialog));
} }
@ -1165,7 +1161,7 @@ new_profile_response_cb (GtkWidget *new_profile_dialog,
new_profile /* adopts the refcount */); new_profile /* adopts the refcount */);
/* And now save the new profile name to GSettings */ /* And now save the new profile name to GSettings */
gsettings_append_strv (app->settings_global, gsettings_append_strv (settings_global,
PROFILE_LIST_KEY, PROFILE_LIST_KEY,
new_profile_name); new_profile_name);
@ -1412,20 +1408,20 @@ terminal_app_init (TerminalApp *app)
app->encodings = terminal_encodings_get_builtins (); app->encodings = terminal_encodings_get_builtins ();
app->settings_global = g_settings_new (CONF_GLOBAL_SCHEMA); settings_global = g_settings_new (CONF_GLOBAL_SCHEMA);
app->settings_font = g_settings_new (MONOSPACE_FONT_SCHEMA); app->settings_font = g_settings_new (MONOSPACE_FONT_SCHEMA);
g_signal_connect (app->settings_global, g_signal_connect (settings_global,
"changed::" PROFILE_LIST_KEY, "changed::" PROFILE_LIST_KEY,
G_CALLBACK(terminal_app_profile_list_notify_cb), G_CALLBACK(terminal_app_profile_list_notify_cb),
app); app);
g_signal_connect (app->settings_global, g_signal_connect (settings_global,
"changed::" DEFAULT_PROFILE_KEY, "changed::" DEFAULT_PROFILE_KEY,
G_CALLBACK(terminal_app_default_profile_notify_cb), G_CALLBACK(terminal_app_default_profile_notify_cb),
app); app);
g_signal_connect (app->settings_global, g_signal_connect (settings_global,
"changed::" ENCODING_LIST_KEY, "changed::" ENCODING_LIST_KEY,
G_CALLBACK(terminal_app_encoding_list_notify_cb), G_CALLBACK(terminal_app_encoding_list_notify_cb),
app); app);
@ -1436,33 +1432,33 @@ terminal_app_init (TerminalApp *app)
app); app);
g_signal_connect (app->settings_global, g_signal_connect (settings_global,
"changed::" ENABLE_MNEMONICS_KEY, "changed::" ENABLE_MNEMONICS_KEY,
G_CALLBACK(terminal_app_enable_mnemonics_notify_cb), G_CALLBACK(terminal_app_enable_mnemonics_notify_cb),
app); app);
g_signal_connect (app->settings_global, g_signal_connect (settings_global,
"changed::" ENABLE_MENU_BAR_ACCEL_KEY, "changed::" ENABLE_MENU_BAR_ACCEL_KEY,
G_CALLBACK(terminal_app_enable_menu_accels_notify_cb), G_CALLBACK(terminal_app_enable_menu_accels_notify_cb),
app); app);
/* Load the settings */ /* Load the settings */
terminal_app_profile_list_notify_cb (app->settings_global, terminal_app_profile_list_notify_cb (settings_global,
PROFILE_LIST_KEY, PROFILE_LIST_KEY,
app); app);
terminal_app_default_profile_notify_cb (app->settings_global, terminal_app_default_profile_notify_cb (settings_global,
DEFAULT_PROFILE_KEY, DEFAULT_PROFILE_KEY,
app); app);
terminal_app_encoding_list_notify_cb (app->settings_global, terminal_app_encoding_list_notify_cb (settings_global,
ENCODING_LIST_KEY, ENCODING_LIST_KEY,
app); app);
terminal_app_system_font_notify_cb (app->settings_font, terminal_app_system_font_notify_cb (app->settings_font,
MONOSPACE_FONT_KEY, MONOSPACE_FONT_KEY,
app); app);
terminal_app_enable_menu_accels_notify_cb (app->settings_global, terminal_app_enable_menu_accels_notify_cb (settings_global,
ENABLE_MENU_BAR_ACCEL_KEY, ENABLE_MENU_BAR_ACCEL_KEY,
app); app);
terminal_app_enable_mnemonics_notify_cb (app->settings_global, terminal_app_enable_mnemonics_notify_cb (settings_global,
ENABLE_MNEMONICS_KEY, ENABLE_MNEMONICS_KEY,
app); app);
@ -1500,26 +1496,26 @@ terminal_app_finalize (GObject *object)
g_signal_handlers_disconnect_matched (sm_client, G_SIGNAL_MATCH_DATA, g_signal_handlers_disconnect_matched (sm_client, G_SIGNAL_MATCH_DATA,
0, 0, NULL, NULL, app); 0, 0, NULL, NULL, app);
g_signal_handlers_disconnect_by_func (app->settings_global, g_signal_handlers_disconnect_by_func (settings_global,
G_CALLBACK(terminal_app_profile_list_notify_cb), G_CALLBACK(terminal_app_profile_list_notify_cb),
app); app);
g_signal_handlers_disconnect_by_func (app->settings_global, g_signal_handlers_disconnect_by_func (settings_global,
G_CALLBACK(terminal_app_default_profile_notify_cb), G_CALLBACK(terminal_app_default_profile_notify_cb),
app); app);
g_signal_handlers_disconnect_by_func (app->settings_global, g_signal_handlers_disconnect_by_func (settings_global,
G_CALLBACK(terminal_app_encoding_list_notify_cb), G_CALLBACK(terminal_app_encoding_list_notify_cb),
app); app);
g_signal_handlers_disconnect_by_func (app->settings_font, g_signal_handlers_disconnect_by_func (app->settings_font,
G_CALLBACK(terminal_app_system_font_notify_cb), G_CALLBACK(terminal_app_system_font_notify_cb),
app); app);
g_signal_handlers_disconnect_by_func (app->settings_global, g_signal_handlers_disconnect_by_func (settings_global,
G_CALLBACK(terminal_app_enable_menu_accels_notify_cb), G_CALLBACK(terminal_app_enable_menu_accels_notify_cb),
app); app);
g_signal_handlers_disconnect_by_func (app->settings_global, g_signal_handlers_disconnect_by_func (settings_global,
G_CALLBACK(terminal_app_enable_mnemonics_notify_cb), G_CALLBACK(terminal_app_enable_mnemonics_notify_cb),
app); app);
g_object_unref (app->settings_global); g_object_unref (settings_global);
g_object_unref (app->settings_font); g_object_unref (app->settings_font);
g_free (app->default_profile_id); g_free (app->default_profile_id);
@ -1580,11 +1576,11 @@ terminal_app_set_property (GObject *object,
{ {
case PROP_ENABLE_MENU_BAR_ACCEL: case PROP_ENABLE_MENU_BAR_ACCEL:
app->enable_menu_accels = g_value_get_boolean (value); app->enable_menu_accels = g_value_get_boolean (value);
g_settings_set_boolean (app->settings_global, ENABLE_MENU_BAR_ACCEL_KEY, app->enable_menu_accels); g_settings_set_boolean (settings_global, ENABLE_MENU_BAR_ACCEL_KEY, app->enable_menu_accels);
break; break;
case PROP_ENABLE_MNEMONICS: case PROP_ENABLE_MNEMONICS:
app->enable_mnemonics = g_value_get_boolean (value); app->enable_mnemonics = g_value_get_boolean (value);
g_settings_set_boolean (app->settings_global, ENABLE_MNEMONICS_KEY, app->enable_mnemonics); g_settings_set_boolean (settings_global, ENABLE_MNEMONICS_KEY, app->enable_mnemonics);
break; break;
case PROP_DEFAULT_PROFILE: case PROP_DEFAULT_PROFILE:
case PROP_SYSTEM_FONT: case PROP_SYSTEM_FONT:

View File

@ -83,6 +83,8 @@ G_BEGIN_DECLS
typedef struct _TerminalAppClass TerminalAppClass; typedef struct _TerminalAppClass TerminalAppClass;
typedef struct _TerminalApp TerminalApp; typedef struct _TerminalApp TerminalApp;
GSettings *settings_global;
GType terminal_app_get_type (void); GType terminal_app_get_type (void);
TerminalApp* terminal_app_get (void); TerminalApp* terminal_app_get (void);

View File

@ -52,8 +52,6 @@ struct _TerminalWindowPrivate
GtkUIManager *ui_manager; GtkUIManager *ui_manager;
guint ui_id; guint ui_id;
GSettings *global_settings;
GtkActionGroup *profiles_action_group; GtkActionGroup *profiles_action_group;
guint profiles_ui_id; guint profiles_ui_id;
@ -2210,8 +2208,6 @@ terminal_window_init (TerminalWindow *window)
GtkStyleContext *context; GtkStyleContext *context;
priv->global_settings = g_settings_new (CONF_GLOBAL_SCHEMA);
context = gtk_widget_get_style_context (GTK_WIDGET (window)); context = gtk_widget_get_style_context (GTK_WIDGET (window));
gtk_style_context_add_class (context, "mate-terminal"); gtk_style_context_add_class (context, "mate-terminal");
@ -2230,9 +2226,9 @@ terminal_window_init (TerminalWindow *window)
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE); gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE);
gtk_notebook_set_group_name (GTK_NOTEBOOK (priv->notebook), I_("mate-terminal-window")); gtk_notebook_set_group_name (GTK_NOTEBOOK (priv->notebook), I_("mate-terminal-window"));
g_signal_connect (priv->notebook, "button-press-event", g_signal_connect (priv->notebook, "button-press-event",
G_CALLBACK (notebook_button_press_cb), priv->global_settings); G_CALLBACK (notebook_button_press_cb), settings_global);
g_signal_connect (window, "key-press-event", g_signal_connect (window, "key-press-event",
G_CALLBACK (window_key_press_cb), priv->global_settings); G_CALLBACK (window_key_press_cb), settings_global);
g_signal_connect (priv->notebook, "popup-menu", g_signal_connect (priv->notebook, "popup-menu",
G_CALLBACK (notebook_popup_menu_cb), window); G_CALLBACK (notebook_popup_menu_cb), window);
g_signal_connect_after (priv->notebook, "switch-page", g_signal_connect_after (priv->notebook, "switch-page",
@ -2417,7 +2413,6 @@ terminal_window_finalize (GObject *object)
TerminalWindowPrivate *priv = window->priv; TerminalWindowPrivate *priv = window->priv;
g_object_unref (priv->ui_manager); g_object_unref (priv->ui_manager);
g_object_unref (priv->global_settings);
if (priv->confirm_close_dialog) if (priv->confirm_close_dialog)
gtk_dialog_response (GTK_DIALOG (priv->confirm_close_dialog), gtk_dialog_response (GTK_DIALOG (priv->confirm_close_dialog),
@ -3585,7 +3580,7 @@ confirm_close_window_or_tab (TerminalWindow *window,
GTK_RESPONSE_DELETE_EVENT); GTK_RESPONSE_DELETE_EVENT);
} }
do_confirm = g_settings_get_boolean (priv->global_settings, "confirm-window-close"); do_confirm = g_settings_get_boolean (settings_global, "confirm-window-close");
if (!do_confirm) if (!do_confirm)
return FALSE; return FALSE;