diff options
author | John Stebbins <[email protected]> | 2019-06-27 14:21:44 -0700 |
---|---|---|
committer | John Stebbins <[email protected]> | 2019-06-27 14:21:44 -0700 |
commit | c1fb6e1fcff8740850521d8282d8760279393b1f (patch) | |
tree | 7e8a50167ff89adf1e1e448b31814c928f9d3e3f /gtk | |
parent | 19ba0208c2ac34ddaffed61af3ffecdc87d77576 (diff) |
LinGui: refactor some code
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/src/callbacks.c | 65 | ||||
-rw-r--r-- | gtk/src/hb-backend.c | 18 | ||||
-rw-r--r-- | gtk/src/hb-backend.h | 4 |
3 files changed, 44 insertions, 43 deletions
diff --git a/gtk/src/callbacks.c b/gtk/src/callbacks.c index 5027f9128..1383f7b9d 100644 --- a/gtk/src/callbacks.c +++ b/gtk/src/callbacks.c @@ -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); diff --git a/gtk/src/hb-backend.c b/gtk/src/hb-backend.c index c79b821b7..04072d4c2 100644 --- a/gtk/src/hb-backend.c +++ b/gtk/src/hb-backend.c @@ -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 diff --git a/gtk/src/hb-backend.h b/gtk/src/hb-backend.h index 4bcd41a59..18d2f2199 100644 --- a/gtk/src/hb-backend.h +++ b/gtk/src/hb-backend.h @@ -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); |