- g_debug("prefs_dialog_cb ()");
- dialog = GHB_WIDGET(ud->builder, "prefs_dialog");
- response = gtk_dialog_run(GTK_DIALOG(dialog));
- gtk_widget_hide(dialog);
-}
-
-void
-presets_remove_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
-{
- GtkTreeView *treeview;
- GtkTreeSelection *selection;
- GtkTreeModel *store;
- GtkTreeIter iter;
- gchar *preset;
- GtkResponseType response;
-
- g_debug("presets_remove_clicked_cb ()");
- treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
- selection = gtk_tree_view_get_selection (treeview);
- if (gtk_tree_selection_get_selected(selection, &store, &iter))
- {
- GtkWidget *dialog;
-
- gtk_tree_model_get(store, &iter, 0, &preset, -1);
- dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
- GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
- "Confirm deletion of preset %s.", preset);
- response = gtk_dialog_run(GTK_DIALOG(dialog));
- gtk_widget_destroy (dialog);
- if (response == GTK_RESPONSE_YES)
- {
- GtkTreeIter nextIter = iter;
- gchar *nextPreset = NULL;
- if (!gtk_tree_model_iter_next(store, &nextIter))
- {
- if (gtk_tree_model_get_iter_first(store, &nextIter))
- {
- gtk_tree_model_get(store, &nextIter, 0, &nextPreset, -1);
- }
- }
- else
- {
- gtk_tree_model_get(store, &nextIter, 0, &nextPreset, -1);
- }
- // Remove the selected item
- // First unselect it so that selecting the new item works properly
- gtk_tree_selection_unselect_iter (selection, &iter);
- ghb_presets_remove(preset);
- ghb_presets_list_update(ud);
- ghb_select_preset(ud->builder, nextPreset);
- }
- }
-}
-
-static void
-preset_update_title_deps(signal_user_data_t *ud, ghb_title_info_t *tinfo)
-{
- GtkWidget *widget;
-
- ghb_ui_update(ud, "scale_width",
- ghb_int64_value(tinfo->width - tinfo->crop[2] - tinfo->crop[3]));
- // If anamorphic or keep_aspect, the hight will be automatically calculated
- gboolean keep_aspect, anamorphic;
- keep_aspect = ghb_settings_get_boolean(ud->settings, "keep_aspect");
- anamorphic = ghb_settings_get_boolean(ud->settings, "anamorphic");
- if (!(keep_aspect || anamorphic))
- {
- ghb_ui_update(ud, "scale_height",
- ghb_int64_value(tinfo->height - tinfo->crop[0] - tinfo->crop[1]));
- }
-
- // Set the limits of cropping. hb_set_anamorphic_size crashes if
- // you pass it a cropped width or height == 0.
- gint bound;
- bound = tinfo->height / 2 - 2;
- widget = GHB_WIDGET (ud->builder, "crop_top");
- gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
- widget = GHB_WIDGET (ud->builder, "crop_bottom");
- gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
- bound = tinfo->width / 2 - 2;
- widget = GHB_WIDGET (ud->builder, "crop_left");
- gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
- widget = GHB_WIDGET (ud->builder, "crop_right");
- gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 0, bound);
- if (ghb_settings_get_boolean(ud->settings, "autocrop"))
- {
- ghb_ui_update(ud, "crop_top", ghb_int64_value(tinfo->crop[0]));
- ghb_ui_update(ud, "crop_bottom", ghb_int64_value(tinfo->crop[1]));
- ghb_ui_update(ud, "crop_left", ghb_int64_value(tinfo->crop[2]));
- ghb_ui_update(ud, "crop_right", ghb_int64_value(tinfo->crop[3]));
- }
-}
-
-void
-presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud)
-{
- GtkTreeModel *store;
- GtkTreeIter iter;
- gchar *preset;
- ghb_title_info_t tinfo;
- GtkWidget *widget;
-
- g_debug("presets_list_selection_changed_cb ()");
- widget = GHB_WIDGET (ud->builder, "presets_remove");
- if (gtk_tree_selection_get_selected(selection, &store, &iter))
- {
- gtk_tree_model_get(store, &iter, 0, &preset, -1);
- ud->dont_clear_presets = TRUE;
- // Temporarily set the video_quality range to (0,100)
- // This is needed so the video_quality value does not get
- // truncated when set. The range will be readjusted below
- GtkWidget *qp = GHB_WIDGET(ud->builder, "video_quality");
- gtk_range_set_range (GTK_RANGE(qp), 0, 100);
- // Clear the audio list prior to changing the preset. Existing audio
- // can cause the container extension to be automatically changed when
- // it shouldn't be
- clear_audio_list(ud);
- ghb_set_preset(ud, preset);
- gint titleindex;
- titleindex = ghb_settings_combo_int(ud->settings, "title");
- set_pref_audio(titleindex, ud);
- ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
- ud->dont_clear_presets = FALSE;
- if (ghb_get_title_info (&tinfo, titleindex))
- {
- preset_update_title_deps(ud, &tinfo);
- }
- ghb_set_scale (ud, GHB_SCALE_KEEP_NONE);
-
- gint vqmin, vqmax;
- ghb_vquality_range(ud, &vqmin, &vqmax);
- gtk_range_set_range (GTK_RANGE(qp), vqmin, vqmax);
- gtk_widget_set_sensitive(widget, TRUE);
- }
- else
- {
- g_debug("No selection??? Perhaps unselected.");
- gtk_widget_set_sensitive(widget, FALSE);
- }
-}
-
-void
-queue_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud)
-{
- GtkTreeModel *store;
- GtkTreeIter iter, piter;
-
- g_debug("queue_list_selection_changed_cb ()");
- // A queue entry is made up of a parent and multiple
- // children that are visible when expanded. When and entry
- // is selected, I want the parent to be selected.
- // This is purely cosmetic.
- if (gtk_tree_selection_get_selected(selection, &store, &iter))
- {
- if (gtk_tree_model_iter_parent (store, &piter, &iter))
- {
- GtkTreePath *path;
- GtkTreeView *treeview;
-
- gtk_tree_selection_select_iter (selection, &piter);
- path = gtk_tree_model_get_path (store, &piter);
- treeview = gtk_tree_selection_get_tree_view (selection);
- // Make the parent visible in scroll window if it is not.
- gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0, 0);
- gtk_tree_path_free(path);
- }
- }
-}
-
-static void
-add_to_queue_list(signal_user_data_t *ud, GValue *settings, GtkTreeIter *piter)
-{
- GtkTreeView *treeview;
- GtkTreeIter iter;
- GtkTreeStore *store;
- gchar *info;
- gint status;
- GtkTreeIter citer;
- gchar *dest, *preset, *vol_name, *basename;
- const gchar *vcodec, *container;
- gchar *fps, *vcodec_abbr;
- gint title, start_chapter, end_chapter, width, height, vqvalue;
- gint source_width, source_height;
- gboolean pass2, anamorphic, round_dim, keep_aspect, vqtype, turbo;
- gboolean tweaks;
-
- g_debug("update_queue_list ()");
- if (settings == NULL) return;
- treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
- store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
-
- tweaks = ghb_settings_get_boolean(settings, "allow_tweaks");
- title = ghb_settings_combo_int(settings, "title");
- start_chapter = ghb_settings_get_int(settings, "start_chapter");
- end_chapter = ghb_settings_get_int(settings, "end_chapter");
- pass2 = ghb_settings_get_boolean(settings, "two_pass");
- vol_name = ghb_settings_get_string(settings, "volume_label");
- dest = ghb_settings_get_string(settings, "destination");
- basename = g_path_get_basename(dest);
- info = g_strdup_printf
- (
- "<big><b>%s</b></big> "
- "<small>(Title %d, Chapters %d through %d, %d Video %s)"
- " --> %s</small>",
- vol_name, title+1, start_chapter, end_chapter,
- pass2 ? 2:1, pass2 ? "Passes":"Pass", basename
- );
-
- if (piter)
- iter = *piter;
- else
- gtk_tree_store_append(store, &iter, NULL);
-
- gtk_tree_store_set(store, &iter, 1, info, 2, "hb-queue-delete", -1);
- g_free(info);
- status = ghb_settings_get_int(settings, "job_status");
- switch (status)
- {
- case GHB_QUEUE_PENDING:
- gtk_tree_store_set(store, &iter, 0, "hb-queue-job", -1);
- break;
- case GHB_QUEUE_CANCELED:
- gtk_tree_store_set(store, &iter, 0, "hb-canceled", -1);
- break;
- case GHB_QUEUE_RUNNING:
- gtk_tree_store_set(store, &iter, 0, "hb-working0", -1);
- break;
- case GHB_QUEUE_DONE:
- gtk_tree_store_set(store, &iter, 0, "hb-complete", -1);
- break;
- default:
- gtk_tree_store_set(store, &iter, 0, "hb-queue-job", -1);
- break;
- }
-
- GString *str = g_string_new("");
- gboolean markers;
- gboolean preset_modified;
- gint mux;
-
- container = ghb_settings_combo_option(settings, "container");
- mux = ghb_settings_combo_int(settings, "container");
- preset_modified = ghb_settings_get_boolean(settings, "preset_modified");
- preset = ghb_settings_get_string(settings, "preset");
- markers = ghb_settings_get_boolean(settings, "chapter_markers");
-
- if (preset_modified)
- g_string_append_printf(str,
- "<b>Customized Preset Based On:</b> <small>%s</small>\n",
- preset);
- else
- g_string_append_printf(str,
- "<b>Preset:</b> <small>%s</small>\n",
- preset);
-
- if (markers)
- {
- g_string_append_printf(str,
- "<b>Format:</b> <small>%s Container, Chapter Markers</small>\n",
- container);
- }
- else
- {
- g_string_append_printf(str,
- "<b>Format:</b> <small>%s Container</small>\n", container);
- }
- if (mux == HB_MUX_MP4)
- {
- gboolean ipod, http, large;
-
- ipod = ghb_settings_get_boolean(settings, "ipod_file");
- http = ghb_settings_get_boolean(settings, "http_optimize_mp4");
- large = ghb_settings_get_boolean(settings, "large_mp4");
- if (http || ipod || large)
- {
- g_string_append_printf(str, "<b>MP4 Options:</b><small>");
- if (ipod)
- g_string_append_printf(str, " - iPod 5G Support");
- if (http)
- g_string_append_printf(str, " - Web Optimized");
- if (large)
- g_string_append_printf(str, " - Large File Size (>4GB)");
- g_string_append_printf(str, "</small>\n");
- }
- }
- g_string_append_printf(str,
- "<b>Destination:</b> <small>%s</small>\n", dest);
-
- width = ghb_settings_get_int(settings, "scale_width");
- height = ghb_settings_get_int(settings, "scale_height");
- anamorphic = ghb_settings_get_boolean(settings, "anamorphic");
- round_dim = ghb_settings_get_boolean(settings, "round_dimensions");
- keep_aspect = ghb_settings_get_boolean(settings, "keep_aspect");
-
- gchar *aspect_desc;
- if (anamorphic)
- {
- if (round_dim)
- {
- aspect_desc = "(Anamorphic)";
- }
- else
- {
- aspect_desc = "(Strict Anamorphic)";
- }
- }
- else
- {
- if (keep_aspect)
- {
- aspect_desc = "(Aspect Preserved)";
- }
- else
- {
- aspect_desc = "(Aspect Lost)";
- }
- }
- vqtype = ghb_settings_get_boolean(settings, "vquality_type_constant");
- vqvalue = 0;
-
- gchar *vq_desc = "Error";
- gchar *vq_units = "";
- if (!vqtype)
- {
- vqtype = ghb_settings_get_boolean(settings, "vquality_type_target");
- if (!vqtype)
- {
- // Has to be bitrate
- vqvalue = ghb_settings_get_int(settings, "video_bitrate");
- vq_desc = "Bitrate:";
- vq_units = "kbps";
- }
- else
- {
- // Target file size
- vqvalue = ghb_settings_get_int(settings, "video_target");
- vq_desc = "Target Size:";
- vq_units = "MB";
- }
- }
- else
- {
- // Constant quality
- vqvalue = ghb_settings_get_int(settings, "video_quality");
- vq_desc = "Constant Quality:";
- }
- fps = ghb_settings_get_string(settings, "framerate");
- if (strcmp("source", fps) == 0)
- {
- g_free(fps);
- if (ghb_settings_get_boolean(settings, "detelecine"))
- fps = g_strdup("Same As Source (vfr detelecine)");
- else
- fps = g_strdup("Same As Source (variable)");
- }
- else
- {
- gchar *tmp;
- tmp = g_strdup_printf("%s (constant frame rate)", fps);
- g_free(fps);
- fps = tmp;
- }
- vcodec = ghb_settings_combo_option(settings, "video_codec");
- vcodec_abbr = ghb_settings_get_string(settings, "video_codec");
- source_width = ghb_settings_get_int(settings, "source_width");
- source_height = ghb_settings_get_int(settings, "source_height");
- g_string_append_printf(str,
- "<b>Picture:</b> Source: <small>%d x %d, Output %d x %d %s</small>\n",
- source_width, source_height, width, height, aspect_desc);
-
- gboolean decomb;
- gboolean filters = FALSE;
-
- decomb = ghb_settings_get_boolean(settings, "decomb");
- g_string_append_printf(str, "<b>Filters:</b><small>");
- if (ghb_settings_get_boolean(settings, "detelecine"))
- {
- g_string_append_printf(str, " - Detelecine");
- filters = TRUE;
- }
- if (decomb)
- {
- g_string_append_printf(str, " - Decomb");
- filters = TRUE;
- }
- else
- {
- gint deint = ghb_settings_combo_int(settings,
- tweaks ? "tweak_deinterlace":"deinterlace");
- if (deint)
- {
- const gchar *opt = ghb_settings_combo_option(settings,
- tweaks ? "tweak_deinterlace":"deinterlace");
- g_string_append_printf(str, " - Deinterlace: %s", opt);
- filters = TRUE;
- }
- }
- gint denoise = ghb_settings_combo_int(settings,
- tweaks ? "tweak_denoise":"denoise");
- if (denoise)
- {
- const gchar *opt = ghb_settings_combo_option(settings,
- tweaks ? "tweak_denoise":"denoise");
- g_string_append_printf(str, " - Denoise: %s", opt);
- filters = TRUE;
- }
- gint deblock = ghb_settings_get_int(settings, "deblock");
- if (deblock >= 5)
- {
- g_string_append_printf(str, " - Deblock (%d)", deblock);
- filters = TRUE;
- }
- if (ghb_settings_get_boolean(settings, "grayscale"))
- {
- g_string_append_printf(str, " - Grayscale");
- filters = TRUE;
- }
- if (!filters)
- g_string_append_printf(str, " None");
- g_string_append_printf(str, "</small>\n");
-
- g_string_append_printf(str,
- "<b>Video:</b> <small>%s, Framerate: %s, %s %d%s</small>\n",
- vcodec, fps, vq_desc, vqvalue, vq_units);
-
- turbo = ghb_settings_get_boolean(settings, "turbo");
- if (turbo)
- {
- g_string_append_printf(str, "<b>Turbo:</b> <small>On</small>\n");
- }
- if (strcmp(vcodec_abbr, "x264") == 0)
- {
- gchar *x264opts = ghb_build_x264opts_string(settings);
- g_string_append_printf(str,
- "<b>x264 Options:</b> <small>%s</small>\n", x264opts);
- g_free(x264opts);
- }
- // Add the audios
- gint count, ii;
- const GValue *audio_list;
-
- audio_list = ghb_settings_get_value(settings, "audio_list");
- count = ghb_array_len(audio_list);
- for (ii = 0; ii < count; ii++)
- {
- gchar *bitrate, *samplerate, *track;
- const gchar *acodec, *mix;
- GValue *asettings;
-
- asettings = ghb_array_get_nth(audio_list, ii);
-
- acodec = ghb_settings_combo_option(asettings, "audio_codec");
- bitrate = ghb_settings_get_string(asettings, "audio_bitrate");
- samplerate = ghb_settings_get_string(asettings, "audio_rate");
- if (strcmp("source", samplerate) == 0)
- {
- g_free(samplerate);
- samplerate = g_strdup("Same As Source");
- }
- track = ghb_settings_get_string(asettings, "audio_track_long");
- mix = ghb_settings_combo_option(asettings, "audio_mix");
- g_string_append_printf(str,
- "<b>Audio:</b><small> %s, Encoder: %s, Mixdown: %s, SampleRate: %s, Bitrate: %s</small>",
- track, acodec, mix, samplerate, bitrate);
- if (ii < count-1)
- g_string_append_printf(str, "\n");
- g_free(track);
- g_free(bitrate);
- g_free(samplerate);
- }
- info = g_string_free(str, FALSE);
- gtk_tree_store_append(store, &citer, &iter);
- gtk_tree_store_set(store, &citer, 1, info, -1);
- g_free(info);
- g_free(fps);
- g_free(vcodec_abbr);
- g_free(vol_name);
- g_free(dest);
- g_free(preset);
-}
-
-gboolean
-ghb_message_dialog(GtkMessageType type, const gchar *message, const gchar *no, const gchar *yes)
-{
- GtkWidget *dialog;
- GtkResponseType response;
-
- // Toss up a warning dialog
- dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
- type, GTK_BUTTONS_NONE,
- message);
- gtk_dialog_add_buttons( GTK_DIALOG(dialog),
- no, GTK_RESPONSE_NO,
- yes, GTK_RESPONSE_YES, NULL);
- response = gtk_dialog_run(GTK_DIALOG(dialog));
- gtk_widget_destroy (dialog);
- if (response == GTK_RESPONSE_NO)
- {
- return FALSE;
- }
- return TRUE;
-}
-
-static gint64
-estimate_file_size(signal_user_data_t *ud)
-{
- ghb_title_info_t tinfo;
- gint duration;
- gint bitrate;
- gint64 size;
- gint titleindex;
-
- titleindex = ghb_settings_combo_int(ud->settings, "title");
- if (titleindex < 0) return 0;
-
- if (!ghb_get_title_info(&tinfo, titleindex)) return 0;
- duration = ((tinfo.hours*60)+tinfo.minutes)*60+tinfo.seconds;
- bitrate = ghb_guess_bitrate(ud->settings);
- size = (gint64)duration * (gint64)bitrate/8;
- return size;
-}
-
-#define DISK_FREE_THRESH (1024L*1024L*1024L*3)
-
-static gboolean
-validate_settings(signal_user_data_t *ud)
-{
- // Check to see if the dest file exists or is
- // already in the queue
- gchar *message, *dest;
- gint count, ii;
- gint titleindex;
-
- titleindex = ghb_settings_combo_int(ud->settings, "title");
- if (titleindex < 0) return FALSE;
- dest = ghb_settings_get_string(ud->settings, "destination");
- count = ghb_array_len(ud->queue);
- for (ii = 0; ii < count; ii++)
- {
- GValue *js;
- gchar *filename;
-
- js = ghb_array_get_nth(ud->queue, ii);
- filename = ghb_settings_get_string(js, "destination");
- if (strcmp(dest, filename) == 0)
- {
- message = g_strdup_printf(
- "Destination: %s\n\n"
- "Another queued job has specified the same destination.\n"
- "Do you want to overwrite?",
- dest);
- if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Overwrite"))
- {
- g_free(filename);
- g_free(dest);
- g_free(message);
- return FALSE;
- }
- g_free(message);
- break;
- }
- g_free(filename);
- }
- gchar *destdir = g_path_get_dirname(dest);
- if (!g_file_test(destdir, G_FILE_TEST_IS_DIR))
- {
- message = g_strdup_printf(
- "Destination: %s\n\n"
- "This is not a valid directory.",
- destdir);
- ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
- g_free(dest);
- g_free(message);
- g_free(destdir);
- return FALSE;
- }
- if (g_access(destdir, R_OK|W_OK) != 0)
- {
- message = g_strdup_printf(
- "Destination: %s\n\n"
- "Can not read or write the directory.",
- destdir);
- ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
- g_free(dest);
- g_free(message);
- g_free(destdir);
- return FALSE;
- }
- GFile *gfile;
- GFileInfo *info;
- guint64 size;
- gchar *resolved = ghb_resolve_symlink(destdir);
-
- gfile = g_file_new_for_path(resolved);
- info = g_file_query_filesystem_info(gfile,
- G_FILE_ATTRIBUTE_FILESYSTEM_FREE, NULL, NULL);
- if (info != NULL)
- {
- if (g_file_info_has_attribute(info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE))
- {
- size = g_file_info_get_attribute_uint64(info,
- G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
-
- gint64 fsize = estimate_file_size(ud);
- if (size < fsize)
- {
- message = g_strdup_printf(
- "Destination filesystem is almost full: %uM free\n\n"
- "Encode may be incomplete if you proceed.\n",
- (guint)(size / (1024L*1024L)));
- if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Proceed"))
- {
- g_free(dest);
- g_free(message);
- return FALSE;
- }
- g_free(message);
- }
- }
- g_object_unref(info);
- }
- g_object_unref(gfile);
- g_free(resolved);
- g_free(destdir);
- if (g_file_test(dest, G_FILE_TEST_EXISTS))
- {
- message = g_strdup_printf(
- "Destination: %s\n\n"
- "File already exhists.\n"
- "Do you want to overwrite?",
- dest);
- if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Overwrite"))
- {
- g_free(dest);
- g_free(message);
- return FALSE;
- }
- g_free(message);
- g_unlink(dest);
- }
- g_free(dest);
- // Validate video quality is in a reasonable range
- if (!ghb_validate_vquality(ud->settings))
- {
- return FALSE;
- }
- // Validate audio settings
- if (!ghb_validate_audio(ud))
- {
- return FALSE;
- }
- // Validate video settings
- if (!ghb_validate_video(ud))
- {
- return FALSE;
- }
- // Validate container settings
- if (!ghb_validate_container(ud))
- {
- return FALSE;
- }
- // Validate filter settings
- if (!ghb_validate_filters(ud))
- {
- return FALSE;
- }
- audio_list_refresh(ud);
- return TRUE;