1 /*****************************************************************************
2 * interface.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: interface.cpp,v 1.7 2002/11/23 14:28:51 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() */
32 #include <wx/wxprec.h>
35 /* Let vlc take care of the i18n stuff */
38 #ifdef WIN32 /* mingw32 hack */
46 #include "wxwindows.h"
48 /* include the toolbar graphics */
49 #include "bitmaps/file.xpm"
50 #include "bitmaps/disc.xpm"
51 #include "bitmaps/net.xpm"
53 #include "bitmaps/sat.xpm"
55 #include "bitmaps/play.xpm"
56 #include "bitmaps/pause.xpm"
57 #include "bitmaps/stop.xpm"
58 #include "bitmaps/previous.xpm"
59 #include "bitmaps/next.xpm"
60 #include "bitmaps/playlist.xpm"
62 /* include the icon graphic */
63 #include "share/vlc32x32.xpm"
65 /*****************************************************************************
66 * Local class declarations.
67 *****************************************************************************/
69 /*****************************************************************************
71 *****************************************************************************/
73 /* IDs for the controls and the menu commands */
98 /* it is important for the id corresponding to the "About" command to have
99 * this standard value as otherwise it won't be handled properly under Mac
100 * (where it is special and put into the "Apple" menu) */
101 About_Event = wxID_ABOUT
104 BEGIN_EVENT_TABLE(Interface, wxFrame)
106 EVT_MENU(Exit_Event, Interface::OnExit)
107 EVT_MENU(About_Event, Interface::OnAbout)
108 EVT_MENU(Playlist_Event, Interface::OnPlaylist)
109 EVT_MENU(OpenFile_Event, Interface::OnOpenFile)
111 EVT_MENU(OpenFile_Event, Interface::OnOpenFile)
112 EVT_MENU(StopStream_Event, Interface::OnStopStream)
113 EVT_MENU(PlayStream_Event, Interface::OnPlayStream)
114 EVT_MENU(PauseStream_Event, Interface::OnPauseStream)
115 EVT_MENU(PrevStream_Event, Interface::OnPrevStream)
116 EVT_MENU(NextStream_Event, Interface::OnNextStream)
118 EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
121 /*****************************************************************************
123 *****************************************************************************/
124 Interface::Interface( intf_thread_t *_p_intf ):
125 wxFrame( NULL, -1, "title", wxDefaultPosition, wxDefaultSize,
126 wxDEFAULT_FRAME_STYLE )
128 /* Initializations */
131 /* Give our interface a nice little icon */
132 SetIcon( *new wxIcon( vlc_xpm ) );
134 /* Create a sizer for the main frame */
135 frame_sizer = new wxBoxSizer( wxHORIZONTAL );
136 SetSizer( frame_sizer );
138 /* Creation of the menu bar */
141 /* Creation of the tool bar */
144 /* Creation of the slider sub-window */
147 /* Creation of the status bar
148 * Helptext for menu items and toolbar tools will automatically get
150 int i_status_width[2] = {-2,-3};
151 statusbar = CreateStatusBar( 2 ); /* 2 fields */
152 statusbar->SetStatusWidths( 2, i_status_width );
154 SetTitle( COPYRIGHT_MESSAGE );
156 /* Layout everything */
157 SetAutoLayout( TRUE );
158 frame_sizer->Layout();
159 frame_sizer->SetSizeHints(this);
161 /* Associate drop targets with the main interface */
162 SetDropTarget( new DragAndDrop( p_intf ) );
165 Interface::~Interface()
169 /*****************************************************************************
171 *****************************************************************************/
172 void Interface::CreateOurMenuBar()
174 #define HELP_FILE N_("Open a file")
175 #define HELP_DISC N_("Open a DVD or (S)VCD")
176 #define HELP_NET N_("Open a network stream")
177 #define HELP_SAT N_("Open a satellite stream")
178 #define HELP_EJECT N_("Eject the DVD/CD")
179 #define HELP_EXIT N_("Exit this program")
181 #define HELP_PLAYLIST N_("Open the playlist")
182 #define HELP_LOGS N_("Show the program logs")
184 #define HELP_AUDIO N_("Change the current audio track")
185 #define HELP_SUBS N_("Change the current subtitles stream")
186 #define HELP_PREFS N_("Go to the preferences menu")
188 #define HELP_ABOUT N_("About this program")
190 /* Create the "File" menu */
191 wxMenu *file_menu = new wxMenu;
192 file_menu->Append( OpenFile_Event, _("&Open File..."), HELP_FILE );
193 file_menu->Append( OpenDisc_Event, _("Open &Disc..."), HELP_DISC );
194 file_menu->Append( OpenNet_Event, _("&Network Stream..."), HELP_NET );
196 file_menu->Append( OpenSat_Event, _("&Satellite Stream..."), HELP_NET );
198 file_menu->AppendSeparator();
199 file_menu->Append( EjectDisc_Event, _("&Eject Disc"), HELP_EJECT );
200 file_menu->AppendSeparator();
201 file_menu->Append( Exit_Event, _("E&xit"), HELP_EXIT );
203 /* Create the "View" menu */
204 wxMenu *view_menu = new wxMenu;
205 view_menu->Append( Playlist_Event, _("&Playlist..."), HELP_PLAYLIST );
206 view_menu->Append( Logs_Event, _("&Logs..."), HELP_LOGS );
208 /* Create the "Settings" menu */
209 wxMenu *settings_menu = new wxMenu;
210 settings_menu->Append( Audio_Event, _("&Audio"), HELP_AUDIO );
211 settings_menu->Append( Subtitles_Event, _("&Subtitles"), HELP_SUBS );
212 settings_menu->AppendSeparator();
213 settings_menu->Append( Prefs_Event, _("&Preferences..."), HELP_PREFS );
215 /* Create the "Help" menu */
216 wxMenu *help_menu = new wxMenu;
217 help_menu->Append( About_Event, _("&About..."), HELP_ABOUT );
219 /* Append the freshly created menus to the menu bar... */
220 wxMenuBar *menubar = new wxMenuBar( wxMB_DOCKABLE );
221 menubar->Append( file_menu, _("&File") );
222 menubar->Append( view_menu, _("&View") );
223 menubar->Append( settings_menu, _("&Settings") );
224 menubar->Append( help_menu, _("&Help") );
226 /* Attach the menu bar to the frame */
227 SetMenuBar( menubar );
229 /* Associate drop targets with the menubar */
230 menubar->SetDropTarget( new DragAndDrop( p_intf ) );
233 void Interface::CreateOurToolBar()
235 #define HELP_STOP N_("Stop current playlist item")
236 #define HELP_PLAY N_("Play current playlist item")
237 #define HELP_PAUSE N_("Pause current playlist item")
238 #define HELP_PLO N_("Open playlist")
239 #define HELP_PLP N_("Previous playlist item")
240 #define HELP_PLN N_("Next playlist item")
242 wxBitmap *p_bmp_file = new wxBitmap( file_xpm );
243 wxBitmap *p_bmp_disc = new wxBitmap( disc_xpm );
244 wxBitmap *p_bmp_net = new wxBitmap( net_xpm );
245 wxBitmap *p_bmp_play = new wxBitmap( play_xpm );
246 wxBitmap *p_bmp_stop = new wxBitmap( stop_xpm );
247 wxBitmap *p_bmp_pause = new wxBitmap( pause_xpm );
248 wxBitmap *p_bmp_prev = new wxBitmap( previous_xpm );
249 wxBitmap *p_bmp_next = new wxBitmap( next_xpm );
250 wxBitmap *p_bmp_playlist = new wxBitmap( playlist_xpm );
252 wxToolBar *toolbar = CreateToolBar(
253 wxTB_HORIZONTAL | wxTB_TEXT | wxTB_FLAT | wxTB_DOCKABLE );
255 toolbar->AddTool( OpenFile_Event, _("File"), *p_bmp_file, HELP_FILE );
256 toolbar->AddTool( OpenFile_Event, _("Disc"), *p_bmp_disc, HELP_DISC );
257 toolbar->AddTool( OpenFile_Event, _("Net"), *p_bmp_net, HELP_NET );
259 toolbar->AddTool( OpenFile_Event, _("Sat"), *p_bmp_net, HELP_SAT );
261 toolbar->AddSeparator();
262 toolbar->AddTool( StopStream_Event, _("Stop"), *p_bmp_stop, HELP_STOP );
263 toolbar->AddTool( PlayStream_Event, _("Play"), *p_bmp_play, HELP_PLAY );
264 toolbar->AddTool( PauseStream_Event, _("Pause"), *p_bmp_pause, HELP_PAUSE);
265 toolbar->AddSeparator();
266 toolbar->AddTool( Playlist_Event, _("Playlist"), *p_bmp_playlist,
268 toolbar->AddTool( PrevStream_Event, _("Prev"), *p_bmp_prev, HELP_PLP );
269 toolbar->AddTool( NextStream_Event, _("Next"), *p_bmp_next, HELP_PLN );
273 /* Place the toolbar in a sizer, so we can calculate the width of the
274 * toolbar and set this as the minimum for the main frame size. */
275 wxBoxSizer *toolbar_sizer = new wxBoxSizer( wxHORIZONTAL );
276 toolbar_sizer->Add( toolbar, 0, 0, 0 );
277 toolbar_sizer->Layout();
278 frame_sizer->SetMinSize( toolbar_sizer->GetMinSize().GetWidth(), -1 );
280 /* Associate drop targets with the toolbar */
281 toolbar->SetDropTarget( new DragAndDrop( p_intf ) );
284 void Interface::CreateOurSlider()
286 /* Create a new frame containing the slider */
287 slider_frame = new wxPanel( this, -1, wxDefaultPosition, wxSize(-1,50) );
288 slider_frame->SetAutoLayout( TRUE );
289 slider_frame->Hide();
291 /* Create static box to surround the slider */
292 slider_box = new wxStaticBox( slider_frame, -1, "" );
294 /* Create sizer for slider frame */
295 wxStaticBoxSizer *slider_sizer =
296 new wxStaticBoxSizer( slider_box, wxHORIZONTAL );
297 slider_frame->SetSizer( slider_sizer );
300 slider = new wxSlider( slider_frame, SliderScroll_Event, 0, 0,
301 SLIDER_MAX_POS, wxDefaultPosition, wxDefaultSize );
302 slider_sizer->Add( slider, 1, wxGROW | wxALL, 5 );
303 slider_sizer->Layout();
306 /*****************************************************************************
308 *****************************************************************************/
309 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
311 /* TRUE is to force the frame to close. */
315 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
318 msg.Printf( _("This is the about dialog of the VideoLAN Client.\n") );
320 wxMessageBox( msg, _("About VideoLAN Client"),
321 wxOK | wxICON_INFORMATION, this );
324 void Interface::OnPlaylist( wxCommandEvent& WXUNUSED(event) )
326 /* Show/hide the playlist window */
327 wxFrame *p_playlist_window = p_intf->p_sys->p_playlist_window;
328 if( p_playlist_window )
330 p_playlist_window->Show( ! p_playlist_window->IsShown() );
334 void Interface::OnOpenFile( wxCommandEvent& WXUNUSED(event) )
336 wxFileDialog dialog( this, _("Open file"), _(""), _(""), _("*.*") );
338 if( dialog.ShowModal() == wxID_OK )
340 /* Update the playlist */
341 playlist_t *p_playlist =
342 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
344 if( p_playlist == NULL )
349 playlist_Add( p_playlist, (char *)dialog.GetPath().c_str(),
350 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
352 /* Rebuild the playlist */
353 p_intf->p_sys->p_playlist_window->Rebuild();
355 vlc_object_release( p_playlist );
359 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
361 wxCommandEvent dummy;
362 playlist_t *p_playlist =
363 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
365 if( p_playlist == NULL )
371 /* If the playlist is empty, open a file requester instead */
372 vlc_mutex_lock( &p_playlist->object_lock );
373 if( p_playlist->i_size )
375 vlc_mutex_unlock( &p_playlist->object_lock );
376 playlist_Play( p_playlist );
377 vlc_object_release( p_playlist );
381 vlc_mutex_unlock( &p_playlist->object_lock );
382 vlc_object_release( p_playlist );
387 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
389 playlist_t * p_playlist =
390 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
392 if( p_playlist == NULL )
397 playlist_Stop( p_playlist );
398 vlc_object_release( p_playlist );
401 void Interface::OnPauseStream( wxCommandEvent& WXUNUSED(event) )
403 if( p_intf->p_sys->p_input == NULL )
408 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
411 void Interface::OnSliderUpdate( wxScrollEvent& event )
413 p_intf->p_sys->i_slider_pos = event.GetPosition();
416 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
418 playlist_t * p_playlist =
419 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
421 if( p_playlist == NULL )
426 playlist_Prev( p_playlist );
427 vlc_object_release( p_playlist );
430 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
432 playlist_t * p_playlist =
433 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
435 if( p_playlist == NULL )
440 playlist_Next( p_playlist );
441 vlc_object_release( p_playlist );
444 /*****************************************************************************
445 * Definition of DragAndDrop class.
446 *****************************************************************************/
447 DragAndDrop::DragAndDrop( intf_thread_t *_p_intf )
452 bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
453 const wxArrayString& filenames )
457 /* Add dropped files to the playlist */
459 playlist_t *p_playlist =
460 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
462 if( p_playlist == NULL )
467 for( i = 0; i < filenames.GetCount(); i++ )
468 playlist_Add( p_playlist, (char *)filenames[i].c_str(),
469 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
471 /* Rebuild the playlist */
472 p_intf->p_sys->p_playlist_window->Rebuild();
474 vlc_object_release( p_playlist );