From 9b0c42ca6f5cc41d0e1f99c732f99842b04a06ad Mon Sep 17 00:00:00 2001 From: mathiasdm <mathiasdm@mail.i2p> Date: Mon, 3 Jan 2011 18:40:18 +0000 Subject: [PATCH] - Added support for on-the-fly routerconsole.lang changes to desktopgui and routerconsole (routerconsole now commits changes to the I2PAppContext). - Added desktopgui support for detecting if it's running in the same JVM as I2P (without commandline arguments). --- apps/desktopgui/README | 2 +- apps/desktopgui/TODO | 7 +++++-- .../desktopgui/src/net/i2p/desktopgui/Main.java | 17 +++++++++++++++++ .../src/net/i2p/desktopgui/TrayManager.java | 14 +++++++++----- .../i2p/desktopgui/router/RouterManager.java | 7 +++++++ .../src/net/i2p/router/web/ContentHelper.java | 16 +++++++++++++++- 6 files changed, 54 insertions(+), 9 deletions(-) diff --git a/apps/desktopgui/README b/apps/desktopgui/README index 2a4f3a40cb..569ca580a9 100644 --- a/apps/desktopgui/README +++ b/apps/desktopgui/README @@ -6,7 +6,7 @@ Current setup: * Place desktopgui.jar in the $I2P/lib/ directory. * Add to .i2p/clients.config: #Desktopgui - clientApp.6.args=--startWithI2P --I2PLocation=/SOME_LOCATION + clientApp.6.args= clientApp.6.delay=5 clientApp.6.main=net.i2p.desktopgui.Main clientApp.6.name=desktopgui diff --git a/apps/desktopgui/TODO b/apps/desktopgui/TODO index 2a98b7f4fd..dd16102231 100644 --- a/apps/desktopgui/TODO +++ b/apps/desktopgui/TODO @@ -4,10 +4,13 @@ HIGH PRIORITY: - Internationalisation: * Add strings - DONE * Add Windows support - NEED TO CHECK - * Might need some kind of trigger to reload the menu (for live language switching) + * Might need some kind of trigger to reload the menu (for live language switching) - DONE * Language choice is not actually set as a parameter in I2P config? As a result, desktopgui always starts with the default, unless you manually set the language. -- Modify installer to set I2P directory parameter; or use $I2P? + DONE - uses routerconsole.lang -- this parameter is now updated in routerconsole as well +- Check if we're inside I2P without using a command-line parameter - DONE +- Modify installer to set I2P directory parameter; or use $I2P? - Is already there +- Include in installer - TODO - Fix tabs versus spaces ;-) UNKNOWN: - API to allow applications to add themselves to the menu? diff --git a/apps/desktopgui/src/net/i2p/desktopgui/Main.java b/apps/desktopgui/src/net/i2p/desktopgui/Main.java index 540807adac..c24cdd4184 100644 --- a/apps/desktopgui/src/net/i2p/desktopgui/Main.java +++ b/apps/desktopgui/src/net/i2p/desktopgui/Main.java @@ -7,8 +7,12 @@ package net.i2p.desktopgui; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; + +import net.i2p.I2PAppContext; import net.i2p.desktopgui.util.*; import net.i2p.util.Log; +import net.i2p.util.Translate; +import net.i2p.util.I2PProperties.I2PPropertyCallback; /** * The main class of the application. @@ -25,6 +29,19 @@ public class Main { private void startUp() { trayManager = TrayManager.getInstance(); trayManager.startManager(); + I2PAppContext.getCurrentContext().addPropertyCallback(new I2PPropertyCallback() { + + @Override + public String getPropertyKey() { + return Translate.PROP_LANG; + } + + @Override + public void propertyChanged(String arg0, String arg1) { + trayManager.languageChanged(); + } + + }); } /** diff --git a/apps/desktopgui/src/net/i2p/desktopgui/TrayManager.java b/apps/desktopgui/src/net/i2p/desktopgui/TrayManager.java index 1bc8b1b055..01a5d611f2 100644 --- a/apps/desktopgui/src/net/i2p/desktopgui/TrayManager.java +++ b/apps/desktopgui/src/net/i2p/desktopgui/TrayManager.java @@ -42,9 +42,9 @@ public abstract class TrayManager { */ protected TrayManager() {} - public static TrayManager getInstance() { + protected static TrayManager getInstance() { if(instance == null) { - boolean inI2P = ConfigurationManager.getInstance().getBooleanConfiguration("startWithI2P", false); + boolean inI2P = RouterManager.inI2P(); if(inI2P) { instance = new InternalTrayManager(); } @@ -58,7 +58,7 @@ public abstract class TrayManager { /** * Add the tray icon to the system tray and start everything up. */ - public void startManager() { + protected void startManager() { if(SystemTray.isSupported()) { tray = SystemTray.getSystemTray(); trayIcon = new TrayIcon(getTrayImage(), "I2P", getMainMenu()); @@ -70,17 +70,21 @@ public abstract class TrayManager { } } + protected void languageChanged() { + trayIcon.setPopupMenu(getMainMenu()); + } + /** * Build a popup menu, adding callbacks to the different items. * @return popup menu */ - public abstract PopupMenu getMainMenu(); + protected abstract PopupMenu getMainMenu(); /** * Get tray icon image from the desktopgui resources in the jar file. * @return image used for the tray icon */ - public Image getTrayImage() { + private Image getTrayImage() { URL url = getClass().getResource("/desktopgui/resources/images/logo.jpg"); Image image = Toolkit.getDefaultToolkit().getImage(url); return image; diff --git a/apps/desktopgui/src/net/i2p/desktopgui/router/RouterManager.java b/apps/desktopgui/src/net/i2p/desktopgui/router/RouterManager.java index 031c38d7c8..fd36219fa4 100644 --- a/apps/desktopgui/src/net/i2p/desktopgui/router/RouterManager.java +++ b/apps/desktopgui/src/net/i2p/desktopgui/router/RouterManager.java @@ -55,6 +55,13 @@ public class RouterManager { public static void shutDown() { getRouter().shutdownGracefully(); } + + /** + * Check if we are running inside I2P. + */ + public static boolean inI2P() { + return (RouterContext.listContexts().size() > 0); + } private static String _(String s) { return DesktopguiTranslator._(s); diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ContentHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/ContentHelper.java index f9fe7377c8..adc245a6bb 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ContentHelper.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ContentHelper.java @@ -18,7 +18,21 @@ public class ContentHelper extends HelperBase { public void setStartAtBeginning(String moo) { _startAtBeginning = Boolean.valueOf(""+moo).booleanValue(); } - public void setLang(String l) { _lang = l; } + public void setLang(String l) { + if(_lang == null || !_lang.equals(l)) { + //Set language for router console + _lang = l; + + if(_context == null) { + setContextId(null); + } + + //Set language persistently throughout I2P + _context.router().setConfigSetting(Messages.PROP_LANG, _lang); + _context.router().saveConfig(); + _context.setProperty(Messages.PROP_LANG, _lang); + } + } public void setMaxLines(String lines) { if (lines != null) { -- GitLab