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() */
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 "interface.hpp"
50 /* include the icon graphic */
51 #include "../../../share/vlc32x32.xpm"
53 /* Dialogs Provider */
54 class DialogsProvider: public wxFrame
58 DialogsProvider( intf_thread_t *p_intf, wxWindow *p_parent );
59 virtual ~DialogsProvider();
62 void Open( int i_access_method, int i_arg );
64 /* Event handlers (these functions should _not_ be virtual) */
65 void OnUpdateVLC( wxCommandEvent& event );
66 void OnVLM( wxCommandEvent& event );
67 void OnExit( wxCommandEvent& event );
68 void OnPlaylist( wxCommandEvent& event );
69 void OnMessages( wxCommandEvent& event );
70 void OnFileInfo( wxCommandEvent& event );
71 void OnPreferences( wxCommandEvent& event );
72 void OnWizardDialog( wxCommandEvent& event );
73 void OnBookmarks( wxCommandEvent& event );
75 void OnOpenFileGeneric( wxCommandEvent& event );
76 void OnOpenFileSimple( wxCommandEvent& event );
77 void OnOpenDirectory( wxCommandEvent& event );
78 void OnOpenFile( wxCommandEvent& event );
79 void OnOpenDisc( wxCommandEvent& event );
80 void OnOpenNet( wxCommandEvent& event );
81 void OnOpenCapture( wxCommandEvent& event );
82 void OnOpenSat( wxCommandEvent& event );
84 void OnPopupMenu( wxCommandEvent& event );
86 void OnIdle( wxIdleEvent& event );
88 void OnExitThread( wxCommandEvent& event );
90 DECLARE_EVENT_TABLE();
92 intf_thread_t *p_intf;
95 /* Secondary windows */
96 OpenDialog *p_open_dialog;
97 wxFileDialog *p_file_dialog;
98 wxDirDialog *p_dir_dialog;
99 Playlist *p_playlist_dialog;
100 Messages *p_messages_dialog;
101 FileInfo *p_fileinfo_dialog;
102 WizardDialog *p_wizard_dialog;
103 wxFrame *p_prefs_dialog;
104 wxFrame *p_bookmarks_dialog;
105 wxFileDialog *p_file_generic_dialog;
106 UpdateVLC *p_updatevlc_dialog;
107 VLMFrame *p_vlm_dialog;
110 DEFINE_LOCAL_EVENT_TYPE( wxEVT_DIALOG );
112 BEGIN_EVENT_TABLE(DialogsProvider, wxFrame)
113 /* Idle loop used to update some of the dialogs */
114 EVT_IDLE(DialogsProvider::OnIdle)
116 /* Custom wxDialog events */
117 EVT_COMMAND(INTF_DIALOG_FILE, wxEVT_DIALOG, DialogsProvider::OnOpenFile)
118 EVT_COMMAND(INTF_DIALOG_DISC, wxEVT_DIALOG, DialogsProvider::OnOpenDisc)
119 EVT_COMMAND(INTF_DIALOG_NET, wxEVT_DIALOG, DialogsProvider::OnOpenNet)
120 EVT_COMMAND(INTF_DIALOG_CAPTURE, wxEVT_DIALOG,
121 DialogsProvider::OnOpenCapture)
122 EVT_COMMAND(INTF_DIALOG_FILE_SIMPLE, wxEVT_DIALOG,
123 DialogsProvider::OnOpenFileSimple)
124 EVT_COMMAND(INTF_DIALOG_FILE_GENERIC, wxEVT_DIALOG,
125 DialogsProvider::OnOpenFileGeneric)
126 EVT_COMMAND(INTF_DIALOG_DIRECTORY, wxEVT_DIALOG,
127 DialogsProvider::OnOpenDirectory)
129 EVT_COMMAND(INTF_DIALOG_PLAYLIST, wxEVT_DIALOG,
130 DialogsProvider::OnPlaylist)
131 EVT_COMMAND(INTF_DIALOG_MESSAGES, wxEVT_DIALOG,
132 DialogsProvider::OnMessages)
133 EVT_COMMAND(INTF_DIALOG_PREFS, wxEVT_DIALOG,
134 DialogsProvider::OnPreferences)
135 EVT_COMMAND(INTF_DIALOG_WIZARD, wxEVT_DIALOG,
136 DialogsProvider::OnWizardDialog)
137 EVT_COMMAND(INTF_DIALOG_FILEINFO, wxEVT_DIALOG,
138 DialogsProvider::OnFileInfo)
139 EVT_COMMAND(INTF_DIALOG_BOOKMARKS, wxEVT_DIALOG,
140 DialogsProvider::OnBookmarks)
141 EVT_COMMAND(INTF_DIALOG_POPUPMENU, wxEVT_DIALOG,
142 DialogsProvider::OnPopupMenu)
143 EVT_COMMAND(INTF_DIALOG_EXIT, wxEVT_DIALOG,
144 DialogsProvider::OnExitThread)
145 EVT_COMMAND(INTF_DIALOG_UPDATEVLC, wxEVT_DIALOG,
146 DialogsProvider::OnUpdateVLC)
147 EVT_COMMAND(INTF_DIALOG_VLM, wxEVT_DIALOG,
148 DialogsProvider::OnVLM)
151 wxWindow *CreateDialogsProvider( intf_thread_t *p_intf, wxWindow *p_parent )
153 return new DialogsProvider( p_intf, p_parent );
156 /*****************************************************************************
158 *****************************************************************************/
159 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf, wxWindow *p_parent )
160 : wxFrame( p_parent, -1, wxT("") )
162 /* Initializations */
164 p_open_dialog = NULL;
165 p_file_dialog = NULL;
166 p_playlist_dialog = NULL;
167 p_messages_dialog = NULL;
168 p_fileinfo_dialog = NULL;
169 p_prefs_dialog = NULL;
170 p_file_generic_dialog = NULL;
171 p_wizard_dialog = NULL;
172 p_bookmarks_dialog = NULL;
174 p_updatevlc_dialog = NULL;
177 /* Give our interface a nice little icon */
178 p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
180 /* Create the messages dialog so it can begin storing logs */
181 p_messages_dialog = new Messages( p_intf, p_parent ? p_parent : this );
183 /* Check if user wants to show the bookmarks dialog by default */
184 wxCommandEvent dummy_event;
185 if( config_GetInt( p_intf, "wx-bookmarks" ) )
186 OnBookmarks( dummy_event );
188 /* Intercept all menu events in our custom event handler */
189 PushEventHandler( new MenuEvtHandler( p_intf, NULL ) );
192 WindowSettings *ws = p_intf->p_sys->p_window_settings;
197 #define INIT( id, w, N, S ) \
198 if( ws->GetSettings( WindowSettings::id, b_shown, p, s ) && b_shown ) \
207 INIT( ID_PLAYLIST, p_playlist_dialog, new Playlist(p_intf,this), ShowPlaylist );
208 INIT( ID_MESSAGES, p_messages_dialog, new Messages(p_intf,this), Show );
209 INIT( ID_FILE_INFO, p_fileinfo_dialog, new FileInfo(p_intf,this), Show );
210 INIT( ID_BOOKMARKS, p_bookmarks_dialog, new BookmarksDialog(p_intf,this), Show);
214 DialogsProvider::~DialogsProvider()
216 WindowSettings *ws = p_intf->p_sys->p_window_settings;
218 #define UPDATE(id,w) \
220 if( w && w->IsShown() && !w->IsIconized() ) \
221 ws->SetSettings( WindowSettings::id, true, \
222 w->GetPosition(), w->GetSize() ); \
224 ws->SetSettings( WindowSettings::id, false ); \
227 UPDATE( ID_PLAYLIST, p_playlist_dialog );
228 UPDATE( ID_MESSAGES, p_messages_dialog );
229 UPDATE( ID_FILE_INFO, p_fileinfo_dialog );
230 UPDATE( ID_BOOKMARKS, p_bookmarks_dialog );
234 PopEventHandler(true);
237 if( p_open_dialog ) delete p_open_dialog;
238 if( p_prefs_dialog ) p_prefs_dialog->Destroy();
239 if( p_file_dialog ) delete p_file_dialog;
240 if( p_playlist_dialog ) delete p_playlist_dialog;
241 if( p_messages_dialog ) delete p_messages_dialog;
242 if( p_fileinfo_dialog ) delete p_fileinfo_dialog;
243 if( p_file_generic_dialog ) delete p_file_generic_dialog;
244 if( p_wizard_dialog ) delete p_wizard_dialog;
245 if( p_bookmarks_dialog ) delete p_bookmarks_dialog;
246 if( p_updatevlc_dialog ) delete p_updatevlc_dialog;
247 if( p_vlm_dialog ) delete p_vlm_dialog;
250 if( p_intf->p_sys->p_icon ) delete p_intf->p_sys->p_icon;
252 /* We must set this here because on win32 this destructor will be
253 * automatically called so we must not call it again on wxApp->OnExit().
254 * There shouldn't be any race conditions as all this should be done
255 * from the same thread. */
256 p_intf->p_sys->p_wxwindow = NULL;
259 void DialogsProvider::OnIdle( wxIdleEvent& WXUNUSED(event) )
261 /* Update the log window */
262 if( p_messages_dialog )
263 p_messages_dialog->UpdateLog();
265 /* Update the playlist */
266 if( p_playlist_dialog )
267 p_playlist_dialog->UpdatePlaylist();
269 /* Update the fileinfo windows */
270 if( p_fileinfo_dialog )
271 p_fileinfo_dialog->UpdateFileInfo();
274 void DialogsProvider::OnPlaylist( wxCommandEvent& WXUNUSED(event) )
276 /* Show/hide the playlist window */
277 if( !p_playlist_dialog )
278 p_playlist_dialog = new Playlist( p_intf, this );
280 if( p_playlist_dialog )
282 p_playlist_dialog->ShowPlaylist( !p_playlist_dialog->IsShown() );
286 void DialogsProvider::OnMessages( wxCommandEvent& WXUNUSED(event) )
288 /* Show/hide the log window */
289 if( !p_messages_dialog )
290 p_messages_dialog = new Messages( p_intf, this );
292 if( p_messages_dialog )
294 p_messages_dialog->Show( !p_messages_dialog->IsShown() );
298 void DialogsProvider::OnFileInfo( wxCommandEvent& WXUNUSED(event) )
300 /* Show/hide the file info window */
301 if( !p_fileinfo_dialog )
302 p_fileinfo_dialog = new FileInfo( p_intf, this );
304 if( p_fileinfo_dialog )
306 p_fileinfo_dialog->Show( !p_fileinfo_dialog->IsShown() );
310 void DialogsProvider::OnPreferences( wxCommandEvent& WXUNUSED(event) )
312 /* Show/hide the open dialog */
313 if( !p_prefs_dialog )
314 p_prefs_dialog = new PrefsDialog( p_intf, this );
318 p_prefs_dialog->Show( !p_prefs_dialog->IsShown() );
322 void DialogsProvider::OnWizardDialog( wxCommandEvent& WXUNUSED(event) )
324 p_wizard_dialog = new WizardDialog( p_intf, this, NULL, 0, 0 );
326 if( p_wizard_dialog )
328 p_wizard_dialog->Run();
329 delete p_wizard_dialog;
332 p_wizard_dialog = NULL;
335 void DialogsProvider::OnBookmarks( wxCommandEvent& WXUNUSED(event) )
337 /* Show/hide the open dialog */
338 if( !p_bookmarks_dialog )
339 p_bookmarks_dialog = new BookmarksDialog( p_intf, this );
341 if( p_bookmarks_dialog )
343 p_bookmarks_dialog->Show( !p_bookmarks_dialog->IsShown() );
347 void DialogsProvider::OnOpenFileGeneric( wxCommandEvent& event )
349 intf_dialog_args_t *p_arg = (intf_dialog_args_t *)event.GetClientData();
353 msg_Dbg( p_intf, "OnOpenFileGeneric() called with NULL arg" );
357 if( p_file_generic_dialog == NULL )
358 p_file_generic_dialog = new wxFileDialog( NULL );
360 if( p_file_generic_dialog )
362 p_file_generic_dialog->SetMessage( wxU(p_arg->psz_title) );
363 p_file_generic_dialog->SetWildcard( wxU(p_arg->psz_extensions) );
364 p_file_generic_dialog->SetStyle( (p_arg->b_save ? wxSAVE : wxOPEN) |
365 (p_arg->b_multiple ? wxMULTIPLE:0) );
368 if( p_file_generic_dialog &&
369 p_file_generic_dialog->ShowModal() == wxID_OK )
373 p_file_generic_dialog->GetPaths( paths );
375 p_arg->i_results = paths.GetCount();
376 p_arg->psz_results = (char **)malloc( p_arg->i_results *
378 for( size_t i = 0; i < paths.GetCount(); i++ )
380 p_arg->psz_results[i] = strdup( paths[i].mb_str() );
385 if( p_arg->pf_callback )
387 p_arg->pf_callback( p_arg );
390 if( p_arg->psz_results )
392 for( int i = 0; i < p_arg->i_results; i++ )
394 free( p_arg->psz_results[i] );
396 free( p_arg->psz_results );
398 if( p_arg->psz_title ) free( p_arg->psz_title );
399 if( p_arg->psz_extensions ) free( p_arg->psz_extensions );
404 void DialogsProvider::OnOpenFileSimple( wxCommandEvent& event )
406 playlist_t *p_playlist =
407 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
409 if( p_playlist == NULL )
414 if( p_file_dialog == NULL )
415 p_file_dialog = new wxFileDialog( NULL, wxU(_("Open File")),
416 wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
418 if( p_file_dialog && p_file_dialog->ShowModal() == wxID_OK )
422 p_file_dialog->GetPaths( paths );
424 for( size_t i = 0; i < paths.GetCount(); i++ )
426 char *psz_utf8 = wxFromLocale( paths[i] );
428 playlist_Add( p_playlist, psz_utf8, psz_utf8,
429 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO),
432 playlist_Add( p_playlist, psz_utf8, psz_utf8,
433 PLAYLIST_APPEND, PLAYLIST_END );
434 wxLocaleFree( psz_utf8 );
438 vlc_object_release( p_playlist );
441 void DialogsProvider::OnOpenDirectory( wxCommandEvent& event )
443 playlist_t *p_playlist =
444 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
446 if( p_playlist == NULL )
451 if( p_dir_dialog == NULL )
452 p_dir_dialog = new wxDirDialog( NULL );
454 if( p_dir_dialog && p_dir_dialog->ShowModal() == wxID_OK )
456 wxString path = p_dir_dialog->GetPath();
457 char *psz_utf8 = wxFromLocale( path );
458 playlist_Add( p_playlist, psz_utf8, psz_utf8,
459 PLAYLIST_APPEND | (event.GetInt() ? PLAYLIST_GO : 0),
461 wxLocaleFree( psz_utf8 );
464 vlc_object_release( p_playlist );
467 void DialogsProvider::OnOpenFile( wxCommandEvent& event )
469 Open( FILE_ACCESS, event.GetInt() );
472 void DialogsProvider::OnOpenDisc( wxCommandEvent& event )
474 Open( DISC_ACCESS, event.GetInt() );
477 void DialogsProvider::OnOpenNet( wxCommandEvent& event )
479 Open( NET_ACCESS, event.GetInt() );
482 void DialogsProvider::OnOpenCapture( wxCommandEvent& event )
484 Open( CAPTURE_ACCESS, event.GetInt() );
487 void DialogsProvider::Open( int i_access_method, int i_arg )
489 /* Show/hide the open dialog */
491 p_open_dialog = new OpenDialog( p_intf, this, i_access_method, i_arg,
496 p_open_dialog->Show( i_access_method, i_arg );
500 void DialogsProvider::OnPopupMenu( wxCommandEvent& event )
502 wxPoint mousepos = ScreenToClient( wxGetMousePosition() );
503 ::PopupMenu( p_intf, this, mousepos );
506 void DialogsProvider::OnExitThread( wxCommandEvent& WXUNUSED(event) )
508 wxTheApp->ExitMainLoop();
511 void DialogsProvider::OnUpdateVLC( wxCommandEvent& WXUNUSED(event) )
513 /* Show/hide the file info window */
514 if( !p_updatevlc_dialog )
515 p_updatevlc_dialog = new UpdateVLC( p_intf, this );
517 if( p_updatevlc_dialog )
519 p_updatevlc_dialog->Show( !p_updatevlc_dialog->IsShown() );
523 void DialogsProvider::OnVLM( wxCommandEvent& WXUNUSED(event) )
525 /* Show/hide the file info window */
527 p_vlm_dialog = new VLMFrame( p_intf, this );
531 p_vlm_dialog->Show( !p_vlm_dialog->IsShown() );