Qt 4.8
qmime_mac.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qmime.h"
43 
44 //#define USE_INTERNET_CONFIG
45 
46 #ifndef USE_INTERNET_CONFIG
47 # include "qfile.h"
48 # include "qfileinfo.h"
49 # include "qtextstream.h"
50 # include "qdir.h"
51 # include <unistd.h>
52 # include <sys/types.h>
53 # include <sys/stat.h>
54 # include <sys/fcntl.h>
55 #endif
56 
57 #include "qdebug.h"
58 #include "qpixmap.h"
59 #include "qimagewriter.h"
60 #include "qimagereader.h"
61 #include "qdatastream.h"
62 #include "qbuffer.h"
63 #include "qdatetime.h"
64 #include "qapplication_p.h"
65 #include "qtextcodec.h"
66 #include "qregexp.h"
67 #include "qurl.h"
68 #include "qmap.h"
69 #include <private/qt_mac_p.h>
70 
71 
72 #ifdef Q_WS_MAC32
73 #include <QuickTime/QuickTime.h>
74 #include <qlibrary.h>
75 #endif
76 
78 
79 extern CGImageRef qt_mac_createCGImageFromQImage(const QImage &img, const QImage **imagePtr = 0); // qpaintengine_mac.cpp
80 
82 Q_GLOBAL_STATIC(MimeList, globalMimeList)
83 
84 static void cleanup_mimes()
85 {
86  MimeList *mimes = globalMimeList();
87  while (!mimes->isEmpty())
88  delete mimes->takeFirst();
89 }
90 
91 Q_GLOBAL_STATIC(QStringList, globalDraggedTypesList)
92 
93 
110 {
111  (*globalDraggedTypesList()) += types;
112 }
113 
115 {
116  return (*globalDraggedTypesList());
117 }
118 
119 
120 /*****************************************************************************
121  QDnD debug facilities
122  *****************************************************************************/
123 //#define DEBUG_MIME_MAPS
124 
125 ScrapFlavorType qt_mac_mime_type = 'CUTE';
126 CFStringRef qt_mac_mime_typeUTI = CFSTR("com.pasteboard.trolltech.marker");
127 
181 {
182  globalMimeList()->append(this);
183 }
184 
190 {
192  globalMimeList()->removeAll(this);
193 }
194 
196 private:
197 
198 public:
200  }
202  }
204 
205  QString flavorFor(const QString &mime);
206  QString mimeFor(QString flav);
207  bool canConvert(const QString &mime, QString flav);
209  QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav);
210 };
211 
213 {
214  return QLatin1String("Any-Mime");
215 }
216 
218 {
219  // do not handle the mime type name in the drag pasteboard
220  if(mime == QLatin1String("application/x-qt-mime-type-name"))
221  return QString();
222  QString ret = QLatin1String("com.trolltech.anymime.") + mime;
223  return ret.replace(QLatin1Char('/'), QLatin1String("--"));
224 }
225 
227 {
228  const QString any_prefix = QLatin1String("com.trolltech.anymime.");
229  if(flav.size() > any_prefix.length() && flav.startsWith(any_prefix))
230  return flav.mid(any_prefix.length()).replace(QLatin1String("--"), QLatin1String("/"));
231  return QString();
232 }
233 
235 {
236  return mimeFor(flav) == mime;
237 }
238 
240 {
241  if(data.count() > 1)
242  qWarning("QMacPasteboardMimeAny: Cannot handle multiple member data");
243  QVariant ret;
244  if (mime == QLatin1String("text/plain"))
245  ret = QString::fromUtf8(data.first());
246  else
247  ret = data.first();
248  return ret;
249 }
250 
252 {
253  QList<QByteArray> ret;
254  if (mime == QLatin1String("text/plain"))
255  ret.append(data.toString().toUtf8());
256  else
257  ret.append(data.toByteArray());
258  return ret;
259 }
260 
262 private:
263 
264 public:
266  }
268  }
270 
271  QString flavorFor(const QString &mime);
272  QString mimeFor(QString flav);
273  bool canConvert(const QString &mime, QString flav);
275  QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav);
276 };
277 
279 {
280  return QLatin1String("Qt-Mime-Type");
281 }
282 
284 {
285  if(mime == QLatin1String("application/x-qt-mime-type-name"))
286  return QLatin1String("com.trolltech.qt.MimeTypeName");
287  return QString();
288 }
289 
291 {
292  return QString();
293 }
294 
296 {
297  return false;
298 }
299 
301 {
302  QVariant ret;
303  return ret;
304 }
305 
307 {
308  QList<QByteArray> ret;
309  ret.append(QString("x-qt-mime-type-name").toUtf8());
310  return ret;
311 }
312 
314 public:
317 
318  QString flavorFor(const QString &mime);
319  QString mimeFor(QString flav);
320  bool canConvert(const QString &mime, QString flav);
322  QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav);
323 };
324 
326 {
327  return QLatin1String("PlainText");
328 }
329 
331 {
332  if (mime == QLatin1String("text/plain"))
333  return QLatin1String("com.apple.traditional-mac-plain-text");
334  return QString();
335 }
336 
338 {
339  if (flav == QLatin1String("com.apple.traditional-mac-plain-text"))
340  return QLatin1String("text/plain");
341  return QString();
342 }
343 
345 {
346  return flavorFor(mime) == flav;
347 }
348 
350 {
351  if(data.count() > 1)
352  qWarning("QMacPasteboardMimePlainText: Cannot handle multiple member data");
353  const QByteArray &firstData = data.first();
354  QVariant ret;
355  if(flavor == QCFString(QLatin1String("com.apple.traditional-mac-plain-text"))) {
356  QCFString str(CFStringCreateWithBytes(kCFAllocatorDefault,
357  reinterpret_cast<const UInt8 *>(firstData.constData()),
358  firstData.size(), CFStringGetSystemEncoding(), false));
359  ret = QString(str);
360  } else {
361  qWarning("QMime::convertToMime: unhandled mimetype: %s", qPrintable(mimetype));
362  }
363  return ret;
364 }
365 
367 {
368  QList<QByteArray> ret;
369  QString string = data.toString();
370  if(flavor == QCFString(QLatin1String("com.apple.traditional-mac-plain-text")))
371  ret.append(string.toLatin1());
372  return ret;
373 }
374 
376 public:
379 
380  QString flavorFor(const QString &mime);
381  QString mimeFor(QString flav);
382  bool canConvert(const QString &mime, QString flav);
384  QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav);
385 };
386 
388 {
389  return QLatin1String("UnicodeText");
390 }
391 
393 {
394  if (mime == QLatin1String("text/plain"))
395  return QLatin1String("public.utf16-plain-text");
396  int i = mime.indexOf(QLatin1String("charset="));
397  if (i >= 0) {
398  QString cs(mime.mid(i+8).toLower());
399  i = cs.indexOf(QLatin1Char(';'));
400  if (i>=0)
401  cs = cs.left(i);
402  if (cs == QLatin1String("system"))
403  return QLatin1String("public.utf8-plain-text");
404  else if (cs == QLatin1String("iso-10646-ucs-2")
405  || cs == QLatin1String("utf16"))
406  return QLatin1String("public.utf16-plain-text");
407  }
408  return QString();
409 }
410 
412 {
413  if (flav == QLatin1String("public.utf16-plain-text") || flav == QLatin1String("public.utf8-plain-text"))
414  return QLatin1String("text/plain");
415  return QString();
416 }
417 
419 {
420  return flavorFor(mime) == flav;
421 }
422 
424 {
425  if(data.count() > 1)
426  qWarning("QMacPasteboardMimeUnicodeText: Cannot handle multiple member data");
427  const QByteArray &firstData = data.first();
428  // I can only handle two types (system and unicode) so deal with them that way
429  QVariant ret;
430  if(flavor == QLatin1String("public.utf8-plain-text")) {
431  QCFString str(CFStringCreateWithBytes(kCFAllocatorDefault,
432  reinterpret_cast<const UInt8 *>(firstData.constData()),
433  firstData.size(), CFStringGetSystemEncoding(), false));
434  ret = QString(str);
435  } else if (flavor == QLatin1String("public.utf16-plain-text")) {
436  ret = QString(reinterpret_cast<const QChar *>(firstData.constData()),
437  firstData.size() / sizeof(QChar));
438  } else {
439  qWarning("QMime::convertToMime: unhandled mimetype: %s", qPrintable(mimetype));
440  }
441  return ret;
442 }
443 
445 {
446  QList<QByteArray> ret;
447  QString string = data.toString();
448  if(flavor == QLatin1String("public.utf8-plain-text"))
449  ret.append(string.toUtf8());
450  else if (flavor == QLatin1String("public.utf16-plain-text"))
451  ret.append(QByteArray((char*)string.utf16(), string.length()*2));
452  return ret;
453 }
454 
456 public:
459 
460  QString flavorFor(const QString &mime);
461  QString mimeFor(QString flav);
462  bool canConvert(const QString &mime, QString flav);
464  QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav);
465 };
466 
468 {
469  return QLatin1String("HTML");
470 }
471 
473 {
474  if (mime == QLatin1String("text/html"))
475  return QLatin1String("public.html");
476  return QString();
477 }
478 
480 {
481  if (flav == QLatin1String("public.html"))
482  return QLatin1String("text/html");
483  return QString();
484 }
485 
487 {
488  return flavorFor(mime) == flav;
489 }
490 
492 {
493  if (!canConvert(mimeType, flavor))
494  return QVariant();
495  if (data.count() > 1)
496  qWarning("QMacPasteboardMimeHTMLText: Cannot handle multiple member data");
497  return data.first();
498 }
499 
501 {
502  QList<QByteArray> ret;
503  if (!canConvert(mime, flavor))
504  return ret;
505  ret.append(data.toByteArray());
506  return ret;
507 }
508 
509 
510 #ifdef Q_WS_MAC32
511 
512 // This can be removed once 10.6 is the minimum (or we have to require 64-bit) whichever comes first.
513 
514 typedef ComponentResult (*PtrGraphicsImportSetDataHandle)(GraphicsImportComponent, Handle);
515 typedef ComponentResult (*PtrGraphicsImportCreateCGImage)(GraphicsImportComponent, CGImageRef*, UInt32);
516 typedef ComponentResult (*PtrGraphicsExportSetInputCGImage)(GraphicsExportComponent, CGImageRef);
517 typedef ComponentResult (*PtrGraphicsExportSetOutputHandle)(GraphicsExportComponent, Handle);
518 typedef ComponentResult (*PtrGraphicsExportDoExport)(GraphicsExportComponent, unsigned long *);
519 
520 static PtrGraphicsImportSetDataHandle ptrGraphicsImportSetDataHandle = 0;
521 static PtrGraphicsImportCreateCGImage ptrGraphicsImportCreateCGImage = 0;
522 static PtrGraphicsExportSetInputCGImage ptrGraphicsExportSetInputCGImage = 0;
523 static PtrGraphicsExportSetOutputHandle ptrGraphicsExportSetOutputHandle = 0;
524 static PtrGraphicsExportDoExport ptrGraphicsExportDoExport = 0;
525 
526 static bool resolveMimeQuickTimeSymbols()
527 {
528  static bool triedResolve = false;
529  if (!triedResolve) {
530  QLibrary library(QLatin1String("/System/Library/Frameworks/QuickTime.framework/QuickTime"));
531  ptrGraphicsImportSetDataHandle = reinterpret_cast<PtrGraphicsImportSetDataHandle>(library.resolve("GraphicsImportSetDataHandle"));
532  ptrGraphicsImportCreateCGImage = reinterpret_cast<PtrGraphicsImportCreateCGImage>(library.resolve("GraphicsImportCreateCGImage"));
533  ptrGraphicsExportSetInputCGImage = reinterpret_cast<PtrGraphicsExportSetInputCGImage>(library.resolve("GraphicsExportSetInputCGImage"));
534  ptrGraphicsExportSetOutputHandle = reinterpret_cast<PtrGraphicsExportSetOutputHandle>(library.resolve("GraphicsExportSetOutputHandle"));
535  ptrGraphicsExportDoExport = reinterpret_cast<PtrGraphicsExportDoExport>(library.resolve("GraphicsExportDoExport"));
536  triedResolve = true;
537  }
538 
539  return ptrGraphicsImportSetDataHandle != 0
540  && ptrGraphicsImportCreateCGImage != 0 && ptrGraphicsExportSetInputCGImage != 0
541  && ptrGraphicsExportSetOutputHandle != 0 && ptrGraphicsExportDoExport != 0;
542 }
543 
544 class QMacPasteboardMimePict : public QMacPasteboardMime {
545 public:
546  QMacPasteboardMimePict() : QMacPasteboardMime(MIME_ALL) { }
548 
549  QString flavorFor(const QString &mime);
550  QString mimeFor(QString flav);
551  bool canConvert(const QString &mime, QString flav);
553  QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav);
554 };
555 
556 QString QMacPasteboardMimePict::convertorName()
557 {
558  return QLatin1String("Pict");
559 }
560 
561 QString QMacPasteboardMimePict::flavorFor(const QString &mime)
562 {
563  if(mime.startsWith(QLatin1String("application/x-qt-image")))
564  return QLatin1String("com.apple.pict");
565  return QString();
566 }
567 
568 QString QMacPasteboardMimePict::mimeFor(QString flav)
569 {
570  if(flav == QLatin1String("com.apple.pict"))
571  return QLatin1String("application/x-qt-image");
572  return QString();
573 }
574 
575 bool QMacPasteboardMimePict::canConvert(const QString &mime, QString flav)
576 {
577  return flav == QLatin1String("com.apple.pict")
578  && mime == QLatin1String("application/x-qt-image");
579 }
580 
581 
582 QVariant QMacPasteboardMimePict::convertToMime(const QString &mime, QList<QByteArray> data, QString flav)
583 {
584  if(data.count() > 1)
585  qWarning("QMacPasteboardMimePict: Cannot handle multiple member data");
586  QVariant ret;
587  if (!resolveMimeQuickTimeSymbols())
588  return ret;
589 
590  if(!canConvert(mime, flav))
591  return ret;
592  const QByteArray &a = data.first();
593 
594  // This function expects the 512 header (just to skip it, so create the extra space for it).
595  Handle pic = NewHandle(a.size() + 512);
596  memcpy(*pic + 512, a.constData(), a.size());
597 
598  GraphicsImportComponent graphicsImporter;
599  ComponentResult result = OpenADefaultComponent(GraphicsImporterComponentType,
600  kQTFileTypePicture, &graphicsImporter);
601  QCFType<CGImageRef> cgImage;
602  if (!result)
603  result = ptrGraphicsImportSetDataHandle(graphicsImporter, pic);
604  if (!result)
605  result = ptrGraphicsImportCreateCGImage(graphicsImporter, &cgImage,
606  kGraphicsImportCreateCGImageUsingCurrentSettings);
607  if (!result)
608  ret = QVariant(QPixmap::fromMacCGImageRef(cgImage).toImage());
609  CloseComponent(graphicsImporter);
610  DisposeHandle(pic);
611  return ret;
612 }
613 
614 QList<QByteArray> QMacPasteboardMimePict::convertFromMime(const QString &mime, QVariant variant,
615  QString flav)
616 {
617  QList<QByteArray> ret;
618  if (!resolveMimeQuickTimeSymbols())
619  return ret;
620 
621  if (!canConvert(mime, flav))
622  return ret;
623  QCFType<CGImageRef> cgimage = qt_mac_createCGImageFromQImage(qvariant_cast<QImage>(variant));
624  Handle pic = NewHandle(0);
625  GraphicsExportComponent graphicsExporter;
626  ComponentResult result = OpenADefaultComponent(GraphicsExporterComponentType,
627  kQTFileTypePicture, &graphicsExporter);
628  if (!result) {
629  unsigned long sizeWritten;
630  result = ptrGraphicsExportSetInputCGImage(graphicsExporter, cgimage);
631  if (!result)
632  result = ptrGraphicsExportSetOutputHandle(graphicsExporter, pic);
633  if (!result)
634  result = ptrGraphicsExportDoExport(graphicsExporter, &sizeWritten);
635 
636  CloseComponent(graphicsExporter);
637  }
638 
639  int size = GetHandleSize((Handle)pic);
640  // Skip the Picture File header (512 bytes) and feed the raw data
641  QByteArray ar(reinterpret_cast<char *>(*pic + 512), size - 512);
642  ret.append(ar);
643  DisposeHandle(pic);
644  return ret;
645 }
646 
647 
648 #endif //Q_WS_MAC32
649 
651 public:
654 
655  QString flavorFor(const QString &mime);
656  QString mimeFor(QString flav);
657  bool canConvert(const QString &mime, QString flav);
658  QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav);
659  QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav);
660 };
661 
663 {
664  return QLatin1String("Tiff");
665 }
666 
668 {
669  if(mime.startsWith(QLatin1String("application/x-qt-image")))
670  return QLatin1String("public.tiff");
671  return QString();
672 }
673 
675 {
676  if(flav == QLatin1String("public.tiff"))
677  return QLatin1String("application/x-qt-image");
678  return QString();
679 }
680 
682 {
683  return flav == QLatin1String("public.tiff") && mime == QLatin1String("application/x-qt-image");
684 }
685 
687 {
688  if(data.count() > 1)
689  qWarning("QMacPasteboardMimeTiff: Cannot handle multiple member data");
690  QVariant ret;
691  if (!canConvert(mime, flav))
692  return ret;
693  const QByteArray &a = data.first();
694  QCFType<CGImageRef> image;
695  QCFType<CFDataRef> tiffData = CFDataCreateWithBytesNoCopy(0,
696  reinterpret_cast<const UInt8 *>(a.constData()),
697  a.size(), kCFAllocatorNull);
698  QCFType<CGImageSourceRef> imageSource = CGImageSourceCreateWithData(tiffData, 0);
699  image = CGImageSourceCreateImageAtIndex(imageSource, 0, 0);
700 
701  if (image != 0)
702  ret = QVariant(QPixmap::fromMacCGImageRef(image).toImage());
703  return ret;
704 }
705 
707 {
708  QList<QByteArray> ret;
709  if (!canConvert(mime, flav))
710  return ret;
711 
714 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
716  QCFType<CFMutableDataRef> data = CFDataCreateMutable(0, 0);
717  QCFType<CGImageDestinationRef> imageDestination = CGImageDestinationCreateWithData(data, kUTTypeTIFF, 1, 0);
718  if (imageDestination != 0) {
719  CFTypeRef keys[2];
721  QCFType<CFDictionaryRef> options;
722  keys[0] = kCGImagePropertyPixelWidth;
723  keys[1] = kCGImagePropertyPixelHeight;
724  int width = img.width();
725  int height = img.height();
726  values[0] = CFNumberCreate(0, kCFNumberIntType, &width);
727  values[1] = CFNumberCreate(0, kCFNumberIntType, &height);
728  options = CFDictionaryCreate(0, reinterpret_cast<const void **>(keys),
729  reinterpret_cast<const void **>(values), 2,
730  &kCFTypeDictionaryKeyCallBacks,
731  &kCFTypeDictionaryValueCallBacks);
732  CGImageDestinationAddImage(imageDestination, cgimage, options);
733  CGImageDestinationFinalize(imageDestination);
734  }
735  QByteArray ar(CFDataGetLength(data), 0);
736  CFDataGetBytes(data,
737  CFRangeMake(0, ar.size()),
738  reinterpret_cast<UInt8 *>(ar.data()));
739  ret.append(ar);
740  } else
741 #endif
742  {
743 #ifdef Q_WS_MAC32
744  Handle tiff = NewHandle(0);
745  if (resolveMimeQuickTimeSymbols()) {
746  GraphicsExportComponent graphicsExporter;
747  ComponentResult result = OpenADefaultComponent(GraphicsExporterComponentType,
748  kQTFileTypeTIFF, &graphicsExporter);
749  if (!result) {
750  unsigned long sizeWritten;
751  result = ptrGraphicsExportSetInputCGImage(graphicsExporter, cgimage);
752  if (!result)
753  result = ptrGraphicsExportSetOutputHandle(graphicsExporter, tiff);
754  if (!result)
755  result = ptrGraphicsExportDoExport(graphicsExporter, &sizeWritten);
756 
757  CloseComponent(graphicsExporter);
758  }
759  }
760  int size = GetHandleSize((Handle)tiff);
761  QByteArray ar(reinterpret_cast<char *>(*tiff), size);
762  ret.append(ar);
763  DisposeHandle(tiff);
764 #endif
765  }
766  return ret;
767 }
768 
769 
771 public:
774 
775  QString flavorFor(const QString &mime);
776  QString mimeFor(QString flav);
777  bool canConvert(const QString &mime, QString flav);
778  QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav);
779  QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav);
780 };
781 
783 {
784  return QLatin1String("FileURL");
785 }
786 
788 {
789  if (mime == QLatin1String("text/uri-list"))
790  return QCFString(UTTypeCreatePreferredIdentifierForTag(kUTTagClassOSType, CFSTR("furl"), 0));
791  return QString();
792 }
793 
795 {
796  if (flav == QCFString(UTTypeCreatePreferredIdentifierForTag(kUTTagClassOSType, CFSTR("furl"), 0)))
797  return QLatin1String("text/uri-list");
798  return QString();
799 }
800 
802 {
803  return mime == QLatin1String("text/uri-list")
804  && flav == QCFString(UTTypeCreatePreferredIdentifierForTag(kUTTagClassOSType, CFSTR("furl"), 0));
805 }
806 
808 {
809  if(!canConvert(mime, flav))
810  return QVariant();
811  QList<QVariant> ret;
812  for(int i = 0; i < data.size(); ++i) {
813  QUrl url = QUrl::fromEncoded(data.at(i));
814  if (url.host().toLower() == QLatin1String("localhost"))
815  url.setHost(QString());
817  ret.append(url);
818  }
819  return QVariant(ret);
820 }
821 
823 {
824  QList<QByteArray> ret;
825  if (!canConvert(mime, flav))
826  return ret;
827  QList<QVariant> urls = data.toList();
828  for(int i = 0; i < urls.size(); ++i) {
829  QUrl url = urls.at(i).toUrl();
830  if (url.scheme().isEmpty())
831  url.setScheme(QLatin1String("file"));
832  if (url.scheme().toLower() == QLatin1String("file")) {
833  if (url.host().isEmpty())
834  url.setHost(QLatin1String("localhost"));
836  }
837  ret.append(url.toEncoded());
838  }
839  return ret;
840 }
841 
843 public:
846 
847  QString flavorFor(const QString &mime);
848  QString mimeFor(QString flav);
849  bool canConvert(const QString &mime, QString flav);
850  QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav);
851  QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav);
852 };
853 
855 {
856  return QLatin1String("URL");
857 }
858 
860 {
861  if(mime.startsWith(QLatin1String("text/uri-list")))
862  return QLatin1String("public.url");
863  return QString();
864 }
865 
867 {
868  if(flav == QLatin1String("public.url"))
869  return QLatin1String("text/uri-list");
870  return QString();
871 }
872 
874 {
875  return flav == QLatin1String("public.url")
876  && mime == QLatin1String("text/uri-list");
877 }
878 
880 {
881  if(!canConvert(mime, flav))
882  return QVariant();
883 
884  QList<QVariant> ret;
885  for (int i=0; i<data.size(); ++i) {
886  QUrl url = QUrl::fromEncoded(data.at(i));
887  if (url.host().toLower() == QLatin1String("localhost"))
888  url.setHost(QString());
890  ret.append(url);
891  }
892  return QVariant(ret);
893 }
894 
896 {
897  QList<QByteArray> ret;
898  if (!canConvert(mime, flav))
899  return ret;
900 
901  QList<QVariant> urls = data.toList();
902  for(int i=0; i<urls.size(); ++i) {
903  QUrl url = urls.at(i).toUrl();
904  if (url.scheme().isEmpty())
905  url.setScheme(QLatin1String("file"));
906  if (url.scheme().toLower() == QLatin1String("file")) {
907  if (url.host().isEmpty())
908  url.setHost(QLatin1String("localhost"));
910  }
911  ret.append(url.toEncoded());
912  }
913  return ret;
914 }
915 
917 {
918 public:
921 
922  QString flavorFor(const QString &mime);
923  QString mimeFor(QString flav);
924  bool canConvert(const QString &mime, QString flav);
925  QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav);
926  QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav);
927 };
928 
930 {
931  return QString("VCard");
932 }
933 
935 {
936  return mimeFor(flav) == mime;
937 }
938 
940 {
941  if(mime.startsWith(QLatin1String("text/plain")))
942  return QLatin1String("public.vcard");
943  return QString();
944 }
945 
947 {
948  if (flav == QLatin1String("public.vcard"))
949  return QLatin1String("text/plain");
950  return QString();
951 }
952 
954 {
955  QByteArray cards;
956  if (mime == QLatin1String("text/plain")) {
957  for (int i=0; i<data.size(); ++i)
958  cards += data[i];
959  }
960  return QVariant(cards);
961 }
962 
964 {
965  QList<QByteArray> ret;
966  if (mime == QLatin1String("text/plain"))
967  ret.append(data.toString().toUtf8());
968  return ret;
969 }
970 
971 #ifdef QT3_SUPPORT
972 class QMacPasteboardMimeQt3Any : public QMacPasteboardMime {
973 private:
974  int current_max;
975  QFile library_file;
976  QDateTime mime_registry_loaded;
977  QMap<QString, int> mime_registry;
978  int registerMimeType(const QString &mime);
979  bool loadMimeRegistry();
980 
981 public:
982  QMacPasteboardMimeQt3Any() : QMacPasteboardMime(MIME_QT3_CONVERTOR) {
983  current_max = 'QT00';
984  }
985  ~QMacPasteboardMimeQt3Any() {
986  }
988 
989  QString flavorFor(const QString &mime);
990  QString mimeFor(QString flav);
991  bool canConvert(const QString &mime, QString flav);
992  QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav);
993  QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav);
994 };
995 
996 static bool qt_mac_openMimeRegistry(bool global, QIODevice::OpenMode mode, QFile &file)
997 {
998  QString dir = QLatin1String("/Library/Qt");
999  if(!global)
1000  dir.prepend(QDir::homePath());
1001  file.setFileName(dir + QLatin1String("/.mime_types"));
1002  if(mode != QIODevice::ReadOnly) {
1003  if(!QFile::exists(dir)) {
1004  // Do it with a system call as I don't see much worth in
1005  // doing it with QDir since we have to chmod anyway.
1006  bool success = ::mkdir(dir.toLocal8Bit().constData(), S_IRUSR | S_IWUSR | S_IXUSR) == 0;
1007  if (success)
1008  success = ::chmod(dir.toLocal8Bit().constData(), S_IRUSR | S_IWUSR | S_IXUSR
1009  | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH) == 0;
1010  if (!success)
1011  return false;
1012  }
1013  if (!file.exists()) {
1014  // Create the file and chmod it so that everyone can write to it.
1015  int fd = ::open(file.fileName().toLocal8Bit().constData(), O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
1016  bool success = fd != -1;
1017  if (success)
1018  success = ::fchmod(fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) == 0;
1019  if (fd != -1)
1020  ::close(fd);
1021  if(!success)
1022  return false;
1023  }
1024  }
1025  return file.open(mode);
1026 }
1027 
1028 static void qt_mac_loadMimeRegistry(QFile &file, QMap<QString, int> &registry, int &max)
1029 {
1030  file.reset();
1031  QTextStream stream(&file);
1032  while(!stream.atEnd()) {
1033  QString mime = stream.readLine();
1034  int mactype = stream.readLine().toInt();
1035  if(mactype > max)
1036  max = mactype;
1037  registry.insert(mime, mactype);
1038  }
1039 }
1040 
1041 bool QMacPasteboardMimeQt3Any::loadMimeRegistry()
1042 {
1043  if(!library_file.isOpen()) {
1044  if(!qt_mac_openMimeRegistry(true, QIODevice::ReadWrite, library_file)) {
1045  QFile global;
1046  if(qt_mac_openMimeRegistry(true, QIODevice::ReadOnly, global)) {
1047  qt_mac_loadMimeRegistry(global, mime_registry, current_max);
1048  global.close();
1049  }
1050  if(!qt_mac_openMimeRegistry(false, QIODevice::ReadWrite, library_file)) {
1051  qWarning("QMacPasteboardMimeAnyQt3Mime: Failure to open mime resources %s -- %s", library_file.fileName().toLatin1().constData(),
1052  library_file.errorString().toLatin1().constData());
1053  return false;
1054  }
1055  }
1056  }
1057 
1058  QFileInfo fi(library_file);
1059  if(!mime_registry_loaded.isNull() && mime_registry_loaded == fi.lastModified())
1060  return true;
1061  mime_registry_loaded = fi.lastModified();
1062  qt_mac_loadMimeRegistry(library_file, mime_registry, current_max);
1063  return true;
1064 }
1065 
1066 int QMacPasteboardMimeQt3Any::registerMimeType(const QString &mime)
1067 {
1068  if(!mime_registry.contains(mime)) {
1069  if(!loadMimeRegistry()) {
1070  qWarning("QMacPasteboardMimeAnyQt3Mime: Internal error");
1071  return 0;
1072  }
1073  if(!mime_registry.contains(mime)) {
1074  if(!library_file.isOpen()) {
1075  if(!library_file.open(QIODevice::WriteOnly)) {
1076  qWarning("QMacPasteboardMimeAnyQt3Mime: Failure to open %s -- %s", library_file.fileName().toLatin1().constData(),
1077  library_file.errorString().toLatin1().constData());
1078  return false;
1079  }
1080  }
1081  int ret = ++current_max;
1082  mime_registry_loaded = QFileInfo(library_file).lastModified();
1083  QTextStream stream(&library_file);
1084  stream << mime << endl;
1085  stream << ret << endl;
1086  mime_registry.insert(mime, ret);
1087  library_file.flush(); //flush and set mtime
1088  return ret;
1089  }
1090  }
1091  return mime_registry[mime];
1092 }
1093 
1094 QString QMacPasteboardMimeQt3Any::convertorName()
1095 {
1096  return QLatin1String("Qt3-Any-Mime");
1097 }
1098 
1099 QString QMacPasteboardMimeQt3Any::flavorFor(const QString &mime)
1100 {
1101  const int os_flav = registerMimeType(mime);
1102  QCFType<CFArrayRef> ids = UTTypeCreateAllIdentifiersForTag(0, kUTTagClassOSType,
1103  QCFString(UTCreateStringForOSType(os_flav)));
1104  if(ids) {
1105  const int type_count = CFArrayGetCount(ids);
1106  if(type_count) {
1107  if(type_count > 1)
1108  qDebug("Can't happen!");
1109  return QCFString::toQString((CFStringRef)CFArrayGetValueAtIndex(ids, 0));
1110  }
1111  }
1112  return QString();
1113 }
1114 
1115 QString QMacPasteboardMimeQt3Any::mimeFor(QString flav)
1116 {
1117  loadMimeRegistry();
1118  const int os_flav = UTGetOSTypeFromString(UTTypeCopyPreferredTagWithClass(QCFString(flav), kUTTagClassOSType));
1119  for(QMap<QString, int>::const_iterator it = mime_registry.constBegin();
1120  it != mime_registry.constEnd(); ++it) {
1121  if(it.value() == os_flav)
1122  return QString::fromLatin1(it.key().toLatin1());
1123  }
1124  return QString();
1125 }
1126 
1127 bool QMacPasteboardMimeQt3Any::canConvert(const QString &mime, QString flav)
1128 {
1129  loadMimeRegistry();
1130  const int os_flav = UTGetOSTypeFromString(UTTypeCopyPreferredTagWithClass(QCFString(flav), kUTTagClassOSType));
1131  if(mime_registry.contains(mime) && mime_registry[mime] == os_flav)
1132  return true;
1133  return false;
1134 }
1135 
1136 QVariant QMacPasteboardMimeQt3Any::convertToMime(const QString &, QList<QByteArray>, QString)
1137 {
1138  qWarning("QMacPasteboardMimeAnyQt3Mime: Cannot write anything!");
1139  return QVariant();
1140 }
1141 
1142 QList<QByteArray> QMacPasteboardMimeQt3Any::convertFromMime(const QString &mime, QVariant data, QString)
1143 {
1144  QList<QByteArray> ret;
1145  if (mime == QLatin1String("text/plain")) {
1146  ret.append(data.toString().toUtf8());
1147  } else {
1148  ret.append(data.toByteArray());
1149  }
1150  return ret;
1151 }
1152 #endif
1153 
1163 {
1164  if(globalMimeList()->isEmpty()) {
1166 
1167  //standard types that we wrap
1169 #ifdef Q_WS_MAC32
1170  // 10.6 does automatic synthesis to and from PICT to standard image types (like TIFF),
1171  // so don't bother doing it ourselves, especially since it's not available in 64-bit.
1173  new QMacPasteboardMimePict;
1174 #endif
1182  //make sure our "non-standard" types are always last! --Sam
1184 #ifdef QT3_SUPPORT
1185  new QMacPasteboardMimeQt3Any;
1186 #endif
1187  }
1188 }
1189 
1197 {
1198  MimeList *mimes = globalMimeList();
1199  for(MimeList::const_iterator it = mimes->constBegin(); it != mimes->constEnd(); ++it) {
1200 #ifdef DEBUG_MIME_MAPS
1201  qDebug("QMacPasteboardMime::convertor: seeing if %s (%d) can convert %s to %d[%c%c%c%c] [%d]",
1202  (*it)->convertorName().toLatin1().constData(),
1203  (*it)->type & t, mime.toLatin1().constData(),
1204  flav, (flav >> 24) & 0xFF, (flav >> 16) & 0xFF, (flav >> 8) & 0xFF, (flav) & 0xFF,
1205  (*it)->canConvert(mime,flav));
1206  for(int i = 0; i < (*it)->countFlavors(); ++i) {
1207  int f = (*it)->flavor(i);
1208  qDebug(" %d) %d[%c%c%c%c] [%s]", i, f,
1209  (f >> 24) & 0xFF, (f >> 16) & 0xFF, (f >> 8) & 0xFF, (f) & 0xFF,
1210  (*it)->convertorName().toLatin1().constData());
1211  }
1212 #endif
1213  if(((*it)->type & t) && (*it)->canConvert(mime, flav))
1214  return (*it);
1215  }
1216  return 0;
1217 }
1222 {
1223  MimeList *mimes = globalMimeList();
1224  for(MimeList::const_iterator it = mimes->constBegin(); it != mimes->constEnd(); ++it) {
1225 #ifdef DEBUG_MIME_MAPS
1226  qDebug("QMacMIme::flavorToMime: attempting %s (%d) for flavor %d[%c%c%c%c] [%s]",
1227  (*it)->convertorName().toLatin1().constData(),
1228  (*it)->type & t, flav, (flav >> 24) & 0xFF, (flav >> 16) & 0xFF, (flav >> 8) & 0xFF, (flav) & 0xFF,
1229  (*it)->mimeFor(flav).toLatin1().constData());
1230 
1231 #endif
1232  if((*it)->type & t) {
1233  QString mimeType = (*it)->mimeFor(flav);
1234  if(!mimeType.isNull())
1235  return mimeType;
1236  }
1237  }
1238  return QString();
1239 }
1240 
1245 {
1246  MimeList ret;
1247  MimeList *mimes = globalMimeList();
1248  for(MimeList::const_iterator it = mimes->constBegin(); it != mimes->constEnd(); ++it) {
1249  if((*it)->type & t)
1250  ret.append((*it));
1251  }
1252  return ret;
1253 }
1254 
1255 
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
#define S_IWOTH
Definition: qzip.cpp:83
bool canConvert(const QString &mime, QString flav)
Returns true if the convertor can convert (both ways) between mime and flav; otherwise returns false...
Definition: qmime_mac.cpp:486
QString fileName() const
Returns the name set by setFileName() or to the QFile constructors.
Definition: qfile.cpp:470
const struct __CFString * CFStringRef
static void cleanup_mimes()
Definition: qmime_mac.cpp:84
int type
Definition: qmetatype.cpp:239
QString flavorFor(const QString &mime)
Returns the Mac UTI used for MIME type mime, or 0 if this convertor does not support mime...
Definition: qmime_mac.cpp:283
QString flavorFor(const QString &mime)
Returns the Mac UTI used for MIME type mime, or 0 if this convertor does not support mime...
Definition: qmime_mac.cpp:330
QString convertorName()
Returns a name for the convertor.
Definition: qmime_mac.cpp:662
#define S_IRGRP
Definition: qzip.cpp:79
CFStringRef qt_mac_mime_typeUTI
Definition: qmime_mac.cpp:126
QString convertorName()
Returns a name for the convertor.
Definition: qmime_mac.cpp:782
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define S_IXGRP
Definition: qzip.cpp:81
QVariant convertToMime(const QString &mime, QList< QByteArray > data, QString flav)
Returns data converted from Mac UTI flav to MIME type mime.
Definition: qmime_mac.cpp:423
QString readLine(qint64 maxlen=0)
Reads one line of text from the stream, and returns it as a QString.
QList< QByteArray > convertFromMime(const QString &mime, QVariant data, QString flav)
Returns data converted from MIME type mime to Mac UTI flav.
Definition: qmime_mac.cpp:500
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
QList< QByteArray > convertFromMime(const QString &mime, QVariant data, QString flav)
Returns data converted from MIME type mime to Mac UTI flav.
Definition: qmime_mac.cpp:963
static QList< QMacPasteboardMime * > all(uchar)
Returns a list of all currently defined QMacPasteboardMime objects of type t.
Definition: qmime_mac.cpp:1244
int toInt(bool *ok=0, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
Definition: qstring.cpp:6090
#define it(className, varName)
bool canConvert(const QString &mime, QString flav)
Returns true if the convertor can convert (both ways) between mime and flav; otherwise returns false...
Definition: qmime_mac.cpp:934
void qAddPostRoutine(QtCleanUpFunction p)
virtual QString mimeFor(QString flav)=0
Returns the MIME UTI used for Mac flavor flav, or 0 if this convertor does not support flav...
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition: qfile.cpp:1064
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QVariant convertToMime(const QString &mime, QList< QByteArray > data, QString flav)
Returns data converted from Mac UTI flav to MIME type mime.
Definition: qmime_mac.cpp:953
static void initialize()
This is an internal function.
Definition: qmime_mac.cpp:1162
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
#define S_IRUSR
Definition: qzip.cpp:71
QString & prepend(QChar c)
Definition: qstring.h:261
#define S_IXUSR
Definition: qzip.cpp:77
QList< QByteArray > convertFromMime(const QString &mime, QVariant data, QString flav)
Returns data converted from MIME type mime to Mac UTI flav.
Definition: qmime_mac.cpp:444
const QStringList & qEnabledDraggedTypes()
Definition: qmime_mac.cpp:114
QList< QByteArray > convertFromMime(const QString &mime, QVariant data, QString flav)
Returns data converted from MIME type mime to Mac UTI flav.
Definition: qmime_mac.cpp:366
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
static QString toQString(CFStringRef cfstr)
Definition: qcore_mac.cpp:47
const char * mime
CGImageRef qt_mac_createCGImageFromQImage(const QImage &img, const QImage **imagePtr=0)
The QList::const_iterator class provides an STL-style const iterator for QList and QQueue...
Definition: qlist.h:228
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QString mimeFor(QString flav)
Returns the MIME UTI used for Mac flavor flav, or 0 if this convertor does not support flav...
Definition: qmime_mac.cpp:946
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has type() List or StringList ; otherwise return...
Definition: qvariant.cpp:2751
void setPath(const QString &path)
Sets the path of the URL to path.
Definition: qurl.cpp:4960
struct CGImage * CGImageRef
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QString flavorFor(const QString &mime)
Returns the Mac UTI used for MIME type mime, or 0 if this convertor does not support mime...
Definition: qmime_mac.cpp:392
void * resolve(const char *symbol)
Returns the address of the exported symbol symbol.
Definition: qlibrary.cpp:1155
QVariant convertToMime(const QString &mime, QList< QByteArray > data, QString flav)
Returns data converted from Mac UTI flav to MIME type mime.
Definition: qmime_mac.cpp:300
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString host() const
Returns the host of the URL if it is defined; otherwise an empty string is returned.
Definition: qurl.cpp:4837
QString normalized(NormalizationForm mode) const Q_REQUIRED_RESULT
Returns the string in the given Unicode normalization mode.
Definition: qstring.cpp:6635
QVariant convertToMime(const QString &mime, QList< QByteArray > data, QString flav)
Returns data converted from Mac UTI flav to MIME type mime.
Definition: qmime_mac.cpp:349
void setHost(const QString &host)
Sets the host of the URL to host.
Definition: qurl.cpp:4821
#define O_CREAT
QString mimeFor(QString flav)
Returns the MIME UTI used for Mac flavor flav, or 0 if this convertor does not support flav...
Definition: qmime_mac.cpp:411
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QStringList keys
QString convertorName()
Returns a name for the convertor.
Definition: qmime_mac.cpp:929
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
Definition: qvariant.cpp:2383
QString mimeFor(QString flav)
Returns the MIME UTI used for Mac flavor flav, or 0 if this convertor does not support flav...
Definition: qmime_mac.cpp:290
bool canConvert(const QString &mime, QString flav)
Returns true if the convertor can convert (both ways) between mime and flav; otherwise returns false...
Definition: qmime_mac.cpp:873
static QPixmap fromMacCGImageRef(CGImageRef image)
Returns a QPixmap that is equivalent to the given image.
QString path() const
Returns the path of the URL.
Definition: qurl.cpp:4977
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QString convertorName()
Returns a name for the convertor.
Definition: qmime_mac.cpp:854
bool exists() const
Returns true if the file specified by fileName() exists; otherwise returns false. ...
Definition: qfile.cpp:626
Q_CORE_EXPORT void qDebug(const char *,...)
virtual QString flavorFor(const QString &mime)=0
Returns the Mac UTI used for MIME type mime, or 0 if this convertor does not support mime...
virtual QList< QByteArray > convertFromMime(const QString &mime, QVariant data, QString flav)=0
Returns data converted from MIME type mime to Mac UTI flav.
unsigned char uchar
Definition: qglobal.h:994
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static FILE * stream
static bool isEmpty(const char *str)
QString mimeFor(QString flav)
Returns the MIME UTI used for Mac flavor flav, or 0 if this convertor does not support flav...
Definition: qmime_mac.cpp:479
QList< QByteArray > convertFromMime(const QString &mime, QVariant data, QString flav)
Returns data converted from MIME type mime to Mac UTI flav.
Definition: qmime_mac.cpp:306
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
static QMacPasteboardMime * convertor(uchar, const QString &mime, QString flav)
Returns the most-recently created QMacPasteboardMime of type t that can convert between the mime and ...
Definition: qmime_mac.cpp:1196
virtual ~QMacPasteboardMime()
Destroys a conversion object, removing it from the global list of available convertors.
Definition: qmime_mac.cpp:189
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define S_IXOTH
Definition: qzip.cpp:84
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
ScrapFlavorType qt_mac_mime_type
Definition: qmime_mac.cpp:125
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
Q_CORE_EXPORT void qWarning(const char *,...)
QList< QMacPasteboardMime * > MimeList
Definition: qmime_mac.cpp:81
bool canConvert(const QString &mime, QString flav)
Returns true if the convertor can convert (both ways) between mime and flav; otherwise returns false...
Definition: qmime_mac.cpp:344
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
#define S_IROTH
Definition: qzip.cpp:82
static const char * data(const QByteArray &arr)
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
virtual QVariant convertToMime(const QString &mime, QList< QByteArray > data, QString flav)=0
Returns data converted from Mac UTI flav to MIME type mime.
QString convertorName()
Returns a name for the convertor.
Definition: qmime_mac.cpp:325
bool canConvert(const QString &mime, QString flav)
Returns true if the convertor can convert (both ways) between mime and flav; otherwise returns false...
Definition: qmime_mac.cpp:681
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
quint16 values[128]
QString convertorName()
Returns a name for the convertor.
Definition: qmime_mac.cpp:212
QUrl toUrl() const
Returns the variant as a QUrl if the variant has type() Url ; otherwise returns an invalid QUrl...
Definition: qvariant.cpp:2528
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
const void * CFTypeRef
QString mimeFor(QString flav)
Returns the MIME UTI used for Mac flavor flav, or 0 if this convertor does not support flav...
Definition: qmime_mac.cpp:337
QString mimeFor(QString flav)
Returns the MIME UTI used for Mac flavor flav, or 0 if this convertor does not support flav...
Definition: qmime_mac.cpp:226
QByteArray toEncoded(FormattingOptions options=None) const
Returns the encoded representation of the URL if it&#39;s valid; otherwise an empty QByteArray is returne...
Definition: qurl.cpp:5949
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
QString flavorFor(const QString &mime)
Returns the Mac UTI used for MIME type mime, or 0 if this convertor does not support mime...
Definition: qmime_mac.cpp:217
virtual bool canConvert(const QString &mime, QString flav)=0
Returns true if the convertor can convert (both ways) between mime and flav; otherwise returns false...
QString scheme() const
Returns the scheme of the URL.
Definition: qurl.cpp:4550
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QString flavorFor(const QString &mime)
Returns the Mac UTI used for MIME type mime, or 0 if this convertor does not support mime...
Definition: qmime_mac.cpp:787
QString convertorName()
Returns a name for the convertor.
Definition: qmime_mac.cpp:467
static bool closingDown()
Returns true if the application objects are being destroyed; otherwise returns false.
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
static const struct @32 types[]
bool canConvert(const QString &mime, QString flav)
Returns true if the convertor can convert (both ways) between mime and flav; otherwise returns false...
Definition: qmime_mac.cpp:295
static QString flavorToMime(uchar, QString flav)
Returns a MIME type of type t for flav, or 0 if none exists.
Definition: qmime_mac.cpp:1221
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
QVariant convertToMime(const QString &mime, QList< QByteArray > data, QString flav)
Returns data converted from Mac UTI flav to MIME type mime.
Definition: qmime_mac.cpp:807
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
QVariant convertToMime(const QString &mime, QList< QByteArray > data, QString flav)
Returns data converted from Mac UTI flav to MIME type mime.
Definition: qmime_mac.cpp:879
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
QString mimeFor(QString flav)
Returns the MIME UTI used for Mac flavor flav, or 0 if this convertor does not support flav...
Definition: qmime_mac.cpp:674
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool canConvert(const QString &mime, QString flav)
Returns true if the convertor can convert (both ways) between mime and flav; otherwise returns false...
Definition: qmime_mac.cpp:418
QVariant convertToMime(const QString &mime, QList< QByteArray > data, QString flav)
Returns data converted from Mac UTI flav to MIME type mime.
Definition: qmime_mac.cpp:491
QList< QByteArray > convertFromMime(const QString &mime, QVariant data, QString flav)
Returns data converted from MIME type mime to Mac UTI flav.
Definition: qmime_mac.cpp:822
virtual bool reset()
Seeks to the start of input for random-access devices.
Definition: qiodevice.cpp:732
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QString flavorFor(const QString &mime)
Returns the Mac UTI used for MIME type mime, or 0 if this convertor does not support mime...
Definition: qmime_mac.cpp:472
void setScheme(const QString &scheme)
Sets the scheme of the URL to scheme.
Definition: qurl.cpp:4533
void flush()
Flushes any buffered data waiting to be written to the device.
QVariant convertToMime(const QString &mime, QList< QByteArray > data, QString flav)
Returns data converted from Mac UTI flav to MIME type mime.
Definition: qmime_mac.cpp:686
QList< QByteArray > convertFromMime(const QString &mime, QVariant data, QString flav)
Returns data converted from MIME type mime to Mac UTI flav.
Definition: qmime_mac.cpp:895
static const MacVersion MacintoshVersion
the version of the Macintosh operating system on which the application is run (Mac only)...
Definition: qglobal.h:1646
QVariant convertToMime(const QString &mime, QList< QByteArray > data, QString flav)
Returns data converted from Mac UTI flav to MIME type mime.
Definition: qmime_mac.cpp:239
#define S_IWGRP
Definition: qzip.cpp:80
QString convertorName()
Returns a name for the convertor.
Definition: qmime_mac.cpp:387
QString flavorFor(const QString &mime)
Returns the Mac UTI used for MIME type mime, or 0 if this convertor does not support mime...
Definition: qmime_mac.cpp:667
const char * variant
bool atEnd() const
Returns true if there is no more data to be read from the QTextStream; otherwise returns false...
static QUrl fromEncoded(const QByteArray &url)
Parses input and returns the corresponding QUrl.
Definition: qurl.cpp:5964
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
QList< QByteArray > convertFromMime(const QString &mime, QVariant data, QString flav)
Returns data converted from MIME type mime to Mac UTI flav.
Definition: qmime_mac.cpp:251
void qRegisterDraggedTypes(const QStringList &types)
Registers the given types as custom pasteboard types.
virtual void close()
Calls QFile::flush() and closes the file.
Definition: qfile.cpp:1680
#define qPrintable(string)
Definition: qglobal.h:1750
The QMacPasteboardMime class converts between a MIME type and a.
Definition: qmime.h:141
QList< QByteArray > convertFromMime(const QString &mime, QVariant data, QString flav)
Returns data converted from MIME type mime to Mac UTI flav.
Definition: qmime_mac.cpp:706
QString mimeFor(QString flav)
Returns the MIME UTI used for Mac flavor flav, or 0 if this convertor does not support flav...
Definition: qmime_mac.cpp:866
QMacPasteboardMime(char)
Constructs a new conversion object of type t, adding it to the globally accessed list of available co...
Definition: qmime_mac.cpp:180
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
#define O_WRONLY
QString mimeFor(QString flav)
Returns the MIME UTI used for Mac flavor flav, or 0 if this convertor does not support flav...
Definition: qmime_mac.cpp:794
QString convertorName()
Returns a name for the convertor.
Definition: qmime_mac.cpp:278
QString flavorFor(const QString &mime)
Returns the Mac UTI used for MIME type mime, or 0 if this convertor does not support mime...
Definition: qmime_mac.cpp:859
void setFileName(const QString &name)
Sets the name of the file.
Definition: qfile.cpp:494
QString flavorFor(const QString &mime)
Returns the Mac UTI used for MIME type mime, or 0 if this convertor does not support mime...
Definition: qmime_mac.cpp:939
int open(const char *, int,...)
The QLibrary class loads shared libraries at runtime.
Definition: qlibrary.h:62
virtual QString convertorName()=0
Returns a name for the convertor.
#define S_IWUSR
Definition: qzip.cpp:74
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272
static QString homePath()
Returns the absolute path of the user&#39;s home directory.
Definition: qdir.cpp:1942
bool canConvert(const QString &mime, QString flav)
Returns true if the convertor can convert (both ways) between mime and flav; otherwise returns false...
Definition: qmime_mac.cpp:234
bool canConvert(const QString &mime, QString flav)
Returns true if the convertor can convert (both ways) between mime and flav; otherwise returns false...
Definition: qmime_mac.cpp:801
Q_CORE_EXPORT QTextStream & endl(QTextStream &s)
QDateTime lastModified() const
Returns the date and time when the file was last modified.
Definition: qfileinfo.cpp:1296