]> git.sesse.net Git - vlc/blob - modules/gui/skins/src/vlcproc.cpp
* modules/gui/skins/*: removed useless code
[vlc] / modules / gui / skins / src / vlcproc.cpp
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 $
6  *
7  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8  *          Emmanuel Puig    <karibu@via.ecp.fr>
9  *
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.
14  *
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.
19  *
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,
23  * USA.
24  *****************************************************************************/
25
26 //--- VLC -------------------------------------------------------------------
27 #include <vlc/vlc.h>
28 #include <vlc/intf.h>
29 #include <vlc/aout.h>
30 #include <vlc/vout.h>
31
32 //--- SKIN ------------------------------------------------------------------
33 #include "../os_api.h"
34 #include "event.h"
35 #include "banks.h"
36 #include "theme.h"
37 #include "../os_theme.h"
38 #include "themeloader.h"
39 #include "window.h"
40 #include "vlcproc.h"
41 #include "skin_common.h"
42 #include "dialogs.h"
43
44 //---------------------------------------------------------------------------
45 // VlcProc
46 //---------------------------------------------------------------------------
47 VlcProc::VlcProc( intf_thread_t *_p_intf )
48 {
49     p_intf = _p_intf;
50
51     playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
52         VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
53     if( p_playlist != NULL )
54     {
55         // We want to be noticed of playlit changes
56         var_AddCallback( p_playlist, "intf-change", RefreshCallback, this );
57
58         // Raise/lower interface with middle click on vout
59         var_AddCallback( p_playlist, "intf-show", IntfShowCallback, this );
60
61         vlc_object_release( p_playlist );
62     }
63 }
64 //---------------------------------------------------------------------------
65 VlcProc::~VlcProc()
66 {
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 )
71     {
72         var_DelCallback( p_playlist, "intf-change", RefreshCallback, this );
73         vlc_object_release( p_playlist );
74     }
75 }
76 //---------------------------------------------------------------------------
77 bool VlcProc::EventProc( Event *evt )
78 {
79     switch( evt->GetMessage() )
80     {
81         case VLC_STREAMPOS:
82             MoveStream( evt->GetParam2() );
83             return true;
84
85         case VLC_VOLUME_CHANGE:
86             ChangeVolume( evt->GetParam1(), evt->GetParam2() );
87             return true;
88
89         case VLC_FULLSCREEN:
90             FullScreen();
91             return true;
92
93         case VLC_HIDE:
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++ )
97             {
98                 (*win)->OnStartThemeVisible = !(*win)->IsHidden();
99             }
100             p_intf->p_sys->i_close_status = (int)evt->GetParam1();
101             OSAPI_PostMessage( NULL, WINDOW_CLOSE, 1, 0 );
102             return true;
103
104         case VLC_SHOW:
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++ )
108             {
109                 if( (*win)->OnStartThemeVisible )
110                     OSAPI_PostMessage( (*win), WINDOW_OPEN, 1, 0 );
111             }
112             p_intf->p_sys->b_all_win_closed = false;
113             return true;
114
115         case VLC_OPEN:
116             p_intf->p_sys->p_dialogs->ShowOpen( true );
117             InterfaceRefresh();
118             return true;
119
120         case VLC_LOAD_SKIN:
121             LoadSkin();
122             return true;
123
124         case VLC_DROP:
125             DropFile( evt->GetParam1() );
126             return true;
127
128         case VLC_PLAY:
129             PlayStream();
130             return true;
131
132         case VLC_PAUSE:
133             PauseStream();
134             return true;
135
136         case VLC_STOP:
137             StopStream();
138             return true;
139
140         case VLC_NEXT:
141             NextStream();
142             return true;
143
144         case VLC_PREV:
145             PrevStream();
146             return true;
147
148         case VLC_PLAYLIST_ADD_FILE:
149             p_intf->p_sys->p_dialogs->ShowOpen( false );
150             InterfaceRefresh();
151             return true;
152
153         case VLC_LOG_SHOW:
154             p_intf->p_sys->p_dialogs->ShowMessages();
155             return true;
156
157         case VLC_PREFS_SHOW:
158             p_intf->p_sys->p_dialogs->ShowPrefs();
159             return true;
160
161         case VLC_INFO_SHOW:
162             p_intf->p_sys->p_dialogs->ShowFileInfo();
163             return true;
164
165         case VLC_INTF_REFRESH:
166             InterfaceRefresh();
167             return true;
168
169         case VLC_TEST_ALL_CLOSED:
170             return EventProcEnd();
171
172         case VLC_QUIT:
173             return false;
174
175         case VLC_CHANGE_TRAY:
176             p_intf->p_sys->p_theme->ChangeTray();
177             return true;
178
179         case VLC_CHANGE_TASKBAR:
180             p_intf->p_sys->p_theme->ChangeTaskbar();
181             return true;
182
183         default:
184             return true;
185     }
186 }
187 //---------------------------------------------------------------------------
188 bool VlcProc::EventProcEnd()
189 {
190     if( p_intf->p_sys->b_all_win_closed )
191         return true;
192
193     list<SkinWindow *>::const_iterator win;
194
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++ )
198     {
199         if( !(*win)->IsHidden() )   // Not all windows closed
200         {
201             return true;
202         }
203     }
204
205     // All window are closed
206     switch( p_intf->p_sys->i_close_status )
207     {
208         case VLC_QUIT:
209             // Save config before exiting
210             p_intf->p_sys->p_theme->SaveConfig();
211             break;
212     }
213
214     // Send specified event
215     OSAPI_PostMessage( NULL, p_intf->p_sys->i_close_status, 0, 0 );
216
217     // Reset values
218     p_intf->p_sys->i_close_status = VLC_NOTHING;
219     p_intf->p_sys->b_all_win_closed = true;
220
221     // Return true
222     return true;
223 }
224 //---------------------------------------------------------------------------
225 bool VlcProc::IsClosing()
226 {
227     if( p_intf->b_die && p_intf->p_sys->i_close_status != VLC_QUIT )
228     {
229         p_intf->p_sys->i_close_status = VLC_QUIT;
230         OSAPI_PostMessage( NULL, VLC_HIDE, VLC_QUIT, 0 );
231     }
232     return true;
233 }
234 //---------------------------------------------------------------------------
235
236
237
238
239 //---------------------------------------------------------------------------
240 // Private methods
241 //---------------------------------------------------------------------------
242
243 // Refresh callback
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 )
246 {
247     ( (VlcProc*)param )->InterfaceRefresh();
248     return VLC_SUCCESS;
249 }
250
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 )
254 {
255     if( new_val.b_bool == VLC_TRUE )
256     {
257         OSAPI_PostMessage( NULL, VLC_SHOW, 1, 0 );
258     }
259     else
260     {
261         OSAPI_PostMessage( NULL, VLC_HIDE, 1, 0 );
262     }
263     return VLC_SUCCESS;
264 }
265
266 void VlcProc::InterfaceRefresh()
267 {
268     // Shortcut pointers
269     intf_sys_t  *Sys      = p_intf->p_sys;
270     Theme       *Thema    = Sys->p_theme;
271     playlist_t  *PlayList = Sys->p_playlist;
272
273     // Refresh
274     if( PlayList != NULL )
275     {
276         // Refresh stream control controls ! :)
277         switch( PlayList->i_status )
278         {
279             case PLAYLIST_STOPPED:
280                 EnabledEvent( "time", false );
281                 EnabledEvent( "stop", false );
282                 EnabledEvent( "play", true );
283                 EnabledEvent( "pause", false );
284                 break;
285             case PLAYLIST_RUNNING:
286                 EnabledEvent( "time", true );
287                 EnabledEvent( "stop", true );
288                 EnabledEvent( "play", false );
289                 EnabledEvent( "pause", true );
290                 break;
291             case PLAYLIST_PAUSED:
292                 EnabledEvent( "time", true );
293                 EnabledEvent( "stop", true );
294                 EnabledEvent( "play", true );
295                 EnabledEvent( "pause", false );
296                 break;
297         }
298
299         // Refresh next and prev buttons
300         if( PlayList->i_index == 0 || PlayList->i_size == 1 )
301             EnabledEvent( "prev", false );
302         else
303             EnabledEvent( "prev", true );
304
305         if( PlayList->i_index == PlayList->i_size - 1 || PlayList->i_size == 1 )
306             EnabledEvent( "next", false );
307         else
308             EnabledEvent( "next", true );
309
310         // Update file name
311         if( PlayList->i_index != Sys->i_index )
312         {
313             string long_name = PlayList->pp_items[PlayList->i_index]->psz_name;
314             int pos = long_name.rfind( DIRECTORY_SEPARATOR, long_name.size() );
315
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 );
322         }
323
324         // Update playlists
325         if( PlayList->i_index != Sys->i_index ||
326             PlayList->i_size != Sys->i_size )
327         {
328             Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
329             Sys->i_size  = PlayList->i_size;
330             Sys->i_index = PlayList->i_index;
331         }
332     }
333     else
334     {
335         EnabledEvent( "time", false );
336         EnabledEvent( "stop",  false );
337         EnabledEvent( "play",  false );
338         EnabledEvent( "pause", false );
339         EnabledEvent( "prev",  false );
340         EnabledEvent( "next",  false );
341
342         // Update playlists
343         if( Sys->i_size > 0 )
344         {
345             Thema->EvtBank->Get( "playlist_refresh" )->PostSynchroMessage();
346             Sys->i_size  = 0;
347         }
348     }
349 }
350 //---------------------------------------------------------------------------
351 void VlcProc::EnabledEvent( string type, bool state )
352 {
353     OSAPI_PostMessage( NULL, CTRL_ENABLED, (unsigned int)
354         p_intf->p_sys->p_theme->EvtBank->Get( type ), (int)state );
355 }
356 //---------------------------------------------------------------------------
357
358
359 //---------------------------------------------------------------------------
360 // Common VLC procedures
361 //---------------------------------------------------------------------------
362 void VlcProc::LoadSkin()
363 {
364     if( p_intf->p_sys->p_new_theme_file == NULL )
365     {
366         p_intf->p_sys->p_dialogs->ShowOpenSkin( 0 /*none blocking*/ );
367     }
368     else
369     {
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 );
375
376         // Run the XML parser
377         ThemeLoader *Loader = new ThemeLoader( p_intf );
378         if( Loader->Load( p_intf->p_sys->p_new_theme_file ) )
379         {
380             // Everything went well
381             msg_Dbg( p_intf, "New theme successfully loaded" );
382             delete (OSTheme *)oldTheme;
383
384             // Show the theme
385             p_intf->p_sys->p_theme->InitTheme();
386             p_intf->p_sys->p_theme->ShowTheme();
387         }
388         else
389         {
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;
394
395             // Show the theme
396             p_intf->p_sys->p_theme->ShowTheme();
397         }
398         delete Loader;
399
400         // Uninitialize new theme
401         delete[] p_intf->p_sys->p_new_theme_file;
402         p_intf->p_sys->p_new_theme_file = NULL;
403     }
404 }
405 //---------------------------------------------------------------------------
406
407 void VlcProc::DropFile( unsigned int param )
408 {
409     // Get pointer to file
410     char *FileName = (char *)param;
411
412     // Add the new file to the playlist
413     if( p_intf->p_sys->p_playlist != NULL )
414     {
415         if( config_GetInt( p_intf, "enqueue" ) )
416         {
417             playlist_Add( p_intf->p_sys->p_playlist, FileName,
418                           PLAYLIST_APPEND, PLAYLIST_END );
419         }
420         else
421         {
422             playlist_Add( p_intf->p_sys->p_playlist, FileName,
423                           PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
424         }
425     }
426
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
430     delete[] FileName;
431
432     // Refresh interface
433     InterfaceRefresh();
434
435 }
436 //---------------------------------------------------------------------------
437
438
439
440
441 //---------------------------------------------------------------------------
442 // Stream Control
443 //---------------------------------------------------------------------------
444 void VlcProc::PauseStream()
445 {
446     if( p_intf->p_sys->p_input == NULL )
447         return;
448     input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
449
450     // Refresh interface
451     InterfaceRefresh();
452 }
453 //---------------------------------------------------------------------------
454 void VlcProc::PlayStream()
455 {
456     if( p_intf->p_sys->p_playlist == NULL )
457         return;
458
459     if( !p_intf->p_sys->p_playlist->i_size )
460     {
461         p_intf->p_sys->p_dialogs->ShowOpen( true );
462         InterfaceRefresh();
463         return;
464     }
465
466     playlist_Play( p_intf->p_sys->p_playlist );
467
468     // Refresh interface
469     InterfaceRefresh();
470 }
471 //---------------------------------------------------------------------------
472 void VlcProc::StopStream()
473 {
474     if( p_intf->p_sys->p_playlist == NULL )
475         return;
476     playlist_Stop( p_intf->p_sys->p_playlist );
477
478     // Refresh interface
479     InterfaceRefresh();
480 }
481 //---------------------------------------------------------------------------
482 void VlcProc::NextStream()
483 {
484     if( p_intf->p_sys->p_playlist == NULL )
485         return;
486
487     playlist_Next( p_intf->p_sys->p_playlist );
488
489     // Refresh interface
490     InterfaceRefresh();
491 }
492 //---------------------------------------------------------------------------
493 void VlcProc::PrevStream()
494 {
495     if( p_intf->p_sys->p_playlist == NULL )
496         return;
497
498     playlist_Prev( p_intf->p_sys->p_playlist );
499
500     // Refresh interface
501     InterfaceRefresh();
502 }
503 //---------------------------------------------------------------------------
504 void VlcProc::MoveStream( long Pos )
505 {
506     if( p_intf->p_sys->p_input == NULL )
507         return;
508
509     off_t i_seek = (off_t)(Pos *
510         p_intf->p_sys->p_input->stream.p_selected_area->i_size
511         / SLIDER_RANGE);
512
513     input_Seek( p_intf->p_sys->p_input, i_seek, INPUT_SEEK_SET );
514
515     // Refresh interface
516     InterfaceRefresh();
517 }
518 //---------------------------------------------------------------------------
519
520
521
522 //---------------------------------------------------------------------------
523 // Fullscreen
524 //---------------------------------------------------------------------------
525 void VlcProc::FullScreen()
526 {
527     vout_thread_t *p_vout;
528
529     if( p_intf->p_sys->p_input == NULL )
530         return;
531
532     p_vout = (vout_thread_t *)vlc_object_find( p_intf->p_sys->p_input,
533                                                VLC_OBJECT_VOUT, FIND_CHILD );
534     if( p_vout == NULL )
535         return;
536
537     p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
538     vlc_object_release( p_vout );
539 }
540 //---------------------------------------------------------------------------
541
542
543
544 //---------------------------------------------------------------------------
545 // Volume Control
546 //---------------------------------------------------------------------------
547 void VlcProc::ChangeVolume( unsigned int msg, long param )
548 {
549     audio_volume_t volume;
550     switch( msg )
551     {
552         case VLC_VOLUME_MUTE:
553             aout_VolumeMute( p_intf, NULL );
554             break;
555         case VLC_VOLUME_UP:
556             aout_VolumeUp( p_intf, 1, NULL );
557             break;
558         case VLC_VOLUME_DOWN:
559             aout_VolumeDown( p_intf, 1, NULL );
560             break;
561         case VLC_VOLUME_SET:
562             aout_VolumeSet( p_intf, param * AOUT_VOLUME_MAX / SLIDER_RANGE );
563             break;
564     }
565     aout_VolumeGet( p_intf, &volume );
566
567 }
568 //---------------------------------------------------------------------------