* modules/gui/wxwindows/*: added demuxdump support to the open dialog.
[vlc.git] / modules / gui / wxwindows / open.cpp
index cf72e3b..da8055a 100644 (file)
@@ -2,7 +2,7 @@
  * open.cpp : wxWindows plugin for vlc
  *****************************************************************************
  * Copyright (C) 2000-2001 VideoLAN
- * $Id: open.cpp,v 1.1 2003/01/23 23:57:50 gbazin Exp $
+ * $Id: open.cpp,v 1.7 2003/03/29 01:50:12 gbazin Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
 #include <wx/textctrl.h>
 #include <wx/combobox.h>
 #include <wx/spinctrl.h>
+#include <wx/statline.h>
 
 #include <vlc/intf.h>
 
 #include "wxwindows.h"
 
+#ifndef wxRB_SINGLE
+#   define wxRB_SINGLE 0
+#endif
+
 /*****************************************************************************
  * Event Table.
  *****************************************************************************/
@@ -72,13 +77,19 @@ enum
     NetRadio1_Event, NetRadio2_Event, NetRadio3_Event, NetRadio4_Event,
     NetPort1_Event, NetPort2_Event, NetPort3_Event, NetPort4_Event,
     NetAddr1_Event, NetAddr2_Event, NetAddr3_Event, NetAddr4_Event,
+
+    SoutEnable_Event,
+    SoutSettings_Event,
+
+    DemuxDump_Event,
+    DemuxDumpEnable_Event,
+    DemuxDumpBrowse_Event,
 };
 
 BEGIN_EVENT_TABLE(OpenDialog, wxDialog)
     /* Button events */
     EVT_BUTTON(wxID_OK, OpenDialog::OnOk)
     EVT_BUTTON(wxID_CANCEL, OpenDialog::OnCancel)
-    EVT_BUTTON(FileBrowse_Event, OpenDialog::OnFileBrowse)
 
     EVT_NOTEBOOK_PAGE_CHANGED(Notebook_Event, OpenDialog::OnPageChange)
 
@@ -86,6 +97,7 @@ BEGIN_EVENT_TABLE(OpenDialog, wxDialog)
 
     /* Events generated by the file panel */
     EVT_TEXT(FileName_Event, OpenDialog::OnFilePanelChange)
+    EVT_BUTTON(FileBrowse_Event, OpenDialog::OnFileBrowse)
 
     /* Events generated by the disc panel */
     EVT_RADIOBOX(DiscType_Event, OpenDialog::OnDiscTypeChange)
@@ -110,6 +122,15 @@ BEGIN_EVENT_TABLE(OpenDialog, wxDialog)
     EVT_TEXT(NetAddr3_Event, OpenDialog::OnNetPanelChange)
     EVT_TEXT(NetAddr4_Event, OpenDialog::OnNetPanelChange)
 
+    /* Events generated by the stream output buttons */
+    EVT_CHECKBOX(SoutEnable_Event, OpenDialog::OnSoutEnable)
+    EVT_BUTTON(SoutSettings_Event, OpenDialog::OnSoutSettings)
+
+    /* Events generated by the demux dump buttons */
+    EVT_CHECKBOX(DemuxDumpEnable_Event, OpenDialog::OnDemuxDumpEnable)
+    EVT_TEXT(DemuxDump_Event, OpenDialog::OnDemuxDumpChange)
+    EVT_BUTTON(DemuxDumpBrowse_Event, OpenDialog::OnDemuxDumpBrowse)
+
 END_EVENT_TABLE()
 
 /*****************************************************************************
@@ -150,9 +171,9 @@ OpenDialog::OpenDialog( intf_thread_t *_p_intf, Interface *_p_main_interface,
           "following predefined targets:") );
 
     /* Create notebook */
