void session_init (Gimp *gimp) { gchar *filename; GScanner *scanner; GTokenType token; GError *error = NULL; g_return_if_fail (GIMP_IS_GIMP (gimp)); filename = session_filename (gimp); scanner = gimp_scanner_new_file (filename, &error); if (! scanner && error->code == GIMP_CONFIG_ERROR_OPEN_ENOENT) { g_clear_error (&error); g_free (filename); filename = g_build_filename (gimp_sysconf_directory (), "sessionrc", NULL); scanner = gimp_scanner_new_file (filename, NULL); } if (! scanner) { g_clear_error (&error); g_free (filename); return; } if (gimp->be_verbose) g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename)); g_scanner_scope_add_symbol (scanner, 0, "session-info", GINT_TO_POINTER (SESSION_INFO)); g_scanner_scope_add_symbol (scanner, 0, "hide-docks", GINT_TO_POINTER (HIDE_DOCKS)); g_scanner_scope_add_symbol (scanner, 0, "single-window-mode", GINT_TO_POINTER (SINGLE_WINDOW_MODE)); g_scanner_scope_add_symbol (scanner, 0, "last-tip-shown", GINT_TO_POINTER (LAST_TIP_SHOWN)); token = G_TOKEN_LEFT_PAREN; while (g_scanner_peek_next_token (scanner) == token) { token = g_scanner_get_next_token (scanner); switch (token) { case G_TOKEN_LEFT_PAREN: token = G_TOKEN_SYMBOL; break; case G_TOKEN_SYMBOL: if (scanner->value.v_symbol == GINT_TO_POINTER (SESSION_INFO)) { GimpDialogFactory *factory = NULL; GimpSessionInfo *info = NULL; gchar *factory_name = NULL; gchar *entry_name = NULL; GimpDialogFactoryEntry *entry = NULL; token = G_TOKEN_STRING; if (! gimp_scanner_parse_string (scanner, &factory_name)) break; /* In versions <= GIMP 2.6 there was a "toolbox", a * "dock", a "display" and a "toplevel" factory. These * are now merged to a single gimp_dialog_factory_get_singleton (). We * need the legacy name though, so keep it around. */ factory = gimp_dialog_factory_get_singleton (); info = gimp_session_info_new (); /* GIMP 2.6 has the entry name as part of the * session-info header, so try to get it */ gimp_scanner_parse_string (scanner, &entry_name); if (entry_name) { /* Previously, GimpDock was a toplevel. That is why * versions <= GIMP 2.6 has "dock" as the entry name. We * want "dock" to be interpreted as 'dock window' * however so have some special-casing for that. When * the entry name is "dock" the factory name is either * "dock" or "toolbox". */ if (strcmp (entry_name, "dock") == 0) { entry = gimp_dialog_factory_find_entry (factory, (strcmp (factory_name, "toolbox") == 0 ? "gimp-toolbox-window" : "gimp-dock-window")); } else { entry = gimp_dialog_factory_find_entry (factory, entry_name); } } /* We're done with these now */ g_free (factory_name); g_free (entry_name); /* We can get the factory entry either now (the GIMP <= * 2.6 way), or when we deserialize (the GIMP 2.8 way) */ if (entry) { gimp_session_info_set_factory_entry (info, entry); } /* Always try to deserialize */ if (gimp_config_deserialize (GIMP_CONFIG (info), scanner, 1, NULL)) { /* Make sure we got a factory entry either the 2.6 * or 2.8 way */ if (gimp_session_info_get_factory_entry (info)) { GIMP_LOG (DIALOG_FACTORY, "successfully parsed and added session info %p", info); gimp_dialog_factory_add_session_info (factory, info); } else { GIMP_LOG (DIALOG_FACTORY, "failed to parse session info %p, not adding", info); } g_object_unref (info); } else { g_object_unref (info); break; } } else if (scanner->value.v_symbol == GINT_TO_POINTER (HIDE_DOCKS)) { gboolean hide_docks; token = G_TOKEN_IDENTIFIER; if (! gimp_scanner_parse_boolean (scanner, &hide_docks)) break; g_object_set (gimp->config, "hide-docks", hide_docks, NULL); } else if (scanner->value.v_symbol == GINT_TO_POINTER (SINGLE_WINDOW_MODE)) { gboolean single_window_mode; token = G_TOKEN_IDENTIFIER; if (! gimp_scanner_parse_boolean (scanner, &single_window_mode)) break; g_object_set (gimp->config, "single-window-mode", single_window_mode, NULL); } else if (scanner->value.v_symbol == GINT_TO_POINTER (LAST_TIP_SHOWN)) { gint last_tip_shown; token = G_TOKEN_INT; if (! gimp_scanner_parse_int (scanner, &last_tip_shown)) break; g_object_set (gimp->config, "last-tip-shown", last_tip_shown, NULL); } token = G_TOKEN_RIGHT_PAREN; break; case G_TOKEN_RIGHT_PAREN: token = G_TOKEN_LEFT_PAREN; break; default: /* do nothing */ break; } } if (token != G_TOKEN_LEFT_PAREN) { g_scanner_get_next_token (scanner); g_scanner_unexp_token (scanner, token, NULL, NULL, NULL, _("fatal parse error"), TRUE); } if (error) { gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message); g_clear_error (&error); gimp_config_file_backup_on_error (filename, "sessionrc", NULL); } gimp_scanner_destroy (scanner); g_free (filename); dialogs_load_recent_docks (gimp); }
void gimp_dialog_factory_add_dialog (GimpDialogFactory *factory, GtkWidget *dialog) { GimpDialogFactory *dialog_factory; GimpDialogFactoryEntry *entry; GimpSessionInfo *info; GList *list; gboolean toplevel; g_return_if_fail (GIMP_IS_DIALOG_FACTORY (factory)); g_return_if_fail (GTK_IS_WIDGET (dialog)); if (g_list_find (factory->open_dialogs, dialog)) { g_warning ("%s: dialog already registered", G_STRFUNC); return; } dialog_factory = gimp_dialog_factory_from_widget (dialog, &entry); if (! (dialog_factory && (entry || GIMP_IS_DOCK (dialog)))) { g_warning ("%s: dialog was not created by a GimpDialogFactory", G_STRFUNC); return; } if (dialog_factory != factory) { g_warning ("%s: dialog was created by a different GimpDialogFactory", G_STRFUNC); return; } toplevel = GTK_WIDGET_TOPLEVEL (dialog); if (entry) /* dialog is a toplevel (but not a GimpDock) or a GimpDockable */ { D (g_print ("%s: adding %s \"%s\"\n", G_STRFUNC, toplevel ? "toplevel" : "dockable", entry->identifier)); for (list = factory->session_infos; list; list = g_list_next (list)) { info = list->data; if ((info->toplevel_entry == entry) || (info->dockable_entry == entry)) { if (info->widget) { if (entry->singleton) { g_warning ("%s: singleton dialog \"%s\" created twice", G_STRFUNC, entry->identifier); D (g_print ("%s: corrupt session info: %p (widget %p)\n", G_STRFUNC, info, info->widget)); return; } continue; } info->widget = dialog; D (g_print ("%s: updating session info %p (widget %p) for %s \"%s\"\n", G_STRFUNC, info, info->widget, toplevel ? "toplevel" : "dockable", entry->identifier)); if (toplevel && entry->session_managed) gimp_session_info_set_geometry (info); break; } } if (! list) /* didn't find a session info */ { info = gimp_session_info_new (); info->widget = dialog; D (g_print ("%s: creating session info %p (widget %p) for %s \"%s\"\n", G_STRFUNC, info, info->widget, toplevel ? "toplevel" : "dockable", entry->identifier)); if (toplevel) { info->toplevel_entry = entry; /* if we create a new session info, we never call * gimp_session_info_set_geometry(), but still the * dialog needs GDK_HINT_USER_POS so it keeps its * position when hidden/shown within this(!) session. */ if (entry->session_managed) g_signal_connect (dialog, "configure-event", G_CALLBACK (gimp_dialog_factory_set_user_pos), NULL); } else { info->dockable_entry = entry; } factory->session_infos = g_list_append (factory->session_infos, info); } } else /* dialog is a GimpDock */ { D (g_print ("%s: adding dock\n", G_STRFUNC)); for (list = factory->session_infos; list; list = g_list_next (list)) { info = list->data; /* take the first empty slot */ if (! info->toplevel_entry && ! info->dockable_entry && ! info->widget) { info->widget = dialog; D (g_print ("%s: updating session info %p (widget %p) for dock\n", G_STRFUNC, info, info->widget)); gimp_session_info_set_geometry (info); break; } } if (! list) /* didn't find a session info */ { info = gimp_session_info_new (); info->widget = dialog; D (g_print ("%s: creating session info %p (widget %p) for dock\n", G_STRFUNC, info, info->widget)); /* if we create a new session info, we never call * gimp_session_info_set_geometry(), but still the * dialog needs GDK_HINT_USER_POS so it keeps its * position when hidden/shown within this(!) session. */ g_signal_connect (dialog, "configure-event", G_CALLBACK (gimp_dialog_factory_set_user_pos), NULL); factory->session_infos = g_list_append (factory->session_infos, info); } } factory->open_dialogs = g_list_prepend (factory->open_dialogs, dialog); g_signal_connect_object (dialog, "destroy", G_CALLBACK (gimp_dialog_factory_remove_dialog), factory, G_CONNECT_SWAPPED); if (entry && entry->session_managed && toplevel) g_signal_connect_object (dialog, "configure-event", G_CALLBACK (gimp_dialog_factory_dialog_configure), factory, 0); }