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