From 6073d2796518651cb98f61e09c928b024fee2edb Mon Sep 17 00:00:00 2001 From: Tony Houghton Date: Wed, 27 May 2009 21:11:48 +0100 Subject: [PATCH] New options in mount point Properties dialog: What action to take when all a mount point's windows are closed. --- ROX-Filer/src/filer.c | 76 ++++++++++++++++++++++++---------------------- ROX-Filer/src/filer.h | 11 +++++++ ROX-Filer/src/infobox.c | 80 ++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 121 insertions(+), 46 deletions(-) diff --git a/ROX-Filer/src/filer.c b/ROX-Filer/src/filer.c index 8d73aa0c..2e084164 100644 --- a/ROX-Filer/src/filer.c +++ b/ROX-Filer/src/filer.c @@ -120,13 +120,7 @@ enum settings_flags{ SET_FILTER=128, /* filter_type, filter */ }; -typedef enum { - Umount_Prompt_ASK = 0, - Umount_Prompt_NO_CHANGE, - Umount_Prompt_UNMOUNT, - Umount_Prompt_EJECT -} umount_prompt_t; -static GHashTable *umount_prompt_actions = NULL; +static GHashTable *unmount_prompt_actions = NULL; /* Static prototypes */ static void attach(FilerWindow *filer_window); @@ -515,38 +509,37 @@ static char *get_ancestor_user_mount_point(const char *start) } } -static void umount_dialog_response(GtkWidget *dialog, int response, char *mount) +static void unmount_dialog_response(GtkWidget *dialog, + int response, char *mount) { GList *list = NULL; - umount_prompt_t prompt_val = 0; + UnmountPrompt prompt_val = 0; switch (response) { case GTK_RESPONSE_OK: list = g_list_prepend(NULL, mount); action_mount(list, FALSE, FALSE, TRUE); - prompt_val = Umount_Prompt_UNMOUNT; + prompt_val = UNMOUNT_PROMPT_UNMOUNT; break; case ROX_RESPONSE_EJECT: list = g_list_prepend(NULL, mount); action_eject(list); - prompt_val = Umount_Prompt_EJECT; + prompt_val = UNMOUNT_PROMPT_EJECT; break; default: - prompt_val = Umount_Prompt_NO_CHANGE; + prompt_val = UNMOUNT_PROMPT_NO_CHANGE; break; } if (list) g_list_free(list); if (gtk_toggle_button_get_active(g_object_get_data(G_OBJECT(dialog), - "umount_mem_btn"))) + "unmount_mem_btn"))) { - g_hash_table_insert(umount_prompt_actions, g_strdup(mount), - GINT_TO_POINTER(prompt_val)); - save_learnt_mounts(); + filer_set_unmount_action(mount, prompt_val); } g_free(mount); @@ -564,7 +557,7 @@ static void umount_dialog_response(GtkWidget *dialog, int response, char *mount) */ static void may_offer_unmount(FilerWindow *filer_window, char *mount) { - GtkWidget *dialog, *button, *umount_mem_btn; + GtkWidget *dialog, *button, *unmount_mem_btn; GList *next; int len; @@ -594,21 +587,19 @@ static void may_offer_unmount(FilerWindow *filer_window, char *mount) return; } - if (umount_prompt_actions) + if (unmount_prompt_actions) { GList *list = NULL; - umount_prompt_t umount_val = GPOINTER_TO_INT( \ - g_hash_table_lookup(umount_prompt_actions, mount)); + UnmountPrompt unmount_val = filer_get_unmount_action(mount); - fprintf(stderr, "umount_val for %s is %d\n", mount, umount_val); - switch (umount_val) + switch (unmount_val) { - case Umount_Prompt_UNMOUNT: + case UNMOUNT_PROMPT_UNMOUNT: list = g_list_prepend(NULL, mount); action_mount(list, FALSE, FALSE, TRUE); break; - case Umount_Prompt_EJECT: + case UNMOUNT_PROMPT_EJECT: list = g_list_prepend(NULL, mount); action_eject(list); break; @@ -618,7 +609,7 @@ static void may_offer_unmount(FilerWindow *filer_window, char *mount) } if (list) g_list_free(list); - if (umount_val) + if (unmount_val) { g_free(mount); return; @@ -631,13 +622,13 @@ static void may_offer_unmount(FilerWindow *filer_window, char *mount) "Unmounting a device makes it safe to remove " "the disk.")); - umount_mem_btn = gtk_check_button_new_with_label( + unmount_mem_btn = gtk_check_button_new_with_label( _("Perform the same action in future for this mount point")); - gtk_widget_show(umount_mem_btn); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), umount_mem_btn, + gtk_widget_show(unmount_mem_btn); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), unmount_mem_btn, FALSE, FALSE, 0); - g_object_set_data(G_OBJECT(dialog), "umount_mem_btn", - umount_mem_btn); + g_object_set_data(G_OBJECT(dialog), "unmount_mem_btn", + unmount_mem_btn); button = button_new_mixed(ROX_STOCK_MOUNTED, _("No change")); GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); @@ -659,7 +650,7 @@ static void may_offer_unmount(FilerWindow *filer_window, char *mount) gtk_widget_show(button); g_signal_connect(G_OBJECT(dialog), "response", - G_CALLBACK(umount_dialog_response), mount); + G_CALLBACK(unmount_dialog_response), mount); gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); @@ -3035,7 +3026,8 @@ void filer_set_hidden(FilerWindow *filer_window, gboolean hidden) } /* Provided to hide the implementation */ -void filer_set_filter_directories(FilerWindow *filer_window, gboolean filter_directories) +void filer_set_filter_directories(FilerWindow *filer_window, + gboolean filter_directories) { filer_window->filter_directories=filter_directories; } @@ -3189,7 +3181,7 @@ static void load_learnt_mounts(void) gchar **entries; int n; - umount_prompt_actions = g_hash_table_new_full(g_str_hash, + unmount_prompt_actions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); path = choices_find_xdg_path_load("Mounts", PROJECT, SITE); @@ -3220,7 +3212,7 @@ static void load_learnt_mounts(void) if (len > 2) { buffer[len - 2] = 0; - g_hash_table_insert(umount_prompt_actions, g_strdup(buffer), + g_hash_table_insert(unmount_prompt_actions, g_strdup(buffer), GINT_TO_POINTER(buffer[len - 1] - '0')); } } @@ -3249,8 +3241,8 @@ static void save_learnt_mounts(void) FILE *fp = NULL; /* A GHashTableIter would be easier, but it's a relatively new feature */ - if (umount_prompt_actions) - g_hash_table_foreach(umount_prompt_actions, (GHFunc) save_mount, &fp); + if (unmount_prompt_actions) + g_hash_table_foreach(unmount_prompt_actions, (GHFunc) save_mount, &fp); if (fp) fclose(fp); } @@ -3639,3 +3631,15 @@ err: return comment; } + +UnmountPrompt filer_get_unmount_action(const char *path) +{ + return GPOINTER_TO_INT(g_hash_table_lookup(unmount_prompt_actions, path)); +} + +void filer_set_unmount_action(const char *path, UnmountPrompt action) +{ + g_hash_table_insert(unmount_prompt_actions, g_strdup(path), + GINT_TO_POINTER(action)); + save_learnt_mounts(); +} diff --git a/ROX-Filer/src/filer.h b/ROX-Filer/src/filer.h index fed38982..daf67d30 100644 --- a/ROX-Filer/src/filer.h +++ b/ROX-Filer/src/filer.h @@ -43,6 +43,14 @@ typedef enum FILER_SHOW_GLOB, /* Show files that match a glob pattern */ } FilterType; +/* What to do when all a mount point's windows are closed */ +typedef enum { + UNMOUNT_PROMPT_ASK = 0, + UNMOUNT_PROMPT_NO_CHANGE, + UNMOUNT_PROMPT_UNMOUNT, + UNMOUNT_PROMPT_EJECT +} UnmountPrompt; + /* iter's next method has just returned the clicked item... */ typedef void (*TargetFunc)(FilerWindow *filer_window, ViewIter *iter, @@ -168,4 +176,7 @@ void filer_set_hidden(FilerWindow *fwin, gboolean hidden); void filer_next_selected(FilerWindow *filer_window, int dir); void filer_save_settings(FilerWindow *fwin); +UnmountPrompt filer_get_unmount_action(const char *path); +void filer_set_unmount_action(const char *path, UnmountPrompt action); + #endif /* _FILER_H */ diff --git a/ROX-Filer/src/infobox.c b/ROX-Filer/src/infobox.c index e4845fef..d2d589c0 100644 --- a/ROX-Filer/src/infobox.c +++ b/ROX-Filer/src/infobox.c @@ -45,6 +45,7 @@ #include "mount.h" #include "pixmaps.h" #include "xtypes.h" +#include "filer.h" typedef struct _FileStatus FileStatus; @@ -83,6 +84,7 @@ static GtkWidget *make_about(const guchar *path, XMLwrapper *ai); static GtkWidget *make_about_desktop(const gchar *path); static GtkWidget *make_file_says(const guchar *path); static GtkWidget *make_permissions(const gchar *path, DirItem *item); +static GtkWidget *make_unmount_options(const gchar *path); static void add_file_output(FileStatus *fs, gint source, GdkInputCondition condition); static const gchar *pretty_type(DirItem *file, const guchar *path); @@ -293,6 +295,15 @@ static GtkWidget *make_vbox(const guchar *path, GObject *window) gtk_box_pack_start_defaults(vbox, make_file_says(path)); } + else if (item->flags & ITEM_FLAG_MOUNT_POINT) + { + label = gtk_label_new(NULL); + gtk_label_set_markup(GTK_LABEL(label), + _("When all directories are closed")); + gtk_misc_set_alignment(GTK_MISC(label), 0, 1); + gtk_box_pack_start(vbox, label, FALSE, TRUE, 2); + gtk_box_pack_start(vbox, make_unmount_options(path), FALSE, TRUE, 0); + } if (ai) g_object_unref(ai); @@ -922,7 +933,7 @@ static GtkWidget *make_permissions(const gchar *path, DirItem *item) { Permissions *perm; GtkWidget *table; - GtkWidget *tick, *label, *align; + GtkWidget *tick, *label; int i, x, y; perm = g_new(Permissions, 1); @@ -940,17 +951,14 @@ static GtkWidget *make_permissions(const gchar *path, DirItem *item) gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4); label = gtk_label_new(_("Read")); - align = gtk_alignment_new(0, 0.5, 0, 1); - gtk_container_add(GTK_CONTAINER(align), label); - gtk_table_attach_defaults(GTK_TABLE(table), align, 1, 2, 0, 1); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, 0, 1); label = gtk_label_new(_("Write")); - align = gtk_alignment_new(0, 0.5, 0, 1); - gtk_container_add(GTK_CONTAINER(align), label); - gtk_table_attach_defaults(GTK_TABLE(table), align, 2, 3, 0, 1); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_table_attach_defaults(GTK_TABLE(table), label, 2, 3, 0, 1); label = gtk_label_new(_("Exec")); - align = gtk_alignment_new(0, 0.5, 0, 1); - gtk_container_add(GTK_CONTAINER(align), label); - gtk_table_attach_defaults(GTK_TABLE(table), align, 3, 4, 0, 1); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_table_attach_defaults(GTK_TABLE(table), label, 3, 4, 0, 1); for (i = 0; i < 9; i++) { @@ -994,6 +1002,58 @@ static GtkWidget *make_permissions(const gchar *path, DirItem *item) return table; } +static void unmount_option_toggled(GtkToggleButton *toggle, const char *path) +{ + if (gtk_toggle_button_get_active(toggle)) + { + filer_set_unmount_action(path, + GPOINTER_TO_INT(g_object_get_data(G_OBJECT(toggle), + "unmount_action"))); + } +} + +static GtkWidget *pack_unmount_radio(const char *path, + UnmountPrompt path_value, const char *label, + UnmountPrompt btn_value, GtkWidget *group_owner, GtkWidget *hbox) +{ + GtkWidget *radio; + + if (group_owner) + { + radio = gtk_radio_button_new_with_label_from_widget( + GTK_RADIO_BUTTON(group_owner), label); + } + else + { + radio = gtk_radio_button_new_with_label(NULL, label); + } + if (path_value == btn_value) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), TRUE); + g_object_set_data(G_OBJECT(radio), "unmount_action", + GINT_TO_POINTER(btn_value)); + g_signal_connect(radio, "toggled", G_CALLBACK(unmount_option_toggled), + (gpointer) path); + gtk_box_pack_start(GTK_BOX(hbox), radio, FALSE, FALSE, 0); + return radio; +} + +static GtkWidget *make_unmount_options(const char *path) +{ + GtkWidget *hbox, *radio; + UnmountPrompt upval = filer_get_unmount_action(path); + + hbox = gtk_hbox_new(TRUE, 4); + radio = pack_unmount_radio(path, upval, + "No change", UNMOUNT_PROMPT_NO_CHANGE, NULL, hbox); + radio = pack_unmount_radio(path, upval, + "Unmount", UNMOUNT_PROMPT_UNMOUNT, radio, hbox); + radio = pack_unmount_radio(path, upval, + "Eject", UNMOUNT_PROMPT_EJECT, radio, hbox); + pack_unmount_radio(path, upval, + "Ask", UNMOUNT_PROMPT_ASK, radio, hbox); + return hbox; +} + /* Don't g_free() the result */ static const gchar *pretty_type(DirItem *file, const guchar *path) { -- 2.11.4.GIT