Corregido bug relativo a bookmarks y los c?mics en pdf o carpetas

Cambiado de uso de QPixmap por QImage en las partes que estan fuera de GUI

Cambiadas las llamadas a enableAction para asegurar que se producen siempre antes
que disableAction en caso de error al abrir.

Corregida la gesti?n de errores de apertura al usar FactoryComic
This commit is contained in:
Luis Ángel San Martín
2013-01-20 15:28:34 +01:00
parent 726061affe
commit ae4913b685
13 changed files with 110 additions and 55 deletions

View File

@ -13,12 +13,12 @@ Bookmarks::Bookmarks()
{ {
list.load(); list.load();
} }
void Bookmarks::setLastPage(int index,const QPixmap & page) void Bookmarks::setLastPage(int index,const QImage & page)
{ {
lastPageIndex = index; lastPageIndex = index;
lastPage = page; lastPage = page;
} }
void Bookmarks::setBookmark(int index,const QPixmap & page) void Bookmarks::setBookmark(int index,const QImage & page)
{ {
if(!bookmarks.contains(index)) if(!bookmarks.contains(index))
{ {
@ -46,12 +46,12 @@ QList<int> Bookmarks::getBookmarkPages() const
return bookmarks.keys(); return bookmarks.keys();
} }
QPixmap Bookmarks::getBookmarkPixmap(int page) const QImage Bookmarks::getBookmarkPixmap(int page) const
{ {
return bookmarks.value(page); return bookmarks.value(page);
} }
QPixmap Bookmarks::getLastPagePixmap() const QImage Bookmarks::getLastPagePixmap() const
{ {
return lastPage; return lastPage;
} }
@ -82,7 +82,7 @@ void Bookmarks::newComic(const QString & path)
lastPageIndex = b.lastPage; lastPageIndex = b.lastPage;
latestBookmarks = b.bookmarks; latestBookmarks = b.bookmarks;
for(int i=0;i<latestBookmarks.count();i++) for(int i=0;i<latestBookmarks.count();i++)
bookmarks.insert(latestBookmarks.at(i),QPixmap()); bookmarks.insert(latestBookmarks.at(i),QImage());
added = b.added; added = b.added;
} }
@ -91,7 +91,7 @@ void Bookmarks::clear()
bookmarks.clear(); bookmarks.clear();
latestBookmarks.clear(); latestBookmarks.clear();
lastPageIndex=0; lastPageIndex=0;
lastPage = QPixmap(); lastPage = QImage();
} }
void Bookmarks::save() void Bookmarks::save()

View File

@ -3,7 +3,7 @@
#include <QObject> #include <QObject>
#include <QMap> #include <QMap>
#include <QPixmap> #include <QImage>
#include <QString> #include <QString>
#include <QMap> #include <QMap>
#include <QDateTime> #include <QDateTime>
@ -49,22 +49,22 @@ class Bookmarks : public QObject
protected: protected:
QString comicPath; QString comicPath;
//bookmarks setted by the user //bookmarks setted by the user
QMap<int,QPixmap> bookmarks; QMap<int,QImage> bookmarks;
QList<int> latestBookmarks; QList<int> latestBookmarks;
//last page readed //last page readed
int lastPageIndex; int lastPageIndex;
QPixmap lastPage; QImage lastPage;
BookmarksList list; BookmarksList list;
QDateTime added; QDateTime added;
public: public:
Bookmarks(); Bookmarks();
void setLastPage(int index,const QPixmap & page); void setLastPage(int index,const QImage & page);
void setBookmark(int index,const QPixmap & page); void setBookmark(int index,const QImage & page);
void removeBookmark(int index); void removeBookmark(int index);
QList<int> getBookmarkPages() const; QList<int> getBookmarkPages() const;
QPixmap getBookmarkPixmap(int page) const; QImage getBookmarkPixmap(int page) const;
QPixmap getLastPagePixmap() const; QImage getLastPagePixmap() const;
int getLastPage() const; int getLastPage() const;
bool isBookmark(int page); bool isBookmark(int page);
bool imageLoaded(int page); bool imageLoaded(int page);

View File

