File indexing completed on 2024-04-28 05:50:48

0001 /*
0002     This source file is part of Konsole, a terminal emulator.
0003 
0004     SPDX-FileCopyrightText: 2006-2008 Robert Knight <robertknight@gmail.com>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef SESSIONLISTMODEL_H
0010 #define SESSIONLISTMODEL_H
0011 
0012 // Qt
0013 #include <QAbstractListModel>
0014 #include <QVariant>
0015 
0016 namespace Konsole
0017 {
0018 class Session;
0019 
0020 /**
0021  * Item-view model which contains a flat list of sessions.
0022  * After constructing the model, call setSessions() to set the sessions displayed
0023  * in the list.  When a session ends (after emitting the finished() signal) it is
0024  * automatically removed from the list.
0025  *
0026  * The internal pointer for each item in the model (index.internalPointer()) is the
0027  * associated Session*
0028  */
0029 class SessionListModel : public QAbstractListModel
0030 {
0031     Q_OBJECT
0032 
0033 public:
0034     explicit SessionListModel(QObject *parent = nullptr);
0035 
0036     /**
0037      * Sets the list of sessions displayed in the model.
0038      * To display all sessions that are currently running in the list,
0039      * call setSessions(SessionManager::instance()->sessions())
0040      */
0041     void setSessions(const QList<Session *> &sessions);
0042 
0043     // reimplemented from QAbstractItemModel
0044     QModelIndex index(int row, int column, const QModelIndex &parent) const override;
0045     QVariant data(const QModelIndex &index, int role) const override;
0046     QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
0047     int columnCount(const QModelIndex &parent) const override;
0048     int rowCount(const QModelIndex &parent) const override;
0049     QModelIndex parent(const QModelIndex &index) const override;
0050 
0051 protected:
0052     virtual void sessionRemoved(Session *)
0053     {
0054     }
0055 
0056 private Q_SLOTS:
0057     void sessionFinished(Session *session);
0058 
0059 private:
0060     QList<Session *> _sessions;
0061 };
0062 }
0063 
0064 #endif // SESSIONLISTMODEL_H