1 /*****************************************************************************
2 * vlcproc.cpp: VlcProc class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: vlcproc.cpp,v 1.40 2003/06/24 22:26:01 asmax Exp $
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 noticed of playlit 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 vlc_object_release( p_playlist );
76 //---------------------------------------------------------------------------
77 bool VlcProc::EventProc( Event *evt )
79 switch( evt->GetMessage() )
82 MoveStream( evt->GetParam2() );
85 case VLC_VOLUME_CHANGE:
86 ChangeVolume( evt->GetParam1(), evt->GetParam2() );
94 for( list<SkinWindow *>::const_iterator win =
95 p_intf->p_sys->p_theme->WindowList.begin();
96 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
98 (*win)->OnStartThemeVisible = !(*win)->IsHidden();
100 p_intf->p_sys->i_close_status = (int)evt->GetParam1();
101 OSAPI_PostMessage( NULL, WINDOW_CLOSE, 1, 0 );
105 for( list<SkinWindow *>::const_iterator win =
106 p_intf->p_sys->p_theme->WindowList.begin();
107 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
109 if( (*win)->OnStartThemeVisible )
110 OSAPI_PostMessage( (*win), WINDOW_OPEN, 1, 0 );
112 p_intf->p_sys->b_all_win_closed = false;
116 p_intf->p_sys->p_dialogs->ShowOpen( true );
125 DropFile( evt->GetParam1() );
148 case VLC_PLAYLIST_ADD_FILE:
149 p_intf->p_sys->p_dialogs->ShowOpen( false );
154 p_intf->p_sys->p_dialogs->ShowMessages();
161 p_intf->p_sys->p_dialogs->ShowPrefs();
165 p_intf->p_sys->p_dialogs->ShowFileInfo();
168 case VLC_INTF_REFRESH:
172 case VLC_TEST_ALL_CLOSED:
173 return EventProcEnd();
178 case VLC_CHANGE_TRAY:
179 p_intf->p_sys->p_theme->ChangeTray();
182 case VLC_CHANGE_TASKBAR:
183 p_intf->p_sys->p_theme->ChangeTaskbar();
187 AddNetworkUDP( (int)evt->GetParam2() );
194 //---------------------------------------------------------------------------
195 bool VlcProc::EventProcEnd()
197 if( p_intf->p_sys->b_all_win_closed )
200 list<SkinWindow *>::const_iterator win;
202 // If a window has been closed, test if all are closed !
203 for( win = p_intf->p_sys->p_theme->WindowList.begin();
204 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
206 if( !(*win)->IsHidden() ) // Not all windows closed
212 // All window are closed
213 switch( p_intf->p_sys->i_close_status )
216 // Save config before exiting
217 p_intf->p_sys->p_theme->SaveConfig();
221 // Send specified event
222 OSAPI_PostMessage( NULL, p_intf->p_sys->i_close_status, 0, 0 );
225 p_intf->p_sys->i_close_status = VLC_NOTHING;
226 p_intf->p_sys->b_all_win_closed = true;
231 //---------------------------------------------------------------------------
232 bool VlcProc::IsClosing()
234 if( p_intf->b_die && p_intf->p_sys->i_close_status != VLC_QUIT )
236 p_intf->p_sys->i_close_status = VLC_QUIT;
237 OSAPI_PostMessage( NULL, VLC_HIDE, VLC_QUIT, 0 );
241 //---------------------------------------------------------------------------
246 //---------------------------------------------------------------------------
248 //---------------------------------------------------------------------------
251 int VlcProc::RefreshCallback( vlc_object_t *p_this, const char *psz_variable,
252 vlc_value_t old_val, vlc_value_t new_val, void *param )
254 ( (VlcProc*)param )->InterfaceRefresh();
258 // Interface show/hide callback
259 int VlcProc::IntfShowCallback( vlc_object_t *p_this, const char *psz_variable,
260 vlc_value_t old_val, vlc_value_t new_val, void *param )
262 if( new_val.b_bool == VLC_TRUE )
264 OSAPI_PostMessage( NULL, VLC_SHOW, 1, 0 );
268 OSAPI_PostMessage( NULL, VLC_HIDE, 1, 0 );
273 void VlcProc::InterfaceRefresh()
276 intf_sys_t *Sys = p_intf->p_sys;
277 Theme *Thema = Sys->p_theme;
278 playlist_t *PlayList = Sys->p_playlist;
281 if( PlayList != NULL )
283 // Refresh stream control controls ! :)
284 switch( PlayList->i_status )
286 case PLAYLIST_STOPPED:
287 EnabledEvent( "time", false );
288 EnabledEvent( "stop", false );
289 EnabledEvent( "play", true );
290 EnabledEvent( "pause", false );
292 case PLAYLIST_RUNNING:
293 EnabledEvent( "time", true );
294 EnabledEvent( "stop", true );
295 EnabledEvent( "play", false );
296 EnabledEvent( "pause", true );
298 case PLAYLIST_PAUSED:
299 EnabledEvent( "time", true );
300 EnabledEvent( "stop", true );
301 EnabledEvent( "play", true );
302 EnabledEvent( "pause", false );
306 // Refresh next and prev buttons
307 if( PlayList->i_index == 0 || PlayList->i_size == 1 )
308 EnabledEvent( "prev", false );
310 EnabledEvent( "prev", true );
312 if( PlayList->i_index == PlayList->i_size - 1 || PlayList->i_size == 1 )
313 EnabledEvent( "next", false );
315 EnabledEvent( "next", true );
318 if( PlayList->i_index != Sys->i_index )
320 string long_name = PlayList->pp_items[PlayList->i_index]->psz_name;
321 int pos = long_name.rfind( DIRECTORY_SEPARATOR, long_name.size() );
323 // Complete file name
324 Thema->EvtBank->Get( "file_name" )->PostTextMessage(
325 PlayList->pp_items[PlayList->i_index]->psz_name );
326 // File name without path
327 Thema->EvtBank->Get( "title" )->PostTextMessage(
328 PlayList->pp_items[PlayList->i_index]->psz_name + pos + 1 );
332 if( PlayList->i_index != Sys->i_index ||
333 PlayList->i_size != Sys->i_size )
335 Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
336 Sys->i_size = PlayList->i_size;
337 Sys->i_index = PlayList->i_index;
342 EnabledEvent( "time", false );
343 EnabledEvent( "stop", false );
344 EnabledEvent( "play", false );
345 EnabledEvent( "pause", false );
346 EnabledEvent( "prev", false );
347 EnabledEvent( "next", false );
350 if( Sys->i_size > 0 )
352 Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
357 //---------------------------------------------------------------------------
358 void VlcProc::EnabledEvent( string type, bool state )
360 OSAPI_PostMessage( NULL, CTRL_ENABLED, (unsigned int)
361 p_intf->p_sys->p_theme->EvtBank->Get( type ), (int)state );
363 //---------------------------------------------------------------------------
366 //---------------------------------------------------------------------------
367 // Common VLC procedures
368 //---------------------------------------------------------------------------
369 void VlcProc::LoadSkin()
371 if( p_intf->p_sys->p_new_theme_file == NULL )
373 p_intf->p_sys->p_dialogs->ShowOpenSkin();
377 // Place a new theme in the global structure, because it will
378 // be filled by the parser
379 // We save the old one to restore it in case of problem
380 Theme *oldTheme = p_intf->p_sys->p_theme;
381 p_intf->p_sys->p_theme = (Theme *)new OSTheme( p_intf );
383 // Run the XML parser
384 ThemeLoader *Loader = new ThemeLoader( p_intf );
385 if( Loader->Load( p_intf->p_sys->p_new_theme_file ) )
387 // Everything went well
388 msg_Dbg( p_intf, "New theme successfully loaded" );
389 delete (OSTheme *)oldTheme;
392 p_intf->p_sys->p_theme->InitTheme();
393 p_intf->p_sys->p_theme->ShowTheme();
397 msg_Warn( p_intf, "A problem occurred when loading the new theme,"
398 " restoring the previous one" );
399 delete (OSTheme *)p_intf->p_sys->p_theme;
400 p_intf->p_sys->p_theme = oldTheme;
403 p_intf->p_sys->p_theme->ShowTheme();
407 // Uninitialize new theme
408 delete[] p_intf->p_sys->p_new_theme_file;
409 p_intf->p_sys->p_new_theme_file = NULL;
412 //---------------------------------------------------------------------------
414 void VlcProc::DropFile( unsigned int param )
416 // Get pointer to file
417 char *FileName = (char *)param;
419 // Add the new file to the playlist
420 if( p_intf->p_sys->p_playlist != NULL )
422 if( config_GetInt( p_intf, "enqueue" ) )
424 playlist_Add( p_intf->p_sys->p_playlist, FileName,
425 PLAYLIST_APPEND, PLAYLIST_END );
429 playlist_Add( p_intf->p_sys->p_playlist, FileName,
430 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
434 // VLC_DROP must be called with a pointer to a char else it will
435 // ******** SEGFAULT ********
436 // The delete is here because the processus in asynchronous
443 //---------------------------------------------------------------------------
448 //---------------------------------------------------------------------------
450 //---------------------------------------------------------------------------
451 void VlcProc::PauseStream()
453 if( p_intf->p_sys->p_input == NULL )
455 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
460 //---------------------------------------------------------------------------
461 void VlcProc::PlayStream()
463 if( p_intf->p_sys->p_playlist == NULL )
466 if( !p_intf->p_sys->p_playlist->i_size )
468 p_intf->p_sys->p_dialogs->ShowOpen( true );
473 playlist_Play( p_intf->p_sys->p_playlist );
478 //---------------------------------------------------------------------------
479 void VlcProc::StopStream()
481 if( p_intf->p_sys->p_playlist == NULL )
483 playlist_Stop( p_intf->p_sys->p_playlist );
488 //---------------------------------------------------------------------------
489 void VlcProc::NextStream()
491 if( p_intf->p_sys->p_playlist == NULL )
494 playlist_Next( p_intf->p_sys->p_playlist );
499 //---------------------------------------------------------------------------
500 void VlcProc::PrevStream()
502 if( p_intf->p_sys->p_playlist == NULL )
505 playlist_Prev( p_intf->p_sys->p_playlist );
510 //---------------------------------------------------------------------------
511 void VlcProc::MoveStream( long Pos )
513 if( p_intf->p_sys->p_input == NULL )
516 off_t i_seek = (off_t)(Pos *
517 p_intf->p_sys->p_input->stream.p_selected_area->i_size
520 input_Seek( p_intf->p_sys->p_input, i_seek, INPUT_SEEK_SET );
525 //---------------------------------------------------------------------------
529 //---------------------------------------------------------------------------
531 //---------------------------------------------------------------------------
532 void VlcProc::FullScreen()
534 vout_thread_t *p_vout;
536 if( p_intf->p_sys->p_input == NULL )
539 p_vout = (vout_thread_t *)vlc_object_find( p_intf->p_sys->p_input,
540 VLC_OBJECT_VOUT, FIND_CHILD );
544 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
545 vlc_object_release( p_vout );
547 //---------------------------------------------------------------------------
551 //---------------------------------------------------------------------------
553 //---------------------------------------------------------------------------
554 void VlcProc::ChangeVolume( unsigned int msg, long param )
556 audio_volume_t volume;
559 case VLC_VOLUME_MUTE:
560 aout_VolumeMute( p_intf, NULL );
563 aout_VolumeUp( p_intf, 1, NULL );
565 case VLC_VOLUME_DOWN:
566 aout_VolumeDown( p_intf, 1, NULL );
569 aout_VolumeSet( p_intf, param * AOUT_VOLUME_MAX / SLIDER_RANGE );
572 aout_VolumeGet( p_intf, &volume );
575 //---------------------------------------------------------------------------
578 //---------------------------------------------------------------------------
580 //---------------------------------------------------------------------------
581 void VlcProc::AddNetworkUDP( int port )
584 char *s_port = new char[5];
585 sprintf( s_port, "%i", port );
586 string source = "udp:@:" + (string)s_port;
589 playlist_Add( p_intf->p_sys->p_playlist, (char *)source.c_str(),
590 PLAYLIST_APPEND, PLAYLIST_END );
592 // Refresh interface !
593 p_intf->p_sys->p_theme->EvtBank->Get( "playlist_refresh" )
594 ->PostSynchroMessage();
597 //---------------------------------------------------------------------------