diff options
author | William Jon McCann <jmccann@redhat.com> | 2012-04-27 12:23:38 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2012-04-30 06:42:31 -0400 |
commit | bbb7b2987e00b050ba9fb06ce211b659341f232e (patch) | |
tree | d5a2a1a5f9f506d2bb30a0423fc4ff03f5278392 /gtk/gtkcustompaperunixdialog.c | |
parent | fa0d6127c322c4ebd3d37bedf19cf9d2fc8bf00d (diff) | |
download | gtk+-bbb7b2987e00b050ba9fb06ce211b659341f232e.tar.gz |
Migrate to XDG config dir for custom papers
Will read from old location if new location isn't found but will
only write to the new location.
https://bugzilla.gnome.org/show_bug.cgi?id=646631
Diffstat (limited to 'gtk/gtkcustompaperunixdialog.c')
-rw-r--r-- | gtk/gtkcustompaperunixdialog.c | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/gtk/gtkcustompaperunixdialog.c b/gtk/gtkcustompaperunixdialog.c index de9ca83ad0..a76bc4545c 100644 --- a/gtk/gtkcustompaperunixdialog.c +++ b/gtk/gtkcustompaperunixdialog.c @@ -38,7 +38,8 @@ #include "gtkprintbackend.h" #include "gtkprintutils.h" -#define CUSTOM_PAPER_FILENAME ".gtk-custom-papers" +#define LEGACY_CUSTOM_PAPER_FILENAME ".gtk-custom-papers" +#define CUSTOM_PAPER_FILENAME "custom-papers" typedef struct @@ -131,11 +132,23 @@ _gtk_print_get_default_user_units (void) } static char * -custom_paper_get_filename (void) +custom_paper_get_legacy_filename (void) { gchar *filename; filename = g_build_filename (g_get_home_dir (), + LEGACY_CUSTOM_PAPER_FILENAME, NULL); + g_assert (filename != NULL); + return filename; +} + +static char * +custom_paper_get_filename (void) +{ + gchar *filename; + + filename = g_build_filename (g_get_user_config_dir (), + "gtk-3.0", CUSTOM_PAPER_FILENAME, NULL); g_assert (filename != NULL); return filename; @@ -158,6 +171,13 @@ _gtk_load_custom_papers (void) g_free (filename); if (!load_ok) { + /* try legacy file */ + filename = custom_paper_get_legacy_filename (); + load_ok = g_key_file_load_from_file (keyfile, filename, 0, NULL); + g_free (filename); + } + if (!load_ok) + { g_key_file_free (keyfile); return NULL; } @@ -209,7 +229,7 @@ _gtk_print_save_custom_papers (GtkListStore *store) GtkTreeModel *model = GTK_TREE_MODEL (store); GtkTreeIter iter; GKeyFile *keyfile; - gchar *filename, *data; + gchar *filename, *data, *parentdir; gsize len; gint i = 0; @@ -233,9 +253,16 @@ _gtk_print_save_custom_papers (GtkListStore *store) } filename = custom_paper_get_filename (); - data = g_key_file_to_data (keyfile, &len, NULL); - g_file_set_contents (filename, data, len, NULL); - g_free (data); + parentdir = g_build_filename (g_get_user_config_dir (), + "gtk-3.0", + NULL); + if (g_mkdir_with_parents (parentdir, 0700) == 0) + { + data = g_key_file_to_data (keyfile, &len, NULL); + g_file_set_contents (filename, data, len, NULL); + g_free (data); + } + g_free (parentdir); g_free (filename); } |