From: APTX Date: Tue, 3 Jul 2012 12:44:14 +0000 (+0200) Subject: Add new level to MyListModel showing file locations X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=9cec4910c924df01f35ca7accd59063a0a35cfa5;p=localmylist.git Add new level to MyListModel showing file locations --- diff --git a/localmylist/mylistmodel.h b/localmylist/mylistmodel.h index 99d9bc5..42e3d4f 100644 --- a/localmylist/mylistmodel.h +++ b/localmylist/mylistmodel.h @@ -17,7 +17,8 @@ public: None, Anime, Episode, - File + File, + FileLocation }; explicit MyListModel(QObject *parent = 0); diff --git a/localmylist/mylistnode.cpp b/localmylist/mylistnode.cpp index 9388c02..764c91e 100644 --- a/localmylist/mylistnode.cpp +++ b/localmylist/mylistnode.cpp @@ -19,7 +19,7 @@ MyListNode::MyListNode(NodeType type, int id, const QList &data, MyLis if (m_type != Root) return; - itemData << "Title" << "Episode / Version" << "Rating / Quality" << "Vote" << "Watched"; + itemData << "Title" << "Episode / Version" << "Rating / Quality" << "Vote" << "Watched / Renamed"; } @@ -66,7 +66,7 @@ int MyListNode::totalRowCount() const if (m_totalRowCount != -1) return m_totalRowCount; - if (m_type == File) + if (m_type == FileLocation) { m_totalRowCount = 0; return m_totalRowCount; @@ -88,14 +88,14 @@ int MyListNode::totalRowCount() const bool MyListNode::canFetchMore() const { - if (m_type != File && childCount() < totalRowCount()) + if (m_type != FileLocation && childCount() < totalRowCount()) return true; return false; } int MyListNode::fetchMore() { - qDebug() << "fetching some more for" << m_id; + qDebug() << "fetching some more for root"; QSqlQuery q(LocalMyList::instance()->database()->connection()); if (!q.exec("SELECT aid, title_romaji AS title, (SELECT COUNT(e.eid) FROM episode e WHERE e.aid = a.aid), rating, my_vote, (SELECT COUNT(DISTINCT f.eid) FROM episode e JOIN file f ON (f.eid = e.eid) WHERE e.aid = a.aid AND f.my_watched IS NOT NULL) FROM anime a ORDER BY title ASC " @@ -119,7 +119,7 @@ int MyListNode::fetchMore() bool MyListNode::hasChildren() const { - if (m_type == File) + if (m_type == FileLocation) return false; return true; @@ -218,10 +218,47 @@ MyListFileNode::MyListFileNode(int id, const QList &data, MyListNode * int MyListFileNode::fetchMore() { - return 0; + qDebug() << "fetching some more for fid" << m_id; + QSqlQuery q(LocalMyList::instance()->database()->connection()); + + if (!q.exec("SELECT fl.fid, fl.host_id, h.name, fl.path, fl.renamed, fl.failed_rename FROM file_location fl " + " JOIN host h ON (fl.host_id = h.host_id) " + "WHERE fl.fid = " + QString::number(m_id))) + return 0; + + while (q.next()) + { + int id = q.value(0).toInt(); + QVariantList data; + data << q.value(3) + << QObject::tr("%1 (%2)").arg(q.value(2).toString()).arg(q.value(1).toString()) + << "" + << "" + << (q.value(5).toBool() ? QObject::tr("Rename Failed") : q.value(4).toDateTime().isValid() ? QObject::tr("Yes, on %1").arg(q.value(4).toDateTime().toString()) : QObject::tr("Not Renamed")); + childItems << new MyListFileLocationNode(id, data, this); + } + + return q.size(); } QString MyListFileNode::totalRowCountSql() const +{ + return "SELECT COUNT(fid) FROM file_location WHERE fid = " + QString::number(m_id); +} + +// --------------- + +MyListFileLocationNode::MyListFileLocationNode(int id, const QList &data, MyListNode *parent) : + MyListNode(FileLocation, id, data, parent) +{ +} + +int MyListFileLocationNode::fetchMore() +{ + return 0; +} + +QString MyListFileLocationNode::totalRowCountSql() const { return "SELECT 0"; } diff --git a/localmylist/mylistnode.h b/localmylist/mylistnode.h index 1e23e82..423e04c 100644 --- a/localmylist/mylistnode.h +++ b/localmylist/mylistnode.h @@ -12,7 +12,8 @@ public: Root, Anime, Episode, - File + File, + FileLocation }; MyListNode(NodeType type = Root, int m_id = 0, const QList &data = QList(), MyListNode *parent = 0); @@ -85,6 +86,17 @@ protected: QString totalRowCountSql() const; }; +class MyListFileLocationNode : public MyListNode +{ +public: + MyListFileLocationNode(int id = 0, const QList &data = QList(), MyListNode *parent = 0); + + int fetchMore(); + +protected: + QString totalRowCountSql() const; +}; + } // namespace LocalMyList #endif // MYLISTNODE_H