Add missing capability.cpp
[harmattan/cameraplus] / src / postcapturemodel.cpp
index 658eed5..fc639c9 100644 (file)
@@ -1,7 +1,7 @@
 /*!
  * This file is part of CameraPlus.
  *
- * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
 #include <QSparqlQuery>
 #include <QSparqlResult>
 #include <QSparqlError>
+#if defined(QT4)
 #include <QDeclarativeInfo>
+#elif defined(QT5)
+#include <QQmlInfo>
+#endif
 #include <QDateTime>
 #include <QDBusConnection>
 #include <QStringList>
@@ -70,14 +74,16 @@ const QDBusArgument& operator>>(const QDBusArgument& argument, Quad& t) {
 
 PostCaptureModel::PostCaptureModel(QObject *parent) :
   QAbstractListModel(parent),
-  m_connection(0) {
+  m_connection(0),
+  m_connected(false) {
+
+  qDBusRegisterMetaType<Quad>();
+  qDBusRegisterMetaType<QList<Quad> >();
 
   QHash<int, QByteArray> roles;
   roles.insert(Item, "item");
-  setRoleNames(roles);
 
-  qDBusRegisterMetaType<Quad>();
-  qDBusRegisterMetaType<QList<Quad> >();
+  setRoleNames(roles);
 }
 
 PostCaptureModel::~PostCaptureModel() {
@@ -87,14 +93,6 @@ PostCaptureModel::~PostCaptureModel() {
   delete m_connection; m_connection = 0;
 }
 
-void PostCaptureModel::classBegin() {
-
-}
-
-void PostCaptureModel::componentComplete() {
-
-}
-
 void PostCaptureModel::reload() {
   delete m_connection; m_connection = 0;
 
@@ -117,12 +115,20 @@ void PostCaptureModel::reload() {
   q.bindValue("equipment", equipment);
   exec(q);
 
-  QDBusConnection::sessionBus().connect(TRACKER_SERVICE, TRACKER_RESOURCE_PATH,
-                                       TRACKER_RESOURCE_INTERFACE, TRACKER_RESOURCE_SIGNAL,
-                                       TRACKER_RESOURCE_SIGNAL_SIGNATURE,
-                                       this, SLOT(graphUpdated(const QString&,
-                                                               const QList<Quad>&,
-                                                               const QList<Quad>&)));
+  if (!m_connected) {
+    const char *slot = SLOT(graphUpdated(const QString&,
+                                        const QList<Quad>&,
+                                        const QList<Quad>&));
+    m_connected = QDBusConnection::sessionBus().connect(TRACKER_SERVICE, TRACKER_RESOURCE_PATH,
+                                                       TRACKER_RESOURCE_INTERFACE,
+                                                       TRACKER_RESOURCE_SIGNAL,
+                                                       TRACKER_RESOURCE_SIGNAL_SIGNATURE,
+                                                       this, slot);
+  }
+
+  if (!m_connected) {
+    qmlInfo(this) << "Failed to connect to tracker " << TRACKER_RESOURCE_SIGNAL;
+  }
 }
 
 void PostCaptureModel::exec(QSparqlQuery& query) {
@@ -274,6 +280,16 @@ void PostCaptureModel::graphUpdated(const QString& className, const QList<Quad>&
   }
 }
 
+#if defined(QT5)
+QHash<int, QByteArray> PostCaptureModel::roleNames() const {
+  return m_roles;
+}
+
+void PostCaptureModel::setRoleNames(const QHash<int, QByteArray>& roles) {
+  m_roles = roles;
+}
+#endif
+
 PostCaptureModelItem::PostCaptureModelItem(const QSparqlResultRow& row, QObject *parent) :
   QObject(parent) {