Changeset 334 for trunk/src/gui/kernel/qmime_pm.cpp
- Timestamp:
- Nov 20, 2009, 7:39:03 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gui/kernel/qmime_pm.cpp
r332 r334 246 246 247 247 /*! 248 \fn Q StringListQPMMime::mimesForFormats(const QList<ULONG> &formats) const248 \fn QList<MimeCFPair> QPMMime::mimesForFormats(const QList<ULONG> &formats) const 249 249 250 250 Returns a list of mime types that will be created form the specified \a list 251 251 of \a formats, in order of precedence (the most suitable mime type comes 252 252 first), or an empty list if neither of the \a formats is supported by this 253 converter. 253 converter. Note that each pair in the returned list consists of the mime 254 type name and the corresponding format identifier. 254 255 255 256 All subclasses must reimplement this pure virtual function. … … 276 277 QList<QPMMime*> mimes = theMimeList()->mimes(); 277 278 for (int i = mimes.size()-1; i >= 0; --i) { 278 Q StringListfmts = mimes[i]->mimesForFormats(formats);279 QList<MimeCFPair> fmts = mimes[i]->mimesForFormats(formats); 279 280 int priority = 0; 280 foreach ( QStringfmt, fmts) {281 foreach (MimeCFPair fmt, fmts) { 281 282 ++priority; 282 283 QList<Match>::iterator it = matches.begin(); 283 284 for (; it != matches.end(); ++it) { 284 285 Match &match = *it; 285 if (match.mime == fmt ) {286 if (match.mime == fmt.first) { 286 287 // replace if priority is higher, ignore otherwise 287 288 if (priority < match.priority) { 288 289 match.converter = mimes[i]; 290 match.format = fmt.second; 289 291 match.priority = priority; 290 292 } … … 293 295 } 294 296 if (it == matches.end()) { 295 matches += Match(mimes[i], fmt , priority);297 matches += Match(mimes[i], fmt.first, fmt.second, priority); 296 298 } 297 299 } … … 344 346 ULONG &flags, ULONG *data) const; 345 347 346 Q StringListmimesForFormats(const QList<ULONG> &formats) const;348 QList<MimeCFPair> mimesForFormats(const QList<ULONG> &formats) const; 347 349 QVariant convertFromFormat(ULONG format, ULONG flags, ULONG data, 348 350 const QString &mimeType, … … 388 390 int maxsize = str.size()+str.size()/40+3; 389 391 r.fill('\0', maxsize); 390 char *o = r.data();391 const char *d = str.data();392 char *o = r.data(); 393 const char *d = str.data(); 392 394 const int s = str.size(); 393 395 bool cr = false; … … 454 456 } 455 457 456 Q StringListQPMMimeText::mimesForFormats(const QList<ULONG> &formats) const457 { 458 Q StringListmimes;458 QList<QPMMime::MimeCFPair> QPMMimeText::mimesForFormats(const QList<ULONG> &formats) const 459 { 460 QList<MimeCFPair> mimes; 459 461 foreach(ULONG cf, formats) { 460 if (cf == CF_TEXT || cf == CF_TextUnicode){ 461 mimes << QLatin1String("text/plain"); 462 break; 463 } 462 // prefer unicode over local8Bit 463 if (cf == CF_TextUnicode) 464 mimes.prepend(qMakePair(QString(QLatin1String("text/plain")), cf)); 465 if (cf == CF_TEXT) 466 mimes.append(qMakePair(QString(QLatin1String("text/plain")), cf)); 464 467 } 465 468 return mimes; … … 470 473 QVariant::Type preferredType) const 471 474 { 472 return QVariant(); 475 QVariant ret; 476 477 // @todo why is it startsWith? the rest of the mime specification (encoding, 478 // etc) isn't taken into account... Anyway, copied the logic from Windows. 479 if (!mimeType.startsWith("text/plain")) 480 return ret; 481 if (!(flags & CFI_POINTER) || !data) 482 return ret; 483 484 QString str; 485 486 if (format == CF_TEXT) { 487 const char *d = (const char *)data; 488 QByteArray r(""); 489 if (*d) { 490 const int s = qstrlen(d); 491 r.fill('\0', s); 492 char *o = r.data(); 493 int j = 0; 494 for (int i = 0; i < s; i++) { 495 char c = d[i]; 496 if (c != '\r') 497 o[j++] = c; 498 } 499 } 500 str = QString::fromLocal8Bit(r); 501 } else if (format == CF_TextUnicode) { 502 str = QString::fromUtf16((const unsigned short *)data); 503 str.replace(QLatin1String("\r\n"), QLatin1String("\n")); 504 } 505 506 if (preferredType == QVariant::String) 507 ret = str; 508 else 509 ret = str.toUtf8(); 510 511 return ret; 473 512 } 474 513
Note:
See TracChangeset
for help on using the changeset viewer.