Skip to content
Permalink
Browse files

Add gsettings for showing confirmation dialog and moving files

Preserve the current defaults this way.
  • Loading branch information...
cosimoc committed Feb 26, 2014
1 parent 24f2876 commit d2efbfaa47d6babc2d3874906ece82a7febe0bba
Showing with 143 additions and 83 deletions.
  1. +13 −1 Makefile.am
  2. +2 −0 configure.ac
  3. +14 −0 org.gnome.xdg-user-dirs.gschema.xml.in
  4. +114 −82 update.c
@@ -8,6 +8,14 @@ autostart_DATA = $(autostart_in_files:.desktop.in=.desktop)

@INTLTOOL_DESKTOP_RULE@

gsettingsschema_in_files = org.gnome.xdg-user-dirs.gschema.xml.in
gsettings_SCHEMAS = $(gsettingsschema_in_files:.xml.in=.xml)
.PRECIOUS: $(gsettings_SCHEMAS)

@INTLTOOL_XML_NOMERGE_RULE@

@GSETTINGS_RULES@

INCLUDES = \
-I$(top_srcdir) \
-I$(top_builddir) \
@@ -21,6 +29,7 @@ EXTRA_DIST = \
intltool-merge.in \
intltool-update.in \
$(autostart_in_files) \
$(gsettingsschema_in_files) \
$(NULL)


@@ -33,7 +42,10 @@ bin_PROGRAMS = \
xdg_user_dirs_gtk_update_SOURCES = parse.c parse.h update.c
xdg_user_dirs_gtk_update_LDADD = $(libraries)

CLEANFILES = $(autostart_DATA)
CLEANFILES = \
$(autostart_DATA) \
$(gsettings_SCHEMAS) \
$(NULL)

DISTCLEANFILES = \
intltool-extract \
@@ -26,6 +26,8 @@ AM_GLIB_GNU_GETTEXT
GLIB_DEFINE_LOCALEDIR(GLIBLOCALEDIR)

IT_PROG_INTLTOOL([0.35.0])

GLIB_GSETTINGS

PKG_CHECK_MODULES(GTK, gtk+-3.0)
AC_SUBST(GTK_CFLAGS)
@@ -0,0 +1,14 @@
<schemalist>
<schema id="org.gnome.xdg-user-dirs" path="/org/gnome/xdg-user-dirs/" gettext-domain="xdg-user-dirs-gtk">
<key name="move-directories" type="b">
<default>false</default>
<_summary>Whether to move old directories after locale changes</_summary>
<_description>If set to true, then old directories will be moved when locale changes. If set to false, new directories will be created but the content will not be moved.</_description>
</key>
<key name="show-confirmation-dialog" type="b">
<default>true</default>
<_summary>Whether to show a confirmation dialog before applying locale changes</_summary>
<_description>If set to true, then a confirmation dialog will be displayed upon login to confirm renames after a locale change. If set to false, changes will automatically be applied.</_description>
</key>
</schema>
</schemalist>
196 update.c
@@ -82,42 +82,128 @@ save_locale (void)
}

static gboolean
update_command_can_move (void)
update_command_should_move (GSettings *settings)
{
char *help_stdout = NULL;
gboolean can_move = FALSE;
gboolean should_move = FALSE;

if (!g_settings_get_boolean (settings, "move-directories"))
return FALSE;

g_spawn_command_line_sync (XDG_USER_DIRS_UPDATE " --help",
&help_stdout,
NULL, NULL, NULL);

if (strstr (help_stdout, "--move") != NULL)
can_move = TRUE;
should_move = TRUE;
g_free (help_stdout);

return can_move;
return should_move;
}

static gboolean
do_run_dialog (GtkListStore *list_store,
gboolean should_move,
gboolean *save_locale_out)
{
GtkWidget *dialog, *vbox;
GtkWidget *treeview, *check;
GtkCellRenderer *cell;
GtkWidget *scrolledwindow;
GtkWidget *label;
int response;

dialog = gtk_message_dialog_new (NULL, 0,
GTK_MESSAGE_WARNING,
GTK_BUTTONS_NONE,
_("Update standard folders to current language?"));
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
_("You have logged in in a new language. You can automatically update the names of some standard folders in your home folder to match this language. The update would change the following folders:"));

gtk_dialog_add_buttons (GTK_DIALOG (dialog),
_("_Keep Old Names"), GTK_RESPONSE_NO,
_("_Update Names"), GTK_RESPONSE_YES,
NULL);

gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_NO);

vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
vbox, TRUE, TRUE, 0);
gtk_widget_show (vbox);

scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
GTK_POLICY_NEVER,
GTK_POLICY_NEVER);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow),
GTK_SHADOW_IN);

gtk_box_pack_start (GTK_BOX (vbox), scrolledwindow, TRUE, TRUE, 0);

treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));

gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)),
GTK_SELECTION_NONE);

cell = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
-1, _("Current folder name"),
cell,
"text", 0,
NULL);
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
-1, _("New folder name"),
cell,
"text", 1,
NULL);

gtk_container_add (GTK_CONTAINER (scrolledwindow),
treeview);

gtk_widget_show_all (scrolledwindow);

if (!should_move)
{
label = gtk_label_new (_("Note that existing content will not be moved."));
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_label_set_selectable (GTK_LABEL (label), TRUE);
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
gtk_widget_show (label);
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
}

check = gtk_check_button_new_with_mnemonic (_("_Don't ask me this again"));
gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
gtk_widget_show (check);

response = gtk_dialog_run (GTK_DIALOG (dialog));

if (save_locale_out)
*save_locale_out = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));

gtk_widget_destroy (dialog);
return (response == GTK_RESPONSE_YES);
}

static void
update_locale (XdgDirEntry *old_entries)
{
XdgDirEntry *new_entries, *entry;
GtkWidget *dialog, *vbox;
int exit_status;
int fd;
char *filename;
char *cmdline;
int response;
int i, j;
GtkListStore *list_store;
GtkTreeIter iter;
GtkWidget *treeview, *check;
GtkCellRenderer *cell;
GtkWidget *scrolledwindow;
GtkWidget *label;
char *std_out, *std_err;
gboolean has_changes;
gboolean can_move;
gboolean should_move;
gboolean should_save_locale;
gboolean should_show_dialog;
gboolean should_update;
GSettings *settings;

fd = g_file_open_tmp ("dirs-XXXXXX", &filename, NULL);
if (fd == -1)
@@ -140,6 +226,9 @@ update_locale (XdgDirEntry *old_entries)
if (!WIFEXITED(exit_status) || WEXITSTATUS(exit_status) != 0)
return;

settings = g_settings_new ("org.gnome.xdg-user-dirs");
should_move = update_command_should_move (settings);

new_entries = parse_xdg_dirs (filename);
g_unlink (filename);
g_free (filename);
@@ -194,82 +283,27 @@ update_locale (XdgDirEntry *old_entries)

if (!has_changes)
{
g_object_unref (settings);
g_object_unref (list_store);
return;
}

dialog = gtk_message_dialog_new (NULL, 0,
GTK_MESSAGE_WARNING,
GTK_BUTTONS_NONE,
_("Update standard folders to current language?"));
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
_("You have logged in in a new language. You can automatically update the names of some standard folders in your home folder to match this language. The update would change the following folders:"));

gtk_dialog_add_buttons (GTK_DIALOG (dialog),
_("_Keep Old Names"), GTK_RESPONSE_NO,
_("_Update Names"), GTK_RESPONSE_YES,
NULL);

gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_NO);

vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
vbox, TRUE, TRUE, 0);
gtk_widget_show (vbox);

scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
GTK_POLICY_NEVER,
GTK_POLICY_NEVER);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow),
GTK_SHADOW_IN);

gtk_box_pack_start (GTK_BOX (vbox), scrolledwindow, TRUE, TRUE, 0);

treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));

gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)),
GTK_SELECTION_NONE);

cell = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
-1, _("Current folder name"),
cell,
"text", 0,
NULL);
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
-1, _("New folder name"),
cell,
"text", 1,
NULL);

gtk_container_add (GTK_CONTAINER (scrolledwindow),
treeview);

gtk_widget_show_all (scrolledwindow);

can_move = update_command_can_move ();
if (!can_move)
should_show_dialog = g_settings_get_boolean (settings, "show-confirmation-dialog");
if (should_show_dialog)
{
label = gtk_label_new (_("Note that existing content will not be moved."));
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_label_set_selectable (GTK_LABEL (label), TRUE);
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
gtk_widget_show (label);
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
should_update = do_run_dialog (list_store, should_move, &should_save_locale);
}
else
{
should_save_locale = TRUE;
should_update = TRUE;
}

check = gtk_check_button_new_with_mnemonic (_("_Don't ask me this again"));
gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
gtk_widget_show (check);

response = gtk_dialog_run (GTK_DIALOG (dialog));

if (response == GTK_RESPONSE_YES)
if (should_update)
{
const gchar *cmdline;

if (can_move)
if (should_move)
cmdline = XDG_USER_DIRS_UPDATE " --move --force";
else
cmdline = XDG_USER_DIRS_UPDATE " --force";
@@ -308,15 +342,13 @@ update_locale (XdgDirEntry *old_entries)
}
}

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)))
{
save_locale ();
}
if (should_save_locale)
save_locale ();

g_free (new_entries);

gtk_widget_destroy (dialog);
g_object_unref (list_store);
g_object_unref (settings);
}

int

0 comments on commit d2efbfa

Please sign in to comment.
You can’t perform that action at this time.