]> git.sesse.net Git - vlc/blobdiff - modules/gui/wxwindows/messages.cpp
- Fix playlist deadlock between Timer and Playlist stuff
[vlc] / modules / gui / wxwindows / messages.cpp
index 68a6df0064e8474d8c634656c46bd45f3d36f566..f4de7beafc6d04d257d5cda1ce2b31008aef2ad0 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
- * playlist.cpp : wxWindows plugin for vlc
+ * messages.cpp : wxWindows plugin for vlc
  *****************************************************************************
- * Copyright (C) 2000-2001 VideoLAN
- * $Id: messages.cpp,v 1.3 2003/04/06 16:30:43 gbazin Exp $
+ * Copyright (C) 2000-2004 VideoLAN
+ * $Id$
  *
  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
  *
 #include <stdio.h>
 
 #include <vlc/vlc.h>
-
-#ifdef WIN32                                                 /* mingw32 hack */
-#undef Yield
-#undef CreateDialog
-#endif
-
-/* Let vlc take care of the i18n stuff */
-#define WXINTL_NO_GETTEXT_MACRO
-
-#include <wx/wxprec.h>
-#include <wx/wx.h>
-#include <wx/textctrl.h>
-
 #include <vlc/intf.h>
 
 #include "wxwindows.h"
 enum
 {
     Close_Event,
-    Verbose_Event
+    Clear_Event,
+    Save_Log_Event
 };
 
 BEGIN_EVENT_TABLE(Messages, wxFrame)
     /* Button events */
     EVT_BUTTON(wxID_OK, Messages::OnClose)
-    EVT_CHECKBOX(Verbose_Event, Messages::OnVerbose)
+    EVT_BUTTON(wxID_CLEAR, Messages::OnClear)
+    EVT_BUTTON(wxID_SAVEAS, Messages::OnSaveLog)
 
     /* Special events : we don't want to destroy the window when the user
      * clicks on (X) */
@@ -71,22 +60,23 @@ END_EVENT_TABLE()
 /*****************************************************************************
  * Constructor.
  *****************************************************************************/
