Ignore:
Timestamp:
Jul 6, 2006, 11:11:46 PM (19 years ago)
Author:
dmik
Message:

QTextDrag: decode() gives mime types in Unicode encodings a higher priprity (to guarantee loseless decoding); "text/whatever" w/o any charset is reported as the first mime format (for better integration with native drop targets).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel/qdragobject.cpp

    r8 r96  
    607607
    608608    switch ( i ) {
     609#if defined(Q_WS_PM)
     610      // We want "text/whatever" w/o any charset to be the first (the "default")
     611      // mime type of the QTextDrag object, so that a rendering mechanism/format
     612      // pair for it will be the first in the RMF list, wchich is essential for
     613      // some native drop targets (i.e. WPS) to render text correctly. Note that
     614      // it won't hide unicode data from Qt apps because QTextDrag::decode()
     615      // for Q_WS_PM prefers unicode mime types (see the implementation below).
     616      case 0:
     617        return "";
     618      case 1:
     619        if ( localcharset.isNull() ) {
     620            QTextCodec *localCodec = QTextCodec::codecForLocale();
     621            if ( localCodec ) {
     622                localcharset = localCodec->name();
     623                localcharset = localcharset.lower();
     624                stripws(localcharset);
     625            } else {
     626                localcharset = "";
     627            }
     628        }
     629        return localcharset;
     630      case 2:
     631        return "UTF-8";
     632      case 3:
     633        return "ISO-10646-UCS-2";
     634#else
    609635      case 0:
    610636        return "UTF-8";
     
    625651        }
    626652        return localcharset;
     653#endif       
    627654    }
    628655    return 0;
     
    898925    }
    899926
     927#if defined(Q_WS_PM)
     928    // We give Unicode formats a higher priority, so that if there are several
     929    // encodings of the same subtype present in the given mime source, a
     930    // Unicode one will be used for decoding. Otherwise, the first recognized
     931    // format will be choosen.
     932    int fallbackMime = -1;
     933    bool secondPass = FALSE;
     934
     935    const char *mime;
     936    for( int i = 0; /* FOREVER */; ++i ) {
     937        mime = e->format( i );
     938        if ( !mime ) {
     939            // We went through all mimes but didn't find Unicode. If there is
     940            // a fall-back mime, iterate again starting directly from it.
     941            if ( !secondPass && fallbackMime >= 0 ) {
     942                i = fallbackMime - 1; // will do ++i on continue
     943                secondPass = TRUE;
     944                continue;
     945            }
     946            break;
     947        }
     948#else       
    900949    const char* mime;
    901950    for (int i=0; (mime = e->format(i)); i++) {
     951#endif   
    902952        if ( 0==qstrnicmp(mime,"text/",5) ) {
    903953            QCString m(mime);
     
    916966                    codec = qt_findcharset(m);
    917967                if ( codec ) {
     968#if defined(Q_WS_PM)
     969                    if ( codec->mibEnum() == 1000 /* ISO-10646-UCS-2 */ ||
     970                         codec->mibEnum() == 106 /* UTF-8 */ ) {
     971                        // no need to try it again on the second pass
     972                        if ( secondPass )
     973                            continue;
     974                    } else if ( !secondPass ) {
     975                        // memorize the fall-back mime on the first pass
     976                        if ( fallbackMime < 0 )
     977                            fallbackMime = i;
     978                        continue;
     979                    }
     980#endif
    918981                    QByteArray payload;
    919 
    920982                    payload = e->encodedData(mime);
    921983                    if ( payload.size() ) {
Note: See TracChangeset for help on using the changeset viewer.