]> granicus.if.org Git - handbrake/commitdiff
LinGui: add SSA import
authorJohn Stebbins <jstebbins.hb@gmail.com>
Sun, 6 Jan 2019 17:33:11 +0000 (10:33 -0700)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Mon, 14 Jan 2019 21:36:08 +0000 (13:36 -0800)
gtk/src/ghb.m4
gtk/src/queuehandler.c
gtk/src/settings.c
gtk/src/subtitlehandler.c

index d1af69c13fd8729fbda5986e82ef5d16262116fa..53d97b57984d970d8db7fd8e80e6c9a1ee291642 100644 (file)
@@ -8217,7 +8217,24 @@ filter_output([
               </packing>
             </child>
             <child>
-              <object class="GtkRadioButton" id="SubtitleSrtDisable">
+              <object class="GtkRadioButton" id="SubtitleSsaEnable">
+                <property name="label" translatable="yes">Import SSA</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                <property name="tooltip_text" translatable="yes">Enable settings to import an SSA subtitle file</property>
+                <property name="halign">start</property>
+                <property name="draw_indicator">True</property>
+                <property name="group">SubtitleSrtEnable</property>
+                <signal name="toggled" handler="subtitle_import_radio_toggled_cb" swapped="no"/>
+              </object>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkRadioButton" id="SubtitleImportDisable">
                 <property name="label" translatable="yes">Embedded Subtitle List</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
@@ -8227,6 +8244,7 @@ filter_output([
                 <property name="halign">start</property>
                 <property name="draw_indicator">True</property>
                 <property name="group">SubtitleSrtEnable</property>
+                <signal name="toggled" handler="subtitle_import_radio_toggled_cb" swapped="no"/>
               </object>
               <packing>
                 <property name="position">1</property>
index 488c4d19541d28d69ee62ff3cf97ed398c6ca440..95b79c51b6febb5bed33129a47de9d7e1eb10cc5 100644 (file)
@@ -88,15 +88,20 @@ ghb_subtitle_short_description(const GhbValue *subsource,
     import = ghb_dict_get(subsettings, "Import");
     if (import != NULL)
     {
-        const gchar *format = "SRT";
-        const gchar *code;
-        const gchar *lang;
+        const gchar * format = "SRT";
+        const gchar * code;
+        const gchar * lang;
+        int           source = IMPORTSRT;
         const iso639_lang_t *iso;
 
         format = ghb_dict_get_string(import, "Format");
-        lang = ghb_dict_get_string(import, "Language");
-        code = ghb_dict_get_string(import, "Codeset");
+        lang   = ghb_dict_get_string(import, "Language");
+        code   = ghb_dict_get_string(import, "Codeset");
 
+        if (format != NULL && !strcasecmp(format, "SSA"))
+        {
+            source = IMPORTSSA;
+        }
         iso = lang_lookup(lang);
         if (iso != NULL)
         {
@@ -106,7 +111,7 @@ ghb_subtitle_short_description(const GhbValue *subsource,
                 lang = iso->eng_name;
         }
 
-        if (code != NULL)
+        if (source == IMPORTSRT)
         {
             desc = g_strdup_printf("%s (%s)(%s)", lang, code, format);
         }
@@ -138,16 +143,21 @@ subtitle_get_track_description(const GhbValue *subsource,
     import = ghb_dict_get(subsettings, "Import");
     if (import != NULL)
     {
-        const gchar *format = "SRT";
-        const gchar *filename, *code;
-        const gchar *lang;
+        const gchar * format = "SRT";
+        const gchar * filename, *code;
+        const gchar * lang;
+        int           source = IMPORTSRT;
         const iso639_lang_t *iso;
 
-        format = ghb_dict_get_string(import, "Format");
-        lang = ghb_dict_get_string(import, "Language");
-        code = ghb_dict_get_string(import, "Codeset");
+        format   = ghb_dict_get_string(import, "Format");
+        lang     = ghb_dict_get_string(import, "Language");
+        code     = ghb_dict_get_string(import, "Codeset");
         filename = ghb_dict_get_string(import, "Filename");
 
+        if (format != NULL && !strcasecmp(format, "SSA"))
+        {
+            source = IMPORTSSA;
+        }
         iso = lang_lookup(lang);
         if (iso != NULL)
         {
@@ -162,7 +172,7 @@ subtitle_get_track_description(const GhbValue *subsource,
             gchar *basename;
 
             basename = g_path_get_basename(filename);
-            if (code != NULL)
+            if (source == IMPORTSRT)
             {
                 desc = g_strdup_printf("%s (%s)(%s)(%s)",
                                        lang, code, format, basename);
@@ -175,7 +185,7 @@ subtitle_get_track_description(const GhbValue *subsource,
         }
         else
         {
-            if (code != NULL)
+            if (source == IMPORTSRT)
             {
                 desc = g_strdup_printf("%s (%s)(%s)", lang, code, format);
             }
index 40c3624379b462be223b12d47e6e2ee58539d56b..856081c2a3f41e1a9f40ab3e5d15786922456e5b 100644 (file)
@@ -699,11 +699,12 @@ ghb_update_widget(GtkWidget *widget, const GhbValue *value)
             }
             else
             {
-                gchar *dirname;
+                gchar * dirname;
 
                 dirname = g_path_get_dirname(str);
                 gtk_file_chooser_set_current_folder(
                     GTK_FILE_CHOOSER(widget), dirname);
+                gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(widget));
                 g_free(dirname);
             }
         }
index a4fd3314b13ed39edca0b6cba35e270abf4367aa..dbf80c57bd4624765c7b6c55c362baee24c11367 100644 (file)
@@ -346,6 +346,7 @@ subtitle_get_track_description(GhbValue *settings, GhbValue *subsettings)
         const gchar * format = "SRT";
         const gchar * filename, * code;
         const gchar * lang;
+        int           source = IMPORTSRT;
         const iso639_lang_t * iso;
 
         format   = ghb_dict_get_string(import, "Format");
@@ -353,6 +354,10 @@ subtitle_get_track_description(GhbValue *settings, GhbValue *subsettings)
         lang     = ghb_dict_get_string(import, "Language");
         code     = ghb_dict_get_string(import, "Codeset");
 
+        if (format != NULL && !strcasecmp(format, "SSA"))
+        {
+            source = IMPORTSSA;
+        }
         iso = lang_lookup(lang);
         if (iso != NULL)
         {
@@ -367,7 +372,7 @@ subtitle_get_track_description(GhbValue *settings, GhbValue *subsettings)
             gchar *basename;
 
             basename = g_path_get_basename(filename);
-            if (code != NULL)
+            if (source == IMPORTSRT)
             {
                 desc = g_strdup_printf("%s (%s)(%s)(%s)",
                                        lang, code, format, basename);
@@ -380,7 +385,7 @@ subtitle_get_track_description(GhbValue *settings, GhbValue *subsettings)
         }
         else
         {
-            if (code != NULL)
+            if (source == IMPORTSRT)
             {
                 desc = g_strdup_printf("%s (%s)(%s)", lang, code, format);
             }
@@ -502,7 +507,7 @@ ghb_subtitle_title_change(signal_user_data_t *ud, gboolean show)
     const hb_title_t *title = ghb_lookup_title(title_id, NULL);
     if (title != NULL)
     {
-        w = GHB_WIDGET(ud->builder, "SubtitleSrtDisable");
+        w = GHB_WIDGET(ud->builder, "SubtitleImportDisable");
         gtk_widget_set_sensitive(w, !!hb_list_count(title->list_subtitle));
     }
 }
@@ -528,12 +533,12 @@ ghb_set_pref_subtitle(signal_user_data_t *ud)
     if (sub_count == 0)
     {
         // No source subtitles
-        widget = GHB_WIDGET(ud->builder, "SubtitleSrtDisable");
-        gtk_widget_set_sensitive(widget, FALSE);
+        widget = GHB_WIDGET(ud->builder, "SubtitleSrtEnable");
+        gtk_widget_set_sensitive(widget, TRUE);
     }
     else
     {
-        widget = GHB_WIDGET(ud->builder, "SubtitleSrtDisable");
+        widget = GHB_WIDGET(ud->builder, "SubtitleImportDisable");
         gtk_widget_set_sensitive(widget, TRUE);
     }
     GhbValue *job = ghb_get_job_settings(ud->settings);
@@ -671,7 +676,14 @@ subtitle_update_dialog_widgets(signal_user_data_t *ud, GhbValue *subsettings)
 
         if (import != NULL)
         {
-            ghb_ui_update(ud, "SubtitleSrtEnable", ghb_boolean_value(TRUE));
+            if (source == IMPORTSSA)
+            {
+                ghb_ui_update(ud, "SubtitleSsaEnable", ghb_boolean_value(TRUE));
+            }
+            else
+            {
+                ghb_ui_update(ud, "SubtitleSrtEnable", ghb_boolean_value(TRUE));
+            }
             val = ghb_dict_get(import, "Language");
             ghb_ui_update(ud, "ImportLanguage", val);
             val = ghb_dict_get(import, "Codeset");
@@ -683,7 +695,7 @@ subtitle_update_dialog_widgets(signal_user_data_t *ud, GhbValue *subsettings)
         }
         else
         {
-            ghb_ui_update(ud, "SubtitleSrtDisable", ghb_boolean_value(TRUE));
+            ghb_ui_update(ud, "SubtitleImportDisable", ghb_boolean_value(TRUE));
         }
 
         widget = GHB_WIDGET(ud->builder, "SubtitleBurned");
@@ -825,24 +837,40 @@ subtitle_import_radio_toggled_cb(GtkWidget *widget, signal_user_data_t *ud)
     GhbValue *subsettings;
 
     ghb_widget_to_setting(ud->settings, widget);
+    if (!ghb_dict_get_bool(ud->settings, "SubtitleSrtEnable") &&
+        !ghb_dict_get_bool(ud->settings, "SubtitleSsaEnable") &&
+        !ghb_dict_get_bool(ud->settings, "SubtitleImportDisable"))
+    {
+        // Radio buttons are in an in-between state with none enabled.
+        // Wait for the next toggle when something gets enabled.
+        return;
+    }
     subsettings = subtitle_get_selected_settings(ud, NULL);
     if (subsettings != NULL)
     {
-        if (ghb_dict_get_bool(ud->settings, "SubtitleSrtEnable"))
+        if (ghb_dict_get_bool(ud->settings, "SubtitleSrtEnable") ||
+            ghb_dict_get_bool(ud->settings, "SubtitleSsaEnable"))
         {
             const gchar *pref_lang, *dir;
             gchar *filename;
-            GhbValue *srt = ghb_dict_new();
+            GhbValue *import = ghb_dict_get(subsettings, "Import");
 
-            ghb_dict_set(subsettings, "Import", srt);
-            pref_lang = ghb_dict_get_string(ud->settings, "PreferredLanguage");
-            ghb_dict_set_string(srt, "Language", pref_lang);
-            ghb_dict_set_string(srt, "Codeset", "UTF-8");
-
-            dir = ghb_dict_get_string(ud->prefs, "SrtDir");
-            filename = g_strdup_printf("%s/none", dir);
-            ghb_dict_set_string(srt, "Filename", filename);
-            g_free(filename);
+            if (import == NULL)
+            {
+                import = ghb_dict_new();
+                ghb_dict_set(subsettings, "Import", import);
+                pref_lang = ghb_dict_get_string(ud->settings, "PreferredLanguage");
+                ghb_dict_set_string(import, "Language", pref_lang);
+                ghb_dict_set_string(import, "Codeset", "UTF-8");
+
+                dir = ghb_dict_get_string(ud->prefs, "SrtDir");
+                filename = g_strdup_printf("%s/none", dir);
+                ghb_dict_set_string(import, "Filename", filename);
+                g_free(filename);
+            }
+            ghb_dict_set_string(import, "Format",
+                        hb_dict_get_bool(ud->settings, "SubtitleSrtEnable") ?
+                            "SRT" : "SSA");
         }
         else
         {