diff options
author | jstebbins <[email protected]> | 2008-11-26 16:23:23 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2008-11-26 16:23:23 +0000 |
commit | b69a2ae27d28eba72585246bc810de0ea0d33886 (patch) | |
tree | b753074abf11464925132d55a95f9a550ee7970a /gtk | |
parent | 54c7e6f7e9f5c2bb57fcca2808fce07aaf0589c9 (diff) |
LinGui: add a file chooser button for the dest directory. dest file is
separated with its own entry box.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1955 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/src/callbacks.c | 112 | ||||
-rw-r--r-- | gtk/src/ghb.ui | 77 | ||||
-rw-r--r-- | gtk/src/internal_defaults.xml | 4 | ||||
-rw-r--r-- | gtk/src/presets.c | 8 | ||||
-rw-r--r-- | gtk/src/resource_data.h | 129 | ||||
-rw-r--r-- | gtk/src/resources.plist | 81 | ||||
-rw-r--r-- | gtk/src/settings.c | 20 |
7 files changed, 177 insertions, 254 deletions
diff --git a/gtk/src/callbacks.c b/gtk/src/callbacks.c index 5f2a55a43..3223f91cd 100644 --- a/gtk/src/callbacks.c +++ b/gtk/src/callbacks.c @@ -216,40 +216,6 @@ ghb_check_all_depencencies(signal_user_data_t *ud) } } -static gchar* -expand_tilde(const gchar *path) -{ - const gchar *user_home; - gchar *home; - const gchar *suffix; - gchar *expanded_path = NULL; - - g_debug("expand_tilde ()"); - if (path[0] == '~') - { - user_home = g_get_home_dir(); - home = NULL; // squash warning about home uninitialized - if (path[1] == 0) - { - home = g_strdup(user_home); - suffix = ""; - } - else if (path[1] == '/') - { - home = g_strdup(user_home); - suffix = &path[2]; - } - else - { - home = g_path_get_dirname(user_home); - suffix = &path[1]; - } - expanded_path = g_strdup_printf("%s/%s", home, suffix); - g_free(home); - } - return expanded_path; -} - void on_quit1_activate(GtkMenuItem *quit, signal_user_data_t *ud) { @@ -278,11 +244,10 @@ set_destination(signal_user_data_t *ud) if (ghb_settings_get_boolean(ud->settings, "use_source_name")) { gchar *vol_name, *filename, *extension; - gchar *dir, *new_name; + gchar *new_name; - filename = ghb_settings_get_string(ud->settings, "destination"); + filename = ghb_settings_get_string(ud->settings, "dest_file"); extension = ghb_settings_get_string(ud->settings, "FileFormat"); - dir = g_path_get_dirname (filename); vol_name = ghb_settings_get_string(ud->settings, "volume_label"); if (ghb_settings_get_boolean(ud->settings, "chapters_in_destination")) { @@ -292,24 +257,23 @@ set_destination(signal_user_data_t *ud) end = ghb_settings_get_int(ud->settings, "end_chapter"); if (start == end) { - new_name = g_strdup_printf("%s/%s-%d.%s", - dir, vol_name, start, extension); + new_name = g_strdup_printf("%s-%d.%s", + vol_name, start, extension); } else { - new_name = g_strdup_printf("%s/%s-%d-%d.%s", - dir, vol_name, start, end, extension); + new_name = g_strdup_printf("%s-%d-%d.%s", + vol_name, start, end, extension); } } else { - new_name = g_strdup_printf("%s/%s.%s", dir, vol_name, extension); + new_name = g_strdup_printf("%s.%s", vol_name, extension); } - ghb_ui_update(ud, "destination", ghb_string_value(new_name)); + ghb_ui_update(ud, "dest_file", ghb_string_value(new_name)); g_free(filename); g_free(extension); g_free(vol_name); - g_free(dir); g_free(new_name); } } @@ -705,7 +669,7 @@ update_destination_extension(signal_user_data_t *ud) g_debug("update_destination_extension ()"); extension = ghb_settings_get_string(ud->settings, "FileFormat"); - entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "destination")); + entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "dest_file")); filename = g_strdup(gtk_entry_get_text(entry)); for (ii = 0; containers[ii] != NULL; ii++) { @@ -727,7 +691,7 @@ update_destination_extension(signal_user_data_t *ud) break; } new_name = g_strjoin(".", filename, extension, NULL); - ghb_ui_update(ud, "destination", ghb_string_value(new_name)); + ghb_ui_update(ud, "dest_file", ghb_string_value(new_name)); g_free(new_name); break; } @@ -758,6 +722,7 @@ destination_select_title(GtkEntry *entry) break; } } + if (start < 0) start = 0; if (start < end) { gtk_editable_select_region(GTK_EDITABLE(entry), start, end); @@ -776,20 +741,39 @@ destination_grab_cb( static gboolean update_default_destination = FALSE; void -destination_entry_changed_cb(GtkEntry *entry, signal_user_data_t *ud) +dest_dir_set_cb(GtkFileChooserButton *dest_chooser, signal_user_data_t *ud) { - gchar *dest; + gchar *dest_file, *dest_dir, *dest; - g_debug("destination_entry_changed_cb ()"); - if ((dest = expand_tilde(gtk_entry_get_text(entry))) != NULL) - { - gtk_entry_set_text(entry, dest); - g_free(dest); - } + g_debug("dest_dir_set_cb ()"); + ghb_widget_to_setting(ud->settings, (GtkWidget*)dest_chooser); + dest_file = ghb_settings_get_string(ud->settings, "dest_file"); + dest_dir = ghb_settings_get_string(ud->settings, "dest_dir"); + dest = g_strdup_printf("%s/%s", dest_dir, dest_file); + ghb_settings_set_string(ud->settings, "destination", dest); + g_free(dest_file); + g_free(dest_dir); + g_free(dest); + update_default_destination = TRUE; +} + +void +dest_file_changed_cb(GtkEntry *entry, signal_user_data_t *ud) +{ + gchar *dest_file, *dest_dir, *dest; + + g_debug("dest_file_changed_cb ()"); update_destination_extension(ud); ghb_widget_to_setting(ud->settings, (GtkWidget*)entry); // This signal goes off with ever keystroke, so I'm putting this // update on the timer. + dest_file = ghb_settings_get_string(ud->settings, "dest_file"); + dest_dir = ghb_settings_get_string(ud->settings, "dest_dir"); + dest = g_strdup_printf("%s/%s", dest_dir, dest_file); + ghb_settings_set_string(ud->settings, "destination", dest); + g_free(dest_file); + g_free(dest_dir); + g_free(dest); update_default_destination = TRUE; } @@ -816,18 +800,18 @@ destination_browse_clicked_cb(GtkButton *button, signal_user_data_t *ud) g_free(basename); if (gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { - char *filename; + char *filename, *dirname; + GtkFileChooser *dest_chooser; filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); - entry = (GtkEntry*)GHB_WIDGET(ud->builder, "destination"); - if (entry == NULL) - { - g_debug("Failed to find widget: %s", "destination"); - } - else - { - gtk_entry_set_text(entry, filename); - } + basename = g_path_get_basename(filename); + dirname = g_path_get_dirname(filename); + entry = (GtkEntry*)GHB_WIDGET(ud->builder, "dest_file"); + gtk_entry_set_text(entry, basename); + dest_chooser = GTK_FILE_CHOOSER(GHB_WIDGET(ud->builder, "dest_dir")); + gtk_file_chooser_set_filename(dest_chooser, dirname); + g_free (dirname); + g_free (basename); g_free (filename); } gtk_widget_destroy(dialog); diff --git a/gtk/src/ghb.ui b/gtk/src/ghb.ui index 3e3e75fcc..6e013342a 100644 --- a/gtk/src/ghb.ui +++ b/gtk/src/ghb.ui @@ -714,78 +714,53 @@ <child> <object class="GtkHBox" id="hbox6"> <property name="visible">True</property> + <property name="spacing">5</property> + + + + <child> - <object class="GtkLabel" id="label8"> + <object class="GtkFileChooserButton" id="dest_dir"> <property name="visible">True</property> - <property name="label" translatable="yes">File:</property> + <property name="action">select-folder</property> + <property name="title" translatable="yes">Destination Directory</property> + <signal name="selection_changed" handler="dest_dir_set_cb"/> </object> <packing> - <property name="expand">False</property> - <property name="fill">False</property> + <property name="position">0</property> </packing> </child> <child> - <object class="GtkEntry" id="destination"> + <object class="GtkLabel" id="label18"> <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="tooltip-text" translatable="yes">Destination path with file name for output.</property> - <property name="width_chars">41</property> - <signal handler="destination_entry_changed_cb" name="changed"/> - <signal handler="destination_grab_cb" name="grab-focus" after="yes"/> - <accelerator key="d" signal="grab-focus" modifiers="GDK_MOD1_MASK"/> + <property name="label" translatable="yes">File:</property> </object> <packing> + <property name="expand">False</property> + <property name="fill">False</property> <property name="position">1</property> </packing> </child> <child> - <object class="GtkButton" id="destination_browse"> + <object class="GtkEntry" id="dest_file"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="relief">GTK_RELIEF_NONE</property> - <signal handler="destination_browse_clicked_cb" name="clicked"/> - <child> - <object class="GtkAlignment" id="alignment4"> - <property name="visible">True</property> - <property name="xscale">0</property> - <property name="yscale">0</property> - <child> - <object class="GtkHBox" id="hbox7"> - <property name="visible">True</property> - <property name="spacing">2</property> - <child> - <object class="GtkImage" id="image2"> - <property name="visible">True</property> - <property name="stock">gtk-open</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label9"> - <property name="visible">True</property> - <property name="label" translatable="yes">Browse</property> - <property name="use_underline">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - </child> - </object> - </child> + <property name="width_chars">20</property> + <accelerator key="d" signal="grab-focus" modifiers="GDK_MOD1_MASK"/> + <signal name="changed" handler="dest_file_changed_cb"/> + <signal name="grab_focus" handler="destination_grab_cb" after="yes"/> </object> <packing> - <property name="expand">False</property> - <property name="fill">False</property> <property name="position">2</property> </packing> </child> + + + + + + + </object> </child> <child> diff --git a/gtk/src/internal_defaults.xml b/gtk/src/internal_defaults.xml index be0d9e519..bdb599afe 100644 --- a/gtk/src/internal_defaults.xml +++ b/gtk/src/internal_defaults.xml @@ -8,6 +8,10 @@ <true /> <key>autoscale</key> <false /> + <key>dest_dir</key> + <string></string> + <key>dest_file</key> + <string>new_video.mp4</string> <key>end_chapter</key> <integer>100</integer> <key>folder</key> diff --git a/gtk/src/presets.c b/gtk/src/presets.c index f7504d681..4153e38e4 100644 --- a/gtk/src/presets.c +++ b/gtk/src/presets.c @@ -1177,12 +1177,14 @@ ghb_prefs_to_ui(signal_user_data_t *ud) } gval = ghb_settings_get_value(ud->settings, "default_source"); ghb_settings_set_value (ud->settings, "source", gval); + str = ghb_settings_get_string(ud->settings, "destination_dir"); + ghb_ui_update(ud, "dest_dir", ghb_string_value(str)); - gchar *path = g_strdup_printf ("%s/new_video.mp4", str); - ghb_ui_update(ud, "destination", ghb_string_value(path)); + gchar *file = g_strdup_printf ("new_video.mp4"); + ghb_ui_update(ud, "dest_file", ghb_string_value(file)); g_free(str); - g_free(path); + g_free(file); prefs_initializing = FALSE; } diff --git a/gtk/src/resource_data.h b/gtk/src/resource_data.h index a6fe4794e..7631d0249 100644 --- a/gtk/src/resource_data.h +++ b/gtk/src/resource_data.h @@ -1078,9 +1078,33 @@ "quot;hbox6">\n" " <property name="visible"&g" "t;True</property>\n" +" <property name="spacing"&g" +"t;5</property>\n" +"\n" +"\n" +"\n" +"\n" +" <child>\n" +" <object class="GtkFileChooser" +"Button" id="dest_dir">\n" +" <property name="visible&quo" +"t;>True</property>\n" +" <property name="action"" +";>select-folder</property>\n" +" <property name="title"" +" translatable="yes">Destination Directory</property>" +"\n" +" <signal name="selection_cha" +"nged" handler="dest_dir_set_cb"/>\n" +" </object>\n" +" <packing>\n" +" <property name="position&qu" +"ot;>0</property>\n" +" </packing>\n" +" </child>\n" " <child>\n" " <object class="GtkLabel"" -" id="label8">\n" +" id="label18">\n" " <property name="visible&quo" "t;>True</property>\n" " <property name="label"" @@ -1091,107 +1115,38 @@ ";>False</property>\n" " <property name="fill"&" "gt;False</property>\n" +" <property name="position&qu" +"ot;>1</property>\n" " </packing>\n" " </child>\n" " <child>\n" " <object class="GtkEntry"" -" id="destination">\n" +" id="dest_file">\n" " <property name="visible&quo" "t;>True</property>\n" " <property name="can_focus&q" "uot;>True</property>\n" -" <property name="tooltip-tex" -"t" translatable="yes">Destination path with file name" -" for output.</property>\n" " <property name="width_chars" -"">41</property>\n" -" <signal handler="destinatio" -"n_entry_changed_cb" name="changed"/>\n" -" <signal handler="destinatio" -"n_grab_cb" name="grab-focus" after="yes"/>\n" +"">20</property>\n" " <accelerator key="d" s" "ignal="grab-focus" modifiers="GDK_MOD1_MASK"/>\n" +" <signal name="changed"" +" handler="dest_file_changed_cb"/>\n" +" <signal name="grab_focus&qu" +"ot; handler="destination_grab_cb" after="yes"/>\n" " </object>\n" " <packing>\n" " <property name="position&qu" -"ot;>1</property>\n" -" </packing>\n" -" </child>\n" -" <child>\n" -" <object class="GtkButton"" -"; id="destination_browse">\n" -" <property name="visible&quo" -"t;>True</property>\n" -" <property name="can_focus&q" -"uot;>True</property>\n" -" <property name="relief"" -";>GTK_RELIEF_NONE</property>\n" -" <signal handler="destinatio" -"n_browse_clicked_cb" name="clicked"/>\n" -" <child>\n" -" <object class="GtkAlignme" -"nt" id="alignment4">\n" -" <property name="visible" -"">True</property>\n" -" <property name="xscale&" -"quot;>0</property>\n" -" <property name="yscale&" -"quot;>0</property>\n" -" <child>\n" -" <object class="GtkHBo" -"x" id="hbox7">\n" -" <property name="vis" -"ible">True</property>\n" -" <property name="spa" -"cing">2</property>\n" -" <child>\n" -" <object class="Gt" -"kImage" id="image2">\n" -" <property name="" -";visible">True</property>\n" -" <property name="" -";stock">gtk-open</property>\n" -" </object>\n" -" <packing>\n" -" <property name="" -";expand">False</property>\n" -" <property name="" -";fill">False</property>\n" -" </packing>\n" -" </child>\n" -" <child>\n" -" <object class="Gt" -"kLabel" id="label9">\n" -" <property name="" -";visible">True</property>\n" -" <property name="" -";label" translatable="yes">Browse</property>\n" -" <property name="" -";use_underline">True</property>\n" -" </object>\n" -" <packing>\n" -" <property name="" -";expand">False</property>\n" -" <property name="" -";fill">False</property>\n" -" <property name="" -";position">1</property>\n" -" </packing>\n" -" </child>\n" -" </object>\n" -" </child>\n" -" </object>\n" -" </child>\n" -" </object>\n" -" <packing>\n" -" <property name="expand"" -";>False</property>\n" -" <property name="fill"&" -"gt;False</property>\n" -" <property name="position&qu" "ot;>2</property>\n" " </packing>\n" " </child>\n" +"\n" +"\n" +"\n" +"\n" +"\n" +"\n" +"\n" " </object>\n" " </child>\n" " <child>\n" @@ -10576,6 +10531,10 @@ " </array>\n" " <key>autoscale</key>\n" " <false />\n" +" <key>dest_dir</key>\n" +" <string></string>\n" +" <key>dest_file</key>\n" +" <string>new_video.mp4</string>\n" " <key>end_chapter</key>\n" " <integer>100</integer>\n" " <key>folder</key>\n" diff --git a/gtk/src/resources.plist b/gtk/src/resources.plist index f01338942..72771ba72 100644 --- a/gtk/src/resources.plist +++ b/gtk/src/resources.plist @@ -719,78 +719,53 @@ <child> <object class="GtkHBox" id="hbox6"> <property name="visible">True</property> + <property name="spacing">5</property> + + + + <child> - <object class="GtkLabel" id="label8"> + <object class="GtkFileChooserButton" id="dest_dir"> <property name="visible">True</property> - <property name="label" translatable="yes">File:</property> + <property name="action">select-folder</property> + <property name="title" translatable="yes">Destination Directory</property> + <signal name="selection_changed" handler="dest_dir_set_cb"/> </object> <packing> - <property name="expand">False</property> - <property name="fill">False</property> + <property name="position">0</property> </packing> </child> <child> - <object class="GtkEntry" id="destination"> + <object class="GtkLabel" id="label18"> <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="tooltip-text" translatable="yes">Destination path with file name for output.</property> - <property name="width_chars">41</property> - <signal handler="destination_entry_changed_cb" name="changed"/> - <signal handler="destination_grab_cb" name="grab-focus" after="yes"/> - <accelerator key="d" signal="grab-focus" modifiers="GDK_MOD1_MASK"/> + <property name="label" translatable="yes">File:</property> </object> <packing> + <property name="expand">False</property> + <property name="fill">False</property> <property name="position">1</property> </packing> </child> <child> - <object class="GtkButton" id="destination_browse"> + <object class="GtkEntry" id="dest_file"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="relief">GTK_RELIEF_NONE</property> - <signal handler="destination_browse_clicked_cb" name="clicked"/> - <child> - <object class="GtkAlignment" id="alignment4"> - <property name="visible">True</property> - <property name="xscale">0</property> - <property name="yscale">0</property> - <child> - <object class="GtkHBox" id="hbox7"> - <property name="visible">True</property> - <property name="spacing">2</property> - <child> - <object class="GtkImage" id="image2"> - <property name="visible">True</property> - <property name="stock">gtk-open</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label9"> - <property name="visible">True</property> - <property name="label" translatable="yes">Browse</property> - <property name="use_underline">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - </child> - </object> - </child> + <property name="width_chars">20</property> + <accelerator key="d" signal="grab-focus" modifiers="GDK_MOD1_MASK"/> + <signal name="changed" handler="dest_file_changed_cb"/> + <signal name="grab_focus" handler="destination_grab_cb" after="yes"/> </object> <packing> - <property name="expand">False</property> - <property name="fill">False</property> <property name="position">2</property> </packing> </child> + + + + + + + </object> </child> <child> @@ -5196,6 +5171,10 @@ R2RrUAAABBgBAQACAAAAQAAAABAAAAAQ////AP///wD///8A////AP///wD///8A////AP///wD///8A </array> <key>autoscale</key> <false /> + <key>dest_dir</key> + <string></string> + <key>dest_file</key> + <string>new_video.mp4</string> <key>end_chapter</key> <integer>100</integer> <key>folder</key> diff --git a/gtk/src/settings.c b/gtk/src/settings.c index 0b5c90283..03d65c766 100644 --- a/gtk/src/settings.c +++ b/gtk/src/settings.c @@ -321,6 +321,12 @@ ghb_widget_value(GtkWidget *widget) str = gtk_label_get_text (GTK_LABEL(widget)); value = ghb_string_value_new(str); } + else if (type == GTK_TYPE_FILE_CHOOSER_BUTTON) + { + const gchar *str; + str = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(widget)); + value = ghb_string_value_new(str); + } else { g_debug("Attempt to set unknown widget type: %s\n", name); @@ -569,6 +575,20 @@ update_widget(GtkWidget *widget, const GValue *value) { gtk_label_set_text (GTK_LABEL(widget), str); } + else if (type == GTK_TYPE_FILE_CHOOSER_BUTTON) + { + GtkFileChooserAction act; + act = gtk_file_chooser_get_action(GTK_FILE_CHOOSER(widget)); + if (act == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER || + act == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER) + { + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(widget), str); + } + else + { + gtk_file_chooser_set_filename (GTK_FILE_CHOOSER(widget), str); + } + } else { g_debug("Attempt to set unknown widget type"); |