• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kalarm/lib

  • sources
  • kde-4.12
  • kdepim
  • kalarm
  • lib
shellprocess.h
Go to the documentation of this file.
1 /*
2  * shellprocess.h - execute a process through the shell
3  * Program: kalarm
4  * Copyright © 2004-2008 by David Jarvie <djarvie@kde.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef SHELLPROCESS_H
22 #define SHELLPROCESS_H
23 
26 #include <kprocess.h>
27 #include <QQueue>
28 #include <QByteArray>
29 
30 
52 class ShellProcess : public KProcess
53 {
54  Q_OBJECT
55  public:
65  enum Status {
66  INACTIVE, // start() has not yet been called to run the command
67  RUNNING, // command is currently running
68  SUCCESS, // command appears to have exited successfully
69  UNAUTHORISED, // shell commands are not authorised for this user
70  DIED, // command didn't exit cleanly, i.e. was killed or died
71  NOT_FOUND, // command either not found or not executable
72  START_FAIL // command couldn't be started for other reasons
73  };
77  explicit ShellProcess(const QString& command);
81  bool start(OpenMode = ReadWrite);
83  Status status() const { return mStatus; }
85  int exitCode() const { return mExitCode; }
89  bool normalExit() const { return mStatus == SUCCESS; }
91  const QString& command() const { return mCommand; }
96  QString errorMessage() const;
98  void writeStdin(const char* buffer, int bufflen);
100  void stdinExit();
104  static bool authorised();
108  static const QByteArray& shellName() { shellPath(); return mShellName; }
112  static const QByteArray& shellPath();
113 
114  signals:
118  void shellExited(ShellProcess*);
120  void receivedStdout(ShellProcess*);
122  void receivedStderr(ShellProcess*);
123 
124  private slots:
125  void writtenStdin(qint64 bytes);
126  void stdoutReady() { emit receivedStdout(this); }
127  void stderrReady() { emit receivedStderr(this); }
128  void slotExited(int exitCode, QProcess::ExitStatus);
129 
130  private:
131  // Prohibit the following inherited methods
132  ShellProcess& operator<<(const QString&);
133  ShellProcess& operator<<(const QStringList&);
134 
135  static QByteArray mShellName; // name of shell to be used
136  static QByteArray mShellPath; // path of shell to be used
137  static bool mInitialised; // true once static data has been initialised
138  static bool mAuthorised; // true if shell commands are authorised
139  QString mCommand; // copy of command to be executed
140  QQueue<QByteArray> mStdinQueue; // queued strings to send to STDIN
141  qint64 mStdinBytes; // bytes still to be written from first queued string
142  int mExitCode; // shell exit value (if mStatus == SUCCESS or NOT_FOUND)
143  Status mStatus; // current execution status
144  bool mStdinExit; // exit once STDIN queue has been written
145 };
146 
147 #endif // SHELLPROCESS_H
148 
149 // vim: et sw=4:
KProcess
ShellProcess::UNAUTHORISED
Definition: shellprocess.h:69
ShellProcess::exitCode
int exitCode() const
Returns the shell exit code.
Definition: shellprocess.h:85
ShellProcess::shellExited
void shellExited(ShellProcess *)
Signal emitted when the shell process execution completes.
ShellProcess::NOT_FOUND
Definition: shellprocess.h:71
ShellProcess::writeStdin
void writeStdin(const char *buffer, int bufflen)
Writes a string to the process's STDIN.
Definition: shellprocess.cpp:104
ShellProcess::SUCCESS
Definition: shellprocess.h:68
ShellProcess::RUNNING
Definition: shellprocess.h:67
ShellProcess::authorised
static bool authorised()
Returns whether the user is authorised to run shell commands.
Definition: shellprocess.cpp:215
ShellProcess::ShellProcess
ShellProcess(const QString &command)
Constructor.
Definition: shellprocess.cpp:38
ShellProcess::status
Status status() const
Returns the current status of the shell process.
Definition: shellprocess.h:83
ShellProcess::START_FAIL
Definition: shellprocess.h:72
ShellProcess::shellPath
static const QByteArray & shellPath()
Determines which shell to use.
Definition: shellprocess.cpp:180
ShellProcess::errorMessage
QString errorMessage() const
Returns the error message corresponding to the command exit status.
Definition: shellprocess.cpp:153
ShellProcess::stdinExit
void stdinExit()
Tell the process to exit once any outstanding STDIN strings have been written.
Definition: shellprocess.cpp:141
ShellProcess::INACTIVE
Definition: shellprocess.h:66
ShellProcess::shellName
static const QByteArray & shellName()
Determines which shell to use.
Definition: shellprocess.h:108
ShellProcess::Status
Status
Current status of the shell process.
Definition: shellprocess.h:65
ShellProcess::normalExit
bool normalExit() const
Returns whether the command was run successfully.
Definition: shellprocess.h:89
ShellProcess::receivedStdout
void receivedStdout(ShellProcess *)
Signal emitted when input is available from the process's stdout.
ShellProcess::DIED
Definition: shellprocess.h:70
ShellProcess::command
const QString & command() const
Returns the command configured to be run.
Definition: shellprocess.h:91
ShellProcess::receivedStderr
void receivedStderr(ShellProcess *)
Signal emitted when input is available from the process's stderr.
ShellProcess
Enhanced KProcess to run a shell command.
Definition: shellprocess.h:52
ShellProcess::start
bool start(OpenMode=ReadWrite)
Executes the configured command.
Definition: shellprocess.cpp:49
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:59:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalarm/lib

Skip menu "kalarm/lib"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal