2 * page_clips.c -- Clips Page Handling
3 * Copyright (C) 2002-2003 Charles Yates <charles.yates@pandora.be>
4 * Copyright (C) 2010 Dan Dennedy <dan@dennedy.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #include <gdk/gdkkeysyms.h>
31 #include "interface.h"
33 #include "dv1394app.h"
47 // TODO: This comes out later
49 GtkWidget
*modes
[ 4 ];
51 *page_clips
, page_clips_t
;
53 static GtkWidget
*this_page_get_widget( page_clips
this );
55 static void list_clips( page_clips
this, char *path
)
57 GtkWidget
*treeview
= lookup_widget( this_page_get_widget( this ), "list_clips" );
58 GtkWidget
*dirview
= lookup_widget( this_page_get_widget( this ), "list_dir" );
59 GtkWidget
*label
= lookup_widget( this_page_get_widget( this ), "label_directory" );
62 mvcp_dir dir
= mvcp_dir_init( this->dv
, path
);
63 GtkListStore
*dir_store
= NULL
;
64 GtkListStore
*clip_store
= NULL
;
67 mvcp_dir_entry_t entry
;
70 this->path
= strdup( path
);
72 gtk_label_set_text( GTK_LABEL( label
), this->path
);
74 if ( gtk_tree_view_get_model( GTK_TREE_VIEW( treeview
) ) == NULL
)
76 GtkCellRenderer
*renderer
;
77 GtkTreeViewColumn
*column
;
79 clip_store
= gtk_list_store_new( 2, G_TYPE_STRING
, G_TYPE_STRING
);
80 gtk_tree_view_set_model( GTK_TREE_VIEW( treeview
), GTK_TREE_MODEL( clip_store
) );
82 renderer
= gtk_cell_renderer_text_new( );
83 column
= gtk_tree_view_column_new_with_attributes ( "Description", renderer
, "text", 0, NULL
);
84 gtk_tree_view_column_set_sort_column_id( column
, 0 );
85 gtk_tree_view_append_column( GTK_TREE_VIEW( treeview
), column
);
87 dir_store
= gtk_list_store_new( 2, G_TYPE_STRING
, G_TYPE_STRING
);
88 gtk_tree_view_set_model( GTK_TREE_VIEW( dirview
), GTK_TREE_MODEL( dir_store
) );
90 renderer
= gtk_cell_renderer_text_new( );
91 column
= gtk_tree_view_column_new_with_attributes ( "Description", renderer
, "text", 0, NULL
);
92 gtk_tree_view_column_set_sort_column_id( column
, 0 );
93 gtk_tree_view_append_column( GTK_TREE_VIEW( dirview
), column
);
97 clip_store
= GTK_LIST_STORE( gtk_tree_view_get_model( GTK_TREE_VIEW( treeview
) ) );
98 dir_store
= GTK_LIST_STORE( gtk_tree_view_get_model( GTK_TREE_VIEW( dirview
) ) );
99 gtk_list_store_clear( clip_store
);
100 gtk_list_store_clear( dir_store
);
103 if ( strcmp( path
, "/" ) )
105 gtk_list_store_append( clip_store
, &iter
);
106 gtk_list_store_set( clip_store
, &iter
, 0, "..", -1 );
107 gtk_list_store_append( dir_store
, &iter
);
108 gtk_list_store_set( dir_store
, &iter
, 0, "..", -1 );
111 for ( index
= 0; index
< mvcp_dir_count( dir
); index
++ )
113 mvcp_dir_get( dir
, index
, &entry
);
114 if ( strchr( entry
.name
, '/' ) )
116 gtk_list_store_append( dir_store
, &iter
);
117 gtk_list_store_set( dir_store
, &iter
, 0, entry
.name
, -1 );
121 gtk_list_store_append( clip_store
, &iter
);
122 gtk_list_store_set( clip_store
, &iter
, 0, entry
.name
, -1 );
126 mvcp_dir_close( dir
);
130 gtk_label_set_text( GTK_LABEL( label
), "Disconnected" );
131 if ( gtk_tree_view_get_model( GTK_TREE_VIEW( treeview
) ) )
133 GtkListStore
*list_store
= GTK_LIST_STORE( gtk_tree_view_get_model( GTK_TREE_VIEW( treeview
) ) );
134 gtk_list_store_clear( list_store
);
135 list_store
= GTK_LIST_STORE( gtk_tree_view_get_model( GTK_TREE_VIEW( dirview
) ) );
136 gtk_list_store_clear( list_store
);
137 treeview
= lookup_widget( this_page_get_widget( this ), "treeview1" );
138 gtk_list_store_clear( list_store
);
143 static void list_queue( page_clips
this, int clip
)
145 GtkWidget
*treeview
= lookup_widget( this_page_get_widget( this ), "treeview1" );
146 mvcp_list list
= mvcp_list_init( this->dv
, dv1394app_get_selected_unit( this->app
) );
147 GtkListStore
*list_store
= NULL
;
151 mvcp_list_entry_t entry
;
153 if ( gtk_tree_view_get_model( GTK_TREE_VIEW( treeview
) ) == NULL
)
155 GtkCellRenderer
*renderer
;
156 GtkTreeViewColumn
*column
;
158 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
);
159 gtk_tree_view_set_model( GTK_TREE_VIEW( treeview
), GTK_TREE_MODEL( list_store
) );
161 renderer
= gtk_cell_renderer_toggle_new( );
162 column
= gtk_tree_view_column_new_with_attributes ( "", renderer
, "active", 0, NULL
);
163 gtk_tree_view_append_column( GTK_TREE_VIEW( treeview
), column
);
165 renderer
= gtk_cell_renderer_text_new( );
166 column
= gtk_tree_view_column_new_with_attributes ( "In", renderer
, "text", 1, NULL
);
167 gtk_tree_view_append_column( GTK_TREE_VIEW( treeview
), column
);
169 renderer
= gtk_cell_renderer_text_new( );
170 column
= gtk_tree_view_column_new_with_attributes ( "Out", renderer
, "text", 2, NULL
);
171 gtk_tree_view_append_column( GTK_TREE_VIEW( treeview
), column
);
173 renderer
= gtk_cell_renderer_text_new( );
174 column
= gtk_tree_view_column_new_with_attributes ( "Length", renderer
, "text", 3, NULL
);
175 gtk_tree_view_append_column( GTK_TREE_VIEW( treeview
), column
);
177 renderer
= gtk_cell_renderer_text_new( );
178 column
= gtk_tree_view_column_new_with_attributes ( "Clip", renderer
, "text", 4, NULL
);
179 gtk_tree_view_append_column( GTK_TREE_VIEW( treeview
), column
);
183 list_store
= GTK_LIST_STORE( gtk_tree_view_get_model( GTK_TREE_VIEW( treeview
) ) );
184 gtk_list_store_clear( list_store
);
187 this->generation
= list
->generation
;
189 for ( index
= 0; index
< mvcp_list_count( list
); index
++ )
191 mvcp_list_get( list
, index
, &entry
);
192 gtk_list_store_append( list_store
, &iter
);
193 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 );
197 if ( clip
< mvcp_list_count( list
) )
199 path
= gtk_tree_path_new_from_indices( this->clip
, -1 );
200 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW( treeview
), path
, NULL
, TRUE
, 0.5, 0 );
201 gtk_tree_path_free( path
);
204 mvcp_list_close( list
);
207 static void list_active( page_clips
this, int clip
)
209 GtkWidget
*treeview
= lookup_widget( this_page_get_widget( this ), "treeview1" );
210 GtkListStore
*list_store
= GTK_LIST_STORE( gtk_tree_view_get_model( GTK_TREE_VIEW( treeview
) ) );
211 GtkTreePath
*path
= gtk_tree_path_new_from_indices( this->clip
, -1 );
214 gtk_tree_model_get_iter( GTK_TREE_MODEL (list_store
), &iter
, path
);
215 gtk_tree_path_free( path
);
216 gtk_list_store_set( list_store
, &iter
, 0, FALSE
, -1 );
219 path
= gtk_tree_path_new_from_indices( this->clip
, -1 );
220 gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW( treeview
), path
, NULL
, TRUE
, 0.5, 0 );
221 gtk_tree_model_get_iter( GTK_TREE_MODEL (list_store
), &iter
, path
);
222 gtk_tree_path_free( path
);
223 gtk_list_store_set( list_store
, &iter
, 0, TRUE
, -1 );
226 static gboolean
on_ok( GtkWidget
*dummy
, gpointer data
)
228 page_clips
this = data
;
229 GtkWidget
*widget
= lookup_widget( this_page_get_widget( this ), "list_clips" );
230 GtkTreeSelection
*select
= gtk_tree_view_get_selection( GTK_TREE_VIEW( widget
) );
235 if ( gtk_tree_selection_get_selected( select
, &model
, &iter
) )
237 gtk_tree_model_get( model
, &iter
, 0, &text
, -1 );
239 if ( !strcmp( text
, ".." ) )
241 char *temp
= strdup( this->path
);
242 temp
[ strlen( temp
) - 1 ] = '\0';
243 *( strrchr( temp
, '/' ) + 1 ) = '\0';
244 list_clips( this, temp
);
249 char *temp
= malloc( strlen( this->path
) + strlen( text
) + 1 );
250 strcpy( temp
, this->path
);
251 strcat( temp
, text
);
255 mvcp_unit_load_back( this->dv
, dv1394app_get_selected_unit( this->app
), temp
);
256 mvcp_unit_play( this->dv
, dv1394app_get_selected_unit( this->app
) );
259 mvcp_unit_load( this->dv
, dv1394app_get_selected_unit( this->app
), temp
);
262 mvcp_unit_append( this->dv
, dv1394app_get_selected_unit( this->app
), temp
, -1, -1 );
265 mvcp_unit_clip_insert( this->dv
, dv1394app_get_selected_unit( this->app
), mvcp_relative
, 1, temp
, -1, -1 );
278 static gboolean
on_dir( GtkWidget
*dummy
, gpointer data
)
280 page_clips
this = data
;
281 GtkWidget
*widget
= lookup_widget( this_page_get_widget( this ), "list_dir" );
282 GtkTreeSelection
*select
= gtk_tree_view_get_selection( GTK_TREE_VIEW( widget
) );
287 if ( gtk_tree_selection_get_selected( select
, &model
, &iter
) )
289 gtk_tree_model_get( model
, &iter
, 0, &text
, -1 );
291 if ( !strcmp( text
, ".." ) )
293 char *temp
= strdup( this->path
);
294 temp
[ strlen( temp
) - 1 ] = '\0';
295 *( strrchr( temp
, '/' ) + 1 ) = '\0';
296 list_clips( this, temp
);
299 else if ( text
[ strlen( text
) - 1 ] == '/' )
301 char *temp
= malloc( strlen( this->path
) + strlen( text
) + 1 );
302 strcpy( temp
, this->path
);
303 strcat( temp
, text
);
304 list_clips( this, temp
);
314 static gboolean
on_queue_item( GtkWidget
*dummy
, gpointer data
)
316 page_clips
this = data
;
317 GtkWidget
*widget
= lookup_widget( this_page_get_widget( this ), "treeview1" );
318 GtkTreeSelection
*select
= gtk_tree_view_get_selection( GTK_TREE_VIEW( widget
) );
323 if ( gtk_tree_selection_get_selected( select
, &model
, &iter
) )
325 gtk_tree_model_get( model
, &iter
, 5, &clip
, -1 );
326 mvcp_unit_clip_goto( this->dv
, dv1394app_get_selected_unit( this->app
), mvcp_absolute
, clip
, 0 );
327 mvcp_unit_play( this->dv
, dv1394app_get_selected_unit( this->app
) );
333 static gboolean
on_clip_selected( GtkWidget
*widget
, GdkEventButton
*event
, gpointer data
)
335 if ( event
->button
==1 && event
->type
==GDK_2BUTTON_PRESS
)
336 return on_ok( widget
, data
);
340 static gboolean
on_clip_key_press( GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
)
342 if ( event
->keyval
== GDK_Return
)
343 return on_ok( widget
, data
);
347 static gboolean
on_dir_selected( GtkWidget
*widget
, GdkEventButton
*event
, gpointer data
)
349 if ( event
->button
==1 && event
->type
==GDK_2BUTTON_PRESS
)
350 return on_dir( widget
, data
);
354 static gboolean
on_dir_key_press( GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
)
356 if ( event
->keyval
== GDK_Return
)
357 return on_dir( widget
, data
);
361 static gboolean
on_queue_selected( GtkWidget
*widget
, GdkEventButton
*event
, gpointer data
)
363 if ( event
->button
==1 && event
->type
==GDK_2BUTTON_PRESS
)
364 return on_queue_item( widget
, data
);
368 static gboolean
on_queue_key_press( GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
)
370 if ( event
->keyval
== GDK_Return
)
371 return on_queue_item( widget
, data
);
375 static gboolean
on_home( GtkWidget
*button
, gpointer data
)
377 page_clips
this = data
;
378 list_clips( this, "/" );
382 static gboolean
on_refresh( GtkWidget
*button
, gpointer data
)
384 page_clips
this = data
;
385 char *temp
= strdup( this->path
);
386 list_clips( this, temp
);
392 static gboolean
on_up( GtkWidget
*dummy
, gpointer data
)
394 page_clips
this = data
;
395 mvcp_unit_clip_move( this->dv
, dv1394app_get_selected_unit( this->app
), mvcp_relative
, 0, mvcp_relative
, -1 );
399 static gboolean
on_down( GtkWidget
*dummy
, gpointer data
)
401 page_clips
this = data
;
402 mvcp_unit_clip_move( this->dv
, dv1394app_get_selected_unit( this->app
), mvcp_relative
, 0, mvcp_relative
, 1 );
406 static gboolean
on_remove( GtkWidget
*dummy
, gpointer data
)
408 page_clips
this = data
;
409 mvcp_unit_remove_current_clip( this->dv
, dv1394app_get_selected_unit( this->app
) );
413 static gboolean
on_clean( GtkWidget
*dummy
, gpointer data
)
415 page_clips
this = data
;
416 mvcp_unit_clean( this->dv
, dv1394app_get_selected_unit( this->app
) );
420 void on_mode_change( GtkMenuItem
*menuitem
, gpointer data
)
422 page_clips
this = data
;
425 for ( index
= 0; index
< 4; index
++ )
426 if ( GTK_WIDGET( menuitem
) == this->modes
[ index
] )
432 static GtkWidget
*this_page_get_widget( page_clips
this )
434 if ( this->widget
== NULL
)
435 this->widget
= create_page_clips( );
439 static void this_page_get_toolbar_info( page
this, GtkIconSize size
, GtkWidget
**icon
, char **label
)
441 *icon
= gtk_image_new_from_stock( "gtk-justify-fill", size
);
442 *label
= _("_Playlist");
445 static void this_page_on_connect( page_clips
this )
447 this->dv
= mvcp_init( dv1394app_get_parser( this->app
) );
448 list_clips( this, "/" );
451 static void this_page_on_unit_change( page_clips
this, int unit
)
453 if ( unit
!= this->unit
)
457 static void this_page_on_disconnect( page_clips
this )
459 list_clips( this, NULL
);
460 mvcp_close( this->dv
);
463 static void this_page_show_status( page_clips
this, mvcp_status status
)
465 if ( status
->status
!= unit_disconnected
)
467 if ( this->generation
!= status
->generation
)
468 list_queue( this, status
->clip_index
);
469 else if ( this->clip
!= status
->clip_index
)
470 list_active( this, status
->clip_index
);
474 static void this_page_close( page_clips
this )
480 page
page_clips_init( dv1394app app
)
482 page_clips
this = calloc( 1, sizeof( page_clips_t
) );
486 this->parent
.get_widget
= ( GtkWidget
*(*)( page
) )this_page_get_widget
;
487 this->parent
.get_toolbar_info
= this_page_get_toolbar_info
;
488 this->parent
.on_connect
= ( void (*)( page
) )this_page_on_connect
;
489 this->parent
.on_unit_change
= ( void (*)( page
, int ) )this_page_on_unit_change
;
490 this->parent
.on_disconnect
= ( void (*)( page
) )this_page_on_disconnect
;
491 this->parent
.show_status
= ( void (*)( page
, mvcp_status
) )this_page_show_status
;
492 this->parent
.close
= ( void (*)( page
) )this_page_close
;
494 this->generation
= -1;
496 widget
= lookup_widget( this_page_get_widget( this ), "list_clips" );
497 g_signal_connect( G_OBJECT( widget
), "button-press-event", G_CALLBACK( on_clip_selected
), this );
498 g_signal_connect( G_OBJECT( widget
), "key-press-event", G_CALLBACK( on_clip_key_press
), this );
499 widget
= lookup_widget( this_page_get_widget( this ), "list_dir" );
500 g_signal_connect( G_OBJECT( widget
), "button-press-event", G_CALLBACK( on_dir_selected
), this );
501 g_signal_connect( G_OBJECT( widget
), "key-press-event", G_CALLBACK( on_dir_key_press
), this );
502 widget
= lookup_widget( this_page_get_widget( this ), "button_clips_refresh" );
503 gtk_signal_connect( GTK_OBJECT( widget
), "clicked", GTK_SIGNAL_FUNC( on_refresh
), this );
504 widget
= lookup_widget( this_page_get_widget( this ), "button_clips_home" );
505 gtk_signal_connect( GTK_OBJECT( widget
), "clicked", GTK_SIGNAL_FUNC( on_home
), this );
506 widget
= lookup_widget( this_page_get_widget( this ), "button_up" );
507 gtk_signal_connect( GTK_OBJECT( widget
), "clicked", GTK_SIGNAL_FUNC( on_up
), this );
508 widget
= lookup_widget( this_page_get_widget( this ), "button_down" );
509 gtk_signal_connect( GTK_OBJECT( widget
), "clicked", GTK_SIGNAL_FUNC( on_down
), this );
510 widget
= lookup_widget( this_page_get_widget( this ), "button_remove" );
511 gtk_signal_connect( GTK_OBJECT( widget
), "clicked", GTK_SIGNAL_FUNC( on_remove
), this );
512 widget
= lookup_widget( this_page_get_widget( this ), "button_clean" );
513 gtk_signal_connect( GTK_OBJECT( widget
), "clicked", GTK_SIGNAL_FUNC( on_clean
), this );
515 widget
= lookup_widget( this_page_get_widget( this ), "table4" );
516 gtk_widget_show( widget
);
518 widget
= lookup_widget( this_page_get_widget( this ), "treeview1" );
519 g_signal_connect( G_OBJECT( widget
), "button-press-event", G_CALLBACK( on_queue_selected
), this );
520 g_signal_connect( G_OBJECT( widget
), "key-press-event", G_CALLBACK( on_queue_key_press
), this );
522 for ( index
= 0; index
< 4; index
++ )
525 sprintf( item
, "mode_%d", index
);
526 widget
= lookup_widget( this_page_get_widget( this ), item
);
527 gtk_signal_connect( GTK_OBJECT( widget
), "activate", GTK_SIGNAL_FUNC( on_mode_change
), this );
528 this->modes
[ index
] = widget
;