populate post capture model when page is current and clear it when we leave
[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 clear();
62   void remove(const QUrl& file);
63
64 signals:
65   void imagePathChanged();
66   void videoPathChanged();
67
68 protected:
69   bool lessThan(const QModelIndex& left, const QModelIndex& right) const;
70
71 private:
72   QFileInfo info(const QString& path) const;
73
74   QString m_imagePath;
75   QString m_videoPath;
76
77   FileInfoModel *m_model;
78
79   QStringList loadDir(QDir& dir);
80
81   mutable QHash<QString, QFileInfo> m_data;
82
83 #if defined(QT5)
84   QHash<int, QByteArray> roleNames() const;
85   void setRoleNames(const QHash<int, QByteArray>& roles);
86   QHash<int, QByteArray> m_roles;
87 #endif
88 };
89
90 #endif /* POST_CAPTURE_MODEL_H */