1 /*****************************************************************************
2 * interface.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: interface.cpp,v 1.4 2002/11/18 17:31:54 gbazin Exp $
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
35 /* Let wxWindows take care of the i18n stuff */
38 #ifdef WIN32 /* mingw32 hack */
43 #include <wx/wxprec.h>
46 #include "wxwindows.h"
47 #include "wx/artprov.h"
49 /* include the toolbar graphics */
50 #include "bitmaps/file.xpm"
51 #include "bitmaps/disc.xpm"
52 #include "bitmaps/net.xpm"
54 #include "bitmaps/sat.xpm"
56 #include "bitmaps/play.xpm"
57 #include "bitmaps/pause.xpm"
58 #include "bitmaps/stop.xpm"
59 #include "bitmaps/previous.xpm"
60 #include "bitmaps/next.xpm"
61 #include "bitmaps/playlist.xpm"
62 /*****************************************************************************
64 *****************************************************************************/
66 const int ID_TOOLBAR = 500;
68 /* IDs for the controls and the menu commands */
92 /* it is important for the id corresponding to the "About" command to have
93 * this standard value as otherwise it won't be handled properly under Mac
94 * (where it is special and put into the "Apple" menu) */
95 About_Event = wxID_ABOUT
98 BEGIN_EVENT_TABLE(Interface, wxFrame)
100 EVT_MENU(Exit_Event, Interface::OnExit)
101 EVT_MENU(About_Event, Interface::OnAbout)
102 EVT_MENU(OpenFile_Event, Interface::OnOpenFile)
104 EVT_MENU(OpenFile_Event, Interface::OnOpenFile)
105 EVT_MENU(StopStream_Event, Interface::OnStopStream)
106 EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
107 EVT_MENU(PauseStream_Event, Interface::OnPauseStream)
108 EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
109 EVT_MENU(NextStream_Event, Interface::OnNextStream)
111 EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
114 /*****************************************************************************
116 *****************************************************************************/
117 Interface::Interface( intf_thread_t *_p_intf ):
118 wxFrame( NULL, -1, "title", wxDefaultPosition, wxDefaultSize,
119 wxDEFAULT_FRAME_STYLE )
122 /* Initializations */
125 /* Give our interface a nice icon */
126 //SetIcon( wxICON(vlcicon) );
128 /* Create our "File" menu */
129 #define HELP_FILE N_("Open a file")
130 #define HELP_DISC N_("Open a DVD or (S)VCD")
131 #define HELP_NET N_("Open a network stream")
132 #define HELP_SAT N_("Open a satellite stream")
133 #define HELP_EJECT N_("Eject the DVD/CD")
134 #define HELP_EXIT N_("Exit this program")
135 wxMenu *file_menu = new wxMenu;
136 file_menu->Append( OpenFile_Event, _("&Open File..."), HELP_FILE );
137 file_menu->Append( OpenDisc_Event, _("Open &Disc..."), HELP_DISC );
138 file_menu->Append( OpenNet_Event, _("&Network Stream..."), HELP_NET );
140 file_menu->Append( OpenSat_Event, _("&Satellite Stream..."), HELP_NET );
142 file_menu->AppendSeparator();
143 file_menu->Append( EjectDisc_Event, _("&Eject Disc"), HELP_EJECT );
144 file_menu->AppendSeparator();
145 file_menu->Append( Exit_Event, _("E&xit"), HELP_EXIT );
147 /* Create our "View" menu */
148 #define HELP_LOGS N_("Show the program logs")
149 wxMenu *view_menu = new wxMenu;
150 view_menu->Append( Logs_Event, _("&Logs..."), HELP_LOGS );
152 /* Create our "Settings" menu */
153 #define HELP_AUDIO N_("Change the current audio track")
154 #define HELP_SUBS N_("Change the current subtitles stream")
155 #define HELP_PREFS N_("Go to the preferences menu")
156 wxMenu *settings_menu = new wxMenu;
157 settings_menu->Append( Audio_Event, _("&Audio"), HELP_AUDIO );
158 settings_menu->Append( Subtitles_Event, _("&Subtitles"), HELP_SUBS );
159 settings_menu->AppendSeparator();
160 settings_menu->Append( Prefs_Event, _("&Preferences..."), HELP_PREFS );
162 /* Create our "Help" menu */
163 #define HELP_ABOUT N_("About this program")
164 wxMenu *help_menu = new wxMenu;
165 help_menu->Append( About_Event, _("&About..."), HELP_ABOUT );
167 /* Append the freshly created menus to the menu bar... */
168 wxMenuBar *menubar = new wxMenuBar( wxMB_DOCKABLE );
169 menubar->Append( file_menu, _("&File") );
170 menubar->Append( view_menu, _("&View") );
171 menubar->Append( settings_menu, _("&Settings") );
172 menubar->Append( help_menu, _("&Help") );
174 /* Attach the menu bar to the frame */
175 SetMenuBar( menubar );
178 #define HELP_STOP N_("Stop current playlist item")
179 #define HELP_PLAY N_("Play current playlist item")
180 #define HELP_PAUSE N_("Pause current playlist item")
181 #define HELP_PLO N_("Open playlist")
182 #define HELP_PLP N_("Previous playlist item")
183 #define HELP_PLN N_("Next playlist item")
184 wxBitmap *p_bmp_file = new wxBitmap( file_xpm );
185 wxBitmap *p_bmp_disc = new wxBitmap( disc_xpm );
186 wxBitmap *p_bmp_net = new wxBitmap( net_xpm );
187 wxBitmap *p_bmp_play = new wxBitmap( play_xpm );
188 wxBitmap *p_bmp_stop = new wxBitmap( stop_xpm );
189 wxBitmap *p_bmp_pause = new wxBitmap( pause_xpm );
190 wxBitmap *p_bmp_prev = new wxBitmap( previous_xpm );
191 wxBitmap *p_bmp_next = new wxBitmap( next_xpm );
192 wxBitmap *p_bmp_playlist = new wxBitmap( playlist_xpm );
194 wxToolBar *toolbar = CreateToolBar(
195 wxTB_HORIZONTAL | wxTB_TEXT | wxTB_FLAT | wxTB_DOCKABLE, ID_TOOLBAR );
197 toolbar->AddTool( OpenFile_Event, _("File"), *p_bmp_file, HELP_FILE );
198 toolbar->AddTool( OpenFile_Event, _("Disc"), *p_bmp_disc, HELP_DISC );
199 toolbar->AddTool( OpenFile_Event, _("Net"), *p_bmp_net, HELP_NET );
201 toolbar->AddTool( OpenFile_Event, _("Sat"), *p_bmp_net, HELP_SAT );
203 toolbar->AddSeparator();
204 toolbar->AddTool( StopStream_Event, _("Stop"), *p_bmp_stop, HELP_STOP );
205 toolbar->AddTool( PlayStream_Event, _("Play"), *p_bmp_play, HELP_PLAY );
206 toolbar->AddTool( PauseStream_Event, _("Pause"), *p_bmp_pause, HELP_PAUSE);
207 toolbar->AddSeparator();
208 toolbar->AddTool( wxID_OPEN, _("Playlist"), *p_bmp_playlist, HELP_PLO );
209 toolbar->AddTool( PrevStream_Event, _("Prev"), *p_bmp_prev, HELP_PLP );
210 toolbar->AddTool( NextStream_Event, _("Next"), *p_bmp_next, HELP_PLN );
215 wxBoxSizer *slider_sizer = new wxBoxSizer( wxVERTICAL );
216 slider = new wxSlider( this, SliderScroll_Event, 0, 0, 100,
217 wxDefaultPosition, wxSize( 450, 50 ),
218 wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_TOP );
219 slider_sizer->Add( slider, 0, wxGROW | wxALL | wxALIGN_CENTER, 5 );
221 /* use the sizer for layout */
223 slider_sizer->Layout();
224 SetSizerAndFit( slider_sizer );
226 /* Give the frame an optional statusbar. The '1' just means one field.
227 * A gripsizer will automatically get put on into the corner, if that
228 * is the normal OS behaviour for frames on that platform. Helptext
229 * for menu items and toolbar tools will automatically get displayed
231 statusbar = CreateStatusBar(2);
232 int i_status_width[2] = {-1,-2};
233 statusbar->SetStatusWidths( 2, i_status_width );
235 SetTitle( COPYRIGHT_MESSAGE );
236 SetAutoLayout( TRUE );
240 Interface::~Interface()
244 /*****************************************************************************
246 *****************************************************************************/
247 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
249 /* TRUE is to force the frame to close. */
253 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
256 msg.Printf( _("This is the about dialog of the VideoLAN Client.\n") );
258 wxMessageBox( msg, "About VideoLAN Client",
259 wxOK | wxICON_INFORMATION, this );
262 void Interface::OnOpenFile( wxCommandEvent& WXUNUSED(event) )
264 wxFileDialog dialog( this, _("Open file"), _(""), _(""),
267 if( dialog.ShowModal() == wxID_OK )
269 /* Update the playlist */
270 playlist_t *p_playlist =
271 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
273 if( p_playlist == NULL )
278 playlist_Add( p_playlist, (char *)dialog.GetPath().c_str(),
279 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
281 vlc_object_release( p_playlist );
285 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
287 wxCommandEvent dummy;
288 playlist_t *p_playlist =
289 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
291 if( p_playlist == NULL )
297 /* If the playlist is empty, open a file requester instead */
298 vlc_mutex_lock( &p_playlist->object_lock );
299 if( p_playlist->i_size )
301 vlc_mutex_unlock( &p_playlist->object_lock );
302 playlist_Play( p_playlist );
303 vlc_object_release( p_playlist );
307 vlc_mutex_unlock( &p_playlist->object_lock );
308 vlc_object_release( p_playlist );
313 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
315 playlist_t * p_playlist =
316 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
318 if( p_playlist == NULL )
323 playlist_Stop( p_playlist );
324 vlc_object_release( p_playlist );
327 void Interface::OnPauseStream( wxCommandEvent& WXUNUSED(event) )
329 if( p_intf->p_sys->p_input == NULL )
334 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
337 void Interface::OnSliderUpdate( wxScrollEvent& event )
339 p_intf->p_sys->i_slider_pos = event.GetPosition();
342 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
344 playlist_t * p_playlist =
345 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
347 if( p_playlist == NULL )
352 playlist_Prev( p_playlist );
353 vlc_object_release( p_playlist );
356 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
358 playlist_t * p_playlist =
359 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
361 if( p_playlist == NULL )
366 playlist_Next( p_playlist );
367 vlc_object_release( p_playlist );