//# 0 errors, 95 messages
//#
/*
    //#KDialogProcess.java:1:1: class: com.dmdirc.addons.dcc.kde.KDialogProcess
 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.dmdirc.addons.dcc.kde;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

/**
 * Hold a Process and stream readers for a KDialog Process
 */
public class KDialogProcess {
	/** Is kdialog in /bin? */
	private final static boolean isBin = (new File("/bin/kdialog")).exists();
    //#KDialogProcess.java:34: method: com.dmdirc.addons.dcc.kde.KDialogProcess.com.dmdirc.addons.dcc.kde.KDialogProcess__static_init
    //#output(com.dmdirc.addons.dcc.kde.KDialogProcess__static_init): __Descendant_Table[com/dmdirc/addons/dcc/kde/KDialogProcess]
    //#output(com.dmdirc.addons.dcc.kde.KDialogProcess__static_init): __Dispatch_Table.getProcess()Ljava/lang/Process;
    //#output(com.dmdirc.addons.dcc.kde.KDialogProcess__static_init): __Dispatch_Table.getStdErrStream()Lcom/dmdirc/addons/dcc/kde/StreamReader;
    //#output(com.dmdirc.addons.dcc.kde.KDialogProcess__static_init): __Dispatch_Table.getStdOutStream()Lcom/dmdirc/addons/dcc/kde/StreamReader;
    //#output(com.dmdirc.addons.dcc.kde.KDialogProcess__static_init): __Dispatch_Table.waitFor()V
    //#output(com.dmdirc.addons.dcc.kde.KDialogProcess__static_init): hasKDialog
    //#output(com.dmdirc.addons.dcc.kde.KDialogProcess__static_init): isBin
    //#post(com.dmdirc.addons.dcc.kde.KDialogProcess__static_init): __Descendant_Table[com/dmdirc/addons/dcc/kde/KDialogProcess] == &__Dispatch_Table
    //#post(com.dmdirc.addons.dcc.kde.KDialogProcess__static_init): __Dispatch_Table.getProcess()Ljava/lang/Process; == &getProcess
    //#post(com.dmdirc.addons.dcc.kde.KDialogProcess__static_init): __Dispatch_Table.getStdErrStream()Lcom/dmdirc/addons/dcc/kde/StreamReader; == &getStdErrStream
    //#post(com.dmdirc.addons.dcc.kde.KDialogProcess__static_init): __Dispatch_Table.getStdOutStream()Lcom/dmdirc/addons/dcc/kde/StreamReader; == &getStdOutStream
    //#post(com.dmdirc.addons.dcc.kde.KDialogProcess__static_init): __Dispatch_Table.waitFor()V == &waitFor
    //#post(com.dmdirc.addons.dcc.kde.KDialogProcess__static_init): init'ed(hasKDialog)
    //#post(com.dmdirc.addons.dcc.kde.KDialogProcess__static_init): init'ed(isBin)
	
	/** Does KDialog exist? */
	private final static boolean hasKDialog = (new File("/usr/bin/kdialog")).exists() || isBin;	
    //#KDialogProcess.java:37: end of method: com.dmdirc.addons.dcc.kde.KDialogProcess.com.dmdirc.addons.dcc.kde.KDialogProcess__static_init

	/** Stream for the stdout stream for this process */
	private final StreamReader stdOutputStream;
	
	/** Stream for the stderr stream for this process */
	private final StreamReader stdErrorStream;
	
	/** The actual process for this process */
	private final Process process;
	
	/**
	 * Execute kdialog with the Parameters in params
	 *
	 * @param params Parameters to pass to kdialog
	 */
	public KDialogProcess(final String[] params) throws IOException {
    //#KDialogProcess.java:53: method: void com.dmdirc.addons.dcc.kde.KDialogProcess.com.dmdirc.addons.dcc.kde.KDialogProcess(String[])
    //#input(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): isBin
    //#input(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): params
    //#input(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): params.length
    //#input(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): this
    //#output(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): new ArrayList(KDialogProcess#3) num objects
    //#output(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): new ArrayList(KDialogProcess#5) num objects
    //#output(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): new StreamReader(KDialogProcess#2) num objects
    //#output(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): this.stdOutputStream.__Tag
    //#output(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): this.stdOutputStream.list
    //#output(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): this.stdOutputStream.prefix
    //#output(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): this.stdOutputStream.stream
    //#output(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): new StreamReader(KDialogProcess#4) num objects
    //#output(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): this.stdErrorStream.__Tag
    //#output(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): this.stdErrorStream.list
    //#output(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): this.stdErrorStream.prefix
    //#output(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): this.stdErrorStream.stream
    //#output(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): this.process
    //#output(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): this.stdErrorStream
    //#output(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): this.stdOutputStream
    //#new obj(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): new ArrayList(KDialogProcess#3)
    //#new obj(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): new ArrayList(KDialogProcess#5)
    //#new obj(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): new StreamReader(KDialogProcess#2)
    //#new obj(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): new StreamReader(KDialogProcess#4)
    //#pre[1] (void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): params != null
    //#presumption(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): java.lang.Runtime:exec(...)@57 != null
    //#presumption(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): java.lang.Runtime:getRuntime(...)@57 != null
    //#post(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): this.process != null
    //#post(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): this.stdErrorStream == &new StreamReader(KDialogProcess#4)
    //#post(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): this.stdOutputStream == &new StreamReader(KDialogProcess#2)
    //#post(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): new ArrayList(KDialogProcess#3) num objects == 1
    //#post(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): new ArrayList(KDialogProcess#5) num objects == 1
    //#post(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): new StreamReader(KDialogProcess#2) num objects == 1
    //#post(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): new StreamReader(KDialogProcess#4) num objects == 1
    //#post(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): this.stdOutputStream.__Tag == com/dmdirc/addons/dcc/kde/StreamReader
    //#post(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): this.stdErrorStream.__Tag == com/dmdirc/addons/dcc/kde/StreamReader
    //#post(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): this.stdOutputStream.list == &new ArrayList(KDialogProcess#3)
    //#post(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): init'ed(this.stdOutputStream.prefix)
    //#post(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): init'ed(this.stdOutputStream.stream)
    //#post(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): this.stdErrorStream.list == &new ArrayList(KDialogProcess#5)
    //#post(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): init'ed(this.stdErrorStream.prefix)
    //#post(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): init'ed(this.stdErrorStream.stream)
    //#unanalyzed(void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])): Effects-of-calling:java.lang.Thread
		final String[] exec = new String[params.length+1];
		System.arraycopy(params, 0, exec, 1, params.length);
		exec[0] = (isBin) ? "/bin/kdialog" : "/usr/bin/kdialog";
		process = Runtime.getRuntime().exec(exec);
		stdOutputStream = new StreamReader(process.getInputStream(), new ArrayList<String>());
		stdErrorStream = new StreamReader(process.getErrorStream(), new ArrayList<String>());
		stdOutputStream.start();
    //#KDialogProcess.java:60: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.addons.dcc.kde.StreamReader:start()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.dcc.kde.KDialogProcess
    //#    method: void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])
    //#    unanalyzed callee: void com.dmdirc.addons.dcc.kde.StreamReader:start()
		stdErrorStream.start();
    //#KDialogProcess.java:61: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.addons.dcc.kde.StreamReader:start()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.dcc.kde.KDialogProcess
    //#    method: void com.dmdirc.addons.dcc.kde.KDialogProcess(String[])
    //#    unanalyzed callee: void com.dmdirc.addons.dcc.kde.StreamReader:start()
	}
    //#KDialogProcess.java:62: end of method: void com.dmdirc.addons.dcc.kde.KDialogProcess.com.dmdirc.addons.dcc.kde.KDialogProcess(String[])
	
