]>
Commit | Line | Data |
---|---|---|
39b42ff3 RC |
1 | /* |
2 | * Copyright (c) 2003, Robert Collins <rbtcollins@hotmail.com> | |
3 | * | |
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. | |
8 | * | |
9 | * A copy of the GNU General Public License can be found at | |
10 | * http://www.gnu.org/ | |
11 | * | |
12 | * Written by Robert Collins. | |
13 | * | |
14 | */ | |
15 | ||
16 | #if 0 | |
17 | static const char *cvsid = | |
18 | "\n%%% $Id$\n"; | |
19 | #endif | |
20 | ||
21 | #include "ConnectionSetting.h" | |
22 | #include "UserSettings.h" | |
23 | #include "io_stream.h" | |
24 | #include "state.h" | |
25 | #include "resource.h" | |
26 | #include "String++.h" | |
27 | ||
28 | void | |
29 | ConnectionSetting::load() | |
30 | { | |
31 | static int inited = 0; | |
32 | if (inited) | |
33 | return; | |
34 | io_stream *f = UserSettings::Instance().settingFileForLoad("last-connection"); | |
35 | if (f) | |
36 | { | |
37 | char localdir[1000]; | |
38 | char *fg_ret = f->gets (localdir, 1000); | |
39b42ff3 RC |
39 | if (fg_ret) |
40 | net_method = typeFromString(fg_ret); | |
1622a084 RC |
41 | fg_ret = f->gets (localdir, 1000); |
42 | if (fg_ret) | |
43 | net_proxy_host = strdup(fg_ret); | |
44 | fg_ret = f->gets (localdir, 1000); | |
45 | if (fg_ret) | |
46 | net_proxy_port = atoi(fg_ret); | |
47 | delete f; | |
39b42ff3 RC |
48 | } |
49 | inited = 1; | |
50 | } | |
51 | ||
52 | void | |
53 | ConnectionSetting::save() | |
54 | { | |
1622a084 | 55 | char port_str[20]; |
39b42ff3 RC |
56 | |
57 | io_stream *f = UserSettings::Instance().settingFileForSave("last-connection"); | |
58 | if (f) | |
59 | { | |
60 | switch (net_method) { | |
61 | case IDC_NET_DIRECT: | |
62 | f->write("Direct\n",7); | |
63 | break; | |
64 | case IDC_NET_IE5: | |
65 | f->write("IE\n",3); | |
66 | break; | |
67 | case IDC_NET_PROXY: | |
68 | f->write("Proxy\n",6); | |
1622a084 RC |
69 | f->write(net_proxy_host,strlen(net_proxy_host)); |
70 | sprintf(port_str, "\n%d\n", net_proxy_port); | |
71 | f->write(port_str,strlen(port_str)); | |
39b42ff3 RC |
72 | break; |
73 | default: | |
74 | break; | |
75 | } | |
76 | delete f; | |
77 | } | |
78 | } | |
79 | ||
80 | int | |
81 | ConnectionSetting::typeFromString(String const & aType) | |
82 | { | |
83 | if (!aType.casecompare("Direct")) | |
84 | return IDC_NET_DIRECT; | |
85 | if (!aType.casecompare("IE")) | |
86 | return IDC_NET_IE5; | |
87 | if (!aType.casecompare("Proxy")) | |
88 | return IDC_NET_PROXY; | |
89 | ||
90 | /* A sanish default */ | |
91 | return IDC_NET_IE5; | |
92 | } |