README: document some recent changes in the build environment
[cygwin-setup.git] / net.cc
blob1402c67f495a9b81e40f48202fcd6433bde72cdf
1 /*
2 * Copyright (c) 2000, Red Hat, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
12 * Written by DJ Delorie <dj@cygnus.com>
16 /* The purpose of this file is to get the network configuration
17 information from the user. */
19 #if 0
20 static const char *cvsid =
21 "\n%%% $Id$\n";
22 #endif
24 #include "net.h"
26 #include "LogSingleton.h"
28 #include "win32.h"
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <sstream>
32 #include "dialog.h"
33 #include "resource.h"
34 #include "netio.h"
35 #include "msg.h"
37 #include "getopt++/StringOption.h"
38 #include "propsheet.h"
39 #include "threebar.h"
40 #include "ConnectionSetting.h"
41 extern ThreeBarProgressPage Progress;
43 static StringOption ProxyOption ("", 'p', "proxy", "HTTP/FTP proxy (host:port)", false);
45 static int rb[] = { IDC_NET_IE5, IDC_NET_DIRECT, IDC_NET_PROXY, 0 };
46 static bool doing_loading = false;
48 void
49 NetPage::CheckIfEnableNext ()
51 int e = 0, p = 0, pu = 0;
52 DWORD ButtonFlags = PSWIZB_BACK;
54 if (NetIO::net_method == IDC_NET_IE5)
55 pu = 1;
56 if (NetIO::net_method == IDC_NET_IE5 || NetIO::net_method == IDC_NET_DIRECT)
57 e = 1;
58 else if (NetIO::net_method == IDC_NET_PROXY)
60 p = pu = 1;
61 if (NetIO::net_proxy_host && NetIO::net_proxy_port)
62 e = 1;
64 if (e)
66 // There's something in the proxy and port boxes, enable "Next".
67 ButtonFlags |= PSWIZB_NEXT;
70 GetOwner ()->SetButtons (ButtonFlags);
72 EnableWindow (GetDlgItem (IDC_PROXY_HOST), p);
73 EnableWindow (GetDlgItem (IDC_PROXY_PORT), p);
76 static void
77 load_dialog (HWND h)
79 doing_loading = true;
81 rbset (h, rb, NetIO::net_method);
82 eset (h, IDC_PROXY_HOST, NetIO::net_proxy_host);
83 if (NetIO::net_proxy_port == 0)
84 NetIO::net_proxy_port = 80;
85 eset (h, IDC_PROXY_PORT, NetIO::net_proxy_port);
87 doing_loading = false;
90 static void
91 save_dialog (HWND h)
93 // Without this, save_dialog() is called in the middle of load_dialog()
94 // because the window receives a message when the value changes. If this
95 // happens, save_dialog() tries to read the values of the fields, resulting
96 // in the net_proxy_port being reset to zero - this is the cause of the
97 // preference not sticking.
98 if (doing_loading)
99 return;
101 NetIO::net_method = rbget (h, rb);
102 NetIO::net_proxy_host = eget (h, IDC_PROXY_HOST, NetIO::net_proxy_host);
103 NetIO::net_proxy_port = eget (h, IDC_PROXY_PORT);
106 bool
107 NetPage::Create ()
109 return PropertyPage::Create (IDD_NET);
112 void
113 NetPage::OnInit ()
115 HWND h = GetHWND ();
116 std::string proxyString (ProxyOption);
118 if (!NetIO::net_method)
119 NetIO::net_method = IDC_NET_DIRECT;
121 if (proxyString.size ())
123 unsigned int pos = proxyString.find_last_of (':');
124 if ((pos > 0) && (pos < (proxyString.size () - 1)))
126 NetIO::net_method = IDC_NET_PROXY;
127 NetIO::net_proxy_host = strdup (proxyString.substr (0, pos).c_str ());
128 std::string portString = proxyString.substr (pos + 1, proxyString.size () - (pos + 1));
129 std::istringstream iss (portString, std::istringstream::in);
130 iss >> NetIO::net_proxy_port;
134 load_dialog (h);
135 CheckIfEnableNext();
137 // Check to see if any radio buttons are selected. If not, select a default.
138 if ((!SendMessage (GetDlgItem (IDC_NET_IE5), BM_GETCHECK, 0, 0) ==
139 BST_CHECKED)
140 && (!SendMessage (GetDlgItem (IDC_NET_PROXY), BM_GETCHECK, 0, 0)
141 == BST_CHECKED))
143 SendMessage (GetDlgItem (IDC_NET_DIRECT), BM_CLICK, 0, 0);
147 long
148 NetPage::OnNext ()
150 save_dialog (GetHWND ());
152 Log (LOG_PLAIN) << "net: "
153 << ((NetIO::net_method == IDC_NET_IE5) ? "IE5" :
154 (NetIO::net_method == IDC_NET_DIRECT) ? "Direct" : "Proxy") << endLog;
156 Progress.SetActivateTask (WM_APP_START_SITE_INFO_DOWNLOAD);
157 return IDD_INSTATUS;
160 long
161 NetPage::OnUnattended()
163 return OnNext ();
166 long
167 NetPage::OnBack ()
169 save_dialog (GetHWND ());
170 return 0;
173 bool
174 NetPage::OnMessageCmd (int id, HWND hwndctl, UINT code)
176 switch (id)
178 case IDC_NET_IE5:
179 case IDC_NET_DIRECT:
180 case IDC_NET_PROXY:
181 case IDC_PROXY_HOST:
182 case IDC_PROXY_PORT:
183 save_dialog (GetHWND());
184 CheckIfEnableNext ();
185 break;
187 default:
188 // Wasn't recognized or handled.
189 return false;
192 // Was handled since we never got to default above.
193 return true;