1 /*****************************************************************************
2 * vlcproc.cpp: VlcProc class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: vlcproc.cpp,v 1.47 2003/10/17 16:40:09 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 -------------------------------------------------------------------
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 notified 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 var_DelCallback( p_playlist, "intf-show", IntfShowCallback, this );
74 vlc_object_release( p_playlist );
77 //---------------------------------------------------------------------------
78 bool VlcProc::EventProc( Event *evt )
80 switch( evt->GetMessage() )
83 MoveStream( evt->GetParam2() );
86 case VLC_VOLUME_CHANGE:
87 ChangeVolume( evt->GetParam1(), evt->GetParam2() );
95 for( list<SkinWindow *>::const_iterator win =
96 p_intf->p_sys->p_theme->WindowList.begin();
97 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
99 (*win)->OnStartThemeVisible = !(*win)->IsHidden();
101 p_intf->p_sys->i_close_status = (int)evt->GetParam1();
102 OSAPI_PostMessage( NULL, WINDOW_CLOSE, 1, 0 );
106 for( list<SkinWindow *>::const_iterator win =
107 p_intf->p_sys->p_theme->WindowList.begin();
108 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
110 if( (*win)->OnStartThemeVisible )
111 OSAPI_PostMessage( (*win), WINDOW_OPEN, 1, 0 );
113 p_intf->p_sys->b_all_win_closed = false;
117 p_intf->p_sys->p_dialogs->ShowOpen( true );
122 p_intf->p_sys->p_dialogs->ShowNet();
131 DropFile( evt->GetParam1() );
154 case VLC_PLAYLIST_ADD_FILE:
155 p_intf->p_sys->p_dialogs->ShowOpen( false );
160 p_intf->p_sys->p_dialogs->ShowMessages();
164 p_intf->p_sys->p_dialogs->ShowPrefs();
168 p_intf->p_sys->p_dialogs->ShowFileInfo();
171 case VLC_INTF_REFRESH:
175 case VLC_TEST_ALL_CLOSED:
176 return EventProcEnd();
181 case VLC_CHANGE_TRAY:
182 p_intf->p_sys->p_theme->ChangeTray();
185 case VLC_CHANGE_TASKBAR:
186 p_intf->p_sys->p_theme->ChangeTaskbar();
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 //---------------------------------------------------------------------------
250 int VlcProc::RefreshCallback( vlc_object_t *p_this, const char *psz_variable,
251 vlc_value_t old_val, vlc_value_t new_val, void *param )
253 ( (VlcProc*)param )->InterfaceRefresh();
257 // Interface show/hide callback
258 int VlcProc::IntfShowCallback( vlc_object_t *p_this, const char *psz_variable,
259 vlc_value_t old_val, vlc_value_t new_val, void *param )
261 if( new_val.b_bool == VLC_TRUE )
263 OSAPI_PostMessage( NULL, VLC_SHOW, 1, 0 );
267 OSAPI_PostMessage( NULL, VLC_HIDE, 1, 0 );
272 void VlcProc::InterfaceRefresh()
275 intf_sys_t *Sys = p_intf->p_sys;
276 Theme *Thema = Sys->p_theme;
277 playlist_t *PlayList = Sys->p_playlist;
280 if( PlayList != NULL )
282 vlc_mutex_lock( &PlayList->object_lock );
284 // Refresh stream control controls ! :)
285 switch( PlayList->i_status )
287 case PLAYLIST_STOPPED:
288 EnabledEvent( "time", false );
289 EnabledEvent( "stop", false );
290 EnabledEvent( "play", true );
291 EnabledEvent( "pause", false );
293 case PLAYLIST_RUNNING:
294 EnabledEvent( "time", true );
295 EnabledEvent( "stop", true );
296 EnabledEvent( "play", false );
297 EnabledEvent( "pause", true );
299 case PLAYLIST_PAUSED:
300 EnabledEvent( "time", true );
301 EnabledEvent( "stop", true );
302 EnabledEvent( "play", true );
303 EnabledEvent( "pause", false );
307 // Refresh next and prev buttons
308 if( PlayList->i_index == 0 || PlayList->i_size == 1 )
309 EnabledEvent( "prev", false );
311 EnabledEvent( "prev", true );
313 if( PlayList->i_index == PlayList->i_size - 1 || PlayList->i_size == 1 )
314 EnabledEvent( "next", false );
316 EnabledEvent( "next", true );
319 if( PlayList->i_index >= 0 && PlayList->i_index != Sys->i_index )
321 string long_name = PlayList->pp_items[PlayList->i_index]->psz_name;
322 int pos = long_name.rfind( DIRECTORY_SEPARATOR, long_name.size() );
324 // Complete file name
325 Thema->EvtBank->Get( "file_name" )->PostTextMessage(
326 PlayList->pp_items[PlayList->i_index]->psz_name );
327 // File name without path
328 Thema->EvtBank->Get( "title" )->PostTextMessage(
329 PlayList->pp_items[PlayList->i_index]->psz_name + pos + 1 );
333 if( PlayList->i_index != Sys->i_index ||
334 PlayList->i_size != Sys->i_size )
336 Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
337 Sys->i_size = PlayList->i_size;
338 Sys->i_index = PlayList->i_index;
341 vlc_mutex_unlock( &PlayList->object_lock );
345 EnabledEvent( "time", false );
346 EnabledEvent( "stop", false );
347 EnabledEvent( "play", false );
348 EnabledEvent( "pause", false );
349 EnabledEvent( "prev", false );
350 EnabledEvent( "next", false );
353 if( Sys->i_size > 0 )
355 Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
360 //---------------------------------------------------------------------------
361 void VlcProc::EnabledEvent( string type, bool state )
363 OSAPI_PostMessage( NULL, CTRL_ENABLED, (unsigned int)
364 p_intf->p_sys->p_theme->EvtBank->Get( type ), (int)state );
366 //---------------------------------------------------------------------------
369 //---------------------------------------------------------------------------
370 // Common VLC procedures
371 //---------------------------------------------------------------------------
372 void VlcProc::LoadSkin()
374 if( p_intf->p_sys->p_new_theme_file == NULL )
376 p_intf->p_sys->p_dialogs->ShowOpenSkin( 0 /*none blocking*/ );
380 // Place a new theme in the global structure, because it will
381 // be filled by the parser
382 // We save the old one to restore it in case of problem
383 Theme *oldTheme = p_intf->p_sys->p_theme;
384 p_intf->p_sys->p_theme = (Theme *)new OSTheme( p_intf );
386 // Run the XML parser
387 ThemeLoader *Loader = new ThemeLoader( p_intf );
388 if( Loader->Load( p_intf->p_sys->p_new_theme_file ) )
390 // Everything went well
391 msg_Dbg( p_intf, "New theme successfully loaded" );
392 delete (OSTheme *)oldTheme;
395 p_intf->p_sys->p_theme->InitTheme();
396 p_intf->p_sys->p_theme->ShowTheme();
400 msg_Warn( p_intf, "A problem occurred when loading the new theme,"
401 " restoring the previous one" );
402 delete (OSTheme *)p_intf->p_sys->p_theme;
403 p_intf->p_sys->p_theme = oldTheme;
406 p_intf->p_sys->p_theme->ShowTheme();
410 // Uninitialize new theme
411 delete[] p_intf->p_sys->p_new_theme_file;
412 p_intf->p_sys->p_new_theme_file = NULL;
415 //---------------------------------------------------------------------------
417 void VlcProc::DropFile( unsigned int param )
419 // Get pointer to file
420 char *FileName = (char *)param;
422 // Add the new file to the playlist
423 if( p_intf->p_sys->p_playlist != NULL )
425 if( config_GetInt( p_intf, "enqueue" ) )
427 playlist_Add( p_intf->p_sys->p_playlist, FileName, 0, 0,
428 PLAYLIST_APPEND, PLAYLIST_END );
432 playlist_Add( p_intf->p_sys->p_playlist, FileName, 0, 0,
433 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
437 // VLC_DROP must be called with a pointer to a char else it will
438 // ******** SEGFAULT ********
439 // The delete is here because the processus in asynchronous
446 //---------------------------------------------------------------------------
451 //---------------------------------------------------------------------------
453 //---------------------------------------------------------------------------
454 void VlcProc::PauseStream()
456 if( p_intf->p_sys->p_input == NULL )
458 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
463 //---------------------------------------------------------------------------
464 void VlcProc::PlayStream()
466 if( p_intf->p_sys->p_playlist == NULL )
469 if( !p_intf->p_sys->p_playlist->i_size )
471 p_intf->p_sys->p_dialogs->ShowOpen( true );
476 playlist_Play( p_intf->p_sys->p_playlist );
481 //---------------------------------------------------------------------------
482 void VlcProc::StopStream()
484 if( p_intf->p_sys->p_playlist == NULL )
486 playlist_Stop( p_intf->p_sys->p_playlist );
491 //---------------------------------------------------------------------------
492 void VlcProc::NextStream()
494 if( p_intf->p_sys->p_playlist == NULL )
497 playlist_Next( p_intf->p_sys->p_playlist );
502 //---------------------------------------------------------------------------
503 void VlcProc::PrevStream()
505 if( p_intf->p_sys->p_playlist == NULL )
508 playlist_Prev( p_intf->p_sys->p_playlist );
513 //---------------------------------------------------------------------------
514 void VlcProc::MoveStream( long Pos )
516 if( p_intf->p_sys->p_input == NULL )
519 off_t i_seek = (off_t)(Pos *
520 p_intf->p_sys->p_input->stream.p_selected_area->i_size
523 input_Seek( p_intf->p_sys->p_input, i_seek, INPUT_SEEK_SET );
528 //---------------------------------------------------------------------------
532 //---------------------------------------------------------------------------
534 //---------------------------------------------------------------------------
535 void VlcProc::FullScreen()
537 vout_thread_t *p_vout;
539 if( p_intf->p_sys->p_input == NULL )
542 p_vout = (vout_thread_t *)vlc_object_find( p_intf->p_sys->p_input,
543 VLC_OBJECT_VOUT, FIND_CHILD );
547 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
548 vlc_object_release( p_vout );
550 //---------------------------------------------------------------------------
554 //---------------------------------------------------------------------------
556 //---------------------------------------------------------------------------
557 void VlcProc::ChangeVolume( unsigned int msg, long param )
559 audio_volume_t volume;
562 case VLC_VOLUME_MUTE:
563 aout_VolumeMute( p_intf, NULL );
566 aout_VolumeUp( p_intf, 1, NULL );
568 case VLC_VOLUME_DOWN:
569 aout_VolumeDown( p_intf, 1, NULL );
572 aout_VolumeSet( p_intf, param * (AOUT_VOLUME_DEFAULT * 2) /
576 aout_VolumeGet( p_intf, &volume );
579 //---------------------------------------------------------------------------