]> git.sesse.net Git - vlc/commitdiff
* Interaction between bookmarks and streaming wizard
authorClément Stenac <zorglub@videolan.org>
Sun, 6 Jun 2004 12:44:35 +0000 (12:44 +0000)
committerClément Stenac <zorglub@videolan.org>
Sun, 6 Jun 2004 12:44:35 +0000 (12:44 +0000)
* Edit bookmarks if possible

include/ninput.h
modules/gui/wxwindows/bookmarks.cpp
modules/gui/wxwindows/dialogs.cpp
modules/gui/wxwindows/wizard.cpp
modules/gui/wxwindows/wxwindows.h
src/input/control.c

index 7c3a525092f023d625af596fced74c15843d01ea..07f8599b40260c9672e085db3855a5c74d201113 100644 (file)
@@ -593,6 +593,7 @@ enum input_query_e
     INPUT_GET_BOOKMARKS,   /* arg1= seekpoint_t *** arg2= int * res=can fail */
     INPUT_CLEAR_BOOKMARKS, /* res=can fail */
     INPUT_ADD_BOOKMARK,    /* arg1= seekpoint_t *  res=can fail   */
+    INPUT_CHANGE_BOOKMARK, /* arg1= seekpoint_t * arg2= int * res=can fail   */
     INPUT_DEL_BOOKMARK,    /* arg1= seekpoint_t *  res=can fail   */
     INPUT_SET_BOOKMARK,    /* arg1= int  res=can fail    */
 
index 5b907ade64ad2aa069a76bc944940f8f7a80dd8a..bf61f516d1be65232c3373041337eb5d2f9bb6ef 100644 (file)
@@ -32,6 +32,8 @@
 #include <vlc/vlc.h>
 #include <vlc/intf.h>
 
+#include <wx/dialog.h>
+
 #include "wxwindows.h"
 
 /* Callback prototype */
