]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/messages.cpp
corrected a newbie notation
[vlc] / modules / gui / wxwindows / messages.cpp
1 /*****************************************************************************
2  * playlist.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2001 VideoLAN
5  * $Id: messages.cpp,v 1.9 2003/07/09 10:59:11 adn Exp $
6  *
7  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <string.h>                                            /* strerror() */
30 #include <stdio.h>
31
32 #include <vlc/vlc.h>
33
34 #ifdef WIN32                                                 /* mingw32 hack */
35 #undef Yield
36 #undef CreateDialog
37 #endif
38
39 /* Let vlc take care of the i18n stuff */
40 #define WXINTL_NO_GETTEXT_MACRO
41
42 #include <wx/wxprec.h>
43 #include <wx/wx.h>
44 #include <wx/textctrl.h>
45
46 #include <vlc/intf.h>
47
48 #if defined MODULE_NAME_IS_skins
49 #   include "../skins/src/skin_common.h"
50 #endif
51
52 #include "wxwindows.h"
53
54 /*****************************************************************************
55  * Event Table.
56  *****************************************************************************/
57
58 /* IDs for the controls and the menu commands */
59 enum
60 {
61     Close_Event,
62     Verbose_Event
63 };
64
65 BEGIN_EVENT_TABLE(Messages, wxFrame)
66     /* Button events */
67     EVT_BUTTON(wxID_OK, Messages::OnClose)
68     EVT_CHECKBOX(Verbose_Event, Messages::OnVerbose)
69     EVT_BUTTON(wxID_CLEAR, Messages::OnClear)
70
71     /* Special events : we don't want to destroy the window when the user
72      * clicks on (X) */
73     EVT_CLOSE(Messages::OnClose)
74 END_EVENT_TABLE()
75
76 /*****************************************************************************
77  * Constructor.
78  *****************************************************************************/
79 Messages::Messages( intf_thread_t *_p_intf, wxWindow *p_parent ):
80     wxFrame( p_parent, -1, wxU(_("Messages")), wxDefaultPosition,
81              wxDefaultSize, wxDEFAULT_FRAME_STYLE )
82 {
83     /* Initializations */
84     p_intf = _p_intf;
85     b_verbose = VLC_FALSE;
86     SetIcon( *p_intf->p_sys->p_icon );
87
88     /* Create a panel to put everything in */
89     wxPanel *messages_panel = new wxPanel( this, -1 );
90     messages_panel->SetAutoLayout( TRUE );
91
92     /* Create the textctrl and some text attributes */
93     textctrl = new wxTextCtrl( messages_panel, -1, wxT(""), wxDefaultPosition,
94         wxSize::wxSize( 400, 500 ), wxTE_MULTILINE | wxTE_READONLY |
95                                     wxTE_RICH | wxTE_NOHIDESEL );
96     info_attr = new wxTextAttr( wxColour::wxColour( 0, 128, 0 ) );
97     err_attr = new wxTextAttr( *wxRED );
98     warn_attr = new wxTextAttr( *wxBLUE );
99     dbg_attr = new wxTextAttr( *wxBLACK );
100
101     /* Create the OK button */
102     wxButton *ok_button = new wxButton( messages_panel, wxID_OK, wxU(_("OK")));
103     ok_button->SetDefault();
104
105     /* Create the Clear button */
106     wxButton *clear_button = new wxButton( messages_panel, wxID_CLEAR, wxU(_("Clear")));
107     clear_button->SetDefault();
108
109     /* Create the Verbose checkbox */
110     wxCheckBox *verbose_checkbox =
111         new wxCheckBox( messages_panel, Verbose_Event, wxU(_("Verbose")) );
112
113     /* Place everything in sizers */
114     wxBoxSizer *buttons_sizer = new wxBoxSizer( wxHORIZONTAL );
115     buttons_sizer->Add( ok_button, 0, wxEXPAND |wxALIGN_LEFT| wxALL, 5 );
116     buttons_sizer->Add( clear_button, 0, wxEXPAND |wxALIGN_LEFT| wxALL, 5 );
117     buttons_sizer->Add( new wxPanel( this, -1 ), 1, wxALL, 5 );
118     buttons_sizer->Add( verbose_checkbox, 0, wxEXPAND |wxALIGN_RIGHT | wxALL, 5 );
119     buttons_sizer->Layout();
120     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
121     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
122     panel_sizer->Add( textctrl, 1, wxEXPAND | wxALL, 5 );
123     panel_sizer->Add( buttons_sizer, 0, wxEXPAND | wxALL, 5 );
124     panel_sizer->Layout();
125     messages_panel->SetSizerAndFit( panel_sizer );
126     main_sizer->Add( messages_panel, 1, wxGROW, 0 );
127     main_sizer->Layout();
128     SetSizerAndFit( main_sizer );
129 }
130
131 Messages::~Messages()
132 {
133 }
134
135 void Messages::UpdateLog()
136 {
137     msg_subscription_t *p_sub = p_intf->p_sys->p_sub;
138     int i_start;
139
140     vlc_mutex_lock( p_sub->p_lock );
141     int i_stop = *p_sub->pi_stop;
142     vlc_mutex_unlock( p_sub->p_lock );
143
144     if( p_sub->i_start != i_stop )
145     {
146         for( i_start = p_sub->i_start;
147              i_start != i_stop;
148              i_start = (i_start+1) % VLC_MSG_QSIZE )
149         {
150
151             if( !b_verbose &&
152                 VLC_MSG_ERR != p_sub->p_msg[i_start].i_type &&
153                 VLC_MSG_INFO != p_sub->p_msg[i_start].i_type )
154                 continue;
155
156             /* Append all messages to log window */
157             textctrl->SetDefaultStyle( *dbg_attr );
158             (*textctrl) << wxU(p_sub->p_msg[i_start].psz_module);
159
160             switch( p_sub->p_msg[i_start].i_type )
161             {
162             case VLC_MSG_INFO:
163                 (*textctrl) << wxT(": ");
164                 textctrl->SetDefaultStyle( *info_attr );
165                 break;
166             case VLC_MSG_ERR:
167                 (*textctrl) << wxT(" error: ");
168                 textctrl->SetDefaultStyle( *err_attr );
169                 break;
170             case VLC_MSG_WARN:
171                 (*textctrl) << wxT(" warning: ");
172                 textctrl->SetDefaultStyle( *warn_attr );
173                 break;
174             case VLC_MSG_DBG:
175             default:
176                 (*textctrl) << wxT(" debug: ");
177                 break;
178             }
179
180             /* Add message */
181             (*textctrl) << wxU(p_sub->p_msg[i_start].psz_msg) << wxT("\n");
182         }
183
184         vlc_mutex_lock( p_sub->p_lock );
185         p_sub->i_start = i_start;
186         vlc_mutex_unlock( p_sub->p_lock );
187     }
188 }
189
190 /*****************************************************************************
191  * Private methods.
192  *****************************************************************************/
193 void Messages::OnClose( wxCommandEvent& WXUNUSED(event) )
194 {
195     Hide();
196 }
197
198 void Messages::OnClear( wxCommandEvent& WXUNUSED(event) )
199 {
200     textctrl->Clear();
201 }
202
203 void Messages::OnVerbose( wxCommandEvent& event )
204 {
205     b_verbose = event.IsChecked();
206 }