]> git.sesse.net Git - vlc/blob - plugins/win32/network.cpp
516277fef23e2b9f89ef031a3516a928a22c22d6
[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 link "CSPIN"\r
42 #pragma resource "*.dfm"\r
43 \r
44 extern struct intf_thread_s *p_intfGlobal;\r
45 \r
46 //---------------------------------------------------------------------------\r
47 __fastcall TNetworkDlg::TNetworkDlg( TComponent* Owner )\r
48         : TForm( Owner )\r
49 {\r
50         char *psz_channel_server;\r
51 \r
52         OldRadioValue = 0;\r
53 \r
54         /* server port */\r
55         SpinEditUDPPort->Value = config_GetIntVariable( "server-port" );\r
56         SpinEditMulticastPort->Value = config_GetIntVariable( "server-port" );\r
57 \r
58         /* channel server */\r
59         if( config_GetIntVariable( "network-channel" ) )\r
60         {\r
61             RadioButtonCS->Checked = true;\r
62             RadioButtonCSEnter( RadioButtonCS );\r
63         }\r
64 \r
65         psz_channel_server = config_GetPszVariable( "channel-server" );\r
66         if( psz_channel_server )\r
67         {\r
68             ComboBoxCSAddress->Text = psz_channel_server;\r
69             free( psz_channel_server );\r
70         }\r
71 \r
72         SpinEditCSPort->Value = config_GetIntVariable( "channel-port" );\r
73 }\r
74 //---------------------------------------------------------------------------\r
75 void __fastcall TNetworkDlg::FormShow( TObject *Sender )\r
76 {\r
77     p_intfGlobal->p_sys->p_window->MenuNetworkStream->Checked = true;\r
78     p_intfGlobal->p_sys->p_window->PopupNetworkStream->Checked = true;\r
79 }\r
80 //---------------------------------------------------------------------------\r
81 void __fastcall TNetworkDlg::FormHide( TObject *Sender )\r
82 {\r
83     p_intfGlobal->p_sys->p_window->MenuNetworkStream->Checked = false;\r
84     p_intfGlobal->p_sys->p_window->PopupNetworkStream->Checked = false;\r
85 }\r
86 //---------------------------------------------------------------------------\r
87 void __fastcall TNetworkDlg::BitBtnCancelClick( TObject *Sender )\r
88 {\r
89     Hide();\r
90 }\r
91 //---------------------------------------------------------------------------\r
92 void __fastcall TNetworkDlg::BitBtnOkClick( TObject *Sender )\r
93 {\r
94     AnsiString      Source, Address;\r
95     AnsiString      Channel = ComboBoxCSAddress->Text;\r
96     unsigned int    i_channel_port = SpinEditCSPort->Value;\r
97     unsigned int    i_port;\r
98     int             i_end = p_main->p_playlist->i_size;\r
99 \r
100     Hide();\r
101 \r
102     /* select added item */\r
103     if( p_input_bank->pp_input[0] != NULL )\r
104     {\r
105         p_input_bank->pp_input[0]->b_eof = 1;\r
106     }\r
107 \r
108     /* Check which option was chosen */\r
109     switch( OldRadioValue )\r
110     {\r
111         /* UDP */\r
112         case 0:\r
113             config_PutIntVariable( "network-channel", FALSE );\r
114             i_port = SpinEditUDPPort->Value;\r
115 \r
116             /* Build source name */\r
117             Source = "udp:@:" + IntToStr( i_port );\r
118 \r
119             intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, Source.c_str() );\r
120 \r
121             /* update the display */\r
122             p_intfGlobal->p_sys->p_playlist->UpdateGrid( p_main->p_playlist );\r
123 \r
124             intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );\r
125             break;\r
126 \r
127         /* UDP Multicast */\r
128         case 1:\r
129             config_PutIntVariable( "network-channel", FALSE );\r
130             Address = ComboBoxMulticastAddress->Text;\r
131             i_port = SpinEditMulticastPort->Value;\r
132 \r
133             /* Build source name */\r
134             Source = "udp:@" + Address + ":" + IntToStr( i_port );\r
135 \r
136             intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, Source.c_str() );\r
137 \r
138             /* update the display */\r
139             p_intfGlobal->p_sys->p_playlist->UpdateGrid( p_main->p_playlist );\r
140 \r
141             intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );\r
142             break;\r
143 \r
144         /* Channel server */\r
145         case 2:\r
146             config_PutIntVariable( "network-channel", TRUE );\r
147             config_PutPszVariable( "channel-server", Channel.c_str() );\r
148             config_PutIntVariable( "channel-port", i_channel_port );\r
149 \r
150             if( p_main->p_channel == NULL )\r
151             {\r
152                 network_ChannelCreate();\r
153             }\r
154 \r
155             p_intfGlobal->p_sys->b_playing = 1;\r
156             break;\r
157 \r
158         /* HTTP */\r
159         case 3:\r
160             config_PutIntVariable( "network-channel", FALSE );\r
161             Address = EditHTTPURL->Text;\r
162 \r
163             /* Build source name */\r
164             Source = "http:" + Address;\r
165 \r
166             intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, Source.c_str() );\r
167 \r
168             /* update the display */\r
169             p_intfGlobal->p_sys->p_playlist->UpdateGrid( p_main->p_playlist );\r
170 \r
171             intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );\r
172             break;\r
173     }\r
174 }\r
175 //---------------------------------------------------------------------------\r
176 void __fastcall TNetworkDlg::ChangeEnabled( int i_selected )\r
177 {\r
178     switch( i_selected )\r
179     {\r
180         case 0:\r
181             LabelUDPPort->Enabled = NOT( LabelUDPPort->Enabled );\r
182             SpinEditUDPPort->Enabled = NOT( SpinEditUDPPort->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             SpinEditMulticastPort->Enabled = NOT( SpinEditMulticastPort->Enabled );\r
191             break;\r
192         case 2:\r
193             LabelCSAddress->Enabled = NOT( LabelCSAddress->Enabled );\r
194             ComboBoxCSAddress->Enabled = NOT( ComboBoxCSAddress->Enabled );\r
195             LabelCSPort->Enabled = NOT( LabelCSPort->Enabled );\r
196             SpinEditCSPort->Enabled = NOT( SpinEditCSPort->Enabled );\r
197             break;\r
198         case 3:\r
199             LabelHTTPURL->Enabled = NOT( LabelHTTPURL->Enabled );\r
200             EditHTTPURL->Enabled = NOT( EditHTTPURL->Enabled );\r
201             break;\r
202     }\r
203 }\r
204 //---------------------------------------------------------------------------\r
205 void __fastcall TNetworkDlg::RadioButtonUDPEnter( TObject *Sender )\r
206 {\r
207     ChangeEnabled( OldRadioValue );\r
208     OldRadioValue = 0;\r
209     ChangeEnabled( OldRadioValue );\r
210 }\r
211 //---------------------------------------------------------------------------\r
212 void __fastcall TNetworkDlg::RadioButtonMulticastEnter( TObject *Sender )\r
213 {\r
214     ChangeEnabled( OldRadioValue );\r
215     OldRadioValue = 1;\r
216     ChangeEnabled( OldRadioValue );\r
217 }\r
218 //---------------------------------------------------------------------------\r
219 void __fastcall TNetworkDlg::RadioButtonCSEnter( TObject *Sender )\r
220 {\r
221     ChangeEnabled( OldRadioValue );\r
222     OldRadioValue = 2;\r
223     ChangeEnabled( OldRadioValue );\r
224 }\r
225 //---------------------------------------------------------------------------\r
226 void __fastcall TNetworkDlg::RadioButtonHTTPEnter( TObject *Sender )\r
227 {\r
228     ChangeEnabled( OldRadioValue );\r
229     OldRadioValue = 3;\r
230     ChangeEnabled( OldRadioValue );\r
231 }\r
232 //---------------------------------------------------------------------------\r
233 \r