File indexing completed on 2024-04-21 16:32:05

0001 /* This file is part of Kairo Timer
0002 
0003    SPDX-FileCopyrightText: 2016 (c) Kevin Ottens <ervin@kde.org>
0004 
0005    SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006 
0007 */
0008 
0009 #ifndef CIRCUITLISTMODEL_H
0010 #define CIRCUITLISTMODEL_H
0011 
0012 #include <QAbstractListModel>
0013 #include <QDir>
0014 
0015 #include "circuitmodel.h"
0016 
0017 class QFileSystemWatcher;
0018 
0019 class CircuitListModel : public QAbstractListModel
0020 {
0021     Q_OBJECT
0022     Q_PROPERTY(QString path READ path CONSTANT)
0023 public:
0024     enum Role {
0025         FilePathRole = Qt::UserRole + 1
0026     };
0027     Q_ENUM(Role)
0028 
0029     explicit CircuitListModel(QObject *parent = nullptr);
0030 
0031     QHash<int, QByteArray> roleNames() const override;
0032     Q_INVOKABLE int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0033     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0034 
0035     Q_INVOKABLE CircuitModel loadCircuit(int index);
0036 
0037     QString path() const;
0038 
0039 private slots:
0040     void onDirectoryContentChanged();
0041 
0042 private:
0043     QDir storageDir();
0044 
0045     struct CircuitFile
0046     {
0047         QString filePath;
0048         QString name;
0049 
0050         bool operator<(const CircuitFile &other) const;
0051         bool operator==(const CircuitFile &other) const;
0052     };
0053 
0054     QFileSystemWatcher *m_watcher;
0055     QVector<CircuitFile> m_circuits;
0056 };
0057 
0058 #endif