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