+static void
+set_destination(signal_user_data_t *ud)
+{
+ g_debug("set_destination");
+ if (ghb_settings_get_boolean(ud->settings, "use_source_name"))
+ {
+ GString *str = g_string_new("");
+ gchar *vol_name, *filename;
+ const gchar *extension;
+ gchar *new_name;
+ gint title;
+
+ filename = ghb_settings_get_string(ud->settings, "dest_file");
+ extension = get_extension(ud);
+ vol_name = ghb_settings_get_string(ud->settings, "volume_label");
+ g_string_append_printf(str, "%s", vol_name);
+ title = ghb_settings_combo_int(ud->settings, "title");
+ if (title >= 0)
+ {
+ if (ghb_settings_get_boolean(
+ ud->settings, "title_no_in_destination"))
+ {
+
+ title = ghb_settings_combo_int(ud->settings, "title");
+ g_string_append_printf(str, " - %d", title+1);
+ }
+ if (ghb_settings_combo_int(ud->settings, "PtoPType") == 0 &&
+ ghb_settings_get_boolean(
+ ud->settings, "chapters_in_destination"))
+ {
+ gint start, end;
+
+ if (!ghb_settings_get_boolean(
+ ud->settings, "title_no_in_destination"))
+ {
+ g_string_append_printf(str, " -");
+ }
+ start = ghb_settings_get_int(ud->settings, "start_point");
+ end = ghb_settings_get_int(ud->settings, "end_point");
+ if (start == end)
+ g_string_append_printf(str, " Ch %d", start);
+ else
+ g_string_append_printf(str, " Ch %d-%d", start, end);
+ }
+ }
+ g_string_append_printf(str, ".%s", extension);
+ new_name = g_string_free(str, FALSE);
+ ghb_ui_update(ud, "dest_file", ghb_string_value(new_name));
+ g_free(filename);
+ g_free(vol_name);
+ g_free(new_name);
+ }
+}
+
+static gchar*
+get_file_label(const gchar *filename)
+{
+ gchar *base, *pos, *end;
+
+ base = g_path_get_basename(filename);
+ pos = strrchr(base, '.');
+ if (pos != NULL)
+ {
+ // If the last '.' is within 4 chars of end of name, assume
+ // there is an extension we want to strip.
+ end = &base[strlen(base) - 1];
+ if (end - pos <= 4)
+ *pos = 0;
+ }
+ return base;
+}
+
+static gchar*
+resolve_drive_name(gchar *filename)
+{
+#if defined(_WIN32)
+ if (filename[1] == ':')
+ {
+ gchar drive[4];
+ gchar *name;
+ gint dtype;
+
+ g_strlcpy(drive, filename, 4);
+ dtype = GetDriveType(drive);
+ if (dtype == DRIVE_CDROM)
+ {
+ gchar vname[51], fsname[51];
+ GetVolumeInformation(drive, vname, 50, NULL,
+ NULL, NULL, fsname, 50);
+ name = g_strdup(vname);
+ return name;
+ }
+ }
+ return NULL;
+#else
+ return NULL;
+#endif
+}
+
+static gboolean
+update_source_label(signal_user_data_t *ud, const gchar *source, gboolean update_dest)
+{
+ gchar *label = NULL;
+ gint len;
+ gchar **path;
+ gchar *start;
+ gchar *filename = g_strdup(source);
+
+ g_debug("update_source_label()");
+ len = strlen(filename);
+ if (g_file_test(filename, G_FILE_TEST_IS_DIR))
+ {
+ // Skip dos drive letters
+#if defined(_WIN32)
+ start = strchr(filename, ':');
+#else
+ start = filename;
+#endif
+ label = resolve_drive_name(filename);
+ if (label != NULL)
+ {
+ if (uppers_and_unders(label))
+ {
+ camel_convert(label);
+ }
+ }
+ else
+ {
+ if (filename[len-1] == G_DIR_SEPARATOR) filename[len-1] = 0;
+ if (start != NULL)
+ start++;
+ else
+ start = filename;
+
+ path = g_strsplit(start, G_DIR_SEPARATOR_S, -1);
+ len = g_strv_length (path);
+ if ((len > 1) && (strcmp("VIDEO_TS", path[len-1]) == 0))
+ {
+ label = g_strdup(path[len-2]);
+ if (uppers_and_unders(label))
+ {
+ camel_convert(label);
+ }
+ }
+ else if (len > 0)
+ {
+ if (path[len-1][0] != 0)
+ {
+ label = g_strdup(path[len-1]);
+ if (uppers_and_unders(label))
+ {
+ camel_convert(label);
+ }
+ }
+ else
+ label = g_strdup("new_video");
+ }
+ else
+ label = g_strdup("new_video");
+ g_strfreev (path);
+ }
+ }
+ else
+ {
+ // Is regular file or block dev.
+ // Check to see if it is a dvd image
+ label = ghb_dvd_volname (filename);
+ if (label == NULL)
+ {
+ label = get_file_label(filename);
+ }
+ else
+ {
+ if (uppers_and_unders(label))
+ {
+ camel_convert(label);
+ }
+ }
+ }
+ g_free(filename);
+ GtkWidget *widget = GHB_WIDGET (ud->builder, "source_title");
+ if (label != NULL)
+ {
+ gtk_label_set_text (GTK_LABEL(widget), label);
+ ghb_settings_set_string(ud->settings, "volume_label", label);
+ g_free(label);
+ if (update_dest)
+ set_destination(ud);
+ }
+ else
+ {
+ label = "No Title Found";
+ gtk_label_set_text (GTK_LABEL(widget), label);
+ ghb_settings_set_string(ud->settings, "volume_label", label);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+G_MODULE_EXPORT void
+chooser_file_selected_cb(GtkFileChooser *dialog, signal_user_data_t *ud)
+{
+ gchar *name = gtk_file_chooser_get_filename (dialog);
+ GtkTreeModel *store;
+ GtkTreeIter iter;
+ const gchar *device;
+ gboolean foundit = FALSE;
+ GtkComboBox *combo;
+
+ if (name == NULL) return;
+ combo = GTK_COMBO_BOX(GHB_WIDGET(ud->builder, "source_device"));
+ store = gtk_combo_box_get_model(combo);
+ if (gtk_tree_model_get_iter_first(store, &iter))
+ {
+ do
+ {
+ gtk_tree_model_get(store, &iter, 0, &device, -1);
+ if (strcmp(name, device) == 0)