1 /*****************************************************************************
2 * dialogs.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2004 VideoLAN
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() */
36 #include "wxwindows.h"
38 /* include the icon graphic */
39 #include "../../../share/vlc32x32.xpm"
41 /* Dialogs Provider */
42 class DialogsProvider: public wxFrame
46 DialogsProvider( intf_thread_t *p_intf, wxWindow *p_parent );
47 virtual ~DialogsProvider();
50 void Open( int i_access_method, int i_arg );
52 /* Event handlers (these functions should _not_ be virtual) */
53 void OnExit( wxCommandEvent& event );
54 void OnPlaylist( wxCommandEvent& event );
55 void OnMessages( wxCommandEvent& event );
56 void OnFileInfo( wxCommandEvent& event );
57 void OnPreferences( wxCommandEvent& event );
58 void OnWizardDialog( wxCommandEvent& event );
59 void OnBookmarks( wxCommandEvent& event );
61 void OnOpenFileGeneric( wxCommandEvent& event );
62 void OnOpenFileSimple( wxCommandEvent& event );
63 void OnOpenDirectory( wxCommandEvent& event );
64 void OnOpenFile( wxCommandEvent& event );
65 void OnOpenDisc( wxCommandEvent& event );
66 void OnOpenNet( wxCommandEvent& event );
67 void OnOpenCapture( wxCommandEvent& event );
68 void OnOpenSat( wxCommandEvent& event );
70 void OnPopupMenu( wxCommandEvent& event );
72 void OnIdle( wxIdleEvent& event );
74 void OnExitThread( wxCommandEvent& event );
76 DECLARE_EVENT_TABLE();
78 intf_thread_t *p_intf;
81 /* Secondary windows */
82 OpenDialog *p_open_dialog;
83 wxFileDialog *p_file_dialog;
84 wxDirDialog *p_dir_dialog;
85 Playlist *p_playlist_dialog;
86 Messages *p_messages_dialog;
87 FileInfo *p_fileinfo_dialog;
88 WizardDialog *p_wizard_dialog;
89 wxFrame *p_prefs_dialog;
90 wxWindow *p_bookmarks_dialog;
91 wxFileDialog *p_file_generic_dialog;
94 DEFINE_LOCAL_EVENT_TYPE( wxEVT_DIALOG );
96 BEGIN_EVENT_TABLE(DialogsProvider, wxFrame)
97 /* Idle loop used to update some of the dialogs */
98 EVT_IDLE(DialogsProvider::OnIdle)
100 /* Custom wxDialog events */
101 EVT_COMMAND(INTF_DIALOG_FILE, wxEVT_DIALOG, DialogsProvider::OnOpenFile)
102 EVT_COMMAND(INTF_DIALOG_DISC, wxEVT_DIALOG, DialogsProvider::OnOpenDisc)
103 EVT_COMMAND(INTF_DIALOG_NET, wxEVT_DIALOG, DialogsProvider::OnOpenNet)
104 EVT_COMMAND(INTF_DIALOG_CAPTURE, wxEVT_DIALOG,
105 DialogsProvider::OnOpenCapture)
106 EVT_COMMAND(INTF_DIALOG_FILE_SIMPLE, wxEVT_DIALOG,
107 DialogsProvider::OnOpenFileSimple)
108 EVT_COMMAND(INTF_DIALOG_FILE_GENERIC, wxEVT_DIALOG,
109 DialogsProvider::OnOpenFileGeneric)
110 EVT_COMMAND(INTF_DIALOG_DIRECTORY, wxEVT_DIALOG,
111 DialogsProvider::OnOpenDirectory)
113 EVT_COMMAND(INTF_DIALOG_PLAYLIST, wxEVT_DIALOG,
114 DialogsProvider::OnPlaylist)
115 EVT_COMMAND(INTF_DIALOG_MESSAGES, wxEVT_DIALOG,
116 DialogsProvider::OnMessages)
117 EVT_COMMAND(INTF_DIALOG_PREFS, wxEVT_DIALOG,
118 DialogsProvider::OnPreferences)
119 EVT_COMMAND(INTF_DIALOG_WIZARD, wxEVT_DIALOG,
120 DialogsProvider::OnWizardDialog)
121 EVT_COMMAND(INTF_DIALOG_FILEINFO, wxEVT_DIALOG,
122 DialogsProvider::OnFileInfo)
123 EVT_COMMAND(INTF_DIALOG_BOOKMARKS, wxEVT_DIALOG,
124 DialogsProvider::OnBookmarks)
125 EVT_COMMAND(INTF_DIALOG_POPUPMENU, wxEVT_DIALOG,
126 DialogsProvider::OnPopupMenu)
127 EVT_COMMAND(INTF_DIALOG_EXIT, wxEVT_DIALOG,
128 DialogsProvider::OnExitThread)
131 wxWindow *CreateDialogsProvider( intf_thread_t *p_intf, wxWindow *p_parent )
133 return new DialogsProvider( p_intf, p_parent );
136 /*****************************************************************************
138 *****************************************************************************/
139 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf, wxWindow *p_parent )
140 : wxFrame( p_parent, -1, wxT("") )
142 /* Initializations */
144 p_open_dialog = NULL;
145 p_file_dialog = NULL;
146 p_playlist_dialog = NULL;
147 p_messages_dialog = NULL;
148 p_fileinfo_dialog = NULL;
149 p_prefs_dialog = NULL;
150 p_file_generic_dialog = NULL;
151 p_wizard_dialog = NULL;
152 p_bookmarks_dialog = NULL;
154 /* Give our interface a nice little icon */
155 p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
157 /* Create the messages dialog so it can begin storing logs */
158 p_messages_dialog = new Messages( p_intf, p_parent ? p_parent : this );
160 /* Check if user wants to show the bookmarks dialog by default */
161 wxCommandEvent dummy_event;
162 if( config_GetInt( p_intf, "wxwin-bookmarks" ) )
163 OnBookmarks( dummy_event );
165 /* Intercept all menu events in our custom event handler */
166 PushEventHandler( new MenuEvtHandler( p_intf, NULL ) );
169 DialogsProvider::~DialogsProvider()
172 if( p_open_dialog ) delete p_open_dialog;
173 if( p_prefs_dialog ) p_prefs_dialog->Destroy();
174 if( p_file_dialog ) delete p_file_dialog;
175 if( p_playlist_dialog ) delete p_playlist_dialog;
176 if( p_messages_dialog ) delete p_messages_dialog;
177 if( p_fileinfo_dialog ) delete p_fileinfo_dialog;
178 if( p_file_generic_dialog ) delete p_file_generic_dialog;
179 if( p_wizard_dialog ) delete p_wizard_dialog;
180 if( p_bookmarks_dialog ) delete p_bookmarks_dialog;
183 if( p_intf->p_sys->p_icon ) delete p_intf->p_sys->p_icon;
185 /* We must set this here because on win32 this destructor will be
186 * automatically called so we must not call it again on wxApp->OnExit().
187 * There shouldn't be any race conditions as all this should be done
188 * from the same thread. */
189 p_intf->p_sys->p_wxwindow = NULL;
192 void DialogsProvider::OnIdle( wxIdleEvent& WXUNUSED(event) )
194 /* Update the log window */
195 if( p_messages_dialog )
196 // p_messages_dialog->UpdateLog();
198 /* Update the playlist */
199 if( p_playlist_dialog )
200 p_playlist_dialog->UpdatePlaylist();
202 /* Update the fileinfo windows */
203 if( p_fileinfo_dialog )
204 p_fileinfo_dialog->UpdateFileInfo();
207 void DialogsProvider::OnPlaylist( wxCommandEvent& WXUNUSED(event) )
209 /* Show/hide the playlist window */
210 if( !p_playlist_dialog )
211 p_playlist_dialog = new Playlist( p_intf, this );
213 if( p_playlist_dialog )
215 p_playlist_dialog->ShowPlaylist( !p_playlist_dialog->IsShown() );
219 void DialogsProvider::OnMessages( wxCommandEvent& WXUNUSED(event) )
221 /* Show/hide the log window */
222 if( !p_messages_dialog )
223 p_messages_dialog = new Messages( p_intf, this );
225 if( p_messages_dialog )
227 p_messages_dialog->Show( !p_messages_dialog->IsShown() );
231 void DialogsProvider::OnFileInfo( wxCommandEvent& WXUNUSED(event) )
233 /* Show/hide the file info window */
234 if( !p_fileinfo_dialog )
235 p_fileinfo_dialog = new FileInfo( p_intf, this );
237 if( p_fileinfo_dialog )
239 p_fileinfo_dialog->Show( !p_fileinfo_dialog->IsShown() );
243 void DialogsProvider::OnPreferences( wxCommandEvent& WXUNUSED(event) )
245 /* Show/hide the open dialog */
246 if( !p_prefs_dialog )
247 p_prefs_dialog = new PrefsDialog( p_intf, this );
251 p_prefs_dialog->Show( !p_prefs_dialog->IsShown() );
255 void DialogsProvider::OnWizardDialog( wxCommandEvent& WXUNUSED(event) )
257 p_wizard_dialog = new WizardDialog( p_intf, this, NULL, 0, 0 );
259 if( p_wizard_dialog )
261 p_wizard_dialog->Run();
262 delete p_wizard_dialog;
265 p_wizard_dialog = NULL;
268 void DialogsProvider::OnBookmarks( wxCommandEvent& WXUNUSED(event) )
270 /* Show/hide the open dialog */
271 if( !p_bookmarks_dialog )
272 p_bookmarks_dialog = BookmarksDialog( p_intf, this );
274 if( p_bookmarks_dialog )
276 p_bookmarks_dialog->Show( !p_bookmarks_dialog->IsShown() );
280 void DialogsProvider::OnOpenFileGeneric( wxCommandEvent& event )
282 intf_dialog_args_t *p_arg = (intf_dialog_args_t *)event.GetClientData();
286 msg_Dbg( p_intf, "OnOpenFileGeneric() called with NULL arg" );
290 if( p_file_generic_dialog == NULL )
291 p_file_generic_dialog = new wxFileDialog( NULL );
293 if( p_file_generic_dialog )
295 p_file_generic_dialog->SetMessage( wxU(p_arg->psz_title) );
296 p_file_generic_dialog->SetWildcard( wxU(p_arg->psz_extensions) );
297 p_file_generic_dialog->SetStyle( (p_arg->b_save ? wxSAVE : wxOPEN) |
298 (p_arg->b_multiple ? wxMULTIPLE:0) );
301 if( p_file_generic_dialog &&
302 p_file_generic_dialog->ShowModal() == wxID_OK )
306 p_file_generic_dialog->GetPaths( paths );
308 p_arg->i_results = paths.GetCount();
309 p_arg->psz_results = (char **)malloc( p_arg->i_results *
311 for( size_t i = 0; i < paths.GetCount(); i++ )
313 p_arg->psz_results[i] = strdup( paths[i].mb_str() );
318 if( p_arg->pf_callback )
320 p_arg->pf_callback( p_arg );
323 if( p_arg->psz_results )
325 for( int i = 0; i < p_arg->i_results; i++ )
327 free( p_arg->psz_results[i] );
329 free( p_arg->psz_results );
331 if( p_arg->psz_title ) free( p_arg->psz_title );
332 if( p_arg->psz_extensions ) free( p_arg->psz_extensions );
337 void DialogsProvider::OnOpenFileSimple( wxCommandEvent& event )
339 playlist_t *p_playlist =
340 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
342 if( p_playlist == NULL )
347 if( p_file_dialog == NULL )
348 p_file_dialog = new wxFileDialog( NULL, wxU(_("Open File")),
349 wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
351 if( p_file_dialog && p_file_dialog->ShowModal() == wxID_OK )
355 p_file_dialog->GetPaths( paths );
357 for( size_t i = 0; i < paths.GetCount(); i++ )
359 playlist_Add( p_playlist, (const char *)paths[i].mb_str(),
360 (const char *)paths[i].mb_str(),
361 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO),
364 playlist_Add( p_playlist, (const char *)paths[i].mb_str(),
365 (const char *)paths[i].mb_str(),
366 PLAYLIST_APPEND, PLAYLIST_END );
369 vlc_object_release( p_playlist );
372 void DialogsProvider::OnOpenDirectory( wxCommandEvent& event )
374 playlist_t *p_playlist =
375 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
377 if( p_playlist == NULL )
382 if( p_dir_dialog == NULL )
383 p_dir_dialog = new wxDirDialog( NULL );
385 if( p_dir_dialog && p_dir_dialog->ShowModal() == wxID_OK )
387 playlist_item_t *p_item;
388 wxString path = p_dir_dialog->GetPath();
390 int i_id = playlist_Add( p_playlist, (const char *)path.mb_str(),
391 (const char *)path.mb_str(),
392 PLAYLIST_APPEND, PLAYLIST_END );
393 p_item = playlist_ItemGetById( p_playlist, i_id );
396 input_CreateThread( p_intf, &p_item->input );
400 vlc_object_release( p_playlist );
403 void DialogsProvider::OnOpenFile( wxCommandEvent& event )
405 Open( FILE_ACCESS, event.GetInt() );
408 void DialogsProvider::OnOpenDisc( wxCommandEvent& event )
410 Open( DISC_ACCESS, event.GetInt() );
413 void DialogsProvider::OnOpenNet( wxCommandEvent& event )
415 Open( NET_ACCESS, event.GetInt() );
418 void DialogsProvider::OnOpenCapture( wxCommandEvent& event )
420 Open( CAPTURE_ACCESS, event.GetInt() );
423 void DialogsProvider::Open( int i_access_method, int i_arg )
425 /* Show/hide the open dialog */
427 p_open_dialog = new OpenDialog( p_intf, this, i_access_method, i_arg,
432 p_open_dialog->Show( i_access_method, i_arg );
436 void DialogsProvider::OnPopupMenu( wxCommandEvent& event )
438 wxPoint mousepos = ScreenToClient( wxGetMousePosition() );
439 ::PopupMenu( p_intf, this, mousepos );
442 void DialogsProvider::OnExitThread( wxCommandEvent& WXUNUSED(event) )
444 wxTheApp->ExitMainLoop();