1 /*****************************************************************************
2 * messages.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 VideoLAN
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() */
35 #include "wxwindows.h"
37 /*****************************************************************************
39 *****************************************************************************/
41 /* IDs for the controls and the menu commands */
49 BEGIN_EVENT_TABLE(Messages, wxFrame)
51 EVT_BUTTON(wxID_OK, Messages::OnButtonClose)
52 EVT_BUTTON(wxID_CLEAR, Messages::OnClear)
53 EVT_BUTTON(wxID_SAVEAS, Messages::OnSaveLog)
55 /* Special events : we don't want to destroy the window when the user
57 EVT_CLOSE(Messages::OnClose)
60 /*****************************************************************************
62 *****************************************************************************/
63 Messages::Messages( intf_thread_t *_p_intf, wxWindow *p_parent ):
64 wxFrame( p_parent, -1, wxU(_("Messages")), wxDefaultPosition,
65 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
69 b_verbose = VLC_FALSE;
70 SetIcon( *p_intf->p_sys->p_icon );
71 save_log_dialog = NULL;
72 b_verbose = VLC_FALSE;
74 /* Create a panel to put everything in */
75 wxPanel *messages_panel = new wxPanel( this, -1 );
76 messages_panel->SetAutoLayout( TRUE );
78 /* Create the textctrl and some text attributes */
79 textctrl = new wxTextCtrl( messages_panel, -1, wxT(""), wxDefaultPosition,
80 wxSize::wxSize( 400, 500 ), wxTE_MULTILINE | wxTE_READONLY |
81 wxTE_RICH | wxTE_NOHIDESEL );
82 info_attr = new wxTextAttr( wxColour::wxColour( 0, 128, 0 ) );
83 err_attr = new wxTextAttr( *wxRED );
84 warn_attr = new wxTextAttr( *wxBLUE );
85 dbg_attr = new wxTextAttr( *wxBLACK );
87 /* Create the OK button */
88 wxButton *ok_button = new wxButton( messages_panel, wxID_OK,
90 ok_button->SetDefault();
92 /* Create the Clear button */
93 wxButton *clear_button = new wxButton( messages_panel, wxID_CLEAR,
95 clear_button->SetDefault();
97 /* Create the Save Log button */
98 wxButton *save_log_button = new wxButton( messages_panel, wxID_SAVEAS,
99 wxU(_("Save As...")));
100 save_log_button->SetDefault();
102 /* Place everything in sizers */
103 wxBoxSizer *buttons_sizer = new wxBoxSizer( wxHORIZONTAL );
104 buttons_sizer->Add( ok_button, 0, wxEXPAND |wxALIGN_LEFT| wxALL, 5 );
105 buttons_sizer->Add( clear_button, 0, wxEXPAND |wxALIGN_LEFT| wxALL, 5 );
106 buttons_sizer->Add( save_log_button, 0, wxEXPAND |wxALIGN_LEFT| wxALL, 5 );
107 buttons_sizer->Add( new wxPanel( this, -1 ), 1, wxALL, 5 );
108 buttons_sizer->Layout();
109 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
110 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
111 panel_sizer->Add( textctrl, 1, wxEXPAND | wxALL, 5 );
112 panel_sizer->Add( buttons_sizer, 0, wxEXPAND | wxALL, 5 );
113 panel_sizer->Layout();
114 messages_panel->SetSizerAndFit( panel_sizer );
115 main_sizer->Add( messages_panel, 1, wxGROW, 0 );
116 main_sizer->Layout();
117 SetSizerAndFit( main_sizer );
120 Messages::~Messages()
123 if( save_log_dialog ) delete save_log_dialog;
131 bool Messages::Show( bool show )
134 return wxFrame::Show( show );
137 void Messages::UpdateLog()
139 msg_subscription_t *p_sub = p_intf->p_sys->p_sub;
142 vlc_mutex_lock( p_sub->p_lock );
143 int i_stop = *p_sub->pi_stop;
144 vlc_mutex_unlock( p_sub->p_lock );
146 textctrl->SetInsertionPointEnd();
148 if( p_sub->i_start != i_stop )
150 for( i_start = p_sub->i_start;
152 i_start = (i_start+1) % VLC_MSG_QSIZE )
156 VLC_MSG_ERR != p_sub->p_msg[i_start].i_type )
159 /* Append all messages to log window */
160 textctrl->SetDefaultStyle( *dbg_attr );
161 (*textctrl) << wxL2U(p_sub->p_msg[i_start].psz_module);
163 switch( p_sub->p_msg[i_start].i_type )
166 (*textctrl) << wxT(": ");
167 textctrl->SetDefaultStyle( *info_attr );
170 (*textctrl) << wxT(" error: ");
171 textctrl->SetDefaultStyle( *err_attr );
174 (*textctrl) << wxT(" warning: ");
175 textctrl->SetDefaultStyle( *warn_attr );
179 (*textctrl) << wxT(" debug: ");
184 (*textctrl) << wxL2U(p_sub->p_msg[i_start].psz_msg) << wxT("\n");
187 vlc_mutex_lock( p_sub->p_lock );
188 p_sub->i_start = i_start;
189 vlc_mutex_unlock( p_sub->p_lock );
193 /*****************************************************************************
195 *****************************************************************************/
196 void Messages::OnButtonClose( wxCommandEvent& WXUNUSED(event) )
202 void Messages::OnClose( wxCloseEvent& WXUNUSED(event) )
207 void Messages::OnClear( wxCommandEvent& WXUNUSED(event) )
212 void Messages::OnSaveLog( wxCommandEvent& WXUNUSED(event) )
214 if( save_log_dialog == NULL )
215 save_log_dialog = new wxFileDialog( this,
216 wxU(_("Save Messages As...")),
217 wxT(""), wxT("messages"), wxT("*"), wxSAVE | wxOVERWRITE_PROMPT );
219 if( save_log_dialog && save_log_dialog->ShowModal() == wxID_OK )
221 if( !textctrl->SaveFile( save_log_dialog->GetPath() ) )
223 // [FIX ME] should print an error message