source: trunk/src/org/expeditee/settings/UserSettings.java@ 1277

Last change on this file since 1277 was 1277, checked in by bln4, 5 years ago

Changes have been made to how mail is stored. Each user now has a location in their deaddrops folder (found inside their resources folder) that acts as an exchange location for each of their partnerships. Mail databases now belong in there.

Initial functionality to support the culling of already processed messages from the mail database has been implemented with more to follow.

File size: 12.7 KB
Line 
1/**
2 * UserSettings.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.settings;
20
21import java.io.File;
22import java.io.FileNotFoundException;
23import java.io.IOException;
24import java.nio.file.Paths;
25import java.util.ArrayList;
26import java.util.LinkedList;
27import java.util.List;
28
29import org.expeditee.agents.SearchGreenstone;
30import org.expeditee.agents.mail.MailSession;
31import org.expeditee.agents.wordprocessing.JSpellChecker;
32import org.expeditee.gui.Browser;
33import org.expeditee.gui.Frame;
34import org.expeditee.gui.FrameIO;
35import org.expeditee.gui.FrameUtils;
36import org.expeditee.gui.MessageBay;
37import org.expeditee.items.Text;
38import org.expeditee.setting.BooleanSetting;
39import org.expeditee.setting.FloatSetting;
40import org.expeditee.setting.FrameSetting;
41import org.expeditee.setting.FunctionSetting;
42import org.expeditee.setting.IntegerSetting;
43import org.expeditee.setting.ListSetting;
44import org.expeditee.setting.StringSetting;
45import org.expeditee.settings.folders.FolderSettings;
46
47/**
48 * Central class to contain all values that can be set by the user on their
49 * profile frame. These values should be updated only by
50 * FrameUtils.ParseProfile.
51 */
52public abstract class UserSettings {
53
54 public static String DEFAULT_PROFILE_NAME = "default";
55
56 public static Boolean PublicAndPrivateResources;
57
58 public static final IntegerSetting Gravity = new IntegerSetting("Distance the cursor has to be from a text item to select the text item", "Gravity", 3);
59
60 public static final StringSetting StartFrame = new StringSetting("The frame to go to when Expeditee is started (defaults to the profile frame)", null);
61
62 /*
63 * Stuff that goes first
64 */
65 public static final StringSetting HomeFrame = new StringSetting("The home frame", null) {
66 @Override
67 public boolean setSetting(Text text) {
68 if(text.getText().indexOf(':') == -1 || !text.hasLink()) {
69 text.setLink(UserSettings.ProfileName.get() + "1");
70 //text.setLink(FrameIO.LoadProfile(UserSettings.ProfileName.get()).getName());
71 }
72 String first = FrameUtils.getLink(text, UserSettings.HomeFrame.get());
73 // do not use non-existent frames as the first frame
74 if (FrameIO.isValidFrameName(first)) {
75 _value = first;
76 }
77 // warn the user
78 else {
79 // MessageBay.warningMessage("Home frame: " + first
80 // + " is not a valid frame.");
81 _value = FrameIO.LoadProfile(UserSettings.ProfileName.get()).getName();
82 }
83 return true;
84 }
85 };
86 public static final IntegerSetting InitialWidth = new IntegerSetting("Initial width of Expeditee window", "InitialWidth", 1024);
87
88 public static final IntegerSetting InitialHeight = new IntegerSetting("Initial height of Expeditee window", "InitialHeight", 768);
89
90 /*
91 * General settings (no setter functions)
92 */
93
94 public static final FloatSetting ScaleFactor = new FloatSetting("Scale Factor for drawing (TODO: does this even do anything?)", "ScaleFactor", 1F);
95
96 public static final FloatSetting FormatSpacingMin = new FloatSetting("Minimum spacing ratio", "FormatSpacingMin", null);
97
98 public static final FloatSetting FormatSpacingMax = new FloatSetting("Maximum spacing ratio", "FormatSpacingMax", null);
99
100 public static final IntegerSetting LineStraightenThreshold = new IntegerSetting("Threshold for straightening a line (TODO: does this even do anything?)", "LineStraightenThreshold", 15);
101
102 public static final IntegerSetting NoOpThreshold = new IntegerSetting("Distance the cursor may be dragged before Gestures must be reinterpreted. E.g. Copy becomes range.", "NoOpThreshold", 10);
103
104 public static final IntegerSetting TitlePosition = new IntegerSetting("Position of title item in frame (TODO: find whether this is x-offset or y-offset)", "TitlePosition", 150);
105
106 public static final StringSetting UserName = new StringSetting("Profile name", FrameIO.ConvertToValidFramesetName(System.getProperty("user.name")));
107
108 public static final StringSetting ProfileName = new StringSetting("Profile name", UserName.get());
109
110 public static final BooleanSetting AntiAlias = new BooleanSetting("Whether anti-aliasing should be enabled", "AntiAlias", false);
111
112 public static final BooleanSetting LineHighlight = new BooleanSetting("Whether lines should be highlighted", "LineHighlight", false);
113
114 public static final BooleanSetting Logging = new BooleanSetting("Whether logging should be enabled", "Logging", false);
115
116 public static final BooleanSetting LogStats = new BooleanSetting("Whether stats should be logged", "LogStats", true);
117
118 public static final BooleanSetting Threading = new BooleanSetting("Whether threading should be enabled", "Threading", true);
119
120 /*
121 * Frames
122 */
123 public static final StringSetting StatisticsFrameset = new StringSetting("The statistics frameset", null);
124
125 public static final StringSetting MenuFrame = new StringSetting("The menu frame", null);
126
127 /*
128 * Other
129 */
130 public static final ListSetting<Text> Style = new ListSetting<Text>("Set the style (TODO: what does this do?)", "Style") {
131 @Override
132 public boolean setSetting(Text text) {
133 Frame child = text.getChild();
134 if (child == null) {
135 _value = new LinkedList<Text>();
136 return true;
137 }
138
139
140 List<Text> style = new ArrayList<Text>(8);
141 for (int i = 0; i < 10; i++) {
142 style.add(null);
143 }
144
145 for (Text t : child.getBodyTextItems(false)) {
146 String type = t.getText();
147 char lastChar = type.charAt(type.length() - 1);
148 if (Character.isDigit(lastChar)) {
149 style.set(lastChar - '0', t);
150 } else {
151 style.set(0, t);
152 }
153 }
154 _value = style;
155 return true;
156 }
157 };
158
159 public static final FunctionSetting SpellChecker = new FunctionSetting("Enables the dictionary with the default dictionary", "SpellChecker") {
160 @Override
161 public void run() {
162 try {
163 JSpellChecker.create();
164 } catch (FileNotFoundException e) {
165 MessageBay.errorMessage("Could not find dictionary: " + e.getMessage());
166 } catch (IOException e) {
167 e.printStackTrace();
168 }
169 }
170 };
171 public static final FrameSetting Spelling = new FrameSetting("Enables the dictionary and adds the items in the child frame to the dictionary", "Spelling") {
172 @Override
173 public void run(Frame frame) {
174 try {
175 JSpellChecker.create(frame);
176 } catch (Exception e) {
177 e.printStackTrace();
178 }
179 }
180 };
181
182 public static final FrameSetting GreenstoneSettings = new FrameSetting("Greenstone settings (TODO: What are these for?)", "GreenstoneSettings") {
183 @Override
184 public void run(Frame frame) {
185 SearchGreenstone.init(frame);
186 }
187 };
188
189 public static final FrameSetting Reminders = new FrameSetting("Reminders (TODO: What are these for?)", "Reminders") {
190 @Override
191 public void run(Frame frame) {
192 org.expeditee.gui.Reminders.init(frame);
193 }
194 };
195
196 public static final FrameSetting MailSettings = new FrameSetting("Mail Settings (TODO: How does this work?)", "MailSettings") {
197 @Override
198 public void run(Frame frame) {
199 MailSession.init(frame);
200 }
201 };
202
203 // add default values
204 static {
205 // Are we in the new regime or the old regime?
206 File resFile = Paths.get(getExpediteeHome()).resolve(".res").toFile();
207 File resourcesPrivateFile = Paths.get(getExpediteeHome() + "resources-private" + File.separator).toFile();
208 if (resourcesPrivateFile.exists()) {
209 // If resources-private exists then this is a good sign we have new regime available.
210 PublicAndPrivateResources = Boolean.TRUE;
211 }
212 else if (resFile.exists()) {
213 // If we do not, but do have the .res file then this is a good sign we are in old regime.
214 PublicAndPrivateResources = Boolean.FALSE;
215 }
216 else {
217 // If we have neither then we are unpacking and therefore will have new regime available once unpacked.
218 PublicAndPrivateResources = Boolean.TRUE;
219 }
220
221 setupDefaultFolders();
222 }
223
224 public static void setupDefaultFolders() {
225 String expeditee_home = getExpediteeHome();
226
227 FrameIO.changeParentAndSubFolders(expeditee_home);
228
229 FolderSettings.FrameDirs.get().clear();
230 FolderSettings.ImageDirs.get().clear();
231 FolderSettings.AudioDirs.get().clear();
232 appendDefaultFolders();
233
234 }
235
236 private static String getExpediteeHome() {
237 String home_property = System.getProperty("expeditee.home");
238 String expeditee_home = (home_property != null) ? home_property + File.separator : getSaveLocation();
239 return expeditee_home;
240 }
241
242 public static void appendDefaultFolders() {
243 if (PublicAndPrivateResources && !UserSettings.UserName.get().equals(Browser.USER_NOBODY)) {
244 // The comments here explain how things have changed with the new regime.
245 // FrameDirs
246 // 1. PROFILE_PATH Still points to same place.
247 // 2. SHARED_FRAMESETS_PATH Still points to same place. (encryption stops just anyone reading it)
248 // 3. framesets-<username> Generated on user account creation and must be refreshed on user switching. Also gives access to tutorial stuffs.
249 // 4. FRAME_PATH <expeditee-home>\resources-public\framesets.
250 // 5. HELP_PUBLIC_PATH <expeditee-home>\resources-public\documentation.
251 // 6. MESSAGES_PATH Still points to same place. Should these be per user and encrypted?
252 // 7. PUBLIC_PATH Still points to same place. Kept for compatibility.
253 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.PROFILE_PATH);
254 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.FRAME_PRIVATE_PATH);
255 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.SHARED_FRAMESETS_PATH);
256 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.FRAME_PATH);
257 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.RESOURCES_PATH);
258 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.MESSAGES_PATH);
259 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.PUBLIC_PATH);
260 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.HELP_PRIVATE_PATH);
261 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.MAIL_PATH);
262 FolderSettings.FrameDirs.setDefault(FolderSettings.FrameDirs.get());
263
264 // ImageDirs
265 // 1. resources-<username>\images Generated on user account creation and must be refreshed on user switching.
266 // 2. IMAGES_PATH <expeditee-home>\resources-public\images
267 FolderSettings.ImageDirs.addAbsoluteDir(FrameIO.IMAGES_PRIVATE_PATH);
268 FolderSettings.ImageDirs.addAbsoluteDir(FrameIO.IMAGES_PATH);
269 FolderSettings.ImageDirs.setDefault(FolderSettings.ImageDirs.get());
270
271 FolderSettings.AudioDirs.addAbsoluteDir(FrameIO.AUDIO_PRIVATE_PATH);
272 FolderSettings.AudioDirs.addAbsoluteDir(FrameIO.AUDIO_PATH);
273 FolderSettings.AudioDirs.setDefault(FolderSettings.AudioDirs.get());
274 } else {
275 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.FRAME_PATH);
276 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.PUBLIC_PATH);
277 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.PROFILE_PATH);
278 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.HELP_PATH);
279 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.MESSAGES_PATH);
280 FolderSettings.FrameDirs.setDefault(FolderSettings.FrameDirs.get());
281
282 FolderSettings.ImageDirs.addAbsoluteDir(FrameIO.IMAGES_PATH);
283 FolderSettings.ImageDirs.setDefault(FolderSettings.ImageDirs.get());
284
285 FolderSettings.AudioDirs.addAbsoluteDir(FrameIO.AUDIO_PATH);
286 FolderSettings.AudioDirs.setDefault(FolderSettings.AudioDirs.get());
287 }
288 }
289
290 /**
291 * Find the appropriate directory to store application settings in for
292 * the current OS.
293 * This has only been tested on Linux so far, so if it doesn't work it
294 * may need to be modified or reverted. Should return:
295 * Linux: ~/.expeditee
296 * Windows: %appdata%\.expeditee
297 * Mac: ~/Library/Application\ Support/.expeditee
298 * @return the path to store expeditee's settings
299 */
300 public static String getSaveLocation() {
301 String OS=System.getProperty("os.name").toLowerCase();
302 if(OS.indexOf("win")>=0) { //windoze
303 return System.getenv("APPDATA")+File.separator+".expeditee"+File.separator;
304 } else if(OS.indexOf("mac")>=0) { //mac
305 return System.getProperty("user.home")+File.separator+"Library"+File.separator+"Application Support"+File.separator+".expeditee"+File.separator;
306 } else { //linux or other
307 return System.getProperty("user.home")+File.separator+".expeditee"+File.separator;
308 }
309 }
310}
Note: See TracBrowser for help on using the repository browser.