File indexing completed on 2024-05-12 15:59:13

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2012 KO GmbH. Contact : Boudewijn Rempt <boud@kogmbh.com>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 #ifndef KRITA_SKETCH_DOCUMENTLISTMODEL_H
0007 #define KRITA_SKETCH_DOCUMENTLISTMODEL_H
0008 
0009 #include <QAbstractListModel>
0010 #include <QDateTime>
0011 #include <QColor>
0012 #include <QUrl>
0013 #include <QFont>
0014 
0015 #include "krita_sketch_export.h"
0016 
0017 class KRITA_SKETCH_EXPORT DocumentListModel : public QAbstractListModel
0018 {
0019     Q_OBJECT
0020     Q_ENUMS(DocumentType)
0021     Q_PROPERTY(DocumentType filter READ filter WRITE setFilter)
0022 
0023 public:
0024     DocumentListModel(QObject *parent = nullptr);
0025     ~DocumentListModel() override;
0026 
0027     QHash<int, QByteArray> roleNames() const override;
0028 
0029     enum CustomRoles {
0030         FileNameRole = Qt::UserRole + 1,
0031         FilePathRole,
0032         DocTypeRole,
0033         FileSizeRole,
0034         AuthorNameRole,
0035         AccessedTimeRole,
0036         ModifiedTimeRole,
0037         UUIDRole,
0038     };
0039 
0040     enum DocumentType {
0041         UnknownType,
0042         TextDocumentType,
0043         PresentationType,
0044         SpreadsheetType,
0045         PDFDocumentType,
0046     };
0047 
0048     struct DocumentInfo {
0049         bool operator==(const DocumentInfo &other) const {
0050             return filePath == other.filePath;
0051         }
0052         QString filePath;
0053         QString fileName;
0054         DocumentType docType;
0055         QString fileSize;
0056         QString authorName;
0057         QDateTime accessedTime;
0058         QDateTime modifiedTime;
0059         QString uuid;
0060     };
0061 
0062     // reimp from QAbstractListModel
0063     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0064     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0065     QVariant data(const QModelIndex &index,
0066                   int role = Qt::DisplayRole) const override;
0067     QVariant headerData(int section,
0068                         Qt::Orientation orientation,
0069                         int role = Qt::DisplayRole) const override;
0070 
0071     DocumentType filter();
0072 
0073     static QString prettyTime(const QDateTime &theTime);
0074     static DocumentType typeForFile(const QString &file);
0075 
0076 public Q_SLOTS:
0077     void addDocument(const DocumentListModel::DocumentInfo &info);
0078     void setFilter(DocumentType newFilter);
0079 
0080 private:
0081 
0082     class Private;
0083     const QScopedPointer<Private> d;
0084 
0085     static QHash<QString, DocumentType> sm_extensions;
0086 };
0087 
0088 Q_DECLARE_METATYPE(DocumentListModel::DocumentInfo);
0089 
0090 #endif // KRITA_SKETCH_DOCUMENTLISTMODEL_H
0091