1 /*****************************************************************************
2 * vlcproc.cpp: VlcProc class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: vlcproc.cpp,v 1.36 2003/06/20 19:50:29 ipkiss 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 //---------------------------------------------------------------------------
55 //---------------------------------------------------------------------------
56 bool VlcProc::EventProc( Event *evt )
58 switch( evt->GetMessage() )
61 MoveStream( evt->GetParam2() );
64 case VLC_VOLUME_CHANGE:
65 ChangeVolume( evt->GetParam1(), evt->GetParam2() );
73 for( list<SkinWindow *>::const_iterator win =
74 p_intf->p_sys->p_theme->WindowList.begin();
75 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
77 (*win)->OnStartThemeVisible = !(*win)->IsHidden();
79 p_intf->p_sys->i_close_status = (int)evt->GetParam1();
80 OSAPI_PostMessage( NULL, WINDOW_CLOSE, 1, 0 );
84 for( list<SkinWindow *>::const_iterator win =
85 p_intf->p_sys->p_theme->WindowList.begin();
86 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
88 if( (*win)->OnStartThemeVisible )
89 OSAPI_PostMessage( (*win), WINDOW_OPEN, 1, 0 );
91 p_intf->p_sys->b_all_win_closed = false;
95 p_intf->p_sys->p_dialogs->ShowOpen( true );
104 DropFile( evt->GetParam1() );
127 case VLC_PLAYLIST_ADD_FILE:
128 p_intf->p_sys->p_dialogs->ShowOpen( false );
133 p_intf->p_sys->p_dialogs->ShowMessages();
140 p_intf->p_sys->p_dialogs->ShowPrefs();
144 p_intf->p_sys->p_dialogs->ShowFileInfo();
147 case VLC_INTF_REFRESH:
148 InterfaceRefresh( (bool)evt->GetParam2() );
151 case VLC_TEST_ALL_CLOSED:
152 return EventProcEnd();
157 case VLC_CHANGE_TRAY:
158 p_intf->p_sys->p_theme->ChangeTray();
161 case VLC_CHANGE_TASKBAR:
162 p_intf->p_sys->p_theme->ChangeTaskbar();
166 AddNetworkUDP( (int)evt->GetParam2() );
173 //---------------------------------------------------------------------------
174 bool VlcProc::EventProcEnd()
176 if( p_intf->p_sys->b_all_win_closed )
179 list<SkinWindow *>::const_iterator win;
181 // If a window has been closed, test if all are closed !
182 for( win = p_intf->p_sys->p_theme->WindowList.begin();
183 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
185 if( !(*win)->IsHidden() ) // Not all windows closed
191 // All window are closed
192 switch( p_intf->p_sys->i_close_status )
195 // Save config before exiting
196 p_intf->p_sys->p_theme->SaveConfig();
200 // Send specified event
201 OSAPI_PostMessage( NULL, p_intf->p_sys->i_close_status, 0, 0 );
204 p_intf->p_sys->i_close_status = VLC_NOTHING;
205 p_intf->p_sys->b_all_win_closed = true;
210 //---------------------------------------------------------------------------
211 bool VlcProc::IsClosing()
213 if( p_intf->b_die && p_intf->p_sys->i_close_status != VLC_QUIT )
215 p_intf->p_sys->i_close_status = VLC_QUIT;
216 OSAPI_PostMessage( NULL, VLC_HIDE, VLC_QUIT, 0 );
220 //---------------------------------------------------------------------------
225 //---------------------------------------------------------------------------
227 //---------------------------------------------------------------------------
228 void VlcProc::InterfaceRefresh( bool All )
231 intf_sys_t *Sys = p_intf->p_sys;
232 Theme *Thema = Sys->p_theme;
233 playlist_t *PlayList = Sys->p_playlist;
236 if( PlayList != NULL )
238 // Refresh stream control controls ! :)
239 switch( PlayList->i_status )
241 case PLAYLIST_STOPPED:
242 EnabledEvent( "time", false );
243 EnabledEvent( "stop", false );
244 EnabledEvent( "play", true );
245 EnabledEvent( "pause", false );
247 case PLAYLIST_RUNNING:
248 EnabledEvent( "time", true );
249 EnabledEvent( "stop", true );
250 EnabledEvent( "play", false );
251 EnabledEvent( "pause", true );
253 case PLAYLIST_PAUSED:
254 EnabledEvent( "time", true );
255 EnabledEvent( "stop", true );
256 EnabledEvent( "play", true );
257 EnabledEvent( "pause", false );
261 // Refresh next and prev buttons
262 if( PlayList->i_index == 0 || PlayList->i_size == 1 )
263 EnabledEvent( "prev", false );
265 EnabledEvent( "prev", true );
267 if( PlayList->i_index == PlayList->i_size - 1 || PlayList->i_size == 1 )
268 EnabledEvent( "next", false );
270 EnabledEvent( "next", true );
273 if( PlayList->i_index != Sys->i_index )
275 string long_name = PlayList->pp_items[PlayList->i_index]->psz_name;
276 int pos = long_name.rfind( DIRECTORY_SEPARATOR, long_name.size() );
278 // Complete file name
279 Thema->EvtBank->Get( "file_name" )->PostTextMessage(
280 PlayList->pp_items[PlayList->i_index]->psz_name );
281 // File name without path
282 Thema->EvtBank->Get( "title" )->PostTextMessage(
283 PlayList->pp_items[PlayList->i_index]->psz_name + pos + 1 );
287 if( PlayList->i_index != Sys->i_index ||
288 PlayList->i_size != Sys->i_size )
290 Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
291 Sys->i_size = PlayList->i_size;
292 Sys->i_index = PlayList->i_index;
297 EnabledEvent( "time", false );
298 EnabledEvent( "stop", false );
299 EnabledEvent( "play", false );
300 EnabledEvent( "pause", false );
301 EnabledEvent( "prev", false );
302 EnabledEvent( "next", false );
305 if( Sys->i_size > 0 )
307 Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
313 //---------------------------------------------------------------------------
314 void VlcProc::EnabledEvent( string type, bool state )
316 OSAPI_PostMessage( NULL, CTRL_ENABLED, (unsigned int)
317 p_intf->p_sys->p_theme->EvtBank->Get( type ), (int)state );
319 //---------------------------------------------------------------------------
322 //---------------------------------------------------------------------------
323 // Common VLC procedures
324 //---------------------------------------------------------------------------
325 void VlcProc::LoadSkin()
327 if( p_intf->p_sys->p_new_theme_file == NULL )
329 p_intf->p_sys->p_dialogs->ShowOpenSkin();
333 // Place a new theme in the global structure, because it will
334 // be filled by the parser
335 // We save the old one to restore it in case of problem
336 Theme *oldTheme = p_intf->p_sys->p_theme;
337 p_intf->p_sys->p_theme = (Theme *)new OSTheme( p_intf );
339 // Run the XML parser
340 ThemeLoader *Loader = new ThemeLoader( p_intf );
341 if( Loader->Load( p_intf->p_sys->p_new_theme_file ) )
343 // Everything went well
344 msg_Dbg( p_intf, "New theme successfully loaded" );
345 delete (OSTheme *)oldTheme;
348 p_intf->p_sys->p_theme->InitTheme();
349 p_intf->p_sys->p_theme->ShowTheme();
353 msg_Warn( p_intf, "A problem occurred when loading the new theme,"
354 " restoring the previous one" );
355 delete (OSTheme *)p_intf->p_sys->p_theme;
356 p_intf->p_sys->p_theme = oldTheme;
359 p_intf->p_sys->p_theme->ShowTheme();
363 // Uninitialize new theme
364 delete (char *)p_intf->p_sys->p_new_theme_file;
365 p_intf->p_sys->p_new_theme_file = NULL;
368 //---------------------------------------------------------------------------
370 void VlcProc::DropFile( unsigned int param )
372 // Get pointer to file
373 char *FileName = (char *)param;
375 // Add the new file to the playlist
376 if( p_intf->p_sys->p_playlist != NULL )
378 if( config_GetInt( p_intf, "enqueue" ) )
380 playlist_Add( p_intf->p_sys->p_playlist, FileName,
381 PLAYLIST_APPEND, PLAYLIST_END );
385 playlist_Add( p_intf->p_sys->p_playlist, FileName,
386 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
390 // VLC_DROP must be called with a pointer to a char else it will
391 // ******** SEGFAULT ********
392 // The delete is here because the processus in asynchronous
399 //---------------------------------------------------------------------------
404 //---------------------------------------------------------------------------
406 //---------------------------------------------------------------------------
407 void VlcProc::PauseStream()
409 if( p_intf->p_sys->p_input == NULL )
411 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
416 //---------------------------------------------------------------------------
417 void VlcProc::PlayStream()
419 if( p_intf->p_sys->p_playlist == NULL )
422 if( !p_intf->p_sys->p_playlist->i_size )
424 p_intf->p_sys->p_dialogs->ShowOpen( true );
429 playlist_Play( p_intf->p_sys->p_playlist );
434 //---------------------------------------------------------------------------
435 void VlcProc::StopStream()
437 if( p_intf->p_sys->p_playlist == NULL )
439 playlist_Stop( p_intf->p_sys->p_playlist );
444 //---------------------------------------------------------------------------
445 void VlcProc::NextStream()
447 if( p_intf->p_sys->p_playlist == NULL )
450 playlist_Next( p_intf->p_sys->p_playlist );
455 //---------------------------------------------------------------------------
456 void VlcProc::PrevStream()
458 if( p_intf->p_sys->p_playlist == NULL )
461 playlist_Prev( p_intf->p_sys->p_playlist );
466 //---------------------------------------------------------------------------
467 void VlcProc::MoveStream( long Pos )
469 if( p_intf->p_sys->p_input == NULL )
472 off_t i_seek = (off_t)(Pos *
473 p_intf->p_sys->p_input->stream.p_selected_area->i_size
476 input_Seek( p_intf->p_sys->p_input, i_seek, INPUT_SEEK_SET );
481 //---------------------------------------------------------------------------
485 //---------------------------------------------------------------------------
487 //---------------------------------------------------------------------------
488 void VlcProc::FullScreen()
490 vout_thread_t *p_vout;
492 if( p_intf->p_sys->p_input == NULL )
495 p_vout = (vout_thread_t *)vlc_object_find( p_intf->p_sys->p_input,
496 VLC_OBJECT_VOUT, FIND_CHILD );
500 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
501 vlc_object_release( p_vout );
503 //---------------------------------------------------------------------------
507 //---------------------------------------------------------------------------
509 //---------------------------------------------------------------------------
510 void VlcProc::ChangeVolume( unsigned int msg, long param )
512 audio_volume_t volume;
515 case VLC_VOLUME_MUTE:
516 aout_VolumeMute( p_intf, NULL );
519 aout_VolumeUp( p_intf, 1, NULL );
521 case VLC_VOLUME_DOWN:
522 aout_VolumeDown( p_intf, 1, NULL );
525 aout_VolumeSet( p_intf, param * AOUT_VOLUME_MAX / SLIDER_RANGE );
528 aout_VolumeGet( p_intf, &volume );
531 //---------------------------------------------------------------------------
534 //---------------------------------------------------------------------------
536 //---------------------------------------------------------------------------
537 void VlcProc::AddNetworkUDP( int port )
540 char *s_port = new char[5];
541 sprintf( s_port, "%i", port );
542 string source = "udp:@:" + (string)s_port;
545 playlist_Add( p_intf->p_sys->p_playlist, (char *)source.c_str(),
546 PLAYLIST_APPEND, PLAYLIST_END );
548 // Refresh interface !
549 p_intf->p_sys->p_theme->EvtBank->Get( "playlist_refresh" )
550 ->PostSynchroMessage();
553 //---------------------------------------------------------------------------