bgo #708248 - inconsistency in strings: libtool, whitespace use
[anjuta.git] / src / anjuta-application.c
blob27b49d241e3d2edb53a6646acb1fdc2b218e7d8e
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * anjuta-application.c
4 * Copyright (C) 2000 Naba Kumar <naba@gnome.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <config.h>
22 #ifdef ENABLE_NLS
23 # include <locale.h>
24 #endif
26 #include <string.h>
27 #include <stdlib.h>
28 #include <libanjuta/anjuta-shell.h>
29 #include <libanjuta/anjuta-debug.h>
30 #include <libanjuta/anjuta-utils.h>
31 #include <libanjuta/anjuta-save-prompt.h>
32 #include <libanjuta/anjuta-plugin-manager.h>
33 #include <libanjuta/resources.h>
34 #include <libanjuta/interfaces/ianjuta-file-loader.h>
35 #include <libanjuta/interfaces/ianjuta-file.h>
37 #include "anjuta-application.h"
38 #include "action-callbacks.h"
40 #define ANJUTA_REMEMBERED_PLUGINS "remembered-plugins"
41 #define USER_SESSION_PATH_NEW (anjuta_util_get_user_cache_file_path ("session/", NULL))
43 #define ANJUTA_SESSION_SKIP_LAST "session-skip-last"
44 #define ANJUTA_SESSION_SKIP_LAST_FILES "session-skip-last-files"
46 #define PROFILE_DIRECTORY "file://"PACKAGE_DATA_DIR"/profiles"
47 #define USER_PROFILE_NAME "user"
49 #define ANJUTA_PIXMAP_SPLASH_SCREEN "anjuta_splash.png"
51 #define ANJUTA_GEOMETRY_HINT ";g="
52 #define ANJUTA_PROFILE_HINT ";P="
53 #define ANJUTA_NO_SPLASH_HINT ";s"
54 #define ANJUTA_NO_SESSION_HINT ";n"
55 #define ANJUTA_NO_FILES_HINT ";f"
57 static gchar DEFAULT_PROFILE[] = "default.profile";
59 #define ANJUTA_MENU_UI_FILE PACKAGE_DATA_DIR"/glade/anjuta-menu.ui"
61 G_DEFINE_TYPE (AnjutaApplication, anjuta_application, GTK_TYPE_APPLICATION)
63 struct _AnjutaApplicationPrivate {
64 gboolean no_splash;
65 gboolean proper_shutdown;
66 gboolean no_files;
67 gboolean no_session;
68 gchar *geometry;
69 gchar *profile;
72 static void
73 on_app_preferences (GSimpleAction *action,
74 GVariant *parameter,
75 gpointer user_data)
77 GtkApplication *app;
78 AnjutaWindow* window;
80 app = GTK_APPLICATION (user_data);
81 window = ANJUTA_WINDOW (gtk_application_get_active_window (app));
83 on_preferences_activate (NULL, window);
86 static void
87 on_app_manual (GSimpleAction *action,
88 GVariant *parameter,
89 gpointer user_data)
91 GtkApplication *app;
92 AnjutaWindow* window;
94 app = GTK_APPLICATION (user_data);
95 window = ANJUTA_WINDOW (gtk_application_get_active_window (app));
97 on_help_manual_activate (NULL, window);
100 static void
101 on_app_about (GSimpleAction *action,
102 GVariant *parameter,
103 gpointer user_data)
105 GtkApplication *app;
106 AnjutaWindow* window;
108 app = GTK_APPLICATION (user_data);
109 window = ANJUTA_WINDOW (gtk_application_get_active_window (app));
111 on_about_activate (NULL, window);
114 static void
115 on_app_quit (GSimpleAction *action,
116 GVariant *parameter,
117 gpointer user_data)
119 GtkApplication *app;
120 AnjutaWindow* window;
122 app = GTK_APPLICATION (user_data);
123 window = ANJUTA_WINDOW (gtk_application_get_active_window (app));
125 on_exit_activate (NULL, window);
129 static gboolean
130 on_anjuta_delete_event (AnjutaWindow *win, GdkEvent *event, gpointer user_data)
132 AnjutaApplication *app = user_data;
133 AnjutaApplicationPrivate *priv = app->priv;
135 AnjutaPluginManager *plugin_manager;
136 AnjutaProfileManager *profile_manager;
137 AnjutaSavePrompt *save_prompt;
138 gchar *remembered_plugins;
140 DEBUG_PRINT ("%s", "AnjutaWindow delete event");
142 plugin_manager = anjuta_shell_get_plugin_manager (ANJUTA_SHELL (win), NULL);
143 profile_manager = anjuta_shell_get_profile_manager (ANJUTA_SHELL (win), NULL);
145 /* Save remembered plugins */
146 remembered_plugins =
147 anjuta_plugin_manager_get_remembered_plugins (plugin_manager);
148 g_settings_set_string (win->settings,
149 ANJUTA_REMEMBERED_PLUGINS,
150 remembered_plugins);
151 g_free (remembered_plugins);
153 /* Check for unsaved data */
154 save_prompt = anjuta_save_prompt_new (GTK_WINDOW (win));
155 anjuta_shell_save_prompt (ANJUTA_SHELL (win), save_prompt, NULL);
157 if (anjuta_save_prompt_get_items_count (save_prompt) > 0)
159 switch (gtk_dialog_run (GTK_DIALOG (save_prompt)))
161 case GTK_RESPONSE_DELETE_EVENT:
162 case ANJUTA_SAVE_PROMPT_RESPONSE_CANCEL:
163 gtk_widget_destroy (GTK_WIDGET (save_prompt));
164 /* Do not exit now */
165 return TRUE;
166 case ANJUTA_SAVE_PROMPT_RESPONSE_DISCARD:
167 case ANJUTA_SAVE_PROMPT_RESPONSE_SAVE_CLOSE:
168 /* exit now */
169 break;
172 gtk_widget_destroy (GTK_WIDGET (save_prompt));
174 /* Wait for files to be really saved (asyncronous operation) */
175 if (win->save_count > 0)
177 g_message ("Waiting for %d file(s) to be saved!", win->save_count);
178 while (win->save_count > 0)
180 g_main_context_iteration (NULL, TRUE);
184 /* Close the profile manager which will emit "descoped" and release
185 * all previous profiles. */
186 anjuta_profile_manager_close (profile_manager);
188 /* If this is the last window we can just quit the application and skip
189 * deactivating plugins and other cleanup. */
190 if (!priv->proper_shutdown &&
191 g_list_length (gtk_application_get_windows (GTK_APPLICATION (app))) == 1)
193 g_application_quit (G_APPLICATION (app));
194 return TRUE;
197 /* Hide the window while unloading all the plugins. */
198 gtk_widget_hide (GTK_WIDGET (win));
199 anjuta_plugin_manager_unload_all_plugins (plugin_manager);
201 return FALSE;
204 static void
205 on_profile_scoped (AnjutaProfile *profile, AnjutaWindow *win)
207 gchar *session_dir;
208 static gboolean first_time = TRUE;
209 AnjutaSession *session;
211 DEBUG_PRINT ("%s", "User profile loaded; Restoring user session");
213 /* If profile scoped to "user", restore user session */
214 session_dir = USER_SESSION_PATH_NEW;
216 session = anjuta_session_new (session_dir);
217 if (first_time)
219 if (g_settings_get_boolean (win->settings, ANJUTA_SESSION_SKIP_LAST))
221 /* Clear session */
222 anjuta_session_clear (session);
224 else if (g_settings_get_boolean (win->settings, ANJUTA_SESSION_SKIP_LAST_FILES))
226 /* Clear files from session */
227 anjuta_session_set_string_list (session, "File Loader",
228 "Files", NULL);
230 first_time = FALSE;
232 else
234 /* Clear the files list since we don't want to load them later */
235 anjuta_session_set_string_list (session, "File Loader",
236 "Files", NULL);
238 anjuta_session_sync (session);
239 g_object_unref (session);
241 /* Restore session */
242 anjuta_shell_session_load (ANJUTA_SHELL (win), session_dir, NULL);
243 g_free (session_dir);
246 static void
247 on_profile_descoped (AnjutaProfile *profile, AnjutaWindow *win)
249 gchar *session_dir;
251 DEBUG_PRINT ("%s", "User profile descoped; Saving user session");
253 /* If profile descoped from is "user", save user session */
254 session_dir = USER_SESSION_PATH_NEW;
256 /* Save current session */
257 anjuta_shell_session_save (ANJUTA_SHELL (win), session_dir, NULL);
258 g_free (session_dir);
261 /* Create hint string.
262 * Pass command line options to primary instance if needed */
263 static gchar *
264 create_anjuta_application_hint (const gchar *geometry,
265 gboolean no_splash,
266 gboolean no_session,
267 gboolean no_files,
268 const gchar *profile)
270 GString *hint;
272 hint = g_string_new (NULL);
273 if (geometry != NULL)
275 g_string_append (hint, ANJUTA_GEOMETRY_HINT);
276 g_string_append (hint, geometry);
278 if (no_splash) g_string_append (hint,ANJUTA_NO_SPLASH_HINT);
279 if (no_session) g_string_append (hint,ANJUTA_NO_SESSION_HINT);
280 if (no_files) g_string_append (hint,ANJUTA_NO_FILES_HINT);
281 if (profile != NULL)
283 g_string_append (hint, ANJUTA_PROFILE_HINT);
284 g_string_append_uri_escaped (hint, profile, NULL, FALSE);
286 g_string_append_c(hint, ';');
288 return g_string_free (hint, FALSE);
291 /* Parse hint string to set flag in primary application */
292 static void
293 anjuta_application_parse_hint (AnjutaApplication *app,
294 const gchar* hint)
296 const gchar *geometry;
297 const gchar *profile;
299 g_free (app->priv->geometry);
300 app->priv->geometry = NULL;
301 geometry = strstr(hint, ANJUTA_GEOMETRY_HINT);
302 if (geometry != NULL)
304 const gchar *end = strstr(geometry + 1, ";");
306 if (end != NULL)
308 geometry += strlen (ANJUTA_GEOMETRY_HINT);
309 app->priv->geometry = g_strndup (geometry, end - geometry);
312 app->priv->no_splash = strstr(hint, ANJUTA_NO_SPLASH_HINT ";") != NULL ? TRUE : FALSE;
313 app->priv->no_session = strstr(hint, ANJUTA_NO_SESSION_HINT ";") != NULL ? TRUE : FALSE;
314 app->priv->no_files = strstr(hint, ANJUTA_NO_FILES_HINT ";") != NULL ? TRUE : FALSE;
315 g_free (app->priv->profile);
316 app->priv->profile = NULL;
317 profile = strstr(hint, ANJUTA_PROFILE_HINT);
318 if (profile != NULL)
320 const gchar *end = strstr(profile + 1, ";");
322 if (end != NULL)
324 profile += strlen (ANJUTA_PROFILE_HINT);
325 app->priv->profile = g_uri_unescape_segment (profile, end, NULL);
330 static void
331 anjuta_application_reset_hint (AnjutaApplication *app)
333 g_free (app->priv->geometry);
334 app->priv->geometry = NULL;
335 app->priv->no_splash = FALSE;
336 app->priv->no_session = FALSE;
337 app->priv->no_files = FALSE;
341 /* GApplication implementation
342 *---------------------------------------------------------------------------*/
344 static gboolean
345 anjuta_application_local_command_line (GApplication *application,
346 gchar ***arguments,
347 gint *exit_status)
349 /* Command line options */
350 gboolean no_splash = FALSE;
351 gboolean no_client = FALSE;
352 gboolean no_session = FALSE;
353 gboolean no_files = FALSE;
354 gboolean version = FALSE;
355 gchar *geometry = NULL;
356 gchar *profile = NULL;
357 gchar **filenames = NULL;
359 const GOptionEntry anjuta_options[] = {
361 "geometry", 'g', 0, G_OPTION_ARG_STRING,
362 &geometry,
363 N_("Specify the size and location of the main window"),
364 /* This is the format you can specify the size andposition
365 * of the window on command line */
366 N_("WIDTHxHEIGHT+XOFF+YOFF")
369 "no-splash", 's', 0, G_OPTION_ARG_NONE,
370 &no_splash,
371 N_("Do not show the splash screen"),
372 NULL
375 "no-client", 'c', 0, G_OPTION_ARG_NONE,
376 &no_client,
377 N_("Start a new instance and do not open the file in an existing instance"),
378 NULL
381 "no-session", 'n', 0, G_OPTION_ARG_NONE,
382 &no_session,
383 N_("Do not open last session on startup"),
384 NULL
387 "no-files", 'f', 0, G_OPTION_ARG_NONE,
388 &no_files,
389 N_("Do not open last project and files on startup"),
390 NULL
393 "proper-shutdown", 'p', 0, G_OPTION_ARG_NONE,
394 &((ANJUTA_APPLICATION (application))->priv->proper_shutdown),
395 N_("Shut down Anjuta properly, releasing all resources (for debugging)"),
396 NULL
399 "version", 'v', 0, G_OPTION_ARG_NONE,
400 &version,
401 N_("Display program version"),
402 NULL
405 "profile", 'P', 0, G_OPTION_ARG_STRING,
406 &profile,
407 N_("Specify another profile"),
408 N_("PROFILE_FILE")
411 G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY,
412 &filenames,
413 NULL,
414 NULL
416 {NULL}
418 GOptionContext *context;
419 gint argc = 0;
420 gchar **argv = NULL;
421 GError *error = NULL;
422 gchar *hint = NULL;
423 GPtrArray *files;
425 context = g_option_context_new (_("- Integrated Development Environment"));
426 #ifdef ENABLE_NLS
427 g_option_context_add_main_entries (context, anjuta_options, GETTEXT_PACKAGE);
428 #else
429 g_option_context_add_main_entries (context, anjuta_options, NULL);
430 #endif
431 g_option_context_add_group (context, gtk_get_option_group (TRUE));
433 /* Parse arguments */
434 argv = *arguments;
435 argc = g_strv_length (argv);
436 if (!g_option_context_parse (context, &argc, &argv, &error))
438 g_printerr ("Could not parse arguments: %s\n", error->message);
439 g_error_free (error);
440 g_option_context_free (context);
442 *exit_status = EXIT_FAILURE;
443 return TRUE;
445 *exit_status = EXIT_SUCCESS;
446 g_option_context_free (context);
449 /* Display version */
450 if (version)
452 g_print ("%s\n", PACKAGE_STRING);
453 return TRUE;
456 /* Set application prefix */
457 if (profile != NULL)
459 gchar *application_id = g_strconcat (g_application_get_application_id (application), "-", profile, NULL);
461 g_application_set_application_id (application, application_id);
462 anjuta_util_set_anjuta_prefix (profile);
463 g_free (application_id);
466 /* Register application */
467 if (no_client) g_application_set_flags (application, G_APPLICATION_NON_UNIQUE | g_application_get_flags (application));
468 g_application_register (G_APPLICATION (application), NULL, NULL);
470 /* Convert all file names to GFile, so an already existing instance of
471 * Anjuta having another current directory can still open the files */
472 files = g_ptr_array_new ();
473 if (filenames)
475 gchar** filename;
477 for (filename = filenames; *filename != NULL; filename++)
479 GFile* file = g_file_new_for_commandline_arg(*filename);
480 if (file != NULL) g_ptr_array_add (files, file);
484 /* Create hint string */
485 hint = create_anjuta_application_hint (geometry, no_splash, no_session, no_files, profile);
487 /* Open files */
488 g_application_open (application, (GFile **)files->pdata, files->len, hint);
489 g_ptr_array_foreach (files, (GFunc)g_object_unref, NULL);
490 g_ptr_array_free (files, TRUE);
491 g_free (hint);
493 return TRUE;
496 static void
497 anjuta_application_open (GApplication *application,
498 GFile **files,
499 gint n_files,
500 const gchar* hint)
502 GList *windows;
503 AnjutaShell *win;
504 IAnjutaFileLoader* loader = NULL;
505 gint i;
507 anjuta_application_parse_hint (ANJUTA_APPLICATION (application), hint);
509 windows = gtk_application_get_windows (GTK_APPLICATION (application));
510 if (windows == NULL)
512 if (n_files == 0)
514 win = ANJUTA_SHELL (anjuta_application_create_window (ANJUTA_APPLICATION (application)));
516 else
518 gboolean no_files = ANJUTA_APPLICATION (application)->priv->no_files;
519 ANJUTA_APPLICATION (application)->priv->no_files = TRUE;
520 win = ANJUTA_SHELL (anjuta_application_create_window (ANJUTA_APPLICATION (application)));
521 ANJUTA_APPLICATION (application)->priv->no_files = no_files;
524 else
526 if (n_files == 0)
528 gboolean no_files = ANJUTA_APPLICATION (application)->priv->no_files;
529 ANJUTA_APPLICATION (application)->priv->no_files = TRUE;
530 win = ANJUTA_SHELL (anjuta_application_create_window (ANJUTA_APPLICATION (application)));
531 ANJUTA_APPLICATION (application)->priv->no_files = no_files;
533 else
535 win = ANJUTA_SHELL (windows->data);
539 if (win != NULL)
541 loader = anjuta_shell_get_interface(win, IAnjutaFileLoader, NULL);
543 if (!loader)
544 return;
546 for (i = 0; i < n_files; i++)
548 ianjuta_file_loader_load(loader, files[i], FALSE, NULL);
551 anjuta_application_reset_hint (ANJUTA_APPLICATION (application));
554 static GActionEntry app_entries[] = {
555 { "preferences", on_app_preferences, NULL, NULL, NULL },
556 { "help", on_app_manual, NULL, NULL, NULL },
557 { "about", on_app_about, NULL, NULL, NULL },
558 { "quit", on_app_quit, NULL, NULL, NULL }
561 static void
562 anjuta_application_startup (GApplication* application)
564 AnjutaApplication *app = ANJUTA_APPLICATION (application);
565 GtkBuilder *builder;
566 GError *error = NULL;
567 GtkSettings* settings = gtk_settings_get_default ();
568 gboolean has_app_menu;
571 #ifdef ENABLE_NLS
572 setlocale (LC_ALL, "");
573 bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
574 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
575 textdomain (GETTEXT_PACKAGE);
576 #endif
578 G_APPLICATION_CLASS (anjuta_application_parent_class)->startup (application);
580 g_object_get (G_OBJECT (settings),
581 "gtk-shell-shows-app-menu", &has_app_menu,
582 NULL);
583 if (has_app_menu)
585 g_action_map_add_action_entries (G_ACTION_MAP (app),
586 app_entries,
587 G_N_ELEMENTS (app_entries),
588 app);
590 builder = gtk_builder_new ();
591 if (!gtk_builder_add_from_file (builder,
592 ANJUTA_MENU_UI_FILE,
593 &error))
595 g_warning ("loading menu builder file: %s", error->message);
596 g_error_free (error);
598 else
600 GMenuModel *app_menu;
602 app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
603 gtk_application_set_app_menu (GTK_APPLICATION (application),
604 app_menu);
607 g_object_unref (builder);
611 /* GObject implementation
612 *---------------------------------------------------------------------------*/
614 static void
615 anjuta_application_finalize (GObject *object)
617 AnjutaApplication *app = ANJUTA_APPLICATION (object);
619 if (app->priv->geometry != NULL)
621 g_free (app->priv->geometry);
622 app->priv->geometry = NULL;
624 G_OBJECT_CLASS (anjuta_application_parent_class)->finalize (object);
627 static void
628 anjuta_application_init (AnjutaApplication *application)
630 application->priv = G_TYPE_INSTANCE_GET_PRIVATE (application,
631 ANJUTA_TYPE_APPLICATION,
632 AnjutaApplicationPrivate);
633 application->priv->proper_shutdown = FALSE;
634 application->priv->no_files = FALSE;
635 application->priv->no_session = FALSE;
636 application->priv->no_splash = FALSE;
637 application->priv->geometry = NULL;
640 static void
641 anjuta_application_class_init (AnjutaApplicationClass *klass)
643 GObjectClass* object_class = G_OBJECT_CLASS (klass);
644 GApplicationClass* app_class = G_APPLICATION_CLASS (klass);
646 object_class->finalize = anjuta_application_finalize;
648 app_class->open = anjuta_application_open;
649 app_class->local_command_line = anjuta_application_local_command_line;
650 app_class->startup = anjuta_application_startup;
652 g_type_class_add_private (klass, sizeof (AnjutaApplicationPrivate));
657 /* Public functions
658 *---------------------------------------------------------------------------*/
660 AnjutaApplication*
661 anjuta_application_new (void)
663 g_type_init ();
665 return g_object_new (anjuta_application_get_type (),
666 "application-id", "org.gnome.anjuta",
667 "flags", G_APPLICATION_HANDLES_OPEN,
668 NULL);
671 gboolean
672 anjuta_application_get_proper_shutdown (AnjutaApplication *app)
674 return app->priv->proper_shutdown;
677 gboolean
678 anjuta_application_get_no_files (AnjutaApplication *app)
680 return app->priv->no_files;
683 gboolean
684 anjuta_application_get_no_session (AnjutaApplication *app)
686 return app->priv->no_session;
689 const gchar *
690 anjuta_application_get_geometry (AnjutaApplication *app)
692 return app->priv->geometry;
695 AnjutaWindow*
696 anjuta_application_create_window (AnjutaApplication *app)
698 AnjutaPluginManager *plugin_manager;
699 AnjutaProfileManager *profile_manager;
700 AnjutaWindow *win;
701 AnjutaStatus *status;
702 AnjutaProfile *profile;
703 gchar *profile_filename;
704 GFile *profile_directory;
705 GFile *session_profile;
706 gchar *remembered_plugins;
707 GError *error = NULL;
709 /* Initialize application */
710 win = ANJUTA_WINDOW (anjuta_window_new (GTK_APPLICATION(app)));
711 gtk_application_window_set_show_menubar (GTK_APPLICATION_WINDOW(win),
712 FALSE);
713 gtk_application_add_window (GTK_APPLICATION (app), GTK_WINDOW (win));
714 status = anjuta_shell_get_status (ANJUTA_SHELL (win), NULL);
715 anjuta_status_progress_add_ticks (status, 1);
717 gtk_window_set_role (GTK_WINDOW (win), "anjuta-app");
718 gtk_window_set_auto_startup_notification(TRUE);
719 gtk_window_set_default_icon_name ("anjuta");
720 gtk_window_set_auto_startup_notification(FALSE);
722 if (app->priv->no_splash)
724 anjuta_status_disable_splash (status, TRUE);
726 else
728 gchar *im_file = NULL;
729 im_file = anjuta_res_get_pixmap_file (ANJUTA_PIXMAP_SPLASH_SCREEN);
730 if (im_file)
732 anjuta_status_set_splash (status, im_file, 100);
733 g_free (im_file);
737 g_signal_connect (G_OBJECT (win), "delete_event",
738 G_CALLBACK (on_anjuta_delete_event), app);
740 /* Setup application framework */
741 plugin_manager = anjuta_shell_get_plugin_manager (ANJUTA_SHELL (win),
742 NULL);
743 profile_manager = anjuta_shell_get_profile_manager (ANJUTA_SHELL (win),
744 NULL);
746 /* Restore remembered plugins */
747 remembered_plugins =
748 g_settings_get_string (win->settings, ANJUTA_REMEMBERED_PLUGINS);
749 if (remembered_plugins)
750 anjuta_plugin_manager_set_remembered_plugins (plugin_manager,
751 remembered_plugins);
752 g_free (remembered_plugins);
754 /* Prepare system profile */
755 profile = anjuta_profile_new (ANJUTA_SYSTEM_PROFILE_NAME, plugin_manager);
756 profile_filename = app->priv->profile == NULL ? DEFAULT_PROFILE : g_strconcat(app->priv->profile, ".profile", NULL);
757 profile_directory = g_file_new_for_uri (PROFILE_DIRECTORY);
758 session_profile = g_file_get_child(profile_directory, profile_filename);
759 g_object_unref(profile_directory);
760 anjuta_profile_add_plugins_from_xml (profile, session_profile,
761 TRUE, &error);
762 if (error)
764 anjuta_util_dialog_error (GTK_WINDOW (win), _("Invalid profile %s: %s"), g_file_get_path (session_profile), error->message);
766 g_error_free (error);
767 error = NULL;
769 g_object_unref (session_profile);
770 anjuta_profile_manager_freeze (profile_manager);
771 anjuta_profile_manager_push (profile_manager, profile, &error);
772 if (error)
774 anjuta_util_dialog_error (GTK_WINDOW (win), "%s", error->message);
775 g_error_free (error);
776 error = NULL;
779 /* Prepare user profile */
780 profile = anjuta_profile_new (USER_PROFILE_NAME, plugin_manager);
781 session_profile = anjuta_util_get_user_cache_file (profile_filename, NULL);
782 if (g_file_query_exists (session_profile, NULL))
784 anjuta_profile_add_plugins_from_xml (profile, session_profile,
785 FALSE, &error);
786 if (error)
788 anjuta_util_dialog_error (GTK_WINDOW (win), "%s", error->message);
789 g_error_free (error);
790 error = NULL;
793 anjuta_profile_set_sync_file (profile, session_profile);
794 g_object_unref (session_profile);
795 if (profile_filename != DEFAULT_PROFILE) g_free (profile_filename);
797 /* Load profile */
798 anjuta_profile_manager_push (profile_manager, profile, &error);
799 if (error)
801 anjuta_util_dialog_error (GTK_WINDOW (win), "%s", error->message);
802 g_error_free (error);
803 error = NULL;
806 /* Prepare for session save and load on profile change */
807 g_signal_connect (profile, "scoped", G_CALLBACK (on_profile_scoped), win);
808 anjuta_profile_manager_thaw (profile_manager, &error);
810 if (error)
812 anjuta_util_dialog_error (GTK_WINDOW (win), "%s", error->message);
813 g_error_free (error);
814 error = NULL;
816 g_signal_connect (profile, "descoped", G_CALLBACK (on_profile_descoped), win);
818 anjuta_status_progress_tick (status, NULL, _("Loaded Session…"));
819 anjuta_status_disable_splash (status, TRUE);
821 return win;