summaryrefslogtreecommitdiffstats
path: root/gtk
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2009-07-17 20:53:16 +0000
committerjstebbins <[email protected]>2009-07-17 20:53:16 +0000
commitae2424a127a71e74727dd75b7ab0375821d94121 (patch)
treedba52a6627bfe6c14fbdba40bdbeaa3a6d071f65 /gtk
parent890cb717a4570aac796ccfbcd200983ad52447d5 (diff)
LinGui: add preference option to automatically add CC track if present
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2706 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'gtk')
-rw-r--r--gtk/src/ghb.ui22
-rw-r--r--gtk/src/hb-backend.c63
-rw-r--r--gtk/src/hb-backend.h2
-rw-r--r--gtk/src/internal_defaults.xml2
-rw-r--r--gtk/src/subtitlehandler.c29
5 files changed, 111 insertions, 7 deletions
diff --git a/gtk/src/ghb.ui b/gtk/src/ghb.ui
index 2c5779000..354912593 100644
--- a/gtk/src/ghb.ui
+++ b/gtk/src/ghb.ui
@@ -4016,15 +4016,23 @@ no-dct-decimate=0:cabac=1</property>
</packing>
</child>
<child>
- <object class="GtkHBox" id="hbox63">
+ <object class="GtkAlignment" id="alignment61">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="spacing">4</property>
- <child>
- <placeholder/>
- </child>
+ <property name="yscale">0</property>
+ <property name="left_padding">12</property>
+ <property name="top_padding">6</property>
+ <property name="bottom_padding">6</property>
<child>
- <placeholder/>
+ <object class="GtkCheckButton" id="AddCC">
+ <property name="label" translatable="yes">Add Closed Captions when available</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="active">False</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="pref_changed_cb"/>
+ </object>
</child>
</object>
<packing>
@@ -4040,7 +4048,7 @@ no-dct-decimate=0:cabac=1</property>
<child type="tab">
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
- <property name="label" translatable="yes">Audio</property>
+ <property name="label" translatable="yes">Audio/Subtitles</property>
</object>
<packing>
<property name="position">1</property>
diff --git a/gtk/src/hb-backend.c b/gtk/src/hb-backend.c
index 0a4c58ed7..54301af09 100644
--- a/gtk/src/hb-backend.c
+++ b/gtk/src/hb-backend.c
@@ -31,6 +31,7 @@
#include "settings.h"
#include "callbacks.h"
#include "subtitlehandler.h"
+#include "audiohandler.h"
#include "x264handler.h"
#include "preview.h"
#include "values.h"
@@ -1162,6 +1163,42 @@ done:
return name;
}
+gchar*
+ghb_subtitle_track_lang(signal_user_data_t *ud, gint track)
+{
+ gint titleindex;
+
+ titleindex = ghb_settings_combo_int(ud->settings, "title");
+ if (titleindex < 0)
+ goto fail;
+ if (track == -1)
+ return ghb_get_user_audio_lang(ud, titleindex, 0);
+ if (track < 0)
+ goto fail;
+
+ hb_list_t * list;
+ hb_title_t * title;
+ hb_subtitle_t * sub;
+
+ if (h_scan == NULL)
+ goto fail;
+
+ list = hb_get_titles( h_scan );
+ if( !hb_list_count( list ) )
+ {
+ /* No valid title, stop right there */
+ goto fail;
+ }
+ title = hb_list_item( list, titleindex );
+ if (title == NULL) // Bad titleindex
+ goto fail;
+ sub = hb_list_item( title->list_subtitle, track);
+ if (sub != NULL)
+ return g_strdup(sub->iso639_2);
+
+fail:
+ return g_strdup("und");
+}
gint
ghb_get_title_number(gint titleindex)
@@ -2113,6 +2150,32 @@ ghb_find_pref_subtitle_track(const gchar *lang)
}
gint
+ghb_find_cc_track(gint titleindex)
+{
+ hb_list_t * list;
+ hb_title_t * title;
+ hb_subtitle_t * subtitle;
+ gint count, ii;
+
+ g_debug("ghb_find_cc_track ()\n");
+ if (h_scan == NULL) return -2;
+ list = hb_get_titles( h_scan );
+ title = (hb_title_t*)hb_list_item( list, titleindex );
+ if (title != NULL)
+ {
+ count = hb_list_count( title->list_subtitle );
+ // Try to find an item that matches the preferred language
+ for (ii = 0; ii < count; ii++)
+ {
+ subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
+ if (subtitle->source == CC608SUB || subtitle->source == CC708SUB)
+ return ii;
+ }
+ }
+ return -2;
+}
+
+gint
ghb_find_subtitle_track(
gint titleindex,
const gchar *lang,
diff --git a/gtk/src/hb-backend.h b/gtk/src/hb-backend.h
index f46b64175..f110528f0 100644
--- a/gtk/src/hb-backend.h
+++ b/gtk/src/hb-backend.h
@@ -145,6 +145,7 @@ gint ghb_find_pref_subtitle_track(const gchar *lang);
gint ghb_find_subtitle_track(
gint titleindex, const gchar *lang, GHashTable *track_indices);
gint ghb_pick_subtitle_track(signal_user_data_t *ud);
+gint ghb_find_cc_track(gint titleindex);
gint ghb_longest_title(void);
gchar* ghb_build_x264opts_string(GValue *settings);
GdkPixbuf* ghb_get_preview_image(
@@ -155,6 +156,7 @@ gchar* ghb_dvd_volname(const gchar *device);
gint ghb_get_title_number(gint titleindex);
gint ghb_subtitle_track_source(signal_user_data_t *ud, gint track);
const char* ghb_subtitle_track_source_name(signal_user_data_t *ud, gint track);
+gchar* ghb_subtitle_track_lang(signal_user_data_t *ud, gint track);
gboolean ghb_validate_vquality(GValue *settings);
gboolean ghb_validate_audio(signal_user_data_t *ud);
diff --git a/gtk/src/internal_defaults.xml b/gtk/src/internal_defaults.xml
index f09df0da4..88d27af24 100644
--- a/gtk/src/internal_defaults.xml
+++ b/gtk/src/internal_defaults.xml
@@ -105,6 +105,8 @@
</dict>
<key>Preferences</key>
<dict>
+ <key>AddCC</key>
+ <false />
<key>EncodeLogLocation</key>
<false />
<key>show_status</key>
diff --git a/gtk/src/subtitlehandler.c b/gtk/src/subtitlehandler.c
index 938323ea4..c2bce5fc5 100644
--- a/gtk/src/subtitlehandler.c
+++ b/gtk/src/subtitlehandler.c
@@ -264,6 +264,7 @@ ghb_set_pref_subtitle(gint titleindex, signal_user_data_t *ud)
gchar *lang, *pref_lang = NULL;
gchar *audio_lang;
gint foreign_lang_index = -1;
+ gboolean found_cc = FALSE;
const GValue *pref_subtitle;
GValue *subtitle;
@@ -313,9 +314,12 @@ ghb_set_pref_subtitle(gint titleindex, signal_user_data_t *ud)
// select sequential tracks for each. The hash keeps track
// of the tracks used for each language.
track = ghb_find_subtitle_track(titleindex, lang, track_indices);
+ g_free(lang);
if (track >= -1)
{
+ gint source;
GValue *dup = ghb_value_dup(subtitle);
+ lang = ghb_subtitle_track_lang(ud, track);
ghb_settings_set_int(dup, "SubtitleTrack", track);
if (foreign_lang_index < 0 && pref_lang != NULL &&
strcmp(lang, pref_lang) == 0)
@@ -326,6 +330,9 @@ ghb_set_pref_subtitle(gint titleindex, signal_user_data_t *ud)
ghb_settings_take_value(dup, "SubtitleDefaultTrack",
ghb_boolean_value_new(TRUE));
}
+ source = ghb_subtitle_track_source(ud, track);
+ if (source == CC608SUB || source == CC708SUB)
+ found_cc = TRUE;
ghb_add_subtitle(ud, dup);
jj++;
}
@@ -333,6 +340,7 @@ ghb_set_pref_subtitle(gint titleindex, signal_user_data_t *ud)
}
if (foreign_lang_index < 0 && pref_lang != NULL)
{
+ // Subtitle for foreign language audio not added yet
GValue *settings;
gboolean burn;
@@ -369,6 +377,27 @@ ghb_set_pref_subtitle(gint titleindex, signal_user_data_t *ud)
ghb_subtitle_exclusive_default(ud, foreign_lang_index);
ghb_log("adding subtitle for foreign language audio: %s", audio_lang);
}
+ if (ghb_settings_get_boolean(ud->settings, "AddCC") && !found_cc)
+ {
+ // Subtitle for foreign language audio not added yet
+ GValue *settings;
+
+ track = ghb_find_cc_track(titleindex);
+ if (track >= 0)
+ {
+ settings = ghb_dict_value_new();
+ ghb_settings_set_int(settings, "SubtitleTrack", track);
+ ghb_settings_take_value(settings, "SubtitleForced",
+ ghb_boolean_value_new(FALSE));
+ ghb_settings_take_value(settings, "SubtitleBurned",
+ ghb_boolean_value_new(FALSE));
+ ghb_settings_take_value(settings, "SubtitleDefaultTrack",
+ ghb_boolean_value_new(FALSE));
+
+ ghb_add_subtitle(ud, settings);
+ ghb_log("adding Closed Captions: %s", audio_lang);
+ }
+ }
if (pref_lang != NULL)
g_free(pref_lang);
if (audio_lang != NULL)