00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <stdlib.h>
00028 #include <errno.h>
00029 #include <string.h>
00030 #include <stdio.h>
00031
00032 #include <vlc/vlc.h>
00033 #include <vlc/aout.h>
00034 #include <vlc/intf.h>
00035 #include "charset.h"
00036
00037 #include "wxwidgets.h"
00038
00039
00040 #include "../../../share/vlc32x32.xpm"
00041
00042
00043 class DialogsProvider: public wxFrame
00044 {
00045 public:
00046
00047 DialogsProvider( intf_thread_t *p_intf, wxWindow *p_parent );
00048 virtual ~DialogsProvider();
00049
00050 private:
00051 void Open( int i_access_method, int i_arg );
00052
00053
00054 void OnExit( wxCommandEvent& event );
00055 void OnPlaylist( wxCommandEvent& event );
00056 void OnMessages( wxCommandEvent& event );
00057 void OnFileInfo( wxCommandEvent& event );
00058 void OnPreferences( wxCommandEvent& event );
00059 void OnWizardDialog( wxCommandEvent& event );
00060 void OnBookmarks( wxCommandEvent& event );
00061
00062 void OnOpenFileGeneric( wxCommandEvent& event );
00063 void OnOpenFileSimple( wxCommandEvent& event );
00064 void OnOpenDirectory( wxCommandEvent& event );
00065 void OnOpenFile( wxCommandEvent& event );
00066 void OnOpenDisc( wxCommandEvent& event );
00067 void OnOpenNet( wxCommandEvent& event );
00068 void OnOpenCapture( wxCommandEvent& event );
00069 void OnOpenSat( wxCommandEvent& event );
00070
00071 void OnPopupMenu( wxCommandEvent& event );
00072
00073 void OnIdle( wxIdleEvent& event );
00074
00075 void OnExitThread( wxCommandEvent& event );
00076
00077 DECLARE_EVENT_TABLE();
00078
00079 intf_thread_t *p_intf;
00080
00081 public:
00082
00083 OpenDialog *p_open_dialog;
00084 wxFileDialog *p_file_dialog;
00085 wxDirDialog *p_dir_dialog;
00086 Playlist *p_playlist_dialog;
00087 Messages *p_messages_dialog;
00088 FileInfo *p_fileinfo_dialog;
00089 WizardDialog *p_wizard_dialog;
00090 wxFrame *p_prefs_dialog;
00091 wxFrame *p_bookmarks_dialog;
00092 wxFileDialog *p_file_generic_dialog;
00093 };
00094
00095 DEFINE_LOCAL_EVENT_TYPE( wxEVT_DIALOG );
00096
00097 BEGIN_EVENT_TABLE(DialogsProvider, wxFrame)
00098
00099 EVT_IDLE(DialogsProvider::OnIdle)
00100
00101
00102 EVT_COMMAND(INTF_DIALOG_FILE, wxEVT_DIALOG, DialogsProvider::OnOpenFile)
00103 EVT_COMMAND(INTF_DIALOG_DISC, wxEVT_DIALOG, DialogsProvider::OnOpenDisc)
00104 EVT_COMMAND(INTF_DIALOG_NET, wxEVT_DIALOG, DialogsProvider::OnOpenNet)
00105 EVT_COMMAND(INTF_DIALOG_CAPTURE, wxEVT_DIALOG,
00106 DialogsProvider::OnOpenCapture)
00107 EVT_COMMAND(INTF_DIALOG_FILE_SIMPLE, wxEVT_DIALOG,
00108 DialogsProvider::OnOpenFileSimple)
00109 EVT_COMMAND(INTF_DIALOG_FILE_GENERIC, wxEVT_DIALOG,
00110 DialogsProvider::OnOpenFileGeneric)
00111 EVT_COMMAND(INTF_DIALOG_DIRECTORY, wxEVT_DIALOG,
00112 DialogsProvider::OnOpenDirectory)
00113
00114 EVT_COMMAND(INTF_DIALOG_PLAYLIST, wxEVT_DIALOG,
00115 DialogsProvider::OnPlaylist)
00116 EVT_COMMAND(INTF_DIALOG_MESSAGES, wxEVT_DIALOG,
00117 DialogsProvider::OnMessages)
00118 EVT_COMMAND(INTF_DIALOG_PREFS, wxEVT_DIALOG,
00119 DialogsProvider::OnPreferences)
00120 EVT_COMMAND(INTF_DIALOG_WIZARD, wxEVT_DIALOG,
00121 DialogsProvider::OnWizardDialog)
00122 EVT_COMMAND(INTF_DIALOG_FILEINFO, wxEVT_DIALOG,
00123 DialogsProvider::OnFileInfo)
00124 EVT_COMMAND(INTF_DIALOG_BOOKMARKS, wxEVT_DIALOG,
00125 DialogsProvider::OnBookmarks)
00126 EVT_COMMAND(INTF_DIALOG_POPUPMENU, wxEVT_DIALOG,
00127 DialogsProvider::OnPopupMenu)
00128 EVT_COMMAND(INTF_DIALOG_EXIT, wxEVT_DIALOG,
00129 DialogsProvider::OnExitThread)
00130 END_EVENT_TABLE()
00131
00132 wxWindow *CreateDialogsProvider( intf_thread_t *p_intf, wxWindow *p_parent )
00133 {
00134 return new DialogsProvider( p_intf, p_parent );
00135 }
00136
00137
00138
00139
00140 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf, wxWindow *p_parent )
00141 : wxFrame( p_parent, -1, wxT("") )
00142 {
00143
00144 p_intf = _p_intf;
00145 p_open_dialog = NULL;
00146 p_file_dialog = NULL;
00147 p_playlist_dialog = NULL;
00148 p_messages_dialog = NULL;
00149 p_fileinfo_dialog = NULL;
00150 p_prefs_dialog = NULL;
00151 p_file_generic_dialog = NULL;
00152 p_wizard_dialog = NULL;
00153 p_bookmarks_dialog = NULL;
00154 p_dir_dialog = NULL;
00155
00156
00157 p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
00158
00159
00160 p_messages_dialog = new Messages( p_intf, p_parent ? p_parent : this );
00161
00162
00163 wxCommandEvent dummy_event;
00164 if( config_GetInt( p_intf, "wx-bookmarks" ) )
00165 OnBookmarks( dummy_event );
00166
00167
00168 PushEventHandler( new MenuEvtHandler( p_intf, NULL ) );
00169
00170
00171 WindowSettings *ws = p_intf->p_sys->p_window_settings;
00172 wxPoint p;
00173 wxSize s;
00174 bool b_shown;
00175
00176 #define INIT( id, w, N, S ) \
00177 if( ws->GetSettings( WindowSettings::id, b_shown, p, s ) && b_shown ) \
00178 { \
00179 if( !w ) \
00180 w = N; \
00181 w->SetSize( s ); \
00182 w->Move( p ); \
00183 w->S( true ); \
00184 }
00185
00186 INIT( ID_PLAYLIST, p_playlist_dialog, new Playlist(p_intf,this), ShowPlaylist );
00187 INIT( ID_MESSAGES, p_messages_dialog, new Messages(p_intf,this), Show );
00188 INIT( ID_FILE_INFO, p_fileinfo_dialog, new FileInfo(p_intf,this), Show );
00189 INIT( ID_BOOKMARKS, p_bookmarks_dialog, BookmarksDialog(p_intf,this), Show);
00190 #undef INIT
00191 }
00192
00193 DialogsProvider::~DialogsProvider()
00194 {
00195 WindowSettings *ws = p_intf->p_sys->p_window_settings;
00196
00197 #define UPDATE(id,w) \
00198 { \
00199 if( w && w->IsShown() && !w->IsIconized() ) \
00200 ws->SetSettings( WindowSettings::id, true, \
00201 w->GetPosition(), w->GetSize() ); \
00202 else \
00203 ws->SetSettings( WindowSettings::id, false ); \
00204 }
00205
00206 UPDATE( ID_PLAYLIST, p_playlist_dialog );
00207 UPDATE( ID_MESSAGES, p_messages_dialog );
00208 UPDATE( ID_FILE_INFO, p_fileinfo_dialog );
00209 UPDATE( ID_BOOKMARKS, p_bookmarks_dialog );
00210
00211 #undef UPDATE
00212
00213 PopEventHandler(true);
00214
00215
00216 if( p_open_dialog ) delete p_open_dialog;
00217 if( p_prefs_dialog ) p_prefs_dialog->Destroy();
00218 if( p_file_dialog ) delete p_file_dialog;
00219 if( p_playlist_dialog ) delete p_playlist_dialog;
00220 if( p_messages_dialog ) delete p_messages_dialog;
00221 if( p_fileinfo_dialog ) delete p_fileinfo_dialog;
00222 if( p_file_generic_dialog ) delete p_file_generic_dialog;
00223 if( p_wizard_dialog ) delete p_wizard_dialog;
00224 if( p_bookmarks_dialog ) delete p_bookmarks_dialog;
00225
00226
00227 if( p_intf->p_sys->p_icon ) delete p_intf->p_sys->p_icon;
00228
00229
00230
00231
00232
00233 p_intf->p_sys->p_wxwindow = NULL;
00234 }
00235
00236 void DialogsProvider::OnIdle( wxIdleEvent& WXUNUSED(event) )
00237 {
00238
00239 if( p_messages_dialog )
00240 p_messages_dialog->UpdateLog();
00241
00242
00243 if( p_playlist_dialog )
00244 p_playlist_dialog->UpdatePlaylist();
00245
00246
00247 if( p_fileinfo_dialog )
00248 p_fileinfo_dialog->UpdateFileInfo();
00249 }
00250
00251 void DialogsProvider::OnPlaylist( wxCommandEvent& WXUNUSED(event) )
00252 {
00253
00254 if( !p_playlist_dialog )
00255 p_playlist_dialog = new Playlist( p_intf, this );
00256
00257 if( p_playlist_dialog )
00258 {
00259 p_playlist_dialog->ShowPlaylist( !p_playlist_dialog->IsShown() );
00260 }
00261 }
00262
00263 void DialogsProvider::OnMessages( wxCommandEvent& WXUNUSED(event) )
00264 {
00265
00266 if( !p_messages_dialog )
00267 p_messages_dialog = new Messages( p_intf, this );
00268
00269 if( p_messages_dialog )
00270 {
00271 p_messages_dialog->Show( !p_messages_dialog->IsShown() );
00272 }
00273 }
00274
00275 void DialogsProvider::OnFileInfo( wxCommandEvent& WXUNUSED(event) )
00276 {
00277
00278 if( !p_fileinfo_dialog )
00279 p_fileinfo_dialog = new FileInfo( p_intf, this );
00280
00281 if( p_fileinfo_dialog )
00282 {
00283 p_fileinfo_dialog->Show( !p_fileinfo_dialog->IsShown() );
00284 }
00285 }
00286
00287 void DialogsProvider::OnPreferences( wxCommandEvent& WXUNUSED(event) )
00288 {
00289
00290 if( !p_prefs_dialog )
00291 p_prefs_dialog = new PrefsDialog( p_intf, this );
00292
00293 if( p_prefs_dialog )
00294 {
00295 p_prefs_dialog->Show( !p_prefs_dialog->IsShown() );
00296 }
00297 }
00298
00299 void DialogsProvider::OnWizardDialog( wxCommandEvent& WXUNUSED(event) )
00300 {
00301 p_wizard_dialog = new WizardDialog( p_intf, this, NULL, 0, 0 );
00302
00303 if( p_wizard_dialog )
00304 {
00305 p_wizard_dialog->Run();
00306 delete p_wizard_dialog;
00307 }
00308
00309 p_wizard_dialog = NULL;
00310 }
00311
00312 void DialogsProvider::OnBookmarks( wxCommandEvent& WXUNUSED(event) )
00313 {
00314
00315 if( !p_bookmarks_dialog )
00316 p_bookmarks_dialog = BookmarksDialog( p_intf, this );
00317
00318 if( p_bookmarks_dialog )
00319 {
00320 p_bookmarks_dialog->Show( !p_bookmarks_dialog->IsShown() );
00321 }
00322 }
00323
00324 void DialogsProvider::OnOpenFileGeneric( wxCommandEvent& event )
00325 {
00326 intf_dialog_args_t *p_arg = (intf_dialog_args_t *)event.GetClientData();
00327
00328 if( p_arg == NULL )
00329 {
00330 msg_Dbg( p_intf, "OnOpenFileGeneric() called with NULL arg" );
00331 return;
00332 }
00333
00334 if( p_file_generic_dialog == NULL )
00335 p_file_generic_dialog = new wxFileDialog( NULL );
00336
00337 if( p_file_generic_dialog )
00338 {
00339 p_file_generic_dialog->SetMessage( wxU(p_arg->psz_title) );
00340 p_file_generic_dialog->SetWildcard( wxU(p_arg->psz_extensions) );
00341 p_file_generic_dialog->SetStyle( (p_arg->b_save ? wxSAVE : wxOPEN) |
00342 (p_arg->b_multiple ? wxMULTIPLE:0) );
00343 }
00344
00345 if( p_file_generic_dialog &&
00346 p_file_generic_dialog->ShowModal() == wxID_OK )
00347 {
00348 wxArrayString paths;
00349
00350 p_file_generic_dialog->GetPaths( paths );
00351
00352 p_arg->i_results = paths.GetCount();
00353 p_arg->psz_results = (char **)malloc( p_arg->i_results *
00354 sizeof(char *) );
00355 for( size_t i = 0; i < paths.GetCount(); i++ )
00356 {
00357 p_arg->psz_results[i] = strdup( paths[i].mb_str() );
00358 }
00359 }
00360
00361
00362 if( p_arg->pf_callback )
00363 {
00364 p_arg->pf_callback( p_arg );
00365 }
00366
00367 if( p_arg->psz_results )
00368 {
00369 for( int i = 0; i < p_arg->i_results; i++ )
00370 {
00371 free( p_arg->psz_results[i] );
00372 }
00373 free( p_arg->psz_results );
00374 }
00375 if( p_arg->psz_title ) free( p_arg->psz_title );
00376 if( p_arg->psz_extensions ) free( p_arg->psz_extensions );
00377
00378 free( p_arg );
00379 }
00380
00381 void DialogsProvider::OnOpenFileSimple( wxCommandEvent& event )
00382 {
00383 playlist_t *p_playlist =
00384 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
00385 FIND_ANYWHERE );
00386 if( p_playlist == NULL )
00387 {
00388 return;
00389 }
00390
00391 if( p_file_dialog == NULL )
00392 p_file_dialog = new wxFileDialog( NULL, wxU(_("Open File")),
00393 wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
00394
00395 if( p_file_dialog && p_file_dialog->ShowModal() == wxID_OK )
00396 {
00397 wxArrayString paths;
00398
00399 p_file_dialog->GetPaths( paths );
00400
00401 for( size_t i = 0; i < paths.GetCount(); i++ )
00402 {
00403 char *psz_utf8 = wxFromLocale( paths[i] );
00404 if( event.GetInt() )
00405 playlist_Add( p_playlist, psz_utf8, psz_utf8,
00406 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO),
00407 PLAYLIST_END );
00408 else
00409 playlist_Add( p_playlist, psz_utf8, psz_utf8,
00410 PLAYLIST_APPEND, PLAYLIST_END );
00411 wxLocaleFree( psz_utf8 );
00412 }
00413 }
00414
00415 vlc_object_release( p_playlist );
00416 }
00417
00418 void DialogsProvider::OnOpenDirectory( wxCommandEvent& event )
00419 {
00420 playlist_t *p_playlist =
00421 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
00422 FIND_ANYWHERE );
00423 if( p_playlist == NULL )
00424 {
00425 return;
00426 }
00427
00428 if( p_dir_dialog == NULL )
00429 p_dir_dialog = new wxDirDialog( NULL );
00430
00431 if( p_dir_dialog && p_dir_dialog->ShowModal() == wxID_OK )
00432 {
00433 wxString path = p_dir_dialog->GetPath();
00434 char *psz_utf8 = wxFromLocale( path );
00435 playlist_Add( p_playlist, psz_utf8, psz_utf8,
00436 PLAYLIST_APPEND | (event.GetInt() ? PLAYLIST_GO : 0),
00437 PLAYLIST_END );
00438 wxLocaleFree( psz_utf8 );
00439 }
00440
00441 vlc_object_release( p_playlist );
00442 }
00443
00444 void DialogsProvider::OnOpenFile( wxCommandEvent& event )
00445 {
00446 Open( FILE_ACCESS, event.GetInt() );
00447 }
00448
00449 void DialogsProvider::OnOpenDisc( wxCommandEvent& event )
00450 {
00451 Open( DISC_ACCESS, event.GetInt() );
00452 }
00453
00454 void DialogsProvider::OnOpenNet( wxCommandEvent& event )
00455 {
00456 Open( NET_ACCESS, event.GetInt() );
00457 }
00458
00459 void DialogsProvider::OnOpenCapture( wxCommandEvent& event )
00460 {
00461 Open( CAPTURE_ACCESS, event.GetInt() );
00462 }
00463
00464 void DialogsProvider::Open( int i_access_method, int i_arg )
00465 {
00466
00467 if( !p_open_dialog )
00468 p_open_dialog = new OpenDialog( p_intf, this, i_access_method, i_arg,
00469 OPEN_NORMAL );
00470
00471 if( p_open_dialog )
00472 {
00473 p_open_dialog->Show( i_access_method, i_arg );
00474 }
00475 }
00476
00477 void DialogsProvider::OnPopupMenu( wxCommandEvent& event )
00478 {
00479 wxPoint mousepos = ScreenToClient( wxGetMousePosition() );
00480 ::PopupMenu( p_intf, this, mousepos );
00481 }
00482
00483 void DialogsProvider::OnExitThread( wxCommandEvent& WXUNUSED(event) )
00484 {
00485 wxTheApp->ExitMainLoop();
00486 }