mirror of
https://github.com/YACReader/yacreader
synced 2025-07-22 06:54:39 -04:00
fixed build issues
This commit is contained in:
@ -29,7 +29,7 @@ CONFIG += release
|
||||
CONFIG -= flat
|
||||
|
||||
# Input
|
||||
HEADERS += $$PWD/comic.h \
|
||||
HEADERS += $$PWD/../common/comic.h \
|
||||
$$PWD/configuration.h \
|
||||
$$PWD/goto_dialog.h \
|
||||
$$PWD/magnifying_glass.h \
|
||||
@ -37,7 +37,7 @@ HEADERS += $$PWD/comic.h \
|
||||
$$PWD/viewer.h \
|
||||
$$PWD/goto_flow.h \
|
||||
$$PWD/options_dialog.h \
|
||||
$$PWD/bookmarks.h \
|
||||
$$PWD/../common/bookmarks.h \
|
||||
$$PWD/bookmarks_dialog.h \
|
||||
$$PWD/render.h \
|
||||
$$PWD/shortcuts_dialog.h \
|
||||
@ -62,7 +62,7 @@ HEADERS += $$PWD/comic.h \
|
||||
$$PWD/yacreader_local_client.h \
|
||||
$$PWD/../common/http_worker.h
|
||||
|
||||
SOURCES += $$PWD/comic.cpp \
|
||||
SOURCES += $$PWD/../common/comic.cpp \
|
||||
$$PWD/configuration.cpp \
|
||||
$$PWD/goto_dialog.cpp \
|
||||
$$PWD/magnifying_glass.cpp \
|
||||
@ -70,7 +70,7 @@ SOURCES += $$PWD/comic.cpp \
|
||||
$$PWD/viewer.cpp \
|
||||
$$PWD/goto_flow.cpp \
|
||||
$$PWD/options_dialog.cpp \
|
||||
$$PWD/bookmarks.cpp \
|
||||
$$PWD/../common/bookmarks.cpp \
|
||||
$$PWD/bookmarks_dialog.cpp \
|
||||
$$PWD/render.cpp \
|
||||
$$PWD/shortcuts_dialog.cpp \
|
||||
|
@ -1,172 +0,0 @@
|
||||
#include "bookmarks.h"
|
||||
#include <QFile>
|
||||
#include <QDataStream>
|
||||
#include <QCoreApplication>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QList>
|
||||
|
||||
Bookmarks::Bookmarks()
|
||||
:lastPageIndex(0)
|
||||
{
|
||||
list.load();
|
||||
}
|
||||
void Bookmarks::setLastPage(int index,const QImage & page)
|
||||
{
|
||||
lastPageIndex = index;
|
||||
lastPage = page;
|
||||
}
|
||||
void Bookmarks::setBookmark(int index,const QImage & page)
|
||||
{
|
||||
if(!bookmarks.contains(index))
|
||||
{
|
||||
bookmarks.insert(index,page);
|
||||
latestBookmarks.push_front(index);
|
||||
if(latestBookmarks.count()>3)
|
||||
{
|
||||
bookmarks.remove(latestBookmarks.back());
|
||||
latestBookmarks.pop_back();
|
||||
}
|
||||
}
|
||||
else //udate de pixmap;
|
||||
{
|
||||
bookmarks[index]=page;
|
||||
}
|
||||
}
|
||||
|
||||
void Bookmarks::removeBookmark(int index)
|
||||
{
|
||||
bookmarks.remove(index);
|
||||
}
|
||||
|
||||
QList<int> Bookmarks::getBookmarkPages() const
|
||||
{
|
||||
return bookmarks.keys();
|
||||
}
|
||||
|
||||
QImage Bookmarks::getBookmarkPixmap(int page) const
|
||||
{
|
||||
return bookmarks.value(page);
|
||||
}
|
||||
|
||||
QImage Bookmarks::getLastPagePixmap() const
|
||||
{
|
||||
return lastPage;
|
||||
}
|
||||
|
||||
int Bookmarks::getLastPage() const
|
||||
{
|
||||
return lastPageIndex;
|
||||
}
|
||||
|
||||
|
||||
bool Bookmarks::isBookmark(int page)
|
||||
{
|
||||
return bookmarks.contains(page);
|
||||
}
|
||||
|
||||
bool Bookmarks::imageLoaded(int page)
|
||||
{
|
||||
return !bookmarks.value(page).isNull();
|
||||
}
|
||||
|
||||
void Bookmarks::newComic(const QString & path)
|
||||
{
|
||||
QFileInfo f(path);
|
||||
QString comicID = f.fileName().toLower()+QString::number(f.size());
|
||||
clear();
|
||||
BookmarksList::Bookmark b = list.get(comicID);
|
||||
comicPath=comicID;
|
||||
lastPageIndex = b.lastPage;
|
||||
latestBookmarks = b.bookmarks;
|
||||
for(int i=0;i<latestBookmarks.count();i++)
|
||||
bookmarks.insert(latestBookmarks.at(i),QImage());
|
||||
added = b.added;
|
||||
}
|
||||
|
||||
void Bookmarks::clear()
|
||||
{
|
||||
bookmarks.clear();
|
||||
latestBookmarks.clear();
|
||||
lastPageIndex=0;
|
||||
lastPage = QImage();
|
||||
}
|
||||
|
||||
bool Bookmarks::load(const QList<int> & bookmarkIndexes, int lastPage)
|
||||
{
|
||||
lastPageIndex = lastPage;
|
||||
foreach(int b, bookmarkIndexes)
|
||||
if(b != -1)
|
||||
{
|
||||
latestBookmarks.push_back(b);
|
||||
bookmarks.insert(b,QImage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Bookmarks::save()
|
||||
{
|
||||
BookmarksList::Bookmark b;
|
||||
b.lastPage = lastPageIndex;
|
||||
b.bookmarks = getBookmarkPages();
|
||||
|
||||
BookmarksList::Bookmark previousBookmarks;
|
||||
bool updated = ((previousBookmarks.lastPage != b.lastPage) || (previousBookmarks.bookmarks != b.bookmarks));
|
||||
|
||||
if(b.added.isNull() || updated)
|
||||
b.added = QDateTime::currentDateTime();
|
||||
list.add(comicPath,b);
|
||||
list.save();
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
void BookmarksList::load()
|
||||
{
|
||||
QFile f(QCoreApplication::applicationDirPath()+"/bookmarks.yacr");
|
||||
if(f.open(QIODevice::ReadOnly))
|
||||
{
|
||||
QDataStream dataS(&f);
|
||||
dataS >> list;
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarksList::save()
|
||||
{
|
||||
QFile f(QCoreApplication::applicationDirPath()+"/bookmarks.yacr");
|
||||
f.open(QIODevice::WriteOnly);
|
||||
QDataStream dataS(&f);
|
||||
if(list.count()>numMaxBookmarks)
|
||||
deleteOldest(list.count()-numMaxBookmarks);
|
||||
dataS << list;
|
||||
f.close();
|
||||
}
|
||||
|
||||
|
||||
void BookmarksList::deleteOldest(int num)
|
||||
{
|
||||
Q_UNUSED(num)
|
||||
QString comic;
|
||||
QDateTime date(QDate(10000,1,1));//TODO MAX_DATE??
|
||||
for(QMap<QString,Bookmark>::const_iterator itr=list.begin();itr!=list.end();itr++)
|
||||
{
|
||||
if(itr->added<date)
|
||||
{
|
||||
comic=itr.key();
|
||||
date = itr->added;
|
||||
}
|
||||
}
|
||||
list.remove(comic);
|
||||
}
|
||||
|
||||
void BookmarksList::add(const QString & comicID, const Bookmark & b)
|
||||
{
|
||||
list.insert(comicID,b);
|
||||
}
|
||||
|
||||
BookmarksList::Bookmark BookmarksList::get(const QString & comicID)
|
||||
{
|
||||
//if(list.contains(comicID)
|
||||
return list.value(comicID);
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
#ifndef BOOKMARKS_H
|
||||
#define BOOKMARKS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QMap>
|
||||
#include <QImage>
|
||||
#include <QString>
|
||||
#include <QMap>
|
||||
#include <QDateTime>
|
||||
class BookmarksList
|
||||
{
|
||||
public:
|
||||
struct Bookmark {
|
||||
int lastPage;
|
||||
QList<int> bookmarks;
|
||||
QDateTime added;
|
||||
Bookmark():lastPage(0){};
|
||||
friend QDataStream & operator<< ( QDataStream & out, const Bookmark & bm )
|
||||
{
|
||||
out << bm.lastPage;
|
||||
out << bm.bookmarks;
|
||||
out << bm.added;
|
||||
return out;
|
||||
}
|
||||
friend QDataStream & operator>> ( QDataStream & in, Bookmark & bm )
|
||||
{
|
||||
in >> bm.lastPage;
|
||||
in >> bm.bookmarks;
|
||||
in >> bm.added;
|
||||
return in;
|
||||
}
|
||||
|
||||
};
|
||||
BookmarksList():numMaxBookmarks(400){}
|
||||
void load();
|
||||
void save();
|
||||
void add(const QString & comicID, const Bookmark & b);
|
||||
Bookmark get(const QString & comicID);
|
||||
protected:
|
||||
QMap<QString,Bookmark> list;
|
||||
void deleteOldest(int num);
|
||||
private:
|
||||
int numMaxBookmarks;
|
||||
|
||||
};
|
||||
|
||||
class Bookmarks : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
QString comicPath;
|
||||
//bookmarks setted by the user
|
||||
QMap<int,QImage> bookmarks;
|
||||
QList<int> latestBookmarks;
|
||||
//last page readed
|
||||
int lastPageIndex;
|
||||
QImage lastPage;
|
||||
BookmarksList list;
|
||||
QDateTime added;
|
||||
|
||||
public:
|
||||
Bookmarks();
|
||||
void setLastPage(int index,const QImage & page);
|
||||
void setBookmark(int index,const QImage & page);
|
||||
void removeBookmark(int index);
|
||||
QList<int> getBookmarkPages() const;
|
||||
QImage getBookmarkPixmap(int page) const;
|
||||
QImage getLastPagePixmap() const;
|
||||
int getLastPage() const;
|
||||
bool isBookmark(int page);
|
||||
bool imageLoaded(int page);
|
||||
void newComic(const QString & path);
|
||||
void clear();
|
||||
void save();
|
||||
bool load(const QList<int> & bookmarkIndexes, int lastPage);
|
||||
|
||||
};
|
||||
|
||||
#endif // BOOKMARKS_H
|
@ -1,701 +0,0 @@
|
||||
#include "comic.h"
|
||||
|
||||
#include <QPixmap>
|
||||
#include <QRegExp>
|
||||
#include <QString>
|
||||
#include <algorithm>
|
||||
#include <QDir>
|
||||
#include <QFileInfoList>
|
||||
#include "bookmarks.h" //TODO desacoplar la dependencia con bookmarks
|
||||
#include "qnaturalsorting.h"
|
||||
#include "compressed_archive.h"
|
||||
#include "comic_db.h"
|
||||
|
||||
QStringList Comic::extensions = QStringList() << "*.jpg" << "*.jpeg" << "*.png" << "*.gif" << "*.tiff" << "*.tif" << "*.bmp";
|
||||
QStringList Comic::literalExtensions = QStringList() << ".jpg" << ".jpeg" << ".png" << ".gif" << ".tiff" << ".tif" << ".bmp";
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
Comic::Comic()
|
||||
:_pages(),_index(0),_path(),_loaded(false),bm(new Bookmarks()),_loadedPages(),_isPDF(false)
|
||||
{
|
||||
setup();
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
Comic::Comic(const QString & pathFile, int atPage )
|
||||
:_pages(),_index(0),_path(pathFile),_loaded(false),bm(new Bookmarks()),_loadedPages(),_isPDF(false),_firstPage(atPage)
|
||||
{
|
||||
setup();
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
Comic::~Comic()
|
||||
{
|
||||
delete bm;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
void Comic::setup()
|
||||
{
|
||||
connect(this,SIGNAL(pageChanged(int)),this,SLOT(checkIsBookmark(int)));
|
||||
connect(this,SIGNAL(imageLoaded(int)),this,SLOT(updateBookmarkImage(int)));
|
||||
connect(this,SIGNAL(imageLoaded(int)),this,SLOT(setPageLoaded(int)));
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
int Comic::nextPage()
|
||||
{
|
||||
if(_index<_pages.size()-1)
|
||||
{
|
||||
_index++;
|
||||
|
||||
emit pageChanged(_index);
|
||||
}
|
||||
else
|
||||
emit isLast();
|
||||
return _index;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
int Comic::previousPage()
|
||||
{
|
||||
if(_index>0)
|
||||
{
|
||||
_index--;
|
||||
|
||||
emit pageChanged(_index);
|
||||
}
|
||||
else
|
||||
emit isCover();
|
||||
|
||||
return _index;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
void Comic::setIndex(unsigned int index)
|
||||
{
|
||||
int previousIndex = _index;
|
||||
if(static_cast<int>(index)<_pages.size()-1)
|
||||
_index = index;
|
||||
else
|
||||
_index = _pages.size()-1;
|
||||
|
||||
if(previousIndex != _index)
|
||||
emit pageChanged(_index);
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
/*QPixmap * Comic::currentPage()
|
||||
{
|
||||
QPixmap * p = new QPixmap();
|
||||
p->loadFromData(_pages[_index]);
|
||||
return p;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
QPixmap * Comic::operator[](unsigned int index)
|
||||
{
|
||||
QPixmap * p = new QPixmap();
|
||||
p->loadFromData(_pages[index]);
|
||||
return p;
|
||||
}*/
|
||||
bool Comic::load(const QString & path, const ComicDB & comic)
|
||||
{
|
||||
Q_UNUSED(path);
|
||||
Q_UNUSED(comic);
|
||||
return false;
|
||||
};
|
||||
//-----------------------------------------------------------------------------
|
||||
bool Comic::loaded()
|
||||
{
|
||||
return _loaded;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
void Comic::loadFinished()
|
||||
{
|
||||
emit imagesLoaded();
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
void Comic::setBookmark()
|
||||
{
|
||||
QImage p;
|
||||
p.loadFromData(_pages[_index]);
|
||||
bm->setBookmark(_index,p);
|
||||
//emit bookmarksLoaded(*bm);
|
||||
emit bookmarksUpdated();
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
void Comic::removeBookmark()
|
||||
{
|
||||
bm->removeBookmark(_index);
|
||||
//emit bookmarksLoaded(*bm);
|
||||
emit bookmarksUpdated();
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
void Comic::saveBookmarks()
|
||||
{
|
||||
QImage p;
|
||||
p.loadFromData(_pages[_index]);
|
||||
bm->setLastPage(_index,p);
|
||||
bm->save();
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
void Comic::checkIsBookmark(int index)
|
||||
{
|
||||
emit isBookmark(bm->isBookmark(index));
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
void Comic::updateBookmarkImage(int index)
|
||||
{
|
||||
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)
|
||||
{
|
||||
_loadedPages[page] = true;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
QByteArray Comic::getRawPage(int page)
|
||||
{
|
||||
if(page < 0 || page >= _pages.size())
|
||||
return QByteArray();
|
||||
return _pages[page];
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
bool Comic::pageIsLoaded(int page)
|
||||
{
|
||||
if(page < 0 || page >= _pages.size())
|
||||
return false;
|
||||
return _loadedPages[page];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
FileComic::FileComic()
|
||||
:Comic()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
FileComic::FileComic(const QString & path, int atPage )
|
||||
:Comic(path,atPage)
|
||||
{
|
||||
load(path,atPage);
|
||||
}
|
||||
|
||||
FileComic::~FileComic()
|
||||
{
|
||||
_pages.clear();
|
||||
_loadedPages.clear();
|
||||
_fileNames.clear();
|
||||
_newOrder.clear();
|
||||
_order.clear();
|
||||
}
|
||||
|
||||
bool FileComic::load(const QString & path, int atPage)
|
||||
{
|
||||
QFileInfo fi(path);
|
||||
|
||||
if(fi.exists())
|
||||
{
|
||||
if(atPage == -1)
|
||||
{
|
||||
bm->newComic(path);
|
||||
emit bookmarksUpdated();
|
||||
}
|
||||
_firstPage = atPage;
|
||||
//emit bookmarksLoaded(*bm);
|
||||
|
||||
_path = QDir::cleanPath(path);
|
||||
//load files size
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//QMessageBox::critical(NULL,tr("Not found"),tr("Comic not found")+" : " + path);
|
||||
emit errorOpening();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool FileComic::load(const QString & path, const ComicDB & comic)
|
||||
{
|
||||
QFileInfo fi(path);
|
||||
|
||||
if(fi.exists())
|
||||
{
|
||||
QList<int> bookmarkIndexes;
|
||||
bookmarkIndexes << comic.info.bookmark1 << comic.info.bookmark2 << comic.info.bookmark3;
|
||||
if(bm->load(bookmarkIndexes,comic.info.currentPage-1))
|
||||
emit bookmarksUpdated();
|
||||
_firstPage = comic.info.currentPage-1;
|
||||
_path = QDir::cleanPath(path);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//QMessageBox::critical(NULL,tr("Not found"),tr("Comic not found")+" : " + path);
|
||||
emit errorOpening();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QList<QString> FileComic::filter(const QList<QString> & src)
|
||||
{
|
||||
QList<QString> extensions = getSupportedImageLiteralFormats();
|
||||
QList<QString> filtered;
|
||||
bool fileAccepted = false;
|
||||
|
||||
foreach(QString fileName,src)
|
||||
{
|
||||
fileAccepted = false;
|
||||
if(!fileName.contains("__MACOSX"))
|
||||
{
|
||||
foreach(QString extension,extensions)
|
||||
{
|
||||
if(fileName.endsWith(extension,Qt::CaseInsensitive))
|
||||
{
|
||||
fileAccepted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(fileAccepted)
|
||||
filtered.append(fileName);
|
||||
}
|
||||
|
||||
return filtered;
|
||||
}
|
||||
|
||||
//DELEGATE methods
|
||||
void FileComic::fileExtracted(int index, const QByteArray & rawData)
|
||||
{
|
||||
/*QFile f("c:/temp/out2.txt");
|
||||
f.open(QIODevice::Append);
|
||||
QTextStream out(&f);*/
|
||||
int sortedIndex = _fileNames.indexOf(_order.at(index));
|
||||
//out << sortedIndex << " , ";
|
||||
//f.close();
|
||||
if(sortedIndex == -1)
|
||||
return;
|
||||
_pages[sortedIndex] = rawData;
|
||||
emit imageLoaded(sortedIndex);
|
||||
emit imageLoaded(sortedIndex,_pages[sortedIndex]);
|
||||
}
|
||||
|
||||
void FileComic::crcError(int index)
|
||||
{
|
||||
emit errorOpening(tr("CRC error on page (%1): some of the pages will not be displayed correctly").arg(index));
|
||||
}
|
||||
|
||||
//TODO: comprobar que si se produce uno de estos errores, la carga del c<>mic es irrecuperable
|
||||
void FileComic::unknownError(int index)
|
||||
{
|
||||
Q_UNUSED(index)
|
||||
//emit errorOpening(tr("Unknown error opening the file"));
|
||||
//emit errorOpening();
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
|
||||
QList<QVector<quint32> > FileComic::getSections(int & sectionIndex)
|
||||
{
|
||||
QVector<quint32> sortedIndexes;
|
||||
foreach(QString name, _fileNames)
|
||||
{
|
||||
sortedIndexes.append(_order.indexOf(name));
|
||||
}
|
||||
QList<QVector <quint32> > sections;
|
||||
quint32 previous = 0;
|
||||
sectionIndex = -1;
|
||||
int sectionCount = 0;
|
||||
QVector <quint32> section;
|
||||
int idx = 0;
|
||||
unsigned int realIdx;
|
||||
foreach(quint32 i, sortedIndexes)
|
||||
{
|
||||
|
||||
if(_firstPage == idx)
|
||||
{
|
||||
sectionIndex = sectionCount;
|
||||
realIdx = i;
|
||||
}
|
||||
if(previous <= i)
|
||||
{
|
||||
//out << "idx : " << i << endl;
|
||||
section.append(i);
|
||||
previous = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
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;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
sections.append(section);
|
||||
}
|
||||
}
|
||||
else
|
||||
sections.append(section);
|
||||
|
||||
section = QVector <quint32> ();
|
||||
//out << "---------------" << endl;
|
||||
section.append(i);
|
||||
//out << "idx : " << i << endl;
|
||||
previous = i;
|
||||
sectionCount++;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
sections.append(section);
|
||||
}
|
||||
}
|
||||
else
|
||||
sections.append(section);
|
||||
|
||||
//out << "se han encontrado : " << sections.count() << " sectionIndex : " << sectionIndex << endl;
|
||||
return sections;
|
||||
}
|
||||
|
||||
void FileComic::process()
|
||||
{
|
||||
CompressedArchive archive(_path);
|
||||
//se filtran para obtener s<>lo los formatos soportados
|
||||
_order = archive.getFileNames();
|
||||
_fileNames = filter(_order);
|
||||
|
||||
if(_fileNames.size()==0)
|
||||
{
|
||||
//QMessageBox::critical(NULL,tr("File error"),tr("File not found or not images in file"));
|
||||
emit errorOpening();
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO, cambiar por listas
|
||||
//_order = _fileNames;
|
||||
|
||||
_pages.resize(_fileNames.size());
|
||||
_loadedPages = QVector<bool>(_fileNames.size(),false);
|
||||
|
||||
emit pageChanged(0); // this indicates new comic, index=0
|
||||
emit numPages(_pages.size());
|
||||
_loaded = true;
|
||||
|
||||
_cfi=0;
|
||||
qSort(_fileNames.begin(),_fileNames.end(), naturalSortLessThanCI);
|
||||
|
||||
if(_firstPage == -1)
|
||||
_firstPage = bm->getLastPage();
|
||||
_index = _firstPage;
|
||||
emit(openAt(_index));
|
||||
|
||||
int sectionIndex;
|
||||
QList<QVector <quint32> > sections = getSections(sectionIndex);
|
||||
|
||||
for(int i = sectionIndex; i<sections.count() ; i++)
|
||||
archive.getAllData(sections.at(i),this);
|
||||
for(int i = 0; i<sectionIndex; i++)
|
||||
archive.getAllData(sections.at(i),this);
|
||||
//archive.getAllData(QVector<quint32>(),this);
|
||||
/*
|
||||
foreach(QString name,_fileNames)
|
||||
{
|
||||
index = _order.indexOf(name);
|
||||
sortedIndex = _fileNames.indexOf(name);
|
||||
_pages[sortedIndex] = allData.at(index);
|
||||
emit imageLoaded(sortedIndex);
|
||||
emit imageLoaded(sortedIndex,_pages[sortedIndex]);
|
||||
}*/
|
||||
|
||||
emit imagesLoaded();
|
||||
//moveToThread(QApplication::instance()->thread());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
FolderComic::FolderComic()
|
||||
:Comic()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
FolderComic::FolderComic(const QString & path, int atPage )
|
||||
:Comic(path, atPage )
|
||||
{
|
||||
load(path, atPage );
|
||||
}
|
||||
|
||||
FolderComic::~FolderComic()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool FolderComic::load(const QString & path, int atPage )
|
||||
{
|
||||
_path = path;
|
||||
if(atPage == -1)
|
||||
{
|
||||
bm->newComic(_path);
|
||||
emit bookmarksUpdated();
|
||||
}
|
||||
_firstPage = atPage;
|
||||
//emit bookmarksLoaded(*bm);
|
||||
return true;
|
||||
}
|
||||
|
||||
void FolderComic::process()
|
||||
{
|
||||
QDir d(_path);
|
||||
|
||||
d.setNameFilters(getSupportedImageFormats());
|
||||
d.setFilter(QDir::Files|QDir::NoDotAndDotDot);
|
||||
//d.setSorting(QDir::Name|QDir::IgnoreCase|QDir::LocaleAware);
|
||||
QFileInfoList list = d.entryInfoList();
|
||||
|
||||
qSort(list.begin(),list.end(),naturalSortLessThanCIFileInfo);
|
||||
|
||||
int nPages = list.size();
|
||||
_pages.clear();
|
||||
_pages.resize(nPages);
|
||||
_loadedPages = QVector<bool>(nPages,false);
|
||||
|
||||
if(nPages==0)
|
||||
{
|
||||
//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"));
|
||||
emit errorOpening();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(_firstPage == -1)
|
||||
_firstPage = bm->getLastPage();
|
||||
|
||||
_index = _firstPage;
|
||||
|
||||
emit(openAt(_index));
|
||||
|
||||
emit pageChanged(0); // this indicates new comic, index=0
|
||||
emit numPages(_pages.size());
|
||||
_loaded = true;
|
||||
|
||||
int count=0;
|
||||
int i=_firstPage;
|
||||
while(count<nPages)
|
||||
{
|
||||
QFile f(list.at(i).absoluteFilePath());
|
||||
f.open(QIODevice::ReadOnly);
|
||||
_pages[i]=f.readAll();
|
||||
emit imageLoaded(i);
|
||||
emit imageLoaded(i,_pages[i]);
|
||||
i++;
|
||||
if(i==nPages)
|
||||
i=0;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
emit imagesLoaded();
|
||||
moveToThread(QApplication::instance()->thread());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PDFComic::PDFComic()
|
||||
:Comic()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PDFComic::PDFComic(const QString & path, int atPage)
|
||||
:Comic(path,atPage)
|
||||
{
|
||||
load(path,atPage);
|
||||
}
|
||||
|
||||
PDFComic::~PDFComic()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool PDFComic::load(const QString & path, int atPage)
|
||||
{
|
||||
QFileInfo fi(path);
|
||||
|
||||
if(fi.exists())
|
||||
{
|
||||
_path = path;
|
||||
if(atPage == -1)
|
||||
{
|
||||
bm->newComic(_path);
|
||||
emit bookmarksUpdated();
|
||||
}
|
||||
_firstPage = atPage;
|
||||
//emit bookmarksLoaded(*bm);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
emit errorOpening();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool PDFComic::load(const QString & path, const ComicDB & comic)
|
||||
{
|
||||
QFileInfo fi(path);
|
||||
|
||||
if(fi.exists())
|
||||
{
|
||||
QList<int> bookmarkIndexes;
|
||||
bookmarkIndexes << comic.info.bookmark1 << comic.info.bookmark2 << comic.info.bookmark3;
|
||||
if(bm->load(bookmarkIndexes,comic.info.currentPage-1))
|
||||
emit bookmarksUpdated();
|
||||
_firstPage = comic.info.currentPage-1;
|
||||
_path = QDir::cleanPath(path);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//QMessageBox::critical(NULL,tr("Not found"),tr("Comic not found")+" : " + path);
|
||||
emit errorOpening();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void PDFComic::process()
|
||||
{
|
||||
pdfComic = Poppler::Document::load(_path);
|
||||
if (!pdfComic)
|
||||
{
|
||||
delete pdfComic;
|
||||
pdfComic = 0;
|
||||
//TODO emitir este mensaje en otro sitio
|
||||
//QMessageBox::critical(NULL,QObject::tr("Bad PDF File"),QObject::tr("Invalid PDF file"));
|
||||
emit errorOpening();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//pdfComic->setRenderHint(Poppler::Document::Antialiasing, true);
|
||||
pdfComic->setRenderHint(Poppler::Document::TextAntialiasing, true);
|
||||
int nPages = pdfComic->numPages();
|
||||
emit pageChanged(0); // this indicates new comic, index=0
|
||||
emit numPages(nPages);
|
||||
_loaded = true;
|
||||
//QMessageBox::critical(NULL,QString("%1").arg(nPages),tr("Invalid PDF file"));
|
||||
|
||||
_pages.clear();
|
||||
_pages.resize(nPages);
|
||||
_loadedPages = QVector<bool>(nPages,false);
|
||||
|
||||
if(_firstPage == -1)
|
||||
_firstPage = bm->getLastPage();
|
||||
_index = _firstPage;
|
||||
emit(openAt(_index));
|
||||
|
||||
for(int i=_index;i<nPages;i++)
|
||||
renderPage(i);
|
||||
for(int i=0;i<_index;i++)
|
||||
renderPage(i);
|
||||
|
||||
delete pdfComic;
|
||||
emit imagesLoaded();
|
||||
moveToThread(QApplication::instance()->thread());
|
||||
}
|
||||
|
||||
void PDFComic::renderPage(int page)
|
||||
{
|
||||
Poppler::Page* pdfpage = pdfComic->page(page);
|
||||
if (pdfpage)
|
||||
{
|
||||
QImage img = pdfpage->renderToImage(150,150);
|
||||
delete pdfpage;
|
||||
QByteArray ba;
|
||||
QBuffer buf(&ba);
|
||||
img.save(&buf, "jpg");
|
||||
_pages[page] = ba;
|
||||
emit imageLoaded(page);
|
||||
emit imageLoaded(page,_pages[page]);
|
||||
}
|
||||
}
|
||||
|
||||
Comic * FactoryComic::newComic(const QString & path)
|
||||
{
|
||||
|
||||
QFileInfo fi(path);
|
||||
if(fi.exists())
|
||||
{
|
||||
if(fi.isFile())
|
||||
{
|
||||
if(fi.suffix().compare("pdf",Qt::CaseInsensitive) == 0)
|
||||
return new PDFComic();
|
||||
else
|
||||
return new FileComic();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(fi.isDir())
|
||||
return new FolderComic();
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
|
||||
}
|
@ -1,158 +0,0 @@
|
||||
#ifndef __COMIC_H
|
||||
#define __COMIC_H
|
||||
#include <QtCore>
|
||||
#include <QImage>
|
||||
#include <QtGui>
|
||||
#include <QByteArray>
|
||||
#include <QMap>
|
||||
|
||||
#include "extract_delegate.h"
|
||||
|
||||
#include "bookmarks.h"
|
||||
|
||||
#include "poppler-qt4.h"
|
||||
|
||||
class ComicDB;
|
||||
//#define EXTENSIONS << "*.jpg" << "*.jpeg" << "*.png" << "*.gif" << "*.tiff" << "*.tif" << "*.bmp" Comic::getSupportedImageFormats()
|
||||
//#define EXTENSIONS_LITERAL << ".jpg" << ".jpeg" << ".png" << ".gif" << ".tiff" << ".tif" << ".bmp" //Comic::getSupportedImageLiteralFormats()
|
||||
class Comic : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
protected:
|
||||
//Comic pages, one QPixmap for each file.
|
||||
QVector<QByteArray> _pages;
|
||||
QVector<bool> _loadedPages;
|
||||
//QVector<uint> _sizes;
|
||||
QStringList _fileNames;
|
||||
QMap<QString,int> _newOrder;
|
||||
QList<QString> _order;
|
||||
int _index;
|
||||
QString _path;
|
||||
bool _loaded;
|
||||
|
||||
int _cfi;
|
||||
|
||||
//open the comic at this point
|
||||
int _firstPage;
|
||||
|
||||
bool _isPDF;
|
||||
|
||||
static QStringList extensions;
|
||||
static QStringList literalExtensions;
|
||||
public:
|
||||
Bookmarks * bm;
|
||||
|
||||
//Constructors
|
||||
Comic();
|
||||
Comic(const QString & pathFile, int atPage = -1);
|
||||
~Comic();
|
||||
void setup();
|
||||
//Load pages from file
|
||||
virtual bool load(const QString & path, int atPage = -1) = 0;
|
||||
virtual bool load(const QString & path, const ComicDB & comic);
|
||||
|
||||
/*void loadFromFile(const QString & pathFile);
|
||||
void loadFromDir(const QString & pathDir);
|
||||
void loadFromPDF(const QString & pathPDF);*/
|
||||
int nextPage();
|
||||
int previousPage();
|
||||
void setIndex(unsigned int index);
|
||||
unsigned int getIndex(){return _index;};
|
||||
unsigned int numPages(){return _pages.size();}
|
||||
//QPixmap * currentPage();
|
||||
bool loaded();
|
||||
//QPixmap * operator[](unsigned int index);
|
||||
QVector<QByteArray> * getRawData(){return &_pages;};
|
||||
QByteArray getRawPage(int page);
|
||||
bool pageIsLoaded(int page);
|
||||
|
||||
inline static QStringList getSupportedImageFormats() { return extensions;};
|
||||
inline static QStringList getSupportedImageLiteralFormats() { return literalExtensions;};
|
||||
|
||||
public slots:
|
||||
void loadFinished();
|
||||
void setBookmark();
|
||||
void removeBookmark();
|
||||
void saveBookmarks();
|
||||
void checkIsBookmark(int index);
|
||||
void updateBookmarkImage(int);
|
||||
void setPageLoaded(int page);
|
||||
signals:
|
||||
void imagesLoaded();
|
||||
void imageLoaded(int index);
|
||||
void imageLoaded(int index,const QByteArray & image);
|
||||
void pageChanged(int index);
|
||||
void openAt(int index);
|
||||
void numPages(unsigned int numPages);
|
||||
void errorOpening();
|
||||
void errorOpening(QString);
|
||||
void isBookmark(bool);
|
||||
void bookmarksUpdated();
|
||||
void isCover();
|
||||
void isLast();
|
||||
|
||||
};
|
||||
|
||||
class FileComic : public Comic, public ExtractDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
QList<QVector<quint32> > getSections(int & sectionIndex);
|
||||
public:
|
||||
FileComic();
|
||||
FileComic(const QString & path, int atPage = -1);
|
||||
~FileComic();
|
||||
void fileExtracted(int index, const QByteArray & rawData);
|
||||
virtual bool load(const QString & path, int atPage = -1);
|
||||
virtual bool load(const QString & path, const ComicDB & comic);
|
||||
void crcError(int index);
|
||||
void unknownError(int index);
|
||||
static QList<QString> filter(const QList<QString> & src);
|
||||
public slots:
|
||||
void process();
|
||||
};
|
||||
|
||||
class FolderComic : public Comic
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
//void run();
|
||||
public:
|
||||
FolderComic();
|
||||
FolderComic(const QString & path, int atPage = -1);
|
||||
~FolderComic();
|
||||
|
||||
virtual bool load(const QString & path, int atPage = -1);
|
||||
public slots:
|
||||
void process();
|
||||
|
||||
};
|
||||
|
||||
class PDFComic : public Comic
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
//pdf
|
||||
Poppler::Document * pdfComic;
|
||||
void renderPage(int page);
|
||||
|
||||
//void run();
|
||||
public:
|
||||
PDFComic();
|
||||
PDFComic(const QString & path, int atPage = -1);
|
||||
~PDFComic();
|
||||
|
||||
virtual bool load(const QString & path, int atPage = -1);
|
||||
virtual bool load(const QString & path, const ComicDB & comic);
|
||||
public slots:
|
||||
void process();
|
||||
};
|
||||
|
||||
class FactoryComic
|
||||
{
|
||||
public:
|
||||
static Comic * newComic(const QString & path);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user