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. */
21 #include "LogSingleton.h"
32 #include "getopt++/StringOption.h"
33 #include "propsheet.h"
35 #include "ConnectionSetting.h"
36 extern ThreeBarProgressPage Progress
;
38 static StringOption
ProxyOption ("", 'p', "proxy", IDS_HELPTEXT_PROXY
, false);
40 static int rb
[] = { IDC_NET_PRECONFIG
, IDC_NET_DIRECT
, IDC_NET_PROXY
, 0 };
41 static bool doing_loading
= false;
44 NetPage::CheckIfEnableNext ()
47 DWORD ButtonFlags
= PSWIZB_BACK
;
49 if (NetIO::net_method
== IDC_NET_PRECONFIG
||
50 NetIO::net_method
== IDC_NET_DIRECT
)
52 else if (NetIO::net_method
== IDC_NET_PROXY
)
55 if (NetIO::net_proxy_host
&& NetIO::net_proxy_port
)
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
);
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;
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.
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
);
104 return PropertyPage::Create (IDD_NET
);
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
;
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);
141 save_dialog (GetHWND ());
143 Log (LOG_PLAIN
) << "net: " << NetIO::net_method_name() << endLog
;
145 Progress
.SetActivateTask (WM_APP_START_SITE_INFO_DOWNLOAD
);
150 NetPage::OnUnattended()
158 save_dialog (GetHWND ());
163 NetPage::OnMessageCmd (int id
, HWND hwndctl
, UINT code
)
167 case IDC_NET_PRECONFIG
:
172 save_dialog (GetHWND());
173 CheckIfEnableNext ();
177 // Wasn't recognized or handled.
181 // Was handled since we never got to default above.