: EmuFrontObject(id, name), file(file) {}
EmuFrontFileObject::EmuFrontFileObject(const EmuFrontFileObject &pl)
- : EmuFrontObject(pl.id, pl.name)
+ : EmuFrontObject(pl)
{
EmuFrontFile *f = pl.file;
- file = new EmuFrontFile(*f);
+ file = f ? new EmuFrontFile(*f) : 0;
}
EmuFrontFileObject::~EmuFrontFileObject()
}
EmuFrontObject::EmuFrontObject(const EmuFrontObject &ob)
- : QObject(), id(ob.id), name(ob.name)
+ //: QObject(ob) //, id(ob.id), name(ob.name)
{
+ id = ob.id;
+ name = ob.name;
// no need to perform deep copy here, see:
// http://doc.trolltech.com/4.0/shclass.html
}
// You should have received a copy of the GNU General Public License
// along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
+#include <QDebug>
#include "filepathobject.h"
#include "setup.h"
}
FilePathObject::FilePathObject(const FilePathObject &fpobj)
- : EmuFrontObject(fpobj.id, fpobj.name), type(fpobj.type)
+ : EmuFrontObject(fpobj), type(fpobj.type)
{
+ qDebug() << "FilePathObject copy constructor.";
Setup *s = fpobj.setup;
+ qDebug() << "Setup name " << s->getName();
+ qDebug() << "Setup id " << s->getId();
setup = new Setup(*s);
}
: EmuFrontFileObject(id, name, file)
{
}
+
+MediaType::MediaType(const MediaType &mt)
+ : EmuFrontFileObject(mt)
+{
+}
MediaType();
MediaType(int id, QString name);
MediaType(int id, QString name, EmuFrontFile*);
+ MediaType(const MediaType &);
};
#endif // MEDIATYPE_H
: EmuFrontFileObject(id, name, file)
{
}
+
+Platform::Platform(const Platform &p)
+ : EmuFrontFileObject(p)
+{
+}
+
Platform();
Platform(int id, QString name);
Platform(int id, QString name, EmuFrontFile*);
+ Platform(const Platform &);
};
#endif // PLATFORM_H
// You should have received a copy of the GNU General Public License
// along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
+#include <QDebug>
#include "setup.h"
#include "platform.h"
#include "mediatype.h"
}
Setup::Setup(const Setup &s)
- : EmuFrontObject(s.getId(), s.getName()),
+ : EmuFrontObject(s),
fileTypeExtensions(s.fileTypeExtensions)
{
Platform *p = s.platform;
MediaType *m = s.mediaType;
+ qDebug() << "Setup copy constructor, platform is "
+ << p->getName() << p->getId() << ", mediatype is " << m->getName() << m->getId();
platform = new Platform(*p);
mediaType = new MediaType(*m);
}
"END;"
);
+ query.exec(
+ "CREATE TRIGGER IF NOT EXISTS trg_onfilepathdelete "
+ "AFTER DELETE ON filepath "
+ "BEGIN "
+ " DELETE FROM mediaimagecontainer WHERE filepathid=old.id; "
+ "END;"
+ );
+
// NOTE:
// media image container is not explicitily deleted,
// mediaimagecontainer entry should be deleted implicitely with
return id;
}
-bool DbEmuFrontFileObject::deleteDataObject(int id) const
+/*bool DbEmuFrontFileObject::deleteDataObject(int id) const
{
if (countDataObjectRefs(id) > 0)
// TODO
q.bindValue(":id", id);
return q.exec();
-}
+}*/
// WARNING: this will delete also all the databindings to selected platform
bool DbEmuFrontFileObject::deleteDataObjectFromModel(QModelIndex *index)
virtual QString constructFilterById(int id) const;
virtual EmuFrontObject* recordToDataObject(const QSqlRecord* );
virtual EmuFrontObject* createEmuFrontFileObject(int id, QString name, EmuFrontFile *f) = 0;
- virtual bool deleteDataObject(int id) const;
+ //virtual bool deleteDataObject(int id) const;
private:
virtual QSqlQueryModel* getData();
#include <QSqlQuery>
#include <QSqlQueryModel>
+#include <QSqlError>
#include <QDebug>
#include "dbquerymodelmanager.h"
bool DbQueryModelManager::deleteDataObject(int id) const
{
+ QString sql = getDeleteObjectSql();
+ qDebug() << sql;
QSqlQuery q;
- q.prepare(getDeleteObjectSql());
+ q.prepare(sql);
q.bindValue(":id", id);
- return q.exec();
+ bool ret = q.exec();
+ if (!ret) {
+ qDebug() << q.lastError().text();
+ }
+ return ret;
}
QString DbQueryModelManager::getDeleteObjectSql() const
QStringList l;
l << "*.zip"; // TODO set filters in a global constant class
- QList<MediaImageContainer*> files = fileUtil.scanFilePath(fpo, l);
- qDebug() << "Storing scanned " << files.size() << " files to database";
- dbMediaImageContainer->storeContainers(files, fpo);
- qDebug() << "Done storing scanned " << files.size() << " files to database";
- // the media image and media image container objects can be deleted now
- qDeleteAll(files);
+ int count = fileUtil.scanFilePath(fpo, l, dbMediaImageContainer);
+ qDebug() << "Storing scanned " << count << " files to database";
delete fpo;
}
catch (EmuFrontException s)
#include "../dataobjects/mediaimagecontainer.h"
#include "../dataobjects/mediatype.h"
#include "../dataobjects/platform.h"
+#include "../db/dbmediaimagecontainer.h"
+
+//int FileUtil::MIC_BUFFER_SIZE = 50;
FileUtil::FileUtil(QObject *parent) : QObject(parent)
{
}
/* Throws EmuFrontException */
-QList<MediaImageContainer*> FileUtil::scanFilePath(FilePathObject *fp, QStringList filters)
+int FileUtil::scanFilePath(FilePathObject *fp, QStringList filters, DbMediaImageContainer *dbMic)
{
if (!fp->getSetup()){
throw EmuFrontException(tr("Setup not available with %1.").arg(fp->getName()));
throw new EmuFrontException(tr("No media type available with %1.")
.arg(fp->getSetup()->getName()));
}
+ int count = 0;
qDebug() << QString("We have a platform %1, media type %2")
.arg(fp->getSetup()->getPlatform()->getName())
.arg(fp->getSetup()->getMediaType()->getName());
- QList<MediaImageContainer*> containers;
QDir dir(fp->getName());
if (!dir.exists() || !dir.isReadable())
throw EmuFrontException(tr("Directory %1 doesn't exists or isn't readable!").arg(fp->getName()));
// we'll go through the filtered archive files...
QFileInfoList list = dir.entryInfoList();
+ // TODO: only a buffer of objects should be kept here,
+ // and write to database each time the buffer is filled.
+ QList<MediaImageContainer*> containers;
for (int i = 0; i < list.size(); ++i)
{
QFileInfo fileInfo = list.at(i);
if (files.count() > 0)
{
quint32 crc = readCrc32(fileInfo.absoluteFilePath());
+ FilePathObject *fpo = new FilePathObject(*fp);
MediaImageContainer *con = new MediaImageContainer
(
fileInfo.fileName(),
QString("%1").arg(crc, 0, 16),
fileInfo.size(),
files,
- new FilePathObject(*fp)
+ fpo // we need a copy since MediaImageContainers are deleted and the original filepath object would get deleted also.
);
containers.append(con);
+ ++count;
+ qDebug() << "We have " << containers.count() << " containers.";
+
+ if (containers.count() >= MIC_BUFFER_SIZE) {
+ qDebug() << "We have " << containers.count()
+ << " containers .. storing to db.";
+ dbMic->storeContainers(containers, fp);
+ qDeleteAll(containers);
+ containers.clear();
+ qDebug() << "containers now: " << containers.count();
+ }
qDebug() << "We have " << containers.size() << " containers.";
}
}
+ if (containers.count() > 0) {
+ qDebug() << "Storing the rest " << containers.count() << " containers.";
+ dbMic->storeContainers(containers, fp);
+ qDeleteAll(containers);
+ containers.clear();
+
+ }
qDebug() << "Done scanning files!";
- return containers;
+ return count;
}
/* Uses crc32 from zlib.h to count crc32 checksum value */
class QStringList;
class MediaImageContainer;
class MediaImage;
+class DbMediaImageContainer;
class FileUtil : QObject
{
public:
FileUtil(QObject *parent);
~FileUtil();
- QList<MediaImageContainer*> scanFilePath(FilePathObject *fpo, const QStringList filters);
+ int scanFilePath(FilePathObject *fpo, const QStringList filters, DbMediaImageContainer *mic);
private:
char *buf;
quint32 readCrc32(QString filePath);
QList<MediaImage*> listContents(const QString filePath, const FilePathObject *fp);
bool isSupportedFile(const QString filename, const QStringList supportedFileExtensions);
+ static const int MIC_BUFFER_SIZE = 50;
};
#endif // FILEUTIL_H