Translated using Weblate (Chinese (Simplified))
[cygwin-setup.git] / ConnectionSetting.cc
blobd33acc9aa1171837a6fb13ca37fb7d402568afa4
1 /*
2 * Copyright (c) 2003, Robert Collins <rbtcollins@hotmail.com>
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 Robert Collins.
16 #include <stdlib.h>
17 #include "ConnectionSetting.h"
18 #include "UserSettings.h"
19 #include "io_stream.h"
20 #include "netio.h"
21 #include "resource.h"
22 #include "String++.h"
24 ConnectionSetting::ConnectionSetting ()
26 const char *fg_ret;
27 if ((fg_ret = UserSettings::instance().get ("net-method")))
28 NetIO::net_method = typeFromString(fg_ret);
29 if ((fg_ret = UserSettings::instance().get ("net-proxy-host")))
30 NetIO::net_proxy_host = strdup(fg_ret);
31 if ((fg_ret = UserSettings::instance().get ("net-proxy-port")))
32 NetIO::net_proxy_port = atoi(fg_ret);
35 ConnectionSetting::~ConnectionSetting ()
37 switch (NetIO::net_method)
39 case IDC_NET_DIRECT:
40 UserSettings::instance().set("net-method", "Direct");
41 break;
42 case IDC_NET_PRECONFIG:
43 UserSettings::instance().set("net-method", "IE");
44 break;
45 case IDC_NET_PROXY:
46 char port_str[20];
47 UserSettings::instance().set("net-method", "Proxy");
48 UserSettings::instance().set("net-proxy-host", NetIO::net_proxy_host);
49 sprintf(port_str, "%d", NetIO::net_proxy_port);
50 UserSettings::instance().set("net-proxy-port", port_str);
51 break;
52 default:
53 break;
57 int
58 ConnectionSetting::typeFromString(const std::string& aType)
60 if (!casecompare(aType, "Direct"))
61 return IDC_NET_DIRECT;
62 if (!casecompare(aType, "IE"))
63 return IDC_NET_PRECONFIG;
64 if (!casecompare(aType, "Proxy"))
65 return IDC_NET_PROXY;
67 /* Migrate the removed direct(legacy) to direct */
68 if (!casecompare(aType, "Legacy"))
69 return IDC_NET_DIRECT;
71 /* A sanish default */
72 return IDC_NET_PRECONFIG;