Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

MessagesWindow.cpp

00001 /*****************************************************************************
00002  * MessagesWindow.cpp: beos interface
00003  *****************************************************************************
00004  * Copyright (C) 1999, 2000, 2001 the VideoLAN team
00005  * $Id: MessagesWindow.cpp 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Eric Petit <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /* BeOS headers */
00025 #include <InterfaceKit.h>
00026 #include <SupportKit.h>
00027 
00028 /* VLC headers */
00029 #include <vlc/vlc.h>
00030 #include <vlc/intf.h>
00031 
00032 /* BeOS module headers */
00033 #include "InterfaceWindow.h"
00034 #include "MessagesWindow.h"
00035 
00036 /*****************************************************************************
00037  * MessagesView::Pulse
00038  *****************************************************************************/
00039 void MessagesView::Pulse()
00040 {
00041     bool isScrolling = false;
00042     if( fScrollBar->LockLooper() )
00043     {
00044         float min, max;
00045         fScrollBar->GetRange( &min, &max );
00046         if( fScrollBar->Value() != max )
00047             isScrolling = true;
00048         fScrollBar->UnlockLooper();
00049 
00050     }
00051 
00052     int i_start, oldLength;
00053     char * psz_module_type = NULL;
00054     rgb_color red = { 200, 0, 0 };
00055     rgb_color gray = { 150, 150, 150 };
00056     rgb_color green = { 0, 150, 0 };
00057     rgb_color orange = { 230, 180, 00 };
00058     rgb_color color;
00059 
00060     vlc_mutex_lock( p_sub->p_lock );
00061     int i_stop = *p_sub->pi_stop;
00062     vlc_mutex_unlock( p_sub->p_lock );
00063 
00064     if( p_sub->i_start != i_stop )
00065     {
00066         for( i_start = p_sub->i_start;
00067              i_start != i_stop;
00068                  i_start = (i_start+1) % VLC_MSG_QSIZE )
00069         {
00070             /* Add message */
00071             switch( p_sub->p_msg[i_start].i_type )
00072             {
00073                 case VLC_MSG_INFO: color = green; break;
00074                 case VLC_MSG_WARN: color = orange; break;
00075                 case VLC_MSG_ERR: color = red; break;
00076                 case VLC_MSG_DBG: color = gray; break;
00077             }
00078 
00079             switch( p_sub->p_msg[i_start].i_object_type )
00080             {
00081                 case VLC_OBJECT_ROOT: psz_module_type = "root"; break;
00082                 case VLC_OBJECT_VLC: psz_module_type = "vlc"; break;
00083                 case VLC_OBJECT_MODULE: psz_module_type = "module"; break;
00084                 case VLC_OBJECT_INTF: psz_module_type = "interface"; break;
00085                 case VLC_OBJECT_PLAYLIST: psz_module_type = "playlist"; break;
00086                 case VLC_OBJECT_ITEM: psz_module_type = "item"; break;
00087                 case VLC_OBJECT_INPUT: psz_module_type = "input"; break;
00088                 case VLC_OBJECT_DECODER: psz_module_type = "decoder"; break;
00089                 case VLC_OBJECT_VOUT: psz_module_type = "video output"; break;
00090                 case VLC_OBJECT_AOUT: psz_module_type = "audio output"; break;
00091                 case VLC_OBJECT_SOUT: psz_module_type = "stream output"; break;
00092             }
00093 
00094             if( LockLooper() )
00095             {
00096                 oldLength = TextLength();
00097                 BString string;
00098                 string << p_sub->p_msg[i_start].psz_module
00099                     << " " << psz_module_type << " : "
00100                     << p_sub->p_msg[i_start].psz_msg << "\n";
00101                 Insert( TextLength(), string.String(), strlen( string.String() ) );
00102                 SetFontAndColor( oldLength, TextLength(), NULL, 0, &color );
00103                 Draw( Bounds() );
00104                 UnlockLooper();
00105             }
00106         }
00107 
00108         vlc_mutex_lock( p_sub->p_lock );
00109         p_sub->i_start = i_start;
00110         vlc_mutex_unlock( p_sub->p_lock );
00111     }
00112 
00113     /* Scroll at the end unless the is user is scrolling or selecting something */
00114     int32 start, end;
00115     GetSelection( &start, &end );
00116     if( !isScrolling && start == end && fScrollBar->LockLooper() )
00117     {
00118         float min, max;
00119         fScrollBar->GetRange( &min, &max );
00120         fScrollBar->SetValue( max );
00121         fScrollBar->UnlockLooper();
00122     }
00123 
00124     BTextView::Pulse();
00125 }
00126 
00127 /*****************************************************************************
00128  * MessagesWindow::MessagesWindow
00129  *****************************************************************************/
00130 MessagesWindow::MessagesWindow( intf_thread_t * _p_intf,
00131                                 BRect frame, const char * name )
00132     : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
00133                B_NOT_ZOOMABLE ),
00134     p_intf(_p_intf)
00135 {
00136     SetSizeLimits( 400, 2000, 200, 2000 );
00137 
00138     p_sub = msg_Subscribe( p_intf );
00139     
00140     BRect rect, textRect;
00141 
00142     rect = Bounds();
00143     rect.right -= B_V_SCROLL_BAR_WIDTH;
00144     textRect = rect;
00145     textRect.InsetBy( 5, 5 );
00146     fMessagesView = new MessagesView( p_sub,
00147                                       rect, "messages", textRect,
00148                                       B_FOLLOW_ALL, B_WILL_DRAW );
00149     fMessagesView->MakeEditable( false );
00150     fMessagesView->SetStylable( true );
00151     fScrollView = new BScrollView( "scrollview", fMessagesView, B_WILL_DRAW,
00152                                    B_FOLLOW_ALL, false, true );
00153     fMessagesView->fScrollBar = fScrollView->ScrollBar( B_VERTICAL );
00154     AddChild( fScrollView );
00155     
00156     /* start window thread in hidden state */
00157     Hide();
00158     Show();
00159 }
00160 
00161 /*****************************************************************************
00162  * MessagesWindow::~MessagesWindow
00163  *****************************************************************************/
00164 MessagesWindow::~MessagesWindow()
00165 {
00166      msg_Unsubscribe( p_intf, p_sub );
00167 }
00168 
00169 /*****************************************************************************
00170  * MessagesWindow::FrameResized
00171  *****************************************************************************/
00172 void MessagesWindow::FrameResized( float width, float height )
00173 {
00174     BWindow::FrameResized( width, height );
00175     BRect rect = fMessagesView->Bounds();
00176     rect.InsetBy( 5, 5 );
00177     fMessagesView->SetTextRect( rect );
00178 }
00179 
00180 /*****************************************************************************
00181  * MessagesWindow::QuitRequested
00182  *****************************************************************************/
00183 bool MessagesWindow::QuitRequested()
00184 {
00185     Hide();
00186     return false;
00187 }
00188 
00189 /*****************************************************************************
00190  * MessagesWindow::ReallyQuit
00191  *****************************************************************************/
00192 void MessagesWindow::ReallyQuit()
00193 {
00194     Lock();
00195     Hide();
00196     Quit();
00197 }

Generated on Tue Dec 20 10:14:37 2005 for vlc-0.8.4a by  doxygen 1.4.2