1 /*****************************************************************************
2 * playlist.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: messages.cpp,v 1.10 2003/07/10 11:15:18 adn 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 #if defined MODULE_NAME_IS_skins
49 # include "../skins/src/skin_common.h"
52 #include "wxwindows.h"
54 /*****************************************************************************
56 *****************************************************************************/
58 /* IDs for the controls and the menu commands */
67 BEGIN_EVENT_TABLE(Messages, wxFrame)
69 EVT_BUTTON(wxID_OK, Messages::OnClose)
70 EVT_CHECKBOX(Verbose_Event, Messages::OnVerbose)
71 EVT_BUTTON(wxID_CLEAR, Messages::OnClear)
72 EVT_BUTTON(wxID_SAVEAS, Messages::OnSaveLog)
74 /* Special events : we don't want to destroy the window when the user
76 EVT_CLOSE(Messages::OnClose)
79 /*****************************************************************************
81 *****************************************************************************/
82 Messages::Messages( intf_thread_t *_p_intf, wxWindow *p_parent ):
83 wxFrame( p_parent, -1, wxU(_("Messages")), wxDefaultPosition,
84 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
88 b_verbose = VLC_FALSE;
89 SetIcon( *p_intf->p_sys->p_icon );
90 save_log_dialog = NULL;
92 /* Create a panel to put everything in */
93 wxPanel *messages_panel = new wxPanel( this, -1 );
94 messages_panel->SetAutoLayout( TRUE );
96 /* Create the textctrl and some text attributes */
97 textctrl = new wxTextCtrl( messages_panel, -1, wxT(""), wxDefaultPosition,
98 wxSize::wxSize( 400, 500 ), wxTE_MULTILINE | wxTE_READONLY |
99 wxTE_RICH | wxTE_NOHIDESEL );
100 info_attr = new wxTextAttr( wxColour::wxColour( 0, 128, 0 ) );
101 err_attr = new wxTextAttr( *wxRED );
102 warn_attr = new wxTextAttr( *wxBLUE );
103 dbg_attr = new wxTextAttr( *wxBLACK );
105 /* Create the OK button */
106 wxButton *ok_button = new wxButton( messages_panel, wxID_OK, wxU(_("OK")));
107 ok_button->SetDefault();
109 /* Create the Clear button */
110 wxButton *clear_button = new wxButton( messages_panel, wxID_CLEAR, wxU(_("Clear")));
111 clear_button->SetDefault();
113 /* Create the Save Log button */
114 wxButton *save_log_button = new wxButton( messages_panel, wxID_SAVEAS, wxU(_("Save As...")));
115 save_log_button->SetDefault();
117 /* Create the Verbose checkbox */
118 wxCheckBox *verbose_checkbox =
119 new wxCheckBox( messages_panel, Verbose_Event, wxU(_("Verbose")) );
121 /* Place everything in sizers */
122 wxBoxSizer *buttons_sizer = new wxBoxSizer( wxHORIZONTAL );
123 buttons_sizer->Add( ok_button, 0, wxEXPAND |wxALIGN_LEFT| wxALL, 5 );
124 buttons_sizer->Add( clear_button, 0, wxEXPAND |wxALIGN_LEFT| wxALL, 5 );
125 buttons_sizer->Add( save_log_button, 0, wxEXPAND |wxALIGN_LEFT| wxALL, 5 );
126 buttons_sizer->Add( new wxPanel( this, -1 ), 1, wxALL, 5 );
127 buttons_sizer->Add( verbose_checkbox, 0, wxEXPAND |wxALIGN_RIGHT | wxALL, 5 );
128 buttons_sizer->Layout();
129 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
130 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
131 panel_sizer->Add( textctrl, 1, wxEXPAND | wxALL, 5 );
132 panel_sizer->Add( buttons_sizer, 0, wxEXPAND | wxALL, 5 );
133 panel_sizer->Layout();
134 messages_panel->SetSizerAndFit( panel_sizer );
135 main_sizer->Add( messages_panel, 1, wxGROW, 0 );
136 main_sizer->Layout();
137 SetSizerAndFit( main_sizer );
140 Messages::~Messages()
143 if( save_log_dialog ) delete save_log_dialog;
146 void Messages::UpdateLog()
148 msg_subscription_t *p_sub = p_intf->p_sys->p_sub;
151 vlc_mutex_lock( p_sub->p_lock );
152 int i_stop = *p_sub->pi_stop;
153 vlc_mutex_unlock( p_sub->p_lock );
155 if( p_sub->i_start != i_stop )
157 for( i_start = p_sub->i_start;
159 i_start = (i_start+1) % VLC_MSG_QSIZE )
163 VLC_MSG_ERR != p_sub->p_msg[i_start].i_type &&
164 VLC_MSG_INFO != p_sub->p_msg[i_start].i_type )
167 /* Append all messages to log window */
168 textctrl->SetDefaultStyle( *dbg_attr );
169 (*textctrl) << wxU(p_sub->p_msg[i_start].psz_module);
171 switch( p_sub->p_msg[i_start].i_type )
174 (*textctrl) << wxT(": ");
175 textctrl->SetDefaultStyle( *info_attr );
178 (*textctrl) << wxT(" error: ");
179 textctrl->SetDefaultStyle( *err_attr );
182 (*textctrl) << wxT(" warning: ");
183 textctrl->SetDefaultStyle( *warn_attr );
187 (*textctrl) << wxT(" debug: ");
192 (*textctrl) << wxU(p_sub->p_msg[i_start].psz_msg) << wxT("\n");
195 vlc_mutex_lock( p_sub->p_lock );
196 p_sub->i_start = i_start;
197 vlc_mutex_unlock( p_sub->p_lock );
201 /*****************************************************************************
203 *****************************************************************************/
204 void Messages::OnClose( wxCommandEvent& WXUNUSED(event) )
209 void Messages::OnClear( wxCommandEvent& WXUNUSED(event) )
214 void Messages::OnSaveLog( wxCommandEvent& WXUNUSED(event) )
216 if( save_log_dialog == NULL )
217 save_log_dialog = new wxFileDialog( this, wxU(_("Save Messages As a file...")),
218 wxT(""), wxT("messages"), wxT("*"), wxSAVE | wxOVERWRITE_PROMPT );
220 if( save_log_dialog && save_log_dialog->ShowModal() == wxID_OK )
222 if( !textctrl->SaveFile( save_log_dialog->GetPath() ) )
224 // [FIX ME] should print an error message
229 void Messages::OnVerbose( wxCommandEvent& event )
231 b_verbose = event.IsChecked();