Updated copyright year
[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 <QAbstractListModel>
27 #include <QDeclarativeParserStatus>
28 #include <QUrl>
29
30 class QSparqlConnection;
31 class PostCaptureModelItem;
32 class QDateTime;
33 class Quad;
34 class QSparqlQuery;
35 class QSparqlResultRow;
36
37 class PostCaptureModel : public QAbstractListModel, public QDeclarativeParserStatus {
38   Q_OBJECT
39   Q_INTERFACES(QDeclarativeParserStatus);
40
41   Q_PROPERTY(QString manufacturer READ manufacturer WRITE setManufacturer NOTIFY manufacturerChanged);
42   Q_PROPERTY(QString model READ model WRITE setModel NOTIFY modelChanged);
43
44   typedef enum {
45     Item = Qt::UserRole + 1
46   } Roles;
47
48 public:
49   PostCaptureModel(QObject *parent = 0);
50   ~PostCaptureModel();
51
52   virtual void classBegin();
53   virtual void componentComplete();
54
55   virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
56   virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
57
58   QString manufacturer() const;
59   void setManufacturer(const QString& manufacturer);
60
61   QString model() const;
62   void setModel(const QString& model);
63
64 signals:
65   void error(const QString& msg);
66
67   void manufacturerChanged();
68   void modelChanged();
69
70 public slots:
71   void reload();
72   void remove(QObject *item);
73
74 private slots:
75   void dataReady(int totalCount);
76   void graphUpdated(const QString& className, const QList<Quad>& deleted,
77                     const QList<Quad>& inserted);
78
79 private:
80   void addRow(PostCaptureModelItem *item);
81   void exec(QSparqlQuery& query);
82
83   QSparqlConnection *m_connection;
84   QString m_manufacturer;
85   QString m_model;
86
87   QList<PostCaptureModelItem *> m_items;
88   QHash<int, PostCaptureModelItem *> m_hash;
89 };
90
91 class PostCaptureModelItem : public QObject {
92   Q_OBJECT
93
94   Q_PROPERTY(QString type READ type NOTIFY typeChanged);
95   Q_PROPERTY(QUrl url READ url NOTIFY urlChanged);
96   Q_PROPERTY(QString created READ created NOTIFY createdChanged);
97   Q_PROPERTY(QString title READ title NOTIFY titleChanged);
98   Q_PROPERTY(QString fileName READ fileName NOTIFY fileNameChanged);
99   Q_PROPERTY(QString mimeType READ mimeType NOTIFY mimeTypeChanged);
100   Q_PROPERTY(bool available READ available NOTIFY availableChanged);
101   Q_PROPERTY(QString lastModified READ lastModified NOTIFY lastModifiedChanged);
102   Q_PROPERTY(unsigned trackerId READ trackerId CONSTANT);
103   Q_PROPERTY(bool favorite READ favorite WRITE setFavorite NOTIFY favoriteChanged);
104
105 public:
106   PostCaptureModelItem(const QSparqlResultRow& row, QObject *parent = 0);
107
108   ~PostCaptureModelItem() {
109
110   }
111
112   void update(PostCaptureModelItem *other);
113
114   QString type() const;
115   QUrl url() const;
116   QString created() const;
117   QString title() const;
118   QString fileName() const;
119   QString mimeType() const;
120   bool available() const;
121   QString lastModified() const;
122   unsigned trackerId() const;
123
124   void setFavorite(bool add);
125   bool favorite() const;
126
127 signals:
128   void typeChanged();
129   void urlChanged();
130   void createdChanged();
131   void titleChanged();
132   void fileNameChanged();
133   void mimeTypeChanged();
134   void availableChanged();
135   void lastModifiedChanged();
136   void favoriteChanged();
137
138 private:
139   QString formatDateTime(const QDateTime& dt) const;
140   QVariant value(const QString& id, const QVariant& def = QVariant()) const;
141
142   QVariantMap m_data;
143 };
144
145 #endif /* POST_CAPTURE_MODEL_H */