--- gtk+-2.10.11/gtk/Makefile.am.user-dirs 2007-04-10 20:50:54.000000000 +0200 +++ gtk+-2.10.11/gtk/Makefile.am 2007-04-10 20:50:54.000000000 +0200 @@ -598,6 +598,7 @@ gtkwidget.c \ gtkwindow-decorate.c \ gtkwindow.c \ + xdg-user-dir-lookup.c \ $(gtk_clipboard_dnd_c_sources) gtk_c_sources = $(gtk_base_c_sources) gtk_all_c_sources = $(gtk_base_c_sources) --- gtk+-2.10.11/gtk/gtkpathbar.c.user-dirs 2007-03-14 05:07:01.000000000 +0100 +++ gtk+-2.10.11/gtk/gtkpathbar.c 2007-04-10 20:50:54.000000000 +0200 @@ -1586,6 +1586,8 @@ return TRUE; } +char *_xdg_user_dir_lookup (const char *type); + /* FIXME: This should be a construct-only property */ void _gtk_path_bar_set_file_system (GtkPathBar *path_bar, @@ -1607,9 +1609,9 @@ /* FIXME: Need file system backend specific way of getting the * Desktop path. */ - desktop = g_build_filename (home, "Desktop", NULL); + desktop = _xdg_user_dir_lookup ("DESKTOP"); path_bar->desktop_path = gtk_file_system_filename_to_path (path_bar->file_system, desktop); - g_free (desktop); + free (desktop); } else { --- gtk+-2.10.11/gtk/gtkfilesystemunix.c.user-dirs 2007-03-14 05:07:06.000000000 +0100 +++ gtk+-2.10.11/gtk/gtkfilesystemunix.c 2007-04-10 20:50:54.000000000 +0200 @@ -1605,6 +1605,8 @@ return filename_to_path (filename); } +char *_xdg_user_dir_lookup (const char *type); + /* Returns the name of the icon to be used for a path which is known to be a * directory. This can vary for Home, Desktop, etc. */ @@ -1617,7 +1619,7 @@ return "gnome-fs-directory"; if (!desktop_path) - desktop_path = g_build_filename (g_get_home_dir (), "Desktop", NULL); + desktop_path = _xdg_user_dir_lookup ("DESKTOP"); if (strcmp (g_get_home_dir (), path) == 0) return "gnome-fs-home"; --- gtk+-2.10.11/gtk/gtkfilechooserdefault.c.user-dirs 2007-04-10 20:50:54.000000000 +0200 +++ gtk+-2.10.11/gtk/gtkfilechooserdefault.c 2007-04-10 21:15:22.000000000 +0200 @@ -1767,12 +1767,14 @@ profile_end ("end", NULL); } +char *_xdg_user_dir_lookup (const char *type); + /* Appends the ~/Desktop directory to the shortcuts model */ static void shortcuts_append_desktop (GtkFileChooserDefault *impl) { - char *name; - const char *home; + char *name, *tmp; + const char *display_name = NULL; GtkFilePath *path; profile_start ("start", NULL); @@ -1780,20 +1782,18 @@ #ifdef G_OS_WIN32 name = _gtk_file_system_win32_get_desktop (); #else - home = g_get_home_dir (); - if (home == NULL) - { - profile_end ("end - no home directory!?", NULL); - return; - } - - name = g_build_filename (home, "Desktop", NULL); + tmp = _xdg_user_dir_lookup ("DESKTOP"); + name = g_strdup (tmp); + free (tmp); + display_name = g_path_get_basename (name); #endif path = gtk_file_system_filename_to_path (impl->file_system, name); g_free (name); - shortcuts_insert_path (impl, -1, SHORTCUT_TYPE_PATH, NULL, path, _("Desktop"), FALSE, SHORTCUTS_DESKTOP); + shortcuts_insert_path (impl, -1, SHORTCUT_TYPE_PATH, NULL, path, + display_name ? display_name : _("Desktop"), + FALSE, SHORTCUTS_DESKTOP); impl->has_desktop = TRUE; /* We do not actually pop up an error dialog if there is no desktop directory @@ -1801,6 +1801,7 @@ */ gtk_file_path_free (path); + g_free (display_name); profile_end ("end", NULL); } --- /dev/null 2007-04-10 17:42:06.546489881 +0200 +++ gtk+-2.10.11/gtk/xdg-user-dir-lookup.c 2007-04-10 20:50:54.000000000 +0200 @@ -0,0 +1,150 @@ +/* + This file is not licenced under the GPL like the rest of the code. + Its is under the MIT license, to encourage reuse by cut-and-paste. + + 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. +*/ + +#include +#include +#include + + +char * +_xdg_user_dir_lookup (const char *type) +{ + FILE *file; + char *home_dir, *config_home, *config_file; + char buffer[512]; + char *user_dir; + char *p, *d; + int len; + int relative; + + home_dir = getenv ("HOME"); + + if (home_dir == NULL) + return strdup ("/tmp"); + + config_home = getenv ("XDG_CONFIG_HOME"); + if (config_home == NULL || config_home[0] == 0) + { + config_file = malloc (strlen (home_dir) + strlen ("/.config/user-dirs.dirs") + 1); + strcpy (config_file, home_dir); + strcat (config_file, "/.config/user-dirs.dirs"); + } + else + { + config_file = malloc (strlen (config_home) + strlen ("/user-dirs.dirs") + 1); + strcpy (config_file, config_home); + strcat (config_file, "/user-dirs.dirs"); + } + + file = fopen (config_file, "r"); + free (config_file); + if (file == NULL) + goto error; + + user_dir = NULL; + while (fgets (buffer, sizeof (buffer), file)) + { + /* 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_", 4) != 0) + continue; + p += 4; + if (strncmp (p, type, strlen (type)) != 0) + continue; + p += strlen (type); + if (strncmp (p, "_DIR", 4) != 0) + continue; + p += 4; + + while (*p == ' ' || *p == '\t') + p++; + + if (*p != '=') + continue; + p++; + + while (*p == ' ' || *p == '\t') + p++; + + if (*p != '"') + continue; + p++; + + relative = 0; + if (strncmp (p, "$HOME/", 6) == 0) + { + p += 6; + relative = 1; + } + else if (*p != '/') + continue; + + if (relative) + { + user_dir = malloc (strlen (home_dir) + 1 + strlen (p) + 1); + strcpy (user_dir, home_dir); + strcat (user_dir, "/"); + } + else + { + user_dir = malloc (strlen (p) + 1); + *user_dir = 0; + } + + d = user_dir + strlen (user_dir); + while (*p && *p != '"') + { + if ((*p == '\\') && (*(p+1) != 0)) + p++; + *d++ = *p++; + } + *d = 0; + } + fclose (file); + + if (user_dir) + return user_dir; + + error: + /* Special case desktop for historical compatibility */ + if (strcmp (type, "DESKTOP") == 0) + { + user_dir = malloc (strlen (home_dir) + strlen ("/Desktop") + 1); + strcpy (user_dir, home_dir); + strcat (user_dir, "/Desktop"); + return user_dir; + } + else + return strdup (home_dir); +} --- gtk+-2.10.11/gtk/gtkfilechooserbutton.c.user-dirs 2007-03-14 05:07:03.000000000 +0100 +++ gtk+-2.10.11/gtk/gtkfilechooserbutton.c 2007-04-10 21:15:42.000000000 +0200 @@ -65,7 +65,6 @@ #define GTK_FILE_CHOOSER_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_FILE_CHOOSER_BUTTON, GtkFileChooserButtonPrivate)) #define DEFAULT_TITLE N_("Select A File") -#define DESKTOP_DISPLAY_NAME N_("Desktop") #define FALLBACK_DISPLAY_NAME N_("(None)") #define FALLBACK_ICON_NAME "stock_unknown" #define FALLBACK_ICON_SIZE 16 @@ -1642,11 +1641,14 @@ g_object_unref (handle); } +char *_xdg_user_dir_lookup (const char *type); + static inline void model_add_special (GtkFileChooserButton *button) { const gchar *homedir; gchar *desktopdir = NULL; + gchar *desktopname = NULL; GtkListStore *store; GtkTreeIter iter; GtkFilePath *path; @@ -1690,12 +1692,14 @@ button->priv->n_special++; #ifndef G_OS_WIN32 - desktopdir = g_build_filename (homedir, DESKTOP_DISPLAY_NAME, NULL); + desktopdir = _xdg_user_dir_lookup ("DESKTOP"); + desktopname = g_path_get_basename (desktopdir); #endif } #ifdef G_OS_WIN32 desktopdir = _gtk_file_system_win32_get_desktop (); + desktopname = NULL; #endif if (desktopdir) @@ -1723,7 +1727,7 @@ gtk_list_store_set (store, &iter, TYPE_COLUMN, ROW_TYPE_SPECIAL, ICON_COLUMN, NULL, - DISPLAY_NAME_COLUMN, _(DESKTOP_DISPLAY_NAME), + DISPLAY_NAME_COLUMN, desktopname ? desktopname :_("Desktop"), DATA_COLUMN, path, IS_FOLDER_COLUMN, TRUE, HANDLE_COLUMN, handle, @@ -1731,6 +1735,8 @@ button->priv->n_special++; } + + g_free (desktopname); } static void