1 /*****************************************************************************
2 * vlcproc.cpp: VlcProc class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: vlcproc.cpp,v 1.42 2003/07/20 20:42:23 ipkiss 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 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
52 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
53 if( p_playlist != NULL )
55 // We want to be noticed of playlit changes
56 var_AddCallback( p_playlist, "intf-change", RefreshCallback, this );
58 // Raise/lower interface with middle click on vout
59 var_AddCallback( p_playlist, "intf-show", IntfShowCallback, this );
61 vlc_object_release( p_playlist );
64 //---------------------------------------------------------------------------
67 // Remove the refresh callback
68 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
69 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
70 if( p_playlist != NULL )
72 var_DelCallback( p_playlist, "intf-change", RefreshCallback, this );
73 vlc_object_release( p_playlist );
76 //---------------------------------------------------------------------------
77 bool VlcProc::EventProc( Event *evt )
79 switch( evt->GetMessage() )
82 MoveStream( evt->GetParam2() );
85 case VLC_VOLUME_CHANGE:
86 ChangeVolume( evt->GetParam1(), evt->GetParam2() );
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 (*win)->OnStartThemeVisible = !(*win)->IsHidden();
100 p_intf->p_sys->i_close_status = (int)evt->GetParam1();
101 OSAPI_PostMessage( NULL, WINDOW_CLOSE, 1, 0 );
105 for( list<SkinWindow *>::const_iterator win =
106 p_intf->p_sys->p_theme->WindowList.begin();
107 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
109 if( (*win)->OnStartThemeVisible )
110 OSAPI_PostMessage( (*win), WINDOW_OPEN, 1, 0 );
112 p_intf->p_sys->b_all_win_closed = false;
116 p_intf->p_sys->p_dialogs->ShowOpen( true );
125 DropFile( evt->GetParam1() );
148 case VLC_PLAYLIST_ADD_FILE:
149 p_intf->p_sys->p_dialogs->ShowOpen( false );
154 p_intf->p_sys->p_dialogs->ShowMessages();
158 p_intf->p_sys->p_dialogs->ShowPrefs();
162 p_intf->p_sys->p_dialogs->ShowFileInfo();
165 case VLC_INTF_REFRESH:
169 case VLC_TEST_ALL_CLOSED:
170 return EventProcEnd();
175 case VLC_CHANGE_TRAY:
176 p_intf->p_sys->p_theme->ChangeTray();
179 case VLC_CHANGE_TASKBAR:
180 p_intf->p_sys->p_theme->ChangeTaskbar();
187 //---------------------------------------------------------------------------
188 bool VlcProc::EventProcEnd()
190 if( p_intf->p_sys->b_all_win_closed )
193 list<SkinWindow *>::const_iterator win;
195 // If a window has been closed, test if all are closed !
196 for( win = p_intf->p_sys->p_theme->WindowList.begin();
197 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
199 if( !(*win)->IsHidden() ) // Not all windows closed
205 // All window are closed
206 switch( p_intf->p_sys->i_close_status )
209 // Save config before exiting
210 p_intf->p_sys->p_theme->SaveConfig();
214 // Send specified event
215 OSAPI_PostMessage( NULL, p_intf->p_sys->i_close_status, 0, 0 );
218 p_intf->p_sys->i_close_status = VLC_NOTHING;
219 p_intf->p_sys->b_all_win_closed = true;
224 //---------------------------------------------------------------------------
225 bool VlcProc::IsClosing()
227 if( p_intf->b_die && p_intf->p_sys->i_close_status != VLC_QUIT )
229 p_intf->p_sys->i_close_status = VLC_QUIT;
230 OSAPI_PostMessage( NULL, VLC_HIDE, VLC_QUIT, 0 );
234 //---------------------------------------------------------------------------
239 //---------------------------------------------------------------------------
241 //---------------------------------------------------------------------------
244 int VlcProc::RefreshCallback( vlc_object_t *p_this, const char *psz_variable,
245 vlc_value_t old_val, vlc_value_t new_val, void *param )
247 ( (VlcProc*)param )->InterfaceRefresh();
251 // Interface show/hide callback
252 int VlcProc::IntfShowCallback( vlc_object_t *p_this, const char *psz_variable,
253 vlc_value_t old_val, vlc_value_t new_val, void *param )
255 if( new_val.b_bool == VLC_TRUE )
257 OSAPI_PostMessage( NULL, VLC_SHOW, 1, 0 );
261 OSAPI_PostMessage( NULL, VLC_HIDE, 1, 0 );
266 void VlcProc::InterfaceRefresh()
269 intf_sys_t *Sys = p_intf->p_sys;
270 Theme *Thema = Sys->p_theme;
271 playlist_t *PlayList = Sys->p_playlist;
274 if( PlayList != NULL )
276 // Refresh stream control controls ! :)
277 switch( PlayList->i_status )
279 case PLAYLIST_STOPPED:
280 EnabledEvent( "time", false );
281 EnabledEvent( "stop", false );
282 EnabledEvent( "play", true );
283 EnabledEvent( "pause", false );
285 case PLAYLIST_RUNNING:
286 EnabledEvent( "time", true );
287 EnabledEvent( "stop", true );
288 EnabledEvent( "play", false );
289 EnabledEvent( "pause", true );
291 case PLAYLIST_PAUSED:
292 EnabledEvent( "time", true );
293 EnabledEvent( "stop", true );
294 EnabledEvent( "play", true );
295 EnabledEvent( "pause", false );
299 // Refresh next and prev buttons
300 if( PlayList->i_index == 0 || PlayList->i_size == 1 )
301 EnabledEvent( "prev", false );
303 EnabledEvent( "prev", true );
305 if( PlayList->i_index == PlayList->i_size - 1 || PlayList->i_size == 1 )
306 EnabledEvent( "next", false );
308 EnabledEvent( "next", true );
311 if( PlayList->i_index != Sys->i_index )
313 string long_name = PlayList->pp_items[PlayList->i_index]->psz_name;
314 int pos = long_name.rfind( DIRECTORY_SEPARATOR, long_name.size() );
316 // Complete file name
317 Thema->EvtBank->Get( "file_name" )->PostTextMessage(
318 PlayList->pp_items[PlayList->i_index]->psz_name );
319 // File name without path
320 Thema->EvtBank->Get( "title" )->PostTextMessage(
321 PlayList->pp_items[PlayList->i_index]->psz_name + pos + 1 );
325 if( PlayList->i_index != Sys->i_index ||
326 PlayList->i_size != Sys->i_size )
328 Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
329 Sys->i_size = PlayList->i_size;
330 Sys->i_index = PlayList->i_index;
335 EnabledEvent( "time", false );
336 EnabledEvent( "stop", false );
337 EnabledEvent( "play", false );
338 EnabledEvent( "pause", false );
339 EnabledEvent( "prev", false );
340 EnabledEvent( "next", false );
343 if( Sys->i_size > 0 )
345 Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
350 //---------------------------------------------------------------------------
351 void VlcProc::EnabledEvent( string type, bool state )
353 OSAPI_PostMessage( NULL, CTRL_ENABLED, (unsigned int)
354 p_intf->p_sys->p_theme->EvtBank->Get( type ), (int)state );
356 //---------------------------------------------------------------------------
359 //---------------------------------------------------------------------------
360 // Common VLC procedures
361 //---------------------------------------------------------------------------
362 void VlcProc::LoadSkin()
364 if( p_intf->p_sys->p_new_theme_file == NULL )
366 p_intf->p_sys->p_dialogs->ShowOpenSkin( 0 /*none blocking*/ );
370 // Place a new theme in the global structure, because it will
371 // be filled by the parser
372 // We save the old one to restore it in case of problem
373 Theme *oldTheme = p_intf->p_sys->p_theme;
374 p_intf->p_sys->p_theme = (Theme *)new OSTheme( p_intf );
376 // Run the XML parser
377 ThemeLoader *Loader = new ThemeLoader( p_intf );
378 if( Loader->Load( p_intf->p_sys->p_new_theme_file ) )
380 // Everything went well
381 msg_Dbg( p_intf, "New theme successfully loaded" );
382 delete (OSTheme *)oldTheme;
385 p_intf->p_sys->p_theme->InitTheme();
386 p_intf->p_sys->p_theme->ShowTheme();
390 msg_Warn( p_intf, "A problem occurred when loading the new theme,"
391 " restoring the previous one" );
392 delete (OSTheme *)p_intf->p_sys->p_theme;
393 p_intf->p_sys->p_theme = oldTheme;
396 p_intf->p_sys->p_theme->ShowTheme();
400 // Uninitialize new theme
401 delete[] p_intf->p_sys->p_new_theme_file;
402 p_intf->p_sys->p_new_theme_file = NULL;
405 //---------------------------------------------------------------------------
407 void VlcProc::DropFile( unsigned int param )
409 // Get pointer to file
410 char *FileName = (char *)param;
412 // Add the new file to the playlist
413 if( p_intf->p_sys->p_playlist != NULL )
415 if( config_GetInt( p_intf, "enqueue" ) )
417 playlist_Add( p_intf->p_sys->p_playlist, FileName,
418 PLAYLIST_APPEND, PLAYLIST_END );
422 playlist_Add( p_intf->p_sys->p_playlist, FileName,
423 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
427 // VLC_DROP must be called with a pointer to a char else it will
428 // ******** SEGFAULT ********
429 // The delete is here because the processus in asynchronous
436 //---------------------------------------------------------------------------
441 //---------------------------------------------------------------------------
443 //---------------------------------------------------------------------------
444 void VlcProc::PauseStream()
446 if( p_intf->p_sys->p_input == NULL )
448 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
453 //---------------------------------------------------------------------------
454 void VlcProc::PlayStream()
456 if( p_intf->p_sys->p_playlist == NULL )
459 if( !p_intf->p_sys->p_playlist->i_size )
461 p_intf->p_sys->p_dialogs->ShowOpen( true );
466 playlist_Play( p_intf->p_sys->p_playlist );
471 //---------------------------------------------------------------------------
472 void VlcProc::StopStream()
474 if( p_intf->p_sys->p_playlist == NULL )
476 playlist_Stop( p_intf->p_sys->p_playlist );
481 //---------------------------------------------------------------------------
482 void VlcProc::NextStream()
484 if( p_intf->p_sys->p_playlist == NULL )
487 playlist_Next( p_intf->p_sys->p_playlist );
492 //---------------------------------------------------------------------------
493 void VlcProc::PrevStream()
495 if( p_intf->p_sys->p_playlist == NULL )
498 playlist_Prev( p_intf->p_sys->p_playlist );
503 //---------------------------------------------------------------------------
504 void VlcProc::MoveStream( long Pos )
506 if( p_intf->p_sys->p_input == NULL )
509 off_t i_seek = (off_t)(Pos *
510 p_intf->p_sys->p_input->stream.p_selected_area->i_size
513 input_Seek( p_intf->p_sys->p_input, i_seek, INPUT_SEEK_SET );
518 //---------------------------------------------------------------------------
522 //---------------------------------------------------------------------------
524 //---------------------------------------------------------------------------
525 void VlcProc::FullScreen()
527 vout_thread_t *p_vout;
529 if( p_intf->p_sys->p_input == NULL )
532 p_vout = (vout_thread_t *)vlc_object_find( p_intf->p_sys->p_input,
533 VLC_OBJECT_VOUT, FIND_CHILD );
537 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
538 vlc_object_release( p_vout );
540 //---------------------------------------------------------------------------
544 //---------------------------------------------------------------------------
546 //---------------------------------------------------------------------------
547 void VlcProc::ChangeVolume( unsigned int msg, long param )
549 audio_volume_t volume;
552 case VLC_VOLUME_MUTE:
553 aout_VolumeMute( p_intf, NULL );
556 aout_VolumeUp( p_intf, 1, NULL );
558 case VLC_VOLUME_DOWN:
559 aout_VolumeDown( p_intf, 1, NULL );
562 aout_VolumeSet( p_intf, param * AOUT_VOLUME_MAX / SLIDER_RANGE );
565 aout_VolumeGet( p_intf, &volume );
568 //---------------------------------------------------------------------------