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