[Xfce4-commits] [apps/mousepad] 01/01: Add mousepad_setting_connect_object()
noreply at xfce.org
noreply at xfce.org
Sun Jul 13 05:51:37 CEST 2014
This is an automated email from the git hooks/post-receive script.
mbrush pushed a commit to branch master
in repository apps/mousepad.
commit f715e3d5f68764a615619dfdac066afe830eed4e
Author: Matthew Brush <mbrush at codebrainz.ca>
Date: Sat Jul 12 20:48:47 2014 -0700
Add mousepad_setting_connect_object()
So we don't have to manually disconnect all of the GSettings signals
since we always pass a GObject as user_data anyway.
---
mousepad/mousepad-prefs-dialog.c | 62 +++++-----------
mousepad/mousepad-settings.c | 34 +++++++++
mousepad/mousepad-settings.h | 68 +++++++++--------
mousepad/mousepad-view.c | 15 +---
mousepad/mousepad-window.c | 150 +++++++++++++-------------------------
5 files changed, 148 insertions(+), 181 deletions(-)
diff --git a/mousepad/mousepad-prefs-dialog.c b/mousepad/mousepad-prefs-dialog.c
index 19fa080..ed3a309 100644
--- a/mousepad/mousepad-prefs-dialog.c
+++ b/mousepad/mousepad-prefs-dialog.c
@@ -57,11 +57,6 @@ struct MousepadPrefsDialog_
GtkDialog parent;
GtkBuilder *builder;
gboolean blocked;
- gulong color_scheme_signal;
- gulong tab_mode_signal;
- gulong home_end_signal;
- gulong toolbar_style_signal;
- gulong toolbar_icon_size_signal;
};
struct MousepadPrefsDialogClass_
@@ -100,18 +95,6 @@ mousepad_prefs_dialog_finalize (GObject *object)
self = MOUSEPAD_PREFS_DIALOG (object);
- /* disconnect the "changed" signals from the settings that we connected manually */
- if (self->color_scheme_signal > 0)
- MOUSEPAD_SETTING_DISCONNECT (COLOR_SCHEME, self->color_scheme_signal);
- if (self->tab_mode_signal > 0)
- MOUSEPAD_SETTING_DISCONNECT (INSERT_SPACES, self->tab_mode_signal);
- if (self->home_end_signal > 0)
- MOUSEPAD_SETTING_DISCONNECT (SMART_HOME_END, self->home_end_signal);
- if (self->toolbar_style_signal > 0)
- MOUSEPAD_SETTING_DISCONNECT (TOOLBAR_STYLE, self->toolbar_style_signal);
- if (self->toolbar_icon_size_signal > 0)
- MOUSEPAD_SETTING_DISCONNECT (TOOLBAR_ICON_SIZE, self->toolbar_icon_size_signal);
-
/* destroy the GtkBuilder instance */
if (G_IS_OBJECT (self->builder))
g_object_unref (self->builder);
@@ -224,11 +207,10 @@ mousepad_prefs_dialog_setup_color_schemes_combo (MousepadPrefsDialog *self)
G_CALLBACK (mousepad_prefs_dialog_color_scheme_changed),
self);
- self->color_scheme_signal =
- MOUSEPAD_SETTING_CONNECT (COLOR_SCHEME,
- G_CALLBACK (mousepad_prefs_dialog_color_scheme_setting_changed),
- self,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT_OBJECT (COLOR_SCHEME,
+ G_CALLBACK (mousepad_prefs_dialog_color_scheme_setting_changed),
+ self,
+ G_CONNECT_SWAPPED);
}
@@ -518,11 +500,10 @@ mousepad_prefs_dialog_init (MousepadPrefsDialog *self)
self);
/* update tab mode combo when setting changes */
- self->tab_mode_signal =
- MOUSEPAD_SETTING_CONNECT (INSERT_SPACES,
- G_CALLBACK (mousepad_prefs_dialog_tab_mode_setting_changed),
- self,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT_OBJECT (INSERT_SPACES,
+ G_CALLBACK (mousepad_prefs_dialog_tab_mode_setting_changed),
+ self,
+ G_CONNECT_SWAPPED);
/* update home/end when changed */
g_signal_connect_swapped (gtk_builder_get_object (self->builder, WID_SMART_HOME_END_COMBO),
@@ -531,11 +512,10 @@ mousepad_prefs_dialog_init (MousepadPrefsDialog *self)
self);
/* update home/end combo when setting changes */
- self->home_end_signal =
- MOUSEPAD_SETTING_CONNECT (SMART_HOME_END,
- G_CALLBACK (mousepad_prefs_dialog_home_end_setting_changed),
- self,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT_OBJECT (SMART_HOME_END,
+ G_CALLBACK (mousepad_prefs_dialog_home_end_setting_changed),
+ self,
+ G_CONNECT_SWAPPED);
/* update toolbar style when changed */
g_signal_connect_swapped (gtk_builder_get_object (self->builder, WID_TOOLBAR_STYLE_COMBO),
@@ -544,11 +524,10 @@ mousepad_prefs_dialog_init (MousepadPrefsDialog *self)
self);
/* update toolbar style combo when the setting changes */
- self->toolbar_style_signal =
- MOUSEPAD_SETTING_CONNECT (TOOLBAR_STYLE,
- G_CALLBACK (mousepad_prefs_dialog_toolbar_style_setting_changed),
- self,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT_OBJECT (TOOLBAR_STYLE,
+ G_CALLBACK (mousepad_prefs_dialog_toolbar_style_setting_changed),
+ self,
+ G_CONNECT_SWAPPED);
/* update toolbar icon size when changed */
g_signal_connect_swapped (gtk_builder_get_object (self->builder, WID_TOOLBAR_ICON_SIZE_COMBO),
@@ -557,11 +536,10 @@ mousepad_prefs_dialog_init (MousepadPrefsDialog *self)
self);
/* update toolbar icon size combo when setting changes */
- self->toolbar_icon_size_signal =
- MOUSEPAD_SETTING_CONNECT (TOOLBAR_ICON_SIZE,
- G_CALLBACK (mousepad_prefs_dialog_toolbar_icon_size_setting_changed),
- self,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT_OBJECT (TOOLBAR_ICON_SIZE,
+ G_CALLBACK (mousepad_prefs_dialog_toolbar_icon_size_setting_changed),
+ self,
+ G_CONNECT_SWAPPED);
}
diff --git a/mousepad/mousepad-settings.c b/mousepad/mousepad-settings.c
index 2fe9939..6d28b8e 100644
--- a/mousepad/mousepad-settings.c
+++ b/mousepad/mousepad-settings.c
@@ -103,6 +103,40 @@ mousepad_setting_connect (const gchar *path,
+gulong
+mousepad_setting_connect_object (const gchar *path,
+ GCallback callback,
+ gpointer gobject,
+ GConnectFlags connect_flags)
+{
+ gulong signal_id = 0;
+ const gchar *key_name = NULL;
+ GSettings *settings = NULL;
+
+ g_return_val_if_fail (path != NULL, 0);
+ g_return_val_if_fail (callback != NULL, 0);
+ g_return_val_if_fail (G_IS_OBJECT (gobject), 0);
+
+ if (mousepad_settings_store_lookup (settings_store, path, &key_name, &settings))
+ {
+ gchar *signal_name;
+
+ signal_name = g_strdup_printf ("changed::%s", key_name);
+
+ signal_id = g_signal_connect_object (settings,
+ signal_name,
+ callback,
+ gobject,
+ connect_flags);
+
+ g_free (signal_name);
+ }
+
+ return signal_id;
+}
+
+
+
void
mousepad_setting_disconnect (const gchar *path,
gulong handler_id)
diff --git a/mousepad/mousepad-settings.h b/mousepad/mousepad-settings.h
index 725ce97..a30cc69 100644
--- a/mousepad/mousepad-settings.h
+++ b/mousepad/mousepad-settings.h
@@ -55,53 +55,58 @@ G_BEGIN_DECLS
#define MOUSEPAD_SETTING_WINDOW_MAXIMIZED "/state/window/maximized"
#define MOUSEPAD_SETTING_WINDOW_FULLSCREEN "/state/window/fullscreen"
-void mousepad_settings_init (void);
-void mousepad_settings_finalize (void);
+void mousepad_settings_init (void);
+void mousepad_settings_finalize (void);
-gboolean mousepad_setting_bind (const gchar *path,
- gpointer object,
- const gchar *prop,
- GSettingsBindFlags flags);
+gboolean mousepad_setting_bind (const gchar *path,
+ gpointer object,
+ const gchar *prop,
+ GSettingsBindFlags flags);
-gulong mousepad_setting_connect (const gchar *path,
- GCallback callback,
- gpointer user_data,
- GSignalFlags connect_flags);
+gulong mousepad_setting_connect (const gchar *path,
+ GCallback callback,
+ gpointer user_data,
+ GSignalFlags connect_flags);
-void mousepad_setting_disconnect (const gchar *path,
- gulong handler_id);
+gulong mousepad_setting_connect_object (const gchar *path,
+ GCallback callback,
+ gpointer gobject,
+ GConnectFlags connect_flags);
+
+void mousepad_setting_disconnect (const gchar *path,
+ gulong handler_id);
/* functions for reading and writing settings */
-gboolean mousepad_setting_get (const gchar *path,
- const gchar *format_string,
- ...);
+gboolean mousepad_setting_get (const gchar *path,
+ const gchar *format_string,
+ ...);
-gboolean mousepad_setting_set (const gchar *path,
- const gchar *format_string,
- ...);
+gboolean mousepad_setting_set (const gchar *path,
+ const gchar *format_string,
+ ...);
/* convenience functions for reading/writing common types */
-gboolean mousepad_setting_get_boolean (const gchar *path);
+gboolean mousepad_setting_get_boolean (const gchar *path);
-void mousepad_setting_set_boolean (const gchar *path,
- gboolean value);
+void mousepad_setting_set_boolean (const gchar *path,
+ gboolean value);
-gint mousepad_setting_get_int (const gchar *path);
+gint mousepad_setting_get_int (const gchar *path);
-void mousepad_setting_set_int (const gchar *path,
- gint value);
+void mousepad_setting_set_int (const gchar *path,
+ gint value);
-gchar *mousepad_setting_get_string (const gchar *path);
+gchar *mousepad_setting_get_string (const gchar *path);
-void mousepad_setting_set_string (const gchar *path,
- const gchar *value);
+void mousepad_setting_set_string (const gchar *path,
+ const gchar *value);
-gint mousepad_setting_get_enum (const gchar *path);
+gint mousepad_setting_get_enum (const gchar *path);
-void mousepad_setting_set_enum (const gchar *path,
- gint value);
+void mousepad_setting_set_enum (const gchar *path,
+ gint value);
/* wrappers for above read/write functions with shorter arguments */
@@ -111,6 +116,9 @@ void mousepad_setting_set_enum (const gchar *path,
#define MOUSEPAD_SETTING_CONNECT(setting, callback, user_data, connect_flags) \
mousepad_setting_connect (MOUSEPAD_SETTING_##setting, callback, user_data, connect_flags)
+#define MOUSEPAD_SETTING_CONNECT_OBJECT(setting, callback, object, connect_flags) \
+ mousepad_setting_connect_object (MOUSEPAD_SETTING_##setting, callback, object, connect_flags)
+
#define MOUSEPAD_SETTING_DISCONNECT(setting, id) \
mousepad_setting_disconnect (MOUSEPAD_SETTING_##setting, id)
diff --git a/mousepad/mousepad-view.c b/mousepad/mousepad-view.c
index 1bc35f7..d6739d2 100644
--- a/mousepad/mousepad-view.c
+++ b/mousepad/mousepad-view.c
@@ -126,7 +126,6 @@ struct _MousepadView
/* the font used in the view */
gchar *font_name;
PangoFontDescription *font_desc;
- gulong font_handler;
/* whitespace visualization */
gboolean show_whitespace;
@@ -277,7 +276,6 @@ mousepad_view_init (MousepadView *view)
view->color_scheme = g_strdup ("none");
view->font_name = NULL;
view->font_desc = NULL;
- view->font_handler = 0;
view->match_braces = FALSE;
/* make sure any buffers set on the view get the color scheme applied to them */
@@ -316,11 +314,10 @@ mousepad_view_init (MousepadView *view)
BIND_ (MATCH_BRACES, "match-braces");
/* override with default font when the setting is enabled */
- view->font_handler =
- MOUSEPAD_SETTING_CONNECT (USE_DEFAULT_FONT,
- G_CALLBACK (mousepad_view_use_default_font_setting_changed),
- view,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT_OBJECT (USE_DEFAULT_FONT,
+ G_CALLBACK (mousepad_view_use_default_font_setting_changed),
+ view,
+ G_CONNECT_SWAPPED);
#undef BIND_
}
@@ -336,10 +333,6 @@ mousepad_view_finalize (GObject *object)
if (G_UNLIKELY (view->selection_timeout_id != 0))
g_source_remove (view->selection_timeout_id);
- /* disconnect the settings changed callback */
- if (view->font_handler > 0)
- MOUSEPAD_SETTING_DISCONNECT (FONT_NAME, view->font_handler);
-
/* free the selection marks list (marks are owned by the buffer) */
if (G_UNLIKELY (view->selection_marks != NULL))
g_slist_free (view->selection_marks);
diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c
index 7e68b1f..8c16ef9 100644
--- a/mousepad/mousepad-window.c
+++ b/mousepad/mousepad-window.c
@@ -406,21 +406,6 @@ struct _MousepadWindow
/* idle update functions for the recent and go menu */
guint update_recent_menu_id;
guint update_go_menu_id;
-
- /* settings signal handler ids that must be disconnected on destruction */
- gulong menubar_visible_id;
- gulong menubar_visible_fs_id;
- gulong toolbar_visible_id;
- gulong toolbar_visible_fs_id;
- gulong toolbar_style_id;
- gulong toolbar_icon_size_id;
- gulong tab_width_id;
- gulong insert_spaces_id;
- gulong statusbar_visible_id;
- gulong statusbar_visible_fs_id;
- gulong path_in_title_id;
- gulong always_show_tabs_id;
- gulong recent_menu_items_id;
};
@@ -717,17 +702,15 @@ mousepad_window_create_menubar (MousepadWindow *window)
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), active);
gtk_widget_set_visible (window->menubar, active);
- window->menubar_visible_id =
- MOUSEPAD_SETTING_CONNECT (MENUBAR_VISIBLE,
- G_CALLBACK (mousepad_window_update_main_widgets),
- window,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT_OBJECT (MENUBAR_VISIBLE,
+ G_CALLBACK (mousepad_window_update_main_widgets),
+ window,
+ G_CONNECT_SWAPPED);
- window->menubar_visible_fs_id =
- MOUSEPAD_SETTING_CONNECT (MENUBAR_VISIBLE_FULLSCREEN,
- G_CALLBACK (mousepad_window_update_main_widgets),
- window,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT_OBJECT (MENUBAR_VISIBLE_FULLSCREEN,
+ G_CALLBACK (mousepad_window_update_main_widgets),
+ window,
+ G_CONNECT_SWAPPED);
}
@@ -763,29 +746,25 @@ mousepad_window_create_toolbar (MousepadWindow *window)
mousepad_window_update_toolbar (window, NULL, NULL);
/* connect to some signals to keep in sync */
- window->toolbar_visible_id =
- MOUSEPAD_SETTING_CONNECT (TOOLBAR_VISIBLE,
- G_CALLBACK (mousepad_window_update_toolbar),
- window,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT_OBJECT (TOOLBAR_VISIBLE,
+ G_CALLBACK (mousepad_window_update_toolbar),
+ window,
+ G_CONNECT_SWAPPED);
- window->toolbar_visible_fs_id =
- MOUSEPAD_SETTING_CONNECT (TOOLBAR_VISIBLE_FULLSCREEN,
- G_CALLBACK (mousepad_window_update_main_widgets),
- window,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT_OBJECT (TOOLBAR_VISIBLE_FULLSCREEN,
+ G_CALLBACK (mousepad_window_update_main_widgets),
+ window,
+ G_CONNECT_SWAPPED);
- window->toolbar_style_id =
- MOUSEPAD_SETTING_CONNECT (TOOLBAR_STYLE,
- G_CALLBACK (mousepad_window_update_toolbar),
- window,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT_OBJECT (TOOLBAR_STYLE,
+ G_CALLBACK (mousepad_window_update_toolbar),
+ window,
+ G_CONNECT_SWAPPED);
- window->toolbar_icon_size_id =
- MOUSEPAD_SETTING_CONNECT (TOOLBAR_ICON_SIZE,
- G_CALLBACK (mousepad_window_update_toolbar),
- window,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT_OBJECT (TOOLBAR_ICON_SIZE,
+ G_CALLBACK (mousepad_window_update_toolbar),
+ window,
+ G_CONNECT_SWAPPED);
}
@@ -901,29 +880,25 @@ mousepad_window_create_statusbar (MousepadWindow *window)
mousepad_document_send_signals (window->active);
/* update the statusbar with certain settings */
- window->tab_width_id =
- MOUSEPAD_SETTING_CONNECT (TAB_WIDTH,
- G_CALLBACK (mousepad_window_update_statusbar_settings),
- window,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT_OBJECT (TAB_WIDTH,
+ G_CALLBACK (mousepad_window_update_statusbar_settings),
+ window,
+ G_CONNECT_SWAPPED);
- window->insert_spaces_id =
- MOUSEPAD_SETTING_CONNECT (INSERT_SPACES,
- G_CALLBACK (mousepad_window_update_statusbar_settings),
- window,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT_OBJECT (INSERT_SPACES,
+ G_CALLBACK (mousepad_window_update_statusbar_settings),
+ window,
+ G_CONNECT_SWAPPED);
- window->statusbar_visible_id =
- MOUSEPAD_SETTING_CONNECT (STATUSBAR_VISIBLE,
- G_CALLBACK (mousepad_window_update_main_widgets),
- window,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT_OBJECT (STATUSBAR_VISIBLE,
+ G_CALLBACK (mousepad_window_update_main_widgets),
+ window,
+ G_CONNECT_SWAPPED);
- window->statusbar_visible_fs_id =
- MOUSEPAD_SETTING_CONNECT (STATUSBAR_VISIBLE_FULLSCREEN,
- G_CALLBACK (mousepad_window_update_main_widgets),
- window,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT_OBJECT (STATUSBAR_VISIBLE_FULLSCREEN,
+ G_CALLBACK (mousepad_window_update_main_widgets),
+ window,
+ G_CONNECT_SWAPPED);
}
@@ -1032,25 +1007,22 @@ mousepad_window_init (MousepadWindow *window)
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
/* update the window title when 'path-in-title' setting changes */
- window->path_in_title_id =
- MOUSEPAD_SETTING_CONNECT (PATH_IN_TITLE,
- G_CALLBACK (mousepad_window_update_window_title),
- window,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT_OBJECT (PATH_IN_TITLE,
+ G_CALLBACK (mousepad_window_update_window_title),
+ window,
+ G_CONNECT_SWAPPED);
/* update the tabs when 'always-show-tabs' setting changes */
- window->always_show_tabs_id =
- MOUSEPAD_SETTING_CONNECT (ALWAYS_SHOW_TABS,
- G_CALLBACK (mousepad_window_update_tabs),
- window,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT_OBJECT (ALWAYS_SHOW_TABS,
+ G_CALLBACK (mousepad_window_update_tabs),
+ window,
+ G_CONNECT_SWAPPED);
/* update the recent items menu when 'window-recent-menu-items' setting changes */
- window->recent_menu_items_id =
- MOUSEPAD_SETTING_CONNECT (RECENT_MENU_ITEMS,
- G_CALLBACK (mousepad_window_update_recent_menu),
- window,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT_OBJECT (RECENT_MENU_ITEMS,
+ G_CALLBACK (mousepad_window_update_recent_menu),
+ window,
+ G_CONNECT_SWAPPED);
}
@@ -1078,24 +1050,6 @@ mousepad_window_finalize (GObject *object)
{
MousepadWindow *window = MOUSEPAD_WINDOW (object);
- /* disconnect settings callbacks since settings lives longer than the window */
-# define DISCONNECT_(setting, lower) \
- MOUSEPAD_SETTING_DISCONNECT (setting, window->lower##_id)
- DISCONNECT_ (MENUBAR_VISIBLE, menubar_visible);
- DISCONNECT_ (MENUBAR_VISIBLE_FULLSCREEN, menubar_visible_fs);
- DISCONNECT_ (TOOLBAR_VISIBLE, toolbar_visible);
- DISCONNECT_ (TOOLBAR_VISIBLE_FULLSCREEN, toolbar_visible_fs);
- DISCONNECT_ (TOOLBAR_STYLE, toolbar_style);
- DISCONNECT_ (TOOLBAR_ICON_SIZE, toolbar_icon_size);
- DISCONNECT_ (TAB_WIDTH, tab_width);
- DISCONNECT_ (INSERT_SPACES, insert_spaces);
- DISCONNECT_ (STATUSBAR_VISIBLE, statusbar_visible);
- DISCONNECT_ (STATUSBAR_VISIBLE_FULLSCREEN, statusbar_visible_fs);
- DISCONNECT_ (PATH_IN_TITLE, path_in_title);
- DISCONNECT_ (ALWAYS_SHOW_TABS, always_show_tabs);
- DISCONNECT_ (RECENT_MENU_ITEMS, recent_menu_items);
-# undef DISCONNECT_
-
/* decrease history clipboard ref count */
clipboard_history_ref_count--;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list