[anjuta] libanjuta: Move scoped and descoped signal on AnjutaProfile object



commit 4853cd7e52ce541f08b74eda5e6ce3f49446dc50
Author: SĂ©bastien Granjoux <seb sfo free fr>
Date:   Sun Mar 24 17:21:26 2013 +0100

    libanjuta: Move scoped and descoped signal on AnjutaProfile object
    
    scoped and descoped signal were emitted by the AnjutaProfileManager object and
    the handlers were checking the profile name (user or project). This is not
    needed anymore so the profile name can be freely choosen.

 libanjuta/anjuta-profile-manager.c |   62 +++++------------------------------
 libanjuta/anjuta-profile-manager.h |    6 +---
 libanjuta/anjuta-profile.c         |   35 ++++++++++++++++++++
 libanjuta/anjuta-profile.h         |    2 +
 plugins/project-manager/plugin.c   |   45 +++++++++++---------------
 plugins/project-manager/plugin.h   |    3 ++
 src/anjuta-application.c           |   22 +++----------
 7 files changed, 74 insertions(+), 101 deletions(-)
---
diff --git a/libanjuta/anjuta-profile-manager.c b/libanjuta/anjuta-profile-manager.c
index 5be4dee..1a1593b 100644
--- a/libanjuta/anjuta-profile-manager.c
+++ b/libanjuta/anjuta-profile-manager.c
@@ -51,8 +51,6 @@ enum
 {
        PROFILE_PUSHED,
        PROFILE_POPPED,
-       PROFILE_DESCOPED,
-       PROFILE_SCOPED,
        LAST_SIGNAL
 };
 
@@ -236,41 +234,6 @@ anjuta_profile_manager_class_init (AnjutaProfileManagerClass *klass)
                              G_TYPE_NONE, 1,
                              ANJUTA_TYPE_PROFILE);
        
-       /**
-        * AnjutaProfileManager::profile-descoped:
-        * @profile_manager: a #AnjutaProfileManager object.
-        * @profile: the old unloaded #AnjutaProfile.
-        * 
-        * Emitted when a profile will be unloaded.
-        */
-       profile_manager_signals[PROFILE_DESCOPED] =
-               g_signal_new ("profile-descoped",
-                             G_OBJECT_CLASS_TYPE (klass),
-                             G_SIGNAL_RUN_FIRST,
-                             G_STRUCT_OFFSET (AnjutaProfileManagerClass,
-                                                                          profile_descoped),
-                             NULL, NULL,
-                                         anjuta_cclosure_marshal_VOID__OBJECT,
-                             G_TYPE_NONE, 1,
-                             ANJUTA_TYPE_PROFILE);
-       
-       /**
-        * AnjutaProfileManager::profile-scoped:
-        * @profile_manager: a #AnjutaProfileManager object.
-        * @profile: the current loaded #AnjutaProfile.
-        * 
-        * Emitted when a new profile is loaded.
-        */
-       profile_manager_signals[PROFILE_SCOPED] =
-               g_signal_new ("profile-scoped",
-                             G_OBJECT_CLASS_TYPE (klass),
-                             G_SIGNAL_RUN_FIRST,
-                             G_STRUCT_OFFSET (AnjutaProfileManagerClass,
-                                                                          profile_scoped),
-                             NULL, NULL,
-                                         anjuta_cclosure_marshal_VOID__OBJECT,
-                             G_TYPE_NONE, 1,
-                             ANJUTA_TYPE_PROFILE);
 }
 
 GType
