1 /*****************************************************************************
2 * vlcproc.cpp: VlcProc class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: vlcproc.cpp,v 1.33 2003/06/09 12:33:16 asmax 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 //---------------------------------------------------------------------------
56 //---------------------------------------------------------------------------
57 VlcProc::VlcProc( intf_thread_t *_p_intf )
61 //---------------------------------------------------------------------------
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;
106 p_intf->p_sys->p_dialogs->ShowOpen( true );
116 DropFile( evt->GetParam1() );
139 case VLC_PLAYLIST_ADD_FILE:
141 p_intf->p_sys->p_dialogs->ShowOpen( false );
148 p_intf->p_sys->p_dialogs->ShowMessages();
157 p_intf->p_sys->p_dialogs->ShowPrefs();
163 p_intf->p_sys->p_dialogs->ShowFileInfo();
167 case VLC_INTF_REFRESH:
168 InterfaceRefresh( (bool)evt->GetParam2() );
171 case VLC_TEST_ALL_CLOSED:
172 return EventProcEnd();
177 case VLC_CHANGE_TRAY:
178 p_intf->p_sys->p_theme->ChangeTray();
181 case VLC_CHANGE_TASKBAR:
182 p_intf->p_sys->p_theme->ChangeTaskbar();
186 AddNetworkUDP( (int)evt->GetParam2() );
193 //---------------------------------------------------------------------------
194 bool VlcProc::EventProcEnd()
196 if( p_intf->p_sys->b_all_win_closed )
199 list<SkinWindow *>::const_iterator win;
201 // If a window has been closed, test if all are closed !
202 for( win = p_intf->p_sys->p_theme->WindowList.begin();
203 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
205 if( !(*win)->IsHidden() ) // Not all windows closed
211 // All window are closed
212 switch( p_intf->p_sys->i_close_status )
215 // Save config before exiting
216 p_intf->p_sys->p_theme->SaveConfig();
220 // Send specified event
221 OSAPI_PostMessage( NULL, p_intf->p_sys->i_close_status, 0, 0 );
224 p_intf->p_sys->i_close_status = VLC_NOTHING;
225 p_intf->p_sys->b_all_win_closed = true;
230 //---------------------------------------------------------------------------
231 bool VlcProc::IsClosing()
233 if( p_intf->b_die && p_intf->p_sys->i_close_status != VLC_QUIT )
235 p_intf->p_sys->i_close_status = VLC_QUIT;
236 OSAPI_PostMessage( NULL, VLC_HIDE, VLC_QUIT, 0 );
240 //---------------------------------------------------------------------------
245 //---------------------------------------------------------------------------
247 //---------------------------------------------------------------------------
248 void VlcProc::InterfaceRefresh( bool All )
251 intf_sys_t *Sys = p_intf->p_sys;
252 Theme *Thema = Sys->p_theme;
253 playlist_t *PlayList = Sys->p_playlist;
256 if( PlayList != NULL )
258 // Refresh stream control controls ! :)
259 switch( PlayList->i_status )
261 case PLAYLIST_STOPPED:
262 EnabledEvent( "time", false );
263 EnabledEvent( "stop", false );
264 EnabledEvent( "play", true );
265 EnabledEvent( "pause", false );
267 case PLAYLIST_RUNNING:
268 EnabledEvent( "time", true );
269 EnabledEvent( "stop", true );
270 EnabledEvent( "play", false );
271 EnabledEvent( "pause", true );
273 case PLAYLIST_PAUSED:
274 EnabledEvent( "time", true );
275 EnabledEvent( "stop", true );
276 EnabledEvent( "play", true );
277 EnabledEvent( "pause", false );
281 // Refresh next and prev buttons
282 if( PlayList->i_index == 0 || PlayList->i_size == 1 )
283 EnabledEvent( "prev", false );
285 EnabledEvent( "prev", true );
287 if( PlayList->i_index == PlayList->i_size - 1 || PlayList->i_size == 1 )
288 EnabledEvent( "next", false );
290 EnabledEvent( "next", true );
293 // Update file name text
294 if( PlayList->i_index != Sys->i_index )
296 Thema->EvtBank->Get( "file_name" )->PostTextMessage(
297 PlayList->pp_items[PlayList->i_index]->psz_name );
301 if( PlayList->i_index != Sys->i_index ||
302 PlayList->i_size != Sys->i_size )
304 Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
305 Sys->i_size = PlayList->i_size;
306 Sys->i_index = PlayList->i_index;
311 EnabledEvent( "time", false );
312 EnabledEvent( "stop", false );
313 EnabledEvent( "play", false );
314 EnabledEvent( "pause", false );
315 EnabledEvent( "prev", false );
316 EnabledEvent( "next", false );
319 if( Sys->i_size > 0 )
321 Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
327 //---------------------------------------------------------------------------
328 void VlcProc::EnabledEvent( string type, bool state )
330 OSAPI_PostMessage( NULL, CTRL_ENABLED, (unsigned int)
331 p_intf->p_sys->p_theme->EvtBank->Get( type ), (int)state );
333 //---------------------------------------------------------------------------
336 //---------------------------------------------------------------------------
337 // Common VLC procedures
338 //---------------------------------------------------------------------------
339 void VlcProc::LoadSkin()
341 if( p_intf->p_sys->p_new_theme_file == NULL )
344 p_intf->p_sys->p_dialogs->ShowOpenSkin();
349 // Place a new theme in the global structure, because it will
350 // be filled by the parser
351 // We save the old one to restore it in case of problem
352 Theme *oldTheme = p_intf->p_sys->p_theme;
353 p_intf->p_sys->p_theme = (Theme *)new OSTheme( p_intf );
355 // Run the XML parser
356 ThemeLoader *Loader = new ThemeLoader( p_intf );
357 if( Loader->Load( p_intf->p_sys->p_new_theme_file ) )
359 // Everything went well
360 msg_Dbg( p_intf, "New theme successfully loaded" );
361 delete (OSTheme *)oldTheme;
364 p_intf->p_sys->p_theme->InitTheme();
365 p_intf->p_sys->p_theme->ShowTheme();
369 msg_Warn( p_intf, "A problem occurred when loading the new theme,"
370 " restoring the previous one" );
371 delete (OSTheme *)p_intf->p_sys->p_theme;
372 p_intf->p_sys->p_theme = oldTheme;
375 p_intf->p_sys->p_theme->ShowTheme();
379 // Uninitialize new theme
380 delete (char *)p_intf->p_sys->p_new_theme_file;
381 p_intf->p_sys->p_new_theme_file = NULL;
384 //---------------------------------------------------------------------------
386 void VlcProc::DropFile( unsigned int param )
388 // Get pointer to file
389 char *FileName = (char *)param;
391 // Add the new file to the playlist
392 if( p_intf->p_sys->p_playlist != NULL )
394 if( config_GetInt( p_intf, "enqueue" ) )
396 playlist_Add( p_intf->p_sys->p_playlist, FileName,
397 PLAYLIST_APPEND, PLAYLIST_END );
401 playlist_Add( p_intf->p_sys->p_playlist, FileName,
402 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
406 // VLC_DROP must be called with a pointer to a char else it will
407 // ******** SEGFAULT ********
408 // The delete is here because the processus in asynchronous
415 //---------------------------------------------------------------------------
420 //---------------------------------------------------------------------------
422 //---------------------------------------------------------------------------
423 void VlcProc::PauseStream()
425 if( p_intf->p_sys->p_input == NULL )
427 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
432 //---------------------------------------------------------------------------
433 void VlcProc::PlayStream()
435 if( p_intf->p_sys->p_playlist == NULL )
438 if( !p_intf->p_sys->p_playlist->i_size )
441 p_intf->p_sys->p_dialogs->ShowOpen( true );
447 playlist_Play( p_intf->p_sys->p_playlist );
452 //---------------------------------------------------------------------------
453 void VlcProc::StopStream()
455 if( p_intf->p_sys->p_playlist == NULL )
457 playlist_Stop( p_intf->p_sys->p_playlist );
462 //---------------------------------------------------------------------------
463 void VlcProc::NextStream()
465 if( p_intf->p_sys->p_playlist == NULL )
468 playlist_Next( p_intf->p_sys->p_playlist );
473 //---------------------------------------------------------------------------
474 void VlcProc::PrevStream()
476 if( p_intf->p_sys->p_playlist == NULL )
479 playlist_Prev( p_intf->p_sys->p_playlist );
484 //---------------------------------------------------------------------------
485 void VlcProc::MoveStream( long Pos )
487 if( p_intf->p_sys->p_input == NULL )
490 off_t i_seek = (off_t)(Pos *
491 p_intf->p_sys->p_input->stream.p_selected_area->i_size
494 input_Seek( p_intf->p_sys->p_input, i_seek, INPUT_SEEK_SET );
499 //---------------------------------------------------------------------------
503 //---------------------------------------------------------------------------
505 //---------------------------------------------------------------------------
506 void VlcProc::FullScreen()
508 vout_thread_t *p_vout;
510 if( p_intf->p_sys->p_input == NULL )
513 p_vout = (vout_thread_t *)vlc_object_find( p_intf->p_sys->p_input,
514 VLC_OBJECT_VOUT, FIND_CHILD );
518 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
519 vlc_object_release( p_vout );
521 //---------------------------------------------------------------------------
525 //---------------------------------------------------------------------------
527 //---------------------------------------------------------------------------
528 void VlcProc::ChangeVolume( unsigned int msg, long param )
530 audio_volume_t volume;
533 case VLC_VOLUME_MUTE:
534 aout_VolumeMute( p_intf, NULL );
537 aout_VolumeUp( p_intf, 1, NULL );
539 case VLC_VOLUME_DOWN:
540 aout_VolumeDown( p_intf, 1, NULL );
543 aout_VolumeSet( p_intf, param * AOUT_VOLUME_MAX / SLIDER_RANGE );
546 aout_VolumeGet( p_intf, &volume );
549 //---------------------------------------------------------------------------
552 //---------------------------------------------------------------------------
554 //---------------------------------------------------------------------------
555 void VlcProc::AddNetworkUDP( int port )
558 char *s_port = new char[5];
559 sprintf( s_port, "%i", port );
560 string source = "udp:@:" + (string)s_port;
563 playlist_Add( p_intf->p_sys->p_playlist, (char *)source.c_str(),
564 PLAYLIST_APPEND, PLAYLIST_END );
566 // Refresh interface !
567 p_intf->p_sys->p_theme->EvtBank->Get( "playlist_refresh" )
568 ->PostSynchroMessage();
571 //---------------------------------------------------------------------------