@ -85,7 +85,7 @@ void BookmarksDialog::setBookmarks(const Bookmarks & bm)
lastPage = bm.getLastPage(); lastPage = bm.getLastPage();
if (lastPage > 0) if (lastPage > 0)
{ {
QPixmap p = bm.getLastPagePixmap(); QPixmap p = QPixmap::fromImage(bm.getLastPagePixmap());
if(p.isNull()) if(p.isNull())
{ {
images.at(0)->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); images.at(0)->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
@ -109,7 +109,7 @@ void BookmarksDialog::setBookmarks(const Bookmarks & bm)
for(int i=0;i<s;i++) for(int i=0;i<s;i++)
{ {
pages.at(i+1)->setText(QString::number(l.at(i)+1)); pages.at(i+1)->setText(QString::number(l.at(i)+1));
QPixmap p = bm.getBookmarkPixmap(l.at(i)); QPixmap p = QPixmap::fromImage(bm.getBookmarkPixmap(l.at(i)));
if(p.isNull()) if(p.isNull())
{ {
images.at(i+1)->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); images.at(i+1)->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);

View File

@ -92,21 +92,23 @@ void Comic::loadFinished()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Comic::setBookmark() void Comic::setBookmark()
{ {
QPixmap p; QImage p;
p.loadFromData(_pages[_index]); p.loadFromData(_pages[_index]);
bm->setBookmark(_index,p); bm->setBookmark(_index,p);
emit bookmarksLoaded(*bm); //emit bookmarksLoaded(*bm);
emit bookmarksUpdated();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Comic::removeBookmark() void Comic::removeBookmark()
{ {
bm->removeBookmark(_index); bm->removeBookmark(_index);
emit bookmarksLoaded(*bm); //emit bookmarksLoaded(*bm);
emit bookmarksUpdated();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Comic::saveBookmarks() void Comic::saveBookmarks()
{ {
QPixmap p; QImage p;
p.loadFromData(_pages[_index]); p.loadFromData(_pages[_index]);
bm->setLastPage(_index,p); bm->setLastPage(_index,p);
bm->save(); bm->save();
@ -121,17 +123,20 @@ void Comic::updateBookmarkImage(int index)
{ {
if(bm->isBookmark(index)) if(bm->isBookmark(index))
{ {
QPixmap p; QImage p;
p.loadFromData(_pages[_index]); p.loadFromData(_pages[index]);
bm->setBookmark(index,p); bm->setBookmark(index,p);
emit bookmarksLoaded(*bm); emit bookmarksUpdated();
//emit bookmarksLoaded(*bm);
} }
if(bm->getLastPage() == index) if(bm->getLastPage() == index)
{ {
QPixmap p; QImage p;
p.loadFromData(_pages[_index]); p.loadFromData(_pages[index]);
bm->setLastPage(index,p); bm->setLastPage(index,p);
emit bookmarksLoaded(*bm); emit bookmarksUpdated();
//emit bookmarksLoaded(*bm);
} }
} }
@ -183,7 +188,8 @@ bool FileComic::load(const QString & path)
if(fi.exists()) if(fi.exists())
{ {
bm->newComic(path); bm->newComic(path);
emit bookmarksLoaded(*bm); emit bookmarksUpdated();
//emit bookmarksLoaded(*bm);
_path = QDir::cleanPath(path); _path = QDir::cleanPath(path);
//load files size //load files size
@ -322,6 +328,9 @@ FolderComic::~FolderComic()
bool FolderComic::load(const QString & path) bool FolderComic::load(const QString & path)
{ {
_path = path; _path = path;
bm->newComic(_path);
emit bookmarksUpdated();
//emit bookmarksLoaded(*bm);
return true; return true;
} }
@ -363,8 +372,6 @@ void FolderComic::process()
} }
} }
emit imagesLoaded(); emit imagesLoaded();
moveToThread(QApplication::instance()->thread());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -391,6 +398,9 @@ PDFComic::~PDFComic()
bool PDFComic::load(const QString & path) bool PDFComic::load(const QString & path)
{ {
_path = path; _path = path;
bm->newComic(_path);
emit bookmarksUpdated();
//emit bookmarksLoaded(*bm);
return true; return true;
} }
@ -406,6 +416,7 @@ void PDFComic::process()
emit errorOpening(); emit errorOpening();
return; return;
} }
//pdfComic->setRenderHint(Poppler::Document::Antialiasing, true); //pdfComic->setRenderHint(Poppler::Document::Antialiasing, true);
pdfComic->setRenderHint(Poppler::Document::TextAntialiasing, true); pdfComic->setRenderHint(Poppler::Document::TextAntialiasing, true);
@ -424,7 +435,7 @@ void PDFComic::process()
Poppler::Page* pdfpage = pdfComic->page(i); Poppler::Page* pdfpage = pdfComic->page(i);
if (pdfpage) if (pdfpage)
{ {
QImage img = pdfpage->renderToImage(150,150); //TODO use defaults if not using X11 (e.g. MS Win) QImage img = pdfpage->renderToImage(150,150);
delete pdfpage; delete pdfpage;
QByteArray ba; QByteArray ba;
QBuffer buf(&ba); QBuffer buf(&ba);
@ -438,8 +449,6 @@ void PDFComic::process()
} }
delete pdfComic; delete pdfComic;
emit imagesLoaded(); emit imagesLoaded();
moveToThread(QApplication::instance()->thread());
} }
@ -448,14 +457,22 @@ Comic * FactoryComic::newComic(const QString & path)
QFileInfo fi(path); QFileInfo fi(path);
if(fi.exists()) if(fi.exists())
{
if(fi.isFile()) if(fi.isFile())
{
if(fi.suffix().compare("pdf",Qt::CaseInsensitive) == 0) if(fi.suffix().compare("pdf",Qt::CaseInsensitive) == 0)
return new PDFComic(); return new PDFComic();
else else
return new FileComic(); return new FileComic();
}
else else
{
if(fi.isDir()) if(fi.isDir())
return new FolderComic(); return new FolderComic();
else
return NULL;
}
}
else else
return NULL; return NULL;

View File

@ -27,11 +27,13 @@
int _cfi; int _cfi;
Bookmarks * bm;
bool _isPDF; bool _isPDF;
public: public:
Bookmarks * bm;
//Constructors //Constructors
Comic(); Comic();
Comic(const QString & pathFile); Comic(const QString & pathFile);
@ -71,7 +73,7 @@
void numPages(unsigned int numPages); void numPages(unsigned int numPages);
void errorOpening(); void errorOpening();
void isBookmark(bool); void isBookmark(bool);
void bookmarksLoaded(const Bookmarks &); void bookmarksUpdated();
}; };

View File

@ -81,9 +81,11 @@ void MainWindowViewer::setupUI()
getSiblingComics(fi.absolutePath(),fi.fileName()); getSiblingComics(fi.absolutePath(),fi.fileName());
setWindowTitle("YACReader - " + fi.fileName()); setWindowTitle("YACReader - " + fi.fileName());
viewer->open(pathFile);
enableActions(); enableActions();
viewer->open(pathFile);
} }
versionChecker = new HttpVersionChecker(); versionChecker = new HttpVersionChecker();
@ -410,8 +412,10 @@ void MainWindowViewer::openComicFromPath(QString pathFile)
setWindowTitle("YACReader - " + fi.fileName()); setWindowTitle("YACReader - " + fi.fileName());
viewer->open(pathFile);
enableActions(); enableActions();
viewer->open(pathFile);
} }
void MainWindowViewer::openFolder() void MainWindowViewer::openFolder()
@ -432,8 +436,10 @@ void MainWindowViewer::openFolderFromPath(QString pathDir)
setWindowTitle("YACReader - " + fi.fileName()); setWindowTitle("YACReader - " + fi.fileName());
viewer->open(pathDir);
enableActions(); enableActions();
viewer->open(pathDir);
} }
void MainWindowViewer::saveImage() void MainWindowViewer::saveImage()

