2014-03-01 11:13:32 +01:00
|
|
|
package com.rarchives.ripme.ui;
|
|
|
|
|
2014-03-02 10:12:20 +01:00
|
|
|
import java.awt.Color;
|
2014-03-02 08:28:37 +01:00
|
|
|
import java.awt.Container;
|
2014-03-02 03:08:16 +01:00
|
|
|
import java.awt.Desktop;
|
2014-03-02 10:12:20 +01:00
|
|
|
import java.awt.Dimension;
|
2014-03-02 08:28:37 +01:00
|
|
|
import java.awt.GridBagConstraints;
|
|
|
|
import java.awt.GridBagLayout;
|
2014-03-01 11:13:32 +01:00
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
import java.awt.event.ActionListener;
|
2014-03-08 21:22:49 +01:00
|
|
|
import java.io.BufferedReader;
|
2014-03-01 11:13:32 +01:00
|
|
|
import java.io.File;
|
2014-03-08 21:22:49 +01:00
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.FileReader;
|
|
|
|
import java.io.FileWriter;
|
|
|
|
import java.io.IOException;
|
2014-03-09 08:59:36 +01:00
|
|
|
import java.net.MalformedURLException;
|
2014-03-01 11:13:32 +01:00
|
|
|
import java.net.URL;
|
|
|
|
|
2014-03-08 21:22:49 +01:00
|
|
|
import javax.swing.DefaultListModel;
|
2014-03-01 11:13:32 +01:00
|
|
|
import javax.swing.JButton;
|
2014-04-06 01:57:54 +02:00
|
|
|
import javax.swing.JCheckBox;
|
2014-03-01 11:13:32 +01:00
|
|
|
import javax.swing.JFrame;
|
|
|
|
import javax.swing.JLabel;
|
2014-03-02 10:12:20 +01:00
|
|
|
import javax.swing.JList;
|
2014-03-02 03:08:16 +01:00
|
|
|
import javax.swing.JPanel;
|
2014-03-02 08:28:37 +01:00
|
|
|
import javax.swing.JProgressBar;
|
|
|
|
import javax.swing.JScrollPane;
|
2014-03-01 11:13:32 +01:00
|
|
|
import javax.swing.JTextField;
|
2014-03-02 08:28:37 +01:00
|
|
|
import javax.swing.JTextPane;
|
2014-03-09 08:59:36 +01:00
|
|
|
import javax.swing.ListSelectionModel;
|
2014-03-08 21:22:49 +01:00
|
|
|
import javax.swing.SwingUtilities;
|
2014-03-02 08:28:37 +01:00
|
|
|
import javax.swing.border.EmptyBorder;
|
2014-03-02 10:12:20 +01:00
|
|
|
import javax.swing.text.BadLocationException;
|
|
|
|
import javax.swing.text.SimpleAttributeSet;
|
|
|
|
import javax.swing.text.StyleConstants;
|
|
|
|
import javax.swing.text.StyledDocument;
|
2014-03-02 03:08:16 +01:00
|
|
|
|
|
|
|
import org.apache.log4j.Logger;
|
2014-03-01 11:13:32 +01:00
|
|
|
|
|
|
|
import com.rarchives.ripme.ripper.AbstractRipper;
|
2014-03-02 03:08:16 +01:00
|
|
|
import com.rarchives.ripme.utils.Utils;
|
2014-03-01 11:13:32 +01:00
|
|
|
|
2014-03-09 09:20:22 +01:00
|
|
|
/**
|
|
|
|
* Everything UI-related starts and ends here.
|
|
|
|
*/
|
2014-03-13 20:18:35 +01:00
|
|
|
public class MainWindow implements Runnable, RipStatusHandler {
|
2014-03-01 11:13:32 +01:00
|
|
|
|
2014-03-02 03:08:16 +01:00
|
|
|
private static final Logger logger = Logger.getLogger(MainWindow.class);
|
2014-03-09 08:59:36 +01:00
|
|
|
|
2014-03-01 11:13:32 +01:00
|
|
|
private static final String WINDOW_TITLE = "RipMe";
|
2014-03-08 21:22:49 +01:00
|
|
|
private static final String HISTORY_FILE = ".history";
|
2014-03-01 11:13:32 +01:00
|
|
|
|
|
|
|
private static JFrame mainFrame;
|
|
|
|
private static JTextField ripTextfield;
|
|
|
|
private static JButton ripButton;
|
|
|
|
|
2014-03-02 03:08:16 +01:00
|
|
|
private static JLabel statusLabel;
|
2014-03-02 08:28:37 +01:00
|
|
|
private static JButton openButton;
|
|
|
|
private static JProgressBar statusProgress;
|
|
|
|
|
2014-03-02 10:12:20 +01:00
|
|
|
// Log
|
|
|
|
private static JButton optionLog;
|
|
|
|
private static JPanel logPanel;
|
|
|
|
private static JTextPane logText;
|
|
|
|
private static JScrollPane logTextScroll;
|
2014-03-01 11:13:32 +01:00
|
|
|
|
2014-03-02 10:12:20 +01:00
|
|
|
// History
|
|
|
|
private static JButton optionHistory;
|
|
|
|
private static JPanel historyPanel;
|
|
|
|
private static JList historyList;
|
2014-03-08 21:22:49 +01:00
|
|
|
private static DefaultListModel historyListModel;
|
2014-03-02 10:12:20 +01:00
|
|
|
private static JScrollPane historyListScroll;
|
2014-03-09 08:59:36 +01:00
|
|
|
private static JPanel historyButtonPanel;
|
2014-03-08 21:22:49 +01:00
|
|
|
private static JButton historyButtonRemove,
|
|
|
|
historyButtonClear,
|
|
|
|
historyButtonRerip;
|
2014-03-02 10:12:20 +01:00
|
|
|
|
|
|
|
// Configuration
|
|
|
|
private static JButton optionConfiguration;
|
|
|
|
private static JPanel configurationPanel;
|
2014-04-05 10:39:10 +02:00
|
|
|
private static JButton configUpdateButton;
|
|
|
|
private static JLabel configUpdateLabel;
|
2014-04-06 01:57:54 +02:00
|
|
|
private static JTextField configTimeoutText;
|
|
|
|
private static JTextField configThreadsText;
|
|
|
|
private static JCheckBox configOverwriteCheckbox;
|
2014-03-02 10:12:20 +01:00
|
|
|
// TODO Configuration components
|
|
|
|
|
2014-03-01 11:13:32 +01:00
|
|
|
public MainWindow() {
|
2014-04-06 01:57:54 +02:00
|
|
|
mainFrame = new JFrame(WINDOW_TITLE + " v" + UpdateUtils.getThisJarVersion());
|
2014-03-01 11:13:32 +01:00
|
|
|
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
2014-03-02 10:12:20 +01:00
|
|
|
//mainFrame.setPreferredSize(new Dimension(400, 180));
|
|
|
|
//mainFrame.setResizable(false);
|
2014-03-02 08:28:37 +01:00
|
|
|
mainFrame.setLayout(new GridBagLayout());
|
|
|
|
|
|
|
|
createUI(mainFrame.getContentPane());
|
2014-03-08 21:22:49 +01:00
|
|
|
loadHistory();
|
2014-03-02 08:28:37 +01:00
|
|
|
setupHandlers();
|
2014-03-01 11:13:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
mainFrame.pack();
|
|
|
|
mainFrame.setLocationRelativeTo(null);
|
|
|
|
mainFrame.setVisible(true);
|
|
|
|
}
|
|
|
|
|
2014-03-13 20:38:11 +01:00
|
|
|
private void status(String text) {
|
2014-04-04 10:08:04 +02:00
|
|
|
statusWithColor(text, Color.BLACK);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void error(String text) {
|
|
|
|
statusWithColor(text, Color.RED);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void statusWithColor(String text, Color color) {
|
|
|
|
statusLabel.setForeground(color);
|
2014-03-02 03:08:16 +01:00
|
|
|
statusLabel.setText(text);
|
2014-03-02 08:28:37 +01:00
|
|
|
mainFrame.pack();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void createUI(Container pane) {
|
|
|
|
EmptyBorder emptyBorder = new EmptyBorder(5, 5, 5, 5);
|
|
|
|
GridBagConstraints gbc = new GridBagConstraints();
|
2014-03-02 10:12:20 +01:00
|
|
|
gbc.fill = GridBagConstraints.BOTH;
|
|
|
|
gbc.weightx = 2; gbc.ipadx = 2; gbc.gridx = 0;
|
|
|
|
gbc.weighty = 2; gbc.ipady = 2; gbc.gridy = 0;
|
2014-03-02 08:28:37 +01:00
|
|
|
|
|
|
|
ripTextfield = new JTextField("", 20);
|
2014-03-08 21:22:49 +01:00
|
|
|
ripButton = new JButton("Rip");
|
2014-03-02 08:28:37 +01:00
|
|
|
JPanel ripPanel = new JPanel(new GridBagLayout());
|
|
|
|
ripPanel.setBorder(emptyBorder);
|
|
|
|
|
2014-03-08 21:22:49 +01:00
|
|
|
gbc.gridx = 0; ripPanel.add(new JLabel("URL:", JLabel.RIGHT), gbc);
|
|
|
|
gbc.gridx = 1; ripPanel.add(ripTextfield, gbc);
|
|
|
|
gbc.gridx = 2; ripPanel.add(ripButton, gbc);
|
2014-03-02 08:28:37 +01:00
|
|
|
|
|
|
|
statusLabel = new JLabel("Inactive");
|
2014-03-02 10:12:20 +01:00
|
|
|
statusLabel.setHorizontalAlignment(JLabel.CENTER);
|
2014-03-02 08:28:37 +01:00
|
|
|
openButton = new JButton();
|
|
|
|
openButton.setVisible(false);
|
|
|
|
JPanel statusPanel = new JPanel(new GridBagLayout());
|
|
|
|
statusPanel.setBorder(emptyBorder);
|
2014-03-02 10:12:20 +01:00
|
|
|
|
|
|
|
gbc.gridx = 0;
|
2014-03-02 08:28:37 +01:00
|
|
|
statusPanel.add(statusLabel, gbc);
|
|
|
|
statusPanel.add(openButton, gbc);
|
|
|
|
|
|
|
|
JPanel progressPanel = new JPanel(new GridBagLayout());
|
|
|
|
progressPanel.setBorder(emptyBorder);
|
|
|
|
statusProgress = new JProgressBar(0, 100);
|
|
|
|
progressPanel.add(statusProgress, gbc);
|
2014-03-02 10:12:20 +01:00
|
|
|
|
|
|
|
JPanel optionsPanel = new JPanel(new GridBagLayout());
|
|
|
|
optionsPanel.setBorder(emptyBorder);
|
|
|
|
optionLog = new JButton("Log");
|
|
|
|
optionHistory = new JButton("History");
|
|
|
|
optionConfiguration = new JButton("Configuration");
|
2014-03-08 21:22:49 +01:00
|
|
|
gbc.gridx = 0; optionsPanel.add(optionLog, gbc);
|
|
|
|
gbc.gridx = 1; optionsPanel.add(optionHistory, gbc);
|
|
|
|
gbc.gridx = 2; optionsPanel.add(optionConfiguration, gbc);
|
2014-03-02 10:12:20 +01:00
|
|
|
|
|
|
|
logPanel = new JPanel(new GridBagLayout());
|
2014-03-02 08:28:37 +01:00
|
|
|
logPanel.setBorder(emptyBorder);
|
2014-03-02 10:12:20 +01:00
|
|
|
logText = new JTextPaneNoWrap();
|
|
|
|
logTextScroll = new JScrollPane(logText);
|
|
|
|
logPanel.setVisible(false);
|
2014-03-11 09:29:26 +01:00
|
|
|
logPanel.setPreferredSize(new Dimension(300, 250));
|
2014-03-02 10:12:20 +01:00
|
|
|
logPanel.add(logTextScroll, gbc);
|
2014-03-08 20:27:30 +01:00
|
|
|
|
2014-03-02 10:12:20 +01:00
|
|
|
historyPanel = new JPanel(new GridBagLayout());
|
|
|
|
historyPanel.setBorder(emptyBorder);
|
|
|
|
historyPanel.setVisible(false);
|
2014-03-11 09:29:26 +01:00
|
|
|
historyPanel.setPreferredSize(new Dimension(300, 250));
|
2014-03-08 21:22:49 +01:00
|
|
|
historyListModel = new DefaultListModel();
|
|
|
|
historyList = new JList(historyListModel);
|
2014-03-09 08:59:36 +01:00
|
|
|
historyList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
2014-03-12 07:54:36 +01:00
|
|
|
historyListScroll = new JScrollPane(historyList,
|
|
|
|
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
|
|
|
|
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
2014-03-08 21:22:49 +01:00
|
|
|
historyButtonRemove = new JButton("Remove");
|
|
|
|
historyButtonClear = new JButton("Clear");
|
|
|
|
historyButtonRerip = new JButton("Re-rip All");
|
|
|
|
gbc.gridx = 0;
|
2014-03-11 09:29:26 +01:00
|
|
|
JPanel historyListPanel = new JPanel(new GridBagLayout());
|
|
|
|
historyListPanel.add(historyListScroll, gbc);
|
2014-04-04 10:08:04 +02:00
|
|
|
gbc.ipady = 150;
|
2014-03-11 09:29:26 +01:00
|
|
|
historyPanel.add(historyListPanel, gbc);
|
2014-04-04 10:08:04 +02:00
|
|
|
gbc.ipady = 0;
|
2014-03-09 08:59:36 +01:00
|
|
|
historyButtonPanel = new JPanel(new GridBagLayout());
|
2014-03-11 09:29:26 +01:00
|
|
|
historyButtonPanel.setPreferredSize(new Dimension(300, 10));
|
2014-03-08 21:22:49 +01:00
|
|
|
historyButtonPanel.setBorder(emptyBorder);
|
|
|
|
gbc.gridx = 0; historyButtonPanel.add(historyButtonRemove, gbc);
|
|
|
|
gbc.gridx = 1; historyButtonPanel.add(historyButtonClear, gbc);
|
|
|
|
gbc.gridx = 2; historyButtonPanel.add(historyButtonRerip, gbc);
|
|
|
|
gbc.gridy = 1; gbc.gridx = 0;
|
|
|
|
historyPanel.add(historyButtonPanel, gbc);
|
2014-04-05 10:39:10 +02:00
|
|
|
|
2014-03-02 10:12:20 +01:00
|
|
|
configurationPanel = new JPanel(new GridBagLayout());
|
|
|
|
configurationPanel.setBorder(emptyBorder);
|
|
|
|
configurationPanel.setVisible(false);
|
2014-03-11 09:29:26 +01:00
|
|
|
configurationPanel.setPreferredSize(new Dimension(300, 250));
|
2014-03-02 10:12:20 +01:00
|
|
|
// TODO Configuration components
|
2014-04-05 10:39:10 +02:00
|
|
|
configUpdateButton = new JButton("Check for updates");
|
2014-04-06 01:57:54 +02:00
|
|
|
configUpdateLabel = new JLabel("Current version: " + UpdateUtils.getThisJarVersion(), JLabel.RIGHT);
|
|
|
|
JLabel configTimeoutLabel = new JLabel("Timeout (in milliseconds):", JLabel.RIGHT);
|
|
|
|
JLabel configThreadsLabel = new JLabel("Maximum download threads:", JLabel.RIGHT);
|
|
|
|
configTimeoutText = new JTextField(Integer.toString(Utils.getConfigInteger("download.timeout", 60000)));
|
|
|
|
configThreadsText = new JTextField(Integer.toString(Utils.getConfigInteger("threads.size", 3)));
|
|
|
|
configOverwriteCheckbox = new JCheckBox("Overwrite existing files?", Utils.getConfigBoolean("file.overwrite", false));
|
|
|
|
configOverwriteCheckbox.setHorizontalAlignment(JCheckBox.RIGHT);
|
|
|
|
configOverwriteCheckbox.setHorizontalTextPosition(JCheckBox.LEFT);
|
|
|
|
gbc.gridy = 0; gbc.gridx = 0; configurationPanel.add(configUpdateLabel, gbc);
|
|
|
|
gbc.gridx = 1; configurationPanel.add(configUpdateButton, gbc);
|
|
|
|
gbc.gridy = 1; gbc.gridx = 0; configurationPanel.add(configTimeoutLabel, gbc);
|
|
|
|
gbc.gridx = 1; configurationPanel.add(configTimeoutText, gbc);
|
|
|
|
gbc.gridy = 2; gbc.gridx = 0; configurationPanel.add(configThreadsLabel, gbc);
|
|
|
|
gbc.gridx = 1; configurationPanel.add(configThreadsText, gbc);
|
|
|
|
gbc.gridy = 3; gbc.gridx = 0; configurationPanel.add(configOverwriteCheckbox, gbc);
|
|
|
|
|
2014-03-08 21:22:49 +01:00
|
|
|
gbc.gridy = 0; pane.add(ripPanel, gbc);
|
|
|
|
gbc.gridy = 1; pane.add(statusPanel, gbc);
|
|
|
|
gbc.gridy = 2; pane.add(progressPanel, gbc);
|
|
|
|
gbc.gridy = 3; pane.add(optionsPanel, gbc);
|
|
|
|
gbc.gridy = 4; pane.add(logPanel, gbc);
|
|
|
|
gbc.gridy = 5; pane.add(historyPanel, gbc);
|
|
|
|
gbc.gridy = 5; pane.add(configurationPanel, gbc);
|
2014-03-02 08:28:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void setupHandlers() {
|
|
|
|
ripButton.addActionListener(new RipButtonHandler());
|
2014-04-04 10:08:04 +02:00
|
|
|
ripTextfield.addActionListener(new RipButtonHandler());
|
2014-03-02 10:12:20 +01:00
|
|
|
optionLog.addActionListener(new ActionListener() {
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent event) {
|
|
|
|
logPanel.setVisible(!logPanel.isVisible());
|
|
|
|
historyPanel.setVisible(false);
|
|
|
|
configurationPanel.setVisible(false);
|
|
|
|
mainFrame.pack();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
optionHistory.addActionListener(new ActionListener() {
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent event) {
|
|
|
|
logPanel.setVisible(false);
|
|
|
|
historyPanel.setVisible(!historyPanel.isVisible());
|
|
|
|
configurationPanel.setVisible(false);
|
|
|
|
mainFrame.pack();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
optionConfiguration.addActionListener(new ActionListener() {
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent event) {
|
|
|
|
logPanel.setVisible(false);
|
|
|
|
historyPanel.setVisible(false);
|
|
|
|
configurationPanel.setVisible(!configurationPanel.isVisible());
|
|
|
|
mainFrame.pack();
|
|
|
|
}
|
|
|
|
});
|
2014-03-09 08:59:36 +01:00
|
|
|
historyButtonRemove.addActionListener(new ActionListener() {
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent event) {
|
|
|
|
int[] indices = historyList.getSelectedIndices();
|
|
|
|
for (int i = indices.length - 1; i >= 0; i--) {
|
|
|
|
historyListModel.remove(indices[i]);
|
|
|
|
}
|
|
|
|
saveHistory();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
historyButtonClear.addActionListener(new ActionListener() {
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent event) {
|
|
|
|
historyListModel.clear();
|
|
|
|
saveHistory();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Re-rip all history
|
|
|
|
historyButtonRerip.addActionListener(new ActionListener() {
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent event) {
|
|
|
|
Runnable ripAllThread = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
historyButtonPanel.setEnabled(false);
|
|
|
|
historyList.setEnabled(false);
|
|
|
|
for (int i = 0; i < historyListModel.size(); i++) {
|
|
|
|
historyList.clearSelection();
|
|
|
|
historyList.setSelectedIndex(i);
|
|
|
|
Thread t = ripAlbum( (String) historyListModel.get(i) );
|
|
|
|
try {
|
|
|
|
synchronized (t) {
|
|
|
|
t.wait();
|
|
|
|
}
|
|
|
|
t.join();
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
logger.error("[!] Exception while waiting for ripper to finish:", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
historyList.setEnabled(true);
|
|
|
|
historyButtonPanel.setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
new Thread(ripAllThread).start();
|
|
|
|
}
|
|
|
|
});
|
2014-04-05 10:39:10 +02:00
|
|
|
configUpdateButton.addActionListener(new ActionListener() {
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent arg0) {
|
2014-04-06 01:57:54 +02:00
|
|
|
Thread t = new Thread() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
UpdateUtils.updateProgram(configUpdateLabel);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
t.start();
|
2014-04-05 10:39:10 +02:00
|
|
|
}
|
|
|
|
});
|
2014-03-02 10:12:20 +01:00
|
|
|
}
|
|
|
|
|
2014-03-08 21:22:49 +01:00
|
|
|
private void appendLog(final String text, final Color color) {
|
2014-03-13 20:18:35 +01:00
|
|
|
SimpleAttributeSet sas = new SimpleAttributeSet();
|
|
|
|
StyleConstants.setForeground(sas, color);
|
|
|
|
StyledDocument sd = logText.getStyledDocument();
|
|
|
|
try {
|
|
|
|
sd.insertString(sd.getLength(), text + "\n", sas);
|
|
|
|
} catch (BadLocationException e) { }
|
|
|
|
|
|
|
|
logText.setCaretPosition(sd.getLength());
|
2014-03-08 21:22:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void loadHistory() {
|
|
|
|
File f; FileReader fr = null; BufferedReader br;
|
|
|
|
try {
|
|
|
|
f = new File(HISTORY_FILE);
|
|
|
|
fr = new FileReader(f);
|
|
|
|
br = new BufferedReader(fr);
|
|
|
|
String line;
|
|
|
|
while ( (line = br.readLine()) != null ) {
|
2014-03-09 08:59:36 +01:00
|
|
|
if (!line.trim().equals("")) {
|
|
|
|
historyListModel.addElement(line.trim());
|
|
|
|
}
|
2014-03-08 21:22:49 +01:00
|
|
|
}
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
// Do nothing
|
|
|
|
} catch (IOException e) {
|
|
|
|
logger.error("[!] Error while loading history file " + HISTORY_FILE, e);
|
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
if (fr != null) {
|
|
|
|
fr.close();
|
|
|
|
}
|
|
|
|
} catch (IOException e) { }
|
|
|
|
}
|
|
|
|
}
|
2014-03-02 10:12:20 +01:00
|
|
|
|
2014-03-08 21:22:49 +01:00
|
|
|
private void saveHistory() {
|
|
|
|
FileWriter fw = null;
|
2014-03-02 10:12:20 +01:00
|
|
|
try {
|
2014-03-08 21:22:49 +01:00
|
|
|
fw = new FileWriter(HISTORY_FILE, false);
|
|
|
|
for (int i = 0; i < historyListModel.size(); i++) {
|
|
|
|
fw.write( (String) historyListModel.get(i) );
|
|
|
|
fw.write("\n");
|
|
|
|
fw.flush();
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
logger.error("[!] Error while saving history file " + HISTORY_FILE, e);
|
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
if (fw != null) {
|
|
|
|
fw.close();
|
|
|
|
}
|
|
|
|
} catch (IOException e) { }
|
2014-03-02 10:12:20 +01:00
|
|
|
}
|
2014-03-01 11:13:32 +01:00
|
|
|
}
|
|
|
|
|
2014-03-09 08:59:36 +01:00
|
|
|
private Thread ripAlbum(String urlString) {
|
2014-04-04 09:38:40 +02:00
|
|
|
if (urlString.toLowerCase().startsWith("gonewild:")) {
|
|
|
|
urlString = "http://gonewild.com/user/" + urlString.substring(urlString.indexOf(':') + 1);
|
|
|
|
}
|
|
|
|
if (!urlString.startsWith("http")) {
|
|
|
|
urlString = "http://" + urlString;
|
|
|
|
}
|
2014-03-09 08:59:36 +01:00
|
|
|
URL url = null;
|
|
|
|
try {
|
|
|
|
url = new URL(urlString);
|
|
|
|
} catch (MalformedURLException e) {
|
|
|
|
logger.error("[!] Could not generate URL for '" + urlString + "'", e);
|
2014-04-04 10:08:04 +02:00
|
|
|
error("Given URL is not valid, expecting http://website.com/page/...");
|
2014-03-09 08:59:36 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
ripButton.setEnabled(false);
|
|
|
|
ripTextfield.setEnabled(false);
|
|
|
|
statusProgress.setValue(100);
|
|
|
|
openButton.setVisible(false);
|
|
|
|
statusLabel.setVisible(true);
|
|
|
|
mainFrame.pack();
|
|
|
|
try {
|
|
|
|
AbstractRipper ripper = AbstractRipper.getRipper(url);
|
|
|
|
ripTextfield.setText(ripper.getURL().toExternalForm());
|
2014-04-04 10:08:04 +02:00
|
|
|
status("Starting rip...");
|
2014-03-13 20:18:35 +01:00
|
|
|
ripper.setObserver((RipStatusHandler) this);
|
2014-03-09 08:59:36 +01:00
|
|
|
Thread t = new Thread(ripper);
|
|
|
|
t.start();
|
|
|
|
return t;
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("[!] Error while ripping: " + e.getMessage(), e);
|
2014-04-04 10:08:04 +02:00
|
|
|
error("Unable to rip this URL: " + e.getMessage());
|
2014-03-24 16:02:32 +01:00
|
|
|
ripButton.setEnabled(true);
|
|
|
|
ripTextfield.setEnabled(true);
|
|
|
|
statusProgress.setValue(0);
|
|
|
|
mainFrame.pack();
|
2014-03-09 08:59:36 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-01 11:13:32 +01:00
|
|
|
class RipButtonHandler implements ActionListener {
|
|
|
|
public void actionPerformed(ActionEvent event) {
|
2014-03-09 08:59:36 +01:00
|
|
|
ripAlbum(ripTextfield.getText());
|
2014-03-01 11:13:32 +01:00
|
|
|
}
|
|
|
|
}
|
2014-03-13 20:18:35 +01:00
|
|
|
|
|
|
|
private class StatusEvent implements Runnable {
|
|
|
|
private final AbstractRipper ripper;
|
|
|
|
private final RipStatusMessage msg;
|
2014-03-01 11:13:32 +01:00
|
|
|
|
2014-03-13 20:18:35 +01:00
|
|
|
public StatusEvent(AbstractRipper ripper, RipStatusMessage msg) {
|
|
|
|
this.ripper = ripper;
|
|
|
|
this.msg = msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
handleEvent(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleEvent(StatusEvent evt) {
|
|
|
|
RipStatusMessage msg = evt.msg;
|
|
|
|
|
|
|
|
int completedPercent = evt.ripper.getCompletionPercentage();
|
|
|
|
statusProgress.setValue(completedPercent);
|
|
|
|
status( evt.ripper.getStatusText() );
|
|
|
|
|
|
|
|
switch(msg.getStatus()) {
|
|
|
|
case LOADING_RESOURCE:
|
|
|
|
case DOWNLOAD_STARTED:
|
|
|
|
appendLog( "Downloading: " + (String) msg.getObject(), Color.BLACK);
|
|
|
|
break;
|
|
|
|
case DOWNLOAD_COMPLETE:
|
|
|
|
appendLog( "Completed: " + (String) msg.getObject(), Color.GREEN);
|
|
|
|
break;
|
|
|
|
case DOWNLOAD_ERRORED:
|
|
|
|
appendLog( "Error: " + (String) msg.getObject(), Color.RED);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DOWNLOAD_WARN:
|
|
|
|
appendLog( "Warn: " + (String) msg.getObject(), Color.ORANGE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIP_COMPLETE:
|
|
|
|
if (!historyListModel.contains(ripTextfield.getText())) {
|
|
|
|
historyListModel.addElement(ripTextfield.getText());
|
2014-03-01 11:13:32 +01:00
|
|
|
}
|
2014-03-13 20:18:35 +01:00
|
|
|
saveHistory();
|
|
|
|
ripButton.setEnabled(true);
|
|
|
|
ripTextfield.setEnabled(true);
|
|
|
|
statusProgress.setValue(100);
|
|
|
|
statusLabel.setVisible(false);
|
|
|
|
openButton.setVisible(true);
|
|
|
|
File f = (File) msg.getObject();
|
|
|
|
String prettyFile = Utils.removeCWD(f);
|
|
|
|
openButton.setText("Open " + prettyFile);
|
|
|
|
appendLog( "Rip complete, saved to " + prettyFile, Color.GREEN);
|
|
|
|
openButton.setActionCommand(f.toString());
|
|
|
|
openButton.addActionListener(new ActionListener() {
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent event) {
|
|
|
|
try {
|
|
|
|
Desktop.getDesktop().open(new File(event.getActionCommand()));
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
mainFrame.pack();
|
2014-03-01 11:13:32 +01:00
|
|
|
}
|
|
|
|
}
|
2014-03-13 20:18:35 +01:00
|
|
|
|
|
|
|
public void update(AbstractRipper ripper, RipStatusMessage message) {
|
|
|
|
StatusEvent event = new StatusEvent(ripper, message);
|
|
|
|
SwingUtilities.invokeLater(event);
|
|
|
|
}
|
2014-03-02 10:12:20 +01:00
|
|
|
|
2014-03-02 10:30:52 +01:00
|
|
|
/** Simple TextPane that allows horizontal scrolling. */
|
2014-03-02 10:12:20 +01:00
|
|
|
class JTextPaneNoWrap extends JTextPane {
|
2014-03-02 10:30:52 +01:00
|
|
|
private static final long serialVersionUID = 1L;
|
2014-03-13 20:18:35 +01:00
|
|
|
|
|
|
|
@Override
|
2014-03-02 10:12:20 +01:00
|
|
|
public boolean getScrollableTracksViewportWidth() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-03-01 11:13:32 +01:00
|
|
|
}
|