]> git.sesse.net Git - vlc/blob - modules/gui/beos/MessagesWindow.cpp
modules/gui/beos/* : cosmetic
[vlc] / modules / gui / beos / MessagesWindow.cpp
1 /*****************************************************************************
2  * MessagesWindow.cpp: beos interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 VideoLAN
5  * $Id: MessagesWindow.cpp,v 1.9 2003/05/17 15:20:46 titer Exp $
6  *
7  * Authors: Eric Petit <titer@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /* BeOS headers */
25 #include <InterfaceKit.h>
26 #include <SupportKit.h>
27
28 /* VLC headers */
29 #include <vlc/vlc.h>
30 #include <vlc/intf.h>
31
32 /* BeOS module headers */
33 #include "VlcWrapper.h"
34 #include "InterfaceWindow.h"
35 #include "MessagesWindow.h"
36
37 static int UpdateMessages( intf_thread_t * p_intf );
38
39 /*****************************************************************************
40  * MessagesWindow::MessagesWindow
41  *****************************************************************************/
42 MessagesWindow::MessagesWindow( intf_thread_t * p_intf,
43                                 BRect frame, const char * name )
44         : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
45                B_NOT_ZOOMABLE )
46 {
47         this->p_intf = p_intf;
48
49     SetSizeLimits( 400, 2000, 200, 2000 );
50         
51         BRect rect, textRect;
52
53         rect = Bounds();
54         rect.right -= B_V_SCROLL_BAR_WIDTH;
55         textRect = rect;
56         textRect.InsetBy( 5, 5 );
57         fMessagesView = new BTextView( rect, "messages", textRect,
58                                        B_FOLLOW_ALL, B_WILL_DRAW );
59         fMessagesView->MakeEditable( false );
60         fMessagesView->SetStylable( true );
61         fScrollView = new BScrollView( "scrollview", fMessagesView, B_WILL_DRAW,
62                                        B_FOLLOW_ALL, false, true );
63         fScrollBar = fScrollView->ScrollBar( B_VERTICAL );
64         AddChild( fScrollView );
65         
66     /* start window thread in hidden state */
67     Hide();
68     Show();
69
70     /* update it */
71     if( vlc_thread_create( p_intf, "update messages", UpdateMessages,
72                            VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
73     {
74         msg_Err( p_intf, "cannot create update messages thread" );
75     }
76 }
77
78 /*****************************************************************************
79  * MessagesWindow::~MessagesWindow
80  *****************************************************************************/
81 MessagesWindow::~MessagesWindow()
82 {
83     vlc_thread_join( p_intf );
84 }
85
86 /*****************************************************************************
87  * MessagesWindow::FrameResized
88  *****************************************************************************/
89 void MessagesWindow::FrameResized( float width, float height )
90 {
91     BWindow::FrameResized( width, height );
92     BRect rect = fMessagesView->Bounds();
93     rect.InsetBy( 5, 5 );
94     fMessagesView->SetTextRect( rect );
95 }
96
97 /*****************************************************************************
98  * MessagesWindow::QuitRequested
99  *****************************************************************************/
100 bool MessagesWindow::QuitRequested()
101 {
102     Hide();
103     return false;
104 }
105
106 /*****************************************************************************
107  * MessagesWindow::ReallyQuit
108  *****************************************************************************/
109 void MessagesWindow::ReallyQuit()
110 {
111     Lock();
112     Hide();
113     Quit();
114 }
115
116 /*****************************************************************************
117  * UpdateMessages
118  *****************************************************************************/
119 static int UpdateMessages( intf_thread_t * p_intf )
120 {
121     /* workaround: wait a bit or it'll crash */
122     msleep( 500000 );
123
124     intf_sys_t * p_sys = (intf_sys_t*)p_intf->p_sys;
125     msg_subscription_t * p_sub = p_sys->p_sub;
126     MessagesWindow * messagesWindow = p_sys->p_window->fMessagesWindow;
127     BTextView * messagesView = messagesWindow->fMessagesView;
128     BScrollBar * scrollBar = messagesWindow->fScrollBar;
129
130     while( !p_intf->b_die )
131     {
132         int i_start, oldLength;
133         char * psz_module_type = NULL;
134         rgb_color red = { 200, 0, 0 };
135         rgb_color gray = { 150, 150, 150 };
136         rgb_color green = { 0, 150, 0 };
137         rgb_color orange = { 230, 180, 00 };
138         rgb_color color;
139     
140         vlc_mutex_lock( p_sub->p_lock );
141         int i_stop = *p_sub->pi_stop;
142         vlc_mutex_unlock( p_sub->p_lock );
143
144         if( p_sub->i_start != i_stop )
145         {
146             for( i_start = p_sub->i_start;
147                  i_start != i_stop;
148                  i_start = (i_start+1) % VLC_MSG_QSIZE )
149             {
150                 /* Add message */
151                 switch( p_sub->p_msg[i_start].i_type )
152                 {
153                     case VLC_MSG_INFO: color = green; break;
154                     case VLC_MSG_WARN: color = orange; break;
155                     case VLC_MSG_ERR: color = red; break;
156                     case VLC_MSG_DBG: color = gray; break;
157                 }
158             
159                 switch( p_sub->p_msg[i_start].i_object_type )
160                 {
161                     case VLC_OBJECT_ROOT: psz_module_type = "root"; break;
162                     case VLC_OBJECT_VLC: psz_module_type = "vlc"; break;
163                     case VLC_OBJECT_MODULE: psz_module_type = "module"; break;
164                     case VLC_OBJECT_INTF: psz_module_type = "interface"; break;
165                     case VLC_OBJECT_PLAYLIST: psz_module_type = "playlist"; break;
166                     case VLC_OBJECT_ITEM: psz_module_type = "item"; break;
167                     case VLC_OBJECT_INPUT: psz_module_type = "input"; break;
168                     case VLC_OBJECT_DECODER: psz_module_type = "decoder"; break;
169                     case VLC_OBJECT_VOUT: psz_module_type = "video output"; break;
170                     case VLC_OBJECT_AOUT: psz_module_type = "audio output"; break;
171                     case VLC_OBJECT_SOUT: psz_module_type = "stream output"; break;
172                 }
173    
174                 if ( messagesView->LockLooper() )
175                 {
176                     oldLength = messagesView->TextLength();
177                     BString string;
178                     string << p_sub->p_msg[i_start].psz_module << " " << psz_module_type << " : " <<
179                         p_sub->p_msg[i_start].psz_msg << "\n";
180                     messagesView->Insert( messagesView->TextLength(),
181                                           string.String(),
182                                           strlen( string.String() ) );
183                     messagesView->SetFontAndColor( oldLength,
184                                                    messagesView->TextLength(),
185                                                    NULL, 0, &color );
186                     messagesView->Draw( messagesView->Bounds() );
187                         messagesView->UnlockLooper();
188                 }
189             
190                 /* Scroll at the end */
191                 
192                 if( scrollBar->LockLooper() )
193                 {
194                     float min, max;
195                     scrollBar->GetRange( &min, &max );
196                     scrollBar->SetValue( max );
197                     scrollBar->UnlockLooper();
198                 }
199             }
200
201             vlc_mutex_lock( p_sub->p_lock );
202             p_sub->i_start = i_start;
203             vlc_mutex_unlock( p_sub->p_lock );
204         }
205         /* Wait a bit */
206         msleep( INTF_IDLE_SLEEP );
207     }
208     return 0;
209 }