}
}
+ function addOrRemoveFavorite() {
+ if (!available) {
+ return;
+ }
+
+ if (currentItem.itemData.favorite) {
+ if (!trackerStore.removeFromFavorites(currentItem.itemData.url)) {
+ showError(qsTr("Failed to remove favorite"));
+ }
+ else {
+ currentItem.itemData.favorite = false;
+ }
+ }
+ else {
+ if (!trackerStore.addToFavorites(currentItem.itemData.url)) {
+ showError(qsTr("Failed to add favorite"));
+ }
+ else {
+ currentItem.itemData.favorite = true;
+ }
+ }
+ }
+
ShareHelper {
id: share
}
tools: ToolBarLayout {
id: layout
ToolIcon { iconId: "icon-m-toolbar-back-white"; onClicked: { pageStack.pop(); } }
- ToolIcon { iconId: available ? "icon-m-toolbar-favorite-mark-white" : "icon-m-toolbar-favorite-mark-dimmed-white"}
+ ToolIcon { iconId: !available ? "icon-m-toolbar-favorite-mark-dimmed-white" : currentItem.itemData.favorite ? "icon-m-toolbar-favorite-mark-white" : "icon-m-toolbar-favorite-unmark-white"; onClicked: addOrRemoveFavorite(); }
ToolIcon { iconId: available ? "icon-m-toolbar-share-white" : "icon-m-toolbar-share-dimmed-white"; onClicked: shareCurrentItem(); }
ToolIcon { iconId: available ? "icon-m-toolbar-delete-white" : "icon-m-toolbar-delete-dimmed-white"; onClicked: deleteCurrentItem(); }
ToolIcon { iconId: "icon-m-toolbar-view-menu-white"; onClicked: menu.open(); }
// We will just assume tracker:available has changed and that's it.
// We are not really interested in the rest of properties.
- Q_UNUSED(deleted);
-
if (!(className == QLatin1String(PHOTO_CLASS) || className == QLatin1String(VIDEO_CLASS))) {
return;
}
QList<int> items;
+ for (int x = 0; x < deleted.size(); x++) {
+ Quad q = deleted[x];
+ if (m_hash.contains(q.subject) && items.indexOf(q.subject) == -1) {
+ items << q.subject;
+ }
+ }
+
for (int x = 0; x < inserted.size(); x++) {
Quad q = inserted[x];
if (m_hash.contains(q.subject) && items.indexOf(q.subject) == -1) {
}
bool PostCaptureModelItem::favorite() const {
- return value("favorite").toBool();
+ return value("favorite", false).toBool();
+}
+
+void PostCaptureModelItem::setFavorite(bool add) {
+ if (favorite() != add) {
+ m_data["favorite"] = add;
+
+ emit favoriteChanged();
+ }
}
QString PostCaptureModelItem::formatDateTime(const QDateTime& dt) const {
void PostCaptureModelItem::update(PostCaptureModelItem *other) {
// We will only update available, favorite and title:
+#if 0
+ qDebug() << "i" << trackerId() << other->trackerId() << "\n"
+ << "a" << available() << other->available() << "\n"
+ << "t" << title() << other->title() << "\n"
+ << "f" << favorite() << other->favorite();
+#endif
+
if (available() != other->available()) {
m_data["available"] = other->available();
emit availableChanged();
Q_PROPERTY(bool available READ available NOTIFY availableChanged);
Q_PROPERTY(QString lastModified READ lastModified NOTIFY lastModifiedChanged);
Q_PROPERTY(unsigned trackerId READ trackerId CONSTANT);
- Q_PROPERTY(bool favorite READ favorite NOTIFY favoriteChanged);
+ Q_PROPERTY(bool favorite READ favorite WRITE setFavorite NOTIFY favoriteChanged);
public:
PostCaptureModelItem(const QSparqlResultRow& row, QObject *parent = 0);
bool available() const;
QString lastModified() const;
unsigned trackerId() const;
+
+ void setFavorite(bool add);
bool favorite() const;
signals:
#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),
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()) {
#include <QObject>
class QSparqlConnection;
+class QUrl;
+class QSparqlQuery;
class TrackerStore : public QObject {
Q_OBJECT
QString model() const;
void setModel(const QString& model);
+ Q_INVOKABLE bool addToFavorites(const QUrl& url);
+ Q_INVOKABLE bool removeFromFavorites(const QUrl& url);
+
signals:
void activeChanged();
void manufacturerChanged();
private:
bool execQuery(const QString& query, const QString& path);
+ bool exec(QSparqlQuery& q);
QSparqlConnection *m_connection;
QString m_manufacturer;