1 /*****************************************************************************
2 * MessagesWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: MessagesWindow.cpp,v 1.7 2003/02/10 15:23:46 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 "InterfaceWindow.h"
35 #include "MessagesWindow.h"
37 static int UpdateMessages( intf_thread_t * p_intf );
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,
47 this->p_intf = p_intf;
52 rect.right -= B_V_SCROLL_BAR_WIDTH;
54 textRect.InsetBy( 5, 5 );
55 fMessagesView = new BTextView( rect, "messages", textRect,
56 B_FOLLOW_ALL, B_WILL_DRAW );
57 fMessagesView->MakeEditable( false );
58 fMessagesView->SetStylable( true );
59 fScrollView = new BScrollView( "scrollview", fMessagesView, B_WILL_DRAW,
60 B_FOLLOW_ALL, false, true );
61 fScrollBar = fScrollView->ScrollBar( B_VERTICAL );
62 AddChild( fScrollView );
64 /* start window thread in hidden state */
69 if( vlc_thread_create( p_intf, "update messages", UpdateMessages,
70 VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
72 msg_Err( p_intf, "cannot create update messages thread" );
76 /*****************************************************************************
77 * MessagesWindow::~MessagesWindow
78 *****************************************************************************/
79 MessagesWindow::~MessagesWindow()
81 vlc_thread_join( p_intf );
84 /*****************************************************************************
85 * MessagesWindow::FrameResized
86 *****************************************************************************/
87 void MessagesWindow::FrameResized( float, float )
89 BRect rect = fMessagesView->Bounds();
91 fMessagesView->SetTextRect( rect );
94 /*****************************************************************************
95 * MessagesWindow::QuitRequested
96 *****************************************************************************/
97 bool MessagesWindow::QuitRequested()
103 /*****************************************************************************
104 * MessagesWindow::ReallyQuit
105 *****************************************************************************/
106 void MessagesWindow::ReallyQuit()
113 /*****************************************************************************
115 *****************************************************************************/
116 static int UpdateMessages( intf_thread_t * p_intf )
118 /* workaround: wait a bit or it'll crash */
121 intf_sys_t * p_sys = (intf_sys_t*)p_intf->p_sys;
122 msg_subscription_t * p_sub = p_sys->p_sub;
123 MessagesWindow * messagesWindow = p_sys->p_window->fMessagesWindow;
124 BTextView * messagesView = messagesWindow->fMessagesView;
125 BScrollBar * scrollBar = messagesWindow->fScrollBar;
127 while( !p_intf->b_die )
129 int i_start, oldLength;
130 char * psz_module_type = NULL;
131 rgb_color red = { 200, 0, 0 };
132 rgb_color gray = { 150, 150, 150 };
133 rgb_color green = { 0, 150, 0 };
134 rgb_color orange = { 230, 180, 00 };
137 vlc_mutex_lock( p_sub->p_lock );
138 int i_stop = *p_sub->pi_stop;
139 vlc_mutex_unlock( p_sub->p_lock );
141 if( p_sub->i_start != i_stop )
143 for( i_start = p_sub->i_start;
145 i_start = (i_start+1) % VLC_MSG_QSIZE )
148 switch( p_sub->p_msg[i_start].i_type )
150 case VLC_MSG_INFO: color = green; break;
151 case VLC_MSG_WARN: color = orange; break;
152 case VLC_MSG_ERR: color = red; break;
153 case VLC_MSG_DBG: color = gray; break;
156 switch( p_sub->p_msg[i_start].i_object_type )
158 case VLC_OBJECT_ROOT: psz_module_type = "root"; break;
159 case VLC_OBJECT_VLC: psz_module_type = "vlc"; break;
160 case VLC_OBJECT_MODULE: psz_module_type = "module"; break;
161 case VLC_OBJECT_INTF: psz_module_type = "interface"; break;
162 case VLC_OBJECT_PLAYLIST: psz_module_type = "playlist"; break;
163 case VLC_OBJECT_ITEM: psz_module_type = "item"; break;
164 case VLC_OBJECT_INPUT: psz_module_type = "input"; break;
165 case VLC_OBJECT_DECODER: psz_module_type = "decoder"; break;
166 case VLC_OBJECT_VOUT: psz_module_type = "video output"; break;
167 case VLC_OBJECT_AOUT: psz_module_type = "audio output"; break;
168 case VLC_OBJECT_SOUT: psz_module_type = "stream output"; break;
171 if ( messagesView->LockLooper() )
173 oldLength = messagesView->TextLength();
175 string << p_sub->p_msg[i_start].psz_module << " " << psz_module_type << " : " <<
176 p_sub->p_msg[i_start].psz_msg << "\n";
177 messagesView->Insert( string.String() );
178 messagesView->SetFontAndColor( oldLength,
179 messagesView->TextLength(),
181 messagesView->Draw( messagesView->Bounds() );
182 messagesView->UnlockLooper();
185 /* Scroll at the end */
186 if( scrollBar->LockLooper() )
189 scrollBar->GetRange( &min, &max );
190 scrollBar->SetValue( max );
191 scrollBar->UnlockLooper();
195 vlc_mutex_lock( p_sub->p_lock );
196 p_sub->i_start = i_start;
197 vlc_mutex_unlock( p_sub->p_lock );
200 msleep( INTF_IDLE_SLEEP );