1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) John Stebbins 2008 <stebbins@stebbins>
6 * callbacks.c is free software.
8 * You may redistribute it and/or modify it under the terms of the
9 * GNU General Public License, as published by the Free Software
10 * Foundation; either version 2 of the License, or (at your option)
15 #include <gdk/gdkkeysyms.h>
16 #include <glib/gstdio.h>
20 #include "hb-backend.h"
22 #include "callbacks.h"
27 queue_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud)
30 GtkTreeIter iter, piter;
32 g_debug("queue_list_selection_changed_cb ()");
33 // A queue entry is made up of a parent and multiple
34 // children that are visible when expanded. When and entry
35 // is selected, I want the parent to be selected.
36 // This is purely cosmetic.
37 if (gtk_tree_selection_get_selected(selection, &store, &iter))
39 GtkWidget *widget = GHB_WIDGET (ud->builder, "queue_edit");
40 gtk_widget_set_sensitive (widget, TRUE);
41 if (gtk_tree_model_iter_parent (store, &piter, &iter))
44 GtkTreeView *treeview;
46 gtk_tree_selection_select_iter (selection, &piter);
47 path = gtk_tree_model_get_path (store, &piter);
48 treeview = gtk_tree_selection_get_tree_view (selection);
49 // Make the parent visible in scroll window if it is not.
50 gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0, 0);
51 gtk_tree_path_free(path);
56 GtkWidget *widget = GHB_WIDGET (ud->builder, "queue_edit");
57 gtk_widget_set_sensitive (widget, FALSE);
62 add_to_queue_list(signal_user_data_t *ud, GValue *settings, GtkTreeIter *piter)
64 GtkTreeView *treeview;
70 gchar *dest, *preset, *vol_name, *basename;
71 const gchar *vcodec, *container;
72 gchar *fps, *vcodec_abbr;
73 gint title, start_chapter, end_chapter, width, height;
74 gint source_width, source_height;
75 gboolean pass2, anamorphic, round_dim, keep_aspect, vqtype, turbo;
79 g_debug("update_queue_list ()");
80 if (settings == NULL) return;
81 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
82 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
84 tweaks = ghb_settings_get_boolean(settings, "allow_tweaks");
85 title = ghb_settings_get_int(settings, "titlenum");
86 start_chapter = ghb_settings_get_int(settings, "start_chapter");
87 end_chapter = ghb_settings_get_int(settings, "end_chapter");
88 pass2 = ghb_settings_get_boolean(settings, "VideoTwoPass");
89 vol_name = ghb_settings_get_string(settings, "volume_label");
90 dest = ghb_settings_get_string(settings, "destination");
91 basename = g_path_get_basename(dest);
92 escape = g_markup_escape_text(basename, -1);
93 info = g_strdup_printf
95 "<big><b>%s</b></big> "
96 "<small>(Title %d, Chapters %d through %d, %d Video %s)"
98 vol_name, title, start_chapter, end_chapter,
99 pass2 ? 2:1, pass2 ? "Passes":"Pass", escape
107 gtk_tree_store_append(store, &iter, NULL);
109 gtk_tree_store_set(store, &iter, 1, info, 2, "hb-queue-delete", -1);
111 status = ghb_settings_get_int(settings, "job_status");
114 case GHB_QUEUE_PENDING:
115 gtk_tree_store_set(store, &iter, 0, "hb-queue-job", -1);
117 case GHB_QUEUE_CANCELED:
118 gtk_tree_store_set(store, &iter, 0, "hb-canceled", -1);
120 case GHB_QUEUE_RUNNING:
121 gtk_tree_store_set(store, &iter, 0, "hb-working0", -1);
124 gtk_tree_store_set(store, &iter, 0, "hb-complete", -1);
127 gtk_tree_store_set(store, &iter, 0, "hb-queue-job", -1);
131 GString *str = g_string_new("");
133 gboolean preset_modified;
137 container = ghb_settings_combo_option(settings, "FileFormat");
138 mux = ghb_settings_combo_int(settings, "FileFormat");
139 preset_modified = ghb_settings_get_boolean(settings, "preset_modified");
140 path = ghb_settings_get_value(settings, "preset");
141 preset = ghb_preset_path_string(path);
142 markers = ghb_settings_get_boolean(settings, "ChapterMarkers");
145 g_string_append_printf(str,
146 "<b>Modified Preset Based On:</b> <small>%s</small>\n",
149 g_string_append_printf(str,
150 "<b>Preset:</b> <small>%s</small>\n",
155 g_string_append_printf(str,
156 "<b>Format:</b> <small>%s Container, Chapter Markers</small>\n",
161 g_string_append_printf(str,
162 "<b>Format:</b> <small>%s Container</small>\n", container);
164 if (mux == HB_MUX_MP4)
166 gboolean ipod, http, large;
168 ipod = ghb_settings_get_boolean(settings, "Mp4iPodCompatible");
169 http = ghb_settings_get_boolean(settings, "Mp4HttpOptimize");
170 large = ghb_settings_get_boolean(settings, "Mp4LargeFile");
171 if (http || ipod || large)
173 g_string_append_printf(str, "<b>MP4 Options:</b><small>");
175 g_string_append_printf(str, " - iPod 5G Support");
177 g_string_append_printf(str, " - Web Optimized");
179 g_string_append_printf(str, " - Large File Size (>4GB)");
180 g_string_append_printf(str, "</small>\n");
183 escape = g_markup_escape_text(dest, -1);
184 g_string_append_printf(str,
185 "<b>Destination:</b> <small>%s</small>\n", escape);
187 width = ghb_settings_get_int(settings, "scale_width");
188 height = ghb_settings_get_int(settings, "scale_height");
189 anamorphic = ghb_settings_get_boolean(settings, "anamorphic");
190 round_dim = ghb_settings_get_boolean(settings, "ModDimensions");
191 keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");
198 aspect_desc = "(Anamorphic)";
202 aspect_desc = "(Strict Anamorphic)";
209 aspect_desc = "(Aspect Preserved)";
213 aspect_desc = "(Aspect Lost)";
216 vqtype = ghb_settings_get_boolean(settings, "vquality_type_constant");
218 gchar *vq_desc = "Error";
219 gchar *vq_units = "";
224 vqtype = ghb_settings_get_boolean(settings, "vquality_type_target");
228 vqvalue = ghb_settings_get_int(settings, "VideoAvgBitrate");
229 vq_desc = "Bitrate:";
235 vqvalue = ghb_settings_get_int(settings, "VideoTargetSize");
236 vq_desc = "Target Size:";
239 vqstr = g_strdup_printf("%d", (gint)vqvalue);
244 vqvalue = ghb_settings_get_double(settings, "VideoQualitySlider");
245 vq_desc = "Constant Quality:";
246 if (ghb_settings_get_boolean(settings, "directqp"))
248 vqstr = g_strdup_printf("%d", (gint)vqvalue);
253 vqstr = g_strdup_printf("%.1f", 100*vqvalue);
257 fps = ghb_settings_get_string(settings, "VideoFramerate");
258 if (strcmp("source", fps) == 0)
261 if (ghb_settings_get_boolean(settings, "PictureDetelecine"))
262 fps = g_strdup("Same As Source (vfr detelecine)");
264 fps = g_strdup("Same As Source (variable)");
269 tmp = g_strdup_printf("%s (constant frame rate)", fps);
273 vcodec = ghb_settings_combo_option(settings, "VideoEncoder");
274 vcodec_abbr = ghb_settings_get_string(settings, "VideoEncoder");
275 source_width = ghb_settings_get_int(settings, "source_width");
276 source_height = ghb_settings_get_int(settings, "source_height");
277 g_string_append_printf(str,
278 "<b>Picture:</b> Source: <small>%d x %d, Output %d x %d %s</small>\n",
279 source_width, source_height, width, height, aspect_desc);
282 gboolean filters = FALSE;
284 decomb = ghb_settings_get_boolean(settings, "PictureDecomb");
285 g_string_append_printf(str, "<b>Filters:</b><small>");
286 if (ghb_settings_get_boolean(settings, "PictureDetelecine"))
288 g_string_append_printf(str, " - Detelecine");
293 g_string_append_printf(str, " - Decomb");
298 gint deint = ghb_settings_combo_int(settings,
299 tweaks ? "tweak_PictureDeinterlace":"PictureDeinterlace");
302 const gchar *opt = ghb_settings_combo_option(settings,
303 tweaks ? "tweak_PictureDeinterlace":"PictureDeinterlace");
304 g_string_append_printf(str, " - Deinterlace: %s", opt);
308 gint denoise = ghb_settings_combo_int(settings,
309 tweaks ? "tweak_PictureDenoise":"PictureDenoise");
312 const gchar *opt = ghb_settings_combo_option(settings,
313 tweaks ? "tweak_PictureDenoise":"PictureDenoise");
314 g_string_append_printf(str, " - Denoise: %s", opt);
317 gint deblock = ghb_settings_get_int(settings, "PictureDeblock");
320 g_string_append_printf(str, " - Deblock (%d)", deblock);
323 if (ghb_settings_get_boolean(settings, "VideoGrayScale"))
325 g_string_append_printf(str, " - Grayscale");
329 g_string_append_printf(str, " None");
330 g_string_append_printf(str, "</small>\n");
332 g_string_append_printf(str,
333 "<b>Video:</b> <small>%s, Framerate: %s, %s %s%s</small>\n",
334 vcodec, fps, vq_desc, vqstr, vq_units);
336 turbo = ghb_settings_get_boolean(settings, "VideoTurboTwoPass");
339 g_string_append_printf(str, "<b>Turbo:</b> <small>On</small>\n");
341 if (strcmp(vcodec_abbr, "x264") == 0)
343 gchar *x264opts = ghb_build_x264opts_string(settings);
344 g_string_append_printf(str,
345 "<b>x264 Options:</b> <small>%s</small>\n", x264opts);
350 const GValue *audio_list;
352 audio_list = ghb_settings_get_value(settings, "audio_list");
353 count = ghb_array_len(audio_list);
354 for (ii = 0; ii < count; ii++)
356 gchar *bitrate, *samplerate, *track;
357 const gchar *acodec, *mix;
360 asettings = ghb_array_get_nth(audio_list, ii);
362 acodec = ghb_settings_combo_option(asettings, "AudioEncoder");
363 bitrate = ghb_settings_get_string(asettings, "AudioBitrate");
364 samplerate = ghb_settings_get_string(asettings, "AudioSamplerate");
365 if (strcmp("source", samplerate) == 0)
368 samplerate = g_strdup("Same As Source");
370 track = ghb_settings_get_string(asettings, "AudioTrackDescription");
371 mix = ghb_settings_combo_option(asettings, "AudioMixdown");
372 g_string_append_printf(str,
373 "<b>Audio:</b><small> %s, Encoder: %s, Mixdown: %s, SampleRate: %s, Bitrate: %s</small>",
374 track, acodec, mix, samplerate, bitrate);
376 g_string_append_printf(str, "\n");
381 info = g_string_free(str, FALSE);
382 gtk_tree_store_append(store, &citer, &iter);
383 gtk_tree_store_set(store, &citer, 1, info, -1);
393 audio_list_refresh(signal_user_data_t *ud)
395 GtkTreeView *treeview;
400 const GValue *audio_list;
402 g_debug("ghb_audio_list_refresh ()");
403 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_list"));
404 store = GTK_LIST_STORE(gtk_tree_view_get_model(treeview));
405 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter))
409 const gchar *track, *codec, *br, *sr, *mix;
410 gchar *drc, *s_track, *s_codec, *s_br, *s_sr, *s_mix;
414 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
415 if (row >= ghb_array_len(audio_list))
417 asettings = ghb_array_get_nth(audio_list, row);
419 track = ghb_settings_combo_option(asettings, "AudioTrack");
420 codec = ghb_settings_combo_option(asettings, "AudioEncoder");
421 br = ghb_settings_combo_option(asettings, "AudioBitrate");
422 sr = ghb_settings_combo_option(asettings, "AudioSamplerate");
423 mix = ghb_settings_combo_option(asettings, "AudioMixdown");
424 drc = ghb_settings_get_string(asettings, "AudioTrackDRCSlider");
426 s_track = ghb_settings_get_string(asettings, "AudioTrack");
427 s_codec = ghb_settings_get_string(asettings, "AudioEncoder");
428 s_br = ghb_settings_get_string(asettings, "AudioBitrate");
429 s_sr = ghb_settings_get_string(asettings, "AudioSamplerate");
430 s_mix = ghb_settings_get_string(asettings, "AudioMixdown");
431 s_drc = ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
433 gtk_list_store_set(GTK_LIST_STORE(store), &iter,
434 // These are displayed in list
440 // These are used to set combo values when an item is selected
455 done = !gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
462 validate_settings(signal_user_data_t *ud)
464 // Check to see if the dest file exists or is
465 // already in the queue
466 gchar *message, *dest;
470 titleindex = ghb_settings_combo_int(ud->settings, "title");
471 if (titleindex < 0) return FALSE;
472 dest = ghb_settings_get_string(ud->settings, "destination");
473 count = ghb_array_len(ud->queue);
474 for (ii = 0; ii < count; ii++)
479 js = ghb_array_get_nth(ud->queue, ii);
480 filename = ghb_settings_get_string(js, "destination");
481 if (strcmp(dest, filename) == 0)
483 message = g_strdup_printf(
484 "Destination: %s\n\n"
485 "Another queued job has specified the same destination.\n"
486 "Do you want to overwrite?",
488 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Overwrite"))
500 gchar *destdir = g_path_get_dirname(dest);
501 if (!g_file_test(destdir, G_FILE_TEST_IS_DIR))
503 message = g_strdup_printf(
504 "Destination: %s\n\n"
505 "This is not a valid directory.",
507 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
513 if (g_access(destdir, R_OK|W_OK) != 0)
515 message = g_strdup_printf(
516 "Destination: %s\n\n"
517 "Can not read or write the directory.",
519 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
528 gchar *resolved = ghb_resolve_symlink(destdir);
530 gfile = g_file_new_for_path(resolved);
531 info = g_file_query_filesystem_info(gfile,
532 G_FILE_ATTRIBUTE_FILESYSTEM_FREE, NULL, NULL);
535 if (g_file_info_has_attribute(info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE))
537 size = g_file_info_get_attribute_uint64(info,
538 G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
540 gint64 fsize = (guint64)10 * 1024 * 1024 * 1024;
543 message = g_strdup_printf(
544 "Destination filesystem is almost full: %uM free\n\n"
545 "Encode may be incomplete if you proceed.\n",
546 (guint)(size / (1024L*1024L)));
547 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Proceed"))
556 g_object_unref(info);
558 g_object_unref(gfile);
561 if (g_file_test(dest, G_FILE_TEST_EXISTS))
563 message = g_strdup_printf(
564 "Destination: %s\n\n"
565 "File already exhists.\n"
566 "Do you want to overwrite?",
568 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Overwrite"))
578 // Validate video quality is in a reasonable range
579 if (!ghb_validate_vquality(ud->settings))
583 // Validate audio settings
584 if (!ghb_validate_audio(ud))
588 // Validate video settings
589 if (!ghb_validate_video(ud))
593 // Validate filter settings
594 if (!ghb_validate_filters(ud))
598 audio_list_refresh(ud);
603 queue_add(signal_user_data_t *ud)
605 // Add settings to the queue
610 g_debug("queue_add ()");
611 if (!validate_settings(ud))
615 if (ud->queue == NULL)
616 ud->queue = ghb_array_value_new(32);
617 // Make a copy of current settings to be used for the new job
618 settings = ghb_value_dup(ud->settings);
619 ghb_settings_set_int(settings, "job_status", GHB_QUEUE_PENDING);
620 ghb_settings_set_int(settings, "job_unique_id", 0);
621 titleindex = ghb_settings_combo_int(settings, "title");
622 titlenum = ghb_get_title_number(titleindex);
623 ghb_settings_set_int(settings, "titlenum", titlenum);
624 ghb_array_append(ud->queue, settings);
625 add_to_queue_list(ud, settings, NULL);
626 ghb_save_queue(ud->queue);
632 queue_add_clicked_cb(GtkWidget *widget, signal_user_data_t *ud)
634 g_debug("queue_add_clicked_cb ()");
639 queue_remove_clicked_cb(GtkWidget *widget, gchar *path, signal_user_data_t *ud)
641 GtkTreeView *treeview;
642 GtkTreePath *treepath;
651 g_debug("queue_remove_clicked_cb ()");
652 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
653 store = gtk_tree_view_get_model(treeview);
654 treepath = gtk_tree_path_new_from_string (path);
655 if (gtk_tree_path_get_depth(treepath) > 1) return;
656 if (gtk_tree_model_get_iter(store, &iter, treepath))
658 // Find the entry in the queue
659 indices = gtk_tree_path_get_indices (treepath);
661 // Can only free the treepath After getting what I need from
662 // indices since this points into treepath somewhere.
663 gtk_tree_path_free (treepath);
665 if (row >= ghb_array_len(ud->queue))
667 settings = ghb_array_get_nth(ud->queue, row);
668 status = ghb_settings_get_int(settings, "job_status");
669 if (status == GHB_QUEUE_RUNNING)
671 // Ask if wants to stop encode.
672 if (!ghb_cancel_encode(NULL))
676 unique_id = ghb_settings_get_int(settings, "job_unique_id");
677 ghb_remove_job(unique_id);
679 // Remove the selected item
680 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
681 // Remove the corresponding item from the queue list
682 GValue *old = ghb_array_get_nth(ud->queue, row);
684 ghb_array_remove(ud->queue, row);
685 ghb_save_queue(ud->queue);
689 gtk_tree_path_free (treepath);
694 find_last_finished(GValue *queue)
700 g_debug("find_last_finished");
701 count = ghb_array_len(queue);
702 for (ii = 0; ii < count; ii++)
704 js = ghb_array_get_nth(queue, ii);
705 status = ghb_settings_get_int(js, "job_status");
706 if (status != GHB_QUEUE_DONE && status != GHB_QUEUE_RUNNING)
714 // This little bit is needed to prevent the default drag motion
715 // handler from expanding rows if you hover over them while
717 // Also controls where valid drop locations are
719 queue_drag_motion_cb(
725 signal_user_data_t *ud)
727 GtkTreePath *path = NULL;
728 GtkTreeViewDropPosition pos;
729 gint *indices, row, status, finished;
734 GtkTreeSelection *select;
736 // This bit checks to see if the source is allowed to be
737 // moved. Only pending and canceled items may be moved.
738 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
739 select = gtk_tree_view_get_selection (srctv);
740 gtk_tree_selection_get_selected (select, &model, &iter);
741 path = gtk_tree_model_get_path (model, &iter);
742 indices = gtk_tree_path_get_indices(path);
744 gtk_tree_path_free(path);
745 js = ghb_array_get_nth(ud->queue, row);
746 status = ghb_settings_get_int(js, "job_status");
747 if (status != GHB_QUEUE_PENDING && status != GHB_QUEUE_CANCELED)
749 gdk_drag_status(ctx, 0, time);
753 // The reset checks that the destination is a valid position
754 // in the list. Can not move above any finished or running items
755 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &pos);
758 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
761 // Don't allow *drop into*
762 if (pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
763 pos = GTK_TREE_VIEW_DROP_BEFORE;
764 if (pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
765 pos = GTK_TREE_VIEW_DROP_AFTER;
766 // Don't allow droping int child items
767 if (gtk_tree_path_get_depth(path) > 1)
769 gtk_tree_path_up(path);
770 pos = GTK_TREE_VIEW_DROP_AFTER;
772 indices = gtk_tree_path_get_indices(path);
774 js = ghb_array_get_nth(ud->queue, row);
776 finished = find_last_finished(ud->queue);
779 gtk_tree_path_free(path);
780 gdk_drag_status(ctx, 0, time);
783 if (pos != GTK_TREE_VIEW_DROP_AFTER &&
786 gtk_tree_path_free(path);
787 gdk_drag_status(ctx, 0, time);
790 gtk_tree_view_set_drag_dest_row(tv, path, pos);
791 gtk_tree_path_free(path);
792 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
798 GtkTreeView *dstwidget,
801 GtkSelectionData *selection_data,
803 signal_user_data_t *ud)
805 GtkTreePath *path = NULL;
806 //GtkTreeModel *model;
807 GtkTreeViewDropPosition pos;
808 GtkTreeIter dstiter, srciter;
812 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
814 g_debug("queue_drag_cb ()");
815 // This doesn't work here for some reason...
816 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &pos);
817 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &pos);
818 // This little hack is needed because attempting to drop after
819 // the last item gives us no path or pos.
824 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
827 pos = GTK_TREE_VIEW_DROP_AFTER;
828 path = gtk_tree_path_new_from_indices(n_children-1, -1);
832 pos = GTK_TREE_VIEW_DROP_BEFORE;
833 path = gtk_tree_path_new_from_indices(0, -1);
838 if (gtk_tree_path_get_depth(path) > 1)
839 gtk_tree_path_up(path);
840 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
843 GtkTreeView *srcwidget;
844 GtkTreeModel *srcmodel;
845 GtkTreeSelection *select;
846 GtkTreePath *srcpath = NULL;
847 GtkTreePath *dstpath = NULL;
849 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
850 //srcmodel = gtk_tree_view_get_model(srcwidget);
851 select = gtk_tree_view_get_selection (srcwidget);
852 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
854 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
855 indices = gtk_tree_path_get_indices(srcpath);
857 gtk_tree_path_free(srcpath);
858 js = ghb_array_get_nth(ud->queue, row);
862 case GTK_TREE_VIEW_DROP_BEFORE:
863 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
864 gtk_tree_store_insert_before (GTK_TREE_STORE (dstmodel),
865 &iter, NULL, &dstiter);
868 case GTK_TREE_VIEW_DROP_AFTER:
869 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
870 gtk_tree_store_insert_after (GTK_TREE_STORE (dstmodel),
871 &iter, NULL, &dstiter);
877 // Reset job to pending
878 ghb_settings_set_int(js, "job_status", GHB_QUEUE_PENDING);
879 add_to_queue_list(ud, js, &iter);
881 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
882 indices = gtk_tree_path_get_indices(dstpath);
884 gtk_tree_path_free(dstpath);
885 ghb_array_insert(ud->queue, row, js);
887 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
888 indices = gtk_tree_path_get_indices(srcpath);
890 gtk_tree_path_free(srcpath);
891 ghb_array_remove(ud->queue, row);
892 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
893 ghb_save_queue(ud->queue);
895 gtk_tree_path_free(path);
900 ghb_queue_buttons_grey(signal_user_data_t *ud, gboolean working)
908 queue_count = ghb_array_len(ud->queue);
909 titleindex = ghb_settings_combo_int(ud->settings, "title");
910 title_ok = (titleindex >= 0);
912 widget = GHB_WIDGET (ud->builder, "queue_start1");
913 gtk_widget_set_sensitive (widget, !working && (title_ok || queue_count));
914 widget = GHB_WIDGET (ud->builder, "queue_start2");
915 gtk_widget_set_sensitive (widget, !working && (title_ok || queue_count));
916 action = GHB_ACTION (ud->builder, "queue_start_menu");
917 gtk_action_set_sensitive (action, !working && (title_ok || queue_count));
918 widget = GHB_WIDGET (ud->builder, "queue_pause1");
919 gtk_widget_set_sensitive (widget, working);
920 widget = GHB_WIDGET (ud->builder, "queue_pause2");
921 gtk_widget_set_sensitive (widget, working);
922 action = GHB_ACTION (ud->builder, "queue_pause_menu");
923 gtk_action_set_sensitive (action, working);
924 widget = GHB_WIDGET (ud->builder, "queue_stop");
925 gtk_widget_set_sensitive (widget, working);
926 action = GHB_ACTION (ud->builder, "queue_stop_menu");
927 gtk_action_set_sensitive (action, working);
931 queue_list_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, GtkCellRenderer *cell)
933 GtkTreeViewColumn *column;
936 column = gtk_tree_view_get_column (GTK_TREE_VIEW(widget), 0);
937 width = gtk_tree_view_column_get_width(column);
938 g_debug("col width %d alloc width %d", width, allocation->width);
939 // Set new wrap-width. Shave a little off to accomidate the icons
940 // that share this column.
941 if (width >= 564) // Don't allow below a certain size
942 g_object_set(cell, "wrap-width", width-70, NULL);
946 queue_start_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
949 gboolean running = FALSE;
954 count = ghb_array_len(ud->queue);
955 for (ii = 0; ii < count; ii++)
957 js = ghb_array_get_nth(ud->queue, ii);
958 status = ghb_settings_get_int(js, "job_status");
959 if ((status == GHB_QUEUE_RUNNING) ||
960 (status == GHB_QUEUE_PENDING))
968 // The queue has no running or pending jobs.
969 // Add current settings to the queue, then run.
973 state = ghb_get_queue_state();
974 if (state == GHB_STATE_IDLE)
976 // Add the first pending queue item and start
977 ud->current_job = ghb_start_next_job(ud, TRUE);
982 queue_stop_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
984 ud->cancel_encode = TRUE;
985 ghb_cancel_encode(NULL);
989 queue_pause_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
995 ghb_reload_queue(signal_user_data_t *ud)
1004 g_debug("ghb_reload_queue");
1006 // I really shouldn't have to do this, but at startup the
1007 // initial window size is larger than it should be. This
1008 // make it adjust to the proper size.
1009 GtkWindow *hb_window;
1010 hb_window = GTK_WINDOW(GHB_WIDGET (ud->builder, "hb_window"));
1011 gtk_window_resize(hb_window, 16, 16);
1013 queue = ghb_load_queue();
1014 // Look for unfinished entries
1015 count = ghb_array_len(queue);
1016 for (ii = 0; ii < count; ii++)
1018 settings = ghb_array_get_nth(queue, ii);
1019 status = ghb_settings_get_int(settings, "job_status");
1020 if (status != GHB_QUEUE_DONE && status != GHB_QUEUE_CANCELED)
1027 message = g_strdup_printf(
1028 "You have %d unfinished job%s in a saved queue.\n\n"
1029 "Would you like to reload %s?",
1031 (unfinished > 1) ? "s" : "",
1032 (unfinished > 1) ? "them" : "it");
1033 if (ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "No", "Yes"))
1035 GtkWidget *widget = GHB_WIDGET (ud->builder, "queue_window");
1036 gtk_widget_show (widget);
1039 // First get rid of any old items we don't want
1040 for (ii = count-1; ii >= 0; ii--)
1042 settings = ghb_array_get_nth(queue, ii);
1043 status = ghb_settings_get_int(settings, "job_status");
1044 if (status == GHB_QUEUE_DONE || status == GHB_QUEUE_CANCELED)
1046 GValue *old = ghb_array_get_nth(queue, ii);
1047 ghb_value_free(old);
1048 ghb_array_remove(queue, ii);
1051 count = ghb_array_len(queue);
1052 for (ii = 0; ii < count; ii++)
1054 settings = ghb_array_get_nth(queue, ii);
1055 ghb_settings_set_int(settings, "job_unique_id", 0);
1056 ghb_settings_set_int(settings, "job_status", GHB_QUEUE_PENDING);
1057 add_to_queue_list(ud, settings, NULL);
1059 ghb_queue_buttons_grey(ud, FALSE);
1063 ghb_value_free(queue);
1064 ghb_remove_queue_file();
1075 signal_user_data_t *ud)
1077 GtkTreeView *treeview;
1078 GtkTreeSelection *selection;
1079 GtkTreeModel *store;
1087 g_debug("queue_key_press_cb ()");
1088 if (event->keyval != GDK_Delete)
1090 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
1091 store = gtk_tree_view_get_model(treeview);
1093 selection = gtk_tree_view_get_selection (treeview);
1094 if (gtk_tree_selection_get_selected(selection, &store, &iter))
1096 GtkTreePath *treepath;
1098 treepath = gtk_tree_model_get_path (store, &iter);
1099 // Find the entry in the queue
1100 indices = gtk_tree_path_get_indices (treepath);
1102 // Can only free the treepath After getting what I need from
1103 // indices since this points into treepath somewhere.
1104 gtk_tree_path_free (treepath);
1105 if (row < 0) return FALSE;
1106 if (row >= ghb_array_len(ud->queue))
1108 settings = ghb_array_get_nth(ud->queue, row);
1109 status = ghb_settings_get_int(settings, "job_status");
1110 if (status == GHB_QUEUE_RUNNING)
1112 // Ask if wants to stop encode.
1113 if (!ghb_cancel_encode(NULL))
1117 unique_id = ghb_settings_get_int(settings, "job_unique_id");
1118 ghb_remove_job(unique_id);
1120 // Remove the selected item
1121 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
1122 // Remove the corresponding item from the queue list
1123 GValue *old = ghb_array_get_nth(ud->queue, row);
1124 ghb_value_free(old);
1125 ghb_array_remove(ud->queue, row);
1126 ghb_save_queue(ud->queue);
1132 GValue *ghb_queue_edit_settings = NULL;
1135 queue_edit_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
1137 GtkTreeView *treeview;
1138 GtkTreeSelection *selection;
1139 GtkTreeModel *store;
1145 g_debug("queue_key_press_cb ()");
1146 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
1147 store = gtk_tree_view_get_model(treeview);
1149 selection = gtk_tree_view_get_selection (treeview);
1150 if (gtk_tree_selection_get_selected(selection, &store, &iter))
1152 GtkTreePath *treepath;
1154 treepath = gtk_tree_model_get_path (store, &iter);
1155 // Find the entry in the queue
1156 indices = gtk_tree_path_get_indices (treepath);
1158 // Can only free the treepath After getting what I need from
1159 // indices since this points into treepath somewhere.
1160 gtk_tree_path_free (treepath);
1161 if (row < 0) return;
1162 if (row >= ghb_array_len(ud->queue))
1164 ghb_queue_edit_settings = ghb_array_get_nth(ud->queue, row);
1165 status = ghb_settings_get_int(ghb_queue_edit_settings, "job_status");
1166 if (status == GHB_QUEUE_PENDING)
1168 // Remove the selected item
1169 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
1170 // Remove the corresponding item from the queue list
1171 ghb_array_remove(ud->queue, row);
1174 source = ghb_settings_get_string(ghb_queue_edit_settings, "source");
1175 ghb_do_scan(ud, source, FALSE);