Changeset 561 for trunk/src/gui/kernel/qmime_mac.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/kernel/qmime_mac.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 69 69 #include <private/qt_mac_p.h> 70 70 71 71 72 #ifdef Q_WS_MAC32 72 73 #include <QuickTime/QuickTime.h> 73 #include "qlibrary.h"74 #include <qlibrary.h> 74 75 #endif 75 76 … … 128 129 /*! 129 130 \class QMacPasteboardMime 130 \brief The QMacPasteboardMime class maps open-standard MIME to Mac flavors. 131 \brief The QMacPasteboardMime class converts between a MIME type and a 132 \l{http://developer.apple.com/macosx/uniformtypeidentifiers.html}{Uniform 133 Type Identifier (UTI)} format. 131 134 \since 4.2 132 \ingroup io 135 133 136 \ingroup draganddrop 134 \ingroup misc 135 136 Qt's drag and drop support and clipboard facilities use the MIME137 standard. On X11, this maps trivially to the Xdnd protocol, but on138 Mac although some applications use MIME types to describe clipboard139 formats, others use arbitrary non-standardized naming conventions, 140 or unnamed built-in Mac formats.141 142 By instantiating subclasses of QMacPasteboardMime that provide conversions143 between Mac flavors and MIME formats, you can convert proprietary 144 clipboard formats to MIME formats.145 146 Qt has predefined support for the following Mac flavors:137 138 Qt's drag and drop and clipboard facilities use the MIME 139 standard. On X11, this maps trivially to the Xdnd protocol. On 140 Mac, although some applications use MIME to describe clipboard 141 contents, it is more common to use Apple's UTI format. 142 143 QMacPasteboardMime's role is to bridge the gap between MIME and UTI; 144 By subclasses this class, one can extend Qt's drag and drop 145 and clipboard handling to convert to and from unsupported, or proprietary, UTI formats. 146 147 A subclass of QMacPasteboardMime will automatically be registered, and active, upon instantiation. 148 149 Qt has predefined support for the following UTIs: 147 150 \list 148 \i kScrapFlavorTypeUnicode - converted to "text/plain;charset=ISO-10646-UCS-2" 149 \i kScrapFlavorTypeText - converted to "text/plain;charset=system" or "text/plain" 150 \i kScrapFlavorTypePicture - converted to "application/x-qt-image" 151 \i typeFileURL - converted to "text/uri-list" 151 \i public.utf8-plain-text - converts to "text/plain" 152 \i public.utf16-plain-text - converts to "text/plain" 153 \i public.html - converts to "text/html" 154 \i public.url - converts to "text/uri-list" 155 \i public.file-url - converts to "text/uri-list" 156 \i public.tiff - converts to "application/x-qt-image" 157 \i com.apple.traditional-mac-plain-text - converts to "text/plain" 158 \i com.apple.pict - converts to "application/x-qt-image" 152 159 \endlist 153 160 154 You can check if a MIME type is convertible using canConvert() and 155 can perform conversions with convertToMime() and convertFromMime(). 161 When working with MIME data, Qt will interate through all instances of QMacPasteboardMime to 162 find an instance that can convert to, or from, a specific MIME type. It will do this by calling 163 canConvert() on each instance, starting with (and choosing) the last created instance first. 164 The actual conversions will be done by using convertToMime() and convertFromMime(). 165 166 \note The API uses the term "flavor" in some cases. This is for backwards 167 compatibility reasons, and should now be understood as UTIs. 156 168 */ 157 169 … … 207 219 return QString(); 208 220 QString ret = QLatin1String("com.trolltech.anymime.") + mime; 209 return ret.replace(QLatin1 String("/"), QLatin1String("--"));221 return ret.replace(QLatin1Char('/'), QLatin1String("--")); 210 222 } 211 223 … … 383 395 if (i >= 0) { 384 396 QString cs(mime.mid(i+8).toLower()); 385 i = cs.indexOf(QLatin1 String(";"));397 i = cs.indexOf(QLatin1Char(';')); 386 398 if (i>=0) 387 399 cs = cs.left(i); … … 496 508 #ifdef Q_WS_MAC32 497 509 510 // This can be removed once 10.6 is the minimum (or we have to require 64-bit) whichever comes first. 511 498 512 typedef ComponentResult (*PtrGraphicsImportSetDataHandle)(GraphicsImportComponent, Handle); 499 513 typedef ComponentResult (*PtrGraphicsImportCreateCGImage)(GraphicsImportComponent, CGImageRef*, UInt32); … … 626 640 return ret; 627 641 } 628 #endif 642 643 644 #endif //Q_WS_MAC32 629 645 630 646 class QMacPasteboardMimeTiff : public QMacPasteboardMime { … … 673 689 const QByteArray &a = data.first(); 674 690 QCFType<CGImageRef> image; 675 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 676 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { 677 QCFType<CFDataRef> data = CFDataCreateWithBytesNoCopy(0, 678 reinterpret_cast<const UInt8 *>(a.constData()), 679 a.size(), kCFAllocatorNull); 680 QCFType<CGImageSourceRef> imageSource = CGImageSourceCreateWithData(data, 0); 681 image = CGImageSourceCreateImageAtIndex(imageSource, 0, 0); 682 } else 683 #endif 684 { 685 #ifdef Q_WS_MAC32 686 if (resolveMimeQuickTimeSymbols()) { 687 Handle tiff = NewHandle(a.size()); 688 memcpy(*tiff, a.constData(), a.size()); 689 GraphicsImportComponent graphicsImporter; 690 ComponentResult result = OpenADefaultComponent(GraphicsImporterComponentType, 691 kQTFileTypeTIFF, &graphicsImporter); 692 if (!result) 693 result = ptrGraphicsImportSetDataHandle(graphicsImporter, tiff); 694 if (!result) 695 result = ptrGraphicsImportCreateCGImage(graphicsImporter, &image, 696 kGraphicsImportCreateCGImageUsingCurrentSettings); 697 CloseComponent(graphicsImporter); 698 DisposeHandle(tiff); 699 } 700 #endif 701 } 691 QCFType<CFDataRef> tiffData = CFDataCreateWithBytesNoCopy(0, 692 reinterpret_cast<const UInt8 *>(a.constData()), 693 a.size(), kCFAllocatorNull); 694 QCFType<CGImageSourceRef> imageSource = CGImageSourceCreateWithData(tiffData, 0); 695 image = CGImageSourceCreateImageAtIndex(imageSource, 0, 0); 702 696 703 697 if (image != 0) … … 842 836 } 843 837 838 class QMacPasteboardMimeUrl : public QMacPasteboardMime { 839 public: 840 QMacPasteboardMimeUrl() : QMacPasteboardMime(MIME_ALL) { } 841 QString convertorName(); 842 843 QString flavorFor(const QString &mime); 844 QString mimeFor(QString flav); 845 bool canConvert(const QString &mime, QString flav); 846 QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav); 847 QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav); 848 }; 849 850 QString QMacPasteboardMimeUrl::convertorName() 851 { 852 return QLatin1String("URL"); 853 } 854 855 QString QMacPasteboardMimeUrl::flavorFor(const QString &mime) 856 { 857 if(mime.startsWith(QLatin1String("text/uri-list"))) 858 return QLatin1String("public.url"); 859 return QString(); 860 } 861 862 QString QMacPasteboardMimeUrl::mimeFor(QString flav) 863 { 864 if(flav == QLatin1String("public.url")) 865 return QLatin1String("text/uri-list"); 866 return QString(); 867 } 868 869 bool QMacPasteboardMimeUrl::canConvert(const QString &mime, QString flav) 870 { 871 return flav == QLatin1String("public.url") 872 && mime == QLatin1String("text/uri-list"); 873 } 874 875 QVariant QMacPasteboardMimeUrl::convertToMime(const QString &mime, QList<QByteArray> data, QString flav) 876 { 877 if(!canConvert(mime, flav)) 878 return QVariant(); 879 880 QList<QVariant> ret; 881 for (int i=0; i<data.size(); ++i) { 882 QUrl url = QUrl::fromEncoded(data.at(i)); 883 if (url.host().toLower() == QLatin1String("localhost")) 884 url.setHost(QString()); 885 url.setPath(url.path().normalized(QString::NormalizationForm_C)); 886 ret.append(url); 887 } 888 return QVariant(ret); 889 } 890 891 QList<QByteArray> QMacPasteboardMimeUrl::convertFromMime(const QString &mime, QVariant data, QString flav) 892 { 893 QList<QByteArray> ret; 894 if (!canConvert(mime, flav)) 895 return ret; 896 897 QList<QVariant> urls = data.toList(); 898 for(int i=0; i<urls.size(); ++i) { 899 QUrl url = urls.at(i).toUrl(); 900 if (url.scheme().isEmpty()) 901 url.setScheme(QLatin1String("file")); 902 if (url.scheme().toLower() == QLatin1String("file")) { 903 if (url.host().isEmpty()) 904 url.setHost(QLatin1String("localhost")); 905 url.setPath(url.path().normalized(QString::NormalizationForm_D)); 906 } 907 ret.append(url.toEncoded()); 908 } 909 return ret; 910 } 911 844 912 #ifdef QT3_SUPPORT 845 913 class QMacPasteboardMimeQt3Any : public QMacPasteboardMime { … … 1038 1106 new QMacPasteboardMimeTiff; 1039 1107 #ifdef Q_WS_MAC32 1040 new QMacPasteboardMimePict; 1108 // 10.6 does automatic synthesis to and from PICT to standard image types (like TIFF), 1109 // so don't bother doing it ourselves, especially since it's not available in 64-bit. 1110 if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_6) 1111 new QMacPasteboardMimePict; 1041 1112 #endif 1042 1113 new QMacPasteboardMimeUnicodeText; … … 1044 1115 new QMacPasteboardMimeHTMLText; 1045 1116 new QMacPasteboardMimeFileUri; 1117 new QMacPasteboardMimeUrl; 1046 1118 new QMacPasteboardMimeTypeName; 1047 1119 //make sure our "non-standard" types are always last! --Sam
Note:
See TracChangeset
for help on using the changeset viewer.