From 3208b7289ec5437d7713d8fe4987b239ec1898ae Mon Sep 17 00:00:00 2001 From: mathiasdm Date: Thu, 21 May 2009 22:32:34 +0000 Subject: [PATCH] * desktopgui: - Updating works in general config - Switched to Swingworker threads for improved responsiveness - version increase to 0.1.3 --- LICENSE.txt | 4 + apps/desktopgui/build.xml | 2 + apps/desktopgui/nbproject/project.properties | 4 +- .../i2p/desktopgui/desktopgui/GUIVersion.java | 2 +- .../desktopgui/gui/GeneralConfiguration.form | 17 ++- .../desktopgui/gui/GeneralConfiguration.java | 142 +++++++++++++++++- .../src/net/i2p/desktopgui/gui/Tray.java | 2 +- .../router/configuration/UpdateHandler.java | 19 +++ .../router/configuration/UpdateHelper.java | 66 ++++++++ build.xml | 2 +- history.txt | 5 + 11 files changed, 250 insertions(+), 15 deletions(-) create mode 100644 apps/desktopgui/src/net/i2p/desktopgui/router/configuration/UpdateHandler.java create mode 100644 apps/desktopgui/src/net/i2p/desktopgui/router/configuration/UpdateHelper.java diff --git a/LICENSE.txt b/LICENSE.txt index 02b2862d8..f68af6e0c 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -179,6 +179,10 @@ distributions. See the source package for the additional license information. Atalk: Public domain + Desktopgui + Copyright (c) Mathias De Maré + See apps/desktopgui/LICENSE + SAM C Library: Copyright (c) 2004, Matthew P. Cashdollar See apps/sam/c/doc/license.txt diff --git a/apps/desktopgui/build.xml b/apps/desktopgui/build.xml index 77bd6d778..795edf046 100644 --- a/apps/desktopgui/build.xml +++ b/apps/desktopgui/build.xml @@ -76,10 +76,12 @@ + + diff --git a/apps/desktopgui/nbproject/project.properties b/apps/desktopgui/nbproject/project.properties index e9f5d1a2a..fb880932f 100644 --- a/apps/desktopgui/nbproject/project.properties +++ b/apps/desktopgui/nbproject/project.properties @@ -23,6 +23,7 @@ excludes= file.reference.appframework.jar=lib/appframework.jar file.reference.i2p.jar=../../core/java/build/i2p.jar file.reference.router.jar=../../router/java/build/router.jar +file.reference.routerconsole.jar=../routerconsole/java/build/routerconsole.jar file.reference.swing-worker.jar=lib/swing-worker.jar includes=** jar.compress=false @@ -30,7 +31,8 @@ javac.classpath=\ ${file.reference.router.jar}:\ ${file.reference.appframework.jar}:\ ${file.reference.swing-worker.jar}:\ - ${file.reference.i2p.jar} + ${file.reference.i2p.jar}:\ + ${file.reference.routerconsole.jar} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false diff --git a/apps/desktopgui/src/net/i2p/desktopgui/desktopgui/GUIVersion.java b/apps/desktopgui/src/net/i2p/desktopgui/desktopgui/GUIVersion.java index f4e948e52..10a6e5293 100644 --- a/apps/desktopgui/src/net/i2p/desktopgui/desktopgui/GUIVersion.java +++ b/apps/desktopgui/src/net/i2p/desktopgui/desktopgui/GUIVersion.java @@ -10,5 +10,5 @@ package net.i2p.desktopgui.desktopgui; * @author mathias */ public class GUIVersion { - public static final String VERSION = "0.0.1.2"; + public static final String VERSION = "0.0.1.3"; } diff --git a/apps/desktopgui/src/net/i2p/desktopgui/gui/GeneralConfiguration.form b/apps/desktopgui/src/net/i2p/desktopgui/gui/GeneralConfiguration.form index 8e0acbb14..4c7cb5afc 100644 --- a/apps/desktopgui/src/net/i2p/desktopgui/gui/GeneralConfiguration.form +++ b/apps/desktopgui/src/net/i2p/desktopgui/gui/GeneralConfiguration.form @@ -2,7 +2,7 @@
- + @@ -371,7 +371,7 @@ - + @@ -380,7 +380,7 @@ - + @@ -389,7 +389,7 @@ - + @@ -400,18 +400,27 @@ + + + + + + + + + diff --git a/apps/desktopgui/src/net/i2p/desktopgui/gui/GeneralConfiguration.java b/apps/desktopgui/src/net/i2p/desktopgui/gui/GeneralConfiguration.java index b0dbccabc..474e39473 100644 --- a/apps/desktopgui/src/net/i2p/desktopgui/gui/GeneralConfiguration.java +++ b/apps/desktopgui/src/net/i2p/desktopgui/gui/GeneralConfiguration.java @@ -6,10 +6,23 @@ package net.i2p.desktopgui.gui; +import java.awt.Desktop; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.logging.Level; +import java.util.logging.Logger; import net.i2p.desktopgui.router.configuration.SpeedHelper; import javax.swing.JComboBox; +import javax.swing.ButtonModel; import javax.swing.JTextField; +import net.i2p.desktopgui.router.RouterHelper; import net.i2p.desktopgui.router.configuration.SpeedHandler; +import net.i2p.desktopgui.router.configuration.UpdateHelper; +import net.i2p.router.web.NewsFetcher; +import net.i2p.desktopgui.router.configuration.UpdateHandler; +import java.util.Date; +import javax.swing.SwingWorker; /** * @@ -22,11 +35,14 @@ public class GeneralConfiguration extends javax.swing.JFrame { initComponents(); extraInitComponents(); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); + this.setLocationRelativeTo(null); + this.requestFocus(); this.setVisible(true); } private void extraInitComponents() { initSpeedTab(); + initUpdateTab(); } private void initSpeedTab() { @@ -34,8 +50,8 @@ public class GeneralConfiguration extends javax.swing.JFrame { String inbound = SpeedHelper.getInboundBandwidth(); String outbound = SpeedHelper.getOutboundBandwidth(); - initSpeeds(inbound, outbound); - initUsage("" + Integer.parseInt(inbound)/8, "" + Integer.parseInt(outbound)/8); + initSpeeds("" + Integer.parseInt(inbound)*8, "" + Integer.parseInt(outbound)*8); + initUsage("" + Integer.parseInt(inbound), "" + Integer.parseInt(outbound)); } catch(Exception e) { e.printStackTrace(); @@ -45,6 +61,32 @@ public class GeneralConfiguration extends javax.swing.JFrame { } } + private void initUpdateTab() { + //Set update policy + String updatePolicy = UpdateHelper.getUpdatePolicy(); + if(updatePolicy.equals(UpdateHelper.NOTIFY_UPDATE_POLICY)) { + updateButtonGroup.setSelected(updateInform.getModel(), true); + } + else if(updatePolicy.equals(UpdateHelper.DOWNLOAD_UPDATE_POLICY)) { + updateButtonGroup.setSelected(updateDownload.getModel(), true); + } + else if(updatePolicy.equals(UpdateHelper.INSTALL_UPDATE_POLICY)) { + updateButtonGroup.setSelected(updateDownloadRestart.getModel(), true); + } + else { + System.out.println("desktopgui: no updates for you!"); + } + + //Check if an update is available + //TODO: move this method out of the routerconsole so desktopgui doesn't depend on routerconsole!!! + if(NewsFetcher.getInstance(RouterHelper.getContext()).updateAvailable()) { + updateNow.setVisible(true); + } + else { + updateNow.setVisible(false); + } + } + /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is @@ -54,7 +96,7 @@ public class GeneralConfiguration extends javax.swing.JFrame { // //GEN-BEGIN:initComponents private void initComponents() { - buttonGroup1 = new javax.swing.ButtonGroup(); + updateButtonGroup = new javax.swing.ButtonGroup(); applyPanel = new javax.swing.JPanel(); cancel = new javax.swing.JToggleButton(); ok = new javax.swing.JToggleButton(); @@ -240,26 +282,41 @@ public class GeneralConfiguration extends javax.swing.JFrame { updateMethod.setText(resourceMap.getString("updateMethod.text")); // NOI18N updateMethod.setName("updateMethod"); // NOI18N - buttonGroup1.add(updateInform); + updateButtonGroup.add(updateInform); updateInform.setText(resourceMap.getString("updateInform.text")); // NOI18N updateInform.setName("updateInform"); // NOI18N - buttonGroup1.add(updateDownload); + updateButtonGroup.add(updateDownload); updateDownload.setText(resourceMap.getString("updateDownload.text")); // NOI18N updateDownload.setName("updateDownload"); // NOI18N - buttonGroup1.add(updateDownloadRestart); + updateButtonGroup.add(updateDownloadRestart); updateDownloadRestart.setText(resourceMap.getString("updateDownloadRestart.text")); // NOI18N updateDownloadRestart.setName("updateDownloadRestart"); // NOI18N checkUpdates.setText(resourceMap.getString("checkUpdates.text")); // NOI18N checkUpdates.setName("checkUpdates"); // NOI18N + checkUpdates.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + checkUpdatesActionPerformed(evt); + } + }); updateNow.setText(resourceMap.getString("updateNow.text")); // NOI18N updateNow.setName("updateNow"); // NOI18N + updateNow.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + updateNowActionPerformed(evt); + } + }); advancedUpdateConfig.setText(resourceMap.getString("advancedUpdateConfig.text")); // NOI18N advancedUpdateConfig.setName("advancedUpdateConfig"); // NOI18N + advancedUpdateConfig.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + advancedUpdateConfigActionPerformed(evt); + } + }); javax.swing.GroupLayout updatesPanelLayout = new javax.swing.GroupLayout(updatesPanel); updatesPanel.setLayout(updatesPanelLayout); @@ -468,9 +525,65 @@ private void cancelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:even private void okMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_okMouseClicked saveSpeeds(); + saveUpdatePolicy(); this.dispose(); }//GEN-LAST:event_okMouseClicked +private void checkUpdatesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkUpdatesActionPerformed + long current = new Date().getTime(); + if(current < newsLastFetched + 5*60*1000) { + return; + } + checkUpdates.setText("Checking for updates"); + checkUpdates.setEnabled(false); + newsLastFetched = current; + SwingWorker sw = new SwingWorker() { + + @Override + protected Object doInBackground() throws Exception { + NewsFetcher.getInstance(RouterHelper.getContext()).fetchNews(); + return null; + } + + @Override + protected void done() { + checkUpdates.setText("Check for updates now"); + checkUpdates.setEnabled(true); + if(NewsFetcher.getInstance(RouterHelper.getContext()).updateAvailable()) { + updateNow.setVisible(true); + } + } + + }; +}//GEN-LAST:event_checkUpdatesActionPerformed + +private void updateNowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateNowActionPerformed + SwingWorker sw = new SwingWorker() { + + @Override + protected Object doInBackground() throws Exception { + new net.i2p.router.web.UpdateHandler().update(); + return null; + } + + }; + updateNow.setEnabled(false); + updateNow.setText("Updating..."); + checkUpdates.setEnabled(false); + +}//GEN-LAST:event_updateNowActionPerformed + +private void advancedUpdateConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_advancedUpdateConfigActionPerformed + try { + Desktop.getDesktop().browse(new URI("http://127.0.0.1:7657/configupdate.jsp")); + } catch (URISyntaxException ex) { + Logger.getLogger(GeneralConfiguration.class.getName()).log(Level.SEVERE, null, ex); + } + catch (IOException ex) { + Logger.getLogger(GeneralConfiguration.class.getName()).log(Level.SEVERE, null, ex); + } +}//GEN-LAST:event_advancedUpdateConfigActionPerformed + protected void initUsage(String upload, String download) { uploadgb.setText("" + SpeedHelper.calculateMonthlyUsage(Integer.parseInt(upload))); downloadgb.setText("" + SpeedHelper.calculateMonthlyUsage(Integer.parseInt(download))); @@ -513,11 +626,23 @@ private void okMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ok } } + protected void saveUpdatePolicy() { + ButtonModel policyButton = updateButtonGroup.getSelection(); + if(policyButton.equals(updateInform.getModel())) { + UpdateHandler.setUpdatePolicy(UpdateHelper.NOTIFY_UPDATE_POLICY); + } + else if(policyButton.equals(updateDownload.getModel())) { + UpdateHandler.setUpdatePolicy(UpdateHelper.DOWNLOAD_UPDATE_POLICY); + } + else if(policyButton.equals(updateDownloadRestart.getModel())) { + UpdateHandler.setUpdatePolicy(UpdateHelper.INSTALL_UPDATE_POLICY); + } + } + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel advancedPanel; private javax.swing.JToggleButton advancedUpdateConfig; private javax.swing.JPanel applyPanel; - private javax.swing.ButtonGroup buttonGroup1; private javax.swing.JToggleButton cancel; private javax.swing.JToggleButton checkUpdates; private javax.swing.JScrollPane clientFrame; @@ -537,6 +662,7 @@ private void okMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ok private javax.swing.JPanel speedPanel; private javax.swing.JPanel tunnelPanel; private javax.swing.JLabel tunnelsExplanation; + private javax.swing.ButtonGroup updateButtonGroup; private javax.swing.JRadioButton updateDownload; private javax.swing.JRadioButton updateDownloadRestart; private javax.swing.JRadioButton updateInform; @@ -553,4 +679,6 @@ private void okMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ok public static final int KILOBIT = 0; public static final int KILOBYTE = 1; + + private long newsLastFetched = 0; } diff --git a/apps/desktopgui/src/net/i2p/desktopgui/gui/Tray.java b/apps/desktopgui/src/net/i2p/desktopgui/gui/Tray.java index 42f720c27..02fb5b2df 100644 --- a/apps/desktopgui/src/net/i2p/desktopgui/gui/Tray.java +++ b/apps/desktopgui/src/net/i2p/desktopgui/gui/Tray.java @@ -151,7 +151,7 @@ public class Tray { public void actionPerformed(ActionEvent arg0) { RouterHandler.setStatus(RouterHandler.SHUTDOWN_GRACEFULLY); long shutdownTime = RouterHelper.getGracefulShutdownTimeRemaining(); - System.out.println(shutdownTime); + System.out.println("Shutdowntime remaining: " + shutdownTime); if(shutdownTime>0) { trayIcon.displayMessage("Shutting down...", "Shutdown time remaining: " + shutdownTime/1000 + " seconds." + System.getProperty("line.separator") + "Shutdown will not happen immediately, because we are still participating in the network.", TrayIcon.MessageType.INFO); diff --git a/apps/desktopgui/src/net/i2p/desktopgui/router/configuration/UpdateHandler.java b/apps/desktopgui/src/net/i2p/desktopgui/router/configuration/UpdateHandler.java new file mode 100644 index 000000000..e913f5e51 --- /dev/null +++ b/apps/desktopgui/src/net/i2p/desktopgui/router/configuration/UpdateHandler.java @@ -0,0 +1,19 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package net.i2p.desktopgui.router.configuration; + +import net.i2p.desktopgui.router.RouterHelper; + +/** + * + * @author mathias + */ +public class UpdateHandler { + public static void setUpdatePolicy(String policy) { + RouterHelper.getContext().router().setConfigSetting(UpdateHelper.PROP_UPDATE_POLICY, policy); + RouterHelper.getContext().router().saveConfig(); + } +} diff --git a/apps/desktopgui/src/net/i2p/desktopgui/router/configuration/UpdateHelper.java b/apps/desktopgui/src/net/i2p/desktopgui/router/configuration/UpdateHelper.java new file mode 100644 index 000000000..86db6f708 --- /dev/null +++ b/apps/desktopgui/src/net/i2p/desktopgui/router/configuration/UpdateHelper.java @@ -0,0 +1,66 @@ +package net.i2p.desktopgui.router.configuration; + +import net.i2p.desktopgui.router.RouterHelper; + +/** + * + * @author mathias + */ +public class UpdateHelper { + + public static final String PROP_NEWS_URL = "router.newsURL"; + public static final String DEFAULT_NEWS_URL = "http://complication.i2p/news.xml"; + + public static final String PROP_REFRESH_FREQUENCY = "router.newsRefreshFrequency"; + public static final String DEFAULT_REFRESH_FREQUENCY = 24*60*60*1000 + ""; + + public static final String PROP_UPDATE_POLICY = "router.updatePolicy"; + public static final String NOTIFY_UPDATE_POLICY = "notify"; + public static final String DOWNLOAD_UPDATE_POLICY = "download"; + public static final String INSTALL_UPDATE_POLICY = "install"; + public static final String DEFAULT_UPDATE_POLICY = DOWNLOAD_UPDATE_POLICY; + + public static final String PROP_SHOULD_PROXY = "router.updateThroughProxy"; + public static final String DEFAULT_SHOULD_PROXY = Boolean.TRUE.toString(); + public static final String PROP_PROXY_HOST = "router.updateProxyHost"; + public static final String DEFAULT_PROXY_HOST = "127.0.0.1"; + public static final String PROP_PROXY_PORT = "router.updateProxyPort"; + public static final String DEFAULT_PROXY_PORT = "4444"; + + public static final String PROP_UPDATE_URL = "router.updateURL"; + public static final String DEFAULT_UPDATE_URL = + "http://echelon.i2p/i2p/i2pupdate.sud\r\n" + + "http://stats.i2p/i2p/i2pupdate.sud\r\n" + + "http://complication.i2p/i2p/i2pupdate.sud\r\n" + + "http://www.i2p2.i2p/_static/i2pupdate.sud\r\n" + + "http://update.postman.i2p/i2pupdate.sud" ; + + public static final String PROP_TRUSTED_KEYS = "router.trustedUpdateKeys"; + + public static String getNewsURL() { + String url = RouterHelper.getContext().getProperty(PROP_NEWS_URL); + if(url == null) { + return DEFAULT_NEWS_URL; + } + else { + return url; + } + } + + public static String getUpdatePolicy() { + String policy = null; + try { + policy = RouterHelper.getContext().getProperty(PROP_UPDATE_POLICY); + } + catch(Exception e) { + e.printStackTrace(); + } + System.out.println("Policy: " + policy); + if(policy == null) { + return DEFAULT_UPDATE_POLICY; + } + else { + return policy; + } + } +} diff --git a/build.xml b/build.xml index 886ca438c..d9abb0947 100644 --- a/build.xml +++ b/build.xml @@ -524,7 +524,7 @@ - + diff --git a/history.txt b/history.txt index 99799e856..7319ee267 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,8 @@ +2009-05-22 Mathiasdm + * desktopgui: + - Updating works in general config + - Switched to Swingworker threads for improved responsiveness + 2009-05-21 zzz * Router Watchdog: - Log memory stats