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));
|
||||
|
||||
if(relativeFolderPath.startsWith("/"))
|
||||
{
|
||||
relativeFolderPath = relativeFolderPath.remove(0,1);//remove firts '/'
|
||||
}
|
||||
|
||||
QStringList folders;
|
||||
|
||||
if(!relativeFolderPath.isEmpty()) //updating root
|
||||
{
|
||||
folders = relativeFolderPath.split('/');
|
||||
}
|
||||
|
||||
QLOG_DEBUG() << "folders found in relative path : " << folders << "-" << relativeFolderPath;
|
||||
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(target);
|
||||
|
||||
foreach (QString folderName, folders) {
|
||||
foreach (QString folderName, folders)
|
||||
{
|
||||
if(folderName.isEmpty())
|
||||
{
|
||||
break;
|
||||
}
|
||||
qulonglong parentId = _currentPathFolders.last().id;
|
||||
_currentPathFolders.append(DBHelper::loadFolder(folderName, parentId, db));
|
||||
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();
|
||||
_mode = CREATOR;
|
||||
}
|
||||
else //
|
||||
else
|
||||
{ //
|
||||
_mode = UPDATER;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -120,6 +129,7 @@ void LibraryCreator::run()
|
||||
#else
|
||||
QLibrary *sevenzLib = new QLibrary(QApplication::applicationDirPath()+"/utils/7z");
|
||||
#endif
|
||||
|
||||
if(!sevenzLib->load())
|
||||
{
|
||||
QLOG_ERROR() << "Loading 7z.dll : " + sevenzLib->errorString() << endl;
|
||||
@ -180,10 +190,15 @@ void LibraryCreator::run()
|
||||
}
|
||||
QSqlQuery pragma("PRAGMA foreign_keys = ON",_database);
|
||||
_database.transaction();
|
||||
|
||||
if(partialUpdate)
|
||||
{
|
||||
update(QDir(_sourceFolder));
|
||||
}
|
||||
else
|
||||
{
|
||||
update(QDir(_source));
|
||||
}
|
||||
_database.commit();
|
||||
_database.close();
|
||||
QSqlDatabase::removeDatabase(_target);
|
||||
@ -191,10 +206,14 @@ void LibraryCreator::run()
|
||||
if(!partialUpdate)
|
||||
{
|
||||
if(!creation)
|
||||
{
|
||||
emit(updated());
|
||||
}
|
||||
else
|
||||
{
|
||||
emit(created());
|
||||
}
|
||||
}
|
||||
QLOG_INFO() << "Update library END";
|
||||
}
|
||||
//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 finished();
|
||||
}
|
||||
else
|
||||
else //TODO check this part!!
|
||||
emit finished();
|
||||
creation = false;
|
||||
}
|
||||
@ -260,6 +279,7 @@ void LibraryCreator::create(QDir dir)
|
||||
#endif
|
||||
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
|
||||
_currentPathFolders.append(Folder(fileInfo.fileName(),relativePath));
|
||||
create(QDir(fileInfo.absoluteFilePath()));
|
||||
@ -268,6 +288,7 @@ void LibraryCreator::create(QDir dir)
|
||||
}
|
||||
else
|
||||
{
|
||||
QLOG_INFO() << "Parsing file" << fileInfo.filePath();
|
||||
insertComic(relativePath,fileInfo);
|
||||
}
|
||||
}
|
||||
@ -298,8 +319,10 @@ void LibraryCreator::insertComic(const QString & relativePath,const QFileInfo &
|
||||
tc.create();
|
||||
numPages = tc.getNumPages();
|
||||
if (numPages > 0)
|
||||
{
|
||||
emit(comicAdded(relativePath,_target+"/covers/"+hash+".jpg"));
|
||||
}
|
||||
}
|
||||
|
||||
if (numPages > 0 || exists)
|
||||
{
|
||||
@ -603,13 +626,12 @@ void ThumbnailCreator::create()
|
||||
delete pdfComic;
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
_numPages = pdfComic->numPages();
|
||||
if(_numPages >= _coverPage)
|
||||
{
|
||||
#ifdef Q_OS_MAC
|
||||
{
|
||||
{ //TODO is this "{" one too much?
|
||||
QImage p = pdfComic->getPage(_coverPage-1); //TODO check if the page is valid
|
||||
#else
|
||||
QImage p = pdfComic->page(_coverPage-1)->renderToImage(72,72);
|
||||
@ -619,13 +641,17 @@ void ThumbnailCreator::create()
|
||||
{
|
||||
QImage scaled;
|
||||
if(p.width()>p.height()) //landscape??
|
||||
{
|
||||
scaled = p.scaledToWidth(640,Qt::SmoothTransformation);
|
||||
}
|
||||
else
|
||||
{
|
||||
scaled = p.scaledToWidth(480,Qt::SmoothTransformation);
|
||||
}
|
||||
scaled.save(_target,0,75);
|
||||
}
|
||||
#ifdef Q_OS_MAC
|
||||
}
|
||||
} //TODO is this "{" one too much?
|
||||
pdfComic->releaseLastPageData();
|
||||
#endif
|
||||
}
|
||||
@ -643,7 +669,9 @@ void ThumbnailCreator::create()
|
||||
{
|
||||
|
||||
if(crash)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CompressedArchive archive(_fileSource);
|
||||
if(!archive.toolsLoaded())
|
||||
@ -653,7 +681,9 @@ void ThumbnailCreator::create()
|
||||
return;
|
||||
}
|
||||
if(!archive.isValid())
|
||||
{
|
||||
QLOG_WARN() << "Extracting cover: file format not supported " << _fileSource;
|
||||
}
|
||||
//se filtran para obtener sólo los formatos soportados
|
||||
QList<QString> order = archive.getFileNames();
|
||||
QList<QString> fileNames = FileComic::filter(order);
|
||||
@ -663,12 +693,16 @@ void ThumbnailCreator::create()
|
||||
QLOG_WARN() << "Extracting cover: empty comic " << _fileSource;
|
||||
_cover.load(":/images/notCover.png");
|
||||
if(_target!="")
|
||||
{
|
||||
_cover.save(_target);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(_coverPage > _numPages)
|
||||
{
|
||||
_coverPage = 1;
|
||||
}
|
||||
qSort(fileNames.begin(),fileNames.end(), naturalSortLessThanCI);
|
||||
int index = order.indexOf(fileNames.at(_coverPage-1));
|
||||
|
||||
@ -687,9 +721,13 @@ void ThumbnailCreator::create()
|
||||
{
|
||||
QImage scaled;
|
||||
if(p.width()>p.height()) //landscape??
|
||||
{
|
||||
scaled = p.scaledToWidth(640,Qt::SmoothTransformation);
|
||||
}
|
||||
else
|
||||
{
|
||||
scaled = p.scaledToWidth(480,Qt::SmoothTransformation);
|
||||
}
|
||||
scaled.save(_target,0,75);
|
||||
}
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user