Commit 65b5865c authored by Gildas Bazin's avatar Gildas Bazin

* modules/gui/wxwindows/*: bookmarks improvements.

parent 89f8daf2
......@@ -34,6 +34,10 @@
#include "wxwindows.h"
/* Callback prototype */
static int PlaylistChanged( vlc_object_t *, const char *,
vlc_value_t, vlc_value_t, void * );
/*****************************************************************************
* Event Table.
*****************************************************************************/
......@@ -43,16 +47,22 @@ enum
{
/* menu items */
ButtonAdd_Event = wxID_HIGHEST + 1,
ButtonDel_Event
ButtonDel_Event,
ButtonClear_Event
};
DEFINE_LOCAL_EVENT_TYPE( wxEVT_BOOKMARKS );
BEGIN_EVENT_TABLE(BookmarksDialog, wxFrame)
/* Hide the window when the user closes the window */
EVT_CLOSE(BookmarksDialog::OnClose )
EVT_BUTTON( ButtonAdd_Event, BookmarksDialog::OnAdd )
EVT_BUTTON( ButtonDel_Event, BookmarksDialog::OnDel )
EVT_BUTTON( ButtonClear_Event, BookmarksDialog::OnClear )
EVT_LIST_ITEM_ACTIVATED( -1, BookmarksDialog::OnActivateItem )
EVT_COMMAND( -1, wxEVT_BOOKMARKS, BookmarksDialog::OnUpdate )
END_EVENT_TABLE()
/*****************************************************************************
......@@ -80,8 +90,11 @@ BookmarksDialog::BookmarksDialog( intf_thread_t *_p_intf, wxWindow *p_parent )
new wxButton( panel, ButtonAdd_Event, wxU(_("Add")) );
wxButton *button_del =
new wxButton( panel, ButtonDel_Event, wxU(_("Remove")) );
wxButton *button_clear =
new wxButton( panel, ButtonClear_Event, wxU(_("Clear")) );
panel_sizer->Add( button_add, 0, wxEXPAND );
panel_sizer->Add( button_del, 0, wxEXPAND );
panel_sizer->Add( button_clear, 0, wxEXPAND );
panel->SetSizerAndFit( panel_sizer );
list_ctrl = new wxListView( this, -1, wxDefaultPosition, wxDefaultSize,
......@@ -95,10 +108,27 @@ BookmarksDialog::BookmarksDialog( intf_thread_t *_p_intf, wxWindow *p_parent )
sizer->Add( panel, 0, wxEXPAND | wxALL, 5 );
sizer->Add( list_ctrl, 1, wxEXPAND | wxALL, 5 );
SetSizer( sizer );
playlist_t *p_playlist =
(playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE );
if( p_playlist )
{
/* Some global changes happened -> Rebuild all */
var_AddCallback( p_playlist, "playlist-current", PlaylistChanged, this );
}
}
BookmarksDialog::~BookmarksDialog()
{
playlist_t *p_playlist =
(playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE );
if( p_playlist )
{
/* Some global changes happened -> Rebuild all */
var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
}
}
/*****************************************************************************
......@@ -115,6 +145,7 @@ void BookmarksDialog::Update()
seekpoint_t **pp_bookmarks;
int i_bookmarks;
list_ctrl->DeleteAllItems();
if( input_Control( p_input, INPUT_GET_BOOKMARKS, &pp_bookmarks,
&i_bookmarks ) != VLC_SUCCESS )
{
......@@ -122,7 +153,6 @@ void BookmarksDialog::Update()
return;
}
list_ctrl->DeleteAllItems();
for( int i = 0; i < i_bookmarks; i++ )
{
list_ctrl->InsertItem( i, wxL2U( pp_bookmarks[i]->psz_name ) );
......@@ -158,7 +188,7 @@ void BookmarksDialog::OnAdd( wxCommandEvent& event )
var_Get( p_input, "position", &pos );
bookmark.psz_name = NULL;
bookmark.i_byte_offset =
(pos.f_float * p_input->stream.p_selected_area->i_size);
(int64_t)((double)pos.f_float * p_input->stream.p_selected_area->i_size);
var_Get( p_input, "time", &pos );
bookmark.i_time_offset = pos.i_time;
input_Control( p_input, INPUT_ADD_BOOKMARK, &bookmark );
......@@ -186,6 +216,20 @@ void BookmarksDialog::OnDel( wxCommandEvent& event )
Update();
}
void BookmarksDialog::OnClear( wxCommandEvent& event )
{
input_thread_t *p_input =
(input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
FIND_ANYWHERE );
if( !p_input ) return;
input_Control( p_input, INPUT_CLEAR_BOOKMARKS );
vlc_object_release( p_input );
Update();
}
void BookmarksDialog::OnActivateItem( wxListEvent& event )
{
input_thread_t *p_input =
......@@ -197,3 +241,24 @@ void BookmarksDialog::OnActivateItem( wxListEvent& event )
vlc_object_release( p_input );
}
void BookmarksDialog::OnUpdate( wxCommandEvent &event )
{
Update();
}
/*****************************************************************************
* PlaylistChanged: callback triggered by the intf-change playlist variable
* We don't rebuild the playlist directly here because we don't want the
* caller to block for a too long time.
*****************************************************************************/
static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t oval, vlc_value_t nval, void *param )
{
BookmarksDialog *p_dialog = (BookmarksDialog *)param;
wxCommandEvent bookmarks_event( wxEVT_BOOKMARKS, 0 );
p_dialog->AddPendingEvent( bookmarks_event );
return VLC_SUCCESS;
}
......@@ -30,12 +30,12 @@
#include "wxwindows.h"
/* Callback prototype */
int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t old_val, vlc_value_t new_val, void *param );
int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t old_val, vlc_value_t new_val, void *param );
int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t old_val, vlc_value_t new_val, void *param );
static int PlaylistChanged( vlc_object_t *, const char *,
vlc_value_t, vlc_value_t, void * );
static int PlaylistNext( vlc_object_t *, const char *,
vlc_value_t, vlc_value_t, void * );
static int ItemChanged( vlc_object_t *, const char *,
vlc_value_t, vlc_value_t, void * );
/*****************************************************************************
* Event Table.
......@@ -1229,8 +1229,8 @@ void Playlist::OnPlaylistEvent( wxCommandEvent& event )
* We don't rebuild the playlist directly here because we don't want the
* caller to block for a too long time.
*****************************************************************************/
int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t old_val, vlc_value_t new_val, void *param )
static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t oval, vlc_value_t nval, void *param )
{
Playlist *p_playlist_dialog = (Playlist *)param;
p_playlist_dialog->b_need_update = VLC_TRUE;
......@@ -1240,15 +1240,15 @@ int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
/*****************************************************************************
* Next: callback triggered by the playlist-current playlist variable
*****************************************************************************/
int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t old_val, vlc_value_t new_val, void *param )
static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t oval, vlc_value_t nval, void *param )
{
Playlist *p_playlist_dialog = (Playlist *)param;
wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
event.SetInt( old_val.i_int );
event.SetInt( oval.i_int );
p_playlist_dialog->AddPendingEvent( event );
event.SetInt( new_val.i_int );
event.SetInt( nval.i_int );
p_playlist_dialog->AddPendingEvent( event );
return 0;
......@@ -1257,7 +1257,7 @@ int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
/*****************************************************************************
* ItemChanged: callback triggered by the item-change playlist variable
*****************************************************************************/
int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t old_val, vlc_value_t new_val, void *param )
{
Playlist *p_playlist_dialog = (Playlist *)param;
......
......@@ -1018,7 +1018,9 @@ private:
void OnClose( wxCommandEvent& event );
void OnAdd( wxCommandEvent& event );
void OnDel( wxCommandEvent& event );
void OnClear( wxCommandEvent& event );
void OnActivateItem( wxListEvent& event );
void OnUpdate( wxCommandEvent &event );
DECLARE_EVENT_TABLE();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment