* display OpenSubtitles download quota on login
This commit is contained in:
parent
77915ca7af
commit
3e790b1cc2
|
@ -1,7 +1,5 @@
|
|||
|
||||
package net.filebot.ui;
|
||||
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.net.URI;
|
||||
|
@ -17,63 +15,57 @@ 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"));
|
||||
|
||||
|
||||
setBackground(Color.WHITE);
|
||||
setOpaque(true);
|
||||
|
||||
|
||||
setupHeader();
|
||||
}
|
||||
|
||||
|
||||
private void setupHeader() {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
JLabel columnHeader = new JLabel();
|
||||
|
||||
|
||||
columnHeader.setFont(columnHeader.getFont().deriveFont(Font.BOLD));
|
||||
|
||||
|
||||
columnHeaders.add(columnHeader);
|
||||
|
||||
|
||||
add(columnHeader, getHeaderConstraint(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
||||
add(c1, "align left");
|
||||
|
||||
|
||||
// set minimum with to 100px so the text is aligned to the right,
|
||||
// even though the whole label is centered
|
||||
add(c2, "align center, wmin 100");
|
||||
|
||||
|
||||
add(c3, "align right");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
|
||||
package net.filebot.util.ui;
|
||||
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Desktop;
|
||||
|
@ -18,99 +16,92 @@ 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);
|
||||
|
||||
|
||||
setFocusPainted(false);
|
||||
setOpaque(false);
|
||||
setContentAreaFilled(false);
|
||||
setBorder(null);
|
||||
|
||||
|
||||
setHorizontalAlignment(LEFT);
|
||||
setIconTextGap(6);
|
||||
setRolloverEnabled(true);
|
||||
|
||||
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void setRolloverEnabled(boolean enabled) {
|
||||
super.setRolloverEnabled(enabled);
|
||||
|
||||
|
||||
// always remove listener if there is one
|
||||
removeMouseListener(rolloverListener);
|
||||
|
||||
|
||||
if (enabled) {
|
||||
// add listener again, if enabled
|
||||
addMouseListener(rolloverListener);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
protected final MouseListener rolloverListener = new MouseAdapter() {
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
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 {
|
||||
URI uri = (URI) getValue(URI);
|
||||
|
||||
|
||||
if (uri != null) {
|
||||
Desktop.getDesktop().browse(uri);
|
||||
}
|
||||
|
@ -120,5 +111,5 @@ public class LinkButton extends JButton {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue