summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/CMakeLists.txt1
-rw-r--r--java/com/tigervnc/rfb/CSecurityTLS.java36
-rw-r--r--java/com/tigervnc/rfb/Configuration.java69
-rw-r--r--java/com/tigervnc/vncviewer/CConn.java59
-rw-r--r--java/com/tigervnc/vncviewer/F8Menu.java15
-rw-r--r--java/com/tigervnc/vncviewer/FileUtils.java84
-rw-r--r--java/com/tigervnc/vncviewer/OptionsDialog.java228
-rw-r--r--java/com/tigervnc/vncviewer/ServerDialog.java42
-rw-r--r--java/com/tigervnc/vncviewer/UserPreferences.java149
-rw-r--r--java/com/tigervnc/vncviewer/UserPrefs.java286
-rw-r--r--java/com/tigervnc/vncviewer/VncViewer.java13
11 files changed, 599 insertions, 383 deletions
diff --git a/java/CMakeLists.txt b/java/CMakeLists.txt
index d00bedb4..a157226d 100644
--- a/java/CMakeLists.txt
+++ b/java/CMakeLists.txt
@@ -30,7 +30,6 @@ set(JAVA_CLASSNAMES
PlatformPixelBuffer
OptionsDialog
ServerDialog
- UserPrefs
VncViewer)
set(JAVA_SOURCES "")
diff --git a/java/com/tigervnc/rfb/CSecurityTLS.java b/java/com/tigervnc/rfb/CSecurityTLS.java
index c7e3108c..4486eef4 100644
--- a/java/com/tigervnc/rfb/CSecurityTLS.java
+++ b/java/com/tigervnc/rfb/CSecurityTLS.java
@@ -34,11 +34,9 @@ import java.util.ArrayList;
import java.util.Collection;
import javax.swing.JOptionPane;
-import com.tigervnc.vncviewer.UserPrefs;
import com.tigervnc.rdr.*;
import com.tigervnc.network.*;
-import java.util.concurrent.Executors;
-import java.nio.channels.SelectionKey;
+import com.tigervnc.vncviewer.*;
public class CSecurityTLS extends CSecurity {
@@ -74,24 +72,24 @@ public class CSecurityTLS extends CSecurity {
crlfile = x509crl.getData();
}
- public static void setDefaults()
- {
- String homeDir = null;
-
- if ((homeDir=UserPrefs.getHomeDir()) == null) {
- vlog.error("Could not obtain VNC home directory path");
- return;
- }
+ public static String getDefaultCA() {
+ if (UserPreferences.get("viewer", "x509ca") != null)
+ return UserPreferences.get("viewer", "x509ca");
+ return FileUtils.getVncHomeDir()+"x509_ca.pem";
+ }
- String vnchomedir = homeDir+UserPrefs.getFileSeparator()+".vnc"+
- UserPrefs.getFileSeparator();
- String caDefault = new String(vnchomedir+"x509_ca.pem");
- String crlDefault = new String(vnchomedir+"x509_crl.pem");
+ public static String getDefaultCRL() {
+ if (UserPreferences.get("viewer", "x509crl") != null)
+ return UserPreferences.get("viewer", "x509crl");
+ return FileUtils.getVncHomeDir()+"x509_crl.pem";
+ }
- if (new File(caDefault).exists())
- x509ca.setDefaultStr(caDefault);
- if (new File(crlDefault).exists())
- x509crl.setDefaultStr(crlDefault);
+ public static void setDefaults()
+ {
+ if (new File(getDefaultCA()).exists())
+ x509ca.setDefaultStr(getDefaultCA());
+ if (new File(getDefaultCRL()).exists())
+ x509crl.setDefaultStr(getDefaultCRL());
}
// FIXME:
diff --git a/java/com/tigervnc/rfb/Configuration.java b/java/com/tigervnc/rfb/Configuration.java
index de8cfc71..aca8b536 100644
--- a/java/com/tigervnc/rfb/Configuration.java
+++ b/java/com/tigervnc/rfb/Configuration.java
@@ -24,9 +24,15 @@
package com.tigervnc.rfb;
+import java.io.FileInputStream;
+import java.io.PrintWriter;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
public class Configuration {
- static LogWriter vlog = new LogWriter("Config");
+ static LogWriter vlog = new LogWriter("Configuration");
public enum ConfigurationObject { ConfGlobal, ConfServer, ConfViewer };
@@ -263,6 +269,67 @@ public class Configuration {
}
}
+ public static void load(String filename) {
+ if (filename == null)
+ return;
+
+ /* Read parameters from file */
+ Properties props = new Properties();
+ try {
+ props.load(new FileInputStream(filename));
+ } catch(java.security.AccessControlException e) {
+ vlog.error("Cannot access system properties:"+e.getMessage());
+ return;
+ } catch (java.lang.Exception e) {
+ vlog.error("Error opening config file:"+e.getMessage());
+ return;
+ }
+
+ for (Iterator i = props.stringPropertyNames().iterator(); i.hasNext();) {
+ String name = (String)i.next();
+ if (name.startsWith("[")) {
+ // skip the section delimiters
+ continue;
+ } else if (name.equals("host")) {
+ setParam("Server", props.getProperty(name));
+ } else if (name.equals("disableclipboard")) {
+ setParam("RecvClipboard", props.getProperty(name));
+ setParam("SendClipboard", props.getProperty(name));
+ } else if (name.equals("localcursor")) {
+ setParam("UseLocalCursor", props.getProperty(name));
+ } else {
+ if (!setParam(name, props.getProperty(name)))
+ vlog.debug("Cannot set parameter: "+name);
+ }
+ }
+ }
+
+ public static void save(String filename) {
+ PrintWriter pw = null;
+ try {
+ pw = new PrintWriter(filename, "UTF-8");
+ } catch (java.lang.Exception e) {
+ vlog.error("Error opening config file:"+e.getMessage());
+ return;
+ }
+
+ pw.println("# TigerVNC viewer configuration");
+ DateFormat dateFormat = new SimpleDateFormat("E MMM d k:m:s z yyyy");
+ Date date = new Date();
+ pw.println("# "+dateFormat.format(date));
+ VoidParameter current = Configuration.global().head;
+ while (current != null) {
+ String name = current.getName();
+ String value = current.getValueStr();
+ if (!name.equals("Server") && !name.equals("Port") &&
+ value != null && value != current.getDefaultStr())
+ pw.println(name+"="+current.getValueStr());
+ current = current._next;
+ }
+ pw.flush();
+ pw.close();
+ }
+
// Name for this Configuration
private String name;
diff --git a/java/com/tigervnc/vncviewer/CConn.java b/java/com/tigervnc/vncviewer/CConn.java
index 3b42c394..22cbe1fc 100644
--- a/java/com/tigervnc/vncviewer/CConn.java
+++ b/java/com/tigervnc/vncviewer/CConn.java
@@ -766,8 +766,8 @@ public class CConn extends CConnection
public void setOptions() {
int digit;
- options.autoSelect.setSelected(autoSelect);
- options.fullColour.setSelected(fullColour);
+ options.autoSelect.setSelected(viewer.autoSelect.getValue());
+ options.fullColour.setSelected(viewer.fullColour.getValue());
options.veryLowColour.setSelected(!fullColour && lowColourLevel == 0);
options.lowColour.setSelected(!fullColour && lowColourLevel == 1);
options.mediumColour.setSelected(!fullColour && lowColourLevel == 2);
@@ -810,8 +810,12 @@ public class CConn extends CConnection
options.secVnc.setEnabled(false);
options.secPlain.setEnabled(false);
options.sendLocalUsername.setEnabled(false);
+ options.cfLoadButton.setEnabled(false);
+ options.cfSaveAsButton.setEnabled(true);
} else {
options.shared.setSelected(viewer.shared.getValue());
+ options.sendLocalUsername.setSelected(viewer.sendLocalUsername.getValue());
+ options.cfSaveAsButton.setEnabled(false);
/* Process non-VeNCrypt sectypes */
java.util.List<Integer> secTypes = new ArrayList<Integer>();
@@ -819,15 +823,15 @@ public class CConn extends CConnection
for (Iterator i = secTypes.iterator(); i.hasNext();) {
switch ((Integer)i.next()) {
case Security.secTypeVeNCrypt:
- options.secVeNCrypt.setSelected(true);
+ options.secVeNCrypt.setSelected(UserPreferences.getBool("viewer", "secVeNCrypt", true));
break;
case Security.secTypeNone:
options.encNone.setSelected(true);
- options.secNone.setSelected(true);
+ options.secNone.setSelected(UserPreferences.getBool("viewer", "secTypeNone", true));
break;
case Security.secTypeVncAuth:
options.encNone.setSelected(true);
- options.secVnc.setSelected(true);
+ options.secVnc.setSelected(UserPreferences.getBool("viewer", "secTypeVncAuth", true));
break;
}
}
@@ -839,46 +843,55 @@ public class CConn extends CConnection
for (Iterator iext = secTypesExt.iterator(); iext.hasNext();) {
switch ((Integer)iext.next()) {
case Security.secTypePlain:
- options.secPlain.setSelected(true);
+ options.encNone.setSelected(UserPreferences.getBool("viewer", "encNone", true));
+ options.secPlain.setSelected(UserPreferences.getBool("viewer", "secPlain", true));
break;
case Security.secTypeIdent:
- options.secIdent.setSelected(true);
+ options.encNone.setSelected(UserPreferences.getBool("viewer", "encNone", true));
+ options.secIdent.setSelected(UserPreferences.getBool("viewer", "secIdent", true));
break;
case Security.secTypeTLSNone:
- options.encTLS.setSelected(true);
- options.secNone.setSelected(true);
+ options.encTLS.setSelected(UserPreferences.getBool("viewer", "encTLS", true));
+ options.secNone.setSelected(UserPreferences.getBool("viewer", "secNone", true));
break;
case Security.secTypeTLSVnc:
- options.encTLS.setSelected(true);
- options.secVnc.setSelected(true);
+ options.encTLS.setSelected(UserPreferences.getBool("viewer", "encTLS", true));
+ options.secVnc.setSelected(UserPreferences.getBool("viewer", "secVnc", true));
break;
case Security.secTypeTLSPlain:
- options.encTLS.setSelected(true);
- options.secPlain.setSelected(true);
+ options.encTLS.setSelected(UserPreferences.getBool("viewer", "encTLS", true));
+ options.secPlain.setSelected(UserPreferences.getBool("viewer", "secPlain", true));
break;
case Security.secTypeTLSIdent:
- options.encTLS.setSelected(true);
- options.secIdent.setSelected(true);
+ options.encTLS.setSelected(UserPreferences.getBool("viewer", "encTLS", true));
+ options.secIdent.setSelected(UserPreferences.getBool("viewer", "secIdent", true));
break;
case Security.secTypeX509None:
- options.encX509.setSelected(true);
- options.secNone.setSelected(true);
+ options.encX509.setSelected(UserPreferences.getBool("viewer", "encX509", true));
+ options.secNone.setSelected(UserPreferences.getBool("viewer", "secNone", true));
break;
case Security.secTypeX509Vnc:
- options.encX509.setSelected(true);
- options.secVnc.setSelected(true);
+ options.encX509.setSelected(UserPreferences.getBool("viewer", "encX509", true));
+ options.secVnc.setSelected(UserPreferences.getBool("viewer", "secVnc", true));
break;
case Security.secTypeX509Plain:
- options.encX509.setSelected(true);
- options.secPlain.setSelected(true);
+ options.encX509.setSelected(UserPreferences.getBool("viewer", "encX509", true));
+ options.secPlain.setSelected(UserPreferences.getBool("viewer", "secPlain", true));
break;
case Security.secTypeX509Ident:
- options.encX509.setSelected(true);
- options.secIdent.setSelected(true);
+ options.encX509.setSelected(UserPreferences.getBool("viewer", "encX509", true));
+ options.secIdent.setSelected(UserPreferences.getBool("viewer", "secIdent", true));
break;
}
}
}
+ options.encNone.setEnabled(options.secVeNCrypt.isSelected());
+ options.encTLS.setEnabled(options.secVeNCrypt.isSelected());
+ options.encX509.setEnabled(options.secVeNCrypt.isSelected());
+ options.ca.setEnabled(options.secVeNCrypt.isSelected());
+ options.crl.setEnabled(options.secVeNCrypt.isSelected());
+ options.secIdent.setEnabled(options.secVeNCrypt.isSelected());
+ options.secPlain.setEnabled(options.secVeNCrypt.isSelected());
options.sendLocalUsername.setEnabled(options.secPlain.isSelected()||
options.secIdent.isSelected());
}
diff --git a/java/com/tigervnc/vncviewer/F8Menu.java b/java/com/tigervnc/vncviewer/F8Menu.java
index 5d804b5b..07e8974e 100644
--- a/java/com/tigervnc/vncviewer/F8Menu.java
+++ b/java/com/tigervnc/vncviewer/F8Menu.java
@@ -22,6 +22,7 @@ package com.tigervnc.vncviewer;
import java.awt.Cursor;
import java.awt.event.*;
import javax.swing.JFrame;
+import javax.swing.JFileChooser;
import javax.swing.JPopupMenu;
import javax.swing.JMenuItem;
import javax.swing.JCheckBoxMenuItem;
@@ -58,6 +59,7 @@ public class F8Menu extends JPopupMenu implements ActionListener {
addSeparator();
newConn = addMenuItem("New connection...", KeyEvent.VK_W);
options = addMenuItem("Options...", KeyEvent.VK_O);
+ save = addMenuItem("Save connection info as...", KeyEvent.VK_S);
info = addMenuItem("Connection info...", KeyEvent.VK_I);
about = addMenuItem("About VncViewer...", KeyEvent.VK_A);
addSeparator();
@@ -115,6 +117,17 @@ public class F8Menu extends JPopupMenu implements ActionListener {
VncViewer.newViewer(cc.viewer);
} else if (actionMatch(ev, options)) {
cc.options.showDialog(cc.viewport);
+ } else if (actionMatch(ev, save)) {
+ JFileChooser fc = new JFileChooser();
+ fc.setDialogTitle("Save current configuration as:");
+ fc.setApproveButtonText("OK");
+ fc.setFileHidingEnabled(false);
+ int ret = fc.showOpenDialog(this);
+ if (ret == JFileChooser.APPROVE_OPTION) {
+ String filename = fc.getSelectedFile().toString();
+ if (filename != null)
+ Configuration.save(filename);
+ }
} else if (actionMatch(ev, info)) {
cc.showInfo();
} else if (actionMatch(ev, about)) {
@@ -127,7 +140,7 @@ public class F8Menu extends JPopupMenu implements ActionListener {
CConn cc;
JMenuItem restore, move, size, minimize, maximize;
JMenuItem exit, clipboard, ctrlAltDel, refresh;
- JMenuItem newConn, options, info, about, dismiss;
+ JMenuItem newConn, options, save, info, about, dismiss;
static JMenuItem f8;
JCheckBoxMenuItem fullScreen;
static LogWriter vlog = new LogWriter("F8Menu");
diff --git a/java/com/tigervnc/vncviewer/FileUtils.java b/java/com/tigervnc/vncviewer/FileUtils.java
new file mode 100644
index 00000000..e7f3c5a4
--- /dev/null
+++ b/java/com/tigervnc/vncviewer/FileUtils.java
@@ -0,0 +1,84 @@
+/* Copyright (C) 2012 Brian P. Hinz
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
+ */
+
+package com.tigervnc.vncviewer;
+
+import javax.swing.filechooser.FileSystemView;
+
+import com.tigervnc.rfb.LogWriter;
+
+public class FileUtils {
+
+ public static final String getHomeDir() {
+ String homeDir = null;
+ try {
+ String os = System.getProperty("os.name");
+ try {
+ if (os.startsWith("Windows")) {
+ // JRE prior to 1.5 cannot reliably determine USERPROFILE
+ // return user.home and hope it's right...
+ if (Integer.parseInt(System.getProperty("java.version").split("\\.")[1]) < 5) {
+ try {
+ homeDir = System.getProperty("user.home");
+ } catch(java.security.AccessControlException e) {
+ vlog.error("Cannot access user.home system property:"+e.getMessage());
+ }
+ } else {
+ homeDir = System.getenv("USERPROFILE");
+ }
+ } else {
+ try {
+ homeDir = FileSystemView.getFileSystemView().
+ getDefaultDirectory().getCanonicalPath();
+ } catch(java.security.AccessControlException e) {
+ vlog.error("Cannot access system property:"+e.getMessage());
+ }
+ }
+ } catch (java.lang.Exception e) {
+ e.printStackTrace();
+ }
+ } catch(java.security.AccessControlException e) {
+ vlog.error("Cannot access os.name system property:"+e.getMessage());
+ }
+
+ String separator = null;
+ try {
+ separator = Character.toString(java.io.File.separatorChar);
+ } catch(java.security.AccessControlException e) {
+ vlog.error("Cannot access file.separator system property:"+e.getMessage());
+ }
+
+ return homeDir + getFileSeparator();
+ }
+
+ public static final String getVncHomeDir() {
+ return getHomeDir()+".vnc"+getFileSeparator();
+ }
+
+ public static final String getFileSeparator() {
+ String separator = null;
+ try {
+ separator = Character.toString(java.io.File.separatorChar);
+ } catch(java.security.AccessControlException e) {
+ vlog.error("Cannot access file.separator system property:"+e.getMessage());
+ }
+ return separator;
+ }
+
+ static LogWriter vlog = new LogWriter("FileUtils");
+}
diff --git a/java/com/tigervnc/vncviewer/OptionsDialog.java b/java/com/tigervnc/vncviewer/OptionsDialog.java
index afeaf2d7..49757335 100644
--- a/java/com/tigervnc/vncviewer/OptionsDialog.java
+++ b/java/com/tigervnc/vncviewer/OptionsDialog.java
@@ -21,6 +21,7 @@ package com.tigervnc.vncviewer;
import java.awt.*;
import java.awt.event.*;
+import java.io.File;
import javax.swing.*;
import javax.swing.border.*;
@@ -48,15 +49,13 @@ class OptionsDialog extends Dialog implements
JCheckBox secNone, secVnc, secPlain, secIdent, sendLocalUsername;
JButton okButton, cancelButton;
JButton ca, crl;
- JButton defSaveButton;
- UserPrefs defaults;
+ JButton cfLoadButton, cfSaveAsButton, defSaveButton, defReloadButton, defClearButton;
public OptionsDialog(OptionsDialogCallback cb_) {
super(false);
cb = cb_;
setResizable(false);
setTitle("VNC Viewer Options");
- defaults = new UserPrefs("vncviewer");
getContentPane().setLayout(
new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS));
@@ -118,7 +117,7 @@ class OptionsDialog extends Dialog implements
veryLowColour = addRadioCheckbox("Very low(8 colours)", colourGroup, colourPanel);
addGBComponent(autoSelect,FormatPanel, 0, 0, 2, 1, 2, 2, 1, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.FIRST_LINE_START, new Insets(4,5,0,5));
- addGBComponent(encodingPanel,FormatPanel, 0, 1, 1, 1, 2, 2, 1, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START, new Insets(0,10,0,5));
+ addGBComponent(encodingPanel,FormatPanel, 0, 1, 1, 1, 2, 2, 3, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START, new Insets(0,5,0,5));
addGBComponent(colourPanel,FormatPanel, 1, 1, 1, 1, 2, 2, 1, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_END, new Insets(0,0,0,5));
addGBComponent(tightPanel,FormatPanel, 0, 2, 2, GridBagConstraints.REMAINDER, 2, 2, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.FIRST_LINE_START, new Insets(0,5,0,5));
@@ -183,32 +182,28 @@ class OptionsDialog extends Dialog implements
JPanel configPanel = new JPanel(new GridBagLayout());
configPanel.setBorder(BorderFactory.createTitledBorder("Configuration File"));
- JButton cfReloadButton = new JButton("Reload");
- cfReloadButton.addActionListener(this);
- addGBComponent(cfReloadButton,configPanel, 0, 0, 1, 1, 0, 0, 0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(4,8,4,8));
- JButton cfSaveButton = new JButton("Save");
- cfSaveButton.addActionListener(this);
- addGBComponent(cfSaveButton,configPanel, 0, 1, 1, 1, 0, 0, 0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(4,8,4,8));
- JButton cfSaveAsButton = new JButton("Save As...");
+ cfLoadButton = new JButton("Load");
+ cfLoadButton.addActionListener(this);
+ addGBComponent(cfLoadButton,configPanel, 0, 0, 1, 1, 0, 0, 0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(4,8,4,8));
+ cfSaveAsButton = new JButton("Save As...");
cfSaveAsButton.addActionListener(this);
- addGBComponent(cfSaveAsButton,configPanel, 0, 2, 1, 1, 0, 0, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(4,8,4,8));
- cfReloadButton.setEnabled(false);
- cfSaveButton.setEnabled(false);
- //cfSaveAsButton.setEnabled(!applet);
+ addGBComponent(cfSaveAsButton,configPanel, 0, 1, 1, 1, 0, 0, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(4,8,4,8));
JPanel defaultsPanel = new JPanel(new GridBagLayout());
defaultsPanel.setBorder(BorderFactory.createTitledBorder("Defaults"));
- JButton defReloadButton = new JButton("Reload");
+ defClearButton = new JButton("Clear");
+ defClearButton.addActionListener(this);
+ addGBComponent(defClearButton,defaultsPanel, 0, 0, 1, 1, 0, 0, 1, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(4,8,4,8));
+ defReloadButton = new JButton("Reload");
defReloadButton.addActionListener(this);
- addGBComponent(defReloadButton,defaultsPanel, 0, 0, 1, 1, 0, 0, 1, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(4,8,4,8));
+ addGBComponent(defReloadButton,defaultsPanel, 0, 1, 1, 1, 0, 0, 0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(4,8,4,8));
defSaveButton = new JButton("Save");
defSaveButton.addActionListener(this);
- addGBComponent(defSaveButton,defaultsPanel, 0, 1, 1, 1, 0, 0, 0, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(4,8,4,8));
+ addGBComponent(defSaveButton,defaultsPanel, 0, 2, 1, 1, 0, 0, 0, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(4,8,4,8));
addGBComponent(configPanel,DefaultsPanel, 0, 0, 1, GridBagConstraints.REMAINDER, 0, 0, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.PAGE_START, new Insets(4,5,4,5));
addGBComponent(defaultsPanel,DefaultsPanel, 1, 0, 1, GridBagConstraints.REMAINDER, 0, 0, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.PAGE_START, new Insets(4,0,4,5));
//defReloadButton.setEnabled(!applet);
- //defSaveButton.setEnabled(!applet);
// security tab
SecPanel=new JPanel(new GridBagLayout());
@@ -295,6 +290,146 @@ class OptionsDialog extends Dialog implements
sendLocalUsername.setEnabled(secVeNCrypt.isEnabled()&&
(secPlain.isSelected()||secIdent.isSelected()));
}
+
+ private void updatePreferences() {
+ //UserPreferences.clear("global");
+ if (autoSelect.isSelected()) {
+ UserPreferences.set("global", "AutoSelect", true);
+ } else {
+ UserPreferences.set("global", "AutoSelect", false);
+ if (zrle.isSelected()) {
+ UserPreferences.set("global", "PreferredEncoding", "ZRLE");
+ } else if (hextile.isSelected()) {
+ UserPreferences.set("global", "PreferredEncoding", "hextile");
+ } else if (tight.isSelected()) {
+ UserPreferences.set("global", "PreferredEncoding", "Tight");
+ } else if (raw.isSelected()) {
+ UserPreferences.set("global", "PreferredEncoding", "raw");
+ }
+ }
+ if (fullColour.isSelected()) {
+ UserPreferences.set("global", "FullColour", true);
+ } else {
+ UserPreferences.set("global", "FullColour", false);
+ if (mediumColour.isSelected()) {
+ UserPreferences.set("global", "LowColorLevel", 2);
+ } else if (lowColour.isSelected()) {
+ UserPreferences.set("global", "LowColorLevel", 1);
+ } else if (veryLowColour.isSelected()) {
+ UserPreferences.set("global", "LowColorLevel", 0);
+ }
+ }
+ UserPreferences.set("global", "NoJPEG", !noJpeg.isSelected());
+ UserPreferences.set("global", "QualityLevel", (Integer)qualityLevel.getSelectedItem());
+ UserPreferences.set("global", "CustomCompressLevel", customCompressLevel.isSelected());
+ UserPreferences.set("global", "CompressLevel", (Integer)compressLevel.getSelectedItem());
+ UserPreferences.set("global", "ViewOnly", viewOnly.isSelected());
+ UserPreferences.set("global", "AcceptClipboard", acceptClipboard.isSelected());
+ UserPreferences.set("global", "SendClipboard", sendClipboard.isSelected());
+ String menuKeyStr = MenuKey.getMenuKeySymbols()[menuKey.getSelectedIndex()].name;
+ UserPreferences.set("global", "MenuKey", menuKeyStr);
+ UserPreferences.set("global", "FullScreen", fullScreen.isSelected());
+ UserPreferences.set("global", "Shared", shared.isSelected());
+ UserPreferences.set("global", "UseLocalCursor", useLocalCursor.isSelected());
+ UserPreferences.set("global", "AcceptBell", acceptBell.isSelected());
+ String scaleString = scalingFactor.getSelectedItem().toString();
+ if (scaleString.equalsIgnoreCase("Auto")) {
+ UserPreferences.set("global", "ScalingFactor", "Auto");
+ } else if(scaleString.equalsIgnoreCase("Fixed Aspect Ratio")) {
+ UserPreferences.set("global", "ScalingFactor", "FixedRatio");
+ } else {
+ scaleString=scaleString.substring(0, scaleString.length()-1);
+ UserPreferences.set("global", "ScalingFactor", scaleString);
+ }
+ UserPreferences.set("viewer", "secVeNCrypt", secVeNCrypt.isSelected());
+ UserPreferences.set("viewer", "encNone", encNone.isSelected());
+ UserPreferences.set("viewer", "encTLS", encTLS.isSelected());
+ UserPreferences.set("viewer", "encX509", encX509.isSelected());
+ UserPreferences.set("viewer", "secNone", secNone.isSelected());
+ UserPreferences.set("viewer", "secVnc", secVnc.isSelected());
+ UserPreferences.set("viewer", "secPlain", secPlain.isSelected());
+ UserPreferences.set("viewer", "secIdent", secIdent.isSelected());
+ UserPreferences.set("global", "SendLocalUsername", sendLocalUsername.isSelected());
+ if (CSecurityTLS.x509ca.getValueStr() != "")
+ UserPreferences.set("viewer", "x509ca", CSecurityTLS.x509ca.getValueStr());
+ if (CSecurityTLS.x509crl.getValueStr() != "")
+ UserPreferences.set("viewer", "x509crl", CSecurityTLS.x509crl.getValueStr());
+ }
+
+ private void restorePreferences() {
+ autoSelect.setSelected(UserPreferences.getBool("global", "AutoSelect"));
+ if (!autoSelect.isSelected()) {
+ if (UserPreferences.getBool("global", "FullColour")) {
+ fullColour.setSelected(true);
+ } else {
+ switch (UserPreferences.getInt("global", "LowColorLevel")) {
+ case 2:
+ mediumColour.setSelected(true);
+ break;
+ case 1:
+ lowColour.setSelected(true);
+ break;
+ case 0:
+ veryLowColour.setSelected(true);
+ break;
+ }
+ }
+ String encoding = UserPreferences.get("global", "PreferredEncoding");
+ if (encoding != null) {
+ switch (Encodings.encodingNum(encoding)) {
+ case Encodings.encodingZRLE:
+ zrle.setSelected(true);
+ break;
+ case Encodings.encodingHextile:
+ hextile.setSelected(true);
+ break;
+ case Encodings.encodingRaw:
+ raw.setSelected(true);
+ break;
+ default:
+ tight.setSelected(true);
+ }
+ }
+ }
+ noJpeg.setSelected(!UserPreferences.getBool("global", "NoJPEG"));
+ qualityLevel.setSelectedItem(UserPreferences.getInt("global", "QualityLevel"));
+ customCompressLevel.setSelected(UserPreferences.getBool("global", "CustomCompressLevel"));
+ compressLevel.setSelectedItem(UserPreferences.getInt("global", "CompressLevel"));
+ viewOnly.setSelected(UserPreferences.getBool("global", "ViewOnly"));
+ acceptClipboard.setSelected(UserPreferences.getBool("global", "AcceptClipboard"));
+ sendClipboard.setSelected(UserPreferences.getBool("global", "SendClipboard"));
+ menuKey.setSelectedItem(UserPreferences.get("global", "MenuKey"));
+ fullScreen.setSelected(UserPreferences.getBool("global", "FullScreen"));
+ if (shared.isEnabled())
+ shared.setSelected(UserPreferences.getBool("global", "Shared"));
+ useLocalCursor.setSelected(UserPreferences.getBool("global", "UseLocalCursor"));
+ acceptBell.setSelected(UserPreferences.getBool("global", "AcceptBell"));
+ String scaleString = UserPreferences.get("global", "ScalingFactor");
+ if (scaleString != null) {
+ if (scaleString.equalsIgnoreCase("Auto")) {
+ scalingFactor.setSelectedItem("Auto");
+ } else if (scaleString.equalsIgnoreCase("FixedRatio")) {
+ scalingFactor.setSelectedItem("Fixed Aspect Ratio");
+ } else {
+ scalingFactor.setSelectedItem(scaleString+"%");
+ }
+ }
+ if (secVeNCrypt.isEnabled()) {
+ secVeNCrypt.setSelected(UserPreferences.getBool("viewer", "secVeNCrypt", true));
+ if (secVeNCrypt.isSelected()) {
+ encNone.setSelected(UserPreferences.getBool("viewer", "encNone", true));
+ encTLS.setSelected(UserPreferences.getBool("viewer", "encTLS", true));
+ encX509.setSelected(UserPreferences.getBool("viewer", "encX509", true));
+ secPlain.setSelected(UserPreferences.getBool("viewer", "secPlain", true));
+ secIdent.setSelected(UserPreferences.getBool("viewer", "secIdent", true));
+ sendLocalUsername.setSelected(UserPreferences.getBool("global", "SendLocalUsername"));
+ }
+ }
+ if (secNone.isEnabled())
+ secNone.setSelected(UserPreferences.getBool("viewer", "secNone", true));
+ if (secVnc.isEnabled())
+ secVnc.setSelected(UserPreferences.getBool("viewer", "secVnc", true));
+ }
JRadioButton addRadioCheckbox(String str, ButtonGroup group, JPanel panel) {
JRadioButton c = new JRadioButton(str);
@@ -343,19 +478,50 @@ class OptionsDialog extends Dialog implements
} else if (s instanceof JButton && (JButton)s == cancelButton) {
ok = false;
endDialog();
+ } else if (s instanceof JButton && (JButton)s == cfLoadButton) {
+ JFileChooser fc = new JFileChooser();
+ fc.setDialogTitle("Path to configuration file");
+ fc.setApproveButtonText("OK");
+ fc.setFileHidingEnabled(false);
+ int ret = fc.showOpenDialog(this);
+ if (ret == JFileChooser.APPROVE_OPTION) {
+ String filename = fc.getSelectedFile().toString();
+ if (filename != null)
+ Configuration.load(filename);
+ cb.setOptions();
+ }
+ } else if (s instanceof JButton && (JButton)s == cfSaveAsButton) {
+ JFileChooser fc = new JFileChooser();
+ fc.setDialogTitle("Save current configuration as:");
+ fc.setApproveButtonText("OK");
+ fc.setFileHidingEnabled(false);
+ int ret = fc.showOpenDialog(this);
+ if (ret == JFileChooser.APPROVE_OPTION) {
+ String filename = fc.getSelectedFile().toString();
+ if (filename != null)
+ Configuration.save(filename);
+ }
} else if (s instanceof JButton && (JButton)s == defSaveButton) {
- try {
- defaults.Save();
- } catch (java.lang.Exception x) { }
+ updatePreferences();
+ UserPreferences.save();
+ } else if (s instanceof JButton && (JButton)s == defReloadButton) {
+ restorePreferences();
+ } else if (s instanceof JButton && (JButton)s == defClearButton) {
+ UserPreferences.clear();
+ cb.setOptions();
} else if (s instanceof JButton && (JButton)s == ca) {
- JFileChooser fc = new JFileChooser();
+ JFileChooser fc = new JFileChooser(new File(CSecurityTLS.getDefaultCA()));
fc.setDialogTitle("Path to X509 CA certificate");
+ fc.setApproveButtonText("OK");
+ fc.setFileHidingEnabled(false);
int ret = fc.showOpenDialog(this);
if (ret == JFileChooser.APPROVE_OPTION)
CSecurityTLS.x509ca.setParam(fc.getSelectedFile().toString());
} else if (s instanceof JButton && (JButton)s == crl) {
- JFileChooser fc = new JFileChooser();
+ JFileChooser fc = new JFileChooser(new File(CSecurityTLS.getDefaultCRL()));
fc.setDialogTitle("Path to X509 CRL file");
+ fc.setApproveButtonText("OK");
+ fc.setFileHidingEnabled(false);
int ret = fc.showOpenDialog(this);
if (ret == JFileChooser.APPROVE_OPTION)
CSecurityTLS.x509crl.setParam(fc.getSelectedFile().toString());
@@ -373,18 +539,12 @@ class OptionsDialog extends Dialog implements
mediumColour.setEnabled(!autoSelect.isSelected());
lowColour.setEnabled(!autoSelect.isSelected());
veryLowColour.setEnabled(!autoSelect.isSelected());
- defaults.setPref("autoSelect",(autoSelect.isSelected()) ? "on" : "off");
}
if (s instanceof JCheckBox && (JCheckBox)s == customCompressLevel) {
compressLevel.setEnabled(customCompressLevel.isSelected());
- defaults.setPref("customCompressLevel",(customCompressLevel.isSelected()) ? "on" : "off");
}
if (s instanceof JCheckBox && (JCheckBox)s == noJpeg) {
qualityLevel.setEnabled(noJpeg.isSelected());
- defaults.setPref("noJpeg",(noJpeg.isSelected()) ? "on" : "off");
- }
- if (s instanceof JCheckBox && (JCheckBox)s == sendLocalUsername) {
- defaults.setPref("sendLocalUsername",(sendLocalUsername.isSelected()) ? "on" : "off");
}
if (s instanceof JCheckBox && (JCheckBox)s == secVeNCrypt) {
encNone.setEnabled(secVeNCrypt.isSelected());
@@ -393,11 +553,15 @@ class OptionsDialog extends Dialog implements
ca.setEnabled(secVeNCrypt.isSelected());
crl.setEnabled(secVeNCrypt.isSelected());
secIdent.setEnabled(secVeNCrypt.isSelected());
- secNone.setEnabled(secVeNCrypt.isSelected());
- secVnc.setEnabled(secVeNCrypt.isSelected());
secPlain.setEnabled(secVeNCrypt.isSelected());
sendLocalUsername.setEnabled(secVeNCrypt.isSelected());
}
+ if (s instanceof JCheckBox && (JCheckBox)s == encNone) {
+ secNone.setSelected(encNone.isSelected() &&
+ UserPreferences.getBool("viewer", "secNone", true));
+ secVnc.setSelected(encNone.isSelected() &&
+ UserPreferences.getBool("viewer", "secVnc", true));
+ }
if (s instanceof JCheckBox && (JCheckBox)s == secIdent ||
s instanceof JCheckBox && (JCheckBox)s == secPlain) {
sendLocalUsername.setEnabled(secIdent.isSelected()||secPlain.isSelected());
diff --git a/java/com/tigervnc/vncviewer/ServerDialog.java b/java/com/tigervnc/vncviewer/ServerDialog.java
index b596dbfd..3efc5859 100644
--- a/java/com/tigervnc/vncviewer/ServerDialog.java
+++ b/java/com/tigervnc/vncviewer/ServerDialog.java
@@ -57,8 +57,9 @@ class ServerDialog extends Dialog implements
getContentPane().setLayout(new GridBagLayout());
JLabel serverLabel = new JLabel("Server:", JLabel.RIGHT);
- if (options.defaults.getString("server") != null) {
- server = new JComboBox(options.defaults.getString("server").split(","));
+ if (UserPreferences.get("ServerDialog", "history") != null) {
+ String valueStr = UserPreferences.get("ServerDialog", "history");
+ server = new JComboBox(valueStr.split(","));
} else {
server = new JComboBox();
}
@@ -123,6 +124,11 @@ class ServerDialog extends Dialog implements
Object s = e.getSource();
if (s instanceof JButton && (JButton)s == okButton) {
ok = true;
+ String serverName = (String)server.getSelectedItem();
+ if (serverName != null) {
+ Configuration.setParam("Server", Hostname.getHost(serverName));
+ Configuration.setParam("Port", Integer.toString(Hostname.getPort(serverName)));
+ }
endDialog();
} else if (s instanceof JButton && (JButton)s == cancelButton) {
ok = false;
@@ -143,27 +149,23 @@ class ServerDialog extends Dialog implements
public void endDialog() {
if (ok) {
- try {
- if (!server.getSelectedItem().toString().equals("")) {
- String t = (options.defaults.getString("server")==null) ? "" : options.defaults.getString("server");
- StringTokenizer st = new StringTokenizer(t, ",");
- StringBuffer sb = new StringBuffer().append((String)server.getSelectedItem());
- while (st.hasMoreTokens()) {
- String s = st.nextToken();
- if (!s.equals((String)server.getSelectedItem()) && !s.equals("")) {
- sb.append(',');
- sb.append(s);
- }
+ if (!server.getSelectedItem().toString().equals("")) {
+ String valueStr = UserPreferences.get("ServerDialog", "history");
+ String t = (valueStr == null) ? "" : valueStr;
+ StringTokenizer st = new StringTokenizer(t, ",");
+ StringBuffer sb = new StringBuffer().append((String)server.getSelectedItem());
+ while (st.hasMoreTokens()) {
+ String s = st.nextToken();
+ if (!s.equals((String)server.getSelectedItem()) && !s.equals("")) {
+ sb.append(',');
+ sb.append(s);
}
- options.defaults.setPref("server", sb.toString());
}
- options.defaults.Save();
- } catch (java.io.IOException e) {
- System.out.println(e.toString());
- } catch(java.security.AccessControlException e) {
- System.out.println(e.toString());
- }
+ UserPreferences.set("ServerDialog", "history", sb.toString());
+ UserPreferences.save("ServerDialog");
+ }
}
+
done = true;
if (modal) {
synchronized (this) {
diff --git a/java/com/tigervnc/vncviewer/UserPreferences.java b/java/com/tigervnc/vncviewer/UserPreferences.java
new file mode 100644
index 00000000..95c56fbd
--- /dev/null
+++ b/java/com/tigervnc/vncviewer/UserPreferences.java
@@ -0,0 +1,149 @@
+/* Copyright (C) 2012 Brian P. Hinz
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
+ */
+
+//
+// For storing user preferences not specified as configuration parameters.
+//
+
+package com.tigervnc.vncviewer;
+
+import java.util.prefs.Preferences;
+import java.util.prefs.BackingStoreException;
+
+import com.tigervnc.rfb.*;
+
+public class UserPreferences {
+
+ private static Preferences root = Preferences.userRoot().node("TigerVNC");
+
+ public static void set(String nName, String key, String val) {
+ Preferences node = root.node(nName);
+ node.put(key, val);
+ }
+
+ public static void set(String nName, String key, int val) {
+ Preferences node = root.node(nName);
+ node.putInt(key, val);
+ }
+
+ public static void set(String nName, String key, boolean val) {
+ Preferences node = root.node(nName);
+ node.putBoolean(key, val);
+ }
+
+ public static String get(String nName, String key) {
+ Preferences node = root.node(nName);
+ VoidParameter p = Configuration.getParam(key);
+ if (p != null)
+ return node.get(key, p.getDefaultStr());
+ return node.get(key, null);
+ }
+
+ public static boolean getBool(String nName, String key, boolean defval) {
+ Preferences node = root.node(nName);
+ VoidParameter p = Configuration.getParam(key);
+ if (p != null && p.isBool())
+ return node.getBoolean(key, ((p.getDefaultStr() == "1") ? true : false));
+ // for non-parameter preferences
+ return node.getBoolean(key, defval);
+ }
+
+ public static boolean getBool(String nName, String key) {
+ // default value of "false" arbitrarily chosen
+ return getBool(nName, key, false);
+ }
+
+ public static int getInt(String nName, String key) {
+ Preferences node = root.node(nName);
+ VoidParameter p = Configuration.getParam(key);
+ if (p != null && !p.isBool())
+ return node.getInt(key, Integer.parseInt(p.getDefaultStr()));
+ // FIXME
+ return -1;
+ }
+
+ public static void save() {
+ try {
+ root.sync();
+ String[] keys = root.keys();
+ for (int i = 0; i < keys.length; i++)
+ vlog.debug(keys[i]+" = "+root.get(keys[i], null));
+ } catch (BackingStoreException e) {
+ vlog.error(e.getMessage());
+ }
+ }
+
+ public static void save(String nName) {
+ try {
+ Preferences node = root.node(nName);
+ node.sync();
+ String[] keys = root.keys();
+ for (int i = 0; i < keys.length; i++)
+ vlog.debug(keys[i]+" = "+node.get(keys[i], null));
+ } catch (BackingStoreException e) {
+ vlog.error(e.getMessage());
+ }
+ }
+
+ public static void clear() {
+ try {
+ root.clear();
+ String[] children = root.childrenNames();
+ for (int i = 0; i < children.length; i++) {
+ Preferences node = root.node(children[i]);
+ node.removeNode();
+ }
+ root.sync();
+ } catch (BackingStoreException e) {
+ vlog.error(e.getMessage());
+ }
+ }
+
+ public static void clear(String nName) {
+ try {
+ Preferences node = root.node(nName);
+ node.clear();
+ node.sync();
+ } catch (BackingStoreException e) {
+ vlog.error(e.getMessage());
+ }
+ }
+
+ public static void load(String nName) {
+ // Sets the value of any corresponding Configuration parameters
+ try {
+ Preferences node = root.node(nName);
+ String[] keys = node.keys();
+ for (int i = 0; i < keys.length; i++) {
+ String key = keys[i];
+ VoidParameter p = Configuration.getParam(key);
+ if (p == null)
+ continue;
+ String valueStr = node.get(key, null);
+ if (valueStr == null)
+ valueStr = p.getDefaultStr();
+ Configuration.setParam(key, valueStr);
+ }
+ } catch (BackingStoreException e) {
+ vlog.error(e.getMessage());
+ }
+ }
+
+ static LogWriter vlog = new LogWriter("UserPreferences");
+}
+
diff --git a/java/com/tigervnc/vncviewer/UserPrefs.java b/java/com/tigervnc/vncviewer/UserPrefs.java
deleted file mode 100644
index 3294d7f6..00000000
--- a/java/com/tigervnc/vncviewer/UserPrefs.java
+++ /dev/null
@@ -1,286 +0,0 @@
-/* Copyright (C) 2011 TigerVNC Team. All Rights Reserved.
- *
- * This is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this software; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
- * USA.
- */
-
-package com.tigervnc.vncviewer;
-
-import java.util.Properties;
-import java.io.FileOutputStream;
-import javax.swing.filechooser.*;
-
-/**
- * Simple, generic class to load up or save properties for an application.
- * (eg user preferences)
- *
- * While reading in values, it will automatically convert from string format,
- * to your choice of int or boolean, if desired.
- *
- * We assume that you want properties stored in a file named
- * $HOME/.yourappname, where $HOME represents the users "home directory"
- *
- * Feel free to email comments or suggestions to the author
- *
- * @version 1.0, 09/16/1997
- * @author Philip Brown phil@bolthole.com
- */
-
-public class UserPrefs extends Properties {
- String userhome=null; //This will have fileseparator on end if it
- String prefFile;
- String appName;
-
- Properties systemprops;
-
-
- /**
- * We try to read in a preferences file, from the user's "HOME"
- * directory. We base the name of the file, on the name of the
- * application we are in.
- * Use the getHomeDir() call if you want to know what directory
- * this is in.
- *
- * @param appName_ name of application calling this class
- */
- public UserPrefs(String appName_) {
- appName = appName_;
-
- try {
- systemprops=System.getProperties();
- } catch(java.security.AccessControlException e) {
- System.out.println("Cannot access system properties");
- }
- // This is guaranteed as always being some valid directory,
- // according to spec.
- prefFile= getHomeDir()+getFileSeparator()+
- "."+appName;
- try {
- load(new java.io.FileInputStream(prefFile));
- } catch(java.security.AccessControlException e) {
- System.out.println("Cannot access system properties");
- } catch (Exception err) {
- if(err instanceof java.io.FileNotFoundException) {
- try {
- store(new FileOutputStream(prefFile), appName+" preferences");
- } catch (Exception e) { /* FIXME */ }
- } else {
- // FIXME - should be a dialog
- System.out.println("Error opening prefs file:"+err.getMessage());
- }
- }
-
- }
-
- // Strip off any comments
- String trimValue(String prop) {
- if(prop==null)
- return null;
-
- int lastpos;
- lastpos=prop.indexOf('#');
- if(lastpos==-1)
- lastpos=prop.length()-1;
- while((prop.charAt(lastpos)==' ') ||
- (prop.charAt(lastpos)=='\t')) {
- lastpos--;
- if(lastpos==0)
- break;
- }
-
- return prop.substring(0, lastpos+1);
- }
-
- /**
- * The java spec guarantees that a "home" directory be
- * specified. We look it up for our own uses at initialization
- * If you want to do other things in the user's home dir,
- * this routine is an easy way to find out where it is.
- *
- * This returns string that will have trailing fileseparator, eg "/")
- * so you can slap together a filename directly after it, and
- * not worry about that sort of junk.
- */
- final public static String getHomeDir() {
- String homeDir = null;
- try {
- String os = System.getProperty("os.name");
- try {
- if (os.startsWith("Windows")) {
- // JRE prior to 1.5 cannot reliably determine USERPROFILE
- // return user.home and hope it's right...
- if (Integer.parseInt(System.getProperty("java.version").split("\\.")[1]) < 5) {
- try {
- homeDir = System.getProperty("user.home");
- } catch(java.security.AccessControlException e) {
- System.out.println("Cannot access user.home system property");
- }
- } else {
- homeDir = System.getenv("USERPROFILE");
- }
- } else {
- try {
- homeDir = FileSystemView.getFileSystemView().
- getDefaultDirectory().getCanonicalPath();
- } catch(java.security.AccessControlException e) {
- System.out.println("Cannot access system property");
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- } catch(java.security.AccessControlException e) {
- System.out.println("Cannot access os.name system property");
- }
- return homeDir;
- }
-
- final private String getUserName() {
- String userName = null;
- try {
- userName = (String) System.getProperties().get("user.name");
- } catch(java.security.AccessControlException e) {
- System.out.println("Cannot access user.name system property");
- }
- return userName;
- }
-
- final public static String getFileSeparator() {
- String separator = null;
- try {
- separator = Character.toString(java.io.File.separatorChar);
- } catch(java.security.AccessControlException e) {
- System.out.println("Cannot access file.separator system property");
- }
- return separator;
- }
-
- /**
- * way to directly set a preference. You'll have to
- * do your own type conversion.
- * @param prefname name of property
- * @param value string value of property
- */
- public void setPref(String prefname, String value) {
- setProperty(prefname, value);
- }
-
- public void setPref(String prefname, int value) {
- systemprops.put(prefname, java.lang.Integer.toString(value));
- }
-
- public void setPref(String prefname, boolean value) {
- put(prefname, (value ? "true" : "false"));
- }
-
- /**
- * Gets named resource, as a string value.
- * returns null if no such resource defined.
- * @param name name of property
- */
- public String getString(String name) {
- return trimValue(getProperty(name));
- }
- /**
- * Gets named resource, as a string value.
- *
- * @param name name of property
- * @param defval default value to remember and return , if
- * no existing property name found.
- */
- public String getString(String name, String defstr) {
- String val = trimValue(getProperty(name));
- if(val==null) {
- setPref(name, defstr);
- return defstr;
- }
- return val;
- }
-
- /**
- * look up property that is an int value
- * @param name name of property
- */
- public int getInt(String name) {
- String strint = trimValue(getProperty(name));
- int val=0;
- try {
- val = Integer.parseInt(strint);
- } catch (NumberFormatException err) {
- //we dont care
- }
- return val;
- }
-
- /**
- * look up property that is an int value
- * @param name name of property
- * @param defval default value to remember and return , if
- * no existing property name found.
- */
- public int getInt(String name, int defval) {
- String strint = trimValue(getProperty(name));
- if(strint==null) {
- setPref(name, String.valueOf(defval));
- return defval;
- }
- int val=0;
- try {
- val = Integer.parseInt(strint);
- } catch (NumberFormatException err) {
- //we dont care
- }
- return val;
- }
-
- /**
- * look up property that is a boolean value
- * @param name name of property
- * @param defval default value to remember and return , if
- * no existing property name found.
- */
- public boolean getBool(String name) {
- String strval = trimValue(getProperty(name));
- if(strval.equals("true"))
- return true;
-
- return false;
- }
-
- /**
- * @param name name of property
- * @param defval default value to remember and return , if
- * no existing property name found.
- */
- public boolean getBool(String name, boolean defval) {
- String strval = trimValue(getProperty(name));
- if(strval==null) {
- setPref(name, String.valueOf(defval));
- return defval;
- }
-
- if(strval.equals("true"))
- return true;
-
- return false;
- }
-
- /**
- * save user preferences to default file. Duh.
- */
- public void Save() throws java.io.IOException {
- store(new FileOutputStream(prefFile), appName+" preferences");
- }
-}
diff --git a/java/com/tigervnc/vncviewer/VncViewer.java b/java/com/tigervnc/vncviewer/VncViewer.java
index d045e532..f6ef2085 100644
--- a/java/com/tigervnc/vncviewer/VncViewer.java
+++ b/java/com/tigervnc/vncviewer/VncViewer.java
@@ -115,6 +115,9 @@ public class VncViewer extends java.applet.Applet implements Runnable
public VncViewer(String[] argv) {
applet = false;
+ // load user preferences
+ UserPreferences.load("global");
+
SecurityClient.setDefaults();
// Write about text to console, still using normal locale codeset
@@ -130,6 +133,12 @@ public class VncViewer extends java.applet.Applet implements Runnable
if (argv[i].length() == 0)
continue;
+ if (argv[i].equalsIgnoreCase("-config")) {
+ if (++i >= argv.length) usage();
+ Configuration.load(argv[i]);
+ continue;
+ }
+
if (argv[i].equalsIgnoreCase("-log")) {
if (++i >= argv.length) usage();
System.err.println("Log setting: "+argv[i]);
@@ -535,6 +544,10 @@ public class VncViewer extends java.applet.Applet implements Runnable
"0 = Low, 9 = High",
8);
+ StringParameter config
+ = new StringParameter("config",
+ "Specifies a configuration file to load.", null);
+
Thread thread;
Socket sock;
boolean applet;