1 /*****************************************************************************
2 * dialogs.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: dialogs.cpp,v 1.4 2003/07/20 10:38:49 gbazin Exp $
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
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 #ifdef WIN32 /* mingw32 hack */
40 /* Let vlc take care of the i18n stuff */
41 #define WXINTL_NO_GETTEXT_MACRO
43 #include <wx/wxprec.h>
47 #include "stream_control.h"
49 #include "wxwindows.h"
51 /* include the icon graphic */
52 #include "../../../share/vlc32x32.xpm"
54 DEFINE_LOCAL_EVENT_TYPE( wxEVT_DIALOG );
56 BEGIN_EVENT_TABLE(DialogsProvider, wxFrame)
57 /* Idle loop used to update some of the dialogs */
58 EVT_IDLE(DialogsProvider::OnIdle)
60 /* Custom wxDialog events */
61 EVT_COMMAND(INTF_DIALOG_FILE, wxEVT_DIALOG, DialogsProvider::OnOpenFile)
62 EVT_COMMAND(INTF_DIALOG_DISC, wxEVT_DIALOG, DialogsProvider::OnOpenDisc)
63 EVT_COMMAND(INTF_DIALOG_NET, wxEVT_DIALOG, DialogsProvider::OnOpenNet)
64 EVT_COMMAND(INTF_DIALOG_FILE_SIMPLE, wxEVT_DIALOG,
65 DialogsProvider::OnOpenFileSimple)
66 EVT_COMMAND(INTF_DIALOG_FILE_GENERIC, wxEVT_DIALOG,
67 DialogsProvider::OnOpenFileGeneric)
69 EVT_COMMAND(INTF_DIALOG_PLAYLIST, wxEVT_DIALOG,
70 DialogsProvider::OnPlaylist)
71 EVT_COMMAND(INTF_DIALOG_MESSAGES, wxEVT_DIALOG,
72 DialogsProvider::OnMessages)
73 EVT_COMMAND(INTF_DIALOG_PREFS, wxEVT_DIALOG,
74 DialogsProvider::OnPreferences)
75 EVT_COMMAND(INTF_DIALOG_FILEINFO, wxEVT_DIALOG,
76 DialogsProvider::OnFileInfo)
77 EVT_COMMAND(INTF_DIALOG_POPUPMENU, wxEVT_DIALOG,
78 DialogsProvider::OnPopupMenu)
79 EVT_COMMAND(INTF_DIALOG_EXIT, wxEVT_DIALOG,
80 DialogsProvider::OnExitThread)
83 /*****************************************************************************
85 *****************************************************************************/
86 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf, wxWindow *p_parent )
87 : wxFrame( p_parent, -1, wxT("") )
93 p_playlist_dialog = NULL;
94 p_messages_dialog = NULL;
95 p_fileinfo_dialog = NULL;
96 p_prefs_dialog = NULL;
97 p_file_generic_dialog = NULL;
99 /* Give our interface a nice little icon */
100 p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
102 /* Create the messages dialog so it can begin storing logs */
103 p_messages_dialog = new Messages( p_intf, p_parent ? p_parent : this );
105 /* Intercept all menu events in our custom event handler */
106 PushEventHandler( new MenuEvtHandler( p_intf, NULL ) );
109 DialogsProvider::~DialogsProvider()
112 if( p_open_dialog ) delete p_open_dialog;
113 if( p_prefs_dialog ) p_prefs_dialog->Destroy();
114 if( p_file_dialog ) delete p_file_dialog;
115 if( p_playlist_dialog ) delete p_playlist_dialog;
116 if( p_messages_dialog ) delete p_messages_dialog;
117 if( p_fileinfo_dialog ) delete p_fileinfo_dialog;
118 if( p_file_generic_dialog ) delete p_file_generic_dialog;
120 if( p_intf->p_sys->p_icon ) delete p_intf->p_sys->p_icon;
123 void DialogsProvider::OnIdle( wxIdleEvent& WXUNUSED(event) )
125 /* Update the log window */
126 if( p_messages_dialog )
127 p_messages_dialog->UpdateLog();
129 /* Update the playlist */
130 if( p_playlist_dialog )
131 p_playlist_dialog->UpdatePlaylist();
133 /* Update the fileinfo windows */
134 if( p_fileinfo_dialog )
135 p_fileinfo_dialog->UpdateFileInfo();
138 void DialogsProvider::OnPlaylist( wxCommandEvent& WXUNUSED(event) )
140 /* Show/hide the playlist window */
141 if( !p_playlist_dialog )
142 p_playlist_dialog = new Playlist( p_intf, this );
144 if( p_playlist_dialog )
146 p_playlist_dialog->ShowPlaylist( !p_playlist_dialog->IsShown() );
150 void DialogsProvider::OnMessages( wxCommandEvent& WXUNUSED(event) )
152 /* Show/hide the log window */
153 if( !p_messages_dialog )
154 p_messages_dialog = new Messages( p_intf, this );
156 if( p_messages_dialog )
158 p_messages_dialog->Show( !p_messages_dialog->IsShown() );
162 void DialogsProvider::OnFileInfo( wxCommandEvent& WXUNUSED(event) )
164 /* Show/hide the file info window */
165 if( !p_fileinfo_dialog )
166 p_fileinfo_dialog = new FileInfo( p_intf, this );
168 if( p_fileinfo_dialog )
170 p_fileinfo_dialog->Show( !p_fileinfo_dialog->IsShown() );
174 void DialogsProvider::OnPreferences( wxCommandEvent& WXUNUSED(event) )
176 /* Show/hide the open dialog */
177 if( !p_prefs_dialog )
178 p_prefs_dialog = new PrefsDialog( p_intf, this );
182 p_prefs_dialog->Show( !p_prefs_dialog->IsShown() );
186 void DialogsProvider::OnOpenFileGeneric( wxCommandEvent& event )
188 intf_dialog_args_t *p_arg = (intf_dialog_args_t *)event.GetClientData();
192 msg_Dbg( p_intf, "OnOpenFileGeneric() called with NULL arg" );
196 if( p_file_generic_dialog == NULL )
197 p_file_generic_dialog = new wxFileDialog( this );
199 if( p_file_generic_dialog )
201 p_file_generic_dialog->SetMessage( wxU(p_arg->psz_title) );
202 p_file_generic_dialog->SetWildcard( wxU(p_arg->psz_extensions) );
203 p_file_generic_dialog->SetStyle( (p_arg->b_save ? wxSAVE : wxOPEN) |
204 (p_arg->b_multiple ? wxMULTIPLE:0) );
207 if( p_file_generic_dialog &&
208 p_file_generic_dialog->ShowModal() == wxID_OK )
212 p_file_generic_dialog->GetPaths( paths );
214 p_arg->i_results = paths.GetCount();
215 p_arg->psz_results = (char **)malloc( p_arg->i_results *
217 for( size_t i = 0; i < paths.GetCount(); i++ )
219 p_arg->psz_results[i] = strdup( paths[i].mb_str() );
224 if( p_arg->pf_callback )
226 p_arg->pf_callback( p_arg );
229 /* Blocking or not ? */
230 if( p_arg->b_blocking )
232 vlc_mutex_lock( &p_arg->lock );
234 vlc_cond_signal( &p_arg->wait );
235 vlc_mutex_unlock( &p_arg->lock );
239 if( p_arg->b_blocking )
241 vlc_mutex_destroy( &p_arg->lock );
242 vlc_cond_destroy( &p_arg->wait );
244 if( p_arg->psz_results )
246 for( int i = 0; i < p_arg->i_results; i++ )
248 free( p_arg->psz_results[i] );
250 free( p_arg->psz_results );
252 if( p_arg->psz_title ) free( p_arg->psz_title );
253 if( p_arg->psz_extensions ) free( p_arg->psz_extensions );
257 void DialogsProvider::OnOpenFileSimple( wxCommandEvent& event )
259 playlist_t *p_playlist =
260 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
262 if( p_playlist == NULL )
267 if( p_file_dialog == NULL )
268 p_file_dialog = new wxFileDialog( this, wxU(_("Open file")),
269 wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
271 if( p_file_dialog && p_file_dialog->ShowModal() == wxID_OK )
275 p_file_dialog->GetPaths( paths );
277 for( size_t i = 0; i < paths.GetCount(); i++ )
279 playlist_Add( p_playlist, (const char *)paths[i].mb_str(),
280 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO),
283 playlist_Add( p_playlist, (const char *)paths[i].mb_str(),
284 PLAYLIST_APPEND, PLAYLIST_END );
287 vlc_object_release( p_playlist );
290 void DialogsProvider::OnOpenFile( wxCommandEvent& event )
292 Open( FILE_ACCESS, event.GetInt() );
295 void DialogsProvider::OnOpenDisc( wxCommandEvent& event )
297 Open( DISC_ACCESS, event.GetInt() );
300 void DialogsProvider::OnOpenNet( wxCommandEvent& event )
302 Open( NET_ACCESS, event.GetInt() );
305 void DialogsProvider::OnOpenSat( wxCommandEvent& event )
307 Open( SAT_ACCESS, event.GetInt() );
310 void DialogsProvider::Open( int i_access_method, int i_arg )
312 /* Show/hide the open dialog */
314 p_open_dialog = new OpenDialog( p_intf, this, i_access_method, i_arg );
318 p_open_dialog->Show( i_access_method, i_arg );
322 void DialogsProvider::OnPopupMenu( wxCommandEvent& event )
324 wxPoint mousepos = ScreenToClient( wxGetMousePosition() );
325 ::PopupMenu( p_intf, this, mousepos );
329 void DialogsProvider::OnExitThread( wxCommandEvent& WXUNUSED(event) )
332 wxTheApp->ExitMainLoop();