gimp/libgimpbase/gimpenv.c

1210 lines
32 KiB
C
Raw Normal View History

1999-03-07 20:56:03 +08:00
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpenv.c
* Copyright (C) 1999 Tor Lillqvist <tml@iki.fi>
1999-03-07 20:56:03 +08:00
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
1999-03-07 20:56:03 +08:00
*
* This library is distributed in the hope that it will be useful,
1999-03-07 20:56:03 +08:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
1999-03-07 20:56:03 +08:00
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
1999-03-07 20:56:03 +08:00
*/
#include "config.h"
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef PLATFORM_OSX
#include <AppKit/AppKit.h>
#endif
#include <gio/gio.h>
#include <glib/gstdio.h>
#include "gimpbasetypes.h"
#define __GIMP_ENV_C__
1999-03-07 20:56:03 +08:00
#include "gimpenv.h"
#include "gimpversion.h"
#include "gimpreloc.h"
1999-03-07 20:56:03 +08:00
#ifdef G_OS_WIN32
1999-03-07 20:56:03 +08:00
#define STRICT
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <io.h>
#ifndef S_IWUSR
# define S_IWUSR _S_IWRITE
#endif
#ifndef S_IWGRP
#define S_IWGRP (_S_IWRITE>>3)
#define S_IWOTH (_S_IWRITE>>6)
#endif
#ifndef S_ISDIR
# define __S_ISTYPE(mode, mask) (((mode) & _S_IFMT) == (mask))
# define S_ISDIR(mode) __S_ISTYPE((mode), _S_IFDIR)
#endif
#define uid_t gint
#define gid_t gint
#define geteuid() 0
#define getegid() 0
#include <shlobj.h>
/* Constant available since Shell32.dll 4.72 */
#ifndef CSIDL_APPDATA
#define CSIDL_APPDATA 0x001a
#endif
1999-03-07 20:56:03 +08:00
#endif
/**
* SECTION: gimpenv
* @title: gimpenv
* @short_description: Functions to access the GIMP environment.
*
* A set of functions to find the locations of GIMP's data directories
* and configuration files.
**/
static gchar * gimp_env_get_dir (const gchar *gimp_env_name,
const gchar *compile_time_dir,
const gchar *relative_subdir);
const guint gimp_major_version = GIMP_MAJOR_VERSION;
const guint gimp_minor_version = GIMP_MINOR_VERSION;
const guint gimp_micro_version = GIMP_MICRO_VERSION;
/**
* gimp_env_init:
* @plug_in: must be %TRUE if this function is called from a plug-in
*
* You don't need to care about this function. It is being called for
* you automatically (by means of the MAIN() macro that every plug-in
* runs). Calling it again will cause a fatal error.
*
* Since: 2.4
*/
void
gimp_env_init (gboolean plug_in)
{
static gboolean gimp_env_initialized = FALSE;
const gchar *data_home = g_get_user_data_dir ();
if (gimp_env_initialized)
g_error ("gimp_env_init() must only be called once!");
gimp_env_initialized = TRUE;
#ifndef G_OS_WIN32
if (plug_in)
{
_gimp_reloc_init_lib (NULL);
}
else if (_gimp_reloc_init (NULL))
{
/* Set $LD_LIBRARY_PATH to ensure that plugins can be loaded. */
const gchar *ldpath = g_getenv ("LD_LIBRARY_PATH");
gchar *libdir = g_build_filename (gimp_installation_directory (),
"lib",
NULL);
if (ldpath && *ldpath)
{
gchar *tmp = g_strconcat (libdir, ":", ldpath, NULL);
g_setenv ("LD_LIBRARY_PATH", tmp, TRUE);
g_free (tmp);
}
else
{
g_setenv ("LD_LIBRARY_PATH", libdir, TRUE);
}
g_free (libdir);
}
#endif
/* The user data directory (XDG_DATA_HOME on Unix) is used to store
* various data, like crash logs (win32) or recently used file history
* (by GTK+). Yet it may be absent, in particular on non-Linux
* platforms. Make sure it exists.
*/
if (! g_file_test (data_home, G_FILE_TEST_IS_DIR))
{
if (g_mkdir_with_parents (data_home, S_IRUSR | S_IWUSR | S_IXUSR) != 0)
{
g_warning ("Failed to create the data directory '%s': %s",
data_home, g_strerror (errno));
}
}
}
#ifdef G_OS_WIN32
static char *
get_known_folder (REFKNOWNFOLDERID id)
{
wchar_t *path_utf16 = NULL;
char *path = NULL;
if (SUCCEEDED (SHGetKnownFolderPath (id, KF_FLAG_DEFAULT, NULL, &path_utf16)))
path = g_utf16_to_utf8 (path_utf16, -1, NULL, NULL, NULL);
if (path_utf16)
CoTaskMemFree (path_utf16);
return path;
}
extern IMAGE_DOS_HEADER __ImageBase;
static HMODULE
this_module (void)
{
return (HMODULE) &__ImageBase;
}
#endif
2000-02-07 07:16:24 +08:00
/**
* gimp_directory:
*
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
* Returns the user-specific GIMP settings directory. If the
* environment variable GIMP3_DIRECTORY exists, it is used. If it is
* an absolute path, it is used as is. If it is a relative path, it
* is taken to be a subdirectory of the home directory. If it is a
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
* relative path, and no home directory can be determined, it is taken
* to be a subdirectory of gimp_data_directory().
2000-02-07 07:16:24 +08:00
*
* The usual case is that no GIMP3_DIRECTORY environment variable
* exists, and then we use the GIMPDIR subdirectory of the local
* configuration directory:
*
* - UNIX: $XDG_CONFIG_HOME (defaults to $HOME/.config/)
*
* - Windows: CSIDL_APPDATA
*
* - OSX (UNIX exception): the Application Support Directory.
*
* If neither the configuration nor home directory exist,
* g_get_user_config_dir() will return {tmp}/{user_name}/.config/ where
* the temporary directory {tmp} and the {user_name} are determined
* according to platform rules.
*
* In any case, we always return some non-empty string, whether it
* corresponds to an existing directory or not.
2000-02-07 07:16:24 +08:00
*
* 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
* UTF-8.)
2000-02-07 07:16:24 +08:00
*
* Returns: The user-specific GIMP settings directory.
**/
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
const gchar *
2000-02-07 07:16:24 +08:00
gimp_directory (void)
1999-03-07 20:56:03 +08:00
{
static gchar *gimp_dir = NULL;
static gchar *last_env_gimp_dir = NULL;
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) 2001-07-24 Michael Natterer <mitch@gimp.org> Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) * configure.in: require glib/gtk+ >= 1.3.7, commented out the gtkxmhtml stuff. From now on, you will need glib, pango, atk and gtk+ HEAD from CVS to hack or use GIMP HEAD. Beware, it crashes randomly :) * app/core/Makefile.am * app/core/gimpmarshal.list: new file plus rules to generate gimpmarshal.[ch] from it. * app/core/* * app/tools/* * app/widgets/* * libgimpwidgets/*: started to use the glib object system. All core/ objects are still gtk objects however. All signals are created using g_signal_new(). There are many gtk+ artefacts left. Finally, we will _not_ use the gtk_signal_foo() wrappers and friends any more. * app/colormaps.c * app/devices.[ch] * app/disp_callbacks.c * app/errorconsole.c * app/file-save.[ch] * app/interface.c * app/module_db.c * app/nav_window.c * app/ops_buttons.c * app/scroll.c * app/user_install.c * app/gui/about-dialog.c * app/gui/brush-editor.c * app/gui/brushes-commands.c * app/gui/color-notebook.c * app/gui/colormap-dialog.c * app/gui/dialogs-commands.c * app/gui/dialogs-constructors.c * app/gui/file-commands.c * app/gui/file-dialog-utils.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.[ch] * app/gui/file-save-dialog.c * app/gui/gradient-editor.c * app/gui/gradients-commands.c * app/gui/image-commands.c * app/gui/info-dialog.[ch] * app/gui/layer-select.c * app/gui/layers-commands.c * app/gui/menus.c * app/gui/offset-dialog.c * app/gui/palette-editor.c * app/gui/palettes-commands.c * app/gui/patterns-commands.c * app/gui/preferences-dialog.c * app/gui/resize-dialog.[ch] * app/gui/splash.c * app/gui/tips-dialog.c * app/gui/tool-options-dialog.c * app/gui/toolbox.c * app/gui/tools-commands.c * libgimp/gimpbrushmenu.c * libgimp/gimpmenu.c * libgimp/gimppatternmenu.c * libgimp/gimpui.c * libgimpbase/gimpenv.c: tons and tons of changes like "const gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete and currently disables), lots of s/gtk_signal/g_signal/, removal/replacement of deprecated stuff, s/GtkSignalFunc/GCallback/ and lots of small changes and fixes while I was on it, zillions of warnings left... * modules/Makefile.am: disabled the water color selector temporarily (XInput issues). * plug-ins/Makefile.am * plug-ins/common/.cvsignore * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl: simply excluded all plug-ins which did not build (including Script-Fu). They are trivial to fix.
2001-07-25 05:27:11 +08:00
const gchar *env_gimp_dir;
1999-03-07 20:56:03 +08:00
env_gimp_dir = g_getenv ("GIMP3_DIRECTORY");
if (gimp_dir)
{
gboolean gimp3_directory_changed = FALSE;
/* We have constructed the gimp_dir already. We can return
* gimp_dir unless some parameter gimp_dir depends on has
* changed. For now we just check for changes to GIMP3_DIRECTORY
*/
gimp3_directory_changed =
(env_gimp_dir == NULL &&
last_env_gimp_dir != NULL) ||
(env_gimp_dir != NULL &&
last_env_gimp_dir == NULL) ||
(env_gimp_dir != NULL &&
last_env_gimp_dir != NULL &&
strcmp (env_gimp_dir, last_env_gimp_dir) != 0);
if (! gimp3_directory_changed)
{
return gimp_dir;
}
else
{
/* Free the old gimp_dir and go on to update it */
g_free (gimp_dir);
gimp_dir = NULL;
}
}
1999-03-07 20:56:03 +08:00
/* Remember the GIMP3_DIRECTORY to next invocation so we can check
* if it changes
*/
g_free (last_env_gimp_dir);
last_env_gimp_dir = g_strdup (env_gimp_dir);
if (env_gimp_dir)
1999-03-07 20:56:03 +08:00
{
if (g_path_is_absolute (env_gimp_dir))
{
gimp_dir = g_strdup (env_gimp_dir);
}
1999-03-07 20:56:03 +08:00
else
{
const gchar *home_dir = g_get_home_dir ();
if (home_dir)
gimp_dir = g_build_filename (home_dir, env_gimp_dir, NULL);
else
gimp_dir = g_build_filename (gimp_data_directory (), env_gimp_dir, NULL);
}
1999-03-07 20:56:03 +08:00
}
else if (g_path_is_absolute (GIMPDIR))
{
gimp_dir = g_strdup (GIMPDIR);
}
1999-03-07 20:56:03 +08:00
else
{
#ifdef PLATFORM_OSX
NSAutoreleasePool *pool;
NSArray *path;
NSString *library_dir;
pool = [[NSAutoreleasePool alloc] init];
path = NSSearchPathForDirectoriesInDomains (NSApplicationSupportDirectory,
NSUserDomainMask, YES);
library_dir = [path objectAtIndex:0];
2012-05-12 22:48:05 +08:00
gimp_dir = g_build_filename ([library_dir UTF8String],
GIMPDIR, GIMP_USER_VERSION, NULL);
[pool drain];
#elif defined G_OS_WIN32
char *conf_dir = get_known_folder (&FOLDERID_RoamingAppData);
gimp_dir = g_build_filename (conf_dir,
GIMPDIR, GIMP_USER_VERSION, NULL);
g_free(conf_dir);
#else /* UNIX */
/* g_get_user_config_dir () always returns a path as a non-null
* and non-empty string
*/
gimp_dir = g_build_filename (g_get_user_config_dir (),
GIMPDIR, GIMP_USER_VERSION, NULL);
#endif /* PLATFORM_OSX */
1999-03-07 20:56:03 +08:00
}
return gimp_dir;
}
/**
* gimp_installation_directory:
*
* Returns the top installation directory of GIMP. On Unix the
* compile-time defined installation prefix is used. On Windows, the
* installation directory as deduced from the executable's full
* 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
* UTF-8.)
*
* Since: 2.8
*
* Returns: The toplevel installation directory of GIMP.
**/
const gchar *
gimp_installation_directory (void)
{
static gchar *toplevel = NULL;
if (toplevel)
return toplevel;
#ifdef G_OS_WIN32
2022-12-31 18:17:20 +08:00
toplevel = g_win32_get_package_installation_directory_of_module (this_module ());
if (! toplevel)
g_error ("g_win32_get_package_installation_directory_of_module() failed");
#elif PLATFORM_OSX
{
NSAutoreleasePool *pool;
NSString *resource_path;
gchar *basename;
gchar *basepath;
gchar *dirname;
pool = [[NSAutoreleasePool alloc] init];
resource_path = [[NSBundle mainBundle] resourcePath];
basename = g_path_get_basename ([resource_path UTF8String]);
basepath = g_path_get_dirname ([resource_path UTF8String]);
dirname = g_path_get_basename (basepath);
if (! strcmp (basename, ".libs"))
{
/* we are running from the source dir, do normal unix things */
toplevel = _gimp_reloc_find_prefix (PREFIX);
}
else if (! strcmp (basename, "bin"))
{
/* we are running the main app, but not from a bundle, the resource
* path is the directory which contains the executable
*/
toplevel = g_strdup (basepath);
}
else if (! strcmp (dirname, "plug-ins") ||
! strcmp (dirname, "extensions"))
{
/* same for plug-ins and extensions in subdirectory, go three
* levels up from prefix/lib/gimp/x.y
*/
gchar *tmp = g_path_get_dirname (basepath);
gchar *tmp2 = g_path_get_dirname (tmp);
gchar *tmp3 = g_path_get_dirname (tmp2);
toplevel = g_path_get_dirname (tmp3);
g_free (tmp);
g_free (tmp2);
g_free (tmp3);
}
else if (strstr (basepath, "/Cellar/"))
{
/* we are running from a Python.framework bundle built in homebrew
* during the build phase
*/
gchar *fulldir = g_strdup (basepath);
gchar *lastdir = g_path_get_basename (fulldir);
gchar *tmp_fulldir;
while (strcmp (lastdir, "Cellar"))
{
tmp_fulldir = g_path_get_dirname (fulldir);
g_free (lastdir);
g_free (fulldir);
fulldir = tmp_fulldir;
lastdir = g_path_get_basename (fulldir);
}
toplevel = g_path_get_dirname (fulldir);
g_free (fulldir);
g_free (lastdir);
}
else
{
/* if none of the above match, we assume that we are really in a bundle */
toplevel = g_strdup ([resource_path UTF8String]);
}
g_free (basename);
g_free (basepath);
g_free (dirname);
[pool drain];
}
#else
toplevel = _gimp_reloc_find_prefix (PREFIX);
#endif
return toplevel;
}
2000-02-07 07:16:24 +08:00
/**
* gimp_data_directory:
*
* 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.
*
* 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.
2000-02-07 07:16:24 +08:00
*
* 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.)
2000-02-07 07:16:24 +08:00
*
* Returns: The top directory for GIMP data.
**/
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
const gchar *
2000-02-07 07:16:24 +08:00
gimp_data_directory (void)
1999-03-07 20:56:03 +08:00
{
2000-02-07 07:16:24 +08:00
static gchar *gimp_data_dir = NULL;
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) 2001-07-24 Michael Natterer <mitch@gimp.org> Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) * configure.in: require glib/gtk+ >= 1.3.7, commented out the gtkxmhtml stuff. From now on, you will need glib, pango, atk and gtk+ HEAD from CVS to hack or use GIMP HEAD. Beware, it crashes randomly :) * app/core/Makefile.am * app/core/gimpmarshal.list: new file plus rules to generate gimpmarshal.[ch] from it. * app/core/* * app/tools/* * app/widgets/* * libgimpwidgets/*: started to use the glib object system. All core/ objects are still gtk objects however. All signals are created using g_signal_new(). There are many gtk+ artefacts left. Finally, we will _not_ use the gtk_signal_foo() wrappers and friends any more. * app/colormaps.c * app/devices.[ch] * app/disp_callbacks.c * app/errorconsole.c * app/file-save.[ch] * app/interface.c * app/module_db.c * app/nav_window.c * app/ops_buttons.c * app/scroll.c * app/user_install.c * app/gui/about-dialog.c * app/gui/brush-editor.c * app/gui/brushes-commands.c * app/gui/color-notebook.c * app/gui/colormap-dialog.c * app/gui/dialogs-commands.c * app/gui/dialogs-constructors.c * app/gui/file-commands.c * app/gui/file-dialog-utils.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.[ch] * app/gui/file-save-dialog.c * app/gui/gradient-editor.c * app/gui/gradients-commands.c * app/gui/image-commands.c * app/gui/info-dialog.[ch] * app/gui/layer-select.c * app/gui/layers-commands.c * app/gui/menus.c * app/gui/offset-dialog.c * app/gui/palette-editor.c * app/gui/palettes-commands.c * app/gui/patterns-commands.c * app/gui/preferences-dialog.c * app/gui/resize-dialog.[ch] * app/gui/splash.c * app/gui/tips-dialog.c * app/gui/tool-options-dialog.c * app/gui/toolbox.c * app/gui/tools-commands.c * libgimp/gimpbrushmenu.c * libgimp/gimpmenu.c * libgimp/gimppatternmenu.c * libgimp/gimpui.c * libgimpbase/gimpenv.c: tons and tons of changes like "const gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete and currently disables), lots of s/gtk_signal/g_signal/, removal/replacement of deprecated stuff, s/GtkSignalFunc/GCallback/ and lots of small changes and fixes while I was on it, zillions of warnings left... * modules/Makefile.am: disabled the water color selector temporarily (XInput issues). * plug-ins/Makefile.am * plug-ins/common/.cvsignore * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl: simply excluded all plug-ins which did not build (including Script-Fu). They are trivial to fix.
2001-07-25 05:27:11 +08:00
if (! gimp_data_dir)
{
gchar *tmp = g_build_filename ("share",
GIMP_PACKAGE,
GIMP_DATA_VERSION,
NULL);
gimp_data_dir = gimp_env_get_dir ("GIMP3_DATADIR", GIMPDATADIR, tmp);
g_free (tmp);
}
1999-03-07 20:56:03 +08:00
return gimp_data_dir;
}
add appconfig.lib. Statically link libgimptool/gimptool.lib. 2001-05-11 Hans Breuer <hans@breuer.org> * app/makefile.msc : add appconfig.lib. Statically link libgimptool/gimptool.lib. * app/main.c : use gimp_locale_directory() * app/config/gimpconfig-utils.c : <string.h> * app/config/makefile.msc : add gimpscanner * app/core/gimpimagefile.c : some G_OS_WIN32 mess to get mkdir() and chmod() * app/display/gimpdisplayshell.c app/plug-in/plug-in-progrss.c app/tool/gimpcolorpickertool.c app/tool/gimpcroptool.c app/tool/gimpmeasuretool.c app/tool/gimpperspectivetool.c app/tool/gimprotatetool.c app/tool/gimpscaletool.c app/tool/gimpsheartool.c app/tool/gimptransformtool.c app/widgets/gimpcolormapeditor.c app/widgets/gimpcolorpanel.c app/widgets/gimptoolbox-color-area.c add #ifdef __GNUC__ to avoid breaking on non standard pragma #warning * app/tools/makefile.msc : add gimptoolcontrol remove tools-enum * app/tools/tool_manager.c : need to include libgimptool/gimptoolcontrol.h after core includes otherwise we would compile without prototypes or break miserably * app/gui/plug-in-menus.c : replace LOCALEDIR with gimp_locale_directory () * app/gui/preferences-dialog.c (prefs_notebook_append_page) : only try to gdk_pixbuf_new_from_file() with a valid filename. It should simply return NULL otherwise, but fails if the filename is an empty string. * app/paint-funcs/makefile.msc : add -FImsvc_recommended_pragmas.h * app/widgets/gimpcolormapeditor.c : the 'row' allocated needs to be 'xn * cellsize * 2' (to avoid accessing unowned memory) not only width, which has become allocation.width by someone commenting out the correct size calculation * app/widgets/gimpdialogfactory.c : varargs to macros are GCCism or at least non standard. #define DEBUG to g_print or nothing - without arguments - does fix it somewhat dirty as the compiler needs to tolerate the '(blah, foo, bar);' statement than * app/widgets/makefile.msc : updated * app/xcf/makefile.msc : add -FImsvc_recommended_pragmas.h * etc/gimprc.win32 : use ';' to separate theme-path * libgimpbase/gimpenv.c : #include <stdio.h> for sprintf() * app/widgets/gimpdnd.c (gimp_dnd_set_file_data) : the passed in vals chunk is not always null-terminated (at least not on win32). Use the length parameter too to avoid reading junk filenames. * libgimp/gimp.def : export gimp_image_get_name() * libgimpbase/gimpbase.def : export gimp_locale_directory() * libgimpbase/gimpenv.[ch] : added gimp_locale_directory () * libgimpbase/makefile.msc : define DATADIR and SYSCONFDIR to empty string to let gimp find its files in the common place (win32: relative to the top level gimp dir) * plug-ins/common/pixelize.c : <string.h> * plug-ins/flame/cmap.c : #include <glib.h> for g_random_int() * plug-ins/makefile.msc : -FImsvc_recommended_pragams.h and a little hack to give imagemap the prototypes it desires without changing the lexed source * themes/Default/images/makefile.msc : now added (see below) * themes/Default/images/stock-button-reset.png : made it binary
2002-05-11 07:30:09 +08:00
/**
* gimp_locale_directory:
*
* Returns the top directory for GIMP locale files. If the environment
* variable GIMP3_LOCALEDIR exists, that is used. It should be an
add appconfig.lib. Statically link libgimptool/gimptool.lib. 2001-05-11 Hans Breuer <hans@breuer.org> * app/makefile.msc : add appconfig.lib. Statically link libgimptool/gimptool.lib. * app/main.c : use gimp_locale_directory() * app/config/gimpconfig-utils.c : <string.h> * app/config/makefile.msc : add gimpscanner * app/core/gimpimagefile.c : some G_OS_WIN32 mess to get mkdir() and chmod() * app/display/gimpdisplayshell.c app/plug-in/plug-in-progrss.c app/tool/gimpcolorpickertool.c app/tool/gimpcroptool.c app/tool/gimpmeasuretool.c app/tool/gimpperspectivetool.c app/tool/gimprotatetool.c app/tool/gimpscaletool.c app/tool/gimpsheartool.c app/tool/gimptransformtool.c app/widgets/gimpcolormapeditor.c app/widgets/gimpcolorpanel.c app/widgets/gimptoolbox-color-area.c add #ifdef __GNUC__ to avoid breaking on non standard pragma #warning * app/tools/makefile.msc : add gimptoolcontrol remove tools-enum * app/tools/tool_manager.c : need to include libgimptool/gimptoolcontrol.h after core includes otherwise we would compile without prototypes or break miserably * app/gui/plug-in-menus.c : replace LOCALEDIR with gimp_locale_directory () * app/gui/preferences-dialog.c (prefs_notebook_append_page) : only try to gdk_pixbuf_new_from_file() with a valid filename. It should simply return NULL otherwise, but fails if the filename is an empty string. * app/paint-funcs/makefile.msc : add -FImsvc_recommended_pragmas.h * app/widgets/gimpcolormapeditor.c : the 'row' allocated needs to be 'xn * cellsize * 2' (to avoid accessing unowned memory) not only width, which has become allocation.width by someone commenting out the correct size calculation * app/widgets/gimpdialogfactory.c : varargs to macros are GCCism or at least non standard. #define DEBUG to g_print or nothing - without arguments - does fix it somewhat dirty as the compiler needs to tolerate the '(blah, foo, bar);' statement than * app/widgets/makefile.msc : updated * app/xcf/makefile.msc : add -FImsvc_recommended_pragmas.h * etc/gimprc.win32 : use ';' to separate theme-path * libgimpbase/gimpenv.c : #include <stdio.h> for sprintf() * app/widgets/gimpdnd.c (gimp_dnd_set_file_data) : the passed in vals chunk is not always null-terminated (at least not on win32). Use the length parameter too to avoid reading junk filenames. * libgimp/gimp.def : export gimp_image_get_name() * libgimpbase/gimpbase.def : export gimp_locale_directory() * libgimpbase/gimpenv.[ch] : added gimp_locale_directory () * libgimpbase/makefile.msc : define DATADIR and SYSCONFDIR to empty string to let gimp find its files in the common place (win32: relative to the top level gimp dir) * plug-ins/common/pixelize.c : <string.h> * plug-ins/flame/cmap.c : #include <glib.h> for g_random_int() * plug-ins/makefile.msc : -FImsvc_recommended_pragams.h and a little hack to give imagemap the prototypes it desires without changing the lexed source * themes/Default/images/makefile.msc : now added (see below) * themes/Default/images/stock-button-reset.png : made it binary
2002-05-11 07:30:09 +08:00
* 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.
add appconfig.lib. Statically link libgimptool/gimptool.lib. 2001-05-11 Hans Breuer <hans@breuer.org> * app/makefile.msc : add appconfig.lib. Statically link libgimptool/gimptool.lib. * app/main.c : use gimp_locale_directory() * app/config/gimpconfig-utils.c : <string.h> * app/config/makefile.msc : add gimpscanner * app/core/gimpimagefile.c : some G_OS_WIN32 mess to get mkdir() and chmod() * app/display/gimpdisplayshell.c app/plug-in/plug-in-progrss.c app/tool/gimpcolorpickertool.c app/tool/gimpcroptool.c app/tool/gimpmeasuretool.c app/tool/gimpperspectivetool.c app/tool/gimprotatetool.c app/tool/gimpscaletool.c app/tool/gimpsheartool.c app/tool/gimptransformtool.c app/widgets/gimpcolormapeditor.c app/widgets/gimpcolorpanel.c app/widgets/gimptoolbox-color-area.c add #ifdef __GNUC__ to avoid breaking on non standard pragma #warning * app/tools/makefile.msc : add gimptoolcontrol remove tools-enum * app/tools/tool_manager.c : need to include libgimptool/gimptoolcontrol.h after core includes otherwise we would compile without prototypes or break miserably * app/gui/plug-in-menus.c : replace LOCALEDIR with gimp_locale_directory () * app/gui/preferences-dialog.c (prefs_notebook_append_page) : only try to gdk_pixbuf_new_from_file() with a valid filename. It should simply return NULL otherwise, but fails if the filename is an empty string. * app/paint-funcs/makefile.msc : add -FImsvc_recommended_pragmas.h * app/widgets/gimpcolormapeditor.c : the 'row' allocated needs to be 'xn * cellsize * 2' (to avoid accessing unowned memory) not only width, which has become allocation.width by someone commenting out the correct size calculation * app/widgets/gimpdialogfactory.c : varargs to macros are GCCism or at least non standard. #define DEBUG to g_print or nothing - without arguments - does fix it somewhat dirty as the compiler needs to tolerate the '(blah, foo, bar);' statement than * app/widgets/makefile.msc : updated * app/xcf/makefile.msc : add -FImsvc_recommended_pragmas.h * etc/gimprc.win32 : use ';' to separate theme-path * libgimpbase/gimpenv.c : #include <stdio.h> for sprintf() * app/widgets/gimpdnd.c (gimp_dnd_set_file_data) : the passed in vals chunk is not always null-terminated (at least not on win32). Use the length parameter too to avoid reading junk filenames. * libgimp/gimp.def : export gimp_image_get_name() * libgimpbase/gimpbase.def : export gimp_locale_directory() * libgimpbase/gimpenv.[ch] : added gimp_locale_directory () * libgimpbase/makefile.msc : define DATADIR and SYSCONFDIR to empty string to let gimp find its files in the common place (win32: relative to the top level gimp dir) * plug-ins/common/pixelize.c : <string.h> * plug-ins/flame/cmap.c : #include <glib.h> for g_random_int() * plug-ins/makefile.msc : -FImsvc_recommended_pragams.h and a little hack to give imagemap the prototypes it desires without changing the lexed source * themes/Default/images/makefile.msc : now added (see below) * themes/Default/images/stock-button-reset.png : made it binary
2002-05-11 07:30:09 +08:00
*
* The returned string is owned by GIMP and must not be modified or
* freed. The returned string encoding depends on the system where GIMP
* is running: on UNIX it's in the encoding used for filenames by
* the C library (which isn't necessarily UTF-8); on Windows it's UTF-8.
*
* On UNIX the returned string can be passed directly to the bindtextdomain()
* function from libintl; on Windows the returned string can be converted to
* UTF-16 and passed to the wbindtextdomain() function from libintl.
add appconfig.lib. Statically link libgimptool/gimptool.lib. 2001-05-11 Hans Breuer <hans@breuer.org> * app/makefile.msc : add appconfig.lib. Statically link libgimptool/gimptool.lib. * app/main.c : use gimp_locale_directory() * app/config/gimpconfig-utils.c : <string.h> * app/config/makefile.msc : add gimpscanner * app/core/gimpimagefile.c : some G_OS_WIN32 mess to get mkdir() and chmod() * app/display/gimpdisplayshell.c app/plug-in/plug-in-progrss.c app/tool/gimpcolorpickertool.c app/tool/gimpcroptool.c app/tool/gimpmeasuretool.c app/tool/gimpperspectivetool.c app/tool/gimprotatetool.c app/tool/gimpscaletool.c app/tool/gimpsheartool.c app/tool/gimptransformtool.c app/widgets/gimpcolormapeditor.c app/widgets/gimpcolorpanel.c app/widgets/gimptoolbox-color-area.c add #ifdef __GNUC__ to avoid breaking on non standard pragma #warning * app/tools/makefile.msc : add gimptoolcontrol remove tools-enum * app/tools/tool_manager.c : need to include libgimptool/gimptoolcontrol.h after core includes otherwise we would compile without prototypes or break miserably * app/gui/plug-in-menus.c : replace LOCALEDIR with gimp_locale_directory () * app/gui/preferences-dialog.c (prefs_notebook_append_page) : only try to gdk_pixbuf_new_from_file() with a valid filename. It should simply return NULL otherwise, but fails if the filename is an empty string. * app/paint-funcs/makefile.msc : add -FImsvc_recommended_pragmas.h * app/widgets/gimpcolormapeditor.c : the 'row' allocated needs to be 'xn * cellsize * 2' (to avoid accessing unowned memory) not only width, which has become allocation.width by someone commenting out the correct size calculation * app/widgets/gimpdialogfactory.c : varargs to macros are GCCism or at least non standard. #define DEBUG to g_print or nothing - without arguments - does fix it somewhat dirty as the compiler needs to tolerate the '(blah, foo, bar);' statement than * app/widgets/makefile.msc : updated * app/xcf/makefile.msc : add -FImsvc_recommended_pragmas.h * etc/gimprc.win32 : use ';' to separate theme-path * libgimpbase/gimpenv.c : #include <stdio.h> for sprintf() * app/widgets/gimpdnd.c (gimp_dnd_set_file_data) : the passed in vals chunk is not always null-terminated (at least not on win32). Use the length parameter too to avoid reading junk filenames. * libgimp/gimp.def : export gimp_image_get_name() * libgimpbase/gimpbase.def : export gimp_locale_directory() * libgimpbase/gimpenv.[ch] : added gimp_locale_directory () * libgimpbase/makefile.msc : define DATADIR and SYSCONFDIR to empty string to let gimp find its files in the common place (win32: relative to the top level gimp dir) * plug-ins/common/pixelize.c : <string.h> * plug-ins/flame/cmap.c : #include <glib.h> for g_random_int() * plug-ins/makefile.msc : -FImsvc_recommended_pragams.h and a little hack to give imagemap the prototypes it desires without changing the lexed source * themes/Default/images/makefile.msc : now added (see below) * themes/Default/images/stock-button-reset.png : made it binary
2002-05-11 07:30:09 +08:00
*
* Returns: (type filename): The top directory for GIMP locale files.
add appconfig.lib. Statically link libgimptool/gimptool.lib. 2001-05-11 Hans Breuer <hans@breuer.org> * app/makefile.msc : add appconfig.lib. Statically link libgimptool/gimptool.lib. * app/main.c : use gimp_locale_directory() * app/config/gimpconfig-utils.c : <string.h> * app/config/makefile.msc : add gimpscanner * app/core/gimpimagefile.c : some G_OS_WIN32 mess to get mkdir() and chmod() * app/display/gimpdisplayshell.c app/plug-in/plug-in-progrss.c app/tool/gimpcolorpickertool.c app/tool/gimpcroptool.c app/tool/gimpmeasuretool.c app/tool/gimpperspectivetool.c app/tool/gimprotatetool.c app/tool/gimpscaletool.c app/tool/gimpsheartool.c app/tool/gimptransformtool.c app/widgets/gimpcolormapeditor.c app/widgets/gimpcolorpanel.c app/widgets/gimptoolbox-color-area.c add #ifdef __GNUC__ to avoid breaking on non standard pragma #warning * app/tools/makefile.msc : add gimptoolcontrol remove tools-enum * app/tools/tool_manager.c : need to include libgimptool/gimptoolcontrol.h after core includes otherwise we would compile without prototypes or break miserably * app/gui/plug-in-menus.c : replace LOCALEDIR with gimp_locale_directory () * app/gui/preferences-dialog.c (prefs_notebook_append_page) : only try to gdk_pixbuf_new_from_file() with a valid filename. It should simply return NULL otherwise, but fails if the filename is an empty string. * app/paint-funcs/makefile.msc : add -FImsvc_recommended_pragmas.h * app/widgets/gimpcolormapeditor.c : the 'row' allocated needs to be 'xn * cellsize * 2' (to avoid accessing unowned memory) not only width, which has become allocation.width by someone commenting out the correct size calculation * app/widgets/gimpdialogfactory.c : varargs to macros are GCCism or at least non standard. #define DEBUG to g_print or nothing - without arguments - does fix it somewhat dirty as the compiler needs to tolerate the '(blah, foo, bar);' statement than * app/widgets/makefile.msc : updated * app/xcf/makefile.msc : add -FImsvc_recommended_pragmas.h * etc/gimprc.win32 : use ';' to separate theme-path * libgimpbase/gimpenv.c : #include <stdio.h> for sprintf() * app/widgets/gimpdnd.c (gimp_dnd_set_file_data) : the passed in vals chunk is not always null-terminated (at least not on win32). Use the length parameter too to avoid reading junk filenames. * libgimp/gimp.def : export gimp_image_get_name() * libgimpbase/gimpbase.def : export gimp_locale_directory() * libgimpbase/gimpenv.[ch] : added gimp_locale_directory () * libgimpbase/makefile.msc : define DATADIR and SYSCONFDIR to empty string to let gimp find its files in the common place (win32: relative to the top level gimp dir) * plug-ins/common/pixelize.c : <string.h> * plug-ins/flame/cmap.c : #include <glib.h> for g_random_int() * plug-ins/makefile.msc : -FImsvc_recommended_pragams.h and a little hack to give imagemap the prototypes it desires without changing the lexed source * themes/Default/images/makefile.msc : now added (see below) * themes/Default/images/stock-button-reset.png : made it binary
2002-05-11 07:30:09 +08:00
*/
const gchar *
gimp_locale_directory (void)
{
static gchar *gimp_locale_dir = NULL;
if (! gimp_locale_dir)
{
gchar *tmp = g_build_filename ("share",
"locale",
NULL);
gimp_locale_dir = gimp_env_get_dir ("GIMP3_LOCALEDIR", LOCALEDIR, tmp);
g_free (tmp);
}
add appconfig.lib. Statically link libgimptool/gimptool.lib. 2001-05-11 Hans Breuer <hans@breuer.org> * app/makefile.msc : add appconfig.lib. Statically link libgimptool/gimptool.lib. * app/main.c : use gimp_locale_directory() * app/config/gimpconfig-utils.c : <string.h> * app/config/makefile.msc : add gimpscanner * app/core/gimpimagefile.c : some G_OS_WIN32 mess to get mkdir() and chmod() * app/display/gimpdisplayshell.c app/plug-in/plug-in-progrss.c app/tool/gimpcolorpickertool.c app/tool/gimpcroptool.c app/tool/gimpmeasuretool.c app/tool/gimpperspectivetool.c app/tool/gimprotatetool.c app/tool/gimpscaletool.c app/tool/gimpsheartool.c app/tool/gimptransformtool.c app/widgets/gimpcolormapeditor.c app/widgets/gimpcolorpanel.c app/widgets/gimptoolbox-color-area.c add #ifdef __GNUC__ to avoid breaking on non standard pragma #warning * app/tools/makefile.msc : add gimptoolcontrol remove tools-enum * app/tools/tool_manager.c : need to include libgimptool/gimptoolcontrol.h after core includes otherwise we would compile without prototypes or break miserably * app/gui/plug-in-menus.c : replace LOCALEDIR with gimp_locale_directory () * app/gui/preferences-dialog.c (prefs_notebook_append_page) : only try to gdk_pixbuf_new_from_file() with a valid filename. It should simply return NULL otherwise, but fails if the filename is an empty string. * app/paint-funcs/makefile.msc : add -FImsvc_recommended_pragmas.h * app/widgets/gimpcolormapeditor.c : the 'row' allocated needs to be 'xn * cellsize * 2' (to avoid accessing unowned memory) not only width, which has become allocation.width by someone commenting out the correct size calculation * app/widgets/gimpdialogfactory.c : varargs to macros are GCCism or at least non standard. #define DEBUG to g_print or nothing - without arguments - does fix it somewhat dirty as the compiler needs to tolerate the '(blah, foo, bar);' statement than * app/widgets/makefile.msc : updated * app/xcf/makefile.msc : add -FImsvc_recommended_pragmas.h * etc/gimprc.win32 : use ';' to separate theme-path * libgimpbase/gimpenv.c : #include <stdio.h> for sprintf() * app/widgets/gimpdnd.c (gimp_dnd_set_file_data) : the passed in vals chunk is not always null-terminated (at least not on win32). Use the length parameter too to avoid reading junk filenames. * libgimp/gimp.def : export gimp_image_get_name() * libgimpbase/gimpbase.def : export gimp_locale_directory() * libgimpbase/gimpenv.[ch] : added gimp_locale_directory () * libgimpbase/makefile.msc : define DATADIR and SYSCONFDIR to empty string to let gimp find its files in the common place (win32: relative to the top level gimp dir) * plug-ins/common/pixelize.c : <string.h> * plug-ins/flame/cmap.c : #include <glib.h> for g_random_int() * plug-ins/makefile.msc : -FImsvc_recommended_pragams.h and a little hack to give imagemap the prototypes it desires without changing the lexed source * themes/Default/images/makefile.msc : now added (see below) * themes/Default/images/stock-button-reset.png : made it binary
2002-05-11 07:30:09 +08:00
return gimp_locale_dir;
}
/**
* gimp_sysconf_directory:
*
* Returns the top directory for GIMP config files. If the environment
* variable GIMP3_SYSCONFDIR 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.
*
* 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
* UTF-8.).
*
* Returns: The top directory for GIMP config files.
**/
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
const gchar *
gimp_sysconf_directory (void)
{
static gchar *gimp_sysconf_dir = NULL;
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) 2001-07-24 Michael Natterer <mitch@gimp.org> Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) * configure.in: require glib/gtk+ >= 1.3.7, commented out the gtkxmhtml stuff. From now on, you will need glib, pango, atk and gtk+ HEAD from CVS to hack or use GIMP HEAD. Beware, it crashes randomly :) * app/core/Makefile.am * app/core/gimpmarshal.list: new file plus rules to generate gimpmarshal.[ch] from it. * app/core/* * app/tools/* * app/widgets/* * libgimpwidgets/*: started to use the glib object system. All core/ objects are still gtk objects however. All signals are created using g_signal_new(). There are many gtk+ artefacts left. Finally, we will _not_ use the gtk_signal_foo() wrappers and friends any more. * app/colormaps.c * app/devices.[ch] * app/disp_callbacks.c * app/errorconsole.c * app/file-save.[ch] * app/interface.c * app/module_db.c * app/nav_window.c * app/ops_buttons.c * app/scroll.c * app/user_install.c * app/gui/about-dialog.c * app/gui/brush-editor.c * app/gui/brushes-commands.c * app/gui/color-notebook.c * app/gui/colormap-dialog.c * app/gui/dialogs-commands.c * app/gui/dialogs-constructors.c * app/gui/file-commands.c * app/gui/file-dialog-utils.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.[ch] * app/gui/file-save-dialog.c * app/gui/gradient-editor.c * app/gui/gradients-commands.c * app/gui/image-commands.c * app/gui/info-dialog.[ch] * app/gui/layer-select.c * app/gui/layers-commands.c * app/gui/menus.c * app/gui/offset-dialog.c * app/gui/palette-editor.c * app/gui/palettes-commands.c * app/gui/patterns-commands.c * app/gui/preferences-dialog.c * app/gui/resize-dialog.[ch] * app/gui/splash.c * app/gui/tips-dialog.c * app/gui/tool-options-dialog.c * app/gui/toolbox.c * app/gui/tools-commands.c * libgimp/gimpbrushmenu.c * libgimp/gimpmenu.c * libgimp/gimppatternmenu.c * libgimp/gimpui.c * libgimpbase/gimpenv.c: tons and tons of changes like "const gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete and currently disables), lots of s/gtk_signal/g_signal/, removal/replacement of deprecated stuff, s/GtkSignalFunc/GCallback/ and lots of small changes and fixes while I was on it, zillions of warnings left... * modules/Makefile.am: disabled the water color selector temporarily (XInput issues). * plug-ins/Makefile.am * plug-ins/common/.cvsignore * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl: simply excluded all plug-ins which did not build (including Script-Fu). They are trivial to fix.
2001-07-25 05:27:11 +08:00
if (! gimp_sysconf_dir)
{
gchar *tmp = g_build_filename ("etc",
GIMP_PACKAGE,
GIMP_SYSCONF_VERSION,
NULL);
gimp_sysconf_dir = gimp_env_get_dir ("GIMP3_SYSCONFDIR", GIMPSYSCONFDIR, tmp);
g_free (tmp);
}
return gimp_sysconf_dir;
}
/**
* gimp_plug_in_directory:
*
* 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.
*
* 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
* GLib, which isn't necessarily UTF-8. (On Windows it always is
* UTF-8.)
*
* Returns: The top directory for GIMP plug_ins and modules.
**/
const gchar *
gimp_plug_in_directory (void)
{
static gchar *gimp_plug_in_dir = NULL;
if (! gimp_plug_in_dir)
{
gchar *tmp = g_build_filename ("lib",
GIMP_PACKAGE,
GIMP_PLUGIN_VERSION,
NULL);
gimp_plug_in_dir = gimp_env_get_dir ("GIMP3_PLUGINDIR", PLUGINDIR, tmp);
g_free (tmp);
}
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,
va_list args)
{
GFile *file = g_file_new_for_path (parent);
while (element)
{
GFile *child = g_file_get_child (file, element);
g_object_unref (file);
file = child;
element = va_arg (args, const gchar *);
}
return file;
}
/**
* gimp_directory_file: (skip)
* @first_element: the first element of a path to a file in the
* user's GIMP directory, or %NULL.
* @...: a %NULL terminated list of the remaining elements of the path
* to the file.
*
* Returns a #GFile in the user's GIMP directory, or the GIMP
* directory itself if @first_element is %NULL.
*
* See also: gimp_directory().
*
* Since: 2.10
*
* Returns: (transfer full):
* a new @GFile for the path, Free with g_object_unref().
**/
GFile *
gimp_directory_file (const gchar *first_element,
...)
{
GFile *file;
va_list args;
va_start (args, first_element);
file = gimp_child_file (gimp_directory (), first_element, args);
va_end (args);
return file;
}
/**
* gimp_installation_directory_file: (skip)
* @first_element: the first element of a path to a file in the
* top installation directory, or %NULL.
* @...: a %NULL terminated list of the remaining elements of the path
* to the file.
*
* Returns a #GFile in the installation directory, or the installation
* directory itself if @first_element is %NULL.
*
* See also: gimp_installation_directory().
*
* Since: 2.10.10
*
* Returns: (transfer full):
* a new @GFile for the path, Free with g_object_unref().
**/
GFile *
gimp_installation_directory_file (const gchar *first_element,
...)
{
GFile *file;
va_list args;
va_start (args, first_element);
file = gimp_child_file (gimp_installation_directory (), first_element, args);
va_end (args);
return file;
}
/**
* gimp_data_directory_file: (skip)
* @first_element: the first element of a path to a file in the
* data directory, or %NULL.
* @...: a %NULL terminated list of the remaining elements of the path
* to the file.
*
* Returns a #GFile in the data directory, or the data directory
* itself if @first_element is %NULL.
*
* See also: gimp_data_directory().
*
* Since: 2.10
*
* Returns: (transfer full):
* a new @GFile for the path, Free with g_object_unref().
**/
GFile *
gimp_data_directory_file (const gchar *first_element,
...)
{
GFile *file;
va_list args;
va_start (args, first_element);
file = gimp_child_file (gimp_data_directory (), first_element, args);
va_end (args);
return file;
}
/**
* gimp_locale_directory_file: (skip)
* @first_element: the first element of a path to a file in the
* locale directory, or %NULL.
* @...: a %NULL terminated list of the remaining elements of the path
* to the file.
*
* Returns a #GFile in the locale directory, or the locale directory
* itself if @first_element is %NULL.
*
* See also: gimp_locale_directory().
*
* Since: 2.10
*
* Returns: (transfer full):
* a new @GFile for the path, Free with g_object_unref().
**/
GFile *
gimp_locale_directory_file (const gchar *first_element,
...)
{
GFile *file;
va_list args;
va_start (args, first_element);
file = gimp_child_file (gimp_locale_directory (), first_element, args);
va_end (args);
return file;
}
/**
* gimp_sysconf_directory_file:
* @first_element: the first element of a path to a file in the
* sysconf directory, or %NULL.
* @...: a %NULL terminated list of the remaining elements of the path
* to the file.
*
* Returns a #GFile in the sysconf directory, or the sysconf directory
* itself if @first_element is %NULL.
*
* See also: gimp_sysconf_directory().
*
* Since: 2.10
*
* Returns: (transfer full):
* a new @GFile for the path, Free with g_object_unref().
**/
GFile *
gimp_sysconf_directory_file (const gchar *first_element,
...)
{
GFile *file;
va_list args;
va_start (args, first_element);
file = gimp_child_file (gimp_sysconf_directory (), first_element, args);
va_end (args);
return file;
}
/**
* gimp_plug_in_directory_file:
* @first_element: the first element of a path to a file in the
* plug-in directory, or %NULL.
* @...: a %NULL terminated list of the remaining elements of the path
* to the file.
*
* Returns a #GFile in the plug-in directory, or the plug-in directory
* itself if @first_element is %NULL.
*
* See also: gimp_plug_in_directory().
*
* Since: 2.10
*
* Returns: (transfer full):
* a new @GFile for the path, Free with g_object_unref().
**/
GFile *
gimp_plug_in_directory_file (const gchar *first_element,
...)
{
GFile *file;
va_list args;
va_start (args, first_element);
file = gimp_child_file (gimp_plug_in_directory (), first_element, args);
va_end (args);
return file;
}
/**
* gimp_path_runtime_fix:
* @path: A pointer to a string (allocated with g_malloc) that is
* (or could be) a pathname.
*
* On Windows, this function checks if the string pointed to by @path
* starts with the compile-time prefix, and in that case, replaces the
* prefix with the run-time one. @path should be a pointer to a
* dynamically allocated (with g_malloc, g_strconcat, etc) string. If
* the replacement takes place, the original string is deallocated,
* and *@path is replaced with a pointer to a new string with the
* run-time prefix spliced in.
*
* On Linux and other Unices, it does the same thing, but only if BinReloc
* support is enabled, and only if we are not running GIMP in-build directory.
*/
static void
gimp_path_runtime_fix (gchar **path)
{
#if defined (G_OS_WIN32) && defined (PREFIX)
gchar *p;
/* Yes, I do mean forward slashes below */
if (strncmp (*path, PREFIX "/", strlen (PREFIX "/")) == 0)
{
/* This is a compile-time entry. Replace the path with the
* real one on this machine.
*/
p = *path;
*path = g_strconcat (gimp_installation_directory (),
"\\",
*path + strlen (PREFIX "/"),
NULL);
g_free (p);
}
/* Replace forward slashes with backslashes, just for
* completeness */
p = *path;
while ((p = strchr (p, '/')) != NULL)
{
*p = '\\';
p++;
}
add appconfig.lib. Statically link libgimptool/gimptool.lib. 2001-05-11 Hans Breuer <hans@breuer.org> * app/makefile.msc : add appconfig.lib. Statically link libgimptool/gimptool.lib. * app/main.c : use gimp_locale_directory() * app/config/gimpconfig-utils.c : <string.h> * app/config/makefile.msc : add gimpscanner * app/core/gimpimagefile.c : some G_OS_WIN32 mess to get mkdir() and chmod() * app/display/gimpdisplayshell.c app/plug-in/plug-in-progrss.c app/tool/gimpcolorpickertool.c app/tool/gimpcroptool.c app/tool/gimpmeasuretool.c app/tool/gimpperspectivetool.c app/tool/gimprotatetool.c app/tool/gimpscaletool.c app/tool/gimpsheartool.c app/tool/gimptransformtool.c app/widgets/gimpcolormapeditor.c app/widgets/gimpcolorpanel.c app/widgets/gimptoolbox-color-area.c add #ifdef __GNUC__ to avoid breaking on non standard pragma #warning * app/tools/makefile.msc : add gimptoolcontrol remove tools-enum * app/tools/tool_manager.c : need to include libgimptool/gimptoolcontrol.h after core includes otherwise we would compile without prototypes or break miserably * app/gui/plug-in-menus.c : replace LOCALEDIR with gimp_locale_directory () * app/gui/preferences-dialog.c (prefs_notebook_append_page) : only try to gdk_pixbuf_new_from_file() with a valid filename. It should simply return NULL otherwise, but fails if the filename is an empty string. * app/paint-funcs/makefile.msc : add -FImsvc_recommended_pragmas.h * app/widgets/gimpcolormapeditor.c : the 'row' allocated needs to be 'xn * cellsize * 2' (to avoid accessing unowned memory) not only width, which has become allocation.width by someone commenting out the correct size calculation * app/widgets/gimpdialogfactory.c : varargs to macros are GCCism or at least non standard. #define DEBUG to g_print or nothing - without arguments - does fix it somewhat dirty as the compiler needs to tolerate the '(blah, foo, bar);' statement than * app/widgets/makefile.msc : updated * app/xcf/makefile.msc : add -FImsvc_recommended_pragmas.h * etc/gimprc.win32 : use ';' to separate theme-path * libgimpbase/gimpenv.c : #include <stdio.h> for sprintf() * app/widgets/gimpdnd.c (gimp_dnd_set_file_data) : the passed in vals chunk is not always null-terminated (at least not on win32). Use the length parameter too to avoid reading junk filenames. * libgimp/gimp.def : export gimp_image_get_name() * libgimpbase/gimpbase.def : export gimp_locale_directory() * libgimpbase/gimpenv.[ch] : added gimp_locale_directory () * libgimpbase/makefile.msc : define DATADIR and SYSCONFDIR to empty string to let gimp find its files in the common place (win32: relative to the top level gimp dir) * plug-ins/common/pixelize.c : <string.h> * plug-ins/flame/cmap.c : #include <glib.h> for g_random_int() * plug-ins/makefile.msc : -FImsvc_recommended_pragams.h and a little hack to give imagemap the prototypes it desires without changing the lexed source * themes/Default/images/makefile.msc : now added (see below) * themes/Default/images/stock-button-reset.png : made it binary
2002-05-11 07:30:09 +08:00
#elif defined (G_OS_WIN32)
/* without defineing PREFIX do something useful too */
gchar *p = *path;
if (!g_path_is_absolute (p))
{
*path = g_build_filename (gimp_installation_directory (), *path, NULL);
add appconfig.lib. Statically link libgimptool/gimptool.lib. 2001-05-11 Hans Breuer <hans@breuer.org> * app/makefile.msc : add appconfig.lib. Statically link libgimptool/gimptool.lib. * app/main.c : use gimp_locale_directory() * app/config/gimpconfig-utils.c : <string.h> * app/config/makefile.msc : add gimpscanner * app/core/gimpimagefile.c : some G_OS_WIN32 mess to get mkdir() and chmod() * app/display/gimpdisplayshell.c app/plug-in/plug-in-progrss.c app/tool/gimpcolorpickertool.c app/tool/gimpcroptool.c app/tool/gimpmeasuretool.c app/tool/gimpperspectivetool.c app/tool/gimprotatetool.c app/tool/gimpscaletool.c app/tool/gimpsheartool.c app/tool/gimptransformtool.c app/widgets/gimpcolormapeditor.c app/widgets/gimpcolorpanel.c app/widgets/gimptoolbox-color-area.c add #ifdef __GNUC__ to avoid breaking on non standard pragma #warning * app/tools/makefile.msc : add gimptoolcontrol remove tools-enum * app/tools/tool_manager.c : need to include libgimptool/gimptoolcontrol.h after core includes otherwise we would compile without prototypes or break miserably * app/gui/plug-in-menus.c : replace LOCALEDIR with gimp_locale_directory () * app/gui/preferences-dialog.c (prefs_notebook_append_page) : only try to gdk_pixbuf_new_from_file() with a valid filename. It should simply return NULL otherwise, but fails if the filename is an empty string. * app/paint-funcs/makefile.msc : add -FImsvc_recommended_pragmas.h * app/widgets/gimpcolormapeditor.c : the 'row' allocated needs to be 'xn * cellsize * 2' (to avoid accessing unowned memory) not only width, which has become allocation.width by someone commenting out the correct size calculation * app/widgets/gimpdialogfactory.c : varargs to macros are GCCism or at least non standard. #define DEBUG to g_print or nothing - without arguments - does fix it somewhat dirty as the compiler needs to tolerate the '(blah, foo, bar);' statement than * app/widgets/makefile.msc : updated * app/xcf/makefile.msc : add -FImsvc_recommended_pragmas.h * etc/gimprc.win32 : use ';' to separate theme-path * libgimpbase/gimpenv.c : #include <stdio.h> for sprintf() * app/widgets/gimpdnd.c (gimp_dnd_set_file_data) : the passed in vals chunk is not always null-terminated (at least not on win32). Use the length parameter too to avoid reading junk filenames. * libgimp/gimp.def : export gimp_image_get_name() * libgimpbase/gimpbase.def : export gimp_locale_directory() * libgimpbase/gimpenv.[ch] : added gimp_locale_directory () * libgimpbase/makefile.msc : define DATADIR and SYSCONFDIR to empty string to let gimp find its files in the common place (win32: relative to the top level gimp dir) * plug-ins/common/pixelize.c : <string.h> * plug-ins/flame/cmap.c : #include <glib.h> for g_random_int() * plug-ins/makefile.msc : -FImsvc_recommended_pragams.h and a little hack to give imagemap the prototypes it desires without changing the lexed source * themes/Default/images/makefile.msc : now added (see below) * themes/Default/images/stock-button-reset.png : made it binary
2002-05-11 07:30:09 +08:00
g_free (p);
}
#elif defined (ENABLE_RELOCATABLE_RESOURCES)
gchar *p;
/* XXX: I could actually test any of the other GIMP_TESTING_* environment
* variables. The goal is only to check if we are running GIMP from within the
* build directory. In such case, no substitution should happen.
*/
if (! g_getenv ("GIMP_TESTING_PLUGINDIRS") &&
strncmp (*path, PREFIX G_DIR_SEPARATOR_S,
strlen (PREFIX G_DIR_SEPARATOR_S)) == 0)
{
/* This is a compile-time entry. Replace the path with the
* real one on this machine.
*/
p = *path;
*path = g_build_filename (gimp_installation_directory (),
*path + strlen (PREFIX G_DIR_SEPARATOR_S),
NULL);
g_free (p);
}
#endif
}
/**
* gimp_path_parse:
* @path: A list of directories separated by #G_SEARCHPATH_SEPARATOR.
* @max_paths: The maximum number of directories to return.
* @check: %TRUE if you want the directories to be checked.
* @check_failed: (element-type filename) (out callee-allocates):
Returns a #GList of path elements for which the check failed.
*
* Returns: (element-type filename) (transfer full):
A #GList of all directories in @path.
**/
GList *
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
gimp_path_parse (const gchar *path,
gint max_paths,
gboolean check,
GList **check_failed)
{
gchar **patharray;
GList *list = NULL;
GList *fail_list = NULL;
gint i;
gboolean exists = TRUE;
if (!path || !*path || max_paths < 1 || max_paths > 256)
return NULL;
2000-02-07 07:16:24 +08:00
patharray = g_strsplit (path, G_SEARCHPATH_SEPARATOR_S, max_paths);
for (i = 0; i < max_paths; i++)
{
GString *dir;
2000-02-07 07:16:24 +08:00
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) 2001-07-24 Michael Natterer <mitch@gimp.org> Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) * configure.in: require glib/gtk+ >= 1.3.7, commented out the gtkxmhtml stuff. From now on, you will need glib, pango, atk and gtk+ HEAD from CVS to hack or use GIMP HEAD. Beware, it crashes randomly :) * app/core/Makefile.am * app/core/gimpmarshal.list: new file plus rules to generate gimpmarshal.[ch] from it. * app/core/* * app/tools/* * app/widgets/* * libgimpwidgets/*: started to use the glib object system. All core/ objects are still gtk objects however. All signals are created using g_signal_new(). There are many gtk+ artefacts left. Finally, we will _not_ use the gtk_signal_foo() wrappers and friends any more. * app/colormaps.c * app/devices.[ch] * app/disp_callbacks.c * app/errorconsole.c * app/file-save.[ch] * app/interface.c * app/module_db.c * app/nav_window.c * app/ops_buttons.c * app/scroll.c * app/user_install.c * app/gui/about-dialog.c * app/gui/brush-editor.c * app/gui/brushes-commands.c * app/gui/color-notebook.c * app/gui/colormap-dialog.c * app/gui/dialogs-commands.c * app/gui/dialogs-constructors.c * app/gui/file-commands.c * app/gui/file-dialog-utils.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.[ch] * app/gui/file-save-dialog.c * app/gui/gradient-editor.c * app/gui/gradients-commands.c * app/gui/image-commands.c * app/gui/info-dialog.[ch] * app/gui/layer-select.c * app/gui/layers-commands.c * app/gui/menus.c * app/gui/offset-dialog.c * app/gui/palette-editor.c * app/gui/palettes-commands.c * app/gui/patterns-commands.c * app/gui/preferences-dialog.c * app/gui/resize-dialog.[ch] * app/gui/splash.c * app/gui/tips-dialog.c * app/gui/tool-options-dialog.c * app/gui/toolbox.c * app/gui/tools-commands.c * libgimp/gimpbrushmenu.c * libgimp/gimpmenu.c * libgimp/gimppatternmenu.c * libgimp/gimpui.c * libgimpbase/gimpenv.c: tons and tons of changes like "const gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete and currently disables), lots of s/gtk_signal/g_signal/, removal/replacement of deprecated stuff, s/GtkSignalFunc/GCallback/ and lots of small changes and fixes while I was on it, zillions of warnings left... * modules/Makefile.am: disabled the water color selector temporarily (XInput issues). * plug-ins/Makefile.am * plug-ins/common/.cvsignore * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl: simply excluded all plug-ins which did not build (including Script-Fu). They are trivial to fix.
2001-07-25 05:27:11 +08:00
if (! patharray[i])
break;
#ifndef G_OS_WIN32
if (*patharray[i] == '~')
{
dir = g_string_new (g_get_home_dir ());
g_string_append (dir, patharray[i] + 1);
}
else
#endif
{
gimp_path_runtime_fix (&patharray[i]);
dir = g_string_new (patharray[i]);
}
if (check)
exists = g_file_test (dir->str, G_FILE_TEST_IS_DIR);
if (exists)
{
GList *dup;
/* check for duplicate entries, see bug #784502 */
for (dup = list; dup; dup = g_list_next (dup))
{
if (! strcmp (dir->str, dup->data))
break;
}
/* only add to the list if it's not a duplicate */
if (! dup)
list = g_list_prepend (list, g_strdup (dir->str));
}
else if (check_failed)
{
fail_list = g_list_prepend (fail_list, g_strdup (dir->str));
}
g_string_free (dir, TRUE);
}
g_strfreev (patharray);
list = g_list_reverse (list);
if (check && check_failed)
{
fail_list = g_list_reverse (fail_list);
*check_failed = fail_list;
}
return list;
}
/**
* gimp_path_to_str:
* @path: (element-type filename):
* A list of directories as returned by gimp_path_parse().
*
* Returns: (type filename) (transfer full):
* A searchpath string separated by #G_SEARCHPATH_SEPARATOR.
**/
gchar *
gimp_path_to_str (GList *path)
{
GString *str = NULL;
GList *list;
gchar *retval = NULL;
for (list = path; list; list = g_list_next (list))
{
gchar *dir = list->data;
if (str)
{
g_string_append_c (str, G_SEARCHPATH_SEPARATOR);
g_string_append (str, dir);
}
else
{
str = g_string_new (dir);
}
}
if (str)
retval = g_string_free (str, FALSE);
return retval;
}
/**
* gimp_path_free:
* @path: (element-type filename):
* A list of directories as returned by gimp_path_parse().
*
* This function frees the memory allocated for the list and the strings
* it contains.
**/
void
gimp_path_free (GList *path)
{
g_list_free_full (path, (GDestroyNotify) g_free);
}
/**
* gimp_path_get_user_writable_dir:
* @path: (element-type filename):
* A list of directories as returned by gimp_path_parse().
*
* Note that you have to g_free() the returned string.
*
* Returns: The first directory in @path where the user has write permission.
**/
gchar *
gimp_path_get_user_writable_dir (GList *path)
{
GList *list;
uid_t euid;
gid_t egid;
GStatBuf filestat;
gint err;
g_return_val_if_fail (path != NULL, NULL);
euid = geteuid ();
egid = getegid ();
for (list = path; list; list = g_list_next (list))
{
gchar *dir = list->data;
/* check if directory exists */
err = g_stat (dir, &filestat);
/* this is tricky:
* if a file is e.g. owned by the current user but not user-writable,
* the user has no permission to write to the file regardless
* of their group's or other's write permissions
*/
if (!err && S_ISDIR (filestat.st_mode) &&
((filestat.st_mode & S_IWUSR) ||
((filestat.st_mode & S_IWGRP) &&
(euid != filestat.st_uid)) ||
((filestat.st_mode & S_IWOTH) &&
(euid != filestat.st_uid) &&
(egid != filestat.st_gid))))
{
return g_strdup (dir);
}
}
return NULL;
}
static gchar *
gimp_env_get_dir (const gchar *gimp_env_name,
const gchar *compile_time_dir,
const gchar *relative_subdir)
{
const gchar *env = g_getenv (gimp_env_name);
if (env)
{
if (! g_path_is_absolute (env))
g_error ("%s environment variable should be an absolute path.",
gimp_env_name);
return g_strdup (env);
}
else if (compile_time_dir)
{
gchar *retval = g_strdup (compile_time_dir);
gimp_path_runtime_fix (&retval);
return retval;
}
else if (! g_path_is_absolute (relative_subdir))
{
return g_build_filename (gimp_installation_directory (),
relative_subdir,
NULL);
}
return g_strdup (relative_subdir);
}