1 /*****************************************************************************
2 * vlcproc.cpp: VlcProc class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: vlcproc.cpp,v 1.35 2003/06/11 10:42:34 gbazin 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 // Update file name text
274 if( PlayList->i_index != Sys->i_index )
276 Thema->EvtBank->Get( "file_name" )->PostTextMessage(
277 PlayList->pp_items[PlayList->i_index]->psz_name );
281 if( PlayList->i_index != Sys->i_index ||
282 PlayList->i_size != Sys->i_size )
284 Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
285 Sys->i_size = PlayList->i_size;
286 Sys->i_index = PlayList->i_index;
291 EnabledEvent( "time", false );
292 EnabledEvent( "stop", false );
293 EnabledEvent( "play", false );
294 EnabledEvent( "pause", false );
295 EnabledEvent( "prev", false );
296 EnabledEvent( "next", false );
299 if( Sys->i_size > 0 )
301 Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
307 //---------------------------------------------------------------------------
308 void VlcProc::EnabledEvent( string type, bool state )
310 OSAPI_PostMessage( NULL, CTRL_ENABLED, (unsigned int)
311 p_intf->p_sys->p_theme->EvtBank->Get( type ), (int)state );
313 //---------------------------------------------------------------------------
316 //---------------------------------------------------------------------------
317 // Common VLC procedures
318 //---------------------------------------------------------------------------
319 void VlcProc::LoadSkin()
321 if( p_intf->p_sys->p_new_theme_file == NULL )
323 p_intf->p_sys->p_dialogs->ShowOpenSkin();
327 // Place a new theme in the global structure, because it will
328 // be filled by the parser
329 // We save the old one to restore it in case of problem
330 Theme *oldTheme = p_intf->p_sys->p_theme;
331 p_intf->p_sys->p_theme = (Theme *)new OSTheme( p_intf );
333 // Run the XML parser
334 ThemeLoader *Loader = new ThemeLoader( p_intf );
335 if( Loader->Load( p_intf->p_sys->p_new_theme_file ) )
337 // Everything went well
338 msg_Dbg( p_intf, "New theme successfully loaded" );
339 delete (OSTheme *)oldTheme;
342 p_intf->p_sys->p_theme->InitTheme();
343 p_intf->p_sys->p_theme->ShowTheme();
347 msg_Warn( p_intf, "A problem occurred when loading the new theme,"
348 " restoring the previous one" );
349 delete (OSTheme *)p_intf->p_sys->p_theme;
350 p_intf->p_sys->p_theme = oldTheme;
353 p_intf->p_sys->p_theme->ShowTheme();
357 // Uninitialize new theme
358 delete (char *)p_intf->p_sys->p_new_theme_file;
359 p_intf->p_sys->p_new_theme_file = NULL;
362 //---------------------------------------------------------------------------
364 void VlcProc::DropFile( unsigned int param )
366 // Get pointer to file
367 char *FileName = (char *)param;
369 // Add the new file to the playlist
370 if( p_intf->p_sys->p_playlist != NULL )
372 if( config_GetInt( p_intf, "enqueue" ) )
374 playlist_Add( p_intf->p_sys->p_playlist, FileName,
375 PLAYLIST_APPEND, PLAYLIST_END );
379 playlist_Add( p_intf->p_sys->p_playlist, FileName,
380 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
384 // VLC_DROP must be called with a pointer to a char else it will
385 // ******** SEGFAULT ********
386 // The delete is here because the processus in asynchronous
393 //---------------------------------------------------------------------------
398 //---------------------------------------------------------------------------
400 //---------------------------------------------------------------------------
401 void VlcProc::PauseStream()
403 if( p_intf->p_sys->p_input == NULL )
405 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
410 //---------------------------------------------------------------------------
411 void VlcProc::PlayStream()
413 if( p_intf->p_sys->p_playlist == NULL )
416 if( !p_intf->p_sys->p_playlist->i_size )
418 p_intf->p_sys->p_dialogs->ShowOpen( true );
423 playlist_Play( p_intf->p_sys->p_playlist );
428 //---------------------------------------------------------------------------
429 void VlcProc::StopStream()
431 if( p_intf->p_sys->p_playlist == NULL )
433 playlist_Stop( p_intf->p_sys->p_playlist );
438 //---------------------------------------------------------------------------
439 void VlcProc::NextStream()
441 if( p_intf->p_sys->p_playlist == NULL )
444 playlist_Next( p_intf->p_sys->p_playlist );
449 //---------------------------------------------------------------------------
450 void VlcProc::PrevStream()
452 if( p_intf->p_sys->p_playlist == NULL )
455 playlist_Prev( p_intf->p_sys->p_playlist );
460 //---------------------------------------------------------------------------
461 void VlcProc::MoveStream( long Pos )
463 if( p_intf->p_sys->p_input == NULL )
466 off_t i_seek = (off_t)(Pos *
467 p_intf->p_sys->p_input->stream.p_selected_area->i_size
470 input_Seek( p_intf->p_sys->p_input, i_seek, INPUT_SEEK_SET );
475 //---------------------------------------------------------------------------
479 //---------------------------------------------------------------------------
481 //---------------------------------------------------------------------------
482 void VlcProc::FullScreen()
484 vout_thread_t *p_vout;
486 if( p_intf->p_sys->p_input == NULL )
489 p_vout = (vout_thread_t *)vlc_object_find( p_intf->p_sys->p_input,
490 VLC_OBJECT_VOUT, FIND_CHILD );
494 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
495 vlc_object_release( p_vout );
497 //---------------------------------------------------------------------------
501 //---------------------------------------------------------------------------
503 //---------------------------------------------------------------------------
504 void VlcProc::ChangeVolume( unsigned int msg, long param )
506 audio_volume_t volume;
509 case VLC_VOLUME_MUTE:
510 aout_VolumeMute( p_intf, NULL );
513 aout_VolumeUp( p_intf, 1, NULL );
515 case VLC_VOLUME_DOWN:
516 aout_VolumeDown( p_intf, 1, NULL );
519 aout_VolumeSet( p_intf, param * AOUT_VOLUME_MAX / SLIDER_RANGE );
522 aout_VolumeGet( p_intf, &volume );
525 //---------------------------------------------------------------------------
528 //---------------------------------------------------------------------------
530 //---------------------------------------------------------------------------
531 void VlcProc::AddNetworkUDP( int port )
534 char *s_port = new char[5];
535 sprintf( s_port, "%i", port );
536 string source = "udp:@:" + (string)s_port;
539 playlist_Add( p_intf->p_sys->p_playlist, (char *)source.c_str(),
540 PLAYLIST_APPEND, PLAYLIST_END );
542 // Refresh interface !
543 p_intf->p_sys->p_theme->EvtBank->Get( "playlist_refresh" )
544 ->PostSynchroMessage();
547 //---------------------------------------------------------------------------