1 /*****************************************************************************
2 * messages.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #include "dialogs/messages.hpp"
26 /*****************************************************************************
28 *****************************************************************************/
30 /* IDs for the controls and the menu commands */
38 BEGIN_EVENT_TABLE(Messages, wxFrame)
40 EVT_BUTTON(wxID_CLOSE, Messages::OnButtonClose)
41 EVT_BUTTON(wxID_CLEAR, Messages::OnClear)
42 EVT_BUTTON(wxID_SAVEAS, Messages::OnSaveLog)
44 /* Special events : we don't want to destroy the window when the user
46 EVT_CLOSE(Messages::OnClose)
49 /*****************************************************************************
51 *****************************************************************************/
52 Messages::Messages( intf_thread_t *_p_intf, wxWindow *p_parent ):
53 wxFrame( p_parent, -1, wxU(_("Messages")), wxDefaultPosition,
54 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
58 b_verbose = VLC_FALSE;
59 SetIcon( *p_intf->p_sys->p_icon );
60 save_log_dialog = NULL;
61 b_verbose = VLC_FALSE;
63 /* Create a panel to put everything in */
64 wxPanel *messages_panel = new wxPanel( this, -1 );
65 messages_panel->SetAutoLayout( TRUE );
67 /* Create the textctrl and some text attributes */
68 textctrl = new wxTextCtrl( messages_panel, -1, wxT(""), wxDefaultPosition,
69 wxSize::wxSize( 400, 500 ), wxTE_MULTILINE | wxTE_READONLY |
70 wxTE_RICH | wxTE_NOHIDESEL );
71 info_attr = new wxTextAttr( wxColour::wxColour( 0, 128, 0 ) );
72 err_attr = new wxTextAttr( *wxRED );
73 warn_attr = new wxTextAttr( *wxBLUE );
74 dbg_attr = new wxTextAttr( *wxBLACK );
76 /* Create the OK button */
77 wxButton *ok_button = new wxButton( messages_panel, wxID_CLOSE);
78 ok_button->SetDefault();
80 /* Create the Clear button */
81 wxButton *clear_button = new wxButton( messages_panel, wxID_CLEAR );
82 clear_button->SetDefault();
84 /* Create the Save Log button */
85 wxButton *save_log_button = new wxButton( messages_panel, wxID_SAVEAS );
86 save_log_button->SetDefault();
88 /* Place everything in sizers */
89 wxBoxSizer *buttons_sizer = new wxBoxSizer( wxHORIZONTAL );
90 buttons_sizer->Add( ok_button, 0, wxEXPAND |wxALIGN_LEFT| wxALL, 5 );
91 buttons_sizer->Add( clear_button, 0, wxEXPAND |wxALIGN_LEFT| wxALL, 5 );
92 buttons_sizer->Add( save_log_button, 0, wxEXPAND |wxALIGN_LEFT| wxALL, 5 );
93 buttons_sizer->Add( new wxPanel( this, -1 ), 1, wxALL, 5 );
94 buttons_sizer->Layout();
95 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
96 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
97 panel_sizer->Add( textctrl, 1, wxEXPAND | wxALL, 5 );
98 panel_sizer->Add( buttons_sizer, 0, wxEXPAND | wxALL, 5 );
99 panel_sizer->Layout();
100 messages_panel->SetSizerAndFit( panel_sizer );
101 main_sizer->Add( messages_panel, 1, wxGROW, 0 );
102 main_sizer->Layout();
103 SetSizerAndFit( main_sizer );
106 Messages::~Messages()
109 if( save_log_dialog ) delete save_log_dialog;
117 bool Messages::Show( bool show )
120 return wxFrame::Show( show );
123 void Messages::UpdateLog()
125 msg_subscription_t *p_sub = p_intf->p_sys->p_sub;
128 vlc_mutex_lock( p_sub->p_lock );
129 int i_stop = *p_sub->pi_stop;
130 vlc_mutex_unlock( p_sub->p_lock );
133 if( p_sub->i_start != i_stop )
135 textctrl->SetInsertionPointEnd();
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 )
146 /* Append all messages to log window */
147 textctrl->SetDefaultStyle( *dbg_attr );
148 (*textctrl) << wxL2U(p_sub->p_msg[i_start].psz_module);
150 switch( p_sub->p_msg[i_start].i_type )
153 (*textctrl) << wxT(": ");
154 textctrl->SetDefaultStyle( *info_attr );
157 (*textctrl) << wxT(" error: ");
158 textctrl->SetDefaultStyle( *err_attr );
161 (*textctrl) << wxT(" warning: ");
162 textctrl->SetDefaultStyle( *warn_attr );
166 (*textctrl) << wxT(" debug: ");
171 (*textctrl) << wxL2U(p_sub->p_msg[i_start].psz_msg) << wxT("\n");
174 vlc_mutex_lock( p_sub->p_lock );
175 p_sub->i_start = i_start;
176 vlc_mutex_unlock( p_sub->p_lock );
180 /*****************************************************************************
182 *****************************************************************************/
183 void Messages::OnButtonClose( wxCommandEvent& WXUNUSED(event) )
189 void Messages::OnClose( wxCloseEvent& WXUNUSED(event) )
194 void Messages::OnClear( wxCommandEvent& WXUNUSED(event) )
199 void Messages::OnSaveLog( wxCommandEvent& WXUNUSED(event) )
201 if( save_log_dialog == NULL )
202 save_log_dialog = new wxFileDialog( this,
203 wxU(_("Save Messages As...")),
204 wxT(""), wxT("messages"), wxT("*"), wxSAVE | wxOVERWRITE_PROMPT );
206 if( save_log_dialog && save_log_dialog->ShowModal() == wxID_OK )
208 if( !textctrl->SaveFile( save_log_dialog->GetPath() ) )
210 // [FIX ME] should print an error message