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 <stdlib.h> /* malloc(), free() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
38 #include "dialogs/vlm/vlm_panel.hpp"
39 #include "dialogs/bookmarks.hpp"
40 #include "dialogs/wizard.hpp"
41 #include "dialogs/playlist.hpp"
42 #include "dialogs/open.hpp"
43 #include "dialogs/updatevlc.hpp"
44 #include "dialogs/fileinfo.hpp"
45 #include "dialogs/iteminfo.hpp"
46 #include "dialogs/preferences.hpp"
47 #include "dialogs/messages.hpp"
48 #include "dialogs/interaction.hpp"
49 #include "interface.hpp"
51 /* include the icon graphic */
52 #include "../../../share/vlc32x32.xpm"
54 /* 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 );
88 void OnIdle( wxIdleEvent& event );
90 void OnExitThread( wxCommandEvent& event );
92 DECLARE_EVENT_TABLE();
94 intf_thread_t *p_intf;
97 /* Secondary windows */
98 OpenDialog *p_open_dialog;
99 wxFileDialog *p_file_dialog;
100 wxDirDialog *p_dir_dialog;
101 Playlist *p_playlist_dialog;
102 Messages *p_messages_dialog;
103 FileInfo *p_fileinfo_dialog;
104 WizardDialog *p_wizard_dialog;
105 wxFrame *p_prefs_dialog;
106 wxFrame *p_bookmarks_dialog;
107 wxFileDialog *p_file_generic_dialog;
108 UpdateVLC *p_updatevlc_dialog;
109 VLMFrame *p_vlm_dialog;
112 DEFINE_LOCAL_EVENT_TYPE( wxEVT_DIALOG );
114 BEGIN_EVENT_TABLE(DialogsProvider, wxFrame)
115 /* Idle loop used to update some of the dialogs */
116 EVT_IDLE(DialogsProvider::OnIdle)
118 /* Custom wxDialog events */
119 EVT_COMMAND(INTF_DIALOG_FILE, wxEVT_DIALOG, DialogsProvider::OnOpenFile)
120 EVT_COMMAND(INTF_DIALOG_DISC, wxEVT_DIALOG, DialogsProvider::OnOpenDisc)
121 EVT_COMMAND(INTF_DIALOG_NET, wxEVT_DIALOG, DialogsProvider::OnOpenNet)
122 EVT_COMMAND(INTF_DIALOG_CAPTURE, wxEVT_DIALOG,
123 DialogsProvider::OnOpenCapture)
124 EVT_COMMAND(INTF_DIALOG_FILE_SIMPLE, wxEVT_DIALOG,
125 DialogsProvider::OnOpenFileSimple)
126 EVT_COMMAND(INTF_DIALOG_FILE_GENERIC, wxEVT_DIALOG,
127 DialogsProvider::OnOpenFileGeneric)
128 EVT_COMMAND(INTF_DIALOG_DIRECTORY, wxEVT_DIALOG,
129 DialogsProvider::OnOpenDirectory)
131 EVT_COMMAND(INTF_DIALOG_PLAYLIST, wxEVT_DIALOG,
132 DialogsProvider::OnPlaylist)
133 EVT_COMMAND(INTF_DIALOG_MESSAGES, wxEVT_DIALOG,
134 DialogsProvider::OnMessages)
135 EVT_COMMAND(INTF_DIALOG_PREFS, wxEVT_DIALOG,
136 DialogsProvider::OnPreferences)
137 EVT_COMMAND(INTF_DIALOG_WIZARD, wxEVT_DIALOG,
138 DialogsProvider::OnWizardDialog)
139 EVT_COMMAND(INTF_DIALOG_FILEINFO, wxEVT_DIALOG,
140 DialogsProvider::OnFileInfo)
141 EVT_COMMAND(INTF_DIALOG_BOOKMARKS, wxEVT_DIALOG,
142 DialogsProvider::OnBookmarks)
143 EVT_COMMAND(INTF_DIALOG_POPUPMENU, wxEVT_DIALOG,
144 DialogsProvider::OnPopupMenu)
145 EVT_COMMAND(INTF_DIALOG_EXIT, wxEVT_DIALOG,
146 DialogsProvider::OnExitThread)
147 EVT_COMMAND(INTF_DIALOG_UPDATEVLC, wxEVT_DIALOG,
148 DialogsProvider::OnUpdateVLC)
149 EVT_COMMAND(INTF_DIALOG_VLM, wxEVT_DIALOG,
150 DialogsProvider::OnVLM)
151 EVT_COMMAND( INTF_DIALOG_INTERACTION, wxEVT_DIALOG,
152 DialogsProvider::OnInteraction )
155 wxWindow *CreateDialogsProvider( intf_thread_t *p_intf, wxWindow *p_parent )
157 return new DialogsProvider( p_intf, p_parent );
160 /*****************************************************************************
162 *****************************************************************************/
163 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf, wxWindow *p_parent )
164 : wxFrame( p_parent, -1, wxT("") )
166 /* Initializations */
168 p_open_dialog = NULL;
169 p_file_dialog = NULL;
170 p_playlist_dialog = NULL;
171 p_messages_dialog = NULL;
172 p_fileinfo_dialog = NULL;
173 p_prefs_dialog = NULL;
174 p_file_generic_dialog = NULL;
175 p_wizard_dialog = NULL;
176 p_bookmarks_dialog = NULL;
178 p_updatevlc_dialog = NULL;
181 /* Give our interface a nice little icon */
182 p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
184 /* Create the messages dialog so it can begin storing logs */
185 p_messages_dialog = new Messages( p_intf, p_parent ? p_parent : this );
187 /* Check if user wants to show the bookmarks dialog by default */
188 wxCommandEvent dummy_event;
189 if( config_GetInt( p_intf, "wx-bookmarks" ) )
190 OnBookmarks( dummy_event );
192 /* Intercept all menu events in our custom event handler */
193 PushEventHandler( new MenuEvtHandler( p_intf, NULL ) );
196 WindowSettings *ws = p_intf->p_sys->p_window_settings;
201 #define INIT( id, w, N, S ) \
202 if( ws->GetSettings( WindowSettings::id, b_shown, p, s ) && b_shown ) \
211 INIT( ID_PLAYLIST, p_playlist_dialog, new Playlist(p_intf,this), ShowPlaylist );
212 INIT( ID_MESSAGES, p_messages_dialog, new Messages(p_intf,this), Show );
213 INIT( ID_FILE_INFO, p_fileinfo_dialog, new FileInfo(p_intf,this), Show );
214 INIT( ID_BOOKMARKS, p_bookmarks_dialog, new BookmarksDialog(p_intf,this), Show);
218 DialogsProvider::~DialogsProvider()
220 WindowSettings *ws = p_intf->p_sys->p_window_settings;
222 #define UPDATE(id,w) \
224 if( w && w->IsShown() && !w->IsIconized() ) \
225 ws->SetSettings( WindowSettings::id, true, \
226 w->GetPosition(), w->GetSize() ); \
228 ws->SetSettings( WindowSettings::id, false ); \
231 UPDATE( ID_PLAYLIST, p_playlist_dialog );
232 UPDATE( ID_MESSAGES, p_messages_dialog );
233 UPDATE( ID_FILE_INFO, p_fileinfo_dialog );
234 UPDATE( ID_BOOKMARKS, p_bookmarks_dialog );
238 PopEventHandler(true);
241 if( p_open_dialog ) delete p_open_dialog;
242 if( p_prefs_dialog ) p_prefs_dialog->Destroy();
243 if( p_file_dialog ) delete p_file_dialog;
244 if( p_playlist_dialog ) delete p_playlist_dialog;
245 if( p_messages_dialog ) delete p_messages_dialog;
246 if( p_fileinfo_dialog ) delete p_fileinfo_dialog;
247 if( p_file_generic_dialog ) delete p_file_generic_dialog;
248 if( p_wizard_dialog ) delete p_wizard_dialog;
249 if( p_bookmarks_dialog ) delete p_bookmarks_dialog;
250 if( p_updatevlc_dialog ) delete p_updatevlc_dialog;
251 if( p_vlm_dialog ) delete p_vlm_dialog;
254 if( p_intf->p_sys->p_icon ) delete p_intf->p_sys->p_icon;
256 /* We must set this here because on win32 this destructor will be
257 * automatically called so we must not call it again on wxApp->OnExit().
258 * There shouldn't be any race conditions as all this should be done
259 * from the same thread. */
260 p_intf->p_sys->p_wxwindow = NULL;
263 void DialogsProvider::OnIdle( wxIdleEvent& WXUNUSED(event) )
265 /* Update the log window */
266 if( p_messages_dialog )
267 p_messages_dialog->UpdateLog();
269 /* Update the playlist */
270 if( p_playlist_dialog )
271 p_playlist_dialog->UpdatePlaylist();
273 /* Update the fileinfo windows */
274 if( p_fileinfo_dialog )
275 p_fileinfo_dialog->Update();
278 void DialogsProvider::OnPlaylist( wxCommandEvent& WXUNUSED(event) )
280 /* Show/hide the playlist window */
281 if( !p_playlist_dialog )
282 p_playlist_dialog = new Playlist( p_intf, this );
284 if( p_playlist_dialog )
286 p_playlist_dialog->ShowPlaylist( !p_playlist_dialog->IsShown() );
290 void DialogsProvider::OnMessages( wxCommandEvent& WXUNUSED(event) )
292 /* Show/hide the log window */
293 if( !p_messages_dialog )
294 p_messages_dialog = new Messages( p_intf, this );
296 if( p_messages_dialog )
298 p_messages_dialog->Show( !p_messages_dialog->IsShown() );
302 void DialogsProvider::OnFileInfo( wxCommandEvent& WXUNUSED(event) )
304 /* Show/hide the file info window */
305 if( !p_fileinfo_dialog )
306 p_fileinfo_dialog = new FileInfo( p_intf, this );
308 if( p_fileinfo_dialog )
310 p_fileinfo_dialog->Show( !p_fileinfo_dialog->IsShown() );
314 void DialogsProvider::OnPreferences( wxCommandEvent& WXUNUSED(event) )
316 /* Show/hide the open dialog */
317 if( !p_prefs_dialog )
318 p_prefs_dialog = new PrefsDialog( p_intf, this );
322 p_prefs_dialog->Show( !p_prefs_dialog->IsShown() );
326 void DialogsProvider::OnWizardDialog( wxCommandEvent& WXUNUSED(event) )
328 p_wizard_dialog = new WizardDialog( p_intf, this, NULL, 0, 0 );
330 if( p_wizard_dialog )
332 p_wizard_dialog->Run();
333 delete p_wizard_dialog;
336 p_wizard_dialog = NULL;
339 void DialogsProvider::OnBookmarks( wxCommandEvent& WXUNUSED(event) )
341 /* Show/hide the open dialog */
342 if( !p_bookmarks_dialog )
343 p_bookmarks_dialog = new BookmarksDialog( p_intf, this );
345 if( p_bookmarks_dialog )
347 p_bookmarks_dialog->Show( !p_bookmarks_dialog->IsShown() );
351 void DialogsProvider::OnOpenFileGeneric( wxCommandEvent& event )
353 intf_dialog_args_t *p_arg = (intf_dialog_args_t *)event.GetClientData();
357 msg_Dbg( p_intf, "OnOpenFileGeneric() called with NULL arg" );
361 if( p_file_generic_dialog == NULL )
362 p_file_generic_dialog = new wxFileDialog( NULL );
364 if( p_file_generic_dialog )
366 p_file_generic_dialog->SetMessage( wxU(p_arg->psz_title) );
367 p_file_generic_dialog->SetWildcard( wxU(p_arg->psz_extensions) );
368 p_file_generic_dialog->SetStyle( (p_arg->b_save ? wxSAVE : wxOPEN) |
369 (p_arg->b_multiple ? wxMULTIPLE:0) );
372 if( p_file_generic_dialog &&
373 p_file_generic_dialog->ShowModal() == wxID_OK )
377 p_file_generic_dialog->GetPaths( paths );
379 p_arg->i_results = paths.GetCount();
380 p_arg->psz_results = (char **)malloc( p_arg->i_results *
382 for( size_t i = 0; i < paths.GetCount(); i++ )
384 p_arg->psz_results[i] = strdup( paths[i].mb_str() );
389 if( p_arg->pf_callback )
391 p_arg->pf_callback( p_arg );
394 if( p_arg->psz_results )
396 for( int i = 0; i < p_arg->i_results; i++ )
398 free( p_arg->psz_results[i] );
400 free( p_arg->psz_results );
402 if( p_arg->psz_title ) free( p_arg->psz_title );
403 if( p_arg->psz_extensions ) free( p_arg->psz_extensions );
408 void DialogsProvider::OnOpenFileSimple( wxCommandEvent& event )
410 playlist_t *p_playlist =
411 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
413 if( p_playlist == NULL )
418 if( p_file_dialog == NULL )
419 p_file_dialog = new wxFileDialog( NULL, wxU(_("Open File")),
420 wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
422 if( p_file_dialog && p_file_dialog->ShowModal() == wxID_OK )
426 p_file_dialog->GetPaths( paths );
428 for( size_t i = 0; i < paths.GetCount(); i++ )
430 char *psz_utf8 = wxFromLocale( paths[i] );
432 playlist_Add( p_playlist, psz_utf8, psz_utf8,
433 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
434 (i ? PLAYLIST_PREPARSE : 0 ),
437 playlist_Add( p_playlist, psz_utf8, psz_utf8,
438 PLAYLIST_APPEND | PLAYLIST_PREPARSE , PLAYLIST_END );
439 wxLocaleFree( psz_utf8 );
443 vlc_object_release( p_playlist );
446 void DialogsProvider::OnOpenDirectory( wxCommandEvent& event )
448 playlist_t *p_playlist =
449 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
451 if( p_playlist == NULL )
456 if( p_dir_dialog == NULL )
457 p_dir_dialog = new wxDirDialog( NULL );
459 if( p_dir_dialog && p_dir_dialog->ShowModal() == wxID_OK )
461 wxString path = p_dir_dialog->GetPath();
462 char *psz_utf8 = wxFromLocale( path );
463 playlist_Add( p_playlist, psz_utf8, psz_utf8,
464 PLAYLIST_APPEND | (event.GetInt() ? PLAYLIST_GO : 0),
466 wxLocaleFree( psz_utf8 );
469 vlc_object_release( p_playlist );
472 void DialogsProvider::OnOpenFile( wxCommandEvent& event )
474 Open( FILE_ACCESS, event.GetInt() );
477 void DialogsProvider::OnOpenDisc( wxCommandEvent& event )
479 Open( DISC_ACCESS, event.GetInt() );
482 void DialogsProvider::OnOpenNet( wxCommandEvent& event )
484 Open( NET_ACCESS, event.GetInt() );
487 void DialogsProvider::OnOpenCapture( wxCommandEvent& event )
489 Open( CAPTURE_ACCESS, event.GetInt() );
492 void DialogsProvider::Open( int i_access_method, int i_arg )
494 /* Show/hide the open dialog */
496 p_open_dialog = new OpenDialog( p_intf, this, i_access_method, i_arg,
501 p_open_dialog->Show( i_access_method, i_arg );
505 void DialogsProvider::OnPopupMenu( wxCommandEvent& event )
507 wxPoint mousepos = ScreenToClient( wxGetMousePosition() );
508 ::PopupMenu( p_intf, this, mousepos );
511 void DialogsProvider::OnExitThread( wxCommandEvent& WXUNUSED(event) )
513 wxTheApp->ExitMainLoop();
516 void DialogsProvider::OnUpdateVLC( wxCommandEvent& WXUNUSED(event) )
518 /* Show/hide the file info window */
519 if( !p_updatevlc_dialog )
520 p_updatevlc_dialog = new UpdateVLC( p_intf, this );
522 if( p_updatevlc_dialog )
524 p_updatevlc_dialog->Show( !p_updatevlc_dialog->IsShown() );
528 void DialogsProvider::OnVLM( wxCommandEvent& WXUNUSED(event) )
530 /* Show/hide the file info window */
532 p_vlm_dialog = new VLMFrame( p_intf, this );
536 p_vlm_dialog->Show( !p_vlm_dialog->IsShown() );
540 void DialogsProvider::OnInteraction( wxCommandEvent& event )
542 intf_dialog_args_t *p_arg = (intf_dialog_args_t *)event.GetClientData();
543 interaction_dialog_t *p_dialog;
544 InteractionDialog *p_wxdialog;
548 msg_Dbg( p_intf, "OnInteraction() called with NULL arg" );
551 p_dialog = p_arg->p_dialog;
553 /** \bug We store the interface object for the dialog in the p_private
554 * field of the core dialog object. This is not safe if we change
555 * interface while a dialog is loaded */
557 switch( p_dialog->i_action )
560 p_wxdialog = new InteractionDialog( p_intf, this, p_dialog );
561 p_dialog->p_private = (void*)p_wxdialog;
564 case INTERACT_UPDATE:
565 p_wxdialog = (InteractionDialog*)(p_dialog->p_private);
567 p_wxdialog->Update();
570 p_wxdialog = (InteractionDialog*)(p_dialog->p_private);
573 p_dialog->i_status = HIDDEN_DIALOG;
575 case INTERACT_DESTROY:
576 p_wxdialog = (InteractionDialog*)(p_dialog->p_private);
578 p_dialog->i_status = DESTROYED_DIALOG;