1 /*****************************************************************************
2 * vlcproc.cpp: VlcProc class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: vlcproc.cpp,v 1.51 2003/10/22 19:12:56 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 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 for( list<SkinWindow *>::const_iterator win =
132 p_intf->p_sys->p_theme->WindowList.begin();
133 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
135 (*win)->ToggleOnTop();
137 // Set the indicator to the new state
138 p_intf->p_sys->b_on_top = !p_intf->p_sys->b_on_top;
142 DropFile( evt->GetParam1(), evt->GetParam2() );
165 case VLC_PLAYLIST_ADD_FILE:
166 p_intf->p_sys->p_dialogs->ShowOpen( false );
171 p_intf->p_sys->p_dialogs->ShowMessages();
175 p_intf->p_sys->p_dialogs->ShowPrefs();
179 p_intf->p_sys->p_dialogs->ShowFileInfo();
182 case VLC_INTF_REFRESH:
186 case VLC_TEST_ALL_CLOSED:
187 return EventProcEnd();
192 case VLC_CHANGE_TRAY:
193 p_intf->p_sys->p_theme->ChangeTray();
196 case VLC_CHANGE_TASKBAR:
197 p_intf->p_sys->p_theme->ChangeTaskbar();
204 //---------------------------------------------------------------------------
205 bool VlcProc::EventProcEnd()
207 if( p_intf->p_sys->b_all_win_closed )
210 list<SkinWindow *>::const_iterator win;
212 // If a window has been closed, test if all are closed !
213 for( win = p_intf->p_sys->p_theme->WindowList.begin();
214 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
216 if( !(*win)->IsHidden() ) // Not all windows closed
222 // All window are closed
223 switch( p_intf->p_sys->i_close_status )
226 // Save config before exiting
227 p_intf->p_sys->p_theme->SaveConfig();
231 // Send specified event
232 OSAPI_PostMessage( NULL, p_intf->p_sys->i_close_status, 0, 0 );
235 p_intf->p_sys->i_close_status = VLC_NOTHING;
236 p_intf->p_sys->b_all_win_closed = true;
241 //---------------------------------------------------------------------------
242 bool VlcProc::IsClosing()
244 if( p_intf->b_die && p_intf->p_sys->i_close_status != VLC_QUIT )
246 p_intf->p_sys->i_close_status = VLC_QUIT;
247 OSAPI_PostMessage( NULL, VLC_HIDE, VLC_QUIT, 0 );
251 //---------------------------------------------------------------------------
256 //---------------------------------------------------------------------------
258 //---------------------------------------------------------------------------
261 int VlcProc::RefreshCallback( vlc_object_t *p_this, const char *psz_variable,
262 vlc_value_t old_val, vlc_value_t new_val, void *param )
264 ( (VlcProc*)param )->InterfaceRefresh();
268 // Interface show/hide callback
269 int VlcProc::IntfShowCallback( vlc_object_t *p_this, const char *psz_variable,
270 vlc_value_t old_val, vlc_value_t new_val, void *param )
272 if( new_val.b_bool == VLC_TRUE )
274 OSAPI_PostMessage( NULL, VLC_SHOW, 1, 0 );
278 OSAPI_PostMessage( NULL, VLC_HIDE, 1, 0 );
283 void VlcProc::InterfaceRefresh()
286 intf_sys_t *Sys = p_intf->p_sys;
287 Theme *Thema = Sys->p_theme;
288 playlist_t *PlayList = Sys->p_playlist;
291 if( PlayList != NULL )
293 vlc_mutex_lock( &PlayList->object_lock );
295 // Refresh stream control controls ! :)
296 switch( PlayList->i_status )
298 case PLAYLIST_STOPPED:
299 EnabledEvent( "time", false );
300 EnabledEvent( "stop", false );
301 EnabledEvent( "play", true );
302 EnabledEvent( "pause", false );
304 case PLAYLIST_RUNNING:
305 EnabledEvent( "time", true );
306 EnabledEvent( "stop", true );
307 EnabledEvent( "play", false );
308 EnabledEvent( "pause", true );
310 case PLAYLIST_PAUSED:
311 EnabledEvent( "time", true );
312 EnabledEvent( "stop", true );
313 EnabledEvent( "play", true );
314 EnabledEvent( "pause", false );
318 // Refresh next and prev buttons
319 if( PlayList->i_index == 0 || PlayList->i_size == 1 )
320 EnabledEvent( "prev", false );
322 EnabledEvent( "prev", true );
324 if( PlayList->i_index == PlayList->i_size - 1 || PlayList->i_size == 1 )
325 EnabledEvent( "next", false );
327 EnabledEvent( "next", true );
330 if( PlayList->i_index >= 0 && PlayList->i_index != Sys->i_index )
332 string long_name = PlayList->pp_items[PlayList->i_index]->psz_name;
333 int pos = long_name.rfind( DIRECTORY_SEPARATOR, long_name.size() );
335 // Complete file name
336 Thema->EvtBank->Get( "file_name" )->PostTextMessage(
337 PlayList->pp_items[PlayList->i_index]->psz_name );
338 // File name without path
339 Thema->EvtBank->Get( "title" )->PostTextMessage(
340 PlayList->pp_items[PlayList->i_index]->psz_name + pos + 1 );
344 if( PlayList->i_index != Sys->i_index ||
345 PlayList->i_size != Sys->i_size )
347 Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
348 Sys->i_size = PlayList->i_size;
349 Sys->i_index = PlayList->i_index;
352 vlc_mutex_unlock( &PlayList->object_lock );
356 EnabledEvent( "time", false );
357 EnabledEvent( "stop", false );
358 EnabledEvent( "play", false );
359 EnabledEvent( "pause", false );
360 EnabledEvent( "prev", false );
361 EnabledEvent( "next", false );
364 if( Sys->i_size > 0 )
366 Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
371 //---------------------------------------------------------------------------
372 void VlcProc::EnabledEvent( string type, bool state )
374 OSAPI_PostMessage( NULL, CTRL_ENABLED, (unsigned int)
375 p_intf->p_sys->p_theme->EvtBank->Get( type ), (int)state );
379 OSAPI_PostMessage( NULL, CTRL_SYNCHRO, (unsigned int)
380 p_intf->p_sys->p_theme->EvtBank->Get( type ), (int)false );
383 //---------------------------------------------------------------------------
386 //---------------------------------------------------------------------------
387 // Common VLC procedures
388 //---------------------------------------------------------------------------
389 void VlcProc::LoadSkin()
391 if( p_intf->p_sys->p_new_theme_file == NULL )
393 p_intf->p_sys->p_dialogs->ShowOpenSkin( 0 /*none blocking*/ );
397 // Place a new theme in the global structure, because it will
398 // be filled by the parser
399 // We save the old one to restore it in case of problem
400 Theme *oldTheme = p_intf->p_sys->p_theme;
401 p_intf->p_sys->p_theme = (Theme *)new OSTheme( p_intf );
403 // Run the XML parser
404 ThemeLoader *Loader = new ThemeLoader( p_intf );
405 if( Loader->Load( p_intf->p_sys->p_new_theme_file ) )
407 // Everything went well
408 msg_Dbg( p_intf, "New theme successfully loaded" );
409 delete (OSTheme *)oldTheme;
412 p_intf->p_sys->p_theme->InitTheme();
413 p_intf->p_sys->p_theme->ShowTheme();
417 msg_Warn( p_intf, "A problem occurred when loading the new theme,"
418 " restoring the previous one" );
419 delete (OSTheme *)p_intf->p_sys->p_theme;
420 p_intf->p_sys->p_theme = oldTheme;
423 p_intf->p_sys->p_theme->ShowTheme();
427 // Uninitialize new theme
428 free( p_intf->p_sys->p_new_theme_file );
429 p_intf->p_sys->p_new_theme_file = NULL;
432 //---------------------------------------------------------------------------
434 void VlcProc::DropFile( unsigned int param1, long param2 )
436 // Get pointer to file
437 char *FileName = (char *)param1;
439 // Add the new file to the playlist
440 if( p_intf->p_sys->p_playlist != NULL )
445 playlist_Add( p_intf->p_sys->p_playlist, FileName, 0, 0,
446 PLAYLIST_APPEND, PLAYLIST_END );
450 // Enqueue and play the item
451 playlist_Add( p_intf->p_sys->p_playlist, FileName, 0, 0,
452 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
456 // VLC_DROP must be called with a pointer to a char else it will
457 // ******** SEGFAULT ********
458 // The delete is here because the processus in asynchronous
464 //---------------------------------------------------------------------------
469 //---------------------------------------------------------------------------
471 //---------------------------------------------------------------------------
472 void VlcProc::PauseStream()
474 if( p_intf->p_sys->p_playlist == NULL )
477 playlist_Command( p_intf->p_sys->p_playlist, PLAYLIST_PAUSE, 0 );
482 //---------------------------------------------------------------------------
483 void VlcProc::PlayStream()
485 if( p_intf->p_sys->p_playlist == NULL )
488 if( !p_intf->p_sys->p_playlist->i_size )
490 p_intf->p_sys->p_dialogs->ShowOpen( true );
495 playlist_Play( p_intf->p_sys->p_playlist );
500 //---------------------------------------------------------------------------
501 void VlcProc::StopStream()
503 if( p_intf->p_sys->p_playlist == NULL )
505 playlist_Stop( p_intf->p_sys->p_playlist );
510 //---------------------------------------------------------------------------
511 void VlcProc::NextStream()
513 if( p_intf->p_sys->p_playlist == NULL )
516 playlist_Next( p_intf->p_sys->p_playlist );
521 //---------------------------------------------------------------------------
522 void VlcProc::PrevStream()
524 if( p_intf->p_sys->p_playlist == NULL )
527 playlist_Prev( p_intf->p_sys->p_playlist );
532 //---------------------------------------------------------------------------
533 void VlcProc::MoveStream( long Pos )
535 if( p_intf->p_sys->p_input == NULL )
538 off_t i_seek = (off_t)(Pos *
539 p_intf->p_sys->p_input->stream.p_selected_area->i_size
542 input_Seek( p_intf->p_sys->p_input, i_seek, INPUT_SEEK_SET );
547 //---------------------------------------------------------------------------
551 //---------------------------------------------------------------------------
553 //---------------------------------------------------------------------------
554 void VlcProc::FullScreen()
556 vout_thread_t *p_vout;
558 if( p_intf->p_sys->p_input == NULL )
561 p_vout = (vout_thread_t *)vlc_object_find( p_intf->p_sys->p_input,
562 VLC_OBJECT_VOUT, FIND_CHILD );
566 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
567 vlc_object_release( p_vout );
569 //---------------------------------------------------------------------------
573 //---------------------------------------------------------------------------
575 //---------------------------------------------------------------------------
576 void VlcProc::ChangeVolume( unsigned int msg, long param )
578 audio_volume_t volume;
581 case VLC_VOLUME_MUTE:
582 aout_VolumeMute( p_intf, NULL );
585 aout_VolumeUp( p_intf, 1, NULL );
587 case VLC_VOLUME_DOWN:
588 aout_VolumeDown( p_intf, 1, NULL );
591 aout_VolumeSet( p_intf, param * (AOUT_VOLUME_DEFAULT * 2) /
595 aout_VolumeGet( p_intf, &volume );
597 //---------------------------------------------------------------------------