]> git.sesse.net Git - vlc/blob - modules/gui/wxwidgets/dialogs/vlm/vlm_streampanel.cpp
fd984d41d3a1c98cb2904de2809f27196217cccd
[vlc] / modules / gui / wxwidgets / dialogs / vlm / vlm_streampanel.cpp
1 /*****************************************************************************
2  * vlm_streampanel:cpp
3  *****************************************************************************
4  * Copyright (C) 2000-2005 the VideoLAN team
5  * $Id: playlist.cpp 12582 2005-09-17 14:15:32Z zorglub $
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/OR MODIFy
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #include "dialogs/vlm/vlm_streampanel.hpp"
25 #include "dialogs/vlm/vlm_stream.hpp"
26 #include "dialogs/vlm/vlm_slider_manager.hpp"
27
28 #include "dialogs/vlm/vlm_panel.hpp"
29
30 #include "bitmaps/play.xpm"
31 #include "bitmaps/pause.xpm"
32 #include "bitmaps/stop.xpm"
33 #include "bitmaps/trash.xpm"
34
35 enum
36 {
37     BPlay_Event,
38     BStop_Event,
39     BSlider_Event,
40     BEdit_Event,
41     BTrash_Event,
42 };
43
44 BEGIN_EVENT_TABLE( VLMBroadcastStreamPanel, wxPanel )
45     EVT_BUTTON( BPlay_Event, VLMBroadcastStreamPanel::OnPlay )
46     EVT_BUTTON( BStop_Event, VLMBroadcastStreamPanel::OnStop )
47     EVT_BUTTON( BEdit_Event, VLMBroadcastStreamPanel::OnEdit )
48     EVT_BUTTON( BTrash_Event, VLMBroadcastStreamPanel::OnTrash )
49     EVT_COMMAND_SCROLL( BSlider_Event, VLMBroadcastStreamPanel::OnSliderUpdate )
50 END_EVENT_TABLE()
51
52 /***********************************************************************
53  * VLMStream
54  ***********************************************************************/
55 VLMStreamPanel::VLMStreamPanel( intf_thread_t * _p_intf, wxWindow * _p_parent ):
56          wxPanel( _p_parent, -1, wxDefaultPosition, wxDefaultSize )
57 {
58     p_intf = _p_intf;
59     p_slider = NULL;
60 }
61
62 VLMStreamPanel::~VLMStreamPanel()
63 {
64 }
65
66 /***********************************************************************
67  * VLMBroadcastStream
68  ***********************************************************************/
69 VLMBroadcastStreamPanel::VLMBroadcastStreamPanel( intf_thread_t* _p_intf,
70        wxWindow *_p_parent , VLMBroadcastStream *_stream ):
71        VLMStreamPanel( _p_intf, _p_parent ),
72        p_stream( _stream )
73 {
74     wxStaticBox *box = new wxStaticBox( this, -1,
75                     wxU( p_stream->p_media->psz_name ) );
76
77     wxStaticBoxSizer *box_sizer = new wxStaticBoxSizer( box, wxHORIZONTAL );
78
79     play_button = new wxBitmapButton( this, BPlay_Event,
80                                 wxBitmap( play_xpm ) );
81     play_button->SetToolTip( wxU(_("Play/Pause") ) );
82     box_sizer->Add( play_button, 0, wxEXPAND | wxALL, 5 );
83
84     wxBitmapButton *stop_button = new wxBitmapButton( this, BStop_Event,
85                                           wxBitmap( stop_xpm ) );
86     stop_button->SetToolTip( wxU(_("Stop") ) );
87     box_sizer->Add( stop_button, 0, wxEXPAND | wxALL, 5 );
88
89     p_slider = new wxSlider( this,  BSlider_Event, 0, 0,
90                             SLIDER_MAX_POS, wxDefaultPosition, wxDefaultSize );
91     p_slider->Disable();
92     box_sizer->Add( p_slider,    1, wxEXPAND | wxALL, 5 );
93
94     p_time = new wxStaticText( this, -1, wxU( "0:00:00 / 0:00:00") );
95     box_sizer->Add( p_time, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5 );
96
97     wxBitmapButton *edit_button = new wxBitmapButton( this, BEdit_Event,
98                                     wxBitmap( trash_xpm ) );
99     edit_button->SetToolTip( wxU( _("Edit") ) );
100     box_sizer->Add( edit_button, 0, wxEXPAND | wxALL , 5 );
101
102     wxBitmapButton *trash_button = new wxBitmapButton( this, BTrash_Event,
103                                     wxBitmap( trash_xpm ) );
104     trash_button->SetToolTip( wxU( _("Delete" ) ) );
105     box_sizer->Add( trash_button, 0, wxEXPAND | wxALL , 5 );
106
107     box_sizer->Layout();
108     SetSizerAndFit( box_sizer );
109
110     p_sm = new VLMSliderManager( p_intf, this );
111 }
112
113 VLMBroadcastStreamPanel::~VLMBroadcastStreamPanel()
114 {
115 }
116
117 void VLMBroadcastStreamPanel::TogglePlayButton( int state )
118 {
119     if( state == PLAYING_S )
120     {
121         play_button->SetBitmapLabel( wxBitmap( pause_xpm ) );
122     }
123     if( state == PAUSE_S )
124     {
125         play_button->SetBitmapLabel( wxBitmap( play_xpm ) );
126     }
127 }
128
129 void VLMBroadcastStreamPanel::Update()
130 {
131     /* Update managed slider */
132     p_sm->Update();
133     p_time->SetLabel( p_sm->time_string );
134 }
135
136 void VLMBroadcastStreamPanel::OnPlay( wxCommandEvent &event )
137 {
138     /* FIXME: Factorize input / VLM code here */
139     /* Handle multiple instance */
140     if( p_stream->p_media->i_instance > 0 &&
141         p_stream->p_media->instance[0]->p_input )
142     {
143         vlc_value_t val;
144         vlc_object_yield( p_stream->p_media->instance[0]->p_input );
145         var_Get( p_stream->p_media->instance[0]->p_input, "state", &val );
146         if( val.i_int != PAUSE_S )
147         {
148             /* Pause */
149             val.i_int = PAUSE_S;
150         }
151         else
152         {
153             /* Resume */
154             val.i_int = PLAYING_S;
155         }
156         var_Set( p_stream->p_media->instance[0]->p_input, "state", val );
157         TogglePlayButton( val.i_int );
158         vlc_object_release( p_stream->p_media->instance[0]->p_input );
159     }
160     else
161     {
162          p_stream->Play();
163          TogglePlayButton( PLAYING_S );
164     }
165 }
166
167 void VLMBroadcastStreamPanel::OnStop( wxCommandEvent &event )
168 {
169     p_stream->Stop();
170 }
171
172 void VLMBroadcastStreamPanel::OnEdit( wxCommandEvent &event )
173 {
174      VLMEditStreamFrame *p_frame =
175            new  VLMEditStreamFrame( p_intf, this, p_stream->p_vlm, VLC_TRUE,
176                                     p_stream );
177      p_frame->Show();
178 }
179
180 void VLMBroadcastStreamPanel::OnTrash( wxCommandEvent &event )
181 {
182     p_stream->Delete();
183 }
184
185 void VLMBroadcastStreamPanel::OnSliderUpdate( wxScrollEvent& event )
186 {
187     p_sm->ProcessUpdate( event );
188 }
189
190 /***********************************************************************
191  * VLMVODStream
192  ***********************************************************************/
193 VLMVODStreamPanel::VLMVODStreamPanel( intf_thread_t* _p_intf,
194        wxWindow *_p_parent , VLMVODStream *_stream ):
195        VLMStreamPanel( _p_intf, _p_parent ),
196        p_stream( _stream )
197 {
198 }
199
200 VLMVODStreamPanel::~VLMVODStreamPanel()
201 {
202 }