updated Folder class

This commit is contained in:
Luis Ángel San Martín 2016-01-24 17:41:26 +01:00
parent 37328edc64
commit bac7fe1351
7 changed files with 125 additions and 26 deletions

View File

@ -733,7 +733,13 @@ QList<LibraryItem *> DBHelper::getFoldersFromParent(qulonglong parentId, QSqlDat
data << record.value(i);
//TODO sort by sort indicator and name
currentItem = new Folder(record.value("id").toULongLong(),record.value("parentId").toULongLong(),record.value("name").toString(),record.value("path").toString());
int lessThan = 0;
if(!record.value("numChildren").isNull() && record.value("numChildren").isValid())
currentItem->setNumChildren(record.value("numChildren").toInt());
currentItem->setFirstChildId(record.value("firstChildId").toULongLong());
currentItem->setCustomImage(record.value("customImage").toString());
int lessThan = 0;
if(list.isEmpty() || !sort)
list.append(currentItem);
@ -930,9 +936,10 @@ Folder DBHelper::loadFolder(qulonglong id, QSqlDatabase & db)
folder.setFinished(record.value("finished").toBool());
folder.setCompleted(record.value("completed").toBool());
//new 8.6
folder.numChildren = record.value("numChildren").isNull() ? -1 : record.value("numChildren").toInt();
folder.firstChildId = record.value("firstChildId").toULongLong();
folder.customImage = record.value("customImage").toString();
if(!record.value("numChildren").isNull() && record.value("numChildren").isValid())
folder.setNumChildren(record.value("numChildren").toInt());
folder.setFirstChildId(record.value("firstChildId").toULongLong());
folder.setCustomImage(record.value("customImage").toString());
}
return folder;
@ -962,9 +969,10 @@ Folder DBHelper::loadFolder(const QString &folderName, qulonglong parentId, QSql
folder.setFinished(record.value("finished").toBool());
folder.setCompleted(record.value("completed").toBool());
//new 8.6
folder.numChildren = record.value("numChildren").isNull() ? -1 : record.value("numChildren").toInt();
folder.firstChildId = record.value("firstChildId").toULongLong();
folder.customImage = record.value("customImage").toString();
if(!record.value("numChildren").isNull() && record.value("numChildren").isValid())
folder.setNumChildren(record.value("numChildren").toInt());
folder.setFirstChildId(record.value("firstChildId").toULongLong());
folder.setCustomImage(record.value("customImage").toString());
QLOG_DEBUG() << "FOUND!!";
}

View File

@ -54,7 +54,7 @@ void FolderContentController::serviceContent(const int &library, const qulonglon
if((*itr)->isDir())
{
currentFolder = (Folder *)(*itr);
response.writeText(QString("f:%1:%2:%3:%4\r\n").arg(library).arg(currentFolder->id).arg(currentFolder->name).arg(currentFolder->numChildren));
response.writeText(QString("f:%1:%2:%3:%4\r\n").arg(library).arg(currentFolder->id).arg(currentFolder->name).arg(currentFolder->getNumChildren()));
}
else
{

View File

@ -11,7 +11,7 @@ ComicDB::ComicDB()
}
bool ComicDB::isDir()
bool ComicDB::isDir() const
{
return false;
}

View File

@ -124,7 +124,7 @@ class ComicDB : public LibraryItem
public:
ComicDB();
bool isDir();
bool isDir() const;
bool _hasCover;

View File

@ -0,0 +1,30 @@
#include "folder.h"
Folder::Folder()
:knownParent(false),
knownId(false),
numChildren(-1),
firstChildId(0)
{}
Folder::Folder(qulonglong folderId, qulonglong parentId, const QString &folderName, const QString &folderPath)
:knownParent(true),
knownId(true),
numChildren(-1),
firstChildId(0)
{
this->id = folderId;
this->parentId = parentId;
this->name = folderName;
this->path = folderPath;
}
Folder::Folder(const QString & folderName, const QString & folderPath)
:knownParent(false),
knownId(false),
numChildren(-1),
firstChildId(0)
{
this->name = folderName;
this->path = folderPath;
}

View File

@ -10,25 +10,86 @@ class Folder : public LibraryItem
public:
bool knownParent;
bool knownId;
qint32 numChildren; //-1 for unknown number of children
qulonglong firstChildId; //0 for unknown first child
QString customImage; //empty for none custom image
Folder():knownParent(false), knownId(false){};
Folder(qulonglong sid, qulonglong pid,QString fn, QString fp):knownParent(true), knownId(true){id = sid; parentId = pid;name = fn; path = fp;};
Folder(QString fn, QString fp):knownParent(false), knownId(false){name = fn; path = fp;};
void setId(qulonglong sid){id = sid;knownId = true;};
void setFather(qulonglong pid){parentId = pid;knownParent = true;};
bool isDir() {return true;};
bool isFinished() const {return finished;};
bool isCompleted() const {return completed;};
void setFinished(bool b) {finished = b;};
void setCompleted(bool b) {completed = b;};
Folder();
Folder(qulonglong folderId, qulonglong parentId,const QString & folderName, const QString & folderPath);
Folder(const QString & folderName, const QString & folderPath);
inline void setId(qulonglong sid)
{
id = sid;
knownId = true;
}
inline void setFather(qulonglong pid)
{
parentId = pid;
knownParent = true;
}
inline bool isDir() const
{
return true;
}
inline bool isFinished() const
{
return finished;
}
inline bool isCompleted() const
{
return completed;
}
inline void setFinished(bool b)
{
finished = b;
}
inline void setCompleted(bool b)
{
completed = b;
}
inline qint32 getNumChildren() const
{
return numChildren;
}
inline void setNumChildren(const qint32 v)
{
numChildren = v;
}
inline qulonglong getFirstChildId() const
{
return firstChildId;
}
inline void setFirstChildId(const qulonglong v)
{
firstChildId = v;
}
inline qulonglong getCustomImage() const
{
return firstChildId;
}
inline void setCustomImage(const QString & s)
{
customImage = s;
}
private:
bool finished;
bool completed;
qint32 numChildren; //-1 for unknown number of children
qulonglong firstChildId; //0 for unknown first child
QString customImage; //empty for none custom image
};
#endif

View File

@ -6,11 +6,11 @@
class LibraryItem
{
public:
virtual bool isDir() = 0;
virtual bool isDir() const = 0;
QString name;
QString path;
qulonglong parentId;
qulonglong id;
};
#endif
#endif