Video4Linux / PVR / KFIR unified panel
[vlc.git] / modules / gui / wxwindows / open.cpp
index a6961ae..32f7e58 100644 (file)
@@ -2,7 +2,7 @@
  * open.cpp : wxWindows plugin for vlc
  *****************************************************************************
  * Copyright (C) 2000-2001 VideoLAN
- * $Id: open.cpp,v 1.36 2003/08/10 09:22:07 gbazin Exp $
+ * $Id: open.cpp,v 1.37 2003/08/19 21:16:09 adn Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
@@ -79,6 +79,11 @@ enum
     NetPort1_Event, NetPort2_Event, NetPort3_Event,
     NetAddr1_Event, NetAddr2_Event, NetAddr3_Event,
 
+    VideoType_Event,
+    VideoDevice_Event,
+    VideoChannel_Event,
+    V4LSettings_Event,
+
     SubsFileEnable_Event,
     SubsFileSettings_Event,
 
@@ -97,7 +102,7 @@ BEGIN_EVENT_TABLE(OpenDialog, wxFrame)
 
     EVT_NOTEBOOK_PAGE_CHANGED(Notebook_Event, OpenDialog::OnPageChange)
 
-    EVT_TEXT(MRL_Event, OpenDialog::OnMRLChange) 
+    EVT_TEXT(MRL_Event, OpenDialog::OnMRLChange)
 
     /* Events generated by the file panel */
     EVT_TEXT(FileName_Event, OpenDialog::OnFilePanelChange)
@@ -124,6 +129,12 @@ BEGIN_EVENT_TABLE(OpenDialog, wxFrame)
     EVT_TEXT(NetAddr2_Event, OpenDialog::OnNetPanelChange)
     EVT_TEXT(NetAddr3_Event, OpenDialog::OnNetPanelChange)
 
+    /* Events generated by the v4l panel */
+    EVT_RADIOBOX(VideoType_Event, OpenDialog::OnV4LTypeChange)
+    EVT_TEXT(VideoDevice_Event, OpenDialog::OnV4LPanelChange)
+    EVT_SPINCTRL(VideoChannel_Event, OpenDialog::OnV4LPanelChange)
+    EVT_BUTTON(V4LSettings_Event, OpenDialog::OnV4LSettingsChange)
+
     /* Events generated by the subtitle file buttons */
     EVT_CHECKBOX(SubsFileEnable_Event, OpenDialog::OnSubsFileEnable)
     EVT_BUTTON(SubsFileSettings_Event, OpenDialog::OnSubsFileSettings)
@@ -155,6 +166,7 @@ OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
     p_parent = _p_parent;
     SetIcon( *p_intf->p_sys->p_icon );
     file_dialog = NULL;
+    v4l_dialog = NULL;
     sout_dialog = NULL;
     subsfile_dialog = NULL;
     demuxdump_dialog = NULL;
@@ -261,6 +273,9 @@ OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
                        i_access_method == SAT_ACCESS );
 #endif
 
+    notebook->AddPage( V4LPanel( notebook ), wxU(_("Video For Linux")),
+                       i_access_method == V4L_ACCESS );
+
     /* Update Disc panel */
     wxCommandEvent dummy_event;
     OnDiscTypeChange( dummy_event );
