- 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(message);
- return FALSE;
- }
- g_free(message);
- g_unlink(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;
-}
-
-static gboolean
-queue_add(signal_user_data_t *ud)
-{
- // Add settings to the queue
- job_settings_t *queue_item;
- GSList *link;
- static gint unique_id = 0;
-
- g_debug("queue_add ()\n");
- if (!validate_settings(ud))
- {
- return FALSE;
- }
- // Make a copy of current settings to be used for the new job
- queue_item = g_malloc(sizeof(job_settings_t));
- queue_item->settings = ghb_settings_dup(ud->settings);
- queue_item->audio_settings = NULL;
- link = ud->audio_settings;
- while (link != NULL)
- {
- GHashTable *asettings;
- asettings = ghb_settings_dup((GHashTable*)link->data);
- queue_item->audio_settings =
- g_slist_append(queue_item->audio_settings, asettings);
- link = g_slist_next(link);
- }
- queue_item->chapter_list = g_strdupv(ud->chapter_list);
- ud->queue = g_slist_append(ud->queue, queue_item);
- add_to_queue_list(ud, queue_item);
- ghb_add_job (queue_item, unique_id);
- queue_item->unique_id = unique_id;
- queue_item->status = GHB_QUEUE_PENDING;
- unique_id++;
- return TRUE;
-}
-
-void
-queue_add_clicked_cb(GtkWidget *widget, signal_user_data_t *ud)
-{
- g_debug("queue_add_clicked_cb ()\n");
- queue_add(ud);
-}
-
-static gboolean
-cancel_encode(const gchar *extra_msg)
-{
- GtkWidget *dialog;
- GtkResponseType response;
-
- if (extra_msg == NULL) extra_msg = "";
- // Toss up a warning dialog
- dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
- GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE,
- "%sYour movie will be lost if you don't continue encoding.",
- extra_msg);
- gtk_dialog_add_buttons( GTK_DIALOG(dialog),
- "Continue Encoding", GTK_RESPONSE_NO,
- "Stop Encoding", GTK_RESPONSE_YES, NULL);
- response = gtk_dialog_run(GTK_DIALOG(dialog));
- gtk_widget_destroy (dialog);
- if (response == GTK_RESPONSE_NO) return FALSE;
- ghb_stop_queue();
- return TRUE;
-}
-
-void
-queue_remove_clicked_cb(GtkWidget *widget, gchar *path, signal_user_data_t *ud)
-{
- GtkTreeView *treeview;
- GtkTreePath *treepath;
- GtkTreeModel *store;
- GtkTreeIter iter;
- gint row;
- GSList *link;
- gint *indices;
- job_settings_t *queue_item;
- gint unique_id;
-
- g_debug("queue_remove_clicked_cb ()\n");
- g_debug("ud %p\n", ud);
- g_debug("ud->builder %p\n", ud->builder);
-
- treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
- store = gtk_tree_view_get_model(treeview);
- treepath = gtk_tree_path_new_from_string (path);
- if (gtk_tree_model_get_iter(store, &iter, treepath))
- {
- // Find the entry in the queue
- indices = gtk_tree_path_get_indices (treepath);
- row = indices[0];
- // Can only free the treepath After getting what I need from
- // indices since this points into treepath somewhere.
- gtk_tree_path_free (treepath);
- if (row < 0) return;
- link = g_slist_nth(ud->queue, row);
- if (link == NULL) return;
- queue_item = (job_settings_t*)link->data;
- if (queue_item->status == GHB_QUEUE_RUNNING)
- {
- // Ask if wants to stop encode.
- if (!cancel_encode(NULL))
- {
- return;
- }
- }
- // Remove the selected item
- g_debug(" should be removing from treestore\n");
- gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
- // Remove the corresponding item from the queue list
- ud->queue = g_slist_remove_link(ud->queue, link);
- g_slist_free_1(link);
- g_hash_table_destroy(queue_item->settings);
- link = queue_item->audio_settings;
- while (link != NULL)
- {
- GSList *nextlink;
- g_hash_table_destroy((GHashTable*)link->data);
- nextlink = g_slist_next(link);
- g_slist_free_1(link);
- link = nextlink;
- }
- g_strfreev (queue_item->chapter_list);
- unique_id = queue_item->unique_id;
- g_free(queue_item);
- ghb_remove_job(unique_id);
- }
- else
- {
- gtk_tree_path_free (treepath);
- }
-}
-
-static gint
-find_queue_item(GSList *queue, gint unique_id, job_settings_t **job)
-{
- job_settings_t *js;
- gint index = -1;
-
- while (queue != NULL)
- {
- index++;
- js = (job_settings_t*)queue->data;
- if (js->unique_id == unique_id)
- {
- *job = js;
- return index;
- }
- queue = queue->next;
- }
- *job = NULL;
- return index;
-}
-
-static void
-queue_buttons_grey(signal_user_data_t *ud, gboolean working)
-{
- GtkWidget *widget;
- GtkAction *action;
- gint titleindex = ghb_settings_get_int(ud->settings, "title");
- gboolean title_ok = (titleindex >= 0);
- widget = GHB_WIDGET (ud->builder, "queue_start1");
- gtk_widget_set_sensitive (widget, !working && title_ok);
- widget = GHB_WIDGET (ud->builder, "queue_start2");
- gtk_widget_set_sensitive (widget, !working && title_ok);
- action = GHB_ACTION (ud->builder, "queue_start_menu");
- gtk_action_set_sensitive (action, !working && title_ok);
- widget = GHB_WIDGET (ud->builder, "queue_pause1");
- gtk_widget_set_sensitive (widget, working);
- widget = GHB_WIDGET (ud->builder, "queue_pause2");
- gtk_widget_set_sensitive (widget, working);
- action = GHB_ACTION (ud->builder, "queue_pause_menu");
- gtk_action_set_sensitive (action, working);
- widget = GHB_WIDGET (ud->builder, "queue_stop");
- gtk_widget_set_sensitive (widget, working);
- action = GHB_ACTION (ud->builder, "queue_stop_menu");
- gtk_action_set_sensitive (action, working);
-}
-
-void queue_start_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud);
-
-static void
-ghb_backend_events(signal_user_data_t *ud)
-{
- ghb_status_t status;
- gchar *status_str;
- GtkProgressBar *progress;
- gint titleindex;
- job_settings_t *js;
- static gint current_id = -1;
- gint index;
- GtkTreeView *treeview;
- GtkTreeStore *store;
- GtkTreeIter iter;
- static gint working = 0;
- static gboolean work_started = FALSE;
-
- ghb_track_status();
- ghb_get_status(&status);
- progress = GTK_PROGRESS_BAR(GHB_WIDGET (ud->builder, "progressbar"));
- if (status.state & GHB_STATE_SCANNING)
- {
- status_str = g_strdup_printf ("Scanning title %d of %d...",
- status.title_cur, status.title_count );
- gtk_progress_bar_set_text (progress, status_str);
- g_free(status_str);
- if (status.title_count > 0)
- {
- gtk_progress_bar_set_fraction (progress,
- (gdouble)status.title_cur / status.title_count);
- }
- }
- else if (status.state & GHB_STATE_SCANDONE)
- {
- status_str = g_strdup_printf ("Scan done");
- gtk_progress_bar_set_text (progress, status_str);
- g_free(status_str);
- gtk_progress_bar_set_fraction (progress, 1.0);
-
- ghb_title_info_t tinfo;
-
- ghb_update_ui_combo_box(ud->builder, "title", 0, FALSE);
- titleindex = ghb_longest_title();
- ghb_ui_update_int(ud, "title", titleindex);
-
- // Are there really any titles.
- if (!ghb_get_title_info(&tinfo, titleindex))
- {
- GtkProgressBar *progress;
- progress = GTK_PROGRESS_BAR(GHB_WIDGET (ud->builder, "progressbar"));
- gtk_progress_bar_set_fraction (progress, 0);
- gtk_progress_bar_set_text (progress, "No Source");
- }
- ghb_clear_state(GHB_STATE_SCANDONE);
- queue_buttons_grey(ud, (0 != (status.state & GHB_STATE_WORKING)));
- }
- else if (status.state & GHB_STATE_WORKING)
- {
- if(status.seconds > -1)
- {
- status_str= g_strdup_printf(
- "Encoding: task %d of %d, %.2f %%"
- " (%.2f fps, avg %.2f fps, ETA %02dh%02dm%02ds)",
- status.job_cur, status.job_count,
- 100.0 * status.progress,
- status.rate_cur, status.rate_avg, status.hours,
- status.minutes, status.seconds );
- }
- else
- {
- status_str= g_strdup_printf(
- "Encoding: task %d of %d, %.2f %%",
- status.job_cur, status.job_count,
- 100.0 * status.progress );
- }
- gtk_progress_bar_set_text (progress, status_str);
- gtk_progress_bar_set_fraction (progress, status.progress);
- g_free(status_str);
- }
- else if (status.state & GHB_STATE_WORKDONE)
- {
- work_started = FALSE;
- queue_buttons_grey(ud, FALSE);
- index = find_queue_item(ud->queue, current_id, &js);
- treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
- store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
- switch( status.error )