411a9a96568057195e877a2bdb4260fc789ed9e3
[harmattan/cameraplus] / src / postcapturemodel.h
1 // -*- c++ -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #ifndef POST_CAPTURE_MODEL_H
24 #define POST_CAPTURE_MODEL_H
25
26 #include <QSortFilterProxyModel>
27 #include <QStringList>
28 #include <QFileInfo>
29
30 class FileInfoModel;
31 class QDir;
32
33 class PostCaptureModel : public QSortFilterProxyModel {
34   Q_OBJECT
35
36   Q_PROPERTY(QString imagePath READ imagePath WRITE setImagePath NOTIFY imagePathChanged);
37   Q_PROPERTY(QString videoPath READ videoPath WRITE setVideoPath NOTIFY videoPathChanged);
38
39   typedef enum {
40     UrlRole = Qt::UserRole + 1,
41     TitleRole = Qt::UserRole + 2,
42     MimeTypeRole = Qt::UserRole + 3,
43     CreatedRole = Qt::UserRole + 4,
44     FileNameRole = Qt::UserRole + 5,
45   } Roles;
46
47 public:
48   PostCaptureModel(QObject *parent = 0);
49   ~PostCaptureModel();
50
51   virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
52
53   QString imagePath() const;
54   void setImagePath(const QString& path);
55
56   QString videoPath() const;
57   void setVideoPath(const QString& path);
58
59 public slots:
60   void reload();
61   void remove(const QUrl& file);
62
63 signals:
64   void imagePathChanged();
65   void videoPathChanged();
66
67 protected:
68   bool lessThan(const QModelIndex& left, const QModelIndex& right) const;
69
70 private:
71   QFileInfo info(const QString& path) const;
72
73   QString m_imagePath;
74   QString m_videoPath;
75
76   FileInfoModel *m_model;
77
78   QStringList loadDir(QDir& dir);
79
80   mutable QHash<QString, QFileInfo> m_data;
81
82 #if defined(QT5)
83   QHash<int, QByteArray> roleNames() const;
84   void setRoleNames(const QHash<int, QByteArray>& roles);
85   QHash<int, QByteArray> m_roles;
86 #endif
87 };
88
89 #endif /* POST_CAPTURE_MODEL_H */