The client can auto-start and auto-signin

This commit is contained in:
Laurent Clouet
2015-04-03 19:50:58 +01:00
parent ebe6914624
commit eb0f762625
3 changed files with 43 additions and 4 deletions

View File

@@ -51,6 +51,7 @@ public class Configuration {
private boolean printLog; private boolean printLog;
public List<Pair<Calendar, Calendar>> requestTime; public List<Pair<Calendar, Calendar>> requestTime;
private String extras; private String extras;
private boolean autoSignIn;
public Configuration(File cache_dir_, String login_, String password_) { public Configuration(File cache_dir_, String login_, String password_) {
this.login = login_; this.login = login_;
@@ -67,6 +68,7 @@ public class Configuration {
this.printLog = false; this.printLog = false;
this.requestTime = null; this.requestTime = null;
this.extras = ""; this.extras = "";
this.autoSignIn = false;
} }
public String toString() { public String toString() {
@@ -185,6 +187,14 @@ public class Configuration {
return this.extras; return this.extras;
} }
public void setAutoSignIn(boolean v) {
this.autoSignIn = v;
}
public boolean getAutoSignIn() {
return this.autoSignIn;
}
public void cleanWorkingDirectory() { public void cleanWorkingDirectory() {
this.cleanDirectory(this.workingDirectory); this.cleanDirectory(this.workingDirectory);
this.cleanDirectory(this.storageDirectory); this.cleanDirectory(this.storageDirectory);

View File

@@ -21,16 +21,18 @@ public class SettingsLoader {
private String computeMethod; private String computeMethod;
private String gpu; private String gpu;
private String cacheDir; private String cacheDir;
private String autoSignIn;
public SettingsLoader() { public SettingsLoader() {
generateFilePath(); 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(); generateFilePath();
login = login_; login = login_;
password = password_; password = password_;
cacheDir = cacheDir_; cacheDir = cacheDir_;
autoSignIn = String.valueOf(autoSignIn_);
if (computeMethod_ != null) { if (computeMethod_ != null) {
try { try {
@@ -79,6 +81,10 @@ public class SettingsLoader {
prop.setProperty("password", password); prop.setProperty("password", password);
} }
if (autoSignIn != null) {
prop.setProperty("auto-signin", autoSignIn);
}
prop.store(output, null); prop.store(output, null);
} }
catch (IOException io) { catch (IOException io) {
@@ -102,6 +108,7 @@ public class SettingsLoader {
this.computeMethod = null; this.computeMethod = null;
this.gpu = null; this.gpu = null;
this.cacheDir = null; this.cacheDir = null;
this.autoSignIn = null;
if (new File(path).exists() == false) { if (new File(path).exists() == false) {
return; return;
@@ -132,6 +139,10 @@ public class SettingsLoader {
if (prop.containsKey("password")) { if (prop.containsKey("password")) {
this.password = prop.getProperty("password"); this.password = prop.getProperty("password");
} }
if (prop.containsKey("auto-signin")) {
this.autoSignIn = prop.getProperty("auto-signin");
}
} }
catch (IOException io) { catch (IOException io) {
io.printStackTrace(); io.printStackTrace();
@@ -178,6 +189,8 @@ public class SettingsLoader {
if (config.getUserSpecifiedACacheDir() == false && cacheDir != null) { if (config.getUserSpecifiedACacheDir() == false && cacheDir != null) {
config.setCacheDir(new File(cacheDir)); config.setCacheDir(new File(cacheDir));
} }
config.setAutoSignIn(Boolean.valueOf(autoSignIn));
} }
@Override @Override

View File

@@ -38,12 +38,16 @@ public class Settings implements Activity {
private List<JCheckBoxGPU> useGPUs; private List<JCheckBoxGPU> useGPUs;
private JCheckBox saveFile; private JCheckBox saveFile;
private JCheckBox autoSignIn;
JButton saveButton; JButton saveButton;
private boolean haveAutoStarted;
public Settings(GuiSwing parent_) { public Settings(GuiSwing parent_) {
parent = parent_; parent = parent_;
cacheDir = null; cacheDir = null;
useGPUs = new LinkedList<JCheckBoxGPU>(); useGPUs = new LinkedList<JCheckBoxGPU>();
haveAutoStarted = false;
} }
@Override @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); saveFile.setBounds(start_label_right, n, end_label_right - start_label_right, size_height_label);
parent.getContentPane().add(saveFile); 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; n += sep;
saveButton = new JButton("Start"); saveButton = new JButton("Start");
@@ -172,10 +183,14 @@ public class Settings implements Activity {
saveButton.addActionListener(new SaveAction()); saveButton.addActionListener(new SaveAction());
parent.getContentPane().add(saveButton); 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(); boolean selected = useCPU.isSelected();
for (JCheckBoxGPU box : useGPUs) { for (JCheckBoxGPU box : useGPUs) {
if (box.isSelected()) { if (box.isSelected()) {
@@ -186,6 +201,7 @@ public class Settings implements Activity {
selected = false; selected = false;
} }
saveButton.setEnabled(selected); saveButton.setEnabled(selected);
return selected;
} }
class ChooseFileAction implements ActionListener { class ChooseFileAction implements ActionListener {
@@ -287,7 +303,7 @@ public class Settings implements Activity {
} }
if (saveFile.isSelected()) { 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 { else {
try { try {