]> Some of my projects - localmylist.git/commitdiff
Add new level to MyListModel showing file locations
authorAPTX <marek321@gmail.com>
Tue, 3 Jul 2012 12:44:14 +0000 (14:44 +0200)
committerAPTX <marek321@gmail.com>
Tue, 3 Jul 2012 12:44:14 +0000 (14:44 +0200)
localmylist/mylistmodel.h
localmylist/mylistnode.cpp
localmylist/mylistnode.h

index 99d9bc51bf566bb6308408b7c3ee0b687106abde..42e3d4f97a8e90ce8f53d9708ea7c78c5b32a95c 100644 (file)
@@ -17,7 +17,8 @@ public:
                None,
                Anime,
                Episode,
-               File
+               File,
+               FileLocation
        };
 
        explicit MyListModel(QObject *parent = 0);
index 9388c027ecb9ac0635ffd59d2cdea3505316902f..764c91e099eb12be06bf37901b41b3185912755f 100644 (file)
@@ -19,7 +19,7 @@ MyListNode::MyListNode(NodeType type, int id, const QList<QVariant> &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<QVariant> &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<QVariant> &data, MyListNode *parent) :
+       MyListNode(FileLocation, id, data, parent)
+{
+}
+
+int MyListFileLocationNode::fetchMore()
+{
+       return 0;
+}
+
+QString MyListFileLocationNode::totalRowCountSql() const
 {
        return "SELECT 0";
 }
index 1e23e823a1132c227dd309f596b3c0666ed27973..423e04c4194a150b260601ae1dfa39d111832d5a 100644 (file)
@@ -12,7 +12,8 @@ public:
                Root,
                Anime,
                Episode,
-               File
+               File,
+               FileLocation
        };
 
        MyListNode(NodeType type = Root, int m_id = 0, const QList<QVariant> &data = QList<QVariant>(), MyListNode *parent = 0);
@@ -85,6 +86,17 @@ protected:
        QString totalRowCountSql() const;
 };
 
+class MyListFileLocationNode : public MyListNode
+{
+public:
+       MyListFileLocationNode(int id = 0, const QList<QVariant> &data = QList<QVariant>(), MyListNode *parent = 0);
+
+       int fetchMore();
+
+protected:
+       QString totalRowCountSql() const;
+};
+
 } // namespace LocalMyList
 
 #endif // MYLISTNODE_H