format duration nicely

This commit is contained in:
Brandon Lewis 2010-07-21 19:01:33 +02:00 committed by Edward Hervey
parent 853c31e75e
commit 01f6795733
2 changed files with 25 additions and 1 deletions

View file

@ -61,6 +61,9 @@ void app_selection_changed_cb (GtkTreeSelection * selection, App * app);
gboolean duration_scale_change_value_cb (GtkRange * range, GtkScrollType
unused, gdouble value, App * app);
void duration_cell_func (GtkTreeViewColumn * column, GtkCellRenderer * renderer,
GtkTreeModel * model, GtkTreeIter * iter, gpointer user);
gboolean create_ui (App * app);
void connect_to_filesource (GESTimelineObject * object, App * app);
@ -124,6 +127,18 @@ duration_scale_change_value_cb (GtkRange * range, GtkScrollType unused,
return TRUE;
}
void
duration_cell_func (GtkTreeViewColumn * column, GtkCellRenderer * renderer,
GtkTreeModel * model, GtkTreeIter * iter, gpointer user)
{
gchar buf[30];
guint64 duration;
gtk_tree_model_get (model, iter, 1, &duration, -1);
g_snprintf (buf, sizeof (buf), "%u:%02u:%02u.%09u", GST_TIME_ARGS (duration));
g_object_set (renderer, "text", &buf, NULL);
}
/* application methods ******************************************************/
static void selection_foreach (GtkTreeModel * model, GtkTreePath * path,
@ -388,6 +403,8 @@ create_ui (App * app)
{
GtkBuilder *builder;
GtkTreeView *timeline;
GtkTreeViewColumn *duration_col;
GtkCellRenderer *duration_renderer;
/* construct widget tree */
@ -401,6 +418,8 @@ create_ui (App * app)
GET_WIDGET (app->properties, "properties", GTK_WIDGET);
GET_WIDGET (app->main_window, "window", GTK_WIDGET);
GET_WIDGET (app->duration, "duration_scale", GTK_HSCALE);
GET_WIDGET (duration_col, "duration_column", GTK_TREE_VIEW_COLUMN);
GET_WIDGET (duration_renderer, "duration_renderer", GTK_CELL_RENDERER);
/* we care when the tree selection changes */
@ -417,6 +436,11 @@ create_ui (App * app)
goto fail;
gtk_tree_view_set_model (timeline, GTK_TREE_MODEL (app->model));
/* register custom cell data function */
gtk_tree_view_column_set_cell_data_func (duration_col, duration_renderer,
duration_cell_func, NULL, NULL);
/* register callbacks on GES objects */
g_signal_connect (app->layer, "object-added",

View file

@ -200,7 +200,7 @@
<property name="sizing">autosize</property>
<property name="title">Duration</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext1"/>
<object class="GtkCellRendererText" id="duration_renderer"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>