g_debug("on_quit1_activate ()");
if (state & GHB_STATE_WORKING)
{
- if (ghb_cancel_encode("Closing HandBrake will terminate encoding.\n"))
+ if (ghb_cancel_encode2(ud, "Closing HandBrake will terminate encoding.\n"))
{
ghb_hb_cleanup(FALSE);
prune_logs(ud);
gchar *result = NULL;
gchar vname[51], fsname[51];
- if (GetVolumeInformation(drive, vname, 50, NULL, NULL, NULL, fsname, 51))
+ if (GetVolumeInformation(drive, vname, 50, NULL, NULL, NULL, fsname, 50))
{
result = g_strdup_printf("%s", vname);
}
static gchar*
get_file_label(const gchar *filename)
{
- static gchar *containers[] =
- {".vob", ".mpg", ".m2ts", ".mkv", ".mp4", ".m4v", ".avi", ".ogm", NULL};
- gchar *base;
- gint ii;
+ gchar *base, *pos, *end;
base = g_path_get_basename(filename);
- for (ii = 0; containers[ii] != NULL; ii++)
+ pos = strrchr(base, '.');
+ if (pos != NULL)
{
- if (g_str_has_suffix(base, containers[ii]))
- {
- gchar *pos;
- pos = strrchr(base, '.');
+ // 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;
- break;
- }
}
return base;
}
gchar *start;
gchar *filename = g_strdup(source);
+ g_debug("update_source_label()");
len = strlen(filename);
- if (filename[len-1] == G_DIR_SEPARATOR) filename[len-1] = 0;
if (g_file_test(filename, G_FILE_TEST_IS_DIR))
{
// Skip dos drive letters
}
else
{
+ if (filename[len-1] == G_DIR_SEPARATOR) filename[len-1] = 0;
if (start != NULL)
start++;
else
gtk_label_set_text( label, "Scanning ..." );
}
+static void
+start_scan(
+ signal_user_data_t *ud,
+ const gchar *path,
+ gint titlenum,
+ gint preview_count)
+{
+ GtkWidget *widget;
+ GtkAction *action;
+ ghb_status_t status;
+
+ ghb_get_status(&status);
+ if (status.scan.state != GHB_STATE_IDLE)
+ return;
+
+ widget = GHB_WIDGET(ud->builder, "sourcetoolbutton");
+ gtk_widget_set_sensitive(widget, FALSE);
+ action = GHB_ACTION(ud->builder, "source_action");
+ gtk_action_set_sensitive(action, FALSE);
+ action = GHB_ACTION(ud->builder, "source_single_action");
+ gtk_action_set_sensitive(action, FALSE);
+ ghb_backend_scan(path, titlenum, preview_count);
+}
+
void
ghb_do_scan(
signal_user_data_t *ud,
gint titlenum,
gboolean force)
{
+ g_debug("ghb_do_scan()");
if (!force && last_scan_file != NULL &&
strcmp(last_scan_file, filename) == 0)
{
prune_logs(ud);
preview_count = ghb_settings_get_int(ud->settings, "preview_count");
- ghb_backend_scan(path, titlenum, preview_count);
+ start_scan(ud, path, titlenum, preview_count);
g_free(path);
}
else
g_debug("window_delete_event_cb ()");
if (state & GHB_STATE_WORKING)
{
- if (ghb_cancel_encode("Closing HandBrake will terminate encoding.\n"))
+ if (ghb_cancel_encode2(ud, "Closing HandBrake will terminate encoding.\n"))
{
ghb_hb_cleanup(FALSE);
prune_logs(ud);
gtk_widget_destroy (dialog);
}
+void
+ghb_cancel_encode(signal_user_data_t *ud, 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),
+ "Cancel Current and Stop", 1,
+ "Cancel Current, Start Next", 2,
+ "Finish Current, then Stop", 3,
+ "Continue Encoding", 4,
+ NULL);
+ response = gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy (dialog);
+ switch (response)
+ {
+ case 1:
+ ghb_stop_queue();
+ ud->cancel_encode = GHB_CANCEL_ALL;
+ break;
+ case 2:
+ ghb_stop_queue();
+ ud->cancel_encode = GHB_CANCEL_CURRENT;
+ break;
+ case 3:
+ ud->cancel_encode = GHB_CANCEL_FINISH;
+ break;
+ case 4:
+ default:
+ ud->cancel_encode = GHB_CANCEL_NONE;
+ break;
+ }
+}
+
gboolean
-ghb_cancel_encode(const gchar *extra_msg)
+ghb_cancel_encode2(signal_user_data_t *ud, const gchar *extra_msg)
{
GtkWidget *dialog;
GtkResponseType response;
"%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);
+ "Cancel Current and Stop", 1,
+ "Continue Encoding", 4,
+ NULL);
response = gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy (dialog);
- if (response == GTK_RESPONSE_NO) return FALSE;
- ghb_stop_queue();
- return TRUE;
+ switch (response)
+ {
+ case 1:
+ ghb_stop_queue();
+ ud->cancel_encode = GHB_CANCEL_ALL;
+ return TRUE;
+ case 4:
+ default:
+ break;
+ }
+ return FALSE;
}
static void
label = GTK_LABEL(GHB_WIDGET(ud->builder, "pending_status"));
pending = queue_pending_count(ud->queue);
- str = g_strdup_printf("%d encode(s) pending in the queue", pending);
+ str = g_strdup_printf("%d encode(s) pending", pending);
gtk_label_set_text(label, str);
g_free(str);
}
*job = NULL;
g_debug("find_queue_job");
+ if (unique_id == 0) // Invalid Id
+ return -1;
+
count = ghb_array_len(queue);
for (ii = 0; ii < count; ii++)
{
GtkProgressBar *scan_prog;
GtkLabel *label;
+ GtkWidget *widget;
+ GtkAction *action;
+
+ widget = GHB_WIDGET(ud->builder, "sourcetoolbutton");
+ gtk_widget_set_sensitive(widget, TRUE);
+ action = GHB_ACTION(ud->builder, "source_action");
+ gtk_action_set_sensitive(action, TRUE);
+ action = GHB_ACTION(ud->builder, "source_single_action");
+ gtk_action_set_sensitive(action, TRUE);
+
source = ghb_settings_get_string(ud->settings, "source");
update_source_label(ud, source, FALSE);
index = find_queue_job(ud->queue, status.queue.unique_id, &js);
treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
- if (ud->cancel_encode)
+ if (ud->cancel_encode == GHB_CANCEL_ALL ||
+ ud->cancel_encode == GHB_CANCEL_CURRENT)
status.queue.error = GHB_ERROR_CANCELED;
switch( status.queue.error )
{
if (ud->job_activity_log)
g_io_channel_unref(ud->job_activity_log);
ud->job_activity_log = NULL;
- if (!ud->cancel_encode)
+ if (ud->cancel_encode != GHB_CANCEL_ALL &&
+ ud->cancel_encode != GHB_CANCEL_FINISH)
{
ud->current_job = ghb_start_next_job(ud, FALSE);
}
if (js)
ghb_settings_set_int(js, "job_status", qstatus);
ghb_save_queue(ud->queue);
- ud->cancel_encode = FALSE;
+ ud->cancel_encode = GHB_CANCEL_NONE;
#if !GTK_CHECK_VERSION(2, 16, 0)
GtkStatusIcon *si;
ghb_log_cb(GIOChannel *source, GIOCondition cond, gpointer data)
{
gchar *text = NULL;
- gsize length;
+ gsize length, outlength;
GtkTextView *textview;
GtkTextBuffer *buffer;
GtkTextIter iter;
signal_user_data_t *ud = (signal_user_data_t*)data;
status = g_io_channel_read_line (source, &text, &length, NULL, &gerror);
- if (text != NULL && length > 0 && text[length-1] != 0)
+ // Trim nils from end of text, they cause g_io_channel_write_chars to
+ // fail with an assertion that aborts
+ while (length > 0 && text[length-1] == 0)
+ length--;
+ if (text != NULL && length > 0)
{
GdkWindow *window;
gint width, height;
text[length-1] = '\r';
#endif
g_io_channel_write_chars (ud->activity_log, text,
- length, &length, NULL);
+ length, &outlength, NULL);
#if defined(_WIN32)
g_io_channel_write_chars (ud->activity_log, "\n",
one, &one, NULL);
if (ud->job_activity_log)
{
g_io_channel_write_chars (ud->job_activity_log, text,
- length, &length, NULL);
+ length, &outlength, NULL);
#if defined(_WIN32)
g_io_channel_write_chars (ud->activity_log, "\n",
- one, &one, NULL);
+ one, &outlength, NULL);
#endif
g_io_channel_flush(ud->job_activity_log, NULL);
}
- g_free(text);
}
+ if (text != NULL)
+ g_free(text);
+
if (status != G_IO_STATUS_NORMAL)
{
// This should never happen, but if it does I would get into an
if (ins_count == 2)
{
g_thread_create((GThreadFunc)ghb_cache_volnames, ud, FALSE, NULL);
- if (ud->current_dvd_device != NULL &&
+ if (ghb_settings_get_boolean(ud->settings, "AutoScan") &&
+ ud->current_dvd_device != NULL &&
strcmp(device, ud->current_dvd_device) == 0)
{
show_scan_progress(ud);
update_source_label(ud, device, TRUE);
gint preview_count;
preview_count = ghb_settings_get_int(ud->settings, "preview_count");
- ghb_backend_scan(device, 0, preview_count);
+ start_scan(ud, device, 0, preview_count);
}
}
}
{
ghb_hb_cleanup(TRUE);
prune_logs(ud);
- ghb_backend_scan("/dev/null", 0, 1);
+ ghb_settings_set_string(ud->settings, "source", "/dev/null");
+ start_scan(ud, "/dev/null", 0, 1);
}
}
}
}
if (g_drive_has_media(gd))
{
- show_scan_progress(ud);
- update_source_label(ud, device, TRUE);
- gint preview_count;
- preview_count = ghb_settings_get_int(ud->settings, "preview_count");
- ghb_backend_scan(device, 0, preview_count);
+ if (ghb_settings_get_boolean(ud->settings, "AutoScan"))
+ {
+ show_scan_progress(ud);
+ update_source_label(ud, device, TRUE);
+ gint preview_count;
+ preview_count = ghb_settings_get_int(ud->settings, "preview_count");
+ start_scan(ud, device, 0, preview_count);
+ }
}
else
{
ghb_hb_cleanup(TRUE);
prune_logs(ud);
- ghb_backend_scan("/dev/null", 0, 1);
+ ghb_settings_set_string(ud->settings, "source", "/dev/null");
+ start_scan(ud, "/dev/null", 0, 1);
}
}
#endif