1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) John Stebbins 2008-2011 <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;
78 gchar *escape, *escape2;
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);
93 escape2 = g_markup_escape_text(vol_name, -1);
95 vqtype = ghb_settings_get_boolean(settings, "vquality_type_constant");
97 pass2 = ghb_settings_get_boolean(settings, "VideoTwoPass");
98 const gchar *points = "Chapters";
99 if (ghb_settings_combo_int(settings, "PtoPType") == 0)
101 else if (ghb_settings_combo_int(settings, "PtoPType") == 1)
103 else if (ghb_settings_combo_int(settings, "PtoPType") == 2)
105 info = g_strdup_printf
107 "<big><b>%s</b></big> "
108 "<small>(Title %d, %s %d through %d, %d Video %s)"
110 escape2, title, points, start_point, end_point,
111 pass2 ? 2:1, pass2 ? "Passes":"Pass", escape
120 gtk_tree_store_append(store, &iter, NULL);
122 gtk_tree_store_set(store, &iter, 1, info, 2, "hb-queue-delete", -1);
124 status = ghb_settings_get_int(settings, "job_status");
127 case GHB_QUEUE_PENDING:
128 gtk_tree_store_set(store, &iter, 0, "hb-queue-job", -1);
130 case GHB_QUEUE_CANCELED:
131 gtk_tree_store_set(store, &iter, 0, "hb-canceled", -1);
133 case GHB_QUEUE_RUNNING:
134 gtk_tree_store_set(store, &iter, 0, "hb-working0", -1);
137 gtk_tree_store_set(store, &iter, 0, "hb-complete", -1);
140 gtk_tree_store_set(store, &iter, 0, "hb-queue-job", -1);
144 GString *str = g_string_new("");
146 gboolean preset_modified;
150 container = ghb_settings_combo_option(settings, "FileFormat");
151 mux = ghb_settings_combo_int(settings, "FileFormat");
152 preset_modified = ghb_settings_get_boolean(settings, "preset_modified");
153 path = ghb_settings_get_value(settings, "preset");
154 preset = ghb_preset_path_string(path);
155 markers = ghb_settings_get_boolean(settings, "ChapterMarkers");
158 g_string_append_printf(str,
159 "<b>Modified Preset Based On:</b> <small>%s</small>\n",
162 g_string_append_printf(str,
163 "<b>Preset:</b> <small>%s</small>\n",
168 g_string_append_printf(str,
169 "<b>Format:</b> <small>%s Container, Chapter Markers</small>\n",
174 g_string_append_printf(str,
175 "<b>Format:</b> <small>%s Container</small>\n", container);
177 if (mux == HB_MUX_MP4)
179 gboolean ipod, http, large;
181 ipod = ghb_settings_get_boolean(settings, "Mp4iPodCompatible");
182 http = ghb_settings_get_boolean(settings, "Mp4HttpOptimize");
183 large = ghb_settings_get_boolean(settings, "Mp4LargeFile");
184 if (http || ipod || large)
186 g_string_append_printf(str, "<b>MP4 Options:</b><small>");
188 g_string_append_printf(str, " - iPod 5G Support");
190 g_string_append_printf(str, " - Web Optimized");
192 g_string_append_printf(str, " - Large File Size (>4GB)");
193 g_string_append_printf(str, "</small>\n");
196 escape = g_markup_escape_text(dest, -1);
197 g_string_append_printf(str,
198 "<b>Destination:</b> <small>%s</small>\n", escape);
200 width = ghb_settings_get_int(settings, "scale_width");
201 height = ghb_settings_get_int(settings, "scale_height");
202 pic_par = ghb_settings_combo_int(settings, "PicturePAR");
203 keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");
212 aspect_desc = "(Aspect Preserved)";
216 aspect_desc = "(Aspect Lost)";
222 aspect_desc = "(Strict Anamorphic)";
227 aspect_desc = "(Loose Anamorphic)";
232 aspect_desc = "(Custom Anamorphic)";
237 aspect_desc = "(Unknown)";
240 vqtype = ghb_settings_get_boolean(settings, "vquality_type_constant");
242 gchar *vq_desc = "Error";
243 gchar *vq_units = "";
249 vqvalue = ghb_settings_get_int(settings, "VideoAvgBitrate");
250 vq_desc = "Bitrate:";
252 vqstr = g_strdup_printf("%d", (gint)vqvalue);
257 vqvalue = ghb_settings_get_double(settings, "VideoQualitySlider");
258 vq_desc = "Constant Quality:";
259 vqstr = g_strdup_printf("%d", (gint)vqvalue);
262 fps = ghb_settings_get_string(settings, "VideoFramerate");
263 if (strcmp("source", fps) == 0)
266 if (ghb_settings_combo_int(settings, "PictureDetelecine"))
267 fps = g_strdup("Same As Source (vfr detelecine)");
269 fps = g_strdup("Same As Source (variable)");
274 tmp = g_strdup_printf("%s (constant frame rate)", fps);
278 vcodec = ghb_settings_combo_option(settings, "VideoEncoder");
279 vcodec_abbr = ghb_settings_get_string(settings, "VideoEncoder");
280 source_width = ghb_settings_get_int(settings, "source_width");
281 source_height = ghb_settings_get_int(settings, "source_height");
282 g_string_append_printf(str,
283 "<b>Picture:</b> Source: <small>%d x %d, Output %d x %d %s</small>\n",
284 source_width, source_height, width, height, aspect_desc);
287 gboolean decomb_deint;
288 gboolean filters = FALSE;
290 decomb_deint = ghb_settings_get_boolean(settings, "PictureDecombDeinterlace");
291 decomb = ghb_settings_combo_int(settings, "PictureDecomb");
292 g_string_append_printf(str, "<b>Filters:</b><small>");
293 detel = ghb_settings_combo_int(settings, "PictureDetelecine");
296 g_string_append_printf(str, " - Detelecine");
300 cust = ghb_settings_get_string(settings, "PictureDetelecineCustom");
301 g_string_append_printf(str, ": %s", cust);
306 if (decomb_deint && decomb)
308 g_string_append_printf(str, " - Decomb");
312 cust = ghb_settings_get_string(settings, "PictureDecombCustom");
313 g_string_append_printf(str, ": %s", cust);
318 else if (!decomb_deint)
320 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
325 gchar *cust = ghb_settings_get_string(settings,
326 "PictureDeinterlaceCustom");
327 g_string_append_printf(str, " - Deinterlace: %s", cust);
332 const gchar *opt = ghb_settings_combo_option(settings,
333 "PictureDeinterlace");
334 g_string_append_printf(str, " - Deinterlace: %s", opt);
339 gint denoise = ghb_settings_combo_int(settings, "PictureDenoise");
344 gchar *cust = ghb_settings_get_string(settings,
345 "PictureDenoiseCustom");
346 g_string_append_printf(str, " - Denoise: %s", cust);
351 const gchar *opt = ghb_settings_combo_option(settings,
353 g_string_append_printf(str, " - Denoise: %s", opt);
357 gint deblock = ghb_settings_get_int(settings, "PictureDeblock");
360 g_string_append_printf(str, " - Deblock (%d)", deblock);
363 if (ghb_settings_get_boolean(settings, "VideoGrayScale"))
365 g_string_append_printf(str, " - Grayscale");
369 g_string_append_printf(str, " None");
370 g_string_append_printf(str, "</small>\n");
372 g_string_append_printf(str,
373 "<b>Video:</b> <small>%s, Framerate: %s, %s %s%s</small>\n",
374 vcodec, fps, vq_desc, vqstr, vq_units);
376 turbo = ghb_settings_get_boolean(settings, "VideoTurboTwoPass");
379 g_string_append_printf(str, "<b>Turbo:</b> <small>On</small>\n");
381 if (strcmp(vcodec_abbr, "x264") == 0)
383 gchar *x264opts = ghb_build_x264opts_string(settings);
384 g_string_append_printf(str,
385 "<b>x264 Options:</b> <small>%s</small>\n", x264opts);
390 const GValue *audio_list;
392 audio_list = ghb_settings_get_value(settings, "audio_list");
393 count = ghb_array_len(audio_list);
394 for (ii = 0; ii < count; ii++)
396 gchar *bitrate, *samplerate, *track;
397 const gchar *acodec, *mix;
401 asettings = ghb_array_get_nth(audio_list, ii);
403 acodec = ghb_settings_combo_option(asettings, "AudioEncoderActual");
404 bitrate = ghb_settings_get_string(asettings, "AudioBitrate");
405 sr = ghb_settings_get_double(asettings, "AudioSamplerate");
406 samplerate = ghb_settings_get_string(asettings, "AudioSamplerate");
409 samplerate = g_strdup("Same As Source");
413 samplerate = g_strdup_printf("%.4g", sr);
415 track = ghb_settings_get_string(asettings, "AudioTrackDescription");
416 mix = ghb_settings_combo_option(asettings, "AudioMixdown");
418 g_string_append_printf(str, "<b>Audio:</b>");
420 g_string_append_printf(str, "<b>Audio:</b>\n");
422 g_string_append_printf(str, "\t");
424 g_string_append_printf(str,
425 "<small> %s, Encoder: %s, Mixdown: %s, SampleRate: %s, Bitrate: %s</small>\n",
426 track, acodec, mix, samplerate, bitrate);
433 const GValue *sub_list;
435 sub_list = ghb_settings_get_value(settings, "subtitle_list");
436 count = ghb_array_len(sub_list);
437 for (ii = 0; ii < count; ii++)
441 gboolean force, burn, def;
444 settings = ghb_array_get_nth(sub_list, ii);
445 track = ghb_settings_get_string(settings, "SubtitleTrackDescription");
446 source = ghb_settings_get_int(settings, "SubtitleSource");
447 force = ghb_settings_get_boolean(settings, "SubtitleForced");
448 burn = ghb_settings_get_boolean(settings, "SubtitleBurned");
449 def = ghb_settings_get_boolean(settings, "SubtitleDefaultTrack");
451 g_string_append_printf(str, "<b>Subtitle:</b>");
453 g_string_append_printf(str, "<b>Subtitles:</b>\n");
455 g_string_append_printf(str, "\t");
457 if (source != SRTSUB)
459 g_string_append_printf(str,
460 "<small> %s%s%s%s</small>",
462 force ? " (Force)":"",
464 def ? " (Default)":""
470 gchar *filename, *basename, *code;
472 offset = ghb_settings_get_int(settings, "SrtOffset");
473 filename = ghb_settings_get_string(settings, "SrtFile");
474 basename = g_path_get_basename(filename);
475 code = ghb_settings_get_string(settings, "SrtCodeset");
476 g_string_append_printf(str,
477 "<small> %s (%s), %s, Offset (ms) %d%s</small>",
478 track, code, basename, offset,
479 def ? " (Default)":""
486 g_string_append_printf(str, "\n");
490 info = g_string_free(str, FALSE);
491 gtk_tree_store_append(store, &citer, &iter);
492 gtk_tree_store_set(store, &citer, 1, info, -1);
502 audio_list_refresh(signal_user_data_t *ud)
504 GtkTreeView *treeview;
509 const GValue *audio_list;
511 g_debug("ghb_audio_list_refresh ()");
512 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_list"));
513 store = GTK_LIST_STORE(gtk_tree_view_get_model(treeview));
514 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter))
518 const gchar *track, *codec, *br, *sr, *mix;
524 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
525 if (row >= ghb_array_len(audio_list))
527 asettings = ghb_array_get_nth(audio_list, row);
529 track = ghb_settings_combo_option(asettings, "AudioTrack");
530 itrack = ghb_settings_combo_int(asettings, "AudioTrack");
531 codec = ghb_settings_combo_option(asettings, "AudioEncoderActual");
532 br = ghb_settings_combo_option(asettings, "AudioBitrate");
533 sr = ghb_settings_combo_option(asettings, "AudioSamplerate");
534 mix = ghb_settings_combo_option(asettings, "AudioMixdown");
536 drc = ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
538 s_drc = g_strdup("Off");
540 s_drc = g_strdup_printf("%.1f", drc);
542 gtk_list_store_set(GTK_LIST_STORE(store), &iter,
543 // These are displayed in list
552 done = !gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
559 validate_settings(signal_user_data_t *ud)
561 // Check to see if the dest file exists or is
562 // already in the queue
563 gchar *message, *dest;
567 titleindex = ghb_settings_combo_int(ud->settings, "title");
568 if (titleindex < 0) return FALSE;
569 dest = ghb_settings_get_string(ud->settings, "destination");
570 count = ghb_array_len(ud->queue);
571 for (ii = 0; ii < count; ii++)
576 js = ghb_array_get_nth(ud->queue, ii);
577 filename = ghb_settings_get_string(js, "destination");
578 if (strcmp(dest, filename) == 0)
580 message = g_strdup_printf(
581 "Destination: %s\n\n"
582 "Another queued job has specified the same destination.\n"
583 "Do you want to overwrite?",
585 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Overwrite"))
597 gchar *destdir = g_path_get_dirname(dest);
598 if (!g_file_test(destdir, G_FILE_TEST_IS_DIR))
600 message = g_strdup_printf(
601 "Destination: %s\n\n"
602 "This is not a valid directory.",
604 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
611 // This doesn't work properly on windows
612 if (g_access(destdir, R_OK|W_OK) != 0)
614 message = g_strdup_printf(
615 "Destination: %s\n\n"
616 "Can not read or write the directory.",
618 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
628 gchar *resolved = ghb_resolve_symlink(destdir);
630 gfile = g_file_new_for_path(resolved);
631 info = g_file_query_filesystem_info(gfile,
632 G_FILE_ATTRIBUTE_FILESYSTEM_FREE, NULL, NULL);
635 if (g_file_info_has_attribute(info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE))
637 size = g_file_info_get_attribute_uint64(info,
638 G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
640 gint64 fsize = (guint64)10 * 1024 * 1024 * 1024;
643 message = g_strdup_printf(
644 "Destination filesystem is almost full: %uM free\n\n"
645 "Encode may be incomplete if you proceed.\n",
646 (guint)(size / (1024L*1024L)));
647 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Proceed"))
656 g_object_unref(info);
658 g_object_unref(gfile);
661 if (g_file_test(dest, G_FILE_TEST_EXISTS))
663 message = g_strdup_printf(
664 "Destination: %s\n\n"
665 "File already exists.\n"
666 "Do you want to overwrite?",
668 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "Cancel", "Overwrite"))
678 // Validate video quality is in a reasonable range
679 if (!ghb_validate_vquality(ud->settings))
683 // Validate audio settings
684 if (!ghb_validate_audio(ud))
688 // Validate audio settings
689 if (!ghb_validate_subtitles(ud))
693 // Validate video settings
694 if (!ghb_validate_video(ud))
698 // Validate filter settings
699 if (!ghb_validate_filters(ud))
703 audio_list_refresh(ud);
708 queue_add(signal_user_data_t *ud)
710 // Add settings to the queue
715 g_debug("queue_add ()");
716 if (!validate_settings(ud))
721 if (ud->queue == NULL)
722 ud->queue = ghb_array_value_new(32);
723 // Make a copy of current settings to be used for the new job
724 settings = ghb_value_dup(ud->settings);
725 ghb_settings_set_int(settings, "job_status", GHB_QUEUE_PENDING);
726 ghb_settings_set_int(settings, "job_unique_id", 0);
727 titleindex = ghb_settings_combo_int(settings, "title");
728 titlenum = ghb_get_title_number(titleindex);
729 ghb_settings_set_int(settings, "titlenum", titlenum);
730 ghb_array_append(ud->queue, settings);
731 add_to_queue_list(ud, settings, NULL);
732 ghb_save_queue(ud->queue);
733 ghb_update_pending(ud);
739 queue_add_clicked_cb(GtkWidget *widget, signal_user_data_t *ud)
741 g_debug("queue_add_clicked_cb ()");
746 queue_remove_clicked_cb(GtkWidget *widget, gchar *path, signal_user_data_t *ud)
748 GtkTreeView *treeview;
749 GtkTreePath *treepath;
758 g_debug("queue_remove_clicked_cb ()");
759 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
760 store = gtk_tree_view_get_model(treeview);
761 treepath = gtk_tree_path_new_from_string (path);
762 if (gtk_tree_path_get_depth(treepath) > 1) return;
763 if (gtk_tree_model_get_iter(store, &iter, treepath))
765 // Find the entry in the queue
766 indices = gtk_tree_path_get_indices (treepath);
768 // Can only free the treepath After getting what I need from
769 // indices since this points into treepath somewhere.
770 gtk_tree_path_free (treepath);
772 if (row >= ghb_array_len(ud->queue))
774 settings = ghb_array_get_nth(ud->queue, row);
775 status = ghb_settings_get_int(settings, "job_status");
776 if (status == GHB_QUEUE_RUNNING)
778 // Ask if wants to stop encode.
779 if (!ghb_cancel_encode2(ud, NULL))
783 unique_id = ghb_settings_get_int(settings, "job_unique_id");
784 ghb_remove_job(unique_id);
786 // Remove the selected item
787 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
788 // Remove the corresponding item from the queue list
789 GValue *old = ghb_array_get_nth(ud->queue, row);
791 ghb_array_remove(ud->queue, row);
792 ghb_save_queue(ud->queue);
796 gtk_tree_path_free (treepath);
798 ghb_update_pending(ud);
802 find_last_finished(GValue *queue)
808 g_debug("find_last_finished");
809 count = ghb_array_len(queue);
810 for (ii = 0; ii < count; ii++)
812 js = ghb_array_get_nth(queue, ii);
813 status = ghb_settings_get_int(js, "job_status");
814 if (status != GHB_QUEUE_DONE && status != GHB_QUEUE_RUNNING)
822 // This little bit is needed to prevent the default drag motion
823 // handler from expanding rows if you hover over them while
825 // Also controls where valid drop locations are
826 G_MODULE_EXPORT gboolean
827 queue_drag_motion_cb(
833 signal_user_data_t *ud)
835 GtkTreePath *path = NULL;
836 GtkTreeViewDropPosition pos;
837 gint *indices, row, status, finished;
842 GtkTreeSelection *select;
845 widget = gtk_drag_get_source_widget(ctx);
846 if (widget == NULL || widget != GTK_WIDGET(tv))
849 // This bit checks to see if the source is allowed to be
850 // moved. Only pending and canceled items may be moved.
851 srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
852 select = gtk_tree_view_get_selection (srctv);
853 gtk_tree_selection_get_selected (select, &model, &iter);
854 path = gtk_tree_model_get_path (model, &iter);
855 indices = gtk_tree_path_get_indices(path);
857 gtk_tree_path_free(path);
858 js = ghb_array_get_nth(ud->queue, row);
859 status = ghb_settings_get_int(js, "job_status");
860 if (status != GHB_QUEUE_PENDING && status != GHB_QUEUE_CANCELED)
862 gdk_drag_status(ctx, 0, time);
866 // The reset checks that the destination is a valid position
867 // in the list. Can not move above any finished or running items
868 gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &pos);
871 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
874 // Don't allow *drop into*
875 if (pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
876 pos = GTK_TREE_VIEW_DROP_BEFORE;
877 if (pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
878 pos = GTK_TREE_VIEW_DROP_AFTER;
879 // Don't allow droping int child items
880 if (gtk_tree_path_get_depth(path) > 1)
882 gtk_tree_path_up(path);
883 pos = GTK_TREE_VIEW_DROP_AFTER;
885 indices = gtk_tree_path_get_indices(path);
887 js = ghb_array_get_nth(ud->queue, row);
889 finished = find_last_finished(ud->queue);
892 gtk_tree_path_free(path);
893 gdk_drag_status(ctx, 0, time);
896 if (pos != GTK_TREE_VIEW_DROP_AFTER &&
899 gtk_tree_path_free(path);
900 gdk_drag_status(ctx, 0, time);
903 gtk_tree_view_set_drag_dest_row(tv, path, pos);
904 gtk_tree_path_free(path);
905 gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
911 GtkTreeView *dstwidget,
914 GtkSelectionData *selection_data,
916 signal_user_data_t *ud)
918 GtkTreePath *path = NULL;
919 //GtkTreeModel *model;
920 GtkTreeViewDropPosition pos;
921 GtkTreeIter dstiter, srciter;
925 GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
927 g_debug("queue_drag_cb ()");
928 // This doesn't work here for some reason...
929 // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &pos);
930 gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &pos);
931 // This little hack is needed because attempting to drop after
932 // the last item gives us no path or pos.
937 n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
940 pos = GTK_TREE_VIEW_DROP_AFTER;
941 path = gtk_tree_path_new_from_indices(n_children-1, -1);
945 pos = GTK_TREE_VIEW_DROP_BEFORE;
946 path = gtk_tree_path_new_from_indices(0, -1);
951 if (gtk_tree_path_get_depth(path) > 1)
952 gtk_tree_path_up(path);
953 if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
956 GtkTreeView *srcwidget;
957 GtkTreeModel *srcmodel;
958 GtkTreeSelection *select;
959 GtkTreePath *srcpath = NULL;
960 GtkTreePath *dstpath = NULL;
962 srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
963 //srcmodel = gtk_tree_view_get_model(srcwidget);
964 select = gtk_tree_view_get_selection (srcwidget);
965 gtk_tree_selection_get_selected (select, &srcmodel, &srciter);
967 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
968 indices = gtk_tree_path_get_indices(srcpath);
970 gtk_tree_path_free(srcpath);
971 js = ghb_array_get_nth(ud->queue, row);
975 case GTK_TREE_VIEW_DROP_BEFORE:
976 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
977 gtk_tree_store_insert_before (GTK_TREE_STORE (dstmodel),
978 &iter, NULL, &dstiter);
981 case GTK_TREE_VIEW_DROP_AFTER:
982 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
983 gtk_tree_store_insert_after (GTK_TREE_STORE (dstmodel),
984 &iter, NULL, &dstiter);
990 // Reset job to pending
991 ghb_settings_set_int(js, "job_status", GHB_QUEUE_PENDING);
992 add_to_queue_list(ud, js, &iter);
994 dstpath = gtk_tree_model_get_path (dstmodel, &iter);
995 indices = gtk_tree_path_get_indices(dstpath);
997 gtk_tree_path_free(dstpath);
998 ghb_array_insert(ud->queue, row, js);
1000 srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
1001 indices = gtk_tree_path_get_indices(srcpath);
1003 gtk_tree_path_free(srcpath);
1004 ghb_array_remove(ud->queue, row);
1005 gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
1006 ghb_save_queue(ud->queue);
1008 gtk_tree_path_free(path);
1013 ghb_queue_buttons_grey(signal_user_data_t *ud)
1019 gint queue_state, scan_state;
1020 gboolean show_start, show_stop, paused;
1022 queue_count = ghb_array_len(ud->queue);
1023 titleindex = ghb_settings_combo_int(ud->settings, "title");
1025 queue_state = ghb_get_queue_state();
1026 scan_state = ghb_get_scan_state();
1028 show_stop = queue_state &
1029 (GHB_STATE_WORKING | GHB_STATE_SEARCHING |
1030 GHB_STATE_SCANNING | GHB_STATE_MUXING);
1031 show_start = !(scan_state & GHB_STATE_SCANNING) &&
1032 (titleindex >= 0 || queue_count > 0);
1035 paused = queue_state & GHB_STATE_PAUSED;
1037 widget = GHB_WIDGET(ud->builder, "queue_add");
1038 gtk_widget_set_sensitive(widget, show_start);
1039 action = GHB_ACTION(ud->builder, "queue_add_menu");
1040 gtk_action_set_sensitive(action, show_start);
1042 widget = GHB_WIDGET (ud->builder, "queue_start1");
1045 gtk_widget_set_sensitive (widget, TRUE);
1046 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-stop");
1047 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Stop");
1048 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Stop Encoding");
1052 gtk_widget_set_sensitive (widget, show_start);
1053 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-play");
1054 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Start");
1055 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Start Encoding");
1057 widget = GHB_WIDGET (ud->builder, "queue_start2");
1060 gtk_widget_set_sensitive (widget, TRUE);
1061 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-stop");
1062 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Stop");
1063 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Stop Encoding");
1067 gtk_widget_set_sensitive (widget, show_start);
1068 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-play");
1069 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Start");
1070 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Start Encoding");
1072 widget = GHB_WIDGET (ud->builder, "queue_pause1");
1075 gtk_widget_set_sensitive (widget, show_stop);
1076 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-play");
1077 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Resume");
1078 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Resume Encoding");
1082 gtk_widget_set_sensitive (widget, show_stop);
1083 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-pause");
1084 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Pause");
1085 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Pause Encoding");
1087 widget = GHB_WIDGET (ud->builder, "queue_pause2");
1090 gtk_widget_set_sensitive (widget, show_stop);
1091 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-play");
1092 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Resume");
1093 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Resume Encoding");
1097 gtk_widget_set_sensitive (widget, show_stop);
1098 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(widget), "hb-pause");
1099 gtk_tool_button_set_label(GTK_TOOL_BUTTON(widget), "Pause");
1100 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), "Pause Encoding");
1103 action = GHB_ACTION (ud->builder, "queue_start_menu");
1106 gtk_action_set_sensitive (action, TRUE);
1107 #if GTK_CHECK_VERSION(2, 16, 0)
1108 gtk_action_set_icon_name(action, "hb-stop");
1109 gtk_action_set_label(action, "S_top Queue");
1110 gtk_action_set_tooltip(action, "Stop Encoding");
1112 g_object_set_property(G_OBJECT(action), "icon-name",
1113 ghb_string_value("hb-stop"));
1114 g_object_set_property(G_OBJECT(action), "label",
1115 ghb_string_value("S_top Queue"));
1116 g_object_set_property(G_OBJECT(action), "tooltip",
1117 ghb_string_value("Stop Encoding"));
1122 gtk_action_set_sensitive (action, show_start);
1123 #if GTK_CHECK_VERSION(2, 16, 0)
1124 gtk_action_set_icon_name(action, "hb-play");
1125 gtk_action_set_label(action, "_Start Queue");
1126 gtk_action_set_tooltip(action, "Start Encoding");
1128 g_object_set_property(G_OBJECT(action), "icon-name",
1129 ghb_string_value("hb-play"));
1130 g_object_set_property(G_OBJECT(action), "label",
1131 ghb_string_value("_Start Queue"));
1132 g_object_set_property(G_OBJECT(action), "tooltip",
1133 ghb_string_value("Start Encoding"));
1136 action = GHB_ACTION (ud->builder, "queue_pause_menu");
1139 gtk_action_set_sensitive (action, show_start);
1140 #if GTK_CHECK_VERSION(2, 16, 0)
1141 gtk_action_set_icon_name(action, "hb-play");
1142 gtk_action_set_label(action, "_Resume Queue");
1143 gtk_action_set_tooltip(action, "Resume Encoding");
1145 g_object_set_property(G_OBJECT(action), "icon-name",
1146 ghb_string_value("hb-play"));
1147 g_object_set_property(G_OBJECT(action), "label",
1148 ghb_string_value("_Resume Queue"));
1149 g_object_set_property(G_OBJECT(action), "tooltip",
1150 ghb_string_value("Resume Encoding"));
1155 gtk_action_set_sensitive (action, show_stop);
1156 #if GTK_CHECK_VERSION(2, 16, 0)
1157 gtk_action_set_icon_name(action, "hb-pause");
1158 gtk_action_set_label(action, "_Pause Queue");
1159 gtk_action_set_tooltip(action, "Pause Encoding");
1161 g_object_set_property(G_OBJECT(action), "icon-name",
1162 ghb_string_value("hb-pause"));
1163 g_object_set_property(G_OBJECT(action), "label",
1164 ghb_string_value("_Pause Queue"));
1165 g_object_set_property(G_OBJECT(action), "tooltip",
1166 ghb_string_value("Pause Encoding"));
1171 G_MODULE_EXPORT void
1172 queue_list_size_allocate_cb(GtkWidget *widget, GtkAllocation *allocation, GtkCellRenderer *cell)
1174 GtkTreeViewColumn *column;
1177 column = gtk_tree_view_get_column (GTK_TREE_VIEW(widget), 0);
1178 width = gtk_tree_view_column_get_width(column);
1179 g_debug("col width %d alloc width %d", width, allocation->width);
1180 // Set new wrap-width. Shave a little off to accomidate the icons
1181 // that share this column.
1182 if (width >= 564) // Don't allow below a certain size
1183 g_object_set(cell, "wrap-width", width-70, NULL);
1186 G_MODULE_EXPORT void
1187 queue_start_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
1190 gboolean running = FALSE;
1195 state = ghb_get_queue_state();
1196 if (state & (GHB_STATE_WORKING | GHB_STATE_SEARCHING |
1197 GHB_STATE_SCANNING | GHB_STATE_MUXING))
1199 ghb_cancel_encode(ud, "You are currently encoding. "
1200 "What would you like to do?");
1204 count = ghb_array_len(ud->queue);
1205 for (ii = 0; ii < count; ii++)
1207 js = ghb_array_get_nth(ud->queue, ii);
1208 status = ghb_settings_get_int(js, "job_status");
1209 if ((status == GHB_QUEUE_RUNNING) ||
1210 (status == GHB_QUEUE_PENDING))
1218 // The queue has no running or pending jobs.
1219 // Add current settings to the queue, then run.
1223 if (state == GHB_STATE_IDLE)
1225 // Add the first pending queue item and start
1226 ud->current_job = ghb_start_next_job(ud, TRUE);
1230 G_MODULE_EXPORT void
1231 queue_pause_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
1237 ghb_reload_queue(signal_user_data_t *ud)
1240 gint unfinished = 0;
1247 g_debug("ghb_reload_queue");
1250 pid = ghb_find_pid_file();
1254 queue = ghb_load_old_queue(pid);
1255 ghb_remove_old_queue_file(pid);
1256 // Look for unfinished entries
1257 count = ghb_array_len(queue);
1258 for (ii = 0; ii < count; ii++)
1260 settings = ghb_array_get_nth(queue, ii);
1261 status = ghb_settings_get_int(settings, "job_status");
1262 if (status != GHB_QUEUE_DONE && status != GHB_QUEUE_CANCELED)
1272 message = g_strdup_printf(
1273 "You have %d unfinished job%s in a saved queue.\n\n"
1274 "Would you like to reload %s?",
1276 (unfinished > 1) ? "s" : "",
1277 (unfinished > 1) ? "them" : "it");
1278 if (ghb_message_dialog(GTK_MESSAGE_QUESTION, message, "No", "Yes"))
1280 GtkWidget *widget = GHB_WIDGET (ud->builder, "queue_window");
1281 gtk_widget_show (widget);
1282 widget = GHB_WIDGET (ud->builder, "show_queue");
1283 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(widget), TRUE);
1286 // First get rid of any old items we don't want
1287 for (ii = count-1; ii >= 0; ii--)
1289 settings = ghb_array_get_nth(queue, ii);
1290 status = ghb_settings_get_int(settings, "job_status");
1291 if (status == GHB_QUEUE_DONE || status == GHB_QUEUE_CANCELED)
1293 GValue *old = ghb_array_get_nth(queue, ii);
1294 ghb_value_free(old);
1295 ghb_array_remove(queue, ii);
1298 count = ghb_array_len(queue);
1299 for (ii = 0; ii < count; ii++)
1301 settings = ghb_array_get_nth(queue, ii);
1302 ghb_settings_set_int(settings, "job_unique_id", 0);
1303 ghb_settings_set_int(settings, "job_status", GHB_QUEUE_PENDING);
1304 add_to_queue_list(ud, settings, NULL);
1306 ghb_queue_buttons_grey(ud);
1307 ghb_save_queue(ud->queue);
1311 ghb_value_free(queue);
1318 G_MODULE_EXPORT gboolean
1322 signal_user_data_t *ud)
1324 GtkTreeView *treeview;
1325 GtkTreeSelection *selection;
1326 GtkTreeModel *store;
1334 g_debug("queue_key_press_cb ()");
1335 if (event->keyval != GDK_Delete)
1337 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
1338 store = gtk_tree_view_get_model(treeview);
1340 selection = gtk_tree_view_get_selection (treeview);
1341 if (gtk_tree_selection_get_selected(selection, &store, &iter))
1343 GtkTreePath *treepath;
1345 treepath = gtk_tree_model_get_path (store, &iter);
1346 // Find the entry in the queue
1347 indices = gtk_tree_path_get_indices (treepath);
1349 // Can only free the treepath After getting what I need from
1350 // indices since this points into treepath somewhere.
1351 gtk_tree_path_free (treepath);
1352 if (row < 0) return FALSE;
1353 if (row >= ghb_array_len(ud->queue))
1355 settings = ghb_array_get_nth(ud->queue, row);
1356 status = ghb_settings_get_int(settings, "job_status");
1357 if (status == GHB_QUEUE_RUNNING)
1359 // Ask if wants to stop encode.
1360 if (!ghb_cancel_encode2(ud, NULL))
1364 unique_id = ghb_settings_get_int(settings, "job_unique_id");
1365 ghb_remove_job(unique_id);
1367 // Remove the selected item
1368 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
1369 // Remove the corresponding item from the queue list
1370 GValue *old = ghb_array_get_nth(ud->queue, row);
1371 ghb_value_free(old);
1372 ghb_array_remove(ud->queue, row);
1373 ghb_save_queue(ud->queue);
1379 GValue *ghb_queue_edit_settings = NULL;
1381 G_MODULE_EXPORT void
1382 queue_edit_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
1384 GtkTreeView *treeview;
1385 GtkTreeSelection *selection;
1386 GtkTreeModel *store;
1392 g_debug("queue_key_press_cb ()");
1393 treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "queue_list"));
1394 store = gtk_tree_view_get_model(treeview);
1396 selection = gtk_tree_view_get_selection (treeview);
1397 if (gtk_tree_selection_get_selected(selection, &store, &iter))
1399 GtkTreePath *treepath;
1401 treepath = gtk_tree_model_get_path (store, &iter);
1402 // Find the entry in the queue
1403 indices = gtk_tree_path_get_indices (treepath);
1405 // Can only free the treepath After getting what I need from
1406 // indices since this points into treepath somewhere.
1407 gtk_tree_path_free (treepath);
1408 if (row < 0) return;
1409 if (row >= ghb_array_len(ud->queue))
1411 ghb_queue_edit_settings = ghb_array_get_nth(ud->queue, row);
1412 status = ghb_settings_get_int(ghb_queue_edit_settings, "job_status");
1413 if (status == GHB_QUEUE_PENDING)
1415 // Remove the selected item
1416 gtk_tree_store_remove(GTK_TREE_STORE(store), &iter);
1417 // Remove the corresponding item from the queue list
1418 ghb_array_remove(ud->queue, row);
1422 ghb_queue_edit_settings = ghb_value_dup(ghb_queue_edit_settings);
1425 source = ghb_settings_get_string(ghb_queue_edit_settings, "source");
1426 ghb_do_scan(ud, source, 0, FALSE);