* display OpenSubtitles download quota on login
This commit is contained in:
parent
77915ca7af
commit
3e790b1cc2
|
@ -1,7 +1,5 @@
|
||||||
|
|
||||||
package net.filebot.ui;
|
package net.filebot.ui;
|
||||||
|
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
@ -17,12 +15,10 @@ import javax.swing.SwingConstants;
|
||||||
import net.filebot.util.ui.LinkButton;
|
import net.filebot.util.ui.LinkButton;
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
|
|
||||||
|
|
||||||
public class HistoryPanel extends JPanel {
|
public class HistoryPanel extends JPanel {
|
||||||
|
|
||||||
private final List<JLabel> columnHeaders = new ArrayList<JLabel>(3);
|
private final List<JLabel> columnHeaders = new ArrayList<JLabel>(3);
|
||||||
|
|
||||||
|
|
||||||
public HistoryPanel() {
|
public HistoryPanel() {
|
||||||
super(new MigLayout("fillx, insets 10 30 10 50, wrap 3"));
|
super(new MigLayout("fillx, insets 10 30 10 50, wrap 3"));
|
||||||
|
|
||||||
|
@ -32,7 +28,6 @@ public class HistoryPanel extends JPanel {
|
||||||
setupHeader();
|
setupHeader();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setupHeader() {
|
private void setupHeader() {
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
JLabel columnHeader = new JLabel();
|
JLabel columnHeader = new JLabel();
|
||||||
|
@ -45,7 +40,6 @@ public class HistoryPanel extends JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String getHeaderConstraint(int headerIndex) {
|
private String getHeaderConstraint(int headerIndex) {
|
||||||
switch (headerIndex) {
|
switch (headerIndex) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -57,14 +51,12 @@ public class HistoryPanel extends JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setColumnHeader(int index, String text) {
|
public void setColumnHeader(int index, String text) {
|
||||||
columnHeaders.get(index).setText(text);
|
columnHeaders.get(index).setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void add(String column1, URI link, Icon icon, String column2, String column3) {
|
public void add(String column1, URI link, Icon icon, String column2, String column3) {
|
||||||
JComponent c1 = link != null ? new LinkButton(column1, icon, link) : new JLabel(column1, icon, SwingConstants.LEFT);
|
JComponent c1 = link != null ? new LinkButton(column1, null, icon, link) : new JLabel(column1, icon, SwingConstants.LEFT);
|
||||||
JComponent c2 = new JLabel(column2, SwingConstants.RIGHT);
|
JComponent c2 = new JLabel(column2, SwingConstants.RIGHT);
|
||||||
JComponent c3 = new JLabel(column3, SwingConstants.RIGHT);
|
JComponent c3 = new JLabel(column3, SwingConstants.RIGHT);
|
||||||
|
|
||||||
|
|
|
@ -170,7 +170,7 @@ class SubtitleAutoMatchDialog extends JDialog {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addSubtitleService(final SubtitleServiceBean service, final JPanel servicePanel) {
|
protected void addSubtitleService(final SubtitleServiceBean service, final JPanel servicePanel) {
|
||||||
final LinkButton component = new LinkButton(service.getName(), ResourceManager.getIcon("database"), service.getLink());
|
final LinkButton component = new LinkButton(service.getName(), null, ResourceManager.getIcon("database"), service.getLink());
|
||||||
component.setBorder(BorderFactory.createEmptyBorder());
|
component.setBorder(BorderFactory.createEmptyBorder());
|
||||||
component.setVisible(false);
|
component.setVisible(false);
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,9 @@ import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.swing.AbstractAction;
|
import javax.swing.AbstractAction;
|
||||||
import javax.swing.Action;
|
import javax.swing.Action;
|
||||||
|
@ -284,9 +286,9 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
|
||||||
osdbPass.setText(osdbAuth[1]);
|
osdbPass.setText(osdbAuth[1]);
|
||||||
|
|
||||||
if (osdbUser.getText().isEmpty()) {
|
if (osdbUser.getText().isEmpty()) {
|
||||||
osdbGroup.add(new LinkButton("Register", WebServices.OpenSubtitles.getIcon(), URI.create("http://www.opensubtitles.org/en/newuser")), "spanx 2, tag help");
|
osdbGroup.add(new LinkButton("Register", "Register to increase your download quota", WebServices.OpenSubtitles.getIcon(), URI.create("http://www.opensubtitles.org/en/newuser")), "spanx 2, tag left");
|
||||||
} else {
|
} else {
|
||||||
osdbGroup.add(new LinkButton("Upgrade", WebServices.OpenSubtitles.getIcon(), URI.create("http://www.opensubtitles.org/en/support")), "spanx 2, tag help");
|
osdbGroup.add(new LinkButton("Upgrade", "Upgrade to increase your download quota", WebServices.OpenSubtitles.getIcon(), URI.create("http://www.opensubtitles.org/en/support")), "spanx 2, tag left");
|
||||||
}
|
}
|
||||||
|
|
||||||
JRootPane container = authPanel.getRootPane();
|
JRootPane container = authPanel.getRootPane();
|
||||||
|
@ -304,9 +306,23 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (osdbUser.getText().length() > 0 && osdbPass.getPassword().length > 0) {
|
if (osdbUser.getText().length() > 0 && osdbPass.getPassword().length > 0) {
|
||||||
OpenSubtitlesClient osdb = new OpenSubtitlesClient(getApplicationName(), getApplicationVersion());
|
final OpenSubtitlesClient osdb = new OpenSubtitlesClient(getApplicationName(), getApplicationVersion());
|
||||||
osdb.setUser(osdbUser.getText(), new String(osdbPass.getPassword()));
|
osdb.setUser(osdbUser.getText(), new String(osdbPass.getPassword()));
|
||||||
osdb.login();
|
osdb.login();
|
||||||
|
|
||||||
|
// do some status checks in background (since OpenSubtitles can be really really slow)
|
||||||
|
WebServices.requestThreadPool.submit(() -> {
|
||||||
|
try {
|
||||||
|
// check download quota for the current user
|
||||||
|
Map<?, ?> limits = (Map<?, ?>) osdb.getServerInfo().get("download_limits");
|
||||||
|
UILogger.log(Level.INFO, String.format("Your daily download quota is at %s of %s.", limits.get("client_24h_download_count"), limits.get("client_24h_download_limit")));
|
||||||
|
|
||||||
|
// logout from test session
|
||||||
|
osdb.logout();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Logger.getLogger(SubtitlePanel.class.getName()).log(Level.WARNING, e.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
UILogger.log(Level.WARNING, "OpenSubtitles: " + e.getMessage());
|
UILogger.log(Level.WARNING, "OpenSubtitles: " + e.getMessage());
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
|
|
||||||
package net.filebot.util.ui;
|
package net.filebot.util.ui;
|
||||||
|
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Cursor;
|
import java.awt.Cursor;
|
||||||
import java.awt.Desktop;
|
import java.awt.Desktop;
|
||||||
|
@ -18,18 +16,15 @@ import javax.swing.Action;
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
|
|
||||||
|
|
||||||
public class LinkButton extends JButton {
|
public class LinkButton extends JButton {
|
||||||
|
|
||||||
private Color color = getForeground();
|
private Color color = getForeground();
|
||||||
private Color rolloverColor = new Color(0x3399FF);
|
private Color rolloverColor = new Color(0x3399FF);
|
||||||
|
|
||||||
|
public LinkButton(String text, String tooltip, Icon icon, URI uri) {
|
||||||
public LinkButton(String text, Icon icon, URI uri) {
|
this(new OpenUriAction(text, tooltip, icon, uri));
|
||||||
this(new OpenUriAction(text, icon, uri));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public LinkButton(Action action) {
|
public LinkButton(Action action) {
|
||||||
setAction(action);
|
setAction(action);
|
||||||
|
|
||||||
|
@ -45,7 +40,6 @@ public class LinkButton extends JButton {
|
||||||
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setRolloverEnabled(boolean enabled) {
|
public void setRolloverEnabled(boolean enabled) {
|
||||||
super.setRolloverEnabled(enabled);
|
super.setRolloverEnabled(enabled);
|
||||||
|
@ -59,23 +53,19 @@ public class LinkButton extends JButton {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Color getColor() {
|
public Color getColor() {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setColor(Color color) {
|
public void setColor(Color color) {
|
||||||
this.color = color;
|
this.color = color;
|
||||||
this.setForeground(color);
|
this.setForeground(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Color getRolloverColor() {
|
public Color getRolloverColor() {
|
||||||
return rolloverColor;
|
return rolloverColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setRolloverColor(Color rolloverColor) {
|
public void setRolloverColor(Color rolloverColor) {
|
||||||
this.rolloverColor = rolloverColor;
|
this.rolloverColor = rolloverColor;
|
||||||
}
|
}
|
||||||
|
@ -87,24 +77,25 @@ public class LinkButton extends JButton {
|
||||||
setForeground(rolloverColor);
|
setForeground(rolloverColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseExited(MouseEvent e) {
|
public void mouseExited(MouseEvent e) {
|
||||||
setForeground(color);
|
setForeground(color);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
protected static class OpenUriAction extends AbstractAction {
|
protected static class OpenUriAction extends AbstractAction {
|
||||||
|
|
||||||
public static final String URI = "uri";
|
public static final String URI = "uri";
|
||||||
|
|
||||||
|
public OpenUriAction(String text, String tooltip, Icon icon, URI uri) {
|
||||||
public OpenUriAction(String text, Icon icon, URI uri) {
|
|
||||||
super(text, icon);
|
super(text, icon);
|
||||||
|
if (uri != null) {
|
||||||
putValue(URI, uri);
|
putValue(URI, uri);
|
||||||
}
|
}
|
||||||
|
if (tooltip != null) {
|
||||||
|
putValue(SHORT_DESCRIPTION, tooltip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent evt) {
|
public void actionPerformed(ActionEvent evt) {
|
||||||
|
|
|
@ -505,7 +505,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
|
||||||
logoutTimer.set(10, TimeUnit.MINUTES, true);
|
logoutTimer.set(10, TimeUnit.MINUTES, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected synchronized void logout() {
|
public synchronized void logout() {
|
||||||
if (xmlrpc.isLoggedOn()) {
|
if (xmlrpc.isLoggedOn()) {
|
||||||
try {
|
try {
|
||||||
xmlrpc.logout();
|
xmlrpc.logout();
|
||||||
|
|
|
@ -324,6 +324,8 @@ public class OpenSubtitlesXmlRpc {
|
||||||
|
|
||||||
// rethrow exception
|
// rethrow exception
|
||||||
throw e;
|
throw e;
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
throw new XmlRpcFault(500, "The remote server returned an unexpected response");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue