1 /*****************************************************************************
2 * vlcproc.cpp: VlcProc class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
7 * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8 * Emmanuel Puig <karibu@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111,
24 *****************************************************************************/
26 //--- VLC -------------------------------------------------------------------
32 //--- SKIN ------------------------------------------------------------------
33 #include "../os_api.h"
37 #include "../os_theme.h"
38 #include "themeloader.h"
41 #include "skin_common.h"
44 //---------------------------------------------------------------------------
46 //---------------------------------------------------------------------------
47 VlcProc::VlcProc( intf_thread_t *_p_intf )
51 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
52 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
53 if( p_playlist != NULL )
55 // We want to be notified of playlist changes
56 var_AddCallback( p_playlist, "intf-change", RefreshCallback, this );
58 // Raise/lower interface with middle click on vout
59 var_AddCallback( p_playlist, "intf-show", IntfShowCallback, this );
61 vlc_object_release( p_playlist );
64 //---------------------------------------------------------------------------
67 // Remove the refresh callback
68 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
69 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
70 if( p_playlist != NULL )
72 var_DelCallback( p_playlist, "intf-change", RefreshCallback, this );
73 var_DelCallback( p_playlist, "intf-show", IntfShowCallback, this );
74 vlc_object_release( p_playlist );
77 //---------------------------------------------------------------------------
78 bool VlcProc::EventProc( Event *evt )
80 switch( evt->GetMessage() )
83 MoveStream( evt->GetParam2() );
86 case VLC_VOLUME_CHANGE:
87 ChangeVolume( evt->GetParam1(), evt->GetParam2() );
95 for( list<SkinWindow *>::const_iterator win =
96 p_intf->p_sys->p_theme->WindowList.begin();
97 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
99 (*win)->OnStartThemeVisible = !(*win)->IsHidden();
101 p_intf->p_sys->i_close_status = (int)evt->GetParam1();
102 OSAPI_PostMessage( NULL, WINDOW_CLOSE, 1, 0 );
106 for( list<SkinWindow *>::const_iterator win =
107 p_intf->p_sys->p_theme->WindowList.begin();
108 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
110 if( (*win)->OnStartThemeVisible )
111 OSAPI_PostMessage( (*win), WINDOW_OPEN, 1, 0 );
113 p_intf->p_sys->b_all_win_closed = false;
117 p_intf->p_sys->p_dialogs->ShowOpen( true );
122 p_intf->p_sys->p_dialogs->ShowNet();
131 for( list<SkinWindow *>::const_iterator win =
132 p_intf->p_sys->p_theme->WindowList.begin();
133 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
135 (*win)->ToggleOnTop();
137 // Set the indicator to the new state
138 p_intf->p_sys->b_on_top = !p_intf->p_sys->b_on_top;
142 DropFile( evt->GetParam1(), evt->GetParam2() );
173 case VLC_PLAYLIST_ADD_FILE:
174 p_intf->p_sys->p_dialogs->ShowOpen( false );
179 p_intf->p_sys->p_dialogs->ShowMessages();
183 p_intf->p_sys->p_dialogs->ShowPrefs();
187 p_intf->p_sys->p_dialogs->ShowFileInfo();
190 case VLC_INTF_REFRESH:
194 case VLC_TEST_ALL_CLOSED:
195 return EventProcEnd();
200 case VLC_CHANGE_TRAY:
201 p_intf->p_sys->p_theme->ChangeTray();
204 case VLC_CHANGE_TASKBAR:
205 p_intf->p_sys->p_theme->ChangeTaskbar();
212 //---------------------------------------------------------------------------
213 bool VlcProc::EventProcEnd()
215 if( p_intf->p_sys->b_all_win_closed )
218 list<SkinWindow *>::const_iterator win;
220 // If a window has been closed, test if all are closed !
221 for( win = p_intf->p_sys->p_theme->WindowList.begin();
222 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
224 if( !(*win)->IsHidden() ) // Not all windows closed
230 // All window are closed
231 switch( p_intf->p_sys->i_close_status )
234 // Save config before exiting
235 p_intf->p_sys->p_theme->SaveConfig();
239 // Send specified event
240 OSAPI_PostMessage( NULL, p_intf->p_sys->i_close_status, 0, 0 );
243 p_intf->p_sys->i_close_status = VLC_NOTHING;
244 p_intf->p_sys->b_all_win_closed = true;
249 //---------------------------------------------------------------------------
250 bool VlcProc::IsClosing()
252 if( p_intf->b_die && p_intf->p_sys->i_close_status != VLC_QUIT )
254 p_intf->p_sys->i_close_status = VLC_QUIT;
255 OSAPI_PostMessage( NULL, VLC_HIDE, VLC_QUIT, 0 );
259 //---------------------------------------------------------------------------
264 //---------------------------------------------------------------------------
266 //---------------------------------------------------------------------------
269 int VlcProc::RefreshCallback( vlc_object_t *p_this, const char *psz_variable,
270 vlc_value_t old_val, vlc_value_t new_val, void *param )
272 ( (VlcProc*)param )->InterfaceRefresh();
276 // Interface show/hide callback
277 int VlcProc::IntfShowCallback( vlc_object_t *p_this, const char *psz_variable,
278 vlc_value_t old_val, vlc_value_t new_val, void *param )
280 if( new_val.b_bool == VLC_TRUE )
282 OSAPI_PostMessage( NULL, VLC_SHOW, 1, 0 );
286 OSAPI_PostMessage( NULL, VLC_HIDE, 1, 0 );
291 void VlcProc::InterfaceRefresh()
294 intf_sys_t *Sys = p_intf->p_sys;
295 Theme *Thema = Sys->p_theme;
296 playlist_t *PlayList = Sys->p_playlist;
299 if( PlayList != NULL )
301 vlc_mutex_lock( &PlayList->object_lock );
303 // Refresh stream control controls ! :)
304 switch( PlayList->i_status )
306 case PLAYLIST_STOPPED:
307 EnabledEvent( "time", false );
308 EnabledEvent( "stop", false );
309 EnabledEvent( "play", true );
310 EnabledEvent( "pause", false );
312 case PLAYLIST_RUNNING:
313 EnabledEvent( "time", true );
314 EnabledEvent( "stop", true );
315 EnabledEvent( "play", false );
316 EnabledEvent( "pause", true );
318 case PLAYLIST_PAUSED:
319 EnabledEvent( "time", true );
320 EnabledEvent( "stop", true );
321 EnabledEvent( "play", true );
322 EnabledEvent( "pause", false );
326 // Refresh next and prev buttons
327 if( PlayList->i_index == 0 || PlayList->i_size == 1 )
328 EnabledEvent( "prev", false );
330 EnabledEvent( "prev", true );
332 if( PlayList->i_index == PlayList->i_size - 1 || PlayList->i_size == 1 )
333 EnabledEvent( "next", false );
335 EnabledEvent( "next", true );
338 if( PlayList->i_index >= 0 && PlayList->i_index != Sys->i_index )
340 string long_name = PlayList->pp_items[PlayList->i_index]->input.psz_name;
341 int pos = long_name.rfind( DIRECTORY_SEPARATOR, long_name.size() );
343 // Complete file name
344 Thema->EvtBank->Get( "file_name" )->PostTextMessage(
345 PlayList->pp_items[PlayList->i_index]->input.psz_name );
346 // File name without path
347 Thema->EvtBank->Get( "title" )->PostTextMessage(
348 PlayList->pp_items[PlayList->i_index]->input.psz_name + pos + 1 );
352 if( PlayList->i_index != Sys->i_index ||
353 PlayList->i_size != Sys->i_size )
355 Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
356 Sys->i_size = PlayList->i_size;
357 Sys->i_index = PlayList->i_index;
360 vlc_mutex_unlock( &PlayList->object_lock );
364 EnabledEvent( "time", false );
365 EnabledEvent( "stop", false );
366 EnabledEvent( "play", false );
367 EnabledEvent( "pause", false );
368 EnabledEvent( "prev", false );
369 EnabledEvent( "next", false );
372 if( Sys->i_size > 0 )
374 Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
379 //---------------------------------------------------------------------------
380 void VlcProc::EnabledEvent( string type, bool state )
382 OSAPI_PostMessage( NULL, CTRL_ENABLED, (unsigned int)
383 p_intf->p_sys->p_theme->EvtBank->Get( type ), (int)state );
387 OSAPI_PostMessage( NULL, CTRL_SYNCHRO, (unsigned int)
388 p_intf->p_sys->p_theme->EvtBank->Get( type ), (int)false );
391 //---------------------------------------------------------------------------
394 //---------------------------------------------------------------------------
395 // Common VLC procedures
396 //---------------------------------------------------------------------------
397 void VlcProc::LoadSkin()
399 if( p_intf->p_sys->p_new_theme_file == NULL )
401 p_intf->p_sys->p_dialogs->ShowOpenSkin( 0 /*none blocking*/ );
405 // Place a new theme in the global structure, because it will
406 // be filled by the parser
407 // We save the old one to restore it in case of problem
408 Theme *oldTheme = p_intf->p_sys->p_theme;
409 p_intf->p_sys->p_theme = (Theme *)new OSTheme( p_intf );
411 // Run the XML parser
412 ThemeLoader *Loader = new ThemeLoader( p_intf );
413 if( Loader->Load( p_intf->p_sys->p_new_theme_file ) )
415 // Everything went well
416 msg_Dbg( p_intf, "New theme successfully loaded" );
417 delete (OSTheme *)oldTheme;
420 p_intf->p_sys->p_theme->InitTheme();
421 p_intf->p_sys->p_theme->ShowTheme();
425 msg_Warn( p_intf, "A problem occurred when loading the new theme,"
426 " restoring the previous one" );
427 delete (OSTheme *)p_intf->p_sys->p_theme;
428 p_intf->p_sys->p_theme = oldTheme;
431 p_intf->p_sys->p_theme->ShowTheme();
435 // Uninitialize new theme
436 free( p_intf->p_sys->p_new_theme_file );
437 p_intf->p_sys->p_new_theme_file = NULL;
439 OSAPI_PostMessage( NULL, VLC_INTF_REFRESH, 0, (int)true );
442 //---------------------------------------------------------------------------
444 void VlcProc::DropFile( unsigned int param1, long param2 )
446 // Get pointer to file
447 char *FileName = (char *)param1;
449 // Add the new file to the playlist
450 if( p_intf->p_sys->p_playlist != NULL )
455 playlist_Add( p_intf->p_sys->p_playlist, FileName, FileName,
456 PLAYLIST_APPEND, PLAYLIST_END );
460 // Enqueue and play the item
461 playlist_Add( p_intf->p_sys->p_playlist, FileName, FileName,
462 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
466 // VLC_DROP must be called with a pointer to a char else it will
467 // ******** SEGFAULT ********
468 // The delete is here because the processus in asynchronous
474 //---------------------------------------------------------------------------
479 //---------------------------------------------------------------------------
481 //---------------------------------------------------------------------------
482 void VlcProc::PauseStream()
484 if( p_intf->p_sys->p_playlist == NULL )
487 playlist_Command( p_intf->p_sys->p_playlist, PLAYLIST_PAUSE, 0 );
492 //---------------------------------------------------------------------------
493 void VlcProc::PlayStream()
495 if( p_intf->p_sys->p_playlist == NULL )
498 if( !p_intf->p_sys->p_playlist->i_size )
500 p_intf->p_sys->p_dialogs->ShowOpen( true );
505 playlist_Play( p_intf->p_sys->p_playlist );
510 //---------------------------------------------------------------------------
511 void VlcProc::StopStream()
513 if( p_intf->p_sys->p_playlist == NULL )
515 playlist_Stop( p_intf->p_sys->p_playlist );
520 //---------------------------------------------------------------------------
521 void VlcProc::NextStream()
523 if( p_intf->p_sys->p_playlist == NULL )
526 playlist_Next( p_intf->p_sys->p_playlist );
531 //---------------------------------------------------------------------------
532 void VlcProc::PrevStream()
534 if( p_intf->p_sys->p_playlist == NULL )
537 playlist_Prev( p_intf->p_sys->p_playlist );
542 //---------------------------------------------------------------------------
543 void VlcProc::SlowStream()
545 input_thread_t *p_input =
546 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
550 vlc_value_t val; val.b_bool = VLC_TRUE;
552 var_Set( p_input, "rate-slower", val );
553 vlc_object_release( p_input );
556 //---------------------------------------------------------------------------
557 void VlcProc::FastStream()
559 input_thread_t *p_input =
560 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
564 vlc_value_t val; val.b_bool = VLC_TRUE;
566 var_Set( p_input, "rate-faster", val );
567 vlc_object_release( p_input );
570 //---------------------------------------------------------------------------
571 void VlcProc::MoveStream( long Pos )
573 if( p_intf->p_sys->p_input == NULL )
576 var_SetFloat( p_intf->p_input, "position", (double)Pos / SLIDER_RANGE );
581 //---------------------------------------------------------------------------
585 //---------------------------------------------------------------------------
587 //---------------------------------------------------------------------------
588 void VlcProc::FullScreen()
590 vout_thread_t *p_vout;
592 if( p_intf->p_sys->p_input == NULL )
595 p_vout = (vout_thread_t *)vlc_object_find( p_intf->p_sys->p_input,
596 VLC_OBJECT_VOUT, FIND_CHILD );
600 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
601 vlc_object_release( p_vout );
603 //---------------------------------------------------------------------------
607 //---------------------------------------------------------------------------
609 //---------------------------------------------------------------------------
610 void VlcProc::ChangeVolume( unsigned int msg, long param )
612 audio_volume_t volume;
615 case VLC_VOLUME_MUTE:
616 aout_VolumeMute( p_intf, NULL );
619 aout_VolumeUp( p_intf, 1, NULL );
621 case VLC_VOLUME_DOWN:
622 aout_VolumeDown( p_intf, 1, NULL );
625 aout_VolumeSet( p_intf, param * (AOUT_VOLUME_DEFAULT * 2) /
629 aout_VolumeGet( p_intf, &volume );
631 //---------------------------------------------------------------------------