File indexing completed on 2024-04-28 05:50:48
0001 /* 0002 SPDX-FileCopyrightText: 2007-2008 Robert Knight <robertknight@gmail.com> 0003 SPDX-FileCopyrightText: 1997, 1998 Lars Doelle <lars.doelle@on-line.de> 0004 SPDX-FileCopyrightText: 2009 Thomas Dreibholz <dreibh@iem.uni-due.de> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef SESSIONGROUP_H 0010 #define SESSIONGROUP_H 0011 0012 // Qt 0013 #include <QHash> 0014 #include <QList> 0015 #include <QObject> 0016 0017 namespace Konsole 0018 { 0019 class Session; 0020 0021 /** 0022 * Provides a group of sessions which is divided into master and slave sessions. 0023 * Activity in master sessions can be propagated to all sessions within the group. 0024 * The type of activity which is propagated and method of propagation is controlled 0025 * by the masterMode() flags. 0026 */ 0027 class SessionGroup : public QObject 0028 { 0029 Q_OBJECT 0030 0031 public: 0032 /** Constructs an empty session group. */ 0033 explicit SessionGroup(QObject *parent); 0034 /** Destroys the session group and removes all connections between master and slave sessions. */ 0035 ~SessionGroup() override; 0036 0037 /** Adds a session to the group. */ 0038 void addSession(Session *session); 0039 /** Removes a session from the group. */ 0040 void removeSession(Session *session); 0041 0042 /** Returns the list of sessions currently in the group. */ 0043 QList<Session *> sessions() const; 0044 0045 /** 0046 * Sets whether a particular session is a master within the group. 0047 * Changes or activity in the group's master sessions may be propagated 0048 * to all the sessions in the group, depending on the current masterMode() 0049 * 0050 * @param session The session whose master status should be changed. 0051 * @param master True to make this session a master or false otherwise 0052 */ 0053 void setMasterStatus(Session *session, bool master); 0054 0055 /** 0056 * This enum describes the options for propagating certain activity or 0057 * changes in the group's master sessions to all sessions in the group. 0058 */ 0059 enum MasterMode { 0060 /** 0061 * Any input key presses in the master sessions are sent to all 0062 * sessions in the group. 0063 */ 0064 CopyInputToAll = 1, 0065 }; 0066 0067 /** 0068 * Specifies which activity in the group's master sessions is propagated 0069 * to all sessions in the group. 0070 * 0071 * @param mode A bitwise OR of MasterMode flags. 0072 */ 0073 void setMasterMode(int mode); 0074 0075 private Q_SLOTS: 0076 void sessionFinished(Session *session); 0077 void forwardData(const QByteArray &data); 0078 0079 private: 0080 // maps sessions to their master status 0081 QHash<Session *, bool> _sessions; 0082 0083 int _masterMode = 0; 0084 }; 0085 } // namespace Konsole 0086 0087 #endif // SESSIONGROUP_H