1 /*****************************************************************************
2 * vlcproc.cpp: VlcProc class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: vlcproc.cpp,v 1.3 2003/03/20 09:29:07 karibu 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 *****************************************************************************/
27 //--- VLC -------------------------------------------------------------------
34 //--- SKIN ------------------------------------------------------------------
37 #include "os_dialog.h"
42 #include "themeloader.h"
45 #include "skin_common.h"
49 //---------------------------------------------------------------------------
51 //---------------------------------------------------------------------------
52 VlcProc::VlcProc( intf_thread_t *_p_intf )
56 //---------------------------------------------------------------------------
57 bool VlcProc::EventProc( Event *evt )
59 switch( evt->GetMessage() )
62 MoveStream( evt->GetParam2() );
65 case VLC_VOLUME_CHANGE:
66 ChangeVolume( evt->GetParam1(), evt->GetParam2() );
74 for( list<Window *>::const_iterator win =
75 p_intf->p_sys->p_theme->WindowList.begin();
76 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
78 (*win)->OnStartThemeVisible = !(*win)->IsHidden();
80 p_intf->p_sys->i_close_status = (int)evt->GetParam1();
81 OSAPI_PostMessage( NULL, WINDOW_CLOSE, 1, 0 );
85 for( list<Window *>::const_iterator win =
86 p_intf->p_sys->p_theme->WindowList.begin();
87 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
89 if( (*win)->OnStartThemeVisible )
90 OSAPI_PostMessage( (*win), WINDOW_OPEN, 1, 0 );
92 p_intf->p_sys->b_all_win_closed = false;
104 DropFile( evt->GetParam1() );
127 case VLC_PLAYLIST_ADD_FILE:
132 p_intf->p_sys->p_theme->ShowLog( evt->GetParam2() );
136 p_intf->p_sys->p_theme->ClearLog();
139 case VLC_INTF_REFRESH:
140 InterfaceRefresh( (bool)evt->GetParam2() );
143 case VLC_TEST_ALL_CLOSED:
144 return EventProcEnd();
149 case VLC_CHANGE_TRAY:
150 p_intf->p_sys->p_theme->ChangeTray();
153 case VLC_CHANGE_TASKBAR:
154 p_intf->p_sys->p_theme->ChangeTaskbar();
161 //---------------------------------------------------------------------------
162 bool VlcProc::EventProcEnd()
164 if( p_intf->p_sys->b_all_win_closed )
167 list<Window *>::const_iterator win;
169 // If a window has been closed, test if all are closed !
170 for( win = p_intf->p_sys->p_theme->WindowList.begin();
171 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
173 if( !(*win)->IsHidden() ) // Not all windows closed
179 // All window are closed
180 switch( p_intf->p_sys->i_close_status )
183 // Save config before exiting
184 p_intf->p_sys->p_theme->SaveConfig();
188 // Send specified event
189 OSAPI_PostMessage( NULL, p_intf->p_sys->i_close_status, 0, 0 );
192 p_intf->p_sys->i_close_status = VLC_NOTHING;
193 p_intf->p_sys->b_all_win_closed = true;
198 //---------------------------------------------------------------------------
199 bool VlcProc::IsClosing()
201 if( p_intf->b_die && p_intf->p_sys->i_close_status != VLC_QUIT )
203 p_intf->p_sys->i_close_status = VLC_QUIT;
204 OSAPI_PostMessage( NULL, VLC_HIDE, VLC_QUIT, 0 );
208 //---------------------------------------------------------------------------
213 //---------------------------------------------------------------------------
215 //---------------------------------------------------------------------------
216 void VlcProc::InterfaceRefresh( bool All )
219 intf_sys_t *Sys = p_intf->p_sys;
220 Theme *Thema = Sys->p_theme;
221 playlist_t *PlayList = Sys->p_playlist;
225 if( PlayList != NULL && Sys->p_input != NULL &&
226 Sys->p_input->stream.b_seekable )
228 // Refresh stream control controls ! :)
229 switch( PlayList->i_status )
231 case PLAYLIST_STOPPED:
232 EnabledEvent( "time", false );
233 EnabledEvent( "stop", false );
234 EnabledEvent( "play", true );
235 EnabledEvent( "pause", false );
237 case PLAYLIST_RUNNING:
238 EnabledEvent( "time", true );
239 EnabledEvent( "stop", true );
240 EnabledEvent( "play", false );
241 EnabledEvent( "pause", true );
243 case PLAYLIST_PAUSED:
244 EnabledEvent( "time", true );
245 EnabledEvent( "stop", true );
246 EnabledEvent( "play", true );
247 EnabledEvent( "pause", false );
251 // Refresh next and prev buttons
252 if( PlayList->i_index == 0 || PlayList->i_size == 1 )
253 EnabledEvent( "prev", false );
255 EnabledEvent( "prev", true );
257 if( PlayList->i_index == PlayList->i_size - 1 || PlayList->i_size == 1 )
258 EnabledEvent( "next", false );
260 EnabledEvent( "next", true );
263 // Update file name text
264 if( PlayList->i_index != Sys->i_index )
266 Thema->EvtBank->Get( "file_name" )->PostTextMessage(
267 PlayList->pp_items[PlayList->i_index]->psz_name );
271 if( PlayList->i_index != Sys->i_index ||
272 PlayList->i_size != Sys->i_size )
274 Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
275 Sys->i_size = PlayList->i_size;
276 Sys->i_index = PlayList->i_index;
281 EnabledEvent( "time", false );
282 EnabledEvent( "stop", false );
283 EnabledEvent( "play", false );
284 EnabledEvent( "pause", false );
285 EnabledEvent( "prev", false );
286 EnabledEvent( "next", false );
289 if( Sys->i_size > 0 )
291 Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
297 //---------------------------------------------------------------------------
298 void VlcProc::EnabledEvent( string type, bool state )
300 OSAPI_PostMessage( NULL, CTRL_ENABLED, (unsigned int)
301 p_intf->p_sys->p_theme->EvtBank->Get( type ), (int)state );
303 //---------------------------------------------------------------------------
307 //---------------------------------------------------------------------------
308 // Common VLC procedures
309 //---------------------------------------------------------------------------
310 void VlcProc::LoadSkin()
312 if( p_intf->p_sys->p_new_theme_file == NULL )
314 // Initialize file structure
315 OpenFileDialog *OpenFile;
316 OpenFile = (OpenFileDialog *)new OSOpenFileDialog( p_intf,
317 _("Change skin - Open new file"), false );
318 OpenFile->AddFilter( _("Skin files"), "*.vlt" );
319 OpenFile->AddFilter( _("Skin files"), "*.xml" );
320 OpenFile->AddFilter( _("All files"), "*.*" );
323 if( OpenFile->Open() )
325 p_intf->p_sys->p_new_theme_file =
326 new char[OpenFile->FileList.front().length()];
328 strcpy( p_intf->p_sys->p_new_theme_file,
329 OpenFile->FileList.front().c_str() );
331 // Tell vlc to change skin after hiding interface
332 OSAPI_PostMessage( NULL, VLC_HIDE, VLC_LOAD_SKIN, 0 );
340 // Place a new theme in the global structure, because it will
341 // be filled by the parser
342 // We save the old one to restore it in case of problem
343 Theme *oldTheme = p_intf->p_sys->p_theme;
344 p_intf->p_sys->p_theme = (Theme *)new OSTheme( p_intf );
346 // Run the XML parser
347 ThemeLoader *Loader = new ThemeLoader( p_intf );
348 if( Loader->Load( p_intf->p_sys->p_new_theme_file ) )
350 // Everything went well
351 msg_Dbg( p_intf, "New theme successfully loaded" );
352 delete (OSTheme *)oldTheme;
355 p_intf->p_sys->p_theme->InitTheme();
356 p_intf->p_sys->p_theme->ShowTheme();
360 msg_Warn( p_intf, "A problem occurred when loading the new theme,"
361 " restoring the previous one" );
362 delete (OSTheme *)p_intf->p_sys->p_theme;
363 p_intf->p_sys->p_theme = oldTheme;
366 p_intf->p_sys->p_theme->ShowTheme();
370 // Uninitialize new theme
371 delete (char *)p_intf->p_sys->p_new_theme_file;
372 p_intf->p_sys->p_new_theme_file = NULL;
375 //---------------------------------------------------------------------------
376 void VlcProc::OpenFile( bool play )
378 // Initialize file structure
379 OpenFileDialog *OpenFile;
382 OpenFile = (OpenFileDialog *)new OSOpenFileDialog( p_intf,
383 _("Open file"), false );
387 OpenFile = (OpenFileDialog *)new OSOpenFileDialog( p_intf,
388 _("Add file"), true );
390 OpenFile->AddFilter( _("All files"), "*.*" );
392 // Check if palylist is available
393 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
394 if( p_playlist == NULL )
397 // Open dialog box and launch file
398 if( OpenFile->Open() )
400 list<string>::const_iterator file;
401 for( file = OpenFile->FileList.begin();
402 file != OpenFile->FileList.end(); file++ )
404 playlist_Add( p_playlist, (*file).c_str(), PLAYLIST_APPEND,
412 p_intf->p_sys->p_theme->EvtBank->Get( "play" )->SendEvent();
415 // Refresh interface !
416 p_intf->p_sys->p_theme->EvtBank->Get( "playlist_refresh" )
417 ->PostSynchroMessage();
424 //---------------------------------------------------------------------------
425 void VlcProc::DropFile( unsigned int param )
427 // Get pointer to file
428 char *FileName = (char *)param;
430 // Add the new file to the playlist
431 if( p_intf->p_sys->p_playlist != NULL )
433 if( config_GetInt( p_intf, "enqueue" ) )
435 playlist_Add( p_intf->p_sys->p_playlist, FileName,
436 PLAYLIST_APPEND, PLAYLIST_END );
440 playlist_Add( p_intf->p_sys->p_playlist, FileName,
441 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
445 // VLC_DROP must be called with a pointer to a char else it will
446 // ******** SEGFAULT ********
447 // The delete is here because the processus in asynchronous
454 //---------------------------------------------------------------------------
459 //---------------------------------------------------------------------------
461 //---------------------------------------------------------------------------
462 void VlcProc::PauseStream()
464 if( p_intf->p_sys->p_input == NULL )
466 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
471 //---------------------------------------------------------------------------
472 void VlcProc::PlayStream()
474 if( p_intf->p_sys->p_playlist == NULL )
476 if( !p_intf->p_sys->p_playlist->i_size )
479 playlist_Play( p_intf->p_sys->p_playlist );
484 //---------------------------------------------------------------------------
485 void VlcProc::StopStream()
487 if( p_intf->p_sys->p_playlist == NULL )
489 playlist_Stop( p_intf->p_sys->p_playlist );
494 //---------------------------------------------------------------------------
495 void VlcProc::NextStream()
497 if( p_intf->p_sys->p_playlist == NULL )
500 playlist_Next( p_intf->p_sys->p_playlist );
505 //---------------------------------------------------------------------------
506 void VlcProc::PrevStream()
508 if( p_intf->p_sys->p_playlist == NULL )
511 playlist_Prev( p_intf->p_sys->p_playlist );
516 //---------------------------------------------------------------------------
517 void VlcProc::MoveStream( long Pos )
519 if( p_intf->p_sys->p_input == NULL )
522 off_t i_seek = (off_t)(Pos *
523 p_intf->p_sys->p_input->stream.p_selected_area->i_size
526 input_Seek( p_intf->p_sys->p_input, i_seek, INPUT_SEEK_SET );
531 //---------------------------------------------------------------------------
535 //---------------------------------------------------------------------------
537 //---------------------------------------------------------------------------
538 void VlcProc::FullScreen()
540 vout_thread_t *p_vout;
542 if( p_intf->p_sys->p_input == NULL )
545 p_vout = (vout_thread_t *)vlc_object_find( p_intf->p_sys->p_input,
546 VLC_OBJECT_VOUT, FIND_CHILD );
550 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
551 vlc_object_release( p_vout );
553 //---------------------------------------------------------------------------
557 //---------------------------------------------------------------------------
559 //---------------------------------------------------------------------------
560 void VlcProc::ChangeVolume( unsigned int msg, long param )
562 audio_volume_t volume;
565 case VLC_VOLUME_MUTE:
566 aout_VolumeMute( p_intf, NULL );
569 aout_VolumeUp( p_intf, 1, NULL );
571 case VLC_VOLUME_DOWN:
572 aout_VolumeDown( p_intf, 1, NULL );
575 aout_VolumeSet( p_intf, param * AOUT_VOLUME_MAX / SLIDER_RANGE );
578 aout_VolumeGet( p_intf, &volume );
580 PostMessage( NULL, CTRL_SET_SLIDER,
582 p_intf->p_sys->p_theme->EvtBank->Get( "volume_refresh" ),
583 (int)( volume * SLIDER_RANGE / AOUT_VOLUME_MAX ) );
585 //---------------------------------------------------------------------------