[Xfce4-commits] [apps/mousepad] 26/45: Add helper function mousepad_settings_connect_changed()

noreply at xfce.org noreply at xfce.org
Fri Jul 11 13:03:31 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 c9b556327cd927b3e1c213b5989dc304d7424bd3
Author: Matthew Brush <mbrush at codebrainz.ca>
Date:   Mon Jul 7 03:21:18 2014 -0700

    Add helper function mousepad_settings_connect_changed()
    
    For connecting to GSettings change notifications in one of the
    various schemas. Also fix a missed "search-replace-all" string
    literal that didn't get updated in previous commit.
---
 mousepad/mousepad-replace-dialog.c |   17 +++++--------
 mousepad/mousepad-settings.c       |   35 +++++++++++++++++++++++++++
 mousepad/mousepad-settings.h       |    6 +++++
 mousepad/mousepad-window.c         |   46 ++++++++++++++++++++----------------
 4 files changed, 73 insertions(+), 31 deletions(-)

diff --git a/mousepad/mousepad-replace-dialog.c b/mousepad/mousepad-replace-dialog.c
index bac000f..acf57a2 100644
--- a/mousepad/mousepad-replace-dialog.c
+++ b/mousepad/mousepad-replace-dialog.c
@@ -124,20 +124,15 @@ mousepad_replace_dialog_bind_setting (MousepadReplaceDialog *dialog,
                                       gpointer               object,
                                       const gchar           *property)
 {
-  gchar *signal_name;
-
   mousepad_settings_bind (MOUSEPAD_SCHEMA_SEARCH_STATE, key,
                           object, property,
                           G_SETTINGS_BIND_DEFAULT);
 
-  signal_name = g_strdup_printf ("changed::%s", key);
-
-  g_signal_connect_swapped (MOUSEPAD_SEARCH_STATE_SETTINGS,
-                            signal_name,
-                            G_CALLBACK (mousepad_replace_dialog_settings_changed),
-                            dialog);
-
-  g_free (signal_name);
+  mousepad_settings_connect_changed (MOUSEPAD_SCHEMA_SEARCH_STATE,
+                                     key,
+                                     G_CALLBACK (mousepad_replace_dialog_settings_changed),
+                                     dialog,
+                                     G_CONNECT_SWAPPED);
 }
 
 
