[dasher] Add DasherMain to DasherAppSettings



commit 8906e52191ce16ae4471dfddf3809119a17ece31
Author: Patrick Welche <prlw1 cam ac uk>
Date:   Sat Aug 20 16:15:26 2011 +0100

    Add DasherMain to DasherAppSettings
    
    e.g. on quit, dasher_main_finalize calls dasher_main_save_state,
    which stores some app settings. Unfortunately the app_settings_set_*
    calls then do
    
        // TODO: Use real signals to achieve this
        parameter_notification(0, iParameter, 0);
    
    which bounces around back in DasherMain. This is clearly an
    egregious hack, and this patch just applies a sticking plaster.

 Src/Gtk2/DasherAppSettings.cpp      |   17 +++++++++++++----
 Src/Gtk2/DasherAppSettings.h        |    6 ++++--
 Src/Gtk2/dasher_editor_internal.cpp |    4 +++-
 Src/Gtk2/dasher_main.cpp            |   11 ++++-------
 4 files changed, 24 insertions(+), 14 deletions(-)
---
diff --git a/Src/Gtk2/DasherAppSettings.cpp b/Src/Gtk2/DasherAppSettings.cpp
index e63ceb6..e691056 100644
--- a/Src/Gtk2/DasherAppSettings.cpp
+++ b/Src/Gtk2/DasherAppSettings.cpp
@@ -23,6 +23,10 @@
 #include "dasher.h"
 #include "GtkDasherControl.h"
 
+// XXX PRLW parameter_notification() should be squashed with prejudice
+typedef struct _DasherMain DasherMain;
+struct _DasherMain;
+
 // FIXME - should really do something to make this a singleton class
 
 // TODO: Rename this file to fit in with naming conventions
@@ -37,6 +41,9 @@ struct _DasherAppSettingsPrivate {
   GSettings *psettings;
 #endif
   GtkDasherControl *pDasherWidget;
+  // XXX PRLW nasty hack due to egregious
+  // parameter_notification (0 , iParameter, 0) calls
+  DasherMain *pDasherMain;
 };
 
 typedef struct _DasherAppSettingsPrivate DasherAppSettingsPrivate;
