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

Konsole

  • kde-4.14
  • applications
  • konsole
  • src
ProcessInfo.h
Go to the documentation of this file.
1 /*
2  Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301 USA.
18 */
19 
20 #ifndef PROCESSINFO_H
21 #define PROCESSINFO_H
22 
23 // Qt
24 #include <QtCore/QFile>
25 #include <QtCore/QMap>
26 #include <QtCore/QString>
27 #include <QtCore/QVector>
28 
29 namespace Konsole
30 {
74 class ProcessInfo
75 {
76 public:
88  static ProcessInfo* newInstance(int pid, bool readEnvironment = false);
89 
90  virtual ~ProcessInfo() {}
91 
96  void update();
97 
99  bool isValid() const;
105  int pid(bool* ok) const;
111  int parentPid(bool* ok) const;
112 
122  int foregroundPid(bool* ok) const;
123 
124  /* Returns the user id of the process */
125  int userId(bool* ok) const;
126 
128  QString userName() const;
129 
131  QString userHomeDir() const;
132 
134  static QString localHost();
135 
137  QString name(bool* ok) const;
138 
147  QVector<QString> arguments(bool* ok) const;
156  QMap<QString, QString> environment(bool* ok) const;
157 
163  QString currentDir(bool* ok) const;
164 
168  QString validCurrentDir() const;
169 
171  void setUserHomeDir();
172 
191  QString format(const QString& text) const;
192 
197  enum Error {
199  NoError,
201  UnknownError,
203  PermissionsError
204  };
205 
209  Error error() const;
210 
211 protected:
218  explicit ProcessInfo(int pid , bool readEnvironment = false);
219 
238  virtual bool readProcessInfo(int pid , bool readEnvironment) = 0;
239 
240  /* Read the user name */
241  virtual void readUserName(void) = 0;
242 
244  void setPid(int pid);
246  void setParentPid(int pid);
248  void setForegroundPid(int pid);
250  void setUserId(int uid);
252  void setUserName(const QString& name);
254  void setName(const QString& name);
256  void setCurrentDir(const QString& dir);
257 
259  void setError(Error error);
260 
262  void setFileError(QFile::FileError error);
263 
268  void addArgument(const QString& argument);
269 
274  void clearArguments();
275 
283  void addEnvironmentBinding(const QString& name , const QString& value);
284 
285 private:
286  // takes a full directory path and returns a
287  // shortened version suitable for display in
288  // space-constrained UI elements (eg. tabs)
289  QString formatShortDir(const QString& dirPath) const;
290 
291  // valid bits for _fields variable, ensure that
292  // _fields is changed to an int if more than 8 fields are added
293  enum FIELD_BITS {
294  PROCESS_ID = 1,
295  PARENT_PID = 2,
296  FOREGROUND_PID = 4,
297  ARGUMENTS = 8,
298  ENVIRONMENT = 16,
299  NAME = 32,
300  CURRENT_DIR = 64,
301  UID = 128
302  };
303 
304  char _fields; // a bitmap indicating which fields are valid
305  // used to set the "ok" parameters for the public
306  // accessor functions
307 
308  bool _enableEnvironmentRead; // specifies whether to read the environment
309  // bindings when update() is called
310  int _pid;
311  int _parentPid;
312  int _foregroundPid;
313  int _userId;
314 
315  Error _lastError;
316 
317  QString _name;
318  QString _userName;
319  QString _userHomeDir;
320  QString _currentDir;
321 
322  QVector<QString> _arguments;
323  QMap<QString, QString> _environment;
324 
325  static QSet<QString> commonDirNames();
326  static QSet<QString> _commonDirNames;
327 };
328 
336 class NullProcessInfo : public ProcessInfo
337 {
338 public:
343  explicit NullProcessInfo(int pid, bool readEnvironment = false);
344 protected:
345  virtual bool readProcessInfo(int pid, bool readEnvironment);
346  virtual void readUserName(void);
347 };
348 
349 #if !defined(Q_OS_WIN)
350 
354 class UnixProcessInfo : public ProcessInfo
355 {
356 public:
361  explicit UnixProcessInfo(int pid, bool readEnvironment = false);
362 
363 protected:
368  virtual bool readProcessInfo(int pid , bool readEnvironment);
369 
370  virtual void readUserName(void);
371 
372 private:
378  virtual bool readProcInfo(int pid) = 0;
379 
385  virtual bool readEnvironment(int pid) = 0;
386 
392  virtual bool readArguments(int pid) = 0;
393 
399  virtual bool readCurrentDir(int pid) = 0;
400 };
401 #endif
402 
406 class SSHProcessInfo
407 {
408 public:
415  explicit SSHProcessInfo(const ProcessInfo& process);
416 
421  QString userName() const;
422 
426  QString host() const;
427 
431  QString port() const;
432 
437  QString command() const;
438 
452  QString format(const QString& input) const;
453 
454 private:
455  const ProcessInfo& _process;
456  QString _user;
457  QString _host;
458  QString _port;
459  QString _command;
460 };
461 }
462 #endif //PROCESSINFO_H
Konsole::ProcessInfo::userHomeDir
QString userHomeDir() const
Returns the user's home directory of the process.
Definition: ProcessInfo.cpp:252
Konsole::ProcessInfo::environment
QMap< QString, QString > environment(bool *ok) const
Returns the environment bindings which the process was started with.
Definition: ProcessInfo.cpp:200
Konsole::ProcessInfo::currentDir
QString currentDir(bool *ok) const
Returns the current working directory of the process.
Definition: ProcessInfo.cpp:300
Konsole::ProcessInfo::setError
void setError(Error error)
Sets the error.
Definition: ProcessInfo.cpp:91
Konsole::ProcessInfo::setUserName
void setUserName(const QString &name)
Sets the user name of the process as set by readUserName()
Definition: ProcessInfo.cpp:274
Konsole::ProcessInfo::NoError
No error occurred.
Definition: ProcessInfo.h:199
QMap< QString, QString >
Konsole::NullProcessInfo::readProcessInfo
virtual bool readProcessInfo(int pid, bool readEnvironment)
This is called on construction to read the process state Subclasses should reimplement this function ...
Definition: ProcessInfo.cpp:357
Konsole::ProcessInfo::setCurrentDir
void setCurrentDir(const QString &dir)
Sets the current working directory for the process.
Definition: ProcessInfo.cpp:307
Konsole::ProcessInfo::foregroundPid
int foregroundPid(bool *ok) const
Returns the id of the current foreground process.
Definition: ProcessInfo.cpp:226
Konsole::ProcessInfo::localHost
static QString localHost()
Returns the local host.
Definition: ProcessInfo.cpp:257
Konsole::ProcessInfo::setPid
void setPid(int pid)
Sets the process id associated with this ProcessInfo instance.
Definition: ProcessInfo.cpp:262
Konsole::ProcessInfo::newInstance
static ProcessInfo * newInstance(int pid, bool readEnvironment=false)
Constructs a new instance of a suitable ProcessInfo sub-class for the current platform which provides...
Definition: ProcessInfo.cpp:1165
Konsole::ProcessInfo::pid
int pid(bool *ok) const
Returns the process id.
Definition: ProcessInfo.cpp:212
Konsole::ProcessInfo::update
void update()
Updates the information about the process.
Definition: ProcessInfo.cpp:96
Konsole::NullProcessInfo::NullProcessInfo
NullProcessInfo(int pid, bool readEnvironment=false)
Constructs a new NullProcessInfo instance.
Definition: ProcessInfo.cpp:352
Konsole::ProcessInfo::ProcessInfo
ProcessInfo(int pid, bool readEnvironment=false)
Constructs a new process instance.
Definition: ProcessInfo.cpp:68
Konsole::SSHProcessInfo::userName
QString userName() const
Returns the user name which the user initially logged into on the remote computer.
Definition: ProcessInfo.cpp:1119
Konsole::ProcessInfo::setName
void setName(const QString &name)
Sets the name of the process as returned by name()
Definition: ProcessInfo.cpp:313
Konsole::ProcessInfo::setUserHomeDir
void setUserHomeDir()
Forces the user home directory to be calculated.
Definition: ProcessInfo.cpp:280
Konsole::ProcessInfo::name
QString name(bool *ok) const
Returns the name of the current process.
Definition: ProcessInfo.cpp:233
Konsole::SSHProcessInfo::command
QString command() const
Returns the command which the user specified to execute on the remote computer when starting the SSH ...
Definition: ProcessInfo.cpp:1131
Konsole::UnixProcessInfo
Implementation of ProcessInfo for Unix platforms which uses the /proc filesystem. ...
Definition: ProcessInfo.h:354
Konsole::ProcessInfo::addEnvironmentBinding
void addEnvironmentBinding(const QString &name, const QString &value)
Adds an environment binding for the process, as returned by environment()
Definition: ProcessInfo.cpp:328
Konsole::SSHProcessInfo
Lightweight class which provides additional information about SSH processes.
Definition: ProcessInfo.h:406
Konsole::ProcessInfo
Takes a snapshot of the state of a process and provides access to information such as the process nam...
Definition: ProcessInfo.h:74
Konsole::ProcessInfo::format
QString format(const QString &text) const
Parses an input string, looking for markers beginning with a '' character and returns a string with t...
Definition: ProcessInfo.cpp:120
Konsole::UnixProcessInfo::UnixProcessInfo
UnixProcessInfo(int pid, bool readEnvironment=false)
Constructs a new instance of UnixProcessInfo.
Definition: ProcessInfo.cpp:367
Konsole::ProcessInfo::setUserId
void setUserId(int uid)
Sets the user id associated with this ProcessInfo instance.
Definition: ProcessInfo.cpp:268
Konsole::ProcessInfo::userName
QString userName() const
Returns the user's name of the process.
Definition: ProcessInfo.cpp:247
Konsole::UnixProcessInfo::readProcessInfo
virtual bool readProcessInfo(int pid, bool readEnvironment)
Implementation of ProcessInfo::readProcessInfo(); calls the four private methods below in turn...
Definition: ProcessInfo.cpp:372
QSet< QString >
Konsole::ProcessInfo::readUserName
virtual void readUserName(void)=0
Konsole::SSHProcessInfo::host
QString host() const
Returns the host which the user has connected to.
Definition: ProcessInfo.cpp:1123
Konsole::ProcessInfo::setForegroundPid
void setForegroundPid(int pid)
Sets the foreground process id as returned by foregroundPid()
Definition: ProcessInfo.cpp:294
QString
Konsole::ProcessInfo::Error
Error
This enum describes the errors which can occur when trying to read a process's information.
Definition: ProcessInfo.h:197
Konsole::ProcessInfo::validCurrentDir
QString validCurrentDir() const
Returns the current working directory of the process (or its parent)
Definition: ProcessInfo.cpp:101
Konsole::ProcessInfo::isValid
bool isValid() const
Returns true if the process state was read successfully.
Definition: ProcessInfo.cpp:207
Konsole::ProcessInfo::UnknownError
The nature of the error is unknown.
Definition: ProcessInfo.h:201
Konsole::UnixProcessInfo::readUserName
virtual void readUserName(void)
Definition: ProcessInfo.cpp:389
Konsole::SSHProcessInfo::SSHProcessInfo
SSHProcessInfo(const ProcessInfo &process)
Constructs a new SSHProcessInfo instance which provides additional information about the specified SS...
Definition: ProcessInfo.cpp:1017
QVector< QString >
Konsole::NullProcessInfo
Implementation of ProcessInfo which does nothing.
Definition: ProcessInfo.h:336
Konsole::SSHProcessInfo::format
QString format(const QString &input) const
Operates in the same way as ProcessInfo::format(), except that the set of markers understood is diffe...
Definition: ProcessInfo.cpp:1135
Konsole::ProcessInfo::parentPid
int parentPid(bool *ok) const
Returns the id of the parent process id was read successfully or false otherwise. ...
Definition: ProcessInfo.cpp:219
Konsole::ProcessInfo::arguments
QVector< QString > arguments(bool *ok) const
Returns the command-line arguments which the process was started with.
Definition: ProcessInfo.cpp:193
Konsole::ProcessInfo::~ProcessInfo
virtual ~ProcessInfo()
Definition: ProcessInfo.h:90
Konsole::ProcessInfo::addArgument
void addArgument(const QString &argument)
Adds a commandline argument for the process, as returned by arguments()
Definition: ProcessInfo.cpp:318
Konsole::ProcessInfo::PermissionsError
Konsole does not have permission to obtain the process information.
Definition: ProcessInfo.h:203
Konsole::ProcessInfo::setFileError
void setFileError(QFile::FileError error)
Convenience method.
Definition: ProcessInfo.cpp:333
Konsole::ProcessInfo::error
Error error() const
Returns the last error which occurred.
Definition: ProcessInfo.cpp:87
Konsole::ProcessInfo::setParentPid
void setParentPid(int pid)
Sets the parent process id as returned by parentPid()
Definition: ProcessInfo.cpp:289
Konsole::NullProcessInfo::readUserName
virtual void readUserName(void)
Definition: ProcessInfo.cpp:362
Konsole::ProcessInfo::clearArguments
void clearArguments()
clear the commandline arguments for the process, as returned by arguments()
Definition: ProcessInfo.cpp:323
Konsole::ProcessInfo::readProcessInfo
virtual bool readProcessInfo(int pid, bool readEnvironment)=0
This is called on construction to read the process state Subclasses should reimplement this function ...
Konsole::ProcessInfo::userId
int userId(bool *ok) const
Definition: ProcessInfo.cpp:240
Konsole::SSHProcessInfo::port
QString port() const
Returns the port on host which the user has connected to.
Definition: ProcessInfo.cpp:1127
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

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