Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

messages.cpp

00001 /*****************************************************************************
00002  * messages.cpp : wxWindows plugin for vlc
00003  *****************************************************************************
00004  * Copyright (C) 2000-2004 the VideoLAN team
00005  * $Id: messages.cpp 12826 2005-10-12 19:18:50Z ipkiss $
00006  *
00007  * Authors: Olivier Teulière <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <stdlib.h>                                      /* malloc(), free() */
00028 #include <errno.h>                                                 /* ENOMEM */
00029 #include <string.h>                                            /* strerror() */
00030 #include <stdio.h>
00031 
00032 #include <vlc/vlc.h>
00033 #include <vlc/intf.h>
00034 
00035 #include "wxwidgets.h"
00036 
00037 /*****************************************************************************
00038  * Event Table.
00039  *****************************************************************************/
00040 
00041 /* IDs for the controls and the menu commands */
00042 enum
00043 {
00044     Close_Event,
00045     Clear_Event,
00046     Save_Log_Event
00047 };
00048 
00049 BEGIN_EVENT_TABLE(Messages, wxFrame)
00050     /* Button events */
00051     EVT_BUTTON(wxID_OK, Messages::OnButtonClose)
00052     EVT_BUTTON(wxID_CLEAR, Messages::OnClear)
00053     EVT_BUTTON(wxID_SAVEAS, Messages::OnSaveLog)
00054 
00055     /* Special events : we don't want to destroy the window when the user
00056      * clicks on (X) */
00057     EVT_CLOSE(Messages::OnClose)
00058 END_EVENT_TABLE()
00059 
00060 /*****************************************************************************
00061  * Constructor.
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     /* Initializations */
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     /* Create a panel to put everything in */
00075     wxPanel *messages_panel = new wxPanel( this, -1 );
00076     messages_panel->SetAutoLayout( TRUE );
00077 
00078     /* Create the textctrl and some text attributes */
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     /* Create the OK button */
00088     wxButton *ok_button = new wxButton( messages_panel, wxID_OK,
00089                                         wxU(_("Close")));
00090     ok_button->SetDefault();
00091 
00092     /* Create the Clear button */
00093     wxButton *clear_button = new wxButton( messages_panel, wxID_CLEAR,
00094                                            wxU(_("Clear")));
00095     clear_button->SetDefault();
00096 
00097     /* Create the Save Log button */
00098     wxButton *save_log_button = new wxButton( messages_panel, wxID_SAVEAS,
00099                                               wxU(_("Save As...")));
00100     save_log_button->SetDefault();
00101 
00102     /* Place everything in sizers */
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     /* Clean up */
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             /* Append all messages to log window */
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             /* Add message */
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  * Private methods.
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             // [FIX ME] should print an error message
00224         }
00225     }
00226 }

Generated on Tue Dec 20 10:14:45 2005 for vlc-0.8.4a by  doxygen 1.4.2