diff --git a/src/com/sheepit/client/Configuration.java b/src/com/sheepit/client/Configuration.java index 84ab387..8b1750a 100644 --- a/src/com/sheepit/client/Configuration.java +++ b/src/com/sheepit/client/Configuration.java @@ -51,6 +51,7 @@ public class Configuration { private boolean printLog; public List> requestTime; private String extras; + private boolean autoSignIn; public Configuration(File cache_dir_, String login_, String password_) { this.login = login_; @@ -67,6 +68,7 @@ public class Configuration { this.printLog = false; this.requestTime = null; this.extras = ""; + this.autoSignIn = false; } public String toString() { @@ -185,6 +187,14 @@ public class Configuration { return this.extras; } + public void setAutoSignIn(boolean v) { + this.autoSignIn = v; + } + + public boolean getAutoSignIn() { + return this.autoSignIn; + } + public void cleanWorkingDirectory() { this.cleanDirectory(this.workingDirectory); this.cleanDirectory(this.storageDirectory); diff --git a/src/com/sheepit/client/standalone/swing/SettingsLoader.java b/src/com/sheepit/client/standalone/swing/SettingsLoader.java index 08195d8..dcd6d6e 100644 --- a/src/com/sheepit/client/standalone/swing/SettingsLoader.java +++ b/src/com/sheepit/client/standalone/swing/SettingsLoader.java @@ -21,16 +21,18 @@ public class SettingsLoader { private String computeMethod; private String gpu; private String cacheDir; + private String autoSignIn; public SettingsLoader() { generateFilePath(); } - public SettingsLoader(String login_, String password_, ComputeType computeMethod_, GPUDevice gpu_, String cacheDir_) { + public SettingsLoader(String login_, String password_, ComputeType computeMethod_, GPUDevice gpu_, String cacheDir_, boolean autoSignIn_) { generateFilePath(); login = login_; password = password_; cacheDir = cacheDir_; + autoSignIn = String.valueOf(autoSignIn_); if (computeMethod_ != null) { try { @@ -79,6 +81,10 @@ public class SettingsLoader { prop.setProperty("password", password); } + if (autoSignIn != null) { + prop.setProperty("auto-signin", autoSignIn); + } + prop.store(output, null); } catch (IOException io) { @@ -102,6 +108,7 @@ public class SettingsLoader { this.computeMethod = null; this.gpu = null; this.cacheDir = null; + this.autoSignIn = null; if (new File(path).exists() == false) { return; @@ -132,6 +139,10 @@ public class SettingsLoader { if (prop.containsKey("password")) { this.password = prop.getProperty("password"); } + + if (prop.containsKey("auto-signin")) { + this.autoSignIn = prop.getProperty("auto-signin"); + } } catch (IOException io) { io.printStackTrace(); @@ -178,6 +189,8 @@ public class SettingsLoader { if (config.getUserSpecifiedACacheDir() == false && cacheDir != null) { config.setCacheDir(new File(cacheDir)); } + + config.setAutoSignIn(Boolean.valueOf(autoSignIn)); } @Override diff --git a/src/com/sheepit/client/standalone/swing/activity/Settings.java b/src/com/sheepit/client/standalone/swing/activity/Settings.java index 9855ea5..f421b87 100644 --- a/src/com/sheepit/client/standalone/swing/activity/Settings.java +++ b/src/com/sheepit/client/standalone/swing/activity/Settings.java @@ -38,12 +38,16 @@ public class Settings implements Activity { private List useGPUs; private JCheckBox saveFile; + private JCheckBox autoSignIn; JButton saveButton; + private boolean haveAutoStarted; + public Settings(GuiSwing parent_) { parent = parent_; cacheDir = null; useGPUs = new LinkedList(); + haveAutoStarted = false; } @Override @@ -165,6 +169,13 @@ public class Settings implements Activity { saveFile.setBounds(start_label_right, n, end_label_right - start_label_right, size_height_label); parent.getContentPane().add(saveFile); + n += 20; + + autoSignIn = new JCheckBox("Auto sign in", config.getAutoSignIn()); + autoSignIn.setBounds(start_label_right, n, end_label_right - start_label_right, size_height_label); + autoSignIn.addActionListener(new AutoSignInChangeAction()); + parent.getContentPane().add(autoSignIn); + n += sep; saveButton = new JButton("Start"); @@ -172,10 +183,14 @@ public class Settings implements Activity { saveButton.addActionListener(new SaveAction()); parent.getContentPane().add(saveButton); - checkDisplaySaveButton(); + if (haveAutoStarted == false && config.getAutoSignIn() && checkDisplaySaveButton()) { + // auto start + haveAutoStarted = true; + new SaveAction().actionPerformed(null); + } } - public void checkDisplaySaveButton() { + public boolean checkDisplaySaveButton() { boolean selected = useCPU.isSelected(); for (JCheckBoxGPU box : useGPUs) { if (box.isSelected()) { @@ -186,6 +201,7 @@ public class Settings implements Activity { selected = false; } saveButton.setEnabled(selected); + return selected; } class ChooseFileAction implements ActionListener { @@ -287,7 +303,7 @@ public class Settings implements Activity { } if (saveFile.isSelected()) { - new SettingsLoader(login.getText(), new String(password.getPassword()), method, selected_gpu, cachePath).saveFile(); + new SettingsLoader(login.getText(), new String(password.getPassword()), method, selected_gpu, cachePath, autoSignIn.isSelected()).saveFile(); } else { try {