Commit a644825a authored by Gildas Bazin's avatar Gildas Bazin

* modules/gui/wxwidgets: massive cleanup and simplification of the main interface code.

parent 70e52acc
......@@ -8,8 +8,7 @@ SOURCES_wxwidgets = \
menus.cpp \
timer.cpp \
video.cpp \
slider_manager.cpp \
main_slider_manager.cpp \
input_manager.cpp \
dialogs.cpp \
dialogs/open.cpp \
dialogs/streamout.cpp \
......@@ -41,8 +40,7 @@ EXTRA_DIST += \
extrapanel.hpp \
timer.hpp \
video.hpp \
slider_manager.hpp \
main_slider_manager.hpp \
input_manager.hpp \
dialogs/fileinfo.hpp \
dialogs/preferences.hpp \
dialogs/wizard.hpp \
......
......@@ -2,7 +2,7 @@
* vlm_slider_manager.cpp : Manage an input slider for a VLM stream
*****************************************************************************
* Copyright (C) 2000-2005 the VideoLAN team
* $Id: timer.cpp 11981 2005-08-03 15:03:23Z xtophe $
* $Id$
*
* Authors: Clment Stenac <zorglub@videolan.org>
*
......@@ -32,11 +32,13 @@
* Constructor.
*****************************************************************************/
VLMSliderManager::VLMSliderManager( intf_thread_t *_p_intf,
VLMBroadcastStreamPanel *_p_sp ) :
SliderManager( _p_intf )
VLMBroadcastStreamPanel *_p_sp )
{
p_intf = _p_intf;
p_input = NULL;
p_sp = _p_sp;
_slider = p_sp->p_slider;
slider = p_sp->p_slider;
b_slider_free = VLC_TRUE;
time_string = wxU( "0:00:00 / 0:00:00");
......@@ -47,9 +49,75 @@ VLMSliderManager::~VLMSliderManager()
}
/*****************************************************************************
* Private methods.
* Public methods.
*****************************************************************************/
void VLMSliderManager::Update()
{
/* Update the input */
if( p_input == NULL )
{
UpdateInput();
if( p_input )
{
slider->SetValue( 0 );
UpdateButtons( VLC_TRUE );
}
}
else if( p_input->b_dead )
{
HideSlider();
UpdateButtons( VLC_FALSE );
vlc_object_release( p_input );
p_input = NULL;
}
if( p_input && !p_input->b_die )
{
vlc_value_t pos;
/* Really manage the slider */
var_Get( p_input, "position", &pos );
if( pos.f_float > 0.0 && ! IsShown() ) ShowSlider();
else if( pos.f_float <= 0.0 ) HideSlider();
if( IsPlaying() && IsShown() )
{
/* Update the slider if the user isn't dragging it. */
if( IsFree() )
{
char psz_time[ MSTRTIME_MAX_SIZE ];
char psz_total[ MSTRTIME_MAX_SIZE ];
vlc_value_t time;
mtime_t i_seconds;
/* Update the value */
if( pos.f_float >= 0.0 )
{
i_slider_pos = (int)(SLIDER_MAX_POS * pos.f_float);
slider->SetValue( i_slider_pos );
var_Get( p_input, "time", &time );
i_seconds = time.i_time / 1000000;
secstotimestr ( psz_time, i_seconds );
var_Get( p_input, "length", &time );
i_seconds = time.i_time / 1000000;
secstotimestr ( psz_total, i_seconds );
UpdateTime( psz_time, psz_total );
}
}
}
}
}
/*****************************************************************************
* Private methods.
*****************************************************************************/
void VLMSliderManager::UpdateInput()
{
if( p_sp->GetStream()->p_media->i_instance == 0 )
......@@ -75,18 +143,18 @@ void VLMSliderManager::UpdateButtons( vlc_bool_t b_play )
vlc_bool_t VLMSliderManager::IsShown()
{
return _slider->IsEnabled();
return slider->IsEnabled();
}
void VLMSliderManager::ShowSlider()
{
_slider->Enable();
slider->Enable();
}
void VLMSliderManager::HideSlider()
{
_slider->SetValue( 0 );
_slider->Disable();
slider->SetValue( 0 );
slider->Disable();
UpdateTime( "0:00:00", "0:00:00" );
}
......
......@@ -2,7 +2,7 @@
* vlm_slider_manager.hpp: Header for slider_manager
*****************************************************************************
* Copyright (C) 1999-2005 the VideoLAN team
* $Id: wxwidgets.h 12502 2005-09-09 19:38:01Z gbazin $
* $Id$
*
* Authors: Clment Stenac <zorglub@videolan.org>
*
......@@ -24,7 +24,7 @@
#ifndef _VLM_SLIDER_MANAGER_H_
#define _VLM_SLIDER_MANAGER_H_
#include "slider_manager.hpp"
#include "wxwidgets.hpp"
namespace wxvlc
{
......@@ -32,7 +32,7 @@ namespace wxvlc
/**
* This class manages a slider corresponding to the main input
*/
class VLMSliderManager: public SliderManager
class VLMSliderManager
{
public:
VLMSliderManager( intf_thread_t *, VLMBroadcastStreamPanel * );
......@@ -40,6 +40,7 @@ namespace wxvlc
wxString time_string;
void Update();
void ProcessUpdate( wxScrollEvent & );
protected:
......@@ -56,6 +57,11 @@ namespace wxvlc
virtual void ShowSlider();
VLMBroadcastStreamPanel * p_sp;
intf_thread_t * p_intf;
input_thread_t *p_input;
wxSlider *slider; ///< Slider for this input
int i_slider_pos; ///< Current slider position
};
};
......
......@@ -150,7 +150,6 @@ static const struct filter vfilters[] =
{ "clone", N_("Image clone"), N_("Creates several clones of the image") },
{ "distort", N_("Distortion"), N_("Adds distorsion effects") },
{ "invert", N_("Image inversion") , N_("Inverts the image colors") },
{ "crop", N_("Image cropping"), N_("Crops the image") },
{ "motionblur", N_("Blurring"), N_("Creates a motion blurring on the image") },
{ "transform", N_("Transformation"), N_("Rotates or flips the image") },
{ "magnify", N_("Magnify"), N_("Magnifies part of the image") },
......@@ -311,7 +310,7 @@ wxPanel *ExtraPanel::VideoPanel( wxWindow *parent )
{
wxCheckBox *box = new wxCheckBox( panel, Filter0_Event + i,
wxU( _( vfilters[i].psz_name ) ) );
t_col_sizer->Add( box, 0, wxALL, 4 );
t_col_sizer->Add( box, 0, wxALL, 2 );
box->SetToolTip( wxU( _( vfilters[i].psz_help ) ) );
}
......@@ -1215,13 +1214,11 @@ ExtraWindow::ExtraWindow( intf_thread_t *_p_intf, wxWindow *p_parent,
wxFrame( p_parent, -1, wxU(_("Extended controls")), wxDefaultPosition,
wxDefaultSize, wxDEFAULT_FRAME_STYLE )
{
fprintf(stderr,"Creating extrawindow\n");
p_intf = _p_intf;
SetIcon( *p_intf->p_sys->p_icon );
wxBoxSizer *window_sizer = new wxBoxSizer( wxVERTICAL );
SetSizer( window_sizer );
// panel = new ExtraPanel( p_intf, this );//_extra_panel;
panel = _extra_panel;
window_sizer->Add( panel );
......
......@@ -2,7 +2,7 @@
* extrapanel.hpp: Headers for the extra panel window
*****************************************************************************
* Copyright (C) 1999-2005 the VideoLAN team
* $Id: wxwidgets.h 12670 2005-09-25 11:16:31Z zorglub $
* $Id$
*
* Authors: Clment Stenac <zorglub@videolan.org>
*
......
/*****************************************************************************
* slider_manager.cpp : Manage an input slider
*****************************************************************************
* Copyright (C) 2000-2005 the VideoLAN team
* $Id$
*
* Authors: Gildas Bazin <gbazin@videolan.org>
* Clment Stenac <zorglub@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include "input_manager.hpp"
#include "interface.hpp"
#include "video.hpp"
#include <vlc_meta.h>
/* include the toolbar graphics */
#include "bitmaps/prev.xpm"
#include "bitmaps/next.xpm"
#include "bitmaps/playlist.xpm"
/* IDs for the controls */
enum
{
SliderScroll_Event = wxID_HIGHEST,
DiscMenu_Event,
DiscPrev_Event,
DiscNext_Event
};
BEGIN_EVENT_TABLE(InputManager, wxPanel)
/* Slider events */
EVT_COMMAND_SCROLL(SliderScroll_Event, InputManager::OnSliderUpdate)
/* Disc Buttons events */
EVT_BUTTON(DiscMenu_Event, InputManager::OnDiscMenu)
EVT_BUTTON(DiscPrev_Event, InputManager::OnDiscPrev)
EVT_BUTTON(DiscNext_Event, InputManager::OnDiscNext)
END_EVENT_TABLE()
#define STATUS_STOP 0
#define STATUS_PLAYING 1
#define STATUS_PAUSE 2
/*****************************************************************************
* Constructor.
*****************************************************************************/
InputManager::InputManager( intf_thread_t *_p_intf, Interface *_p_main_intf,
wxWindow *p_parent )
: wxPanel( p_parent )
{
p_intf = _p_intf;
p_main_intf = _p_main_intf;
p_input = NULL;
i_old_playing_status = STATUS_STOP;
i_old_rate = INPUT_RATE_DEFAULT;
b_slider_free = VLC_TRUE;
/* Create slider */
slider = new wxSlider( this, SliderScroll_Event, 0, 0, SLIDER_MAX_POS );
/* Create disc buttons */
disc_frame = new wxPanel( this );
disc_menu_button = new wxBitmapButton( disc_frame, DiscMenu_Event,
wxBitmap( playlist_xpm ) );
disc_prev_button = new wxBitmapButton( disc_frame, DiscPrev_Event,
wxBitmap( prev_xpm ) );
disc_next_button = new wxBitmapButton( disc_frame, DiscNext_Event,
wxBitmap( next_xpm ) );
disc_sizer = new wxBoxSizer( wxHORIZONTAL );
disc_sizer->Add( disc_menu_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
disc_sizer->Add( disc_prev_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
disc_sizer->Add( disc_next_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 1 );
disc_frame->SetSizer( disc_sizer );
disc_sizer->Layout();
/* Add everything to the panel */
sizer = new wxBoxSizer( wxHORIZONTAL );
SetSizer( sizer );
sizer->Add( slider, 1, wxEXPAND | wxALL, 5 );
sizer->Add( disc_frame, 0, wxALL, 2 );
/* Hide by default */
sizer->Hide( disc_frame );
sizer->Hide( slider );
sizer->Layout();
Fit();
}
InputManager::~InputManager()
{
vlc_mutex_lock( &p_intf->change_lock );
if( p_intf->p_sys->p_input ) vlc_object_release( p_intf->p_sys->p_input );
p_intf->p_sys->p_input = NULL;
vlc_mutex_unlock( &p_intf->change_lock );
}
/*****************************************************************************
* Public methods.
*****************************************************************************/
vlc_bool_t InputManager::IsPlaying()
{
return (p_input && !p_input->b_die);
}
/*****************************************************************************
* Private methods.
*****************************************************************************/
void InputManager::UpdateInput()
{
playlist_t *p_playlist =
(playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE );
if( p_playlist != NULL )
{
LockPlaylist( p_intf->p_sys, p_playlist );
p_input = p_intf->p_sys->p_input = p_playlist->p_input;
if( p_intf->p_sys->p_input )
vlc_object_yield( p_intf->p_sys->p_input );
UnlockPlaylist( p_intf->p_sys, p_playlist );
vlc_object_release( p_playlist );
}
}
void InputManager::UpdateNowPlaying()
{
char *psz_now_playing = vlc_input_item_GetInfo( p_input->input.p_item,
_("Meta-information"), _(VLC_META_NOW_PLAYING) );
if( psz_now_playing && *psz_now_playing )
{
p_main_intf->statusbar->SetStatusText(
wxString(wxU(psz_now_playing)) + wxT( " - " ) +
wxU(p_input->input.p_item->psz_name), 2 );
}
else
{
p_main_intf->statusbar->SetStatusText(
wxU(p_input->input.p_item->psz_name), 2 );
}
free( psz_now_playing );
}
void InputManager::UpdateButtons( vlc_bool_t b_play )
{
if( !b_play )
{
if( i_old_playing_status == STATUS_STOP ) return;
i_old_playing_status = STATUS_STOP;
p_main_intf->TogglePlayButton( PAUSE_S );
p_main_intf->statusbar->SetStatusText( wxT(""), 0 );
p_main_intf->statusbar->SetStatusText( wxT(""), 2 );
#ifdef wxHAS_TASK_BAR_ICON
if( p_main_intf->p_systray )
{
p_main_intf->p_systray->UpdateTooltip(
wxString(wxT("VLC media player - ")) + wxU(_("Stopped")) );
}
#endif
return;
}
/* Manage Playing status */
vlc_value_t val;
var_Get( p_input, "state", &val );
val.i_int = val.i_int == PAUSE_S ? STATUS_PAUSE : STATUS_PLAYING;
if( i_old_playing_status != val.i_int )
{
i_old_playing_status = val.i_int;
p_main_intf->TogglePlayButton( val.i_int == STATUS_PAUSE ?
PAUSE_S : PLAYING_S );
#ifdef wxHAS_TASK_BAR_ICON
if( p_main_intf->p_systray )
{
p_main_intf->p_systray->UpdateTooltip(
wxU(p_input->input.p_item->psz_name) + wxString(wxT(" - ")) +
(val.i_int == PAUSE_S ? wxU(_("Paused")) : wxU(_("Playing"))));
}
#endif
}
}
void InputManager::UpdateDiscButtons()
{
vlc_value_t val;
var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
if( val.i_int > 0 && !disc_frame->IsShown() )
{
vlc_value_t val;
#define HELP_MENU N_("Menu")
#define HELP_PCH N_("Previous chapter")
#define HELP_NCH N_("Next chapter")
#define HELP_PTR N_("Previous track")
#define HELP_NTR N_("Next track")
var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val, NULL );
if( val.i_int > 0 )
{
disc_menu_button->Show();
disc_sizer->Show( disc_menu_button );
disc_sizer->Layout();
disc_sizer->Fit( disc_frame );
disc_menu_button->SetToolTip( wxU(_( HELP_MENU ) ) );
disc_prev_button->SetToolTip( wxU(_( HELP_PCH ) ) );
disc_next_button->SetToolTip( wxU(_( HELP_NCH ) ) );
}
else
{
disc_menu_button->Hide();
disc_sizer->Hide( disc_menu_button );
disc_prev_button->SetToolTip( wxU(_( HELP_PTR ) ) );
disc_next_button->SetToolTip( wxU(_( HELP_NTR ) ) );
}
ShowDiscFrame();
}
else if( val.i_int == 0 && disc_frame->IsShown() )
{
HideDiscFrame();
}
}
void InputManager::HideSlider()
{
ShowSlider( false );
}
void InputManager::HideDiscFrame()
{
ShowDiscFrame( false );
}
void InputManager::UpdateTime()
{
char psz_time[ MSTRTIME_MAX_SIZE ], psz_total[ MSTRTIME_MAX_SIZE ];
mtime_t i_seconds;
i_seconds = var_GetTime( p_intf->p_sys->p_input, "length" ) / 1000000;
secstotimestr( psz_total, i_seconds );
i_seconds = var_GetTime( p_intf->p_sys->p_input, "time" ) / 1000000;
secstotimestr( psz_time, i_seconds );
p_main_intf->statusbar->SetStatusText(
wxU(psz_time) + wxString(wxT(" / ")) +wxU(psz_total), 0 );
}
void InputManager::Update()
{
/* Update the input */
if( p_input == NULL )
{
UpdateInput();
if( p_input )
{
slider->SetValue( 0 );
}
else
{
if( disc_frame->IsShown() ) HideDiscFrame();
if( slider->IsShown() ) HideSlider();
}
}
else if( p_input->b_dead )
{
UpdateButtons( VLC_FALSE );
vlc_object_release( p_input );
p_input = NULL;
}
if( p_input && !p_input->b_die )
{
vlc_value_t pos, len;
UpdateTime();
UpdateButtons( VLC_TRUE );
UpdateNowPlaying();
UpdateDiscButtons();
/* Really manage the slider */
var_Get( p_input, "position", &pos );
var_Get( p_input, "length", &len );
if( len.i_time > 0 && pos.f_float >= 0 &&
!slider->IsShown() ) ShowSlider();
else if( len.i_time < 0 && pos.f_float <= 0 &&
slider->IsShown() ) HideSlider();
/* Update the slider if the user isn't dragging it. */
if( slider->IsShown() && b_slider_free )
{
i_slider_pos = (int)(SLIDER_MAX_POS * pos.f_float);
slider->SetValue( i_slider_pos );
}
/* Manage Speed status */
vlc_value_t val;
var_Get( p_input, "rate", &val );
if( i_old_rate != val.i_int )
{
p_main_intf->statusbar->SetStatusText(
wxString::Format(wxT("x%.2f"),
(float)INPUT_RATE_DEFAULT / val.i_int ), 1 );
i_old_rate = val.i_int;
}
}
}
/*****************************************************************************
* Event Handlers.
*****************************************************************************/
void InputManager::OnDiscMenu( wxCommandEvent& WXUNUSED(event) )
{
input_thread_t *p_input =
(input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
FIND_ANYWHERE );
if( p_input )
{
vlc_value_t val; val.i_int = 2;
var_Set( p_input, "title 0", val);
vlc_object_release( p_input );
}
}
void InputManager::OnDiscPrev( wxCommandEvent& WXUNUSED(event) )
{
input_thread_t *p_input =
(input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
FIND_ANYWHERE );
if( p_input )
{
int i_type = var_Type( p_input, "prev-chapter" );
vlc_value_t val; val.b_bool = VLC_TRUE;
var_Set( p_input, ( i_type & VLC_VAR_TYPE ) != 0 ?
"prev-chapter" : "prev-title", val );
vlc_object_release( p_input );
}
}
void InputManager::OnDiscNext( wxCommandEvent& WXUNUSED(event) )
{
input_thread_t *p_input =
(input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
FIND_ANYWHERE );
if( p_input )
{
int i_type = var_Type( p_input, "next-chapter" );
vlc_value_t val; val.b_bool = VLC_TRUE;
var_Set( p_input, ( i_type & VLC_VAR_TYPE ) != 0 ?