File indexing completed on 2024-05-12 05:52:09

0001 /*
0002  *  SPDX-FileCopyrightText: 2022 Eugene Popov <popov895@ukr.net>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #pragma once
0008 
0009 #include "katesessionmanager.h"
0010 
0011 #include <QAbstractListModel>
0012 #include <QDateTime>
0013 
0014 class SavedSessionsModel : public QAbstractListModel
0015 {
0016     Q_OBJECT
0017 
0018 public:
0019     explicit SavedSessionsModel(QObject *parent = nullptr);
0020 
0021     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0022     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0023 
0024     void refresh(const KateSessionList &sessionList);
0025 
0026 private:
0027     struct SessionInfo {
0028         QDateTime lastOpened;
0029         QString name;
0030 
0031         bool operator<(const SessionInfo &other) const
0032         {
0033             return lastOpened > other.lastOpened;
0034         }
0035     };
0036 
0037     std::vector<SessionInfo> m_sessions;
0038 };