static gchar * gimp_plug_in_manager_get_pluginrc (GimpPlugInManager *manager) { Gimp *gimp = manager->gimp; gchar *pluginrc; if (gimp->config->plug_in_rc_path) { pluginrc = gimp_config_path_expand (gimp->config->plug_in_rc_path, TRUE, NULL); if (! g_path_is_absolute (pluginrc)) { gchar *str = g_build_filename (gimp_directory (), pluginrc, NULL); g_free (pluginrc); pluginrc = str; } } else { pluginrc = gimp_personal_rc_file ("pluginrc"); } return pluginrc; }
GFile * gimp_get_temp_file (Gimp *gimp, const gchar *extension) { static gint id = 0; static gint pid; gchar *basename; gchar *path; GFile *dir; GFile *file; g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); if (id == 0) pid = gimp_get_pid (); if (extension) basename = g_strdup_printf ("gimp-temp-%d%d.%s", pid, id++, extension); else basename = g_strdup_printf ("gimp-temp-%d%d", pid, id++); path = gimp_config_path_expand (GIMP_GEGL_CONFIG (gimp->config)->temp_path, TRUE, NULL); dir = g_file_new_for_path (path); g_free (path); file = g_file_get_child (dir, basename); g_free (basename); g_object_unref (dir); return file; }
static GFile * gimp_plug_in_manager_get_pluginrc (GimpPlugInManager *manager) { Gimp *gimp = manager->gimp; GFile *pluginrc; if (gimp->config->plug_in_rc_path) { gchar *path; path = gimp_config_path_expand (gimp->config->plug_in_rc_path, TRUE, NULL); if (! g_path_is_absolute (path)) { gchar *str = g_build_filename (gimp_directory (), path, NULL); g_free (path); path = str; } pluginrc = g_file_new_for_path (path); g_free (path); } else { pluginrc = gimp_personal_rc_gfile ("pluginrc"); } return pluginrc; }
static void base_toast_old_swap_files (const gchar *swap_path) { GDir *dir = NULL; gchar *dirname; const char *entry; if (! swap_path) return; dirname = gimp_config_path_expand (swap_path, TRUE, NULL); if (!dirname) return; dir = g_dir_open (dirname, 0, NULL); if (!dir) { g_free (dirname); return; } while ((entry = g_dir_read_name (dir)) != NULL) if (g_str_has_prefix (entry, "gimpswap.")) { /* don't try to kill swap files of running processes * yes, I know they might not all be gimp processes, and when you * unlink, it's refcounted, but lets not confuse the user by * "where did my disk space go?" cause the filename is gone * if the kill succeeds, and there running process isn't gimp * we'll probably get it the next time around */ gint pid = atoi (entry + 9); /* On Windows, you can't remove open files anyhow, * so no harm trying. */ #ifndef G_OS_WIN32 if (kill (pid, 0)) #endif { gchar *filename = g_build_filename (dirname, entry, NULL); g_unlink (filename); g_free (filename); } } g_dir_close (dir); g_free (dirname); }
gboolean base_init (GimpBaseConfig *config, gboolean be_verbose, gboolean use_cpu_accel) { gboolean swap_is_ok; gchar *temp_dir; g_return_val_if_fail (GIMP_IS_BASE_CONFIG (config), FALSE); g_return_val_if_fail (base_config == NULL, FALSE); base_config = g_object_ref (config); tile_cache_init (config->tile_cache_size); g_signal_connect (config, "notify::tile-cache-size", G_CALLBACK (base_tile_cache_size_notify), NULL); if (! config->swap_path || ! *config->swap_path) gimp_config_reset_property (G_OBJECT (config), "swap-path"); base_toast_old_swap_files (config->swap_path); tile_swap_init (config->swap_path); swap_is_ok = tile_swap_test (); /* create the temp directory if it doesn't exist */ if (! config->temp_path || ! *config->temp_path) gimp_config_reset_property (G_OBJECT (config), "temp-path"); temp_dir = gimp_config_path_expand (config->temp_path, TRUE, NULL); if (! g_file_test (temp_dir, G_FILE_TEST_EXISTS)) g_mkdir_with_parents (temp_dir, S_IRUSR | S_IXUSR | S_IWUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); g_free (temp_dir); pixel_processor_init (config->num_processors); g_signal_connect (config, "notify::num-processors", G_CALLBACK (base_num_processors_notify), NULL); gimp_composite_init (be_verbose, use_cpu_accel); paint_funcs_setup (); return swap_is_ok; }
void gimp_modules_refresh (Gimp *gimp) { g_return_if_fail (GIMP_IS_GIMP (gimp)); if (! gimp->no_interface) { gchar *path; path = gimp_config_path_expand (gimp->config->module_path, TRUE, NULL); gimp_module_db_refresh (gimp->module_db, path); g_free (path); } }
void gimp_fonts_load (Gimp *gimp) { FcConfig *config; gchar *fonts_conf; gchar *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_personal_rc_file (CONF_FNAME); if (! gimp_fonts_load_fonts_conf (config, fonts_conf)) goto cleanup; fonts_conf = g_build_filename (gimp_sysconf_directory (), CONF_FNAME, NULL); if (! gimp_fonts_load_fonts_conf (config, fonts_conf)) goto cleanup; path = gimp_config_path_expand (gimp->config->font_path, TRUE, NULL); gimp_fonts_add_directories (config, path); g_free (path); 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); }
/* search for binaries in the plug-in directory path */ static void gimp_plug_in_manager_search (GimpPlugInManager *manager, GimpInitStatusFunc status_callback) { gchar *path; const gchar *pathext = g_getenv ("PATHEXT"); /* If PATHEXT is set, we are likely on Windows and need to add * the known file extensions. */ if (pathext) { gchar *exts; exts = gimp_interpreter_db_get_extensions (manager->interpreter_db); if (exts) { gchar *value; value = g_strconcat (pathext, G_SEARCHPATH_SEPARATOR_S, exts, NULL); g_setenv ("PATHEXT", value, TRUE); g_free (value); g_free (exts); } } status_callback (_("Searching Plug-Ins"), "", 0.0); /* Give automatic tests a chance to use plug-ins from the build * dir */ path = g_strdup(g_getenv("GIMP_TESTING_PLUGINDIRS")); if (! path) path = gimp_config_path_expand (manager->gimp->config->plug_in_path, TRUE, NULL); gimp_datafiles_read_directories (path, G_FILE_TEST_IS_EXECUTABLE, gimp_plug_in_manager_add_from_file, manager); g_free (path); }
static void shooter_ensure_modules (void) { static GimpModuleDB *module_db = NULL; if (! module_db) { gchar *config = gimp_config_build_plug_in_path ("modules"); gchar *path = gimp_config_path_expand (config, TRUE, NULL); module_db = gimp_module_db_new (FALSE); gimp_module_db_load (module_db, path); g_free (path); g_free (config); } }
static GTokenType gimp_config_deserialize_file_value (GValue *value, GParamSpec *prop_spec, GScanner *scanner) { GTokenType token; token = g_scanner_peek_next_token (scanner); if (token != G_TOKEN_IDENTIFIER && token != G_TOKEN_STRING) { return G_TOKEN_STRING; } g_scanner_get_next_token (scanner); if (token == G_TOKEN_IDENTIFIER) { /* this is supposed to parse a literal "NULL" only, but so what... */ g_value_set_object (value, NULL); } else { gchar *path = gimp_config_path_expand (scanner->value.v_string, TRUE, NULL); if (path) { GFile *file = g_file_new_for_path (path); g_value_take_object (value, file); g_free (path); } else { g_value_set_object (value, NULL); } } return G_TOKEN_RIGHT_PAREN; }
static GTokenType gimp_config_deserialize_path (GValue *value, GParamSpec *prop_spec, GScanner *scanner) { GError *error = NULL; if (g_scanner_peek_next_token (scanner) != G_TOKEN_STRING) return G_TOKEN_STRING; g_scanner_get_next_token (scanner); if (!scanner_string_utf8_valid (scanner, prop_spec->name)) return G_TOKEN_NONE; if (scanner->value.v_string) { /* Check if the string can be expanded * and converted to the filesystem encoding. */ gchar *expand = gimp_config_path_expand (scanner->value.v_string, TRUE, &error); if (!expand) { g_scanner_error (scanner, _("while parsing token '%s': %s"), prop_spec->name, error->message); g_error_free (error); return G_TOKEN_NONE; } g_free (expand); g_value_set_static_string (value, scanner->value.v_string); } return G_TOKEN_RIGHT_PAREN; }
/* This function is memoized. Once it finds the value it permanently * caches it * */ GList * parsepath (void) { gchar *rc_path, *path; if (parsepath_cached_path) return parsepath_cached_path; path = gimp_gimprc_query ("gimpressionist-path"); if (path) { rc_path = g_filename_from_utf8 (path, -1, NULL, NULL, NULL); g_free (path); } else { gchar *gimprc = gimp_personal_rc_file ("gimprc"); gchar *full_path = gimp_config_build_data_path ("gimpressionist"); gchar *esc_path = g_strescape (full_path, NULL); g_message (_("No %s in gimprc:\n" "You need to add an entry like\n" "(%s \"%s\")\n" "to your %s file."), "gflare-path", "gflare-path", esc_path, gimp_filename_to_utf8 (gimprc)); g_free (gimprc); g_free (esc_path); rc_path = gimp_config_path_expand (full_path, TRUE, NULL); g_free (full_path); } parsepath_cached_path = gimp_path_parse (rc_path, 16, FALSE, NULL); g_free (rc_path); return parsepath_cached_path; }
void themes_init (Gimp *gimp) { GimpGuiConfig *config; gchar *themerc; g_return_if_fail (GIMP_IS_GIMP (gimp)); config = GIMP_GUI_CONFIG (gimp->config); themes_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); if (config->theme_path) { gchar *path; path = gimp_config_path_expand (config->theme_path, TRUE, NULL); gimp_datafiles_read_directories (path, G_FILE_TEST_IS_DIR, themes_directories_foreach, gimp); g_free (path); } themes_apply_theme (gimp, config->theme); themerc = gimp_personal_rc_file ("themerc"); gtk_rc_parse (themerc); g_free (themerc); g_signal_connect (config, "notify::theme", G_CALLBACK (themes_theme_change_notify), gimp); }
static WidgetInfo * create_path_editor (void) { GtkWidget *vbox; GtkWidget *editor; GtkWidget *align; gchar *config = gimp_config_build_data_path ("patterns"); gchar *path = gimp_config_path_expand (config, TRUE, NULL); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0); editor = gimp_path_editor_new ("Path Editor", path); gtk_widget_set_size_request (editor, -1, 240); gtk_container_add (GTK_CONTAINER (align), editor); gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("Path Editor"), FALSE, FALSE, 0); g_free (path); g_free (config); return new_widget_info ("gimp-widget-path-editor", vbox, ASIS); }
void gimp_modules_load (Gimp *gimp) { gchar *filename; gchar *path; GScanner *scanner; gchar *module_load_inhibit = NULL; g_return_if_fail (GIMP_IS_GIMP (gimp)); if (gimp->no_interface) return; filename = gimp_personal_rc_file ("modulerc"); if (gimp->be_verbose) g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename)); scanner = gimp_scanner_new_file (filename, NULL); g_free (filename); if (scanner) { GTokenType token; GError *error = NULL; #define MODULE_LOAD_INHIBIT 1 g_scanner_scope_add_symbol (scanner, 0, "module-load-inhibit", GINT_TO_POINTER (MODULE_LOAD_INHIBIT)); 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 (MODULE_LOAD_INHIBIT)) { token = G_TOKEN_STRING; if (! gimp_scanner_parse_string_no_validate (scanner, &module_load_inhibit)) goto error; } token = G_TOKEN_RIGHT_PAREN; break; case G_TOKEN_RIGHT_PAREN: token = G_TOKEN_LEFT_PAREN; break; default: /* do nothing */ break; } } #undef MODULE_LOAD_INHIBIT 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); } error: if (error) { gimp_message (gimp, NULL, GIMP_MESSAGE_ERROR, "%s", error->message); g_clear_error (&error); } gimp_scanner_destroy (scanner); } if (module_load_inhibit) { gimp_module_db_set_load_inhibit (gimp->module_db, module_load_inhibit); g_free (module_load_inhibit); } path = gimp_config_path_expand (gimp->config->module_path, TRUE, NULL); gimp_module_db_load (gimp->module_db, path); g_free (path); }
void app_run (const gchar *full_prog_name, const gchar **filenames, const gchar *alternate_system_gimprc, const gchar *alternate_gimprc, const gchar *session_name, const gchar *batch_interpreter, const gchar **batch_commands, gboolean as_new, gboolean no_interface, gboolean no_data, gboolean no_fonts, gboolean no_splash, gboolean be_verbose, gboolean use_shm, gboolean use_cpu_accel, gboolean console_messages, gboolean use_debug_handler, GimpStackTraceMode stack_trace_mode, GimpPDBCompatMode pdb_compat_mode) { GimpInitStatusFunc update_status_func = NULL; Gimp *gimp; GimpGeglConfig *config; GMainLoop *loop; gboolean swap_is_ok; /* Create an instance of the "Gimp" object which is the root of the * core object system */ gimp = gimp_new (full_prog_name, session_name, be_verbose, no_data, no_fonts, no_interface, use_shm, console_messages, stack_trace_mode, pdb_compat_mode); errors_init (gimp, full_prog_name, use_debug_handler, stack_trace_mode); units_init (gimp); /* Check if the user's gimp_directory exists */ if (! g_file_test (gimp_directory (), G_FILE_TEST_IS_DIR)) { GimpUserInstall *install = gimp_user_install_new (be_verbose); #ifdef GIMP_CONSOLE_COMPILATION gimp_user_install_run (install); #else if (! (no_interface ? gimp_user_install_run (install) : user_install_dialog_run (install))) exit (EXIT_FAILURE); #endif gimp_user_install_free (install); } gimp_load_config (gimp, alternate_system_gimprc, alternate_gimprc); config = GIMP_GEGL_CONFIG (gimp->config); /* change the locale if a language if specified */ language_init (gimp->config->language); /* initialize lowlevel stuff */ swap_is_ok = base_init (config, be_verbose, use_cpu_accel); gimp_gegl_init (gimp); #ifndef GIMP_CONSOLE_COMPILATION if (! no_interface) update_status_func = gui_init (gimp, no_splash); #endif if (! update_status_func) update_status_func = app_init_update_noop; /* Create all members of the global Gimp instance which need an already * parsed gimprc, e.g. the data factories */ gimp_initialize (gimp, update_status_func); /* Load all data files */ gimp_restore (gimp, update_status_func); /* display a warning when no test swap file could be generated */ if (! swap_is_ok) { gchar *path = gimp_config_path_expand (config->swap_path, FALSE, NULL); g_message (_("Unable to open a test swap file.\n\n" "To avoid data loss, please check the location " "and permissions of the swap directory defined in " "your Preferences (currently \"%s\")."), path); g_free (path); } /* enable autosave late so we don't autosave when the * monitor resolution is set in gui_init() */ gimp_rc_set_autosave (GIMP_RC (gimp->edit_config), TRUE); /* Load the images given on the command-line. */ if (filenames) { gint i; for (i = 0; filenames[i] != NULL; i++) file_open_from_command_line (gimp, filenames[i], as_new); } batch_run (gimp, batch_interpreter, batch_commands); loop = g_main_loop_new (NULL, FALSE); g_signal_connect_after (gimp, "exit", G_CALLBACK (app_exit_after_callback), loop); gimp_threads_leave (gimp); g_main_loop_run (loop); gimp_threads_enter (gimp); g_main_loop_unref (loop); g_object_unref (gimp); gimp_debug_instances (); errors_exit (); gegl_exit (); base_exit (); }
/** * gimp_rc_query: * @rc: a #GimpRc object. * @key: a string used as a key for the lookup. * * This function looks up @key in the object properties of @rc. If * there's a matching property, a string representation of its value * is returned. If no property is found, the list of unknown tokens * attached to the @rc object is searched. * * Return value: a newly allocated string representing the value or %NULL * if the key couldn't be found. **/ gchar * gimp_rc_query (GimpRc *rc, const gchar *key) { GObjectClass *klass; GObject *rc_object; GParamSpec **property_specs; GParamSpec *prop_spec; guint i, n_property_specs; gchar *retval = NULL; g_return_val_if_fail (GIMP_IS_RC (rc), NULL); g_return_val_if_fail (key != NULL, NULL); rc_object = G_OBJECT (rc); klass = G_OBJECT_GET_CLASS (rc); property_specs = g_object_class_list_properties (klass, &n_property_specs); if (!property_specs) return NULL; for (i = 0, prop_spec = NULL; i < n_property_specs && !prop_spec; i++) { prop_spec = property_specs[i]; if (! (prop_spec->flags & GIMP_CONFIG_PARAM_SERIALIZE) || strcmp (prop_spec->name, key)) { prop_spec = NULL; } } if (prop_spec) { GString *str = g_string_new (NULL); GValue value = { 0, }; g_value_init (&value, prop_spec->value_type); g_object_get_property (rc_object, prop_spec->name, &value); if (gimp_config_serialize_value (&value, str, FALSE)) retval = g_string_free (str, FALSE); else g_string_free (str, TRUE); g_value_unset (&value); } else { retval = g_strdup (gimp_rc_lookup_unknown_token (GIMP_CONFIG (rc), key)); } g_free (property_specs); if (!retval) { const gchar * const path_tokens[] = { "gimp_dir", "gimp_data_dir", "gimp_plug_in_dir", "gimp_plugin_dir", "gimp_sysconf_dir" }; for (i = 0; !retval && i < G_N_ELEMENTS (path_tokens); i++) if (strcmp (key, path_tokens[i]) == 0) retval = g_strdup_printf ("${%s}", path_tokens[i]); } if (retval) { gchar *tmp = gimp_config_path_expand (retval, FALSE, NULL); if (tmp) { g_free (retval); retval = tmp; } } return retval; }
static GTokenType plug_in_def_deserialize (Gimp *gimp, GScanner *scanner, GSList **plug_in_defs) { GimpPlugInDef *plug_in_def; GimpPlugInProcedure *proc = NULL; gchar *name; gchar *path; GFile *file; gint64 mtime; GTokenType token; if (! gimp_scanner_parse_string (scanner, &name)) return G_TOKEN_STRING; path = gimp_config_path_expand (name, TRUE, NULL); g_free (name); file = g_file_new_for_path (path); g_free (path); plug_in_def = gimp_plug_in_def_new (file); g_object_unref (file); if (! gimp_scanner_parse_int64 (scanner, &mtime)) { g_object_unref (plug_in_def); return G_TOKEN_INT; } plug_in_def->mtime = mtime; 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: switch (GPOINTER_TO_INT (scanner->value.v_symbol)) { case PROC_DEF: token = plug_in_procedure_deserialize (scanner, gimp, plug_in_def->file, &proc); if (token == G_TOKEN_LEFT_PAREN) gimp_plug_in_def_add_procedure (plug_in_def, proc); if (proc) g_object_unref (proc); break; case LOCALE_DEF: token = plug_in_locale_def_deserialize (scanner, plug_in_def); break; case HELP_DEF: token = plug_in_help_def_deserialize (scanner, plug_in_def); break; case HAS_INIT: token = plug_in_has_init_deserialize (scanner, plug_in_def); break; default: break; } break; case G_TOKEN_RIGHT_PAREN: token = G_TOKEN_LEFT_PAREN; break; default: break; } } if (token == G_TOKEN_LEFT_PAREN) { token = G_TOKEN_RIGHT_PAREN; if (gimp_scanner_parse_token (scanner, token)) { *plug_in_defs = g_slist_prepend (*plug_in_defs, plug_in_def); return G_TOKEN_LEFT_PAREN; } } g_object_unref (plug_in_def); return token; }