1   /**
2    * JHylaFax - A java client for HylaFAX.
3    *
4    * Copyright (C) 2005 by Steffen Pingel <steffenp@gmx.de>
5    *
6    * This program is free software; you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation; either version 2 of the License, or
9    * (at your option) any later version.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with this program; if not, write to the Free Software
18   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19   */
20  package net.sf.jhylafax;
21  
22  import static net.sf.jhylafax.JHylaFAX.i18n;
23  import gnu.hylafax.Job;
24  import java.io.File;
25  import java.io.IOException;
26  import java.util.Locale;
27  import java.util.TimeZone;
28  import net.sf.jhylafax.fax.Paper;
29  import org.xnap.commons.gui.completion.AutomaticDropDownCompletionMode;
30  import org.xnap.commons.settings.BooleanSetting;
31  import org.xnap.commons.settings.DefaultCompletionModeSetting;
32  import org.xnap.commons.settings.EnumSetting;
33  import org.xnap.commons.settings.IntSetting;
34  import org.xnap.commons.settings.PropertyResource;
35  import org.xnap.commons.settings.SerializableSetting;
36  import org.xnap.commons.settings.StringSetting;
37  import org.xnap.commons.util.PortRange;
38  
39  /**
40   * Manages the global settings.
41   * 
42   * @author Steffen Pingel
43   */
44  public class Settings {
45  
46  	public final static PropertyResource backstore = new PropertyResource();
47  	
48  	public final static StringSetting HOSTNAME = new StringSetting(backstore, "hostname", "localhost");
49  	public final static IntSetting PORT = new IntSetting(backstore, "port", 4559, PortRange.MIN_PORT, PortRange.MAX_PORT);
50  	public final static BooleanSetting USE_PASSIVE = new BooleanSetting(backstore, "usePassive", false);
51  	public final static BooleanSetting UPDATE_ON_STARTUP = new BooleanSetting(backstore, "updateOnStartup", false);
52  	public final static StringSetting USERNAME = new StringSetting(backstore, "username", System.getProperty("user.name", "").replaceAll(" ", ""));
53  	public final static StringSetting PASSWORD = new StringSetting(backstore, "password", "");
54  	public final static StringSetting FULLNAME = new StringSetting(backstore, "fullname", "");
55  	public final static StringSetting EMAIL = new StringSetting(backstore, "email", "");
56  	public final static BooleanSetting ADMIN_MODE = new BooleanSetting(backstore, "adminMode", false);
57  	public final static StringSetting ADMIN_PASSWORD = new StringSetting(backstore, "adminPassword", "");
58  	
59  	public final static EnumSetting<Paper> PAPER = new EnumSetting<Paper>(backstore, "paper", Paper.A4);
60  	public final static EnumSetting<Resolution> RESOLUTION = new EnumSetting<Resolution>(backstore, "resolution", Resolution.LOW);
61  	public final static EnumSetting<Notification> NOTIFICATION = new EnumSetting<Notification>(backstore, "notification", Notification.NEVER);
62  	public final static IntSetting PRIORITY = new IntSetting(backstore, "priority", 127, 0, 255);
63  	public final static IntSetting MAXDIALS = new IntSetting(backstore, "maxDials", 12, 1);
64  	public final static IntSetting MAXTRIES = new IntSetting(backstore, "maxTries", 3, 1);
65  
66  	public final static BooleanSetting USE_INTERNAL_COVER = new BooleanSetting(backstore, "useInternalCover", true);
67  	public final static BooleanSetting SEND_COVER_AS_DOCUMENT = new BooleanSetting(backstore, "sendCoverAsDocument", false);
68  	public final static StringSetting COVER_PATH = new StringSetting(backstore, "coverPath", "");
69  	public final static StringSetting VIEWER_PATH = new StringSetting(backstore, "viewerPath", "");
70  	public final static StringSetting DOC_VIEWER_PATH = new StringSetting(backstore, "documentViewerPath", "");
71  	
72  	public final static BooleanSetting DO_MONITOR_PATH = new BooleanSetting(backstore, "doMonitorPath", false);
73  	public final static StringSetting MONITOR_PATH = new StringSetting(backstore, "monitorPath", "");
74  	public final static IntSetting MONITOR_PATH_INTERVAL = new IntSetting(backstore, "monitorPathInterval", 90, 1);
75  
76  	public final static BooleanSetting DO_AUTO_UPDATE = new BooleanSetting(backstore, "doAutoUpdate", false);
77  	public final static IntSetting AUTO_UPDATE_INTERVAL = new IntSetting(backstore, "autoUpdateInterval", 180, 1);
78  
79  	public final static BooleanSetting CONFIRM_NONPS = new BooleanSetting(backstore, "confirmNonPostScript", true);
80  	public final static BooleanSetting CONFIRM_DELETE = new BooleanSetting(backstore, "confirmDelete", true);
81  	public final static BooleanSetting SHOW_POLLQ = new BooleanSetting(backstore, "showPollq", false);
82  	
83  	public final static SerializableSetting<Locale> LOCALE = new SerializableSetting<Locale>(backstore, "locale", Locale.getDefault());
84  	public final static StringSetting TIMEZONE = new StringSetting(backstore, "timezone", TimeZone.getDefault().getID());
85  	public final static DefaultCompletionModeSetting DEFAULT_COMPLETION_MODE = new DefaultCompletionModeSetting(backstore, "defaultCompletionMode", AutomaticDropDownCompletionMode.class.getName());
86  		
87  	public final static BooleanSetting HAS_SEEN_WIZARD = new BooleanSetting(backstore, "hasSeenWizard", false);
88  
89  	public final static BooleanSetting CUSTOMIZE_ADDRESS_BOOK_FILENAME = new BooleanSetting(backstore, "customizeAddressBookFilename", false);
90  	public final static StringSetting ADDRESS_BOOK_FILENAME = new StringSetting(backstore, "addressBookFilename", "addressbook.bin");
91  	
92  	public static void load(File file) throws IOException {
93  		backstore.load(file);
94  	}
95  
96  	public static void store(File file) throws IOException {
97  		backstore.store(file);
98  	}
99  
100 	public static enum Resolution {
101 		LOW(Job.RESOLUTION_LOW) { public String toString() { return i18n.tr("Normal"); } }, 
102 		MEDIUM(Job.RESOLUTION_MEDIUM) { public String toString() { return i18n.tr("Fine"); } },
103 		HIGH(Job.RESOLUTION_MEDIUM * 2) { public String toString() { return i18n.tr("Superfine"); } };
104 		
105 		private int linesPerInch;
106 
107 		private Resolution(int linesPerInch) {
108 			this.linesPerInch = linesPerInch;
109 		}
110 		
111 		public int getLinesPerInch() {
112 			return linesPerInch;
113 		}
114 		
115 		public static Resolution getEnum(int linesPerInch) {
116 			for (Resolution value : values()) {
117 				if (linesPerInch == value.getLinesPerInch()) { 
118 					return value;				
119 				}
120 			}
121 			throw new IllegalArgumentException("Invalid value: " + linesPerInch);
122 		}
123 		
124 	}
125 
126 	public static enum Notification {
127 		NEVER(Job.NOTIFY_NONE) { public String toString() { return i18n.tr("Errors only"); } },
128 		SEND(Job.NOTIFY_DONE) { public String toString() { return i18n.tr("After sending"); } },
129 		REQUEUE(Job.NOTIFY_REQUEUE) { public String toString() { return i18n.tr("After requeuing"); } }, 
130 		ALWAYS(Job.NOTIFY_ALL) { public String toString() { return i18n.tr("Always"); } };
131 
132 		private String command;
133 
134 		private Notification(String command) {
135 			this.command = command;
136 		}
137 		
138 		public String getCommand()
139 		{
140 			return command;
141 		}
142 
143 		public static Notification getEnum(String command) {
144 			for (Notification value : values()) {
145 				if (value.getCommand().equals(command)) { 
146 					return value;				
147 				}
148 			}
149 			throw new IllegalArgumentException("Invalid value: " + command);
150 		}
151 	}
152 
153 }