4 * This file is part of CameraPlus.
6 * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
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.
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.
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
23 #ifndef POST_CAPTURE_MODEL_H
24 #define POST_CAPTURE_MODEL_H
26 #include <QAbstractListModel>
29 class QSparqlConnection;
30 class PostCaptureModelItem;
34 class QSparqlResultRow;
36 class PostCaptureModel : public QAbstractListModel {
39 Q_PROPERTY(QString manufacturer READ manufacturer WRITE setManufacturer NOTIFY manufacturerChanged);
40 Q_PROPERTY(QString model READ model WRITE setModel NOTIFY modelChanged);
43 Item = Qt::UserRole + 1
47 PostCaptureModel(QObject *parent = 0);
50 virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
51 virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
53 QString manufacturer() const;
54 void setManufacturer(const QString& manufacturer);
56 QString model() const;
57 void setModel(const QString& model);
60 void error(const QString& msg);
62 void manufacturerChanged();
67 void remove(QObject *item);
70 void dataReady(int totalCount);
71 void graphUpdated(const QString& className, const QList<Quad>& deleted,
72 const QList<Quad>& inserted);
75 void addRow(PostCaptureModelItem *item);
76 void exec(QSparqlQuery& query);
78 QSparqlConnection *m_connection;
79 QString m_manufacturer;
82 QList<PostCaptureModelItem *> m_items;
83 QHash<int, PostCaptureModelItem *> m_hash;
88 QHash<int, QByteArray> roleNames() const;
89 void setRoleNames(const QHash<int, QByteArray>& roles);
90 QHash<int, QByteArray> m_roles;
94 class PostCaptureModelItem : public QObject {
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);
109 PostCaptureModelItem(const QSparqlResultRow& row, QObject *parent = 0);
111 ~PostCaptureModelItem() {
115 void update(PostCaptureModelItem *other);
117 QString type() 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;
127 void setFavorite(bool add);
128 bool favorite() const;
133 void createdChanged();
135 void fileNameChanged();
136 void mimeTypeChanged();
137 void availableChanged();
138 void lastModifiedChanged();
139 void favoriteChanged();
142 QString formatDateTime(const QDateTime& dt) const;
143 QVariant value(const QString& id, const QVariant& def = QVariant()) const;
148 #endif /* POST_CAPTURE_MODEL_H */