1 /*****************************************************************************
2 * vlcproc.cpp: VlcProc class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: vlcproc.cpp,v 1.20 2003/05/05 16:09:40 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 -------------------------------------------------------------------
33 #ifdef WIN32 /* mingw32 hack */
37 /* Let vlc take care of the i18n stuff */
38 #define WXINTL_NO_GETTEXT_MACRO
42 //--- SKIN ------------------------------------------------------------------
43 #include "../os_api.h"
47 #include "../os_theme.h"
48 #include "themeloader.h"
51 #include "skin_common.h"
54 #include "wxdialogs.h"
58 //---------------------------------------------------------------------------
60 //---------------------------------------------------------------------------
61 VlcProc::VlcProc( intf_thread_t *_p_intf )
65 //---------------------------------------------------------------------------
66 bool VlcProc::EventProc( Event *evt )
68 switch( evt->GetMessage() )
71 MoveStream( evt->GetParam2() );
74 case VLC_VOLUME_CHANGE:
75 ChangeVolume( evt->GetParam1(), evt->GetParam2() );
83 for( list<SkinWindow *>::const_iterator win =
84 p_intf->p_sys->p_theme->WindowList.begin();
85 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
87 (*win)->OnStartThemeVisible = !(*win)->IsHidden();
89 p_intf->p_sys->i_close_status = (int)evt->GetParam1();
90 OSAPI_PostMessage( NULL, WINDOW_CLOSE, 1, 0 );
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 if( (*win)->OnStartThemeVisible )
99 OSAPI_PostMessage( (*win), WINDOW_OPEN, 1, 0 );
101 p_intf->p_sys->b_all_win_closed = false;
113 DropFile( evt->GetParam1() );
136 case VLC_PLAYLIST_ADD_FILE:
142 p_intf->p_sys->MessagesDlg->Show(
143 !p_intf->p_sys->MessagesDlg->IsShown() );
150 p_intf->p_sys->PrefsDlg->Show(
151 !p_intf->p_sys->PrefsDlg->IsShown() );
155 p_intf->p_sys->InfoDlg->Show(
156 !p_intf->p_sys->InfoDlg->IsShown() );
160 case VLC_INTF_REFRESH:
161 InterfaceRefresh( (bool)evt->GetParam2() );
164 case VLC_TEST_ALL_CLOSED:
165 return EventProcEnd();
170 case VLC_CHANGE_TRAY:
171 p_intf->p_sys->p_theme->ChangeTray();
174 case VLC_CHANGE_TASKBAR:
175 p_intf->p_sys->p_theme->ChangeTaskbar();
179 AddNetworkUDP( (int)evt->GetParam2() );
186 //---------------------------------------------------------------------------
187 bool VlcProc::EventProcEnd()
189 if( p_intf->p_sys->b_all_win_closed )
192 list<SkinWindow *>::const_iterator win;
194 // If a window has been closed, test if all are closed !
195 for( win = p_intf->p_sys->p_theme->WindowList.begin();
196 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
198 if( !(*win)->IsHidden() ) // Not all windows closed
204 // All window are closed
205 switch( p_intf->p_sys->i_close_status )
208 // Save config before exiting
209 p_intf->p_sys->p_theme->SaveConfig();
213 // Send specified event
214 OSAPI_PostMessage( NULL, p_intf->p_sys->i_close_status, 0, 0 );
217 p_intf->p_sys->i_close_status = VLC_NOTHING;
218 p_intf->p_sys->b_all_win_closed = true;
223 //---------------------------------------------------------------------------
224 bool VlcProc::IsClosing()
226 if( p_intf->b_die && p_intf->p_sys->i_close_status != VLC_QUIT )
228 p_intf->p_sys->i_close_status = VLC_QUIT;
229 OSAPI_PostMessage( NULL, VLC_HIDE, VLC_QUIT, 0 );
233 //---------------------------------------------------------------------------
238 //---------------------------------------------------------------------------
240 //---------------------------------------------------------------------------
241 void VlcProc::InterfaceRefresh( bool All )
244 intf_sys_t *Sys = p_intf->p_sys;
245 Theme *Thema = Sys->p_theme;
246 playlist_t *PlayList = Sys->p_playlist;
249 if( PlayList != NULL )
251 // Refresh stream control controls ! :)
252 switch( PlayList->i_status )
254 case PLAYLIST_STOPPED:
255 EnabledEvent( "time", false );
256 EnabledEvent( "stop", false );
257 EnabledEvent( "play", true );
258 EnabledEvent( "pause", false );
260 case PLAYLIST_RUNNING:
261 EnabledEvent( "time", true );
262 EnabledEvent( "stop", true );
263 EnabledEvent( "play", false );
264 EnabledEvent( "pause", true );
266 case PLAYLIST_PAUSED:
267 EnabledEvent( "time", true );
268 EnabledEvent( "stop", true );
269 EnabledEvent( "play", true );
270 EnabledEvent( "pause", false );
274 // Refresh next and prev buttons
275 if( PlayList->i_index == 0 || PlayList->i_size == 1 )
276 EnabledEvent( "prev", false );
278 EnabledEvent( "prev", true );
280 if( PlayList->i_index == PlayList->i_size - 1 || PlayList->i_size == 1 )
281 EnabledEvent( "next", false );
283 EnabledEvent( "next", true );
286 // Update file name text
287 if( PlayList->i_index != Sys->i_index )
289 Thema->EvtBank->Get( "file_name" )->PostTextMessage(
290 PlayList->pp_items[PlayList->i_index]->psz_name );
294 if( PlayList->i_index != Sys->i_index ||
295 PlayList->i_size != Sys->i_size )
297 Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
298 Sys->i_size = PlayList->i_size;
299 Sys->i_index = PlayList->i_index;
304 EnabledEvent( "time", false );
305 EnabledEvent( "stop", false );
306 EnabledEvent( "play", false );
307 EnabledEvent( "pause", false );
308 EnabledEvent( "prev", false );
309 EnabledEvent( "next", false );
312 if( Sys->i_size > 0 )
314 Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
320 //---------------------------------------------------------------------------
321 void VlcProc::EnabledEvent( string type, bool state )
323 OSAPI_PostMessage( NULL, CTRL_ENABLED, (unsigned int)
324 p_intf->p_sys->p_theme->EvtBank->Get( type ), (int)state );
326 //---------------------------------------------------------------------------
330 //---------------------------------------------------------------------------
331 // Common VLC procedures
332 //---------------------------------------------------------------------------
333 void VlcProc::LoadSkin()
336 if( p_intf->p_sys->p_new_theme_file == NULL )
338 wxFileDialog dialog( NULL, _("Open a skin file"), "", "",
339 "Skin files (*.vlt)|*.vlt|Skin files (*.xml)|*.xml|All files|*.*",
342 if( dialog.ShowModal() == wxID_OK )
344 p_intf->p_sys->p_new_theme_file =
345 new char[dialog.GetPath().Length()];
347 strcpy( p_intf->p_sys->p_new_theme_file,
348 dialog.GetPath().c_str() );
350 // Tell vlc to change skin after hiding interface
351 OSAPI_PostMessage( NULL, VLC_HIDE, VLC_LOAD_SKIN, 0 );
356 // Place a new theme in the global structure, because it will
357 // be filled by the parser
358 // We save the old one to restore it in case of problem
359 Theme *oldTheme = p_intf->p_sys->p_theme;
360 p_intf->p_sys->p_theme = (Theme *)new OSTheme( p_intf );
362 // Run the XML parser
363 ThemeLoader *Loader = new ThemeLoader( p_intf );
364 if( Loader->Load( p_intf->p_sys->p_new_theme_file ) )
366 // Everything went well
367 msg_Dbg( p_intf, "New theme successfully loaded" );
368 delete (OSTheme *)oldTheme;
371 p_intf->p_sys->p_theme->InitTheme();
372 p_intf->p_sys->p_theme->ShowTheme();
376 msg_Warn( p_intf, "A problem occurred when loading the new theme,"
377 " restoring the previous one" );
378 delete (OSTheme *)p_intf->p_sys->p_theme;
379 p_intf->p_sys->p_theme = oldTheme;
382 p_intf->p_sys->p_theme->ShowTheme();
386 // Uninitialize new theme
387 delete (char *)p_intf->p_sys->p_new_theme_file;
388 p_intf->p_sys->p_new_theme_file = NULL;
392 //---------------------------------------------------------------------------
393 void VlcProc::OpenFile( bool play )
396 if( p_intf->p_sys->OpenDlg->ShowModal() != wxID_OK )
401 // Check if playlist is available
402 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
403 if( p_playlist == NULL )
411 playlist_Add( p_playlist,
412 (char *)p_intf->p_sys->OpenDlg->mrl.c_str(),
413 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
415 p_intf->p_sys->p_theme->EvtBank->Get( "play" )->SendEvent();
420 playlist_Add( p_playlist,
421 (char *)p_intf->p_sys->OpenDlg->mrl.c_str(),
422 PLAYLIST_APPEND, PLAYLIST_END );
425 // Refresh interface !
426 p_intf->p_sys->p_theme->EvtBank->Get( "playlist_refresh" )
427 ->PostSynchroMessage();
431 //---------------------------------------------------------------------------
432 void VlcProc::DropFile( unsigned int param )
434 // Get pointer to file
435 char *FileName = (char *)param;
437 // Add the new file to the playlist
438 if( p_intf->p_sys->p_playlist != NULL )
440 if( config_GetInt( p_intf, "enqueue" ) )
442 playlist_Add( p_intf->p_sys->p_playlist, FileName,
443 PLAYLIST_APPEND, PLAYLIST_END );
447 playlist_Add( p_intf->p_sys->p_playlist, FileName,
448 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
452 // VLC_DROP must be called with a pointer to a char else it will
453 // ******** SEGFAULT ********
454 // The delete is here because the processus in asynchronous
461 //---------------------------------------------------------------------------
466 //---------------------------------------------------------------------------
468 //---------------------------------------------------------------------------
469 void VlcProc::PauseStream()
471 if( p_intf->p_sys->p_input == NULL )
473 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
478 //---------------------------------------------------------------------------
479 void VlcProc::PlayStream()
481 if( p_intf->p_sys->p_playlist == NULL )
483 if( !p_intf->p_sys->p_playlist->i_size )
486 playlist_Play( p_intf->p_sys->p_playlist );
491 //---------------------------------------------------------------------------
492 void VlcProc::StopStream()
494 if( p_intf->p_sys->p_playlist == NULL )
496 playlist_Stop( p_intf->p_sys->p_playlist );
501 //---------------------------------------------------------------------------
502 void VlcProc::NextStream()
504 if( p_intf->p_sys->p_playlist == NULL )
507 playlist_Next( p_intf->p_sys->p_playlist );
512 //---------------------------------------------------------------------------
513 void VlcProc::PrevStream()
515 if( p_intf->p_sys->p_playlist == NULL )
518 playlist_Prev( p_intf->p_sys->p_playlist );
523 //---------------------------------------------------------------------------
524 void VlcProc::MoveStream( long Pos )
526 if( p_intf->p_sys->p_input == NULL )
529 off_t i_seek = (off_t)(Pos *
530 p_intf->p_sys->p_input->stream.p_selected_area->i_size
533 input_Seek( p_intf->p_sys->p_input, i_seek, INPUT_SEEK_SET );
538 //---------------------------------------------------------------------------
542 //---------------------------------------------------------------------------
544 //---------------------------------------------------------------------------
545 void VlcProc::FullScreen()
547 vout_thread_t *p_vout;
549 if( p_intf->p_sys->p_input == NULL )
552 p_vout = (vout_thread_t *)vlc_object_find( p_intf->p_sys->p_input,
553 VLC_OBJECT_VOUT, FIND_CHILD );
557 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
558 vlc_object_release( p_vout );
560 //---------------------------------------------------------------------------
564 //---------------------------------------------------------------------------
566 //---------------------------------------------------------------------------
567 void VlcProc::ChangeVolume( unsigned int msg, long param )
569 audio_volume_t volume;
572 case VLC_VOLUME_MUTE:
573 aout_VolumeMute( p_intf, NULL );
576 aout_VolumeUp( p_intf, 1, NULL );
578 case VLC_VOLUME_DOWN:
579 aout_VolumeDown( p_intf, 1, NULL );
582 aout_VolumeSet( p_intf, param * AOUT_VOLUME_MAX / SLIDER_RANGE );
585 aout_VolumeGet( p_intf, &volume );
588 //---------------------------------------------------------------------------
591 //---------------------------------------------------------------------------
593 //---------------------------------------------------------------------------
594 void VlcProc::AddNetworkUDP( int port )
596 config_PutInt( p_intf, "network-channel", VLC_FALSE );
599 char *s_port = new char[5];
600 sprintf( s_port, "%i", port );
601 string source = "udp:@:" + (string)s_port;
604 playlist_Add( p_intf->p_sys->p_playlist, (char *)source.c_str(),
605 PLAYLIST_APPEND, PLAYLIST_END );
607 // Refresh interface !
608 p_intf->p_sys->p_theme->EvtBank->Get( "playlist_refresh" )
609 ->PostSynchroMessage();
612 //---------------------------------------------------------------------------
613 void VlcProc::AddNetworkChannelServer( char *server )
615 char *name = new char[MAX_PARAM_SIZE];
618 // Scan the server address
619 int scan = sscanf( server, "%[^:]:%i", name, &port );
623 msg_Err( p_intf, "Invalid channel server: %s", server );
628 config_PutInt( p_intf, "network-channel", VLC_TRUE );
629 config_PutPsz( p_intf, "channel-server", name );
630 config_PutInt( p_intf, "channel-port", port );
632 if( p_intf->p_vlc->p_channel == NULL )
634 network_ChannelCreate( p_intf );
639 //---------------------------------------------------------------------------