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_point, end_point, width, height;
74 gint source_width, source_height;
75 gboolean pass2 = FALSE, 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_point = ghb_settings_get_int(settings, "start_point");
88 end_point = ghb_settings_get_int(settings, "end_point");
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);
94 vqtype = ghb_settings_get_boolean(settings, "vquality_type_constant");
96 pass2 = ghb_settings_get_boolean(settings, "VideoTwoPass");
98 if (ghb_settings_combo_int(settings, "PtoPType") == 0)
100 else if (ghb_settings_combo_int(settings, "PtoPType") == 1)
102 else if (ghb_settings_combo_int(settings, "PtoPType") == 2)
104 info = g_strdup_printf
106 "<big><b>%s</b></big> "
107 "<small>(Title %d, %s %d through %d, %d Video %s)"
109 vol_name, title, points, start_point, end_point,
110 pass2 ? 2:1, pass2 ? "Passes":"Pass", escape
118 gtk_tree_store_append(store, &iter, NULL);
120 gtk_tree_store_set(store, &iter, 1, info, 2, "hb-queue-delete", -1);
122 status = ghb_settings_get_int(settings, "job_status");
125 case GHB_QUEUE_PENDING:
126 gtk_tree_store_set(store, &iter, 0, "hb-queue-job", -1);
128 case GHB_QUEUE_CANCELED:
129 gtk_tree_store_set(store, &iter, 0, "hb-canceled", -1);
131 case GHB_QUEUE_RUNNING:
132 gtk_tree_store_set(store, &iter, 0, "hb-working0", -1);
135 gtk_tree_store_set(store, &iter, 0, "hb-complete", -1);
138 gtk_tree_store_set(store, &iter, 0, "hb-queue-job", -1);
142 GString *str = g_string_new("");
144 gboolean preset_modified;
148 container = ghb_settings_combo_option(settings, "FileFormat");
149 mux = ghb_settings_combo_int(settings, "FileFormat");
150 preset_modified = ghb_settings_get_boolean(settings, "preset_modified");
151 path = ghb_settings_get_value(settings, "preset");
152 preset = ghb_preset_path_string(path);
153 markers = ghb_settings_get_boolean(settings, "ChapterMarkers");
156 g_string_append_printf(str,
157 "<b>Modified Preset Based On:</b> <small>%s</small>\n",
160 g_string_append_printf(str,
161 "<b>Preset:</b> <small>%s</small>\n",
166 g_string_append_printf(str,
167 "<b>Format:</b> <small>%s Container, Chapter Markers</small>\n",
172 g_string_append_printf(str,
173 "<b>Format:</b> <small>%s Container</small>\n", container);
175 if (mux == HB_MUX_MP4)
177 gboolean ipod, http, large;
179 ipod = ghb_settings_get_boolean(settings, "Mp4iPodCompatible");
180 http = ghb_settings_get_boolean(settings, "Mp4HttpOptimize");
181 large = ghb_settings_get_boolean(settings, "Mp4LargeFile");
182 if (http || ipod || large)
184 g_string_append_printf(str, "<b>MP4 Options:</b><small>");
186 g_string_append_printf(str, " - iPod 5G Support");
188 g_string_append_printf(str, " - Web Optimized");
190 g_string_append_printf(str, " - Large File Size (>4GB)");
191 g_string_append_printf(str, "</small>\n");
194 escape = g_markup_escape_text(dest, -1);
195 g_string_append_printf(str,
196 "<b>Destination:</b> <small>%s</small>\n", escape);
198 width = ghb_settings_get_int(settings, "scale_width");
199 height = ghb_settings_get_int(settings, "scale_height");
200 pic_par = ghb_settings_combo_int(settings, "PicturePAR");
201 keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");
210 aspect_desc = "(Aspect Preserved)";
214 aspect_desc = "(Aspect Lost)";
220 aspect_desc = "(Strict Anamorphic)";
225 aspect_desc = "(Loose Anamorphic)";
230 aspect_desc = "(Custom Anamorphic)";
235 aspect_desc = "(Unknown)";
238 vqtype = ghb_settings_get_boolean(settings, "vquality_type_constant");
240 gchar *vq_desc = "Error";
241 gchar *vq_units = "";
246 vqtype = ghb_settings_get_boolean(settings, "vquality_type_target");
250 vqvalue = ghb_settings_get_int(settings, "VideoAvgBitrate");
251 vq_desc = "Bitrate:";
257 vqvalue = ghb_settings_get_int(settings, "VideoTargetSize");
258 vq_desc = "Target Size:";
261 vqstr = g_strdup_printf("%d", (gint)vqvalue);
266 vqvalue = ghb_settings_get_double(settings, "VideoQualitySlider");
267 vq_desc = "Constant Quality:";
268 vqstr = g_strdup_printf("%d", (gint)vqvalue);
271 fps = ghb_settings_get_string(settings, "VideoFramerate");
272 if (strcmp("source", fps) == 0)
275 if (ghb_settings_combo_int(settings, "PictureDetelecine"))
276 fps = g_strdup("Same As Source (vfr detelecine)");
278 fps = g_strdup("Same As Source (variable)");
283 tmp = g_strdup_printf("%s (constant frame rate)", fps);
287 vcodec = ghb_settings_combo_option(settings, "VideoEncoder");
288 vcodec_abbr = ghb_settings_get_string(settings, "VideoEncoder");
289 source_width = ghb_settings_get_int(settings, "source_width");
290 source_height = ghb_settings_get_int(settings, "source_height");
291 g_string_append_printf(str,
292 "<b>Picture:</b> Source: <small>%d x %d, Output %d x %d %s</small>\n",
293 source_width, source_height, width, height, aspect_desc);
296 gboolean decomb_deint;
297 gboolean filters = FALSE;
299 decomb_deint = ghb_settings_get_boolean(settings, "PictureDecombDeinterlace");
300 decomb = ghb_settings_combo_int(settings, "PictureDecomb");
301 g_string_append_printf(str, "<b>Filters:</b><small>");
302 detel = ghb_settings_combo_int(settings, "PictureDetelecine");
305 g_string_append_printf(str, " - Detelecine");
309 cust = ghb_settings_get_string(settings, "PictureDetelecineCustom");
310 g_string_append_printf(str, ": %s", cust);
315 if (decomb_deint && decomb)
317 g_string_append_printf(str, " - Decomb");
321 cust = ghb_settings_get_string(settings, "PictureDecombCustom");
322 g_string_append_printf(str, ": %s", cust);
327 else if (!decomb_deint)
329 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
334 gchar *cust = ghb_settings_get_string(settings,
335 "PictureDeinterlaceCustom");
336 g_string_append_printf(str, " - Deinterlace: %s", cust);
341 const gchar *opt = ghb_settings_combo_option(settings,
342 "PictureDeinterlace");
343 g_string_append_printf(str, " - Deinterlace: %s", opt);
348 gint denoise = ghb_settings_combo_int(settings, "PictureDenoise");
353 gchar *cust = ghb_settings_get_string(settings,
354 "PictureDenoiseCustom");
355 g_string_append_printf(str, " - Denoise: %s", cust);
360 const gchar *opt = ghb_settings_combo_option(settings,
362 g_string_append_printf(str, " - Denoise: %s", opt);
366 gint deblock = ghb_settings_get_int(settings, "PictureDeblock");
369 g_string_append_printf(str, " - Deblock (%d)", deblock);
372 if (ghb_settings_get_boolean(settings, "VideoGrayScale"))
374 g_string_append_printf(str, " - Grayscale");
378 g_string_append_printf(str, " None");
379 g_string_append_printf(str, "</small>\n");
381 g_string_append_printf(str,
382 "<b>Video:</b> <small>%s, Framerate: %s, %s %s%s</small>\n",
383 vcodec, fps, vq_desc, vqstr, vq_units);
385 turbo = ghb_settings_get_boolean(settings, "VideoTurboTwoPass");
388 g_string_append_printf(str, "<b>Turbo:</b> <small>On</small>\n");
390 if (strcmp(vcodec_abbr, "x264") == 0)
392 gchar *x264opts = ghb_build_x264opts_string(settings);
393 g_string_append_printf(str,
394 "<b>x264 Options:</b> <small>%s</small>\n", x264opts);
399 const GValue *audio_list;
401 audio_list = ghb_settings_get_value(settings, "audio_list");
402 count = ghb_array_len(audio_list);
403 for (ii = 0; ii < count; ii++)
405 gchar *bitrate, *samplerate, *track;
406 const gchar *acodec, *mix;
409 asettings = ghb_array_get_nth(audio_list, ii);
411 acodec = ghb_settings_combo_option(asettings, "AudioEncoder");
412 bitrate = ghb_settings_get_string(asettings, "AudioBitrate");
413 samplerate = ghb_settings_get_string(asettings, "AudioSamplerate");
414 if (strcmp("source", samplerate) == 0)
417 samplerate = g_strdup("Same As Source");
419 track = ghb_settings_get_string(asettings, "AudioTrackDescription");
420 mix = ghb_settings_combo_option(asettings, "AudioMixdown");
422 g_string_append_printf(str, "<b>Audio:</b>");
424 g_string_append_printf(str, "<b>Audio:</b>\n");
426 g_string_append_printf(str, "\t");
428 g_string_append_printf(str,
429 "<small> %s, Encoder: %s, Mixdown: %s, SampleRate: %s, Bitrate: %s</small>\n",
430 track, acodec, mix, samplerate, bitrate);
437 const GValue *sub_list;
439 sub_list = ghb_settings_get_value(settings, "subtitle_list");
440 count = ghb_array_len(sub_list);
441 for (ii = 0; ii < count; ii++)
445 gboolean force, burn, def;
448 settings = ghb_array_get_nth(sub_list, ii);
449 track = ghb_settings_get_string(settings, "SubtitleTrackDescription");
450 source = ghb_settings_get_int(settings, "SubtitleSource");
451 force = ghb_settings_get_boolean(settings, "SubtitleForced");
452 burn = ghb_settings_get_boolean(settings, "SubtitleBurned");
453 def = ghb_settings_get_boolean(settings, "SubtitleDefaultTrack");
455 g_string_append_printf(str, "<b>Subtitle:</b>");
457 g_string_append_printf(str, "<b>Subtitles:</b>\n");
459 g_string_append_printf(str, "\t");
461 if (source != SRTSUB)
463 g_string_append_printf(str,
464 "<small> %s%s%s%s</small>",
466 force ? " (Force)":"",
468 def ? " (Default)":""
474 gchar *filename, *basename, *code;
476 offset = ghb_settings_get_int(settings, "SrtOffset");
477 filename = ghb_settings_get_string(settings, "SrtFile");
478 basename = g_path_get_basename(filename);
479 code = ghb_settings_get_string(settings, "SrtCodeset");
480 g_string_append_printf(str,
481 "<small> %s (%s), %s, Offset (ms) %d%s</small>",
482 track, code, basename, offset,
483 def ? " (Default)":""
490 g_string_append_printf(str, "\n");
494 info = g_string_free(str, FALSE);
495 gtk_tree_store_append(store, &citer, &iter);
496 gtk_tree_store_set(store, &citer, 1, info, -1);
506 audio_list_refresh(signal_user_data_t *ud)
508 GtkTreeView *treeview;
513 const GValue *audio_list;
515 g_debug("ghb_audio_list_refresh ()");
516 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_list"));
517 store = GTK_LIST_STORE(gtk_tree_view_get_model(treeview));
518 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter))
522 const gchar *track, *codec, *br, *sr, *mix;
523 gchar *drc, *s_track, *s_codec, *s_br, *s_sr, *s_mix;
528 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
529 if (row >= ghb_array_len(audio_list))
531 asettings = ghb_array_get_nth(audio_list, row);
533 track = ghb_settings_combo_option(asettings, "AudioTrack");
534 itrack = ghb_settings_combo_int(asettings, "AudioTrack");
535 codec = ghb_settings_combo_option(asettings, "AudioEncoder");
536 icodec = ghb_settings_combo_int(asettings, "AudioEncoder");
537 br = ghb_settings_combo_option(asettings, "AudioBitrate");
538 sr = ghb_settings_combo_option(asettings, "AudioSamplerate");
539 mix = ghb_settings_combo_option(asettings, "AudioMixdown");
541 s_track = ghb_settings_get_string(asettings, "AudioTrack");
542 s_codec = ghb_settings_get_string(asettings, "AudioEncoder");
543 s_br = ghb_settings_get_string(asettings, "AudioBitrate");
544 s_sr = ghb_settings_get_string(asettings, "AudioSamplerate");
545 s_mix = ghb_settings_get_string(asettings, "AudioMixdown");
546 s_drc = ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
548 drc = g_strdup("Off");
550 drc = g_strdup_printf("%.1f", s_drc);
552 if (icodec == HB_ACODEC_MASK)
553 codec = ghb_select_audio_codec_str(ud, itrack);
555 gtk_list_store_set(GTK_LIST_STORE(store), &iter,
556 // These are displayed in list
563 // These are used to set combo values when an item is selected
577 done = !gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
584 validate_settings(signal_user_data_t *ud)
586 // Check to see if the dest file exists or is
587 // already in the queue
588 gchar *message, *dest;
592 titleindex = ghb_settings_combo_int(ud->settings, "title");
593 if (titleindex < 0) return FALSE;
594 dest = ghb_settings_get_string(ud->settings, "destination");
595 count = ghb_array_len(ud->queue);
596 for (ii = 0; ii < count; ii++)
601 js = ghb_array_get_nth(ud->queue, ii);
602 filename = ghb_settings_get_string(js, "destination");
603 if (strcmp(dest, filename) == 0)
605 message = g_strdup_printf(
606 "Destination: %s\n\n"
607 "Another queued job has specified the same destination.\n"
608 "Do you want to overwrite?",
610 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Overwrite"))
622 gchar *destdir = g_path_get_dirname(dest);
623 if (!g_file_test(destdir, G_FILE_TEST_IS_DIR))
625 message = g_strdup_printf(
626 "Destination: %s\n\n"
627 "This is not a valid directory.",
629 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
636 // This doesn't work properly on windows
637 if (g_access(destdir, R_OK|W_OK) != 0)
639 message = g_strdup_printf(
640 "Destination: %s\n\n"
641 "Can not read or write the directory.",
643 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
653 gchar *resolved = ghb_resolve_symlink(destdir);
655 gfile = g_file_new_for_path(resolved);
656 info = g_file_query_filesystem_info(gfile,
657 G_FILE_ATTRIBUTE_FILESYSTEM_FREE, NULL, NULL);
660 if (g_file_info_has_attribute(info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE))
662 size = g_file_info_get_attribute_uint64(info,
663 G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
665 gint64 fsize = (guint64)10 * 1024 * 1024 * 1024;
668 message = g_strdup_printf(
669 "Destination filesystem is almost full: %uM free\n\n"
670 "Encode may be incomplete if you proceed.\n",
671 (guint)(size / (1024L*1024L)));
672 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Proceed"))
681 g_object_unref(info);
683 g_object_unref(gfile);
686 if (g_file_test(dest, G_FILE_TEST_EXISTS))
688 message = g_strdup_printf(
689 "Destination: %s\n\n"
690 "File already exists.\n"
691 "Do you want to overwrite?",
693 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Overwrite"))
703 // Validate video quality is in a reasonable range
704 if (!ghb_validate_vquality(ud->settings))
708 // Validate audio settings
709 if (!ghb_validate_audio(ud))
713 // Validate audio settings
714 if (!ghb_validate_subtitles(ud))
718 // Validate video settings
719 if (!ghb_validate_video(ud))
723 // Validate filter settings
724 if (!ghb_validate_filters(ud))
728 audio_list_refresh(ud);
733 queue_add(signal_user_data_t *ud)
735 // Add settings to the queue
740 g_debug("queue_add ()");
741 if (!validate_settings(ud))
746 if (ud->queue == NULL)
747 ud->queue = ghb_array_value_new(32);
748 // Make a copy of current settings to be used for the new job
749 settings = ghb_value_dup(ud->settings);
750 ghb_settings_set_int(settings, "job_status", GHB_QUEUE_PENDING);
751 ghb_settings_set_int(settings, "job_unique_id", 0);
752 titleindex = ghb_settings_combo_int(settings, "title");
753 titlenum = ghb_get_title_number(titleindex);
754 ghb_settings_set_int(settings, "titlenum", titlenum);
755 ghb_array_append(ud->queue, settings);
756 add_to_queue_list(ud, settings, NULL);
757 ghb_save_queue(ud->queue);
758 ghb_update_pending(ud);
764 queue_add_clicked_cb(GtkWidget *widget, signal_user_data_t *ud)
766 g_debug("queue_add_clicked_cb ()");
771 queue_remove_clicked_cb(GtkWidget *widget, gchar *path, signal_user_data_t *ud)
773 GtkTreeView *treeview;
774 GtkTreePath *treepath;
783 g_debug("queue_remove_clicked_cb ()");
784 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
785 store = gtk_tree_view_get_model(treeview);
786 treepath = gtk_tree_path_new_from_string (path);
787 if (gtk_tree_path_get_depth(treepath) > 1) return;
788 if (gtk_tree_model_get_iter(store, &iter, treepath))
790 // Find the entry in the queue
791 indices = gtk_tree_path_get_indices (treepath);
793 // Can only free the treepath After getting what I need from
794 // indices since this points into treepath somewhere.
795 gtk_tree_path_free (treepath);
797 if (row >= ghb_array_len(ud->queue))
799 settings = ghb_array_get_nth(ud->queue, row);
800 status = ghb_settings_get_int(settings, "job_status");
801 if (status == GHB_QUEUE_RUNNING)
803 // Ask if wants to stop encode.
804 if (!ghb_cancel_encode2(ud, NULL))
808 unique_id = ghb_settings_get_int(settings, "job_unique_id");
809 ghb_remove_job(unique_id);
811 // Remove the selected item
812 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
813 // Remove the corresponding item from the queue list
814 GValue *old = ghb_array_get_nth(ud->queue, row);
816 ghb_array_remove(ud->queue, row);
817 ghb_save_queue(ud->queue);
821 gtk_tree_path_free (treepath);
823 ghb_update_pending(ud);
827 find_last_finished(GValue *queue)
833 g_debug("find_last_finished");
834 count = ghb_array_len(queue);
835 for (ii = 0; ii < count; ii++)
837 js = ghb_array_get_nth(queue, ii);
838 status = ghb_settings_get_int(js, "job_status");
839 if (status != GHB_QUEUE_DONE && status != GHB_QUEUE_RUNNING)
847 // This little bit is needed to prevent the default drag motion
848 // handler from expanding rows if you hover over them while
850 // Also controls where valid drop locations are
851 G_MODULE_EXPORT gboolean
852 queue_drag_motion_cb(
858 signal_user_data_t *ud)
860 GtkTreePath *path = NULL;
861 GtkTreeViewDropPosition pos;
862 gint *indices, row, status, finished;
867 GtkTreeSelection *select;
870 widget = gtk_drag_get_source_widget(ctx);
871 if (widget == NULL || widget != GTK_WIDGET(tv))
874 // This bit checks to see if the source is allowed to be
875 // moved. Only pending and canceled items may be moved.
876 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
877 select = gtk_tree_view_get_selection (srctv);
878 gtk_tree_selection_get_selected (select, &model, &iter);
879 path = gtk_tree_model_get_path (model, &iter);
880 indices = gtk_tree_path_get_indices(path);
882 gtk_tree_path_free(path);
883 js = ghb_array_get_nth(ud->queue, row);
884 status = ghb_settings_get_int(js, "job_status");
885 if (status != GHB_QUEUE_PENDING && status != GHB_QUEUE_CANCELED)
887 gdk_drag_status(ctx, 0, time);
891 // The reset checks that the destination is a valid position
892 // in the list. Can not move above any finished or running items
893 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &pos);
896 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
899 // Don't allow *drop into*
900 if (pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
901 pos = GTK_TREE_VIEW_DROP_BEFORE;
902 if (pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
903 pos = GTK_TREE_VIEW_DROP_AFTER;
904 // Don't allow droping int child items
905 if (gtk_tree_path_get_depth(path) > 1)
907 gtk_tree_path_up(path);
908 pos = GTK_TREE_VIEW_DROP_AFTER;
910 indices = gtk_tree_path_get_indices(path);
912 js = ghb_array_get_nth(ud->queue, row);
914 finished = find_last_finished(ud->queue);
917 gtk_tree_path_free(path);
918 gdk_drag_status(ctx, 0, time);
921 if (pos != GTK_TREE_VIEW_DROP_AFTER &&
924 gtk_tree_path_free(path);
925 gdk_drag_status(ctx, 0, time);
928 gtk_tree_view_set_drag_dest_row(tv, path, pos);
929 gtk_tree_path_free(path);
930 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
936 GtkTreeView *dstwidget,
939 GtkSelectionData *selection_data,
941 signal_user_data_t *ud)
943 GtkTreePath *path = NULL;
944 //GtkTreeModel *model;
945 GtkTreeViewDropPosition pos;
946 GtkTreeIter dstiter, srciter;
950 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
952 g_debug("queue_drag_cb ()");
953 // This doesn't work here for some reason...
954 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &pos);
955 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &pos);
956 // This little hack is needed because attempting to drop after
957 // the last item gives us no path or pos.
962 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
965 pos = GTK_TREE_VIEW_DROP_AFTER;
966 path = gtk_tree_path_new_from_indices(n_children-1, -1);
970 pos = GTK_TREE_VIEW_DROP_BEFORE;
971 path = gtk_tree_path_new_from_indices(0, -1);
976 if (gtk_tree_path_get_depth(path) > 1)
977 gtk_tree_path_up(path);
978 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
981 GtkTreeView *srcwidget;
982 GtkTreeModel *srcmodel;
983 GtkTreeSelection *select;
984 GtkTreePath *srcpath = NULL;
985 GtkTreePath *dstpath = NULL;
987 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
988 //srcmodel = gtk_tree_view_get_model(srcwidget);
989 select = gtk_tree_view_get_selection (srcwidget);
990 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
992 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
993 indices = gtk_tree_path_get_indices(srcpath);
995 gtk_tree_path_free(srcpath);
996 js = ghb_array_get_nth(ud->queue, row);
1000 case GTK_TREE_VIEW_DROP_BEFORE:
1001 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
1002 gtk_tree_store_insert_before (GTK_TREE_STORE (dstmodel),
1003 &iter, NULL, &dstiter);
1006 case GTK_TREE_VIEW_DROP_AFTER:
1007 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
1008 gtk_tree_store_insert_after (GTK_TREE_STORE (dstmodel),
1009 &iter, NULL, &dstiter);
1015 // Reset job to pending
1016 ghb_settings_set_int(js, "job_status", GHB_QUEUE_PENDING);
1017 add_to_queue_list(ud, js, &iter);
1019 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
1020 indices = gtk_tree_path_get_indices(dstpath);
1022 gtk_tree_path_free(dstpath);
1023 ghb_array_insert(ud->queue, row, js);
1025 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
1026 indices = gtk_tree_path_get_indices(srcpath);
1028 gtk_tree_path_free(srcpath);
1029 ghb_array_remove(ud->queue, row);
1030 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
1031 ghb_save_queue(ud->queue);
1033 gtk_tree_path_free(path);
1038 ghb_queue_buttons_grey(signal_user_data_t *ud)
1044 gint queue_state, scan_state;
1045 gboolean show_start, show_stop, paused;
1047 queue_count = ghb_array_len(ud->queue);
1048 titleindex = ghb_settings_combo_int(ud->settings, "title");
1050 queue_state = ghb_get_queue_state();
1051 scan_state = ghb_get_scan_state();
1053 show_stop = queue_state &
1054 (GHB_STATE_WORKING | GHB_STATE_SEARCHING |
1055 GHB_STATE_SCANNING | GHB_STATE_MUXING);
1056 show_start = !(scan_state & GHB_STATE_SCANNING) &&
1057 (titleindex >= 0 || queue_count > 0);
1060 paused = queue_state & GHB_STATE_PAUSED;
1062 widget = GHB_WIDGET (ud->builder, "queue_start1");
1065 gtk_widget_set_sensitive (widget, TRUE);
1066 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-stop");
1067 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Stop");
1068 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Stop Encoding");
1072 gtk_widget_set_sensitive (widget, show_start);
1073 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-play");
1074 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Start");
1075 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Start Encoding");
1077 widget = GHB_WIDGET (ud->builder, "queue_start2");
1080 gtk_widget_set_sensitive (widget, TRUE);
1081 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-stop");
1082 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Stop");
1083 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Stop Encoding");
1087 gtk_widget_set_sensitive (widget, show_start);
1088 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-play");
1089 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Start");
1090 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Start Encoding");
1092 widget = GHB_WIDGET (ud->builder, "queue_pause1");
1095 gtk_widget_set_sensitive (widget, show_stop);
1096 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-play");
1097 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Resume");
1098 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Resume Encoding");
1102 gtk_widget_set_sensitive (widget, show_stop);
1103 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-pause");
1104 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Pause");
1105 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Pause Encoding");
1107 widget = GHB_WIDGET (ud->builder, "queue_pause2");
1110 gtk_widget_set_sensitive (widget, show_stop);
1111 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-play");
1112 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Resume");
1113 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Resume Encoding");
1117 gtk_widget_set_sensitive (widget, show_stop);
1118 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-pause");
1119 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Pause");
1120 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Pause Encoding");
1123 action = GHB_ACTION (ud->builder, "queue_start_menu");
1126 gtk_action_set_sensitive (action, TRUE);
1127 #if GTK_CHECK_VERSION(2, 16, 0)
1128 gtk_action_set_icon_name(action, "hb-stop");
1129 gtk_action_set_label(action, "S_top Queue");
1130 gtk_action_set_tooltip(action, "Stop Encoding");
1132 g_object_set_property(G_OBJECT(action), "icon-name",
1133 ghb_string_value("hb-stop"));
1134 g_object_set_property(G_OBJECT(action), "label",
1135 ghb_string_value("S_top Queue"));
1136 g_object_set_property(G_OBJECT(action), "tooltip",
1137 ghb_string_value("Stop Encoding"));
1142 gtk_action_set_sensitive (action, show_start);
1143 #if GTK_CHECK_VERSION(2, 16, 0)
1144 gtk_action_set_icon_name(action, "hb-play");
1145 gtk_action_set_label(action, "_Start Queue");
1146 gtk_action_set_tooltip(action, "Start Encoding");
1148 g_object_set_property(G_OBJECT(action), "icon-name",
1149 ghb_string_value("hb-play"));
1150 g_object_set_property(G_OBJECT(action), "label",
1151 ghb_string_value("_Start Queue"));
1152 g_object_set_property(G_OBJECT(action), "tooltip",
1153 ghb_string_value("Start Encoding"));
1156 action = GHB_ACTION (ud->builder, "queue_pause_menu");
1159 gtk_action_set_sensitive (action, show_start);
1160 #if GTK_CHECK_VERSION(2, 16, 0)
1161 gtk_action_set_icon_name(action, "hb-play");
1162 gtk_action_set_label(action, "_Resume Queue");
1163 gtk_action_set_tooltip(action, "Resume Encoding");
1165 g_object_set_property(G_OBJECT(action), "icon-name",
1166 ghb_string_value("hb-play"));
1167 g_object_set_property(G_OBJECT(action), "label",
1168 ghb_string_value("_Resume Queue"));
1169 g_object_set_property(G_OBJECT(action), "tooltip",
1170 ghb_string_value("Resume Encoding"));
1175 gtk_action_set_sensitive (action, show_stop);
1176 #if GTK_CHECK_VERSION(2, 16, 0)
1177 gtk_action_set_icon_name(action, "hb-pause");
1178 gtk_action_set_label(action, "_Pause Queue");
1179 gtk_action_set_tooltip(action, "Pause Encoding");
1181 g_object_set_property(G_OBJECT(action), "icon-name",
1182 ghb_string_value("hb-pause"));
1183 g_object_set_property(G_OBJECT(action), "label",
1184 ghb_string_value("_Pause Queue"));
1185 g_object_set_property(G_OBJECT(action), "tooltip",
1186 ghb_string_value("Pause Encoding"));
1191 G_MODULE_EXPORT void
1192 queue_list_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, GtkCellRenderer *cell)
1194 GtkTreeViewColumn *column;
1197 column = gtk_tree_view_get_column (GTK_TREE_VIEW(widget), 0);
1198 width = gtk_tree_view_column_get_width(column);
1199 g_debug("col width %d alloc width %d", width, allocation->width);
1200 // Set new wrap-width. Shave a little off to accomidate the icons
1201 // that share this column.
1202 if (width >= 564) // Don't allow below a certain size
1203 g_object_set(cell, "wrap-width", width-70, NULL);
1206 G_MODULE_EXPORT void
1207 queue_start_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
1210 gboolean running = FALSE;
1215 state = ghb_get_queue_state();
1216 if (state & (GHB_STATE_WORKING | GHB_STATE_SEARCHING |
1217 GHB_STATE_SCANNING | GHB_STATE_MUXING))
1219 ghb_cancel_encode(ud, "You are currently encoding. "
1220 "What would you like to do?");
1224 count = ghb_array_len(ud->queue);
1225 for (ii = 0; ii < count; ii++)
1227 js = ghb_array_get_nth(ud->queue, ii);
1228 status = ghb_settings_get_int(js, "job_status");
1229 if ((status == GHB_QUEUE_RUNNING) ||
1230 (status == GHB_QUEUE_PENDING))
1238 // The queue has no running or pending jobs.
1239 // Add current settings to the queue, then run.
1243 if (state == GHB_STATE_IDLE)
1245 // Add the first pending queue item and start
1246 ud->current_job = ghb_start_next_job(ud, TRUE);
1250 G_MODULE_EXPORT void
1251 queue_pause_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
1257 ghb_reload_queue(signal_user_data_t *ud)
1260 gint unfinished = 0;
1266 g_debug("ghb_reload_queue");
1268 queue = ghb_load_queue();
1269 // Look for unfinished entries
1270 count = ghb_array_len(queue);
1271 for (ii = 0; ii < count; ii++)
1273 settings = ghb_array_get_nth(queue, ii);
1274 status = ghb_settings_get_int(settings, "job_status");
1275 if (status != GHB_QUEUE_DONE && status != GHB_QUEUE_CANCELED)
1282 message = g_strdup_printf(
1283 "You have %d unfinished job%s in a saved queue.\n\n"
1284 "Would you like to reload %s?",
1286 (unfinished > 1) ? "s" : "",
1287 (unfinished > 1) ? "them" : "it");
1288 if (ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "No", "Yes"))
1290 GtkWidget *widget = GHB_WIDGET (ud->builder, "queue_window");
1291 gtk_widget_show (widget);
1292 widget = GHB_WIDGET (ud->builder, "show_queue");
1293 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(widget), TRUE);
1296 // First get rid of any old items we don't want
1297 for (ii = count-1; ii >= 0; ii--)
1299 settings = ghb_array_get_nth(queue, ii);
1300 status = ghb_settings_get_int(settings, "job_status");
1301 if (status == GHB_QUEUE_DONE || status == GHB_QUEUE_CANCELED)
1303 GValue *old = ghb_array_get_nth(queue, ii);
1304 ghb_value_free(old);
1305 ghb_array_remove(queue, ii);
1308 count = ghb_array_len(queue);
1309 for (ii = 0; ii < count; ii++)
1311 settings = ghb_array_get_nth(queue, ii);
1312 ghb_settings_set_int(settings, "job_unique_id", 0);
1313 ghb_settings_set_int(settings, "job_status", GHB_QUEUE_PENDING);
1314 add_to_queue_list(ud, settings, NULL);
1316 ghb_queue_buttons_grey(ud);
1320 ghb_value_free(queue);
1321 ghb_remove_queue_file();
1328 G_MODULE_EXPORT gboolean
1332 signal_user_data_t *ud)
1334 GtkTreeView *treeview;
1335 GtkTreeSelection *selection;
1336 GtkTreeModel *store;
1344 g_debug("queue_key_press_cb ()");
1345 if (event->keyval != GDK_Delete)
1347 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
1348 store = gtk_tree_view_get_model(treeview);
1350 selection = gtk_tree_view_get_selection (treeview);
1351 if (gtk_tree_selection_get_selected(selection, &store, &iter))
1353 GtkTreePath *treepath;
1355 treepath = gtk_tree_model_get_path (store, &iter);
1356 // Find the entry in the queue
1357 indices = gtk_tree_path_get_indices (treepath);
1359 // Can only free the treepath After getting what I need from
1360 // indices since this points into treepath somewhere.
1361 gtk_tree_path_free (treepath);
1362 if (row < 0) return FALSE;
1363 if (row >= ghb_array_len(ud->queue))
1365 settings = ghb_array_get_nth(ud->queue, row);
1366 status = ghb_settings_get_int(settings, "job_status");
1367 if (status == GHB_QUEUE_RUNNING)
1369 // Ask if wants to stop encode.
1370 if (!ghb_cancel_encode2(ud, NULL))
1374 unique_id = ghb_settings_get_int(settings, "job_unique_id");
1375 ghb_remove_job(unique_id);
1377 // Remove the selected item
1378 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
1379 // Remove the corresponding item from the queue list
1380 GValue *old = ghb_array_get_nth(ud->queue, row);
1381 ghb_value_free(old);
1382 ghb_array_remove(ud->queue, row);
1383 ghb_save_queue(ud->queue);
1389 GValue *ghb_queue_edit_settings = NULL;
1391 G_MODULE_EXPORT void
1392 queue_edit_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
1394 GtkTreeView *treeview;
1395 GtkTreeSelection *selection;
1396 GtkTreeModel *store;
1402 g_debug("queue_key_press_cb ()");
1403 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
1404 store = gtk_tree_view_get_model(treeview);
1406 selection = gtk_tree_view_get_selection (treeview);
1407 if (gtk_tree_selection_get_selected(selection, &store, &iter))
1409 GtkTreePath *treepath;
1411 treepath = gtk_tree_model_get_path (store, &iter);
1412 // Find the entry in the queue
1413 indices = gtk_tree_path_get_indices (treepath);
1415 // Can only free the treepath After getting what I need from
1416 // indices since this points into treepath somewhere.
1417 gtk_tree_path_free (treepath);
1418 if (row < 0) return;
1419 if (row >= ghb_array_len(ud->queue))
1421 ghb_queue_edit_settings = ghb_array_get_nth(ud->queue, row);
1422 status = ghb_settings_get_int(ghb_queue_edit_settings, "job_status");
1423 if (status == GHB_QUEUE_PENDING)
1425 // Remove the selected item
1426 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
1427 // Remove the corresponding item from the queue list
1428 ghb_array_remove(ud->queue, row);
1432 ghb_queue_edit_settings = ghb_value_dup(ghb_queue_edit_settings);
1435 source = ghb_settings_get_string(ghb_queue_edit_settings, "source");
1436 ghb_do_scan(ud, source, 0, FALSE);