import net.pterodactylus.irc.util.RandomNickname;
import net.pterodactylus.xdcc.core.event.BotAdded;
import net.pterodactylus.xdcc.core.event.CoreStarted;
+import net.pterodactylus.xdcc.core.event.DownloadFinished;
+import net.pterodactylus.xdcc.core.event.DownloadStarted;
import net.pterodactylus.xdcc.data.Bot;
import net.pterodactylus.xdcc.data.Channel;
import net.pterodactylus.xdcc.data.Download;
download.filename(outputFile.getPath()).outputStream(fileOutputStream).dccReceiver(dccReceiver);
dccReceivers.add(dccReceiver);
dccReceiver.start();
+ eventBus.post(new DownloadStarted(download));
} catch (FileNotFoundException fnfe1) {
logger.log(Level.WARNING, "Could not open file for download!", fnfe1);
}
download.outputStream().close();
File file = new File(download.filename());
file.renameTo(new File(finalDirectory, download.filename()));
+ eventBus.post(new DownloadFinished(download));
} catch (IOException ioe1) {
/* TODO - handle all the errors. */
logger.log(Level.WARNING, String.format("Could not move file %s to directory %s.", download.filename(), finalDirectory), ioe1);
--- /dev/null
+/*
+ * XdccDownloader - DownloadEvent.java - Copyright © 2013 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.xdcc.core.event;
+
+import net.pterodactylus.xdcc.data.Download;
+
+/**
+ * Abstract base class for all {@link Download}-related events.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class AbstractDownloadEvent {
+
+ /** The download this event is about. */
+ protected final Download download;
+
+ /**
+ * Creates a new download event.
+ *
+ * @param download
+ * The download the event is about
+ */
+ public AbstractDownloadEvent(Download download) {
+ this.download = download;
+ }
+
+ /**
+ * Returns the download this event is about.
+ *
+ * @return The download
+ */
+ public Download download() {
+ return download;
+ }
+}
--- /dev/null
+/*
+ * XdccDownloader - DownloadStarted.java - Copyright © 2013 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.xdcc.core.event;
+
+import net.pterodactylus.xdcc.data.Download;
+
+/**
+ * Notifies a listener that a {@link Download} has finished successfully.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class DownloadFinished extends AbstractDownloadEvent {
+
+ /**
+ * Creates a new download finished event.
+ *
+ * @param download
+ * The download that finished
+ */
+ public DownloadFinished(Download download) {
+ super(download);
+ }
+
+}
--- /dev/null
+/*
+ * XdccDownloader - DownloadStarted.java - Copyright © 2013 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.xdcc.core.event;
+
+import net.pterodactylus.xdcc.data.Download;
+
+/**
+ * Notifies a listener that a {@link Download} was started.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public abstract class DownloadStarted extends AbstractDownloadEvent {
+
+ /**
+ * Creates a new download started event.
+ *
+ * @param download
+ * The download that started
+ */
+ protected DownloadStarted(Download download) {
+ super(download);
+ }
+
+}