playlist open/close dialogs basic handlers added
[rugen] / src / dv1394app.c
1 /*
2 * dv1394app.c -- GTK+ 2 dv1394d client demo
3 * Copyright (C) 2002-2003 Charles Yates <charles.yates@pandora.be>
4 * Copyright (C) 2010 Dan Dennedy <dan@dennedy.org>
5 *
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.
10 *
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.
15 *
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.
19 */
20
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <gtk/gtk.h>
29 #include <gdk/gdkkeysyms.h>
30
31 #include "interface.h"
32 #include "support.h"
33 #include "dv1394app.h"
34 #include "page.h"
35 #include "gtkenhancedscale.h"
36 #include <mvcp/mvcp_remote.h>
37 #include <melted/melted_local.h>
38
39
40 /** Window close event.
41 */
42
43 static gboolean on_main_window_delete_event( GtkWidget *widget, GdkEvent *event, gpointer user_data )
44 {
45 gtk_exit( 0 );
46 return TRUE;
47 }
48
49 static gboolean instance_connect( dv1394app this, char *server, char *port )
50 {
51 if ( this->parser == NULL )
52 {
53 if ( strstr( server, ".conf" ) == NULL )
54 this->parser = mvcp_parser_init_remote( server, atoi( port ) );
55 else
56 this->parser = melted_parser_init_local( );
57
58 this->command = mvcp_init( this->parser );
59
60 if ( strstr( server, ".conf" ) != NULL )
61 mvcp_run( this->command, server );
62
63 if ( mvcp_connect( this->command ) == mvcp_ok )
64 {
65 struct timespec t = { 1, 0 };
66 nanosleep( &t, NULL );
67 //gdk_threads_leave( );
68 dv1394app_connect( this );
69 //gdk_threads_enter( );
70 }
71 else
72 {
73 mvcp_close( this->command );
74 mvcp_parser_close( this->parser );
75 this->parser = NULL;
76 // beep( );
77 }
78 }
79
80 return this->parser != NULL;
81 }
82
83 /** Connection window - Connect button pressed.
84 */
85
86 static gboolean on_connect_pressed( GtkWidget *button, gpointer user_data )
87 {
88 dv1394app this = user_data;
89 GtkWidget *widget;
90 char *server;
91 char *port;
92
93 if ( this->parser == NULL )
94 {
95 widget = lookup_widget( this->connect, "entry_server" );
96 server = ( char * )gtk_entry_get_text( GTK_ENTRY( widget ) );
97 widget = lookup_widget( this->connect, "entry_port" );
98 port = ( char * )gtk_entry_get_text( GTK_ENTRY( widget ) );
99 instance_connect( this, server, port );
100 }
101 gtk_widget_destroy( this->connect );
102 this->guard = 1;
103 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( lookup_widget( this->window, "button_connect" ) ), TRUE );
104 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( lookup_widget( this->window, "button_disconnect" ) ), FALSE );
105 this->guard = 0;
106
107 return FALSE;
108 }
109
110 /** Connection window - Cancel button pressed.
111 */
112
113 static gboolean on_cancel_pressed( GtkWidget *button, gpointer user_data )
114 {
115 dv1394app this = user_data;
116 if ( this->guard ) return FALSE;
117 gtk_widget_destroy( this->connect );
118 return FALSE;
119 }
120
121 /** Main window - connect menu item selected.
122 */
123
124 void on_item_connect_activate( GtkMenuItem *menuitem, gpointer user_data )
125 {
126 dv1394app this = user_data;
127 GtkWidget *widget;
128
129 if ( this->guard ) return;
130 this->connect = create_window_connection( );
131
132 /* Connection set up handling */
133 widget = lookup_widget( this->connect, "button_connect" );
134 gtk_signal_connect( GTK_OBJECT( widget ), "clicked", GTK_SIGNAL_FUNC( on_connect_pressed ), this );
135 widget = lookup_widget( this->connect, "button_cancel" );
136 gtk_signal_connect( GTK_OBJECT( widget ), "clicked", GTK_SIGNAL_FUNC( on_cancel_pressed ), this );
137
138 gtk_widget_show( this->connect );
139 }
140
141 /** Main window - disconnect menu item selected.
142 */
143
144 void on_item_disconnect_activate( GtkMenuItem *menuitem, gpointer user_data )
145 {
146 dv1394app this = user_data;
147
148 if ( this->guard ) return;
149 dv1394app_disconnect( this );
150
151 this->guard = 1;
152 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( lookup_widget( this->window, "button_connect" ) ), FALSE );
153 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( lookup_widget( this->window, "button_disconnect" ) ), TRUE );
154 this->guard = 0;
155 }
156
157 /** Main window - quit menu item selected.
158 */
159
160 void on_item_quit_activate( GtkMenuItem *menuitem, gpointer user_data )
161 {
162 gtk_main_quit( );
163 }
164
165 /** Main window - playlist open menu item selected.
166 */
167
168 void on_item_open_playlist_activate( GtkMenuItem *menuitem, gpointer user_data )
169 {
170 dv1394app this = user_data;
171 GtkWidget *dialog;
172
173 dialog = gtk_file_chooser_dialog_new ("Open File",
174 GTK_WINDOW (this->window),
175 GTK_FILE_CHOOSER_ACTION_OPEN,
176 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
177 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
178 NULL);
179
180 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
181 (this->playlist_folder)?this->playlist_folder:getenv("HOME"));
182
183 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
184 {
185 char *filename;
186
187 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
188 fprintf(stderr, "on_item_open_playlist_activate: %s\n", filename);
189
190 if ( this->playlist_folder )
191 g_free (this->playlist_folder);
192 this->playlist_folder = filename;
193 if ( this->playlist_folder )
194 {
195 char* e = strrchr(this->playlist_folder, '/');
196 if(e) *e = 0;
197 }
198 fprintf(stderr, "on_item_open_playlist_activate: this->playlist_folder=[%s]\n", this->playlist_folder);
199 }
200
201 gtk_widget_destroy (dialog);
202 }
203
204 /** Main window - playlist save menu item selected.
205 */
206
207 void on_item_save_playlist_activate( GtkMenuItem *menuitem, gpointer user_data )
208 {
209 dv1394app this = user_data;
210 GtkWidget *dialog;
211
212 dialog = gtk_file_chooser_dialog_new ("Save File",
213 GTK_WINDOW (this->window),
214 GTK_FILE_CHOOSER_ACTION_SAVE,
215 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
216 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
217 NULL);
218
219 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
220
221 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
222 (this->playlist_folder)?this->playlist_folder:getenv("HOME"));
223 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "Untitled document");
224
225 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
226 {
227 char *filename;
228
229 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
230 fprintf(stderr, "on_item_save_playlist_activate: filename=[%s]\n", filename);
231
232 if ( this->playlist_folder )
233 g_free (this->playlist_folder);
234 this->playlist_folder = filename;
235 if ( this->playlist_folder )
236 {
237 char* e = strrchr(this->playlist_folder, '/');
238 if(e) *e = 0;
239 }
240 fprintf(stderr, "on_item_save_playlist_activate: this->playlist_folder=[%s]\n", this->playlist_folder);
241 }
242
243 gtk_widget_destroy (dialog);
244 }
245
246 static gboolean on_page_switch_pressed( GtkWidget *button, gpointer user_data )
247 {
248 dv1394app this = user_data;
249 int index = 0;
250 GtkWidget *notebook = lookup_widget( button, "notebook1" );
251
252 if ( this->guard ) return TRUE;
253 this->guard = 1;
254 for ( index = 0; index < this->page_count; index ++ )
255 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( this->page_buttons[ index ] ), FALSE );
256 for ( index = 0; index < this->page_count; index ++ )
257 {
258 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( this->page_buttons[ index ] ), FALSE );
259 if ( this->page_buttons[ index ] == button )
260 break;
261 }
262 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( this->page_buttons[ index ] ), TRUE );
263 gtk_notebook_set_current_page( GTK_NOTEBOOK( notebook ), index );
264 this->guard = 0;
265
266 return TRUE;
267 }
268
269 static gboolean on_transport_pressed( GtkWidget *button, gpointer data )
270 {
271 int index = 0;
272 dv1394app this = ( dv1394app )data;
273 mvcp dv = dv1394app_get_command( this );
274 int unit = dv1394app_get_selected_unit( this );
275
276 for ( index = 0; index < TRANSPORT_BUTTONS_COUNT; index ++ )
277 if ( this->buttons[ index ] == button )
278 break;
279
280 switch( index )
281 {
282 case 0:
283 mvcp_unit_clip_goto( dv, unit, mvcp_absolute, 0, 0 );
284 break;
285
286 case 1:
287 mvcp_unit_goto( dv, unit, 0 );
288 break;
289
290 case 2:
291 mvcp_unit_rewind( dv, unit );
292 break;
293
294 case 3:
295 mvcp_unit_step( dv, unit, -1 );
296 break;
297
298 case 4:
299 mvcp_unit_pause( dv, unit );
300 break;
301
302 case 5:
303 mvcp_unit_play( dv, unit );
304 break;
305
306 case 6:
307 mvcp_unit_stop( dv, unit );
308 break;
309
310 case 7:
311 mvcp_unit_step( dv, unit, 1 );
312 break;
313
314 case 8:
315 mvcp_unit_fast_forward( dv, unit );
316 break;
317
318 case 9:
319 mvcp_unit_clip_goto( dv, unit, mvcp_relative, 1, 0 );
320 break;
321
322 case 10:
323 mvcp_unit_clip_goto( dv, unit, mvcp_absolute, 9999, -1 );
324 break;
325
326 case 11:
327 mvcp_unit_set( dv, unit, "eof", "loop");
328 this->eof[this->selected_unit] = 0;
329 break;
330
331 case 12:
332 mvcp_unit_set( dv, unit, "eof", "pause");
333 this->eof[this->selected_unit] = 0;
334 break;
335
336 default:
337 break;
338 }
339
340 return TRUE;
341 }
342
343 static void dv1394app_register_page( dv1394app this, page item )
344 {
345 GtkWidget *toolbar = lookup_widget( this->window, "toolbar1" );
346 GtkIconSize size = gtk_toolbar_get_icon_size( GTK_TOOLBAR( toolbar ) );
347 GtkWidget *widget = lookup_widget( this->window, "notebook1" );
348 GtkWidget *bin = gtk_frame_new( NULL );
349 char *label = NULL;
350
351 this->pages[ this->page_count ] = item;
352 gtk_widget_reparent( GTK_BIN( page_get_widget( item ) )->child, bin );
353 gtk_container_add(GTK_CONTAINER( widget ), bin );
354 gtk_frame_set_label_align( GTK_FRAME( bin ), 0, 0 );
355 gtk_frame_set_shadow_type( GTK_FRAME( bin ), GTK_SHADOW_NONE );
356 gtk_widget_show( bin );
357
358 page_get_toolbar_info( item, size, &widget, &label );
359 this->page_buttons[ this->page_count ] = gtk_toolbar_append_element( GTK_TOOLBAR ( toolbar ), GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL, label, NULL, NULL, widget, NULL, NULL);
360 gtk_label_set_use_underline( GTK_LABEL(((GtkToolbarChild*)(g_list_last( GTK_TOOLBAR( toolbar )->children)->data))->label), TRUE);
361 gtk_widget_show( widget );
362 gtk_signal_connect( GTK_OBJECT( this->page_buttons[ this->page_count ] ), "clicked", GTK_SIGNAL_FUNC( on_page_switch_pressed ), this );
363 gtk_signal_connect( GTK_OBJECT( this->page_buttons[ this->page_count ] ), "activate", GTK_SIGNAL_FUNC( on_page_switch_pressed ), this );
364
365 this->page_count ++;
366 }
367
368 static GtkAdjustment *trim_adj[3];
369 #define TRIM_ADJ_POS 0
370 #define TRIM_ADJ_IN 1
371 #define TRIM_ADJ_OUT 2
372
373 void dv1394app_show_status( dv1394app this, mvcp_status status )
374 {
375 int index = 0;
376 for ( index = 0; index < this->page_count; index ++ )
377 page_show_status( this->pages[ index ], status );
378
379 if ( status->seek_flag != this->seek_flag )
380 {
381 gtk_widget_set_sensitive( lookup_widget( dv1394app_get_widget( this ), "transport_2" ), status->seek_flag );
382 gtk_widget_set_sensitive( lookup_widget( dv1394app_get_widget( this ), "transport_3" ), status->seek_flag );
383 gtk_widget_set_sensitive( lookup_widget( dv1394app_get_widget( this ), "transport_7" ), status->seek_flag );
384 gtk_widget_set_sensitive( lookup_widget( dv1394app_get_widget( this ), "transport_8" ), status->seek_flag );
385 this->seek_flag = status->seek_flag;
386 }
387
388 if ( !this->trim_in_use )
389 {
390 int upper = status->length > 0 ? status->length - 1 : 0;
391 trim_adj[TRIM_ADJ_IN]->upper = upper;
392 trim_adj[TRIM_ADJ_IN]->value = status->in;
393 trim_adj[TRIM_ADJ_OUT]->upper = upper;
394 trim_adj[TRIM_ADJ_OUT]->value = status->out;
395 trim_adj[TRIM_ADJ_POS]->upper = upper;
396 trim_adj[TRIM_ADJ_POS]->value = status->position;
397 gtk_signal_emit_by_name( GTK_OBJECT(trim_adj[TRIM_ADJ_POS]), "value_changed" );
398 }
399
400 gtk_widget_set_sensitive( lookup_widget( dv1394app_get_widget( this ), "transport_11" ),
401 this->eof[this->selected_unit] == 'p' );
402 gtk_widget_set_sensitive( lookup_widget( dv1394app_get_widget( this ), "transport_12" ),
403 this->eof[this->selected_unit] == 'l' );
404 }
405
406 static gboolean trim_pressed( GtkWidget *button, GdkEventButton *event, gpointer user_data )
407 {
408 dv1394app this = (dv1394app)user_data;
409 mvcp_unit_pause( dv1394app_get_command( this ), this->selected_unit );
410 this->trim_in = -1;
411 this->trim_out = -1;
412 this->trim_in_use = 1;
413 return FALSE;
414 }
415
416 static gboolean trim_released( GtkWidget *button, GdkEventButton *event, gpointer user_data )
417 {
418 dv1394app this = (dv1394app)user_data;
419 this->trim_in_use = 0;
420 if ( this->trim_in != -1 )
421 mvcp_unit_set_in( dv1394app_get_command( this ), this->selected_unit, this->trim_in );
422 if ( this->trim_out != -1 )
423 mvcp_unit_set_out( dv1394app_get_command( this ), this->selected_unit, this->trim_out );
424 return TRUE;
425 }
426
427 static gboolean on_trim_value_changed_event( GtkWidget *button, gpointer user_data )
428 {
429 dv1394app this = (dv1394app)user_data;
430 if ( this->trim_in_use )
431 {
432 char *value;
433 g_object_get( G_OBJECT( button ), "user_data", &value, NULL );
434
435 if ( !strcmp( value, "position" ) )
436 {
437 mvcp_unit_goto( dv1394app_get_command( this ), this->selected_unit, trim_adj[TRIM_ADJ_POS]->value );
438 }
439 else if ( !strcmp( value, "in" ) )
440 {
441 this->trim_in = trim_adj[TRIM_ADJ_IN]->value;
442 mvcp_unit_goto( dv1394app_get_command( this ), this->selected_unit, trim_adj[TRIM_ADJ_IN]->value );
443 }
444 else if ( !strcmp( value, "out" ) )
445 {
446 this->trim_out = trim_adj[TRIM_ADJ_OUT]->value;
447 mvcp_unit_goto( dv1394app_get_command( this ), this->selected_unit, trim_adj[TRIM_ADJ_OUT]->value );
448 }
449
450 gtk_widget_queue_draw (lookup_widget(this->window, "vbox_trim") );
451 return TRUE;
452 }
453 return FALSE;
454 }
455
456 /** Initialiser for application state.
457 */
458
459 dv1394app dv1394app_init( GtkWidget *window, char *instance )
460 {
461 dv1394app this = calloc( 1, sizeof( dv1394app_t ) );
462
463 if ( this != NULL )
464 {
465 GtkWidget *widget;
466
467 this->window = window;
468
469 /* Window destroy event */
470 gtk_signal_connect( GTK_OBJECT( this->window ), "destroy", GTK_SIGNAL_FUNC( on_main_window_delete_event ), this );
471
472 /* Menu item signal handling */
473 // widget = lookup_widget( this->window, "item_connect" );
474 // gtk_signal_connect( GTK_OBJECT( widget ), "activate", GTK_SIGNAL_FUNC( on_item_connect_activate ), this );
475 widget = lookup_widget( this->window, "button_connect" );
476 gtk_signal_connect( GTK_OBJECT( widget ), "clicked", GTK_SIGNAL_FUNC( on_item_connect_activate ), this );
477 // widget = lookup_widget( this->window, "item_disconnect" );
478 // gtk_signal_connect( GTK_OBJECT( widget ), "activate", GTK_SIGNAL_FUNC( on_item_disconnect_activate ), this );
479 widget = lookup_widget( this->window, "button_disconnect" );
480 gtk_signal_connect( GTK_OBJECT( widget ), "clicked", GTK_SIGNAL_FUNC( on_item_disconnect_activate ), this );
481 // widget = lookup_widget( this->window, "item_quit" );
482 // gtk_signal_connect( GTK_OBJECT( widget ), "activate", GTK_SIGNAL_FUNC( on_item_quit_activate ), this );
483 // widget = lookup_widget( this->window, "button_quit" );
484 // gtk_signal_connect( GTK_OBJECT( widget ), "clicked", GTK_SIGNAL_FUNC( on_item_quit_activate ), this );
485 widget = lookup_widget( this->window, "button_open_playlist" );
486 gtk_signal_connect( GTK_OBJECT( widget ), "clicked", GTK_SIGNAL_FUNC( on_item_open_playlist_activate ), this );
487 widget = lookup_widget( this->window, "button_save_playlist" );
488 gtk_signal_connect( GTK_OBJECT( widget ), "clicked", GTK_SIGNAL_FUNC( on_item_save_playlist_activate ), this );
489
490
491 /* Initialise the pages. */
492 dv1394app_register_page( this, page_operate_init( this ) );
493 dv1394app_register_page( this, page_command_init( this ) );
494 this->guard = 1;
495 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( this->page_buttons[ 0 ] ), TRUE );
496 this->guard = 0;
497
498 /* Remove the empty page */
499 widget = lookup_widget( this->window, "notebook1" );
500 gtk_notebook_remove_page( GTK_NOTEBOOK( widget ), 0 );
501
502 guint keys[ ] = { GDK_0, GDK_1, GDK_2, GDK_3, GDK_4, GDK_5, GDK_6, GDK_7, GDK_8, GDK_9, GDK_A };
503 int index;
504 GtkAccelGroup *accel_group = gtk_accel_group_new( );
505
506 for ( index = 0; index < TRANSPORT_BUTTONS_COUNT; index ++ )
507 {
508 char name[ 256 ];
509 sprintf( name, "transport_%d", index );
510 this->buttons[ index ] = lookup_widget( dv1394app_get_widget( this ), name );
511 gtk_signal_connect( GTK_OBJECT( this->buttons[ index ] ), "clicked", GTK_SIGNAL_FUNC( on_transport_pressed ), this );
512 gtk_widget_add_accelerator( this->buttons[ index ], "clicked", accel_group, keys[ index ], GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE );
513 }
514
515 gtk_window_add_accel_group( GTK_WINDOW( dv1394app_get_widget( this ) ), accel_group);
516
517 trim_adj[TRIM_ADJ_POS] = GTK_ADJUSTMENT( gtk_adjustment_new( 0, 0, 1000, 1, 10, 0 ) );
518 g_object_set( G_OBJECT( trim_adj[TRIM_ADJ_POS] ), "user_data", "position", NULL );
519 trim_adj[TRIM_ADJ_IN] = GTK_ADJUSTMENT( gtk_adjustment_new( 0, 0, 1000, 1, 10, 0 ) );
520 g_object_set( G_OBJECT( trim_adj[TRIM_ADJ_IN] ), "user_data", "in", NULL );
521 trim_adj[TRIM_ADJ_OUT] = GTK_ADJUSTMENT( gtk_adjustment_new( 0, 0, 1000, 1, 10, 0 ) );
522 g_object_set( G_OBJECT( trim_adj[TRIM_ADJ_OUT] ), "user_data", "out", NULL );
523
524 int i;
525 for (i = 0; i < 3; i++)
526 gtk_signal_connect (GTK_OBJECT (trim_adj[i]), "value_changed", GTK_SIGNAL_FUNC (on_trim_value_changed_event), this );
527
528 GtkWidget *trim = gtk_enhanced_scale_new( (GtkObject**) trim_adj, 3);
529 if ( trim != NULL )
530 {
531 gtk_widget_set_name (trim, "trim");
532 GTK_WIDGET_UNSET_FLAGS( GTK_WIDGET( trim ), GTK_CAN_FOCUS );
533 gtk_widget_ref(trim);
534 gtk_object_set_data_full (GTK_OBJECT( this->window ), "trim", trim, (GtkDestroyNotify) gtk_widget_unref);
535 GtkWidget *vbox_trim = lookup_widget(this->window, "vbox_trim");
536 gtk_widget_show(trim);
537 gtk_box_pack_start(GTK_BOX (vbox_trim), trim, TRUE, TRUE, 0);
538 gtk_signal_connect( GTK_OBJECT( trim ), "button_press_event", GTK_SIGNAL_FUNC (trim_pressed), this );
539 gtk_signal_connect( GTK_OBJECT( trim ), "button_release_event", GTK_SIGNAL_FUNC (trim_released), this );
540 }
541 this->seek_flag = 1;
542 }
543
544 if ( instance != NULL )
545 {
546 char *server = strdup( instance );
547 char *port = strchr( server, ':' );
548 if ( port != NULL )
549 *port ++ = '\0';
550 else
551 port = "5250";
552 this->guard = 1;
553 if ( instance_connect( this, server, port ) )
554 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( lookup_widget( this->window, "button_connect" ) ), TRUE );
555 else
556 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( lookup_widget( this->window, "button_disconnect" ) ), TRUE );
557 this->guard = 0;
558 free( server );
559 }
560
561
562 return this;
563 }
564
565 /** Get the app window widget.
566 */
567
568 GtkWidget *dv1394app_get_widget( dv1394app this )
569 {
570 return this->window;
571 }
572
573 /** Get the applications parser.
574 */
575
576 mvcp_parser dv1394app_get_parser( dv1394app this )
577 {
578 return this->parser;
579 }
580
581 /** Return the command parser.
582 */
583
584 mvcp dv1394app_get_command( dv1394app this )
585 {
586 return this->command;
587 }
588
589 /** Issue a connect to all pages.
590 */
591
592 void dv1394app_connect( dv1394app this )
593 {
594 int index = 0;
595 for ( index = 0; index < this->page_count; index ++ )
596 page_on_connect( this->pages[ index ] );
597 }
598
599 /** Inform all pages that the unit has changed.
600 */
601
602 void dv1394app_on_unit_change( dv1394app this, int unit )
603 {
604 int index = 0;
605 this->selected_unit = unit;
606 for ( index = 0; index < this->page_count; index ++ )
607 page_on_unit_change( this->pages[ index ], unit );
608 }
609
610 /** Return the selected unit.
611 */
612
613 int dv1394app_get_selected_unit( dv1394app this )
614 {
615 return this->selected_unit;
616 }
617
618 /** Issue a disconnect to all pages.
619 */
620
621 void dv1394app_disconnect( dv1394app this )
622 {
623 int index = 0;
624 if ( this->parser != NULL )
625 {
626 for ( index = 0; index < this->page_count; index ++ )
627 page_on_disconnect( this->pages[ index ] );
628 mvcp_close( this->command );
629 this->command = NULL;
630 mvcp_parser_close( this->parser );
631 this->parser = NULL;
632 }
633 }
634
635 /** Close application.
636 */
637
638 void dv1394app_close( dv1394app this )
639 {
640 dv1394app_disconnect( this );
641 while ( this->page_count > 0 )
642 page_close( this->pages[ -- this->page_count ] );
643 free( this );
644 }
645
646 char* frames2tc( int f, float fps, char* buf )
647 {
648 int tc[4] = { 0, 0, 0, 0 };
649 float d;
650 int t;
651
652 if ( fps )
653 {
654 d = f / fps;
655 t = d;
656
657 tc[0] = (d - t) * fps;
658 tc[1] = t % 60; t /= 60;
659 tc[2] = t % 60; t /= 60;
660 tc[3] = t % 24;
661 }
662
663 sprintf(buf, "%.2d:%.2d:%.2d:%.2d", tc[3], tc[2], tc[1], tc[0]);
664
665 return buf;
666 }