From 86914fd634220b6c7a5c52648e1325cf16bb42df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sun, 29 Jul 2012 17:03:58 +0200 Subject: [PATCH] corregido bug al intentar abrir un c?mic en un path no existente - ahora se muestra un error al usuario. - y se restaura el estado inicial. --- YACReader/comic.cpp | 37 ++++++++++++++++++++++++------------- YACReader/comic.h | 2 +- YACReader/render.cpp | 15 +++++++++++++-- YACReader/render.h | 1 + YACReader/viewer.cpp | 2 +- 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/YACReader/comic.cpp b/YACReader/comic.cpp index 4be17ce1..e0e89a75 100644 --- a/YACReader/comic.cpp +++ b/YACReader/comic.cpp @@ -31,22 +31,33 @@ void Comic::setup() connect(this,SIGNAL(imageLoaded(int)),this,SLOT(updateBookmarkImage(int))); } //----------------------------------------------------------------------------- -void Comic::load(const QString & path) +bool Comic::load(const QString & path) { - QFileInfo fi(path); - bm->newComic(path); - emit bookmarksLoaded(*bm); - if(fi.isFile()) - { - loadFromFile(path); - } - else - { - if(fi.isDir()) + QFileInfo fi(path); + if(fi.exists()) { - loadFromDir(path); + bm->newComic(path); + emit bookmarksLoaded(*bm); + + if(fi.isFile()) + { + loadFromFile(path); + } + else + { + if(fi.isDir()) + { + loadFromDir(path); + } + } + return true; + } + else + { + QMessageBox::critical(NULL,tr("Not found"),tr("Comic not found")); + emit errorOpening(); + return false; } - } } //----------------------------------------------------------------------------- void Comic::loadFromFile(const QString & pathFile) diff --git a/YACReader/comic.h b/YACReader/comic.h index 2e5a2d49..b1227f10 100644 --- a/YACReader/comic.h +++ b/YACReader/comic.h @@ -33,7 +33,7 @@ Comic(const QString pathFile); void setup(); //Load pages from file - void load(const QString & path); + bool load(const QString & path); void loadFromFile(const QString & pathFile); void loadFromDir(const QString & pathDir); int nextPage(); diff --git a/YACReader/render.cpp b/YACReader/render.cpp index 46fe60e2..4b602d52 100644 --- a/YACReader/render.cpp +++ b/YACReader/render.cpp @@ -403,6 +403,7 @@ void Render::load(const QString & path) 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))); @@ -412,9 +413,19 @@ void Render::load(const QString & path) connect(comic,SIGNAL(isBookmark(bool)),this,SIGNAL(currentPageIsBookmark(bool))); connect(comic,SIGNAL(bookmarksLoaded(const Bookmarks &)),this,SIGNAL(bookmarksLoaded(const Bookmarks &))); pagesReady.clear(); - comic->load(path); + if(comic->load(path)) //garantiza que se va a intentar abrir el cómic + { + invalidate(); + loadedComic = true; + update(); + } + +} + +void Render::reset() +{ + loadedComic = false; invalidate(); - loadedComic = true; //TODO reset if an error occurs while opening } //si se solicita la siguiente página, se calcula cuál debe ser en función de si se lee en modo a doble página o no. //la página sólo se renderiza, si realmente ha cambiado. diff --git a/YACReader/render.h b/YACReader/render.h index d13d1fee..45951f39 100644 --- a/YACReader/render.h +++ b/YACReader/render.h @@ -138,6 +138,7 @@ public slots: void setBookmark(); void removeBookmark(); void save(); + void reset(); signals: void currentPageReady(); diff --git a/YACReader/viewer.cpp b/YACReader/viewer.cpp index 9b1bcc7a..daa54a4d 100644 --- a/YACReader/viewer.cpp +++ b/YACReader/viewer.cpp @@ -130,7 +130,7 @@ void Viewer::open(QString pathFile) goToFlow->reset(); render->load(pathFile); - render->update(); + //render->update(); verticalScrollBar()->setSliderPosition(verticalScrollBar()->minimum()); }