]> git.sesse.net Git - vlc/blob - modules/gui/wxwindows/dialogs.cpp
* modules/gui/wxwindows/*: The wxwindows interface is now a "dialogs provider" module...
[vlc] / modules / gui / wxwindows / dialogs.cpp
1 /*****************************************************************************
2  * dialogs.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2001 VideoLAN
5  * $Id: dialogs.cpp,v 1.1 2003/07/17 17:30:40 gbazin Exp $
6  *
7  * Authors: Gildas Bazin <gbazin@netcourrier.com>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <string.h>                                            /* strerror() */
30 #include <stdio.h>
31
32 #include <vlc/vlc.h>
33 #include <vlc/aout.h>
34
35 #ifdef WIN32                                                 /* mingw32 hack */
36 #undef Yield
37 #undef CreateDialog
38 #endif
39
40 /* Let vlc take care of the i18n stuff */
41 #define WXINTL_NO_GETTEXT_MACRO
42
43 #include <wx/wxprec.h>
44 #include <wx/wx.h>
45
46 #include <vlc/intf.h>
47 #include "stream_control.h"
48
49 #include "wxwindows.h"
50
51 /* include the icon graphic */
52 #include "../../../share/vlc32x32.xpm"
53
54 DEFINE_LOCAL_EVENT_TYPE( wxEVT_DIALOG );
55
56 BEGIN_EVENT_TABLE(DialogsProvider, wxFrame)
57     /* Idle loop used to update some of the dialogs */
58     EVT_IDLE(DialogsProvider::OnIdle)
59
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
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(ShowPopup_Event, wxEVT_DIALOG, DialogsProvider::OnShowPopup)
76 END_EVENT_TABLE()
77
78 /*****************************************************************************
79  * Constructor.
80  *****************************************************************************/
81 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf, wxWindow *p_parent )
82   :  wxFrame( p_parent, -1, wxT("") )
83 {
84     /* Initializations */
85     p_intf = _p_intf;
86     p_open_dialog = NULL;
87     p_file_dialog = NULL;
88     p_playlist_dialog = NULL;
89     p_messages_dialog = NULL;
90     p_fileinfo_dialog = NULL;
91     p_prefs_dialog = NULL;
92
93     /* Give our interface a nice little icon */
94     p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );
95
96     /* Create the messages dialog so it can begin storing logs */
97     p_messages_dialog = new Messages( p_intf, p_parent ? p_parent : this );
98 }
99
100 DialogsProvider::~DialogsProvider()
101 {
102     /* Clean up */
103     if( p_open_dialog )     delete p_open_dialog;
104     if( p_prefs_dialog )    p_prefs_dialog->Destroy();
105     if( p_file_dialog )     delete p_file_dialog;
106     if( p_playlist_dialog ) delete p_playlist_dialog;
107     if( p_messages_dialog ) delete p_messages_dialog;
108     if( p_fileinfo_dialog ) delete p_fileinfo_dialog;
109
110     if( p_intf->p_sys->p_icon ) delete p_intf->p_sys->p_icon;
111 }
112
113 void DialogsProvider::OnIdle( wxIdleEvent& WXUNUSED(event) )
114 {
115   /* Update the log window */
116   if( p_messages_dialog )
117     p_messages_dialog->UpdateLog();
118
119   /* Update the playlist */
120   if( p_playlist_dialog )
121     p_playlist_dialog->UpdatePlaylist();
122
123   /* Update the fileinfo windows */
124   if( p_fileinfo_dialog )
125     p_fileinfo_dialog->UpdateFileInfo();
126 }
127
128 void DialogsProvider::OnPlaylist( wxCommandEvent& WXUNUSED(event) )
129 {
130     /* Show/hide the playlist window */
131     if( !p_playlist_dialog )
132         p_playlist_dialog = new Playlist( p_intf, this );
133
134     if( p_playlist_dialog )
135     {
136         p_playlist_dialog->ShowPlaylist( !p_playlist_dialog->IsShown() );
137     }
138 }
139
140 void DialogsProvider::OnMessages( wxCommandEvent& WXUNUSED(event) )
141 {
142     /* Show/hide the log window */
143     if( !p_messages_dialog )
144         p_messages_dialog = new Messages( p_intf, this );
145
146     if( p_messages_dialog )
147     {
148         p_messages_dialog->Show( !p_messages_dialog->IsShown() );
149     }
150 }
151
152 void DialogsProvider::OnFileInfo( wxCommandEvent& WXUNUSED(event) )
153 {
154     /* Show/hide the file info window */
155     if( !p_fileinfo_dialog )
156         p_fileinfo_dialog = new FileInfo( p_intf, this );
157
158     if( p_fileinfo_dialog )
159     {
160         p_fileinfo_dialog->Show( !p_fileinfo_dialog->IsShown() );
161     }
162 }
163
164 void DialogsProvider::OnPreferences( wxCommandEvent& WXUNUSED(event) )
165 {
166     /* Show/hide the open dialog */
167     if( !p_prefs_dialog )
168         p_prefs_dialog = new PrefsDialog( p_intf, this );
169
170     if( p_prefs_dialog )
171     {
172         p_prefs_dialog->Show( !p_prefs_dialog->IsShown() );
173     }
174 }
175
176 void DialogsProvider::OnOpenFileSimple( wxCommandEvent& event )
177 {
178     playlist_t *p_playlist =
179         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
180                                        FIND_ANYWHERE );
181     if( p_playlist == NULL )
182     {
183         return;
184     }
185
186     if( p_file_dialog == NULL )
187         p_file_dialog = new wxFileDialog( this, wxU(_("Open file")),
188             wxT(""), wxT(""), wxT("*"), wxOPEN | wxMULTIPLE );
189
190     if( p_file_dialog && p_file_dialog->ShowModal() == wxID_OK )
191     {
192         wxArrayString paths;
193
194         p_file_dialog->GetPaths( paths );
195
196         for( size_t i = 0; i < paths.GetCount(); i++ )
197             if( event.GetInt() )
198                 playlist_Add( p_playlist, (const char *)paths[i].mb_str(),
199                               PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO),
200                               PLAYLIST_END );
201             else
202                 playlist_Add( p_playlist, (const char *)paths[i].mb_str(),
203                               PLAYLIST_APPEND, PLAYLIST_END );
204     }
205
206     vlc_object_release( p_playlist );
207 }
208
209 void DialogsProvider::OnOpenFile( wxCommandEvent& event )
210 {
211     Open( FILE_ACCESS, event.GetInt() );
212 }
213
214 void DialogsProvider::OnOpenDisc( wxCommandEvent& event )
215 {
216     Open( DISC_ACCESS, event.GetInt() );
217 }
218
219 void DialogsProvider::OnOpenNet( wxCommandEvent& event )
220 {
221     Open( NET_ACCESS, event.GetInt() );
222 }
223
224 void DialogsProvider::OnOpenSat( wxCommandEvent& event )
225 {
226     Open( SAT_ACCESS, event.GetInt() );
227 }
228
229 void DialogsProvider::Open( int i_access_method, int i_arg )
230 {
231     /* Show/hide the open dialog */
232     if( !p_open_dialog )
233         p_open_dialog = new OpenDialog( p_intf, this, i_access_method, i_arg );
234
235     if( p_open_dialog )
236     {
237         p_open_dialog->Show( i_access_method, i_arg );
238     }
239 }