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, vqvalue;
74 gint source_width, source_height;
75 gboolean pass2, anamorphic, round_dim, keep_aspect, vqtype, turbo;
78 g_debug("update_queue_list ()");
79 if (settings == NULL) return;
80 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
81 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
83 tweaks = ghb_settings_get_boolean(settings, "allow_tweaks");
84 title = ghb_settings_combo_int(settings, "title");
85 start_chapter = ghb_settings_get_int(settings, "start_chapter");
86 end_chapter = ghb_settings_get_int(settings, "end_chapter");
87 pass2 = ghb_settings_get_boolean(settings, "two_pass");
88 vol_name = ghb_settings_get_string(settings, "volume_label");
89 dest = ghb_settings_get_string(settings, "destination");
90 basename = g_path_get_basename(dest);
91 info = g_strdup_printf
93 "<big><b>%s</b></big> "
94 "<small>(Title %d, Chapters %d through %d, %d Video %s)"
96 vol_name, title+1, start_chapter, end_chapter,
97 pass2 ? 2:1, pass2 ? "Passes":"Pass", basename
103 gtk_tree_store_append(store, &iter, NULL);
105 gtk_tree_store_set(store, &iter, 1, info, 2, "hb-queue-delete", -1);
107 status = ghb_settings_get_int(settings, "job_status");
110 case GHB_QUEUE_PENDING:
111 gtk_tree_store_set(store, &iter, 0, "hb-queue-job", -1);
113 case GHB_QUEUE_CANCELED:
114 gtk_tree_store_set(store, &iter, 0, "hb-canceled", -1);
116 case GHB_QUEUE_RUNNING:
117 gtk_tree_store_set(store, &iter, 0, "hb-working0", -1);
120 gtk_tree_store_set(store, &iter, 0, "hb-complete", -1);
123 gtk_tree_store_set(store, &iter, 0, "hb-queue-job", -1);
127 GString *str = g_string_new("");
129 gboolean preset_modified;
133 container = ghb_settings_combo_option(settings, "container");
134 mux = ghb_settings_combo_int(settings, "container");
135 preset_modified = ghb_settings_get_boolean(settings, "preset_modified");
136 path = ghb_settings_get_value(settings, "preset");
137 preset = ghb_preset_path_string(path);
138 markers = ghb_settings_get_boolean(settings, "chapter_markers");
141 g_string_append_printf(str,
142 "<b>Customized Preset Based On:</b> <small>%s</small>\n",
145 g_string_append_printf(str,
146 "<b>Preset:</b> <small>%s</small>\n",
151 g_string_append_printf(str,
152 "<b>Format:</b> <small>%s Container, Chapter Markers</small>\n",
157 g_string_append_printf(str,
158 "<b>Format:</b> <small>%s Container</small>\n", container);
160 if (mux == HB_MUX_MP4)
162 gboolean ipod, http, large;
164 ipod = ghb_settings_get_boolean(settings, "ipod_file");
165 http = ghb_settings_get_boolean(settings, "http_optimize_mp4");
166 large = ghb_settings_get_boolean(settings, "large_mp4");
167 if (http || ipod || large)
169 g_string_append_printf(str, "<b>MP4 Options:</b><small>");
171 g_string_append_printf(str, " - iPod 5G Support");
173 g_string_append_printf(str, " - Web Optimized");
175 g_string_append_printf(str, " - Large File Size (>4GB)");
176 g_string_append_printf(str, "</small>\n");
179 g_string_append_printf(str,
180 "<b>Destination:</b> <small>%s</small>\n", dest);
182 width = ghb_settings_get_int(settings, "scale_width");
183 height = ghb_settings_get_int(settings, "scale_height");
184 anamorphic = ghb_settings_get_boolean(settings, "anamorphic");
185 round_dim = ghb_settings_get_boolean(settings, "round_dimensions");
186 keep_aspect = ghb_settings_get_boolean(settings, "keep_aspect");
193 aspect_desc = "(Anamorphic)";
197 aspect_desc = "(Strict Anamorphic)";
204 aspect_desc = "(Aspect Preserved)";
208 aspect_desc = "(Aspect Lost)";
211 vqtype = ghb_settings_get_boolean(settings, "vquality_type_constant");
214 gchar *vq_desc = "Error";
215 gchar *vq_units = "";
218 vqtype = ghb_settings_get_boolean(settings, "vquality_type_target");
222 vqvalue = ghb_settings_get_int(settings, "video_bitrate");
223 vq_desc = "Bitrate:";
229 vqvalue = ghb_settings_get_int(settings, "video_target_size");
230 vq_desc = "Target Size:";
237 vqvalue = ghb_settings_get_int(settings, "video_quality");
238 vq_desc = "Constant Quality:";
240 fps = ghb_settings_get_string(settings, "framerate");
241 if (strcmp("source", fps) == 0)
244 if (ghb_settings_get_boolean(settings, "detelecine"))
245 fps = g_strdup("Same As Source (vfr detelecine)");
247 fps = g_strdup("Same As Source (variable)");
252 tmp = g_strdup_printf("%s (constant frame rate)", fps);
256 vcodec = ghb_settings_combo_option(settings, "video_codec");
257 vcodec_abbr = ghb_settings_get_string(settings, "video_codec");
258 source_width = ghb_settings_get_int(settings, "source_width");
259 source_height = ghb_settings_get_int(settings, "source_height");
260 g_string_append_printf(str,
261 "<b>Picture:</b> Source: <small>%d x %d, Output %d x %d %s</small>\n",
262 source_width, source_height, width, height, aspect_desc);
265 gboolean filters = FALSE;
267 decomb = ghb_settings_get_boolean(settings, "decomb");
268 g_string_append_printf(str, "<b>Filters:</b><small>");
269 if (ghb_settings_get_boolean(settings, "detelecine"))
271 g_string_append_printf(str, " - Detelecine");
276 g_string_append_printf(str, " - Decomb");
281 gint deint = ghb_settings_combo_int(settings,
282 tweaks ? "tweak_deinterlace":"deinterlace");
285 const gchar *opt = ghb_settings_combo_option(settings,
286 tweaks ? "tweak_deinterlace":"deinterlace");
287 g_string_append_printf(str, " - Deinterlace: %s", opt);
291 gint denoise = ghb_settings_combo_int(settings,
292 tweaks ? "tweak_denoise":"denoise");
295 const gchar *opt = ghb_settings_combo_option(settings,
296 tweaks ? "tweak_denoise":"denoise");
297 g_string_append_printf(str, " - Denoise: %s", opt);
300 gint deblock = ghb_settings_get_int(settings, "deblock");
303 g_string_append_printf(str, " - Deblock (%d)", deblock);
306 if (ghb_settings_get_boolean(settings, "grayscale"))
308 g_string_append_printf(str, " - Grayscale");
312 g_string_append_printf(str, " None");
313 g_string_append_printf(str, "</small>\n");
315 g_string_append_printf(str,
316 "<b>Video:</b> <small>%s, Framerate: %s, %s %d%s</small>\n",
317 vcodec, fps, vq_desc, vqvalue, vq_units);
319 turbo = ghb_settings_get_boolean(settings, "turbo");
322 g_string_append_printf(str, "<b>Turbo:</b> <small>On</small>\n");
324 if (strcmp(vcodec_abbr, "x264") == 0)
326 gchar *x264opts = ghb_build_x264opts_string(settings);
327 g_string_append_printf(str,
328 "<b>x264 Options:</b> <small>%s</small>\n", x264opts);
333 const GValue *audio_list;
335 audio_list = ghb_settings_get_value(settings, "audio_list");
336 count = ghb_array_len(audio_list);
337 for (ii = 0; ii < count; ii++)
339 gchar *bitrate, *samplerate, *track;
340 const gchar *acodec, *mix;
343 asettings = ghb_array_get_nth(audio_list, ii);
345 acodec = ghb_settings_combo_option(asettings, "audio_codec");
346 bitrate = ghb_settings_get_string(asettings, "audio_bitrate");
347 samplerate = ghb_settings_get_string(asettings, "audio_rate");
348 if (strcmp("source", samplerate) == 0)
351 samplerate = g_strdup("Same As Source");
353 track = ghb_settings_get_string(asettings, "audio_track_long");
354 mix = ghb_settings_combo_option(asettings, "audio_mix");
355 g_string_append_printf(str,
356 "<b>Audio:</b><small> %s, Encoder: %s, Mixdown: %s, SampleRate: %s, Bitrate: %s</small>",
357 track, acodec, mix, samplerate, bitrate);
359 g_string_append_printf(str, "\n");
364 info = g_string_free(str, FALSE);
365 gtk_tree_store_append(store, &citer, &iter);
366 gtk_tree_store_set(store, &citer, 1, info, -1);
376 estimate_file_size(signal_user_data_t *ud)
378 ghb_title_info_t tinfo;
384 titleindex = ghb_settings_combo_int(ud->settings, "title");
385 if (titleindex < 0) return 0;
387 if (!ghb_get_title_info(&tinfo, titleindex)) return 0;
388 duration = ((tinfo.hours*60)+tinfo.minutes)*60+tinfo.seconds;
389 bitrate = ghb_guess_bitrate(ud->settings);
390 size = (gint64)duration * (gint64)bitrate/8;
395 audio_list_refresh(signal_user_data_t *ud)
397 GtkTreeView *treeview;
404 g_debug("ghb_audio_list_refresh ()");
405 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_list"));
406 store = GTK_LIST_STORE(gtk_tree_view_get_model(treeview));
407 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter))
411 const gchar *track, *codec, *br, *sr, *mix;
412 gchar *drc, *s_track, *s_codec, *s_br, *s_sr, *s_mix;
416 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
417 if (row >= ghb_array_len(audio_list))
419 asettings = ghb_array_get_nth(audio_list, row);
421 track = ghb_settings_combo_option(asettings, "audio_track");
422 codec = ghb_settings_combo_option(asettings, "audio_codec");
423 br = ghb_settings_combo_option(asettings, "audio_bitrate");
424 sr = ghb_settings_combo_option(asettings, "audio_rate");
425 mix = ghb_settings_combo_option(asettings, "audio_mix");
426 drc = ghb_settings_get_string(asettings, "audio_drc");
428 s_track = ghb_settings_get_string(asettings, "audio_track");
429 s_codec = ghb_settings_get_string(asettings, "audio_codec");
430 s_br = ghb_settings_get_string(asettings, "audio_bitrate");
431 s_sr = ghb_settings_get_string(asettings, "audio_rate");
432 s_mix = ghb_settings_get_string(asettings, "audio_mix");
433 s_drc = ghb_settings_get_double(asettings, "audio_drc");
435 gtk_list_store_set(GTK_LIST_STORE(store), &iter,
436 // These are displayed in list
442 // These are used to set combo values when an item is selected
457 done = !gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
464 validate_settings(signal_user_data_t *ud)
466 // Check to see if the dest file exists or is
467 // already in the queue
468 gchar *message, *dest;
472 titleindex = ghb_settings_combo_int(ud->settings, "title");
473 if (titleindex < 0) return FALSE;
474 dest = ghb_settings_get_string(ud->settings, "destination");
475 count = ghb_array_len(ud->queue);
476 for (ii = 0; ii < count; ii++)
481 js = ghb_array_get_nth(ud->queue, ii);
482 filename = ghb_settings_get_string(js, "destination");
483 if (strcmp(dest, filename) == 0)
485 message = g_strdup_printf(
486 "Destination: %s\n\n"
487 "Another queued job has specified the same destination.\n"
488 "Do you want to overwrite?",
490 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Overwrite"))
502 gchar *destdir = g_path_get_dirname(dest);
503 if (!g_file_test(destdir, G_FILE_TEST_IS_DIR))
505 message = g_strdup_printf(
506 "Destination: %s\n\n"
507 "This is not a valid directory.",
509 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
515 if (g_access(destdir, R_OK|W_OK) != 0)
517 message = g_strdup_printf(
518 "Destination: %s\n\n"
519 "Can not read or write the directory.",
521 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
530 gchar *resolved = ghb_resolve_symlink(destdir);
532 gfile = g_file_new_for_path(resolved);
533 info = g_file_query_filesystem_info(gfile,
534 G_FILE_ATTRIBUTE_FILESYSTEM_FREE, NULL, NULL);
537 if (g_file_info_has_attribute(info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE))
539 size = g_file_info_get_attribute_uint64(info,
540 G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
542 gint64 fsize = estimate_file_size(ud);
545 message = g_strdup_printf(
546 "Destination filesystem is almost full: %uM free\n\n"
547 "Encode may be incomplete if you proceed.\n",
548 (guint)(size / (1024L*1024L)));
549 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Proceed"))
558 g_object_unref(info);
560 g_object_unref(gfile);
563 if (g_file_test(dest, G_FILE_TEST_EXISTS))
565 message = g_strdup_printf(
566 "Destination: %s\n\n"
567 "File already exhists.\n"
568 "Do you want to overwrite?",
570 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Overwrite"))
580 // Validate video quality is in a reasonable range
581 if (!ghb_validate_vquality(ud->settings))
585 // Validate audio settings
586 if (!ghb_validate_audio(ud))
590 // Validate video settings
591 if (!ghb_validate_video(ud))
595 // Validate container settings
596 if (!ghb_validate_container(ud))
600 // Validate filter settings
601 if (!ghb_validate_filters(ud))
605 audio_list_refresh(ud);
610 queue_add(signal_user_data_t *ud)
612 // Add settings to the queue
617 g_debug("queue_add ()");
618 if (!validate_settings(ud))
622 if (ud->queue == NULL)
623 ud->queue = ghb_array_value_new(32);
624 // Make a copy of current settings to be used for the new job
625 settings = ghb_value_dup(ud->settings);
626 ghb_settings_set_int(settings, "job_status", GHB_QUEUE_PENDING);
627 ghb_settings_set_int(settings, "job_unique_id", 0);
628 titleindex = ghb_settings_combo_int(settings, "title");
629 titlenum = ghb_get_title_number(titleindex);
630 ghb_settings_set_int(settings, "titlenum", titlenum);
631 ghb_array_append(ud->queue, settings);
632 add_to_queue_list(ud, settings, NULL);
633 ghb_save_queue(ud->queue);
639 queue_add_clicked_cb(GtkWidget *widget, signal_user_data_t *ud)
641 g_debug("queue_add_clicked_cb ()");
646 queue_remove_clicked_cb(GtkWidget *widget, gchar *path, signal_user_data_t *ud)
648 GtkTreeView *treeview;
649 GtkTreePath *treepath;
658 g_debug("queue_remove_clicked_cb ()");
659 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
660 store = gtk_tree_view_get_model(treeview);
661 treepath = gtk_tree_path_new_from_string (path);
662 if (gtk_tree_path_get_depth(treepath) > 1) return;
663 if (gtk_tree_model_get_iter(store, &iter, treepath))
665 // Find the entry in the queue
666 indices = gtk_tree_path_get_indices (treepath);
668 // Can only free the treepath After getting what I need from
669 // indices since this points into treepath somewhere.
670 gtk_tree_path_free (treepath);
672 if (row >= ghb_array_len(ud->queue))
674 settings = ghb_array_get_nth(ud->queue, row);
675 status = ghb_settings_get_int(settings, "job_status");
676 if (status == GHB_QUEUE_RUNNING)
678 // Ask if wants to stop encode.
679 if (!ghb_cancel_encode(NULL))
683 unique_id = ghb_settings_get_int(settings, "job_unique_id");
684 ghb_remove_job(unique_id);
686 // Remove the selected item
687 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
688 // Remove the corresponding item from the queue list
689 GValue *old = ghb_array_get_nth(ud->queue, row);
691 ghb_array_remove(ud->queue, row);
692 ghb_save_queue(ud->queue);
696 gtk_tree_path_free (treepath);
701 find_last_finished(GValue *queue)
707 g_debug("find_last_finished");
708 count = ghb_array_len(queue);
709 for (ii = 0; ii < count; ii++)
711 js = ghb_array_get_nth(queue, ii);
712 status = ghb_settings_get_int(js, "job_status");
713 if (status != GHB_QUEUE_DONE && status != GHB_QUEUE_RUNNING)
721 // This little bit is needed to prevent the default drag motion
722 // handler from expanding rows if you hover over them while
724 // Also controls where valid drop locations are
726 queue_drag_motion_cb(
732 signal_user_data_t *ud)
734 GtkTreePath *path = NULL;
735 GtkTreeViewDropPosition pos;
736 gint *indices, row, status, finished;
741 GtkTreeSelection *select;
743 // This bit checks to see if the source is allowed to be
744 // moved. Only pending and canceled items may be moved.
745 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
746 select = gtk_tree_view_get_selection (srctv);
747 gtk_tree_selection_get_selected (select, &model, &iter);
748 path = gtk_tree_model_get_path (model, &iter);
749 indices = gtk_tree_path_get_indices(path);
751 gtk_tree_path_free(path);
752 js = ghb_array_get_nth(ud->queue, row);
753 status = ghb_settings_get_int(js, "job_status");
754 if (status != GHB_QUEUE_PENDING && status != GHB_QUEUE_CANCELED)
756 gdk_drag_status(ctx, 0, time);
760 // The reset checks that the destination is a valid position
761 // in the list. Can not move above any finished or running items
762 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &pos);
765 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
768 // Don't allow *drop into*
769 if (pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
770 pos = GTK_TREE_VIEW_DROP_BEFORE;
771 if (pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
772 pos = GTK_TREE_VIEW_DROP_AFTER;
773 // Don't allow droping int child items
774 if (gtk_tree_path_get_depth(path) > 1)
776 gtk_tree_path_up(path);
777 pos = GTK_TREE_VIEW_DROP_AFTER;
779 indices = gtk_tree_path_get_indices(path);
781 js = ghb_array_get_nth(ud->queue, row);
783 finished = find_last_finished(ud->queue);
786 gtk_tree_path_free(path);
787 gdk_drag_status(ctx, 0, time);
790 if (pos != GTK_TREE_VIEW_DROP_AFTER &&
793 gtk_tree_path_free(path);
794 gdk_drag_status(ctx, 0, time);
797 gtk_tree_view_set_drag_dest_row(tv, path, pos);
798 gtk_tree_path_free(path);
799 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
805 GtkTreeView *dstwidget,
808 GtkSelectionData *selection_data,
810 signal_user_data_t *ud)
812 GtkTreePath *path = NULL;
813 //GtkTreeModel *model;
814 GtkTreeViewDropPosition pos;
815 GtkTreeIter dstiter, srciter;
819 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
821 g_debug("queue_drag_cb ()");
822 // This doesn't work here for some reason...
823 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &pos);
824 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &pos);
825 // This little hack is needed because attempting to drop after
826 // the last item gives us no path or pos.
831 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
834 pos = GTK_TREE_VIEW_DROP_AFTER;
835 path = gtk_tree_path_new_from_indices(n_children-1, -1);
839 pos = GTK_TREE_VIEW_DROP_BEFORE;
840 path = gtk_tree_path_new_from_indices(0, -1);
845 if (gtk_tree_path_get_depth(path) > 1)
846 gtk_tree_path_up(path);
847 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
850 GtkTreeView *srcwidget;
851 GtkTreeModel *srcmodel;
852 GtkTreeSelection *select;
853 GtkTreePath *srcpath = NULL;
854 GtkTreePath *dstpath = NULL;
856 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
857 //srcmodel = gtk_tree_view_get_model(srcwidget);
858 select = gtk_tree_view_get_selection (srcwidget);
859 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
861 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
862 indices = gtk_tree_path_get_indices(srcpath);
864 gtk_tree_path_free(srcpath);
865 js = ghb_array_get_nth(ud->queue, row);
869 case GTK_TREE_VIEW_DROP_BEFORE:
870 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
871 gtk_tree_store_insert_before (GTK_TREE_STORE (dstmodel),
872 &iter, NULL, &dstiter);
875 case GTK_TREE_VIEW_DROP_AFTER:
876 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
877 gtk_tree_store_insert_after (GTK_TREE_STORE (dstmodel),
878 &iter, NULL, &dstiter);
884 // Reset job to pending
885 ghb_settings_set_int(js, "job_status", GHB_QUEUE_PENDING);
886 add_to_queue_list(ud, js, &iter);
888 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
889 indices = gtk_tree_path_get_indices(dstpath);
891 gtk_tree_path_free(dstpath);
892 ghb_array_insert(ud->queue, row, js);
894 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
895 indices = gtk_tree_path_get_indices(srcpath);
897 gtk_tree_path_free(srcpath);
898 ghb_array_remove(ud->queue, row);
899 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
900 ghb_save_queue(ud->queue);
902 gtk_tree_path_free(path);
907 ghb_queue_buttons_grey(signal_user_data_t *ud, gboolean working)
915 queue_count = ghb_array_len(ud->queue);
916 titleindex = ghb_settings_combo_int(ud->settings, "title");
917 title_ok = (titleindex >= 0);
919 widget = GHB_WIDGET (ud->builder, "queue_start1");
920 gtk_widget_set_sensitive (widget, !working && (title_ok || queue_count));
921 widget = GHB_WIDGET (ud->builder, "queue_start2");
922 gtk_widget_set_sensitive (widget, !working && (title_ok || queue_count));
923 action = GHB_ACTION (ud->builder, "queue_start_menu");
924 gtk_action_set_sensitive (action, !working && (title_ok || queue_count));
925 widget = GHB_WIDGET (ud->builder, "queue_pause1");
926 gtk_widget_set_sensitive (widget, working);
927 widget = GHB_WIDGET (ud->builder, "queue_pause2");
928 gtk_widget_set_sensitive (widget, working);
929 action = GHB_ACTION (ud->builder, "queue_pause_menu");
930 gtk_action_set_sensitive (action, working);
931 widget = GHB_WIDGET (ud->builder, "queue_stop");
932 gtk_widget_set_sensitive (widget, working);
933 action = GHB_ACTION (ud->builder, "queue_stop_menu");
934 gtk_action_set_sensitive (action, working);
938 queue_list_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, GtkCellRenderer *cell)
940 GtkTreeViewColumn *column;
943 column = gtk_tree_view_get_column (GTK_TREE_VIEW(widget), 0);
944 width = gtk_tree_view_column_get_width(column);
945 g_debug("col width %d alloc width %d", width, allocation->width);
946 // Set new wrap-width. Shave a little off to accomidate the icons
947 // that share this column.
948 if (width >= 564) // Don't allow below a certain size
949 g_object_set(cell, "wrap-width", width-70, NULL);
953 queue_start_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
956 gboolean running = FALSE;
961 count = ghb_array_len(ud->queue);
962 for (ii = 0; ii < count; ii++)
964 js = ghb_array_get_nth(ud->queue, ii);
965 status = ghb_settings_get_int(js, "job_status");
966 if ((status == GHB_QUEUE_RUNNING) ||
967 (status == GHB_QUEUE_PENDING))
975 // The queue has no running or pending jobs.
976 // Add current settings to the queue, then run.
980 state = ghb_get_queue_state();
981 if (state == GHB_STATE_IDLE)
983 // Add the first pending queue item and start
984 ud->current_job = ghb_start_next_job(ud, TRUE);
989 queue_stop_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
991 ud->cancel_encode = TRUE;
992 ghb_cancel_encode(NULL);
996 queue_pause_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
1002 ghb_reload_queue(signal_user_data_t *ud)
1005 gint unfinished = 0;
1011 g_debug("ghb_reload_queue");
1012 queue = ghb_load_queue();
1013 // Look for unfinished entries
1014 count = ghb_array_len(queue);
1015 for (ii = 0; ii < count; ii++)
1017 settings = ghb_array_get_nth(queue, ii);
1018 status = ghb_settings_get_int(settings, "job_status");
1019 if (status != GHB_QUEUE_DONE && status != GHB_QUEUE_CANCELED)
1026 message = g_strdup_printf(
1027 "You have %d unfinished job%s in a saved queue.\n\n"
1028 "Would you like to reload %s?",
1030 (unfinished > 1) ? "s" : "",
1031 (unfinished > 1) ? "them" : "it");
1032 if (ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "No", "Yes"))
1034 GtkWidget *widget = GHB_WIDGET (ud->builder, "queue_window");
1035 gtk_widget_show (widget);
1038 // First get rid of any old items we don't want
1039 for (ii = count-1; ii >= 0; ii--)
1041 settings = ghb_array_get_nth(queue, ii);
1042 status = ghb_settings_get_int(settings, "job_status");
1043 if (status == GHB_QUEUE_DONE || status == GHB_QUEUE_CANCELED)
1045 GValue *old = ghb_array_get_nth(queue, ii);
1046 ghb_value_free(old);
1047 ghb_array_remove(queue, ii);
1050 count = ghb_array_len(queue);
1051 for (ii = 0; ii < count; ii++)
1053 settings = ghb_array_get_nth(queue, ii);
1054 ghb_settings_set_int(settings, "job_unique_id", 0);
1055 ghb_settings_set_int(settings, "job_status", GHB_QUEUE_PENDING);
1056 add_to_queue_list(ud, settings, NULL);
1058 ghb_queue_buttons_grey(ud, FALSE);
1062 ghb_value_free(queue);
1063 ghb_remove_queue_file();
1074 signal_user_data_t *ud)
1076 GtkTreeView *treeview;
1077 GtkTreeSelection *selection;
1078 GtkTreeModel *store;
1086 g_debug("queue_key_press_cb ()");
1087 if (event->keyval != GDK_Delete)
1089 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
1090 store = gtk_tree_view_get_model(treeview);
1092 selection = gtk_tree_view_get_selection (treeview);
1093 if (gtk_tree_selection_get_selected(selection, &store, &iter))
1095 GtkTreePath *treepath;
1097 treepath = gtk_tree_model_get_path (store, &iter);
1098 // Find the entry in the queue
1099 indices = gtk_tree_path_get_indices (treepath);
1101 // Can only free the treepath After getting what I need from
1102 // indices since this points into treepath somewhere.
1103 gtk_tree_path_free (treepath);
1104 if (row < 0) return FALSE;
1105 if (row >= ghb_array_len(ud->queue))
1107 settings = ghb_array_get_nth(ud->queue, row);
1108 status = ghb_settings_get_int(settings, "job_status");
1109 if (status == GHB_QUEUE_RUNNING)
1111 // Ask if wants to stop encode.
1112 if (!ghb_cancel_encode(NULL))
1116 unique_id = ghb_settings_get_int(settings, "job_unique_id");
1117 ghb_remove_job(unique_id);
1119 // Remove the selected item
1120 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
1121 // Remove the corresponding item from the queue list
1122 GValue *old = ghb_array_get_nth(ud->queue, row);
1123 ghb_value_free(old);
1124 ghb_array_remove(ud->queue, row);
1125 ghb_save_queue(ud->queue);
1131 GValue *ghb_queue_edit_settings = NULL;
1134 queue_edit_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
1136 GtkTreeView *treeview;
1137 GtkTreeSelection *selection;
1138 GtkTreeModel *store;
1144 g_debug("queue_key_press_cb ()");
1145 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
1146 store = gtk_tree_view_get_model(treeview);
1148 selection = gtk_tree_view_get_selection (treeview);
1149 if (gtk_tree_selection_get_selected(selection, &store, &iter))
1151 GtkTreePath *treepath;
1153 treepath = gtk_tree_model_get_path (store, &iter);
1154 // Find the entry in the queue
1155 indices = gtk_tree_path_get_indices (treepath);
1157 // Can only free the treepath After getting what I need from
1158 // indices since this points into treepath somewhere.
1159 gtk_tree_path_free (treepath);
1160 if (row < 0) return;
1161 if (row >= ghb_array_len(ud->queue))
1163 ghb_queue_edit_settings = ghb_array_get_nth(ud->queue, row);
1164 status = ghb_settings_get_int(ghb_queue_edit_settings, "job_status");
1165 if (status == GHB_QUEUE_PENDING)
1167 // Remove the selected item
1168 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
1169 // Remove the corresponding item from the queue list
1170 ghb_array_remove(ud->queue, row);
1173 source = ghb_settings_get_string(ghb_queue_edit_settings, "source");
1174 ghb_do_scan(ud, source, FALSE);