]> git.sesse.net Git - vlc/blob - modules/gui/beos/Interface.cpp
modules/gui/beos/* : misc fixes & enhancements
[vlc] / modules / gui / beos / Interface.cpp
1 /*****************************************************************************
2  * intf_beos.cpp: beos interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 VideoLAN
5  * $Id: Interface.cpp,v 1.13 2003/05/30 17:30:54 titer Exp $
6  *
7  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *          Tony Castley <tony@castley.net>
10  *          Richard Shepherd <richard@rshepherd.demon.co.uk>
11  *          Stephan Aßmus <stippi@yellowbites.com>
12  *          Eric Petit <titer@videolan.org>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
27  *****************************************************************************/
28
29 /*****************************************************************************
30  * Preamble
31  *****************************************************************************/
32 #include <stdio.h>
33 #include <stdlib.h>                                      /* malloc(), free() */
34 #include <InterfaceKit.h>
35 #include <Application.h>
36 #include <Message.h>
37 #include <string.h>
38
39 #include <vlc/vlc.h>
40 #include <vlc/intf.h>
41 #include <vlc/aout.h>
42 #include <aout_internal.h>
43
44 #include "VlcWrapper.h"
45 #include "InterfaceWindow.h"
46 #include "MsgVals.h"
47
48 /*****************************************************************************
49  * Local prototype
50  *****************************************************************************/
51 static void Run       ( intf_thread_t *p_intf );
52
53 /*****************************************************************************
54  * intf_Open: initialize interface
55  *****************************************************************************/
56 int E_(OpenIntf) ( vlc_object_t *p_this )
57 {
58     intf_thread_t * p_intf = (intf_thread_t*) p_this;
59
60     /* Allocate instance and initialize some members */
61     p_intf->p_sys = (intf_sys_t*) malloc( sizeof( intf_sys_t ) );
62     if( p_intf->p_sys == NULL )
63     {
64         msg_Err( p_intf, "out of memory" );
65         return( 1 );
66     }
67     
68     p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
69     p_intf->p_sys->p_wrapper = new VlcWrapper( p_intf );
70     p_intf->pf_run = Run;
71
72     /* Create the interface window */
73     BScreen screen(B_MAIN_SCREEN_ID);
74     BRect rect = screen.Frame();
75     rect.top = rect.bottom-100;
76     rect.bottom -= 50;
77     rect.left += 50;
78     rect.right = rect.left + 350;
79     p_intf->p_sys->p_window =
80         new InterfaceWindow( rect,
81                              "VLC " PACKAGE_VERSION,
82                              p_intf );
83     if( p_intf->p_sys->p_window == 0 )
84     {
85         free( p_intf->p_sys );
86         msg_Err( p_intf, "cannot allocate InterfaceWindow" );
87         return( 1 );
88     }
89     else
90     {
91         /* Make the be_app aware the interface has been created */
92         BMessage message(INTERFACE_CREATED);
93         message.AddPointer("window", p_intf->p_sys->p_window);
94         be_app->PostMessage(&message);
95     }
96     p_intf->p_sys->i_saved_volume = AOUT_VOLUME_DEFAULT;
97     p_intf->p_sys->b_loop = 0;
98     p_intf->p_sys->b_mute = 0;
99     
100     return( 0 );
101 }
102
103 /*****************************************************************************
104  * intf_Close: destroy dummy interface
105  *****************************************************************************/
106 void E_(CloseIntf) ( vlc_object_t *p_this )
107 {
108     intf_thread_t *p_intf = (intf_thread_t*) p_this;
109     
110     msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
111
112     /* Destroy the interface window */
113     p_intf->p_sys->p_window->Lock();
114     p_intf->p_sys->p_window->Quit();
115
116     /* Destroy structure */
117     delete p_intf->p_sys->p_wrapper;
118     free( p_intf->p_sys );
119 }
120
121
122 /*****************************************************************************
123  * intf_Run: event loop
124  *****************************************************************************/
125 static void Run( intf_thread_t *p_intf )
126 {
127     while( !p_intf->b_die )
128     {
129         /* Update VlcWrapper internals (p_input, etc) */
130         p_intf->p_sys->p_wrapper->UpdateInput();
131         
132         /* Manage the slider */
133         p_intf->p_sys->p_window->UpdateInterface();
134
135         /* Wait a bit */
136         msleep( INTF_IDLE_SLEEP );
137     }
138 }