Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues/820 history folder #1466

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ protected boolean addURLToDownload(URL url, String prefix, String subdirectory,
if (url.toExternalForm().equals("http:") || url.toExternalForm().equals("https:")) {
LOGGER.info(url.toExternalForm() + " is a invalid url amd will be changed");
return false;

}

// Make sure the url doesn't contain any spaces as that can cause a 400 error when requesting the file
if (url.toExternalForm().contains(" ")) {
// If for some reason the url with all spaces encoded as %20 is malformed print an error
Expand Down
36 changes: 16 additions & 20 deletions src/main/java/com/rarchives/ripme/ui/HistoryEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,23 @@

public class HistoryEntry {

public String url = "",
title = "",
dir = "";
public int count = 0;
public Date startDate = new Date(),
modifiedDate = new Date();
public boolean selected = false;

public HistoryEntry() {
}
public String url = "", title = "", dir = "";
public int count = 0;
public Date startDate = new Date(), modifiedDate = new Date();
public boolean selected = false;

public HistoryEntry fromJSON(JSONObject json) {
this.url = json.getString("url");
this.startDate = new Date(json.getLong("startDate"));
this.url = json.getString("url");
this.startDate = new Date(json.getLong("startDate"));
this.modifiedDate = new Date(json.getLong("modifiedDate"));
if (json.has("title")) {
this.title = json.getString("title");
this.title = json.getString("title");
}
if (json.has("count")) {
this.count = json.getInt("count");
this.count = json.getInt("count");
}
if (json.has("dir")) {
this.dir = json.getString("dir");
this.dir = json.getString("dir");
}
if (json.has("selected")) {
this.selected = json.getBoolean("selected");
Expand All @@ -38,12 +32,14 @@ public HistoryEntry fromJSON(JSONObject json) {

public JSONObject toJSON() {
JSONObject json = new JSONObject();
json.put("url", this.url);
json.put("startDate", this.startDate.getTime());
json.put("url", this.url);
json.put("startDate", this.startDate.getTime());
json.put("modifiedDate", this.modifiedDate.getTime());
json.put("title", this.title);
json.put("count", this.count);
json.put("selected", this.selected);
json.put("title", this.title);
json.put("count", this.count);
json.put("selected", this.selected);
if (!dir.isEmpty())
json.put("dir", this.dir);
return json;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.rarchives.ripme.ui;

import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;

import javax.swing.AbstractAction;
import javax.swing.Action;
Expand All @@ -15,9 +18,10 @@
class HistoryMenuMouseListener extends MouseAdapter {
private JPopupMenu popup = new JPopupMenu();
private JTable tableComponent;
private Point lastPoint;

@SuppressWarnings("serial")
public HistoryMenuMouseListener() {
public HistoryMenuMouseListener(History history) {
Action checkAllAction = new AbstractAction(Utils.getLocalizedString("history.check.all")) {
@Override
public void actionPerformed(ActionEvent ae) {
Expand Down Expand Up @@ -59,6 +63,21 @@ public void actionPerformed(ActionEvent ae) {
}
};
popup.add(uncheckSelected);
popup.addSeparator();
popup.add(new AbstractAction(Utils.getLocalizedString("history.open.folder")) {

@Override
public void actionPerformed(ActionEvent e) {
try {
String url = tableComponent.getValueAt(tableComponent.rowAtPoint(lastPoint), 0).toString();
File dir = new File(history.getEntryByURL(url).dir);
if (dir.exists())
java.awt.Desktop.getDesktop().open(dir);
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
}

@Override
Expand All @@ -71,6 +90,8 @@ public void mouseClicked(MouseEvent e) {
tableComponent = (JTable) e.getSource();
tableComponent.requestFocus();

lastPoint = e.getPoint();

int nx = e.getX();

if (nx > 500) {
Expand Down
44 changes: 33 additions & 11 deletions src/main/java/com/rarchives/ripme/ui/MainWindow.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,44 @@
package com.rarchives.ripme.ui;

import java.awt.*;
import java.awt.AWTException;
import java.awt.CheckboxMenuItem;
import java.awt.Color;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.Point;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.TrayIcon.MessageType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;

import javax.imageio.ImageIO;
Expand All @@ -38,6 +61,7 @@
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.EmptyBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
Expand All @@ -49,16 +73,14 @@
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;

import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import com.rarchives.ripme.ripper.AbstractRipper;
import com.rarchives.ripme.utils.RipUtils;
import com.rarchives.ripme.utils.Utils;

import javax.swing.UnsupportedLookAndFeelException;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

/**
* Everything UI-related starts and ends here.
Expand Down Expand Up @@ -430,7 +452,7 @@ public void setValueAt(Object value, int row, int col) {
}
};
historyTable = new JTable(historyTableModel);
historyTable.addMouseListener(new HistoryMenuMouseListener());
historyTable.addMouseListener(new HistoryMenuMouseListener(HISTORY));
historyTable.setAutoCreateRowSorter(true);
for (int i = 0; i < historyTable.getColumnModel().getColumnCount(); i++) {
int width = 130; // Default
Expand Down Expand Up @@ -1418,10 +1440,10 @@ private synchronized void handleEvent(StatusEvent evt) {
RipStatusComplete rsc = (RipStatusComplete) msg.getObject();
String url = ripper.getURL().toExternalForm();
if (HISTORY.containsURL(url)) {
// TODO update "modifiedDate" of entry in HISTORY
HistoryEntry entry = HISTORY.getEntryByURL(url);
entry.count = rsc.count;
entry.modifiedDate = new Date();
entry.dir = rsc.getDir();
} else {
HistoryEntry entry = new HistoryEntry();
entry.url = url;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/LabelsBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ history.uncheck.selected = Uncheck Selected
history.load.failed.warning = RipMe failed to load the history file at historyFile.getAbsolutePath() \n\nError: %s\n\nClosing RipMe will automatically overwrite the contents of this file,\nso you may want to back the file up before closing RipMe!
history.load.none = There are no history entries to re-rip. Rip some albums first
history.load.none.checked = No history entries have been 'Checked' Check an entry by clicking the checkbox to the right of the URL or Right-click a URL to check/uncheck all items
history.open.folder = Open Folder

# TrayIcon
tray.show = Show
Expand Down