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 vqstr = g_strdup_printf("%d", (gint)vqvalue);
249 fps = ghb_settings_get_string(settings, "VideoFramerate");
250 if (strcmp("source", fps) == 0)
253 if (ghb_settings_combo_int(settings, "PictureDetelecine"))
254 fps = g_strdup("Same As Source (vfr detelecine)");
256 fps = g_strdup("Same As Source (variable)");
261 tmp = g_strdup_printf("%s (constant frame rate)", fps);
265 vcodec = ghb_settings_combo_option(settings, "VideoEncoder");
266 vcodec_abbr = ghb_settings_get_string(settings, "VideoEncoder");
267 source_width = ghb_settings_get_int(settings, "source_width");
268 source_height = ghb_settings_get_int(settings, "source_height");
269 g_string_append_printf(str,
270 "<b>Picture:</b> Source: <small>%d x %d, Output %d x %d %s</small>\n",
271 source_width, source_height, width, height, aspect_desc);
274 gboolean filters = FALSE;
276 decomb = ghb_settings_combo_int(settings, "PictureDecomb");
277 g_string_append_printf(str, "<b>Filters:</b><small>");
278 detel = ghb_settings_combo_int(settings, "PictureDetelecine");
281 g_string_append_printf(str, " - Detelecine");
285 cust = ghb_settings_get_string(settings, "PictureDetelecineCustom");
286 g_string_append_printf(str, ": %s", cust);
293 g_string_append_printf(str, " - Decomb");
297 cust = ghb_settings_get_string(settings, "PictureDecombCustom");
298 g_string_append_printf(str, ": %s", cust);
305 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
310 gchar *cust = ghb_settings_get_string(settings,
311 "PictureDeinterlaceCustom");
312 g_string_append_printf(str, " - Deinterlace: %s", cust);
317 const gchar *opt = ghb_settings_combo_option(settings,
318 "PictureDeinterlace");
319 g_string_append_printf(str, " - Deinterlace: %s", opt);
324 gint denoise = ghb_settings_combo_int(settings, "PictureDenoise");
329 gchar *cust = ghb_settings_get_string(settings,
330 "PictureDenoiseCustom");
331 g_string_append_printf(str, " - Denoise: %s", cust);
336 const gchar *opt = ghb_settings_combo_option(settings,
338 g_string_append_printf(str, " - Denoise: %s", opt);
342 gint deblock = ghb_settings_get_int(settings, "PictureDeblock");
345 g_string_append_printf(str, " - Deblock (%d)", deblock);
348 if (ghb_settings_get_boolean(settings, "VideoGrayScale"))
350 g_string_append_printf(str, " - Grayscale");
354 g_string_append_printf(str, " None");
355 g_string_append_printf(str, "</small>\n");
357 g_string_append_printf(str,
358 "<b>Video:</b> <small>%s, Framerate: %s, %s %s%s</small>\n",
359 vcodec, fps, vq_desc, vqstr, vq_units);
361 turbo = ghb_settings_get_boolean(settings, "VideoTurboTwoPass");
364 g_string_append_printf(str, "<b>Turbo:</b> <small>On</small>\n");
366 if (strcmp(vcodec_abbr, "x264") == 0)
368 gchar *x264opts = ghb_build_x264opts_string(settings);
369 g_string_append_printf(str,
370 "<b>x264 Options:</b> <small>%s</small>\n", x264opts);
375 const GValue *audio_list;
377 audio_list = ghb_settings_get_value(settings, "audio_list");
378 count = ghb_array_len(audio_list);
379 for (ii = 0; ii < count; ii++)
381 gchar *bitrate, *samplerate, *track;
382 const gchar *acodec, *mix;
385 asettings = ghb_array_get_nth(audio_list, ii);
387 acodec = ghb_settings_combo_option(asettings, "AudioEncoder");
388 bitrate = ghb_settings_get_string(asettings, "AudioBitrate");
389 samplerate = ghb_settings_get_string(asettings, "AudioSamplerate");
390 if (strcmp("source", samplerate) == 0)
393 samplerate = g_strdup("Same As Source");
395 track = ghb_settings_get_string(asettings, "AudioTrackDescription");
396 mix = ghb_settings_combo_option(asettings, "AudioMixdown");
397 g_string_append_printf(str,
398 "<b>Audio:</b><small> %s, Encoder: %s, Mixdown: %s, SampleRate: %s, Bitrate: %s</small>",
399 track, acodec, mix, samplerate, bitrate);
401 g_string_append_printf(str, "\n");
406 info = g_string_free(str, FALSE);
407 gtk_tree_store_append(store, &citer, &iter);
408 gtk_tree_store_set(store, &citer, 1, info, -1);
418 audio_list_refresh(signal_user_data_t *ud)
420 GtkTreeView *treeview;
425 const GValue *audio_list;
427 g_debug("ghb_audio_list_refresh ()");
428 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_list"));
429 store = GTK_LIST_STORE(gtk_tree_view_get_model(treeview));
430 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter))
434 const gchar *track, *codec, *br, *sr, *mix;
435 gchar *drc, *s_track, *s_codec, *s_br, *s_sr, *s_mix;
439 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
440 if (row >= ghb_array_len(audio_list))
442 asettings = ghb_array_get_nth(audio_list, row);
444 track = ghb_settings_combo_option(asettings, "AudioTrack");
445 codec = ghb_settings_combo_option(asettings, "AudioEncoder");
446 br = ghb_settings_combo_option(asettings, "AudioBitrate");
447 sr = ghb_settings_combo_option(asettings, "AudioSamplerate");
448 mix = ghb_settings_combo_option(asettings, "AudioMixdown");
450 s_track = ghb_settings_get_string(asettings, "AudioTrack");
451 s_codec = ghb_settings_get_string(asettings, "AudioEncoder");
452 s_br = ghb_settings_get_string(asettings, "AudioBitrate");
453 s_sr = ghb_settings_get_string(asettings, "AudioSamplerate");
454 s_mix = ghb_settings_get_string(asettings, "AudioMixdown");
455 s_drc = ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
457 drc = g_strdup("Off");
459 drc = g_strdup_printf("%.1f", s_drc);
461 gtk_list_store_set(GTK_LIST_STORE(store), &iter,
462 // These are displayed in list
469 // These are used to set combo values when an item is selected
483 done = !gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
490 validate_settings(signal_user_data_t *ud)
492 // Check to see if the dest file exists or is
493 // already in the queue
494 gchar *message, *dest;
498 titleindex = ghb_settings_combo_int(ud->settings, "title");
499 if (titleindex < 0) return FALSE;
500 dest = ghb_settings_get_string(ud->settings, "destination");
501 count = ghb_array_len(ud->queue);
502 for (ii = 0; ii < count; ii++)
507 js = ghb_array_get_nth(ud->queue, ii);
508 filename = ghb_settings_get_string(js, "destination");
509 if (strcmp(dest, filename) == 0)
511 message = g_strdup_printf(
512 "Destination: %s\n\n"
513 "Another queued job has specified the same destination.\n"
514 "Do you want to overwrite?",
516 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Overwrite"))
528 gchar *destdir = g_path_get_dirname(dest);
529 if (!g_file_test(destdir, G_FILE_TEST_IS_DIR))
531 message = g_strdup_printf(
532 "Destination: %s\n\n"
533 "This is not a valid directory.",
535 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
541 if (g_access(destdir, R_OK|W_OK) != 0)
543 message = g_strdup_printf(
544 "Destination: %s\n\n"
545 "Can not read or write the directory.",
547 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
556 gchar *resolved = ghb_resolve_symlink(destdir);
558 gfile = g_file_new_for_path(resolved);
559 info = g_file_query_filesystem_info(gfile,
560 G_FILE_ATTRIBUTE_FILESYSTEM_FREE, NULL, NULL);
563 if (g_file_info_has_attribute(info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE))
565 size = g_file_info_get_attribute_uint64(info,
566 G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
568 gint64 fsize = (guint64)10 * 1024 * 1024 * 1024;
571 message = g_strdup_printf(
572 "Destination filesystem is almost full: %uM free\n\n"
573 "Encode may be incomplete if you proceed.\n",
574 (guint)(size / (1024L*1024L)));
575 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Proceed"))
584 g_object_unref(info);
586 g_object_unref(gfile);
589 if (g_file_test(dest, G_FILE_TEST_EXISTS))
591 message = g_strdup_printf(
592 "Destination: %s\n\n"
593 "File already exhists.\n"
594 "Do you want to overwrite?",
596 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Overwrite"))
606 // Validate video quality is in a reasonable range
607 if (!ghb_validate_vquality(ud->settings))
611 // Validate audio settings
612 if (!ghb_validate_audio(ud))
616 // Validate video settings
617 if (!ghb_validate_video(ud))
621 // Validate filter settings
622 if (!ghb_validate_filters(ud))
626 audio_list_refresh(ud);
631 queue_add(signal_user_data_t *ud)
633 // Add settings to the queue
638 g_debug("queue_add ()");
639 if (!validate_settings(ud))
643 if (ud->queue == NULL)
644 ud->queue = ghb_array_value_new(32);
645 // Make a copy of current settings to be used for the new job
646 settings = ghb_value_dup(ud->settings);
647 ghb_settings_set_int(settings, "job_status", GHB_QUEUE_PENDING);
648 ghb_settings_set_int(settings, "job_unique_id", 0);
649 titleindex = ghb_settings_combo_int(settings, "title");
650 titlenum = ghb_get_title_number(titleindex);
651 ghb_settings_set_int(settings, "titlenum", titlenum);
652 ghb_array_append(ud->queue, settings);
653 add_to_queue_list(ud, settings, NULL);
654 ghb_save_queue(ud->queue);
660 queue_add_clicked_cb(GtkWidget *widget, signal_user_data_t *ud)
662 g_debug("queue_add_clicked_cb ()");
667 queue_remove_clicked_cb(GtkWidget *widget, gchar *path, signal_user_data_t *ud)
669 GtkTreeView *treeview;
670 GtkTreePath *treepath;
679 g_debug("queue_remove_clicked_cb ()");
680 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
681 store = gtk_tree_view_get_model(treeview);
682 treepath = gtk_tree_path_new_from_string (path);
683 if (gtk_tree_path_get_depth(treepath) > 1) return;
684 if (gtk_tree_model_get_iter(store, &iter, treepath))
686 // Find the entry in the queue
687 indices = gtk_tree_path_get_indices (treepath);
689 // Can only free the treepath After getting what I need from
690 // indices since this points into treepath somewhere.
691 gtk_tree_path_free (treepath);
693 if (row >= ghb_array_len(ud->queue))
695 settings = ghb_array_get_nth(ud->queue, row);
696 status = ghb_settings_get_int(settings, "job_status");
697 if (status == GHB_QUEUE_RUNNING)
699 // Ask if wants to stop encode.
700 if (!ghb_cancel_encode(NULL))
704 unique_id = ghb_settings_get_int(settings, "job_unique_id");
705 ghb_remove_job(unique_id);
707 // Remove the selected item
708 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
709 // Remove the corresponding item from the queue list
710 GValue *old = ghb_array_get_nth(ud->queue, row);
712 ghb_array_remove(ud->queue, row);
713 ghb_save_queue(ud->queue);
717 gtk_tree_path_free (treepath);
722 find_last_finished(GValue *queue)
728 g_debug("find_last_finished");
729 count = ghb_array_len(queue);
730 for (ii = 0; ii < count; ii++)
732 js = ghb_array_get_nth(queue, ii);
733 status = ghb_settings_get_int(js, "job_status");
734 if (status != GHB_QUEUE_DONE && status != GHB_QUEUE_RUNNING)
742 // This little bit is needed to prevent the default drag motion
743 // handler from expanding rows if you hover over them while
745 // Also controls where valid drop locations are
747 queue_drag_motion_cb(
753 signal_user_data_t *ud)
755 GtkTreePath *path = NULL;
756 GtkTreeViewDropPosition pos;
757 gint *indices, row, status, finished;
762 GtkTreeSelection *select;
764 // This bit checks to see if the source is allowed to be
765 // moved. Only pending and canceled items may be moved.
766 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
767 select = gtk_tree_view_get_selection (srctv);
768 gtk_tree_selection_get_selected (select, &model, &iter);
769 path = gtk_tree_model_get_path (model, &iter);
770 indices = gtk_tree_path_get_indices(path);
772 gtk_tree_path_free(path);
773 js = ghb_array_get_nth(ud->queue, row);
774 status = ghb_settings_get_int(js, "job_status");
775 if (status != GHB_QUEUE_PENDING && status != GHB_QUEUE_CANCELED)
777 gdk_drag_status(ctx, 0, time);
781 // The reset checks that the destination is a valid position
782 // in the list. Can not move above any finished or running items
783 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &pos);
786 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
789 // Don't allow *drop into*
790 if (pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
791 pos = GTK_TREE_VIEW_DROP_BEFORE;
792 if (pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
793 pos = GTK_TREE_VIEW_DROP_AFTER;
794 // Don't allow droping int child items
795 if (gtk_tree_path_get_depth(path) > 1)
797 gtk_tree_path_up(path);
798 pos = GTK_TREE_VIEW_DROP_AFTER;
800 indices = gtk_tree_path_get_indices(path);
802 js = ghb_array_get_nth(ud->queue, row);
804 finished = find_last_finished(ud->queue);
807 gtk_tree_path_free(path);
808 gdk_drag_status(ctx, 0, time);
811 if (pos != GTK_TREE_VIEW_DROP_AFTER &&
814 gtk_tree_path_free(path);
815 gdk_drag_status(ctx, 0, time);
818 gtk_tree_view_set_drag_dest_row(tv, path, pos);
819 gtk_tree_path_free(path);
820 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
826 GtkTreeView *dstwidget,
829 GtkSelectionData *selection_data,
831 signal_user_data_t *ud)
833 GtkTreePath *path = NULL;
834 //GtkTreeModel *model;
835 GtkTreeViewDropPosition pos;
836 GtkTreeIter dstiter, srciter;
840 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
842 g_debug("queue_drag_cb ()");
843 // This doesn't work here for some reason...
844 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &pos);
845 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &pos);
846 // This little hack is needed because attempting to drop after
847 // the last item gives us no path or pos.
852 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
855 pos = GTK_TREE_VIEW_DROP_AFTER;
856 path = gtk_tree_path_new_from_indices(n_children-1, -1);
860 pos = GTK_TREE_VIEW_DROP_BEFORE;
861 path = gtk_tree_path_new_from_indices(0, -1);
866 if (gtk_tree_path_get_depth(path) > 1)
867 gtk_tree_path_up(path);
868 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
871 GtkTreeView *srcwidget;
872 GtkTreeModel *srcmodel;
873 GtkTreeSelection *select;
874 GtkTreePath *srcpath = NULL;
875 GtkTreePath *dstpath = NULL;
877 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
878 //srcmodel = gtk_tree_view_get_model(srcwidget);
879 select = gtk_tree_view_get_selection (srcwidget);
880 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
882 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
883 indices = gtk_tree_path_get_indices(srcpath);
885 gtk_tree_path_free(srcpath);
886 js = ghb_array_get_nth(ud->queue, row);
890 case GTK_TREE_VIEW_DROP_BEFORE:
891 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
892 gtk_tree_store_insert_before (GTK_TREE_STORE (dstmodel),
893 &iter, NULL, &dstiter);
896 case GTK_TREE_VIEW_DROP_AFTER:
897 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
898 gtk_tree_store_insert_after (GTK_TREE_STORE (dstmodel),
899 &iter, NULL, &dstiter);
905 // Reset job to pending
906 ghb_settings_set_int(js, "job_status", GHB_QUEUE_PENDING);
907 add_to_queue_list(ud, js, &iter);
909 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
910 indices = gtk_tree_path_get_indices(dstpath);
912 gtk_tree_path_free(dstpath);
913 ghb_array_insert(ud->queue, row, js);
915 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
916 indices = gtk_tree_path_get_indices(srcpath);
918 gtk_tree_path_free(srcpath);
919 ghb_array_remove(ud->queue, row);
920 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
921 ghb_save_queue(ud->queue);
923 gtk_tree_path_free(path);
928 ghb_queue_buttons_grey(signal_user_data_t *ud, gboolean working)
936 queue_count = ghb_array_len(ud->queue);
937 titleindex = ghb_settings_combo_int(ud->settings, "title");
938 title_ok = (titleindex >= 0);
940 widget = GHB_WIDGET (ud->builder, "queue_start1");
941 gtk_widget_set_sensitive (widget, !working && (title_ok || queue_count));
942 widget = GHB_WIDGET (ud->builder, "queue_start2");
943 gtk_widget_set_sensitive (widget, !working && (title_ok || queue_count));
944 action = GHB_ACTION (ud->builder, "queue_start_menu");
945 gtk_action_set_sensitive (action, !working && (title_ok || queue_count));
946 widget = GHB_WIDGET (ud->builder, "queue_pause1");
947 gtk_widget_set_sensitive (widget, working);
948 widget = GHB_WIDGET (ud->builder, "queue_pause2");
949 gtk_widget_set_sensitive (widget, working);
950 action = GHB_ACTION (ud->builder, "queue_pause_menu");
951 gtk_action_set_sensitive (action, working);
952 widget = GHB_WIDGET (ud->builder, "queue_stop");
953 gtk_widget_set_sensitive (widget, working);
954 action = GHB_ACTION (ud->builder, "queue_stop_menu");
955 gtk_action_set_sensitive (action, working);
959 queue_list_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, GtkCellRenderer *cell)
961 GtkTreeViewColumn *column;
964 column = gtk_tree_view_get_column (GTK_TREE_VIEW(widget), 0);
965 width = gtk_tree_view_column_get_width(column);
966 g_debug("col width %d alloc width %d", width, allocation->width);
967 // Set new wrap-width. Shave a little off to accomidate the icons
968 // that share this column.
969 if (width >= 564) // Don't allow below a certain size
970 g_object_set(cell, "wrap-width", width-70, NULL);
974 queue_start_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
977 gboolean running = FALSE;
982 count = ghb_array_len(ud->queue);
983 for (ii = 0; ii < count; ii++)
985 js = ghb_array_get_nth(ud->queue, ii);
986 status = ghb_settings_get_int(js, "job_status");
987 if ((status == GHB_QUEUE_RUNNING) ||
988 (status == GHB_QUEUE_PENDING))
996 // The queue has no running or pending jobs.
997 // Add current settings to the queue, then run.
1001 state = ghb_get_queue_state();
1002 if (state == GHB_STATE_IDLE)
1004 // Add the first pending queue item and start
1005 ud->current_job = ghb_start_next_job(ud, TRUE);
1010 queue_stop_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
1012 ud->cancel_encode = TRUE;
1013 ghb_cancel_encode(NULL);
1017 queue_pause_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
1023 ghb_reload_queue(signal_user_data_t *ud)
1026 gint unfinished = 0;
1032 g_debug("ghb_reload_queue");
1034 // I really shouldn't have to do this, but at startup the
1035 // initial window size is larger than it should be. This
1036 // make it adjust to the proper size.
1037 GtkWindow *hb_window;
1038 hb_window = GTK_WINDOW(GHB_WIDGET (ud->builder, "hb_window"));
1039 gtk_window_resize(hb_window, 16, 16);
1041 queue = ghb_load_queue();
1042 // Look for unfinished entries
1043 count = ghb_array_len(queue);
1044 for (ii = 0; ii < count; ii++)
1046 settings = ghb_array_get_nth(queue, ii);
1047 status = ghb_settings_get_int(settings, "job_status");
1048 if (status != GHB_QUEUE_DONE && status != GHB_QUEUE_CANCELED)
1055 message = g_strdup_printf(
1056 "You have %d unfinished job%s in a saved queue.\n\n"
1057 "Would you like to reload %s?",
1059 (unfinished > 1) ? "s" : "",
1060 (unfinished > 1) ? "them" : "it");
1061 if (ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "No", "Yes"))
1063 GtkWidget *widget = GHB_WIDGET (ud->builder, "queue_window");
1064 gtk_widget_show (widget);
1067 // First get rid of any old items we don't want
1068 for (ii = count-1; ii >= 0; ii--)
1070 settings = ghb_array_get_nth(queue, ii);
1071 status = ghb_settings_get_int(settings, "job_status");
1072 if (status == GHB_QUEUE_DONE || status == GHB_QUEUE_CANCELED)
1074 GValue *old = ghb_array_get_nth(queue, ii);
1075 ghb_value_free(old);
1076 ghb_array_remove(queue, ii);
1079 count = ghb_array_len(queue);
1080 for (ii = 0; ii < count; ii++)
1082 settings = ghb_array_get_nth(queue, ii);
1083 ghb_settings_set_int(settings, "job_unique_id", 0);
1084 ghb_settings_set_int(settings, "job_status", GHB_QUEUE_PENDING);
1085 add_to_queue_list(ud, settings, NULL);
1087 ghb_queue_buttons_grey(ud, FALSE);
1091 ghb_value_free(queue);
1092 ghb_remove_queue_file();
1103 signal_user_data_t *ud)
1105 GtkTreeView *treeview;
1106 GtkTreeSelection *selection;
1107 GtkTreeModel *store;
1115 g_debug("queue_key_press_cb ()");
1116 if (event->keyval != GDK_Delete)
1118 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
1119 store = gtk_tree_view_get_model(treeview);
1121 selection = gtk_tree_view_get_selection (treeview);
1122 if (gtk_tree_selection_get_selected(selection, &store, &iter))
1124 GtkTreePath *treepath;
1126 treepath = gtk_tree_model_get_path (store, &iter);
1127 // Find the entry in the queue
1128 indices = gtk_tree_path_get_indices (treepath);
1130 // Can only free the treepath After getting what I need from
1131 // indices since this points into treepath somewhere.
1132 gtk_tree_path_free (treepath);
1133 if (row < 0) return FALSE;
1134 if (row >= ghb_array_len(ud->queue))
1136 settings = ghb_array_get_nth(ud->queue, row);
1137 status = ghb_settings_get_int(settings, "job_status");
1138 if (status == GHB_QUEUE_RUNNING)
1140 // Ask if wants to stop encode.
1141 if (!ghb_cancel_encode(NULL))
1145 unique_id = ghb_settings_get_int(settings, "job_unique_id");
1146 ghb_remove_job(unique_id);
1148 // Remove the selected item
1149 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
1150 // Remove the corresponding item from the queue list
1151 GValue *old = ghb_array_get_nth(ud->queue, row);
1152 ghb_value_free(old);
1153 ghb_array_remove(ud->queue, row);
1154 ghb_save_queue(ud->queue);
1160 GValue *ghb_queue_edit_settings = NULL;
1163 queue_edit_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
1165 GtkTreeView *treeview;
1166 GtkTreeSelection *selection;
1167 GtkTreeModel *store;
1173 g_debug("queue_key_press_cb ()");
1174 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
1175 store = gtk_tree_view_get_model(treeview);
1177 selection = gtk_tree_view_get_selection (treeview);
1178 if (gtk_tree_selection_get_selected(selection, &store, &iter))
1180 GtkTreePath *treepath;
1182 treepath = gtk_tree_model_get_path (store, &iter);
1183 // Find the entry in the queue
1184 indices = gtk_tree_path_get_indices (treepath);
1186 // Can only free the treepath After getting what I need from
1187 // indices since this points into treepath somewhere.
1188 gtk_tree_path_free (treepath);
1189 if (row < 0) return;
1190 if (row >= ghb_array_len(ud->queue))
1192 ghb_queue_edit_settings = ghb_array_get_nth(ud->queue, row);
1193 status = ghb_settings_get_int(ghb_queue_edit_settings, "job_status");
1194 if (status == GHB_QUEUE_PENDING)
1196 // Remove the selected item
1197 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
1198 // Remove the corresponding item from the queue list
1199 ghb_array_remove(ud->queue, row);
1202 source = ghb_settings_get_string(ghb_queue_edit_settings, "source");
1203 ghb_do_scan(ud, source, FALSE);