From d67801792de02507cc7bc4a88bda8167bf196899 Mon Sep 17 00:00:00 2001 From: Brandon Lewis Date: Tue, 27 Jul 2010 15:25:20 +0200 Subject: [PATCH] add text box to set durations from formatted strings --- tests/examples/ges-ui.c | 97 +++++++++++++++++++++++++++++++++++++++++++++ tests/examples/ges-ui.glade | 48 +++++++++++++++++++--- 2 files changed, 139 insertions(+), 6 deletions(-) diff --git a/tests/examples/ges-ui.c b/tests/examples/ges-ui.c index 33155be..e1e02ec 100644 --- a/tests/examples/ges-ui.c +++ b/tests/examples/ges-ui.c @@ -18,9 +18,13 @@ * Boston, MA 02111-1307, USA. */ +#include +#include +#include #include #include #include +#include typedef struct App { @@ -44,6 +48,8 @@ typedef struct App GtkComboBox *halign; GtkComboBox *valign; GtkEntry *text; + GtkEntry *seconds; + GtkWidget *generic_duration; GstState state; GType selected_type; } App; @@ -108,6 +114,9 @@ void connect_to_title_source (GESTimelineObject * object, App * app); void disconnect_from_title_source (GESTimelineObject * object, App * app); +void seconds_notify_text_changed_cb (GtkEntry * widget, GParamSpec * unused, + App * app); + /* UI state functions *******************************************************/ static void @@ -194,6 +203,9 @@ app_selection_changed_cb (GtkTreeSelection * selection, App * app) gtk_widget_set_visible (app->text_properties, app->selected_type == GES_TYPE_TIMELINE_TITLE_SOURCE); + + gtk_widget_set_visible (app->generic_duration, + app->selected_type == GES_TYPE_TIMELINE_TITLE_SOURCE); } gboolean @@ -278,6 +290,74 @@ text_notify_text_changed_cb (GtkEntry * widget, GParamSpec * unused, App * app) } } +static gboolean +check_time (const gchar * time) +{ + static regex_t re; + static gboolean compiled = FALSE; + + if (!compiled) { + compiled = TRUE; + regcomp (&re, "^[0-9][0-9]:[0-5][0-9]:[0-5][0-9](.[0-9]+)?$", + REG_EXTENDED | REG_NOSUB); + } + + if (!regexec (&re, time, (size_t) 0, NULL, 0)) + return TRUE; + return FALSE; +} + +static guint64 +str_to_time (const gchar * str) +{ + guint64 ret; + guint64 h, m; + gdouble s; + gchar buf[15]; + + buf[0] = str[0]; + buf[1] = str[1]; + buf[2] = '\0'; + + h = strtoull (buf, NULL, 10); + + buf[0] = str[3]; + buf[1] = str[4]; + buf[2] = '\0'; + + m = strtoull (buf, NULL, 10); + + strncpy (buf, &str[6], sizeof (buf)); + s = strtod (buf, NULL); + + ret = (h * 3600 * GST_SECOND) + + (m * 60 * GST_SECOND) + ((guint64) (s * GST_SECOND)); + + return ret; +} + +void +seconds_notify_text_changed_cb (GtkEntry * widget, GParamSpec * unused, + App * app) +{ + GList *tmp; + const gchar *text; + + text = gtk_entry_get_text (app->seconds); + + if (!check_time (text)) { + gtk_entry_set_icon_from_stock (app->seconds, + GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_DIALOG_WARNING); + } else { + gtk_entry_set_icon_from_stock (app->seconds, + GTK_ENTRY_ICON_SECONDARY, NULL); + for (tmp = app->selected_objects; tmp; tmp = tmp->next) { + g_object_set (GES_TIMELINE_OBJECT (tmp->data), "duration", + (guint64) str_to_time (text), NULL); + } + } +} + /* application methods ******************************************************/ static void selection_foreach (GtkTreeModel * model, GtkTreePath * path, @@ -653,11 +733,23 @@ disconnect_from_filesource (GESTimelineObject * object, App * app) void connect_to_title_source (GESTimelineObject * object, App * app) { + gdouble s; + guint64 duration; + gchar buf[30]; + GESTimelineTitleSource *obj; obj = GES_TIMELINE_TITLE_SOURCE (object); gtk_combo_box_set_active (app->halign, obj->halign); gtk_combo_box_set_active (app->valign, obj->valign); gtk_entry_set_text (app->text, obj->text); + + duration = GES_TIMELINE_OBJECT_DURATION (object); + + s = (duration / (float) GST_SECOND); + + g_snprintf (buf, sizeof (buf), "%02u:%02u:%02u.%09u", + GST_TIME_ARGS (duration)); + gtk_entry_set_text (app->seconds, buf); } void @@ -717,12 +809,17 @@ create_ui (App * app) GET_WIDGET (app->add_file, "add_file", GTK_ACTION); GET_WIDGET (app->delete, "delete", GTK_ACTION); GET_WIDGET (app->play, "play", GTK_ACTION); + GET_WIDGET (app->seconds, "seconds", GTK_ENTRY); + GET_WIDGET (app->generic_duration, "generic_duration", GTK_WIDGET); /* get text notifications */ g_signal_connect (app->text, "notify::text", G_CALLBACK (text_notify_text_changed_cb), app); + g_signal_connect (app->seconds, "notify::text", + G_CALLBACK (seconds_notify_text_changed_cb), app); + /* we care when the tree selection changes */ if (!(app->selection = gtk_tree_view_get_selection (timeline))) diff --git a/tests/examples/ges-ui.glade b/tests/examples/ges-ui.glade index 62ac96d..4d58dd4 100644 --- a/tests/examples/ges-ui.glade +++ b/tests/examples/ges-ui.glade @@ -133,8 +133,8 @@ True - delete True + delete True True @@ -161,15 +161,15 @@ True - add_file True + add_file True - add_text True + add_text @@ -181,8 +181,8 @@ True - play True + play True True @@ -358,6 +358,40 @@ True 6 + + True + 6 + + + True + 1 + 12 + Duration: + + + False + False + 0 + + + + + True + True + + + + 1 + + + + + False + False + 0 + + + True 6 @@ -444,7 +478,7 @@ False False - 0 + 1 @@ -540,7 +574,7 @@ False False - 1 + 2 @@ -570,12 +604,14 @@ + + -- 2.7.4