]> git.sesse.net Git - vlc/blob - plugins/win32/network.cpp
* Fixed a stupid bug in the Network dialog.
[vlc] / plugins / win32 / network.cpp
1 /*****************************************************************************\r
2  * network.cpp: the "network" dialog box\r
3  *****************************************************************************\r
4  * Copyright (C) 2002 VideoLAN\r
5  *\r
6  * Authors: Olivier Teuliere <ipkiss@via.ecp.fr>\r
7  *\r
8  * This program is free software; you can redistribute it and/or modify\r
9  * it under the terms of the GNU General Public License as published by\r
10  * the Free Software Foundation; either version 2 of the License, or\r
11  * (at your option) any later version.\r
12  * \r
13  * This program is distributed in the hope that it will be useful,\r
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
16  * GNU General Public License for more details.\r
17  *\r
18  * You should have received a copy of the GNU General Public License\r
19  * along with this program; if not, write to the Free Software\r
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.\r
21  *****************************************************************************/\r
22 \r
23 #include <vcl.h>\r
24 #pragma hdrstop\r
25 \r
26 #include <videolan/vlc.h>\r
27 \r
28 #include "stream_control.h"\r
29 #include "input_ext-intf.h"\r
30 \r
31 #include "interface.h"\r
32 #include "intf_playlist.h"\r
33 \r
34 #include "network.h"\r
35 #include "win32_common.h"\r
36 \r
37 #include "netutils.h"\r
38 \r
39 //---------------------------------------------------------------------------\r
40 //#pragma package(smart_init)\r
41 #pragma resource "*.dfm"\r
42 \r
43 extern struct intf_thread_s *p_intfGlobal;\r
44 \r
45 //---------------------------------------------------------------------------\r
46 __fastcall TNetworkDlg::TNetworkDlg( TComponent* Owner )\r
47         : TForm( Owner )\r
48 {\r
49         char *psz_channel_server;\r
50 \r
51         OldRadioValue = 0;\r
52 \r
53         /* server port */\r
54         UpDownUDPPort->Position = config_GetIntVariable( "server-port" );\r
55         UpDownMulticastPort->Position = config_GetIntVariable( "server-port" );\r
56 \r
57         /* channel server */\r
58         if( config_GetIntVariable( "network-channel" ) )\r
59         {\r
60             RadioButtonCS->Checked = true;\r
61             RadioButtonCSEnter( RadioButtonCS );\r
62         }\r
63 \r
64         psz_channel_server = config_GetPszVariable( "channel-server" );\r
65         if( psz_channel_server )\r
66         {\r
67             ComboBoxCSAddress->Text = psz_channel_server;\r
68             free( psz_channel_server );\r
69         }\r
70 \r
71         UpDownCSPort->Position = config_GetIntVariable( "channel-port" );\r
72 }\r
73 //---------------------------------------------------------------------------\r
74 void __fastcall TNetworkDlg::FormShow( TObject *Sender )\r
75 {\r
76     p_intfGlobal->p_sys->p_window->MenuNetworkStream->Checked = true;\r
77     p_intfGlobal->p_sys->p_window->PopupNetworkStream->Checked = true;\r
78 }\r
79 //---------------------------------------------------------------------------\r
80 void __fastcall TNetworkDlg::FormHide( TObject *Sender )\r
81 {\r
82     p_intfGlobal->p_sys->p_window->MenuNetworkStream->Checked = false;\r
83     p_intfGlobal->p_sys->p_window->PopupNetworkStream->Checked = false;\r
84 }\r
85 //---------------------------------------------------------------------------\r
86 void __fastcall TNetworkDlg::BitBtnCancelClick( TObject *Sender )\r
87 {\r
88     Hide();\r
89 }\r
90 //---------------------------------------------------------------------------\r
91 void __fastcall TNetworkDlg::BitBtnOkClick( TObject *Sender )\r
92 {\r
93     AnsiString      Source, Address;\r
94     AnsiString      Channel = ComboBoxCSAddress->Text;\r
95     unsigned int    i_channel_port = UpDownCSPort->Position;\r
96     unsigned int    i_port;\r
97     int             i_end = p_main->p_playlist->i_size;\r
98 \r
99     Hide();\r
100 \r
101     /* select added item */\r
102     if( p_input_bank->pp_input[0] != NULL )\r
103     {\r
104         p_input_bank->pp_input[0]->b_eof = 1;\r
105     }\r
106 \r
107     /* Check which option was chosen */\r
108     switch( OldRadioValue )\r
109     {\r
110         /* UDP */\r
111         case 0:\r
112             config_PutIntVariable( "network-channel", FALSE );\r
113             i_port = UpDownUDPPort->Position;\r
114 \r
115             /* Build source name */\r
116             Source = "udp:@:" + IntToStr( i_port );\r
117 \r
118             intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, Source.c_str() );\r
119 \r
120             /* update the display */\r
121             p_intfGlobal->p_sys->p_playlist->UpdateGrid( p_main->p_playlist );\r
122 \r
123             intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );\r
124             break;\r
125 \r
126         /* UDP Multicast */\r
127         case 1:\r
128             config_PutIntVariable( "network-channel", FALSE );\r
129             Address = ComboBoxMulticastAddress->Text;\r
130             i_port = UpDownMulticastPort->Position;\r
131 \r
132             /* Build source name */\r
133             Source = "udp:@" + Address + ":" + IntToStr( i_port );\r
134 \r
135             intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, Source.c_str() );\r
136 \r
137             /* update the display */\r
138             p_intfGlobal->p_sys->p_playlist->UpdateGrid( p_main->p_playlist );\r
139 \r
140             intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );\r
141             break;\r
142 \r
143         /* Channel server */\r
144         case 2:\r
145             config_PutIntVariable( "network-channel", TRUE );\r
146             config_PutPszVariable( "channel-server", Channel.c_str() );\r
147             config_PutIntVariable( "channel-port", i_channel_port );\r
148 \r
149             if( p_main->p_channel == NULL )\r
150             {\r
151                 network_ChannelCreate();\r
152             }\r
153 \r
154             p_intfGlobal->p_sys->b_playing = 1;\r
155             break;\r
156 \r
157         /* HTTP */\r
158         case 3:\r
159             config_PutIntVariable( "network-channel", FALSE );\r
160             Address = EditHTTPURL->Text;\r
161 \r
162             /* Build source name */\r
163             Source = "http:" + Address;\r
164 \r
165             intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, Source.c_str() );\r
166 \r
167             /* update the display */\r
168             p_intfGlobal->p_sys->p_playlist->UpdateGrid( p_main->p_playlist );\r
169 \r
170             intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );\r
171             break;\r
172     }\r
173 }\r
174 //---------------------------------------------------------------------------\r
175 void __fastcall TNetworkDlg::ChangeEnabled( int i_selected )\r
176 {\r
177     switch( i_selected )\r
178     {\r
179         case 0:\r
180             LabelUDPPort->Enabled = NOT( LabelUDPPort->Enabled );\r
181             EditUDPPort->Enabled = NOT( EditUDPPort->Enabled );\r
182             UpDownUDPPort->Enabled = NOT( UpDownUDPPort->Enabled );\r
183             break;\r
184         case 1:\r
185             LabelMulticastAddress->Enabled =\r
186                     NOT( LabelMulticastAddress->Enabled );\r
187             ComboBoxMulticastAddress->Enabled =\r
188                     NOT( ComboBoxMulticastAddress->Enabled );\r
189             LabelMulticastPort->Enabled = NOT( LabelMulticastPort->Enabled );\r
190             EditMulticastPort->Enabled = NOT( EditMulticastPort->Enabled );\r
191             UpDownMulticastPort->Enabled = NOT( UpDownMulticastPort->Enabled );\r
192             break;\r
193         case 2:\r
194             LabelCSAddress->Enabled = NOT( LabelCSAddress->Enabled );\r
195             ComboBoxCSAddress->Enabled = NOT( ComboBoxCSAddress->Enabled );\r
196             LabelCSPort->Enabled = NOT( LabelCSPort->Enabled );\r
197             EditCSPort->Enabled = NOT( EditCSPort->Enabled );\r
198             UpDownCSPort->Enabled = NOT( UpDownCSPort->Enabled );\r
199             break;\r
200         case 3:\r
201             LabelHTTPURL->Enabled = NOT( LabelHTTPURL->Enabled );\r
202             EditHTTPURL->Enabled = NOT( EditHTTPURL->Enabled );\r
203             break;\r
204     }\r
205 }\r
206 //---------------------------------------------------------------------------\r
207 void __fastcall TNetworkDlg::RadioButtonUDPEnter( TObject *Sender )\r
208 {\r
209     ChangeEnabled( OldRadioValue );\r
210     OldRadioValue = 0;\r
211     ChangeEnabled( OldRadioValue );\r
212 }\r
213 //---------------------------------------------------------------------------\r
214 void __fastcall TNetworkDlg::RadioButtonMulticastEnter( TObject *Sender )\r
215 {\r
216     ChangeEnabled( OldRadioValue );\r
217     OldRadioValue = 1;\r
218     ChangeEnabled( OldRadioValue );\r
219 }\r
220 //---------------------------------------------------------------------------\r
221 void __fastcall TNetworkDlg::RadioButtonCSEnter( TObject *Sender )\r
222 {\r
223     ChangeEnabled( OldRadioValue );\r
224     OldRadioValue = 2;\r
225     ChangeEnabled( OldRadioValue );\r
226 }\r
227 //---------------------------------------------------------------------------\r
228 void __fastcall TNetworkDlg::RadioButtonHTTPEnter( TObject *Sender )\r
229 {\r
230     ChangeEnabled( OldRadioValue );\r
231     OldRadioValue = 3;\r
232     ChangeEnabled( OldRadioValue );\r
233 }\r
234 //---------------------------------------------------------------------------\r
235 \r