1 /*****************************************************************************
2 * MessagesWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN
5 * $Id: MessagesWindow.cpp,v 1.8 2003/05/07 17:27:30 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;
49 SetSizeLimits( 200, 2000, 200, 2000 );
54 rect.right -= B_V_SCROLL_BAR_WIDTH;
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->MakeSelectable( false );
61 fMessagesView->SetStylable( true );
62 fScrollView = new BScrollView( "scrollview", fMessagesView, B_WILL_DRAW,
63 B_FOLLOW_ALL, false, true );
64 fScrollBar = fScrollView->ScrollBar( B_VERTICAL );
65 AddChild( fScrollView );
67 /* start window thread in hidden state */
72 if( vlc_thread_create( p_intf, "update messages", UpdateMessages,
73 VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
75 msg_Err( p_intf, "cannot create update messages thread" );
79 /*****************************************************************************
80 * MessagesWindow::~MessagesWindow
81 *****************************************************************************/
82 MessagesWindow::~MessagesWindow()
84 vlc_thread_join( p_intf );
87 /*****************************************************************************
88 * MessagesWindow::FrameResized
89 *****************************************************************************/
90 void MessagesWindow::FrameResized( float, float )
92 BRect rect = fMessagesView->Bounds();
94 fMessagesView->SetTextRect( rect );
97 /*****************************************************************************
98 * MessagesWindow::QuitRequested
99 *****************************************************************************/
100 bool MessagesWindow::QuitRequested()
106 /*****************************************************************************
107 * MessagesWindow::ReallyQuit
108 *****************************************************************************/
109 void MessagesWindow::ReallyQuit()
116 /*****************************************************************************
118 *****************************************************************************/
119 static int UpdateMessages( intf_thread_t * p_intf )
121 /* workaround: wait a bit or it'll crash */
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;
130 while( !p_intf->b_die )
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 };
140 vlc_mutex_lock( p_sub->p_lock );
141 int i_stop = *p_sub->pi_stop;
142 vlc_mutex_unlock( p_sub->p_lock );
144 if( p_sub->i_start != i_stop )
146 for( i_start = p_sub->i_start;
148 i_start = (i_start+1) % VLC_MSG_QSIZE )
151 switch( p_sub->p_msg[i_start].i_type )
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;
159 switch( p_sub->p_msg[i_start].i_object_type )
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;
174 if ( messagesView->LockLooper() )
176 oldLength = messagesView->TextLength();
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( string.String() );
181 messagesView->SetFontAndColor( oldLength,
182 messagesView->TextLength(),
184 messagesView->Draw( messagesView->Bounds() );
185 messagesView->UnlockLooper();
188 /* Scroll at the end */
190 if( scrollBar->LockLooper() )
193 scrollBar->GetRange( &min, &max );
194 scrollBar->SetValue( max );
195 scrollBar->UnlockLooper();
199 vlc_mutex_lock( p_sub->p_lock );
200 p_sub->i_start = i_start;
201 vlc_mutex_unlock( p_sub->p_lock );
204 msleep( INTF_IDLE_SLEEP );