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.util.Random; 022 023/** 024 * @author Stephane 025 */ 026public class ChatPreferences 027{ 028 /** 029 * preferences id 030 */ 031 private static final String PREF_ID = "chat"; 032 033 /** 034 * id 035 */ 036 private static final String ID_SERVER = "server"; 037 private static final String ID_SERVER_PASSWORD = "serverPassword"; 038 private static final String ID_PORT = "port"; 039 private static final String ID_EXTRA_CHANNELS = "extraChannels"; 040 private static final String ID_DESKTOP_CHANNELS = "desktopChannels"; 041 042 private static final String ID_NICKNAME = "nickname"; 043 private static final String ID_REALNAME = "realname"; 044 private static final String ID_USER_PASSWORD = "userPassword"; 045 046 private static final String ID_AUTO_CONNECT = "autoConnect"; 047 private static final String ID_SHOW_STATUS_MESSAGES = "showStatusMessages"; 048 private static final String ID_SHOW_USERS_PANEL = "showUsersPanel"; 049 private static final String ID_DESKTOP_OVERLAY = "desktopOverlay"; 050 private static final String ID_USERS_PANEL_WIDTH = "usersPanelWidth"; 051 052 /** 053 * defaults values 054 */ 055 private final static String DEFAULT_SERVER = "irc.freenode.net"; 056 private final static String DEFAULT_SERVER_PASSWORD = ""; 057 private final static int DEFAULT_PORT = 6666; 058 059 // private final static String DEFAULT_EXTRA_CHANNELS = "icy-support"; 060 private final static String DEFAULT_EXTRA_CHANNELS = ""; 061 private final static String DEFAULT_DESKTOP_CHANNELS = "icy"; 062 063 /** 064 * preferences 065 */ 066 private static XMLPreferences preferences; 067 068 public static void load() 069 { 070 // load preferences 071 preferences = ApplicationPreferences.getPreferences().node(PREF_ID); 072 } 073 074 /** 075 * @return the preferences 076 */ 077 public static XMLPreferences getPreferences() 078 { 079 return preferences; 080 } 081 082 public static String getServer() 083 { 084 return preferences.get(ID_SERVER, DEFAULT_SERVER); 085 } 086 087 public static void setServer(String value) 088 { 089 preferences.put(ID_SERVER, value); 090 } 091 092 public static String getServerPassword() 093 { 094 return preferences.get(ID_SERVER_PASSWORD, DEFAULT_SERVER_PASSWORD); 095 } 096 097 public static void setServerPassword(String value) 098 { 099 preferences.put(ID_SERVER_PASSWORD, value); 100 } 101 102 public static int getPort() 103 { 104 return preferences.getInt(ID_PORT, DEFAULT_PORT); 105 } 106 107 public static void setPort(int value) 108 { 109 preferences.putInt(ID_PORT, value); 110 } 111 112 public static String getDefaultExtraChannels() 113 { 114 return DEFAULT_EXTRA_CHANNELS; 115 } 116 117 public static String getExtraChannels() 118 { 119 return preferences.get(ID_EXTRA_CHANNELS, getDefaultExtraChannels()); 120 } 121 122 public static void setExtraChannels(String value) 123 { 124 preferences.put(ID_EXTRA_CHANNELS, value); 125 } 126 127 public static String getDefaultDesktopChannels() 128 { 129 return DEFAULT_DESKTOP_CHANNELS; 130 } 131 132 public static String getDesktopChannels() 133 { 134 return preferences.get(ID_DESKTOP_CHANNELS, getDefaultDesktopChannels()); 135 } 136 137 public static void setDesktopChannels(String value) 138 { 139 preferences.put(ID_DESKTOP_CHANNELS, value); 140 } 141 142 public static String getRandomNickname() 143 { 144 return "guest" + Random.nextInt(10000); 145 } 146 147 public static String getNickname() 148 { 149 return preferences.get(ID_NICKNAME, getRandomNickname()); 150 } 151 152 public static String getRealname() 153 { 154 return preferences.get(ID_REALNAME, getNickname()); 155 } 156 157 public static String getUserPassword() 158 { 159 return preferences.get(ID_USER_PASSWORD, ""); 160 } 161 162 public static boolean getAutoConnect() 163 { 164 return preferences.getBoolean(ID_AUTO_CONNECT, true); 165 } 166 167 public static boolean getShowStatusMessages() 168 { 169 return preferences.getBoolean(ID_SHOW_STATUS_MESSAGES, false); 170 } 171 172 public static boolean getShowUsersPanel() 173 { 174 return preferences.getBoolean(ID_SHOW_USERS_PANEL, false); 175 } 176 177 public static boolean getDesktopOverlay() 178 { 179 return preferences.getBoolean(ID_DESKTOP_OVERLAY, true); 180 } 181 182 public static int getUsersPanelWidth() 183 { 184 return preferences.getInt(ID_USERS_PANEL_WIDTH, 120); 185 } 186 187 public static void setNickname(String value) 188 { 189 preferences.put(ID_NICKNAME, value); 190 } 191 192 public static void setRealname(String value) 193 { 194 preferences.put(ID_REALNAME, value); 195 } 196 197 public static void setUserPassword(String value) 198 { 199 preferences.put(ID_USER_PASSWORD, value); 200 } 201 202 public static void setAutoConnect(boolean value) 203 { 204 preferences.putBoolean(ID_AUTO_CONNECT, value); 205 } 206 207 public static void setShowStatusMessages(boolean value) 208 { 209 preferences.putBoolean(ID_SHOW_STATUS_MESSAGES, value); 210 } 211 212 public static void setShowUsersPanel(boolean value) 213 { 214 preferences.putBoolean(ID_SHOW_USERS_PANEL, value); 215 } 216 217 public static void setDesktopOverlay(boolean value) 218 { 219 preferences.putBoolean(ID_DESKTOP_OVERLAY, value); 220 } 221 222 public static void setUsersPanelWidth(int value) 223 { 224 preferences.putInt(ID_USERS_PANEL_WIDTH, value); 225 } 226}