• Skip to content
  • Skip to link menu
KDE 4.2 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     // session management
00247     void saveSessions(KConfig* config);
00248     int  getRestoreId(Session* session);
00249     void restoreSessions(KConfig* config);
00250     Session *idToSession(int id);
00251 
00252 signals:
00254     void profileAdded(Profile::Ptr ptr);
00256     void profileRemoved(Profile::Ptr ptr);
00258     void profileChanged(Profile::Ptr ptr);
00259 
00264     void sessionUpdated(Session* session);
00265 
00272     void favoriteStatusChanged(Profile::Ptr profile , bool favorite);
00273 
00280     void shortcutChanged(Profile::Ptr profile , const QKeySequence& newShortcut);
00281 
00282 protected Q_SLOTS:
00283 
00289     void sessionTerminated( QObject* session );
00290 
00291 private slots:
00292     void sessionProfileCommandReceived(const QString& text);
00293 
00294 private:
00295     
00296     
00297     // loads the mappings between shortcut key sequences and 
00298     // profile paths
00299     void loadShortcuts();
00300     // saves the mappings between shortcut key sequences and
00301     // profile paths
00302     void saveShortcuts();
00303 
00304     //loads the set of favorite sessions
00305     void loadFavorites();
00306     //saves the set of favorite sessions
00307     void saveFavorites();
00308     // saves a profile to a file
00309     // returns the path to which the profile was saved, which will
00310     // be the same as the path property of profile if valid or a newly generated path
00311     // otherwise
00312     QString saveProfile(Profile::Ptr profile);
00313 
00314     // applies updates to a profile
00315     // to all sessions currently using that profile
00316     // if modifiedPropertiesOnly is true, only properties which
00317     // are set in the profile @p key are updated
00318     void applyProfile(Profile::Ptr ptr , bool modifiedPropertiesOnly);
00319     // apples updates to the profile @p info to the session @p session
00320     // if modifiedPropertiesOnly is true, only properties which
00321     // are set in @p info are update ( ie. properties for which info->isPropertySet(<property>) 
00322     // returns true )
00323     void applyProfile(Session* session , const Profile::Ptr info , bool modifiedPropertiesOnly); 
00324 
00325     QSet<Profile::Ptr> _types;
00326     QHash<Session*,Profile::Ptr> _sessionProfiles;
00327     QHash<Session*,int> _restoreMapping;
00328 
00329     struct ShortcutData
00330     {
00331         Profile::Ptr profileKey;
00332         QString profilePath;
00333     };
00334     QMap<QKeySequence,ShortcutData> _shortcuts; // shortcut keys -> profile path
00335 
00336     QList<Session*> _sessions; // list of running sessions
00337 
00338     Profile::Ptr _defaultProfile; 
00339     Profile::Ptr _fallbackProfile;
00340 
00341     QSet<Profile::Ptr> _favorites; // list of favorite profiles
00342 
00343     bool _loadedAllProfiles; // set to true after loadAllProfiles has been called
00344     bool _loadedFavorites; // set to true after loadFavorites has been called
00345     QSignalMapper* _sessionMapper;
00346 };
00347 
00349 class ShouldApplyProperty 
00350 {
00351 public:
00352     ShouldApplyProperty(const Profile::Ptr profile , bool modifiedOnly) : 
00353     _profile(profile) , _modifiedPropertiesOnly(modifiedOnly) {}
00354 
00355     bool shouldApply(Profile::Property property) const
00356     {
00357         return !_modifiedPropertiesOnly || _profile->isPropertySet(property); 
00358     }
00359 private:
00360     const Profile::Ptr _profile;
00361     bool _modifiedPropertiesOnly;
00362 };
00363 
00371 template <class T>
00372 class PopStackOnExit
00373 {
00374 public:
00375     PopStackOnExit(QStack<T>& stack) : _stack(stack) , _count(stack.count()) {} 
00376     ~PopStackOnExit() 
00377     { 
00378         while (_stack.count() > _count) 
00379             _stack.pop(); 
00380     }
00381 private:
00382     QStack<T>& _stack;
00383     int _count;
00384 };
00394 class SessionListModel : public QAbstractListModel
00395 {
00396 Q_OBJECT
00397 
00398 public:
00399     SessionListModel(QObject* parent = 0);
00400 
00406     void setSessions(const QList<Session*>& sessions);
00407 
00408     // reimplemented from QAbstractItemModel
00409     virtual QModelIndex index(int row, int column, const QModelIndex& parent) const;
00410     virtual QVariant data(const QModelIndex& index, int role) const;
00411     virtual QVariant headerData(int section, Qt::Orientation orientation, 
00412                         int role) const;
00413     virtual int columnCount(const QModelIndex& parent) const;
00414     virtual int rowCount(const QModelIndex& parent) const;
00415     virtual QModelIndex parent(const QModelIndex& index) const;
00416 
00417 protected:
00418     virtual void sessionRemoved(Session*) {}
00419 
00420 private slots:
00421     void sessionFinished();
00422 
00423 private:
00424     QList<Session*> _sessions;    
00425 };
00426 
00427 }
00428 #endif //SESSIONMANAGER_H
00429 
00430 /*
00431   Local Variables:
00432   mode: c++
00433   c-file-style: "stroustrup"
00434   indent-tabs-mode: nil
00435   tab-width: 4
00436   End:
00437 */

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