From: APTX Date: Sun, 21 Apr 2013 15:48:29 +0000 (+0200) Subject: Add file_location_delete notification and handling. X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;h=0862ae530f1215b5ee822ffcea27ca87312ff531;p=localmylist.git Add file_location_delete notification and handling. This changes the schema slightly. --- diff --git a/localmylist/database.cpp b/localmylist/database.cpp index 5fe69e8..b5399ce 100644 --- a/localmylist/database.cpp +++ b/localmylist/database.cpp @@ -1604,6 +1604,7 @@ void Database::subscribeToNotifications() d->db.driver()->subscribeToNotification("episode_insert"); d->db.driver()->subscribeToNotification("file_insert"); d->db.driver()->subscribeToNotification("file_location_insert"); + d->db.driver()->subscribeToNotification("file_location_delete"); } OpenFileData Database::readOpenFileData(QSqlQuery &q) @@ -1973,6 +1974,20 @@ void Database::handleNotification(const QString &name) if (locationId) emit fileLocationInsert(locationId, fid); } + else if (name == "file_location_delete") + { + QStringList ids = payload.toString().split(QChar(','), QString::SkipEmptyParts); + int locationId = 0; + int fid = 0; + + if (ids.count()) + locationId = ids.takeFirst().toInt(); + if (ids.count()) + fid = ids.takeFirst().toInt(); + + if (locationId) + emit fileLocationDelete(locationId, fid); + } #endif } diff --git a/localmylist/database.h b/localmylist/database.h index 227fab5..0d25468 100644 --- a/localmylist/database.h +++ b/localmylist/database.h @@ -172,6 +172,8 @@ signals: void fileInsert(int fid, int eid, int aid); void fileLocationInsert(int locationId, int fid); + void fileLocationDelete(int locationId, int fid); + private slots: // moc doesn't expand macros // QT_VERSION_CHECK(5, 0, 0) == 0x050000 diff --git a/localmylist/mylistmodel.cpp b/localmylist/mylistmodel.cpp index a9c3c25..777280a 100644 --- a/localmylist/mylistmodel.cpp +++ b/localmylist/mylistmodel.cpp @@ -23,6 +23,8 @@ MyListModel::MyListModel(QObject *parent) : connect(MyList::instance()->database(), SIGNAL(episodeInsert(int,int)), this, SLOT(episodeInsert(int,int))); connect(MyList::instance()->database(), SIGNAL(fileInsert(int,int,int)), this, SLOT(fileInsert(int,int,int))); connect(MyList::instance()->database(), SIGNAL(fileLocationInsert(int,int)), this, SLOT(fileLocationInsert(int,int))); + + connect(MyList::instance()->database(), SIGNAL(fileLocationDelete(int,int)), this, SLOT(fileLocationDelete(int,int))); } MyListModel::~MyListModel() @@ -168,15 +170,7 @@ QModelIndex MyListModel::fileLocationIndex(int id) const void MyListModel::removeFileLocation(int id) { - auto it = fileLocationSet.find(id); - - if (it != fileLocationSet.end()) - { - MyListFileLocationNode *node = it->node; - MyListNode *parent = node->parent(); - - parent->childRemoved(node); - } + fileLocationDelete(id, 0); MyList::instance()->database()->removeFileLocation(id); } @@ -427,6 +421,21 @@ void MyListModel::fileLocationInsert(int locationId, int fid) parentNode->childAdded(locationId); } +void MyListModel::fileLocationDelete(int locationId, int fid) +{ + Q_UNUSED(fid); + + auto it = fileLocationSet.find(locationId); + + if (it == fileLocationSet.end()) + return; + + MyListFileLocationNode *node = it->node; + MyListNode *parent = node->parent(); + + parent->childRemoved(node); +} + QModelIndex MyListModel::index(MyListNode *node) const { if (!node || node == rootItem) diff --git a/localmylist/mylistmodel.h b/localmylist/mylistmodel.h index efd2ad4..e44ee33 100644 --- a/localmylist/mylistmodel.h +++ b/localmylist/mylistmodel.h @@ -87,6 +87,8 @@ private slots: void fileInsert(int fid, int eid, int aid); void fileLocationInsert(int locationId, int fid); + void fileLocationDelete(int locationId, int fid); + protected: QModelIndex index(MyListNode *node) const; void fetchFinished(MyListNode *node, int newrows); diff --git a/localmylist/share/schema/schema.sql b/localmylist/share/schema/schema.sql index 8888ffe..fc031c0 100644 --- a/localmylist/share/schema/schema.sql +++ b/localmylist/share/schema/schema.sql @@ -341,3 +341,6 @@ CREATE OR REPLACE RULE file_update_notify_rule AS CREATE OR REPLACE RULE file_location_update_notify_rule AS ON UPDATE TO file_location DO SELECT pg_notify('file_location_update', new.location_id::text || ',' || new.fid::text); + +CREATE OR REPLACE RULE file_location_delete_notify_rule AS + ON DELETE TO file_location DO SELECT pg_notify('file_location_delete', old.location_id::text || ',' || old.fid::text);