00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <stdlib.h>
00028 #include <errno.h>
00029 #include <string.h>
00030 #include <stdio.h>
00031
00032 #include <vlc/vlc.h>
00033 #include <vlc/intf.h>
00034
00035 #include "wxwidgets.h"
00036
00037
00038
00039
00040
00041
00042 enum
00043 {
00044 Close_Event,
00045 Clear_Event,
00046 Save_Log_Event
00047 };
00048
00049 BEGIN_EVENT_TABLE(Messages, wxFrame)
00050
00051 EVT_BUTTON(wxID_OK, Messages::OnButtonClose)
00052 EVT_BUTTON(wxID_CLEAR, Messages::OnClear)
00053 EVT_BUTTON(wxID_SAVEAS, Messages::OnSaveLog)
00054
00055
00056
00057 EVT_CLOSE(Messages::OnClose)
00058 END_EVENT_TABLE()
00059
00060
00061
00062
00063 Messages::Messages( intf_thread_t *_p_intf, wxWindow *p_parent ):
00064 wxFrame( p_parent, -1, wxU(_("Messages")), wxDefaultPosition,
00065 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
00066 {
00067
00068 p_intf = _p_intf;
00069 b_verbose = VLC_FALSE;
00070 SetIcon( *p_intf->p_sys->p_icon );
00071 save_log_dialog = NULL;
00072 b_verbose = VLC_FALSE;
00073
00074
00075 wxPanel *messages_panel = new wxPanel( this, -1 );
00076 messages_panel->SetAutoLayout( TRUE );
00077
00078
00079 textctrl = new wxTextCtrl( messages_panel, -1, wxT(""), wxDefaultPosition,
00080 wxSize::wxSize( 400, 500 ), wxTE_MULTILINE | wxTE_READONLY |
00081 wxTE_RICH | wxTE_NOHIDESEL );
00082 info_attr = new wxTextAttr( wxColour::wxColour( 0, 128, 0 ) );
00083 err_attr = new wxTextAttr( *wxRED );
00084 warn_attr = new wxTextAttr( *wxBLUE );
00085 dbg_attr = new wxTextAttr( *wxBLACK );
00086
00087
00088 wxButton *ok_button = new wxButton( messages_panel, wxID_OK,
00089 wxU(_("Close")));
00090 ok_button->SetDefault();
00091
00092
00093 wxButton *clear_button = new wxButton( messages_panel, wxID_CLEAR,
00094 wxU(_("Clear")));
00095 clear_button->SetDefault();
00096
00097
00098 wxButton *save_log_button = new wxButton( messages_panel, wxID_SAVEAS,
00099 wxU(_("Save As...")));
00100 save_log_button->SetDefault();
00101
00102
00103 wxBoxSizer *buttons_sizer = new wxBoxSizer( wxHORIZONTAL );
00104 buttons_sizer->Add( ok_button, 0, wxEXPAND |wxALIGN_LEFT| wxALL, 5 );
00105 buttons_sizer->Add( clear_button, 0, wxEXPAND |wxALIGN_LEFT| wxALL, 5 );
00106 buttons_sizer->Add( save_log_button, 0, wxEXPAND |wxALIGN_LEFT| wxALL, 5 );
00107 buttons_sizer->Add( new wxPanel( this, -1 ), 1, wxALL, 5 );
00108 buttons_sizer->Layout();
00109 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
00110 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
00111 panel_sizer->Add( textctrl, 1, wxEXPAND | wxALL, 5 );
00112 panel_sizer->Add( buttons_sizer, 0, wxEXPAND | wxALL, 5 );
00113 panel_sizer->Layout();
00114 messages_panel->SetSizerAndFit( panel_sizer );
00115 main_sizer->Add( messages_panel, 1, wxGROW, 0 );
00116 main_sizer->Layout();
00117 SetSizerAndFit( main_sizer );
00118 }
00119
00120 Messages::~Messages()
00121 {
00122
00123 if( save_log_dialog ) delete save_log_dialog;
00124
00125 delete info_attr;
00126 delete err_attr;
00127 delete warn_attr;
00128 delete dbg_attr;
00129 }
00130
00131 bool Messages::Show( bool show )
00132 {
00133 b_verbose = show;
00134 return wxFrame::Show( show );
00135 }
00136
00137 void Messages::UpdateLog()
00138 {
00139 msg_subscription_t *p_sub = p_intf->p_sys->p_sub;
00140 int i_start;
00141
00142 vlc_mutex_lock( p_sub->p_lock );
00143 int i_stop = *p_sub->pi_stop;
00144 vlc_mutex_unlock( p_sub->p_lock );
00145
00146 if( p_sub->i_start != i_stop )
00147 {
00148 textctrl->SetInsertionPointEnd();
00149
00150 for( i_start = p_sub->i_start;
00151 i_start != i_stop;
00152 i_start = (i_start+1) % VLC_MSG_QSIZE )
00153 {
00154
00155 if( !b_verbose &&
00156 VLC_MSG_ERR != p_sub->p_msg[i_start].i_type )
00157 continue;
00158
00159
00160 textctrl->SetDefaultStyle( *dbg_attr );
00161 (*textctrl) << wxL2U(p_sub->p_msg[i_start].psz_module);
00162
00163 switch( p_sub->p_msg[i_start].i_type )
00164 {
00165 case VLC_MSG_INFO:
00166 (*textctrl) << wxT(": ");
00167 textctrl->SetDefaultStyle( *info_attr );
00168 break;
00169 case VLC_MSG_ERR:
00170 (*textctrl) << wxT(" error: ");
00171 textctrl->SetDefaultStyle( *err_attr );
00172 break;
00173 case VLC_MSG_WARN:
00174 (*textctrl) << wxT(" warning: ");
00175 textctrl->SetDefaultStyle( *warn_attr );
00176 break;
00177 case VLC_MSG_DBG:
00178 default:
00179 (*textctrl) << wxT(" debug: ");
00180 break;
00181 }
00182
00183
00184 (*textctrl) << wxL2U(p_sub->p_msg[i_start].psz_msg) << wxT("\n");
00185 }
00186
00187 vlc_mutex_lock( p_sub->p_lock );
00188 p_sub->i_start = i_start;
00189 vlc_mutex_unlock( p_sub->p_lock );
00190 }
00191 }
00192
00193
00194
00195
00196 void Messages::OnButtonClose( wxCommandEvent& WXUNUSED(event) )
00197 {
00198 wxCloseEvent cevent;
00199 OnClose(cevent);
00200 }
00201
00202 void Messages::OnClose( wxCloseEvent& WXUNUSED(event) )
00203 {
00204 Hide();
00205 }
00206
00207 void Messages::OnClear( wxCommandEvent& WXUNUSED(event) )
00208 {
00209 textctrl->Clear();
00210 }
00211
00212 void Messages::OnSaveLog( wxCommandEvent& WXUNUSED(event) )
00213 {
00214 if( save_log_dialog == NULL )
00215 save_log_dialog = new wxFileDialog( this,
00216 wxU(_("Save Messages As...")),
00217 wxT(""), wxT("messages"), wxT("*"), wxSAVE | wxOVERWRITE_PROMPT );
00218
00219 if( save_log_dialog && save_log_dialog->ShowModal() == wxID_OK )
00220 {
00221 if( !textctrl->SaveFile( save_log_dialog->GetPath() ) )
00222 {
00223
00224 }
00225 }
00226 }