void gimp_fonts_load (Gimp *gimp) { FcConfig *config; GFile *fonts_conf; GList *path; g_return_if_fail (GIMP_IS_FONT_LIST (gimp->fonts)); gimp_set_busy (gimp); if (gimp->be_verbose) g_print ("Loading fonts\n"); gimp_container_freeze (GIMP_CONTAINER (gimp->fonts)); gimp_container_clear (GIMP_CONTAINER (gimp->fonts)); config = FcInitLoadConfig (); if (! config) goto cleanup; fonts_conf = gimp_directory_file (CONF_FNAME, NULL); if (! gimp_fonts_load_fonts_conf (config, fonts_conf)) goto cleanup; fonts_conf = gimp_sysconf_directory_file (CONF_FNAME, NULL); if (! gimp_fonts_load_fonts_conf (config, fonts_conf)) goto cleanup; path = gimp_config_path_expand_to_files (gimp->config->font_path, FALSE); gimp_fonts_add_directories (config, path); g_list_free_full (path, (GDestroyNotify) g_object_unref); if (! FcConfigBuildFonts (config)) { FcConfigDestroy (config); goto cleanup; } FcConfigSetCurrent (config); gimp_font_list_restore (GIMP_FONT_LIST (gimp->fonts)); cleanup: gimp_container_thaw (GIMP_CONTAINER (gimp->fonts)); gimp_unset_busy (gimp); }
void gimp_templates_load (Gimp *gimp) { GFile *file; GError *error = NULL; g_return_if_fail (GIMP_IS_GIMP (gimp)); g_return_if_fail (GIMP_IS_LIST (gimp->templates)); file = gimp_directory_file ("templaterc", NULL); if (gimp->be_verbose) g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file)); if (! gimp_config_deserialize_gfile (GIMP_CONFIG (gimp->templates), file, NULL, &error)) { if (error->code == GIMP_CONFIG_ERROR_OPEN_ENOENT) { g_clear_error (&error); g_object_unref (file); file = gimp_sysconf_directory_file ("templaterc", NULL); if (! gimp_config_deserialize_gfile (GIMP_CONFIG (gimp->templates), file, NULL, &error)) { gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message); } } else { gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message); } g_clear_error (&error); } gimp_list_reverse (GIMP_LIST (gimp->templates)); g_object_unref (file); }
static void gimp_rc_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { GimpRc *rc = GIMP_RC (object); switch (property_id) { case PROP_VERBOSE: rc->verbose = g_value_get_boolean (value); break; case PROP_SYSTEM_GIMPRC: if (rc->system_gimprc) g_object_unref (rc->system_gimprc); if (g_value_get_object (value)) rc->system_gimprc = g_value_dup_object (value); else rc->system_gimprc = gimp_sysconf_directory_file ("gimprc", NULL); break; case PROP_USER_GIMPRC: if (rc->user_gimprc) g_object_unref (rc->user_gimprc); if (g_value_get_object (value)) rc->user_gimprc = g_value_dup_object (value); else rc->user_gimprc = gimp_directory_file ("gimprc", NULL); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } }
void gimp_unitrc_load (Gimp *gimp) { GFile *file; GScanner *scanner; GTokenType token; GError *error = NULL; g_return_if_fail (GIMP_IS_GIMP (gimp)); file = gimp_directory_file ("unitrc", NULL); if (gimp->be_verbose) g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file)); scanner = gimp_scanner_new_gfile (file, &error); if (! scanner && error->code == GIMP_CONFIG_ERROR_OPEN_ENOENT) { g_clear_error (&error); g_object_unref (file); file = gimp_sysconf_directory_file ("unitrc", NULL); scanner = gimp_scanner_new_gfile (file, NULL); } if (! scanner) { g_clear_error (&error); g_object_unref (file); return; } g_scanner_scope_add_symbol (scanner, 0, "unit-info", GINT_TO_POINTER (UNIT_INFO)); g_scanner_scope_add_symbol (scanner, UNIT_INFO, "factor", GINT_TO_POINTER (UNIT_FACTOR)); g_scanner_scope_add_symbol (scanner, UNIT_INFO, "digits", GINT_TO_POINTER (UNIT_DIGITS)); g_scanner_scope_add_symbol (scanner, UNIT_INFO, "symbol", GINT_TO_POINTER (UNIT_SYMBOL)); g_scanner_scope_add_symbol (scanner, UNIT_INFO, "abbreviation", GINT_TO_POINTER (UNIT_ABBREV)); g_scanner_scope_add_symbol (scanner, UNIT_INFO, "singular", GINT_TO_POINTER (UNIT_SINGULAR)); g_scanner_scope_add_symbol (scanner, UNIT_INFO, "plural", GINT_TO_POINTER (UNIT_PLURAL)); 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 (UNIT_INFO)) { g_scanner_set_scope (scanner, UNIT_INFO); token = gimp_unitrc_unit_info_deserialize (scanner, gimp); if (token == G_TOKEN_RIGHT_PAREN) g_scanner_set_scope (scanner, 0); } 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); gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message); g_clear_error (&error); gimp_config_file_backup_on_error (file, "unitrc", NULL); } gimp_scanner_destroy (scanner); g_object_unref (file); }
void session_init (Gimp *gimp) { GFile *file; GScanner *scanner; GTokenType token; GError *error = NULL; g_return_if_fail (GIMP_IS_GIMP (gimp)); file = session_file (gimp); scanner = gimp_scanner_new_gfile (file, &error); if (! scanner && error->code == GIMP_CONFIG_ERROR_OPEN_ENOENT) { g_clear_error (&error); g_object_unref (file); file = gimp_sysconf_directory_file ("sessionrc", NULL); scanner = gimp_scanner_new_gfile (file, NULL); } if (! scanner) { g_clear_error (&error); g_object_unref (file); return; } if (gimp->be_verbose) g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file)); 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, "show-tabs", GINT_TO_POINTER (SHOW_TABS)); g_scanner_scope_add_symbol (scanner, 0, "tabs-position", GINT_TO_POINTER (TABS_POSITION)); 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); /* set token to left paren to we won't set another * error below, gimp_config_deserialize() already did */ token = G_TOKEN_LEFT_PAREN; goto error; } } 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 (SHOW_TABS)) { gboolean show_tabs; token = G_TOKEN_IDENTIFIER; if (! gimp_scanner_parse_boolean (scanner, &show_tabs)) break; g_object_set (gimp->config, "show-tabs", show_tabs, NULL); } else if (scanner->value.v_symbol == GINT_TO_POINTER (TABS_POSITION)) { gint tabs_position; token = G_TOKEN_INT; if (! gimp_scanner_parse_int (scanner, &tabs_position)) break; g_object_set (gimp->config, "tabs-position", tabs_position, 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; } } error: 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 (file, "sessionrc", NULL); } gimp_scanner_destroy (scanner); g_object_unref (file); dialogs_load_recent_docks (gimp); }
void gimp_fonts_load (Gimp *gimp, GimpInitStatusFunc status_callback) { FcConfig *config; GFile *fonts_conf; GList *path; g_return_if_fail (GIMP_IS_FONT_LIST (gimp->fonts)); gimp_set_busy (gimp); if (gimp->be_verbose) g_print ("Loading fonts\n"); gimp_container_freeze (GIMP_CONTAINER (gimp->fonts)); gimp_container_clear (GIMP_CONTAINER (gimp->fonts)); config = FcInitLoadConfig (); if (! config) goto cleanup; fonts_conf = gimp_directory_file (CONF_FNAME, NULL); if (! gimp_fonts_load_fonts_conf (config, fonts_conf)) goto cleanup; fonts_conf = gimp_sysconf_directory_file (CONF_FNAME, NULL); if (! gimp_fonts_load_fonts_conf (config, fonts_conf)) goto cleanup; path = gimp_config_path_expand_to_files (gimp->config->font_path, FALSE); gimp_fonts_add_directories (config, path); g_list_free_full (path, (GDestroyNotify) g_object_unref); if (status_callback) { gint64 end_time; GThread *cache_thread; GimpFontsLoadFuncData data; /* We perform font cache initialization in a separate thread, so * in the case a cache rebuild is to be done it will not block * the UI. */ data.config = config; g_mutex_init (&data.mutex); g_cond_init (&data.cond); data.caching_complete = FALSE; cache_thread = g_thread_new ("font-cacher", (GThreadFunc) gimp_fonts_load_thread, &data); g_mutex_lock (&data.mutex); end_time = g_get_monotonic_time () + 0.1 * G_TIME_SPAN_SECOND; while (! data.caching_complete) if (! g_cond_wait_until (&data.cond, &data.mutex, end_time)) { status_callback (NULL, NULL, 0.6); end_time += 0.1 * G_TIME_SPAN_SECOND; continue; } g_mutex_unlock (&data.mutex); g_thread_join (cache_thread); g_mutex_clear (&data.mutex); g_cond_clear (&data.cond); } else { gimp_fonts_load_func (config); } gimp_font_list_restore (GIMP_FONT_LIST (gimp->fonts)); cleanup: gimp_container_thaw (GIMP_CONTAINER (gimp->fonts)); gimp_unset_busy (gimp); }