mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
Improve readability of library_creator code. Add parsing info to log.
This commit is contained in:
parent
975d7581ce
commit
57830b588c
@ -65,20 +65,27 @@ void LibraryCreator::updateFolder(const QString &source, const QString &target,
|
|||||||
relativeFolderPath = relativeFolderPath.remove(QDir::cleanPath(source));
|
relativeFolderPath = relativeFolderPath.remove(QDir::cleanPath(source));
|
||||||
|
|
||||||
if(relativeFolderPath.startsWith("/"))
|
if(relativeFolderPath.startsWith("/"))
|
||||||
|
{
|
||||||
relativeFolderPath = relativeFolderPath.remove(0,1);//remove firts '/'
|
relativeFolderPath = relativeFolderPath.remove(0,1);//remove firts '/'
|
||||||
|
}
|
||||||
|
|
||||||
QStringList folders;
|
QStringList folders;
|
||||||
|
|
||||||
if(!relativeFolderPath.isEmpty()) //updating root
|
if(!relativeFolderPath.isEmpty()) //updating root
|
||||||
|
{
|
||||||
folders = relativeFolderPath.split('/');
|
folders = relativeFolderPath.split('/');
|
||||||
|
}
|
||||||
|
|
||||||
QLOG_DEBUG() << "folders found in relative path : " << folders << "-" << relativeFolderPath;
|
QLOG_DEBUG() << "folders found in relative path : " << folders << "-" << relativeFolderPath;
|
||||||
|
|
||||||
QSqlDatabase db = DataBaseManagement::loadDatabase(target);
|
QSqlDatabase db = DataBaseManagement::loadDatabase(target);
|
||||||
|
|
||||||
foreach (QString folderName, folders) {
|
foreach (QString folderName, folders)
|
||||||
|
{
|
||||||
if(folderName.isEmpty())
|
if(folderName.isEmpty())
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
qulonglong parentId = _currentPathFolders.last().id;
|
qulonglong parentId = _currentPathFolders.last().id;
|
||||||
_currentPathFolders.append(DBHelper::loadFolder(folderName, parentId, db));
|
_currentPathFolders.append(DBHelper::loadFolder(folderName, parentId, db));
|
||||||
QLOG_DEBUG() << "Folder appended : " << _currentPathFolders.last().id << " " << _currentPathFolders.last().name << " with parent" << _currentPathFolders.last().parentId;
|
QLOG_DEBUG() << "Folder appended : " << _currentPathFolders.last().id << " " << _currentPathFolders.last().name << " with parent" << _currentPathFolders.last().parentId;
|
||||||
@ -104,8 +111,10 @@ void LibraryCreator::processLibrary(const QString & source, const QString & targ
|
|||||||
d.removeRecursively();
|
d.removeRecursively();
|
||||||
_mode = CREATOR;
|
_mode = CREATOR;
|
||||||
}
|
}
|
||||||
else //
|
else
|
||||||
|
{ //
|
||||||
_mode = UPDATER;
|
_mode = UPDATER;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -120,6 +129,7 @@ void LibraryCreator::run()
|
|||||||
#else
|
#else
|
||||||
QLibrary *sevenzLib = new QLibrary(QApplication::applicationDirPath()+"/utils/7z");
|
QLibrary *sevenzLib = new QLibrary(QApplication::applicationDirPath()+"/utils/7z");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(!sevenzLib->load())
|
if(!sevenzLib->load())
|
||||||
{
|
{
|
||||||
QLOG_ERROR() << "Loading 7z.dll : " + sevenzLib->errorString() << endl;
|
QLOG_ERROR() << "Loading 7z.dll : " + sevenzLib->errorString() << endl;
|
||||||
@ -180,10 +190,15 @@ void LibraryCreator::run()
|
|||||||
}
|
}
|
||||||
QSqlQuery pragma("PRAGMA foreign_keys = ON",_database);
|
QSqlQuery pragma("PRAGMA foreign_keys = ON",_database);
|
||||||
_database.transaction();
|
_database.transaction();
|
||||||
|
|
||||||
if(partialUpdate)
|
if(partialUpdate)
|
||||||
|
{
|
||||||
update(QDir(_sourceFolder));
|
update(QDir(_sourceFolder));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
update(QDir(_source));
|
update(QDir(_source));
|
||||||
|
}
|
||||||
_database.commit();
|
_database.commit();
|
||||||
_database.close();
|
_database.close();
|
||||||
QSqlDatabase::removeDatabase(_target);
|
QSqlDatabase::removeDatabase(_target);
|
||||||
@ -191,10 +206,14 @@ void LibraryCreator::run()
|
|||||||
if(!partialUpdate)
|
if(!partialUpdate)
|
||||||
{
|
{
|
||||||
if(!creation)
|
if(!creation)
|
||||||
|
{
|
||||||
emit(updated());
|
emit(updated());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
emit(created());
|
emit(created());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
QLOG_INFO() << "Update library END";
|
QLOG_INFO() << "Update library END";
|
||||||
}
|
}
|
||||||
//msleep(100);//TODO try to solve the problem with the udpate dialog (ya no se usa más...)
|
//msleep(100);//TODO try to solve the problem with the udpate dialog (ya no se usa más...)
|
||||||
@ -203,7 +222,7 @@ void LibraryCreator::run()
|
|||||||
emit updatedCurrentFolder(folderDestinationModelIndex);
|
emit updatedCurrentFolder(folderDestinationModelIndex);
|
||||||
emit finished();
|
emit finished();
|
||||||
}
|
}
|
||||||
else
|
else //TODO check this part!!
|
||||||
emit finished();
|
emit finished();
|
||||||
creation = false;
|
creation = false;
|
||||||
}
|
}
|
||||||
@ -260,6 +279,7 @@ void LibraryCreator::create(QDir dir)
|
|||||||
#endif
|
#endif
|
||||||
if(fileInfo.isDir())
|
if(fileInfo.isDir())
|
||||||
{
|
{
|
||||||
|
QLOG_INFO() << "Parsing folder" << fileInfo.canonicalPath() ;
|
||||||
//se añade al path actual el folder, aún no se sabe si habrá que añadirlo a la base de datos
|
//se añade al path actual el folder, aún no se sabe si habrá que añadirlo a la base de datos
|
||||||
_currentPathFolders.append(Folder(fileInfo.fileName(),relativePath));
|
_currentPathFolders.append(Folder(fileInfo.fileName(),relativePath));
|
||||||
create(QDir(fileInfo.absoluteFilePath()));
|
create(QDir(fileInfo.absoluteFilePath()));
|
||||||
@ -268,6 +288,7 @@ void LibraryCreator::create(QDir dir)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
QLOG_INFO() << "Parsing file" << fileInfo.filePath();
|
||||||
insertComic(relativePath,fileInfo);
|
insertComic(relativePath,fileInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -298,8 +319,10 @@ void LibraryCreator::insertComic(const QString & relativePath,const QFileInfo &
|
|||||||
tc.create();
|
tc.create();
|
||||||
numPages = tc.getNumPages();
|
numPages = tc.getNumPages();
|
||||||
if (numPages > 0)
|
if (numPages > 0)
|
||||||
|
{
|
||||||
emit(comicAdded(relativePath,_target+"/covers/"+hash+".jpg"));
|
emit(comicAdded(relativePath,_target+"/covers/"+hash+".jpg"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (numPages > 0 || exists)
|
if (numPages > 0 || exists)
|
||||||
{
|
{
|
||||||
@ -603,13 +626,12 @@ void ThumbnailCreator::create()
|
|||||||
delete pdfComic;
|
delete pdfComic;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
_numPages = pdfComic->numPages();
|
_numPages = pdfComic->numPages();
|
||||||
if(_numPages >= _coverPage)
|
if(_numPages >= _coverPage)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
{
|
{ //TODO is this "{" one too much?
|
||||||
QImage p = pdfComic->getPage(_coverPage-1); //TODO check if the page is valid
|
QImage p = pdfComic->getPage(_coverPage-1); //TODO check if the page is valid
|
||||||
#else
|
#else
|
||||||
QImage p = pdfComic->page(_coverPage-1)->renderToImage(72,72);
|
QImage p = pdfComic->page(_coverPage-1)->renderToImage(72,72);
|
||||||
@ -619,13 +641,17 @@ void ThumbnailCreator::create()
|
|||||||
{
|
{
|
||||||
QImage scaled;
|
QImage scaled;
|
||||||
if(p.width()>p.height()) //landscape??
|
if(p.width()>p.height()) //landscape??
|
||||||
|
{
|
||||||
scaled = p.scaledToWidth(640,Qt::SmoothTransformation);
|
scaled = p.scaledToWidth(640,Qt::SmoothTransformation);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
scaled = p.scaledToWidth(480,Qt::SmoothTransformation);
|
scaled = p.scaledToWidth(480,Qt::SmoothTransformation);
|
||||||
|
}
|
||||||
scaled.save(_target,0,75);
|
scaled.save(_target,0,75);
|
||||||
}
|
}
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
}
|
} //TODO is this "{" one too much?
|
||||||
pdfComic->releaseLastPageData();
|
pdfComic->releaseLastPageData();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -643,7 +669,9 @@ void ThumbnailCreator::create()
|
|||||||
{
|
{
|
||||||
|
|
||||||
if(crash)
|
if(crash)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CompressedArchive archive(_fileSource);
|
CompressedArchive archive(_fileSource);
|
||||||
if(!archive.toolsLoaded())
|
if(!archive.toolsLoaded())
|
||||||
@ -653,7 +681,9 @@ void ThumbnailCreator::create()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!archive.isValid())
|
if(!archive.isValid())
|
||||||
|
{
|
||||||
QLOG_WARN() << "Extracting cover: file format not supported " << _fileSource;
|
QLOG_WARN() << "Extracting cover: file format not supported " << _fileSource;
|
||||||
|
}
|
||||||
//se filtran para obtener sólo los formatos soportados
|
//se filtran para obtener sólo los formatos soportados
|
||||||
QList<QString> order = archive.getFileNames();
|
QList<QString> order = archive.getFileNames();
|
||||||
QList<QString> fileNames = FileComic::filter(order);
|
QList<QString> fileNames = FileComic::filter(order);
|
||||||
@ -663,12 +693,16 @@ void ThumbnailCreator::create()
|
|||||||
QLOG_WARN() << "Extracting cover: empty comic " << _fileSource;
|
QLOG_WARN() << "Extracting cover: empty comic " << _fileSource;
|
||||||
_cover.load(":/images/notCover.png");
|
_cover.load(":/images/notCover.png");
|
||||||
if(_target!="")
|
if(_target!="")
|
||||||
|
{
|
||||||
_cover.save(_target);
|
_cover.save(_target);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(_coverPage > _numPages)
|
if(_coverPage > _numPages)
|
||||||
|
{
|
||||||
_coverPage = 1;
|
_coverPage = 1;
|
||||||
|
}
|
||||||
qSort(fileNames.begin(),fileNames.end(), naturalSortLessThanCI);
|
qSort(fileNames.begin(),fileNames.end(), naturalSortLessThanCI);
|
||||||
int index = order.indexOf(fileNames.at(_coverPage-1));
|
int index = order.indexOf(fileNames.at(_coverPage-1));
|
||||||
|
|
||||||
@ -687,9 +721,13 @@ void ThumbnailCreator::create()
|
|||||||
{
|
{
|
||||||
QImage scaled;
|
QImage scaled;
|
||||||
if(p.width()>p.height()) //landscape??
|
if(p.width()>p.height()) //landscape??
|
||||||
|
{
|
||||||
scaled = p.scaledToWidth(640,Qt::SmoothTransformation);
|
scaled = p.scaledToWidth(640,Qt::SmoothTransformation);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
scaled = p.scaledToWidth(480,Qt::SmoothTransformation);
|
scaled = p.scaledToWidth(480,Qt::SmoothTransformation);
|
||||||
|
}
|
||||||
scaled.save(_target,0,75);
|
scaled.save(_target,0,75);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user