From 6967aa47a48c2478319435fbfaf9fbabd39e1fba Mon Sep 17 00:00:00 2001 From: Stephen Watson Date: Mon, 25 Apr 2005 18:02:14 +0000 Subject: [PATCH] r3890: Change over from CHOICESPATH to XDG_CONFIG_HOME and XDG_CONFIG_DIRS --- ROX-Filer/Help/Changes | 5 + ROX-Filer/src/Docs/to_html.xsl | 2 +- ROX-Filer/src/appmenu.c | 4 +- ROX-Filer/src/bookmarks.c | 5 +- ROX-Filer/src/choices.c | 302 +++++++++++++++++++++++++++++++++++++++-- ROX-Filer/src/choices.h | 12 +- ROX-Filer/src/config.h.in | 1 + ROX-Filer/src/filer.c | 9 +- ROX-Filer/src/main.c | 3 + ROX-Filer/src/menu.c | 12 +- ROX-Filer/src/options.c | 6 +- ROX-Filer/src/panel.c | 4 +- ROX-Filer/src/pinboard.c | 4 +- ROX-Filer/src/pixmaps.c | 5 +- ROX-Filer/src/type.c | 26 ++-- ROX-Filer/src/usericons.c | 12 +- 16 files changed, 360 insertions(+), 52 deletions(-) diff --git a/ROX-Filer/Help/Changes b/ROX-Filer/Help/Changes index 0560b43e..1dad0f1d 100644 --- a/ROX-Filer/Help/Changes +++ b/ROX-Filer/Help/Changes @@ -2,6 +2,11 @@ A RISC OS-like filer for X by Thomas Leonard +25-Apr-2005 +~~~~~~~~~~~ +Change over from CHOICESPATH to XDG_CONFIG_HOME and XDG_CONFIG_DIRS (Stephen +Watson). + 21-Apr-2005 ~~~~~~~~~~~ Try to cope with BadWindow errors (suggested by Kacper Wysock). diff --git a/ROX-Filer/src/Docs/to_html.xsl b/ROX-Filer/src/Docs/to_html.xsl index 6905d626..90fd6c85 100644 --- a/ROX-Filer/src/Docs/to_html.xsl +++ b/ROX-Filer/src/Docs/to_html.xsl @@ -3,7 +3,7 @@ - + diff --git a/ROX-Filer/src/appmenu.c b/ROX-Filer/src/appmenu.c index 533ce654..9c6b5b5f 100644 --- a/ROX-Filer/src/appmenu.c +++ b/ROX-Filer/src/appmenu.c @@ -285,7 +285,7 @@ static void customise_type(GtkWidget *item, MIME_type *type) char *path; leaf = g_strconcat(".", type->media_type, "_", type->subtype, NULL); - path = choices_find_path_save(leaf, "SendTo", TRUE); + path = choices_find_xdg_path_save(leaf, "SendTo", SITE, TRUE); g_free(leaf); mkdir(path, 0755); @@ -307,7 +307,7 @@ static void build_menu_for_type(MIME_type *type) DirItem *ditem; leaf = g_strconcat(".", type->media_type, "_", type->subtype, NULL); - path = choices_find_path_load(leaf, "SendTo"); + path = choices_find_xdg_path_load(leaf, "SendTo", SITE); if (!path) goto out; diff --git a/ROX-Filer/src/bookmarks.c b/ROX-Filer/src/bookmarks.c index 2928e6ce..4d9467fa 100644 --- a/ROX-Filer/src/bookmarks.c +++ b/ROX-Filer/src/bookmarks.c @@ -342,7 +342,7 @@ static void update_bookmarks() gchar *path; /* Update the bookmarks, if possible */ - path = choices_find_path_load("Bookmarks.xml", PROJECT); + path = choices_find_xdg_path_load("Bookmarks.xml", PROJECT, SITE); if (path) { XMLwrapper *wrapper; @@ -400,7 +400,8 @@ static void bookmarks_save() { guchar *save_path; - save_path = choices_find_path_save("Bookmarks.xml", PROJECT, TRUE); + save_path = choices_find_xdg_path_save("Bookmarks.xml", PROJECT, SITE, + TRUE); if (save_path) { save_xml_file(bookmarks->doc, save_path); diff --git a/ROX-Filer/src/choices.c b/ROX-Filer/src/choices.c index 219a1ea3..72c81a74 100644 --- a/ROX-Filer/src/choices.c +++ b/ROX-Filer/src/choices.c @@ -34,10 +34,27 @@ static gboolean saving_disabled = TRUE; static gchar **dir_list = NULL; +static gchar **xdg_dir_list = NULL; +static int xdg_dir_count= 0 ; + +static struct migration { + const char *dir; + const char *site; + int symlink; +} to_migrate[]={ + {"ROX-Filer", SITE, TRUE}, + {"SendTo", SITE, TRUE}, + {"Templates", SITE, TRUE}, + {"MIME-types", SITE, TRUE}, + {"MIME-icons", SITE, TRUE}, + {"MIME-thumb", SITE, TRUE}, + + {NULL, NULL, 0} +}; /* Static prototypes */ static gboolean exists(char *path); - +static void migrate_choices(void); /**************************************************************** * EXTERNAL INTERFACE * @@ -52,9 +69,13 @@ static gboolean exists(char *path); void choices_init(void) { char *choices; + const char *env; + char **dirs; + int i, n; g_return_if_fail(dir_list == NULL); + /* Initialize old system */ choices = getenv("CHOICESPATH"); if (choices) @@ -76,18 +97,41 @@ void choices_init(void) else { saving_disabled = FALSE; - + dir_list = g_new(gchar *, 4); - dir_list[0] = g_strconcat(getenv("HOME"), "/Choices", NULL); + dir_list[0] = g_build_filename(g_get_home_dir(), "Choices", + NULL); dir_list[1] = g_strdup("/usr/local/share/Choices"); dir_list[2] = g_strdup("/usr/share/Choices"); dir_list[3] = NULL; } + /* Initialize new system */ + env = getenv("XDG_CONFIG_DIRS"); + if (!env) + env = "/etc/xdg"; + dirs = g_strsplit(env, ":", 0); + g_return_if_fail(dirs != NULL); + for (n = 0; dirs[n]; n++) + ; + for (i = n; i > 0; i--) + dirs[i] = dirs[i - 1]; + env = getenv("XDG_CONFIG_HOME"); + if (env) + dirs[0] = g_strdup(env); + else + dirs[0] = g_build_filename(g_get_home_dir(), ".config", NULL); + + xdg_dir_list = dirs; + xdg_dir_count = n + 1; + #if 0 { gchar **cdir = dir_list; + for(i=0; i "/etc/xdg/rox.sourceforge.net/ROX-Filer/menus". + * + * Falls back on choices_find_path_load(leaf, dir) if it fails + * The return values may be NULL - use built-in defaults. + * g_free() the result. + */ +gchar *choices_find_xdg_path_load(const char *leaf, const char *dir, + const char *site) +{ + int i; + + g_return_val_if_fail(dir_list != NULL, NULL); + + for (i=0; i +#include + +static void migrate_choices(void) +{ + GtkWidget *dialog, *vbox, *lbl; + gint resp; + gchar *opath, *npath; + gchar *text; + + npath=choices_find_xdg_path_save("...", PROJECT, SITE, FALSE); + opath=choices_find_path_save("...", PROJECT,FALSE); + + dialog=gtk_dialog_new_with_buttons(_("Convert Choices to XDG specification?"), + NULL, GTK_DIALOG_NO_SEPARATOR, + GTK_STOCK_NO, GTK_RESPONSE_CANCEL, + GTK_STOCK_YES, GTK_RESPONSE_OK, + NULL); + vbox = GTK_DIALOG(dialog)->vbox; + text=g_strdup_printf(_("Do you wish to migrate your choices, " + "currently stored in\n%s\nto the new " + "standard where they will be stored in\n" + "%s"), + opath, npath); + lbl=gtk_label_new(text); + gtk_label_set_use_markup(GTK_LABEL(lbl), TRUE); + g_free(text); + gtk_box_pack_start(GTK_BOX(vbox), lbl, TRUE, TRUE, 4); + + gtk_widget_show_all(vbox); + + resp=gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + + if(resp==GTK_RESPONSE_OK) + { + int failed=0; + int i; + gchar *src, *dest; + + dest=choices_find_xdg_path_save(".", PROJECT, SITE, TRUE); + g_free(dest); + + for(i=0; to_migrate[i].dir; i++) { + src=g_build_filename(dir_list[0], to_migrate[i].dir, + NULL); + dest=choices_find_xdg_path_save(NULL, NULL, + to_migrate[i].site, + TRUE); + g_free(dest); + dest=choices_find_xdg_path_save(NULL, + to_migrate[i].dir, + to_migrate[i].site, + FALSE); + errno=0; + if(rename(src, dest)==0) { + if(to_migrate[i].symlink) + symlink(dest, src); + } else { + g_warning("rename(%s, %s): %s\n", + src, dest, + g_strerror(errno)); + failed++; + } + g_free(src); + g_free(dest); + } + + if(failed) + delayed_error(_("%d directories could not be migrated"), + failed); + + + } else { + + dialog=gtk_dialog_new_with_buttons(_("OK"), + NULL, + GTK_DIALOG_NO_SEPARATOR, + GTK_STOCK_OK, + GTK_RESPONSE_OK, + NULL); + vbox = GTK_DIALOG(dialog)->vbox; + + text=g_strdup_printf(_("OK. Existing choices will " + "continue to be read from \n" + "%s\n " + "but changes will be saved to \n" + "%s\n"), + opath, npath); + lbl=gtk_label_new(text); + gtk_label_set_use_markup(GTK_LABEL(lbl), TRUE); + g_free(text); + gtk_box_pack_start(GTK_BOX(vbox), lbl, TRUE, TRUE, 4); + + gtk_widget_show_all(vbox); + (void) gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + + } + + g_free(opath); + g_free(npath); +} diff --git a/ROX-Filer/src/choices.h b/ROX-Filer/src/choices.h index c8814fab..d625d2a0 100644 --- a/ROX-Filer/src/choices.h +++ b/ROX-Filer/src/choices.h @@ -6,10 +6,18 @@ #define _CHOICES_H void choices_init (void); +void choices_migrate (void); + GPtrArray *choices_list_dirs (char *dir); void choices_free_list (GPtrArray *list); -guchar *choices_find_path_load(const char *leaf, const char *dir); -guchar *choices_find_path_save(const char *leaf, const char *dir, +gchar *choices_find_path_load(const char *leaf, const char *dir); +gchar *choices_find_xdg_path_load(const char *leaf, const char *dir, + const char *site); +gchar *choices_find_path_save(const char *leaf, const char *dir, gboolean create); +gchar *choices_find_xdg_path_save(const char *leaf, const char *dir, + const char *site, gboolean create); +GPtrArray *choices_list_xdg_dirs(char *dir, char *site); + #endif /* _CHOICES_H */ diff --git a/ROX-Filer/src/config.h.in b/ROX-Filer/src/config.h.in index 99be5e15..c2713cc7 100644 --- a/ROX-Filer/src/config.h.in +++ b/ROX-Filer/src/config.h.in @@ -1,6 +1,7 @@ /* The configure script will auto-generate config.h from config.h.in */ #define PROJECT "ROX-Filer" +#define SITE "rox.sourceforge.net" #define VERSION "Unknown" #define GTK_VERSION "Unknown" diff --git a/ROX-Filer/src/filer.c b/ROX-Filer/src/filer.c index ebe9df3e..e316e1f4 100644 --- a/ROX-Filer/src/filer.c +++ b/ROX-Filer/src/filer.c @@ -919,7 +919,7 @@ static xmlNode *group_find(char *name) gchar *path; /* Update the groups, if possible */ - path = choices_find_path_load("Groups.xml", PROJECT); + path = choices_find_xdg_path_load("Groups.xml", PROJECT, SITE); if (path) { XMLwrapper *wrapper; @@ -990,7 +990,8 @@ static void group_save(FilerWindow *filer_window, char *name) while ((item = iter.next(&iter))) xmlNewTextChild(group, NULL, "item", item->leafname); - save_path = choices_find_path_save("Groups.xml", PROJECT, TRUE); + save_path = choices_find_xdg_path_save("Groups.xml", PROJECT, SITE, + TRUE); if (save_path) { save_xml_file(groups->doc, save_path); @@ -3025,7 +3026,7 @@ static void load_settings(void) gchar *path; XMLwrapper *settings_doc=NULL; - path=choices_find_path_load("Settings.xml", "ROX-Filer"); + path=choices_find_xdg_path_load("Settings.xml", PROJECT, SITE); if(path) { settings_doc=xml_new(path); g_free(path); @@ -3139,7 +3140,7 @@ static void save_settings(void) { gchar *path; - path=choices_find_path_save("Settings.xml", "ROX-Filer", TRUE); + path=choices_find_xdg_path_save("Settings.xml", PROJECT, SITE, TRUE); if(path) { xmlDocPtr doc = xmlNewDoc("1.0"); xmlDocSetRootElement(doc, xmlNewDocNode(doc, NULL, diff --git a/ROX-Filer/src/main.c b/ROX-Filer/src/main.c index 0218e987..86b2f730 100644 --- a/ROX-Filer/src/main.c +++ b/ROX-Filer/src/main.c @@ -580,6 +580,9 @@ int main(int argc, char **argv) session_init(client_id); g_free(client_id); + /* See if we need to migrate the Choices directories*/ + choices_migrate(); + /* Finally, execute the request */ reply = run_soap(rpc); xmlFreeDoc(rpc); diff --git a/ROX-Filer/src/menu.c b/ROX-Filer/src/menu.c index e4818bb9..755cfd1d 100644 --- a/ROX-Filer/src/menu.c +++ b/ROX-Filer/src/menu.c @@ -330,7 +330,7 @@ void menu_init(void) { char *menurc; - menurc = choices_find_path_load(MENUS_NAME, PROJECT); + menurc = choices_find_xdg_path_load(MENUS_NAME, PROJECT, SITE); if (menurc) { gtk_accel_map_load(menurc); @@ -571,7 +571,7 @@ static void update_new_files_menu(MenuIconStyle style) widgets = NULL; } - templ_dname = choices_find_path_load("Templates", ""); + templ_dname = choices_find_xdg_path_load("Templates", "", SITE); if (templ_dname) { widgets = menu_from_dir(filer_new_menu, templ_dname, style, @@ -1405,7 +1405,7 @@ static gboolean new_file_type_cb(GObject *savebox, /* We can work out the template path from the initial name */ oleaf = g_basename(initial); - templ_dname = choices_find_path_load("Templates", ""); + templ_dname = choices_find_xdg_path_load("Templates", "", SITE); if (!templ_dname) { report_error( @@ -1475,7 +1475,7 @@ static void customise_send_to(gpointer data) } choices_free_list(path); - save = choices_find_path_save("", "SendTo", TRUE); + save = choices_find_xdg_path_save("", "SendTo", SITE, TRUE); if (save) mkdir(save, 0777); @@ -1522,7 +1522,7 @@ static void customise_new(gpointer data) } choices_free_list(path); - save = choices_find_path_save("", "Templates", TRUE); + save = choices_find_xdg_path_save("", "Templates", SITE, TRUE); if (save) mkdir(save, 0777); @@ -1825,7 +1825,7 @@ static void save_menus(void) { char *menurc; - menurc = choices_find_path_save(MENUS_NAME, PROJECT, TRUE); + menurc = choices_find_xdg_path_save(MENUS_NAME, PROJECT, SITE, TRUE); if (menurc) { gtk_accel_map_save(menurc); diff --git a/ROX-Filer/src/options.c b/ROX-Filer/src/options.c index 82450af2..1ca4ddbb 100644 --- a/ROX-Filer/src/options.c +++ b/ROX-Filer/src/options.c @@ -170,7 +170,7 @@ void options_init(void) option_hash = g_hash_table_new(g_str_hash, g_str_equal); widget_builder = g_hash_table_new(g_str_hash, g_str_equal); - path = choices_find_path_load("Options", PROJECT); + path = choices_find_xdg_path_load("Options", PROJECT, SITE); if (path) { /* Load in all the options set in the filer, storing them @@ -977,7 +977,7 @@ static GtkWidget *build_window_frame(GtkTreeView **tree_view) gtk_widget_grab_default(button); gtk_widget_grab_focus(button); - save_path = choices_find_path_save("...", PROJECT, FALSE); + save_path = choices_find_xdg_path_save("...", PROJECT, SITE, FALSE); if (save_path) { string = g_strdup_printf(_("Choices will be saved as:\n%s"), @@ -1148,7 +1148,7 @@ static void save_options(void) GList *next; guchar *save, *save_new; - save = choices_find_path_save("Options", PROJECT, TRUE); + save = choices_find_xdg_path_save("Options", PROJECT, SITE, TRUE); if (!save) goto out; diff --git a/ROX-Filer/src/panel.c b/ROX-Filer/src/panel.c index 69a6eb39..acee2c9c 100644 --- a/ROX-Filer/src/panel.c +++ b/ROX-Filer/src/panel.c @@ -306,7 +306,7 @@ Panel *panel_new(const gchar *name, PanelSide side) guchar *leaf; leaf = g_strconcat("pan_", name, NULL); - load_path = choices_find_path_load(leaf, PROJECT); + load_path = choices_find_xdg_path_load(leaf, PROJECT, SITE); g_free(leaf); } @@ -1426,7 +1426,7 @@ void panel_save(Panel *panel) guchar *leaf; leaf = g_strconcat("pan_", panel->name, NULL); - save = choices_find_path_save(leaf, PROJECT, TRUE); + save = choices_find_xdg_path_save(leaf, PROJECT, SITE, TRUE); g_free(leaf); } diff --git a/ROX-Filer/src/pinboard.c b/ROX-Filer/src/pinboard.c index f4fa4fd6..3a0dd406 100644 --- a/ROX-Filer/src/pinboard.c +++ b/ROX-Filer/src/pinboard.c @@ -315,7 +315,7 @@ void pinboard_activate(const gchar *name) guchar *leaf; leaf = g_strconcat("pb_", name, NULL); - path = choices_find_path_load(leaf, PROJECT); + path = choices_find_xdg_path_load(leaf, PROJECT, SITE); g_free(leaf); } @@ -1506,7 +1506,7 @@ static void pinboard_save(void) guchar *leaf; leaf = g_strconcat("pb_", current_pinboard->name, NULL); - save = choices_find_path_save(leaf, PROJECT, TRUE); + save = choices_find_xdg_path_save(leaf, PROJECT, SITE, TRUE); g_free(leaf); } diff --git a/ROX-Filer/src/pixmaps.c b/ROX-Filer/src/pixmaps.c index bbf47da3..ac9c7e65 100644 --- a/ROX-Filer/src/pixmaps.c +++ b/ROX-Filer/src/pixmaps.c @@ -525,14 +525,15 @@ static gchar *thumbnail_program(MIME_type *type) return NULL; leaf = g_strconcat(type->media_type, "_", type->subtype, NULL); - path = choices_find_path_load(leaf, "MIME-thumb"); + path = choices_find_xdg_path_load(leaf, "MIME-thumb", SITE); g_free(leaf); if (path) { return path; } - path = choices_find_path_load(type->media_type, "MIME-thumb"); + path = choices_find_xdg_path_load(type->media_type, "MIME-thumb", + SITE); return path; } diff --git a/ROX-Filer/src/type.c b/ROX-Filer/src/type.c index f0c89608..54e76462 100644 --- a/ROX-Filer/src/type.c +++ b/ROX-Filer/src/type.c @@ -369,11 +369,12 @@ static char *handler_for(MIME_type *type) char *open; type_name = g_strconcat(type->media_type, "_", type->subtype, NULL); - open = choices_find_path_load(type_name, "MIME-types"); + open = choices_find_xdg_path_load(type_name, "MIME-types", SITE); g_free(type_name); if (!open) - open = choices_find_path_load(type->media_type, "MIME-types"); + open = choices_find_xdg_path_load(type->media_type, + "MIME-types", SITE); return open; } @@ -482,7 +483,7 @@ MaskedPixmap *type_to_icon(MIME_type *type) type_name = g_strconcat(type->media_type, "_", type->subtype, ".png", NULL); - path = choices_find_path_load(type_name, "MIME-icons"); + path = choices_find_xdg_path_load(type_name, "MIME-icons", SITE); g_free(type_name); if (path) { @@ -644,14 +645,16 @@ static guchar *handler_for_radios(GObject *dialog) switch (radios_get_value(radios)) { case SET_MEDIA: - return choices_find_path_load(type->media_type, - "MIME-types"); + return choices_find_xdg_path_load(type->media_type, + "MIME-types", SITE); case SET_TYPE: { gchar *tmp, *handler; tmp = g_strconcat(type->media_type, "_", type->subtype, NULL); - handler = choices_find_path_load(tmp, "MIME-types"); + handler = choices_find_xdg_path_load(tmp, + "MIME-types", + SITE); g_free(tmp); return handler; } @@ -1024,7 +1027,7 @@ static char *get_action_save_path(GtkWidget *dialog) type_name = g_strconcat(type->media_type, "_", type->subtype, NULL); - path = choices_find_path_save("", PROJECT, FALSE); + path = choices_find_xdg_path_save("", PROJECT, SITE, FALSE); if (!path) { report_error( @@ -1033,7 +1036,7 @@ static char *get_action_save_path(GtkWidget *dialog) } g_free(path); - path = choices_find_path_save(type_name, "MIME-types", TRUE); + path = choices_find_xdg_path_save(type_name, "MIME-types", SITE, TRUE); if (!remove_handler_with_confirm(path)) null_g_free(&path); @@ -1288,19 +1291,18 @@ static char **get_xdg_data_dirs(int *n_dirs) env = getenv("XDG_DATA_DIRS"); if (!env) - env = "/usr/local/share/:/usr/share/"; + env = "/etc/xdg/"; dirs = g_strsplit(env, ":", 0); g_return_val_if_fail(dirs != NULL, NULL); for (n = 0; dirs[n]; n++) ; for (i = n; i > 0; i--) dirs[i] = dirs[i - 1]; - env = getenv("XDG_DATA_HOME"); + env = getenv("XDG_CONFIG_HOME"); if (env) dirs[0] = g_strdup(env); else - dirs[0] = g_build_filename(g_get_home_dir(), ".local", - "share", NULL); + dirs[0] = g_build_filename(g_get_home_dir(), ".config", NULL); *n_dirs = n + 1; return dirs; } diff --git a/ROX-Filer/src/usericons.c b/ROX-Filer/src/usericons.c index aad924f7..b8fec9e4 100644 --- a/ROX-Filer/src/usericons.c +++ b/ROX-Filer/src/usericons.c @@ -89,7 +89,7 @@ void read_globicons() if (!glob_icons) glob_icons = g_hash_table_new(g_str_hash, g_str_equal); - path = choices_find_path_load("globicons", PROJECT); + path = choices_find_xdg_path_load("globicons", PROJECT, SITE); if (!path) return; /* Nothing to load */ @@ -366,7 +366,8 @@ static void radios_changed(gpointer data) char *path, *type; type = g_strconcat(mime_type->media_type, ".png", NULL); - path = choices_find_path_load(type, "MIME-icons"); + path = choices_find_xdg_path_load(type, "MIME-icons", + SITE); g_free(type); drop_box_set_path(drop_box, path); g_free(path); @@ -378,7 +379,8 @@ static void radios_changed(gpointer data) type = g_strconcat(mime_type->media_type, "_", mime_type->subtype, ".png", NULL); - path = choices_find_path_load(type, "MIME-icons"); + path = choices_find_xdg_path_load(type, "MIME-icons", + SITE); g_free(type); drop_box_set_path(drop_box, path); g_free(path); @@ -431,7 +433,7 @@ static void write_globicons(void) gchar *save = NULL, *save_new = NULL; xmlDocPtr doc = NULL; - save = choices_find_path_save("globicons", PROJECT, TRUE); + save = choices_find_xdg_path_save("globicons", PROJECT, SITE, TRUE); if (!save) return; /* Saving is disabled */ @@ -578,7 +580,7 @@ static gboolean set_icon_for_type(MIME_type *type, const gchar *iconpath, leaf = g_strconcat(type->media_type, "_", type->subtype, ".png", NULL); - target = choices_find_path_save(leaf, "MIME-icons", TRUE); + target = choices_find_xdg_path_save(leaf, "MIME-icons", SITE, TRUE); g_free(leaf); if (!target) -- 2.11.4.GIT