-    wxNotebook *notebook = new wxNotebook( panel, Notebook_Event,
-                                           wxDefaultPosition,
-                                           wxSize( 300, 250 ) );
+    wxNotebook *notebook = new wxNotebook( panel, Notebook_Event );
+    wxNotebookSizer *notebook_sizer = new wxNotebookSizer( notebook );
+
     notebook->AddPage( FilePanel( notebook ), _("File"),
                        i_access_method == FILE_ACCESS );
     notebook->AddPage( DiscPanel( notebook ), _("Disc"),
@@ -162,12 +183,66 @@ OpenDialog::OpenDialog( intf_thread_t *_p_intf, Interface *_p_main_interface,
     notebook->AddPage( SatPanel( notebook ), _("Satellite"),
                        i_access_method == SAT_ACCESS );
 
+    /* Create Stream Output checkox */
+    wxFlexGridSizer *sout_sizer = new wxFlexGridSizer( 2, 1, 20 );
+    sout_checkbox = new wxCheckBox( panel, SoutEnable_Event,
+                                           _("Stream Output") );
+    sout_checkbox->SetToolTip( _("Use VLC has a stream server") );
+    sout_sizer->Add( sout_checkbox, 0,
+                     wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
+    sout_button = new wxButton( panel, SoutSettings_Event, _("Settings...") );
+    sout_button->Disable();
+
+    char *psz_sout = config_GetPsz( p_intf, "sout" );
+    if( psz_sout && *psz_sout )
+    {
+        sout_checkbox->SetValue(TRUE);
+        sout_button->Enable();
+    }
+    if( psz_sout ) free( psz_sout );
+
+    sout_sizer->Add( sout_button, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
+
+    /* Create Demux Dump checkox */
+    wxBoxSizer *demuxdump_sizer = new wxBoxSizer( wxHORIZONTAL );
+    demuxdump_checkbox = new wxCheckBox( panel, DemuxDumpEnable_Event,
+                               _("Capture input stream") );
+    demuxdump_checkbox->SetToolTip(
+                           _("Capture the stream you are playing to a file") );
+    demuxdump_textctrl = new wxTextCtrl( panel, DemuxDump_Event,
+                                         "", wxDefaultPosition, wxDefaultSize,
+                                         wxTE_PROCESS_ENTER);
+    demuxdump_button = new wxButton( panel, DemuxDumpBrowse_Event,
+                                     _("Browse...") );
+
+    char *psz_demuxdump = config_GetPsz( p_intf, "demuxdump-file" );
+    if( psz_demuxdump && *psz_demuxdump )
+    {
+        demuxdump_textctrl->SetValue( psz_demuxdump );
+    }
+    if( psz_demuxdump ) free( psz_demuxdump );
+
+    demuxdump_textctrl->Disable();
+    demuxdump_button->Disable();
+    demuxdump_sizer->Add( demuxdump_checkbox, 0,
+                          wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 10 );
+    demuxdump_sizer->Add( demuxdump_button, 0,
+                          wxALL | wxALIGN_CENTER_VERTICAL, 10 );
+    demuxdump_sizer->Add( demuxdump_textctrl, 1, wxALL, 10 );
+
+    /* Separation */
+    wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
+
     /* Create the buttons */
     wxButton *ok_button = new wxButton( panel, wxID_OK, _("OK") );
     ok_button->SetDefault();
     wxButton *cancel_button = new wxButton( panel, wxID_CANCEL, _("Cancel") );
 
 
+    /* Update Disc panel */
+    wxCommandEvent dummy_event;
+    OnDiscTypeChange( dummy_event );
+
     /* Update MRL */
     wxNotebookEvent event = wxNotebookEvent( wxEVT_NULL, 0, i_access_method );
     OnPageChange( event );
@@ -181,8 +256,11 @@ OpenDialog::OpenDialog( intf_thread_t *_p_intf, Interface *_p_main_interface,
     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
     panel_sizer->Add( mrl_sizer_sizer, 0, wxEXPAND, 5 );
     panel_sizer->Add( label, 0, wxEXPAND | wxALL, 5 );
-    panel_sizer->Add( notebook, 1, wxEXPAND | wxALL, 5 );
-    panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT );
+    panel_sizer->Add( notebook_sizer, 1, wxEXPAND | wxALL, 5 );
+    panel_sizer->Add( sout_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
+    panel_sizer->Add( demuxdump_sizer, 0, wxEXPAND | wxALIGN_LEFT | wxALL, 5 );
+    panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
+    panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALL, 5 );
     panel_sizer->Layout();
     panel->SetSizerAndFit( panel_sizer );
     main_sizer->Add( panel, 1, wxGROW, 0 );
@@ -212,7 +290,6 @@ wxPanel *OpenDialog::FilePanel( wxWindow* parent )
     sizer->Add( browse_button, 0, wxALL, 5 );
 
     panel->SetSizerAndFit( sizer );
-
     return panel;
 }
 
@@ -238,39 +315,26 @@ wxPanel *OpenDialog::DiscPanel( wxWindow* parent )
     sizer_row->Add( disc_type, 0, wxEXPAND | wxALL, 5 );
 
     wxStaticText *label = new wxStaticText( panel, -1, _("Device Name") );
-    char *psz_device = config_GetPsz( p_intf, "dvd" );
-    disc_device = new wxTextCtrl( panel, DiscDevice_Event,
-                                  psz_device ? psz_device : "",
+    disc_device = new wxTextCtrl( panel, DiscDevice_Event, "",
                                   wxDefaultPosition, wxDefaultSize,
                                   wxTE_PROCESS_ENTER);
-    if( psz_device ) free( psz_device );
 
     sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
     sizer->Add( disc_device, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
 
-    int val = 1;
     label = new wxStaticText( panel, -1, _("Title") );
-    disc_title = new wxSpinCtrl( panel, DiscTitle_Event,
-                                 wxString::Format(_("%d"), val),
-                                 wxDefaultPosition, wxDefaultSize,
-                                 wxSP_ARROW_KEYS,
-                                 1, 255, val);
+    disc_title = new wxSpinCtrl( panel, DiscTitle_Event );
 
     sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
     sizer->Add( disc_title, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
 
     label = new wxStaticText( panel, -1, _("Chapter") );
-    disc_chapter = new wxSpinCtrl( panel, DiscChapter_Event,
-                                   wxString::Format(_("%d"), val),
-                                   wxDefaultPosition, wxDefaultSize,
-                                   wxSP_ARROW_KEYS,
-                                   1, 255, val);
+    disc_chapter = new wxSpinCtrl( panel, DiscChapter_Event );
     sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
     sizer->Add( disc_chapter, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
     sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
 
     panel->SetSizerAndFit( sizer_row );
-
     return panel;
 }
 
@@ -318,6 +382,7 @@ wxPanel *OpenDialog::NetPanel( wxWindow* parent )
     subpanel_sizer->Add( net_ports[0], 1,
                          wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
     net_subpanels[0]->SetSizerAndFit( subpanel_sizer );
+    net_radios[0]->SetValue( TRUE );
 
     /* UDP/RTP Multicast row */
     subpanel_sizer = new wxFlexGridSizer( 4, 1, 20 );
@@ -366,7 +431,7 @@ wxPanel *OpenDialog::NetPanel( wxWindow* parent )
     /* HTTP row */
     subpanel_sizer = new wxFlexGridSizer( 2, 1, 20 );
     label = new wxStaticText( net_subpanels[3], -1, _("URL") );
-    net_addrs[3] = new wxTextCtrl( net_subpanels[3], NetAddr4_Event, "http://",
+    net_addrs[3] = new wxTextCtrl( net_subpanels[3], NetAddr4_Event, "",
                                    wxDefaultPosition, wxSize( 200, -1 ),
                                    wxTE_PROCESS_ENTER);
     subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
@@ -385,12 +450,6 @@ wxPanel *OpenDialog::NetPanel( wxWindow* parent )
     sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
 
     panel->SetSizerAndFit( sizer_row );
-
-    /* Update Net panel */
-    wxCommandEvent dummy_event;
-    dummy_event.SetId( NetRadio1_Event );
-    OnNetTypeChange( dummy_event );
-
     return panel;
 }
 
@@ -403,14 +462,25 @@ wxPanel *OpenDialog::SatPanel( wxWindow* parent )
 
 void OpenDialog::UpdateMRL( int i_access_method )
 {
+    wxString demux;
+
+    i_current_access_method = i_access_method;
+
+    /* Check if the user asked for demuxdump */
+    if( demuxdump_checkbox->GetValue() )
+    {
+        demux = "/demuxdump";
+    }
+
     switch( i_access_method )
     {
     case FILE_ACCESS:
-        mrl = "file://" + file_combo->GetValue();
+        mrl = "file" + demux + "://" + file_combo->GetValue();
         break;
     case DISC_ACCESS:
-        mrl = ( disc_type->GetSelection() == 0 ? "dvdold://" :
-                disc_type->GetSelection() == 1 ? "dvd://" : "vcd://" )
+        mrl = ( disc_type->GetSelection() == 0 ? "dvdold" :
+                disc_type->GetSelection() == 1 ? "dvd" : "vcd" )
+                  + demux + "://"
                   + disc_device->GetLineText(0)
                   + wxString::Format( "@%d:%d",
                                       disc_title->GetValue(),
@@ -423,17 +493,17 @@ void OpenDialog::UpdateMRL( int i_access_method )
             if( net_ports[0]->GetValue() !=
                 config_GetInt( p_intf, "server-port" ) )
             {
-                mrl = wxString::Format( "udp://@:%d",
-                                        net_ports[0]->GetValue() );
+                mrl = "udp" + demux +
+                       wxString::Format( "://@:%d", net_ports[0]->GetValue() );
             }
             else
             {
-                mrl = "udp://";
+                mrl = "udp" + demux + "://";
             }
             break;
 
         case 1:
-            mrl = "udp://@" + net_addrs[1]->GetLineText(0);
+            mrl = "udp" + demux + "://@" + net_addrs[1]->GetLineText(0);
             if( net_ports[1]->GetValue() !=
                 config_GetInt( p_intf, "server-port" ) )
             {
@@ -443,18 +513,17 @@ void OpenDialog::UpdateMRL( int i_access_method )
             break;
 
         case 2:
-            mrl = "udp://";
+            mrl = "udp" + demux + "://";
             break;
 
         case 3:
             /* http access */     
-            mrl = net_addrs[3]->GetLineText(0);
+            mrl = "http" + demux + "://" + net_addrs[3]->GetLineText(0);
             break;
         }
         break;
-
     case SAT_ACCESS:
-        mrl = "satellite://";
+        mrl = "satellite" + demux + "://";
         break;
     default:
         break;
@@ -496,7 +565,7 @@ void OpenDialog::OnFilePanelChange( wxCommandEvent& WXUNUSED(event) )
 
 void OpenDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
 {
-    wxFileDialog dialog( this, _("Open file"), _(""), _(""), _("*.*"),
+    wxFileDialog dialog( this, _("Open file"), "", "", "*.*",
                          wxOPEN );
 
     if( dialog.ShowModal() == wxID_OK )
@@ -520,12 +589,11 @@ void OpenDialog::OnDiscTypeChange( wxCommandEvent& WXUNUSED(event) )
 
     switch( disc_type->GetSelection() )
     {
-    case 3:
+    case 2:
         psz_device = config_GetPsz( p_intf, "vcd" );
         disc_device->SetValue( psz_device ? psz_device : "" );
         break;
 
-    case 2:
     default:
         psz_device = config_GetPsz( p_intf, "dvd" );
         disc_device->SetValue( psz_device ? psz_device : "" );
@@ -533,6 +601,24 @@ void OpenDialog::OnDiscTypeChange( wxCommandEvent& WXUNUSED(event) )
     }
 
     if( psz_device ) free( psz_device );
+
+    switch( disc_type->GetSelection() )
+    {
+    case 1:
+        disc_title->SetRange( 0, 255 );
+        disc_title->SetValue( 0 );
+        break;
+
+    default:
+        disc_title->SetRange( 1, 255 );
+        disc_title->SetValue( 1 );
+        break;
+    }
+
+    disc_chapter->SetRange( 1, 255 );
+    disc_chapter->SetValue( 1 );
+
+    UpdateMRL( DISC_ACCESS );
 }
 
 /*****************************************************************************
@@ -551,8 +637,76 @@ void OpenDialog::OnNetTypeChange( wxCommandEvent& event )
 
     for(i=0; i<4; i++)
     {
+        net_radios[i]->SetValue( event.GetId() == (NetRadio1_Event+i) );
         net_subpanels[i]->Enable( event.GetId() == (NetRadio1_Event+i) );
     }
 
     UpdateMRL( NET_ACCESS );
 }
+
+/*****************************************************************************
+ * Stream output event methods.
+ *****************************************************************************/
+void OpenDialog::OnSoutEnable( wxCommandEvent& event )
+{
+    sout_button->Enable( event.GetInt() != 0 );
+    if( !event.GetInt() )
+    {
+        config_PutPsz( p_intf, "sout", "" );
+    }
+    else
+    {
+        demuxdump_checkbox->SetValue( 0 );
+        wxCommandEvent event = wxCommandEvent( wxEVT_NULL );
+        event.SetInt( 0 );
+        OnDemuxDumpEnable( event );
+    }
+}
+
+void OpenDialog::OnSoutSettings( wxCommandEvent& WXUNUSED(event) )
+{
+    /* Show/hide the open dialog */
+    SoutDialog dialog( p_intf, p_main_interface );
+
+    if( dialog.ShowModal() == wxID_OK )
+    {
+        config_PutPsz( p_intf, "sout", (char *)dialog.mrl.c_str() );
+    }
+}
+
+/*****************************************************************************
+ * Demux dump event methods.
+ *****************************************************************************/
+void OpenDialog::OnDemuxDumpEnable( wxCommandEvent& event )
+{
+    demuxdump_textctrl->Enable( event.GetInt() != 0 );
+    demuxdump_button->Enable( event.GetInt() != 0 );
+
+    if( event.GetInt() )
+    {
+        sout_checkbox->SetValue( 0 );
+        wxCommandEvent event = wxCommandEvent( wxEVT_NULL );
+        event.SetInt( 0 );
+        OnSoutEnable( event );
+    }
+
+    UpdateMRL( i_current_access_method );
+}
+
+void OpenDialog::OnDemuxDumpBrowse( wxCommandEvent& WXUNUSED(event) )
+{
+    wxFileDialog dialog( this, _("Save file"), "", "", "*.*", wxSAVE );
+
+    if( dialog.ShowModal() == wxID_OK )
+    {
+        demuxdump_textctrl->SetValue( dialog.GetPath() );
+        wxCommandEvent event = wxCommandEvent( wxEVT_NULL );
+        OnDemuxDumpChange( event );
+    }
+}
+
+void OpenDialog::OnDemuxDumpChange( wxCommandEvent& WXUNUSED(event) )
+{
+    config_PutPsz( p_intf, "demuxdump-file",
+                   demuxdump_textctrl->GetValue() );
+}