From: APTX Date: Thu, 4 Apr 2013 12:02:32 +0000 (+0200) Subject: Actually implement handling file_location inserts by the model X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=b302b3f030869d6db261a53a49bdb81b91e9c318;p=localmylist.git Actually implement handling file_location inserts by the model --- diff --git a/localmylist/database.cpp b/localmylist/database.cpp index c03f559..676d61f 100644 --- a/localmylist/database.cpp +++ b/localmylist/database.cpp @@ -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 } diff --git a/localmylist/database.h b/localmylist/database.h index f048141..bcc14c0 100644 --- a/localmylist/database.h +++ b/localmylist/database.h @@ -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 diff --git a/localmylist/mylistmodel.cpp b/localmylist/mylistmodel.cpp index f727c9b..ce7bf00 100644 --- a/localmylist/mylistmodel.cpp +++ b/localmylist/mylistmodel.cpp @@ -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) diff --git a/localmylist/share/schema/schema.sql b/localmylist/share/schema/schema.sql index f95f8a1..1465d0b 100644 --- a/localmylist/share/schema/schema.sql +++ b/localmylist/share/schema/schema.sql @@ -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);