gwenview2 exif patch

Carles Pina i Estany <[email protected]>
Newsgroups gmane.comp.kde.gwenview
Message-ID <[email protected]>
Hello,

I send a patch for Gwenview 2. 

It will show Exif informatoion in full screen OSD.

Patch has some TODO's. As Gwenview 2 is in development stage I think that I
can send a patch with TODO's (I don't like... but :-) ). I will try to
fix it ASAP, but don't know exactly when (1 or 2 weeks?).

(all todos are in code too)

-OSD size is not correct, I'm sorry. If I call mFullScreenBar->resize
 label disappers (??)

-updateFullScreen calls doc->waitUntilLoaded. I think that should
 receive a signal and not do this blocking (correct?) wait

-Information should be configurable, but no configuration is available
 in Gwenview 2 :-) 

I think that mainly this. 

-- 
Carles Pina i Estany		GPG id: 0x8CBDAE64
	http://pinux.info	Manresa - Barcelona

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/

_______________________________________________
Gwenview-general mailing list
Gwenview-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/gwenview-general
gwenview2.exif.patch (text/x-diff, 12.5 KB)
Index: gwenview/app/documentview.cpp
===================================================================
--- gwenview/app/documentview.cpp	(revision 700913)
+++ gwenview/app/documentview.cpp	(working copy)
@@ -222,5 +222,9 @@
 	return dynamic_cast<ImageViewPart*>(d->mPart);
 }
 
+struct ExifInfo* DocumentView::getExifInfo() const {
+	return imageViewPart()->document()->getExifInfo();
+}
 
+
 } // namespace
Index: gwenview/app/mainwindow.cpp
===================================================================
--- gwenview/app/mainwindow.cpp	(revision 700913)
+++ gwenview/app/mainwindow.cpp	(working copy)
@@ -48,6 +48,7 @@
 #include <kstatusbar.h>
 #include <ktogglefullscreenaction.h>
 #include <ktoolbar.h>
+#include <ktoolbarlabelaction.h>
 #include <kurl.h>
 #include <kurlrequester.h>
 #include <kxmlguifactory.h>
@@ -65,6 +66,7 @@
 #include <lib/cropdialog.h>
 #include <lib/cropimageoperation.h>
 #include <lib/documentfactory.h>
+#include <lib/exifinfo.h>
 #include <lib/fullscreenbar.h>
 #include <lib/imageviewpart.h>
 #include <lib/mimetypeutils.h>
@@ -126,6 +128,7 @@
 	QScrollArea* mSideBarScrollArea;
 	SideBar* mSideBar;
 	FullScreenBar* mFullScreenBar;
+	KToolBarLabelAction *mFullScreenInfo;
 	SaveBar* mSaveBar;
 	SlideShow* mSlideShow;
 
@@ -435,7 +438,16 @@
 		mFullScreenBar->addWidget(mSlideShow->intervalWidget());
 		mFullScreenBar->addWidget(mSlideShow->optionsWidget());
 
-		mFullScreenBar->resize(mFullScreenBar->sizeHint());
+
+		mFullScreenBar->addSeparator();
+		mFullScreenInfo = new KToolBarLabelAction("info", mFullScreenBar);
+		mFullScreenInfo->setText("");
+		mFullScreenBar->addAction(mFullScreenInfo);
+
+		//TODO: adjust this size (or in updateFullScreenInfo
+		//method, because it depends of showed information)
+
+		//mFullScreenBar->resize(mFullScreenBar->sizeHint());
 	}
 
 	bool currentDocumentIsRasterImage() {
@@ -551,6 +563,7 @@
 	d->mWindow = this;
 	d->mDirModel = new SortedDirModel(this);
 	d->mFullScreenBar = 0;
+	d->mFullScreenInfo = 0;
 	d->initDirModel();
 	d->setupWidgets();
 	d->setupActions();
@@ -566,7 +579,51 @@
 		SLOT(generateThumbnailForUrl(const KUrl&)) );
 }
 
