cacaa8c
qt-bugs@ issue : 38642
cacaa8c
bugs.kde.org number : 71084
cacaa8c
applied: no
cacaa8c
author: Lubos Lunak <l.lunak@kde.org>
cacaa8c
cacaa8c
Hello,
cacaa8c
cacaa8c
 start Mozilla, go e.g. to http://kde.org, start KWrite (or basically any Qt 
cacaa8c
app that accepts text drops), select 'Conquer your Desktop!', and try to 
cacaa8c
drag&drop it onto KWrite. The only text pasted should be 'm'.
cacaa8c
cacaa8c
 I don't know much the related mimetype and encoding stuff, so I'm unsure 
cacaa8c
whose fault this actually is. The text drag is provided as a lot of 
cacaa8c
text/something targets, to list some text/_moz_htmlinfo, text/x-moz-url, 
cacaa8c
text/unicode and similar. The problem is, Kate uses QTextDrag::decode() with 
cacaa8c
no subtype specified, probably with the intention that as Kate is a text 
cacaa8c
editor, it can accept any text pasted. And since the first target provided by 
cacaa8c
mozilla is text/x-moz-url, (which moreover seems to be encoded as 16bit 
cacaa8c
unicode), the text dropped is completely wrong. You can easily see all 
cacaa8c
targets provided by Mozilla with see_mime.patch applied.
cacaa8c
cacaa8c
 Solution #1: Say that Kate (any pretty much everybody else expecting text) 
cacaa8c
should say "plain" as the subtype. In such case, I suggest you drop the 
cacaa8c
QTextDrag::decode() variant with no subtype specified, and stress more the 
cacaa8c
fact that not specifying a subtype can result in a lot of rubbish. It's 
cacaa8c
simply too tempting to leave the subtype empty and try to accept anything.
cacaa8c
cacaa8c
 Solution #2: When trying to accept anything, try to get useful data. Which 
cacaa8c
means either sorting the subtypes available somehow, checking only the ones 
cacaa8c
Qt knows.
cacaa8c
cacaa8c
 To me, #1 seems to be a better choice, or possibly at least something like 
cacaa8c
the attached QTextDrag patch, which simply always tries first "plain" subtype 
cacaa8c
if none is specified. With this patch, Mozilla even works (that's irony, of 
cacaa8c
course, Mozilla still pastes the text/plain text as HTML, but at least now it 
cacaa8c
pastes something where it's easy to point at the offender).
cacaa8c
cacaa8c
cacaa8c
--- src/kernel/qdragobject.cpp.sav	2004-01-06 19:24:35.000000000 +0100
cacaa8c
+++ src/kernel/qdragobject.cpp	2004-01-06 19:47:01.000000000 +0100
cacaa8c
@@ -844,6 +844,16 @@ bool QTextDrag::decode( const QMimeSourc
cacaa8c
 {
cacaa8c
     if(!e)
cacaa8c
 	return FALSE;
cacaa8c
+        
cacaa8c
+    // when subtype is not specified, try text/plain first, otherwise this may read
cacaa8c
+    // things like text/x-moz-url even though better targets are available
cacaa8c
+    if( subtype.isNull()) {
cacaa8c
+        QCString subtmp = "plain";
cacaa8c
+        if( decode( e, str, subtmp )) {
cacaa8c
+            subtype = subtmp;
cacaa8c
+            return true;
cacaa8c
+        }
cacaa8c
+    }
cacaa8c
 
cacaa8c
     if ( e->cacheType == QMimeSource::Text ) {
cacaa8c
 	str = *e->cache.txt.str;