]> git.sesse.net Git - vlc/blob - modules/gui/wince/open.cpp
Use pl_Release with the right argument.
[vlc] / modules / gui / wince / open.cpp
1 /*****************************************************************************
2  * open.cpp : WinCE gui plugin for VLC
3  *****************************************************************************
4  * Copyright (C) 2000-2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
8  *          Gildas Bazin <gbazin@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc_common.h>
33 #include <vlc_interface.h>
34
35 #include "wince.h"
36
37 #include <windowsx.h>
38 #include <commctrl.h>
39 #include <commdlg.h>
40 #include <shlobj.h>
41
42 /*****************************************************************************
43  * Event Table.
44  *****************************************************************************/
45
46 /* IDs for the controls and the menu commands */
47 enum
48 {
49     Notebook_Event = 1000,
50     MRL_Event,
51
52     FileBrowse_Event,
53     FileName_Event,
54
55     DiscType_Event,
56     DiscDevice_Event,
57     DiscTitle_Event,
58     DiscChapter_Event,
59
60     NetType_Event,
61     NetRadio1_Event, NetRadio2_Event, NetRadio3_Event, NetRadio4_Event,
62     NetPort1_Event, NetPort2_Event, NetPort3_Event,
63     NetAddr1_Event, NetAddr2_Event, NetAddr3_Event, NetAddr4_Event,
64
65     SubsFileEnable_Event,
66     SubsFileSettings_Event,
67 };
68
69 /*****************************************************************************
70  * AutoBuiltPanel.
71  *****************************************************************************/
72
73 /*****************************************************************************
74  * Constructor.
75  *****************************************************************************/
76 OpenDialog::OpenDialog( intf_thread_t *p_intf, CBaseWindow *p_parent,
77                         HINSTANCE h_inst, int _i_access, int _i_arg )
78   :  CBaseWindow( p_intf, p_parent, h_inst )
79 {
80     /* Initializations */
81     i_access = _i_access;
82     i_open_arg = _i_arg;
83
84     for( int i = 0; i < 4; i++ )
85     {
86         net_radios[i] = 0;
87         net_label[i] = 0;
88         net_port_label[i] = 0;
89         net_ports[i] = 0;
90         hUpdown[i] = 0;
91         i_net_ports[i] = 0;
92         net_addrs_label[i] = 0;
93         net_addrs[i] = 0;
94     }
95
96     CreateWindow( _T("VLC WinCE"), _T("Messages"),
97                   WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_SIZEBOX,
98                   0, 0, /*CW_USEDEFAULT*/300, /*CW_USEDEFAULT*/300,
99                   p_parent->GetHandle(), NULL, h_inst, (void *)this );
100 }
101
102 /***********************************************************************
103
104 FUNCTION:
105   WndProc
106
107 PURPOSE:
108   Processes messages sent to the main window.
109  
110 ***********************************************************************/
111 LRESULT OpenDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
112 {
113     SHINITDLGINFO shidi;
114     INITCOMMONCONTROLSEX  iccex;  // INITCOMMONCONTROLSEX structure
115     RECT rcClient;
116     TC_ITEM tcItem;
117
118     switch( msg )
119     {
120     case WM_CREATE:
121         shidi.dwMask = SHIDIM_FLAGS;
122         shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_FULLSCREENNOMENUBAR;
123         shidi.hDlg = hwnd;
124         SHInitDialog( &shidi );
125
126         // Get the client area rect to put the panels in
127         GetClientRect( hwnd, &rcClient );
128
129         /* Create MRL combobox */
130         mrl_box = CreateWindow( _T("STATIC"),
131                                 _FROMMB(_("Media Resource Locator (MRL)")),
132                                 WS_CHILD | WS_VISIBLE | SS_LEFT,
133                                 5, 10, rcClient.right, 15, hwnd, 0, hInst, 0 );
134
135         mrl_label = CreateWindow( _T("STATIC"), _FROMMB(_("Open:")),
136                                   WS_CHILD | WS_VISIBLE | SS_LEFT,
137                                   5, 10 + 15 + 10, 40, 15, hwnd, 0, hInst, 0 );
138
139         mrl_combo = CreateWindow( _T("COMBOBOX"), _T(""),
140                                   WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL |
141                                   CBS_SORT | WS_VSCROLL, 45, 10 + 15 + 10 - 3,
142                                   rcClient.right - 50 - 5, 5*15 + 6, hwnd,
143                                   0, hInst, 0 );
144
145         // No tooltips for ComboBox
146         label = CreateWindow( _T("STATIC"),
147                               _FROMMB(_("Alternatively, you can build an MRL "
148                                        "using one of the following predefined "
149                                        "targets:" )),
150                               WS_CHILD | WS_VISIBLE | SS_LEFT,
151                               5, 10 + 2*(15 + 10), rcClient.right - 2*5, 2*15,
152                               hwnd, 0, hInst, 0 );
153
154         /* Create notebook */
155         iccex.dwSize = sizeof (INITCOMMONCONTROLSEX);
156         iccex.dwSize = ICC_TAB_CLASSES;
157         InitCommonControlsEx (&iccex);
158
159         notebook = CreateWindowEx( 0, WC_TABCONTROL, NULL,
160             WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE,
161             5, 10 + 4*15 + 2*10, rcClient.right - 2*5,
162             rcClient.bottom - MENU_HEIGHT - 15 - 10 - 10 - (10 + 4*15 + 2*10),
163             hwnd, NULL, hInst, NULL );
164
165         tcItem.mask = TCIF_TEXT;
166         tcItem.pszText = _T("File");
167         TabCtrl_InsertItem( notebook, 0, &tcItem );
168         tcItem.pszText = _T("Network");
169         TabCtrl_InsertItem( notebook, 1, &tcItem );
170
171         switch( i_access )
172         {
173         case FILE_ACCESS:
174             TabCtrl_SetCurSel( notebook, 0 );
175             break;
176         case NET_ACCESS:
177             TabCtrl_SetCurSel( notebook, 1 );
178             break;
179         }
180
181         FilePanel( hwnd );
182         NetPanel( hwnd );
183
184         OnPageChange();
185         break;
186
187     case WM_CLOSE:
188         Show( FALSE );
189         return TRUE;
190
191     case WM_SETFOCUS:
192         SHFullScreen( hwnd, SHFS_SHOWSIPBUTTON );
193         SHSipPreference( hwnd, SIP_DOWN );
194         break;
195
196     case WM_COMMAND:
197         if( LOWORD(wp) == IDOK )
198         {
199             OnOk();
200             Show( FALSE );
201             break;
202         }
203         if( HIWORD(wp) == BN_CLICKED )
204         {
205             if( (HWND)lp == net_radios[0] )
206             {
207                 OnNetTypeChange( NetRadio1_Event );
208             } else if( (HWND)lp == net_radios[1] )
209             {
210                 OnNetTypeChange( NetRadio2_Event );
211             } else if( (HWND)lp == net_radios[2] )
212             {
213                 OnNetTypeChange( NetRadio3_Event );
214             } else if( (HWND)lp == net_radios[3] )
215             {
216                 OnNetTypeChange( NetRadio4_Event );
217             } else if( (HWND)lp == subsfile_checkbox )
218             {
219                 OnSubsFileEnable();
220             } else if( (HWND)lp == subsfile_button )
221             {
222                 OnSubsFileSettings( hwnd );
223             } else if( (HWND)lp == browse_button )
224             {
225                 OnFileBrowse();
226             }
227             break;
228         }
229         if( HIWORD(wp) == EN_CHANGE )
230         {
231             if( (HWND)lp == net_addrs[1] )
232             {
233                 OnNetPanelChange( NetAddr2_Event );
234             } else if( (HWND)lp == net_addrs[2] )
235             {
236                 OnNetPanelChange( NetAddr3_Event );
237             } else if( (HWND)lp == net_addrs[3] )
238             {
239                 OnNetPanelChange( NetAddr4_Event );
240             } else if( (HWND)lp == net_ports[0] )
241             {
242                 OnNetPanelChange( NetPort1_Event );
243             } else if( (HWND)lp == net_ports[1] )
244             {
245                 OnNetPanelChange( NetPort2_Event );
246             }
247         }
248         if( HIWORD(wp) == CBN_EDITUPDATE )
249         {
250             if ((HWND)lp == file_combo)
251             {
252                 OnFilePanelChange();
253             }
254         }
255         break;
256
257     case WM_NOTIFY:
258         if( (((NMHDR *)lp)->code) == TCN_SELCHANGE ) OnPageChange();
259         break;
260
261     default:
262         break;
263     }
264
265     return DefWindowProc( hwnd, msg, wp, lp );
266 }
267
268 /*****************************************************************************
269  * Private methods.
270  *****************************************************************************/
271 void OpenDialog::FilePanel( HWND hwnd )
272 {
273     RECT rc;
274     GetWindowRect( notebook, &rc );
275
276     /* Create browse file line */
277     file_combo = CreateWindow( _T("COMBOBOX"), _T(""),
278         WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL,
279         rc.left + 10, rc.top + 10 - 3, rc.right - 10 - (rc.left + 10),
280         5*15 + 6, hwnd, NULL, hInst, NULL );
281
282     browse_button = CreateWindow( _T("BUTTON"), _T("Browse..."),
283         WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
284         rc.left + 10, rc.top + 10 + 15 + 10 - 3, 80, 15 + 6,
285         hwnd, NULL, hInst, NULL );
286
287     /* Create Subtitles File checkox */
288     subsfile_checkbox = CreateWindow( _T("BUTTON"), _T("Subtitle options"),
289         WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
290         rc.left + 10, rc.top + 10 + 2*(15 + 10), 15, 15,
291         hwnd, NULL, hInst, NULL );
292     SendMessage( subsfile_checkbox, BM_SETCHECK, BST_UNCHECKED, 0 );
293
294     subsfile_label = CreateWindow( _T("STATIC"), _T("Subtitle options"),
295                 WS_CHILD | WS_VISIBLE | SS_LEFT,
296                 rc.left + 10 + 15 + 10, rc.top + 10 + 2*(15 + 10), 100, 15,
297                 hwnd, NULL, hInst, NULL);
298
299     subsfile_button = CreateWindow( _T("BUTTON"), _T("Settings..."),
300                 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_DISABLED,
301                 rc.right - 80 - 10, rc.top + 10 + 2*(15 + 10) - 3, 80, 15 + 6,
302                 hwnd, NULL, hInst, NULL );
303
304     char *psz_subsfile = config_GetPsz( p_intf, "sub-file" );
305     if( psz_subsfile && *psz_subsfile )
306     {
307         SendMessage( subsfile_checkbox, BM_SETCHECK, BST_CHECKED, 0 );
308         EnableWindow( subsfile_button, TRUE );
309         string sz_subsfile = "sub-file=";
310         sz_subsfile += psz_subsfile;
311         subsfile_mrl.push_back( sz_subsfile );
312     }
313     free( psz_subsfile );
314 }
315
316 void OpenDialog::NetPanel( HWND hwnd )
317 {
318     INITCOMMONCONTROLSEX ic;
319     TCHAR psz_text[256];
320
321     struct net_type
322     {
323         TCHAR *psz_text;
324         int length;
325     };
326
327     static struct net_type net_type_array[] =
328     {
329         { _T("UDP/RTP"), 82 },
330         { _T("UDP/RTP Multicast"), 140 },
331         { _T("HTTP/FTP/MMS"), 90 },
332         { _T("RTSP"), 30 }
333     };
334
335     RECT rc;
336     GetWindowRect( notebook, &rc);
337
338     /* UDP/RTP row */
339     net_radios[0] = CreateWindow( _T("BUTTON"), net_type_array[0].psz_text,
340                 WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
341                 rc.left + 5, rc.top + 10, 15, 15, hwnd, NULL, hInst, NULL );
342
343     net_label[0] = CreateWindow( _T("STATIC"), net_type_array[0].psz_text,
344                 WS_CHILD | WS_VISIBLE | SS_LEFT,
345                 rc.left + 5 + 15 + 5, rc.top + 10, net_type_array[0].length,
346                 15, hwnd, NULL, hInst, NULL );
347
348     i_net_ports[0] = config_GetInt( p_intf, "server-port" );
349
350     net_port_label[0] = CreateWindow( _T("STATIC"), _T("Port"),
351                 WS_CHILD | WS_VISIBLE | SS_LEFT,
352                 rc.left + 5 , rc.top + 10 + 2*(15 + 10), 30, 15,
353                 hwnd, NULL, hInst, NULL );
354
355     _stprintf( psz_text, _T("%d"), i_net_ports[0] );
356     net_ports[0] = CreateWindow( _T("EDIT"), psz_text,
357         WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
358         rc.left + 5 + 30 + 5, rc.top + 10 + 2*(15 + 10) - 3,
359         rc.right - 5 - (rc.left + 5 + 30 + 5), 15 + 6, hwnd, NULL, hInst, NULL );
360
361     ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
362     ic.dwICC = ICC_UPDOWN_CLASS;
363     InitCommonControlsEx(&ic);
364
365     hUpdown[0] = CreateUpDownControl(
366                 WS_CHILD | WS_VISIBLE | WS_BORDER | UDS_ALIGNRIGHT |
367                 UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
368                 0, 0, 0, 0, hwnd, 0, hInst,
369                 net_ports[0], 16000, 0, i_net_ports[0]);
370
371     /* UDP/RTP Multicast row */
372     net_radios[1] = CreateWindow( _T("BUTTON"), net_type_array[1].psz_text,
373                 WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
374                 rc.left + 5, rc.top + 10 + 15 + 10, 15, 15,
375                 hwnd, NULL, hInst, NULL);
376
377     net_label[1] = CreateWindow( _T("STATIC"), net_type_array[1].psz_text,
378                 WS_CHILD | WS_VISIBLE | SS_LEFT,
379                 rc.left + 5 + 15 + 5, rc.top + 10 + 15 + 10,
380                 net_type_array[1].length, 15, hwnd, NULL, hInst, NULL );
381
382     net_addrs_label[1] = CreateWindow( _T("STATIC"), _T("Address"),
383                 WS_CHILD | WS_VISIBLE | SS_LEFT,
384                 rc.left + 5 , rc.top + 10 + 2*(15 + 10), 50, 15,
385                 hwnd, NULL, hInst, NULL);
386
387     net_addrs[1] = CreateWindow( _T("EDIT"), _T(""),
388                 WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
389                 rc.left + 5 + 50 + 5, rc.top + 10 + 2*(15 + 10) - 3,
390                 rc.right - 5 - (rc.left + 5 + 50 + 5), 15 + 6,
391                 hwnd, NULL, hInst, NULL);
392
393     net_port_label[1] = CreateWindow( _T("STATIC"), _T("Port"),
394                 WS_CHILD | WS_VISIBLE | SS_LEFT,
395                 rc.left + 5 , rc.top + 10 + 3*(15 + 10), 30, 15,
396                 hwnd, NULL, hInst, NULL);
397
398     i_net_ports[1] = i_net_ports[0];
399
400     _stprintf( psz_text, _T("%d"), i_net_ports[1] );
401     net_ports[1] = CreateWindow( _T("EDIT"), psz_text,
402                 WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
403                 rc.left + 5 + 30 + 5, rc.top + 10 + 3*(15 + 10) - 3,
404                 rc.right - 5 -(rc.left + 5 + 30 + 5), 15 + 6,
405                 hwnd, NULL, hInst, NULL );
406
407     ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
408     ic.dwICC = ICC_UPDOWN_CLASS;
409     InitCommonControlsEx(&ic);
410
411     hUpdown[1] = CreateUpDownControl( WS_CHILD | WS_VISIBLE | WS_BORDER |
412         UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
413         0, 0, 0, 0, hwnd, 0, hInst,
414         net_ports[1], 16000, 0, i_net_ports[1] );
415
416     /* HTTP and RTSP rows */
417     net_radios[2] = CreateWindow( _T("BUTTON"), net_type_array[2].psz_text,
418         WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
419         rc.left + 5 + 15 + 5 + net_type_array[0].length + 5,
420         rc.top + 10, 15, 15, hwnd, NULL, hInst, NULL );
421  
422     net_label[2] = CreateWindow( _T("STATIC"), net_type_array[2].psz_text,
423         WS_CHILD | WS_VISIBLE | SS_LEFT,
424         rc.left + 5 + 15 + 5 + net_type_array[0].length + 5 + 15 + 5,
425         rc.top + 10, net_type_array[2].length, 15,
426         hwnd, NULL, hInst, NULL );
427
428     net_addrs_label[2] = CreateWindow( _T("STATIC"), _T("URL"),
429         WS_CHILD | WS_VISIBLE | SS_LEFT,
430         rc.left + 5 , rc.top + 10 + 2*(15 + 10), 30, 15,
431         hwnd, NULL, hInst, NULL );
432
433     net_addrs[2] = CreateWindow( _T("EDIT"), _T(""),
434         WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
435         rc.left + 5 + 30 + 5, rc.top + 10 + 2*(15 + 10) - 3,
436         rc.right - 5 - (rc.left + 5 + 30 + 5), 15 + 6,
437         hwnd, NULL, hInst, NULL);
438
439     net_radios[3] = CreateWindow( _T("BUTTON"), net_type_array[3].psz_text,
440         WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
441         rc.left + 5 + 15 + 5 + net_type_array[1].length + 5,
442         rc.top + 10 + 15 + 10, 15, 15, hwnd, NULL, hInst, NULL );
443
444     net_label[3] = CreateWindow( _T("STATIC"), net_type_array[3].psz_text,
445         WS_CHILD | WS_VISIBLE | SS_LEFT,
446         rc.left + 5 + 15 + 5 + net_type_array[1].length + 5 + 15 + 5,
447         rc.top + 10 + 15 + 10, net_type_array[3].length, 15,
448         hwnd, NULL, hInst, NULL );
449
450     net_addrs_label[3] = CreateWindow( _T("STATIC"), _T("URL"),
451         WS_CHILD | WS_VISIBLE | SS_LEFT,
452         rc.left + 5 , rc.top + 10 + 2*(15 + 10), 30, 15,
453         hwnd, NULL, hInst, NULL );
454
455     net_addrs[3] = CreateWindow( _T("EDIT"), _T("rtsp://"),
456         WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
457         rc.left + 5 + 30 + 5, rc.top + 10 + 2*(15 + 10) - 3,
458         rc.right - 5 - (rc.left + 5 + 30 + 5), 15 + 6,
459         hwnd, NULL, hInst, NULL );
460
461     SendMessage( net_radios[0], BM_SETCHECK, BST_CHECKED, 0 );
462 }
463
464 void OpenDialog::UpdateMRL()
465 {
466     UpdateMRL( i_access );
467 }
468
469 void OpenDialog::UpdateMRL( int i_access_method )
470 {
471     string demux, mrltemp;
472     TCHAR psz_text[2048];
473     char psz_tmp[256];
474
475     i_access = i_access_method;
476
477     switch( i_access_method )
478     {
479     case FILE_ACCESS:
480         GetWindowText( file_combo, psz_text, 2048 );
481         mrltemp = _TOMB(psz_text);
482         break;
483     case NET_ACCESS:
484         switch( i_net_type )
485         {
486         case 0:
487             mrltemp = "udp" + demux + "://";
488             if( i_net_ports[0] !=
489                 config_GetInt( p_intf, "server-port" ) )
490             {
491                 sprintf( psz_tmp, "@:%d", i_net_ports[0] );
492                 mrltemp += psz_tmp;
493             }
494             break;
495
496         case 1:
497             mrltemp = "udp" + demux + "://@";
498             Edit_GetText( net_addrs[1], psz_text, 2048 );
499             mrltemp += _TOMB(psz_text);
500             if( i_net_ports[1] != config_GetInt( p_intf, "server-port" ) )
501             {
502                 sprintf( psz_tmp, ":%d", i_net_ports[1] );
503                 mrltemp += psz_tmp;
504             }
505             break;
506
507         case 2:
508             /* http access */
509             Edit_GetText( net_addrs[2], psz_text, 2048 );
510             if( !strstr( _TOMB(psz_text), "http://" ) )
511             {
512                 mrltemp = "http" + demux + "://";
513             }
514             mrltemp += _TOMB(psz_text);
515             break;
516
517         case 3:
518             /* RTSP access */
519             Edit_GetText( net_addrs[3], psz_text, 2048 );
520             if( !strstr( _TOMB(psz_text), "rtsp://" ) )
521             {
522                 mrltemp = "rtsp" + demux + "://";
523             }
524             mrltemp += _TOMB(psz_text);
525             break;
526         }
527         break;
528     default:
529         break;
530     }
531
532     SetWindowText( mrl_combo, _FROMMB(mrltemp.c_str()) );
533 }
534
535 void OpenDialog::OnPageChange()
536 {
537     if( TabCtrl_GetCurSel( notebook ) == 0 )
538     {
539         for( int i=0; i<4; i++ )
540         {
541             SetWindowPos( net_radios[i], HWND_BOTTOM, 0, 0, 0, 0,
542                           SWP_NOMOVE | SWP_NOSIZE );
543             SetWindowPos( net_label[i], HWND_BOTTOM, 0, 0, 0, 0,
544                           SWP_NOMOVE | SWP_NOSIZE );
545         }
546         DisableNETCtrl();
547
548         SetWindowPos( file_combo, HWND_TOP, 0, 0, 0, 0,
549                       SWP_NOMOVE | SWP_NOSIZE );
550         SetWindowPos( browse_button, HWND_TOP, 0, 0, 0, 0,
551                       SWP_NOMOVE | SWP_NOSIZE );
552         SetWindowPos( subsfile_checkbox, HWND_TOP, 0, 0, 0, 0,
553                       SWP_NOMOVE | SWP_NOSIZE );
554         SetWindowPos( subsfile_label, HWND_TOP, 0, 0, 0, 0,
555                       SWP_NOMOVE | SWP_NOSIZE );
556         SetWindowPos( subsfile_button, HWND_TOP, 0, 0, 0, 0,
557                       SWP_NOMOVE | SWP_NOSIZE );
558
559         i_access = FILE_ACCESS;
560     }
561     else if ( TabCtrl_GetCurSel( notebook ) == 1 )
562     {
563         SetWindowPos( file_combo, HWND_BOTTOM, 0, 0, 0, 0,
564                       SWP_NOMOVE | SWP_NOSIZE );
565         SetWindowPos( browse_button, HWND_BOTTOM, 0, 0, 0, 0,
566                       SWP_NOMOVE | SWP_NOSIZE );
567         SetWindowPos( subsfile_checkbox, HWND_BOTTOM, 0, 0, 0, 0,
568                       SWP_NOMOVE | SWP_NOSIZE );
569         SetWindowPos( subsfile_label, HWND_BOTTOM, 0, 0, 0, 0,
570                       SWP_NOMOVE | SWP_NOSIZE );
571         SetWindowPos( subsfile_button, HWND_BOTTOM, 0, 0, 0, 0,
572                       SWP_NOMOVE | SWP_NOSIZE );
573
574         for( int i=0; i<4; i++ )
575         {
576             SetWindowPos( net_radios[i], HWND_TOP, 0, 0, 0, 0,
577                           SWP_NOMOVE | SWP_NOSIZE );
578             SendMessage( net_radios[i], BM_SETCHECK, BST_UNCHECKED, 0 );
579             SetWindowPos( net_label[i], HWND_TOP, 0, 0, 0, 0,
580                           SWP_NOMOVE | SWP_NOSIZE );
581         }
582         SetWindowPos( net_port_label[0], HWND_TOP, 0, 0, 0, 0,
583                       SWP_NOMOVE | SWP_NOSIZE );
584         SetWindowPos( net_ports[0], HWND_TOP, 0, 0, 0, 0,
585                       SWP_NOMOVE | SWP_NOSIZE );
586         SetWindowPos( hUpdown[0], HWND_TOP, 0, 0, 0, 0,
587                       SWP_NOMOVE | SWP_NOSIZE );
588
589         SendMessage( net_radios[0], BM_SETCHECK, BST_CHECKED, 0 );
590
591         i_access = NET_ACCESS;
592     }
593
594     UpdateMRL();
595 }
596
597 void OpenDialog::OnOk()
598 {
599     TCHAR psz_text[2048];
600
601     GetWindowText( mrl_combo, psz_text, 2048 );
602
603     int i_args;
604     char **pp_args = vlc_parse_cmdline( _TOMB(psz_text), &i_args );
605
606     ComboBox_AddString( mrl_combo, psz_text );
607     if( ComboBox_GetCount( mrl_combo ) > 10 )
608         ComboBox_DeleteString( mrl_combo, 0 );
609     ComboBox_SetCurSel( mrl_combo, ComboBox_GetCount( mrl_combo ) - 1 );
610
611     /* Update the playlist */
612     playlist_t *p_playlist = pl_Yield( p_intf );
613     if( p_playlist == NULL ) return;
614
615     for( int i = 0; i < i_args; i++ )
616     {
617         bool b_start = !i && i_open_arg;
618         playlist_item_t *p_item =
619             playlist_ItemNew( p_playlist, pp_args[i], pp_args[i] );
620
621         /* Insert options */
622         while( i + 1 < i_args && pp_args[i + 1][0] == ':' )
623         {
624             playlist_ItemAddOption( p_item, pp_args[i + 1] );
625             i++;
626         }
627
628         /* Get the options from the subtitles dialog */
629         if( (SendMessage( subsfile_checkbox, BM_GETCHECK, 0, 0 ) & BST_CHECKED)
630             && subsfile_mrl.size() )
631         {
632             for( int j = 0; j < (int)subsfile_mrl.size(); j++ )
633             {
634                 playlist_ItemAddOption( p_item, subsfile_mrl[j].c_str() );
635             }
636         }
637
638
639         if( b_start )
640         {
641             playlist_AddItem( p_playlist, p_item,
642                               PLAYLIST_APPEND|PLAYLIST_GO, PLAYLIST_END );
643         }
644         else
645         {
646             playlist_AddItem( p_playlist, p_item,
647                               PLAYLIST_APPEND, PLAYLIST_END );
648         }
649     }
650
651     //TogglePlayButton( PLAYING_S );
652
653     while( i_args-- )
654     {
655         free( pp_args[i_args] );
656         if( !i_args ) free( pp_args );
657     }
658     pl_Release( p_intf );
659 }
660
661 /*****************************************************************************
662  * File panel event methods.
663  *****************************************************************************/
664 void OpenDialog::OnFilePanelChange()
665 {
666     UpdateMRL( FILE_ACCESS );
667 }
668
669 static void OnOpenCB( intf_dialog_args_t *p_arg )
670 {
671     OpenDialog *p_this = (OpenDialog *)p_arg->p_arg;
672     char psz_tmp[PATH_MAX+2] = "\0";
673
674     if( p_arg->i_results && p_arg->psz_results[0] )
675     {
676         if( strchr( p_arg->psz_results[0], ' ' ) )
677         {
678             strcat( psz_tmp, "\"" );
679             strcat( psz_tmp, p_arg->psz_results[0] );
680             strcat( psz_tmp, "\"" );
681         }
682         else strcat( psz_tmp, p_arg->psz_results[0] );
683
684         SetWindowText( p_this->file_combo, _FROMMB(psz_tmp) );
685         ComboBox_AddString( p_this->file_combo, _FROMMB(psz_tmp) );
686         if( ComboBox_GetCount( p_this->file_combo ) > 10 )
687             ComboBox_DeleteString( p_this->file_combo, 0 );
688
689         p_this->UpdateMRL( FILE_ACCESS );
690     }
691 }
692
693 void OpenDialog::OnFileBrowse()
694 {
695     intf_dialog_args_t *p_arg =
696         (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
697     memset( p_arg, 0, sizeof(intf_dialog_args_t) );
698
699     p_arg->psz_title = strdup( "Open file" );
700     p_arg->psz_extensions = strdup( "All (*.*)|*.*" );
701     p_arg->p_arg = this;
702     p_arg->pf_callback = OnOpenCB;
703
704     p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_GENERIC, 0, p_arg);
705 }
706
707 /*****************************************************************************
708  * Net panel event methods.
709  *****************************************************************************/
710 void OpenDialog::OnNetPanelChange( int event )
711 {
712     TCHAR psz_text[2048];
713     int port;
714
715     if( event >= NetPort1_Event && event <= NetPort2_Event )
716     {
717         Edit_GetText( net_ports[event - NetPort1_Event], psz_text, 2048 );
718         _stscanf( psz_text, _T("%d"), &port );
719         i_net_ports[event - NetPort1_Event] = port;
720     }
721
722     UpdateMRL( NET_ACCESS );
723 }
724
725 void OpenDialog::OnNetTypeChange( int event )
726 {
727     DisableNETCtrl();
728
729     i_net_type = event - NetRadio1_Event;
730
731     if( event == NetRadio1_Event )
732     {
733         SetWindowPos( net_port_label[0], HWND_TOP, 0, 0, 0, 0,
734                       SWP_NOMOVE | SWP_NOSIZE );
735         SetWindowPos( net_ports[0], HWND_TOP, 0, 0, 0, 0,
736                       SWP_NOMOVE | SWP_NOSIZE );
737         SetWindowPos( hUpdown[0], HWND_TOP, 0, 0, 0, 0,
738                       SWP_NOMOVE | SWP_NOSIZE );
739     }
740     else if( event == NetRadio2_Event )
741     {
742         SetWindowPos( net_addrs_label[1], HWND_TOP, 0, 0, 0, 0,
743                       SWP_NOMOVE | SWP_NOSIZE );
744         SetWindowPos( net_addrs[1], HWND_TOP, 0, 0, 0, 0,
745                       SWP_NOMOVE | SWP_NOSIZE );
746         SetWindowPos( net_port_label[1], HWND_TOP, 0, 0, 0, 0,
747                       SWP_NOMOVE | SWP_NOSIZE );
748         SetWindowPos( net_ports[1], HWND_TOP, 0, 0, 0, 0,
749                       SWP_NOMOVE | SWP_NOSIZE );
750         SetWindowPos( hUpdown[1], HWND_TOP, 0, 0, 0, 0,
751                       SWP_NOMOVE | SWP_NOSIZE );
752     }
753     else if( event == NetRadio3_Event )
754     {
755         SetWindowPos( net_addrs_label[2], HWND_TOP, 0, 0, 0, 0,
756                       SWP_NOMOVE | SWP_NOSIZE );
757         SetWindowPos( net_addrs[2], HWND_TOP, 0, 0, 0, 0,
758                       SWP_NOMOVE | SWP_NOSIZE );
759     }
760     else if( event == NetRadio4_Event )
761     {
762         SetWindowPos( net_addrs_label[3], HWND_TOP, 0, 0, 0, 0,
763                       SWP_NOMOVE | SWP_NOSIZE );
764         SetWindowPos( net_addrs[3], HWND_TOP, 0, 0, 0, 0,
765                       SWP_NOMOVE | SWP_NOSIZE );
766     }
767  
768     UpdateMRL( NET_ACCESS );
769 }
770
771 void OpenDialog::DisableNETCtrl()
772 {
773     for( int i=0; i<4; i++ )
774     {
775         SetWindowPos( net_port_label[i], HWND_BOTTOM, 0, 0, 0, 0,
776                       SWP_NOMOVE | SWP_NOSIZE );
777         SetWindowPos( net_ports[i], HWND_BOTTOM, 0, 0, 0, 0,
778                       SWP_NOMOVE | SWP_NOSIZE );
779         SetWindowPos( hUpdown[i], HWND_BOTTOM, 0, 0, 0, 0,
780                       SWP_NOMOVE | SWP_NOSIZE );
781         SetWindowPos( net_addrs_label[i], HWND_BOTTOM, 0, 0, 0, 0,
782                       SWP_NOMOVE | SWP_NOSIZE );
783         SetWindowPos( net_addrs[i], HWND_BOTTOM, 0, 0, 0, 0,
784                       SWP_NOMOVE | SWP_NOSIZE );
785     }
786
787     UpdateMRL( FILE_ACCESS );
788 }
789
790 /*****************************************************************************
791  * Subtitles file event methods.
792  *****************************************************************************/
793 void OpenDialog::OnSubsFileEnable()
794 {
795     EnableWindow( subsfile_button, ( SendMessage( subsfile_checkbox,
796                   BM_GETCHECK, 0, 0 ) & BST_CHECKED ) ? TRUE : FALSE );
797 }
798
799 void OpenDialog::OnSubsFileSettings( HWND hwnd )
800 {
801
802     /* Show/hide the open dialog */
803     SubsFileDialog *subsfile_dialog = new SubsFileDialog( p_intf, this, hInst);
804     CreateDialogBox(  hwnd, subsfile_dialog );
805
806     subsfile_mrl.clear();
807
808     for( int i = 0; i < (int)subsfile_dialog->subsfile_mrl.size(); i++ )
809         subsfile_mrl.push_back( subsfile_dialog->subsfile_mrl[i] );
810
811     delete subsfile_dialog;
812 }