From fd445459f4116dbe01e6e460b7889f67be6283e5 Mon Sep 17 00:00:00 2001 From: Florian Trabauer Date: Fri, 29 May 2015 21:57:43 +0200 Subject: [PATCH] Implemented a simple update Notification. --- TwitchVodLoaderInfo.txt | 1 + .../channelsync/ChannelSyncController.java | 36 +++++++- .../vod/channelsync/ChannelSyncMenuBar.java | 88 ++++++++++++++++++- 3 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 TwitchVodLoaderInfo.txt diff --git a/TwitchVodLoaderInfo.txt b/TwitchVodLoaderInfo.txt new file mode 100644 index 0000000..4ba23d3 --- /dev/null +++ b/TwitchVodLoaderInfo.txt @@ -0,0 +1 @@ +TwitchVodLoader 0.1 \ No newline at end of file diff --git a/src/com/trabauer/twitchtools/controller/channelsync/ChannelSyncController.java b/src/com/trabauer/twitchtools/controller/channelsync/ChannelSyncController.java index 5a2146e..d63ff01 100755 --- a/src/com/trabauer/twitchtools/controller/channelsync/ChannelSyncController.java +++ b/src/com/trabauer/twitchtools/controller/channelsync/ChannelSyncController.java @@ -36,6 +36,10 @@ public class ChannelSyncController implements ChannelSyncControllerInterface { public static final String FFMPEG_EXE_URL_STR = "http://trabauer.com/downloads/project_ressources/TwitchTools/ffmpeg.exe"; + public static final String VERSION_INFO_URL_STR = "http://trabauer.com/downloads/TwitchVodLoaderInfo.txt"; + public static final String PROGRAM_DOWNLOAD_URL_STR = "http://trabauer.com/downloads/TwitchVodLoader.jar"; + public static final String PROJECT_PAGE_URL_STR = "http://lordh3lmchen.github.io/TwitchDownloader/"; + public static final String PROGRAM_VERSION = "TwitchVodLoader 0.1"; private final JFrame mainFrame; private final SyncChannelMainPanel mainPanel; @@ -56,6 +60,8 @@ public class ChannelSyncController implements ChannelSyncControllerInterface { private ArrayList videoParts; + + public ChannelSyncController() { this.twitchVideoInfoList = new TwitchVideoInfoList(); @@ -82,7 +88,7 @@ public ChannelSyncController() { if(OsValidator.isWindows()) { ffmpegExecutable = new File(new File(getJarURI().getPath()).getParent().concat("/ffmpeg.exe")); if (!ffmpegExecutable.exists()) { - int choice = JOptionPane.showConfirmDialog(mainFrame, "FFMPEG not found! Do you wnat to download it? FFMPEG is required to convert videos", "FFMPEG not found! Download it?", JOptionPane.YES_NO_OPTION); + int choice = JOptionPane.showConfirmDialog(mainFrame, "FFMPEG not found! Do you want to download it? FFMPEG is required to convert videos", "FFMPEG not found! Download it?", JOptionPane.YES_NO_OPTION); if (choice == 0) { //YES downloadFFMPEG(); } //else if(choice == 0) { //NO @@ -100,6 +106,34 @@ public ChannelSyncController() { } catch (URISyntaxException e) { JOptionPane.showMessageDialog(mainPanel, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } + + checkForUpdates(); + + + } + + private void checkForUpdates() { + URL VersionInfoUrl = null; + try { + VersionInfoUrl= new URL(VERSION_INFO_URL_STR); + InputStream is = VersionInfoUrl.openStream(); + Scanner sc = new Scanner(is); + String line = null; + if(sc.hasNextLine()) line = sc.nextLine(); + if(! line.equals(PROGRAM_VERSION)) { + System.out.println("Program isn't up to date. "); + int choice = JOptionPane.showConfirmDialog(mainFrame, "Update Available! Download latest Version?", "Update Available!", JOptionPane.YES_NO_OPTION); + if (choice == 0) { //YES + openUrlInBrowser(new URL(PROJECT_PAGE_URL_STR)); + } //else if(choice == 0) { //NO + // Nothing right now + //} + } + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } } @Override diff --git a/src/com/trabauer/twitchtools/gui/vod/channelsync/ChannelSyncMenuBar.java b/src/com/trabauer/twitchtools/gui/vod/channelsync/ChannelSyncMenuBar.java index 1c2936b..dd8882f 100755 --- a/src/com/trabauer/twitchtools/gui/vod/channelsync/ChannelSyncMenuBar.java +++ b/src/com/trabauer/twitchtools/gui/vod/channelsync/ChannelSyncMenuBar.java @@ -9,7 +9,13 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.font.TextAttribute; import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Map; import java.util.Vector; import java.util.prefs.Preferences; @@ -182,25 +188,99 @@ private void moveQuality(int oldIndex, int newIndex) { - private class AboutThisProgramDialog extends JDialog { + private class AboutThisProgramDialog extends JDialog implements ActionListener { + + private final JLabel visitProjectSiteLbl; + private JButton closeBtn, licenseBtn; + public AboutThisProgramDialog(Frame owner) { super(owner, "About Twitch Downloader"); + GridBagLayout layoutManager = new GridBagLayout(); + GridBagConstraints gc = new GridBagConstraints(); + this.setLayout(layoutManager); ImageIcon logoIcon = new ImageIcon(TwitchToolsImages.getTwitchDownloadToolImage()); - JLabel programNameVersionLabel = new JLabel("TwitchDownloader 0.1", logoIcon, JLabel.CENTER); + JLabel programNameVersionLabel = new JLabel(controller.PROGRAM_VERSION, logoIcon, JLabel.CENTER); Font origFont = programNameVersionLabel.getFont().deriveFont(Font.BOLD); programNameVersionLabel.setFont(origFont.deriveFont(30.0F)); programNameVersionLabel.setVerticalTextPosition(JLabel.BOTTOM); programNameVersionLabel.setHorizontalTextPosition(JLabel.CENTER); - add(programNameVersionLabel); - setVisible(true); + gc.gridx = 0; + gc.gridy = 0; + gc.insets = new Insets(5,5,5,5); + gc.gridwidth = 2; + add(programNameVersionLabel, gc); + + JLabel copyrightLbl = new JLabel("Copyright 2014-2015 Florian Trabauer"); + gc.gridy++; + add(copyrightLbl, gc); + visitProjectSiteLbl = new JLabel("Visit the TwitchDownloader website"); + Font visitProjectSiteFont = visitProjectSiteLbl.getFont(); + Map visitProjectSiteFontAttributes = visitProjectSiteFont.getAttributes(); + visitProjectSiteFontAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); + visitProjectSiteLbl.setForeground(Color.BLUE); + visitProjectSiteLbl.setFont(visitProjectSiteFont.deriveFont(visitProjectSiteFontAttributes)); + visitProjectSiteLbl.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + super.mouseClicked(e); + try { + controller.openUrlInBrowser(new URL("http://lordh3lmchen.github.io/TwitchDownloader/")); + } catch (MalformedURLException e1) { + e1.printStackTrace(); + } + } + }); + gc.gridy++; + add(visitProjectSiteLbl, gc); + licenseBtn = new JButton("License"); + licenseBtn.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + super.mouseClicked(e); + try { + controller.openUrlInBrowser(new URL("http://trabauer.com/downloads/TwitchDownloader_LICENSE.txt")); + } catch (MalformedURLException e1) { + e1.printStackTrace(); + } + } + }); + gc.gridy++; + gc.gridwidth = 1; + add(licenseBtn, gc); + closeBtn = new JButton("Close"); + closeBtn.addActionListener(this); + gc.gridx++; + gc.anchor = GridBagConstraints.LINE_END; + add(closeBtn, gc); + pack(); } + + @Override + public void actionPerformed(ActionEvent e) { + if(e.getSource()==closeBtn) { + this.setVisible(false); + } else if(e.getSource()==licenseBtn) { + this.setVisible(false); //TODO show license instead + } + } } +// private class licenseDialog extends JDialog { //STUB not used default browser is used instead. +// public licenseDialog(Frame owner) { +// super(owner, "License"); +// GridBagLayout layout = new GridBagLayout(); +// setLayout(layout); +// GridBagConstraints gc = new GridBagConstraints(); +// +// +// } +// } + private File showDestinationDirChooser(String path) { JFileChooser fileChooser = null; File file = null;