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 = 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_chapter = ghb_settings_get_int(settings, "start_chapter");
88 end_chapter = ghb_settings_get_int(settings, "end_chapter");
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 info = g_strdup_printf
99 "<big><b>%s</b></big> "
100 "<small>(Title %d, Chapters %d through %d, %d Video %s)"
102 vol_name, title, start_chapter, end_chapter,
103 pass2 ? 2:1, pass2 ? "Passes":"Pass", escape
111 gtk_tree_store_append(store, &iter, NULL);
113 gtk_tree_store_set(store, &iter, 1, info, 2, "hb-queue-delete", -1);
115 status = ghb_settings_get_int(settings, "job_status");
118 case GHB_QUEUE_PENDING:
119 gtk_tree_store_set(store, &iter, 0, "hb-queue-job", -1);
121 case GHB_QUEUE_CANCELED:
122 gtk_tree_store_set(store, &iter, 0, "hb-canceled", -1);
124 case GHB_QUEUE_RUNNING:
125 gtk_tree_store_set(store, &iter, 0, "hb-working0", -1);
128 gtk_tree_store_set(store, &iter, 0, "hb-complete", -1);
131 gtk_tree_store_set(store, &iter, 0, "hb-queue-job", -1);
135 GString *str = g_string_new("");
137 gboolean preset_modified;
141 container = ghb_settings_combo_option(settings, "FileFormat");
142 mux = ghb_settings_combo_int(settings, "FileFormat");
143 preset_modified = ghb_settings_get_boolean(settings, "preset_modified");
144 path = ghb_settings_get_value(settings, "preset");
145 preset = ghb_preset_path_string(path);
146 markers = ghb_settings_get_boolean(settings, "ChapterMarkers");
149 g_string_append_printf(str,
150 "<b>Modified Preset Based On:</b> <small>%s</small>\n",
153 g_string_append_printf(str,
154 "<b>Preset:</b> <small>%s</small>\n",
159 g_string_append_printf(str,
160 "<b>Format:</b> <small>%s Container, Chapter Markers</small>\n",
165 g_string_append_printf(str,
166 "<b>Format:</b> <small>%s Container</small>\n", container);
168 if (mux == HB_MUX_MP4)
170 gboolean ipod, http, large;
172 ipod = ghb_settings_get_boolean(settings, "Mp4iPodCompatible");
173 http = ghb_settings_get_boolean(settings, "Mp4HttpOptimize");
174 large = ghb_settings_get_boolean(settings, "Mp4LargeFile");
175 if (http || ipod || large)
177 g_string_append_printf(str, "<b>MP4 Options:</b><small>");
179 g_string_append_printf(str, " - iPod 5G Support");
181 g_string_append_printf(str, " - Web Optimized");
183 g_string_append_printf(str, " - Large File Size (>4GB)");
184 g_string_append_printf(str, "</small>\n");
187 escape = g_markup_escape_text(dest, -1);
188 g_string_append_printf(str,
189 "<b>Destination:</b> <small>%s</small>\n", escape);
191 width = ghb_settings_get_int(settings, "scale_width");
192 height = ghb_settings_get_int(settings, "scale_height");
193 pic_par = ghb_settings_combo_int(settings, "PicturePAR");
194 keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");
203 aspect_desc = "(Aspect Preserved)";
207 aspect_desc = "(Aspect Lost)";
213 aspect_desc = "(Strict Anamorphic)";
218 aspect_desc = "(Loose Anamorphic)";
223 aspect_desc = "(Custom Anamorphic)";
228 aspect_desc = "(Unknown)";
231 vqtype = ghb_settings_get_boolean(settings, "vquality_type_constant");
233 gchar *vq_desc = "Error";
234 gchar *vq_units = "";
239 vqtype = ghb_settings_get_boolean(settings, "vquality_type_target");
243 vqvalue = ghb_settings_get_int(settings, "VideoAvgBitrate");
244 vq_desc = "Bitrate:";
250 vqvalue = ghb_settings_get_int(settings, "VideoTargetSize");
251 vq_desc = "Target Size:";
254 vqstr = g_strdup_printf("%d", (gint)vqvalue);
259 vqvalue = ghb_settings_get_double(settings, "VideoQualitySlider");
260 vq_desc = "Constant Quality:";
261 vqstr = g_strdup_printf("%d", (gint)vqvalue);
264 fps = ghb_settings_get_string(settings, "VideoFramerate");
265 if (strcmp("source", fps) == 0)
268 if (ghb_settings_combo_int(settings, "PictureDetelecine"))
269 fps = g_strdup("Same As Source (vfr detelecine)");
271 fps = g_strdup("Same As Source (variable)");
276 tmp = g_strdup_printf("%s (constant frame rate)", fps);
280 vcodec = ghb_settings_combo_option(settings, "VideoEncoder");
281 vcodec_abbr = ghb_settings_get_string(settings, "VideoEncoder");
282 source_width = ghb_settings_get_int(settings, "source_width");
283 source_height = ghb_settings_get_int(settings, "source_height");
284 g_string_append_printf(str,
285 "<b>Picture:</b> Source: <small>%d x %d, Output %d x %d %s</small>\n",
286 source_width, source_height, width, height, aspect_desc);
289 gboolean decomb_deint;
290 gboolean filters = FALSE;
292 decomb_deint = ghb_settings_get_boolean(settings, "PictureDecombDeinterlace");
293 decomb = ghb_settings_combo_int(settings, "PictureDecomb");
294 g_string_append_printf(str, "<b>Filters:</b><small>");
295 detel = ghb_settings_combo_int(settings, "PictureDetelecine");
298 g_string_append_printf(str, " - Detelecine");
302 cust = ghb_settings_get_string(settings, "PictureDetelecineCustom");
303 g_string_append_printf(str, ": %s", cust);
308 if (decomb_deint && decomb)
310 g_string_append_printf(str, " - Decomb");
314 cust = ghb_settings_get_string(settings, "PictureDecombCustom");
315 g_string_append_printf(str, ": %s", cust);
320 else if (!decomb_deint)
322 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
327 gchar *cust = ghb_settings_get_string(settings,
328 "PictureDeinterlaceCustom");
329 g_string_append_printf(str, " - Deinterlace: %s", cust);
334 const gchar *opt = ghb_settings_combo_option(settings,
335 "PictureDeinterlace");
336 g_string_append_printf(str, " - Deinterlace: %s", opt);
341 gint denoise = ghb_settings_combo_int(settings, "PictureDenoise");
346 gchar *cust = ghb_settings_get_string(settings,
347 "PictureDenoiseCustom");
348 g_string_append_printf(str, " - Denoise: %s", cust);
353 const gchar *opt = ghb_settings_combo_option(settings,
355 g_string_append_printf(str, " - Denoise: %s", opt);
359 gint deblock = ghb_settings_get_int(settings, "PictureDeblock");
362 g_string_append_printf(str, " - Deblock (%d)", deblock);
365 if (ghb_settings_get_boolean(settings, "VideoGrayScale"))
367 g_string_append_printf(str, " - Grayscale");
371 g_string_append_printf(str, " None");
372 g_string_append_printf(str, "</small>\n");
374 g_string_append_printf(str,
375 "<b>Video:</b> <small>%s, Framerate: %s, %s %s%s</small>\n",
376 vcodec, fps, vq_desc, vqstr, vq_units);
378 turbo = ghb_settings_get_boolean(settings, "VideoTurboTwoPass");
381 g_string_append_printf(str, "<b>Turbo:</b> <small>On</small>\n");
383 if (strcmp(vcodec_abbr, "x264") == 0)
385 gchar *x264opts = ghb_build_x264opts_string(settings);
386 g_string_append_printf(str,
387 "<b>x264 Options:</b> <small>%s</small>\n", x264opts);
392 const GValue *audio_list;
394 audio_list = ghb_settings_get_value(settings, "audio_list");
395 count = ghb_array_len(audio_list);
396 for (ii = 0; ii < count; ii++)
398 gchar *bitrate, *samplerate, *track;
399 const gchar *acodec, *mix;
402 asettings = ghb_array_get_nth(audio_list, ii);
404 acodec = ghb_settings_combo_option(asettings, "AudioEncoder");
405 bitrate = ghb_settings_get_string(asettings, "AudioBitrate");
406 samplerate = ghb_settings_get_string(asettings, "AudioSamplerate");
407 if (strcmp("source", samplerate) == 0)
410 samplerate = g_strdup("Same As Source");
412 track = ghb_settings_get_string(asettings, "AudioTrackDescription");
413 mix = ghb_settings_combo_option(asettings, "AudioMixdown");
415 g_string_append_printf(str, "<b>Audio:</b>");
417 g_string_append_printf(str, "<b>Audio:</b>\n");
419 g_string_append_printf(str, "\t");
421 g_string_append_printf(str,
422 "<small> %s, Encoder: %s, Mixdown: %s, SampleRate: %s, Bitrate: %s</small>\n",
423 track, acodec, mix, samplerate, bitrate);
430 const GValue *sub_list;
432 sub_list = ghb_settings_get_value(settings, "subtitle_list");
433 count = ghb_array_len(sub_list);
434 for (ii = 0; ii < count; ii++)
438 gboolean force, burn, def;
441 settings = ghb_array_get_nth(sub_list, ii);
442 track = ghb_settings_get_string(settings, "SubtitleTrackDescription");
443 source = ghb_settings_get_int(settings, "SubtitleSource");
444 force = ghb_settings_get_boolean(settings, "SubtitleForced");
445 burn = ghb_settings_get_boolean(settings, "SubtitleBurned");
446 def = ghb_settings_get_boolean(settings, "SubtitleDefaultTrack");
448 g_string_append_printf(str, "<b>Subtitle:</b>");
450 g_string_append_printf(str, "<b>Subtitles:</b>\n");
452 g_string_append_printf(str, "\t");
454 if (source != SRTSUB)
456 g_string_append_printf(str,
457 "<small> %s%s%s%s</small>",
459 force ? " (Force)":"",
461 def ? " (Default)":""
467 gchar *filename, *basename, *code;
469 offset = ghb_settings_get_int(settings, "SrtOffset");
470 filename = ghb_settings_get_string(settings, "SrtFile");
471 basename = g_path_get_basename(filename);
472 code = ghb_settings_get_string(settings, "SrtCodeset");
473 g_string_append_printf(str,
474 "<small> %s (%s), %s, Offset (ms) %d%s</small>",
475 track, code, basename, offset,
476 def ? " (Default)":""
483 g_string_append_printf(str, "\n");
487 info = g_string_free(str, FALSE);
488 gtk_tree_store_append(store, &citer, &iter);
489 gtk_tree_store_set(store, &citer, 1, info, -1);
499 audio_list_refresh(signal_user_data_t *ud)
501 GtkTreeView *treeview;
506 const GValue *audio_list;
508 g_debug("ghb_audio_list_refresh ()");
509 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_list"));
510 store = GTK_LIST_STORE(gtk_tree_view_get_model(treeview));
511 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter))
515 const gchar *track, *codec, *br, *sr, *mix;
516 gchar *drc, *s_track, *s_codec, *s_br, *s_sr, *s_mix;
521 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
522 if (row >= ghb_array_len(audio_list))
524 asettings = ghb_array_get_nth(audio_list, row);
526 track = ghb_settings_combo_option(asettings, "AudioTrack");
527 itrack = ghb_settings_combo_int(asettings, "AudioTrack");
528 codec = ghb_settings_combo_option(asettings, "AudioEncoder");
529 icodec = ghb_settings_combo_int(asettings, "AudioEncoder");
530 br = ghb_settings_combo_option(asettings, "AudioBitrate");
531 sr = ghb_settings_combo_option(asettings, "AudioSamplerate");
532 mix = ghb_settings_combo_option(asettings, "AudioMixdown");
534 s_track = ghb_settings_get_string(asettings, "AudioTrack");
535 s_codec = ghb_settings_get_string(asettings, "AudioEncoder");
536 s_br = ghb_settings_get_string(asettings, "AudioBitrate");
537 s_sr = ghb_settings_get_string(asettings, "AudioSamplerate");
538 s_mix = ghb_settings_get_string(asettings, "AudioMixdown");
539 s_drc = ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
541 drc = g_strdup("Off");
543 drc = g_strdup_printf("%.1f", s_drc);
545 if (icodec == HB_ACODEC_MASK)
546 codec = ghb_select_audio_codec_str(ud, itrack);
548 gtk_list_store_set(GTK_LIST_STORE(store), &iter,
549 // These are displayed in list
556 // These are used to set combo values when an item is selected
570 done = !gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
577 validate_settings(signal_user_data_t *ud)
579 // Check to see if the dest file exists or is
580 // already in the queue
581 gchar *message, *dest;
585 titleindex = ghb_settings_combo_int(ud->settings, "title");
586 if (titleindex < 0) return FALSE;
587 dest = ghb_settings_get_string(ud->settings, "destination");
588 count = ghb_array_len(ud->queue);
589 for (ii = 0; ii < count; ii++)
594 js = ghb_array_get_nth(ud->queue, ii);
595 filename = ghb_settings_get_string(js, "destination");
596 if (strcmp(dest, filename) == 0)
598 message = g_strdup_printf(
599 "Destination: %s\n\n"
600 "Another queued job has specified the same destination.\n"
601 "Do you want to overwrite?",
603 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Overwrite"))
615 gchar *destdir = g_path_get_dirname(dest);
616 if (!g_file_test(destdir, G_FILE_TEST_IS_DIR))
618 message = g_strdup_printf(
619 "Destination: %s\n\n"
620 "This is not a valid directory.",
622 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
629 // This doesn't work properly on windows
630 if (g_access(destdir, R_OK|W_OK) != 0)
632 message = g_strdup_printf(
633 "Destination: %s\n\n"
634 "Can not read or write the directory.",
636 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
646 gchar *resolved = ghb_resolve_symlink(destdir);
648 gfile = g_file_new_for_path(resolved);
649 info = g_file_query_filesystem_info(gfile,
650 G_FILE_ATTRIBUTE_FILESYSTEM_FREE, NULL, NULL);
653 if (g_file_info_has_attribute(info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE))
655 size = g_file_info_get_attribute_uint64(info,
656 G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
658 gint64 fsize = (guint64)10 * 1024 * 1024 * 1024;
661 message = g_strdup_printf(
662 "Destination filesystem is almost full: %uM free\n\n"
663 "Encode may be incomplete if you proceed.\n",
664 (guint)(size / (1024L*1024L)));
665 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Proceed"))
674 g_object_unref(info);
676 g_object_unref(gfile);
679 if (g_file_test(dest, G_FILE_TEST_EXISTS))
681 message = g_strdup_printf(
682 "Destination: %s\n\n"
683 "File already exists.\n"
684 "Do you want to overwrite?",
686 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Overwrite"))
696 // Validate video quality is in a reasonable range
697 if (!ghb_validate_vquality(ud->settings))
701 // Validate audio settings
702 if (!ghb_validate_audio(ud))
706 // Validate audio settings
707 if (!ghb_validate_subtitles(ud))
711 // Validate video settings
712 if (!ghb_validate_video(ud))
716 // Validate filter settings
717 if (!ghb_validate_filters(ud))
721 audio_list_refresh(ud);
726 queue_add(signal_user_data_t *ud)
728 // Add settings to the queue
733 g_debug("queue_add ()");
734 if (!validate_settings(ud))
739 if (ud->queue == NULL)
740 ud->queue = ghb_array_value_new(32);
741 // Make a copy of current settings to be used for the new job
742 settings = ghb_value_dup(ud->settings);
743 ghb_settings_set_int(settings, "job_status", GHB_QUEUE_PENDING);
744 ghb_settings_set_int(settings, "job_unique_id", 0);
745 titleindex = ghb_settings_combo_int(settings, "title");
746 titlenum = ghb_get_title_number(titleindex);
747 ghb_settings_set_int(settings, "titlenum", titlenum);
748 ghb_array_append(ud->queue, settings);
749 add_to_queue_list(ud, settings, NULL);
750 ghb_save_queue(ud->queue);
751 ghb_update_pending(ud);
757 queue_add_clicked_cb(GtkWidget *widget, signal_user_data_t *ud)
759 g_debug("queue_add_clicked_cb ()");
764 queue_remove_clicked_cb(GtkWidget *widget, gchar *path, signal_user_data_t *ud)
766 GtkTreeView *treeview;
767 GtkTreePath *treepath;
776 g_debug("queue_remove_clicked_cb ()");
777 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
778 store = gtk_tree_view_get_model(treeview);
779 treepath = gtk_tree_path_new_from_string (path);
780 if (gtk_tree_path_get_depth(treepath) > 1) return;
781 if (gtk_tree_model_get_iter(store, &iter, treepath))
783 // Find the entry in the queue
784 indices = gtk_tree_path_get_indices (treepath);
786 // Can only free the treepath After getting what I need from
787 // indices since this points into treepath somewhere.
788 gtk_tree_path_free (treepath);
790 if (row >= ghb_array_len(ud->queue))
792 settings = ghb_array_get_nth(ud->queue, row);
793 status = ghb_settings_get_int(settings, "job_status");
794 if (status == GHB_QUEUE_RUNNING)
796 // Ask if wants to stop encode.
797 if (!ghb_cancel_encode2(ud, NULL))
801 unique_id = ghb_settings_get_int(settings, "job_unique_id");
802 ghb_remove_job(unique_id);
804 // Remove the selected item
805 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
806 // Remove the corresponding item from the queue list
807 GValue *old = ghb_array_get_nth(ud->queue, row);
809 ghb_array_remove(ud->queue, row);
810 ghb_save_queue(ud->queue);
814 gtk_tree_path_free (treepath);
816 ghb_update_pending(ud);
820 find_last_finished(GValue *queue)
826 g_debug("find_last_finished");
827 count = ghb_array_len(queue);
828 for (ii = 0; ii < count; ii++)
830 js = ghb_array_get_nth(queue, ii);
831 status = ghb_settings_get_int(js, "job_status");
832 if (status != GHB_QUEUE_DONE && status != GHB_QUEUE_RUNNING)
840 // This little bit is needed to prevent the default drag motion
841 // handler from expanding rows if you hover over them while
843 // Also controls where valid drop locations are
844 G_MODULE_EXPORT gboolean
845 queue_drag_motion_cb(
851 signal_user_data_t *ud)
853 GtkTreePath *path = NULL;
854 GtkTreeViewDropPosition pos;
855 gint *indices, row, status, finished;
860 GtkTreeSelection *select;
863 widget = gtk_drag_get_source_widget(ctx);
864 if (widget == NULL || widget != GTK_WIDGET(tv))
867 // This bit checks to see if the source is allowed to be
868 // moved. Only pending and canceled items may be moved.
869 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
870 select = gtk_tree_view_get_selection (srctv);
871 gtk_tree_selection_get_selected (select, &model, &iter);
872 path = gtk_tree_model_get_path (model, &iter);
873 indices = gtk_tree_path_get_indices(path);
875 gtk_tree_path_free(path);
876 js = ghb_array_get_nth(ud->queue, row);
877 status = ghb_settings_get_int(js, "job_status");
878 if (status != GHB_QUEUE_PENDING && status != GHB_QUEUE_CANCELED)
880 gdk_drag_status(ctx, 0, time);
884 // The reset checks that the destination is a valid position
885 // in the list. Can not move above any finished or running items
886 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &pos);
889 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
892 // Don't allow *drop into*
893 if (pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
894 pos = GTK_TREE_VIEW_DROP_BEFORE;
895 if (pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
896 pos = GTK_TREE_VIEW_DROP_AFTER;
897 // Don't allow droping int child items
898 if (gtk_tree_path_get_depth(path) > 1)
900 gtk_tree_path_up(path);
901 pos = GTK_TREE_VIEW_DROP_AFTER;
903 indices = gtk_tree_path_get_indices(path);
905 js = ghb_array_get_nth(ud->queue, row);
907 finished = find_last_finished(ud->queue);
910 gtk_tree_path_free(path);
911 gdk_drag_status(ctx, 0, time);
914 if (pos != GTK_TREE_VIEW_DROP_AFTER &&
917 gtk_tree_path_free(path);
918 gdk_drag_status(ctx, 0, time);
921 gtk_tree_view_set_drag_dest_row(tv, path, pos);
922 gtk_tree_path_free(path);
923 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
929 GtkTreeView *dstwidget,
932 GtkSelectionData *selection_data,
934 signal_user_data_t *ud)
936 GtkTreePath *path = NULL;
937 //GtkTreeModel *model;
938 GtkTreeViewDropPosition pos;
939 GtkTreeIter dstiter, srciter;
943 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
945 g_debug("queue_drag_cb ()");
946 // This doesn't work here for some reason...
947 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &pos);
948 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &pos);
949 // This little hack is needed because attempting to drop after
950 // the last item gives us no path or pos.
955 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
958 pos = GTK_TREE_VIEW_DROP_AFTER;
959 path = gtk_tree_path_new_from_indices(n_children-1, -1);
963 pos = GTK_TREE_VIEW_DROP_BEFORE;
964 path = gtk_tree_path_new_from_indices(0, -1);
969 if (gtk_tree_path_get_depth(path) > 1)
970 gtk_tree_path_up(path);
971 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
974 GtkTreeView *srcwidget;
975 GtkTreeModel *srcmodel;
976 GtkTreeSelection *select;
977 GtkTreePath *srcpath = NULL;
978 GtkTreePath *dstpath = NULL;
980 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
981 //srcmodel = gtk_tree_view_get_model(srcwidget);
982 select = gtk_tree_view_get_selection (srcwidget);
983 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
985 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
986 indices = gtk_tree_path_get_indices(srcpath);
988 gtk_tree_path_free(srcpath);
989 js = ghb_array_get_nth(ud->queue, row);
993 case GTK_TREE_VIEW_DROP_BEFORE:
994 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
995 gtk_tree_store_insert_before (GTK_TREE_STORE (dstmodel),
996 &iter, NULL, &dstiter);
999 case GTK_TREE_VIEW_DROP_AFTER:
1000 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
1001 gtk_tree_store_insert_after (GTK_TREE_STORE (dstmodel),
1002 &iter, NULL, &dstiter);
1008 // Reset job to pending
1009 ghb_settings_set_int(js, "job_status", GHB_QUEUE_PENDING);
1010 add_to_queue_list(ud, js, &iter);
1012 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
1013 indices = gtk_tree_path_get_indices(dstpath);
1015 gtk_tree_path_free(dstpath);
1016 ghb_array_insert(ud->queue, row, js);
1018 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
1019 indices = gtk_tree_path_get_indices(srcpath);
1021 gtk_tree_path_free(srcpath);
1022 ghb_array_remove(ud->queue, row);
1023 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
1024 ghb_save_queue(ud->queue);
1026 gtk_tree_path_free(path);
1031 ghb_queue_buttons_grey(signal_user_data_t *ud)
1037 gint queue_state, scan_state;
1038 gboolean show_start, show_stop, paused;
1040 queue_count = ghb_array_len(ud->queue);
1041 titleindex = ghb_settings_combo_int(ud->settings, "title");
1043 queue_state = ghb_get_queue_state();
1044 scan_state = ghb_get_scan_state();
1046 show_stop = queue_state &
1047 (GHB_STATE_WORKING | GHB_STATE_SCANNING | GHB_STATE_MUXING);
1048 show_start = !(scan_state & GHB_STATE_SCANNING) &&
1049 (titleindex >= 0 || queue_count > 0);
1052 paused = queue_state & GHB_STATE_PAUSED;
1054 widget = GHB_WIDGET (ud->builder, "queue_start1");
1057 gtk_widget_set_sensitive (widget, TRUE);
1058 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-stop");
1059 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Stop");
1060 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Stop Encoding");
1064 gtk_widget_set_sensitive (widget, show_start);
1065 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-play");
1066 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Start");
1067 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Start Encoding");
1069 widget = GHB_WIDGET (ud->builder, "queue_start2");
1072 gtk_widget_set_sensitive (widget, TRUE);
1073 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-stop");
1074 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Stop");
1075 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Stop Encoding");
1079 gtk_widget_set_sensitive (widget, show_start);
1080 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-play");
1081 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Start");
1082 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Start Encoding");
1084 widget = GHB_WIDGET (ud->builder, "queue_pause1");
1087 gtk_widget_set_sensitive (widget, show_stop);
1088 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-play");
1089 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Resume");
1090 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Resume Encoding");
1094 gtk_widget_set_sensitive (widget, show_stop);
1095 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-pause");
1096 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Pause");
1097 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Pause Encoding");
1099 widget = GHB_WIDGET (ud->builder, "queue_pause2");
1102 gtk_widget_set_sensitive (widget, show_stop);
1103 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-play");
1104 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Resume");
1105 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Resume Encoding");
1109 gtk_widget_set_sensitive (widget, show_stop);
1110 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-pause");
1111 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Pause");
1112 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Pause Encoding");
1115 action = GHB_ACTION (ud->builder, "queue_start_menu");
1118 gtk_action_set_sensitive (action, TRUE);
1119 #if GTK_CHECK_VERSION(2, 16, 0)
1120 gtk_action_set_icon_name(action, "hb-stop");
1121 gtk_action_set_label(action, "S_top Queue");
1122 gtk_action_set_tooltip(action, "Stop Encoding");
1124 g_object_set_property(G_OBJECT(action), "icon-name",
1125 ghb_string_value("hb-stop"));
1126 g_object_set_property(G_OBJECT(action), "label",
1127 ghb_string_value("S_top Queue"));
1128 g_object_set_property(G_OBJECT(action), "tooltip",
1129 ghb_string_value("Stop Encoding"));
1134 gtk_action_set_sensitive (action, show_start);
1135 #if GTK_CHECK_VERSION(2, 16, 0)
1136 gtk_action_set_icon_name(action, "hb-play");
1137 gtk_action_set_label(action, "_Start Queue");
1138 gtk_action_set_tooltip(action, "Start Encoding");
1140 g_object_set_property(G_OBJECT(action), "icon-name",
1141 ghb_string_value("hb-play"));
1142 g_object_set_property(G_OBJECT(action), "label",
1143 ghb_string_value("_Start Queue"));
1144 g_object_set_property(G_OBJECT(action), "tooltip",
1145 ghb_string_value("Start Encoding"));
1148 action = GHB_ACTION (ud->builder, "queue_pause_menu");
1151 gtk_action_set_sensitive (action, show_start);
1152 #if GTK_CHECK_VERSION(2, 16, 0)
1153 gtk_action_set_icon_name(action, "hb-play");
1154 gtk_action_set_label(action, "_Resume Queue");
1155 gtk_action_set_tooltip(action, "Resume Encoding");
1157 g_object_set_property(G_OBJECT(action), "icon-name",
1158 ghb_string_value("hb-play"));
1159 g_object_set_property(G_OBJECT(action), "label",
1160 ghb_string_value("_Resume Queue"));
1161 g_object_set_property(G_OBJECT(action), "tooltip",
1162 ghb_string_value("Resume Encoding"));
1167 gtk_action_set_sensitive (action, show_stop);
1168 #if GTK_CHECK_VERSION(2, 16, 0)
1169 gtk_action_set_icon_name(action, "hb-pause");
1170 gtk_action_set_label(action, "_Pause Queue");
1171 gtk_action_set_tooltip(action, "Pause Encoding");
1173 g_object_set_property(G_OBJECT(action), "icon-name",
1174 ghb_string_value("hb-pause"));
1175 g_object_set_property(G_OBJECT(action), "label",
1176 ghb_string_value("_Pause Queue"));
1177 g_object_set_property(G_OBJECT(action), "tooltip",
1178 ghb_string_value("Pause Encoding"));
1183 G_MODULE_EXPORT void
1184 queue_list_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, GtkCellRenderer *cell)
1186 GtkTreeViewColumn *column;
1189 column = gtk_tree_view_get_column (GTK_TREE_VIEW(widget), 0);
1190 width = gtk_tree_view_column_get_width(column);
1191 g_debug("col width %d alloc width %d", width, allocation->width);
1192 // Set new wrap-width. Shave a little off to accomidate the icons
1193 // that share this column.
1194 if (width >= 564) // Don't allow below a certain size
1195 g_object_set(cell, "wrap-width", width-70, NULL);
1198 G_MODULE_EXPORT void
1199 queue_start_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
1202 gboolean running = FALSE;
1207 state = ghb_get_queue_state();
1208 if (state & (GHB_STATE_WORKING | GHB_STATE_SCANNING | GHB_STATE_MUXING))
1210 ghb_cancel_encode(ud, "You are currently encoding. "
1211 "What would you like to do?");
1215 count = ghb_array_len(ud->queue);
1216 for (ii = 0; ii < count; ii++)
1218 js = ghb_array_get_nth(ud->queue, ii);
1219 status = ghb_settings_get_int(js, "job_status");
1220 if ((status == GHB_QUEUE_RUNNING) ||
1221 (status == GHB_QUEUE_PENDING))
1229 // The queue has no running or pending jobs.
1230 // Add current settings to the queue, then run.
1234 if (state == GHB_STATE_IDLE)
1236 // Add the first pending queue item and start
1237 ud->current_job = ghb_start_next_job(ud, TRUE);
1241 G_MODULE_EXPORT void
1242 queue_pause_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
1248 ghb_reload_queue(signal_user_data_t *ud)
1251 gint unfinished = 0;
1257 g_debug("ghb_reload_queue");
1259 queue = ghb_load_queue();
1260 // Look for unfinished entries
1261 count = ghb_array_len(queue);
1262 for (ii = 0; ii < count; ii++)
1264 settings = ghb_array_get_nth(queue, ii);
1265 status = ghb_settings_get_int(settings, "job_status");
1266 if (status != GHB_QUEUE_DONE && status != GHB_QUEUE_CANCELED)
1273 message = g_strdup_printf(
1274 "You have %d unfinished job%s in a saved queue.\n\n"
1275 "Would you like to reload %s?",
1277 (unfinished > 1) ? "s" : "",
1278 (unfinished > 1) ? "them" : "it");
1279 if (ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "No", "Yes"))
1281 GtkWidget *widget = GHB_WIDGET (ud->builder, "queue_window");
1282 gtk_widget_show (widget);
1283 widget = GHB_WIDGET (ud->builder, "show_queue");
1284 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(widget), TRUE);
1287 // First get rid of any old items we don't want
1288 for (ii = count-1; ii >= 0; ii--)
1290 settings = ghb_array_get_nth(queue, ii);
1291 status = ghb_settings_get_int(settings, "job_status");
1292 if (status == GHB_QUEUE_DONE || status == GHB_QUEUE_CANCELED)
1294 GValue *old = ghb_array_get_nth(queue, ii);
1295 ghb_value_free(old);
1296 ghb_array_remove(queue, ii);
1299 count = ghb_array_len(queue);
1300 for (ii = 0; ii < count; ii++)
1302 settings = ghb_array_get_nth(queue, ii);
1303 ghb_settings_set_int(settings, "job_unique_id", 0);
1304 ghb_settings_set_int(settings, "job_status", GHB_QUEUE_PENDING);
1305 add_to_queue_list(ud, settings, NULL);
1307 ghb_queue_buttons_grey(ud);
1311 ghb_value_free(queue);
1312 ghb_remove_queue_file();
1319 G_MODULE_EXPORT gboolean
1323 signal_user_data_t *ud)
1325 GtkTreeView *treeview;
1326 GtkTreeSelection *selection;
1327 GtkTreeModel *store;
1335 g_debug("queue_key_press_cb ()");
1336 if (event->keyval != GDK_Delete)
1338 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
1339 store = gtk_tree_view_get_model(treeview);
1341 selection = gtk_tree_view_get_selection (treeview);
1342 if (gtk_tree_selection_get_selected(selection, &store, &iter))
1344 GtkTreePath *treepath;
1346 treepath = gtk_tree_model_get_path (store, &iter);
1347 // Find the entry in the queue
1348 indices = gtk_tree_path_get_indices (treepath);
1350 // Can only free the treepath After getting what I need from
1351 // indices since this points into treepath somewhere.
1352 gtk_tree_path_free (treepath);
1353 if (row < 0) return FALSE;
1354 if (row >= ghb_array_len(ud->queue))
1356 settings = ghb_array_get_nth(ud->queue, row);
1357 status = ghb_settings_get_int(settings, "job_status");
1358 if (status == GHB_QUEUE_RUNNING)
1360 // Ask if wants to stop encode.
1361 if (!ghb_cancel_encode2(ud, NULL))
1365 unique_id = ghb_settings_get_int(settings, "job_unique_id");
1366 ghb_remove_job(unique_id);
1368 // Remove the selected item
1369 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
1370 // Remove the corresponding item from the queue list
1371 GValue *old = ghb_array_get_nth(ud->queue, row);
1372 ghb_value_free(old);
1373 ghb_array_remove(ud->queue, row);
1374 ghb_save_queue(ud->queue);
1380 GValue *ghb_queue_edit_settings = NULL;
1382 G_MODULE_EXPORT void
1383 queue_edit_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
1385 GtkTreeView *treeview;
1386 GtkTreeSelection *selection;
1387 GtkTreeModel *store;
1393 g_debug("queue_key_press_cb ()");
1394 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
1395 store = gtk_tree_view_get_model(treeview);
1397 selection = gtk_tree_view_get_selection (treeview);
1398 if (gtk_tree_selection_get_selected(selection, &store, &iter))
1400 GtkTreePath *treepath;
1402 treepath = gtk_tree_model_get_path (store, &iter);
1403 // Find the entry in the queue
1404 indices = gtk_tree_path_get_indices (treepath);
1406 // Can only free the treepath After getting what I need from
1407 // indices since this points into treepath somewhere.
1408 gtk_tree_path_free (treepath);
1409 if (row < 0) return;
1410 if (row >= ghb_array_len(ud->queue))
1412 ghb_queue_edit_settings = ghb_array_get_nth(ud->queue, row);
1413 status = ghb_settings_get_int(ghb_queue_edit_settings, "job_status");
1414 if (status == GHB_QUEUE_PENDING)
1416 // Remove the selected item
1417 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
1418 // Remove the corresponding item from the queue list
1419 ghb_array_remove(ud->queue, row);
1423 ghb_queue_edit_settings = ghb_value_dup(ghb_queue_edit_settings);
1426 source = ghb_settings_get_string(ghb_queue_edit_settings, "source");
1427 ghb_do_scan(ud, source, 0, FALSE);