mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
commit
8315e8ec34
@ -1,164 +0,0 @@
|
||||
INCLUDEPATH += $$PWD
|
||||
DEPENDPATH += $$PWD
|
||||
INCLUDEPATH += .
|
||||
INCLUDEPATH += $$PWD/../common \
|
||||
$$PWD/../custom_widgets
|
||||
|
||||
CONFIG(legacy_gl_widget) {
|
||||
INCLUDEPATH += ../common/gl_legacy \
|
||||
} else {
|
||||
INCLUDEPATH += ../common/gl \
|
||||
}
|
||||
|
||||
win32 {
|
||||
LIBS += -L$$PWD/../dependencies/poppler/lib -loleaut32 -lole32
|
||||
|
||||
LIBS += -lpoppler-qt5
|
||||
INCLUDEPATH += ../dependencies/poppler/include/qt5
|
||||
|
||||
QMAKE_CXXFLAGS_RELEASE += /MP /Ob2 /Oi /Ot /GT
|
||||
!CONFIG(no_opengl) {
|
||||
QMAKE_CXXFLAGS_RELEASE += /GL
|
||||
}
|
||||
QMAKE_LFLAGS_RELEASE += /LTCG
|
||||
CONFIG -= embed_manifest_exe
|
||||
}
|
||||
|
||||
unix:!macx{
|
||||
|
||||
INCLUDEPATH += /usr/include/poppler/qt5
|
||||
LIBS += -L/usr/lib -lpoppler-qt5
|
||||
|
||||
!CONFIG(no_opengl) {
|
||||
LIBS += -lGLU
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
macx{
|
||||
#INCLUDEPATH += "/Volumes/Mac OS X Lion/usr/X11/include"
|
||||
#isEqual(QT_MAJOR_VERSION, 5) {
|
||||
#INCLUDEPATH += /usr/local/include/poppler/qt5
|
||||
#LIBS += -L/usr/local/lib -lpoppler-qt5
|
||||
#}
|
||||
#else {
|
||||
#INCLUDEPATH += /usr/local/include/poppler/qt4
|
||||
#LIBS += -L/usr/local/lib -lpoppler-qt4
|
||||
#}
|
||||
CONFIG += objective_c
|
||||
QT += macextras gui-private
|
||||
|
||||
|
||||
LIBS += -framework Foundation -framework ApplicationServices -framework AppKit
|
||||
|
||||
OBJECTIVE_SOURCES += $$PWD/../common/pdf_comic.mm
|
||||
HEADERS += $$PWD/../common/pdf_comic.h
|
||||
}
|
||||
|
||||
QT += network widgets core
|
||||
!CONFIG(no_opengl) {
|
||||
QT += opengl
|
||||
}
|
||||
|
||||
#CONFIG += release
|
||||
CONFIG -= flat
|
||||
|
||||
QT += multimedia
|
||||
|
||||
# Input
|
||||
HEADERS += $$PWD/../common/comic.h \
|
||||
$$PWD/configuration.h \
|
||||
$$PWD/goto_dialog.h \
|
||||
$$PWD/magnifying_glass.h \
|
||||
$$PWD/main_window_viewer.h \
|
||||
$$PWD/viewer.h \
|
||||
$$PWD/goto_flow.h \
|
||||
$$PWD/options_dialog.h \
|
||||
$$PWD/../common/bookmarks.h \
|
||||
$$PWD/bookmarks_dialog.h \
|
||||
$$PWD/render.h \
|
||||
$$PWD/shortcuts_dialog.h \
|
||||
$$PWD/translator.h \
|
||||
$$PWD/goto_flow_widget.h \
|
||||
$$PWD/page_label_widget.h \
|
||||
$$PWD/goto_flow_toolbar.h \
|
||||
$$PWD/goto_flow_decorationbar.h \
|
||||
$$PWD/width_slider.h \
|
||||
$$PWD/notifications_label_widget.h \
|
||||
$$PWD/../common/pictureflow.h \
|
||||
$$PWD/../common/custom_widgets.h \
|
||||
$$PWD/../common/check_new_version.h \
|
||||
$$PWD/../common/qnaturalsorting.h \
|
||||
$$PWD/../common/yacreader_global.h \
|
||||
$$PWD/../common/onstart_flow_selection_dialog.h \
|
||||
$$PWD/../common/comic_db.h \
|
||||
$$PWD/../common/folder.h \
|
||||
$$PWD/../common/library_item.h \
|
||||
$$PWD/yacreader_local_client.h \
|
||||
$$PWD/../common/http_worker.h \
|
||||
$$PWD/../common/exit_check.h \
|
||||
$$PWD/../common/scroll_management.h
|
||||
|
||||
!CONFIG(no_opengl) {
|
||||
CONFIG(legacy_gl_widget) {
|
||||
message("using legacy YACReaderFlowGL (QGLWidget) header")
|
||||
HEADERS += ../common/gl_legacy/yacreader_flow_gl.h
|
||||
} else {
|
||||
HEADERS += ../common/gl/yacreader_flow_gl.h
|
||||
}
|
||||
HEADERS += $$PWD/goto_flow_gl.h
|
||||
}
|
||||
|
||||
SOURCES += $$PWD/../common/comic.cpp \
|
||||
$$PWD/configuration.cpp \
|
||||
$$PWD/goto_dialog.cpp \
|
||||
$$PWD/magnifying_glass.cpp \
|
||||
$$PWD/main_window_viewer.cpp \
|
||||
$$PWD/viewer.cpp \
|
||||
$$PWD/goto_flow.cpp \
|
||||
$$PWD/options_dialog.cpp \
|
||||
$$PWD/../common/bookmarks.cpp \
|
||||
$$PWD/bookmarks_dialog.cpp \
|
||||
$$PWD/render.cpp \
|
||||
$$PWD/shortcuts_dialog.cpp \
|
||||
$$PWD/translator.cpp \
|
||||
$$PWD/goto_flow_widget.cpp \
|
||||
$$PWD/page_label_widget.cpp \
|
||||
$$PWD/goto_flow_toolbar.cpp \
|
||||
$$PWD/goto_flow_decorationbar.cpp \
|
||||
$$PWD/width_slider.cpp \
|
||||
$$PWD/notifications_label_widget.cpp \
|
||||
$$PWD/../common/pictureflow.cpp \
|
||||
$$PWD/../common/custom_widgets.cpp \
|
||||
$$PWD/../common/check_new_version.cpp \
|
||||
$$PWD/../common/qnaturalsorting.cpp \
|
||||
$$PWD/../common/onstart_flow_selection_dialog.cpp \
|
||||
$$PWD/../common/comic_db.cpp \
|
||||
$$PWD/../common/folder.cpp \
|
||||
$$PWD/../common/library_item.cpp \
|
||||
$$PWD/yacreader_local_client.cpp \
|
||||
$$PWD/../common/http_worker.cpp \
|
||||
$$PWD/../common/yacreader_global.cpp \
|
||||
$$PWD/../common/exit_check.cpp \
|
||||
$$PWD/../common/scroll_management.cpp
|
||||
|
||||
!CONFIG(no_opengl) {
|
||||
CONFIG(legacy_gl_widget) {
|
||||
message("using legacy YACReaderFlowGL (QGLWidget) source code")
|
||||
SOURCES += ../common/gl_legacy/yacreader_flow_gl.cpp
|
||||
} else {
|
||||
SOURCES += ../common/gl/yacreader_flow_gl.cpp
|
||||
}
|
||||
SOURCES += $$PWD/goto_flow_gl.cpp
|
||||
}
|
||||
|
||||
include($$PWD/../custom_widgets/custom_widgets_yacreader.pri)
|
||||
include($$PWD/../compressed_archive/wrapper.pri)
|
||||
include($$PWD/../shortcuts_management/shortcuts_management.pri)
|
||||
|
||||
RESOURCES += $$PWD/yacreader_images.qrc \
|
||||
$$PWD/yacreader_files.qrc
|
||||
|
||||
win32:RESOURCES += $$PWD/yacreader_images_win.qrc
|
||||
unix:!macx:RESOURCES += $$PWD/yacreader_images_win.qrc
|
||||
macx:RESOURCES += $$PWD/yacreader_images_osx.qrc
|
@ -174,7 +174,11 @@ SOURCES += ../common/comic.cpp \
|
||||
}
|
||||
|
||||
include(../custom_widgets/custom_widgets_yacreader.pri)
|
||||
!CONFIG(unarr){
|
||||
include(../compressed_archive/wrapper.pri)
|
||||
} else {
|
||||
include(../compressed_archive/unarr/unarr-wrapper.pri)
|
||||
}
|
||||
include(../shortcuts_management/shortcuts_management.pri)
|
||||
|
||||
RESOURCES += yacreader_images.qrc \
|
||||
@ -202,7 +206,7 @@ TRANSLATIONS = yacreader_es.ts \
|
||||
yacreader_de.ts \
|
||||
yacreader_source.ts
|
||||
|
||||
|
||||
!CONFIG(unarr){
|
||||
win32 {
|
||||
!exists (../compressed_archive/lib7zip) {
|
||||
error(You\'ll need 7zip source code to compile YACReader. \
|
||||
@ -219,6 +223,12 @@ exists (../compressed_archive/libp7zip) {
|
||||
Please check the compressed_archive folder for further instructions.)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
exists (../compressed_archive/unarr/unarr-master) {
|
||||
message(Found unarr source-code)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unix:!macx {
|
||||
#set install prefix if it's empty
|
||||
|
@ -100,6 +100,7 @@ QImage changeImage( const QImage& image, int value )
|
||||
colors[ i ] = qRgb( operation( qRed( colors[ i ] ), value ),
|
||||
operation( qGreen( colors[ i ] ), value ),
|
||||
operation( qBlue( colors[ i ] ), value ));
|
||||
im.setColorTable(colors);
|
||||
}
|
||||
return im;
|
||||
}
|
||||
|
@ -220,7 +220,12 @@ SOURCES += comic_flow.cpp \
|
||||
|
||||
include(./server/server.pri)
|
||||
include(../custom_widgets/custom_widgets_yacreaderlibrary.pri)
|
||||
!CONFIG(unarr){
|
||||
include(../compressed_archive/wrapper.pri)
|
||||
} else {
|
||||
include(../compressed_archive/unarr/unarr-wrapper.pri)
|
||||
}
|
||||
|
||||
include(./comic_vine/comic_vine.pri)
|
||||
include(../QsLog/QsLog.pri)
|
||||
include(../shortcuts_management/shortcuts_management.pri)
|
||||
@ -263,6 +268,7 @@ win32:RESOURCES += qml_win.qrc
|
||||
unix:!macx:RESOURCES += qml_win.qrc
|
||||
macx:RESOURCES += qml_osx.qrc
|
||||
|
||||
!CONFIG(unarr){
|
||||
win32 {
|
||||
!exists(../compressed_archive/lib7zip){
|
||||
error(You\'ll need 7zip source code to compile YACReader. \
|
||||
@ -279,6 +285,11 @@ exists (../compressed_archive/libp7zip) {
|
||||
Please check the compressed_archive folder for further instructions.)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
exists (../compressed_archive/unarr/unarr-master) {
|
||||
message(Found unarr source code)
|
||||
}
|
||||
}
|
||||
|
||||
unix:!macx {
|
||||
#set install prefix if it's empty
|
||||
|
@ -44,7 +44,7 @@ LibraryCreator::LibraryCreator()
|
||||
void LibraryCreator::createLibrary(const QString &source, const QString &target)
|
||||
{
|
||||
creation = true;
|
||||
processLibrary(source, target);
|
||||
processLibrary(source, target);
|
||||
}
|
||||
|
||||
void LibraryCreator::updateLibrary(const QString &source, const QString &target)
|
||||
@ -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) {
|
||||
if(folderName.isEmpty())
|
||||
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;
|
||||
@ -100,12 +107,14 @@ void LibraryCreator::processLibrary(const QString & source, const QString & targ
|
||||
if(DataBaseManagement::checkValidDB(target+"/library.ydb")=="")
|
||||
{
|
||||
//se limpia el directorio ./yacreaderlibrary
|
||||
QDir d(target);
|
||||
d.removeRecursively();
|
||||
QDir d(target);
|
||||
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;
|
||||
@ -160,13 +170,13 @@ void LibraryCreator::run()
|
||||
}
|
||||
else
|
||||
{
|
||||
QLOG_INFO() << "Starting to update folder" << _sourceFolder << "in library ( " << _source << "," << _target << ")";
|
||||
if(!partialUpdate)
|
||||
{
|
||||
_currentPathFolders.clear();
|
||||
_currentPathFolders.append(Folder(1,1,"root","/"));
|
||||
QLOG_DEBUG() << "update whole library";
|
||||
}
|
||||
QLOG_INFO() << "Starting to update folder" << _sourceFolder << "in library ( " << _source << "," << _target << ")";
|
||||
if(!partialUpdate)
|
||||
{
|
||||
_currentPathFolders.clear();
|
||||
_currentPathFolders.append(Folder(1,1,"root","/"));
|
||||
QLOG_DEBUG() << "update whole library";
|
||||
}
|
||||
|
||||
_database = DataBaseManagement::loadDatabase(_target);
|
||||
//_database.setDatabaseName(_target+"/library.ydb");
|
||||
@ -180,21 +190,30 @@ void LibraryCreator::run()
|
||||
}
|
||||
QSqlQuery pragma("PRAGMA foreign_keys = ON",_database);
|
||||
_database.transaction();
|
||||
if(partialUpdate)
|
||||
update(QDir(_sourceFolder));
|
||||
else
|
||||
update(QDir(_source));
|
||||
|
||||
if(partialUpdate)
|
||||
{
|
||||
update(QDir(_sourceFolder));
|
||||
}
|
||||
else
|
||||
{
|
||||
update(QDir(_source));
|
||||
}
|
||||
_database.commit();
|
||||
_database.close();
|
||||
QSqlDatabase::removeDatabase(_target);
|
||||
//si estabamos en modo creación, se está añadiendo una librería que ya existía y se ha actualizado antes de añadirse.
|
||||
if(!partialUpdate)
|
||||
{
|
||||
if(!creation)
|
||||
emit(updated());
|
||||
else
|
||||
emit(created());
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -289,26 +310,28 @@ void LibraryCreator::insertComic(const QString & relativePath,const QFileInfo &
|
||||
file.close();
|
||||
//hash Sha1 del primer 0.5MB + filesize
|
||||
QString hash = QString(crypto.result().toHex().constData()) + QString::number(fileInfo.size());
|
||||
ComicDB comic = DBHelper::loadComic(fileInfo.fileName(),relativePath,hash,_database);
|
||||
int numPages = 0;
|
||||
bool exists = checkCover(hash);
|
||||
if(! ( comic.hasCover() && exists))
|
||||
ComicDB comic = DBHelper::loadComic(fileInfo.fileName(),relativePath,hash,_database);
|
||||
int numPages = 0;
|
||||
bool exists = checkCover(hash);
|
||||
if(! ( comic.hasCover() && exists))
|
||||
{
|
||||
ThumbnailCreator tc(QDir::cleanPath(fileInfo.absoluteFilePath()),_target+"/covers/"+hash+".jpg",comic.info.coverPage.toInt());
|
||||
ThumbnailCreator tc(QDir::cleanPath(fileInfo.absoluteFilePath()),_target+"/covers/"+hash+".jpg",comic.info.coverPage.toInt());
|
||||
tc.create();
|
||||
numPages = tc.getNumPages();
|
||||
if (numPages > 0)
|
||||
emit(comicAdded(relativePath,_target+"/covers/"+hash+".jpg"));
|
||||
if (numPages > 0)
|
||||
{
|
||||
emit(comicAdded(relativePath,_target+"/covers/"+hash+".jpg"));
|
||||
}
|
||||
}
|
||||
|
||||
if (numPages > 0 || exists)
|
||||
{
|
||||
//en este punto sabemos que todos los folders que hay en _currentPath, deberían estar añadidos a la base de datos
|
||||
insertFolders();
|
||||
comic.info.numPages = numPages;
|
||||
comic.parentId = _currentPathFolders.last().id;
|
||||
DBHelper::insert(&comic,_database);
|
||||
}
|
||||
if (numPages > 0 || exists)
|
||||
{
|
||||
//en este punto sabemos que todos los folders que hay en _currentPath, deberían estar añadidos a la base de datos
|
||||
insertFolders();
|
||||
comic.info.numPages = numPages;
|
||||
comic.parentId = _currentPathFolders.last().id;
|
||||
DBHelper::insert(&comic,_database);
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryCreator::update(QDir dirS)
|
||||
@ -573,58 +596,71 @@ void ThumbnailCreator::create()
|
||||
{
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
MacOSXPDFComic * pdfComic = new MacOSXPDFComic();
|
||||
if(!pdfComic->openComic(_fileSource))
|
||||
{
|
||||
delete pdfComic;
|
||||
//QImage p;
|
||||
//p.load(":/images/notCover.png");
|
||||
//p.save(_target);
|
||||
return;
|
||||
MacOSXPDFComic * pdfComic = new MacOSXPDFComic();
|
||||
if(!pdfComic->openComic(_fileSource))
|
||||
{
|
||||
delete pdfComic;
|
||||
//QImage p;
|
||||
//p.load(":/images/notCover.png");
|
||||
//p.save(_target);
|
||||
return;
|
||||
}
|
||||
#else
|
||||
Poppler::Document * pdfComic = Poppler::Document::load(_fileSource);
|
||||
#endif
|
||||
if (!pdfComic)
|
||||
{
|
||||
QLOG_WARN() << "Extracting cover: unable to open PDF file " << _fileSource;
|
||||
//delete pdfComic; //TODO check if the delete is needed
|
||||
pdfComic = 0;
|
||||
//QImage p;
|
||||
//p.load(":/images/notCover.png");
|
||||
//p.save(_target);
|
||||
return;
|
||||
}
|
||||
_numPages = pdfComic->numPages();
|
||||
if(_numPages >= _coverPage)
|
||||
{
|
||||
QLOG_WARN() << "Extracting cover: unable to open PDF file " << _fileSource;
|
||||
//delete pdfComic; //TODO check if the delete is needed
|
||||
pdfComic = 0;
|
||||
//QImage p;
|
||||
//p.load(":/images/notCover.png");
|
||||
//p.save(_target);
|
||||
return;
|
||||
}
|
||||
#ifndef Q_OS_MAC
|
||||
//poppler only, not mac
|
||||
if (pdfComic->isLocked())
|
||||
{
|
||||
QLOG_WARN() << "Extracting cover: unable to open PDF file " << _fileSource;
|
||||
delete pdfComic;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
_numPages = pdfComic->numPages();
|
||||
if(_numPages >= _coverPage)
|
||||
{
|
||||
#ifdef Q_OS_MAC
|
||||
{
|
||||
QImage p = pdfComic->getPage(_coverPage-1); //TODO check if the page is valid
|
||||
{ //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);
|
||||
QImage p = pdfComic->page(_coverPage-1)->renderToImage(72,72);
|
||||
#endif
|
||||
_cover = QPixmap::fromImage(p);
|
||||
if(_target!="")
|
||||
{
|
||||
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
|
||||
}
|
||||
else if(_target!="")
|
||||
{
|
||||
QLOG_WARN() << "Extracting cover: requested cover index greater than numPages " << _fileSource;
|
||||
//QImage p;
|
||||
//p.load(":/images/notCover.png");
|
||||
//p.save(_target);
|
||||
//QImage p;
|
||||
//p.load(":/images/notCover.png");
|
||||
//p.save(_target);
|
||||
}
|
||||
|
||||
delete pdfComic;
|
||||
@ -632,63 +668,75 @@ void ThumbnailCreator::create()
|
||||
else
|
||||
{
|
||||
|
||||
if(crash)
|
||||
return;
|
||||
|
||||
CompressedArchive archive(_fileSource);
|
||||
if(!archive.toolsLoaded())
|
||||
{
|
||||
QLOG_WARN() << "Extracting cover: 7z lib not loaded";
|
||||
crash = true;
|
||||
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);
|
||||
_numPages = fileNames.size();
|
||||
if(_numPages == 0)
|
||||
{
|
||||
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));
|
||||
|
||||
if(_target=="")
|
||||
if(crash)
|
||||
{
|
||||
if(!_cover.loadFromData(archive.getRawDataAtIndex(index)))
|
||||
return;
|
||||
}
|
||||
|
||||
CompressedArchive archive(_fileSource);
|
||||
if(!archive.toolsLoaded())
|
||||
{
|
||||
QLOG_WARN() << "Extracting cover: 7z lib not loaded";
|
||||
crash = true;
|
||||
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);
|
||||
_numPages = fileNames.size();
|
||||
if(_numPages == 0)
|
||||
{
|
||||
QLOG_WARN() << "Extracting cover: empty comic " << _fileSource;
|
||||
_cover.load(":/images/notCover.png");
|
||||
if(_target!="")
|
||||
{
|
||||
QLOG_WARN() << "Extracting cover: unable to load image from extracted cover " << _fileSource;
|
||||
_cover.load(":/images/notCover.png");
|
||||
_cover.save(_target);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QImage p;
|
||||
if(p.loadFromData(archive.getRawDataAtIndex(index)))
|
||||
if(_coverPage > _numPages)
|
||||
{
|
||||
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);
|
||||
_coverPage = 1;
|
||||
}
|
||||
qSort(fileNames.begin(),fileNames.end(), naturalSortLessThanCI);
|
||||
int index = order.indexOf(fileNames.at(_coverPage-1));
|
||||
|
||||
if(_target=="")
|
||||
{
|
||||
if(!_cover.loadFromData(archive.getRawDataAtIndex(index)))
|
||||
{
|
||||
QLOG_WARN() << "Extracting cover: unable to load image from extracted cover " << _fileSource;
|
||||
_cover.load(":/images/notCover.png");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QLOG_WARN() << "Extracting cover: unable to load image from extracted cover " << _fileSource;
|
||||
//p.load(":/images/notCover.png");
|
||||
//p.save(_target);
|
||||
QImage p;
|
||||
if(p.loadFromData(archive.getRawDataAtIndex(index)))
|
||||
{
|
||||
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
|
||||
{
|
||||
QLOG_WARN() << "Extracting cover: unable to load image from extracted cover " << _fileSource;
|
||||
//p.load(":/images/notCover.png");
|
||||
//p.save(_target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -708,8 +708,11 @@ void PDFComic::process()
|
||||
emit errorOpening();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (pdfComic->isLocked())
|
||||
{
|
||||
emit errorOpening();
|
||||
return;
|
||||
}
|
||||
|
||||
//pdfComic->setRenderHint(Poppler::Document::Antialiasing, true);
|
||||
pdfComic->setRenderHint(Poppler::Document::TextAntialiasing, true);
|
||||
|
1
compressed_archive/unarr/README.txt
Normal file
1
compressed_archive/unarr/README.txt
Normal file
@ -0,0 +1 @@
|
||||
To use unarr download https://github.com/zeniko/unarr/archive/master.zip and extract it in this folder. Run qmake with CONFIG+=unarr
|
107
compressed_archive/unarr/compressed_archive.cpp
Normal file
107
compressed_archive/unarr/compressed_archive.cpp
Normal file
@ -0,0 +1,107 @@
|
||||
#include "compressed_archive.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QDebug>
|
||||
#include <QApplication>
|
||||
|
||||
#include "yacreader_global.h"
|
||||
#include "extract_delegate.h"
|
||||
|
||||
extern"C" {
|
||||
#include "unarr.h"
|
||||
}
|
||||
|
||||
CompressedArchive::CompressedArchive(const QString & filePath, QObject *parent) :
|
||||
QObject(parent),valid(false),tools(true),numFiles(0),ar(NULL),stream(NULL)
|
||||
{
|
||||
stream = ar_open_file(filePath.toStdString().c_str());
|
||||
//try to open archive
|
||||
ar = ar_open_rar_archive(stream);
|
||||
if (!ar) ar = ar_open_zip_archive(stream, false);
|
||||
//if (!ar) ar = ar_open_7z_archive(stream);
|
||||
if (!ar) ar = ar_open_tar_archive(stream);
|
||||
if (!ar)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//initial parse
|
||||
while (ar_parse_entry(ar))
|
||||
{
|
||||
numFiles++;
|
||||
fileNames.append(ar_entry_get_name(ar));
|
||||
offsets.append(ar_entry_get_offset(ar));
|
||||
}
|
||||
if (numFiles > 0)
|
||||
{
|
||||
valid = true;
|
||||
tools = true;
|
||||
}
|
||||
}
|
||||
|
||||
CompressedArchive::~CompressedArchive()
|
||||
{
|
||||
ar_close_archive(ar);
|
||||
ar_close(stream);
|
||||
}
|
||||
|
||||
QList<QString> CompressedArchive::getFileNames()
|
||||
{
|
||||
return fileNames;
|
||||
}
|
||||
|
||||
bool CompressedArchive::isValid()
|
||||
{
|
||||
return valid;
|
||||
}
|
||||
|
||||
bool CompressedArchive::toolsLoaded()
|
||||
{
|
||||
return tools;
|
||||
}
|
||||
|
||||
int CompressedArchive::getNumFiles()
|
||||
{
|
||||
return numFiles;
|
||||
}
|
||||
|
||||
void CompressedArchive::getAllData(const QVector<quint32> & indexes, ExtractDelegate * delegate)
|
||||
{
|
||||
if (indexes.isEmpty())
|
||||
return;
|
||||
|
||||
QByteArray buffer;
|
||||
|
||||
int i=0;
|
||||
while (i < indexes.count())
|
||||
{
|
||||
if (i==0)
|
||||
{
|
||||
ar_parse_entry_at(ar, offsets.at(indexes.at(0))); //set ar_entry to start of indexes
|
||||
}
|
||||
else
|
||||
{
|
||||
ar_parse_entry(ar);
|
||||
}
|
||||
buffer.resize(ar_entry_get_size(ar));
|
||||
ar_entry_uncompress(ar, buffer.data(), buffer.size());
|
||||
delegate->fileExtracted(indexes.at(i), buffer); //return extracted files :)
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray CompressedArchive::getRawDataAtIndex(int index)
|
||||
{
|
||||
QByteArray buffer;
|
||||
if(index >= 0 && index < getNumFiles())
|
||||
{
|
||||
ar_parse_entry_at(ar, offsets.at(index));
|
||||
while (ar_entry_get_size(ar)==0)
|
||||
{
|
||||
ar_parse_entry(ar);
|
||||
}
|
||||
buffer.resize(ar_entry_get_size(ar));
|
||||
ar_entry_uncompress(ar, buffer.data(), buffer.size());
|
||||
//return buffer;
|
||||
}
|
||||
return buffer;
|
||||
}
|
37
compressed_archive/unarr/compressed_archive.h
Normal file
37
compressed_archive/unarr/compressed_archive.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef COMPRESSED_ARCHIVE_H
|
||||
#define COMPRESSED_ARCHIVE_H
|
||||
|
||||
#include <QObject>
|
||||
#include "extract_delegate.h"
|
||||
extern"C" {
|
||||
#include "unarr.h"
|
||||
}
|
||||
|
||||
class CompressedArchive : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CompressedArchive(const QString & filePath, QObject *parent = 0);
|
||||
~CompressedArchive();
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
int getNumFiles();
|
||||
void getAllData(const QVector<quint32> & indexes, ExtractDelegate * delegate=0);
|
||||
QByteArray getRawDataAtIndex(int index);
|
||||
QList<QString> getFileNames();
|
||||
bool isValid();
|
||||
bool toolsLoaded();
|
||||
private:
|
||||
|
||||
bool tools;
|
||||
bool valid;
|
||||
QList<QString> fileNames;
|
||||
int numFiles;
|
||||
ar_archive *ar;
|
||||
ar_stream *stream;
|
||||
QList<qint64> offsets;
|
||||
};
|
||||
|
||||
#endif // COMPRESSED_ARCHIVE_H
|
14
compressed_archive/unarr/extract_delegate.h
Normal file
14
compressed_archive/unarr/extract_delegate.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef EXTRACT_DELEGATE_H
|
||||
#define EXTRACT_DELEGATE_H
|
||||
|
||||
#include <QByteArray>
|
||||
|
||||
class ExtractDelegate
|
||||
{
|
||||
public:
|
||||
virtual void fileExtracted(int index, const QByteArray & rawData) = 0;
|
||||
virtual void crcError(int index) = 0;
|
||||
virtual void unknownError(int index) = 0;
|
||||
};
|
||||
|
||||
#endif //EXTRACT_DELEGATE_H
|
13
compressed_archive/unarr/unarr-wrapper.pri
Normal file
13
compressed_archive/unarr/unarr-wrapper.pri
Normal file
@ -0,0 +1,13 @@
|
||||
INCLUDEPATH += $$PWD
|
||||
DEPENDPATH += $$PWD
|
||||
|
||||
HEADERS += $$PWD/extract_delegate.h \
|
||||
$$PWD/compressed_archive.h \
|
||||
|
||||
SOURCES += $$PWD/compressed_archive.cpp \
|
||||
|
||||
#static build (no lib)
|
||||
include(unarr.pro)
|
||||
|
||||
#for system libunarr.so
|
||||
#LIBS+=-lunarr
|
Loading…
x
Reference in New Issue
Block a user