+void MainWindow::updateFullScreenInfo() {
+	if (!d->mFullScreenInfo) {
+		return;
+	}
+	//TODO: not use this blocking method to wait the JPEG information
+	//use some callback/signal
+	
+	Document::Ptr doc = DocumentFactory::instance()->load(d->currentUrl());
+	doc->waitUntilLoaded();
 
+	QString filename=d->mDocumentView->url().fileName();
+
+	ExifInfo *ei;
+	ei=d->mDocumentView->getExifInfo();
+	QString *iso,*focallength,*aperture,*shoottime;
+
+	if (ei) {
+		iso=ei->iso;
+		focallength=ei->focallength;
+		aperture=ei->aperture;
+		shoottime=ei->shoottime;
+	}
+	else {
+		iso=new QString("n/a");
+		focallength=new QString("n/a");
+		aperture=new QString("n/a");
+		shoottime=new QString("n/a");
+	}
+
+	//TODO: info is a configuration parameter (like in previous Gwenview)
+	//Adjust the parameter names and info.replaces
+	QString info = "Filename: %filename ISO: %iso FL: %focallength\nF: %aperture S=%shoottime";
+
+	info.replace("%filename",filename);
+	info.replace("%iso",*iso);
+	info.replace("%focallength",*focallength);
+	info.replace("%aperture",*aperture);
+	info.replace("%shoottime",*shoottime);
+
+	d->mFullScreenInfo->setText(info);
+	
+	//TODO: next lines makes to disappers the fullScreenInfo label!
+	//d->mFullScreenBar->resize(d->mFullScreenBar->sizeHint());
+}
+
 void MainWindow::setInitialUrl(const KUrl& url) {
 	if (urlIsDirectory(this, url)) {
 		d->mPreviewAction->trigger();
@@ -723,6 +780,7 @@
 	updatePreviousNextActions();
 	updateContextManager();
 	d->spreadCurrentUrl();
+	updateFullScreenInfo();
 }
 
 
@@ -808,6 +866,7 @@
 			d->createFullScreenBar();
 		}
 		d->mFullScreenBar->setActivated(true);
