00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <stdlib.h>
00029 #include <errno.h>
00030 #include <string.h>
00031 #include <stdio.h>
00032
00033 #include <vlc/vlc.h>
00034 #include <vlc/intf.h>
00035
00036 #include <gtk/gtk.h>
00037
00038 #include "pda_callbacks.h"
00039 #include "pda_interface.h"
00040 #include "pda_support.h"
00041 #include "pda.h"
00042
00043
00044
00045
00046 static int Open ( vlc_object_t * );
00047 static void Close ( vlc_object_t * );
00048 static void Run ( intf_thread_t * );
00049
00050 void GtkAutoPlayFile ( vlc_object_t * );
00051 static int Manage ( intf_thread_t *p_intf );
00052 void E_(GtkDisplayDate) ( GtkAdjustment *p_adj, gpointer userdata );
00053 gint E_(GtkModeManage) ( intf_thread_t * p_intf );
00054
00055
00056
00057
00058 #define AUTOPLAYFILE_TEXT N_("Autoplay selected file")
00059 #define AUTOPLAYFILE_LONGTEXT N_("Automatically play a file when selected in the "\
00060 "file selection list")
00061
00062
00063
00064
00065 vlc_module_begin();
00066 set_description( N_("PDA Linux Gtk2+ interface") );
00067 set_category( CAT_INTERFACE );
00068 set_subcategory( SUBCAT_INTERFACE_GENERAL );
00069
00070 set_capability( "interface", 70 );
00071 set_callbacks( Open, Close );
00072 add_shortcut( "pda" );
00073 vlc_module_end();
00074
00075
00076
00077
00078 static int Open( vlc_object_t *p_this )
00079 {
00080 intf_thread_t *p_intf = (intf_thread_t *)p_this;
00081
00082
00083 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
00084 if( p_intf->p_sys == NULL )
00085 {
00086 msg_Err( p_intf, "out of memory" );
00087 return VLC_ENOMEM;
00088 }
00089
00090 #ifdef NEED_GTK2_MAIN
00091 msg_Dbg( p_intf, "Using gui-helper" );
00092 p_intf->p_sys->p_gtk_main =
00093 module_Need( p_this, "gui-helper", "gtk2", VLC_TRUE );
00094 if( p_intf->p_sys->p_gtk_main == NULL )
00095 {
00096 free( p_intf->p_sys );
00097 return VLC_ENOMOD;
00098 }
00099 #endif
00100
00101
00102 p_intf->p_sys->p_input = NULL;
00103
00104 p_intf->p_sys->b_autoplayfile = 1;
00105 p_intf->p_sys->b_playing = 0;
00106 p_intf->p_sys->b_slider_free = 1;
00107
00108 p_intf->pf_run = Run;
00109
00110 return VLC_SUCCESS;
00111 }
00112
00113
00114
00115
00116 static void Close( vlc_object_t *p_this )
00117 {
00118 intf_thread_t *p_intf = (intf_thread_t *)p_this;
00119
00120 if( p_intf->p_sys->p_input )
00121 {
00122 vlc_object_release( p_intf->p_sys->p_input );
00123 }
00124
00125 #ifdef NEED_GTK2_MAIN
00126 msg_Dbg( p_intf, "Releasing gui-helper" );
00127 module_Unneed( p_intf, p_intf->p_sys->p_gtk_main );
00128 #endif
00129
00130
00131 free( p_intf->p_sys );
00132 }
00133
00134
00135
00136
00137
00138
00139
00140 static void Run( intf_thread_t *p_intf )
00141 {
00142 #ifndef NEED_GTK2_MAIN
00143
00144
00145 char *p_args[] = { "", NULL };
00146 char **pp_args = p_args;
00147 int i_args = 1;
00148 int i_dummy;
00149 #endif
00150 playlist_t *p_playlist;
00151 GtkCellRenderer *p_renderer = NULL;
00152 GtkTreeViewColumn *p_column = NULL;
00153 GtkListStore *p_filelist = NULL;
00154 GtkListStore *p_playlist_store = NULL;
00155
00156 #ifndef NEED_GTK2_MAIN
00157 gtk_set_locale ();
00158 msg_Dbg( p_intf, "Starting pda GTK2+ interface" );
00159 gtk_init( &i_args, &pp_args );
00160 #else
00161
00162 msg_Dbg( p_intf, "Starting pda GTK2+ interface thread" );
00163 gdk_threads_enter();
00164 #endif
00165
00166
00167
00168 add_pixmap_directory("share");
00169 add_pixmap_directory("/usr/share/vlc");
00170
00171
00172 add_pixmap_directory("/usr/local/share/pixmaps/vlc");
00173
00174 add_pixmap_directory("/usr/share/pixmaps/vlc");
00175
00176 p_intf->p_sys->p_window = create_pda();
00177 if (p_intf->p_sys->p_window == NULL)
00178 {
00179 msg_Err( p_intf, "unable to create pda interface" );
00180 }
00181
00182
00183 gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
00184 "p_intf", p_intf );
00185
00186
00187 gtk_window_set_title( GTK_WINDOW(p_intf->p_sys->p_window),
00188 VOUT_TITLE " (PDA Linux interface)");
00189
00190
00191 p_intf->p_sys->p_notebook = GTK_NOTEBOOK( gtk_object_get_data(
00192 GTK_OBJECT( p_intf->p_sys->p_window ), "notebook" ) );
00193
00194
00195 p_intf->p_sys->p_slider = (GtkHScale*) lookup_widget( p_intf->p_sys->p_window, "timeSlider" );
00196 p_intf->p_sys->p_slider_label = (GtkLabel*) lookup_widget( p_intf->p_sys->p_window, "timeLabel" );
00197 if (p_intf->p_sys->p_slider == NULL)
00198 msg_Err( p_intf, "Time slider widget not found." );
00199 if (p_intf->p_sys->p_slider_label == NULL)
00200 msg_Err( p_intf, "Time label widget not found." );
00201
00202
00203 p_intf->p_sys->p_adj = gtk_range_get_adjustment( GTK_RANGE(p_intf->p_sys->p_slider) );
00204 if (p_intf->p_sys->p_adj == NULL)
00205 msg_Err( p_intf, "Adjustment range not found." );
00206 g_signal_connect( GTK_OBJECT( p_intf->p_sys->p_adj ), "value_changed",
00207 G_CALLBACK( E_(GtkDisplayDate) ), p_intf );
00208 p_intf->p_sys->f_adj_oldvalue = 0;
00209 p_intf->p_sys->i_adj_oldvalue = 0;
00210
00211
00212 p_intf->p_sys->p_tvfile = NULL;
00213 p_intf->p_sys->p_tvfile = (GtkTreeView *) lookup_widget( p_intf->p_sys->p_window,
00214 "tvFileList");
00215 if (NULL == p_intf->p_sys->p_tvfile)
00216 msg_Err(p_intf, "Error obtaining pointer to File List");
00217
00218
00219 p_renderer = gtk_cell_renderer_text_new ();
00220 gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 0, (gchar *) N_("Filename"), p_renderer, NULL);
00221 p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 0 );
00222 gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 0 );
00223 gtk_tree_view_column_set_sort_column_id(p_column, 0);
00224
00225 p_renderer = gtk_cell_renderer_text_new ();
00226 gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 1, (gchar *) N_("Permissions"), p_renderer, NULL);
00227 p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 1 );
00228 gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 1 );
00229 gtk_tree_view_column_set_sort_column_id(p_column, 1);
00230
00231 p_renderer = gtk_cell_renderer_text_new ();
00232 gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 2, (gchar *) N_("Size"), p_renderer, NULL);
00233 p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 2 );
00234 gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 2 );
00235 gtk_tree_view_column_set_sort_column_id(p_column, 2);
00236
00237 p_renderer = gtk_cell_renderer_text_new ();
00238 gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 3, (gchar *) N_("Owner"), p_renderer, NULL);
00239 p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 3 );
00240 gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 3 );
00241 gtk_tree_view_column_set_sort_column_id(p_column, 3);
00242
00243 p_renderer = gtk_cell_renderer_text_new ();
00244 gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 4, (gchar *) N_("Group"), p_renderer, NULL);
00245 p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 4 );
00246 gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 4 );
00247 gtk_tree_view_column_set_sort_column_id(p_column, 4);
00248
00249
00250 p_filelist = gtk_list_store_new (5,
00251 G_TYPE_STRING,
00252 G_TYPE_STRING,
00253 G_TYPE_UINT64,
00254 G_TYPE_STRING,
00255 G_TYPE_STRING);
00256 ReadDirectory(p_intf, p_filelist, ".");
00257 gtk_tree_view_set_model(GTK_TREE_VIEW(p_intf->p_sys->p_tvfile), GTK_TREE_MODEL(p_filelist));
00258 g_object_unref(p_filelist);
00259 gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(p_intf->p_sys->p_tvfile)),GTK_SELECTION_MULTIPLE);
00260
00261
00262 gtk_tree_view_set_headers_visible(p_intf->p_sys->p_tvfile, TRUE);
00263 gtk_tree_view_columns_autosize(p_intf->p_sys->p_tvfile);
00264 gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(p_intf->p_sys->p_tvfile),TRUE);
00265
00266
00267
00268 p_intf->p_sys->p_tvplaylist = NULL;
00269 p_intf->p_sys->p_tvplaylist = (GtkTreeView *) lookup_widget( p_intf->p_sys->p_window, "tvPlaylist");
00270 if (NULL == p_intf->p_sys->p_tvplaylist)
00271 msg_Err(p_intf, "Error obtaining pointer to Play List");
00272
00273
00274 p_renderer = gtk_cell_renderer_text_new ();
00275 gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 0, (gchar *) N_("Filename"), p_renderer, NULL);
00276 p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvplaylist, 0 );
00277 gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 0 );
00278 gtk_tree_view_column_set_sort_column_id(p_column, 0);
00279
00280 p_renderer = gtk_cell_renderer_text_new ();
00281 gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 1, (gchar *) N_("Time"), p_renderer, NULL);
00282 p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvplaylist, 1 );
00283 gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 1 );
00284 gtk_tree_view_column_set_sort_column_id(p_column, 1);
00285 #if 0
00286
00287 p_renderer = gtk_cell_renderer_text_new ();
00288 gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 2, (gchar *) N_("Index"), p_renderer, NULL);
00289 p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvplaylist, 2 );
00290 gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 2 );
00291 gtk_tree_view_column_set_sort_column_id(p_column, 2);
00292 #endif
00293
00294 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
00295 p_playlist_store = gtk_list_store_new (3,
00296 G_TYPE_STRING,
00297 G_TYPE_STRING,
00298 G_TYPE_UINT);
00299 PlaylistRebuildListStore(p_playlist_store, p_playlist);
00300 gtk_tree_view_set_model(GTK_TREE_VIEW(p_intf->p_sys->p_tvplaylist), GTK_TREE_MODEL(p_playlist_store));
00301 g_object_unref(p_playlist_store);
00302 vlc_object_release(p_playlist);
00303 gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(p_intf->p_sys->p_tvplaylist)),GTK_SELECTION_MULTIPLE);
00304
00305
00306 gtk_tree_view_set_headers_visible(p_intf->p_sys->p_tvplaylist, TRUE);
00307 gtk_tree_view_columns_autosize(p_intf->p_sys->p_tvplaylist);
00308 gtk_tree_view_set_headers_clickable(p_intf->p_sys->p_tvplaylist, TRUE);
00309
00310
00311
00312 GtkWidget *p_preference_tab = NULL;
00313 p_preference_tab = gtk_notebook_get_nth_page(p_intf->p_sys->p_notebook,5);
00314 if (p_preference_tab != NULL)
00315 gtk_widget_hide(p_preference_tab);
00316
00317
00318 gtk_widget_show( p_intf->p_sys->p_window );
00319
00320 #ifdef NEED_GTK2_MAIN
00321 msg_Dbg( p_intf, "Manage GTK keyboard events using threads" );
00322 while( !p_intf->b_die )
00323 {
00324 Manage( p_intf );
00325
00326
00327
00328 gdk_threads_leave();
00329 if (p_intf->p_libvlc->i_cpu & CPU_CAPABILITY_FPU)
00330 msleep( INTF_IDLE_SLEEP );
00331 else
00332 msleep( 1000 );
00333 gdk_threads_enter();
00334 }
00335 #else
00336 msg_Dbg( p_intf, "Manage GTK keyboard events using timeouts" );
00337
00338
00339 if (p_intf->p_libvlc->i_cpu & CPU_CAPABILITY_FPU)
00340 i_dummy = gtk_timeout_add( INTF_IDLE_SLEEP / 1000, (GtkFunction)Manage, p_intf );
00341 else
00342 i_dummy = gtk_timeout_add( 1000, (GtkFunction)Manage, p_intf );
00343
00344
00345 gtk_main();
00346
00347 gtk_timeout_remove( i_dummy );
00348 #endif
00349
00350 gtk_object_destroy( GTK_OBJECT(p_intf->p_sys->p_window) );
00351 #ifdef NEED_GTK2_MAIN
00352 gdk_threads_leave();
00353 #endif
00354 }
00355
00356
00357
00358
00359 void GtkAutoPlayFile( vlc_object_t *p_this )
00360 {
00361 GtkWidget *cbautoplay;
00362 intf_thread_t *p_intf;
00363 int i_index;
00364 vlc_list_t *p_list = vlc_list_find( p_this, VLC_OBJECT_INTF,
00365 FIND_ANYWHERE );
00366
00367 for( i_index = 0; i_index < p_list->i_count; i_index++ )
00368 {
00369 p_intf = (intf_thread_t *)p_list->p_values[i_index].p_object ;
00370
00371 if( strcmp( MODULE_STRING, p_intf->p_module->psz_object_name ) )
00372 {
00373 continue;
00374 }
00375 cbautoplay = GTK_WIDGET( gtk_object_get_data(
00376 GTK_OBJECT( p_intf->p_sys->p_window ),
00377 "cbautoplay" ) );
00378
00379 if( !config_GetInt( p_this, "pda-autoplayfile" ) )
00380 {
00381 p_intf->p_sys->b_autoplayfile = VLC_FALSE;
00382 }
00383 else
00384 {
00385 p_intf->p_sys->b_autoplayfile = VLC_TRUE;
00386 }
00387 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( cbautoplay ),
00388 p_intf->p_sys->b_autoplayfile );
00389 }
00390 vlc_list_release( p_list );
00391 }
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401 static int Manage( intf_thread_t *p_intf )
00402 {
00403 GtkListStore *p_liststore;
00404 vlc_mutex_lock( &p_intf->change_lock );
00405
00406
00407 if( p_intf->p_sys->p_input == NULL )
00408 {
00409 p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
00410 FIND_ANYWHERE );
00411 }
00412 else if( p_intf->p_sys->p_input->b_dead )
00413 {
00414 vlc_object_release( p_intf->p_sys->p_input );
00415 p_intf->p_sys->p_input = NULL;
00416 }
00417
00418 if( p_intf->p_sys->p_input )
00419 {
00420 input_thread_t *p_input = p_intf->p_sys->p_input;
00421
00422 vlc_mutex_lock( &p_input->object_lock );
00423 if( !p_input->b_die )
00424 {
00425 {
00426 playlist_t *p_playlist;
00427
00428 E_(GtkModeManage)( p_intf );
00429 p_intf->p_sys->b_playing = 1;
00430
00431
00432 p_playlist = (playlist_t *) vlc_object_find(
00433 p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
00434 if (p_playlist != NULL)
00435 {
00436 p_liststore = gtk_list_store_new (3,
00437 G_TYPE_STRING,
00438 G_TYPE_STRING,
00439 G_TYPE_UINT);
00440 PlaylistRebuildListStore(p_liststore, p_playlist);
00441 gtk_tree_view_set_model(p_intf->p_sys->p_tvplaylist, (GtkTreeModel*) p_liststore);
00442 g_object_unref(p_liststore);
00443 vlc_object_release( p_playlist );
00444 }
00445 }
00446
00447
00448 #if 0
00449 #define p_area p_input->p_selected_area
00450 if (p_intf->p_libvlc->i_cpu & CPU_CAPABILITY_FPU)
00451 {
00452
00453 if( p_intf->p_sys->b_playing )
00454 {
00455 float newvalue = p_intf->p_sys->p_adj->value;
00456
00457
00458
00459 if( newvalue == p_intf->p_sys->f_adj_oldvalue )
00460 {
00461
00462 p_intf->p_sys->p_adj->value =
00463 p_intf->p_sys->f_adj_oldvalue =
00464 ( 100. * p_area->i_tell ) / p_area->i_size;
00465 g_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
00466 "value_changed" );
00467 }
00468
00469
00470 else if( p_intf->p_sys->b_slider_free )
00471 {
00472 double f_pos = (double)newvalue / 100.0;
00473
00474
00475 vlc_mutex_unlock( &p_input->object_lock );
00476 var_SetFloat( p_input, "position", f_pos );
00477 vlc_mutex_lock( &p_input->object_lock );
00478
00479
00480 p_intf->p_sys->f_adj_oldvalue = newvalue;
00481 }
00482 }
00483 }
00484 else
00485 {
00486
00487 if( p_intf->p_sys->b_playing )
00488 {
00489 off_t newvalue = p_intf->p_sys->p_adj->value;
00490
00491
00492
00493 if( newvalue == p_intf->p_sys->i_adj_oldvalue )
00494 {
00495
00496 p_intf->p_sys->p_adj->value =
00497 p_intf->p_sys->i_adj_oldvalue =
00498 ( 100 * p_area->i_tell ) / p_area->i_size;
00499 g_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
00500 "value_changed" );
00501 }
00502
00503
00504 else if( p_intf->p_sys->b_slider_free )
00505 {
00506 double f_pos = (double)newvalue / 100.0;
00507
00508
00509 vlc_mutex_unlock( &p_input->object_lock );
00510 var_SetFloat( p_input, "position", f_pos );
00511 vlc_mutex_lock( &p_input->object_lock );
00512
00513
00514 p_intf->p_sys->i_adj_oldvalue = newvalue;
00515 }
00516 }
00517 }
00518 #undef p_area
00519 #endif
00520 }
00521 vlc_mutex_unlock( &p_input->object_lock );
00522 }
00523 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
00524 {
00525 E_(GtkModeManage)( p_intf );
00526 p_intf->p_sys->b_playing = 0;
00527 }
00528
00529 #ifndef NEED_GTK2_MAIN
00530 if( p_intf->b_die )
00531 {
00532 vlc_mutex_unlock( &p_intf->change_lock );
00533
00534
00535 gtk_main_quit();
00536
00537 return FALSE;
00538 }
00539 #endif
00540
00541 vlc_mutex_unlock( &p_intf->change_lock );
00542
00543 return TRUE;
00544 }
00545
00546
00547
00548
00549
00550
00551
00552
00553 void E_(GtkDisplayDate)( GtkAdjustment *p_adj, gpointer userdata )
00554 {
00555 intf_thread_t *p_intf;
00556
00557 p_intf = (intf_thread_t*) userdata;
00558 if (p_intf == NULL)
00559 return;
00560
00561 if( p_intf->p_sys->p_input )
00562 {
00563 char psz_time[ MSTRTIME_MAX_SIZE ];
00564 int64_t i_seconds;
00565
00566 i_seconds = var_GetTime( p_intf->p_sys->p_input, "time" ) / I64C(1000000 );
00567 secstotimestr( psz_time, i_seconds );
00568
00569 gtk_label_set_text( GTK_LABEL( p_intf->p_sys->p_slider_label ),
00570 psz_time );
00571 }
00572 }
00573
00574
00575
00576
00577
00578
00579
00580 gint E_(GtkModeManage)( intf_thread_t * p_intf )
00581 {
00582 GtkWidget * p_slider = NULL;
00583 vlc_bool_t b_control;
00584
00585 if ( p_intf->p_sys->p_window == NULL )
00586 msg_Err( p_intf, "Main widget not found" );
00587
00588 p_slider = lookup_widget( p_intf->p_sys->p_window, "timeSlider");
00589 if (p_slider == NULL)
00590 msg_Err( p_intf, "Slider widget not found" );
00591
00592
00593 b_control = 0;
00594
00595
00596 if( p_intf->p_sys->p_input )
00597 {
00598
00599 {
00600 gtk_widget_show( GTK_WIDGET( p_slider ) );
00601 }
00602
00603
00604 b_control = p_intf->p_sys->p_input->b_can_pace_control;
00605
00606 msg_Dbg( p_intf, "stream has changed, refreshing interface" );
00607 }
00608
00609
00610 gtk_widget_set_sensitive( lookup_widget( p_intf->p_sys->p_window, "tbRewind"), b_control );
00611 gtk_widget_set_sensitive( lookup_widget( p_intf->p_sys->p_window, "tbPause"), b_control );
00612 gtk_widget_set_sensitive( lookup_widget( p_intf->p_sys->p_window, "tbForward"), b_control );
00613 return TRUE;
00614 }
00615