2010-07-20 16:53:15 +00:00
|
|
|
/* GStreamer Editing Services
|
|
|
|
* Copyright (C) 2010 Brandon Lewis <brandon.lewis@collabora.co.uk>
|
|
|
|
* 2010 Nokia Corporation
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2010-07-19 17:02:41 +00:00
|
|
|
#include <gtk/gtk.h>
|
2010-07-20 15:05:26 +00:00
|
|
|
#include <glib.h>
|
|
|
|
#include <ges/ges.h>
|
|
|
|
|
2010-07-20 15:55:06 +00:00
|
|
|
typedef struct App
|
|
|
|
{
|
|
|
|
GESTimeline *timeline;
|
|
|
|
GESTimelinePipeline *pipeline;
|
2010-07-20 16:24:14 +00:00
|
|
|
GESTimelineLayer *layer;
|
2010-07-20 15:55:06 +00:00
|
|
|
GtkWidget *main_window;
|
2010-07-20 17:41:58 +00:00
|
|
|
GtkListStore *model;
|
2010-07-21 11:53:01 +00:00
|
|
|
GtkTreeSelection *selection;
|
2010-07-20 15:55:06 +00:00
|
|
|
} App;
|
|
|
|
|
|
|
|
App *app_new (void);
|
|
|
|
|
|
|
|
void app_dispose (App * app);
|
|
|
|
|
2010-07-20 17:05:15 +00:00
|
|
|
void app_add_file (App * app, gchar * filename);
|
|
|
|
|
2010-07-20 15:59:59 +00:00
|
|
|
void window_destroy_cb (GtkObject * window, App * app);
|
2010-07-20 15:05:26 +00:00
|
|
|
|
2010-07-20 15:59:59 +00:00
|
|
|
void quit_item_activate_cb (GtkMenuItem * item, App * app);
|
2010-07-20 15:05:26 +00:00
|
|
|
|
2010-07-20 15:59:59 +00:00
|
|
|
void delete_item_activate_cb (GtkMenuItem * item, App * app);
|
2010-07-20 15:05:26 +00:00
|
|
|
|
2010-07-20 15:59:59 +00:00
|
|
|
void add_file_item_activate_cb (GtkMenuItem * item, App * app);
|
2010-07-20 15:05:26 +00:00
|
|
|
|
2010-07-20 17:41:58 +00:00
|
|
|
gboolean create_ui (App * app);
|
2010-07-19 17:02:41 +00:00
|
|
|
|
2010-07-20 16:53:15 +00:00
|
|
|
/* signal handlers **********************************************************/
|
|
|
|
|
2010-07-19 17:39:26 +00:00
|
|
|
void
|
2010-07-20 15:59:59 +00:00
|
|
|
window_destroy_cb (GtkObject * window, App * app)
|
2010-07-19 17:39:26 +00:00
|
|
|
{
|
|
|
|
gtk_main_quit ();
|
|
|
|
}
|
|
|
|
|
2010-07-20 11:57:28 +00:00
|
|
|
void
|
2010-07-20 15:59:59 +00:00
|
|
|
quit_item_activate_cb (GtkMenuItem * item, App * app)
|
2010-07-20 11:57:28 +00:00
|
|
|
{
|
|
|
|
gtk_main_quit ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-20 15:59:59 +00:00
|
|
|
delete_item_activate_cb (GtkMenuItem * item, App * app)
|
2010-07-20 11:57:28 +00:00
|
|
|
{
|
|
|
|
g_print ("beleted!");
|
|
|
|
}
|
|
|
|
|
2010-07-20 13:56:12 +00:00
|
|
|
void
|
2010-07-20 15:59:59 +00:00
|
|
|
add_file_item_activate_cb (GtkMenuItem * item, App * app)
|
2010-07-20 13:56:12 +00:00
|
|
|
{
|
2010-07-20 17:05:15 +00:00
|
|
|
GST_DEBUG ("add file signal handler");
|
|
|
|
|
|
|
|
/* TODO: solicit this information from the user */
|
|
|
|
app_add_file (app, (gchar *) "/home/brandon/media/small-mvi_0008.avi");
|
2010-07-20 13:56:12 +00:00
|
|
|
}
|
|
|
|
|
2010-07-20 16:53:15 +00:00
|
|
|
/* application methods ******************************************************/
|
|
|
|
|
2010-07-20 17:05:15 +00:00
|
|
|
void
|
|
|
|
app_add_file (App * app, gchar * filename)
|
|
|
|
{
|
|
|
|
gchar *uri;
|
|
|
|
GESTimelineObject *obj;
|
|
|
|
|
|
|
|
GST_DEBUG ("adding file %s", filename);
|
|
|
|
|
|
|
|
if (!g_file_test (filename, G_FILE_TEST_EXISTS)) {
|
|
|
|
/* TODO: error notification in UI */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uri = g_strdup_printf ("file://%s", filename);
|
|
|
|
|
|
|
|
obj = GES_TIMELINE_OBJECT (ges_timeline_filesource_new (uri));
|
|
|
|
g_free (uri);
|
|
|
|
|
|
|
|
ges_timeline_layer_add_object (app->layer, obj);
|
|
|
|
}
|
2010-07-20 16:53:15 +00:00
|
|
|
|
2010-07-20 15:55:06 +00:00
|
|
|
App *
|
|
|
|
app_new (void)
|
|
|
|
{
|
|
|
|
App *ret;
|
|
|
|
ret = g_new0 (App, 1);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(ret->timeline = ges_timeline_new_audio_video ()))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (!(ret->pipeline = ges_timeline_pipeline_new ()))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (!ges_timeline_pipeline_add_timeline (ret->pipeline, ret->timeline))
|
|
|
|
goto fail;
|
|
|
|
|
2010-07-20 16:24:14 +00:00
|
|
|
if (!(ret->layer = (GESTimelineLayer *) ges_simple_timeline_layer_new ()))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (!(ges_timeline_add_layer (ret->timeline, ret->layer)))
|
|
|
|
goto fail;
|
|
|
|
|
2010-07-20 17:41:58 +00:00
|
|
|
if (!(create_ui (ret)))
|
2010-07-20 15:55:06 +00:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
app_dispose (ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
app_dispose (App * app)
|
|
|
|
{
|
|
|
|
if (app) {
|
|
|
|
if (app->pipeline)
|
|
|
|
gst_object_unref (app->pipeline);
|
|
|
|
|
|
|
|
g_free (app);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-20 17:13:06 +00:00
|
|
|
/* Backend callbacks ********************************************************/
|
|
|
|
|
2010-07-21 09:40:18 +00:00
|
|
|
static gchar *
|
|
|
|
desc_for_object (GESTimelineObject * object)
|
|
|
|
{
|
|
|
|
gchar *uri;
|
|
|
|
|
|
|
|
/* there is only one type of object at the moment */
|
|
|
|
|
|
|
|
/* return the uri */
|
|
|
|
g_object_get (object, "uri", &uri, NULL);
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
|
2010-07-20 17:13:06 +00:00
|
|
|
static void
|
|
|
|
layer_object_added_cb (GESTimelineLayer * layer, GESTimelineObject * object,
|
|
|
|
App * app)
|
|
|
|
{
|
2010-07-21 09:40:18 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
gchar *description;
|
|
|
|
guint64 duration = 0;
|
|
|
|
|
2010-07-20 17:13:06 +00:00
|
|
|
GST_INFO ("layer object added cb %p %p %p", layer, object, app);
|
2010-07-21 09:40:18 +00:00
|
|
|
|
|
|
|
description = desc_for_object (object);
|
|
|
|
g_object_get (object, "duration", &duration, NULL);
|
|
|
|
|
|
|
|
gtk_list_store_append (app->model, &iter);
|
|
|
|
gtk_list_store_set (app->model, &iter, 0, description, 1, duration,
|
|
|
|
2, object, -1);
|
2010-07-20 17:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
layer_object_removed_cb (GESTimelineLayer * layer, GESTimelineObject * object,
|
|
|
|
App * app)
|
|
|
|
{
|
|
|
|
GST_INFO ("layer object removed cb %p %p %p", layer, object, app);
|
|
|
|
g_print ("layer object removed");
|
|
|
|
}
|
|
|
|
|
2010-07-20 16:53:15 +00:00
|
|
|
/* Layout *******************************************************************/
|
|
|
|
|
2010-07-20 17:41:58 +00:00
|
|
|
gboolean
|
2010-07-20 15:59:59 +00:00
|
|
|
create_ui (App * app)
|
2010-07-19 17:02:41 +00:00
|
|
|
{
|
|
|
|
GtkBuilder *builder;
|
2010-07-21 09:40:18 +00:00
|
|
|
GtkTreeView *timeline;
|
2010-07-19 17:02:41 +00:00
|
|
|
|
|
|
|
builder = gtk_builder_new ();
|
|
|
|
gtk_builder_add_from_file (builder, "ges-ui.glade", NULL);
|
2010-07-20 17:41:58 +00:00
|
|
|
|
2010-07-21 09:40:18 +00:00
|
|
|
timeline =
|
|
|
|
GTK_TREE_VIEW (gtk_builder_get_object (builder, "timeline_treeview"));
|
2010-07-20 17:41:58 +00:00
|
|
|
app->main_window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
|
|
|
|
app->model =
|
2010-07-21 09:40:18 +00:00
|
|
|
gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_OBJECT);
|
2010-07-20 17:41:58 +00:00
|
|
|
|
2010-07-21 09:40:18 +00:00
|
|
|
if (!(app->main_window && app->model && timeline)) {
|
2010-07-20 17:41:58 +00:00
|
|
|
g_print ("Could not retrieve all widgets from the XML");
|
2010-07-21 09:40:18 +00:00
|
|
|
goto fail;
|
2010-07-20 17:41:58 +00:00
|
|
|
}
|
|
|
|
|
2010-07-21 11:53:01 +00:00
|
|
|
app->selection = gtk_tree_view_get_selection (timeline);
|
|
|
|
|
|
|
|
if (!app->selection)
|
|
|
|
goto fail;
|
|
|
|
|
2010-07-21 09:40:18 +00:00
|
|
|
gtk_tree_view_set_model (timeline, GTK_TREE_MODEL (app->model));
|
|
|
|
|
2010-07-20 15:59:59 +00:00
|
|
|
gtk_builder_connect_signals (builder, app);
|
2010-07-20 17:41:58 +00:00
|
|
|
|
2010-07-19 17:02:41 +00:00
|
|
|
g_object_unref (G_OBJECT (builder));
|
|
|
|
|
2010-07-20 17:41:58 +00:00
|
|
|
gtk_widget_show (app->main_window);
|
2010-07-20 16:24:14 +00:00
|
|
|
|
2010-07-20 17:13:06 +00:00
|
|
|
g_signal_connect (app->layer, "object-added",
|
|
|
|
G_CALLBACK (layer_object_added_cb), app);
|
|
|
|
g_signal_connect (app->layer, "object-removed",
|
|
|
|
G_CALLBACK (layer_object_removed_cb), app);
|
|
|
|
|
2010-07-20 17:41:58 +00:00
|
|
|
return TRUE;
|
2010-07-21 09:40:18 +00:00
|
|
|
|
|
|
|
fail:
|
|
|
|
g_object_unref (G_OBJECT (builder));
|
|
|
|
return FALSE;
|
2010-07-20 15:05:26 +00:00
|
|
|
}
|
|
|
|
|
2010-07-20 16:53:15 +00:00
|
|
|
/* main *********************************************************************/
|
|
|
|
|
2010-07-20 15:05:26 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2010-07-20 15:55:06 +00:00
|
|
|
App *app;
|
2010-07-20 15:05:26 +00:00
|
|
|
|
|
|
|
/* intialize GStreamer and GES */
|
|
|
|
if (!g_thread_supported ())
|
|
|
|
g_thread_init (NULL);
|
|
|
|
|
|
|
|
gst_init (&argc, &argv);
|
|
|
|
ges_init ();
|
|
|
|
|
|
|
|
/* initialize UI */
|
|
|
|
gtk_init (&argc, &argv);
|
|
|
|
|
2010-07-20 16:38:54 +00:00
|
|
|
if ((app = app_new ())) {
|
|
|
|
gtk_main ();
|
|
|
|
app_dispose (app);
|
|
|
|
}
|
2010-07-20 15:55:06 +00:00
|
|
|
|
2010-07-19 17:02:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|