From 25dfbed3a2deceb48ea2b1a6e36585d21de145cc Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 24 Oct 2015 09:36:13 +0200 Subject: Fix convert to PNG mess Automatically converting a damaged file to PNG and updating the archive is fine as long as we're *in* the archive, but it totally messes things up if we're browsing the file system. So check if the image is in the archive path, and only then consider auto-converting it. Also show a notice in the InfoItem if the file has been converted. --- helper.cpp | 2 +- helper.h | 2 +- pictureviewer2.cpp | 22 +++++++++++++++------- pictureviewer2.h | 3 ++- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/helper.cpp b/helper.cpp index dd6bedf..b913f65 100644 --- a/helper.cpp +++ b/helper.cpp @@ -314,7 +314,7 @@ namespace Helper { return retval; } - PicData convertToPng(PicData data){ + PicData convertArchivefileToPng(PicData data){ if(data.at(2) != "image/jpeg"){ return PicData(); } diff --git a/helper.h b/helper.h index cdfcd88..434ba0d 100644 --- a/helper.h +++ b/helper.h @@ -48,7 +48,7 @@ namespace Helper { QPixmap preview(const QString &path); QImage snapshot(const QString &path, int where); QVariant picSize(const QString &path); - PicData convertToPng(PicData data); + PicData convertArchivefileToPng(PicData data); class Duration { public: Duration(); diff --git a/pictureviewer2.cpp b/pictureviewer2.cpp index a722bbb..189cf80 100644 --- a/pictureviewer2.cpp +++ b/pictureviewer2.cpp @@ -344,6 +344,7 @@ void PictureViewer2::readSettings(){ mScene->setSceneRect(QRectF(0, 0, width(), height())); mCursorOffset = s.value("ui/cursoroffset").toInt(); mScene->setCursorOffset(mCursorOffset); + mArchiveDir = s.value("paths/archivedir").toString(); showFile(mCurPicData); } @@ -578,22 +579,26 @@ void PictureViewer2::showFile(const PicData &file){ return; } mCurPicData = file; + bool converted = false; QFileInfo fi(file.at(PicFilesModel::FullPath).toString()); if(!fi.exists()){ return; } QPixmap pixmap(file.at(PicFilesModel::FullPath).toString()); if(pixmap.isNull()){ - mCurPicData = Helper::convertToPng(file); - mFiles[mCurPos] = mCurPicData; - if(mCurPicData.isEmpty()){ - return; + if(fi.canonicalFilePath().startsWith(mArchiveDir)){ + mCurPicData = Helper::convertArchivefileToPng(file); + mFiles[mCurPos] = mCurPicData; + if(!mCurPicData.isEmpty()){ + pixmap = QPixmap(mCurPicData.at(3).toString()); + converted = true; + } } - pixmap = QPixmap(mCurPicData.at(3).toString()); if(pixmap.isNull()){ pixmap = QPixmap(mDefaultFile); } } + if(mUseGradient){ setGradient(pixmap); }else{ @@ -615,7 +620,7 @@ void PictureViewer2::showFile(const PicData &file){ mCur->setPos(picRect.topLeft()); setWindowTitle(constructWindowTitle()); if(mConfigInfoPos != ConfigurationDialog::NoDisplay && mShowInfoItem){ - constructInfoItem(mCurPicData, pixmap.size()); + constructInfoItem(mCurPicData, pixmap.size(), converted); }else{ if(mFnItem){ mScene->removeItem(mFnItem); @@ -634,7 +639,7 @@ void PictureViewer2::showFile(const PicData &file){ } } -void PictureViewer2::constructInfoItem(const PicData &data, QSize picSize){ +void PictureViewer2::constructInfoItem(const PicData &data, QSize picSize, bool converted){ if(mFnItem){ mInfoPos = mFnItem->scenePos(); mScene->removeItem(mFnItem); @@ -652,6 +657,9 @@ void PictureViewer2::constructInfoItem(const PicData &data, QSize picSize){ mFnItem->appendText("not marked"); } } + if(converted){ + mFnItem->appendText("converted!"); + } mFnItem->setPos(getPos(mFnItem, mConfigInfoPos, mInfoPos)); mScene->addItem(mFnItem); } diff --git a/pictureviewer2.h b/pictureviewer2.h index 63b020d..f0c5e71 100644 --- a/pictureviewer2.h +++ b/pictureviewer2.h @@ -87,7 +87,7 @@ class PictureViewer2 : public QGraphicsView { private slots: void showFile(const PicData &data); - void constructInfoItem(const PicData &file, QSize picSize); + void constructInfoItem(const PicData &file, QSize picSize, bool converted = false); void constructMappingItem(const PicData &file); void docFromTree(SmTreeItem *start, QTextCursor *cur, int indent); void nextFromAll(); @@ -146,6 +146,7 @@ class PictureViewer2 : public QGraphicsView { bool mShowMarkItem; bool mShuffle; QString mCurrentDir; + QString mArchiveDir; }; class PictureViewer2Item : public QGraphicsItem { -- cgit v1.2.3-70-g09d2