@@ -41,6 +43,18 @@ static int PlaylistChanged( vlc_object_t *, const char *,
 /*****************************************************************************
  * Class declaration.
  *****************************************************************************/
+
+/* IDs for the controls and the menu commands */
+enum
+{
+    /* menu items */
+    ButtonAdd_Event = wxID_HIGHEST + 1,
+    ButtonDel_Event,
+    ButtonClear_Event,
+    ButtonExtract_Event,
+    ButtonEdit_Event
+};
+
 class BookmarksDialog: public wxFrame
 {
 public:
@@ -61,6 +75,8 @@ private:
     void OnClear( wxCommandEvent& event );
     void OnActivateItem( wxListEvent& event );
     void OnUpdate( wxCommandEvent &event );
+    void OnEdit( wxCommandEvent& event );
+    void OnExtract( wxCommandEvent& event );
 
     DECLARE_EVENT_TABLE();
 
@@ -69,20 +85,6 @@ private:
 
     wxListView *list_ctrl;
 };
-
-/*****************************************************************************
- * Event Table.
- *****************************************************************************/
-
-/* IDs for the controls and the menu commands */
-enum
-{
-    /* menu items */
-    ButtonAdd_Event = wxID_HIGHEST + 1,
-    ButtonDel_Event,
-    ButtonClear_Event
-};
-
 DEFINE_LOCAL_EVENT_TYPE( wxEVT_BOOKMARKS );
 
 BEGIN_EVENT_TABLE(BookmarksDialog, wxFrame)
@@ -91,12 +93,100 @@ BEGIN_EVENT_TABLE(BookmarksDialog, wxFrame)
     EVT_BUTTON( ButtonAdd_Event, BookmarksDialog::OnAdd )
     EVT_BUTTON( ButtonDel_Event, BookmarksDialog::OnDel )
     EVT_BUTTON( ButtonClear_Event, BookmarksDialog::OnClear )
+    EVT_BUTTON( ButtonExtract_Event, BookmarksDialog::OnExtract )
+    EVT_BUTTON( ButtonEdit_Event, BookmarksDialog::OnEdit )
 
     EVT_LIST_ITEM_ACTIVATED( -1, BookmarksDialog::OnActivateItem )
 
     EVT_COMMAND( -1, wxEVT_BOOKMARKS, BookmarksDialog::OnUpdate )
 END_EVENT_TABLE()
 
+/* Declaration of class BookmarkEditDialog */
+class BookmarkEditDialog : public wxDialog
+{
+public:
+    /* Constructor */
+    BookmarkEditDialog( intf_thread_t *p_intf, wxWindow *p_parent,
+                  seekpoint_t *p_seekpoint );
+    virtual ~BookmarkEditDialog();
+    seekpoint_t *p_seekpoint;
+private:
+
+    wxTextCtrl *name_text, *time_text, *bytes_text;
+
+    void OnOK( wxCommandEvent& event);
+    void OnCancel( wxCommandEvent& event);
+
+    DECLARE_EVENT_TABLE();
+
+    intf_thread_t *p_intf;
+};
+
+BEGIN_EVENT_TABLE( BookmarkEditDialog, wxDialog)
+            EVT_BUTTON( wxID_OK, BookmarkEditDialog::OnOK)
+END_EVENT_TABLE()
+/****************************************************************************
+ * BookmarkEditDialog
+ ***************************************************************************/
+BookmarkEditDialog::BookmarkEditDialog( intf_thread_t *_p_intf,
+           wxWindow *_p_parent, seekpoint_t *_p_seekpoint ):wxDialog(
+            _p_parent, -1, wxU(_("Edit bookmark")), wxDefaultPosition,
+            wxDefaultSize, wxDEFAULT_FRAME_STYLE )
+{
+    /* Initializations */
+    p_intf = _p_intf;
+    p_seekpoint = _p_seekpoint;
+    SetIcon( *p_intf->p_sys->p_icon );
+
+    /* Create a panel to put everything in*/
+    wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
+
+    wxFlexGridSizer * sizer = new wxFlexGridSizer( 2 , 3 , 1 );
+    name_text = new wxTextCtrl( this, -1, wxU( p_seekpoint->psz_name ?
+                                               p_seekpoint->psz_name : "" ),
+                                wxDefaultPosition, wxSize( 100, 20) );
+    time_text = new wxTextCtrl( this, -1, wxString::Format(wxT("%d"),
+                                p_seekpoint->i_time_offset/1000000 ),
+                                wxDefaultPosition, wxSize( 100, 20) );
+    bytes_text = new wxTextCtrl( this, -1, wxString::Format(wxT("%d"),
+                                p_seekpoint->i_byte_offset ),
+                                wxDefaultPosition, wxSize( 100, 20) );
+
+    sizer->Add( new wxStaticText( this, -1, wxU(_("Name") ) ), 0, wxLEFT, 5 );
+    sizer->Add( name_text, 0, wxEXPAND|wxRIGHT , 5 );
+    sizer->Add( new wxStaticText( this, -1, wxU(_("Time") ) ), 0, wxLEFT, 5 );
+    sizer->Add( time_text , 0, wxEXPAND|wxRIGHT , 5);
+    sizer->Add( new wxStaticText( this, -1, wxU(_("Bytes") ) ), 0, wxLEFT, 5 );
+    sizer->Add( bytes_text, 0, wxEXPAND|wxRIGHT, 5);
+
+    wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
+    button_sizer->Add( new wxButton( this, wxID_OK, wxU(_("OK") ) ) );
+    button_sizer->Add( new wxButton( this, wxID_CANCEL, wxU(_("Cancel") ) ) );
+
+    panel_sizer->Add( sizer, 0, wxEXPAND | wxTOP|wxBOTTOM, 5 );
+    panel_sizer->Add( button_sizer, 0, wxEXPAND | wxBOTTOM, 5 );
+    panel_sizer->Layout();
+    SetSizerAndFit( panel_sizer );
+}
+
+BookmarkEditDialog::~BookmarkEditDialog()
+{
+}
+void BookmarkEditDialog::OnOK( wxCommandEvent &event )
+{
+    if( p_seekpoint->psz_name ) free( p_seekpoint->psz_name );
+    p_seekpoint->psz_name = strdup( name_text->GetValue().c_str() );
+    p_seekpoint->i_byte_offset = atoi( bytes_text->GetValue().c_str() );
+    p_seekpoint->i_time_offset =  1000000 *
+                                  atoll( time_text->GetValue().c_str() ) ;
+    EndModal( wxID_OK );
+}
+
+void BookmarkEditDialog::OnCancel( wxCommandEvent &event )
+{
+    EndModal( wxID_CANCEL );
+}
+
 /*****************************************************************************
  * Constructor.
  *****************************************************************************/
@@ -127,15 +217,35 @@ BookmarksDialog::BookmarksDialog( intf_thread_t *_p_intf, wxWindow *p_parent )
         new wxButton( panel, ButtonDel_Event, wxU(_("Remove")) );
     wxButton *button_clear =
         new wxButton( panel, ButtonClear_Event, wxU(_("Clear")) );
+    wxButton *button_edit =
+        new wxButton( panel, ButtonEdit_Event, wxU(_("Edit")) );
+    wxButton *button_extract =
+        new wxButton( panel, ButtonExtract_Event, wxU(_("Extract")) );
+
+#define ADD_TEXT "Adds a bookmark at the current position in the stream"
+#define REMOVE_TEXT "Removes the selected bookmarks"
+#define CLEAR_TEXT "Removes all the bookmarks for that stream"
+#define EDIT_TEXT "Edit the properties of a bookmark"
+#define EXTRACT_TEXT "If you select two or more bookmarks, this will " \
+               "launch the streaming/transcoding wizard to allow you to " \
+              "stream or save the part of the stream between these bookmarks"
+    button_add->SetToolTip(  wxU(_( ADD_TEXT ) ) );
+    button_del->SetToolTip(  wxU(_( REMOVE_TEXT ) ) );
+    button_clear->SetToolTip(  wxU(_( CLEAR_TEXT ) ) );
+    button_edit->SetToolTip(  wxU(_( EDIT_TEXT ) ) );
+    button_extract->SetToolTip( wxU(_( EXTRACT_TEXT ) ) );
+
     panel_sizer->Add( button_add, 0, wxEXPAND );
     panel_sizer->Add( button_del, 0, wxEXPAND );
     panel_sizer->Add( button_clear, 0, wxEXPAND );
+    panel_sizer->Add( button_edit, 0, wxEXPAND );
+    panel_sizer->Add( 0, 0, 1 );
+    panel_sizer->Add( button_extract, 0, wxEXPAND );
     panel->SetSizerAndFit( panel_sizer );
 
     list_ctrl = new wxListView( main_panel, -1,
                                 wxDefaultPosition, wxDefaultSize,
-                                wxLC_REPORT | wxSUNKEN_BORDER |
-                                wxLC_SINGLE_SEL );
+                                wxLC_REPORT | wxSUNKEN_BORDER );
     list_ctrl->InsertColumn( 0, wxU(_("Description")) );
     list_ctrl->SetColumnWidth( 0, 240 );
     list_ctrl->InsertColumn( 1, wxU(_("Size offset")) );
