kalarm/lib

shellprocess.h
Go to the documentation of this file.
00001 /*
00002  *  shellprocess.h  -  execute a process through the shell
00003  *  Program:  kalarm
00004  *  Copyright © 2004-2006 by David Jarvie <software@astrojar.org.uk>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #ifndef SHELLPROCESS_H
00022 #define SHELLPROCESS_H
00023 
00026 #include <kprocess.h>
00027 
00028 
00050 class ShellProcess : public KShellProcess
00051 {
00052         Q_OBJECT
00053   TQ_OBJECT
00054     public:
00064         enum Status {
00065             INACTIVE,     // start() has not yet been called to run the command
00066             RUNNING,      // command is currently running
00067             SUCCESS,      // command appears to have exited successfully
00068             UNAUTHORISED, // shell commands are not authorised for this user
00069             DIED,         // command didn't exit cleanly, i.e. was killed or died
00070             NOT_FOUND,    // command either not found or not executable
00071             START_FAIL    // command couldn't be started for other reasons
00072         };
00076         explicit ShellProcess(const TQString& command);
00081         bool            start(Communication comm = NoCommunication);
00083         Status          status() const       { return mStatus; }
00087         bool            normalExit() const   { return mStatus == SUCCESS; }
00089         const TQString&  command() const      { return mCommand; }
00094         TQString         errorMessage() const;
00096         void            writeStdin(const char* buffer, int bufflen);
00098         void            stdinExit();
00102         static bool     authorised();
00106         static const TQCString& shellName()   { shellPath();  return mShellName; }
00110         static const TQCString& shellPath();
00111 
00112     signals:
00116         void  shellExited(ShellProcess*);
00117 
00118     private slots:
00119         void  writtenStdin(KProcess*);
00120         void  slotExited(KProcess*);
00121 
00122     private:
00123         // Prohibit the following inherited methods
00124         ShellProcess&  operator<<(const TQString&);
00125         ShellProcess&  operator<<(const TQCString&);
00126         ShellProcess&  operator<<(const TQStringList&);
00127         ShellProcess&  operator<<(const char*);
00128 
00129         static TQCString      mShellName;    // name of shell to be used
00130         static TQCString      mShellPath;    // path of shell to be used
00131         static bool          mInitialised;  // true once static data has been initialised
00132         static bool          mAuthorised;   // true if shell commands are authorised
00133         TQString              mCommand;      // copy of command to be executed
00134         TQValueList<TQCString> mStdinQueue;   // queued strings to send to STDIN
00135         Status               mStatus;       // current execution status
00136         bool                 mStdinExit;    // exit once STDIN queue has been written
00137 };
00138 
00139 #endif // SHELLPROCESS_H