@@ -269,6 +284,10 @@ OpenDialog::OpenDialog( intf_thread_t *_p_intf, wxWindow *_p_parent,
     dummy_event.SetId( NetRadio1_Event );
     OnNetTypeChange( dummy_event );
 
+    /* Update v4l panel */
+    dummy_event.SetId( VideoType_Event );
+    OnV4LTypeChange( dummy_event );
+
     /* Update MRL */
     wxNotebookEvent event( wxEVT_NULL, 0, i_access_method );
     OnPageChange( event );
@@ -298,6 +317,7 @@ OpenDialog::~OpenDialog()
 {
     /* Clean up */
     if( file_dialog ) delete file_dialog;
+    if( v4l_dialog ) delete v4l_dialog;
     if( sout_dialog ) delete sout_dialog;
     if( subsfile_dialog ) delete subsfile_dialog;
     if( demuxdump_dialog ) delete demuxdump_dialog;
@@ -513,6 +533,61 @@ wxPanel *OpenDialog::NetPanel( wxWindow* parent )
     return panel;
 }
 
+wxPanel *OpenDialog::V4LPanel( wxWindow* parent )
+{
+    wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
+                                  wxSize(200, 200) );
+
+    wxBoxSizer *sizer_row = new wxBoxSizer( wxVERTICAL );
+    wxFlexGridSizer *sizer = new wxFlexGridSizer( 1, 4, 20 );
+
+    static const wxString video_type_array[] =
+    {
+        wxU(_("WebCam")),
+        wxU(_("TV Card")),
+        wxU(_("PVR")),
+        wxU(_("Kfir")),
+    };
+
+    video_type = new wxRadioBox( panel, VideoType_Event,
+            wxU(_("Video Device Type")),
+            wxDefaultPosition, wxDefaultSize,
+            WXSIZEOF(video_type_array), video_type_array,
+            WXSIZEOF(video_type_array), wxRA_SPECIFY_COLS );
+
+    sizer_row->Add( video_type, 0, wxEXPAND | wxALL, 5 );
+
+
+    /* Video Options */
+    wxFlexGridSizer *video_sizer = new wxFlexGridSizer( 4, 2, 20 );
+    wxStaticText *label = new wxStaticText( panel, -1, wxU(_("Video Device")) );
+    video_device = new wxTextCtrl( panel, VideoDevice_Event, wxT(""),
+                                  wxDefaultPosition, wxDefaultSize,
+                                  wxTE_PROCESS_ENTER);
+
+    video_sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
+    video_sizer->Add( video_device, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
+
+    label = new wxStaticText( panel, -1, wxU(_("Channel")) );
+    video_channel = new wxSpinCtrl( panel, VideoChannel_Event );
+
+    video_sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_HORIZONTAL );
+    video_sizer->Add( video_channel, 1, wxALIGN_LEFT | wxALIGN_CENTER_HORIZONTAL );
+    sizer->Add( video_sizer, 0, wxEXPAND | wxALL, 5 );
+
+    wxBoxSizer *v4lbutton_sizer = new wxBoxSizer( wxHORIZONTAL );
+    v4l_button = new wxButton( panel, V4LSettings_Event,
+                            wxU(_("Advanced Settings...")) );
+
+    v4lbutton_sizer->Add( v4l_button, 0, wxALIGN_RIGHT, 5 );
+
+    sizer_row->Add( sizer, 0, wxEXPAND | wxALL, 5 );
+    sizer_row->Add( v4lbutton_sizer, 0, wxEXPAND | wxALL, 5 );
+
+    panel->SetSizerAndFit( sizer_row );
+    return panel;
+}
+
 wxPanel *OpenDialog::SatPanel( wxWindow* parent )
 {
     wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
@@ -576,7 +651,7 @@ void OpenDialog::UpdateMRL( int i_access_method )
             break;
 
         case 2:
-            /* http access */     
+            /* http access */
             mrltemp = wxT("http") + demux + wxT("://") +
                       net_addrs[2]->GetLineText(0);
             break;
@@ -585,6 +660,28 @@ void OpenDialog::UpdateMRL( int i_access_method )
     case SAT_ACCESS:
         mrltemp = wxT("satellite") + demux + wxT("://");
         break;
+
+    case V4L_ACCESS:
+        mrltemp = ( video_type->GetSelection() == 0 ? wxT("v4l") :
+                    video_type->GetSelection() == 1 ? wxT("v4l") :
+                    video_type->GetSelection() == 2 ? wxT("pvr") :
+                                                      wxT("kfir") )
+            + demux + wxT(":")
+            + video_device->GetLineText( 0 );
+
+        if( video_type->GetSelection() == 1 )
+        {
+            mrltemp += wxString::Format( wxT(":channel=%d"),
+                                         video_channel->GetValue() );
+        }
+
+        if ( /* v4l_dialog != NULL && */ !v4l_mrl.IsEmpty() )
+        {
+            mrltemp += v4l_mrl[0];
+        }
+
+        break;
+
     default:
         break;
     }
