1
/*****************************************************************************
2
* dialogs.cpp : wxWindows plugin for vlc
3
*****************************************************************************
4
* Copyright (C) 2000-2004 VideoLAN
5
* $Id: dialogs.cpp 7555 2004-04-29 18:27:08Z zorglub $
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() */
35
#include "stream_control.h"
37
#include "wxwindows.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 OnExit( wxCommandEvent& event );
55
void OnPlaylist( wxCommandEvent& event );
56
void OnMessages( wxCommandEvent& event );
57
void OnFileInfo( wxCommandEvent& event );
58
void OnPreferences( wxCommandEvent& event );
59
void OnStreamWizardDialog( wxCommandEvent& event );
60
void OnWizardDialog( wxCommandEvent& event );
61
void OnBookmarks( wxCommandEvent& event );
63
void OnOpenFileGeneric( wxCommandEvent& event );
64
void OnOpenFileSimple( wxCommandEvent& event );
65
void OnOpenFile( wxCommandEvent& event );
66
void OnOpenDisc( wxCommandEvent& event );
67
void OnOpenNet( wxCommandEvent& event );
68
void OnOpenCapture( wxCommandEvent& event );
69
void OnOpenSat( wxCommandEvent& event );
71
void OnPopupMenu( wxCommandEvent& event );
73
void OnIdle( wxIdleEvent& event );
75
void OnExitThread( wxCommandEvent& event );
77
DECLARE_EVENT_TABLE();
79
intf_thread_t *p_intf;
82
/* Secondary windows */
83
OpenDialog *p_open_dialog;
84
wxFileDialog *p_file_dialog;
85
Playlist *p_playlist_dialog;
86
Messages *p_messages_dialog;
87
FileInfo *p_fileinfo_dialog;
88
StreamDialog *p_streamwizard_dialog;
89
WizardDialog *p_wizard_dialog;
90
wxFrame *p_prefs_dialog;
91
wxWindow *p_bookmarks_dialog;
92
wxFileDialog *p_file_generic_dialog;
95
DEFINE_LOCAL_EVENT_TYPE( wxEVT_DIALOG );
97
BEGIN_EVENT_TABLE(DialogsProvider, wxFrame)
98
/* Idle loop used to update some of the dialogs */
99
EVT_IDLE(DialogsProvider::OnIdle)
101
/* Custom wxDialog events */
102
EVT_COMMAND(INTF_DIALOG_FILE, wxEVT_DIALOG, DialogsProvider::OnOpenFile)
103
EVT_COMMAND(INTF_DIALOG_DISC, wxEVT_DIALOG, DialogsProvider::OnOpenDisc)
104
EVT_COMMAND(INTF_DIALOG_NET, wxEVT_DIALOG, DialogsProvider::OnOpenNet)
105
EVT_COMMAND(INTF_DIALOG_CAPTURE, wxEVT_DIALOG,
106
DialogsProvider::OnOpenCapture)
107
EVT_COMMAND(INTF_DIALOG_FILE_SIMPLE, wxEVT_DIALOG,
108
DialogsProvider::OnOpenFileSimple)
109
EVT_COMMAND(INTF_DIALOG_FILE_GENERIC, wxEVT_DIALOG,
110
DialogsProvider::OnOpenFileGeneric)
112
EVT_COMMAND(INTF_DIALOG_PLAYLIST, wxEVT_DIALOG,
113
DialogsProvider::OnPlaylist)
114
EVT_COMMAND(INTF_DIALOG_MESSAGES, wxEVT_DIALOG,
115
DialogsProvider::OnMessages)
116
EVT_COMMAND(INTF_DIALOG_PREFS, wxEVT_DIALOG,
117
DialogsProvider::OnPreferences)
118
EVT_COMMAND(INTF_DIALOG_STREAMWIZARD, wxEVT_DIALOG,
119
DialogsProvider::OnStreamWizardDialog)
120
EVT_COMMAND(INTF_DIALOG_WIZARD, wxEVT_DIALOG,
121
DialogsProvider::OnWizardDialog)
122
EVT_COMMAND(INTF_DIALOG_FILEINFO, wxEVT_DIALOG,
123
DialogsProvider::OnFileInfo)
124
EVT_COMMAND(INTF_DIALOG_BOOKMARKS, wxEVT_DIALOG,
125
DialogsProvider::OnBookmarks)
126
EVT_COMMAND(INTF_DIALOG_POPUPMENU, wxEVT_DIALOG,
127
DialogsProvider::OnPopupMenu)
128
EVT_COMMAND(INTF_DIALOG_EXIT, wxEVT_DIALOG,
129
DialogsProvider::OnExitThread)
132
wxWindow *CreateDialogsProvider( intf_thread_t *p_intf, wxWindow *p_parent )
134
return new DialogsProvider( p_intf, p_parent );
137
/*****************************************************************************
139
*****************************************************************************/
140
DialogsProvider::DialogsProvider( intf_thread_t *_p_intf, wxWindow *p_parent )
141
: wxFrame( p_parent, -1, wxT("") )
143
/* Initializations */
145
p_open_dialog = NULL;
146
p_file_dialog = NULL;
147
p_playlist_dialog = NULL;
148
p_messages_dialog = NULL;
149
p_fileinfo_dialog = NULL;
150
p_prefs_dialog = NULL;
151
p_file_generic_dialog = NULL;
152
p_streamwizard_dialog = NULL;
153
p_wizard_dialog = NULL;
154
p_bookmarks_dialog = NULL;
156
/* Give our interface a nice little icon */
157
p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
159
/* Create the messages dialog so it can begin storing logs */
160
p_messages_dialog = new Messages( p_intf, p_parent ? p_parent : this );
162
/* Check if user wants to show the bookmarks dialog by default */
163
wxCommandEvent dummy_event;
164
if( config_GetInt( p_intf, "wxwin-bookmarks" ) )
165
OnBookmarks( dummy_event );
167
/* Intercept all menu events in our custom event handler */
168
PushEventHandler( new MenuEvtHandler( p_intf, NULL ) );
171
DialogsProvider::~DialogsProvider()
174
if( p_open_dialog ) delete p_open_dialog;
175
if( p_prefs_dialog ) p_prefs_dialog->Destroy();
176
if( p_file_dialog ) delete p_file_dialog;
177
if( p_playlist_dialog ) delete p_playlist_dialog;
178
if( p_messages_dialog ) delete p_messages_dialog;
179
if( p_fileinfo_dialog ) delete p_fileinfo_dialog;
180
if( p_file_generic_dialog ) delete p_file_generic_dialog;
181
if( p_streamwizard_dialog ) delete p_streamwizard_dialog;
182
if( p_wizard_dialog ) delete p_wizard_dialog;
183
if( p_bookmarks_dialog ) delete p_bookmarks_dialog;
186
if( p_intf->p_sys->p_icon ) delete p_intf->p_sys->p_icon;
188
/* We must set this here because on win32 this destructor will be
189
* automatically called so we must not call it again on wxApp->OnExit().
190
* There shouldn't be any race conditions as all this should be done
191
* from the same thread. */
192
p_intf->p_sys->p_wxwindow = NULL;
195
void DialogsProvider::OnIdle( wxIdleEvent& WXUNUSED(event) )
197
/* Update the log window */
198
if( p_messages_dialog )
199
p_messages_dialog->UpdateLog();
201
/* Update the playlist */
202
if( p_playlist_dialog )
203
p_playlist_dialog->UpdatePlaylist();
205
/* Update the fileinfo windows */
206
if( p_fileinfo_dialog )
207
p_fileinfo_dialog->UpdateFileInfo();
210
void DialogsProvider::OnPlaylist( wxCommandEvent& WXUNUSED(event) )
212
/* Show/hide the playlist window */
213
if( !p_playlist_dialog )
214
p_playlist_dialog = new Playlist( p_intf, this );
216
if( p_playlist_dialog )
218
p_playlist_dialog->ShowPlaylist( !p_playlist_dialog->IsShown() );
222
void DialogsProvider::OnMessages( wxCommandEvent& WXUNUSED(event) )
224
/* Show/hide the log window */
225
if( !p_messages_dialog )
226
p_messages_dialog = new Messages( p_intf, this );
228
if( p_messages_dialog )
230
p_messages_dialog->Show( !p_messages_dialog->IsShown() );
234
void DialogsProvider::OnFileInfo( wxCommandEvent& WXUNUSED(event) )
236
/* Show/hide the file info window */
237
if( !p_fileinfo_dialog )
238
p_fileinfo_dialog = new FileInfo( p_intf, this );
240
if( p_fileinfo_dialog )
242
p_fileinfo_dialog->Show( !p_fileinfo_dialog->IsShown() );
246
void DialogsProvider::OnPreferences( wxCommandEvent& WXUNUSED(event) )
248
/* Show/hide the open dialog */
249
if( !p_prefs_dialog )
250
p_prefs_dialog = new PrefsDialog( p_intf, this );
254
p_prefs_dialog->Show( !p_prefs_dialog->IsShown() );
258
void DialogsProvider::OnStreamWizardDialog( wxCommandEvent& WXUNUSED(event) )
260
/* Show/hide the stream window */
261
if( !p_streamwizard_dialog )
262
p_streamwizard_dialog = new StreamDialog( p_intf, this );
264
if( p_streamwizard_dialog )
266
p_streamwizard_dialog->Show( !p_streamwizard_dialog->IsShown() );
270
void DialogsProvider::OnWizardDialog( wxCommandEvent& WXUNUSED(event) )
272
p_wizard_dialog = new WizardDialog( p_intf, this );
274
if( p_wizard_dialog )
276
p_wizard_dialog->Run();
279
delete p_wizard_dialog;
280
p_wizard_dialog = NULL;
283
void DialogsProvider::OnBookmarks( wxCommandEvent& WXUNUSED(event) )
285
/* Show/hide the open dialog */
286
if( !p_bookmarks_dialog )
287
p_bookmarks_dialog = BookmarksDialog( p_intf, this );
289
if( p_bookmarks_dialog )
291
p_bookmarks_dialog->Show( !p_bookmarks_dialog->IsShown() );
295
void DialogsProvider::OnOpenFileGeneric( wxCommandEvent& event )
297
intf_dialog_args_t *p_arg = (intf_dialog_args_t *)event.GetClientData();
301
msg_Dbg( p_intf, "OnOpenFileGeneric() called with NULL arg" );
305
if( p_file_generic_dialog == NULL )
306
p_file_generic_dialog = new wxFileDialog( NULL );
308
if( p_file_generic_dialog )
310
p_file_generic_dialog->SetMessage( wxU(p_arg->psz_title) );
311
p_file_generic_dialog->SetWildcard( wxU(p_arg->psz_extensions) );
312
p_file_generic_dialog->SetStyle( (p_arg->b_save ? wxSAVE : wxOPEN) |
313
(p_arg->b_multiple ? wxMULTIPLE:0) );
316
if( p_file_generic_dialog &&
317
p_file_generic_dialog->ShowModal() == wxID_OK )
321
p_file_generic_dialog->GetPaths( paths );
323
p_arg->i_results = paths.GetCount();
324
p_arg->psz_results = (char **)malloc( p_arg->i_results *
326
for( size_t i = 0; i < paths.GetCount(); i++ )
328
p_arg->psz_results[i] = strdup( paths[i].mb_str() );
333
if( p_arg->pf_callback )
335
p_arg->pf_callback( p_arg );
338
/* Blocking or not ? */
339
if( p_arg->b_blocking )
341
vlc_mutex_lock( &p_arg->lock );
343
vlc_cond_signal( &p_arg->wait );
346
if( p_arg->psz_results )
348
for( int i = 0; i < p_arg->i_results; i++ )
350
free( p_arg->psz_results[i] );
352
free( p_arg->psz_results );
354
if( p_arg->psz_title ) free( p_arg->psz_title );
355
if( p_arg->psz_extensions ) free( p_arg->psz_extensions );
357
if( p_arg->b_blocking )
359
vlc_mutex_unlock( &p_arg->lock );
367
void DialogsProvider::OnOpenFileSimple( wxCommandEvent& event )
369
playlist_t *p_playlist =
370
(playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
372
if( p_playlist == NULL )
377
if( p_file_dialog == NULL )
378
p_file_dialog = new wxFileDialog( NULL, wxU(_("Open File")),
379
wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
381
if( p_file_dialog && p_file_dialog->ShowModal() == wxID_OK )
385
p_file_dialog->GetPaths( paths );
387
for( size_t i = 0; i < paths.GetCount(); i++ )
389
playlist_Add( p_playlist, (const char *)paths[i].mb_str(),
390
(const char *)paths[i].mb_str(),
391
PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO),
394
playlist_Add( p_playlist, (const char *)paths[i].mb_str(),
395
(const char *)paths[i].mb_str(),
396
PLAYLIST_APPEND, PLAYLIST_END );
399
vlc_object_release( p_playlist );
402
void DialogsProvider::OnOpenFile( wxCommandEvent& event )
404
Open( FILE_ACCESS, event.GetInt() );
407
void DialogsProvider::OnOpenDisc( wxCommandEvent& event )
409
Open( DISC_ACCESS, event.GetInt() );
412
void DialogsProvider::OnOpenNet( wxCommandEvent& event )
414
Open( NET_ACCESS, event.GetInt() );
417
void DialogsProvider::OnOpenCapture( wxCommandEvent& event )
419
Open( CAPTURE_ACCESS, event.GetInt() );
422
void DialogsProvider::Open( int i_access_method, int i_arg )
424
/* Show/hide the open dialog */
426
p_open_dialog = new OpenDialog( p_intf, this, i_access_method, i_arg,
431
p_open_dialog->Show( i_access_method, i_arg );
435
void DialogsProvider::OnPopupMenu( wxCommandEvent& event )
437
wxPoint mousepos = ScreenToClient( wxGetMousePosition() );
438
::PopupMenu( p_intf, this, mousepos );
441
void DialogsProvider::OnExitThread( wxCommandEvent& WXUNUSED(event) )
443
wxTheApp->ExitMainLoop();