From fbfcfae53f0ebc7aa96086352e2a9889a0b86fdc Mon Sep 17 00:00:00 2001 From: angryziber Date: Tue, 8 Apr 2008 20:41:10 +0000 Subject: [PATCH] gnome-terminal, XFCE Terminal and konsole are now supported in addition to xterm when opening IPs git-svn-id: https://ipscan.svn.sourceforge.net/svnroot/ipscan/trunk@374 375186e5-ef17-0410-b0b6-91563547dcda --- TODO | 2 - .../ipscan/gui/actions/TerminalLauncher.java | 46 ++++++++++++++++++- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/TODO b/TODO index a1473d1c..67380b6d 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,5 @@ Before 3.0: -* save default selection of pinger (Combined for non-root users) * command-line scanning start * fetcher-specific options * multiple port support web-detect @@ -13,7 +12,6 @@ Before 3.0: * public XSL for XMLExporter * Exporter appending functionality exposed to the user * make Display: status bar right-clickable -* support gnome-terminal in openers * rename favorite option in the Manager dialog * show percent in window title * show number of IPs scanned so far in status bar diff --git a/src/net/azib/ipscan/gui/actions/TerminalLauncher.java b/src/net/azib/ipscan/gui/actions/TerminalLauncher.java index d2920d30..9aefa205 100755 --- a/src/net/azib/ipscan/gui/actions/TerminalLauncher.java +++ b/src/net/azib/ipscan/gui/actions/TerminalLauncher.java @@ -23,6 +23,14 @@ public class TerminalLauncher { static final Logger LOG = LoggerFactory.getLogger(); + private static final int UNKNOWN = -1; + private static final int XTERM = 0; + private static final int GNOME = 1; + private static final int XFCE = 2; + private static final int KDE = 3; + /** caches last working terminal type */ + private static int workingTerminal = UNKNOWN; + /** * Launches the execString in the terminal. * Supports Linux/Unix, MacOS, and Windows @@ -48,11 +56,45 @@ public class TerminalLauncher { Runtime.getRuntime().exec(new String[] {"osascript", "-e", "tell application \"Terminal\" to do script \"" + execString + "\""}, null, workingDir); } else { // assume Linux or other Unix - // TODO: maybe gnome-terminal or konsole should be tried as well... - Runtime.getRuntime().exec(new String[] {"xterm", "-e", "bash", "-c", execString + ";bash"}, null, workingDir); + + // detect environment + if (workingTerminal == UNKNOWN) { + if (Runtime.getRuntime().exec(new String[] {"pidof", "gnome-panel"}).waitFor() == 0) { + workingTerminal = GNOME; + } + else + if (Runtime.getRuntime().exec(new String[] {"pidof", "xfce4-session"}).waitFor() == 0) { + workingTerminal = XFCE; + } + else + if (Runtime.getRuntime().exec(new String[] {"pidof", "dcopserver"}).waitFor() == 0) { + workingTerminal = KDE; + } + else { + workingTerminal = XTERM; + } + } + + // run detected terminal program + switch (workingTerminal) { + case GNOME: + Runtime.getRuntime().exec(new String[] {"gnome-terminal", "-x", "bash", "-c", execString + ";bash"}, null, workingDir); + break; + case XFCE: + Runtime.getRuntime().exec(new String[] {"Terminal", "--execute", "sh", "-c", execString + ";sh"}, null, workingDir); + break; + case KDE: + Runtime.getRuntime().exec(new String[] {"konsole", "-e", "bash", "-c", execString + ";bash"}, null, workingDir); + break; + default: // XTERM + Runtime.getRuntime().exec(new String[] {"xterm", "-e", "sh", "-c", execString + ";sh"}, null, workingDir); + } } } catch (Exception e) { + // just try XTERM next time... + workingTerminal = XTERM; + // log and display the error LOG.log(Level.WARNING, "openTerminal.failed", e); throw new UserErrorException("openTerminal.failed", execString); }