diff --git a/src/main/java/com/rarchives/ripme/ui/MainWindow.java b/src/main/java/com/rarchives/ripme/ui/MainWindow.java index 682b8251..ff719990 100644 --- a/src/main/java/com/rarchives/ripme/ui/MainWindow.java +++ b/src/main/java/com/rarchives/ripme/ui/MainWindow.java @@ -104,6 +104,7 @@ public class MainWindow implements Runnable, RipStatusHandler { private static JButton configSaveDirButton; private static JTextField configRetriesText; private static JCheckBox configAutoupdateCheckbox; + private static JCheckBox configPlaySound; private static TrayIcon trayIcon; private static MenuItem trayMenuMain; @@ -166,6 +167,7 @@ public class MainWindow implements Runnable, RipStatusHandler { Utils.setConfigInteger("download.timeout", Integer.parseInt(configTimeoutText.getText())); Utils.setConfigBoolean("clipboard.autorip", ClipboardUtils.getClipboardAutoRip()); Utils.setConfigBoolean("auto.update", configAutoupdateCheckbox.isSelected()); + Utils.setConfigBoolean("play.sound", configPlaySound.isSelected()); saveHistory(); Utils.saveConfig(); } @@ -305,6 +307,9 @@ public class MainWindow implements Runnable, RipStatusHandler { configAutoupdateCheckbox = new JCheckBox("Auto-update?", Utils.getConfigBoolean("auto.update", true)); configAutoupdateCheckbox.setHorizontalAlignment(JCheckBox.RIGHT); configAutoupdateCheckbox.setHorizontalTextPosition(JCheckBox.LEFT); + configPlaySound = new JCheckBox("Sound when rip completes", Utils.getConfigBoolean("play.sound", false)); + configPlaySound.setHorizontalAlignment(JCheckBox.RIGHT); + configPlaySound.setHorizontalTextPosition(JCheckBox.LEFT); configSaveDirLabel = new JLabel(); try { String workingDir = (Utils.shortenPath(Utils.getWorkingDirectory())); @@ -323,7 +328,8 @@ public class MainWindow implements Runnable, RipStatusHandler { gbc.gridy = 4; gbc.gridx = 0; configurationPanel.add(configRetriesLabel, gbc); gbc.gridx = 1; configurationPanel.add(configRetriesText, gbc); gbc.gridy = 5; gbc.gridx = 0; configurationPanel.add(configOverwriteCheckbox, gbc); - gbc.gridy = 6; gbc.gridx = 0; configurationPanel.add(configSaveDirLabel, gbc); + gbc.gridy = 6; gbc.gridx = 0; configurationPanel.add(configPlaySound, gbc); + gbc.gridy = 7; gbc.gridx = 0; configurationPanel.add(configSaveDirLabel, gbc); gbc.gridx = 1; configurationPanel.add(configSaveDirButton, gbc); gbc.gridy = 0; pane.add(ripPanel, gbc); @@ -755,6 +761,9 @@ public class MainWindow implements Runnable, RipStatusHandler { if (!historyListModel.contains(ripTextfield.getText())) { historyListModel.addElement(ripTextfield.getText()); } + if (configPlaySound.isSelected()) { + Utils.playSound("camera.wav"); + } saveHistory(); ripButton.setVisible(true); stopButton.setVisible(false); diff --git a/src/main/java/com/rarchives/ripme/utils/Utils.java b/src/main/java/com/rarchives/ripme/utils/Utils.java index a4ed8ad7..1914ff23 100644 --- a/src/main/java/com/rarchives/ripme/utils/Utils.java +++ b/src/main/java/com/rarchives/ripme/utils/Utils.java @@ -12,6 +12,12 @@ import java.util.List; import java.util.jar.JarEntry; import java.util.jar.JarFile; +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.Clip; +import javax.sound.sampled.Line; +import javax.sound.sampled.LineEvent; +import javax.sound.sampled.LineListener; + import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.log4j.Logger; @@ -283,4 +289,23 @@ public class Utils { } return list; } + + public static void playSound(String filename) { + URL resource = ClassLoader.getSystemClassLoader().getResource(filename); + try { + final Clip clip = (Clip) AudioSystem.getLine(new Line.Info(Clip.class)); + clip.addLineListener(new LineListener() { + @Override + public void update(LineEvent event) { + if (event.getType() == LineEvent.Type.STOP) { + clip.close(); + } + } + }); + clip.open(AudioSystem.getAudioInputStream(resource)); + clip.start(); + } catch (Exception e) { + logger.error("Failed to play sound " + filename, e); + } + } } \ No newline at end of file diff --git a/src/main/resources/camera.wav b/src/main/resources/camera.wav new file mode 100644 index 00000000..617e0f03 Binary files /dev/null and b/src/main/resources/camera.wav differ