diff --git a/app/config/gimpconfig-dump.c b/app/config/gimpconfig-dump.c index 1c1d44463a..dc961f0594 100644 --- a/app/config/gimpconfig-dump.c +++ b/app/config/gimpconfig-dump.c @@ -271,6 +271,14 @@ static const gchar *man_page_path = "Path to configuration files, which is set to the value of the environment\n" "variable GIMP3_SYSCONFDIR or to the compiled-in default value \n" "@gimpsysconfdir@.\n" +".TP\n" +".I gimp_cache_dir\n" +"Path to cached files, which is set to the value of the environment\n" +"variable GIMP3_CACHEDIR or to the system default for per-user cached files.\n" +".TP\n" +".I gimp_temp_dir\n" +"Path to temporary files, which is set to the value of the environment\n" +"variable GIMP3_TEMPDIR or to the system default for temporary files.\n" "\n"; static const gchar man_page_footer[] = diff --git a/app/config/gimpgeglconfig.c b/app/config/gimpgeglconfig.c index eb15586323..9ccbfa9197 100644 --- a/app/config/gimpgeglconfig.c +++ b/app/config/gimpgeglconfig.c @@ -119,7 +119,7 @@ gimp_gegl_config_class_init (GimpGeglConfigClass *klass) "Temp path", TEMP_PATH_BLURB, GIMP_CONFIG_PATH_DIR, - "${gimp_dir}" G_DIR_SEPARATOR_S "tmp", + "${gimp_temp_dir}", GIMP_PARAM_STATIC_STRINGS | GIMP_CONFIG_PARAM_RESTART); @@ -128,7 +128,7 @@ gimp_gegl_config_class_init (GimpGeglConfigClass *klass) "Swap path", SWAP_PATH_BLURB, GIMP_CONFIG_PATH_DIR, - "${gimp_dir}", + "${gimp_cache_dir}", GIMP_PARAM_STATIC_STRINGS | GIMP_CONFIG_PARAM_RESTART); diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c index f5928a10f2..9a64be1bd4 100644 --- a/app/dialogs/preferences-dialog.c +++ b/app/dialogs/preferences-dialog.c @@ -98,6 +98,10 @@ static void prefs_color_management_reset (GtkWidget *widget, GObject *config); static void prefs_dialog_defaults_reset (GtkWidget *widget, GObject *config); +static void prefs_folders_reset (GtkWidget *widget, + GObject *config); +static void prefs_path_reset (GtkWidget *widget, + GObject *config); static void prefs_import_raw_procedure_callback (GtkWidget *widget, GObject *config); @@ -485,6 +489,30 @@ prefs_dialog_defaults_reset (GtkWidget *widget, g_free (pspecs); } +static void +prefs_folders_reset (GtkWidget *widget, + GObject *config) +{ + gimp_config_reset_property (config, "temp-path"); + gimp_config_reset_property (config, "swap-path"); +} + +static void +prefs_path_reset (GtkWidget *widget, + GObject *config) +{ + const gchar *path_property; + const gchar *writable_property; + + path_property = g_object_get_data (G_OBJECT (widget), "path"); + writable_property = g_object_get_data (G_OBJECT (widget), "path-writable"); + + gimp_config_reset_property (config, path_property); + + if (writable_property) + gimp_config_reset_property (config, writable_property); +} + static void prefs_template_select_callback (GimpContainerView *view, GimpTemplate *template, @@ -3060,6 +3088,13 @@ prefs_dialog_new (Gimp *gimp, NULL, &top_iter); + button = gimp_prefs_box_set_page_resettable (GIMP_PREFS_BOX (prefs_box), + vbox, + _("Reset Folders")); + g_signal_connect (button, "clicked", + G_CALLBACK (prefs_folders_reset), + config); + { static const struct { @@ -3103,70 +3138,101 @@ prefs_dialog_new (Gimp *gimp, const gchar *label; const gchar *icon; const gchar *help_data; + const gchar *reset_label; const gchar *fs_label; const gchar *path_property_name; const gchar *writable_property_name; } paths[] = { - { N_("Brushes"), N_("Brush Folders"), "folders-brushes", + { N_("Brushes"), N_("Brush Folders"), + "folders-brushes", GIMP_HELP_PREFS_FOLDERS_BRUSHES, + N_("Reset Brush Folders"), N_("Select Brush Folders"), "brush-path", "brush-path-writable" }, - { N_("Dynamics"), N_("Dynamics Folders"), "folders-dynamics", + { N_("Dynamics"), N_("Dynamics Folders"), + "folders-dynamics", GIMP_HELP_PREFS_FOLDERS_DYNAMICS, + N_("Reset Dynamics Folders"), N_("Select Dynamics Folders"), "dynamics-path", "dynamics-path-writable" }, - { N_("Patterns"), N_("Pattern Folders"), "folders-patterns", + { N_("Patterns"), N_("Pattern Folders"), + "folders-patterns", GIMP_HELP_PREFS_FOLDERS_PATTERNS, + N_("Reset Pattern Folders"), N_("Select Pattern Folders"), "pattern-path", "pattern-path-writable" }, - { N_("Palettes"), N_("Palette Folders"), "folders-palettes", + { N_("Palettes"), N_("Palette Folders"), + "folders-palettes", GIMP_HELP_PREFS_FOLDERS_PALETTES, + N_("Reset Palette Folders"), N_("Select Palette Folders"), "palette-path", "palette-path-writable" }, - { N_("Gradients"), N_("Gradient Folders"), "folders-gradients", + { N_("Gradients"), N_("Gradient Folders"), + "folders-gradients", GIMP_HELP_PREFS_FOLDERS_GRADIENTS, + N_("Reset Gradient Folders"), N_("Select Gradient Folders"), "gradient-path", "gradient-path-writable" }, - { N_("Fonts"), N_("Font Folders"), "folders-fonts", + { N_("Fonts"), N_("Font Folders"), + "folders-fonts", GIMP_HELP_PREFS_FOLDERS_FONTS, + N_("Reset Font Folders"), N_("Select Font Folders"), "font-path", NULL }, - { N_("Tool Presets"), N_("Tool Preset Folders"), "folders-tool-presets", + { N_("Tool Presets"), N_("Tool Preset Folders"), + "folders-tool-presets", GIMP_HELP_PREFS_FOLDERS_TOOL_PRESETS, + N_("Reset Tool Preset Folders"), N_("Select Tool Preset Folders"), "tool-preset-path", "tool-preset-path-writable" }, - { N_("MyPaint Brushes"), N_("MyPaint Brush Folders"), "folders-mypaint-brushes", + { N_("MyPaint Brushes"), N_("MyPaint Brush Folders"), + "folders-mypaint-brushes", GIMP_HELP_PREFS_FOLDERS_MYPAINT_BRUSHES, + N_("Reset MyPaint Brush Folders"), N_("Select MyPaint Brush Folders"), "mypaint-brush-path", "mypaint-brush-path-writable" }, - { N_("Plug-ins"), N_("Plug-in Folders"), "folders-plug-ins", + { N_("Plug-ins"), N_("Plug-in Folders"), + "folders-plug-ins", GIMP_HELP_PREFS_FOLDERS_PLUG_INS, + N_("Reset plug-in Folders"), N_("Select plug-in Folders"), "plug-in-path", NULL }, - { N_("Scripts"), N_("Script-Fu Folders"), "folders-scripts", + { N_("Scripts"), N_("Script-Fu Folders"), + "folders-scripts", GIMP_HELP_PREFS_FOLDERS_SCRIPTS, + N_("Reset Script-Fu Folders"), N_("Select Script-Fu Folders"), "script-fu-path", NULL }, - { N_("Modules"), N_("Module Folders"), "folders-modules", + { N_("Modules"), N_("Module Folders"), + "folders-modules", GIMP_HELP_PREFS_FOLDERS_MODULES, + N_("Reset Module Folders"), N_("Select Module Folders"), "module-path", NULL }, - { N_("Interpreters"), N_("Interpreter Folders"), "folders-interp", + { N_("Interpreters"), N_("Interpreter Folders"), + "folders-interp", GIMP_HELP_PREFS_FOLDERS_INTERPRETERS, + N_("Reset Interpreter Folders"), N_("Select Interpreter Folders"), "interpreter-path", NULL }, - { N_("Environment"), N_("Environment Folders"), "folders-environ", + { N_("Environment"), N_("Environment Folders"), + "folders-environ", GIMP_HELP_PREFS_FOLDERS_ENVIRONMENT, + N_("Reset Environment Folders"), N_("Select Environment Folders"), "environ-path", NULL }, - { N_("Themes"), N_("Theme Folders"), "folders-themes", + { N_("Themes"), N_("Theme Folders"), + "folders-themes", GIMP_HELP_PREFS_FOLDERS_THEMES, + N_("Reset Theme Folders"), N_("Select Theme Folders"), "theme-path", NULL }, - { N_("Icon Themes"), N_("Icon Theme Folders"), "folders-icon-themes", + { N_("Icon Themes"), N_("Icon Theme Folders"), + "folders-icon-themes", GIMP_HELP_PREFS_FOLDERS_ICON_THEMES, + N_("Reset Icon Theme Folders"), N_("Select Icon Theme Folders"), "icon-theme-path", NULL } }; @@ -3186,6 +3252,17 @@ prefs_dialog_new (Gimp *gimp, &child_iter); g_free (icon_name); + button = gimp_prefs_box_set_page_resettable (GIMP_PREFS_BOX (prefs_box), + vbox, + gettext (paths[i].reset_label)); + g_object_set_data (G_OBJECT (button), "path", + (gpointer) paths[i].path_property_name); + g_object_set_data (G_OBJECT (button), "path-writable", + (gpointer) paths[i].writable_property_name); + g_signal_connect (button, "clicked", + G_CALLBACK (prefs_path_reset), + config); + editor = gimp_prop_path_editor_new (object, paths[i].path_property_name, paths[i].writable_property_name, diff --git a/app/gegl/gimp-gegl.c b/app/gegl/gimp-gegl.c index af0c28efca..6c7987b432 100644 --- a/app/gegl/gimp-gegl.c +++ b/app/gegl/gimp-gegl.c @@ -23,6 +23,8 @@ #include #include +#include "libgimpconfig/gimpconfig.h" + #include "gimp-gegl-types.h" #include "config/gimpgeglconfig.h" @@ -35,12 +37,17 @@ #include "gimp-babl.h" #include "gimp-gegl.h" +#include + +static void gimp_gegl_notify_swap_path (GimpGeglConfig *config); +static void gimp_gegl_notify_temp_path (GimpGeglConfig *config); static void gimp_gegl_notify_tile_cache_size (GimpGeglConfig *config); static void gimp_gegl_notify_num_processors (GimpGeglConfig *config); static void gimp_gegl_notify_use_opencl (GimpGeglConfig *config); -#include + +/* public functions */ void gimp_gegl_init (Gimp *gimp) @@ -51,6 +58,10 @@ gimp_gegl_init (Gimp *gimp) config = GIMP_GEGL_CONFIG (gimp->config); + /* make sure swap and temp directories exist */ + gimp_gegl_notify_swap_path (config); + gimp_gegl_notify_temp_path (config); + g_object_set (gegl_config (), "tile-cache-size", (guint64) config->tile_cache_size, "threads", config->num_processors, @@ -59,6 +70,15 @@ gimp_gegl_init (Gimp *gimp) gimp_parallel_init (gimp); + g_signal_connect (config, "notify::swap-path", + G_CALLBACK (gimp_gegl_notify_swap_path), + NULL); + g_signal_connect (config, "notify::temp-path", + G_CALLBACK (gimp_gegl_notify_temp_path), + NULL); + g_signal_connect (config, "notify::num-processors", + G_CALLBACK (gimp_gegl_notify_num_processors), + NULL); g_signal_connect (config, "notify::tile-cache-size", G_CALLBACK (gimp_gegl_notify_tile_cache_size), NULL); @@ -82,6 +102,37 @@ gimp_gegl_exit (Gimp *gimp) gimp_parallel_exit (gimp); } + +/* private functions */ + +static void +gimp_gegl_notify_swap_path (GimpGeglConfig *config) +{ + GFile *file = gimp_file_new_for_config_path (config->swap_path, NULL); + gchar *path = g_file_get_path (file); + + if (! g_file_query_exists (file, NULL)) + g_file_make_directory_with_parents (file, NULL, NULL); + + g_object_set (gegl_config (), + "swap", path, + NULL); + + g_free (path); + g_object_unref (file); +} + +static void +gimp_gegl_notify_temp_path (GimpGeglConfig *config) +{ + GFile *file = gimp_file_new_for_config_path (config->temp_path, NULL); + + if (! g_file_query_exists (file, NULL)) + g_file_make_directory_with_parents (file, NULL, NULL); + + g_object_unref (file); +} + static void gimp_gegl_notify_tile_cache_size (GimpGeglConfig *config) { diff --git a/docs/gimp.1.in b/docs/gimp.1.in index 6bc6110511..665c7a01fa 100644 --- a/docs/gimp.1.in +++ b/docs/gimp.1.in @@ -171,6 +171,14 @@ to get the base location for plug-ins and modules. If unset .B GIMP3_SYSCONFDIR to get the location of configuration files. If unset @gimpsysconfdir@ is used. +.TP 8 +.B GIMP3_CACHEDIR +to get the location for caches files. If unset the system default for +per-user cached files is used. +.TP 8 +.B GIMP3_TEMPDIR +to get the location of temporary files. If unset the system default for +temporary files is used. On Linux GIMP can be compiled with support for binary relocatibility. This will cause data, plug-ins and configuration files to be searched diff --git a/libgimpbase/gimpbase.def b/libgimpbase/gimpbase.def index c43f78da45..42aacd3156 100644 --- a/libgimpbase/gimpbase.def +++ b/libgimpbase/gimpbase.def @@ -6,6 +6,7 @@ EXPORTS gimp_blend_mode_get_type gimp_brush_generated_shape_get_type gimp_bucket_fill_mode_get_type + gimp_cache_directory gimp_canonicalize_identifier gimp_cap_style_get_type gimp_channel_ops_get_type @@ -152,6 +153,7 @@ EXPORTS gimp_stroke_method_get_type gimp_sysconf_directory gimp_sysconf_directory_file + gimp_temp_directory gimp_text_direction_get_type gimp_text_hint_style_get_type gimp_text_justification_get_type diff --git a/libgimpbase/gimpenv.c b/libgimpbase/gimpenv.c index f76d4f4c05..abb7814bfc 100644 --- a/libgimpbase/gimpenv.c +++ b/libgimpbase/gimpenv.c @@ -199,6 +199,9 @@ gimp_env_init (gboolean plug_in) * In any case, we always return some non-empty string, whether it * corresponds to an existing directory or not. * + * In config files such as gimprc, the string ${gimp_dir} expands to + * this directory. + * * The returned string is owned by GIMP and must not be modified or * freed. The returned string is in the encoding used for filenames by * GLib, which isn't necessarily UTF-8 (on Windows it is always @@ -371,6 +374,9 @@ DllMain (HINSTANCE hinstDLL, * filename is used. On OSX we ask [NSBundle mainBundle] for the * resource path to check if GIMP is part of a relocatable bundle. * + * In config files such as gimprc, the string ${gimp_installation_dir} + * expands to this directory. + * * The returned string is owned by GIMP and must not be modified or * freed. The returned string is in the encoding used for filenames by * GLib, which isn't necessarily UTF-8. (On Windows it always is @@ -460,11 +466,17 @@ gimp_installation_directory (void) /** * gimp_data_directory: * - * Returns the top directory for GIMP data. If the environment + * Returns the default top directory for GIMP data. If the environment * variable GIMP3_DATADIR exists, that is used. It should be an * absolute pathname. Otherwise, on Unix the compile-time defined - * directory is used. On Windows, the installation directory as deduced - * from the executable's full filename is used. + * directory is used. On Windows, the installation directory as + * deduced from the executable's full filename is used. + * + * Note that the actual directories used for GIMP data files can be + * overridden by the user in the preferences dialog. + * + * In config files such as gimprc, the string ${gimp_data_dir} expands + * to this directory. * * The returned string is owned by GIMP and must not be modified or * freed. The returned string is in the encoding used for filenames by @@ -550,6 +562,9 @@ gimp_locale_directory (void) * directory is used. On Windows, the installation directory as deduced * from the executable's full filename is used. * + * In config files such as gimprc, the string ${gimp_sysconf_dir} + * expands to this directory. + * * The returned string is owned by GIMP and must not be modified or * freed. The returned string is in the encoding used for filenames by * GLib, which isn't necessarily UTF-8. (On Windows it always is @@ -579,11 +594,17 @@ gimp_sysconf_directory (void) /** * gimp_plug_in_directory: * - * Returns the top directory for GIMP plug_ins and modules. If the - * environment variable GIMP3_PLUGINDIR exists, that is used. It + * Returns the default top directory for GIMP plug-ins and modules. If + * the environment variable GIMP3_PLUGINDIR exists, that is used. It * should be an absolute pathname. Otherwise, on Unix the compile-time - * defined directory is used. On Windows, the installation directory as - * deduced from the executable's full filename is used. + * defined directory is used. On Windows, the installation directory + * as deduced from the executable's full filename is used. + * + * Note that the actual directories used for GIMP plug-ins and modules + * can be overridden by the user in the preferences dialog. + * + * In config files such as gimprc, the string ${gimp_plug_in_dir} + * expands to this directory. * * The returned string is owned by GIMP and must not be modified or * freed. The returned string is in the encoding used for filenames by @@ -611,6 +632,90 @@ gimp_plug_in_directory (void) return gimp_plug_in_dir; } +/** + * gimp_cache_directory: + * + * Returns the default top directory for GIMP cached files. If the + * environment variable GIMP3_CACHEDIR exists, that is used. It + * should be an absolute pathname. Otherwise, a subdirectory of the + * directory returned by g_get_user_cache_dir() is used. + * + * Note that the actual directories used for GIMP caches files can + * be overridden by the user in the preferences dialog. + * + * In config files such as gimprc, the string ${gimp_cache_dir} + * expands to this directory. + * + * The returned string is owned by GIMP and must not be modified or + * freed. The returned string is in the encoding used for filenames by + * GLib, which isn't necessarily UTF-8. (On Windows it always is + * UTF-8.). + * + * Since: 2.10.10 + * + * Returns: The default top directory for GIMP cached files. + **/ +const gchar * +gimp_cache_directory (void) +{ + static gchar *gimp_cache_dir = NULL; + + if (! gimp_cache_dir) + { + gchar *tmp = g_build_filename (g_get_user_cache_dir (), + GIMP_PACKAGE, + GIMP_USER_VERSION, + NULL); + + gimp_cache_dir = gimp_env_get_dir ("GIMP3_CACHEDIR", NULL, tmp); + g_free (tmp); + } + + return gimp_cache_dir; +} + +/** + * gimp_temp_directory: + * + * Returns the default top directory for GIMP temporary files. If the + * environment variable GIMP3_TEMPDIR exists, that is used. It + * should be an absolute pathname. Otherwise, a subdirectory of the + * directory returned by g_get_tmp_dir() is used. + * + * In config files such as gimprc, the string ${gimp_temp_dir} expands + * to this directory. + * + * Note that the actual directories used for GIMP temporary files can + * be overridden by the user in the preferences dialog. + * + * The returned string is owned by GIMP and must not be modified or + * freed. The returned string is in the encoding used for filenames by + * GLib, which isn't necessarily UTF-8. (On Windows it always is + * UTF-8.). + * + * Since: 2.10.10 + * + * Returns: The default top directory for GIMP temporary files. + **/ +const gchar * +gimp_temp_directory (void) +{ + static gchar *gimp_temp_dir = NULL; + + if (! gimp_temp_dir) + { + gchar *tmp = g_build_filename (g_get_tmp_dir (), + GIMP_PACKAGE, + GIMP_USER_VERSION, + NULL); + + gimp_temp_dir = gimp_env_get_dir ("GIMP3_TEMPDIR", NULL, tmp); + g_free (tmp); + } + + return gimp_temp_dir; +} + static GFile * gimp_child_file (const gchar *parent, const gchar *element, @@ -1103,8 +1208,12 @@ gimp_env_get_dir (const gchar *gimp_env_name, return retval; } + else if (! g_path_is_absolute (relative_subdir)) + { + return g_build_filename (gimp_installation_directory (), + relative_subdir, + NULL); + } - return g_build_filename (gimp_installation_directory (), - relative_subdir, - NULL); + return g_strdup (relative_subdir); } diff --git a/libgimpbase/gimpenv.h b/libgimpbase/gimpenv.h index c1aeeaf2dd..a5a1094153 100644 --- a/libgimpbase/gimpenv.h +++ b/libgimpbase/gimpenv.h @@ -53,6 +53,8 @@ const gchar * gimp_data_directory (void) G_GNUC_CONST; const gchar * gimp_locale_directory (void) G_GNUC_CONST; const gchar * gimp_sysconf_directory (void) G_GNUC_CONST; const gchar * gimp_plug_in_directory (void) G_GNUC_CONST; +const gchar * gimp_cache_directory (void) G_GNUC_CONST; +const gchar * gimp_temp_directory (void) G_GNUC_CONST; GFile * gimp_directory_file (const gchar *first_element, ...) G_GNUC_MALLOC; diff --git a/libgimpconfig/gimpconfig-path.c b/libgimpconfig/gimpconfig-path.c index 3eaff5049f..e3a519f233 100644 --- a/libgimpconfig/gimpconfig-path.c +++ b/libgimpconfig/gimpconfig-path.c @@ -566,6 +566,10 @@ gimp_config_path_expand_only (const gchar *path, s = gimp_sysconf_directory (); else if (strcmp (token, "gimp_installation_dir") == 0) s = gimp_installation_directory (); + else if (strcmp (token, "gimp_cache_dir") == 0) + s = gimp_cache_directory (); + else if (strcmp (token, "gimp_temp_dir") == 0) + s = gimp_temp_directory (); if (!s) s = g_getenv (token); @@ -697,6 +701,8 @@ gimp_config_path_unexpand_only (const gchar *path) { "${gimp_data_dir}", gimp_data_directory () }, { "${gimp_sysconf_dir}", gimp_sysconf_directory () }, { "${gimp_installation_dir}", gimp_installation_directory () }, + { "${gimp_cache_dir}", gimp_cache_directory () }, + { "${gimp_temp_dir}", gimp_temp_directory () }, { "${gimp_dir}", gimp_directory () } };