]> granicus.if.org Git - handbrake/commitdiff
LinGui: refactor some code
authorJohn Stebbins <jstebbins.hb@gmail.com>
Thu, 27 Jun 2019 21:21:44 +0000 (14:21 -0700)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Thu, 27 Jun 2019 21:21:44 +0000 (14:21 -0700)
gtk/src/callbacks.c
gtk/src/hb-backend.c
gtk/src/hb-backend.h

index 5027f91289741612cc43ad54b5455305c4fb917a..1383f7b9d7cae5320d54f24eecac5277f335ff1e 100644 (file)
@@ -1389,52 +1389,59 @@ void ghb_break_duration(gint64 duration, gint *hh, gint *mm, gint *ss)
     *ss = duration % 60;
 }
 
-static void
-update_title_duration(signal_user_data_t *ud)
+gint64
+ghb_title_range_get_duration(GhbValue * settings, const hb_title_t * title)
 {
-    gint hh, mm, ss, start, end;
-    gchar *text;
-    GtkWidget *widget;
-    int title_id, titleindex;
-    const hb_title_t *title;
-
-    title_id = ghb_dict_get_int(ud->settings, "title");
-    title = ghb_lookup_title(title_id, &titleindex);
-    widget = GHB_WIDGET (ud->builder, "title_duration");
+    gint64 start, end;
 
-    if (ghb_settings_combo_int(ud->settings, "PtoPType") == 0)
+    if (ghb_settings_combo_int(settings, "PtoPType") == 0)
     {
-        start = ghb_dict_get_int(ud->settings, "start_point");
-        end = ghb_dict_get_int(ud->settings, "end_point");
-        ghb_part_duration(title, start, end, &hh, &mm, &ss);
+        start = ghb_dict_get_int(settings, "start_point");
+        end = ghb_dict_get_int(settings, "end_point");
+        return ghb_chapter_range_get_duration(title, start, end) / 90000;
     }
-    else if (ghb_settings_combo_int(ud->settings, "PtoPType") == 1)
+    else if (ghb_settings_combo_int(settings, "PtoPType") == 1)
     {
-        gint duration;
-
-        start = ghb_dict_get_int(ud->settings, "start_point");
-        end = ghb_dict_get_int(ud->settings, "end_point");
-        duration = end - start;
-        ghb_break_duration(duration, &hh, &mm, &ss);
+        start = ghb_dict_get_int(settings, "start_point");
+        end = ghb_dict_get_int(settings, "end_point");
+        return end - start;
     }
-    else if (ghb_settings_combo_int(ud->settings, "PtoPType") == 2)
+    else if (ghb_settings_combo_int(settings, "PtoPType") == 2)
     {
         if (title != NULL)
         {
             gint64 frames;
-            gint duration;
 
-            start = ghb_dict_get_int(ud->settings, "start_point");
-            end = ghb_dict_get_int(ud->settings, "end_point");
+            start = ghb_dict_get_int(settings, "start_point");
+            end = ghb_dict_get_int(settings, "end_point");
             frames = end - start + 1;
-            duration = frames * title->vrate.den / title->vrate.num;
-            ghb_break_duration(duration, &hh, &mm, &ss);
+            return frames * title->vrate.den / title->vrate.num;
         }
         else
         {
-            hh = mm = ss = 0;
+            return 0;
         }
     }
+    return 0;
+}
+
+static void
+update_title_duration(signal_user_data_t *ud)
+{
+    gint hh, mm, ss;
+    gint64 duration;
+    gchar *text;
+    GtkWidget *widget;
+    int title_id, titleindex;
+    const hb_title_t *title;
+
+    title_id = ghb_dict_get_int(ud->settings, "title");
+    title = ghb_lookup_title(title_id, &titleindex);
+    widget = GHB_WIDGET (ud->builder, "title_duration");
+
+    duration = ghb_title_range_get_duration(ud->settings, title);
+    ghb_break_duration(duration, &hh, &mm, &ss);
+
     text = g_strdup_printf("%02d:%02d:%02d", hh, mm, ss);
     gtk_label_set_text(GTK_LABEL(widget), text);
     g_free(text);
index c79b821b76c69341e23e1045214c11f3b6d0c927..04072d4c2d38d350c817fb0fec427eb3a6b0a3a6 100644 (file)
@@ -3139,26 +3139,23 @@ init_ui_combo_boxes(GtkBuilder *builder)
     }
 }
 
-void
-ghb_part_duration(const hb_title_t *title, gint sc, gint ec, gint *hh, gint *mm, gint *ss)
+gint64
+ghb_chapter_range_get_duration(const hb_title_t *title, gint sc, gint ec)
 {
     hb_chapter_t * chapter;
     gint count, c;
     gint64 duration;
 
-    *hh = *mm = *ss = 0;
-    if (title == NULL) return;
+    if (title == NULL) return 0;
 
-    *hh = title->hours;
-    *mm = title->minutes;
-    *ss = title->seconds;
+    duration = title->duration;
 
     count = hb_list_count(title->list_chapter);
     if (sc > count) sc = count;
     if (ec > count) ec = count;
 
     if (sc == 1 && ec == count)
-        return;
+        return duration;
 
     duration = 0;
     for (c = sc; c <= ec; c++)
@@ -3166,10 +3163,7 @@ ghb_part_duration(const hb_title_t *title, gint sc, gint ec, gint *hh, gint *mm,
         chapter = hb_list_item(title->list_chapter, c-1);
         duration += chapter->duration;
     }
-
-    *hh =   duration / 90000 / 3600;
-    *mm = ((duration / 90000) % 3600) / 60;
-    *ss =  (duration / 90000) % 60;
+    return duration;
 }
 
 gint64
index 4bcd41a59508c135c3d377432f6514293012b6ee..18d2f21995666fc49aa7d6c63c562f8cab984590 100644 (file)
@@ -131,8 +131,8 @@ void ghb_set_scale_settings(GhbValue *settings, gint mode);
 void ghb_picture_settings_deps(signal_user_data_t *ud);
 gint64 ghb_get_chapter_duration(const hb_title_t *title, gint chap);
 gint64 ghb_get_chapter_start(const hb_title_t *title, gint chap);
-void ghb_part_duration(
-    const hb_title_t *title, gint sc, gint ec, gint *hh, gint *mm, gint *ss);
+gint64 ghb_chapter_range_get_duration(const hb_title_t *title,
+                                      gint sc, gint ec);
 gint ghb_get_best_mix(hb_audio_config_t *aconfig, gint acodec, gint mix);
 gboolean ghb_audio_is_passthru(gint acodec);
 gboolean ghb_audio_can_passthru(gint acodec);