@@ -605,7 +702,7 @@ void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
     /* Update the playlist */
     playlist_t *p_playlist =
         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
-                                      FIND_ANYWHERE );
+                                       FIND_ANYWHERE );
     if( p_playlist == NULL ) return;
 
     for( int i = 0; i < (int)mrl.GetCount(); i++ )
@@ -629,7 +726,7 @@ void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
             ppsz_options[j] = strdup( mrl[i + j  + 1].mb_str() );
         }
 
-       i_total_options = i_options;
+        i_total_options = i_options;
 
         /* Get the options from the subtitles dialog */
         if( subsfile_checkbox->IsChecked() && subsfile_mrl.GetCount() )
@@ -646,6 +743,22 @@ void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
             i_total_options += subsfile_mrl.GetCount();
         }
 
+        /* Get the options from the v4l dialog */
+/*        if( v4l_mrl.GetCount() )
+        {
+            ppsz_options = (char **)realloc( ppsz_options, sizeof(char *) *
+                               (i_total_options + v4l_mrl.GetCount()) );
+
+            for( int j = 0; j < (int)v4l_mrl.GetCount(); j++ )
+            {
+                ppsz_options[i_total_options + j] =
+                    strdup( v4l_mrl[j].mb_str() );
+            }
+
+            i_total_options += v4l_mrl.GetCount();
+
+        }
+*/
         /* Get the options from the stream output dialog */
         if( sout_checkbox->IsChecked() && sout_mrl.GetCount() )
         {
@@ -659,6 +772,7 @@ void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
             }
 
             i_total_options += sout_mrl.GetCount();
+
         }
 
         playlist_Add( p_playlist, (const char *)mrl[i].mb_str(),
@@ -813,6 +927,52 @@ void OpenDialog::OnNetTypeChange( wxCommandEvent& event )
     UpdateMRL( NET_ACCESS );
 }
 
+/*****************************************************************************
+ * v4l panel event methods.
+ *****************************************************************************/
+void OpenDialog::OnV4LPanelChange( wxCommandEvent& WXUNUSED(event) )
+{
+    UpdateMRL( V4L_ACCESS );
+}
+
+void OpenDialog::OnV4LTypeChange( wxCommandEvent& WXUNUSED(event) )
+{
+    video_device->SetValue( wxU( "/dev/video" ) );
+
+    v4l_button->Enable();
+    video_channel->Disable();
+
+    switch( video_type->GetSelection() )
+    {
+        case 1:
+            video_channel->Enable();
+            video_channel->SetRange( 0, 255 );
+            video_channel->SetValue( 0 );
+           break;
+        case 3:
+            v4l_button->Disable();
+            break;
+        default:
+            break;
+    }
+
+    UpdateMRL( V4L_ACCESS );
+}
+
+void OpenDialog::OnV4LSettingsChange( wxCommandEvent& WXUNUSED(event) )
+{
+    /* Show/hide the open dialog */
+    if( v4l_dialog == NULL )
+        v4l_dialog = new V4LDialog( p_intf, this );
+
+    if( v4l_dialog && v4l_dialog->ShowModal() == wxID_OK )
+    {
+        v4l_mrl = v4l_dialog->GetOptions();
+    }
+
+    UpdateMRL( V4L_ACCESS );
+}
+
 /*****************************************************************************
  * Subtitles file event methods.
  *****************************************************************************/