1 /*****************************************************************************
2 * MessagesWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: MessagesWindow.cpp,v 1.2 2003/01/26 08:28:20 titer Exp $
7 * Authors: Eric Petit <titer@videolan.org>
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.
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.
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 *****************************************************************************/
25 #include <InterfaceKit.h>
26 #include <SupportKit.h>
32 /* BeOS module headers */
33 #include "VlcWrapper.h"
34 #include "MessagesWindow.h"
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,
44 this->p_intf = p_intf;
45 p_sub = p_intf->p_sys->p_sub;
50 rect.right -= B_V_SCROLL_BAR_WIDTH;
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 );
62 /* start window thread in hidden state */
67 /*****************************************************************************
68 * MessagesWindow::~MessagesWindow
69 *****************************************************************************/
70 MessagesWindow::~MessagesWindow()
74 /*****************************************************************************
75 * MessagesWindow::FrameResized
76 *****************************************************************************/
77 void MessagesWindow::FrameResized( float, float )
79 BRect rect = fMessagesView->Bounds();
81 fMessagesView->SetTextRect( rect );
84 /*****************************************************************************
85 * MessagesWindow::QuitRequested
86 *****************************************************************************/
87 bool MessagesWindow::QuitRequested()
93 /*****************************************************************************
94 * MessagesWindow::ReallyQuit
95 *****************************************************************************/
96 void MessagesWindow::ReallyQuit()
102 /*****************************************************************************
103 * MessagesWindow::UpdateMessages
104 *****************************************************************************/
105 void MessagesWindow::UpdateMessages()
107 int i_start, oldLength;
108 char * psz_module_type = NULL;
109 rgb_color red = { 200, 0, 0 };
110 rgb_color gray = { 150, 150, 150 };
111 rgb_color green = { 0, 150, 0 };
112 rgb_color orange = { 230, 180, 00 };
115 vlc_mutex_lock( p_sub->p_lock );
116 int i_stop = *p_sub->pi_stop;
117 vlc_mutex_unlock( p_sub->p_lock );
119 if( p_sub->i_start != i_stop )
121 for( i_start = p_sub->i_start;
123 i_start = (i_start+1) % VLC_MSG_QSIZE )
126 switch( p_sub->p_msg[i_start].i_type )
128 case VLC_MSG_INFO: color = green; break;
129 case VLC_MSG_WARN: color = orange; break;
130 case VLC_MSG_ERR: color = red; break;
131 case VLC_MSG_DBG: color = gray; break;
134 switch( p_sub->p_msg[i_start].i_object_type )
136 case VLC_OBJECT_ROOT: psz_module_type = "root"; break;
137 case VLC_OBJECT_VLC: psz_module_type = "vlc"; break;
138 case VLC_OBJECT_MODULE: psz_module_type = "module"; break;
139 case VLC_OBJECT_INTF: psz_module_type = "interface"; break;
140 case VLC_OBJECT_PLAYLIST: psz_module_type = "playlist"; break;
141 case VLC_OBJECT_ITEM: psz_module_type = "item"; break;
142 case VLC_OBJECT_INPUT: psz_module_type = "input"; break;
143 case VLC_OBJECT_DECODER: psz_module_type = "decoder"; break;
144 case VLC_OBJECT_VOUT: psz_module_type = "video output"; break;
145 case VLC_OBJECT_AOUT: psz_module_type = "audio output"; break;
146 case VLC_OBJECT_SOUT: psz_module_type = "stream output"; break;
149 fMessagesView->LockLooper();
150 oldLength = fMessagesView->TextLength();
152 string.Append( p_sub->p_msg[i_start].psz_module );
153 string.Append( " " );
154 string.Append( psz_module_type );
155 string.Append( " : " );
156 string.Append( p_sub->p_msg[i_start].psz_msg );
157 string.Append( "\n" );
158 fMessagesView->Insert( string.String() );
159 fMessagesView->SetFontAndColor( oldLength,
160 fMessagesView->TextLength(),
162 fMessagesView->Draw( fMessagesView->Bounds() );
163 fMessagesView->UnlockLooper();
165 /* Scroll at the end */
166 fScrollBar->LockLooper();
168 fScrollBar->GetRange( &min, &max );
169 fScrollBar->SetValue( max );
170 fScrollBar->UnlockLooper();
173 vlc_mutex_lock( p_sub->p_lock );
174 p_sub->i_start = i_start;
175 vlc_mutex_unlock( p_sub->p_lock );