]> Some of my projects - localmylist.git/commitdiff
Actually implement handling file_location inserts by the model
authorAPTX <marek321@gmail.com>
Thu, 4 Apr 2013 12:02:32 +0000 (14:02 +0200)
committerAPTX <marek321@gmail.com>
Thu, 4 Apr 2013 12:02:32 +0000 (14:02 +0200)
localmylist/database.cpp
localmylist/database.h
localmylist/mylistmodel.cpp
localmylist/share/schema/schema.sql

index c03f5599609517436da6520f1b3c2e08732712e4..676d61f223b6f2074e5ad0ec88471fa5ef570087 100644 (file)
@@ -1857,9 +1857,17 @@ void Database::handleNotification(const QString &name)
        }
        else if (name == "file_location_insert")
        {
-               int id = payload.toInt();
-               if (id)
-                       emit fileLocationInsert(id);
+               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 fileLocationInsert(locationId, fid);
        }
 #endif
 }
index f048141513d325f2f2dd81480129422ed64a668c..bcc14c0370863c51e50294cad477e8d7a9d7ec45 100644 (file)
@@ -163,7 +163,7 @@ signals:
        void animeInsert(int aid);
        void episodeInsert(int eid, int aid);
        void fileInsert(int fid, int eid, int aid);
-       void fileLocationInsert(int id);
+       void fileLocationInsert(int locationId, int fid);
 
 private slots:
 // moc doesn't expand macros
index f727c9b221c4c60257ec02de8a138004e648d408..ce7bf000fec6dc4ea335c81a51be49a2e01bcf8a 100644 (file)
@@ -22,7 +22,7 @@ MyListModel::MyListModel(QObject *parent) :
        connect(MyList::instance()->database(), SIGNAL(animeInsert(int)), this, SLOT(animeInsert(int)));
        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)), this, SLOT(fileLocationInsert(int)));
+       connect(MyList::instance()->database(), SIGNAL(fileLocationInsert(int,int)), this, SLOT(fileLocationInsert(int,int)));
 }
 
 MyListModel::~MyListModel()
@@ -389,12 +389,17 @@ void MyListModel::fileInsert(int fid, int eid, int aid)
        parentNode->childAdded(eid);
 }
 
-void MyListModel::fileLocationInsert(int id)
+void MyListModel::fileLocationInsert(int locationId, int fid)
 {
-       if (fileLocationIndex(id).isValid())
+       if (fileLocationIndex(locationId).isValid())
                return;
 
+       MyListNode *parentNode = node(fileIndex(fid));
 
+       if (!parentNode)
+               return;
+
+       parentNode->childAdded(locationId);
 }
 
 QModelIndex MyListModel::index(MyListNode *node) const
@@ -418,7 +423,7 @@ void MyListModel::fetchFinished(MyListNode *node, int newrows)
 
        // Delay fetching of more rows untill they are really needed.
        // Only for the root node
-       // Lazy loading didn't work before for children, not sure why
+       // Lazy loading didn't work for children, even before the async change, not sure why
        // TODO figure out if it can be fixed
        // Enableing this for non-root makes it never fetch more.
        if (node == rootItem)
index f95f8a144d9db39d7df592886c123b4ea34773aa..1465d0b88377e52d9b3e06c3e1c9a6b8f5f59c97 100644 (file)
@@ -333,4 +333,4 @@ CREATE OR REPLACE RULE file_update_rule AS
        ON UPDATE TO file DO SELECT pg_notify('file_update', new.fid::text || ',' || new.eid::text || ',' || new.aid::text);
 
 CREATE OR REPLACE RULE file_location_update_rule AS
-       ON UPDATE TO file_location DO SELECT pg_notify('file_location_update', new.location_id::text);
+       ON UPDATE TO file_location DO SELECT pg_notify('file_location_update', new.location_id::text || ',' || new.fid::text);