* Built-in links for Registering & Upgrading OpenSubtitles accounts
This commit is contained in:
parent
f0566e8fa7
commit
162945c6e3
|
@ -234,17 +234,25 @@ public final class WebServices {
|
|||
}
|
||||
|
||||
public static String[] getLogin(String key) {
|
||||
return Settings.forPackage(WebServices.class).get(key, ":").split(":", 2);
|
||||
try {
|
||||
String[] values = Settings.forPackage(WebServices.class).get(key, ":").split(":", 2); // empty username/password by default
|
||||
if (values != null && values.length == 2 && values[0] != null && values[1] != null) {
|
||||
return values;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.getLogger(WebServices.class.getName()).log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
return new String[] { "", "" };
|
||||
}
|
||||
|
||||
public static void setLogin(String id, String user, String password) {
|
||||
Settings settings = Settings.forPackage(WebServices.class);
|
||||
String value = user.length() > 0 && password.length() > 0 ? user + ":" + password : null;
|
||||
if (value == null) {
|
||||
user = "";
|
||||
password = "";
|
||||
if (user == null || password == null || user.contains(":") || (user.isEmpty() && !password.isEmpty()) || (!user.isEmpty() && password.isEmpty())) {
|
||||
throw new IllegalArgumentException("Illegal login: " + user);
|
||||
}
|
||||
|
||||
Settings settings = Settings.forPackage(WebServices.class);
|
||||
String value = user.isEmpty() && password.isEmpty() ? null : user + ":" + password;
|
||||
|
||||
if (id.equals("osdb.user")) {
|
||||
settings.put(id, value);
|
||||
OpenSubtitles.setUser(user, password);
|
||||
|
|
|
@ -40,6 +40,7 @@ import net.filebot.ui.AbstractSearchPanel;
|
|||
import net.filebot.ui.LanguageComboBox;
|
||||
import net.filebot.ui.SelectDialog;
|
||||
import net.filebot.util.ui.LabelProvider;
|
||||
import net.filebot.util.ui.LinkButton;
|
||||
import net.filebot.util.ui.SimpleLabelProvider;
|
||||
import net.filebot.web.OpenSubtitlesClient;
|
||||
import net.filebot.web.SearchResult;
|
||||
|
@ -261,7 +262,18 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
|
|||
|
||||
osdbGroup.add(new JLabel("Password:"), "gap rel");
|
||||
final JPasswordField osdbPass = new JPasswordField(12);
|
||||
osdbGroup.add(osdbPass, "growx, wrap rel");
|
||||
osdbGroup.add(osdbPass, "growx, wrap unrel");
|
||||
|
||||
// restore values
|
||||
String[] osdbAuth = WebServices.getLogin("osdb.user");
|
||||
osdbUser.setText(osdbAuth[0]);
|
||||
osdbPass.setText(osdbAuth[1]);
|
||||
|
||||
if (osdbUser.getText().isEmpty()) {
|
||||
osdbGroup.add(new LinkButton("Register", WebServices.OpenSubtitles.getIcon(), URI.create("http://www.opensubtitles.org/en/newuser")), "spanx 2, tag help");
|
||||
} else {
|
||||
osdbGroup.add(new LinkButton("Upgrade", WebServices.OpenSubtitles.getIcon(), URI.create("http://www.opensubtitles.org/en/support")), "spanx 2, tag help");
|
||||
}
|
||||
|
||||
JRootPane container = authPanel.getRootPane();
|
||||
container.setLayout(new MigLayout("fill, insets dialog"));
|
||||
|
@ -304,11 +316,6 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
|
|||
container.add(new JButton(cancel), "tag cancel, split 2");
|
||||
container.add(new JButton(ok), "tag ok");
|
||||
|
||||
// restore values
|
||||
String[] osdbAuth = WebServices.getLogin("osdb.user");
|
||||
osdbUser.setText(osdbAuth[0]);
|
||||
osdbPass.setText(osdbAuth[1]);
|
||||
|
||||
authPanel.pack();
|
||||
authPanel.setVisible(true);
|
||||
}
|
||||
|
|
|
@ -423,7 +423,7 @@ public class SubtitleUploadDialog extends JDialog {
|
|||
icon = ResourceManager.getIcon("database.ok");
|
||||
break;
|
||||
case Identifying:
|
||||
text = "Auto-detecting missing information";
|
||||
text = "Auto-detect missing information";
|
||||
icon = ResourceManager.getIcon("action.export");
|
||||
break;
|
||||
case IdentificationRequired:
|
||||
|
|
Loading…
Reference in New Issue