	/**
	 * Does this system have kdialog?
	 *
	 * @return True if kdialog was found, else false
	 */
	public static boolean hasKDialog() {
		return hasKDialog;
    //#KDialogProcess.java:70: method: bool com.dmdirc.addons.dcc.kde.KDialogProcess.hasKDialog()
    //#input(bool hasKDialog()): hasKDialog
    //#output(bool hasKDialog()): return_value
    //#post(bool hasKDialog()): init'ed(return_value)
    //#KDialogProcess.java:70: end of method: bool com.dmdirc.addons.dcc.kde.KDialogProcess.hasKDialog()
	}
	
	/**
	 * Get the process object for this KDialogProcess
	 *
	 * @return The process object for this KDialogProcess
	 */
	public Process getProcess() {
		return process;
    //#KDialogProcess.java:79: method: Process com.dmdirc.addons.dcc.kde.KDialogProcess.getProcess()
    //#input(Process getProcess()): this
    //#input(Process getProcess()): this.process
    //#output(Process getProcess()): return_value
    //#post(Process getProcess()): return_value == this.process
    //#post(Process getProcess()): init'ed(return_value)
    //#KDialogProcess.java:79: end of method: Process com.dmdirc.addons.dcc.kde.KDialogProcess.getProcess()
	}
	
	/**
	 * Get the StreamReader for this KDialogProcess's stdout stream
	 *
	 * @return The StreamReader for this KDialogProcess's stdout stream
	 */
	public StreamReader getStdOutStream() {
		return stdOutputStream;
    //#KDialogProcess.java:88: method: StreamReader com.dmdirc.addons.dcc.kde.KDialogProcess.getStdOutStream()
    //#input(StreamReader getStdOutStream()): this
    //#input(StreamReader getStdOutStream()): this.stdOutputStream
    //#output(StreamReader getStdOutStream()): return_value
    //#post(StreamReader getStdOutStream()): return_value == this.stdOutputStream
    //#post(StreamReader getStdOutStream()): init'ed(return_value)
    //#KDialogProcess.java:88: end of method: StreamReader com.dmdirc.addons.dcc.kde.KDialogProcess.getStdOutStream()
	}
	
	/**
	 * Get the StreamReader for this KDialogProcess's stderr stream
	 *
	 * @return The StreamReader for this KDialogProcess's stderr stream
	 */
	public StreamReader getStdErrStream() {
		return stdErrorStream;
    //#KDialogProcess.java:97: method: StreamReader com.dmdirc.addons.dcc.kde.KDialogProcess.getStdErrStream()
    //#input(StreamReader getStdErrStream()): this
    //#input(StreamReader getStdErrStream()): this.stdErrorStream
    //#output(StreamReader getStdErrStream()): return_value
    //#post(StreamReader getStdErrStream()): return_value == this.stdErrorStream
    //#post(StreamReader getStdErrStream()): init'ed(return_value)
    //#KDialogProcess.java:97: end of method: StreamReader com.dmdirc.addons.dcc.kde.KDialogProcess.getStdErrStream()
	}
	
	/**
	 * Wait for the process to finish.
	 */
	public void waitFor() throws InterruptedException {
		process.waitFor();
    //#KDialogProcess.java:104: method: void com.dmdirc.addons.dcc.kde.KDialogProcess.waitFor()
    //#input(void waitFor()): this
    //#input(void waitFor()): this.process
    //#pre[2] (void waitFor()): this.process != null
	}
    //#KDialogProcess.java:105: end of method: void com.dmdirc.addons.dcc.kde.KDialogProcess.waitFor()
}    //#KDialogProcess.java:: end of class: com.dmdirc.addons.dcc.kde.KDialogProcess
