Revert "Backout changeset c42e71e42d7968ddb6c63fd39011669503b9122c"

This reverts commit 040664d3ba.
This commit is contained in:
Felix Kauselmann
2018-05-23 17:44:32 +02:00
committed by Luis Ángel San Martín
parent 68ae40fda7
commit cc71f419cc
2 changed files with 473 additions and 438 deletions

View File

@ -381,8 +381,8 @@ Render::Render()
Render::~Render() Render::~Render()
{ {
if (comic != nullptr) { if (comic != 0) {
comic->moveToThread(QApplication::instance()->thread()); //comic->moveToThread(QApplication::instance()->thread());
comic->deleteLater(); comic->deleteLater();
} }
@ -607,8 +607,8 @@ void Render::setRotation(int degrees)
void Render::setComic(Comic *c) void Render::setComic(Comic *c)
{ {
if (comic != nullptr) { if (comic != 0) {
comic->moveToThread(QApplication::instance()->thread()); //comic->moveToThread(QApplication::instance()->thread());
comic->disconnect(); comic->disconnect();
comic->deleteLater(); comic->deleteLater();
} }

View File

@ -234,6 +234,21 @@ void Comic::updateBookmarkImage(int index)
emit bookmarksUpdated(); emit bookmarksUpdated();
//emit bookmarksLoaded(*bm); //emit bookmarksLoaded(*bm);
} }
if (bm->isBookmark(index)) {
QImage p;
p.loadFromData(_pages[index]);
bm->setBookmark(index, p);
emit bookmarksUpdated();
//emit bookmarksLoaded(*bm);
}
if (bm->getLastPage() == index) {
QImage p;
p.loadFromData(_pages[index]);
bm->setLastPage(index, p);
emit bookmarksUpdated();
//emit bookmarksLoaded(*bm);
}
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Comic::setPageLoaded(int page) void Comic::setPageLoaded(int page)
@ -378,7 +393,7 @@ bool FileComic::load(const QString &path, const ComicDB &comic)
return true; return true;
} else { } else {
//QMessageBox::critical(NULL,tr("Not found"),tr("Comic not found")+" : " + path); //QMessageBox::critical(NULL,tr("Not found"),tr("Comic not found")+" : " + path);
moveToThread(QCoreApplication::instance()->thread()); //moveToThread(QCoreApplication::instance()->thread());
emit errorOpening(); emit errorOpening();
return false; return false;
} }
@ -502,6 +517,26 @@ QList<QVector<quint32>> FileComic::getSections(int &sectionIndex)
idx++; idx++;
} }
if (sectionIndex == sectionCount) //found
{
if (section.indexOf(realIdx) != 0) {
QVector<quint32> section1;
QVector<quint32> section2;
foreach (quint32 si, section) {
if (si < realIdx) {
section1.append(si);
} else {
section2.append(si);
}
}
sectionIndex++;
sections.append(section1);
sections.append(section2);
//out << "SPLIT" << endl;
idx++;
}
if (sectionIndex == sectionCount) //found if (sectionIndex == sectionCount) //found
{ {
if (section.indexOf(realIdx) != 0) { if (section.indexOf(realIdx) != 0) {
@ -528,19 +563,19 @@ QList<QVector<quint32>> FileComic::getSections(int &sectionIndex)
//out << "se han encontrado : " << sections.count() << " sectionIndex : " << sectionIndex << endl; //out << "se han encontrado : " << sections.count() << " sectionIndex : " << sectionIndex << endl;
return sections; return sections;
} }
void FileComic::process() void FileComic::process()
{ {
CompressedArchive archive(_path); CompressedArchive archive(_path);
if (!archive.toolsLoaded()) { if (!archive.toolsLoaded()) {
moveToThread(QCoreApplication::instance()->thread()); //moveToThread(QCoreApplication::instance()->thread());
emit errorOpening(tr("7z not found")); emit errorOpening(tr("7z not found"));
return; return;
} }
if (!archive.isValid()) { if (!archive.isValid()) {
moveToThread(QCoreApplication::instance()->thread()); //moveToThread(QCoreApplication::instance()->thread());
emit errorOpening(tr("Format not supported")); emit errorOpening(tr("Format not supported"));
return; return;
} }
@ -551,7 +586,7 @@ void FileComic::process()
if (_fileNames.size() == 0) { if (_fileNames.size() == 0) {
//QMessageBox::critical(NULL,tr("File error"),tr("File not found or not images in file")); //QMessageBox::critical(NULL,tr("File error"),tr("File not found or not images in file"));
moveToThread(QCoreApplication::instance()->thread()); //moveToThread(QCoreApplication::instance()->thread());
emit errorOpening(); emit errorOpening();
return; return;
} }
@ -587,14 +622,14 @@ void FileComic::process()
for (int i = sectionIndex; i < sections.count(); i++) { for (int i = sectionIndex; i < sections.count(); i++) {
if (_invalidated) { if (_invalidated) {
moveToThread(QCoreApplication::instance()->thread()); //moveToThread(QCoreApplication::instance()->thread());
return; return;
} }
archive.getAllData(sections.at(i), this); archive.getAllData(sections.at(i), this);
} }
for (int i = 0; i < sectionIndex; i++) { for (int i = 0; i < sectionIndex; i++) {
if (_invalidated) { if (_invalidated) {
moveToThread(QCoreApplication::instance()->thread()); //moveToThread(QCoreApplication::instance()->thread());
return; return;
} }
archive.getAllData(sections.at(i), this); archive.getAllData(sections.at(i), this);
@ -609,31 +644,31 @@ void FileComic::process()
emit imageLoaded(sortedIndex); emit imageLoaded(sortedIndex);
emit imageLoaded(sortedIndex,_pages[sortedIndex]); emit imageLoaded(sortedIndex,_pages[sortedIndex]);
}*/ }*/
moveToThread(QCoreApplication::instance()->thread()); //moveToThread(QCoreApplication::instance()->thread());
emit imagesLoaded(); emit imagesLoaded();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
FolderComic::FolderComic() FolderComic::FolderComic()
: Comic() : Comic()
{ {
} }
FolderComic::FolderComic(const QString &path, int atPage) FolderComic::FolderComic(const QString &path, int atPage)
: Comic(path, atPage) : Comic(path, atPage)
{ {
load(path, atPage); load(path, atPage);
} }
FolderComic::~FolderComic() FolderComic::~FolderComic()
{ {
} }
bool FolderComic::load(const QString &path, int atPage) bool FolderComic::load(const QString &path, int atPage)
{ {
_path = path; _path = path;
if (atPage == -1) { if (atPage == -1) {
bm->newComic(_path); bm->newComic(_path);
@ -642,10 +677,10 @@ bool FolderComic::load(const QString &path, int atPage)
_firstPage = atPage; _firstPage = atPage;
//emit bookmarksLoaded(*bm); //emit bookmarksLoaded(*bm);
return true; return true;
} }
void FolderComic::process() void FolderComic::process()
{ {
QDir d(_path); QDir d(_path);
d.setNameFilters(getSupportedImageFormats()); d.setNameFilters(getSupportedImageFormats());
@ -664,7 +699,7 @@ void FolderComic::process()
if (nPages == 0) { if (nPages == 0) {
//TODO emitir este mensaje en otro sitio //TODO emitir este mensaje en otro sitio
//QMessageBox::critical(NULL,QObject::tr("No images found"),QObject::tr("There are not images on the selected folder")); //QMessageBox::critical(NULL,QObject::tr("No images found"),QObject::tr("There are not images on the selected folder"));
moveToThread(QCoreApplication::instance()->thread()); //moveToThread(QCoreApplication::instance()->thread());
emit errorOpening(); emit errorOpening();
} else { } else {
if (_firstPage == -1) { if (_firstPage == -1) {
@ -687,7 +722,7 @@ void FolderComic::process()
int i = _firstPage; int i = _firstPage;
while (count < nPages) { while (count < nPages) {
if (_invalidated) { if (_invalidated) {
moveToThread(QCoreApplication::instance()->thread()); //moveToThread(QCoreApplication::instance()->thread());
return; return;
} }
@ -703,33 +738,33 @@ void FolderComic::process()
count++; count++;
} }
} }
moveToThread(QCoreApplication::instance()->thread()); //moveToThread(QCoreApplication::instance()->thread());
emit imagesLoaded(); emit imagesLoaded();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#ifndef NO_PDF #ifndef NO_PDF
PDFComic::PDFComic() PDFComic::PDFComic()
: Comic() : Comic()
{ {
} }
PDFComic::PDFComic(const QString &path, int atPage) PDFComic::PDFComic(const QString &path, int atPage)
: Comic(path, atPage) : Comic(path, atPage)
{ {
load(path, atPage); load(path, atPage);
} }
PDFComic::~PDFComic() PDFComic::~PDFComic()
{ {
} }
bool PDFComic::load(const QString &path, int atPage) bool PDFComic::load(const QString &path, int atPage)
{ {
QFileInfo fi(path); QFileInfo fi(path);
if (fi.exists()) { if (fi.exists()) {
@ -742,14 +777,14 @@ bool PDFComic::load(const QString &path, int atPage)
//emit bookmarksLoaded(*bm); //emit bookmarksLoaded(*bm);
return true; return true;
} else { } else {
moveToThread(QCoreApplication::instance()->thread()); //moveToThread(QCoreApplication::instance()->thread());
emit errorOpening(); emit errorOpening();
return false; return false;
} }
} }
bool PDFComic::load(const QString &path, const ComicDB &comic) bool PDFComic::load(const QString &path, const ComicDB &comic)
{ {
QFileInfo fi(path); QFileInfo fi(path);
if (fi.exists()) { if (fi.exists()) {
@ -763,14 +798,14 @@ bool PDFComic::load(const QString &path, const ComicDB &comic)
return true; return true;
} else { } else {
//QMessageBox::critical(NULL,tr("Not found"),tr("Comic not found")+" : " + path); //QMessageBox::critical(NULL,tr("Not found"),tr("Comic not found")+" : " + path);
moveToThread(QCoreApplication::instance()->thread()); //moveToThread(QCoreApplication::instance()->thread());
emit errorOpening(); emit errorOpening();
return false; return false;
} }
} }
void PDFComic::process() void PDFComic::process()
{ {
#if defined Q_OS_MAC && defined USE_PDFKIT #if defined Q_OS_MAC && defined USE_PDFKIT
pdfComic = new MacOSXPDFComic(); pdfComic = new MacOSXPDFComic();
if (!pdfComic->openComic(_path)) { if (!pdfComic->openComic(_path)) {
@ -790,12 +825,12 @@ void PDFComic::process()
if (!pdfComic) { if (!pdfComic) {
//delete pdfComic; //delete pdfComic;
//pdfComic = 0; //pdfComic = 0;
moveToThread(QCoreApplication::instance()->thread()); //moveToThread(QCoreApplication::instance()->thread());
emit errorOpening(); emit errorOpening();
return; return;
} }
if (pdfComic->isLocked()) { if (pdfComic->isLocked()) {
moveToThread(QCoreApplication::instance()->thread()); //moveToThread(QCoreApplication::instance()->thread());
emit errorOpening(); emit errorOpening();
return; return;
} }
@ -830,7 +865,7 @@ void PDFComic::process()
for (int i = buffered_index; i < nPages; i++) { for (int i = buffered_index; i < nPages; i++) {
if (_invalidated) { if (_invalidated) {
delete pdfComic; delete pdfComic;
moveToThread(QCoreApplication::instance()->thread()); //moveToThread(QCoreApplication::instance()->thread());
return; return;
} }
@ -839,19 +874,19 @@ void PDFComic::process()
for (int i = 0; i < buffered_index; i++) { for (int i = 0; i < buffered_index; i++) {
if (_invalidated) { if (_invalidated) {
delete pdfComic; delete pdfComic;
moveToThread(QCoreApplication::instance()->thread()); //moveToThread(QCoreApplication::instance()->thread());
return; return;
} }
renderPage(i); renderPage(i);
} }
delete pdfComic; delete pdfComic;
moveToThread(QCoreApplication::instance()->thread()); //moveToThread(QCoreApplication::instance()->thread());
emit imagesLoaded(); emit imagesLoaded();
} }
void PDFComic::renderPage(int page) void PDFComic::renderPage(int page)
{ {
#if defined Q_OS_MAC && defined USE_PDFKIT #if defined Q_OS_MAC && defined USE_PDFKIT
QImage img = pdfComic->getPage(page); QImage img = pdfComic->getPage(page);
if (!img.isNull()) { if (!img.isNull()) {
@ -871,12 +906,12 @@ void PDFComic::renderPage(int page)
emit imageLoaded(page); emit imageLoaded(page);
emit imageLoaded(page, _pages[page]); emit imageLoaded(page, _pages[page]);
} }
} }
#endif //NO_PDF #endif //NO_PDF
Comic *FactoryComic::newComic(const QString &path) Comic *FactoryComic::newComic(const QString &path)
{ {
QFileInfo fi(path); QFileInfo fi(path);
if (fi.exists()) { if (fi.exists()) {
@ -899,10 +934,10 @@ Comic *FactoryComic::newComic(const QString &path)
} }
} else } else
return NULL; return NULL;
} }
bool is_double_page(const QString &pageName, const QString &commonPrefix, const int maxExpectedDoublePagesNumberLenght) bool is_double_page(const QString &pageName, const QString &commonPrefix, const int maxExpectedDoublePagesNumberLenght)
{ {
if (pageName.startsWith(commonPrefix)) { if (pageName.startsWith(commonPrefix)) {
QString substringContainingPageNumbers = pageName.mid(commonPrefix.length()); QString substringContainingPageNumbers = pageName.mid(commonPrefix.length());
QString pageNumbersSubString; QString pageNumbersSubString;
@ -924,10 +959,10 @@ bool is_double_page(const QString &pageName, const QString &commonPrefix, const
} }
} }
return false; return false;
} }
QString get_most_common_prefix(const QList<QString> &pageNames) QString get_most_common_prefix(const QList<QString> &pageNames)
{ {
if (pageNames.isEmpty()) { if (pageNames.isEmpty()) {
return ""; return "";
} }
@ -988,10 +1023,10 @@ QString get_most_common_prefix(const QList<QString> &pageNames)
} }
return common_prefix; return common_prefix;
} }
void get_double_pages(const QList<QString> &pageNames, QList<QString> &singlePageNames /*out*/, QList<QString> &doublePageNames /*out*/) void get_double_pages(const QList<QString> &pageNames, QList<QString> &singlePageNames /*out*/, QList<QString> &doublePageNames /*out*/)
{ {
uint maxExpectedDoublePagesNumberLenght = (int)(log10(pageNames.length()) + 1) * 2; uint maxExpectedDoublePagesNumberLenght = (int)(log10(pageNames.length()) + 1) * 2;
QString mostCommonPrefix = get_most_common_prefix(pageNames); QString mostCommonPrefix = get_most_common_prefix(pageNames);
@ -1003,10 +1038,10 @@ void get_double_pages(const QList<QString> &pageNames, QList<QString> &singlePag
singlePageNames.append(pageName); singlePageNames.append(pageName);
} }
} }
} }
QList<QString> merge_pages(QList<QString> &singlePageNames, QList<QString> &doublePageNames) QList<QString> merge_pages(QList<QString> & singlePageNames, QList<QString> & doublePageNames)
{ {
//NOTE: this implementation doesn't differ from std::merge using a custom comparator, but it can be easily tweaked if merging requeries an additional heuristic behaviour //NOTE: this implementation doesn't differ from std::merge using a custom comparator, but it can be easily tweaked if merging requeries an additional heuristic behaviour
QList<QString> pageNames; QList<QString> pageNames;
@ -1030,10 +1065,10 @@ QList<QString> merge_pages(QList<QString> &singlePageNames, QList<QString> &doub
} }
return pageNames; return pageNames;
} }
void comic_pages_sort(QList<QString> &pageNames, YACReaderPageSortingMode sortingMode) void comic_pages_sort(QList<QString> & pageNames, YACReaderPageSortingMode sortingMode)
{ {
switch (sortingMode) { switch (sortingMode) {
case YACReaderNumericalSorting: case YACReaderNumericalSorting:
std::sort(pageNames.begin(), pageNames.end(), naturalSortLessThanCI); std::sort(pageNames.begin(), pageNames.end(), naturalSortLessThanCI);
@ -1056,4 +1091,4 @@ void comic_pages_sort(QList<QString> &pageNames, YACReaderPageSortingMode sortin
std::sort(pageNames.begin(), pageNames.end()); std::sort(pageNames.begin(), pageNames.end());
break; break;
} }
} }