]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/interface.cpp
* modules/gui/wxwindows/*: updated the toolbar icons.
[vlc] / modules / gui / wxwindows / interface.cpp
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 $
6  *
7  * Authors: Gildas Bazin <gbazin@netcourrier.com>
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 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <string.h>                                            /* strerror() */
30 #include <stdio.h>
31
32 #include <vlc/vlc.h>
33 #include <vlc/intf.h>
34
35 /* Let wxWindows take care of the i18n stuff */
36 #undef _
37
38 #ifdef WIN32                                                 /* mingw32 hack */
39 #undef Yield()
40 #undef CreateDialog()
41 #endif
42
43 #include <wx/wxprec.h>
44 #include <wx/wx.h>
45
46 #include "wxwindows.h"
47 #include "wx/artprov.h"
48
49 /* include the toolbar graphics */
50 #include "bitmaps/file.xpm"
51 #include "bitmaps/disc.xpm"
52 #include "bitmaps/net.xpm"
53 #if 0
54 #include "bitmaps/sat.xpm"
55 #endif
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 /*****************************************************************************
63  * Event Table.
64  *****************************************************************************/
65
66 const int ID_TOOLBAR = 500;
67
68 /* IDs for the controls and the menu commands */
69 enum
70 {
71     /* menu items */
72     Exit_Event = 1,
73     OpenFile_Event,
74     OpenDisc_Event,
75     OpenNet_Event,
76     OpenSat_Event,
77     EjectDisc_Event,
78
79     Logs_Event,
80
81     Audio_Event,
82     Subtitles_Event,
83     Prefs_Event,
84
85     SliderScroll_Event,
86     StopStream_Event,
87     PlayStream_Event,
88     PauseStream_Event,
89     PrevStream_Event,
90     NextStream_Event,
91
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
96 };
97
98 BEGIN_EVENT_TABLE(Interface, wxFrame)
99     /* Menu events */
100     EVT_MENU(Exit_Event, Interface::OnExit)
101     EVT_MENU(About_Event, Interface::OnAbout)
102     EVT_MENU(OpenFile_Event, Interface::OnOpenFile)
103     /* Toolbar events */
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)
110     /* Slider events */
111     EVT_COMMAND_SCROLL(SliderScroll_Event, Interface::OnSliderUpdate)
112 END_EVENT_TABLE()
113
114 /*****************************************************************************
115  * Constructor.
116  *****************************************************************************/
117 Interface::Interface( intf_thread_t *_p_intf ):
118     wxFrame( NULL, -1, "title", wxDefaultPosition, wxDefaultSize,
119              wxDEFAULT_FRAME_STYLE )
120 {
121
122     /* Initializations */
123     p_intf = _p_intf;
124
125     /* Give our interface a nice icon */
126     //SetIcon( wxICON(vlcicon) );
127
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 );
139 #if 0
140     file_menu->Append( OpenSat_Event, _("&Satellite Stream..."), HELP_NET );
141 #endif
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 );
146
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 );
151
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 );
161
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 );
166
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") );
173
174     /* Attach the menu bar to the frame */
175     SetMenuBar( menubar );
176
177     /* Create toolbar */
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 );
193
194     wxToolBar *toolbar = CreateToolBar(
195         wxTB_HORIZONTAL | wxTB_TEXT | wxTB_FLAT | wxTB_DOCKABLE, ID_TOOLBAR );
196
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 );
200 #if 0
201     toolbar->AddTool( OpenFile_Event, _("Sat"), *p_bmp_net, HELP_SAT );
202 #endif
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 );
211
212     toolbar->Realize();
213
214     /* Create slider */
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 );
220
221     /* use the sizer for layout */
222     slider->Hide();
223     slider_sizer->Layout();
224     SetSizerAndFit( slider_sizer );
225
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
230      * here. */
231     statusbar = CreateStatusBar(2);
232     int i_status_width[2] = {-1,-2};
233     statusbar->SetStatusWidths( 2, i_status_width );
234
235     SetTitle( COPYRIGHT_MESSAGE );
236     SetAutoLayout( TRUE );
237     Layout();
238 }
239
240 Interface::~Interface()
241 {
242 }
243
244 /*****************************************************************************
245  * Private methods.
246  *****************************************************************************/
247 void Interface::OnExit( wxCommandEvent& WXUNUSED(event) )
248 {
249     /* TRUE is to force the frame to close. */
250     Close(TRUE);
251 }
252
253 void Interface::OnAbout( wxCommandEvent& WXUNUSED(event) )
254 {
255     wxString msg;
256     msg.Printf( _("This is the about dialog of the VideoLAN Client.\n") );
257
258     wxMessageBox( msg, "About VideoLAN Client",
259                   wxOK | wxICON_INFORMATION, this );
260 }
261
262 void Interface::OnOpenFile( wxCommandEvent& WXUNUSED(event) )
263 {
264     wxFileDialog dialog( this, _("Open file"), _(""), _(""),
265                          _("*.*") );
266
267     if( dialog.ShowModal() == wxID_OK )
268     {
269         /* Update the playlist */
270         playlist_t *p_playlist =
271             (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
272                                            FIND_ANYWHERE );
273         if( p_playlist == NULL )
274         {
275             return;
276         }
277
278         playlist_Add( p_playlist, (char *)dialog.GetPath().c_str(),
279                       PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
280
281         vlc_object_release( p_playlist );
282     }
283 }
284
285 void Interface::OnPlayStream( wxCommandEvent& WXUNUSED(event) )
286 {
287     wxCommandEvent dummy;
288     playlist_t *p_playlist =
289         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
290                                        FIND_ANYWHERE );
291     if( p_playlist == NULL )
292     {
293         OnOpenFile( dummy );
294         return;
295     }
296
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 )
300     {
301         vlc_mutex_unlock( &p_playlist->object_lock );
302         playlist_Play( p_playlist );
303         vlc_object_release( p_playlist );
304     }
305     else
306     {
307         vlc_mutex_unlock( &p_playlist->object_lock );
308         vlc_object_release( p_playlist );
309         OnOpenFile( dummy );
310     }
311 }
312
313 void Interface::OnStopStream( wxCommandEvent& WXUNUSED(event) )
314 {
315     playlist_t * p_playlist =
316         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
317                                        FIND_ANYWHERE );
318     if( p_playlist == NULL )
319     {
320         return;
321     }
322
323     playlist_Stop( p_playlist );
324     vlc_object_release( p_playlist );
325 }
326
327 void Interface::OnPauseStream( wxCommandEvent& WXUNUSED(event) )
328 {
329     if( p_intf->p_sys->p_input == NULL )
330     {
331         return;
332     }
333
334     input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
335 }
336
337 void Interface::OnSliderUpdate( wxScrollEvent& event )
338 {
339     p_intf->p_sys->i_slider_pos = event.GetPosition();
340 }
341
342 void Interface::OnPrevStream( wxCommandEvent& WXUNUSED(event) )
343 {
344     playlist_t * p_playlist =
345         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
346                                        FIND_ANYWHERE );
347     if( p_playlist == NULL )
348     {
349         return;
350     }
351
352     playlist_Prev( p_playlist );
353     vlc_object_release( p_playlist );
354 }
355
356 void Interface::OnNextStream( wxCommandEvent& WXUNUSED(event) )
357 {
358     playlist_t * p_playlist =
359         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
360                                        FIND_ANYWHERE );
361     if( p_playlist == NULL )
362     {
363         return;
364     }
365
366     playlist_Next( p_playlist );
367     vlc_object_release( p_playlist );
368 }