From 6a45cd59e9b9887e0c71f332c7d8cd6ca37d682c Mon Sep 17 00:00:00 2001 From: 4pr0n Date: Sun, 27 Apr 2014 10:09:52 -0700 Subject: [PATCH] Better about box --- .../ripme/ripper/AbstractRipper.java | 2 +- .../ripme/ripper/rippers/InstagramRipper.java | 3 + .../com/rarchives/ripme/ui/MainWindow.java | 63 ++++++++++++++++--- .../java/com/rarchives/ripme/utils/Utils.java | 18 ++++++ 4 files changed, 75 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java b/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java index 1d617ef2..49ebad57 100644 --- a/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java @@ -255,7 +255,7 @@ public abstract class AbstractRipper * List of constructors for all eligible Rippers. * @throws Exception */ - private static List> getRipperConstructors(String pkg) throws Exception { + public static List> getRipperConstructors(String pkg) throws Exception { List> constructors = new ArrayList>(); for (Class clazz : Utils.getClassesForPackage(pkg)) { if (AbstractRipper.class.isAssignableFrom(clazz)) { diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/InstagramRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/InstagramRipper.java index e82bc58c..c5a82076 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/InstagramRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/InstagramRipper.java @@ -14,6 +14,7 @@ import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import com.rarchives.ripme.ripper.AlbumRipper; +import com.rarchives.ripme.ui.RipStatusMessage.STATUS; public class InstagramRipper extends AlbumRipper { @@ -70,6 +71,7 @@ public class InstagramRipper extends AlbumRipper { private String getUserID(URL url) throws IOException { logger.info(" Retrieving " + url); + this.sendUpdate(STATUS.LOADING_RESOURCE, url.toExternalForm()); Document doc = Jsoup.connect(this.url.toExternalForm()).get(); for (Element element : doc.select("input[id=user_public]")) { return element.attr("value"); @@ -85,6 +87,7 @@ public class InstagramRipper extends AlbumRipper { String params = ""; while (true) { String url = baseURL + params; + this.sendUpdate(STATUS.LOADING_RESOURCE, url); logger.info(" Retrieving " + url); String jsonString = Jsoup.connect(url) .ignoreContentType(true) diff --git a/src/main/java/com/rarchives/ripme/ui/MainWindow.java b/src/main/java/com/rarchives/ripme/ui/MainWindow.java index 01b363f3..72c4daa5 100644 --- a/src/main/java/com/rarchives/ripme/ui/MainWindow.java +++ b/src/main/java/com/rarchives/ripme/ui/MainWindow.java @@ -23,9 +23,12 @@ import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; +import java.io.IOException; import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import java.util.Arrays; +import java.util.List; import javax.imageio.ImageIO; import javax.swing.DefaultListModel; @@ -493,12 +496,56 @@ public class MainWindow implements Runnable, RipStatusHandler { trayMenuAbout.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { - String aboutBlurb = "
Download albums from various websites. rarchives.com"; - JOptionPane.showMessageDialog(null, - aboutBlurb, + StringBuilder about = new StringBuilder(); + about.append("

") + .append(mainFrame.getTitle()) + .append("

"); + about.append("Download albums from various websites:"); + try { + List rippers = Utils.getListOfAlbumRippers(); + about.append("
    "); + for (String ripper : rippers) { + about.append("
  • "); + ripper = ripper.substring(ripper.lastIndexOf('.') + 1); + if (ripper.contains("Ripper")) { + ripper = ripper.substring(0, ripper.indexOf("Ripper")); + } + about.append(ripper); + about.append("
  • "); + } + about.append("
"); + } catch (Exception e) { } + about.append("
And download videos from video sites:"); + try { + List rippers = Utils.getListOfVideoRippers(); + about.append("
    "); + for (String ripper : rippers) { + about.append("
  • "); + ripper = ripper.substring(ripper.lastIndexOf('.') + 1); + if (ripper.contains("Ripper")) { + ripper = ripper.substring(0, ripper.indexOf("Ripper")); + } + about.append(ripper); + about.append("
  • "); + } + about.append("
"); + } catch (Exception e) { } + + about.append("Do you want to visit the project homepage on Github?"); + about.append(""); + int response = JOptionPane.showConfirmDialog(null, + about.toString(), mainFrame.getTitle(), + JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, new ImageIcon(mainIcon)); + if (response == JOptionPane.YES_OPTION) { + try { + Desktop.getDesktop().browse(URI.create("http://github.com/4pr0n/ripme")); + } catch (IOException e) { + logger.error("Exception while opening project home page", e); + } + } } }); trayMenuExit = new MenuItem("Exit"); @@ -626,12 +673,7 @@ public class MainWindow implements Runnable, RipStatusHandler { ripper.setObserver((RipStatusHandler) this); Thread t = new Thread(ripper); t.start(); - if (!mainFrame.isVisible()) { - mainFrame.toFront(); - mainFrame.setAlwaysOnTop(true); - trayIcon.displayMessage(mainFrame.getTitle(), "Started ripping " + ripper.getURL().toExternalForm(), MessageType.INFO); - mainFrame.setAlwaysOnTop(false); - } else if (!mainFrame.isActive()) { + if (!mainFrame.isVisible() || !mainFrame.isActive()) { mainFrame.toFront(); mainFrame.setAlwaysOnTop(true); trayIcon.displayMessage(mainFrame.getTitle(), "Started ripping " + ripper.getURL().toExternalForm(), MessageType.INFO); @@ -653,7 +695,8 @@ public class MainWindow implements Runnable, RipStatusHandler { class RipButtonHandler implements ActionListener { public void actionPerformed(ActionEvent event) { - ripAlbum(ripTextfield.getText()); + Thread t = ripAlbum(ripTextfield.getText()); + SwingUtilities.invokeLater(t); } } diff --git a/src/main/java/com/rarchives/ripme/utils/Utils.java b/src/main/java/com/rarchives/ripme/utils/Utils.java index 9f4f2b1e..cebaa318 100644 --- a/src/main/java/com/rarchives/ripme/utils/Utils.java +++ b/src/main/java/com/rarchives/ripme/utils/Utils.java @@ -2,6 +2,7 @@ package com.rarchives.ripme.utils; import java.io.File; import java.io.IOException; +import java.lang.reflect.Constructor; import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; @@ -14,6 +15,8 @@ import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.log4j.Logger; +import com.rarchives.ripme.ripper.AbstractRipper; + /** * Common utility functions used in various places throughout the project. */ @@ -264,4 +267,19 @@ public class Utils { } return String.format("%.2f%sb", fbytes, mags[magIndex]); } + + public static List getListOfAlbumRippers() throws Exception { + List list = new ArrayList(); + for (Constructor ripper : AbstractRipper.getRipperConstructors("com.rarchives.ripme.ripper.rippers")) { + list.add(ripper.getName()); + } + return list; + } + public static List getListOfVideoRippers() throws Exception { + List list = new ArrayList(); + for (Constructor ripper : AbstractRipper.getRipperConstructors("com.rarchives.ripme.ripper.rippers.video")) { + list.add(ripper.getName()); + } + return list; + } } \ No newline at end of file