File indexing completed on 2024-05-05 08:48:48
0001 /* 0002 SPDX-FileCopyrightText: 2010-2012, 2020 Friedrich W. H. Kossebau <kossebau@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KDEVCLAZY_CHECKSETSELECTIONMANAGER_H 0008 #define KDEVCLAZY_CHECKSETSELECTIONMANAGER_H 0009 0010 // plugin 0011 #include "checksetselection.h" 0012 // Qt 0013 #include <QObject> 0014 #include <QVector> 0015 #include <QDateTime> 0016 #include <QHash> 0017 0018 class KDirWatch; 0019 0020 namespace Clazy { 0021 0022 class CheckSetSelectionLock; 0023 0024 class CheckSetSelectionFileInfo 0025 { 0026 public: 0027 CheckSetSelectionFileInfo(const QDateTime& lastModified, bool locked) 0028 : m_lastModified(lastModified) 0029 , m_locked(locked) 0030 {} 0031 0032 public: 0033 const QDateTime& lastModified() const { return m_lastModified; } 0034 bool isLocked() const { return m_locked; } 0035 0036 void setLastModified(const QDateTime& lastModified) { m_lastModified = lastModified; } 0037 void setLocked(bool isLocked) { m_locked = isLocked; } 0038 0039 private: 0040 QDateTime m_lastModified; 0041 bool m_locked; 0042 }; 0043 0044 0045 using CheckSetSelectionFileInfoLookup = QHash<QString, CheckSetSelectionFileInfo>; 0046 0047 class CheckSetSelectionManager : public QObject 0048 { 0049 Q_OBJECT 0050 0051 public: 0052 CheckSetSelectionManager(); 0053 ~CheckSetSelectionManager() override; 0054 0055 public: 0056 QVector<CheckSetSelection> checkSetSelections() const; 0057 int checkSetSelectionsCount() const; 0058 CheckSetSelection checkSetSelection(const QString& id) const; 0059 QString defaultCheckSetSelectionId() const; 0060 CheckSetSelection defaultCheckSetSelection() const; 0061 bool isCheckSetSelectionLocked(const QString& id) const; 0062 0063 public: 0064 void saveCheckSetSelections(QVector<CheckSetSelection>& checkSetSelections); 0065 void removeCheckSetSelections(const QVector<QString>& checkSetSelectionIds); 0066 void setDefaultCheckSetSelection(const QString& checkSetSelectionId); 0067 0068 CheckSetSelectionLock createLock(const QString& checkSetSelectionId); 0069 0070 Q_SIGNALS: 0071 void checkSetSelectionsChanged(const QVector<CheckSetSelection>& checkSetSelections); 0072 void checkSetSelectionsRemoved(const QVector<QString>& checkSetSelectionIds); 0073 void defaultCheckSetSelectionChanged(const QString& checkSetSelectionId); 0074 void checkSetSelectionsLocked(const QVector<QString>& checkSetSelectionIds); 0075 void checkSetSelectionsUnlocked(const QVector<QString>& checkSetSelectionIds); 0076 0077 private: 0078 QString filePathOfCheckSetSelection(const QString& checkSetSelectionId) const; 0079 // Returns the checkSetSelection as loaded from the file with the given fileName. 0080 // If the loading fails the checkSetSelection has no id set. 0081 CheckSetSelection loadCheckSetSelection(const QString& fileName) const; 0082 void saveCheckSetSelection(const CheckSetSelection& checkSetSelection) const; 0083 void removeCheckSetSelection(const QString& checkSetSelectionId); 0084 0085 private Q_SLOTS: 0086 void onCheckSetSelectionsFolderChanged(const QString& path); 0087 void onDefaultCheckSetSelectionChanged(const QString& path); 0088 0089 private: 0090 QVector<CheckSetSelection> m_checkSetSelections; 0091 0092 QString m_defaultCheckSetSelectionId; 0093 0094 KDirWatch* m_checkSetSelectionFileWatcher; 0095 0096 QHash<QString, CheckSetSelectionFileInfoLookup> m_checkSetSelectionFileInfoLookupPerFolder; 0097 }; 0098 0099 } 0100 0101 #endif