Changeset 338


Ignore:
Timestamp:
Nov 22, 2009, 10:43:33 PM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

gui/kernel: mime: Make sure the fallback converter doesn't participate in the conversion if there is a specialized converter that already presented the given MIME type in the clipboard (to avoid unnecessary duplication of representations).

Location:
trunk/src/gui/kernel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gui/kernel/qmime.h

    r337 r338  
    122122    virtual ~QPMMime();
    123123
     124
     125
     126
     127
     128
     129
     130
    124131    // for converting from Qt
    125     virtual QList<ULONG> formatsForMimeData(const QMimeData *mimeData) const = 0;
     132    virtual QList<> formatsForMimeData(const QMimeData *mimeData) const = 0;
    126133    virtual bool convertFromMimeData(const QMimeData *mimeData, ULONG format,
    127134                                     ULONG &flags, ULONG *data) const = 0;
    128 
    129     typedef QPair<QString, ULONG> MimeCFPair;
    130 
    131135    // for converting to Qt
    132136    virtual QList<MimeCFPair> mimesForFormats(const QList<ULONG> &formats) const = 0;
     
    154158            converter(c), mime(f), format(cf), priority(p) {}
    155159
    156         Match(QPMMime *c, ULONG f, int p) :
    157             converter(c), format(f), priority(p) {}
    158 
    159160        QPMMime *converter;
    160         QString mime; // used by allConvertersFromFormats()
    161         ULONG format; // used by allConvertersFromFormats()/allConvertersFromMimeData()
     161        QString mime;
     162        ULONG format;
    162163        int priority;
    163164    };
  • trunk/src/gui/kernel/qmime_pm.cpp

    r337 r338  
    204204
    205205/*!
    206     \fn QList<ULONG> QPMMime::formatsForMimeData(const QMimeData *mimeData) const
     206    \fn QList<> QPMMime::formatsForMimeData(const QMimeData *mimeData) const
    207207
    208208    Returns a list of ULONG values representing the different OS/2 PM
     
    210210    precedence (the most suitable format goes first), or an empty list if
    211211    neither of the mime types provided by \a mimeData is supported by this
    212     converter.
     212    converter. Note that each item in the returned list is actually a pair
     213    consisting of the mime type name and the corresponding format identifier.
    213214
    214215    All subclasses must reimplement this pure virtual function.
     
    250251    of \a formats, in order of precedence (the most suitable mime type comes
    251252    first), or an empty list if neither of the \a formats is supported by this
    252     converter. Note that each pair in the returned list consists of the mime
    253     type name and the corresponding format identifier.
     253    converter. Note that each
     254    type name and the corresponding format identifier.
    254255
    255256    All subclasses must reimplement this pure virtual function.
     
    283284            for (; it != matches.end(); ++it) {
    284285                Match &match = *it;
    285                 if (match.mime == fmt.first) {
     286                if (match.mime == fmt.) {
    286287                    // replace if priority is higher, ignore otherwise
    287288                    if (priority < match.priority) {
    288289                        match.converter = mime;
    289                         match.format = fmt.second;
     290                        match.format = fmt.;
    290291                        match.priority = priority;
    291292                    }
     
    294295            }
    295296            if (it == matches.end()) {
    296                 matches += Match(mime, fmt.first, fmt.second, priority);
     297                matches += Match(mime, fmt., priority);
    297298            }
    298299        }
     
    309310    QList<QPMMime*> mimes = theMimeList()->mimes();
    310311    foreach(QPMMime *mime, mimes) {
    311         QList<ULONG> cfs = mime->formatsForMimeData(mimeData);
     312        QList<s = mime->formatsForMimeData(mimeData);
    312313        int priority = 0;
    313         foreach (ULONG cf, cfs) {
     314        foreach (s) {
    314315            ++priority;
    315316            QList<Match>::iterator it = matches.begin();
    316317            for (; it != matches.end(); ++it) {
    317318                Match &match = *it;
    318                 if (match.format == cf) {
     319                if (mime == mimes.last()) { // QPMMimeAnyMime?
     320                    if (match.mime == fmt.mime){
     321                        // we assume that specialized converters (that come
     322                        // first) provide a more precise conversion than
     323                        // QPMMimeAnyMime and don't let it get into the list in
     324                        // order to avoid unnecessary duplicate representations
     325                        break;
     326                    }
     327                }
     328                if (match.format == fmt.format) {
    319329                    // replace if priority is higher, ignore otherwise
    320330                    if (priority < match.priority) {
    321331                        match.converter = mime;
     332
    322333                        match.priority = priority;
    323334                    }
     
    326337            }
    327338            if (it == matches.end()) {
    328                 matches += Match(mime, cf, priority);
     339                matches += Match(mime, , priority);
    329340            }
    330341        }
     
    355366
    356367    // for converting from Qt
    357     QList<ULONG> formatsForMimeData(const QMimeData *mimeData) const;
     368    QList<> formatsForMimeData(const QMimeData *mimeData) const;
    358369    bool convertFromMimeData(const QMimeData *mimeData, ULONG format,
    359370                             ULONG &flags, ULONG *data) const;
     
    375386}
    376387
    377 QList<ULONG> QPMMimeText::formatsForMimeData(const QMimeData *mimeData) const
    378 {
    379     QList<ULONG> cfs;
     388QList<> QPMMimeText::formatsForMimeData(const QMimeData *mimeData) const
     389{
     390    QList<s;
    380391    if (mimeData->hasText())
    381         cfs << CF_TEXT << CF_TextUnicode;
    382     return cfs;
     392        fmts << MimeCFPair(QLatin1String("text/plain"), CF_TEXT)
     393             << MimeCFPair(QLatin1String("text/plain"), CF_TextUnicode);
     394    return fmts;
    383395}
    384396
     
    477489        // prefer unicode over local8Bit
    478490        if (cf == CF_TextUnicode)
    479             mimes.prepend(qMakePair(QString(QLatin1String("text/plain")), cf));
     491            mimes.prepend(), cf));
    480492        if (cf == CF_TEXT)
    481             mimes.append(qMakePair(QString(QLatin1String("text/plain")), cf));
     493            mimes.append(), cf));
    482494    }
    483495    return mimes;
     
    535547
    536548    // for converting from Qt
    537     QList<ULONG> formatsForMimeData(const QMimeData *mimeData) const;
     549    QList<> formatsForMimeData(const QMimeData *mimeData) const;
    538550    bool convertFromMimeData(const QMimeData *mimeData, ULONG format,
    539551                             ULONG &flags, ULONG *data) const;
     
    581593}
    582594
    583 QList<ULONG> QPMMimeAnyMime::formatsForMimeData(const QMimeData *mimeData) const
    584 {
    585     QList<ULONG> cfs;
     595QList<> QPMMimeAnyMime::formatsForMimeData(const QMimeData *mimeData) const
     596{
     597    QList<s;
    586598
    587599    QStringList mimes = QInternalMimeData::formatsHelper(mimeData);
     
    591603            cf = registerMimeType(mime);
    592604        if (cf)
    593             cfs << cf;
    594     }
    595 
    596     return cfs;
     605            ;
     606    }
     607
     608    return s;
    597609}
    598610
     
    631643            mime = registerFormat(format);
    632644        if (!mime.isEmpty())
    633             mimes << qMakePair(mime, format);
     645            mimes << Pair(mime, format);
    634646    }
    635647
Note: See TracChangeset for help on using the changeset viewer.