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

Konsole

Profile.h

Go to the documentation of this file.
00001 /*
00002     This source file is part of Konsole, a terminal emulator.
00003 
00004     Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
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
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019     02110-1301  USA.
00020 */
00021 
00022 #ifndef PROFILE_H
00023 #define PROFILE_H
00024 
00025 // Qt
00026 #include <QtCore/QHash>
00027 #include <QtCore/QObject>
00028 #include <QtCore/QPointer>
00029 #include <QtCore/QStringList>
00030 #include <QtCore/QVariant>
00031 
00032 #include <QtGui/QFont>
00033 
00034 // KDE
00035 #include <KSharedPtr>
00036 #include <KDebug>
00037 #include <kdemacros.h>
00038 
00039 class KConfig;
00040 class KConfigGroup;
00041 
00042 namespace Konsole
00043 {
00044 class ProfileGroup;
00045 
00064 class KDE_EXPORT Profile : public QSharedData 
00065 {
00066 
00067 friend class KDE4ProfileReader;
00068 friend class KDE4ProfileWriter;
00069 friend class ProfileGroup;
00070 
00071 public:
00072     typedef KSharedPtr<Profile> Ptr;
00073     typedef KSharedPtr<ProfileGroup> GroupPtr;
00074 
00082     enum Property
00083     {
00085         Path,   
00087         Name,   
00089         Title, 
00093         Icon, 
00097         Command,   
00101         Arguments,
00106         Environment,
00108         Directory,
00110         LocalTabTitleFormat,   
00113         RemoteTabTitleFormat,   
00115         ShowMenuBar,    
00118         TabBarMode,    
00120         Font,           
00125         ColorScheme,   
00129         KeyBindings, 
00133         HistoryMode,
00138         HistorySize,
00142         ScrollBarPosition,  
00144         BidiRenderingEnabled,
00146         BlinkingTextEnabled,       
00150         FlowControlEnabled,
00154         AllowProgramsToResizeWindow,
00158         BlinkingCursorEnabled,
00163         UseCustomCursorColor,
00165         CursorShape,           
00168         CustomCursorColor,        
00172         WordCharacters,
00174         TabBarPosition,
00176         DefaultEncoding,
00178         AntiAliasFonts,
00181         StartInCurrentSessionDir,
00183         ShowNewAndCloseTabButtons
00184     };
00185 
00189     enum TabBarModeEnum
00190     {
00192         AlwaysHideTabBar   = 0,
00194         ShowTabBarAsNeeded = 1,
00196         AlwaysShowTabBar   = 2
00197     };
00198 
00202     enum TabBarPositionEnum
00203     {
00205         TabBarBottom = 0,
00207         TabBarTop    = 1
00208     };
00209 
00214     enum HistoryModeEnum
00215     {
00217         DisableHistory   = 0,
00220         FixedSizeHistory = 1,
00225         UnlimitedHistory = 2
00226     };
00227 
00231     enum ScrollBarPositionEnum
00232     {
00234         ScrollBarLeft   = 0,
00236         ScrollBarRight  = 1,
00238         ScrollBarHidden = 2
00239     };
00240 
00242     enum CursorShapeEnum
00243     {
00245         BlockCursor     = 0,
00247         IBeamCursor     = 1,
00249         UnderlineCursor = 2
00250     };
00251 
00259     explicit Profile(Ptr parent = Ptr());
00260     virtual ~Profile(); 
00261 
00271     void clone(Ptr profile, bool differentOnly = true);
00272 
00278     void setParent(Ptr parent);
00279 
00281     const Ptr parent() const;
00282 
00284     const GroupPtr asGroup() const;
00285     GroupPtr asGroup();
00286 
00296     template <class T>
00297     T property(Property property) const;
00298     
00300     virtual void setProperty(Property property,const QVariant& value);
00302     virtual bool isPropertySet(Property property) const;
00303 
00305     virtual QHash<Property,QVariant> setProperties() const;
00306 
00308     bool isEmpty() const;
00309 
00318     bool isHidden() const;
00319 
00321     void setHidden(bool hidden);
00322 
00323     //
00324     // Convenience methods for property() and setProperty() go here
00325     //
00326 
00328     QString path() const { return property<QString>(Profile::Path); }
00329 
00331     QString name() const { return property<QString>(Profile::Name); }
00332     
00334     QString defaultWorkingDirectory() const 
00335             { return property<QString>(Profile::Directory); }
00336 
00338     QString icon() const { return property<QString>(Profile::Icon); }
00339 
00341     QString command() const { return property<QString>(Profile::Command); }
00342 
00344     QStringList arguments() const { return property<QStringList>(Profile::Arguments); }
00345 
00347     QFont font() const { return property<QFont>(Profile::Font); }
00348 
00350     QString colorScheme() const { return property<QString>(Profile::ColorScheme); }
00351 
00353     QStringList environment() const { return property<QStringList>(Profile::Environment); }
00354 
00359     static bool isNameRegistered(const QString& name);
00360 
00367     static Property lookupByName(const QString& name);
00373     static QList<QString> namesForProperty(Property property);
00374 
00379     static QString primaryNameForProperty(Property property);
00380 
00381 private:
00382     struct PropertyInfo;
00383     // Defines a new property, this property is then available
00384     // to all Profile instances.
00385     static void registerProperty(const PropertyInfo& info); 
00386 
00387     // fills the table with default names for profile properties
00388     // the first time it is called.
00389     // subsequent calls return immediately
00390     static void fillTableWithDefaultNames();
00391 
00392     // returns true if the property can be inherited
00393     static bool canInheritProperty(Property property);
00394 
00395     QHash<Property,QVariant> _propertyValues;
00396     Ptr _parent;
00397 
00398     bool _hidden;
00399 
00400     static QHash<QString,PropertyInfo> _propertyInfoByName;
00401     static QHash<Property,PropertyInfo> _infoByProperty;
00402     
00403     // Describes a property.  Each property has a name and group
00404     // which is used when saving/loading the profile.
00405     struct PropertyInfo
00406     {
00407         Property property;
00408         const char* name;
00409         const char* group;
00410         QVariant::Type type;
00411     };
00412     static const PropertyInfo DefaultPropertyNames[];
00413 };
00414 
00415 template <class T>
00416 inline T Profile::property(Property theProperty) const
00417 {
00418     return property<QVariant>(theProperty).value<T>();
00419 }
00420 template <>
00421 inline QVariant Profile::property(Property property) const
00422 {
00423     if ( _propertyValues.contains(property) ) {
00424         return _propertyValues[property];
00425     }
00426     else if ( _parent && canInheritProperty(property) ) {
00427         return _parent->property<QVariant>(property);
00428     }
00429     else {
00430         return QVariant();
00431     }
00432 }
00433 inline bool Profile::canInheritProperty(Property property) 
00434 { return property != Name && property != Path; }
00435 
00436 
00442 class FallbackProfile : public Profile
00443 {
00444 public:
00445     FallbackProfile();
00446 };
00447 
00461 class KDE_EXPORT ProfileGroup : public Profile
00462 {
00463 public:
00464     typedef KSharedPtr<ProfileGroup> Ptr;
00465 
00467     ProfileGroup(Profile::Ptr parent = Profile::Ptr());
00468 
00472     void addProfile(Profile::Ptr profile)
00473     { _profiles.append(profile); }
00474 
00477     void removeProfile(Profile::Ptr profile)
00478     { _profiles.removeAll(profile); }
00479 
00481     QList<Profile::Ptr> profiles() const
00482     { return _profiles; }
00483 
00495     void updateValues();
00496 
00498     void setProperty(Property property, const QVariant& value);
00499 
00500 private:
00501     QList<Profile::Ptr> _profiles;
00502 };
00503 inline ProfileGroup::ProfileGroup(Profile::Ptr parent)
00504 : Profile(parent)
00505 {
00506     setHidden(true);
00507 }
00508 inline const Profile::GroupPtr Profile::asGroup() const
00509 {
00510     const Profile::GroupPtr ptr(dynamic_cast<ProfileGroup*>(
00511                                 const_cast<Profile*>(this)));
00512     return ptr;
00513 }
00514 inline Profile::GroupPtr Profile::asGroup()
00515 {
00516     return Profile::GroupPtr(dynamic_cast<ProfileGroup*>(this));
00517 }
00518 
00520 class ProfileReader
00521 {
00522 public:
00523     virtual ~ProfileReader() {}
00525     virtual QStringList findProfiles() { return QStringList(); }
00536     virtual bool readProfile(const QString& path , Profile::Ptr profile , QString& parentProfile) = 0;
00537 };
00539 class KDE3ProfileReader : public ProfileReader
00540 {
00541 public:
00542     virtual QStringList findProfiles();
00543     virtual bool readProfile(const QString& path , Profile::Ptr profile, QString& parentProfile);
00544 };
00546 class KDE4ProfileReader : public ProfileReader
00547 {
00548 public:
00549     virtual QStringList findProfiles();
00550     virtual bool readProfile(const QString& path , Profile::Ptr profile, QString& parentProfile);
00551 private:
00552     void readProperties(const KConfig& config, Profile::Ptr profile, 
00553                         const Profile::PropertyInfo* properties);
00554 };
00556 class ProfileWriter
00557 {
00558 public:
00559     virtual ~ProfileWriter() {}
00565     virtual QString getPath(const Profile::Ptr profile) = 0;
00570     virtual bool writeProfile(const QString& path , const Profile::Ptr profile) = 0;
00571 };
00573 class KDE4ProfileWriter : public ProfileWriter
00574 {
00575 public:
00576     virtual QString getPath(const Profile::Ptr profile);
00577     virtual bool writeProfile(const QString& path , const Profile::Ptr profile);
00578 
00579 private:
00580     void writeProperties(KConfig& config, const Profile::Ptr profile, 
00581                          const Profile::PropertyInfo* properties);
00582 };
00583 
00601 class ProfileCommandParser
00602 {
00603 public:
00609     QHash<Profile::Property,QVariant> parse(const QString& input);
00610 
00611 };
00612 
00613 }
00614 Q_DECLARE_METATYPE(Konsole::Profile::Ptr)
00615 
00616 #endif // PROFILE_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.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