@@ -202,9 +312,9 @@ void BookmarksDialog::Update()
     for( int i = 0; i < i_bookmarks; i++ )
     {
         list_ctrl->InsertItem( i, wxL2U( pp_bookmarks[i]->psz_name ) );
-        list_ctrl->SetItem( i, 1, wxString::Format(wxT("%i"),
+        list_ctrl->SetItem( i, 1, wxString::Format(wxT("%d"),
                             pp_bookmarks[i]->i_byte_offset ) );
-        list_ctrl->SetItem( i, 2, wxString::Format(wxT("%i"),
+        list_ctrl->SetItem( i, 2, wxString::Format(wxT("%d"),
                             pp_bookmarks[i]->i_time_offset/1000000 ) );
     }
 
@@ -276,6 +386,61 @@ void BookmarksDialog::OnClear( wxCommandEvent& event )
     Update();
 }
 
+void BookmarksDialog::OnExtract( wxCommandEvent& event )
+{
+    long i_first = list_ctrl->GetNextItem( -1, wxLIST_NEXT_ALL,
+                                          wxLIST_STATE_SELECTED );
+    long i_second = list_ctrl->GetNextItem( i_first, wxLIST_NEXT_ALL,
+                                          wxLIST_STATE_SELECTED );
+
+    if( i_first == -1 || i_second == -1 )
+    {
+        wxMessageBox( wxU(_("You must select two bookmarks") ),
+                      wxU(_("Invalid selection") ), wxICON_WARNING | wxOK,
+                      this );
+        return;
+    }
+    input_thread_t *p_input =
+        (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
+                                           FIND_ANYWHERE );
+    if( !p_input )
+    {
+        wxMessageBox( wxU(_("The stream must be playing or paused for "
+                            "bookmarks to work" ) ), wxU(_("No input found")),
+                            wxICON_WARNING | wxOK,
+                            this );
+        return;
+    }
+
+    seekpoint_t **pp_bookmarks;
+    int i_bookmarks ;
+
+    if( input_Control( p_input, INPUT_GET_BOOKMARKS, &pp_bookmarks,
+                       &i_bookmarks ) != VLC_SUCCESS )
+    {
+        vlc_object_release( p_input );
+        return;
+    }
+
+    if( i_first < i_bookmarks && i_second <= i_bookmarks )
+    {
+        WizardDialog *p_wizard_dialog = new WizardDialog( p_intf, this,
+                               p_input->p_item->psz_uri,
+                               pp_bookmarks[i_first]->i_time_offset/1000000,
+                               pp_bookmarks[i_second]->i_time_offset/1000000 );
+        vlc_object_release( p_input );
+        if( p_wizard_dialog )
+        {
+            p_wizard_dialog->Run();
+            delete p_wizard_dialog;
+        }
+    }
+    else
+    {
+        vlc_object_release( p_input );
+    }
+}
+
 void BookmarksDialog::OnActivateItem( wxListEvent& event )
 {
     input_thread_t *p_input =
@@ -288,6 +453,74 @@ void BookmarksDialog::OnActivateItem( wxListEvent& event )
     vlc_object_release( p_input );
 }
 
+void BookmarksDialog::OnEdit( wxCommandEvent& event )
+{
+    input_thread_t *p_old_input;
+    input_thread_t *p_input =
+            (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
+                                                   FIND_ANYWHERE );
+    if( !p_input ) return;
+
+
+    seekpoint_t **pp_bookmarks;
+    int i_bookmarks;
+
+    if( input_Control( p_input, INPUT_GET_BOOKMARKS, &pp_bookmarks,
+                       &i_bookmarks ) != VLC_SUCCESS )
+    {
+        vlc_object_release( p_input );
+        return;
+    }
+    p_old_input = p_input;
+    vlc_object_release( p_input );
+
+    long i_first = list_ctrl->GetNextItem( -1, wxLIST_NEXT_ALL,
+                                               wxLIST_STATE_SELECTED );
+
+    if( i_first > -1 && i_first <= i_bookmarks )
+    {
+        BookmarkEditDialog *p_bmk_edit;
+        p_bmk_edit = new BookmarkEditDialog( p_intf, this,
+                               pp_bookmarks[i_first]);
+
+        if( p_bmk_edit->ShowModal() == wxID_OK )
+        {
+            p_input =(input_thread_t *)vlc_object_find( p_intf,
+                            VLC_OBJECT_INPUT, FIND_ANYWHERE );
+           if( !p_input )
+           {
+                wxMessageBox( wxU( _("No input found. The stream must be "
+                                  "playing or paused for bookmarks to work") ),
+                               wxU( _("No input") ), wxICON_WARNING | wxOK,
+                               this );
+                return;
+           }
+           if( p_old_input != p_input )
+           {
+                wxMessageBox( wxU( _("Input has changed, unable to save "
+                                  "bookmark. Use \"pause\" while editing "
+                                  "bookmarks to keep the same input.") ),
+                               wxU( _("Input has changed ") ),
+                               wxICON_WARNING | wxOK, this );
+                vlc_object_release( p_input );
+                return;
+
+           }
+           fprintf(stderr,"Changing %i\n",i_first );
+           if( input_Control(  p_input, INPUT_CHANGE_BOOKMARK,
+                                p_bmk_edit->p_seekpoint, i_first ) !=
+               VLC_SUCCESS )
+           {
+               vlc_object_release( p_input );
+               return;
+           }
+           Update();
+           vlc_object_release( p_input );
+        }
+    }
+}
+
+
 void BookmarksDialog::OnUpdate( wxCommandEvent &event )
 {
     Update();
index b27b7734703b5d6c64e5486695f5cd9d7a9de773..d0ec7dec037aa05df557d0a3141696b9b56a12d5 100644 (file)
@@ -269,14 +269,14 @@ void DialogsProvider::OnStreamWizardDialog( wxCommandEvent& WXUNUSED(event) )
 
 void DialogsProvider::OnWizardDialog( wxCommandEvent& WXUNUSED(event) )
 {
-    p_wizard_dialog = new WizardDialog( p_intf, this );
+    p_wizard_dialog = new WizardDialog( p_intf, this, NULL, 0, 0 );
 
     if( p_wizard_dialog )
     {
         p_wizard_dialog->Run();
+        delete p_wizard_dialog;
     }
 
-    delete p_wizard_dialog;
     p_wizard_dialog = NULL;
 }
 
index 8fba29170d6994153f6b5fefaeda323eae529fe9..60c0b529b513dc532ad1987ad120ed07a0155e3e 100644 (file)
@@ -217,6 +217,8 @@ class wizInputPage : public wxWizardPage
         void SetTranscodePage( wxWizardPage *page);
         void SetAction( int i_action );
         void SetPintf( intf_thread_t *p_intf );
+        void SetUri( char *psz_uri );
+        void SetPartial( int i_from, int i_to );
     protected:
         bool b_chosen;
         intf_thread_t *p_intf;
@@ -755,6 +757,23 @@ void wizInputPage::SetPintf( intf_thread_t *p_intf )
     this->p_intf = p_intf;
 }
 
+void wizInputPage::SetUri( char *psz_uri )
+{
+    mrl_text->SetValue( wxU( psz_uri ) );
+}
+
+void wizInputPage::SetPartial( int i_from, int i_to )
+{
+   wxString msg;
+   msg.Printf( wxString( wxT( "%i") ), i_from );
+   from_text->Enable( TRUE );
+   from_text->SetValue( msg );
+   msg.Printf( wxString( wxT( "%i") ), i_to );
+   to_text->Enable( TRUE );
+   to_text->SetValue( msg );
+   enable_checkbox->SetValue( TRUE );
+}
+
 /***************************************************
  * First transcode page: choose codecs             *
  ***************************************************/
@@ -1344,7 +1363,8 @@ wizTranscodeExtraPage *tr_page2 ;
 wizStreamingExtraPage *st_page2;
 wizEncapPage *encap_page;
 
-WizardDialog::WizardDialog(intf_thread_t *_p_intf, wxWindow *_p_parent ) :
+WizardDialog::WizardDialog(intf_thread_t *_p_intf, wxWindow *_p_parent,
+                           char *psz_uri, int _i_from, int _i_to  ) :
 wxWizard( _p_parent, -1, wxU(_("Streaming/Transcoding Wizard")), wxNullBitmap, wxDefaultPosition)
 {
     /* Initializations */
@@ -1353,8 +1373,8 @@ wxWizard( _p_parent, -1, wxU(_("Streaming/Transcoding Wizard")), wxNullBitmap, w
 
     /* Initialize structure */
     i_action = 0;
-    i_from = 0;
-    i_to = 0;
+    i_from = _i_from;
+    i_to = _i_to;
     i_ttl = 1;
     vb = 0;
     ab = 0;
@@ -1363,6 +1383,16 @@ wxWizard( _p_parent, -1, wxU(_("Streaming/Transcoding Wizard")), wxNullBitmap, w
 
     page1 = new wizHelloPage(this);
     page2 = new wizInputPage(this, page1, p_intf);
+
+    if( psz_uri )
+    {
+        page2->SetUri( psz_uri );
+    }
+    if( i_from != 0 || i_to != 0 )
+    {
+        page2->SetPartial( i_from, i_to );
+    }
+
     encap_page = new wizEncapPage(this );
     tr_page1 = new wizTranscodeCodecPage(this, encap_page );
     st_page1 = new wizStreamingMethodPage(this, encap_page);
@@ -1474,6 +1504,7 @@ int WizardDialog::GetAction()
 
 void WizardDialog::Run()
 {
+    fprintf(stderr, "p_intf %p %p", p_intf, this->p_intf);
     msg_Dbg( p_intf,"starting wizard");
     if( RunWizard(page1) )
     {
index 6bfa77c3e912d766081607ea84d7f44ea86e4f65..b91d578793c7b5b9a7fdd9cf3ada21c2a026d3e8 100644 (file)
@@ -574,7 +574,7 @@ class WizardDialog : public wxWizard
 {
 public:
     /* Constructor */
-    WizardDialog( intf_thread_t *p_intf, wxWindow *p_parent );
+    WizardDialog( intf_thread_t *p_intf, wxWindow *p_parent,char *, int, int );
     virtual ~WizardDialog();
     void SetTranscode( char *vcodec, int vb, char *acodec,int ab);
     void SetMrl( const char *mrl );
index 2a7adc802b6786e2c5b5d95744c6219fcf34dbab..938ff5be52f79c08ec3995a0ae75f15f361d24bb 100644 (file)
@@ -66,7 +66,8 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
 {
     int     i_ret;
     seekpoint_t *p_bkmk, ***ppp_bkmk;
-    int i_bkmk, *pi_bkmk;
+    int i_bkmk = 0;
+    int *pi_bkmk;
     int i, *pi;
     vlc_value_t val, text;
     char *psz_option, *psz_value;
@@ -284,6 +285,29 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
             i_ret = VLC_SUCCESS;
             break;
 
+        case INPUT_CHANGE_BOOKMARK:
+             p_bkmk = (seekpoint_t *)va_arg( args, seekpoint_t * );
+             i_bkmk = (int)va_arg( args, int );
+
+             if( i_bkmk < p_input->i_bookmarks )
+             {
+                 p_input->pp_bookmarks[i_bkmk] = p_bkmk;
+
+                 /* Reflect the changes on the object var */
+                 var_Change( p_input, "bookmark", VLC_VAR_CLEARCHOICES, 0, 0 );
+                 for( i = 0; i < p_input->i_bookmarks; i++ )
+                 {
+                     val.i_int = i;
+                     text.psz_string = p_input->pp_bookmarks[i]->psz_name;
+                     var_Change( p_input, "bookmark", VLC_VAR_ADDCHOICE,
+                                 &val, &text );
+                 }
+             }
+             UpdateBookmarksOption( p_input );
+
+             i_ret = VLC_SUCCESS;
+             break;
+
         case INPUT_DEL_BOOKMARK:
             i_bkmk = (int)va_arg( args, int );
             if( i_bkmk < p_input->i_bookmarks )