Corrected video recording resolution for front camera
[harmattan/cameraplus] / src / trackerstore.cpp
index db3d8b8..a0f73e2 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 <QSparqlConnection>
 #include <QSparqlQuery>
 #include <QUrl>
+#if defined(QT4)
 #include <QDeclarativeInfo>
+#elif defined(QT5)
+#include <QQmlInfo>
+#endif
 #include <QSparqlResult>
 #include <QScopedPointer>
 #include <QSparqlError>
@@ -36,7 +40,8 @@
 #define IMAGE_QUERY BEGIN_IMAGE QUERY_END
 #define VIDEO_QUERY BEGIN_VIDEO QUERY_END
 
-// TODO: mime type
+#define ADD_FAVORITE_QUERY "INSERT { ?u nao:hasTag nao:predefined-tag-favorite . } WHERE {?u nie:url <file://%1> . }"
+#define REMOVE_FAVORITE_QUERY "DELETE { ?u nao:hasTag nao:predefined-tag-favorite . } WHERE {?u nie:url <file://%1> . }"
 
 TrackerStore::TrackerStore(QObject *parent) :
   QObject(parent),
@@ -57,7 +62,13 @@ void TrackerStore::setActive(bool active) {
     return;
   }
 
-  m_connection = new QSparqlConnection("QTRACKER_DIRECT", QSparqlConnectionOptions(), this);
+  if (active) {
+    m_connection = new QSparqlConnection("QTRACKER_DIRECT", QSparqlConnectionOptions(), this);
+  }
+  else {
+    m_connection->deleteLater();
+    m_connection = 0;
+  }
 
   emit activeChanged();
 }
@@ -108,6 +119,26 @@ bool TrackerStore::execQuery(const QString& query, const QString& path) {
   q.bindValue("contentCreated", dateTime.toString(Qt::ISODate) +
                  "." + QString().sprintf("%.3d", dateTime.time().msec()));
 
+  return exec(q);
+}
+
+bool TrackerStore::addToFavorites(const QUrl& url) {
+  QString query = QString(ADD_FAVORITE_QUERY).arg(url.toLocalFile());
+
+  QSparqlQuery q(query, QSparqlQuery::InsertStatement);
+
+  return exec(q);
+}
+
+bool TrackerStore::removeFromFavorites(const QUrl& url) {
+  QString query = QString(REMOVE_FAVORITE_QUERY).arg(url.toLocalFile());
+
+  QSparqlQuery q(query, QSparqlQuery::DeleteStatement);
+
+  return exec(q);
+}
+
+bool TrackerStore::exec(QSparqlQuery& q) {
   QScopedPointer<QSparqlResult> r(m_connection->syncExec(q));
 
   if (!r->hasError()) {