diff --git a/apps/systray/doc/LICENSE.systray4j.txt b/apps/systray/doc/LICENSE.systray4j.txt new file mode 100644 index 000000000..4864121e9 --- /dev/null +++ b/apps/systray/doc/LICENSE.systray4j.txt @@ -0,0 +1,341 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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 2 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, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. + diff --git a/apps/systray/java/src/net/i2p/apps/systray/ShellCommand.java b/apps/systray/java/src/net/i2p/apps/systray/ShellCommand.java new file mode 100644 index 000000000..18df8faba --- /dev/null +++ b/apps/systray/java/src/net/i2p/apps/systray/ShellCommand.java @@ -0,0 +1,398 @@ +/* + * I2P - An anonymous, secure, and fully-distributed communication network. + * + * ShellCommand.java + * 2004 The I2P Project + * This code is public domain. + */ + +package net.i2p.apps.systray; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; + +/** + * Passes a command to the OS shell for execution and manages the output. + *

+ * This class must be kept gcj-compatible. + * + * @author hypercubus + */ +public class ShellCommand { + + private static final boolean CONSUME_OUTPUT = true; + private static final boolean NO_CONSUME_OUTPUT = false; + + private static final boolean WAIT_FOR_EXIT_STATUS = true; + private static final boolean NO_WAIT_FOR_EXIT_STATUS = false; + + private boolean _commandSuccessful; + private CommandThread _commandThread; + private InputStream _errorStream; + private InputStream _inputStream; + private OutputStream _outputStream; + private Process _process; + + /** + * Executes a shell command in its own thread. + * + * @author hypercubus + */ + private class CommandThread extends Thread { + + Object caller; + boolean consumeOutput; + String shellCommand; + + CommandThread(Object caller, String shellCommand, boolean consumeOutput) { + super("CommandThread"); + this.caller = caller; + this.shellCommand = shellCommand; + this.consumeOutput = consumeOutput; + } + + public void run() { + _commandSuccessful = execute(shellCommand, consumeOutput, WAIT_FOR_EXIT_STATUS); + synchronized(caller) { + caller.notify(); // In case the caller is still in the wait() state. + } + return; + } + } + + /** + * Consumes stream data. Instances of this class, when given the + * STDOUT and STDERR input streams of a + * Runtime.exec() process for example, will prevent blocking + * during a Process.waitFor() loop and thereby allow the + * process to exit properly. This class makes no attempt to preserve the + * consumed data. + * + * @author hypercubus + */ + private class StreamConsumer extends Thread { + + private BufferedReader bufferedReader; + private InputStreamReader inputStreamReader; + + public StreamConsumer(InputStream inputStream) { + super("StreamConsumer"); + this.inputStreamReader = new InputStreamReader(inputStream); + this.bufferedReader = new BufferedReader(inputStreamReader); + } + + public void run() { + + String streamData; + + try { + while ((streamData = bufferedReader.readLine()) != null) { + // Just like a Hoover. + } + } catch (IOException e) { + // Don't bother. + } + } + } + + /** + * Reads data from a java.io.InputStream and writes it to + * STDOUT. + * + * @author hypercubus + */ + private class StreamReader extends Thread { + + final int BUFFER_SIZE = 1024; + + private BufferedReader bufferedReader; + private InputStreamReader inputStreamReader; + + public StreamReader(InputStream inputStream) { + super("StreamReader"); + this.inputStreamReader = new InputStreamReader(inputStream); + this.bufferedReader = new BufferedReader(inputStreamReader); + } + + public void run() { + + char[] buffer = new char[BUFFER_SIZE]; + int bytesRead; + + try { + + while (true) + while ((bytesRead = bufferedReader.read(buffer, 0, BUFFER_SIZE)) != -1) + for (int i = 0; i < bytesRead; i++) + System.out.print(buffer[i]); // TODO Pipe this to the calling thread instead of STDOUT + + } catch (IOException e) { + // Don't bother. + } + } + } + + /** + * Reads data from STDIN and writes it to a + * java.io.OutputStream. + * + * @author hypercubus + */ + private class StreamWriter extends Thread { + + private BufferedWriter bufferedWriter; + private BufferedReader in; + private OutputStreamWriter outputStreamWriter; + + public StreamWriter(OutputStream outputStream) { + super("StreamWriter"); + this.outputStreamWriter = new OutputStreamWriter(outputStream); + this.bufferedWriter = new BufferedWriter(outputStreamWriter); + } + + public void run() { + + String input; + + in = new BufferedReader(new InputStreamReader(System.in)); + try { + while (true) { + input = in.readLine() + "\r\n"; + bufferedWriter.write(input, 0, input.length()); + bufferedWriter.flush(); + } + } catch (Exception e) { + try { + bufferedWriter.flush(); + } catch (IOException e1) { + // Eat it. + } + } + } + } + + /** + * Passes a command to the shell for execution and returns immediately + * without waiting for an exit status. All output produced by the + * executed command will go to STDOUT and STDERR + * as appropriate, and can be read via {@link #getOutputStream()} and + * {@link #getErrorStream()}, respectively. Input can be passed to the + * STDIN of the shell process via {@link #getInputStream()}. + * + * @param shellCommand The command for the shell to execute. + */ + public void execute(String shellCommand) { + execute(shellCommand, NO_CONSUME_OUTPUT, NO_WAIT_FOR_EXIT_STATUS); + } + + /** + * Passes a command to the shell for execution. This method blocks until + * all of the command's resulting shell processes have completed. All output + * produced by the executed command will go to STDOUT and + * STDERR as appropriate, and can be read via + * {@link #getOutputStream()} and {@link #getErrorStream()}, respectively. + * Input can be passed to the STDIN of the shell process via + * {@link #getInputStream()}. + * + * @param shellCommand The command for the shell to execute. + * @return true if the spawned shell process + * returns an exit status of 0 (indicating success), + * else false. + */ + public boolean executeAndWait(String shellCommand) { + + if (execute(shellCommand, NO_CONSUME_OUTPUT, WAIT_FOR_EXIT_STATUS)) + return true; + + return false; + } + + /** + * Passes a command to the shell for execution. This method blocks until + * all of the command's resulting shell processes have completed, unless a + * specified number of seconds has elapsed first. All output produced by the + * executed command will go to STDOUT and STDERR + * as appropriate, and can be read via {@link #getOutputStream()} and + * {@link #getErrorStream()}, respectively. Input can be passed to the + * STDIN of the shell process via {@link #getInputStream()}. + * + * @param shellCommand The command for the shell to execute. + * @param seconds The method will return true if this + * number of seconds elapses without the process + * returning an exit status. A value of 0 + * here disables waiting. + * @return true if the spawned shell process + * returns an exit status of 0 (indicating success), + * else false. + */ + public synchronized boolean executeAndWaitTimed(String shellCommand, int seconds) { + + _commandThread = new CommandThread(Thread.currentThread(), shellCommand, NO_CONSUME_OUTPUT); + _commandThread.start(); + try { + + if (seconds > 0) { + wait(seconds * 1000); + return true; + } + + } catch (InterruptedException e) { + // Wake up, time to die. + } + + if (_commandSuccessful) + return true; + + return false; + } + + /** + * Passes a command to the shell for execution and returns immediately + * without waiting for an exit status. Any output produced by the executed + * command will not be displayed. + * + * @param shellCommand The command for the shell to execute. + * @throws IOException + */ + public void executeSilent(String shellCommand) throws IOException { + Runtime.getRuntime().exec(shellCommand, null); + } + + /** + * Passes a command to the shell for execution. This method blocks until + * all of the command's resulting shell processes have completed. Any output + * produced by the executed command will not be displayed. + * + * @param shellCommand The command for the shell to execute. + * @return true if the spawned shell process + * returns an exit status of 0 (indicating success), + * else false. + */ + public boolean executeSilentAndWait(String shellCommand) { + + if (execute(shellCommand, CONSUME_OUTPUT, WAIT_FOR_EXIT_STATUS)) + return true; + + return false; + } + + /** + * Passes a command to the shell for execution. This method blocks until + * all of the command's resulting shell processes have completed unless a + * specified number of seconds has elapsed first. Any output produced by the + * executed command will not be displayed. + * + * @param shellCommand The command for the shell to execute. + * @param seconds The method will return true if this + * number of seconds elapses without the process + * returning an exit status. A value of 0 + * here disables waiting. + * @return true if the spawned shell process + * returns an exit status of 0 (indicating success), + * else false. + */ + public synchronized boolean executeSilentAndWaitTimed(String shellCommand, int seconds) { + + _commandThread = new CommandThread(Thread.currentThread(), shellCommand, CONSUME_OUTPUT); + _commandThread.start(); + try { + + if (seconds > 0) { + wait(seconds * 1000); + return true; + } + + } catch (InterruptedException e) { + // Wake up, time to die. + } + + if (_commandSuccessful) + return true; + + return false; + } + + public InputStream getErrorStream() { + return _errorStream; + } + + public InputStream getInputStream() { + return _inputStream; + } + + public OutputStream getOutputStream() { + return _outputStream; + } + + private synchronized boolean execute(String shellCommand, boolean consumeOutput, boolean waitForExitStatus) { + + StreamConsumer processStderrConsumer; + StreamConsumer processStdoutConsumer; + + StreamReader processStderrReader; + StreamWriter processStdinWriter; + StreamReader processStdoutReader; + + try { + _process = Runtime.getRuntime().exec(shellCommand, null); + if (consumeOutput) { + processStderrConsumer = new StreamConsumer(_process.getErrorStream()); + processStderrConsumer.start(); + processStdoutConsumer = new StreamConsumer(_process.getInputStream()); + processStdoutConsumer.start(); + } else { + /* + * Will the following stream readers allow _process to return + * just as if _process's streams had been consumed as above? If + * so, get rid of the stream consumers and just use the + * following for all cases. + */ + _errorStream = _process.getErrorStream(); + _inputStream = _process.getInputStream(); + _outputStream = _process.getOutputStream(); + processStderrReader = new StreamReader(_errorStream); + processStderrReader.start(); + processStdinWriter = new StreamWriter(_outputStream); + processStdinWriter.start(); + processStdoutReader = new StreamReader(_inputStream); + processStdoutReader.start(); + } + + if (waitForExitStatus) { + try { + _process.waitFor(); + } catch (Exception e) { + if (!consumeOutput) { + _errorStream.close(); + _errorStream = null; + _inputStream.close(); + _inputStream = null; + _outputStream.close(); + _outputStream = null; + } + return false; + } + if (!consumeOutput) { + _errorStream.close(); + _errorStream = null; + _inputStream.close(); + _inputStream = null; + _outputStream.close(); + _outputStream = null; + } + + if (_process.exitValue() > 0) + return false; + } + + } catch (Exception e) { + return false; + } + return true; + } +} diff --git a/apps/systray/java/src/net/i2p/apps/systray/SysTray.java b/apps/systray/java/src/net/i2p/apps/systray/SysTray.java new file mode 100644 index 000000000..f7e5bff04 --- /dev/null +++ b/apps/systray/java/src/net/i2p/apps/systray/SysTray.java @@ -0,0 +1,80 @@ +/* + * I2P - An anonymous, secure, and fully-distributed communication network. + * + * SysTray.java + * 2004 The I2P Project + * This code is public domain. + */ + +package net.i2p.apps.systray; + +import snoozesoft.systray4j.SysTrayMenu; +import snoozesoft.systray4j.SysTrayMenuEvent; +import snoozesoft.systray4j.SysTrayMenuIcon; +import snoozesoft.systray4j.SysTrayMenuItem; +import snoozesoft.systray4j.SysTrayMenuListener; + +/** + * A system tray control for launching the I2P router console. + * + * @author hypercubus + */ +public class SysTray implements SysTrayMenuListener { + + private SysTrayMenuItem itemExit = new SysTrayMenuItem("Exit", "exit"); + private SysTrayMenuItem itemStartRouter = new SysTrayMenuItem("Start router", "start"); + private SysTrayMenuItem itemStopRouter = new SysTrayMenuItem("Stop router", "stop"); + private SysTrayMenuIcon sysTrayMenuIconDisabled = new SysTrayMenuIcon("icons/iggy_grey"); + private SysTrayMenuIcon sysTrayMenuIconEnabled = new SysTrayMenuIcon("icons/iggy"); + private SysTrayMenu sysTrayMenu = new SysTrayMenu(sysTrayMenuIconEnabled, "I2P Console"); + + public SysTray() { + sysTrayMenuIconDisabled.addSysTrayMenuListener(this); + sysTrayMenuIconEnabled.addSysTrayMenuListener(this); + createSysTrayMenu(); + } + + public static void main(String[] args) { + new SysTray(); + while(true) + try { + Thread.sleep(2*1000); + } catch (InterruptedException e) { + // blah + } + } + + public void iconLeftClicked(SysTrayMenuEvent e) {} + + public void iconLeftDoubleClicked(SysTrayMenuEvent e) { + System.out.println("Double click!"); + } + + public void menuItemSelected(SysTrayMenuEvent e) { + if (e.getActionCommand().equals("exit")) { + // exit systray + System.exit(0); + } else if (e.getActionCommand().equals("stop")) { + itemStartRouter.setEnabled(true); + itemStopRouter.setEnabled(false); + // stop router + sysTrayMenu.setIcon(sysTrayMenuIconDisabled); + } else if (e.getActionCommand().equals("start")) { + itemStopRouter.setEnabled(true); + itemStartRouter.setEnabled(false); + // start router + sysTrayMenu.setIcon(sysTrayMenuIconEnabled); + } + } + + private void createSysTrayMenu() { + itemStartRouter.addSysTrayMenuListener(this); + itemStartRouter.setEnabled(false); + itemStopRouter.addSysTrayMenuListener(this); + itemExit.addSysTrayMenuListener(this); + sysTrayMenu.addItem(itemExit); + sysTrayMenu.addSeparator(); + sysTrayMenu.addItem(itemStopRouter); + sysTrayMenu.addItem(itemStartRouter); + } +} \ No newline at end of file diff --git a/apps/systray/java/src/net/i2p/apps/systray/UrlLauncher.java b/apps/systray/java/src/net/i2p/apps/systray/UrlLauncher.java new file mode 100644 index 000000000..4b6136e99 --- /dev/null +++ b/apps/systray/java/src/net/i2p/apps/systray/UrlLauncher.java @@ -0,0 +1,81 @@ +/* + * I2P - An anonymous, secure, and fully-distributed communication network. + * + * UrlLauncher.java + * 2004 The I2P Project + * This code is public domain. + */ + +package net.i2p.apps.systray; + +/** + * A quick and simple multi-platform URL launcher. It attempts to launch the + * default browser for the host platform first, then popular third-party + * browsers if that was not successful. + *

+ * Handles Galeon, Internet Explorer, Konqueror, Links, Lynx, Mozilla, Mozilla + * Firefox, Netscape, Opera, and Safari. + * + * @author hypercubus + */ +public class UrlLauncher { + + /** + * Discovers the operating system the installer is running under and tries + * to launch the given URL using the default browser for that platform; if + * unsuccessful, an attempt is made to launch the URL using the most common + * browsers. + */ + public boolean openUrl(String url) throws Exception { + + String osName = System.getProperty("os.name"); + ShellCommand shellCommand = new ShellCommand(); + + if (osName.toLowerCase().indexOf("mac") > -1) { + if (osName.toLowerCase().startsWith("mac os x")) { + + if (shellCommand.executeSilentAndWaitTimed("safari " + url, 5)) + return true; + + } else { + return false; + } + + if (shellCommand.executeSilentAndWaitTimed("iexplore " + url, 5)) + return true; + + } else if (osName.startsWith("Windows")) { + + if (shellCommand.executeSilentAndWaitTimed("\"C:\\Program Files\\Internet Explorer\\iexplore.exe\" " + url, 5)) + return true; + + } else { + + if (shellCommand.executeSilentAndWaitTimed("konqueror " + url, 5)) + return true; + + if (shellCommand.executeSilentAndWaitTimed("galeon " + url, 5)) + return true; + } + + if (shellCommand.executeSilentAndWaitTimed("firefox " + url, 5)) + return true; + + if (shellCommand.executeSilentAndWaitTimed("opera -newpage " + url, 5)) + return true; + + if (shellCommand.executeSilentAndWaitTimed("mozilla " + url, 5)) + return true; + + if (shellCommand.executeSilentAndWaitTimed("netscape " + url, 5)) + return true; + + if (shellCommand.executeSilentAndWaitTimed("links " + url, 5)) + return true; + + if (shellCommand.executeSilentAndWaitTimed("lynx " + url, 5)) + return true; + + return false; + } +} diff --git a/apps/systray/java/src/net/i2p/apps/systray/i2psystray.bat b/apps/systray/java/src/net/i2p/apps/systray/i2psystray.bat new file mode 100644 index 000000000..9ba3580c8 --- /dev/null +++ b/apps/systray/java/src/net/i2p/apps/systray/i2psystray.bat @@ -0,0 +1 @@ +java -cp systray4j.jar;. -Djava.library.path=. SysTray \ No newline at end of file diff --git a/apps/systray/java/src/net/i2p/apps/systray/i2psystray.sh b/apps/systray/java/src/net/i2p/apps/systray/i2psystray.sh new file mode 100644 index 000000000..18ba553eb --- /dev/null +++ b/apps/systray/java/src/net/i2p/apps/systray/i2psystray.sh @@ -0,0 +1 @@ +java -cp systray4j.jar:. -Djava.library.path=. SysTray diff --git a/apps/systray/java/src/net/i2p/apps/systray/icons/iggy.ico b/apps/systray/java/src/net/i2p/apps/systray/icons/iggy.ico new file mode 100644 index 000000000..f41266e06 Binary files /dev/null and b/apps/systray/java/src/net/i2p/apps/systray/icons/iggy.ico differ diff --git a/apps/systray/java/src/net/i2p/apps/systray/icons/iggy.xpm b/apps/systray/java/src/net/i2p/apps/systray/icons/iggy.xpm new file mode 100644 index 000000000..c83b923c5 --- /dev/null +++ b/apps/systray/java/src/net/i2p/apps/systray/icons/iggy.xpm @@ -0,0 +1,210 @@ +/* XPM */ +static char * iggy_24x24_xpm[] = { +"24 24 183 2", +" c None", +". c #717120", +"+ c #8A8A08", +"@ c #959500", +"# c #88880C", +"$ c #6A6A23", +"% c #555615", +"& c #C9C902", +"* c #FDFD00", +"= c #FFFF00", +"- c #FCFC00", +"; c #C0C001", +"> c #5A5A25", +", c #565610", +"' c #E6E600", +") c #E2E201", +"! c #5A5A1F", +"~ c #CACA03", +"{ c #C8C803", +"] c #747414", +"^ c #F9F900", +"/ c #C9C90D", +"( c #C9C90F", +"_ c #FAFA00", +": c #D5D50A", +"< c #A8A859", +"[ c #A6A63D", +"} c #EEEE01", +"| c #767616", +"1 c #ACAC0A", +"2 c #B2B22C", +"3 c #DADAD8", +"4 c #DDDDDC", +"5 c #B7B730", +"6 c #B0B080", +"7 c #FEFEFE", +"8 c #F6F6F6", +"9 c #B0B032", +"0 c #AEAE0A", +"a c #C9C900", +"b c #B2B275", +"c c #D1D1D1", +"d c #B9B97C", +"e c #9F9F81", +"f c #8C8C8C", +"g c #FCFCFC", +"h c #B1B13F", +"i c #D2D200", +"j c #CDCD00", +"k c #B2B22A", +"l c #DBDBDB", +"m c #575756", +"n c #B4B429", +"o c #BDBD11", +"p c #7C7C5E", +"q c #A7A76D", +"r c #E2E205", +"s c #D7D700", +"t c #B6B605", +"u c #C6C601", +"v c #C5C500", +"w c #BBBB05", +"x c #858510", +"y c #868611", +"z c #5C5C34", +"A c #E4E400", +"B c #E3E300", +"C c #48481D", +"D c #76770C", +"E c #F8F800", +"F c #F6F600", +"G c #747416", +"H c #514745", +"I c #746506", +"J c #EDED00", +"K c #735809", +"L c #592732", +"M c #6F2F3F", +"N c #960D2F", +"O c #CD0134", +"P c #DA0037", +"Q c #7F5F08", +"R c #E7E700", +"S c #C2BF01", +"T c #917A06", +"U c #901D1D", +"V c #EA003B", +"W c #FE0040", +"X c #CF1242", +"Y c #8B092A", +"Z c #F6003E", +"` c #FF0040", +" . c #E20039", +".. c #A49A03", +"+. c #FEFE00", +"@. c #7F4E0D", +"#. c #B0002C", +"$. c #C50032", +"%. c #EF003C", +"&. c #83233B", +"*. c #6C2839", +"=. c #FB003F", +"-. c #FC003F", +";. c #B2002D", +">. c #CA0033", +",. c #A40F25", +"'. c #E2E200", +"). c #EEEE00", +"!. c #940B23", +"~. c #F2003D", +"{. c #F7003E", +"]. c #88243D", +"^. c #732C3E", +"/. c #F5003E", +"(. c #7E0020", +"_. c #890022", +":. c #572C0C", +"<. c #A9A402", +"[. c #D80036", +"}. c #920025", +"|. c #682234", +"1. c #790B26", +"2. c #CD0034", +"3. c #ED003B", +"4. c #92102C", +"5. c #C39C76", +"6. c #A78861", +"7. c #4E1E17", +"8. c #F1003C", +"9. c #890023", +"0. c #CC0234", +"a. c #2A1E19", +"b. c #7E6D31", +"c. c #776C22", +"d. c #73041F", +"e. c #E50039", +"f. c #DE0038", +"g. c #BF0030", +"h. c #6F001C", +"i. c #A40029", +"j. c #6F192E", +"k. c #3A3B2D", +"l. c #969703", +"m. c #7C8218", +"n. c #687560", +"o. c #6C7360", +"p. c #372C28", +"q. c #6D7561", +"r. c #7B8E74", +"s. c #819D7E", +"t. c #7D9C7D", +"u. c #6F5C46", +"v. c #96775A", +"w. c #484445", +"x. c #809F80", +"y. c #BAE8BA", +"z. c #CCFFCC", +"A. c #6A8369", +"B. c #AAD5AA", +"C. c #B1DDB1", +"D. c #565441", +"E. c #584F46", +"F. c #546254", +"G. c #BDECBD", +"H. c #8CAE8C", +"I. c #95BA95", +"J. c #B9E7B9", +"K. c #525C52", +"L. c #5B6B5B", +"M. c #A3CCA3", +"N. c #B2DEB2", +"O. c #9BC29B", +"P. c #728E72", +"Q. c #A5CEA5", +"R. c #90B490", +"S. c #4E5D4E", +"T. c #121212", +"U. c #000000", +"V. c #030303", +"W. c #020202", +"X. c #161616", +"Y. c #282828", +"Z. c #3F3F3F", +" . + @ # $ ", +" % & * = = = - ; > ", +" , ' = = = = = = = ) ! ", +" ~ = = = = = = = = = { ", +" ] * ^ / ( _ = : < [ } * | ", +" 1 = 2 3 4 5 = 6 7 8 9 = 0 ", +" a = b 7 c d = e f g h = i ", +" j = k l m n = o p q r = s ", +" t = * u v = = = = = = = w ", +" x = = = = = = = = = = = y ", +" z A = = = = = = = = = B C ", +" D E = = = = = = = F G ", +" H I J = = = = = ' K L ", +" M N O P Q = R s S T U V W V X ", +" Y Z ` ` ...+.@.#.$.%.` ` ` ` ` &. ", +" *.=.-.;.>.,.'.).!.` ` ` ` ` ` ~.{.]. ", +" ^.-./.(._.:.s <.[.` ` ` ` ` ` }.~.|. ", +" 1.2.3.4.5.6.7.W ` ` ` ` ` 8.9.0. ", +" a.b.c.d. .e.f.[.2.g.h.i.j. ", +" k.l.m.n.o.p.q.r.s.t.u.v.w. ", +" x.y.z.z.A.B.z.z.C.D.E. ", +" F.G.z.z.H.I.z.z.J.K. ", +" L.M.N.O.P.Q.R.S. ", +" T.U.U.U.V.W.X.Y.Z. "}; diff --git a/apps/systray/java/src/net/i2p/apps/systray/icons/iggy_grey.ico b/apps/systray/java/src/net/i2p/apps/systray/icons/iggy_grey.ico new file mode 100644 index 000000000..5ecb77cfb Binary files /dev/null and b/apps/systray/java/src/net/i2p/apps/systray/icons/iggy_grey.ico differ diff --git a/apps/systray/java/src/net/i2p/apps/systray/icons/iggy_grey.xpm b/apps/systray/java/src/net/i2p/apps/systray/icons/iggy_grey.xpm new file mode 100644 index 000000000..e32cb5c29 --- /dev/null +++ b/apps/systray/java/src/net/i2p/apps/systray/icons/iggy_grey.xpm @@ -0,0 +1,143 @@ +/* XPM */ +static char * iggy_grey_24x24_xpm[] = { +"24 24 116 2", +" g None", +". g #686868", +"+ g #7C7C7C", +"@ g #858585", +"# g #7A7A7A", +"$ g #626262", +"% g #4F4F4F", +"& g #B3B3B3", +"* g #E1E1E1", +"= g #E3E3E3", +"- g #E0E0E0", +"; g #ABABAB", +"> g #545454", +", g #4E4E4E", +"' g #CDCDCD", +") g #C9C9C9", +"! g #B4B4B4", +"~ g #B2B2B2", +"{ g #696969", +"] g #DEDEDE", +"^ g #B5B5B5", +"/ g #BFBFBF", +"( g #9F9F9F", +"_ g #9A9A9A", +": g #D4D4D4", +"< g #6B6B6B", +"[ g #A3A3A3", +"} g #DADADA", +"| g #DDDDDD", +"1 g #A8A8A8", +"2 g #FEFEFE", +"3 g #F6F6F6", +"4 g #A2A2A2", +"5 g #9C9C9C", +"6 g #D1D1D1", +"7 g #8C8C8C", +"8 g #FCFCFC", +"9 g #A4A4A4", +"0 g #BBBBBB", +"a g #B6B6B6", +"b g #DBDBDB", +"c g #575757", +"d g #A5A5A5", +"e g #AAAAAA", +"f g #797979", +"g g #A1A1A1", +"h g #CACACA", +"i g #B0B0B0", +"j g #AFAFAF", +"k g #A7A7A7", +"l g #787878", +"m g #585858", +"n g #CBCBCB", +"o g #434343", +"p g #6A6A6A", +"q g #4A4A4A", +"r g #5F5F5F", +"s g #D3D3D3", +"t g #373737", +"u g #444444", +"v g #3A3A3A", +"w g #474747", +"x g #CECECE", +"y g #747474", +"z g #3F3F3F", +"A g #4D4D4D", +"B g #535353", +"C g #505050", +"D g #343434", +"E g #515151", +"F g #E2E2E2", +"G g #565656", +"H g #414141", +"I g #424242", +"J g #3E3E3E", +"K g #525252", +"L g #454545", +"M g #292929", +"N g #2D2D2D", +"O g #353535", +"P g #949494", +"Q g #303030", +"R g #393939", +"S g #2F2F2F", +"T g #8D8D8D", +"U g #2C2C2C", +"V g #212121", +"W g #676767", +"X g #282828", +"Y g #4B4B4B", +"Z g #494949", +"` g #242424", +" . g #363636", +".. g #868686", +"+. g #757575", +"@. g #6F6F6F", +"#. g #707070", +"$. g #919191", +"%. g #8F8F8F", +"&. g #7D7D7D", +"*. g #929292", +"=. g #D5D5D5", +"-. g #EAEAEA", +";. g #C3C3C3", +">. g #5C5C5C", +",. g #D9D9D9", +"'. g #A0A0A0", +"). g #646464", +"!. g #CCCCCC", +"~. g #838383", +"{. g #BDBDBD", +"]. g #121212", +"^. g #000000", +"/. g #030303", +"(. g #020202", +"_. g #161616", +" . + @ # $ ", +" % & * = = = - ; > ", +" , ' = = = = = = = ) > ", +" ! = = = = = = = = = ~ ", +" { * ] ! ^ ] = / ( _ : * < ", +" _ = [ } | 1 = ; 2 3 4 = 5 ", +" & = ; 2 6 ~ = 5 7 8 9 = 0 ", +" a = [ b c d = e f g h = / ", +" [ = * i j = = = = = = = k ", +" l = = = = = = = = = = = f ", +" m n = = = = = = = = = h o ", +" < | = = = = = = = b p ", +" q r s = = = = = ' c t ", +" u v u w r = x / ; y z A B A C ", +" D E > > q 7 F G v H , > > > > > I ", +" J K B v I J ) : t > > > > > > % E L ", +" o B C M N O / P w > > > > > > Q % R ", +" S o , v 9 T U B > > > > > % N u ", +" V < W X q Y Z w o z ` .O ", +" R ..+.@.@.S #.@ $.%.r &.L ", +" *.=.-.-.f ;.-.-.n B E ", +" >.,.-.-.'.; -.-.: m ", +" ).0 !.~ ~.{.d c ", +" ].^.^.^./.(._.X z "}; diff --git a/apps/systray/java/src/net/i2p/apps/systray/lib/systray4j.jar b/apps/systray/java/src/net/i2p/apps/systray/lib/systray4j.jar new file mode 100644 index 000000000..35286cec1 Binary files /dev/null and b/apps/systray/java/src/net/i2p/apps/systray/lib/systray4j.jar differ