]> git.sesse.net Git - vlc/blob - modules/gui/beos/MessagesWindow.cpp
* sanity Lock()s
[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.4 2003/01/28 10:05:15 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 "MessagesWindow.h"
35
36 /*****************************************************************************
37  * MessagesWindow::MessagesWindow
38  *****************************************************************************/
39 MessagesWindow::MessagesWindow( intf_thread_t * p_intf,
40                                 BRect frame, const char * name )
41         : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
42                B_NOT_ZOOMABLE )
43 {
44         this->p_intf = p_intf;
45         p_sub = p_intf->p_sys->p_sub;
46         
47         BRect rect, textRect;
48         
49         rect = Bounds();
50         rect.right -= B_V_SCROLL_BAR_WIDTH;
51         textRect = rect;
52         textRect.InsetBy( 5, 5 );
53         fMessagesView = new BTextView( rect, "messages", textRect,
54                                        B_FOLLOW_ALL, B_WILL_DRAW );
55         fMessagesView->MakeEditable( false );
56         fMessagesView->SetStylable( true );
57         fScrollView = new BScrollView( "scrollview", fMessagesView, B_WILL_DRAW,
58                                        B_FOLLOW_ALL, false, true );
59         fScrollBar = fScrollView->ScrollBar( B_VERTICAL );
60         AddChild( fScrollView );
61         
62     /* start window thread in hidden state */
63     Hide();
64     Show();
65 }
66
67 /*****************************************************************************
68  * MessagesWindow::~MessagesWindow
69  *****************************************************************************/
70 MessagesWindow::~MessagesWindow()
71 {
72 }
73
74 /*****************************************************************************
75  * MessagesWindow::FrameResized
76  *****************************************************************************/
77 void MessagesWindow::FrameResized( float, float )
78 {
79     BRect rect = fMessagesView->Bounds();
80     rect.InsetBy( 5, 5 );
81     fMessagesView->SetTextRect( rect );
82 }
83
84 /*****************************************************************************
85  * MessagesWindow::QuitRequested
86  *****************************************************************************/
87 bool MessagesWindow::QuitRequested()
88 {
89     Hide();
90     return false;
91 }
92
93 /*****************************************************************************
94  * MessagesWindow::ReallyQuit
95  *****************************************************************************/
96 void MessagesWindow::ReallyQuit()
97 {
98     Lock();
99     Hide();
100     Quit();
101 }
102
103 /*****************************************************************************
104  * MessagesWindow::UpdateMessages
105  *****************************************************************************/
106 void MessagesWindow::UpdateMessages()
107 {
108     int i_start, oldLength;
109     char * psz_module_type = NULL;
110     rgb_color red = { 200, 0, 0 };
111     rgb_color gray = { 150, 150, 150 };
112     rgb_color green = { 0, 150, 0 };
113     rgb_color orange = { 230, 180, 00 };
114     rgb_color color;
115     
116     vlc_mutex_lock( p_sub->p_lock );
117     int i_stop = *p_sub->pi_stop;
118     vlc_mutex_unlock( p_sub->p_lock );
119
120     if( p_sub->i_start != i_stop )
121     {
122         for( i_start = p_sub->i_start;
123              i_start != i_stop;
124              i_start = (i_start+1) % VLC_MSG_QSIZE )
125         {
126             /* Add message */
127             switch( p_sub->p_msg[i_start].i_type )
128             {
129                 case VLC_MSG_INFO: color = green; break;
130                 case VLC_MSG_WARN: color = orange; break;
131                 case VLC_MSG_ERR: color = red; break;
132                 case VLC_MSG_DBG: color = gray; break;
133             }
134             
135             switch( p_sub->p_msg[i_start].i_object_type )
136             {
137                 case VLC_OBJECT_ROOT: psz_module_type = "root"; break;
138                 case VLC_OBJECT_VLC: psz_module_type = "vlc"; break;
139                 case VLC_OBJECT_MODULE: psz_module_type = "module"; break;
140                 case VLC_OBJECT_INTF: psz_module_type = "interface"; break;
141                 case VLC_OBJECT_PLAYLIST: psz_module_type = "playlist"; break;
142                 case VLC_OBJECT_ITEM: psz_module_type = "item"; break;
143                 case VLC_OBJECT_INPUT: psz_module_type = "input"; break;
144                 case VLC_OBJECT_DECODER: psz_module_type = "decoder"; break;
145                 case VLC_OBJECT_VOUT: psz_module_type = "video output"; break;
146                 case VLC_OBJECT_AOUT: psz_module_type = "audio output"; break;
147                 case VLC_OBJECT_SOUT: psz_module_type = "stream output"; break;
148             }
149             
150             fMessagesView->LockLooper();
151             oldLength = fMessagesView->TextLength();
152             BString string;
153             string.Append( p_sub->p_msg[i_start].psz_module );
154             string.Append( " " );
155             string.Append( psz_module_type );
156             string.Append( " : " );
157             string.Append( p_sub->p_msg[i_start].psz_msg );
158             string.Append( "\n" );
159             fMessagesView->Insert( string.String() );
160             fMessagesView->SetFontAndColor( oldLength,
161                                             fMessagesView->TextLength(),
162                                             NULL, 0, &color );
163             fMessagesView->Draw( fMessagesView->Bounds() );
164             fMessagesView->UnlockLooper();
165             
166             /* Scroll at the end */
167             if( fScrollBar->LockLooper() )
168             {
169                 float min, max;
170                 fScrollBar->GetRange( &min, &max );
171                 fScrollBar->SetValue( max );
172                 fScrollBar->UnlockLooper();
173             }
174         }
175
176         vlc_mutex_lock( p_sub->p_lock );
177         p_sub->i_start = i_start;
178         vlc_mutex_unlock( p_sub->p_lock );
179     }
180 }