+		updateFullScreenInfo();
 	} else {
 		d->mStateBeforeFullScreen.mActiveViewModeAction->trigger();
 		d->mSideBarScrollArea->setVisible(d->mStateBeforeFullScreen.mSideBarVisible);
Index: gwenview/app/documentview.h
===================================================================
--- gwenview/app/documentview.h	(revision 700913)
+++ gwenview/app/documentview.h	(working copy)
@@ -79,6 +79,8 @@
 	 */
 	ImageViewPart* imageViewPart() const;
 
+	struct ExifInfo* getExifInfo() const;
+
 Q_SIGNALS:
 	/**
 	 * Emitted whenever the part changes. Main window should call createGui on
Index: gwenview/app/mainwindow.h
===================================================================
--- gwenview/app/mainwindow.h	(revision 700913)
+++ gwenview/app/mainwindow.h	(working copy)
@@ -105,6 +105,8 @@
 
 	void generateThumbnailForUrl(const KUrl&);
 
+	void updateFullScreenInfo();
+
 private:
 	class Private;
 	std::auto_ptr<Private> d;
Index: gwenview/lib/loadingdocumentimpl.h
===================================================================
--- gwenview/lib/loadingdocumentimpl.h	(revision 700913)
+++ gwenview/lib/loadingdocumentimpl.h	(working copy)
@@ -26,8 +26,12 @@
 // KDE
 
 // Local
+#include "exifinfo.h"
 #include "abstractdocumentimpl.h"
+#include "jpegcontent.h"
+#include "jpegdocumentloadedimpl.h"
 
+
 namespace Gwenview {
 
 
@@ -42,12 +46,14 @@
 	virtual bool isLoaded() const;
 	virtual Document::SaveResult save(const KUrl&, const QByteArray& format);
 	virtual void setImage(const QImage&);
+	virtual struct ExifInfo* getExifInfo();
 
 private Q_SLOTS:
 	void slotImageLoaded();
 
 private:
 	LoadingDocumentImplPrivate* const d;
+	JpegDocumentLoadedImpl* mJpegImpl;
 };
 
 
Index: gwenview/lib/emptydocumentimpl.h
===================================================================
--- gwenview/lib/emptydocumentimpl.h	(revision 700913)
+++ gwenview/lib/emptydocumentimpl.h	(working copy)
@@ -39,6 +39,7 @@
 	virtual bool isLoaded() const;
 	virtual Document::SaveResult save(const KUrl&, const QByteArray& format);
 	virtual void setImage(const QImage&);
+	virtual struct ExifInfo* getExifInfo();
 };
 
 
Index: gwenview/lib/documentloadedimpl.h
===================================================================
--- gwenview/lib/documentloadedimpl.h	(revision 700913)
+++ gwenview/lib/documentloadedimpl.h	(working copy)
@@ -45,6 +45,8 @@
 	virtual void setImage(const QImage&);
 	virtual void applyTransformation(Orientation orientation);
 
+	virtual struct ExifInfo* getExifInfo();
+
 protected:
 	virtual bool saveInternal(QIODevice* device, const QByteArray& format);
 
Index: gwenview/lib/emptydocumentimpl.cpp
===================================================================
--- gwenview/lib/emptydocumentimpl.cpp	(revision 700913)
+++ gwenview/lib/emptydocumentimpl.cpp	(working copy)
@@ -53,4 +53,7 @@
 	// Don't do anything for now, but we could imagine switching to loaded impl
 }
 
+struct ExifInfo* EmptyDocumentImpl::getExifInfo() {
+	return NULL;
+}
 } // namespace
Index: gwenview/lib/jpegdocumentloadedimpl.h
===================================================================
--- gwenview/lib/jpegdocumentloadedimpl.h	(revision 700913)
+++ gwenview/lib/jpegdocumentloadedimpl.h	(working copy)
@@ -41,6 +41,7 @@
 	~JpegDocumentLoadedImpl();
 	virtual void setImage(const QImage&);
 	virtual void applyTransformation(Orientation orientation);
+	virtual struct ExifInfo* getExifInfo();
 
 protected:
 	virtual bool saveInternal(QIODevice* device, const QByteArray& format);
Index: gwenview/lib/abstractdocumentimpl.h
===================================================================
--- gwenview/lib/abstractdocumentimpl.h	(revision 700913)
+++ gwenview/lib/abstractdocumentimpl.h	(working copy)
@@ -28,6 +28,7 @@
 
 // Local
 #include "document.h"
+#include "exifinfo.h"
 
 class QImage;
 class QRect;
@@ -56,6 +57,7 @@
 	virtual void setImage(const QImage&) = 0;
 
 	virtual void applyTransformation(Orientation) {}
+	virtual struct ExifInfo *getExifInfo() = 0;
 
 Q_SIGNALS:
 	void imageRectUpdated();
Index: gwenview/lib/documentloadedimpl.cpp
===================================================================
--- gwenview/lib/documentloadedimpl.cpp	(revision 700913)
+++ gwenview/lib/documentloadedimpl.cpp	(working copy)
@@ -102,4 +102,9 @@
 	imageRectUpdated();
 }
 
+struct ExifInfo* DocumentLoadedImpl::getExifInfo() {
+	printf("getexifinfo de documentloadedimpl\n");
+	return NULL;
+}
+
 } // namespace
Index: gwenview/lib/exifinfo.h
===================================================================
--- gwenview/lib/exifinfo.h	(revision 0)
+++ gwenview/lib/exifinfo.h	(revision 0)
@@ -0,0 +1,21 @@
+#ifndef EXIFINFO_H
+#define EXIFINFO_H
+
+#include <QString>
+
+namespace Gwenview {
+
+// This structure contains all Exif information that will be
+// transported from Jpeg level to MainWindow
+
+struct ExifInfo {
+	QString *iso;
+	QString *aperture;
+	QString *focallength;
+	QString *shoottime;
+};
+}
+
+#endif
+
+
Index: gwenview/lib/document.cpp
===================================================================
--- gwenview/lib/document.cpp	(revision 700913)
+++ gwenview/lib/document.cpp	(working copy)
@@ -29,7 +29,9 @@
 // Local
 #include "emptydocumentimpl.h"
 #include "loadingdocumentimpl.h"
+#include "exifinfo.h"
 
+
 namespace Gwenview {
 
 
@@ -148,4 +150,8 @@
 	d->mImpl->applyTransformation(orientation);
 }
 
+struct ExifInfo *Document::getExifInfo() const {
+       return d->mImpl->getExifInfo();
+}
+
 } // namespace
Index: gwenview/lib/jpegdocumentloadedimpl.cpp
===================================================================
--- gwenview/lib/jpegdocumentloadedimpl.cpp	(revision 700913)
+++ gwenview/lib/jpegdocumentloadedimpl.cpp	(working copy)
@@ -80,4 +80,9 @@
 	d->mJpegContent->transform(orientation);
 }
 
+struct ExifInfo* JpegDocumentLoadedImpl::getExifInfo() {
+       return d->mJpegContent->getExifInfo();
+}
+
+
 } // namespace
Index: gwenview/lib/jpegcontent.cpp
===================================================================
--- gwenview/lib/jpegcontent.cpp	(revision 700913)
+++ gwenview/lib/jpegcontent.cpp	(working copy)
@@ -47,6 +47,7 @@
 
 // Local
 #include "jpegerrormanager.h"
+#include "exifinfo.h"
 
 namespace Gwenview {
 
@@ -142,6 +143,9 @@
 	QByteArray mRawData;
 	QSize mSize;
 	QString mComment;
+
+	ExifInfo *mExifInfo;
+
 	bool mPendingTransformation;
 	QMatrix mTransformMatrix;
 	Exiv2::ExifData mExifData;
@@ -273,11 +277,44 @@
 	default:
 		break;
 	}
+	
+	saveExifInfo();
 
 	return true;
 }
 
+//carles
+QString *JpegContent::getexifinformation(const QString exifkey) const {
+	QString ret;
+     
+	Exiv2::ExifKey key((const char*)exifkey.toLatin1());
+	Exiv2::ExifData::iterator it = d->mExifData.findKey(key);
 
+	if (it != d->mExifData.end()) {
+		std::ostringstream outputString;
+		outputString << *it;
+		ret=QString(outputString.str().c_str());
+	}
+	else {
+		ret=QString("n/a");
+	}
+	return new QString(ret);
+}
+
+void JpegContent::saveExifInfo() const {
+	d->mExifInfo = new ExifInfo;
+
+	d->mExifInfo->iso = getexifinformation("Exif.Photo.ISOSpeedRatings");
+	d->mExifInfo->shoottime = getexifinformation("Exif.Photo.ExposureTime");
+	d->mExifInfo->focallength = getexifinformation("Exif.Photo.FocalLength");
+	d->mExifInfo->aperture = getexifinformation("Exif.Photo.FNumber");
+}
+
+struct ExifInfo* JpegContent::getExifInfo() const {
+	return d->mExifInfo;
+}
+
+
 Orientation JpegContent::orientation() const {
 	Exiv2::ExifKey key("Exif.Image.Orientation");
 	Exiv2::ExifData::iterator it = d->mExifData.findKey(key);
Index: gwenview/lib/loadingdocumentimpl.cpp
===================================================================
--- gwenview/lib/loadingdocumentimpl.cpp	(revision 700913)
+++ gwenview/lib/loadingdocumentimpl.cpp	(working copy)
@@ -258,4 +258,8 @@
 	kWarning() << k_funcinfo << " should not be called\n";
 }
 
+struct ExifInfo* LoadingDocumentImpl::getExifInfo() {
+	return mJpegImpl->getExifInfo();
+}
+
 } // namespace
Index: gwenview/lib/document.h
===================================================================
--- gwenview/lib/document.h	(revision 700913)
+++ gwenview/lib/document.h	(working copy)
@@ -25,6 +25,7 @@
 // Qt
 #include <QObject>
 #include <QSharedData>
+#include <QString>
 
 // KDE
 #include <ksharedptr.h>
@@ -91,6 +92,8 @@
 
 	void waitUntilLoaded() const;
 
+	struct ExifInfo *getExifInfo() const;
+
 Q_SIGNALS:
 	void imageRectUpdated();
 	void loaded();
Index: gwenview/lib/jpegcontent.h
===================================================================
--- gwenview/lib/jpegcontent.h	(revision 700913)
+++ gwenview/lib/jpegcontent.h	(working copy)
@@ -59,6 +59,9 @@
 	bool save(const QString& file);
 	bool save(QIODevice*);
 
+	struct ExifInfo* getExifInfo() const;
+	void saveExifInfo() const;
+
 private:
 	struct Private;
 	Private *d;
@@ -67,6 +70,8 @@
 	void operator=(const JpegContent&);
 	void applyPendingTransformation();
 	int dotsPerMeter(const QString& keyName) const;
+	
+	QString *getexifinformation(const QString exifkey) const;
 };
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.