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
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. */
20 static const char *cvsid
=
26 #include "LogSingleton.h"
37 #include "getopt++/StringOption.h"
38 #include "propsheet.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;
49 NetPage::CheckIfEnableNext ()
51 int e
= 0, p
= 0, pu
= 0;
52 DWORD ButtonFlags
= PSWIZB_BACK
;
54 if (NetIO::net_method
== IDC_NET_IE5
)
56 if (NetIO::net_method
== IDC_NET_IE5
|| NetIO::net_method
== IDC_NET_DIRECT
)
58 else if (NetIO::net_method
== IDC_NET_PROXY
)
61 if (NetIO::net_proxy_host
&& NetIO::net_proxy_port
)
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
);
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;
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.
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
);
109 return PropertyPage::Create (IDD_NET
);
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
;
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) ==
140 && (!SendMessage (GetDlgItem (IDC_NET_PROXY
), BM_GETCHECK
, 0, 0)
143 SendMessage (GetDlgItem (IDC_NET_DIRECT
), BM_CLICK
, 0, 0);
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
);
161 NetPage::OnUnattended()
169 save_dialog (GetHWND ());
174 NetPage::OnMessageCmd (int id
, HWND hwndctl
, UINT code
)
183 save_dialog (GetHWND());
184 CheckIfEnableNext ();
188 // Wasn't recognized or handled.
192 // Was handled since we never got to default above.