• Skip to content
  • Skip to link menu
KDE 4.2 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 
00157     QString validCurrentDir() const;
00158 
00177     QString format(const QString& text) const;
00178 
00183     enum Error
00184     {
00186         NoError,
00188         UnknownError,
00190         PermissionsError
00191     };
00192 
00196     Error error() const;
00197 
00198 protected:
00205     explicit ProcessInfo(int pid , bool readEnvironment = false);
00206 
00225     virtual bool readProcessInfo(int pid , bool readEnvironment) = 0;
00226 
00228     void setPid(int pid);
00230     void setParentPid(int pid);
00232     void setForegroundPid(int pid);
00234     void setName(const QString& name);
00236     void setCurrentDir(const QString& dir);
00237 
00239     void setError( Error error );
00240 
00242     void setFileError( QFile::FileError error ); 
00243 
00248     void addArgument(const QString& argument);
00256     void addEnvironmentBinding(const QString& name , const QString& value);
00257 
00258 private:
00259     // takes a full directory path and returns a
00260     // shortened version suitable for display in 
00261     // space-constrained UI elements (eg. tabs)
00262     QString formatShortDir(const QString& dirPath) const;
00263 
00264     enum CommandFormat
00265     {
00266         ShortCommandFormat,
00267         LongCommandFormat
00268     };
00269     // takes a process name and its arguments and produces formatted output
00270     QString formatCommand(const QString& name , const QVector<QString>& arguments , 
00271                           CommandFormat format) const;
00272 
00273     // valid bits for _fields variable, ensure that
00274     // _fields is changed to an int if more than 8 fields are added
00275     enum FIELD_BITS
00276     {
00277         PROCESS_ID          = 1,
00278         PARENT_PID          = 2,
00279         FOREGROUND_PID      = 4,
00280         ARGUMENTS           = 8,
00281         ENVIRONMENT         = 16,
00282         NAME                = 32,
00283         CURRENT_DIR         = 64
00284     };
00285 
00286     char _fields; // a bitmap indicating which fields are valid
00287                   // used to set the "ok" parameters for the public
00288                   // accessor functions
00289 
00290     bool _enableEnvironmentRead; // specifies whether to read the environment
00291                                  // bindings when update() is called
00292     int _pid;  
00293     int _parentPid;
00294     int _foregroundPid;
00295 
00296     Error _lastError;
00297 
00298     QString _name;
00299     QString _currentDir;
00300 
00301     QVector<QString> _arguments;
00302     QMap<QString,QString> _environment;
00303 
00304     static QSet<QString> commonDirNames();
00305     static QSet<QString> _commonDirNames;
00306 };
00307 
00315 class NullProcessInfo : public ProcessInfo
00316 {
00317 public:
00322     explicit NullProcessInfo(int pid,bool readEnvironment = false);
00323 protected:
00324     virtual bool readProcessInfo(int pid,bool readEnvironment);
00325 };
00326 
00331 class UnixProcessInfo : public ProcessInfo
00332 {
00333 public:
00338     explicit UnixProcessInfo(int pid,bool readEnvironment = false);
00339 
00340 protected:
00345     virtual bool readProcessInfo(int pid , bool readEnvironment);
00346 
00347 private:
00353     virtual bool readProcInfo(int pid)=0;
00354 
00360     virtual bool readEnvironment(int pid)=0;
00361 
00367     virtual bool readArguments(int pid)=0;
00368 
00374     virtual bool readCurrentDir(int pid)=0;
00375 };
00376 
00380 class SSHProcessInfo
00381 {
00382 public:
00389     SSHProcessInfo(const ProcessInfo& process);
00390 
00395     QString userName() const;
00396 
00400     QString host() const;
00401 
00406     QString command() const;
00407 
00421     QString format(const QString& input) const;
00422 
00423 private:
00424     const ProcessInfo& _process;
00425     QString _user;
00426     QString _host;
00427     QString _command;
00428 };
00429 
00430 }
00431 #endif //PROCESSINFO_H
00432 
00433 /*
00434   Local Variables:
00435   mode: c++
00436   c-file-style: "stroustrup"
00437   indent-tabs-mode: nil
00438   tab-width: 4
00439   End:
00440 */

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.7
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