1 /*****************************************************************************
2 * playlist.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: messages.cpp,v 1.3 2003/04/06 16:30:43 gbazin Exp $
7 * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
34 #ifdef WIN32 /* mingw32 hack */
39 /* Let vlc take care of the i18n stuff */
40 #define WXINTL_NO_GETTEXT_MACRO
42 #include <wx/wxprec.h>
44 #include <wx/textctrl.h>
48 #include "wxwindows.h"
50 /*****************************************************************************
52 *****************************************************************************/
54 /* IDs for the controls and the menu commands */
61 BEGIN_EVENT_TABLE(Messages, wxFrame)
63 EVT_BUTTON(wxID_OK, Messages::OnClose)
64 EVT_CHECKBOX(Verbose_Event, Messages::OnVerbose)
66 /* Special events : we don't want to destroy the window when the user
68 EVT_CLOSE(Messages::OnClose)
71 /*****************************************************************************
73 *****************************************************************************/
74 Messages::Messages( intf_thread_t *_p_intf, Interface *_p_main_interface ):
75 wxFrame( _p_main_interface, -1, "Messages", wxDefaultPosition,
76 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
80 p_main_interface = _p_main_interface;
81 b_verbose = VLC_FALSE;
82 SetIcon( *p_intf->p_sys->p_icon );
84 /* Create a panel to put everything in */
85 wxPanel *messages_panel = new wxPanel( this, -1 );
86 messages_panel->SetAutoLayout( TRUE );
88 /* Create the textctrl and some text attributes */
89 textctrl = new wxTextCtrl( messages_panel, -1, "", wxDefaultPosition,
90 wxSize::wxSize( 400, 500 ), wxTE_MULTILINE | wxTE_READONLY |
91 wxTE_RICH | wxTE_NOHIDESEL );
92 info_attr = new wxTextAttr( wxColour::wxColour( 0, 128, 0 ) );
93 err_attr = new wxTextAttr( *wxRED );
94 warn_attr = new wxTextAttr( *wxBLUE );
95 dbg_attr = new wxTextAttr( *wxBLACK );
97 /* Create the OK button */
98 wxButton *ok_button = new wxButton( messages_panel, wxID_OK, _("OK") );
99 ok_button->SetDefault();
101 /* Create the Verbose checkbox */
102 wxCheckBox *verbose_checkbox =
103 new wxCheckBox( messages_panel, Verbose_Event, _("Verbose") );
105 /* Place everything in sizers */
106 wxBoxSizer *buttons_sizer = new wxBoxSizer( wxHORIZONTAL );
107 buttons_sizer->Add( ok_button, 0, wxEXPAND |wxALIGN_LEFT| wxALL, 5 );
108 buttons_sizer->Add( new wxPanel( this, -1 ), 1, wxALL, 5 );
109 buttons_sizer->Add( verbose_checkbox, 0, wxEXPAND |wxALIGN_RIGHT | wxALL, 5 );
110 buttons_sizer->Layout();
111 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
112 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
113 panel_sizer->Add( textctrl, 1, wxEXPAND | wxALL, 5 );
114 panel_sizer->Add( buttons_sizer, 0, wxEXPAND | wxALL, 5 );
115 panel_sizer->Layout();
116 messages_panel->SetSizerAndFit( panel_sizer );
117 main_sizer->Add( messages_panel, 1, wxGROW, 0 );
118 main_sizer->Layout();
119 SetSizerAndFit( main_sizer );
122 Messages::~Messages()
126 void Messages::UpdateLog()
128 msg_subscription_t *p_sub = p_intf->p_sys->p_sub;
131 vlc_mutex_lock( p_sub->p_lock );
132 int i_stop = *p_sub->pi_stop;
133 vlc_mutex_unlock( p_sub->p_lock );
135 if( p_sub->i_start != i_stop )
137 for( i_start = p_sub->i_start;
139 i_start = (i_start+1) % VLC_MSG_QSIZE )
143 VLC_MSG_ERR != p_sub->p_msg[i_start].i_type &&
144 VLC_MSG_INFO != p_sub->p_msg[i_start].i_type )
147 /* Append all messages to log window */
148 textctrl->SetDefaultStyle( *dbg_attr );
149 (*textctrl) << p_sub->p_msg[i_start].psz_module;
151 switch( p_sub->p_msg[i_start].i_type )
155 textctrl->SetDefaultStyle( *info_attr );
158 (*textctrl) << " error: ";
159 textctrl->SetDefaultStyle( *err_attr );
162 (*textctrl) << " warning: ";
163 textctrl->SetDefaultStyle( *warn_attr );
167 (*textctrl) << " debug: ";
172 (*textctrl) << p_sub->p_msg[i_start].psz_msg << "\n";
175 vlc_mutex_lock( p_sub->p_lock );
176 p_sub->i_start = i_start;
177 vlc_mutex_unlock( p_sub->p_lock );
181 /*****************************************************************************
183 *****************************************************************************/
184 void Messages::OnClose( wxCommandEvent& WXUNUSED(event) )
189 void Messages::OnVerbose( wxCommandEvent& event )
191 b_verbose = event.IsChecked();