@@ -345,8 +308,7 @@ anjuta_profile_manager_load_profile (AnjutaProfileManager *profile_manager,
        /* Emit pre-change for the last profile */
        if (previous_profile)
        {
-               g_signal_emit_by_name (profile_manager, "profile-descoped",
-                                                          previous_profile);
+               g_signal_emit_by_name (previous_profile, "descoped");
        }
        
        /* Prepare plugins to activate */
@@ -445,7 +407,7 @@ anjuta_profile_manager_load_profile (AnjutaProfileManager *profile_manager,
        g_signal_handlers_unblock_by_func (priv->plugin_manager,
                                                                           G_CALLBACK (on_plugin_deactivated),
                                                                           profile_manager);
-       g_signal_emit_by_name (profile_manager, "profile-scoped", profile);
+       g_signal_emit_by_name (profile, "scoped");
        return TRUE;
 }
 
@@ -511,7 +473,7 @@ anjuta_profile_manager_push (AnjutaProfileManager *profile_manager,
 /**
  * anjuta_profile_manager_pop:
  * @profile_manager: the #AnjutaProfileManager object.
- * @profile_name: the name of the profile to remove.
+ * @profile: the #AnjutaProfile to remove.
  * @error: error propagation and reporting.
  * 
  * Remove a profile from the profile manager stack. If the manager is not
@@ -524,10 +486,9 @@ anjuta_profile_manager_push (AnjutaProfileManager *profile_manager,
  */
 gboolean
 anjuta_profile_manager_pop (AnjutaProfileManager *profile_manager,
-                                                       const gchar *profile_name, GError **error)
+                                                       AnjutaProfile *profile, GError **error)
 {
        AnjutaProfileManagerPriv *priv;
-       AnjutaProfile *profile;
 
        g_return_val_if_fail (ANJUTA_IS_PROFILE_MANAGER (profile_manager), FALSE);
        priv = profile_manager->priv;
@@ -535,9 +496,7 @@ anjuta_profile_manager_pop (AnjutaProfileManager *profile_manager,
        /* First check in the queue */
        if (priv->profiles_queue)
        {
-               profile = priv->profiles_queue->data;
-               g_return_val_if_fail (strcmp (anjuta_profile_get_name (profile),
-                                                                         profile_name) == 0, FALSE);
+               g_return_val_if_fail (priv->profiles_queue->data == profile, FALSE);
                priv->profiles_queue = g_list_remove (priv->profiles_queue, profile);
                
                g_signal_emit_by_name (profile_manager, "profile-popped",
@@ -550,9 +509,7 @@ anjuta_profile_manager_pop (AnjutaProfileManager *profile_manager,
        /* Then check in the current stack */
        if (priv->profiles)
        {
-               profile = priv->profiles->data;
-               g_return_val_if_fail (strcmp (anjuta_profile_get_name (profile),
-                                                                         profile_name) == 0, FALSE);
+               g_return_val_if_fail (priv->profiles->data == profile, FALSE);
                priv->profiles = g_list_remove (priv->profiles, profile);
                
                g_signal_emit_by_name (profile_manager, "profile-popped",
@@ -669,7 +626,7 @@ anjuta_profile_manager_get_current (AnjutaProfileManager *profile_manager)
  * anjuta_profile_manager_close:
  * @profile_manager: A #AnjutaProfileManager object.
  *
- * Close the #AnjutaProfileManager causing "profile-descoped" to be emitted and
+ * Close the #AnjutaProfileManager causing "descoped" to be emitted and
  * all queued and previous profiles to be released. This function is to be used
  * when destroying an Anjuta instance.
  */
@@ -691,10 +648,9 @@ anjuta_profile_manager_close (AnjutaProfileManager *profile_manager)
        {
                AnjutaProfile *profile = ANJUTA_PROFILE (priv->profiles->data);
 
-               /* Emit "profile-descoped" so that other parts of anjuta can store
+               /* Emit "descoped" so that other parts of anjuta can store
                 * information about the currently loaded profile. */
-               g_signal_emit_by_name (profile_manager, "profile-descoped",
-                                      profile);
+               g_signal_emit_by_name (profile, "descoped");
 
                g_list_free_full (priv->profiles, g_object_unref);
                priv->profiles = NULL;
diff --git a/libanjuta/anjuta-profile-manager.h b/libanjuta/anjuta-profile-manager.h
index 3460303..e6c9d04 100644
--- a/libanjuta/anjuta-profile-manager.h
+++ b/libanjuta/anjuta-profile-manager.h
@@ -45,10 +45,6 @@ struct _AnjutaProfileManagerClass
                                                        AnjutaProfile* profile);
        void(* profile_popped) (AnjutaProfileManager *self,
                                                        AnjutaProfile* profile);
-       void(* profile_descoped) (AnjutaProfileManager *self,
-                                                         AnjutaProfile* profile);
-       void(* profile_scoped) (AnjutaProfileManager *self,
-                                                       AnjutaProfile* profile);
 };
 
 /**
@@ -69,7 +65,7 @@ AnjutaProfileManager *anjuta_profile_manager_new (AnjutaPluginManager *plugin_ma
 gboolean anjuta_profile_manager_push (AnjutaProfileManager *profile_manager,
                                                                          AnjutaProfile *profile, GError 
**error);
 gboolean anjuta_profile_manager_pop (AnjutaProfileManager *profile_manager,
-                                                                        const gchar *profile_name, GError 
**error);
+                                                                        AnjutaProfile *profile, GError 
**error);
 
 void anjuta_profile_manager_freeze (AnjutaProfileManager *profile_manager);
 gboolean anjuta_profile_manager_thaw (AnjutaProfileManager *profile_manager,
diff --git a/libanjuta/anjuta-profile.c b/libanjuta/anjuta-profile.c
index 2b0d82d..a089f88 100644
--- a/libanjuta/anjuta-profile.c
+++ b/libanjuta/anjuta-profile.c
@@ -93,6 +93,8 @@ enum
        PLUGIN_ADDED,
        PLUGIN_REMOVED,
        CHANGED,
+       DESCOPED,
+       SCOPED,
        LAST_SIGNAL
 };
 
@@ -334,6 +336,39 @@ anjuta_profile_class_init (AnjutaProfileClass *klass)
                              anjuta_cclosure_marshal_VOID__POINTER,
                              G_TYPE_NONE, 1,
                              G_TYPE_POINTER);
+
+       /**
+        * AnjutaProfile::profile-descoped:
+        * @profile: the old unloaded #AnjutaProfile
+        *
+        * Emitted when a profile will be unloaded.
+        */
+       profile_signals[DESCOPED] =
+               g_signal_new ("descoped",
+                             G_OBJECT_CLASS_TYPE (klass),
+                             G_SIGNAL_RUN_FIRST,
+                             G_STRUCT_OFFSET (AnjutaProfileClass,
+                                                                          descoped),
+                             NULL, NULL,
+                                         g_cclosure_marshal_VOID__VOID,
+                             G_TYPE_NONE, 0);
+
+       /**
+        * AnjutaProfileManager::profile-scoped:
+        * @profile_manager: a #AnjutaProfileManager object.
+        * @profile: the current loaded #AnjutaProfile.
+        *
+        * Emitted when a new profile is loaded.
+        */
+       profile_signals[SCOPED] =
+               g_signal_new ("scoped",
+                             G_OBJECT_CLASS_TYPE (klass),
+                             G_SIGNAL_RUN_FIRST,
+                             G_STRUCT_OFFSET (AnjutaProfileClass,
+                                                                          scoped),
+                             NULL, NULL,
+                                         g_cclosure_marshal_VOID__VOID,
+                             G_TYPE_NONE, 0);
 }
 
 GType
diff --git a/libanjuta/anjuta-profile.h b/libanjuta/anjuta-profile.h
index 7b9a70e..b46f340 100644
--- a/libanjuta/anjuta-profile.h
+++ b/libanjuta/anjuta-profile.h
@@ -72,6 +72,8 @@ struct _AnjutaProfileClass
        void(* plugin_removed) (AnjutaProfile *self,
                                                        AnjutaPluginDescription *plugin);
        void(* changed) (AnjutaProfile *self, GList *plugins);
+       void(* descoped) (AnjutaProfile *self);
+       void(* scoped) (AnjutaProfile *self);
 };
 
 /**
diff --git a/plugins/project-manager/plugin.c b/plugins/project-manager/plugin.c
index 476d300..5329b63 100644
--- a/plugins/project-manager/plugin.c
+++ b/plugins/project-manager/plugin.c
@@ -1449,15 +1449,9 @@ project_manager_unload_gbf (ProjectManagerPlugin *pm_plugin)
 }
 
 static void
-on_profile_scoped (AnjutaProfileManager *profile_manager,
-                                  AnjutaProfile *profile, ProjectManagerPlugin *plugin)
+on_profile_scoped (AnjutaProfile *profile, ProjectManagerPlugin *plugin)
 {
        gchar *session_dir;
-       DEBUG_PRINT ("Profile scoped: %s", anjuta_profile_get_name (profile));
-       if (strcmp (anjuta_profile_get_name (profile), PROJECT_PROFILE_NAME) != 0)
-               return;
-
-       DEBUG_PRINT ("%s", "Project profile loaded; Restoring project session");
 
        /* Load gbf project */
        project_manager_load_gbf (plugin);
@@ -1482,14 +1476,8 @@ on_profile_scoped (AnjutaProfileManager *profile_manager,
 }
 
 static void
-on_profile_descoped (AnjutaProfileManager *profile_manager,
-                                        AnjutaProfile *profile, ProjectManagerPlugin *plugin)
+on_profile_descoped (AnjutaProfile *profile, ProjectManagerPlugin *plugin)
 {
-       DEBUG_PRINT ("Profile descoped: %s", anjuta_profile_get_name (profile));
-
-       if (strcmp (anjuta_profile_get_name (profile), PROJECT_PROFILE_NAME) != 0)
-               return;
-
        DEBUG_PRINT ("%s", "Project profile descoped; Saving project session");
 
        /* Save current project session */
@@ -1520,7 +1508,8 @@ project_manager_plugin_close (ProjectManagerPlugin *plugin)
        /* Remove project profile */
        profile_manager =
                anjuta_shell_get_profile_manager (ANJUTA_PLUGIN (plugin)->shell, NULL);
-       anjuta_profile_manager_pop (profile_manager, PROJECT_PROFILE_NAME, &error);
+       anjuta_profile_manager_pop (profile_manager, plugin->profile, &error);
+       plugin->profile = NULL;
        if (error)
        {
                anjuta_util_dialog_error (get_plugin_parent_window (plugin),
@@ -1641,11 +1630,7 @@ project_manager_plugin_activate_plugin (AnjutaPlugin *plugin)
                                          G_CALLBACK (on_session_load), plugin);
        profile_manager = anjuta_shell_get_profile_manager (plugin->shell, NULL);
 
-       /* Connect to profile scoping */
-       g_signal_connect (profile_manager, "profile-scoped",
-                                         G_CALLBACK (on_profile_scoped), plugin);
-       g_signal_connect (profile_manager, "profile-descoped",
-                                         G_CALLBACK (on_profile_descoped), plugin);
+
        return TRUE;
 }
 
@@ -1675,12 +1660,15 @@ project_manager_plugin_deactivate_plugin (AnjutaPlugin *plugin)
        g_signal_handlers_disconnect_by_func (G_OBJECT (plugin->shell),
                                                                                  G_CALLBACK 
(on_session_load),
                                                                                  plugin);
-       g_signal_handlers_disconnect_by_func (G_OBJECT (profile_manager),
-                                                                                 G_CALLBACK 
(on_profile_descoped),
-                                                                                 plugin);
-       g_signal_handlers_disconnect_by_func (G_OBJECT (profile_manager),
-                                                                                 G_CALLBACK 
(on_profile_scoped),
-                                                                                 plugin);
+       if (pm_plugin->profile != NULL)
+       {
+               g_signal_handlers_disconnect_by_func (G_OBJECT (pm_plugin->profile),
+                                                     G_CALLBACK (on_profile_descoped),
+                                                     plugin);
+               g_signal_handlers_disconnect_by_func (G_OBJECT (pm_plugin->profile),
+                                                     G_CALLBACK (on_profile_scoped),
+                                                     plugin);
+       }
        /* Remove watches */
        anjuta_plugin_remove_watch (plugin, pm_plugin->fm_watch_id, TRUE);
        anjuta_plugin_remove_watch (plugin, pm_plugin->editor_watch_id, TRUE);
@@ -1735,6 +1723,7 @@ project_manager_plugin_instance_init (GObject *obj)
        plugin->session_by_me = FALSE;
        plugin->close_project_idle = -1;
        plugin->shortcuts = NULL;
+       plugin->profile = NULL;
 }
 
 static void
@@ -2353,6 +2342,10 @@ ifile_open (IAnjutaFile *ifile, GFile* file, GError **e)
 
                return;
        }
+       /* Connect to profile scoping */
+       g_signal_connect (profile, "scoped", G_CALLBACK (on_profile_scoped), plugin);
+       g_signal_connect (profile, "descoped", G_CALLBACK (on_profile_descoped), plugin);
+       plugin->profile = profile;
 
        /* Project default profile */
        anjuta_profile_add_plugins_from_xml (profile, file, TRUE, &error);
diff --git a/plugins/project-manager/plugin.h b/plugins/project-manager/plugin.h
index 9ada095..b31552e 100644
--- a/plugins/project-manager/plugin.h
+++ b/plugins/project-manager/plugin.h
@@ -78,6 +78,9 @@ struct _ProjectManagerPlugin{
 
        /* project is loading */
        gboolean busy;
+
+       /* profile */
+       AnjutaProfile *profile;
 };
 
 struct _ProjectManagerPluginClass{
diff --git a/src/anjuta-application.c b/src/anjuta-application.c
index 4e41eb4..79c59b0 100644
--- a/src/anjuta-application.c
+++ b/src/anjuta-application.c
@@ -114,7 +114,7 @@ on_anjuta_delete_event (AnjutaWindow *win, GdkEvent *event, gpointer user_data)
                }
        }
 
-       /* Close the profile manager which will emit "profile-descoped" and release
+       /* Close the profile manager which will emit "descoped" and release
         * all previous profiles. */
        anjuta_profile_manager_close (profile_manager);
 
@@ -135,17 +135,12 @@ on_anjuta_delete_event (AnjutaWindow *win, GdkEvent *event, gpointer user_data)
 }
 
 static void
-on_profile_scoped (AnjutaProfileManager *profile_manager,
-                                  AnjutaProfile *profile, AnjutaWindow *win)
+on_profile_scoped (AnjutaProfile *profile, AnjutaWindow *win)
 {
        gchar *session_dir;
        static gboolean first_time = TRUE;
        AnjutaSession *session;
 
-       DEBUG_PRINT ("Profile scoped: %s", anjuta_profile_get_name (profile));
-       if (strcmp (anjuta_profile_get_name (profile), USER_PROFILE_NAME) != 0)
-               return;
-
        DEBUG_PRINT ("%s", "User profile loaded; Restoring user session");
 
        /* If profile scoped to "user", restore user session */
@@ -182,15 +177,10 @@ on_profile_scoped (AnjutaProfileManager *profile_manager,
 }
 
 static void
-on_profile_descoped (AnjutaProfileManager *profile_manager,
-                                        AnjutaProfile *profile, AnjutaWindow *win)
+on_profile_descoped (AnjutaProfile *profile, AnjutaWindow *win)
 {
        gchar *session_dir;
 
-       DEBUG_PRINT ("Profile descoped: %s", anjuta_profile_get_name (profile));
-       if (strcmp (anjuta_profile_get_name (profile), USER_PROFILE_NAME) != 0)
-               return;
-
        DEBUG_PRINT ("%s", "User profile descoped; Saving user session");
 
        /* If profile descoped from is "user", save user session */
@@ -640,8 +630,7 @@ anjuta_application_create_window (AnjutaApplication *app)
        }
 
        /* Prepare for session save and load on profile change */
-       g_signal_connect (profile_manager, "profile-scoped",
-                                         G_CALLBACK (on_profile_scoped), win);
+       g_signal_connect (profile, "scoped", G_CALLBACK (on_profile_scoped), win);
        anjuta_profile_manager_thaw (profile_manager, &error);
 
        if (error)
@@ -650,8 +639,7 @@ anjuta_application_create_window (AnjutaApplication *app)
                g_error_free (error);
                error = NULL;
        }
-       g_signal_connect (profile_manager, "profile-descoped",
-                                         G_CALLBACK (on_profile_descoped), win);
+       g_signal_connect (profile, "descoped", G_CALLBACK (on_profile_descoped), win);
 
        anjuta_status_progress_tick (status, NULL, _("Loaded Session…"));
        anjuta_status_disable_splash (status, TRUE);


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