72
71
static guint profile_manager_signals[LAST_SIGNAL] = { 0 };
75
on_plugin_activated (AnjutaPluginManager *plugin_manager,
76
AnjutaPluginDescription *plugin_desc,
77
GObject *plugin_object,
78
AnjutaProfileManager *profile_manager)
80
AnjutaProfileManagerPriv *priv;
81
priv = profile_manager->priv;
85
/* Add it current profile */
88
if (!anjuta_plugin_description_get_boolean (plugin_desc, "Anjuta Plugin", "ExcludeFromSession", &exclude) || !exclude)
90
anjuta_profile_add_plugin (ANJUTA_PROFILE (priv->profiles->data),
97
on_plugin_deactivated (AnjutaPluginManager *plugin_manager,
98
AnjutaPluginDescription *plugin_desc,
99
GObject *plugin_object,
100
AnjutaProfileManager *profile_manager)
102
AnjutaProfileManagerPriv *priv;
103
priv = profile_manager->priv;
107
/* Remove from current profile */
108
anjuta_profile_remove_plugin (ANJUTA_PROFILE (priv->profiles->data),
114
74
anjuta_profile_manager_init (AnjutaProfileManager *object)
116
76
object->priv = g_new0 (AnjutaProfileManagerPriv, 1);
237
193
ANJUTA_TYPE_PROFILE);
240
* AnjutaProfileManager::profile-descoped:
241
* @profile_manager: a #AnjutaProfileManager object.
242
* @profile: the old unloaded #AnjutaProfile.
244
* Emitted when a profile will be unloaded.
246
profile_manager_signals[PROFILE_DESCOPED] =
247
g_signal_new ("profile-descoped",
248
G_OBJECT_CLASS_TYPE (klass),
250
G_STRUCT_OFFSET (AnjutaProfileManagerClass,
253
anjuta_cclosure_marshal_VOID__OBJECT,
255
ANJUTA_TYPE_PROFILE);
258
* AnjutaProfileManager::profile-scoped:
259
* @profile_manager: a #AnjutaProfileManager object.
260
* @profile: the current loaded #AnjutaProfile.
262
* Emitted when a new profile is loaded.
264
profile_manager_signals[PROFILE_SCOPED] =
265
g_signal_new ("profile-scoped",
266
G_OBJECT_CLASS_TYPE (klass),
268
G_STRUCT_OFFSET (AnjutaProfileManagerClass,
271
anjuta_cclosure_marshal_VOID__OBJECT,
273
ANJUTA_TYPE_PROFILE);
323
anjuta_profile_manager_load_profile (AnjutaProfileManager *profile_manager,
324
AnjutaProfile *profile,
325
AnjutaProfile *previous_profile,
244
anjuta_profile_manager_load_profiles (AnjutaProfileManager *profile_manager, GError **error)
328
246
AnjutaProfileManagerPriv *priv;
329
GList *active_plugins, *node;
330
GList *plugins_to_activate, *plugins_to_deactivate;
331
GList *selected_plugins;
333
GHashTable *active_plugins_hash, *plugins_to_activate_hash;
247
gboolean loaded = FALSE;
335
249
priv = profile_manager->priv;
337
/* Disable profile synchronization while the profile is being activated */
338
g_signal_handlers_block_by_func (priv->plugin_manager,
339
G_CALLBACK (on_plugin_activated),
341
g_signal_handlers_block_by_func (priv->plugin_manager,
342
G_CALLBACK (on_plugin_deactivated),
345
/* Emit pre-change for the last profile */
346
if (previous_profile)
348
g_signal_emit_by_name (profile_manager, "profile-descoped",
352
/* Prepare plugins to activate */
353
plugins_to_activate_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
355
/* Select plugins in the profile */
357
selected_plugins = anjuta_profile_get_plugins (profile);
359
selected_plugins = NULL;
361
node = selected_plugins;
364
g_hash_table_insert (plugins_to_activate_hash, node->data, node->data);
365
node = g_list_next (node);
368
/* Prepare active plugins hash */
370
anjuta_plugin_manager_get_active_plugins (priv->plugin_manager);
371
active_plugins_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
372
node = active_plugins;
375
g_hash_table_insert (active_plugins_hash, node->data, node->data);
376
node = g_list_next (node);
379
plugins_to_deactivate = NULL;
381
/* Prepare plugins to deactiveate that are already active, but are
382
* not requested to be active
384
node = active_plugins;
387
if (!g_hash_table_lookup (plugins_to_activate_hash, node->data))
389
plugins_to_deactivate = g_list_prepend (plugins_to_deactivate,
392
node = g_list_next (node);
394
plugins_to_deactivate = g_list_reverse (plugins_to_deactivate);
396
/* Deactivate plugins */
397
node = plugins_to_deactivate;
400
AnjutaPluginDescription *desc;
401
gchar *plugin_id = NULL;
403
desc = (AnjutaPluginDescription *)node->data;
404
anjuta_plugin_description_get_string (desc, "Anjuta Plugin",
405
"Location", &plugin_id);
406
g_assert (plugin_id != NULL);
408
/* DEBUG_PRINT ("Profile: deactivating %s", plugin_id); */
410
anjuta_plugin_manager_unload_plugin_by_id (priv->plugin_manager,
412
node = g_list_next (node);
415
/* Prepare the plugins to activate */
416
plugins_to_activate = NULL;
417
node = selected_plugins;
420
if (!g_hash_table_lookup (active_plugins_hash, node->data))
421
plugins_to_activate = g_list_prepend (plugins_to_activate,
423
node = g_list_next (node);
426
/* Now activate the plugins */
427
if (plugins_to_activate)
430
plugins_to_activate = g_list_reverse (plugins_to_activate);
431
anjuta_plugin_manager_activate_plugins (priv->plugin_manager,
432
plugins_to_activate);
435
g_list_free (plugins_to_activate);
436
g_list_free (active_plugins);
438
g_hash_table_destroy (plugins_to_activate_hash);
439
g_hash_table_destroy (active_plugins_hash);
441
/* Enable profile synchronization */
442
g_signal_handlers_unblock_by_func (priv->plugin_manager,
443
G_CALLBACK (on_plugin_activated),
445
g_signal_handlers_unblock_by_func (priv->plugin_manager,
446
G_CALLBACK (on_plugin_deactivated),
448
g_signal_emit_by_name (profile_manager, "profile-scoped", profile);
251
/* If there is no freeze load profile now */
252
while ((priv->freeze_count <= 0) && (priv->profiles_queue != NULL))
254
AnjutaProfile *previous_profile = NULL;
257
/* We need to load each profile one by one because a "system" profile
258
* contains plugins which are never unloaded. */
260
previous_profile = priv->profiles->data;
261
node = g_list_last (priv->profiles_queue);
262
priv->profiles_queue = g_list_remove_link (priv->profiles_queue, node);
263
priv->profiles = g_list_concat (node, priv->profiles);
265
/* Load profile. Note that loading a profile can trigger the load of
266
* additional profile. Typically loading the default profile will
267
* trigger the load of the last project profile. */
268
if (previous_profile != NULL) anjuta_profile_unload (previous_profile, NULL);
269
loaded = anjuta_profile_load (ANJUTA_PROFILE (node->data), error);
457
280
AnjutaProfileManagerPriv *priv;
459
282
priv = profile_manager->priv;
460
priv->profiles_queue = g_list_prepend (priv->profiles_queue,
284
priv->profiles_queue = g_list_prepend (priv->profiles_queue, profile);
462
286
/* If there is no freeze load profile now */
463
if (priv->freeze_count <= 0)
465
AnjutaProfile *previous_profile = NULL;
468
previous_profile = priv->profiles->data;
470
/* Push queued profiles in stack */
471
priv->profiles = g_list_concat (priv->profiles_queue, priv->profiles);
472
priv->profiles_queue = NULL;
474
return anjuta_profile_manager_load_profile (profile_manager,
475
ANJUTA_PROFILE (priv->profiles->data),
287
return anjuta_profile_manager_load_profiles (profile_manager, error);
550
352
/* Then check in the current stack */
551
353
if (priv->profiles)
553
profile = priv->profiles->data;
554
g_return_val_if_fail (strcmp (anjuta_profile_get_name (profile),
555
profile_name) == 0, FALSE);
355
g_return_val_if_fail (priv->profiles->data == profile, FALSE);
556
356
priv->profiles = g_list_remove (priv->profiles, profile);
558
358
g_signal_emit_by_name (profile_manager, "profile-popped",
561
361
/* Restore the next profile in the stack */
362
anjuta_profile_unload (profile, NULL);
363
g_object_unref (profile);
562
364
if (priv->profiles)
564
return anjuta_profile_manager_load_profile (profile_manager,
565
ANJUTA_PROFILE (priv->profiles->data),
571
return anjuta_profile_manager_load_profile (profile_manager,
575
g_object_unref (profile);
366
return anjuta_profile_load (ANJUTA_PROFILE (priv->profiles->data), error);
682
456
priv = profile_manager->priv;
684
g_signal_handlers_disconnect_by_func (priv->plugin_manager,
685
on_plugin_activated, profile_manager);
686
g_signal_handlers_disconnect_by_func (priv->plugin_manager,
687
on_plugin_deactivated, profile_manager);
689
458
if (priv->profiles)
691
460
AnjutaProfile *profile = ANJUTA_PROFILE (priv->profiles->data);
693
/* Emit "profile-descoped" so that other parts of anjuta can store
462
/* Emit "descoped" so that other parts of anjuta can store
694
463
* information about the currently loaded profile. */
695
g_signal_emit_by_name (profile_manager, "profile-descoped",
464
anjuta_profile_unload (profile, NULL);
698
466
g_list_free_full (priv->profiles, g_object_unref);
699
467
priv->profiles = NULL;