-Messages::Messages( intf_thread_t *_p_intf, Interface *_p_main_interface ):
-    wxFrame( _p_main_interface, -1, "Messages", wxDefaultPosition,
+Messages::Messages( intf_thread_t *_p_intf, wxWindow *p_parent ):
+    wxFrame( p_parent, -1, wxU(_("Messages")), wxDefaultPosition,
              wxDefaultSize, wxDEFAULT_FRAME_STYLE )
 {
     /* Initializations */
     p_intf = _p_intf;
-    p_main_interface = _p_main_interface;
     b_verbose = VLC_FALSE;
     SetIcon( *p_intf->p_sys->p_icon );
+    save_log_dialog = NULL;
+    b_verbose = VLC_FALSE;
 
     /* Create a panel to put everything in */
     wxPanel *messages_panel = new wxPanel( this, -1 );
     messages_panel->SetAutoLayout( TRUE );
 
     /* Create the textctrl and some text attributes */
-    textctrl = new wxTextCtrl( messages_panel, -1, "", wxDefaultPosition,
+    textctrl = new wxTextCtrl( messages_panel, -1, wxT(""), wxDefaultPosition,
         wxSize::wxSize( 400, 500 ), wxTE_MULTILINE | wxTE_READONLY |
                                     wxTE_RICH | wxTE_NOHIDESEL );
     info_attr = new wxTextAttr( wxColour::wxColour( 0, 128, 0 ) );
@@ -95,18 +85,26 @@ Messages::Messages( intf_thread_t *_p_intf, Interface *_p_main_interface ):
     dbg_attr = new wxTextAttr( *wxBLACK );
 
     /* Create the OK button */
-    wxButton *ok_button = new wxButton( messages_panel, wxID_OK, _("OK") );
+    wxButton *ok_button = new wxButton( messages_panel, wxID_OK,
+                                        wxU(_("Close")));
     ok_button->SetDefault();
 
-    /* Create the Verbose checkbox */
-    wxCheckBox *verbose_checkbox =
-        new wxCheckBox( messages_panel, Verbose_Event, _("Verbose") );
+    /* Create the Clear button */
+    wxButton *clear_button = new wxButton( messages_panel, wxID_CLEAR,
+                                           wxU(_("Clear")));
+    clear_button->SetDefault();
+
+    /* Create the Save Log button */
+    wxButton *save_log_button = new wxButton( messages_panel, wxID_SAVEAS,
+                                              wxU(_("Save As...")));
+    save_log_button->SetDefault();
 
     /* Place everything in sizers */
     wxBoxSizer *buttons_sizer = new wxBoxSizer( wxHORIZONTAL );
     buttons_sizer->Add( ok_button, 0, wxEXPAND |wxALIGN_LEFT| wxALL, 5 );
+    buttons_sizer->Add( clear_button, 0, wxEXPAND |wxALIGN_LEFT| wxALL, 5 );
+    buttons_sizer->Add( save_log_button, 0, wxEXPAND |wxALIGN_LEFT| wxALL, 5 );
     buttons_sizer->Add( new wxPanel( this, -1 ), 1, wxALL, 5 );
-    buttons_sizer->Add( verbose_checkbox, 0, wxEXPAND |wxALIGN_RIGHT | wxALL, 5 );
     buttons_sizer->Layout();
     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
@@ -121,6 +119,19 @@ Messages::Messages( intf_thread_t *_p_intf, Interface *_p_main_interface ):
 
 Messages::~Messages()
 {
+    /* Clean up */
+    if( save_log_dialog ) delete save_log_dialog;
+
+    delete info_attr;
+    delete err_attr;
+    delete warn_attr;
+    delete dbg_attr;
+}
+
+bool Messages::Show( bool show )
+{
+    b_verbose = show;
+    return wxFrame::Show( show );
 }
 
 void Messages::UpdateLog()
@@ -132,6 +143,8 @@ void Messages::UpdateLog()
     int i_stop = *p_sub->pi_stop;
     vlc_mutex_unlock( p_sub->p_lock );
 
+    textctrl->SetInsertionPointEnd();
+
     if( p_sub->i_start != i_stop )
     {
         for( i_start = p_sub->i_start;
@@ -140,36 +153,35 @@ void Messages::UpdateLog()
         {
 
             if( !b_verbose &&
-                VLC_MSG_ERR != p_sub->p_msg[i_start].i_type &&
-                VLC_MSG_INFO != p_sub->p_msg[i_start].i_type )
+                VLC_MSG_ERR != p_sub->p_msg[i_start].i_type )
                 continue;
 
             /* Append all messages to log window */
             textctrl->SetDefaultStyle( *dbg_attr );
-            (*textctrl) << p_sub->p_msg[i_start].psz_module;
+            (*textctrl) << wxL2U(p_sub->p_msg[i_start].psz_module);
 
             switch( p_sub->p_msg[i_start].i_type )
             {
             case VLC_MSG_INFO:
-                (*textctrl) << ": ";
+                (*textctrl) << wxT(": ");
                 textctrl->SetDefaultStyle( *info_attr );
                 break;
             case VLC_MSG_ERR:
-                (*textctrl) << " error: ";
+                (*textctrl) << wxT(" error: ");
                 textctrl->SetDefaultStyle( *err_attr );
                 break;
             case VLC_MSG_WARN:
-                (*textctrl) << " warning: ";
+                (*textctrl) << wxT(" warning: ");
                 textctrl->SetDefaultStyle( *warn_attr );
                 break;
             case VLC_MSG_DBG:
             default:
-                (*textctrl) << " debug: ";
+                (*textctrl) << wxT(" debug: ");
                 break;
             }
 
             /* Add message */
-            (*textctrl) << p_sub->p_msg[i_start].psz_msg << "\n";
+            (*textctrl) << wxL2U(p_sub->p_msg[i_start].psz_msg) << wxT("\n");
         }
 
         vlc_mutex_lock( p_sub->p_lock );
@@ -186,7 +198,23 @@ void Messages::OnClose( wxCommandEvent& WXUNUSED(event) )
     Hide();
 }
 
-void Messages::OnVerbose( wxCommandEvent& event )
+void Messages::OnClear( wxCommandEvent& WXUNUSED(event) )
 {
-    b_verbose = event.IsChecked();
+    textctrl->Clear();
+}
+
+void Messages::OnSaveLog( wxCommandEvent& WXUNUSED(event) )
+{
+    if( save_log_dialog == NULL )
+        save_log_dialog = new wxFileDialog( this,
+            wxU(_("Save Messages As...")),
+            wxT(""), wxT("messages"), wxT("*"), wxSAVE | wxOVERWRITE_PROMPT );
+
+    if( save_log_dialog && save_log_dialog->ShowModal() == wxID_OK )
+    {
+        if( !textctrl->SaveFile( save_log_dialog->GetPath() ) )
+        {
+            // [FIX ME] should print an error message
+        }
+    }
 }