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

Konsole

SessionManager.h

Go to the documentation of this file.
00001 /*
00002     This source file is part of Konsole, a terminal emulator.
00003 
00004     Copyright 2006-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 SESSIONMANAGER_H
00023 #define SESSIONMANAGER_H
00024 
00025 // Qt
00026 #include <QtGui/QFont>
00027 #include <QtGui/QKeySequence>
00028 
00029 #include <QtCore/QAbstractListModel>
00030 #include <QtCore/QHash>
00031 #include <QtCore/QList>
00032 #include <QtCore/QSet>
00033 #include <QtCore/QStringList>
00034 #include <QtCore/QPair>
00035 #include <QtCore/QPointer>
00036 #include <QtCore/QVariant>
00037 #include <QtCore/QStack>
00038 
00039 // Konsole
00040 #include "Profile.h"
00041 
00042 class QSignalMapper;
00043 
00044 
00045 namespace Konsole
00046 {
00047 
00048 class Session;
00049 
00059 class KDE_EXPORT SessionManager : public QObject
00060 {
00061 Q_OBJECT
00062 
00063 public:
00068     SessionManager();
00069     
00074     virtual ~SessionManager();
00075 
00077     void closeAll();
00078 
00080     void saveState();
00081 
00092     QList<Profile::Ptr> loadedProfiles() const;
00093 
00098     QStringList availableProfilePaths() const;
00099 
00100     
00114     Profile::Ptr loadProfile(const QString& path);
00115 
00129     void changeProfile(Profile::Ptr profile , QHash<Profile::Property,QVariant> propertyMap, 
00130             bool persistant = true);
00131 
00136     Profile::Ptr defaultProfile() const;
00142     Profile::Ptr fallbackProfile() const;
00143 
00155     Session* createSession(Profile::Ptr profile = Profile::Ptr());
00156 
00158     Profile::Ptr sessionProfile(Session* session) const;
00160     void setSessionProfile(Session* session, Profile::Ptr profile);
00161 
00165     void updateSession(Session* session);
00166 
00170     const QList<Session*> sessions();
00171 
00180     bool deleteProfile(Profile::Ptr profile);
00181 
00186     void setDefaultProfile(Profile::Ptr profile);
00187 
00191     QSet<Profile::Ptr> findFavorites();
00192 
00202     QList<QKeySequence> shortcuts();
00203 
00208     Profile::Ptr findByShortcut(const QKeySequence& shortcut);
00209 
00213     void setShortcut(Profile::Ptr profile , const QKeySequence& shortcut);
00214 
00216     QKeySequence shortcut(Profile::Ptr profile) const;
00217 
00222     void addProfile(Profile::Ptr type);
00223 
00228     void setFavorite(Profile::Ptr profile , bool favorite);
00229 
00235     void loadAllProfiles();
00236 
00240     static void setInstance(SessionManager* instance);
00244     static SessionManager* instance();
00245 
00246 signals:
00248     void profileAdded(Profile::Ptr ptr);
00250     void profileRemoved(Profile::Ptr ptr);
00252     void profileChanged(Profile::Ptr ptr);
00253 
00258     void sessionUpdated(Session* session);
00259 
00266     void favoriteStatusChanged(Profile::Ptr profile , bool favorite);
00267 
00274     void shortcutChanged(Profile::Ptr profile , const QKeySequence& newShortcut);
00275 
00276 protected Q_SLOTS:
00277 
00283     void sessionTerminated( QObject* session );
00284 
00285 private slots:
00286     void sessionProfileCommandReceived(const QString& text);
00287 
00288 private:
00289     
00290     
00291     // loads the mappings between shortcut key sequences and 
00292     // profile paths
00293     void loadShortcuts();
00294     // saves the mappings between shortcut key sequences and
00295     // profile paths
00296     void saveShortcuts();
00297 
00298     //loads the set of favorite sessions
00299     void loadFavorites();
00300     //saves the set of favorite sessions
00301     void saveFavorites();
00302     // saves a profile to a file
00303     // returns the path to which the profile was saved, which will
00304     // be the same as the path property of profile if valid or a newly generated path
00305     // otherwise
00306     QString saveProfile(Profile::Ptr profile);
00307 
00308     // applies updates to a profile
00309     // to all sessions currently using that profile
00310     // if modifiedPropertiesOnly is true, only properties which
00311     // are set in the profile @p key are updated
00312     void applyProfile(Profile::Ptr ptr , bool modifiedPropertiesOnly);
00313     // apples updates to the profile @p info to the session @p session
00314     // if modifiedPropertiesOnly is true, only properties which
00315     // are set in @p info are update ( ie. properties for which info->isPropertySet(<property>) 
00316     // returns true )
00317     void applyProfile(Session* session , const Profile::Ptr info , bool modifiedPropertiesOnly); 
00318 
00319     QSet<Profile::Ptr> _types;
00320     QHash<Session*,Profile::Ptr> _sessionProfiles;
00321 
00322     struct ShortcutData
00323     {
00324         Profile::Ptr profileKey;
00325         QString profilePath;
00326     };
00327     QMap<QKeySequence,ShortcutData> _shortcuts; // shortcut keys -> profile path
00328 
00329     QList<Session*> _sessions; // list of running sessions
00330 
00331     Profile::Ptr _defaultProfile; 
00332     Profile::Ptr _fallbackProfile;
00333 
00334     QSet<Profile::Ptr> _favorites; // list of favorite profiles
00335 
00336     bool _loadedAllProfiles; // set to true after loadAllProfiles has been called
00337     bool _loadedFavorites; // set to true after loadFavorites has been called
00338     QSignalMapper* _sessionMapper;
00339 };
00340 
00341 class ShouldApplyProperty 
00342 {
00343 public:
00344     ShouldApplyProperty(const Profile::Ptr profile , bool modifiedOnly) : 
00345     _profile(profile) , _modifiedPropertiesOnly(modifiedOnly) {}
00346 
00347     bool shouldApply(Profile::Property property) const
00348     {
00349         return !_modifiedPropertiesOnly || _profile->isPropertySet(property); 
00350     }
00351 private:
00352     const Profile::Ptr _profile;
00353     bool _modifiedPropertiesOnly;
00354 };
00355 
00363 template <class T>
00364 class PopStackOnExit
00365 {
00366 public:
00367     PopStackOnExit(QStack<T>& stack) : _stack(stack) , _count(stack.count()) {} 
00368     ~PopStackOnExit() 
00369     { 
00370         while (_stack.count() > _count) 
00371             _stack.pop(); 
00372     }
00373 private:
00374     QStack<T>& _stack;
00375     int _count;
00376 };
00377 
00378 class SessionListModel : public QAbstractListModel
00379 {
00380 Q_OBJECT
00381 
00382 public:
00383     SessionListModel(QObject* parent = 0);
00384 
00385     void setSessions(const QList<Session*>& sessions);
00386 
00387     virtual QModelIndex index(int row, int column, const QModelIndex& parent) const;
00388     virtual QVariant data(const QModelIndex& index, int role) const;
00389     virtual QVariant headerData(int section, Qt::Orientation orientation, 
00390                         int role) const;
00391     virtual int columnCount(const QModelIndex& parent) const;
00392     virtual int rowCount(const QModelIndex& parent) const;
00393     virtual QModelIndex parent(const QModelIndex& index) const;
00394 
00395 protected:
00396     virtual void sessionRemoved(Session*) {}
00397 
00398 private slots:
00399     void sessionFinished();
00400 
00401 private:
00402     QList<Session*> _sessions;  
00403 };
00404 
00405 }
00406 #endif //SESSIONMANAGER_H
00407 

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