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, keep_aspect, vqtype, turbo;
80 g_debug("update_queue_list ()");
81 if (settings == NULL) return;
82 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
83 store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
85 tweaks = ghb_settings_get_boolean(settings, "allow_tweaks");
86 title = ghb_settings_get_int(settings, "titlenum");
87 start_chapter = ghb_settings_get_int(settings, "start_chapter");
88 end_chapter = ghb_settings_get_int(settings, "end_chapter");
89 pass2 = ghb_settings_get_boolean(settings, "VideoTwoPass");
90 vol_name = ghb_settings_get_string(settings, "volume_label");
91 dest = ghb_settings_get_string(settings, "destination");
92 basename = g_path_get_basename(dest);
93 escape = g_markup_escape_text(basename, -1);
94 info = g_strdup_printf
96 "<big><b>%s</b></big> "
97 "<small>(Title %d, Chapters %d through %d, %d Video %s)"
99 vol_name, title, start_chapter, end_chapter,
100 pass2 ? 2:1, pass2 ? "Passes":"Pass", escape
108 gtk_tree_store_append(store, &iter, NULL);
110 gtk_tree_store_set(store, &iter, 1, info, 2, "hb-queue-delete", -1);
112 status = ghb_settings_get_int(settings, "job_status");
115 case GHB_QUEUE_PENDING:
116 gtk_tree_store_set(store, &iter, 0, "hb-queue-job", -1);
118 case GHB_QUEUE_CANCELED:
119 gtk_tree_store_set(store, &iter, 0, "hb-canceled", -1);
121 case GHB_QUEUE_RUNNING:
122 gtk_tree_store_set(store, &iter, 0, "hb-working0", -1);
125 gtk_tree_store_set(store, &iter, 0, "hb-complete", -1);
128 gtk_tree_store_set(store, &iter, 0, "hb-queue-job", -1);
132 GString *str = g_string_new("");
134 gboolean preset_modified;
138 container = ghb_settings_combo_option(settings, "FileFormat");
139 mux = ghb_settings_combo_int(settings, "FileFormat");
140 preset_modified = ghb_settings_get_boolean(settings, "preset_modified");
141 path = ghb_settings_get_value(settings, "preset");
142 preset = ghb_preset_path_string(path);
143 markers = ghb_settings_get_boolean(settings, "ChapterMarkers");
146 g_string_append_printf(str,
147 "<b>Modified Preset Based On:</b> <small>%s</small>\n",
150 g_string_append_printf(str,
151 "<b>Preset:</b> <small>%s</small>\n",
156 g_string_append_printf(str,
157 "<b>Format:</b> <small>%s Container, Chapter Markers</small>\n",
162 g_string_append_printf(str,
163 "<b>Format:</b> <small>%s Container</small>\n", container);
165 if (mux == HB_MUX_MP4)
167 gboolean ipod, http, large;
169 ipod = ghb_settings_get_boolean(settings, "Mp4iPodCompatible");
170 http = ghb_settings_get_boolean(settings, "Mp4HttpOptimize");
171 large = ghb_settings_get_boolean(settings, "Mp4LargeFile");
172 if (http || ipod || large)
174 g_string_append_printf(str, "<b>MP4 Options:</b><small>");
176 g_string_append_printf(str, " - iPod 5G Support");
178 g_string_append_printf(str, " - Web Optimized");
180 g_string_append_printf(str, " - Large File Size (>4GB)");
181 g_string_append_printf(str, "</small>\n");
184 escape = g_markup_escape_text(dest, -1);
185 g_string_append_printf(str,
186 "<b>Destination:</b> <small>%s</small>\n", escape);
188 width = ghb_settings_get_int(settings, "scale_width");
189 height = ghb_settings_get_int(settings, "scale_height");
190 pic_par = ghb_settings_combo_int(settings, "PicturePAR");
191 keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");
200 aspect_desc = "(Aspect Preserved)";
204 aspect_desc = "(Aspect Lost)";
210 aspect_desc = "(Strict Anamorphic)";
215 aspect_desc = "(Loose Anamorphic)";
220 aspect_desc = "(Custom Anamorphic)";
225 aspect_desc = "(Unknown)";
228 vqtype = ghb_settings_get_boolean(settings, "vquality_type_constant");
230 gchar *vq_desc = "Error";
231 gchar *vq_units = "";
236 vqtype = ghb_settings_get_boolean(settings, "vquality_type_target");
240 vqvalue = ghb_settings_get_int(settings, "VideoAvgBitrate");
241 vq_desc = "Bitrate:";
247 vqvalue = ghb_settings_get_int(settings, "VideoTargetSize");
248 vq_desc = "Target Size:";
251 vqstr = g_strdup_printf("%d", (gint)vqvalue);
256 vqvalue = ghb_settings_get_double(settings, "VideoQualitySlider");
257 vq_desc = "Constant Quality:";
258 vqstr = g_strdup_printf("%d", (gint)vqvalue);
261 fps = ghb_settings_get_string(settings, "VideoFramerate");
262 if (strcmp("source", fps) == 0)
265 if (ghb_settings_combo_int(settings, "PictureDetelecine"))
266 fps = g_strdup("Same As Source (vfr detelecine)");
268 fps = g_strdup("Same As Source (variable)");
273 tmp = g_strdup_printf("%s (constant frame rate)", fps);
277 vcodec = ghb_settings_combo_option(settings, "VideoEncoder");
278 vcodec_abbr = ghb_settings_get_string(settings, "VideoEncoder");
279 source_width = ghb_settings_get_int(settings, "source_width");
280 source_height = ghb_settings_get_int(settings, "source_height");
281 g_string_append_printf(str,
282 "<b>Picture:</b> Source: <small>%d x %d, Output %d x %d %s</small>\n",
283 source_width, source_height, width, height, aspect_desc);
286 gboolean filters = FALSE;
288 decomb = ghb_settings_combo_int(settings, "PictureDecomb");
289 g_string_append_printf(str, "<b>Filters:</b><small>");
290 detel = ghb_settings_combo_int(settings, "PictureDetelecine");
293 g_string_append_printf(str, " - Detelecine");
297 cust = ghb_settings_get_string(settings, "PictureDetelecineCustom");
298 g_string_append_printf(str, ": %s", cust);
305 g_string_append_printf(str, " - Decomb");
309 cust = ghb_settings_get_string(settings, "PictureDecombCustom");
310 g_string_append_printf(str, ": %s", cust);
317 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
322 gchar *cust = ghb_settings_get_string(settings,
323 "PictureDeinterlaceCustom");
324 g_string_append_printf(str, " - Deinterlace: %s", cust);
329 const gchar *opt = ghb_settings_combo_option(settings,
330 "PictureDeinterlace");
331 g_string_append_printf(str, " - Deinterlace: %s", opt);
336 gint denoise = ghb_settings_combo_int(settings, "PictureDenoise");
341 gchar *cust = ghb_settings_get_string(settings,
342 "PictureDenoiseCustom");
343 g_string_append_printf(str, " - Denoise: %s", cust);
348 const gchar *opt = ghb_settings_combo_option(settings,
350 g_string_append_printf(str, " - Denoise: %s", opt);
354 gint deblock = ghb_settings_get_int(settings, "PictureDeblock");
357 g_string_append_printf(str, " - Deblock (%d)", deblock);
360 if (ghb_settings_get_boolean(settings, "VideoGrayScale"))
362 g_string_append_printf(str, " - Grayscale");
366 g_string_append_printf(str, " None");
367 g_string_append_printf(str, "</small>\n");
369 g_string_append_printf(str,
370 "<b>Video:</b> <small>%s, Framerate: %s, %s %s%s</small>\n",
371 vcodec, fps, vq_desc, vqstr, vq_units);
373 turbo = ghb_settings_get_boolean(settings, "VideoTurboTwoPass");
376 g_string_append_printf(str, "<b>Turbo:</b> <small>On</small>\n");
378 if (strcmp(vcodec_abbr, "x264") == 0)
380 gchar *x264opts = ghb_build_x264opts_string(settings);
381 g_string_append_printf(str,
382 "<b>x264 Options:</b> <small>%s</small>\n", x264opts);
387 const GValue *audio_list;
389 audio_list = ghb_settings_get_value(settings, "audio_list");
390 count = ghb_array_len(audio_list);
391 for (ii = 0; ii < count; ii++)
393 gchar *bitrate, *samplerate, *track;
394 const gchar *acodec, *mix;
397 asettings = ghb_array_get_nth(audio_list, ii);
399 acodec = ghb_settings_combo_option(asettings, "AudioEncoder");
400 bitrate = ghb_settings_get_string(asettings, "AudioBitrate");
401 samplerate = ghb_settings_get_string(asettings, "AudioSamplerate");
402 if (strcmp("source", samplerate) == 0)
405 samplerate = g_strdup("Same As Source");
407 track = ghb_settings_get_string(asettings, "AudioTrackDescription");
408 mix = ghb_settings_combo_option(asettings, "AudioMixdown");
409 g_string_append_printf(str,
410 "<b>Audio:</b><small> %s, Encoder: %s, Mixdown: %s, SampleRate: %s, Bitrate: %s</small>",
411 track, acodec, mix, samplerate, bitrate);
413 g_string_append_printf(str, "\n");
418 info = g_string_free(str, FALSE);
419 gtk_tree_store_append(store, &citer, &iter);
420 gtk_tree_store_set(store, &citer, 1, info, -1);
430 audio_list_refresh(signal_user_data_t *ud)
432 GtkTreeView *treeview;
437 const GValue *audio_list;
439 g_debug("ghb_audio_list_refresh ()");
440 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_list"));
441 store = GTK_LIST_STORE(gtk_tree_view_get_model(treeview));
442 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter))
446 const gchar *track, *codec, *br, *sr, *mix;
447 gchar *drc, *s_track, *s_codec, *s_br, *s_sr, *s_mix;
451 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
452 if (row >= ghb_array_len(audio_list))
454 asettings = ghb_array_get_nth(audio_list, row);
456 track = ghb_settings_combo_option(asettings, "AudioTrack");
457 codec = ghb_settings_combo_option(asettings, "AudioEncoder");
458 br = ghb_settings_combo_option(asettings, "AudioBitrate");
459 sr = ghb_settings_combo_option(asettings, "AudioSamplerate");
460 mix = ghb_settings_combo_option(asettings, "AudioMixdown");
462 s_track = ghb_settings_get_string(asettings, "AudioTrack");
463 s_codec = ghb_settings_get_string(asettings, "AudioEncoder");
464 s_br = ghb_settings_get_string(asettings, "AudioBitrate");
465 s_sr = ghb_settings_get_string(asettings, "AudioSamplerate");
466 s_mix = ghb_settings_get_string(asettings, "AudioMixdown");
467 s_drc = ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
469 drc = g_strdup("Off");
471 drc = g_strdup_printf("%.1f", s_drc);
473 gtk_list_store_set(GTK_LIST_STORE(store), &iter,
474 // These are displayed in list
481 // These are used to set combo values when an item is selected
495 done = !gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
502 validate_settings(signal_user_data_t *ud)
504 // Check to see if the dest file exists or is
505 // already in the queue
506 gchar *message, *dest;
510 titleindex = ghb_settings_combo_int(ud->settings, "title");
511 if (titleindex < 0) return FALSE;
512 dest = ghb_settings_get_string(ud->settings, "destination");
513 count = ghb_array_len(ud->queue);
514 for (ii = 0; ii < count; ii++)
519 js = ghb_array_get_nth(ud->queue, ii);
520 filename = ghb_settings_get_string(js, "destination");
521 if (strcmp(dest, filename) == 0)
523 message = g_strdup_printf(
524 "Destination: %s\n\n"
525 "Another queued job has specified the same destination.\n"
526 "Do you want to overwrite?",
528 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Overwrite"))
540 gchar *destdir = g_path_get_dirname(dest);
541 if (!g_file_test(destdir, G_FILE_TEST_IS_DIR))
543 message = g_strdup_printf(
544 "Destination: %s\n\n"
545 "This is not a valid directory.",
547 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
553 if (g_access(destdir, R_OK|W_OK) != 0)
555 message = g_strdup_printf(
556 "Destination: %s\n\n"
557 "Can not read or write the directory.",
559 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
568 gchar *resolved = ghb_resolve_symlink(destdir);
570 gfile = g_file_new_for_path(resolved);
571 info = g_file_query_filesystem_info(gfile,
572 G_FILE_ATTRIBUTE_FILESYSTEM_FREE, NULL, NULL);
575 if (g_file_info_has_attribute(info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE))
577 size = g_file_info_get_attribute_uint64(info,
578 G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
580 gint64 fsize = (guint64)10 * 1024 * 1024 * 1024;
583 message = g_strdup_printf(
584 "Destination filesystem is almost full: %uM free\n\n"
585 "Encode may be incomplete if you proceed.\n",
586 (guint)(size / (1024L*1024L)));
587 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Proceed"))
596 g_object_unref(info);
598 g_object_unref(gfile);
601 if (g_file_test(dest, G_FILE_TEST_EXISTS))
603 message = g_strdup_printf(
604 "Destination: %s\n\n"
605 "File already exists.\n"
606 "Do you want to overwrite?",
608 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Overwrite"))
618 // Validate video quality is in a reasonable range
619 if (!ghb_validate_vquality(ud->settings))
623 // Validate audio settings
624 if (!ghb_validate_audio(ud))
628 // Validate video settings
629 if (!ghb_validate_video(ud))
633 // Validate filter settings
634 if (!ghb_validate_filters(ud))
638 audio_list_refresh(ud);
643 queue_add(signal_user_data_t *ud)
645 // Add settings to the queue
650 g_debug("queue_add ()");
651 if (!validate_settings(ud))
658 si = GTK_STATUS_ICON(GHB_OBJECT(ud->builder, "hb_status"));
659 gtk_status_icon_set_from_icon_name(si, "hb-status");
661 if (ud->queue == NULL)
662 ud->queue = ghb_array_value_new(32);
663 // Make a copy of current settings to be used for the new job
664 settings = ghb_value_dup(ud->settings);
665 ghb_settings_set_int(settings, "job_status", GHB_QUEUE_PENDING);
666 ghb_settings_set_int(settings, "job_unique_id", 0);
667 titleindex = ghb_settings_combo_int(settings, "title");
668 titlenum = ghb_get_title_number(titleindex);
669 ghb_settings_set_int(settings, "titlenum", titlenum);
670 ghb_array_append(ud->queue, settings);
671 add_to_queue_list(ud, settings, NULL);
672 ghb_save_queue(ud->queue);
678 queue_add_clicked_cb(GtkWidget *widget, signal_user_data_t *ud)
680 g_debug("queue_add_clicked_cb ()");
685 queue_remove_clicked_cb(GtkWidget *widget, gchar *path, signal_user_data_t *ud)
687 GtkTreeView *treeview;
688 GtkTreePath *treepath;
697 g_debug("queue_remove_clicked_cb ()");
698 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
699 store = gtk_tree_view_get_model(treeview);
700 treepath = gtk_tree_path_new_from_string (path);
701 if (gtk_tree_path_get_depth(treepath) > 1) return;
702 if (gtk_tree_model_get_iter(store, &iter, treepath))
704 // Find the entry in the queue
705 indices = gtk_tree_path_get_indices (treepath);
707 // Can only free the treepath After getting what I need from
708 // indices since this points into treepath somewhere.
709 gtk_tree_path_free (treepath);
711 if (row >= ghb_array_len(ud->queue))
713 settings = ghb_array_get_nth(ud->queue, row);
714 status = ghb_settings_get_int(settings, "job_status");
715 if (status == GHB_QUEUE_RUNNING)
717 // Ask if wants to stop encode.
718 if (!ghb_cancel_encode(NULL))
722 unique_id = ghb_settings_get_int(settings, "job_unique_id");
723 ghb_remove_job(unique_id);
725 // Remove the selected item
726 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
727 // Remove the corresponding item from the queue list
728 GValue *old = ghb_array_get_nth(ud->queue, row);
730 ghb_array_remove(ud->queue, row);
731 ghb_save_queue(ud->queue);
735 gtk_tree_path_free (treepath);
740 find_last_finished(GValue *queue)
746 g_debug("find_last_finished");
747 count = ghb_array_len(queue);
748 for (ii = 0; ii < count; ii++)
750 js = ghb_array_get_nth(queue, ii);
751 status = ghb_settings_get_int(js, "job_status");
752 if (status != GHB_QUEUE_DONE && status != GHB_QUEUE_RUNNING)
760 // This little bit is needed to prevent the default drag motion
761 // handler from expanding rows if you hover over them while
763 // Also controls where valid drop locations are
765 queue_drag_motion_cb(
771 signal_user_data_t *ud)
773 GtkTreePath *path = NULL;
774 GtkTreeViewDropPosition pos;
775 gint *indices, row, status, finished;
780 GtkTreeSelection *select;
782 // This bit checks to see if the source is allowed to be
783 // moved. Only pending and canceled items may be moved.
784 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
785 select = gtk_tree_view_get_selection (srctv);
786 gtk_tree_selection_get_selected (select, &model, &iter);
787 path = gtk_tree_model_get_path (model, &iter);
788 indices = gtk_tree_path_get_indices(path);
790 gtk_tree_path_free(path);
791 js = ghb_array_get_nth(ud->queue, row);
792 status = ghb_settings_get_int(js, "job_status");
793 if (status != GHB_QUEUE_PENDING && status != GHB_QUEUE_CANCELED)
795 gdk_drag_status(ctx, 0, time);
799 // The reset checks that the destination is a valid position
800 // in the list. Can not move above any finished or running items
801 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &pos);
804 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
807 // Don't allow *drop into*
808 if (pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
809 pos = GTK_TREE_VIEW_DROP_BEFORE;
810 if (pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
811 pos = GTK_TREE_VIEW_DROP_AFTER;
812 // Don't allow droping int child items
813 if (gtk_tree_path_get_depth(path) > 1)
815 gtk_tree_path_up(path);
816 pos = GTK_TREE_VIEW_DROP_AFTER;
818 indices = gtk_tree_path_get_indices(path);
820 js = ghb_array_get_nth(ud->queue, row);
822 finished = find_last_finished(ud->queue);
825 gtk_tree_path_free(path);
826 gdk_drag_status(ctx, 0, time);
829 if (pos != GTK_TREE_VIEW_DROP_AFTER &&
832 gtk_tree_path_free(path);
833 gdk_drag_status(ctx, 0, time);
836 gtk_tree_view_set_drag_dest_row(tv, path, pos);
837 gtk_tree_path_free(path);
838 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
844 GtkTreeView *dstwidget,
847 GtkSelectionData *selection_data,
849 signal_user_data_t *ud)
851 GtkTreePath *path = NULL;
852 //GtkTreeModel *model;
853 GtkTreeViewDropPosition pos;
854 GtkTreeIter dstiter, srciter;
858 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
860 g_debug("queue_drag_cb ()");
861 // This doesn't work here for some reason...
862 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &pos);
863 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &pos);
864 // This little hack is needed because attempting to drop after
865 // the last item gives us no path or pos.
870 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
873 pos = GTK_TREE_VIEW_DROP_AFTER;
874 path = gtk_tree_path_new_from_indices(n_children-1, -1);
878 pos = GTK_TREE_VIEW_DROP_BEFORE;
879 path = gtk_tree_path_new_from_indices(0, -1);
884 if (gtk_tree_path_get_depth(path) > 1)
885 gtk_tree_path_up(path);
886 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
889 GtkTreeView *srcwidget;
890 GtkTreeModel *srcmodel;
891 GtkTreeSelection *select;
892 GtkTreePath *srcpath = NULL;
893 GtkTreePath *dstpath = NULL;
895 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
896 //srcmodel = gtk_tree_view_get_model(srcwidget);
897 select = gtk_tree_view_get_selection (srcwidget);
898 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
900 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
901 indices = gtk_tree_path_get_indices(srcpath);
903 gtk_tree_path_free(srcpath);
904 js = ghb_array_get_nth(ud->queue, row);
908 case GTK_TREE_VIEW_DROP_BEFORE:
909 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
910 gtk_tree_store_insert_before (GTK_TREE_STORE (dstmodel),
911 &iter, NULL, &dstiter);
914 case GTK_TREE_VIEW_DROP_AFTER:
915 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
916 gtk_tree_store_insert_after (GTK_TREE_STORE (dstmodel),
917 &iter, NULL, &dstiter);
923 // Reset job to pending
924 ghb_settings_set_int(js, "job_status", GHB_QUEUE_PENDING);
925 add_to_queue_list(ud, js, &iter);
927 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
928 indices = gtk_tree_path_get_indices(dstpath);
930 gtk_tree_path_free(dstpath);
931 ghb_array_insert(ud->queue, row, js);
933 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
934 indices = gtk_tree_path_get_indices(srcpath);
936 gtk_tree_path_free(srcpath);
937 ghb_array_remove(ud->queue, row);
938 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
939 ghb_save_queue(ud->queue);
941 gtk_tree_path_free(path);
946 ghb_queue_buttons_grey(signal_user_data_t *ud, gboolean working)
954 queue_count = ghb_array_len(ud->queue);
955 titleindex = ghb_settings_combo_int(ud->settings, "title");
956 title_ok = (titleindex >= 0);
958 widget = GHB_WIDGET (ud->builder, "queue_start1");
959 gtk_widget_set_sensitive (widget, !working && (title_ok || queue_count));
960 widget = GHB_WIDGET (ud->builder, "queue_start2");
961 gtk_widget_set_sensitive (widget, !working && (title_ok || queue_count));
962 action = GHB_ACTION (ud->builder, "queue_start_menu");
963 gtk_action_set_sensitive (action, !working && (title_ok || queue_count));
964 widget = GHB_WIDGET (ud->builder, "queue_pause1");
965 gtk_widget_set_sensitive (widget, working);
966 widget = GHB_WIDGET (ud->builder, "queue_pause2");
967 gtk_widget_set_sensitive (widget, working);
968 action = GHB_ACTION (ud->builder, "queue_pause_menu");
969 gtk_action_set_sensitive (action, working);
970 widget = GHB_WIDGET (ud->builder, "queue_stop");
971 gtk_widget_set_sensitive (widget, working);
972 action = GHB_ACTION (ud->builder, "queue_stop_menu");
973 gtk_action_set_sensitive (action, working);
977 queue_list_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, GtkCellRenderer *cell)
979 GtkTreeViewColumn *column;
982 column = gtk_tree_view_get_column (GTK_TREE_VIEW(widget), 0);
983 width = gtk_tree_view_column_get_width(column);
984 g_debug("col width %d alloc width %d", width, allocation->width);
985 // Set new wrap-width. Shave a little off to accomidate the icons
986 // that share this column.
987 if (width >= 564) // Don't allow below a certain size
988 g_object_set(cell, "wrap-width", width-70, NULL);
992 queue_start_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
995 gboolean running = FALSE;
1000 count = ghb_array_len(ud->queue);
1001 for (ii = 0; ii < count; ii++)
1003 js = ghb_array_get_nth(ud->queue, ii);
1004 status = ghb_settings_get_int(js, "job_status");
1005 if ((status == GHB_QUEUE_RUNNING) ||
1006 (status == GHB_QUEUE_PENDING))
1014 // The queue has no running or pending jobs.
1015 // Add current settings to the queue, then run.
1019 state = ghb_get_queue_state();
1020 if (state == GHB_STATE_IDLE)
1022 // Add the first pending queue item and start
1023 ud->current_job = ghb_start_next_job(ud, TRUE);
1028 queue_stop_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
1030 ud->cancel_encode = TRUE;
1031 ghb_cancel_encode(NULL);
1035 queue_pause_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
1041 ghb_reload_queue(signal_user_data_t *ud)
1044 gint unfinished = 0;
1050 g_debug("ghb_reload_queue");
1052 queue = ghb_load_queue();
1053 // Look for unfinished entries
1054 count = ghb_array_len(queue);
1055 for (ii = 0; ii < count; ii++)
1057 settings = ghb_array_get_nth(queue, ii);
1058 status = ghb_settings_get_int(settings, "job_status");
1059 if (status != GHB_QUEUE_DONE && status != GHB_QUEUE_CANCELED)
1066 message = g_strdup_printf(
1067 "You have %d unfinished job%s in a saved queue.\n\n"
1068 "Would you like to reload %s?",
1070 (unfinished > 1) ? "s" : "",
1071 (unfinished > 1) ? "them" : "it");
1072 if (ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "No", "Yes"))
1074 GtkWidget *widget = GHB_WIDGET (ud->builder, "queue_window");
1075 gtk_widget_show (widget);
1078 // First get rid of any old items we don't want
1079 for (ii = count-1; ii >= 0; ii--)
1081 settings = ghb_array_get_nth(queue, ii);
1082 status = ghb_settings_get_int(settings, "job_status");
1083 if (status == GHB_QUEUE_DONE || status == GHB_QUEUE_CANCELED)
1085 GValue *old = ghb_array_get_nth(queue, ii);
1086 ghb_value_free(old);
1087 ghb_array_remove(queue, ii);
1090 count = ghb_array_len(queue);
1091 for (ii = 0; ii < count; ii++)
1093 settings = ghb_array_get_nth(queue, ii);
1094 ghb_settings_set_int(settings, "job_unique_id", 0);
1095 ghb_settings_set_int(settings, "job_status", GHB_QUEUE_PENDING);
1096 add_to_queue_list(ud, settings, NULL);
1098 ghb_queue_buttons_grey(ud, FALSE);
1102 ghb_value_free(queue);
1103 ghb_remove_queue_file();
1114 signal_user_data_t *ud)
1116 GtkTreeView *treeview;
1117 GtkTreeSelection *selection;
1118 GtkTreeModel *store;
1126 g_debug("queue_key_press_cb ()");
1127 if (event->keyval != GDK_Delete)
1129 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
1130 store = gtk_tree_view_get_model(treeview);
1132 selection = gtk_tree_view_get_selection (treeview);
1133 if (gtk_tree_selection_get_selected(selection, &store, &iter))
1135 GtkTreePath *treepath;
1137 treepath = gtk_tree_model_get_path (store, &iter);
1138 // Find the entry in the queue
1139 indices = gtk_tree_path_get_indices (treepath);
1141 // Can only free the treepath After getting what I need from
1142 // indices since this points into treepath somewhere.
1143 gtk_tree_path_free (treepath);
1144 if (row < 0) return FALSE;
1145 if (row >= ghb_array_len(ud->queue))
1147 settings = ghb_array_get_nth(ud->queue, row);
1148 status = ghb_settings_get_int(settings, "job_status");
1149 if (status == GHB_QUEUE_RUNNING)
1151 // Ask if wants to stop encode.
1152 if (!ghb_cancel_encode(NULL))
1156 unique_id = ghb_settings_get_int(settings, "job_unique_id");
1157 ghb_remove_job(unique_id);
1159 // Remove the selected item
1160 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
1161 // Remove the corresponding item from the queue list
1162 GValue *old = ghb_array_get_nth(ud->queue, row);
1163 ghb_value_free(old);
1164 ghb_array_remove(ud->queue, row);
1165 ghb_save_queue(ud->queue);
1171 GValue *ghb_queue_edit_settings = NULL;
1174 queue_edit_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
1176 GtkTreeView *treeview;
1177 GtkTreeSelection *selection;
1178 GtkTreeModel *store;
1184 g_debug("queue_key_press_cb ()");
1185 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
1186 store = gtk_tree_view_get_model(treeview);
1188 selection = gtk_tree_view_get_selection (treeview);
1189 if (gtk_tree_selection_get_selected(selection, &store, &iter))
1191 GtkTreePath *treepath;
1193 treepath = gtk_tree_model_get_path (store, &iter);
1194 // Find the entry in the queue
1195 indices = gtk_tree_path_get_indices (treepath);
1197 // Can only free the treepath After getting what I need from
1198 // indices since this points into treepath somewhere.
1199 gtk_tree_path_free (treepath);
1200 if (row < 0) return;
1201 if (row >= ghb_array_len(ud->queue))
1203 ghb_queue_edit_settings = ghb_array_get_nth(ud->queue, row);
1204 status = ghb_settings_get_int(ghb_queue_edit_settings, "job_status");
1205 if (status == GHB_QUEUE_PENDING)
1207 // Remove the selected item
1208 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
1209 // Remove the corresponding item from the queue list
1210 ghb_array_remove(ud->queue, row);
1213 source = ghb_settings_get_string(ghb_queue_edit_settings, "source");
1214 ghb_do_scan(ud, source, 0, FALSE);