fix eof getting per unit
[rugen] / src / page_clips.c
index cab01cc..aeefc74 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * page_clips.c -- Clips Page Handling
  * Copyright (C) 2002-2003 Charles Yates <charles.yates@pandora.be>
+ * Copyright (C) 2010 Dan Dennedy <dan@dennedy.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -30,7 +31,6 @@
 #include "interface.h"
 #include "support.h"
 #include "dv1394app.h"
-#include "util.h"
 #include "page.h"
 
 typedef struct 
@@ -38,7 +38,7 @@ typedef struct
        struct page_t parent;
        dv1394app app;
        GtkWidget *widget;
-       valerie dv;
+       mvcp dv;
        char *path;
        int unit;
        int generation;
@@ -47,6 +47,8 @@ typedef struct
        // TODO: This comes out later
        int mode;
        GtkWidget *modes[ 4 ];
+
+       struct page_t *parent_page;
 }
 *page_clips, page_clips_t;
 
@@ -59,12 +61,12 @@ static void list_clips( page_clips this, char *path )
        GtkWidget *label = lookup_widget( this_page_get_widget( this ), "label_directory" );
        if ( path != NULL )
        {
-               valerie_dir dir = valerie_dir_init( this->dv, path );
+               mvcp_dir dir = mvcp_dir_init( this->dv, path );
                GtkListStore *dir_store = NULL;
                GtkListStore *clip_store = NULL;
                GtkTreeIter iter;
                int index;
-               valerie_dir_entry_t entry;
+               mvcp_dir_entry_t entry;
 
                free( this->path );
                this->path = strdup( path );
@@ -108,9 +110,9 @@ static void list_clips( page_clips this, char *path )
                        gtk_list_store_set( dir_store, &iter, 0, "..", -1 );
                }
                
-               for ( index = 0; index < valerie_dir_count( dir ); index ++ )
+               for ( index = 0; index < mvcp_dir_count( dir ); index ++ )
                {
-                       valerie_dir_get( dir, index, &entry );
+                       mvcp_dir_get( dir, index, &entry );
                        if ( strchr( entry.name, '/' ) )
                        {
                                gtk_list_store_append( dir_store, &iter );
@@ -123,7 +125,7 @@ static void list_clips( page_clips this, char *path )
                        }
                }
                                              
