diff -Naurp libxfce4util.bak/libxfce4util/libxfce4util-aliasdef.c libxfce4util/libxfce4util/libxfce4util-aliasdef.c --- libxfce4util.bak/libxfce4util/libxfce4util-aliasdef.c 2008-08-28 18:28:02.000000000 +0200 +++ libxfce4util/libxfce4util/libxfce4util-aliasdef.c 2008-09-07 06:26:36.000000000 +0200 @@ -139,6 +139,10 @@ extern __typeof (xfce_unsetenv) xfce_uns #undef xfce_expand_variables extern __typeof (xfce_expand_variables) xfce_expand_variables __attribute((alias("IA__xfce_expand_variables"), visibility("default"))); +#if (!GLIB_CHECK_VERSION(2,14,0)) +extern __typeof (xfce_get_user_special_dir) xfce_get_user_special_dir __attribute((alias("IA__xfce_get_user_special_dir"), visibility("default"))); +#endif /* !GLIB_CHECK_VERSION(2,14,0) */ + #endif #endif #if IN_HEADER(__XFCE_POSIX_SIGNAL_HANDLER_H__) diff -Naurp libxfce4util.bak/libxfce4util/libxfce4util-alias.h libxfce4util/libxfce4util/libxfce4util-alias.h --- libxfce4util.bak/libxfce4util/libxfce4util-alias.h 2008-08-28 18:28:02.000000000 +0200 +++ libxfce4util/libxfce4util/libxfce4util-alias.h 2008-09-07 06:25:14.000000000 +0200 @@ -136,6 +136,11 @@ extern __typeof (xfce_unsetenv) IA__xfce extern __typeof (xfce_expand_variables) IA__xfce_expand_variables __attribute((visibility("hidden"))) G_GNUC_MALLOC; #define xfce_expand_variables IA__xfce_expand_variables +#if (!GLIB_CHECK_VERSION(2,14,0)) +extern __typeof (xfce_get_user_special_dir) IA__xfce_get_user_special_dir __attribute((visibility("hidden"))) G_GNUC_MALLOC; +#define xfce_get_user_special_dir IA__xfce_get_user_special_dir +#endif /* !GLIB_CHECK_VERSION(2,14,0) */ + #endif #endif #if IN_HEADER(__XFCE_POSIX_SIGNAL_HANDLER_H__) diff -Naurp libxfce4util.bak/libxfce4util/xfce-miscutils.c libxfce4util/libxfce4util/xfce-miscutils.c --- libxfce4util.bak/libxfce4util/xfce-miscutils.c 2008-08-28 17:52:33.000000000 +0200 +++ libxfce4util/libxfce4util/xfce-miscutils.c 2008-09-07 06:26:58.000000000 +0200 @@ -63,6 +63,7 @@ #include + #define XFCE4DIR ".xfce4" /* environment variable the user can set to change the path to @@ -77,7 +78,9 @@ G_LOCK_DEFINE_STATIC(_lock); static gchar *xfce_homedir = NULL; /* path to users home directory */ static gchar *xfce_userdir = NULL; /* path to users .xfce4 directory */ - +#if (!GLIB_CHECK_VERSION(2,14,0)) +static gchar **xfce_user_special_dirs = NULL; +#endif /* !GLIB_CHECK_VERSION(2,14,0) */ static void internal_initialize(void) @@ -610,7 +613,281 @@ xfce_expand_variables (const gchar *comm return g_strdup (buffer); } +#if (!GLIB_CHECK_VERSION(2,14,0)) + +#ifdef HAVE_CARBON + +static gchar * +find_folder (OSType type) +{ + gchar *filename = NULL; + FSRef found; + + if (FSFindFolder (kUserDomain, type, kDontCreateFolder, &found) == noErr) + { + CFURLRef url = CFURLCreateFromFSRef (kCFAllocatorSystemDefault, &found); + + if (url) + { + CFStringRef path = CFURLCopyFileSystemPath (url, kCFURLPOSIXPathStyle); + + if (path) + { + filename = g_strdup (CFStringGetCStringPtr (path, kCFStringEncodingUTF8)); + + if (! filename) + { + filename = g_new0 (gchar, CFStringGetLength (path) * 3 + 1); + + CFStringGetCString (path, filename, + CFStringGetLength (path) * 3 + 1, + kCFStringEncodingUTF8); + } + + CFRelease (path); + } + + CFRelease (url); + } + } + + return filename; +} + +static void +load_user_special_dirs (void) +{ + xfce_user_special_dirs[XFCE_USER_DIRECTORY_DESKTOP] = find_folder (kDesktopFolderType); + xfce_user_special_dirs[XFCE_USER_DIRECTORY_DOCUMENTS] = find_folder (kDocumentsFolderType); + xfce_user_special_dirs[XFCE_USER_DIRECTORY_DOWNLOAD] = find_folder (kDesktopFolderType); /* XXX correct ? */ + xfce_user_special_dirs[XFCE_USER_DIRECTORY_MUSIC] = find_folder (kMusicDocumentsFolderType); + xfce_user_special_dirs[XFCE_USER_DIRECTORY_PICTURES] = find_folder (kPictureDocumentsFolderType); + xfce_user_special_dirs[XFCE_USER_DIRECTORY_PUBLIC_SHARE] = NULL; + xfce_user_special_dirs[XFCE_USER_DIRECTORY_TEMPLATES] = NULL; + xfce_user_special_dirs[XFCE_USER_DIRECTORY_VIDEOS] = find_folder (kMovieDocumentsFolderType); +} + +#endif /* HAVE_CARBON */ + +#if defined(G_OS_WIN32) +static void +load_user_special_dirs (void) +{ + xfce_user_special_dirs[XFCE_USER_DIRECTORY_DESKTOP] = get_special_folder (CSIDL_DESKTOPDIRECTORY); + xfce_user_special_dirs[XFCE_USER_DIRECTORY_DOCUMENTS] = get_special_folder (CSIDL_PERSONAL); + xfce_user_special_dirs[XFCE_USER_DIRECTORY_DOWNLOAD] = get_special_folder (CSIDL_DESKTOPDIRECTORY); /* XXX correct ? */ + xfce_user_special_dirs[XFCE_USER_DIRECTORY_MUSIC] = get_special_folder (CSIDL_MYMUSIC); + xfce_user_special_dirs[XFCE_USER_DIRECTORY_PICTURES] = get_special_folder (CSIDL_MYPICTURES); + xfce_user_special_dirs[XFCE_USER_DIRECTORY_PUBLIC_SHARE] = get_special_folder (CSIDL_COMMON_DOCUMENTS); /* XXX correct ? */ + xfce_user_special_dirs[XFCE_USER_DIRECTORY_TEMPLATES] = get_special_folder (CSIDL_TEMPLATES); + xfce_user_special_dirs[XFCE_USER_DIRECTORY_VIDEOS] = get_special_folder (CSIDL_MYVIDEO); +} +#endif /* G_OS_WIN32 */ + +#if defined(G_OS_UNIX) && !defined(HAVE_CARBON) + +/* adapted from xdg-user-dir-lookup.c + * + * Copyright (C) 2007 Red Hat Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +static void +load_user_special_dirs (void) +{ + gchar *config_file; + gchar *data; + gchar **lines; + gint n_lines, i; + + /* I suppose there already IS a config dir.. at least it gets created when + * you call g_get_user_config_dir() */ + //xfce_init_user_config_dir (); + config_file = g_build_filename (g_get_user_config_dir(), + "user-dirs.dirs", + NULL); + + if (!g_file_get_contents (config_file, &data, NULL, NULL)) + { + g_free (config_file); + return; + } + + lines = g_strsplit (data, "\n", -1); + n_lines = g_strv_length (lines); + g_free (data); + + for (i = 0; i < n_lines; i++) + { + gchar *buffer = lines[i]; + gchar *d, *p; + gint len; + gboolean is_relative = FALSE; + GUserDirectory directory; + + /* Remove newline at end */ + len = strlen (buffer); + if (len > 0 && buffer[len - 1] == '\n') + buffer[len - 1] = 0; + + p = buffer; + while (*p == ' ' || *p == '\t') + p++; + + if (strncmp (p, "XDG_DESKTOP_DIR", strlen ("XDG_DESKTOP_DIR")) == 0) + { + directory = G_USER_DIRECTORY_DESKTOP; + p += strlen ("XDG_DESKTOP_DIR"); + } + else if (strncmp (p, "XDG_DOCUMENTS_DIR", strlen ("XDG_DOCUMENTS_DIR")) == 0) + { + directory = G_USER_DIRECTORY_DOCUMENTS; + p += strlen ("XDG_DOCUMENTS_DIR"); + } + else if (strncmp (p, "XDG_DOWNLOAD_DIR", strlen ("XDG_DOWNLOAD_DIR")) == 0) + { + directory = G_USER_DIRECTORY_DOWNLOAD; + p += strlen ("XDG_DOWNLOAD_DIR"); + } + else if (strncmp (p, "XDG_MUSIC_DIR", strlen ("XDG_MUSIC_DIR")) == 0) + { + directory = G_USER_DIRECTORY_MUSIC; + p += strlen ("XDG_MUSIC_DIR"); + } + else if (strncmp (p, "XDG_PICTURES_DIR", strlen ("XDG_PICTURES_DIR")) == 0) + { + directory = G_USER_DIRECTORY_PICTURES; + p += strlen ("XDG_PICTURES_DIR"); + } + else if (strncmp (p, "XDG_PUBLICSHARE_DIR", strlen ("XDG_PUBLICSHARE_DIR")) == 0) + { + directory = G_USER_DIRECTORY_PUBLIC_SHARE; + p += strlen ("XDG_PUBLICSHARE_DIR"); + } + else if (strncmp (p, "XDG_TEMPLATES_DIR", strlen ("XDG_TEMPLATES_DIR")) == 0) + { + directory = G_USER_DIRECTORY_TEMPLATES; + p += strlen ("XDG_TEMPLATES_DIR"); + } + else if (strncmp (p, "XDG_VIDEOS_DIR", strlen ("XDG_VIDEOS_DIR")) == 0) + { + directory = G_USER_DIRECTORY_VIDEOS; + p += strlen ("XDG_VIDEOS_DIR"); + } + else + continue; + + while (*p == ' ' || *p == '\t') + p++; + + if (*p != '=') + continue; + p++; + + while (*p == ' ' || *p == '\t') + p++; + + if (*p != '"') + continue; + p++; + + if (strncmp (p, "$HOME", 5) == 0) + { + p += 5; + is_relative = TRUE; + } + else if (*p != '/') + continue; + + d = strrchr (p, '"'); + if (!d) + continue; + *d = 0; + + d = p; + + /* remove trailing slashes */ + len = strlen (d); + if (d[len - 1] == '/') + d[len - 1] = 0; + + if (is_relative) + { + xfce_user_special_dirs[directory] = g_build_filename (g_get_home_dir(), d, NULL); + } + else + xfce_user_special_dirs[directory] = g_strdup (d); + } + + g_strfreev (lines); + g_free (config_file); +} + +#endif /* G_OS_UNIX && !HAVE_CARBON */ + +/** + * xfce_get_user_special_dir: + * @directory: the logical id of special directory + * + * Returns the full path of a special directory using its logical id. + * + * On Unix this is done using the XDG special user directories. + * + * Depending on the platform, the user might be able to change the path + * of the special directory without requiring the session to restart; GLib + * will not reflect any change once the special directories are loaded. + * + * Return value: the path to the specified special directory, or %NULL + * if the logical id was not found. The returned string is owned by + * GLib and should not be modified or freed. + * + */ +G_CONST_RETURN gchar * +xfce_get_user_special_dir (XfceUserDirectory directory) +{ + g_return_val_if_fail (directory >= XFCE_USER_DIRECTORY_DESKTOP && + directory < XFCE_USER_N_DIRECTORIES, NULL); + + G_LOCK (_lock); + + if (G_UNLIKELY (xfce_user_special_dirs == NULL)) + { + xfce_user_special_dirs = g_new0 (gchar *, XFCE_USER_N_DIRECTORIES); + + load_user_special_dirs (); + + /* Special-case desktop for historical compatibility */ + if (xfce_user_special_dirs[G_USER_DIRECTORY_DESKTOP] == NULL) + { + xfce_user_special_dirs[G_USER_DIRECTORY_DESKTOP] = + g_build_filename (g_get_home_dir(), "Desktop", NULL); + } + + } + + G_UNLOCK (_lock); + return xfce_user_special_dirs[directory]; +} +#endif /* !GLIB_CHECK_VERSION(2,14,0) */ #define __XFCE_MISCUTILS_C__ #include diff -Naurp libxfce4util.bak/libxfce4util/xfce-miscutils.h libxfce4util/libxfce4util/xfce-miscutils.h --- libxfce4util.bak/libxfce4util/xfce-miscutils.h 2008-08-28 17:52:33.000000000 +0200 +++ libxfce4util/libxfce4util/xfce-miscutils.h 2008-09-07 06:26:51.000000000 +0200 @@ -94,4 +94,24 @@ void xfce_unsetenv (const gch gchar* xfce_expand_variables (const gchar *command, gchar **envp) G_GNUC_MALLOC; +typedef enum /*< enum >*/ +{ + XFCE_USER_DIRECTORY_DESKTOP, + XFCE_USER_DIRECTORY_DOCUMENTS, + XFCE_USER_DIRECTORY_DOWNLOAD, + XFCE_USER_DIRECTORY_MUSIC, + XFCE_USER_DIRECTORY_PICTURES, + XFCE_USER_DIRECTORY_PUBLIC_SHARE, + XFCE_USER_DIRECTORY_TEMPLATES, + XFCE_USER_DIRECTORY_VIDEOS, + + XFCE_USER_N_DIRECTORIES +} XfceUserDirectory; + +#if (!GLIB_CHECK_VERSION(2,14,0)) +G_CONST_RETURN gchar *xfce_get_user_special_dir(XfceUserDirectory directory); +#else /* GLIB_CHECK_VERSION(2,14,0) */ +#define xfce_get_user_special_dir(a) g_get_user_special_dir((GUserDirectory)(a)) +#endif /* !GLIB_CHECK_VERSION(2,14,0) */ + #endif /* __XFCE_MISCUTILS_H__ */