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");
97 const gchar *points = "Chapters";
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;
410 asettings = ghb_array_get_nth(audio_list, ii);
412 acodec = ghb_settings_combo_option(asettings, "AudioEncoder");
413 bitrate = ghb_settings_get_string(asettings, "AudioBitrate");
414 sr = ghb_settings_get_double(asettings, "AudioSamplerate");
415 samplerate = ghb_settings_get_string(asettings, "AudioSamplerate");
418 samplerate = g_strdup("Same As Source");
422 samplerate = g_strdup_printf("%.4g", sr);
424 track = ghb_settings_get_string(asettings, "AudioTrackDescription");
425 mix = ghb_settings_combo_option(asettings, "AudioMixdown");
427 g_string_append_printf(str, "<b>Audio:</b>");
429 g_string_append_printf(str, "<b>Audio:</b>\n");
431 g_string_append_printf(str, "\t");
433 g_string_append_printf(str,
434 "<small> %s, Encoder: %s, Mixdown: %s, SampleRate: %s, Bitrate: %s</small>\n",
435 track, acodec, mix, samplerate, bitrate);
442 const GValue *sub_list;
444 sub_list = ghb_settings_get_value(settings, "subtitle_list");
445 count = ghb_array_len(sub_list);
446 for (ii = 0; ii < count; ii++)
450 gboolean force, burn, def;
453 settings = ghb_array_get_nth(sub_list, ii);
454 track = ghb_settings_get_string(settings, "SubtitleTrackDescription");
455 source = ghb_settings_get_int(settings, "SubtitleSource");
456 force = ghb_settings_get_boolean(settings, "SubtitleForced");
457 burn = ghb_settings_get_boolean(settings, "SubtitleBurned");
458 def = ghb_settings_get_boolean(settings, "SubtitleDefaultTrack");
460 g_string_append_printf(str, "<b>Subtitle:</b>");
462 g_string_append_printf(str, "<b>Subtitles:</b>\n");
464 g_string_append_printf(str, "\t");
466 if (source != SRTSUB)
468 g_string_append_printf(str,
469 "<small> %s%s%s%s</small>",
471 force ? " (Force)":"",
473 def ? " (Default)":""
479 gchar *filename, *basename, *code;
481 offset = ghb_settings_get_int(settings, "SrtOffset");
482 filename = ghb_settings_get_string(settings, "SrtFile");
483 basename = g_path_get_basename(filename);
484 code = ghb_settings_get_string(settings, "SrtCodeset");
485 g_string_append_printf(str,
486 "<small> %s (%s), %s, Offset (ms) %d%s</small>",
487 track, code, basename, offset,
488 def ? " (Default)":""
495 g_string_append_printf(str, "\n");
499 info = g_string_free(str, FALSE);
500 gtk_tree_store_append(store, &citer, &iter);
501 gtk_tree_store_set(store, &citer, 1, info, -1);
511 audio_list_refresh(signal_user_data_t *ud)
513 GtkTreeView *treeview;
518 const GValue *audio_list;
520 g_debug("ghb_audio_list_refresh ()");
521 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_list"));
522 store = GTK_LIST_STORE(gtk_tree_view_get_model(treeview));
523 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter))
527 const gchar *track, *codec, *br, *sr, *mix;
533 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
534 if (row >= ghb_array_len(audio_list))
536 asettings = ghb_array_get_nth(audio_list, row);
538 track = ghb_settings_combo_option(asettings, "AudioTrack");
539 itrack = ghb_settings_combo_int(asettings, "AudioTrack");
540 codec = ghb_settings_combo_option(asettings, "AudioEncoder");
541 icodec = ghb_settings_combo_int(asettings, "AudioEncoder");
542 br = ghb_settings_combo_option(asettings, "AudioBitrate");
543 sr = ghb_settings_combo_option(asettings, "AudioSamplerate");
544 mix = ghb_settings_combo_option(asettings, "AudioMixdown");
546 drc = ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
548 s_drc = g_strdup("Off");
550 s_drc = g_strdup_printf("%.1f", 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
565 done = !gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
572 validate_settings(signal_user_data_t *ud)
574 // Check to see if the dest file exists or is
575 // already in the queue
576 gchar *message, *dest;
580 titleindex = ghb_settings_combo_int(ud->settings, "title");
581 if (titleindex < 0) return FALSE;
582 dest = ghb_settings_get_string(ud->settings, "destination");
583 count = ghb_array_len(ud->queue);
584 for (ii = 0; ii < count; ii++)
589 js = ghb_array_get_nth(ud->queue, ii);
590 filename = ghb_settings_get_string(js, "destination");
591 if (strcmp(dest, filename) == 0)
593 message = g_strdup_printf(
594 "Destination: %s\n\n"
595 "Another queued job has specified the same destination.\n"
596 "Do you want to overwrite?",
598 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Overwrite"))
610 gchar *destdir = g_path_get_dirname(dest);
611 if (!g_file_test(destdir, G_FILE_TEST_IS_DIR))
613 message = g_strdup_printf(
614 "Destination: %s\n\n"
615 "This is not a valid directory.",
617 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
624 // This doesn't work properly on windows
625 if (g_access(destdir, R_OK|W_OK) != 0)
627 message = g_strdup_printf(
628 "Destination: %s\n\n"
629 "Can not read or write the directory.",
631 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
641 gchar *resolved = ghb_resolve_symlink(destdir);
643 gfile = g_file_new_for_path(resolved);
644 info = g_file_query_filesystem_info(gfile,
645 G_FILE_ATTRIBUTE_FILESYSTEM_FREE, NULL, NULL);
648 if (g_file_info_has_attribute(info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE))
650 size = g_file_info_get_attribute_uint64(info,
651 G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
653 gint64 fsize = (guint64)10 * 1024 * 1024 * 1024;
656 message = g_strdup_printf(
657 "Destination filesystem is almost full: %uM free\n\n"
658 "Encode may be incomplete if you proceed.\n",
659 (guint)(size / (1024L*1024L)));
660 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Proceed"))
669 g_object_unref(info);
671 g_object_unref(gfile);
674 if (g_file_test(dest, G_FILE_TEST_EXISTS))
676 message = g_strdup_printf(
677 "Destination: %s\n\n"
678 "File already exists.\n"
679 "Do you want to overwrite?",
681 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Overwrite"))
691 // Validate video quality is in a reasonable range
692 if (!ghb_validate_vquality(ud->settings))
696 // Validate audio settings
697 if (!ghb_validate_audio(ud))
701 // Validate audio settings
702 if (!ghb_validate_subtitles(ud))
706 // Validate video settings
707 if (!ghb_validate_video(ud))
711 // Validate filter settings
712 if (!ghb_validate_filters(ud))
716 audio_list_refresh(ud);
721 queue_add(signal_user_data_t *ud)
723 // Add settings to the queue
728 g_debug("queue_add ()");
729 if (!validate_settings(ud))
734 if (ud->queue == NULL)
735 ud->queue = ghb_array_value_new(32);
736 // Make a copy of current settings to be used for the new job
737 settings = ghb_value_dup(ud->settings);
738 ghb_settings_set_int(settings, "job_status", GHB_QUEUE_PENDING);
739 ghb_settings_set_int(settings, "job_unique_id", 0);
740 titleindex = ghb_settings_combo_int(settings, "title");
741 titlenum = ghb_get_title_number(titleindex);
742 ghb_settings_set_int(settings, "titlenum", titlenum);
743 ghb_array_append(ud->queue, settings);
744 add_to_queue_list(ud, settings, NULL);
745 ghb_save_queue(ud->queue);
746 ghb_update_pending(ud);
752 queue_add_clicked_cb(GtkWidget *widget, signal_user_data_t *ud)
754 g_debug("queue_add_clicked_cb ()");
759 queue_remove_clicked_cb(GtkWidget *widget, gchar *path, signal_user_data_t *ud)
761 GtkTreeView *treeview;
762 GtkTreePath *treepath;
771 g_debug("queue_remove_clicked_cb ()");
772 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
773 store = gtk_tree_view_get_model(treeview);
774 treepath = gtk_tree_path_new_from_string (path);
775 if (gtk_tree_path_get_depth(treepath) > 1) return;
776 if (gtk_tree_model_get_iter(store, &iter, treepath))
778 // Find the entry in the queue
779 indices = gtk_tree_path_get_indices (treepath);
781 // Can only free the treepath After getting what I need from
782 // indices since this points into treepath somewhere.
783 gtk_tree_path_free (treepath);
785 if (row >= ghb_array_len(ud->queue))
787 settings = ghb_array_get_nth(ud->queue, row);
788 status = ghb_settings_get_int(settings, "job_status");
789 if (status == GHB_QUEUE_RUNNING)
791 // Ask if wants to stop encode.
792 if (!ghb_cancel_encode2(ud, NULL))
796 unique_id = ghb_settings_get_int(settings, "job_unique_id");
797 ghb_remove_job(unique_id);
799 // Remove the selected item
800 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
801 // Remove the corresponding item from the queue list
802 GValue *old = ghb_array_get_nth(ud->queue, row);
804 ghb_array_remove(ud->queue, row);
805 ghb_save_queue(ud->queue);
809 gtk_tree_path_free (treepath);
811 ghb_update_pending(ud);
815 find_last_finished(GValue *queue)
821 g_debug("find_last_finished");
822 count = ghb_array_len(queue);
823 for (ii = 0; ii < count; ii++)
825 js = ghb_array_get_nth(queue, ii);
826 status = ghb_settings_get_int(js, "job_status");
827 if (status != GHB_QUEUE_DONE && status != GHB_QUEUE_RUNNING)
835 // This little bit is needed to prevent the default drag motion
836 // handler from expanding rows if you hover over them while
838 // Also controls where valid drop locations are
839 G_MODULE_EXPORT gboolean
840 queue_drag_motion_cb(
846 signal_user_data_t *ud)
848 GtkTreePath *path = NULL;
849 GtkTreeViewDropPosition pos;
850 gint *indices, row, status, finished;
855 GtkTreeSelection *select;
858 widget = gtk_drag_get_source_widget(ctx);
859 if (widget == NULL || widget != GTK_WIDGET(tv))
862 // This bit checks to see if the source is allowed to be
863 // moved. Only pending and canceled items may be moved.
864 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
865 select = gtk_tree_view_get_selection (srctv);
866 gtk_tree_selection_get_selected (select, &model, &iter);
867 path = gtk_tree_model_get_path (model, &iter);
868 indices = gtk_tree_path_get_indices(path);
870 gtk_tree_path_free(path);
871 js = ghb_array_get_nth(ud->queue, row);
872 status = ghb_settings_get_int(js, "job_status");
873 if (status != GHB_QUEUE_PENDING && status != GHB_QUEUE_CANCELED)
875 gdk_drag_status(ctx, 0, time);
879 // The reset checks that the destination is a valid position
880 // in the list. Can not move above any finished or running items
881 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &pos);
884 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
887 // Don't allow *drop into*
888 if (pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
889 pos = GTK_TREE_VIEW_DROP_BEFORE;
890 if (pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
891 pos = GTK_TREE_VIEW_DROP_AFTER;
892 // Don't allow droping int child items
893 if (gtk_tree_path_get_depth(path) > 1)
895 gtk_tree_path_up(path);
896 pos = GTK_TREE_VIEW_DROP_AFTER;
898 indices = gtk_tree_path_get_indices(path);
900 js = ghb_array_get_nth(ud->queue, row);
902 finished = find_last_finished(ud->queue);
905 gtk_tree_path_free(path);
906 gdk_drag_status(ctx, 0, time);
909 if (pos != GTK_TREE_VIEW_DROP_AFTER &&
912 gtk_tree_path_free(path);
913 gdk_drag_status(ctx, 0, time);
916 gtk_tree_view_set_drag_dest_row(tv, path, pos);
917 gtk_tree_path_free(path);
918 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
924 GtkTreeView *dstwidget,
927 GtkSelectionData *selection_data,
929 signal_user_data_t *ud)
931 GtkTreePath *path = NULL;
932 //GtkTreeModel *model;
933 GtkTreeViewDropPosition pos;
934 GtkTreeIter dstiter, srciter;
938 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
940 g_debug("queue_drag_cb ()");
941 // This doesn't work here for some reason...
942 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &pos);
943 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &pos);
944 // This little hack is needed because attempting to drop after
945 // the last item gives us no path or pos.
950 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
953 pos = GTK_TREE_VIEW_DROP_AFTER;
954 path = gtk_tree_path_new_from_indices(n_children-1, -1);
958 pos = GTK_TREE_VIEW_DROP_BEFORE;
959 path = gtk_tree_path_new_from_indices(0, -1);
964 if (gtk_tree_path_get_depth(path) > 1)
965 gtk_tree_path_up(path);
966 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
969 GtkTreeView *srcwidget;
970 GtkTreeModel *srcmodel;
971 GtkTreeSelection *select;
972 GtkTreePath *srcpath = NULL;
973 GtkTreePath *dstpath = NULL;
975 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
976 //srcmodel = gtk_tree_view_get_model(srcwidget);
977 select = gtk_tree_view_get_selection (srcwidget);
978 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
980 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
981 indices = gtk_tree_path_get_indices(srcpath);
983 gtk_tree_path_free(srcpath);
984 js = ghb_array_get_nth(ud->queue, row);
988 case GTK_TREE_VIEW_DROP_BEFORE:
989 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
990 gtk_tree_store_insert_before (GTK_TREE_STORE (dstmodel),
991 &iter, NULL, &dstiter);
994 case GTK_TREE_VIEW_DROP_AFTER:
995 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
996 gtk_tree_store_insert_after (GTK_TREE_STORE (dstmodel),
997 &iter, NULL, &dstiter);
1003 // Reset job to pending
1004 ghb_settings_set_int(js, "job_status", GHB_QUEUE_PENDING);
1005 add_to_queue_list(ud, js, &iter);
1007 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
1008 indices = gtk_tree_path_get_indices(dstpath);
1010 gtk_tree_path_free(dstpath);
1011 ghb_array_insert(ud->queue, row, js);
1013 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
1014 indices = gtk_tree_path_get_indices(srcpath);
1016 gtk_tree_path_free(srcpath);
1017 ghb_array_remove(ud->queue, row);
1018 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
1019 ghb_save_queue(ud->queue);
1021 gtk_tree_path_free(path);
1026 ghb_queue_buttons_grey(signal_user_data_t *ud)
1032 gint queue_state, scan_state;
1033 gboolean show_start, show_stop, paused;
1035 queue_count = ghb_array_len(ud->queue);
1036 titleindex = ghb_settings_combo_int(ud->settings, "title");
1038 queue_state = ghb_get_queue_state();
1039 scan_state = ghb_get_scan_state();
1041 show_stop = queue_state &
1042 (GHB_STATE_WORKING | GHB_STATE_SEARCHING |
1043 GHB_STATE_SCANNING | GHB_STATE_MUXING);
1044 show_start = !(scan_state & GHB_STATE_SCANNING) &&
1045 (titleindex >= 0 || queue_count > 0);
1048 paused = queue_state & GHB_STATE_PAUSED;
1050 widget = GHB_WIDGET (ud->builder, "queue_start1");
1053 gtk_widget_set_sensitive (widget, TRUE);
1054 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-stop");
1055 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Stop");
1056 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Stop Encoding");
1060 gtk_widget_set_sensitive (widget, show_start);
1061 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-play");
1062 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Start");
1063 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Start Encoding");
1065 widget = GHB_WIDGET (ud->builder, "queue_start2");
1068 gtk_widget_set_sensitive (widget, TRUE);
1069 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-stop");
1070 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Stop");
1071 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Stop Encoding");
1075 gtk_widget_set_sensitive (widget, show_start);
1076 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-play");
1077 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Start");
1078 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Start Encoding");
1080 widget = GHB_WIDGET (ud->builder, "queue_pause1");
1083 gtk_widget_set_sensitive (widget, show_stop);
1084 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-play");
1085 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Resume");
1086 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Resume Encoding");
1090 gtk_widget_set_sensitive (widget, show_stop);
1091 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-pause");
1092 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Pause");
1093 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Pause Encoding");
1095 widget = GHB_WIDGET (ud->builder, "queue_pause2");
1098 gtk_widget_set_sensitive (widget, show_stop);
1099 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-play");
1100 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Resume");
1101 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Resume Encoding");
1105 gtk_widget_set_sensitive (widget, show_stop);
1106 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-pause");
1107 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Pause");
1108 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Pause Encoding");
1111 action = GHB_ACTION (ud->builder, "queue_start_menu");
1114 gtk_action_set_sensitive (action, TRUE);
1115 #if GTK_CHECK_VERSION(2, 16, 0)
1116 gtk_action_set_icon_name(action, "hb-stop");
1117 gtk_action_set_label(action, "S_top Queue");
1118 gtk_action_set_tooltip(action, "Stop Encoding");
1120 g_object_set_property(G_OBJECT(action), "icon-name",
1121 ghb_string_value("hb-stop"));
1122 g_object_set_property(G_OBJECT(action), "label",
1123 ghb_string_value("S_top Queue"));
1124 g_object_set_property(G_OBJECT(action), "tooltip",
1125 ghb_string_value("Stop Encoding"));
1130 gtk_action_set_sensitive (action, show_start);
1131 #if GTK_CHECK_VERSION(2, 16, 0)
1132 gtk_action_set_icon_name(action, "hb-play");
1133 gtk_action_set_label(action, "_Start Queue");
1134 gtk_action_set_tooltip(action, "Start Encoding");
1136 g_object_set_property(G_OBJECT(action), "icon-name",
1137 ghb_string_value("hb-play"));
1138 g_object_set_property(G_OBJECT(action), "label",
1139 ghb_string_value("_Start Queue"));
1140 g_object_set_property(G_OBJECT(action), "tooltip",
1141 ghb_string_value("Start Encoding"));
1144 action = GHB_ACTION (ud->builder, "queue_pause_menu");
1147 gtk_action_set_sensitive (action, show_start);
1148 #if GTK_CHECK_VERSION(2, 16, 0)
1149 gtk_action_set_icon_name(action, "hb-play");
1150 gtk_action_set_label(action, "_Resume Queue");
1151 gtk_action_set_tooltip(action, "Resume Encoding");
1153 g_object_set_property(G_OBJECT(action), "icon-name",
1154 ghb_string_value("hb-play"));
1155 g_object_set_property(G_OBJECT(action), "label",
1156 ghb_string_value("_Resume Queue"));
1157 g_object_set_property(G_OBJECT(action), "tooltip",
1158 ghb_string_value("Resume Encoding"));
1163 gtk_action_set_sensitive (action, show_stop);
1164 #if GTK_CHECK_VERSION(2, 16, 0)
1165 gtk_action_set_icon_name(action, "hb-pause");
1166 gtk_action_set_label(action, "_Pause Queue");
1167 gtk_action_set_tooltip(action, "Pause Encoding");
1169 g_object_set_property(G_OBJECT(action), "icon-name",
1170 ghb_string_value("hb-pause"));
1171 g_object_set_property(G_OBJECT(action), "label",
1172 ghb_string_value("_Pause Queue"));
1173 g_object_set_property(G_OBJECT(action), "tooltip",
1174 ghb_string_value("Pause Encoding"));
1179 G_MODULE_EXPORT void
1180 queue_list_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, GtkCellRenderer *cell)
1182 GtkTreeViewColumn *column;
1185 column = gtk_tree_view_get_column (GTK_TREE_VIEW(widget), 0);
1186 width = gtk_tree_view_column_get_width(column);
1187 g_debug("col width %d alloc width %d", width, allocation->width);
1188 // Set new wrap-width. Shave a little off to accomidate the icons
1189 // that share this column.
1190 if (width >= 564) // Don't allow below a certain size
1191 g_object_set(cell, "wrap-width", width-70, NULL);
1194 G_MODULE_EXPORT void
1195 queue_start_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
1198 gboolean running = FALSE;
1203 state = ghb_get_queue_state();
1204 if (state & (GHB_STATE_WORKING | GHB_STATE_SEARCHING |
1205 GHB_STATE_SCANNING | GHB_STATE_MUXING))
1207 ghb_cancel_encode(ud, "You are currently encoding. "
1208 "What would you like to do?");
1212 count = ghb_array_len(ud->queue);
1213 for (ii = 0; ii < count; ii++)
1215 js = ghb_array_get_nth(ud->queue, ii);
1216 status = ghb_settings_get_int(js, "job_status");
1217 if ((status == GHB_QUEUE_RUNNING) ||
1218 (status == GHB_QUEUE_PENDING))
1226 // The queue has no running or pending jobs.
1227 // Add current settings to the queue, then run.
1231 if (state == GHB_STATE_IDLE)
1233 // Add the first pending queue item and start
1234 ud->current_job = ghb_start_next_job(ud, TRUE);
1238 G_MODULE_EXPORT void
1239 queue_pause_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
1245 ghb_reload_queue(signal_user_data_t *ud)
1248 gint unfinished = 0;
1255 g_debug("ghb_reload_queue");
1258 pid = ghb_find_pid_file();
1262 queue = ghb_load_old_queue(pid);
1263 ghb_remove_old_queue_file(pid);
1264 // Look for unfinished entries
1265 count = ghb_array_len(queue);
1266 for (ii = 0; ii < count; ii++)
1268 settings = ghb_array_get_nth(queue, ii);
1269 status = ghb_settings_get_int(settings, "job_status");
1270 if (status != GHB_QUEUE_DONE && status != GHB_QUEUE_CANCELED)
1280 message = g_strdup_printf(
1281 "You have %d unfinished job%s in a saved queue.\n\n"
1282 "Would you like to reload %s?",
1284 (unfinished > 1) ? "s" : "",
1285 (unfinished > 1) ? "them" : "it");
1286 if (ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "No", "Yes"))
1288 GtkWidget *widget = GHB_WIDGET (ud->builder, "queue_window");
1289 gtk_widget_show (widget);
1290 widget = GHB_WIDGET (ud->builder, "show_queue");
1291 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(widget), TRUE);
1294 // First get rid of any old items we don't want
1295 for (ii = count-1; ii >= 0; ii--)
1297 settings = ghb_array_get_nth(queue, ii);
1298 status = ghb_settings_get_int(settings, "job_status");
1299 if (status == GHB_QUEUE_DONE || status == GHB_QUEUE_CANCELED)
1301 GValue *old = ghb_array_get_nth(queue, ii);
1302 ghb_value_free(old);
1303 ghb_array_remove(queue, ii);
1306 count = ghb_array_len(queue);
1307 for (ii = 0; ii < count; ii++)
1309 settings = ghb_array_get_nth(queue, ii);
1310 ghb_settings_set_int(settings, "job_unique_id", 0);
1311 ghb_settings_set_int(settings, "job_status", GHB_QUEUE_PENDING);
1312 add_to_queue_list(ud, settings, NULL);
1314 ghb_queue_buttons_grey(ud);
1315 ghb_save_queue(ud->queue);
1319 ghb_value_free(queue);
1326 G_MODULE_EXPORT gboolean
1330 signal_user_data_t *ud)
1332 GtkTreeView *treeview;
1333 GtkTreeSelection *selection;
1334 GtkTreeModel *store;
1342 g_debug("queue_key_press_cb ()");
1343 if (event->keyval != GDK_Delete)
1345 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
1346 store = gtk_tree_view_get_model(treeview);
1348 selection = gtk_tree_view_get_selection (treeview);
1349 if (gtk_tree_selection_get_selected(selection, &store, &iter))
1351 GtkTreePath *treepath;
1353 treepath = gtk_tree_model_get_path (store, &iter);
1354 // Find the entry in the queue
1355 indices = gtk_tree_path_get_indices (treepath);
1357 // Can only free the treepath After getting what I need from
1358 // indices since this points into treepath somewhere.
1359 gtk_tree_path_free (treepath);
1360 if (row < 0) return FALSE;
1361 if (row >= ghb_array_len(ud->queue))
1363 settings = ghb_array_get_nth(ud->queue, row);
1364 status = ghb_settings_get_int(settings, "job_status");
1365 if (status == GHB_QUEUE_RUNNING)
1367 // Ask if wants to stop encode.
1368 if (!ghb_cancel_encode2(ud, NULL))
1372 unique_id = ghb_settings_get_int(settings, "job_unique_id");
1373 ghb_remove_job(unique_id);
1375 // Remove the selected item
1376 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
1377 // Remove the corresponding item from the queue list
1378 GValue *old = ghb_array_get_nth(ud->queue, row);
1379 ghb_value_free(old);
1380 ghb_array_remove(ud->queue, row);
1381 ghb_save_queue(ud->queue);
1387 GValue *ghb_queue_edit_settings = NULL;
1389 G_MODULE_EXPORT void
1390 queue_edit_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
1392 GtkTreeView *treeview;
1393 GtkTreeSelection *selection;
1394 GtkTreeModel *store;
1400 g_debug("queue_key_press_cb ()");
1401 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
1402 store = gtk_tree_view_get_model(treeview);
1404 selection = gtk_tree_view_get_selection (treeview);
1405 if (gtk_tree_selection_get_selected(selection, &store, &iter))
1407 GtkTreePath *treepath;
1409 treepath = gtk_tree_model_get_path (store, &iter);
1410 // Find the entry in the queue
1411 indices = gtk_tree_path_get_indices (treepath);
1413 // Can only free the treepath After getting what I need from
1414 // indices since this points into treepath somewhere.
1415 gtk_tree_path_free (treepath);
1416 if (row < 0) return;
1417 if (row >= ghb_array_len(ud->queue))
1419 ghb_queue_edit_settings = ghb_array_get_nth(ud->queue, row);
1420 status = ghb_settings_get_int(ghb_queue_edit_settings, "job_status");
1421 if (status == GHB_QUEUE_PENDING)
1423 // Remove the selected item
1424 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
1425 // Remove the corresponding item from the queue list
1426 ghb_array_remove(ud->queue, row);
1430 ghb_queue_edit_settings = ghb_value_dup(ghb_queue_edit_settings);
1433 source = ghb_settings_get_string(ghb_queue_edit_settings, "source");
1434 ghb_do_scan(ud, source, 0, FALSE);