1 /*****************************************************************************
2 * dialogs.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: dialogs.cpp,v 1.3 2003/07/18 11:39:39 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)
67 EVT_COMMAND(INTF_DIALOG_PLAYLIST, wxEVT_DIALOG,
68 DialogsProvider::OnPlaylist)
69 EVT_COMMAND(INTF_DIALOG_MESSAGES, wxEVT_DIALOG,
70 DialogsProvider::OnMessages)
71 EVT_COMMAND(INTF_DIALOG_PREFS, wxEVT_DIALOG,
72 DialogsProvider::OnPreferences)
73 EVT_COMMAND(INTF_DIALOG_FILEINFO, wxEVT_DIALOG,
74 DialogsProvider::OnFileInfo)
75 EVT_COMMAND(INTF_DIALOG_POPUPMENU, wxEVT_DIALOG,
76 DialogsProvider::OnPopupMenu)
79 /*****************************************************************************
81 *****************************************************************************/
82 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf, wxWindow *p_parent )
83 : wxFrame( p_parent, -1, wxT("") )
89 p_playlist_dialog = NULL;
90 p_messages_dialog = NULL;
91 p_fileinfo_dialog = NULL;
92 p_prefs_dialog = NULL;
94 /* Give our interface a nice little icon */
95 p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
97 /* Create the messages dialog so it can begin storing logs */
98 p_messages_dialog = new Messages( p_intf, p_parent ? p_parent : this );
100 /* Intercept all menu events in our custom event handler */
101 PushEventHandler( new MenuEvtHandler( p_intf, NULL ) );
104 DialogsProvider::~DialogsProvider()
107 if( p_open_dialog ) delete p_open_dialog;
108 if( p_prefs_dialog ) p_prefs_dialog->Destroy();
109 if( p_file_dialog ) delete p_file_dialog;
110 if( p_playlist_dialog ) delete p_playlist_dialog;
111 if( p_messages_dialog ) delete p_messages_dialog;
112 if( p_fileinfo_dialog ) delete p_fileinfo_dialog;
114 if( p_intf->p_sys->p_icon ) delete p_intf->p_sys->p_icon;
117 void DialogsProvider::OnIdle( wxIdleEvent& WXUNUSED(event) )
119 /* Update the log window */
120 if( p_messages_dialog )
121 p_messages_dialog->UpdateLog();
123 /* Update the playlist */
124 if( p_playlist_dialog )
125 p_playlist_dialog->UpdatePlaylist();
127 /* Update the fileinfo windows */
128 if( p_fileinfo_dialog )
129 p_fileinfo_dialog->UpdateFileInfo();
132 void DialogsProvider::OnPlaylist( wxCommandEvent& WXUNUSED(event) )
134 /* Show/hide the playlist window */
135 if( !p_playlist_dialog )
136 p_playlist_dialog = new Playlist( p_intf, this );
138 if( p_playlist_dialog )
140 p_playlist_dialog->ShowPlaylist( !p_playlist_dialog->IsShown() );
144 void DialogsProvider::OnMessages( wxCommandEvent& WXUNUSED(event) )
146 /* Show/hide the log window */
147 if( !p_messages_dialog )
148 p_messages_dialog = new Messages( p_intf, this );
150 if( p_messages_dialog )
152 p_messages_dialog->Show( !p_messages_dialog->IsShown() );
156 void DialogsProvider::OnFileInfo( wxCommandEvent& WXUNUSED(event) )
158 /* Show/hide the file info window */
159 if( !p_fileinfo_dialog )
160 p_fileinfo_dialog = new FileInfo( p_intf, this );
162 if( p_fileinfo_dialog )
164 p_fileinfo_dialog->Show( !p_fileinfo_dialog->IsShown() );
168 void DialogsProvider::OnPreferences( wxCommandEvent& WXUNUSED(event) )
170 /* Show/hide the open dialog */
171 if( !p_prefs_dialog )
172 p_prefs_dialog = new PrefsDialog( p_intf, this );
176 p_prefs_dialog->Show( !p_prefs_dialog->IsShown() );
180 void DialogsProvider::OnOpenFileSimple( wxCommandEvent& event )
182 playlist_t *p_playlist =
183 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
185 if( p_playlist == NULL )
190 if( p_file_dialog == NULL )
191 p_file_dialog = new wxFileDialog( this, wxU(_("Open file")),
192 wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
194 if( p_file_dialog && p_file_dialog->ShowModal() == wxID_OK )
198 p_file_dialog->GetPaths( paths );
200 for( size_t i = 0; i < paths.GetCount(); i++ )
202 playlist_Add( p_playlist, (const char *)paths[i].mb_str(),
203 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO),
206 playlist_Add( p_playlist, (const char *)paths[i].mb_str(),
207 PLAYLIST_APPEND, PLAYLIST_END );
210 vlc_object_release( p_playlist );
213 void DialogsProvider::OnOpenFile( wxCommandEvent& event )
215 Open( FILE_ACCESS, event.GetInt() );
218 void DialogsProvider::OnOpenDisc( wxCommandEvent& event )
220 Open( DISC_ACCESS, event.GetInt() );
223 void DialogsProvider::OnOpenNet( wxCommandEvent& event )
225 Open( NET_ACCESS, event.GetInt() );
228 void DialogsProvider::OnOpenSat( wxCommandEvent& event )
230 Open( SAT_ACCESS, event.GetInt() );
233 void DialogsProvider::Open( int i_access_method, int i_arg )
235 /* Show/hide the open dialog */
237 p_open_dialog = new OpenDialog( p_intf, this, i_access_method, i_arg );
241 p_open_dialog->Show( i_access_method, i_arg );
245 void DialogsProvider::OnPopupMenu( wxCommandEvent& event )
247 wxPoint mousepos = ScreenToClient( wxGetMousePosition() );
248 ::PopupMenu( p_intf, this, mousepos );