diff options
author | Eike Ziller <eike.ziller@theqtcompany.com> | 2015-06-04 15:21:02 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@theqtcompany.com> | 2015-06-10 15:32:55 +0000 |
commit | fef9d7ff94ec497016d7a7120f8b60fde65ce8bf (patch) | |
tree | 4e16765dfc78d9ebb101d1b745acdcd3c8d64352 /src/plugins/imageviewer | |
parent | be0aa40520d8a133b1f975de8750b5b8e25da2be (diff) | |
download | qt-creator-fef9d7ff94ec497016d7a7120f8b60fde65ce8bf.tar.gz |
Editor manager: Abort with a single message if file is not readable.
We show a dialog that offers opening a file in a different editor type
if opening a file fails, but we should not do that if opening the file
fails because it is not readable.
With this change, documents now specify if they failed to open a file
because reading failed, or because they could not handle the file
contents.
Task-number: QTCREATORBUG-14495
Change-Id: I5d4b7cfa74b87ef21b9b55bc30b3ebe2f8238dfa
Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com>
Diffstat (limited to 'src/plugins/imageviewer')
-rw-r--r-- | src/plugins/imageviewer/imageviewerfile.cpp | 22 | ||||
-rw-r--r-- | src/plugins/imageviewer/imageviewerfile.h | 4 |
2 files changed, 15 insertions, 11 deletions
diff --git a/src/plugins/imageviewer/imageviewerfile.cpp b/src/plugins/imageviewer/imageviewerfile.cpp index 92309678e2..479dfa94f9 100644 --- a/src/plugins/imageviewer/imageviewerfile.cpp +++ b/src/plugins/imageviewer/imageviewerfile.cpp @@ -85,25 +85,29 @@ ImageViewerFile::~ImageViewerFile() cleanUp(); } -bool ImageViewerFile::open(QString *errorString, const QString &fileName, const QString &realFileName) +Core::IDocument::OpenResult ImageViewerFile::open(QString *errorString, const QString &fileName, + const QString &realFileName) { QTC_CHECK(fileName == realFileName); // does not support auto save - bool success = openImpl(errorString, fileName); - emit openFinished(success); + OpenResult success = openImpl(errorString, fileName); + emit openFinished(success == OpenResult::Success); return success; } -bool ImageViewerFile::openImpl(QString *errorString, const QString &fileName) +Core::IDocument::OpenResult ImageViewerFile::openImpl(QString *errorString, const QString &fileName) { cleanUp(); m_type = TypeInvalid; + if (!QFileInfo(fileName).isReadable()) + return OpenResult::ReadError; + QByteArray format = QImageReader::imageFormat(fileName); // if it is impossible to recognize a file format - file will not be open correctly if (format.isEmpty()) { if (errorString) *errorString = tr("Image format not supported."); - return false; + return OpenResult::CannotHandle; } #ifndef QT_NO_SVG @@ -114,7 +118,7 @@ bool ImageViewerFile::openImpl(QString *errorString, const QString &fileName) if (bound.width() == 0 && bound.height() == 0) { if (errorString) *errorString = tr("Failed to read SVG image."); - return false; + return OpenResult::CannotHandle; } emit imageSizeChanged(QSize()); } else @@ -135,7 +139,7 @@ bool ImageViewerFile::openImpl(QString *errorString, const QString &fileName) if (errorString) *errorString = tr("Failed to read image."); delete m_pixmap; - return false; + return OpenResult::CannotHandle; } emit imageSizeChanged(m_pixmap->size()); } @@ -143,7 +147,7 @@ bool ImageViewerFile::openImpl(QString *errorString, const QString &fileName) setFilePath(Utils::FileName::fromString(fileName)); Utils::MimeDatabase mdb; setMimeType(mdb.mimeTypeForFile(fileName).name()); - return true; + return OpenResult::Success; } Core::IDocument::ReloadBehavior ImageViewerFile::reloadBehavior(ChangeTrigger state, ChangeType type) const @@ -166,7 +170,7 @@ bool ImageViewerFile::reload(QString *errorString, return true; } emit aboutToReload(); - bool success = openImpl(errorString, filePath().toString()); + bool success = (openImpl(errorString, filePath().toString()) == OpenResult::Success); emit reloadFinished(success); return success; } diff --git a/src/plugins/imageviewer/imageviewerfile.h b/src/plugins/imageviewer/imageviewerfile.h index fc0eee268e..2e71b87173 100644 --- a/src/plugins/imageviewer/imageviewerfile.h +++ b/src/plugins/imageviewer/imageviewerfile.h @@ -65,7 +65,7 @@ public: ImageViewerFile(); ~ImageViewerFile(); - bool open(QString *errorString, const QString &fileName, const QString &realFileName); + OpenResult open(QString *errorString, const QString &fileName, const QString &realFileName); bool save(QString *errorString, const QString &fileName, bool autoSave); bool setContents(const QByteArray &contents); @@ -93,7 +93,7 @@ signals: private: void cleanUp(); - bool openImpl(QString *errorString, const QString &fileName); + OpenResult openImpl(QString *errorString, const QString &fileName); ImageType m_type = TypeInvalid; #ifndef QT_NO_SVG |