[gnome-disk-utility] Remember the last-used directory for disk images
- From: David Zeuthen <davidz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-disk-utility] Remember the last-used directory for disk images
- Date: Sun, 29 Jul 2012 17:31:48 +0000 (UTC)
commit a47bce0f015ceb90be4e45b91a942123215515fc
Author: David Zeuthen <zeuthen gmail com>
Date: Sun Jul 29 10:30:36 2012 -0400
Remember the last-used directory for disk images
Store this in GSettings.
Signed-off-by: David Zeuthen <zeuthen gmail com>
configure.ac | 3 ++
data/Makefile.am | 8 +++++-
data/org.gnome.Disks.gschema.xml.in.in | 10 ++++++++
po/POTFILES.in | 1 +
po/POTFILES.skip | 1 +
src/disks/gducreatediskimagedialog.c | 3 ++
src/disks/gdurestorediskimagedialog.c | 3 ++
src/disks/gduutils.c | 40 ++++++++++++++++++++++++++++---
src/disks/gduutils.h | 2 +
9 files changed, 66 insertions(+), 5 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index c161cbc..33cdc57 100644
--- a/configure.ac
+++ b/configure.ac
@@ -93,6 +93,8 @@ PKG_CHECK_MODULES(GTK3, [gtk+-3.0 >= $GTK3_REQUIRED])
PKG_CHECK_MODULES(LIBSECRET1, [libsecret-1 >= $LIBSECRET1_REQUIRED])
PKG_CHECK_MODULES(PWQUALITY, [pwquality >= $PWQUALITY_REQUIRED])
+GLIB_GSETTINGS
+
dnl **********************************
dnl *** Check for libsystemd-login ***
dnl **********************************
@@ -150,6 +152,7 @@ data/icons/32x32/Makefile
data/icons/48x48/Makefile
data/icons/256x256/Makefile
data/icons/scalable/Makefile
+data/org.gnome.Disks.gschema.xml.in
data/ui/Makefile
doc/Makefile
doc/man/Makefile
diff --git a/data/Makefile.am b/data/Makefile.am
index 661b35b..5924742 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -6,13 +6,19 @@ desktopdir = $(datadir)/applications
desktop_in_files = gnome-disks.desktop.in gnome-disk-image-mounter.desktop.in
desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
+# GSettings schemas
+gsettings_SCHEMAS = org.gnome.Disks.gschema.xml
+
@INTLTOOL_DESKTOP_RULE@
+ INTLTOOL_XML_NOMERGE_RULE@
+ GSETTINGS_RULES@
EXTRA_DIST = \
$(desktop_in_files) \
$(NULL)
-CLEANFILES = \
+CLEANFILES = \
+ $(gsettings_SCHEMAS) \
$(desktop_DATA) \
$(NULL)
diff --git a/data/org.gnome.Disks.gschema.xml.in.in b/data/org.gnome.Disks.gschema.xml.in.in
new file mode 100644
index 0000000..0b6a008
--- /dev/null
+++ b/data/org.gnome.Disks.gschema.xml.in.in
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schemalist>
+ <schema id="org.gnome.Disks" path="/org/gnome/Disks/" gettext-domain="@GETTEXT_PACKAGE@">
+ <key name="image-dir-uri" type="s">
+ <default>''</default>
+ <_summary>Default location for the Create/Restore disk image dialogs</_summary>
+ <_description>Default location for the Create/Restore disk image dialogs. If blank the ~/Documents folder is used.</_description>
+ </key>
+ </schema>
+</schemalist>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 6302d07..9c51eee 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -3,6 +3,7 @@
# Please keep this file sorted alphabetically.
data/gnome-disk-image-mounter.desktop.in
data/gnome-disks.desktop.in
+data/org.gnome.Disks.gschema.xml.in.in
[type: gettext/glade]data/ui/about-dialog.ui
[type: gettext/glade]data/ui/app-menu.ui
[type: gettext/glade]data/ui/benchmark-dialog.ui
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index ab68185..6001ead 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -1,2 +1,3 @@
# List of files where to skip translations.
# Please keep this file sorted alphabetically.
+data/org.gnome.Disks.gschema.xml.in
diff --git a/src/disks/gducreatediskimagedialog.c b/src/disks/gducreatediskimagedialog.c
index df4a3fc..f5a893d 100644
--- a/src/disks/gducreatediskimagedialog.c
+++ b/src/disks/gducreatediskimagedialog.c
@@ -423,6 +423,9 @@ open_cb (UDisksBlock *block,
goto out;
}
+ /* now that we know the user picked a folder, update file chooser settings */
+ gdu_utils_file_chooser_for_disk_images_update_settings (GTK_FILE_CHOOSER (data->destination_name_fcbutton));
+
data->block_stream = g_unix_input_stream_new (fd, TRUE);
/* Alright, time to start copying! */
diff --git a/src/disks/gdurestorediskimagedialog.c b/src/disks/gdurestorediskimagedialog.c
index 779f37e..c359193 100644
--- a/src/disks/gdurestorediskimagedialog.c
+++ b/src/disks/gdurestorediskimagedialog.c
@@ -530,6 +530,9 @@ gdu_restore_disk_image_dialog_show2 (RestoreDiskImageData *data)
_("_Restore")))
goto out;
+ /* now that we know the user picked a folder, update file chooser settings */
+ gdu_utils_file_chooser_for_disk_images_update_settings (GTK_FILE_CHOOSER (data->source_file_fcbutton));
+
s = g_strdup_printf (_("Copying data to device <i>%s</i>..."),
udisks_block_get_preferred_device (data->block));
gtk_label_set_markup (GTK_LABEL (data->copying_label), s);
diff --git a/src/disks/gduutils.c b/src/disks/gduutils.c
index 73264f1..bff85a6 100644
--- a/src/disks/gduutils.c
+++ b/src/disks/gduutils.c
@@ -75,11 +75,22 @@ void
gdu_utils_configure_file_chooser_for_disk_images (GtkFileChooser *file_chooser)
{
GtkFileFilter *filter;
- const gchar *folder;
+ gchar *folder;
+ GSettings *settings;
- /* Default to the "Documents" folder since that's where we save such images */
- folder = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
- if (folder != NULL)
+ /* Get folder from GSettings, and default to the "Documents" folder */
+
+ settings = g_settings_new ("org.gnome.Disks");
+ folder = g_settings_get_string (settings, "image-dir-uri");
+ if (folder == NULL || strlen (folder) == 0)
+ {
+ g_free (folder);
+ folder = g_strdup_printf ("file://%s", g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS));
+ }
+ g_object_set_data_full (G_OBJECT (file_chooser), "x-gdu-orig-folder", g_strdup (folder), g_free);
+ if (g_str_has_prefix (folder, "file://"))
+ gtk_file_chooser_set_current_folder (file_chooser, folder + strlen ("file://"));
+ else
gtk_file_chooser_set_current_folder (file_chooser, folder);
/* TODO: define proper mime-types */
@@ -93,6 +104,27 @@ gdu_utils_configure_file_chooser_for_disk_images (GtkFileChooser *file_chooser)
gtk_file_filter_add_pattern (filter, "*.iso");
gtk_file_chooser_add_filter (file_chooser, filter); /* adopts filter */
gtk_file_chooser_set_filter (file_chooser, filter);
+
+ g_clear_object (&settings);
+ g_free (folder);
+}
+
+/* should be called when user chooses file/dir from @file_chooser */
+void
+gdu_utils_file_chooser_for_disk_images_update_settings (GtkFileChooser *file_chooser)
+{
+ const gchar *orig_folder;
+ gchar *cur_folder;
+
+ orig_folder = g_object_get_data (G_OBJECT (file_chooser), "x-gdu-orig-folder");
+ cur_folder = gtk_file_chooser_get_uri (file_chooser);
+ if (g_strcmp0 (orig_folder, cur_folder) != 0)
+ {
+ GSettings *settings = g_settings_new ("org.gnome.Disks");
+ g_settings_set_string (settings, "image-dir-uri", cur_folder);
+ g_clear_object (&settings);
+ }
+ g_free (cur_folder);
}
/* ---------------------------------------------------------------------------------------------------- */
diff --git a/src/disks/gduutils.h b/src/disks/gduutils.h
index 4783e92..6e96bc5 100644
--- a/src/disks/gduutils.h
+++ b/src/disks/gduutils.h
@@ -34,6 +34,8 @@ gboolean gdu_utils_has_configuration (UDisksBlock *block,
void gdu_utils_configure_file_chooser_for_disk_images (GtkFileChooser *file_chooser);
+void gdu_utils_file_chooser_for_disk_images_update_settings (GtkFileChooser *file_chooser);
+
GtkWidget *gdu_utils_create_info_bar (GtkMessageType message_type,
const gchar *markup,
GtkWidget **out_label);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]