File indexing completed on 2024-04-28 05:50:49
0001 /* 0002 SPDX-FileCopyrightText: 2006-2008 Robert Knight <robertknight@gmail.com> 0003 SPDX-FileCopyrightText: 2009 Thomas Dreibholz <dreibh@iem.uni-due.de> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef SESSIONTASK_H 0009 #define SESSIONTASK_H 0010 0011 #include <QList> 0012 #include <QObject> 0013 #include <QPointer> 0014 0015 #include "Session.h" 0016 0017 namespace Konsole 0018 { 0019 /** 0020 * Abstract class representing a task which can be performed on a group of sessions. 0021 * 0022 * Create a new instance of the appropriate sub-class for the task you want to perform and 0023 * call the addSession() method to add each session which needs to be processed. 0024 * 0025 * Finally, call the execute() method to perform the sub-class specific action on each 0026 * of the sessions. 0027 */ 0028 class SessionTask : public QObject 0029 { 0030 Q_OBJECT 0031 0032 public: 0033 explicit SessionTask(QObject *parent = nullptr); 0034 0035 /** 0036 * Sets whether the task automatically deletes itself when the task has been finished. 0037 * Depending on whether the task operates synchronously or asynchronously, the deletion 0038 * may be scheduled immediately after execute() returns or it may happen some time later. 0039 */ 0040 void setAutoDelete(bool enable); 0041 /** Returns true if the task automatically deletes itself. See setAutoDelete() */ 0042 bool autoDelete() const; 0043 0044 /** Adds a new session to the group */ 0045 void addSession(Session *session); 0046 0047 /** 0048 * Executes the task on each of the sessions in the group. 0049 * The completed() signal is emitted when the task is finished, depending on the specific sub-class 0050 * execute() may be synchronous or asynchronous 0051 */ 0052 virtual void execute() = 0; 0053 0054 Q_SIGNALS: 0055 /** 0056 * Emitted when the task has completed. 0057 * Depending on the task this may occur just before execute() returns, or it 0058 * may occur later 0059 * 0060 * @param success Indicates whether the task completed successfully or not 0061 */ 0062 void completed(bool success); 0063 0064 protected: 0065 /** Returns a list of sessions in the group */ 0066 QList<QPointer<Session>> sessions() const; 0067 0068 private: 0069 bool _autoDelete = false; 0070 QList<QPointer<Session>> _sessions; 0071 }; 0072 0073 } 0074 #endif