* display OpenSubtitles download quota on login

This commit is contained in:
Reinhard Pointner 2014-11-08 11:17:00 +00:00
parent 77915ca7af
commit 3e790b1cc2
6 changed files with 71 additions and 70 deletions

View File

@ -1,7 +1,5 @@
package net.filebot.ui;
import java.awt.Color;
import java.awt.Font;
import java.net.URI;
@ -17,12 +15,10 @@ import javax.swing.SwingConstants;
import net.filebot.util.ui.LinkButton;
import net.miginfocom.swing.MigLayout;
public class HistoryPanel extends JPanel {
private final List<JLabel> columnHeaders = new ArrayList<JLabel>(3);
public HistoryPanel() {
super(new MigLayout("fillx, insets 10 30 10 50, wrap 3"));
@ -32,7 +28,6 @@ public class HistoryPanel extends JPanel {
setupHeader();
}
private void setupHeader() {
for (int i = 0; i < 3; i++) {
JLabel columnHeader = new JLabel();
@ -45,26 +40,23 @@ public class HistoryPanel extends JPanel {
}
}
private String getHeaderConstraint(int headerIndex) {
switch (headerIndex) {
case 0:
return "align left, gapbefore 24";
case 1:
return "align center";
default:
return "align right, gapafter 12";
case 0:
return "align left, gapbefore 24";
case 1:
return "align center";
default:
return "align right, gapafter 12";
}
}
public void setColumnHeader(int index, String text) {
columnHeaders.get(index).setText(text);
}
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 c3 = new JLabel(column3, SwingConstants.RIGHT);

View File

@ -170,7 +170,7 @@ class SubtitleAutoMatchDialog extends JDialog {
}
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.setVisible(false);

View File

@ -18,7 +18,9 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.Action;
@ -284,9 +286,9 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
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");
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 {
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();
@ -304,9 +306,23 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
try {
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.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) {
UILogger.log(Level.WARNING, "OpenSubtitles: " + e.getMessage());

View File

@ -1,7 +1,5 @@
package net.filebot.util.ui;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Desktop;
@ -18,18 +16,15 @@ import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JButton;
public class LinkButton extends JButton {
private Color color = getForeground();
private Color rolloverColor = new Color(0x3399FF);
public LinkButton(String text, Icon icon, URI uri) {
this(new OpenUriAction(text, icon, uri));
public LinkButton(String text, String tooltip, Icon icon, URI uri) {
this(new OpenUriAction(text, tooltip, icon, uri));
}
public LinkButton(Action action) {
setAction(action);
@ -45,7 +40,6 @@ public class LinkButton extends JButton {
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
@Override
public void setRolloverEnabled(boolean enabled) {
super.setRolloverEnabled(enabled);
@ -59,23 +53,19 @@ public class LinkButton extends JButton {
}
}
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
this.setForeground(color);
}
public Color getRolloverColor() {
return rolloverColor;
}
public void setRolloverColor(Color rolloverColor) {
this.rolloverColor = rolloverColor;
}
@ -87,25 +77,26 @@ public class LinkButton extends JButton {
setForeground(rolloverColor);
}
@Override
public void mouseExited(MouseEvent e) {
setForeground(color);
}
};
protected static class OpenUriAction extends AbstractAction {
public static final String URI = "uri";
public OpenUriAction(String text, Icon icon, URI uri) {
public OpenUriAction(String text, String tooltip, Icon icon, URI uri) {
super(text, icon);
putValue(URI, uri);
if (uri != null) {
putValue(URI, uri);
}
if (tooltip != null) {
putValue(SHORT_DESCRIPTION, tooltip);
}
}
@Override
public void actionPerformed(ActionEvent evt) {
try {

View File

@ -505,7 +505,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
logoutTimer.set(10, TimeUnit.MINUTES, true);
}
protected synchronized void logout() {
public synchronized void logout() {
if (xmlrpc.isLoggedOn()) {
try {
xmlrpc.logout();

View File

@ -324,6 +324,8 @@ public class OpenSubtitlesXmlRpc {
// rethrow exception
throw e;
} catch (ClassCastException e) {
throw new XmlRpcFault(500, "The remote server returned an unexpected response");
}
}