@@ -94,6 +101,7 @@ static void dasher_app_settings_init(DasherAppSettings *pDasherControl) {
   pPrivate->psettings = NULL;
 #endif
   pPrivate->pDasherWidget = NULL;
+  pPrivate->pDasherMain = NULL;
 }
 
 static void dasher_app_settings_destroy(GObject *pObject) {
@@ -228,7 +236,7 @@ static void dasher_app_settings_load(DasherAppSettings *pSelf) {
 
 // Public methods
 
-DasherAppSettings *dasher_app_settings_new(int argc, char **argv) {
+DasherAppSettings *dasher_app_settings_new(DasherMain *pDasherMain, int argc, char **argv) {
   DasherAppSettings *pNewAppSettings;
   pNewAppSettings = (DasherAppSettings *)(g_object_new(dasher_app_settings_get_type(), NULL));
   DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate*)(pNewAppSettings->private_data);
@@ -245,6 +253,7 @@ DasherAppSettings *dasher_app_settings_new(int argc, char **argv) {
 #ifdef WITH_GSETTINGS
   pPrivate->psettings = g_settings_new("org.gnome.Dasher");
 #endif
+  pPrivate->pDasherMain = pDasherMain;
   dasher_app_settings_load(pNewAppSettings);
 
   return pNewAppSettings;
@@ -275,7 +284,7 @@ void dasher_app_settings_reset(DasherAppSettings *pSelf, int iParameter) {
     }
   }
   // TODO: Use real signals to achieve this
-  parameter_notification(0, iParameter, 0);
+  parameter_notification(0, iParameter, pPrivate->pDasherMain);
 }
 
 bool dasher_app_settings_get_bool(DasherAppSettings *pSelf, int iParameter) { 
@@ -325,7 +334,7 @@ void dasher_app_settings_set_bool(DasherAppSettings *pSelf, int iParameter, bool
 #endif
 
     // TODO: Use real signals to achieve this
-    parameter_notification(0, iParameter, 0);
+    parameter_notification(0, iParameter, pPrivate->pDasherMain);
   }
 }
 
@@ -375,7 +384,7 @@ void dasher_app_settings_set_long(DasherAppSettings *pSelf, int iParameter, gint
 #endif
     
     // TODO: Use real signals to achieve this
-    parameter_notification(0, iParameter, 0);
+    parameter_notification(0, iParameter, pPrivate->pDasherMain);
   }
 }
 
diff --git a/Src/Gtk2/DasherAppSettings.h b/Src/Gtk2/DasherAppSettings.h
index bcee864..c1afaca 100644
--- a/Src/Gtk2/DasherAppSettings.h
+++ b/Src/Gtk2/DasherAppSettings.h
@@ -8,9 +8,11 @@
 #include "../Common/AppSettingsHeader.h"
 #include "../Common/ModuleSettings.h"
 
-/*Forward declaration*/
+// Forward declarations
 typedef struct _GtkDasherControl GtkDasherControl;
 struct _GtkDasherControl;
+typedef struct _DasherMain DasherMain;
+struct _DasherMain;
 
 // Define first int value of the first element of each type.
 // Useful for offsetting into specific arrays,
@@ -50,7 +52,7 @@ struct _DasherAppSettingsClass {
   GObjectClass parent_class;
 };
 
-DasherAppSettings *dasher_app_settings_new(int argc, char **argv);
+DasherAppSettings *dasher_app_settings_new(DasherMain *, int argc, char **argv);
 GType dasher_app_settings_get_type();
 
 void dasher_app_settings_reset(DasherAppSettings *pSelf, int iParameter);
diff --git a/Src/Gtk2/dasher_editor_internal.cpp b/Src/Gtk2/dasher_editor_internal.cpp
index 16e0d63..1313ab4 100644
--- a/Src/Gtk2/dasher_editor_internal.cpp
+++ b/Src/Gtk2/dasher_editor_internal.cpp
@@ -26,12 +26,15 @@ struct _DasherEditorInternalPrivate {
   DasherAppSettings *pAppSettings;
   gchar *szFilename;
   gboolean bFileModified; // TODO: Make this work properly, export to main for quit etc
+
+  // for conversion mode:
   GtkTextTag *pOutputTag;
   GtkTextTag *pHiddenTag;
   GtkTextTag *pVisibleTag;
   gboolean bConversionMode;
   gint iLastOffset;
   gint iCurrentState; // 0 = unconverted, 1 = converted
+
   //Paralleling the previous approach in dasher_main, we _don't_ send context_changed
   // events if we're in the middle of executing a control action (as this would rebuild
   // the canvas)
@@ -44,7 +47,6 @@ G_DEFINE_TYPE(DasherEditorInternal, dasher_editor_internal, DASHER_TYPE_EDITOR);
 
 static void dasher_editor_internal_finalize(GObject *pObject);
 
-
 static void dasher_editor_internal_handle_font(DasherEditor *pSelf, const gchar *szFont);
 
 gboolean dasher_editor_internal_command(DasherEditor *pSelf, const gchar *szCommand);
diff --git a/Src/Gtk2/dasher_main.cpp b/Src/Gtk2/dasher_main.cpp
index 3886408..0d06651 100644
--- a/Src/Gtk2/dasher_main.cpp
+++ b/Src/Gtk2/dasher_main.cpp
@@ -48,7 +48,6 @@ struct _DasherMainPrivate {
 
   GtkListStore *pAlphabetList;
   GtkAccelGroup *pAccel;
-  gulong iAlphabetComboHandler;
 
   // Widgets used for maemo
 #ifdef WITH_MAEMO
@@ -205,7 +204,7 @@ dasher_main_new(int *argc, char ***argv, SCommandLine *pCommandLine) {
     DasherMainPrivate *pPrivate = DASHER_MAIN_GET_PRIVATE(pDasherMain);
 
     /* Create the app settings object */
-    pPrivate->pAppSettings = dasher_app_settings_new(*argc, *argv);
+    pPrivate->pAppSettings = dasher_app_settings_new(pDasherMain, *argc, *argv);
     
     /* Load the user interface from the GUI file */
     if(pCommandLine && pCommandLine->szAppStyle) {
@@ -534,8 +533,6 @@ dasher_main_load_interface(DasherMain *pSelf) {
   //  g_signal_connect(G_OBJECT(pPrivate->pBufferView), "button-release-event", G_CALLBACK(take_real_focus), NULL);
   // g_signal_connect(G_OBJECT(pPrivate->pBufferView), "key-press-event", G_CALLBACK(edit_key_press), NULL);
   //g_signal_connect(G_OBJECT(pPrivate->pBufferView), "key-release-event", G_CALLBACK(edit_key_release), NULL);
-
-  pPrivate->iAlphabetComboHandler = g_signal_connect(G_OBJECT(pPrivate->pAlphabetCombo), "changed", G_CALLBACK(alphabet_combo_changed), NULL);
   
   //  dasher_main_build_context_menu(pSelf);
 
@@ -1151,7 +1148,7 @@ dasher_main_populate_alphabet_combo(DasherMain *pSelf) {
   // Disconnect the event handler temporarily, otherwise this will
   // trigger alphabet changes
 
-  g_signal_handler_block(pPrivate->pAlphabetCombo, pPrivate->iAlphabetComboHandler);
+  g_signal_handlers_block_by_func(pPrivate->pAlphabetCombo, (gpointer)alphabet_combo_changed, pSelf);
 
   gtk_list_store_clear(pPrivate->pAlphabetList);
 
@@ -1194,7 +1191,7 @@ dasher_main_populate_alphabet_combo(DasherMain *pSelf) {
   gtk_list_store_append(pPrivate->pAlphabetList, &sIter);
   gtk_list_store_set(pPrivate->pAlphabetList, &sIter, 0, "More Alphabets...", -1);
 
-  g_signal_handler_unblock(pPrivate->pAlphabetCombo, pPrivate->iAlphabetComboHandler);
+  g_signal_handlers_unblock_by_func(pPrivate->pAlphabetCombo, (gpointer)alphabet_combo_changed, pSelf);
 
 #endif
 }
@@ -1264,7 +1261,7 @@ dasher_main_cb_window_close(GtkWidget *pWidget, gpointer pUserData) {
 }
 
 extern "C" void 
-parameter_notification(GtkDasherControl *pDasherControl, gint iParameter, gpointer pUserData) { 
+parameter_notification(GtkDasherControl *pDasherControl, gint iParameter, gpointer pUserData) {
   DasherMain *pDasherMain = DASHER_MAIN(pUserData);
   dasher_main_handle_parameter_change(pDasherMain, iParameter);
 }



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