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