1 /*****************************************************************************
2 * vlcproc.cpp: VlcProc class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: vlcproc.cpp,v 1.4 2003/04/11 22:08:06 videolan 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();
158 AddNetworkUDP( (int)evt->GetParam2() );
165 //---------------------------------------------------------------------------
166 bool VlcProc::EventProcEnd()
168 if( p_intf->p_sys->b_all_win_closed )
171 list<Window *>::const_iterator win;
173 // If a window has been closed, test if all are closed !
174 for( win = p_intf->p_sys->p_theme->WindowList.begin();
175 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
177 if( !(*win)->IsHidden() ) // Not all windows closed
183 // All window are closed
184 switch( p_intf->p_sys->i_close_status )
187 // Save config before exiting
188 p_intf->p_sys->p_theme->SaveConfig();
192 // Send specified event
193 OSAPI_PostMessage( NULL, p_intf->p_sys->i_close_status, 0, 0 );
196 p_intf->p_sys->i_close_status = VLC_NOTHING;
197 p_intf->p_sys->b_all_win_closed = true;
202 //---------------------------------------------------------------------------
203 bool VlcProc::IsClosing()
205 if( p_intf->b_die && p_intf->p_sys->i_close_status != VLC_QUIT )
207 p_intf->p_sys->i_close_status = VLC_QUIT;
208 OSAPI_PostMessage( NULL, VLC_HIDE, VLC_QUIT, 0 );
212 //---------------------------------------------------------------------------
217 //---------------------------------------------------------------------------
219 //---------------------------------------------------------------------------
220 void VlcProc::InterfaceRefresh( bool All )
223 intf_sys_t *Sys = p_intf->p_sys;
224 Theme *Thema = Sys->p_theme;
225 playlist_t *PlayList = Sys->p_playlist;
229 if( PlayList != NULL && Sys->p_input != NULL &&
230 Sys->p_input->stream.b_seekable )
232 // Refresh stream control controls ! :)
233 switch( PlayList->i_status )
235 case PLAYLIST_STOPPED:
236 EnabledEvent( "time", false );
237 EnabledEvent( "stop", false );
238 EnabledEvent( "play", true );
239 EnabledEvent( "pause", false );
241 case PLAYLIST_RUNNING:
242 EnabledEvent( "time", true );
243 EnabledEvent( "stop", true );
244 EnabledEvent( "play", false );
245 EnabledEvent( "pause", true );
247 case PLAYLIST_PAUSED:
248 EnabledEvent( "time", true );
249 EnabledEvent( "stop", true );
250 EnabledEvent( "play", true );
251 EnabledEvent( "pause", false );
255 // Refresh next and prev buttons
256 if( PlayList->i_index == 0 || PlayList->i_size == 1 )
257 EnabledEvent( "prev", false );
259 EnabledEvent( "prev", true );
261 if( PlayList->i_index == PlayList->i_size - 1 || PlayList->i_size == 1 )
262 EnabledEvent( "next", false );
264 EnabledEvent( "next", true );
267 // Update file name text
268 if( PlayList->i_index != Sys->i_index )
270 Thema->EvtBank->Get( "file_name" )->PostTextMessage(
271 PlayList->pp_items[PlayList->i_index]->psz_name );
275 if( PlayList->i_index != Sys->i_index ||
276 PlayList->i_size != Sys->i_size )
278 Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
279 Sys->i_size = PlayList->i_size;
280 Sys->i_index = PlayList->i_index;
285 EnabledEvent( "time", false );
286 EnabledEvent( "stop", false );
287 EnabledEvent( "play", false );
288 EnabledEvent( "pause", false );
289 EnabledEvent( "prev", false );
290 EnabledEvent( "next", false );
293 if( Sys->i_size > 0 )
295 Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
301 //---------------------------------------------------------------------------
302 void VlcProc::EnabledEvent( string type, bool state )
304 OSAPI_PostMessage( NULL, CTRL_ENABLED, (unsigned int)
305 p_intf->p_sys->p_theme->EvtBank->Get( type ), (int)state );
307 //---------------------------------------------------------------------------
311 //---------------------------------------------------------------------------
312 // Common VLC procedures
313 //---------------------------------------------------------------------------
314 void VlcProc::LoadSkin()
316 if( p_intf->p_sys->p_new_theme_file == NULL )
318 // Initialize file structure
319 OpenFileDialog *OpenFile;
320 OpenFile = (OpenFileDialog *)new OSOpenFileDialog( p_intf,
321 _("Change skin - Open new file"), false );
322 OpenFile->AddFilter( _("Skin files"), "*.vlt" );
323 OpenFile->AddFilter( _("Skin files"), "*.xml" );
324 OpenFile->AddFilter( _("All files"), "*.*" );
327 if( OpenFile->Open() )
329 p_intf->p_sys->p_new_theme_file =
330 new char[OpenFile->FileList.front().length()];
332 strcpy( p_intf->p_sys->p_new_theme_file,
333 OpenFile->FileList.front().c_str() );
335 // Tell vlc to change skin after hiding interface
336 OSAPI_PostMessage( NULL, VLC_HIDE, VLC_LOAD_SKIN, 0 );
344 // Place a new theme in the global structure, because it will
345 // be filled by the parser
346 // We save the old one to restore it in case of problem
347 Theme *oldTheme = p_intf->p_sys->p_theme;
348 p_intf->p_sys->p_theme = (Theme *)new OSTheme( p_intf );
350 // Run the XML parser
351 ThemeLoader *Loader = new ThemeLoader( p_intf );
352 if( Loader->Load( p_intf->p_sys->p_new_theme_file ) )
354 // Everything went well
355 msg_Dbg( p_intf, "New theme successfully loaded" );
356 delete (OSTheme *)oldTheme;
359 p_intf->p_sys->p_theme->InitTheme();
360 p_intf->p_sys->p_theme->ShowTheme();
364 msg_Warn( p_intf, "A problem occurred when loading the new theme,"
365 " restoring the previous one" );
366 delete (OSTheme *)p_intf->p_sys->p_theme;
367 p_intf->p_sys->p_theme = oldTheme;
370 p_intf->p_sys->p_theme->ShowTheme();
374 // Uninitialize new theme
375 delete (char *)p_intf->p_sys->p_new_theme_file;
376 p_intf->p_sys->p_new_theme_file = NULL;
379 //---------------------------------------------------------------------------
380 void VlcProc::OpenFile( bool play )
382 // Initialize file structure
383 OpenFileDialog *OpenFile;
386 OpenFile = (OpenFileDialog *)new OSOpenFileDialog( p_intf,
387 _("Open file"), false );
391 OpenFile = (OpenFileDialog *)new OSOpenFileDialog( p_intf,
392 _("Add file"), true );
394 OpenFile->AddFilter( _("All files"), "*.*" );
396 // Check if palylist is available
397 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
398 if( p_playlist == NULL )
401 // Open dialog box and launch file
402 if( OpenFile->Open() )
404 list<string>::const_iterator file;
405 for( file = OpenFile->FileList.begin();
406 file != OpenFile->FileList.end(); file++ )
408 playlist_Add( p_playlist, (*file).c_str(), PLAYLIST_APPEND,
416 p_intf->p_sys->p_theme->EvtBank->Get( "play" )->SendEvent();
419 // Refresh interface !
420 p_intf->p_sys->p_theme->EvtBank->Get( "playlist_refresh" )
421 ->PostSynchroMessage();
428 //---------------------------------------------------------------------------
429 void VlcProc::DropFile( unsigned int param )
431 // Get pointer to file
432 char *FileName = (char *)param;
434 // Add the new file to the playlist
435 if( p_intf->p_sys->p_playlist != NULL )
437 if( config_GetInt( p_intf, "enqueue" ) )
439 playlist_Add( p_intf->p_sys->p_playlist, FileName,
440 PLAYLIST_APPEND, PLAYLIST_END );
444 playlist_Add( p_intf->p_sys->p_playlist, FileName,
445 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
449 // VLC_DROP must be called with a pointer to a char else it will
450 // ******** SEGFAULT ********
451 // The delete is here because the processus in asynchronous
458 //---------------------------------------------------------------------------
463 //---------------------------------------------------------------------------
465 //---------------------------------------------------------------------------
466 void VlcProc::PauseStream()
468 if( p_intf->p_sys->p_input == NULL )
470 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
475 //---------------------------------------------------------------------------
476 void VlcProc::PlayStream()
478 if( p_intf->p_sys->p_playlist == NULL )
480 if( !p_intf->p_sys->p_playlist->i_size )
483 playlist_Play( p_intf->p_sys->p_playlist );
488 //---------------------------------------------------------------------------
489 void VlcProc::StopStream()
491 if( p_intf->p_sys->p_playlist == NULL )
493 playlist_Stop( p_intf->p_sys->p_playlist );
498 //---------------------------------------------------------------------------
499 void VlcProc::NextStream()
501 if( p_intf->p_sys->p_playlist == NULL )
504 playlist_Next( p_intf->p_sys->p_playlist );
509 //---------------------------------------------------------------------------
510 void VlcProc::PrevStream()
512 if( p_intf->p_sys->p_playlist == NULL )
515 playlist_Prev( p_intf->p_sys->p_playlist );
520 //---------------------------------------------------------------------------
521 void VlcProc::MoveStream( long Pos )
523 if( p_intf->p_sys->p_input == NULL )
526 off_t i_seek = (off_t)(Pos *
527 p_intf->p_sys->p_input->stream.p_selected_area->i_size
530 input_Seek( p_intf->p_sys->p_input, i_seek, INPUT_SEEK_SET );
535 //---------------------------------------------------------------------------
539 //---------------------------------------------------------------------------
541 //---------------------------------------------------------------------------
542 void VlcProc::FullScreen()
544 vout_thread_t *p_vout;
546 if( p_intf->p_sys->p_input == NULL )
549 p_vout = (vout_thread_t *)vlc_object_find( p_intf->p_sys->p_input,
550 VLC_OBJECT_VOUT, FIND_CHILD );
554 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
555 vlc_object_release( p_vout );
557 //---------------------------------------------------------------------------
561 //---------------------------------------------------------------------------
563 //---------------------------------------------------------------------------
564 void VlcProc::ChangeVolume( unsigned int msg, long param )
566 audio_volume_t volume;
569 case VLC_VOLUME_MUTE:
570 aout_VolumeMute( p_intf, NULL );
573 aout_VolumeUp( p_intf, 1, NULL );
575 case VLC_VOLUME_DOWN:
576 aout_VolumeDown( p_intf, 1, NULL );
579 aout_VolumeSet( p_intf, param * AOUT_VOLUME_MAX / SLIDER_RANGE );
582 aout_VolumeGet( p_intf, &volume );
584 PostMessage( NULL, CTRL_SET_SLIDER,
586 p_intf->p_sys->p_theme->EvtBank->Get( "volume_refresh" ),
587 (int)( volume * SLIDER_RANGE / AOUT_VOLUME_MAX ) );
589 //---------------------------------------------------------------------------
592 //---------------------------------------------------------------------------
594 //---------------------------------------------------------------------------
595 void VlcProc::AddNetworkUDP( int port )
597 config_PutInt( p_intf, "network-channel", FALSE );
600 char *s_port = new char[5];
601 sprintf( s_port, "%i", port );
602 string source = "udp:@:" + (string)s_port;
605 playlist_Add( p_intf->p_sys->p_playlist, (char *)source.c_str(),
606 PLAYLIST_APPEND, PLAYLIST_END );
608 // Refresh interface !
609 p_intf->p_sys->p_theme->EvtBank->Get( "playlist_refresh" )
610 ->PostSynchroMessage();
613 //---------------------------------------------------------------------------