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., 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() */
37 #include "wxwidgets.h"
39 /* include the icon graphic */
40 #include "../../../share/vlc32x32.xpm"
42 /* Dialogs Provider */
43 class DialogsProvider: public wxFrame
47 DialogsProvider( intf_thread_t *p_intf, wxWindow *p_parent );
48 virtual ~DialogsProvider();
51 void Open( int i_access_method, int i_arg );
53 /* Event handlers (these functions should _not_ be virtual) */
54 void OnUpdateVLC( wxCommandEvent& event );
55 void OnExit( wxCommandEvent& event );
56 void OnPlaylist( wxCommandEvent& event );
57 void OnMessages( wxCommandEvent& event );
58 void OnFileInfo( wxCommandEvent& event );
59 void OnPreferences( wxCommandEvent& event );
60 void OnWizardDialog( wxCommandEvent& event );
61 void OnBookmarks( wxCommandEvent& event );
63 void OnOpenFileGeneric( wxCommandEvent& event );
64 void OnOpenFileSimple( wxCommandEvent& event );
65 void OnOpenDirectory( wxCommandEvent& event );
66 void OnOpenFile( wxCommandEvent& event );
67 void OnOpenDisc( wxCommandEvent& event );
68 void OnOpenNet( wxCommandEvent& event );
69 void OnOpenCapture( wxCommandEvent& event );
70 void OnOpenSat( wxCommandEvent& event );
72 void OnPopupMenu( wxCommandEvent& event );
74 void OnIdle( wxIdleEvent& event );
76 void OnExitThread( wxCommandEvent& event );
78 DECLARE_EVENT_TABLE();
80 intf_thread_t *p_intf;
83 /* Secondary windows */
84 OpenDialog *p_open_dialog;
85 wxFileDialog *p_file_dialog;
86 wxDirDialog *p_dir_dialog;
87 Playlist *p_playlist_dialog;
88 Messages *p_messages_dialog;
89 FileInfo *p_fileinfo_dialog;
90 WizardDialog *p_wizard_dialog;
91 wxFrame *p_prefs_dialog;
92 wxFrame *p_bookmarks_dialog;
93 wxFileDialog *p_file_generic_dialog;
94 UpdateVLC *p_updatevlc_dialog;
97 DEFINE_LOCAL_EVENT_TYPE( wxEVT_DIALOG );
99 BEGIN_EVENT_TABLE(DialogsProvider, wxFrame)
100 /* Idle loop used to update some of the dialogs */
101 EVT_IDLE(DialogsProvider::OnIdle)
103 /* Custom wxDialog events */
104 EVT_COMMAND(INTF_DIALOG_FILE, wxEVT_DIALOG, DialogsProvider::OnOpenFile)
105 EVT_COMMAND(INTF_DIALOG_DISC, wxEVT_DIALOG, DialogsProvider::OnOpenDisc)
106 EVT_COMMAND(INTF_DIALOG_NET, wxEVT_DIALOG, DialogsProvider::OnOpenNet)
107 EVT_COMMAND(INTF_DIALOG_CAPTURE, wxEVT_DIALOG,
108 DialogsProvider::OnOpenCapture)
109 EVT_COMMAND(INTF_DIALOG_FILE_SIMPLE, wxEVT_DIALOG,
110 DialogsProvider::OnOpenFileSimple)
111 EVT_COMMAND(INTF_DIALOG_FILE_GENERIC, wxEVT_DIALOG,
112 DialogsProvider::OnOpenFileGeneric)
113 EVT_COMMAND(INTF_DIALOG_DIRECTORY, wxEVT_DIALOG,
114 DialogsProvider::OnOpenDirectory)
116 EVT_COMMAND(INTF_DIALOG_PLAYLIST, wxEVT_DIALOG,
117 DialogsProvider::OnPlaylist)
118 EVT_COMMAND(INTF_DIALOG_MESSAGES, wxEVT_DIALOG,
119 DialogsProvider::OnMessages)
120 EVT_COMMAND(INTF_DIALOG_PREFS, wxEVT_DIALOG,
121 DialogsProvider::OnPreferences)
122 EVT_COMMAND(INTF_DIALOG_WIZARD, wxEVT_DIALOG,
123 DialogsProvider::OnWizardDialog)
124 EVT_COMMAND(INTF_DIALOG_FILEINFO, wxEVT_DIALOG,
125 DialogsProvider::OnFileInfo)
126 EVT_COMMAND(INTF_DIALOG_BOOKMARKS, wxEVT_DIALOG,
127 DialogsProvider::OnBookmarks)
128 EVT_COMMAND(INTF_DIALOG_POPUPMENU, wxEVT_DIALOG,
129 DialogsProvider::OnPopupMenu)
130 EVT_COMMAND(INTF_DIALOG_EXIT, wxEVT_DIALOG,
131 DialogsProvider::OnExitThread)
132 EVT_COMMAND(INTF_DIALOG_UPDATEVLC, wxEVT_DIALOG,
133 DialogsProvider::OnUpdateVLC)
136 wxWindow *CreateDialogsProvider( intf_thread_t *p_intf, wxWindow *p_parent )
138 return new DialogsProvider( p_intf, p_parent );
141 /*****************************************************************************
143 *****************************************************************************/
144 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf, wxWindow *p_parent )
145 : wxFrame( p_parent, -1, wxT("") )
147 /* Initializations */
149 p_open_dialog = NULL;
150 p_file_dialog = NULL;
151 p_playlist_dialog = NULL;
152 p_messages_dialog = NULL;
153 p_fileinfo_dialog = NULL;
154 p_prefs_dialog = NULL;
155 p_file_generic_dialog = NULL;
156 p_wizard_dialog = NULL;
157 p_bookmarks_dialog = NULL;
159 p_updatevlc_dialog = NULL;
161 /* Give our interface a nice little icon */
162 p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
164 /* Create the messages dialog so it can begin storing logs */
165 p_messages_dialog = new Messages( p_intf, p_parent ? p_parent : this );
167 /* Check if user wants to show the bookmarks dialog by default */
168 wxCommandEvent dummy_event;
169 if( config_GetInt( p_intf, "wx-bookmarks" ) )
170 OnBookmarks( dummy_event );
172 /* Intercept all menu events in our custom event handler */
173 PushEventHandler( new MenuEvtHandler( p_intf, NULL ) );
176 WindowSettings *ws = p_intf->p_sys->p_window_settings;
181 #define INIT( id, w, N, S ) \
182 if( ws->GetSettings( WindowSettings::id, b_shown, p, s ) && b_shown ) \
191 INIT( ID_PLAYLIST, p_playlist_dialog, new Playlist(p_intf,this), ShowPlaylist );
192 INIT( ID_MESSAGES, p_messages_dialog, new Messages(p_intf,this), Show );
193 INIT( ID_FILE_INFO, p_fileinfo_dialog, new FileInfo(p_intf,this), Show );
194 INIT( ID_BOOKMARKS, p_bookmarks_dialog, BookmarksDialog(p_intf,this), Show);
198 DialogsProvider::~DialogsProvider()
200 WindowSettings *ws = p_intf->p_sys->p_window_settings;
202 #define UPDATE(id,w) \
204 if( w && w->IsShown() && !w->IsIconized() ) \
205 ws->SetSettings( WindowSettings::id, true, \
206 w->GetPosition(), w->GetSize() ); \
208 ws->SetSettings( WindowSettings::id, false ); \
211 UPDATE( ID_PLAYLIST, p_playlist_dialog );
212 UPDATE( ID_MESSAGES, p_messages_dialog );
213 UPDATE( ID_FILE_INFO, p_fileinfo_dialog );
214 UPDATE( ID_BOOKMARKS, p_bookmarks_dialog );
218 PopEventHandler(true);
221 if( p_open_dialog ) delete p_open_dialog;
222 if( p_prefs_dialog ) p_prefs_dialog->Destroy();
223 if( p_file_dialog ) delete p_file_dialog;
224 if( p_playlist_dialog ) delete p_playlist_dialog;
225 if( p_messages_dialog ) delete p_messages_dialog;
226 if( p_fileinfo_dialog ) delete p_fileinfo_dialog;
227 if( p_file_generic_dialog ) delete p_file_generic_dialog;
228 if( p_wizard_dialog ) delete p_wizard_dialog;
229 if( p_bookmarks_dialog ) delete p_bookmarks_dialog;
230 if( p_updatevlc_dialog ) delete p_updatevlc_dialog;
233 if( p_intf->p_sys->p_icon ) delete p_intf->p_sys->p_icon;
235 /* We must set this here because on win32 this destructor will be
236 * automatically called so we must not call it again on wxApp->OnExit().
237 * There shouldn't be any race conditions as all this should be done
238 * from the same thread. */
239 p_intf->p_sys->p_wxwindow = NULL;
242 void DialogsProvider::OnIdle( wxIdleEvent& WXUNUSED(event) )
244 /* Update the log window */
245 if( p_messages_dialog )
246 p_messages_dialog->UpdateLog();
248 /* Update the playlist */
249 if( p_playlist_dialog )
250 p_playlist_dialog->UpdatePlaylist();
252 /* Update the fileinfo windows */
253 if( p_fileinfo_dialog )
254 p_fileinfo_dialog->UpdateFileInfo();
257 void DialogsProvider::OnPlaylist( wxCommandEvent& WXUNUSED(event) )
259 /* Show/hide the playlist window */
260 if( !p_playlist_dialog )
261 p_playlist_dialog = new Playlist( p_intf, this );
263 if( p_playlist_dialog )
265 p_playlist_dialog->ShowPlaylist( !p_playlist_dialog->IsShown() );
269 void DialogsProvider::OnMessages( wxCommandEvent& WXUNUSED(event) )
271 /* Show/hide the log window */
272 if( !p_messages_dialog )
273 p_messages_dialog = new Messages( p_intf, this );
275 if( p_messages_dialog )
277 p_messages_dialog->Show( !p_messages_dialog->IsShown() );
281 void DialogsProvider::OnFileInfo( wxCommandEvent& WXUNUSED(event) )
283 /* Show/hide the file info window */
284 if( !p_fileinfo_dialog )
285 p_fileinfo_dialog = new FileInfo( p_intf, this );
287 if( p_fileinfo_dialog )
289 p_fileinfo_dialog->Show( !p_fileinfo_dialog->IsShown() );
293 void DialogsProvider::OnPreferences( wxCommandEvent& WXUNUSED(event) )
295 /* Show/hide the open dialog */
296 if( !p_prefs_dialog )
297 p_prefs_dialog = new PrefsDialog( p_intf, this );
301 p_prefs_dialog->Show( !p_prefs_dialog->IsShown() );
305 void DialogsProvider::OnWizardDialog( wxCommandEvent& WXUNUSED(event) )
307 p_wizard_dialog = new WizardDialog( p_intf, this, NULL, 0, 0 );
309 if( p_wizard_dialog )
311 p_wizard_dialog->Run();
312 delete p_wizard_dialog;
315 p_wizard_dialog = NULL;
318 void DialogsProvider::OnBookmarks( wxCommandEvent& WXUNUSED(event) )
320 /* Show/hide the open dialog */
321 if( !p_bookmarks_dialog )
322 p_bookmarks_dialog = BookmarksDialog( p_intf, this );
324 if( p_bookmarks_dialog )
326 p_bookmarks_dialog->Show( !p_bookmarks_dialog->IsShown() );
330 void DialogsProvider::OnOpenFileGeneric( wxCommandEvent& event )
332 intf_dialog_args_t *p_arg = (intf_dialog_args_t *)event.GetClientData();
336 msg_Dbg( p_intf, "OnOpenFileGeneric() called with NULL arg" );
340 if( p_file_generic_dialog == NULL )
341 p_file_generic_dialog = new wxFileDialog( NULL );
343 if( p_file_generic_dialog )
345 p_file_generic_dialog->SetMessage( wxU(p_arg->psz_title) );
346 p_file_generic_dialog->SetWildcard( wxU(p_arg->psz_extensions) );
347 p_file_generic_dialog->SetStyle( (p_arg->b_save ? wxSAVE : wxOPEN) |
348 (p_arg->b_multiple ? wxMULTIPLE:0) );
351 if( p_file_generic_dialog &&
352 p_file_generic_dialog->ShowModal() == wxID_OK )
356 p_file_generic_dialog->GetPaths( paths );
358 p_arg->i_results = paths.GetCount();
359 p_arg->psz_results = (char **)malloc( p_arg->i_results *
361 for( size_t i = 0; i < paths.GetCount(); i++ )
363 p_arg->psz_results[i] = strdup( paths[i].mb_str() );
368 if( p_arg->pf_callback )
370 p_arg->pf_callback( p_arg );
373 if( p_arg->psz_results )
375 for( int i = 0; i < p_arg->i_results; i++ )
377 free( p_arg->psz_results[i] );
379 free( p_arg->psz_results );
381 if( p_arg->psz_title ) free( p_arg->psz_title );
382 if( p_arg->psz_extensions ) free( p_arg->psz_extensions );
387 void DialogsProvider::OnOpenFileSimple( wxCommandEvent& event )
389 playlist_t *p_playlist =
390 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
392 if( p_playlist == NULL )
397 if( p_file_dialog == NULL )
398 p_file_dialog = new wxFileDialog( NULL, wxU(_("Open File")),
399 wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
401 if( p_file_dialog && p_file_dialog->ShowModal() == wxID_OK )
405 p_file_dialog->GetPaths( paths );
407 for( size_t i = 0; i < paths.GetCount(); i++ )
409 char *psz_utf8 = wxFromLocale( paths[i] );
411 playlist_Add( p_playlist, psz_utf8, psz_utf8,
412 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO),
415 playlist_Add( p_playlist, psz_utf8, psz_utf8,
416 PLAYLIST_APPEND, PLAYLIST_END );
417 wxLocaleFree( psz_utf8 );
421 vlc_object_release( p_playlist );
424 void DialogsProvider::OnOpenDirectory( wxCommandEvent& event )
426 playlist_t *p_playlist =
427 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
429 if( p_playlist == NULL )
434 if( p_dir_dialog == NULL )
435 p_dir_dialog = new wxDirDialog( NULL );
437 if( p_dir_dialog && p_dir_dialog->ShowModal() == wxID_OK )
439 wxString path = p_dir_dialog->GetPath();
440 char *psz_utf8 = wxFromLocale( path );
441 playlist_Add( p_playlist, psz_utf8, psz_utf8,
442 PLAYLIST_APPEND | (event.GetInt() ? PLAYLIST_GO : 0),
444 wxLocaleFree( psz_utf8 );
447 vlc_object_release( p_playlist );
450 void DialogsProvider::OnOpenFile( wxCommandEvent& event )
452 Open( FILE_ACCESS, event.GetInt() );
455 void DialogsProvider::OnOpenDisc( wxCommandEvent& event )
457 Open( DISC_ACCESS, event.GetInt() );
460 void DialogsProvider::OnOpenNet( wxCommandEvent& event )
462 Open( NET_ACCESS, event.GetInt() );
465 void DialogsProvider::OnOpenCapture( wxCommandEvent& event )
467 Open( CAPTURE_ACCESS, event.GetInt() );
470 void DialogsProvider::Open( int i_access_method, int i_arg )
472 /* Show/hide the open dialog */
474 p_open_dialog = new OpenDialog( p_intf, this, i_access_method, i_arg,
479 p_open_dialog->Show( i_access_method, i_arg );
483 void DialogsProvider::OnPopupMenu( wxCommandEvent& event )
485 wxPoint mousepos = ScreenToClient( wxGetMousePosition() );
486 ::PopupMenu( p_intf, this, mousepos );
489 void DialogsProvider::OnExitThread( wxCommandEvent& WXUNUSED(event) )
491 wxTheApp->ExitMainLoop();
494 void DialogsProvider::OnUpdateVLC( wxCommandEvent& WXUNUSED(event) )
496 /* Show/hide the file info window */
497 if( !p_updatevlc_dialog )
498 p_updatevlc_dialog = new UpdateVLC( p_intf, this );
500 if( p_updatevlc_dialog )
502 p_updatevlc_dialog->Show( !p_updatevlc_dialog->IsShown() );