Tidy up spacing in french translation
[cygwin-setup.git] / net.cc
blobad497caf1edc40ab8d163f0649759858d7ec87a1
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 #include "net.h"
21 #include "LogSingleton.h"
23 #include "win32.h"
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <sstream>
27 #include "dialog.h"
28 #include "resource.h"
29 #include "netio.h"
30 #include "msg.h"
32 #include "getopt++/StringOption.h"
33 #include "propsheet.h"
34 #include "threebar.h"
35 #include "ConnectionSetting.h"
36 extern ThreeBarProgressPage Progress;
38 static StringOption ProxyOption ("", 'p', "proxy", "HTTP/FTP proxy (host:port)", false);
40 static int rb[] = { IDC_NET_PRECONFIG, IDC_NET_DIRECT, IDC_NET_PROXY, 0 };
41 static bool doing_loading = false;
43 void
44 NetPage::CheckIfEnableNext ()
46 int e = 0, p = 0;
47 DWORD ButtonFlags = PSWIZB_BACK;
49 if (NetIO::net_method == IDC_NET_PRECONFIG ||
50 NetIO::net_method == IDC_NET_DIRECT)
51 e = 1;
52 else if (NetIO::net_method == IDC_NET_PROXY)
54 p = 1;
55 if (NetIO::net_proxy_host && NetIO::net_proxy_port)
56 e = 1;
59 if (e)
61 // There's something in the proxy and port boxes, enable "Next".
62 ButtonFlags |= PSWIZB_NEXT;
65 GetOwner ()->SetButtons (ButtonFlags);
67 EnableWindow (GetDlgItem (IDC_PROXY_HOST), p);
68 EnableWindow (GetDlgItem (IDC_PROXY_PORT), p);
71 static void
72 load_dialog (HWND h)
74 doing_loading = true;
76 rbset (h, rb, NetIO::net_method);
77 eset (h, IDC_PROXY_HOST, NetIO::net_proxy_host);
78 if (NetIO::net_proxy_port == 0)
79 NetIO::net_proxy_port = 80;
80 eset (h, IDC_PROXY_PORT, NetIO::net_proxy_port);
82 doing_loading = false;
85 static void
86 save_dialog (HWND h)
88 // Without this, save_dialog() is called in the middle of load_dialog()
89 // because the window receives a message when the value changes. If this
90 // happens, save_dialog() tries to read the values of the fields, resulting
91 // in the net_proxy_port being reset to zero - this is the cause of the
92 // preference not sticking.
93 if (doing_loading)
94 return;
96 NetIO::net_method = rbget (h, rb);
97 NetIO::net_proxy_host = eget (h, IDC_PROXY_HOST, NetIO::net_proxy_host);
98 NetIO::net_proxy_port = eget (h, IDC_PROXY_PORT);
101 bool
102 NetPage::Create ()
104 return PropertyPage::Create (IDD_NET);
107 void
108 NetPage::OnInit ()
110 HWND h = GetHWND ();
111 std::string proxyString (ProxyOption);
113 if (!NetIO::net_method)
114 NetIO::net_method = IDC_NET_PRECONFIG;
116 if (proxyString.size ())
118 unsigned int pos = proxyString.find_last_of (':');
119 if ((pos > 0) && (pos < (proxyString.size () - 1)))
121 NetIO::net_method = IDC_NET_PROXY;
122 NetIO::net_proxy_host = strdup (proxyString.substr (0, pos).c_str ());
123 std::string portString = proxyString.substr (pos + 1, proxyString.size () - (pos + 1));
124 std::istringstream iss (portString, std::istringstream::in);
125 iss >> NetIO::net_proxy_port;
129 load_dialog (h);
130 CheckIfEnableNext();
132 // Check to see if any radio buttons are selected. If not, select a default.
133 if (SendMessage (GetDlgItem (IDC_NET_DIRECT), BM_GETCHECK, 0, 0) != BST_CHECKED
134 && SendMessage (GetDlgItem (IDC_NET_PROXY), BM_GETCHECK, 0, 0) != BST_CHECKED)
135 SendMessage (GetDlgItem (IDC_NET_PRECONFIG), BM_CLICK, 0, 0);
138 long
139 NetPage::OnNext ()
141 save_dialog (GetHWND ());
143 Log (LOG_PLAIN) << "net: " << NetIO::net_method_name() << endLog;
145 Progress.SetActivateTask (WM_APP_START_SITE_INFO_DOWNLOAD);
146 return IDD_INSTATUS;
149 long
150 NetPage::OnUnattended()
152 return OnNext ();
155 long
156 NetPage::OnBack ()
158 save_dialog (GetHWND ());
159 return 0;
162 bool
163 NetPage::OnMessageCmd (int id, HWND hwndctl, UINT code)
165 switch (id)
167 case IDC_NET_PRECONFIG:
168 case IDC_NET_DIRECT:
169 case IDC_NET_PROXY:
170 case IDC_PROXY_HOST:
171 case IDC_PROXY_PORT:
172 save_dialog (GetHWND());
173 CheckIfEnableNext ();
174 break;
176 default:
177 // Wasn't recognized or handled.
178 return false;
181 // Was handled since we never got to default above.
182 return true;