View File

@ -410,10 +410,29 @@ void Render::load(const QString & path)
//comic->moveToThread(QApplication::instance()->thread()); //comic->moveToThread(QApplication::instance()->thread());
comic = FactoryComic::newComic(path); comic = FactoryComic::newComic(path);
if(comic == NULL) //archivo no encontrado o no v<>lido
if(comic == NULL)//archivo no encontrado o no v<>lido
{
emit errorOpening();
reset();
return; return;
}
previousIndex = currentIndex = 0; previousIndex = currentIndex = 0;
connect(comic,SIGNAL(errorOpening()),this,SIGNAL(errorOpening()));
connect(comic,SIGNAL(errorOpening()),this,SLOT(reset()));
connect(comic,SIGNAL(imageLoaded(int)),this,SIGNAL(imageLoaded(int)));
connect(comic,SIGNAL(imageLoaded(int)),this,SLOT(pageRawDataReady(int)));
//connect(comic,SIGNAL(pageChanged(int)),this,SIGNAL(pageChanged(int)));
connect(comic,SIGNAL(numPages(unsigned int)),this,SIGNAL(numPages(unsigned int)));
connect(comic,SIGNAL(numPages(unsigned int)),this,SLOT(setNumPages(unsigned int)));
connect(comic,SIGNAL(imageLoaded(int,QByteArray)),this,SIGNAL(imageLoaded(int,QByteArray)));
connect(comic,SIGNAL(isBookmark(bool)),this,SIGNAL(currentPageIsBookmark(bool)));
connect(comic,SIGNAL(isBookmark(bool)),this,SLOT(pageIsBookmark(bool)));
connect(comic,SIGNAL(bookmarksUpdated()),this,SIGNAL(bookmarksUpdated()));
QThread * thread = NULL; QThread * thread = NULL;
if (typeid(*comic) != typeid(FileComic)) if (typeid(*comic) != typeid(FileComic))
{ {
@ -426,20 +445,8 @@ void Render::load(const QString & path)
} }
connect(comic,SIGNAL(errorOpening()),this,SIGNAL(errorOpening()));
connect(comic,SIGNAL(errorOpening()),this,SLOT(reset()));
connect(comic,SIGNAL(imageLoaded(int)),this,SIGNAL(imageLoaded(int)));
connect(comic,SIGNAL(imageLoaded(int)),this,SLOT(pageRawDataReady(int)));
//connect(comic,SIGNAL(pageChanged(int)),this,SIGNAL(pageChanged(int)));
connect(comic,SIGNAL(numPages(unsigned int)),this,SIGNAL(numPages(unsigned int)));
connect(comic,SIGNAL(numPages(unsigned int)),this,SLOT(setNumPages(unsigned int)));
connect(comic,SIGNAL(imageLoaded(int,QByteArray)),this,SIGNAL(imageLoaded(int,QByteArray)));
connect(comic,SIGNAL(isBookmark(bool)),this,SIGNAL(currentPageIsBookmark(bool)));
connect(comic,SIGNAL(bookmarksLoaded(const Bookmarks &)),this,SIGNAL(bookmarksLoaded(const Bookmarks &)));
pagesReady.clear(); pagesReady.clear();
comic->load(path); //garantiza que se va a intentar abrir el c<>mic comic->load(path); //garantiza que se va a intentar abrir el c<>mic
if(thread != NULL) if(thread != NULL)
@ -785,3 +792,8 @@ void Render::save()
{ {
comic->saveBookmarks(); comic->saveBookmarks();
} }
Bookmarks * Render::getBookmarks()
{
return comic->bm;
}