-               valerie_dir_close( dir );
+               mvcp_dir_close( dir );
        }
        else
        {
@@ -143,19 +145,25 @@ static void list_clips( page_clips this, char *path )
 static void list_queue( page_clips this, int clip )
 {
        GtkWidget *treeview = lookup_widget( this_page_get_widget( this ), "treeview1" );
-       valerie_list list = valerie_list_init( this->dv, dv1394app_get_selected_unit( this->app ) );
+       mvcp_list list = mvcp_list_init( this->dv, dv1394app_get_selected_unit( this->app ) );
        GtkListStore *list_store = NULL;
        GtkTreeIter iter;
        GtkTreePath *path;
        int index;
-       valerie_list_entry_t entry;
+       mvcp_list_entry_t entry;
 
        if ( gtk_tree_view_get_model( GTK_TREE_VIEW( treeview ) ) == NULL )
        {
                GtkCellRenderer *renderer;
                GtkTreeViewColumn *column;
 
-               list_store = gtk_list_store_new( 6, G_TYPE_BOOLEAN, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INT );
+               list_store = gtk_list_store_new( 6,
+                       G_TYPE_BOOLEAN,
+                       G_TYPE_STRING,
+                       G_TYPE_STRING,
+                       G_TYPE_STRING,
+                       G_TYPE_STRING,
+                       G_TYPE_INT );
                gtk_tree_view_set_model( GTK_TREE_VIEW( treeview ), GTK_TREE_MODEL( list_store ) );
                
                renderer = gtk_cell_renderer_toggle_new( );
@@ -186,22 +194,30 @@ static void list_queue( page_clips this, int clip )
        
        this->generation = list->generation;
        
-       for ( index = 0; index < valerie_list_count( list ); index ++ )
+       for ( index = 0; index < mvcp_list_count( list ); index ++ )
        {
-               valerie_list_get( list, index, &entry );
+               char tc1[12], tc2[12], tc3[12];
+               mvcp_list_get( list, index, &entry );
                gtk_list_store_append( list_store, &iter );
-               gtk_list_store_set( list_store, &iter, 0, index == clip, 1, ( int )entry.in, 2, ( int )entry.out, 3, ( int )entry.size, 4, entry.full, 5, entry.clip, -1 );
+               gtk_list_store_set( list_store, &iter,
+                       0, index == clip,
+                       1, frames2tc( entry.in, entry.fps, tc1),
+                       2, frames2tc( entry.out, entry.fps, tc2),
+                       3, frames2tc( entry.size, entry.fps, tc3),
+                       4, entry.full,
+                       5, entry.clip,
+                       -1 );
        }
 
        this->clip = clip;
-       if ( clip < valerie_list_count( list ) )
+       if ( clip < mvcp_list_count( list ) )
        {
                path = gtk_tree_path_new_from_indices( this->clip, -1 );
                gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW( treeview ), path, NULL, TRUE, 0.5, 0 );
                gtk_tree_path_free( path );
        }
        
-       valerie_list_close( list );
+       mvcp_list_close( list );
 }
 
 static void list_active( page_clips this, int clip )
@@ -252,18 +268,30 @@ static gboolean on_ok( GtkWidget *dummy, gpointer data )
                        switch( this->mode )
                        {
                                case 0:
-                                       valerie_unit_load_back( this->dv, dv1394app_get_selected_unit( this->app ), temp );
-                                       valerie_unit_play( this->dv, dv1394app_get_selected_unit( this->app ) );
+                                       mvcp_unit_load_back( this->dv, dv1394app_get_selected_unit( this->app ), temp );
+                                       mvcp_unit_play( this->dv, dv1394app_get_selected_unit( this->app ) );
                                        break;
                                case 1: 
-                                       valerie_unit_load( this->dv, dv1394app_get_selected_unit( this->app ), temp );
+                                       mvcp_unit_load( this->dv, dv1394app_get_selected_unit( this->app ), temp );
                                        break;
                                case 2: 
-                                       valerie_unit_append( this->dv, dv1394app_get_selected_unit( this->app ), temp, -1, -1 );
+                                       mvcp_unit_append( this->dv, dv1394app_get_selected_unit( this->app ), temp, -1, -1 );
                                        break;
                                case 3:
-                                       valerie_unit_clip_insert( this->dv, dv1394app_get_selected_unit( this->app ), valerie_relative, 1, temp, -1, -1 );
+                               {
+                                       GtkWidget *widget = lookup_widget( this_page_get_widget( this ), "treeview1" );
+                                       GtkTreeSelection *select = gtk_tree_view_get_selection( GTK_TREE_VIEW( widget ) );
+                                       GtkTreeModel *model;
+                                       GtkTreeIter iter;
+                                       int clip;
+                                       
+                                       if ( gtk_tree_selection_get_selected( select, &model, &iter ) )
+                                       {
+                                               gtk_tree_model_get( model, &iter, 5, &clip,     -1 );
+                                               mvcp_unit_clip_insert( this->dv, dv1394app_get_selected_unit( this->app ), mvcp_absolute, clip, temp, -1, -1 );
+                                       }
                                        break;
+                               }
                        }
                        
                        free( temp );
@@ -323,8 +351,8 @@ static gboolean on_queue_item( GtkWidget *dummy, gpointer data )
        if ( gtk_tree_selection_get_selected( select, &model, &iter ) )
        {
                gtk_tree_model_get( model, &iter, 5, &clip,     -1 );
-               valerie_unit_clip_goto( this->dv, dv1394app_get_selected_unit( this->app ), valerie_absolute, clip, 0 );
-               valerie_unit_play( this->dv, dv1394app_get_selected_unit( this->app ) );
+               mvcp_unit_clip_goto( this->dv, dv1394app_get_selected_unit( this->app ), mvcp_absolute, clip, 0 );
+               mvcp_unit_play( this->dv, dv1394app_get_selected_unit( this->app ) );
        }
        
        return TRUE;
@@ -392,28 +420,58 @@ static gboolean on_refresh( GtkWidget *button, gpointer data )
 static gboolean on_up( GtkWidget *dummy, gpointer data )
 {
        page_clips this = data;
-       valerie_unit_clip_move( this->dv, dv1394app_get_selected_unit( this->app ), valerie_relative, 0, valerie_relative, -1 );
+       GtkWidget *widget = lookup_widget( this_page_get_widget( this ), "treeview1" );
+       GtkTreeSelection *select = gtk_tree_view_get_selection( GTK_TREE_VIEW( widget ) );
+       GtkTreeModel *model;
+       GtkTreeIter iter;
+       int clip;
+
+       if ( gtk_tree_selection_get_selected( select, &model, &iter ) )
+       {
+               gtk_tree_model_get( model, &iter, 5, &clip,     -1 );
+               mvcp_unit_clip_move( this->dv, dv1394app_get_selected_unit( this->app ), mvcp_absolute, clip, mvcp_absolute, clip - 1 < 0 ? 0 : clip - 1 );
+       }
        return TRUE;
 }
 
 static gboolean on_down( GtkWidget *dummy, gpointer data )
 {
        page_clips this = data;
-       valerie_unit_clip_move( this->dv, dv1394app_get_selected_unit( this->app ), valerie_relative, 0, valerie_relative, 1 );
+       GtkWidget *widget = lookup_widget( this_page_get_widget( this ), "treeview1" );
+       GtkTreeSelection *select = gtk_tree_view_get_selection( GTK_TREE_VIEW( widget ) );
+       GtkTreeModel *model;
+       GtkTreeIter iter;
+       int clip;
+
+       if ( gtk_tree_selection_get_selected( select, &model, &iter ) )
+       {
+               gtk_tree_model_get( model, &iter, 5, &clip,     -1 );
+               mvcp_unit_clip_move( this->dv, dv1394app_get_selected_unit( this->app ), mvcp_absolute, clip, mvcp_absolute, clip + 1 );
+       }
        return TRUE;
 }
 
 static gboolean on_remove( GtkWidget *dummy, gpointer data )
 {
        page_clips this = data;
-       valerie_unit_remove_current_clip( this->dv, dv1394app_get_selected_unit( this->app ) );
+       GtkWidget *widget = lookup_widget( this_page_get_widget( this ), "treeview1" );
+       GtkTreeSelection *select = gtk_tree_view_get_selection( GTK_TREE_VIEW( widget ) );
+       GtkTreeModel *model;
+       GtkTreeIter iter;
+       int clip;
+
+       if ( gtk_tree_selection_get_selected( select, &model, &iter ) )
+       {
+               gtk_tree_model_get( model, &iter, 5, &clip,     -1 );
+               mvcp_unit_clip_remove( this->dv, dv1394app_get_selected_unit( this->app ), mvcp_absolute, clip );
+       }
        return TRUE;
 }
 
 static gboolean on_clean( GtkWidget *dummy, gpointer data )
 {
        page_clips this = data;
-       valerie_unit_clean( this->dv, dv1394app_get_selected_unit( this->app ) );
+       mvcp_unit_clean( this->dv, dv1394app_get_selected_unit( this->app ) );
        return TRUE;
 }
 
@@ -432,19 +490,19 @@ void on_mode_change( GtkMenuItem *menuitem, gpointer data )
 static GtkWidget *this_page_get_widget( page_clips this )
 {
        if ( this->widget == NULL )
-               this->widget = create_page_clips( );
+               this->widget = this->parent_page->get_widget(this->parent_page);
        return this->widget;
 }
 
 static void this_page_get_toolbar_info( page this, GtkIconSize size, GtkWidget **icon, char **label )
 {
-       *icon = gtk_image_new_from_stock( "gtk-find",  size );
-       *label = "_Clips";
+       *icon = gtk_image_new_from_stock( "gtk-justify-fill",  size );
+       *label = _("_Playlist");
 }
 
 static void this_page_on_connect( page_clips this )
 {
-       this->dv = valerie_init( dv1394app_get_parser( this->app ) );
+       this->dv = mvcp_init( dv1394app_get_parser( this->app ) );
        list_clips( this, "/" );
 }
 
@@ -457,10 +515,10 @@ static void this_page_on_unit_change( page_clips this, int unit )
 static void this_page_on_disconnect( page_clips this )
 {
        list_clips( this, NULL );
-       valerie_close( this->dv );
+       mvcp_close( this->dv );
 }
 
-static void this_page_show_status( page_clips this, valerie_status status )
+static void this_page_show_status( page_clips this, mvcp_status status )
 {
        if ( status->status != unit_disconnected )
        {
@@ -477,18 +535,19 @@ static void this_page_close( page_clips this )
                free( this );
 }
 
-page page_clips_init( dv1394app app )
+page page_clips_init( dv1394app app, struct page_t *parent_page)
 {
        page_clips this = calloc( 1, sizeof( page_clips_t ) );
        GtkWidget *widget;
        int index = 0;
 
+       this->parent_page = parent_page;
        this->parent.get_widget = ( GtkWidget *(*)( page ) )this_page_get_widget;
        this->parent.get_toolbar_info = this_page_get_toolbar_info;
        this->parent.on_connect = ( void (*)( page ) )this_page_on_connect;
        this->parent.on_unit_change = ( void (*)( page, int ) )this_page_on_unit_change;
        this->parent.on_disconnect = ( void (*)( page ) )this_page_on_disconnect;
-       this->parent.show_status = ( void (*)( page, valerie_status ) )this_page_show_status;
+       this->parent.show_status = ( void (*)( page, mvcp_status ) )this_page_show_status;
        this->parent.close = ( void (*)( page ) )this_page_close;
        this->app = app;
        this->generation = -1;