• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Konsole

ProcessInfo.h

Go to the documentation of this file.
00001 /*
00002     Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301  USA.
00018 */
00019 
00020 #ifndef PROCESSINFO_H
00021 #define PROCESSINFO_H
00022 
00023 // Qt
00024 #include <QtCore/QFile>
00025 #include <QtCore/QMap>
00026 #include <QtCore/QString>
00027 #include <QtCore/QVector>
00028 
00029 namespace Konsole
00030 {
00031 
00075 class ProcessInfo
00076 {
00077 public:
00089     static ProcessInfo* newInstance(int pid,bool readEnvironment = false);
00090 
00091     virtual ~ProcessInfo() {}
00092 
00097     void update();
00098 
00100     bool isValid() const;
00106     int pid(bool* ok) const;
00112     int parentPid(bool* ok) const;
00113     
00123     int foregroundPid(bool* ok) const;
00124     
00126     QString name(bool* ok) const;
00127    
00136     QVector<QString> arguments(bool* ok) const;
00145     QMap<QString,QString> environment(bool* ok) const;
00146 
00152     QString currentDir(bool* ok) const;
00153 
00172     QString format(const QString& text) const;
00173 
00178     enum Error
00179     {
00181         NoError,
00183         UnknownError,
00185         PermissionsError
00186     };
00187 
00191     Error error() const;
00192 
00193 protected:
00200     explicit ProcessInfo(int pid , bool readEnvironment = false);
00201 
00220     virtual bool readProcessInfo(int pid , bool readEnvironment) = 0;
00221 
00223     void setPid(int pid);
00225     void setParentPid(int pid);
00227     void setForegroundPid(int pid);
00229     void setName(const QString& name);
00231     void setCurrentDir(const QString& dir);
00232 
00234     void setError( Error error );
00235 
00237     void setFileError( QFile::FileError error ); 
00238 
00243     void addArgument(const QString& argument);
00251     void addEnvironmentBinding(const QString& name , const QString& value);
00252 
00253 private:
00254     // takes a full directory path and returns a
00255     // shortened version suitable for display in 
00256     // space-constrained UI elements (eg. tabs)
00257     QString formatShortDir(const QString& dirPath) const;
00258 
00259     enum CommandFormat
00260     {
00261         ShortCommandFormat,
00262         LongCommandFormat
00263     };
00264     // takes a process name and its arguments and produces formatted output
00265     QString formatCommand(const QString& name , const QVector<QString>& arguments , 
00266                           CommandFormat format) const;
00267 
00268     // valid bits for _fields variable, ensure that
00269     // _fields is changed to an int if more than 8 fields are added
00270     enum FIELD_BITS
00271     {
00272         PROCESS_ID          = 1,
00273         PARENT_PID          = 2,
00274         FOREGROUND_PID      = 4,
00275         ARGUMENTS           = 8,
00276         ENVIRONMENT         = 16,
00277         NAME                = 32,
00278         CURRENT_DIR         = 64
00279     };
00280 
00281     char _fields; // a bitmap indicating which fields are valid
00282                   // used to set the "ok" parameters for the public
00283                   // accessor functions
00284 
00285     bool _enableEnvironmentRead; // specifies whether to read the environment
00286                                  // bindings when update() is called
00287     int _pid;  
00288     int _parentPid;
00289     int _foregroundPid;
00290 
00291     Error _lastError;
00292 
00293     QString _name;
00294     QString _currentDir;
00295 
00296     QVector<QString> _arguments;
00297     QMap<QString,QString> _environment;
00298 
00299     static QSet<QString> commonDirNames();
00300     static QSet<QString> _commonDirNames;
00301 };
00302 
00310 class NullProcessInfo : public ProcessInfo
00311 {
00312 public:
00317     explicit NullProcessInfo(int pid,bool readEnvironment = false);
00318 protected:
00319     virtual bool readProcessInfo(int pid,bool readEnvironment);
00320 };
00321 
00326 class UnixProcessInfo : public ProcessInfo
00327 {
00328 public:
00333     explicit UnixProcessInfo(int pid,bool readEnvironment = false);
00334 
00335 protected:
00340     virtual bool readProcessInfo(int pid , bool readEnvironment);
00341 
00342 private:
00348     virtual bool readProcInfo(int pid)=0;
00349 
00355     virtual bool readEnvironment(int pid)=0;
00356 
00362     virtual bool readArguments(int pid)=0;
00363 
00369     virtual bool readCurrentDir(int pid)=0;
00370 };
00371 
00375 class SSHProcessInfo
00376 {
00377 public:
00384     SSHProcessInfo(const ProcessInfo& process);
00385 
00390     QString userName() const;
00391 
00395     QString host() const;
00396 
00401     QString command() const;
00402 
00416     QString format(const QString& input) const;
00417 
00418 private:
00419     const ProcessInfo& _process;
00420     QString _user;
00421     QString _host;
00422     QString _command;
00423 };
00424 
00425 }
00426 #endif //PROCESSINFO_H

Konsole

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

API Reference

Skip menu "API Reference"
  • Konsole
  • Libraries
  •   libkonq
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal