1 /*****************************************************************************
2 * dialogs.cpp : wxWidgets plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <errno.h> /* ENOMEM */
31 #include <vlc_interface.h>
33 #include "vlc_charset.h"
35 //#include "dialogs/vlm/vlm_panel.hpp"
36 #include "dialogs/bookmarks.hpp"
37 #include "dialogs/wizard.hpp"
38 #include "dialogs/playlist.hpp"
39 #include "dialogs/open.hpp"
40 #include "dialogs/updatevlc.hpp"
41 #include "dialogs/fileinfo.hpp"
42 #include "dialogs/iteminfo.hpp"
43 #include "dialogs/preferences.hpp"
44 #include "dialogs/messages.hpp"
45 #include "dialogs/interaction.hpp"
46 #include "interface.hpp"
48 /* include the icon graphic */
49 #include "../../../share/vlc32x32.xpm"
52 /* Dialogs Provider */
55 class DialogsProvider: public wxFrame
59 DialogsProvider( intf_thread_t *p_intf, wxWindow *p_parent );
60 virtual ~DialogsProvider();
63 void Open( int i_access_method, int i_arg );
65 /* Event handlers (these functions should _not_ be virtual) */
66 void OnUpdateVLC( wxCommandEvent& event );
67 //void OnVLM( wxCommandEvent& event );
68 void OnInteraction( wxCommandEvent& event );
69 void OnExit( wxCommandEvent& event );
70 void OnPlaylist( wxCommandEvent& event );
71 void OnMessages( wxCommandEvent& event );
72 void OnFileInfo( wxCommandEvent& event );
73 void OnPreferences( wxCommandEvent& event );
74 void OnWizardDialog( wxCommandEvent& event );
75 void OnBookmarks( wxCommandEvent& event );
77 void OnOpenFileGeneric( wxCommandEvent& event );
78 void OnOpenFileSimple( wxCommandEvent& event );
79 void OnOpenDirectory( wxCommandEvent& event );
80 void OnOpenFile( wxCommandEvent& event );
81 void OnOpenDisc( wxCommandEvent& event );
82 void OnOpenNet( wxCommandEvent& event );
83 void OnOpenCapture( wxCommandEvent& event );
84 void OnOpenSat( wxCommandEvent& event );
86 void OnPopupMenu( wxCommandEvent& event );
87 void OnAudioPopupMenu( wxCommandEvent& event );
88 void OnVideoPopupMenu( wxCommandEvent& event );
89 void OnMiscPopupMenu( wxCommandEvent& event );
91 void OnIdle( wxIdleEvent& event );
93 void OnExitThread( wxCommandEvent& event );
95 DECLARE_EVENT_TABLE();
97 intf_thread_t *p_intf;
100 /* Secondary windows */
101 OpenDialog *p_open_dialog;
102 wxFileDialog *p_file_dialog;
103 wxDirDialog *p_dir_dialog;
104 Playlist *p_playlist_dialog;
105 Messages *p_messages_dialog;
106 FileInfo *p_fileinfo_dialog;
107 WizardDialog *p_wizard_dialog;
108 wxFrame *p_prefs_dialog;
109 wxFrame *p_bookmarks_dialog;
110 wxFileDialog *p_file_generic_dialog;
111 UpdateVLC *p_updatevlc_dialog;
112 //VLMFrame *p_vlm_dialog;
116 DEFINE_LOCAL_EVENT_TYPE( wxEVT_DIALOG );
118 BEGIN_EVENT_TABLE(DialogsProvider, wxFrame)
119 /* Idle loop used to update some of the dialogs */
120 EVT_IDLE(DialogsProvider::OnIdle)
122 /* Custom wxDialog events */
123 EVT_COMMAND(INTF_DIALOG_FILE, wxEVT_DIALOG, DialogsProvider::OnOpenFile)
124 EVT_COMMAND(INTF_DIALOG_DISC, wxEVT_DIALOG, DialogsProvider::OnOpenDisc)
125 EVT_COMMAND(INTF_DIALOG_NET, wxEVT_DIALOG, DialogsProvider::OnOpenNet)
126 EVT_COMMAND(INTF_DIALOG_CAPTURE, wxEVT_DIALOG,
127 DialogsProvider::OnOpenCapture)
128 EVT_COMMAND(INTF_DIALOG_FILE_SIMPLE, wxEVT_DIALOG,
129 DialogsProvider::OnOpenFileSimple)
130 EVT_COMMAND(INTF_DIALOG_FILE_GENERIC, wxEVT_DIALOG,
131 DialogsProvider::OnOpenFileGeneric)
132 EVT_COMMAND(INTF_DIALOG_DIRECTORY, wxEVT_DIALOG,
133 DialogsProvider::OnOpenDirectory)
135 EVT_COMMAND(INTF_DIALOG_PLAYLIST, wxEVT_DIALOG,
136 DialogsProvider::OnPlaylist)
137 EVT_COMMAND(INTF_DIALOG_MESSAGES, wxEVT_DIALOG,
138 DialogsProvider::OnMessages)
139 EVT_COMMAND(INTF_DIALOG_PREFS, wxEVT_DIALOG,
140 DialogsProvider::OnPreferences)
141 EVT_COMMAND(INTF_DIALOG_WIZARD, wxEVT_DIALOG,
142 DialogsProvider::OnWizardDialog)
143 EVT_COMMAND(INTF_DIALOG_FILEINFO, wxEVT_DIALOG,
144 DialogsProvider::OnFileInfo)
145 EVT_COMMAND(INTF_DIALOG_BOOKMARKS, wxEVT_DIALOG,
146 DialogsProvider::OnBookmarks)
148 EVT_COMMAND(INTF_DIALOG_POPUPMENU, wxEVT_DIALOG,
149 DialogsProvider::OnPopupMenu)
150 EVT_COMMAND(INTF_DIALOG_AUDIOPOPUPMENU, wxEVT_DIALOG,
151 DialogsProvider::OnAudioPopupMenu)
152 EVT_COMMAND(INTF_DIALOG_VIDEOPOPUPMENU, wxEVT_DIALOG,
153 DialogsProvider::OnVideoPopupMenu)
154 EVT_COMMAND(INTF_DIALOG_MISCPOPUPMENU, wxEVT_DIALOG,
155 DialogsProvider::OnMiscPopupMenu)
157 EVT_COMMAND(INTF_DIALOG_EXIT, wxEVT_DIALOG,
158 DialogsProvider::OnExitThread)
159 EVT_COMMAND(INTF_DIALOG_UPDATEVLC, wxEVT_DIALOG,
160 DialogsProvider::OnUpdateVLC)
162 EVT_COMMAND(INTF_DIALOG_VLM, wxEVT_DIALOG,
163 DialogsProvider::OnVLM)
165 EVT_COMMAND( INTF_DIALOG_INTERACTION, wxEVT_DIALOG,
166 DialogsProvider::OnInteraction )
169 wxWindow *CreateDialogsProvider( intf_thread_t *p_intf, wxWindow *p_parent )
171 return new DialogsProvider( p_intf, p_parent );
174 /*****************************************************************************
176 *****************************************************************************/
177 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf, wxWindow *p_parent )
178 : wxFrame( p_parent, -1, wxT("") )
180 /* Initializations */
182 p_open_dialog = NULL;
183 p_file_dialog = NULL;
184 p_playlist_dialog = NULL;
185 p_messages_dialog = NULL;
186 p_fileinfo_dialog = NULL;
187 p_prefs_dialog = NULL;
188 p_file_generic_dialog = NULL;
189 p_wizard_dialog = NULL;
190 p_bookmarks_dialog = NULL;
192 p_updatevlc_dialog = NULL;
193 //p_vlm_dialog = NULL;
195 /* Give our interface a nice little icon */
196 p_intf->p_sys->p_icon = new wxIcon( (const char**) vlc_xpm );
198 /* Create the messages dialog so it can begin storing logs */
199 p_messages_dialog = new Messages( p_intf, p_parent ? p_parent : this );
201 /* Check if user wants to show the bookmarks dialog by default */
202 wxCommandEvent dummy_event;
203 if( config_GetInt( p_intf, "wx-bookmarks" ) )
204 OnBookmarks( dummy_event );
206 /* Intercept all menu events in our custom event handler */
207 PushEventHandler( new MenuEvtHandler( p_intf, NULL ) );
210 WindowSettings *ws = p_intf->p_sys->p_window_settings;
215 #define INIT( id, w, N, S ) \
216 if( ws->GetSettings( WindowSettings::id, b_shown, p, s ) && b_shown ) \
225 INIT( ID_PLAYLIST, p_playlist_dialog, new Playlist(p_intf,this), ShowPlaylist );
226 INIT( ID_MESSAGES, p_messages_dialog, new Messages(p_intf,this), Show );
227 INIT( ID_FILE_INFO, p_fileinfo_dialog, new FileInfo(p_intf,this), Show );
228 INIT( ID_BOOKMARKS, p_bookmarks_dialog, new BookmarksDialog(p_intf,this), Show);
232 DialogsProvider::~DialogsProvider()
234 WindowSettings *ws = p_intf->p_sys->p_window_settings;
236 #define UPDATE(id,w) \
238 if( w && w->IsShown() && !w->IsIconized() ) \
239 ws->SetSettings( WindowSettings::id, true, \
240 w->GetPosition(), w->GetSize() ); \
242 ws->SetSettings( WindowSettings::id, false ); \
245 UPDATE( ID_PLAYLIST, p_playlist_dialog );
246 UPDATE( ID_MESSAGES, p_messages_dialog );
247 UPDATE( ID_FILE_INFO, p_fileinfo_dialog );
248 UPDATE( ID_BOOKMARKS, p_bookmarks_dialog );
252 PopEventHandler(true);
255 if( p_open_dialog ) delete p_open_dialog;
256 if( p_prefs_dialog ) p_prefs_dialog->Destroy();
257 if( p_file_dialog ) delete p_file_dialog;
258 if( p_playlist_dialog ) delete p_playlist_dialog;
259 if( p_messages_dialog ) delete p_messages_dialog;
260 if( p_fileinfo_dialog ) delete p_fileinfo_dialog;
261 if( p_file_generic_dialog ) delete p_file_generic_dialog;
262 if( p_wizard_dialog ) delete p_wizard_dialog;
263 if( p_bookmarks_dialog ) delete p_bookmarks_dialog;
264 if( p_updatevlc_dialog ) delete p_updatevlc_dialog;
265 //if( p_vlm_dialog ) delete p_vlm_dialog;
268 if( p_intf->p_sys->p_icon ) delete p_intf->p_sys->p_icon;
270 /* We must set this here because on win32 this destructor will be
271 * automatically called so we must not call it again on wxApp->OnExit().
272 * There shouldn't be any race conditions as all this should be done
273 * from the same thread. */
274 p_intf->p_sys->p_wxwindow = NULL;
277 void DialogsProvider::OnIdle( wxIdleEvent& WXUNUSED(event) )
279 /* Update the log window */
280 if( p_messages_dialog )
281 p_messages_dialog->UpdateLog();
283 /* Update the playlist */
284 if( p_playlist_dialog )
285 p_playlist_dialog->UpdatePlaylist();
287 /* Update the fileinfo windows */
288 if( p_fileinfo_dialog )
289 p_fileinfo_dialog->Update();
292 void DialogsProvider::OnPlaylist( wxCommandEvent& WXUNUSED(event) )
294 /* Show/hide the playlist window */
295 if( !p_playlist_dialog )
296 p_playlist_dialog = new Playlist( p_intf, this );
298 if( p_playlist_dialog )
300 p_playlist_dialog->ShowPlaylist( !p_playlist_dialog->IsShown() );
304 void DialogsProvider::OnMessages( wxCommandEvent& WXUNUSED(event) )
306 /* Show/hide the log window */
307 if( !p_messages_dialog )
308 p_messages_dialog = new Messages( p_intf, this );
310 if( p_messages_dialog )
312 p_messages_dialog->Show( !p_messages_dialog->IsShown() );
316 void DialogsProvider::OnFileInfo( wxCommandEvent& WXUNUSED(event) )
318 /* Show/hide the file info window */
319 if( !p_fileinfo_dialog )
320 p_fileinfo_dialog = new FileInfo( p_intf, this );
322 if( p_fileinfo_dialog )
324 p_fileinfo_dialog->Show( !p_fileinfo_dialog->IsShown() );
328 void DialogsProvider::OnPreferences( wxCommandEvent& WXUNUSED(event) )
330 /* Show/hide the open dialog */
331 if( !p_prefs_dialog )
332 p_prefs_dialog = new PrefsDialog( p_intf, this );
336 p_prefs_dialog->Show( !p_prefs_dialog->IsShown() );
340 void DialogsProvider::OnWizardDialog( wxCommandEvent& WXUNUSED(event) )
342 p_wizard_dialog = new WizardDialog( p_intf, this, NULL, 0, 0 );
344 if( p_wizard_dialog )
346 p_wizard_dialog->Run();
347 delete p_wizard_dialog;
350 p_wizard_dialog = NULL;
353 void DialogsProvider::OnBookmarks( wxCommandEvent& WXUNUSED(event) )
355 /* Show/hide the open dialog */
356 if( !p_bookmarks_dialog )
357 p_bookmarks_dialog = new BookmarksDialog( p_intf, this );
359 if( p_bookmarks_dialog )
361 p_bookmarks_dialog->Show( !p_bookmarks_dialog->IsShown() );
365 void DialogsProvider::OnOpenFileGeneric( wxCommandEvent& event )
367 intf_dialog_args_t *p_arg = (intf_dialog_args_t *)event.GetClientData();
371 msg_Dbg( p_intf, "OnOpenFileGeneric() called with NULL arg" );
375 if( p_file_generic_dialog == NULL )
376 p_file_generic_dialog = new wxFileDialog( NULL );
378 if( p_file_generic_dialog )
380 p_file_generic_dialog->SetMessage( wxU(p_arg->psz_title) );
381 p_file_generic_dialog->SetWildcard( wxU(p_arg->psz_extensions) );
382 p_file_generic_dialog->SetWindowStyle( (p_arg->b_save ? wxSAVE : wxOPEN) |
383 (p_arg->b_multiple ? wxMULTIPLE:0) );
386 if( p_file_generic_dialog &&
387 p_file_generic_dialog->ShowModal() == wxID_OK )
391 p_file_generic_dialog->GetPaths( paths );
393 p_arg->i_results = paths.GetCount();
394 p_arg->psz_results = (char **)malloc( p_arg->i_results *
396 for( size_t i = 0; i < paths.GetCount(); i++ )
398 p_arg->psz_results[i] = strdup( paths[i].mb_str(wxConvUTF8) );
403 if( p_arg->pf_callback )
405 p_arg->pf_callback( p_arg );
408 if( p_arg->psz_results )
410 for( int i = 0; i < p_arg->i_results; i++ )
412 free( p_arg->psz_results[i] );
414 free( p_arg->psz_results );
416 if( p_arg->psz_title ) free( p_arg->psz_title );
417 if( p_arg->psz_extensions ) free( p_arg->psz_extensions );
422 void DialogsProvider::OnOpenFileSimple( wxCommandEvent& event )
424 playlist_t *p_playlist =
425 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
427 if( p_playlist == NULL )
432 if( p_file_dialog == NULL )
433 p_file_dialog = new wxFileDialog( NULL, wxU(_("Open File")),
434 wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
436 p_file_dialog->SetWildcard(wxU(_("All Files (*.*)|*"
437 "|Sound Files (*.mp3, *.ogg, etc.)|" EXTENSIONS_AUDIO
438 "|Video Files (*.avi, *.mpg, etc.)|" EXTENSIONS_VIDEO
439 "|Playlist Files (*.m3u, *.pls, etc.)|" EXTENSIONS_PLAYLIST
440 "|Subtitle Files (*.srt, *.sub, etc.)|" EXTENSIONS_SUBTITLE)));
442 if( p_file_dialog && p_file_dialog->ShowModal() == wxID_OK )
446 p_file_dialog->GetPaths( paths );
448 for( size_t i = 0; i < paths.GetCount(); i++ )
450 char *psz_utf8 = wxFromLocale( paths[i] );
452 playlist_Add( p_playlist, psz_utf8, NULL,
453 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
454 (i ? PLAYLIST_PREPARSE : 0 ),
455 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
457 playlist_Add( p_playlist, psz_utf8, NULL,
458 PLAYLIST_APPEND | PLAYLIST_PREPARSE , PLAYLIST_END , VLC_TRUE, VLC_FALSE );
459 wxLocaleFree( psz_utf8 );
463 vlc_object_release( p_playlist );
466 void DialogsProvider::OnOpenDirectory( wxCommandEvent& event )
468 playlist_t *p_playlist =
469 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
471 if( p_playlist == NULL )
476 if( p_dir_dialog == NULL )
477 p_dir_dialog = new wxDirDialog( NULL, wxU(_("Select a directory")) );
479 if( p_dir_dialog && p_dir_dialog->ShowModal() == wxID_OK )
481 wxString path = p_dir_dialog->GetPath();
482 char *psz_utf8 = wxFromLocale( path );
483 playlist_Add( p_playlist, psz_utf8, NULL,
484 PLAYLIST_APPEND | (event.GetInt() ? PLAYLIST_GO : 0),
485 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
486 wxLocaleFree( psz_utf8 );
489 vlc_object_release( p_playlist );
492 void DialogsProvider::OnOpenFile( wxCommandEvent& event )
494 Open( FILE_ACCESS, event.GetInt() );
497 void DialogsProvider::OnOpenDisc( wxCommandEvent& event )
499 Open( DISC_ACCESS, event.GetInt() );
502 void DialogsProvider::OnOpenNet( wxCommandEvent& event )
504 Open( NET_ACCESS, event.GetInt() );
507 void DialogsProvider::OnOpenCapture( wxCommandEvent& event )
509 Open( CAPTURE_ACCESS, event.GetInt() );
512 void DialogsProvider::Open( int i_access_method, int i_arg )
514 /* Show/hide the open dialog */
516 p_open_dialog = new OpenDialog( p_intf, this, i_access_method, i_arg,
521 p_open_dialog->Show( i_access_method, i_arg );
525 void DialogsProvider::OnPopupMenu( wxCommandEvent& event )
527 wxPoint mousepos = ScreenToClient( wxGetMousePosition() );
528 ::PopupMenu( p_intf, this, mousepos );
531 void DialogsProvider::OnAudioPopupMenu( wxCommandEvent& event )
533 wxPoint mousepos = ScreenToClient( wxGetMousePosition() );
534 ::AudioPopupMenu( p_intf, this, mousepos );
536 void DialogsProvider::OnVideoPopupMenu( wxCommandEvent& event )
538 wxPoint mousepos = ScreenToClient( wxGetMousePosition() );
539 ::VideoPopupMenu( p_intf, this, mousepos );
541 void DialogsProvider::OnMiscPopupMenu( wxCommandEvent& event )
543 wxPoint mousepos = ScreenToClient( wxGetMousePosition() );
544 ::MiscPopupMenu( p_intf, this, mousepos );
547 void DialogsProvider::OnExitThread( wxCommandEvent& WXUNUSED(event) )
549 wxTheApp->ExitMainLoop();
552 void DialogsProvider::OnUpdateVLC( wxCommandEvent& WXUNUSED(event) )
554 /* Show/hide the file info window */
555 if( !p_updatevlc_dialog )
556 p_updatevlc_dialog = new UpdateVLC( p_intf, this );
558 if( p_updatevlc_dialog )
560 p_updatevlc_dialog->Show( !p_updatevlc_dialog->IsShown() );
565 void DialogsProvider::OnVLM( wxCommandEvent& WXUNUSED(event) )
567 /* Show/hide the file info window */
569 p_vlm_dialog = new VLMFrame( p_intf, this );
573 p_vlm_dialog->Show( !p_vlm_dialog->IsShown() );
578 void DialogsProvider::OnInteraction( wxCommandEvent& event )
580 intf_dialog_args_t *p_arg = (intf_dialog_args_t *)event.GetClientData();
581 interaction_dialog_t *p_dialog;
582 InteractionDialog *p_wxdialog;
588 msg_Dbg( p_intf, "OnInteraction() called with NULL arg" );
591 p_dialog = p_arg->p_dialog;
593 /** \bug We store the interface object for the dialog in the p_private
594 * field of the core dialog object. This is not safe if we change
595 * interface while a dialog is loaded */
597 switch( p_dialog->i_action )
600 p_wxdialog = new InteractionDialog( p_intf, this, p_dialog );
601 p_dialog->p_private = (void*)p_wxdialog;
604 case INTERACT_UPDATE:
605 p_wxdialog = (InteractionDialog*)(p_dialog->p_private);
607 p_wxdialog->Update();
610 p_wxdialog = (InteractionDialog*)(p_dialog->p_private);
613 p_dialog->i_status = HIDDEN_DIALOG;
615 case INTERACT_DESTROY:
616 p_wxdialog = (InteractionDialog*)(p_dialog->p_private);
618 p_dialog->i_status = DESTROYED_DIALOG;