return m_totalRowCount;
}
-int MyListNode::nextFetchSize() const
-{
- int limit = LIMIT;
- return qMin(limit, totalRowCount() - childCount());
-}
-
bool MyListNode::canFetchMore() const
{
if (m_type != FileLocation && childCount() < totalRowCount())
<< (q.value(3).toDouble() < 1 ? "n/a" : QString::number(q.value(3).toDouble(), 'f', 2))
<< (q.value(4).toDouble() < 1 ? "n/a" : QString::number(q.value(4).toDouble(), 'f', 2))
<< QObject::tr("%1 of %2").arg(q.value(5).toInt()).arg(q.value(2).toInt());
- childItems << new MyListAnimeNode(id, data, this);
+ newItems << new MyListAnimeNode(id, data, this);
}
- qDebug() << "root" << q.size();
- return q.size();
+
+ q.finish();
+
+ return newItems.count();
+}
+
+void MyListNode::addFetched()
+{
+ while (newItems.count())
+ childItems << newItems.takeFirst();
}
bool MyListNode::hasChildren() const
<< (q.value(3).toDouble() < 1 ? "n/a" : QString::number(q.value(3).toDouble(), 'f', 2))
<< (q.value(4).toDouble() < 1 ? "n/a" : QString::number(q.value(4).toDouble(), 'f', 2))
<< (q.value(5).toDateTime().isValid() ? QObject::tr("Yes, on %1").arg(q.value(5).toDateTime().toString()) : QObject::tr("No"));
- childItems << new MyListEpisodeNode(id, data, this);
+ newItems << new MyListEpisodeNode(id, data, this);
}
- return q.size();
+ q.finish();
+
+ return newItems.count();
}
// ----
int MyListEpisodeNode::fetchMore()
{
qDebug() << "fetching some more for eid" << m_id;
- QSqlQuery q(LocalMyList::instance()->database()->connection());
+ QSqlQuery &q = LocalMyList::instance()->database()->prepare(
+ "SELECT fid, group_name, version, quality, my_watched "
+ " FROM file "
+ " WHERE eid = :eida "
+ "UNION "
+ "SELECT f.fid, f.group_name, f.version, f.quality, f.my_watched FROM file f "
+ " JOIN file_episode_rel fer ON (fer.fid = f.fid) "
+ " WHERE fer.eid = :eidb ");
+ q.bindValue(":eida", m_id);
+ q.bindValue(":eidb", m_id);
- if (!q.exec(QString(
- "SELECT fid, group_name, version, quality, my_watched "
- " FROM file "
- " WHERE eid = %1 "
- "UNION "
- "SELECT f.fid, f.group_name, f.version, f.quality, f.my_watched FROM file f "
- " JOIN file_episode_rel fer ON (fer.fid = f.fid) "
- " WHERE fer.eid = %1 ").arg(m_id)))
+ if (!LocalMyList::instance()->database()->exec(q))
return 0;
while (q.next())
QVariantList data;
data << q.value(1) << "v" + q.value(2).toString() << q.value(3) << ""
<< (q.value(4).toDateTime().isValid() ? QObject::tr("Yes, on %1").arg(q.value(4).toDateTime().toString()) : QObject::tr("No"));
- childItems << new MyListFileNode(id, data, this);
+ newItems << new MyListFileNode(id, data, this);
}
- return q.size();
+ q.finish();
+
+ return newItems.count();
}
// ---------------
int MyListFileNode::fetchMore()
{
qDebug() << "fetching some more for fid" << m_id;
- QSqlQuery q(LocalMyList::instance()->database()->connection());
+ QSqlQuery &q = LocalMyList::instance()->database()->prepare(
+ "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 = :fid");
+ q.bindValue(":fid", m_id);
- 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)))
+ if (!LocalMyList::instance()->database()->exec(q))
return 0;
while (q.next())
<< ""
<< ""
<< (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);
+ newItems << new MyListFileLocationNode(id, data, this);
}
- return q.size();
+ q.finish();
+
+ return newItems.count();
}
QString MyListFileNode::totalRowCountSql() const