@@ -494,7 +489,7 @@ mousepad_replace_dialog_settings_changed (MousepadReplaceDialog *dialog,
                                           MousepadSettings      *settings)
 {
   /* reset occurences label */
-  if (g_strcmp0 (key, "search-replace-all") == 0)
+  if (g_strcmp0 (key, MOUSEPAD_STATE_SEARCH_REPLACE_ALL) == 0)
     gtk_label_set_text (GTK_LABEL (dialog->hits_label), NULL);
 
   mousepad_replace_dialog_changed (dialog);
diff --git a/mousepad/mousepad-settings.c b/mousepad/mousepad-settings.c
index 183bb96..f9fa270 100644
--- a/mousepad/mousepad-settings.c
+++ b/mousepad/mousepad-settings.c
@@ -231,6 +231,41 @@ mousepad_settings_bind (MousepadSchema     schema,
 
 
 
+gulong
+mousepad_settings_connect_changed (MousepadSchema     schema,
+                                   const gchar       *key,
+                                   GCallback          callback,
+                                   gpointer           user_data,
+                                   GSignalFlags       connect_flags)
+{
+  gulong            signal_id;
+  gchar            *signal_name;
+  MousepadSettings *settings;
+
+  g_return_val_if_fail (schema < MOUSEPAD_NUM_SCHEMAS, 0);
+  g_return_val_if_fail (callback != NULL, 0);
+
+  if (key != NULL)
+    signal_name = g_strdup_printf ("changed::%s", key);
+  else
+    signal_name = g_strdup ("changed");
+
+  settings = mousepad_settings_get_default ();
+
+  signal_id = g_signal_connect_data (settings->settings[schema],
+                                     signal_name,
+                                     callback,
+                                     user_data,
+                                     NULL,
+                                     connect_flags);
+
+  g_free (signal_name);
+
+  return signal_id;
+}
+
+
+
 gboolean
 mousepad_settings_get_boolean (MousepadSchema  schema,
                                const gchar    *key)
diff --git a/mousepad/mousepad-settings.h b/mousepad/mousepad-settings.h
index ac25be7..aeb311b 100644
--- a/mousepad/mousepad-settings.h
+++ b/mousepad/mousepad-settings.h
@@ -41,6 +41,12 @@ void              mousepad_settings_bind            (MousepadSchema     schema,
                                                      const gchar       *prop,
                                                      GSettingsBindFlags flags);
 
+gulong            mousepad_settings_connect_changed (MousepadSchema     schema,
+                                                     const gchar       *key,
+                                                     GCallback          callback,
+                                                     gpointer           user_data,
+                                                     GSignalFlags       connect_flags);
+
 gboolean          mousepad_settings_get_boolean     (MousepadSchema     schema,
                                                      const gchar       *key);
 
diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c
index 5ac4085..ac58320 100644
--- a/mousepad/mousepad-window.c
+++ b/mousepad/mousepad-window.c
@@ -752,32 +752,38 @@ mousepad_window_init (MousepadWindow *window)
   g_signal_connect (G_OBJECT (window), "drag-data-received", G_CALLBACK (mousepad_window_drag_data_received), window);
 
   /* update the statusbar with certain settings */
-  g_signal_connect_swapped (MOUSEPAD_VIEW_SETTINGS,
-                            "changed::" MOUSEPAD_SETTING_TAB_WIDTH,
-                            G_CALLBACK (mousepad_window_update_statusbar_settings),
-                            window);
-  g_signal_connect_swapped (MOUSEPAD_VIEW_SETTINGS,
-                            "changed::" MOUSEPAD_SETTING_INSERT_SPACES,
-                            G_CALLBACK (mousepad_window_update_statusbar_settings),
-                            window);
+  mousepad_settings_connect_changed (MOUSEPAD_SCHEMA_VIEW_SETTINGS,
+                                     MOUSEPAD_SETTING_TAB_WIDTH,
+                                     G_CALLBACK (mousepad_window_update_statusbar_settings),
+                                     window,
+                                     G_CONNECT_SWAPPED);
+
+  mousepad_settings_connect_changed (MOUSEPAD_SCHEMA_VIEW_SETTINGS,
+                                     MOUSEPAD_SETTING_INSERT_SPACES,
+                                     G_CALLBACK (mousepad_window_update_statusbar_settings),
+                                     window,
+                                     G_CONNECT_SWAPPED);
 
   /* update the window title when 'path-in-title' setting changes */
-  g_signal_connect_swapped (MOUSEPAD_WINDOW_SETTINGS,
-                            "changed::" MOUSEPAD_SETTING_PATH_IN_TITLE,
-                            G_CALLBACK (mousepad_window_update_window_title),
-                            window);
+  mousepad_settings_connect_changed (MOUSEPAD_SCHEMA_WINDOW_SETTINGS,
+                                     MOUSEPAD_SETTING_PATH_IN_TITLE,
+                                     G_CALLBACK (mousepad_window_update_window_title),
+                                     window,
+                                     G_CONNECT_SWAPPED);
 
   /* update the tabs when 'always-show-tabs' setting changes */
-  g_signal_connect_swapped (MOUSEPAD_WINDOW_SETTINGS,
-                            "changed::" MOUSEPAD_SETTING_ALWAYS_SHOW_TABS,
-                            G_CALLBACK (mousepad_window_update_tabs),
-                            window);
+  mousepad_settings_connect_changed (MOUSEPAD_SCHEMA_WINDOW_SETTINGS,
+                                     MOUSEPAD_SETTING_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 */
-  g_signal_connect_swapped (MOUSEPAD_WINDOW_SETTINGS,
-                            "changed::" MOUSEPAD_SETTING_RECENT_MENU_ITEMS,
-                            G_CALLBACK (mousepad_window_update_recent_menu),
-                            window);
+  mousepad_settings_connect_changed (MOUSEPAD_SCHEMA_WINDOW_SETTINGS,
+                                     MOUSEPAD_SETTING_RECENT_MENU_ITEMS,
+                                     G_CALLBACK (mousepad_window_update_recent_menu),
+                                     window,
+                                     G_CONNECT_SWAPPED);
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list