001/*
002 * Copyright 2010-2015 Institut Pasteur.
003 * 
004 * This file is part of Icy.
005 * 
006 * Icy is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 * 
011 * Icy is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 * 
016 * You should have received a copy of the GNU General Public License
017 * along with Icy. If not, see <http://www.gnu.org/licenses/>.
018 */
019package icy.preferences;
020
021import icy.network.NetworkUtil;
022
023/**
024 * @author stephane
025 */
026public class NetworkPreferences
027{
028    /**
029     * preferences id
030     */
031    private static final String PREF_ID = "network";
032
033    /**
034     * id
035     */
036    private static final String ID_PROXY_SETTING = "proxySetting";
037    private static final String ID_PROXY_HTTP_HOST = "proxyHTTPHost";
038    private static final String ID_PROXY_HTTP_PORT = "proxyHTTPPort";
039    private static final String ID_PROXY_HTTPS_HOST = "proxyHTTPSHost";
040    private static final String ID_PROXY_HTTPS_PORT = "proxyHTTPSPort";
041    private static final String ID_PROXY_FTP_HOST = "proxyFTPHost";
042    private static final String ID_PROXY_FTP_PORT = "proxyFTPPort";
043    private static final String ID_PROXY_SOCKS_HOST = "proxySOCKSHost";
044    private static final String ID_PROXY_SOCKS_PORT = "proxySOCKSPort";
045    private static final String ID_PROXY_AUTHENTICATION = "proxyAuthentication";
046    private static final String ID_PROXY_USER = "proxyUser";
047    private static final String ID_PROXY_PASSWORD = "proxyPassword";
048
049    /**
050     * preferences
051     */
052    private static XMLPreferences preferences;
053
054    public static void load()
055    {
056        // load preferences
057        preferences = ApplicationPreferences.getPreferences().node(PREF_ID);
058    }
059
060    /**
061     * @return the preferences
062     */
063    public static XMLPreferences getPreferences()
064    {
065        return preferences;
066    }
067
068    public static int getProxySetting()
069    {
070        return preferences.getInt(ID_PROXY_SETTING, NetworkUtil.SYSTEM_PROXY);
071    }
072
073    public static void setProxySetting(int value)
074    {
075        preferences.putInt(ID_PROXY_SETTING, value);
076    }
077
078    public static String getProxyHTTPHost()
079    {
080        return preferences.get(ID_PROXY_HTTP_HOST, "");
081    }
082
083    public static void setProxyHTTPHost(String value)
084    {
085        preferences.put(ID_PROXY_HTTP_HOST, value);
086    }
087
088    public static int getProxyHTTPPort()
089    {
090        return preferences.getInt(ID_PROXY_HTTP_PORT, 80);
091    }
092
093    public static void setProxyHTTPPort(int value)
094    {
095        preferences.putInt(ID_PROXY_HTTP_PORT, value);
096    }
097
098    public static String getProxyHTTPSHost()
099    {
100        return preferences.get(ID_PROXY_HTTPS_HOST, "");
101    }
102
103    public static void setProxyHTTPSHost(String value)
104    {
105        preferences.put(ID_PROXY_HTTPS_HOST, value);
106    }
107
108    public static int getProxyHTTPSPort()
109    {
110        return preferences.getInt(ID_PROXY_HTTPS_PORT, 447);
111    }
112
113    public static void setProxyHTTPSPort(int value)
114    {
115        preferences.putInt(ID_PROXY_HTTPS_PORT, value);
116    }
117
118    public static String getProxyFTPHost()
119    {
120        return preferences.get(ID_PROXY_FTP_HOST, "");
121    }
122
123    public static void setProxyFTPHost(String value)
124    {
125        preferences.put(ID_PROXY_FTP_HOST, value);
126    }
127
128    public static int getProxyFTPPort()
129    {
130        return preferences.getInt(ID_PROXY_FTP_PORT, 21);
131    }
132
133    public static void setProxyFTPPort(int value)
134    {
135        preferences.putInt(ID_PROXY_FTP_PORT, value);
136    }
137
138    public static String getProxySOCKSHost()
139    {
140        return preferences.get(ID_PROXY_SOCKS_HOST, "");
141    }
142
143    public static void setProxySOCKSHost(String value)
144    {
145        preferences.put(ID_PROXY_SOCKS_HOST, value);
146    }
147
148    public static int getProxySOCKSPort()
149    {
150        return preferences.getInt(ID_PROXY_SOCKS_PORT, 1080);
151    }
152
153    public static void setProxySOCKSPort(int value)
154    {
155        preferences.putInt(ID_PROXY_SOCKS_PORT, value);
156    }
157
158    public static boolean getProxyAuthentication()
159    {
160        return preferences.getBoolean(ID_PROXY_AUTHENTICATION, false);
161    }
162
163    public static void setProxyAuthentication(boolean value)
164    {
165        preferences.putBoolean(ID_PROXY_AUTHENTICATION, value);
166    }
167
168    public static String getProxyUser()
169    {
170        return preferences.get(ID_PROXY_USER, "");
171    }
172
173    public static void setProxyUser(String value)
174    {
175        preferences.put(ID_PROXY_USER, value);
176    }
177
178    public static String getProxyPassword()
179    {
180        return preferences.get(ID_PROXY_PASSWORD, "");
181    }
182
183    public static void setProxyPassword(String value)
184    {
185        preferences.put(ID_PROXY_PASSWORD, value);
186    }
187}