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

Last change on this file since 1474 was 1474, checked in by bnemhaus, 5 years ago

Added FrameIO.Mail to the default paths populated on profile frames. With more time this could be done better; as per comment in UserSettings::appendDefaultFolders

File size: 13.0 KB
RevLine 
[919]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
[570]19package org.expeditee.settings;
[4]20
21import java.io.File;
[572]22import java.io.FileNotFoundException;
23import java.io.IOException;
[1242]24import java.nio.file.Paths;
[572]25import java.util.ArrayList;
[4]26import java.util.LinkedList;
27import java.util.List;
28
[572]29import org.expeditee.agents.SearchGreenstone;
30import org.expeditee.agents.mail.MailSession;
31import org.expeditee.agents.wordprocessing.JSpellChecker;
[1287]32import org.expeditee.auth.AuthenticatorBrowser;
[571]33import org.expeditee.gui.Frame;
[570]34import org.expeditee.gui.FrameIO;
[571]35import org.expeditee.gui.FrameUtils;
[572]36import org.expeditee.gui.MessageBay;
[1434]37import org.expeditee.gui.management.ProfileManager;
[4]38import org.expeditee.items.Text;
[666]39import org.expeditee.setting.BooleanSetting;
40import org.expeditee.setting.FloatSetting;
[655]41import org.expeditee.setting.FrameSetting;
42import org.expeditee.setting.FunctionSetting;
[666]43import org.expeditee.setting.IntegerSetting;
[655]44import org.expeditee.setting.ListSetting;
[666]45import org.expeditee.setting.StringSetting;
[778]46import org.expeditee.settings.folders.FolderSettings;
[4]47
48/**
49 * Central class to contain all values that can be set by the user on their
50 * profile frame. These values should be updated only by
51 * FrameUtils.ParseProfile.
52 */
53public abstract class UserSettings {
[348]54
[1434]55 public static final String DEFAULT_PROFILE_NAME = "default";
[1242]56
[1244]57 public static Boolean PublicAndPrivateResources;
[289]58
[1242]59 public static final IntegerSetting Gravity = new IntegerSetting("Distance the cursor has to be from a text item to select the text item", "Gravity", 3);
[717]60
[732]61 public static final StringSetting StartFrame = new StringSetting("The frame to go to when Expeditee is started (defaults to the profile frame)", null);
62
[572]63 /*
[717]64 * Stuff that goes first
65 */
66 public static final StringSetting HomeFrame = new StringSetting("The home frame", null) {
67 @Override
68 public boolean setSetting(Text text) {
[1434]69 String profileName = UserSettings.ProfileName.get();
70 if(text.getText().indexOf(':') == -1 || !text.hasLink()) {
[1467]71 //if (!profileName.equals(ProfileManager.USER_NAME_FLAG)) {
72 if (profileName != null) {
[1434]73 text.setLink(profileName + "1");
74 }
[1213]75 //text.setLink(FrameIO.LoadProfile(UserSettings.ProfileName.get()).getName());
[717]76 }
77 String first = FrameUtils.getLink(text, UserSettings.HomeFrame.get());
[1244]78 // do not use non-existent frames as the first frame
[717]79 if (FrameIO.isValidFrameName(first)) {
80 _value = first;
81 }
82 // warn the user
83 else {
84 // MessageBay.warningMessage("Home frame: " + first
85 // + " is not a valid frame.");
[1434]86 _value = profileName + "1";//FrameIO.LoadProfile(UserSettings.ProfileName.get()).getName();
[717]87 }
88 return true;
89 }
90 };
[1242]91 public static final IntegerSetting InitialWidth = new IntegerSetting("Initial width of Expeditee window", "InitialWidth", 1024);
[717]92
[1242]93 public static final IntegerSetting InitialHeight = new IntegerSetting("Initial height of Expeditee window", "InitialHeight", 768);
[717]94
95 /*
[572]96 * General settings (no setter functions)
97 */
[289]98
[1242]99 public static final FloatSetting ScaleFactor = new FloatSetting("Scale Factor for drawing (TODO: does this even do anything?)", "ScaleFactor", 1F);
[655]100
[1242]101 public static final FloatSetting FormatSpacingMin = new FloatSetting("Minimum spacing ratio", "FormatSpacingMin", null);
[655]102
[1242]103 public static final FloatSetting FormatSpacingMax = new FloatSetting("Maximum spacing ratio", "FormatSpacingMax", null);
[4]104
[1242]105 public static final IntegerSetting LineStraightenThreshold = new IntegerSetting("Threshold for straightening a line (TODO: does this even do anything?)", "LineStraightenThreshold", 15);
[4]106
[1242]107 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);
[74]108
[1242]109 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);
[1272]110
[1467]111 public static final StringSetting UserName = new StringSetting("User name", ProfileManager.USER_NAME_FLAG);
[4]112
[1467]113// public static final StringSetting ProfileName = new StringSetting("Profile name", ProfileManager.USER_NAME_FLAG); // FrameIO.ConvertToValidFramesetName(System.getProperty("user.name"))
114 public static final StringSetting ProfileName = new StringSetting("Profile name", null); // FrameIO.ConvertToValidFramesetName(System.getProperty("user.name"))
[1213]115
[1242]116 public static final BooleanSetting AntiAlias = new BooleanSetting("Whether anti-aliasing should be enabled", "AntiAlias", false);
[572]117
[1242]118 public static final BooleanSetting LineHighlight = new BooleanSetting("Whether lines should be highlighted", "LineHighlight", false);
[572]119
[1242]120 public static final BooleanSetting Logging = new BooleanSetting("Whether logging should be enabled", "Logging", false);
[572]121
[1242]122 public static final BooleanSetting LogStats = new BooleanSetting("Whether stats should be logged", "LogStats", true);
[572]123
[1242]124 public static final BooleanSetting Threading = new BooleanSetting("Whether threading should be enabled", "Threading", true);
[1213]125
[572]126 /*
127 * Frames
128 */
[666]129 public static final StringSetting StatisticsFrameset = new StringSetting("The statistics frameset", null);
[4]130
[666]131 public static final StringSetting MenuFrame = new StringSetting("The menu frame", null);
[572]132
133 /*
134 * Other
135 */
[1242]136 public static final ListSetting<Text> Style = new ListSetting<Text>("Set the style (TODO: what does this do?)", "Style") {
[655]137 @Override
138 public boolean setSetting(Text text) {
139 Frame child = text.getChild();
140 if (child == null) {
141 _value = new LinkedList<Text>();
142 return true;
143 }
144
145
146 List<Text> style = new ArrayList<Text>(8);
147 for (int i = 0; i < 10; i++) {
148 style.add(null);
149 }
150
151 for (Text t : child.getBodyTextItems(false)) {
152 String type = t.getText();
153 char lastChar = type.charAt(type.length() - 1);
154 if (Character.isDigit(lastChar)) {
155 style.set(lastChar - '0', t);
156 } else {
157 style.set(0, t);
158 }
159 }
160 _value = style;
161 return true;
[639]162 }
[655]163 };
[572]164
[1242]165 public static final FunctionSetting SpellChecker = new FunctionSetting("Enables the dictionary with the default dictionary", "SpellChecker") {
[655]166 @Override
167 public void run() {
168 try {
[641]169 JSpellChecker.create();
170 } catch (FileNotFoundException e) {
[655]171 MessageBay.errorMessage("Could not find dictionary: " + e.getMessage());
[641]172 } catch (IOException e) {
173 e.printStackTrace();
174 }
[572]175 }
[655]176 };
[1242]177 public static final FrameSetting Spelling = new FrameSetting("Enables the dictionary and adds the items in the child frame to the dictionary", "Spelling") {
[655]178 @Override
179 public void run(Frame frame) {
180 try {
181 JSpellChecker.create(frame);
182 } catch (Exception e) {
183 e.printStackTrace();
184 }
[641]185 }
[655]186 };
[572]187
[1242]188 public static final FrameSetting GreenstoneSettings = new FrameSetting("Greenstone settings (TODO: What are these for?)", "GreenstoneSettings") {
[655]189 @Override
190 public void run(Frame frame) {
191 SearchGreenstone.init(frame);
192 }
193 };
[572]194
[1242]195 public static final FrameSetting Reminders = new FrameSetting("Reminders (TODO: What are these for?)", "Reminders") {
[655]196 @Override
197 public void run(Frame frame) {
198 org.expeditee.gui.Reminders.init(frame);
[642]199 }
[655]200 };
[572]201
[1242]202 public static final FrameSetting MailSettings = new FrameSetting("Mail Settings (TODO: How does this work?)", "MailSettings") {
[655]203 @Override
204 public void run(Frame frame) {
205 MailSession.init(frame);
[642]206 }
[655]207 };
[761]208
[4]209 // add default values
[355]210 static {
[1242]211 // Are we in the new regime or the old regime?
[1244]212 File resFile = Paths.get(getExpediteeHome()).resolve(".res").toFile();
213 File resourcesPrivateFile = Paths.get(getExpediteeHome() + "resources-private" + File.separator).toFile();
[1242]214 if (resourcesPrivateFile.exists()) {
[1244]215 // If resources-private exists then this is a good sign we have new regime available.
216 PublicAndPrivateResources = Boolean.TRUE;
[1330]217 } else if (resFile.exists()) {
[1242]218 // If we do not, but do have the .res file then this is a good sign we are in old regime.
[1244]219 PublicAndPrivateResources = Boolean.FALSE;
[1330]220 } else {
[1242]221 // If we have neither then we are unpacking and therefore will have new regime available once unpacked.
[1244]222 PublicAndPrivateResources = Boolean.TRUE;
[1242]223 }
224
[946]225 setupDefaultFolders();
226 }
[1242]227
[1244]228 public static void setupDefaultFolders() {
229 String expeditee_home = getExpediteeHome();
230
231 FrameIO.changeParentAndSubFolders(expeditee_home);
232
[946]233 FolderSettings.FrameDirs.get().clear();
234 FolderSettings.ImageDirs.get().clear();
[1244]235 FolderSettings.AudioDirs.get().clear();
[946]236 appendDefaultFolders();
[1244]237
[946]238 }
239
[1244]240 private static String getExpediteeHome() {
241 String home_property = System.getProperty("expeditee.home");
242 String expeditee_home = (home_property != null) ? home_property + File.separator : getSaveLocation();
[1242]243 return expeditee_home;
244 }
[1328]245
[1440]246 public static void appendDefaultFolders() {
[1328]247 if (PublicAndPrivateResources) {
[1440]248 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.HELP_USERNAME_PRIVATE_PATH);
[1328]249 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.HELP_PATH);
[1440]250 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.MESSAGES_PATH);
[1474]251 // TODO: This is not the ideal way of adding mail. Mail should only be available when authenticated.
252 // This would ideally be done on authenticated profile creation auth.account.Create.java
253 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.MAIL_PATH);
[1440]254 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.FRAME_USERNAME_PRIVATE_PATH);
[1328]255 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.FRAME_PATH);
[1440]256
[1328]257 if (AuthenticatorBrowser.isAuthenticated()) {
[1440]258 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.CONTACTS_PATH);
[1474]259 //FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.MAIL_PATH);
[1440]260 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.SHARED_FRAMESETS_PATH);
[1328]261 }
262
[1440]263 FolderSettings.ImageDirs.addAbsoluteDir("${CURRENT_FRAMESET}");
[1434]264 FolderSettings.ImageDirs.addAbsoluteDir(FrameIO.IMAGES_USERNAME_PRIVATE_PATH);
[1440]265 FolderSettings.ImageDirs.addAbsoluteDir(FrameIO.IMAGES_PATH);
[1244]266
[1440]267 FolderSettings.AudioDirs.addAbsoluteDir("${CURRENT_FRAMESET}");
[1328]268 FolderSettings.AudioDirs.addAbsoluteDir(FrameIO.AUDIO_PATH);
[1434]269 FolderSettings.AudioDirs.addAbsoluteDir(FrameIO.AUDIO_USERNAME_PRIVATE_PATH);
[1440]270
271 FolderSettings.FrameDirs.setDefault(FolderSettings.FrameDirs.get());
272 FolderSettings.ImageDirs.setDefault(FolderSettings.ImageDirs.get());
[1244]273 FolderSettings.AudioDirs.setDefault(FolderSettings.AudioDirs.get());
[1242]274 } else {
[1328]275 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.HELP_PATH);
[1244]276 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.FRAME_PATH);
277 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.MESSAGES_PATH);
[1328]278 if (AuthenticatorBrowser.isAuthenticated()) {
279 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.SHARED_FRAMESETS_PATH);
[1360]280 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.MAIL_PATH);
[1375]281 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.CONTACTS_PATH);
[1328]282 }
283
[1245]284 FolderSettings.ImageDirs.addAbsoluteDir(FrameIO.IMAGES_PATH);
[1244]285
[1245]286 FolderSettings.AudioDirs.addAbsoluteDir(FrameIO.AUDIO_PATH);
[1242]287 }
[1440]288
289 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.PUBLIC_PATH);
290 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.GROUP_PATH);
291 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.PROFILE_PATH);
292 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.TRASH_PATH);
293
294 FolderSettings.FrameDirs.setDefault(FolderSettings.FrameDirs.get());
295 FolderSettings.ImageDirs.setDefault(FolderSettings.ImageDirs.get());
296 FolderSettings.AudioDirs.setDefault(FolderSettings.AudioDirs.get());
[4]297 }
298
299 /**
[504]300 * Find the appropriate directory to store application settings in for
301 * the current OS.
302 * This has only been tested on Linux so far, so if it doesn't work it
303 * may need to be modified or reverted. Should return:
304 * Linux: ~/.expeditee
305 * Windows: %appdata%\.expeditee
306 * Mac: ~/Library/Application\ Support/.expeditee
307 * @return the path to store expeditee's settings
[4]308 */
[504]309 public static String getSaveLocation() {
310 String OS=System.getProperty("os.name").toLowerCase();
[768]311 if(OS.indexOf("win")>=0) { //windoze
[504]312 return System.getenv("APPDATA")+File.separator+".expeditee"+File.separator;
[768]313 } else if(OS.indexOf("mac")>=0) { //mac
[504]314 return System.getProperty("user.home")+File.separator+"Library"+File.separator+"Application Support"+File.separator+".expeditee"+File.separator;
315 } else { //linux or other
316 return System.getProperty("user.home")+File.separator+".expeditee"+File.separator;
[4]317 }
318 }
319}
Note: See TracBrowser for help on using the repository browser.