View File

@ -139,6 +139,7 @@ public slots:
void removeBookmark(); void removeBookmark();
void save(); void save();
void reset(); void reset();
Bookmarks * getBookmarks();
signals: signals:
void currentPageReady(); void currentPageReady();
@ -150,7 +151,8 @@ signals:
void numPages(unsigned int numPages); void numPages(unsigned int numPages);
void errorOpening(); void errorOpening();
void currentPageIsBookmark(bool); void currentPageIsBookmark(bool);
void bookmarksLoaded(const Bookmarks &);
void bookmarksUpdated();
private: private:
Comic * comic; Comic * comic;

View File

@ -137,13 +137,16 @@ void Viewer::createConnections()
//render //render
connect(render,SIGNAL(errorOpening()),this,SLOT(resetContent())); connect(render,SIGNAL(errorOpening()),this,SLOT(resetContent()));
connect(render,SIGNAL(errorOpening()),this,SLOT(showMessageErrorOpening()));
connect(render,SIGNAL(numPages(unsigned int)),goToFlow,SLOT(setNumSlides(unsigned int))); connect(render,SIGNAL(numPages(unsigned int)),goToFlow,SLOT(setNumSlides(unsigned int)));
connect(render,SIGNAL(numPages(unsigned int)),goToDialog,SLOT(setNumPages(unsigned int))); connect(render,SIGNAL(numPages(unsigned int)),goToDialog,SLOT(setNumPages(unsigned int)));
connect(render,SIGNAL(imageLoaded(int,QByteArray)),goToFlow,SLOT(setImageReady(int,QByteArray))); connect(render,SIGNAL(imageLoaded(int,QByteArray)),goToFlow,SLOT(setImageReady(int,QByteArray)));
connect(render,SIGNAL(currentPageReady()),this,SLOT(updatePage())); connect(render,SIGNAL(currentPageReady()),this,SLOT(updatePage()));
connect(render,SIGNAL(processingPage()),this,SLOT(setLoadingMessage())); connect(render,SIGNAL(processingPage()),this,SLOT(setLoadingMessage()));
connect(render,SIGNAL(currentPageIsBookmark(bool)),this,SIGNAL(pageIsBookmark(bool))); connect(render,SIGNAL(currentPageIsBookmark(bool)),this,SIGNAL(pageIsBookmark(bool)));
connect(render,SIGNAL(bookmarksLoaded(const Bookmarks &)),bd,SLOT(setBookmarks(const Bookmarks &))); //connect(render,SIGNAL(bookmarksLoaded(Bookmarks)),this,SLOT(setBookmarks(Bookmarks)));
connect(render,SIGNAL(bookmarksUpdated()),this,SLOT(setBookmarks()));
} }
void Viewer::open(QString pathFile) void Viewer::open(QString pathFile)
@ -159,6 +162,11 @@ void Viewer::open(QString pathFile)
verticalScrollBar()->setSliderPosition(verticalScrollBar()->minimum()); verticalScrollBar()->setSliderPosition(verticalScrollBar()->minimum());
} }
void Viewer::showMessageErrorOpening()
{
QMessageBox::critical(NULL,tr("Not found"),tr("Comic not found"));
}
void Viewer::next() void Viewer::next()
{ {
direction = 1; direction = 1;
@ -723,4 +731,9 @@ void Viewer::updateFitToWidthRatio(float ratio)
void Viewer::updateConfig(QSettings * settings) void Viewer::updateConfig(QSettings * settings)
{ {
goToFlow->updateConfig(settings); goToFlow->updateConfig(settings);
}
void Viewer::setBookmarks()
{
bd->setBookmarks(*render->getBookmarks());
} }

View File

@ -25,6 +25,7 @@ class Render;
class GoToDialog; class GoToDialog;
class YACReaderTranslator; class YACReaderTranslator;
class GoToFlowWidget; class GoToFlowWidget;
class Bookmarks;
class Viewer : public QScrollArea class Viewer : public QScrollArea
{ {
@ -73,6 +74,8 @@ virtual void mouseReleaseEvent ( QMouseEvent * event );
void updateBackgroundColor(const QColor & color); void updateBackgroundColor(const QColor & color);
void updateFitToWidthRatio(float ratio); void updateFitToWidthRatio(float ratio);
void updateConfig(QSettings * settings); void updateConfig(QSettings * settings);
void showMessageErrorOpening();
void setBookmarks();
private: private:
bool information; bool information;

View File

@ -1,7 +1,7 @@
#ifndef __YACREADER_GLOBAL_H #ifndef __YACREADER_GLOBAL_H
#define __YACREADER_GLOBAL_H #define __YACREADER_GLOBAL_H
#define VERSION "5.5.0" #define VERSION "5.5.1"
#define PATH "PATH" #define PATH "PATH"
#define MAG_GLASS_SIZE "MAG_GLASS_SIZE" #define MAG_GLASS_SIZE "MAG_GLASS_SIZE"

View File

@ -3,7 +3,7 @@
</head> </head>
<body> <body>
<p> <p>
YACReader - Yet Another Comic Reader - version 5.5 <br/> YACReader - Yet Another Comic Reader - version 5.5.1 <br/>
by Luis Ángel San Martín Rodríguez <br/> by Luis Ángel San Martín Rodríguez <br/>
e-mail: luisangelsm@gmail.com <br/> e-mail: luisangelsm@gmail.com <br/>
web site: <a href="http://www.yacreader.com">http://www.yacreader.com</a> <br/> web site: <a href="http://www.yacreader.com">http://www.yacreader.com</a> <br/>

View File

@ -4,7 +4,7 @@
<body> <body>
<p> <p>
<img src=":/images/icon.png" /> <br/> <img src=":/images/icon.png" /> <br/>
YACReader - Yet Another Comic Reader - versión 5.5 <br/> YACReader - Yet Another Comic Reader - versión 5.5.1 <br/>
por Luis Ángel San Martín Rodríguez <br/> por Luis Ángel San Martín Rodríguez <br/>
e-mail: luisangelsm@gmail.com <br/> e-mail: luisangelsm@gmail.com <br/>
Página web: <a href="http://www.yacreader.com">http://www.yacreader.com</a> <br/> Página web: <a href="http://www.yacreader.com">http://www.yacreader.com</a> <br/>