]> git.sesse.net Git - vlc/blob - modules/gui/skins/src/dialogs.cpp
346d98641d99ea549b2697b2a1c2ab963ff9a12e
[vlc] / modules / gui / skins / src / dialogs.cpp
1 /*****************************************************************************\r
2  * dialogs.cpp: Handles all the different dialog boxes we provide.\r
3  *****************************************************************************\r
4  * Copyright (C) 2003 VideoLAN\r
5  * $Id: dialogs.cpp,v 1.9 2003/07/13 14:55:17 gbazin Exp $\r
6  *\r
7  * Authors: Gildas Bazin <gbazin@netcourrier.com>\r
8  *\r
9  * This program is free software; you can redistribute it and/or modify\r
10  * it under the terms of the GNU General Public License as published by\r
11  * the Free Software Foundation; either version 2 of the License, or\r
12  * (at your option) any later version.\r
13  *\r
14  * This program is distributed in the hope that it will be useful,\r
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
17  * GNU General Public License for more details.\r
18  *\r
19  * You should have received a copy of the GNU General Public License\r
20  * along with this program; if not, write to the Free Software\r
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111,\r
22  * USA.\r
23  *****************************************************************************/\r
24 \r
25 //--- VLC -------------------------------------------------------------------\r
26 #include <vlc/vlc.h>\r
27 #include <vlc/intf.h>\r
28 \r
29 //--- SKIN ------------------------------------------------------------------\r
30 #include "../os_api.h"\r
31 #include "event.h"\r
32 #include "banks.h"\r
33 #include "theme.h"\r
34 #include "../os_theme.h"\r
35 #include "themeloader.h"\r
36 #include "window.h"\r
37 #include "vlcproc.h"\r
38 #include "skin_common.h"\r
39 #include "dialogs.h"\r
40 \r
41 /* Callback prototype */\r
42 int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,\r
43                  vlc_value_t old_val, vlc_value_t new_val, void *param );\r
44 \r
45 #if defined(MODULE_NAME_IS_basic_skins)\r
46 \r
47 // Constructor\r
48 Dialogs::Dialogs( intf_thread_t *_p_intf ){}\r
49 // Destructor\r
50 Dialogs::~Dialogs(){}\r
51 \r
52 void Dialogs::ShowOpen( bool b_play ){}\r
53 void Dialogs::ShowOpenSkin(){}\r
54 void Dialogs::ShowMessages(){}\r
55 void Dialogs::ShowPrefs(){}\r
56 void Dialogs::ShowFileInfo(){}\r
57 void Dialogs::ShowPopup(){}\r
58 \r
59 #else // !MODULE_NAME_IS_basic_skins\r
60 \r
61 #include "../../wxwindows/wxwindows.h"\r
62 #include "../../../../share/vlc32x32.xpm"       // include the graphic icon\r
63 \r
64 #define ShowOpen_Event     0\r
65 #define ShowOpenSkin_Event 1\r
66 #define ShowMessages_Event 2\r
67 #define ShowPrefs_Event    3\r
68 #define ShowFileInfo_Event 4\r
69 #define ShowPopup_Event    5\r
70 #define ExitThread_Event   99\r
71 \r
72 //---------------------------------------------------------------------------\r
73 // Local classes declarations.\r
74 //---------------------------------------------------------------------------\r
75 \r
76 DEFINE_EVENT_TYPE(wxEVT_DIALOG)\r
77 \r
78 class Instance: public wxApp\r
79 {\r
80 public:\r
81     Instance();\r
82     Instance( intf_thread_t *_p_intf );\r
83 \r
84     bool OnInit();\r
85     int  OnExit();\r
86 \r
87 private:\r
88     intf_thread_t *p_intf;\r
89 \r
90     DECLARE_EVENT_TABLE();\r
91 };\r
92 \r
93 BEGIN_EVENT_TABLE(Instance, wxApp)\r
94     EVT_COMMAND(ShowOpen_Event, wxEVT_DIALOG, Dialogs::OnShowOpen)\r
95     EVT_COMMAND(ShowOpenSkin_Event, wxEVT_DIALOG, Dialogs::OnShowOpenSkin)\r
96     EVT_COMMAND(ShowMessages_Event, wxEVT_DIALOG, Dialogs::OnShowMessages)\r
97     EVT_COMMAND(ShowPrefs_Event, wxEVT_DIALOG, Dialogs::OnShowPrefs)\r
98     EVT_COMMAND(ShowFileInfo_Event, wxEVT_DIALOG, Dialogs::OnShowFileInfo)\r
99     EVT_COMMAND(ShowPopup_Event, wxEVT_DIALOG, Dialogs::OnShowPopup)\r
100     EVT_COMMAND(ExitThread_Event, wxEVT_DIALOG, Dialogs::OnExitThread)\r
101 END_EVENT_TABLE()\r
102 \r
103 //---------------------------------------------------------------------------\r
104 // Implementation of Instance class\r
105 //---------------------------------------------------------------------------\r
106 Instance::Instance( )\r
107 {\r
108 }\r
109 \r
110 Instance::Instance( intf_thread_t *_p_intf )\r
111 {\r
112     // Initialization\r
113     p_intf = _p_intf;\r
114 }\r
115 \r
116 IMPLEMENT_APP_NO_MAIN(Instance)\r
117 \r
118 bool Instance::OnInit()\r
119 {\r
120     p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );\r
121 \r
122     // Create all the dialog boxes\r
123     p_intf->p_sys->p_dialogs->OpenDlg =\r
124         new OpenDialog( p_intf, NULL, FILE_ACCESS );\r
125     p_intf->p_sys->p_dialogs->MessagesDlg = new Messages( p_intf, NULL );\r
126     p_intf->p_sys->p_dialogs->PrefsDlg = new PrefsDialog( p_intf, NULL );\r
127     p_intf->p_sys->p_dialogs->FileInfoDlg = new FileInfo( p_intf, NULL );\r
128 \r
129     // OK, initialization is over, now the other thread can go on working...\r
130     vlc_thread_ready( p_intf->p_sys->p_dialogs->p_thread );\r
131 \r
132     /* Register callback for the intf-popupmenu variable */\r
133     playlist_t *p_playlist =\r
134         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,\r
135                                        FIND_ANYWHERE );\r
136     if( p_playlist != NULL )\r
137     {\r
138         var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB,\r
139                          p_intf->p_sys->p_dialogs );\r
140         vlc_object_release( p_playlist );\r
141     }\r
142 \r
143     /* Intercept all menu events in our custom event handler */\r
144     p_intf->p_sys->p_dialogs->OpenDlg->PushEventHandler(\r
145         new MenuEvtHandler( p_intf, NULL ) );\r
146 \r
147     return TRUE;\r
148 }\r
149 \r
150 int Instance::OnExit()\r
151 {\r
152     // Delete evertything\r
153     delete p_intf->p_sys->p_dialogs->FileInfoDlg;\r
154     delete p_intf->p_sys->p_dialogs->PrefsDlg;\r
155     delete p_intf->p_sys->p_dialogs->MessagesDlg;\r
156     delete p_intf->p_sys->p_dialogs->OpenDlg;\r
157     delete p_intf->p_sys->p_icon;\r
158 \r
159     return 0;\r
160 }\r
161 \r
162 //---------------------------------------------------------------------------\r
163 #if !defined(__BUILTIN__) && defined( WIN32 )\r
164 HINSTANCE hInstance = 0;\r
165 extern "C" BOOL WINAPI\r
166 DllMain (HANDLE hModule, DWORD fdwReason, LPVOID lpReserved)\r
167 {\r
168     hInstance = (HINSTANCE)hModule;\r
169     return TRUE;\r
170 }\r
171 #endif\r
172 \r
173 //---------------------------------------------------------------------------\r
174 // Thread callback\r
175 // We create all wxWindows dialogs in a separate thread because we don't want\r
176 // any interaction with our own message loop\r
177 //---------------------------------------------------------------------------\r
178 void SkinsDialogsThread( dialogs_thread_t *p_thread )\r
179 {\r
180 #if !defined( WIN32 )\r
181     static char  *p_args[] = { "" };\r
182 #endif\r
183     intf_thread_t *p_intf = p_thread->p_intf;\r
184 \r
185     /* Hack to pass the p_intf pointer to the new wxWindow Instance object */\r
186     wxTheApp = new Instance( p_intf );\r
187 \r
188 #if defined( WIN32 )\r
189 #if !defined(__BUILTIN__)\r
190     wxEntry( hInstance/*GetModuleHandle(NULL)*/, NULL, NULL, SW_SHOW, TRUE );\r
191 #else\r
192     wxEntry( GetModuleHandle( NULL ), NULL, NULL, SW_SHOW, TRUE );\r
193 #endif\r
194 #else\r
195     wxEntry( 1, p_args );\r
196 #endif\r
197 \r
198     return;\r
199 }\r
200 \r
201 //---------------------------------------------------------------------------\r
202 // Implementation of Dialogs class\r
203 //---------------------------------------------------------------------------\r
204 Dialogs::Dialogs( intf_thread_t *_p_intf )\r
205 {\r
206     p_intf = _p_intf;\r
207     p_intf->p_sys->p_dialogs = this;\r
208     b_popup_change = VLC_FALSE;\r
209 \r
210     p_thread = (dialogs_thread_t *)vlc_object_create( p_intf,\r
211                                                 sizeof(dialogs_thread_t) );\r
212     p_thread->p_intf = p_intf;\r
213 \r
214     // Create a new thread for wxWindows\r
215     if( vlc_thread_create( p_thread, "Skins Dialogs Thread",\r
216                            SkinsDialogsThread, 0, VLC_TRUE ) )\r
217     {\r
218         OpenDlg = NULL;\r
219         msg_Err( p_intf, "cannot create SkinsDialogsThread" );\r
220     }\r
221 }\r
222 \r
223 Dialogs::~Dialogs()\r
224 {\r
225     wxCommandEvent event( wxEVT_DIALOG, ExitThread_Event );\r
226     event.SetClientData( this );\r
227 \r
228     wxTheApp->AddPendingEvent( event );\r
229 \r
230     vlc_thread_join( p_thread );\r
231 }\r
232 \r
233 void Dialogs::ShowOpen( bool b_play )\r
234 {\r
235     wxCommandEvent event( wxEVT_DIALOG, ShowOpen_Event );\r
236     event.SetClientData( this );\r
237     event.SetInt( b_play );\r
238 \r
239     wxTheApp->AddPendingEvent( event );\r
240 }\r
241 \r
242 void Dialogs::ShowOpenSkin()\r
243 {\r
244     wxCommandEvent event( wxEVT_DIALOG, ShowOpenSkin_Event );\r
245     event.SetClientData( this );\r
246 \r
247     wxTheApp->AddPendingEvent( event );\r
248 }\r
249 \r
250 void Dialogs::ShowMessages()\r
251 {\r
252     wxCommandEvent event( wxEVT_DIALOG, ShowMessages_Event );\r
253     event.SetClientData( this );\r
254 \r
255     wxTheApp->AddPendingEvent( event );\r
256 }\r
257 \r
258 void Dialogs::ShowPrefs()\r
259 {\r
260     wxCommandEvent event( wxEVT_DIALOG, ShowPrefs_Event );\r
261     event.SetClientData( this );\r
262 \r
263     wxTheApp->AddPendingEvent( event );\r
264 }\r
265 \r
266 void Dialogs::ShowFileInfo()\r
267 {\r
268     wxCommandEvent event( wxEVT_DIALOG, ShowFileInfo_Event );\r
269     event.SetClientData( this );\r
270 \r
271     wxTheApp->AddPendingEvent( event );\r
272 }\r
273 \r
274 void Dialogs::ShowPopup()\r
275 {\r
276     wxCommandEvent event( wxEVT_DIALOG, ShowPopup_Event );\r
277     event.SetClientData( this );\r
278 \r
279     wxTheApp->AddPendingEvent( event );\r
280 }\r
281 \r
282 void Dialogs::OnShowOpen( wxCommandEvent& event )\r
283 {\r
284     Dialogs *p_dialogs = (Dialogs *)event.GetClientData();\r
285     bool b_play = event.GetInt() ? TRUE : FALSE;\r
286 \r
287     if( p_dialogs->OpenDlg->IsShown() ) return;\r
288  \r
289     if( p_dialogs->OpenDlg->ShowModal() != wxID_OK )\r
290     {\r
291         return;\r
292     }\r
293 \r
294     // Check if playlist is available\r
295     playlist_t *p_playlist = p_dialogs->p_intf->p_sys->p_playlist;\r
296     if( p_playlist == NULL )\r
297     {\r
298         return;\r
299     }\r
300 \r
301     if( b_play )\r
302     {\r
303         // Append and play\r
304         for( size_t i = 0; i < p_dialogs->OpenDlg->mrl.GetCount(); i++ )\r
305         {\r
306             playlist_Add( p_playlist,\r
307                 (const char *)p_dialogs->OpenDlg->mrl[i].mb_str(),\r
308                 PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );\r
309         }\r
310         p_dialogs->p_intf->p_sys->p_theme->EvtBank->Get( "play" )->SendEvent();\r
311     }\r
312     else\r
313     {\r
314         // Append only\r
315         for( size_t i = 0; i < p_dialogs->OpenDlg->mrl.GetCount(); i++ )\r
316         {\r
317             playlist_Add( p_playlist,\r
318                 (const char *)p_dialogs->OpenDlg->mrl[i].mb_str(),\r
319                 PLAYLIST_APPEND, PLAYLIST_END );\r
320         }\r
321     }\r
322 \r
323     // Refresh interface !\r
324     p_dialogs->p_intf->p_sys->p_theme->EvtBank->Get( "playlist_refresh" )\r
325         ->PostSynchroMessage();\r
326 \r
327     return;\r
328 }\r
329 \r
330 void Dialogs::OnShowOpenSkin( wxCommandEvent& event )\r
331 {\r
332     Dialogs *p_dialogs = (Dialogs *)event.GetClientData();\r
333     intf_thread_t *p_intf = p_dialogs->p_intf;\r
334 \r
335     wxFileDialog dialog( NULL,\r
336         wxU(_("Open a skin file")), wxT(""), wxT(""),\r
337         wxT("Skin files (*.vlt)|*.vlt|Skin files (*.xml)|*.xml|"\r
338             "All files|*.*"), wxOPEN );\r
339 \r
340     if( dialog.ShowModal() == wxID_OK )\r
341     {\r
342         p_intf->p_sys->p_new_theme_file =\r
343            new char[strlen(dialog.GetPath().mb_str()) + 1];\r
344 \r
345         strcpy( p_intf->p_sys->p_new_theme_file,\r
346                 dialog.GetPath().mb_str() );\r
347 \r
348         // Tell vlc to change skin after hiding interface\r
349         OSAPI_PostMessage( NULL, VLC_HIDE, VLC_LOAD_SKIN, 0 );\r
350     }\r
351 }\r
352 \r
353 void Dialogs::OnShowMessages( wxCommandEvent& event )\r
354 {\r
355     Dialogs *p_dialogs = (Dialogs *)event.GetClientData();\r
356     p_dialogs->MessagesDlg->Show( !p_dialogs->MessagesDlg->IsShown() );\r
357 }\r
358 \r
359 void Dialogs::OnShowPrefs( wxCommandEvent& event )\r
360 {\r
361     Dialogs *p_dialogs = (Dialogs *)event.GetClientData();\r
362     p_dialogs->PrefsDlg->Show( !p_dialogs->PrefsDlg->IsShown() );\r
363 }\r
364 \r
365 void Dialogs::OnShowFileInfo( wxCommandEvent& event )\r
366 {\r
367     Dialogs *p_dialogs = (Dialogs *)event.GetClientData();\r
368     p_dialogs->FileInfoDlg->Show( !p_dialogs->FileInfoDlg->IsShown() );\r
369 }\r
370 \r
371 void Dialogs::OnShowPopup( wxCommandEvent& event )\r
372 {\r
373     Dialogs *p_dialogs = (Dialogs *)event.GetClientData();\r
374 \r
375     wxPoint mousepos = wxGetMousePosition();\r
376 \r
377     wxMouseEvent mouseevent = wxMouseEvent( wxEVT_RIGHT_UP );\r
378     mouseevent.m_x = p_dialogs->OpenDlg->ScreenToClient(mousepos).x;\r
379     mouseevent.m_y = p_dialogs->OpenDlg->ScreenToClient(mousepos).y;\r
380 \r
381     ::PopupMenu( p_dialogs->p_intf,\r
382                  p_dialogs->OpenDlg, mouseevent.GetPosition() );\r
383 }\r
384 \r
385 void Dialogs::OnExitThread( wxCommandEvent& event )\r
386 {\r
387     wxTheApp->ExitMainLoop();\r
388 }\r
389 #endif // MODULE_NAME_IS_basic_skins\r
390 \r
391 /*****************************************************************************\r
392  * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.\r
393  *  We don't show the menu directly here because we don't want the\r
394  *  caller to block for a too long time.\r
395  *****************************************************************************/\r
396 int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,\r
397                  vlc_value_t old_val, vlc_value_t new_val, void *param )\r
398 {\r
399 #if !defined(MODULE_NAME_IS_basic_skins)\r
400     Dialogs *p_dialogs = (Dialogs *)param;\r
401 \r
402     p_dialogs->ShowPopup();\r
403 #endif\r
404 \r
405     return VLC_SUCCESS;\r
406 }\r