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 (C) 2004, 2005 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     public:
00063         enum Status {
00064             INACTIVE,     // start() has not yet been called to run the command
00065             RUNNING,      // command is currently running
00066             SUCCESS,      // command appears to have exited successfully
00067             UNAUTHORISED, // shell commands are not authorised for this user
00068             DIED,         // command didn't exit cleanly, i.e. was killed or died
00069             NOT_FOUND,    // command either not found or not executable
00070             START_FAIL    // command couldn't be started for other reasons
00071         };
00075         ShellProcess(const QString& command);
00080         bool            start(Communication comm = NoCommunication);
00082         Status          status() const       { return mStatus; }
00086         bool            normalExit() const   { return mStatus == SUCCESS; }
00088         const QString&  command() const      { return mCommand; }
00093         QString         errorMessage() const;
00095         void            writeStdin(const char* buffer, int bufflen);
00097         void            stdinExit();
00101         static bool     authorised();
00105         static const QCString& shellName()   { shellPath();  return mShellName; }
00109         static const QCString& shellPath();
00110 
00111     signals:
00115         void  shellExited(ShellProcess*);
00116 
00117     private slots:
00118         void  writtenStdin(KProcess*);
00119         void  slotExited(KProcess*);
00120 
00121     private:
00122         // Prohibit the following inherited methods
00123         ShellProcess&  operator<<(const QString&);
00124         ShellProcess&  operator<<(const QCString&);
00125         ShellProcess&  operator<<(const QStringList&);
00126         ShellProcess&  operator<<(const char*);
00127 
00128         static QCString      mShellName;    // name of shell to be used
00129         static QCString      mShellPath;    // path of shell to be used
00130         static bool          mInitialised;  // true once static data has been initialised
00131         static bool          mAuthorised;   // true if shell commands are authorised
00132         QString              mCommand;      // copy of command to be executed
00133         QValueList<QCString> mStdinQueue;   // queued strings to send to STDIN
00134         Status               mStatus;       // current execution status
00135         bool                 mStdinExit;    // exit once STDIN queue has been written
00136 };
00137 
00138 #endif // SHELLPROCESS_H
KDE Home | KDE Accessibility Home | Description of Access Keys