]> Some of my projects - localmylist.git/commitdiff
Add file_location_delete notification and handling.
authorAPTX <marek321@gmail.com>
Sun, 21 Apr 2013 15:48:29 +0000 (17:48 +0200)
committerAPTX <marek321@gmail.com>
Sun, 21 Apr 2013 15:48:29 +0000 (17:48 +0200)
This changes the schema slightly.

localmylist/database.cpp
localmylist/database.h
localmylist/mylistmodel.cpp
localmylist/mylistmodel.h
localmylist/share/schema/schema.sql

index 5fe69e8f92df91d72ae282c5787bbb020085aea3..b5399ce6eb0bad9ee455030827e22fd6243a3962 100644 (file)
@@ -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
 }
 
index 227fab5c6ccbb03d0b017cf6e86d4c5ffe5e6c3c..0d254686d38c4ebe4a1c9e8f1ee804bc49307ce2 100644 (file)
@@ -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
index a9c3c25a4ba9484a169b944faf920682f04ad712..777280a96107d198ad2cb0c78dcab7ee1beb0707 100644 (file)
@@ -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)
index efd2ad4fb5754820a682ca353d06fb568ee85db4..e44ee33a2b5af0f19445604f27d761bba74ec9b1 100644 (file)
@@ -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);
index 8888ffe6e5e4b659c7f26957cc26a0d5f925e89f..fc031c0a396a5135a3b5e39826e59168cbfa1823 100644 (file)
@@ -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);