Bug 165068

Summary: Gwenview opens image as binary stuff instead of showing it when being called from konsole
Product: [Applications] gwenview Reporter: Elias Probst <mail>
Component: generalAssignee: Gwenview Bugs <gwenview-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: sven.burmeister
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: Screenshot showing Gwenview how it displays binary stuff instead of an image

Description Elias Probst 2008-06-27 02:50:10 UTC
Version:           SVN r824722 (using Devel)
Installed from:    Compiled sources

How to reproduce:
- Open a konsole
- Paste an URL like this http://bugs.kde.org/attachment.cgi?id=25418&action=view
- Rightclick on the URL → Open Link

Now Gwenview starts, but instead of displaying the image, it just shows strange binary stuff (see following attachment).

This doesn't happen when the MIMEtype of the URL can be directly determined by Konsole like in this one:
http://eliasprobst.eu/~elias/stuff/screenshots/kde4-issues/gwenview/zooming-widget-preview-plasmoid.png
Comment 1 Elias Probst 2008-06-27 02:51:23 UTC
Created attachment 25641 [details]
Screenshot showing Gwenview how it displays binary stuff instead of an image
Comment 2 Drew Fisher 2008-06-27 02:59:24 UTC
I can reproduce this bug on compiled SVN r824835.
Comment 3 Ilya Konkov 2008-06-27 10:06:28 UTC
Looks like KIO::NetAccess::mimetype() can't handle such url and returns "text/html".
This hack solves the problem for me, but I'm sure there is better solution:

Index: lib/mimetypeutils.cpp
===================================================================
--- lib/mimetypeutils.cpp	(revision 825004)
+++ lib/mimetypeutils.cpp	(working copy)
@@ -91,6 +91,13 @@
 		// No luck, look deeper. This can happens with http urls if the filename
 		// does not provide any extension.
 		mimeType = KIO::NetAccess::mimetype(url, KApplication::kApplication()->activeWindow());
+		if (mimeType == "text/html") {
+			QString tmpFile;
+			if( KIO::NetAccess::download(url, tmpFile, KApplication::kApplication()->activeWindow())) {
+				mimeType = KMimeType::findByFileContent(tmpFile);
+ 				KIO::NetAccess::removeTempFile(tmpFile);
+			}
+		}
 	}
 	return mimeType;
 }
Comment 4 Aurelien Gateau 2008-07-06 23:45:07 UTC
Ilya Konkov wrote:
[bugs.kde.org quoted mail]

If I am not mistaken, this patch will cause the image to be downloaded 
twice. This is not good.

It would be better to use KParts::BrowserRun(). You need to:

- Inherit from KParts::BrowserRun() to overload slotBrowserMimeType() so 
that it notifies the outside world when the mimetype is known.

- Modify DocumentView::createPartForUrl() to instantiate your BrowserRun 
and use the mimetype notification to instantiate the appropriate KPart. 
You probably need to add an internal event loop [1]
to wait for slotBrowserMimeType() to be called.

[1] Something like:
while (doNotHaveMimeType) {
	qApp->processEvents(ExcludeUserInput);
}
Comment 5 Aurelien Gateau 2008-07-16 00:06:15 UTC
SVN commit 832982 by gateau:

If we get mimetype=="text/html" from a remote url,
download a chunk of it to determine the real mimetype.
BUG:165068


 M  +7 -0      app/documentview.cpp  
 M  +41 -1     lib/mimetypeutils.cpp  
 M  +5 -0      lib/mimetypeutils.h  
 A             lib/mimetypeutils_p.h   [License: GPL (v2+)]


WebSVN link: http://websvn.kde.org/?view=rev&revision=832982
Comment 6 S. Burmeister 2008-10-13 19:35:31 UTC
I still see this: Go to https://forgesvn1.novell.com/svn/opensuse-art/trunk/app-splashes/kde/ right-click on mockup.png, pick open with > gwenview and you will only get binary code showing up in gwenview (2.1.2)
Comment 7 Elias Probst 2008-10-13 22:42:26 UTC
Confirmed on latest trunk (r870681).
Comment 8 Aurelien Gateau 2008-10-21 09:48:15 UTC
I can reproduce it with Gwenview 2.1.2, but not with latest trunk (r874181).