Qt 4.8
Classes | Public Functions | Private Functions | Static Private Functions | Properties | List of all members
QMacPasteboard Class Reference

#include <qt_mac_p.h>

Classes

struct  Promise
 

Public Functions

void clear ()
 
QStringList formats () const
 
bool hasFlavor (QString flavor) const
 
bool hasFormat (const QString &format) const
 
bool hasOSType (int c_flavor) const
 
QMimeDatamimeData () const
 
OSPasteboardRef pasteBoard () const
 
 QMacPasteboard (OSPasteboardRef p, uchar mime_type=0)
 
 QMacPasteboard (uchar mime_type)
 
 QMacPasteboard (CFStringRef name=0, uchar mime_type=0)
 
QVariant retrieveData (const QString &format, QVariant::Type) const
 
void setMimeData (QMimeData *mime)
 
bool sync () const
 
 ~QMacPasteboard ()
 

Private Functions

void clear_helper ()
 

Static Private Functions

static OSStatus promiseKeeper (OSPasteboardRef, PasteboardItemID, CFStringRef, void *)
 

Properties

bool mac_mime_source
 
QPointer< QMimeDatamime
 
uchar mime_type
 
OSPasteboardRef paste
 
QList< Promisepromises
 

Detailed Description

Definition at line 211 of file qt_mac_p.h.

Constructors and Destructors

◆ QMacPasteboard() [1/3]

QMacPasteboard::QMacPasteboard ( OSPasteboardRef  p,
uchar  mime_type = 0 
)

Definition at line 168 of file qclipboard_mac.cpp.

169 {
170  mac_mime_source = false;
172  paste = p;
173  CFRetain(paste);
174 }
OSPasteboardRef paste
Definition: qt_mac_p.h:223
uchar mime_type
Definition: qt_mac_p.h:224
unsigned char uchar
Definition: qglobal.h:994
bool mac_mime_source
Definition: qt_mac_p.h:226

◆ QMacPasteboard() [2/3]

QMacPasteboard::QMacPasteboard ( uchar  mime_type)

Definition at line 176 of file qclipboard_mac.cpp.

177 {
178  mac_mime_source = false;
180  paste = 0;
181  OSStatus err = PasteboardCreate(0, &paste);
182  if(err == noErr) {
183  PasteboardSetPromiseKeeper(paste, promiseKeeper, this);
184  } else {
185  qDebug("PasteBoard: Error creating pasteboard: [%d]", (int)err);
186  }
187 }
OSPasteboardRef paste
Definition: qt_mac_p.h:223
uchar mime_type
Definition: qt_mac_p.h:224
Q_CORE_EXPORT void qDebug(const char *,...)
unsigned char uchar
Definition: qglobal.h:994
bool mac_mime_source
Definition: qt_mac_p.h:226
signed long OSStatus
static OSStatus promiseKeeper(OSPasteboardRef, PasteboardItemID, CFStringRef, void *)

◆ QMacPasteboard() [3/3]

QMacPasteboard::QMacPasteboard ( CFStringRef  name = 0,
uchar  mime_type = 0 
)

Definition at line 189 of file qclipboard_mac.cpp.

190 {
191  mac_mime_source = false;
193  paste = 0;
194  OSStatus err = PasteboardCreate(name, &paste);
195  if(err == noErr) {
196  PasteboardSetPromiseKeeper(paste, promiseKeeper, this);
197  } else {
198  qDebug("PasteBoard: Error creating pasteboard: %s [%d]", QCFString::toQString(name).toLatin1().constData(), (int)err);
199  }
200 }
static QString toQString(CFStringRef cfstr)
Definition: qcore_mac.cpp:47
OSPasteboardRef paste
Definition: qt_mac_p.h:223
uchar mime_type
Definition: qt_mac_p.h:224
Q_CORE_EXPORT void qDebug(const char *,...)
unsigned char uchar
Definition: qglobal.h:994
const char * name
bool mac_mime_source
Definition: qt_mac_p.h:226
signed long OSStatus
static OSStatus promiseKeeper(OSPasteboardRef, PasteboardItemID, CFStringRef, void *)

◆ ~QMacPasteboard()

QMacPasteboard::~QMacPasteboard ( )

Definition at line 202 of file qclipboard_mac.cpp.

203 {
204  // commit all promises for paste after exit close
205  for (int i = 0; i < promises.count(); ++i) {
206  const Promise &promise = promises.at(i);
207  QCFString flavor = QCFString(promise.convertor->flavorFor(promise.mime));
208  promiseKeeper(paste, (PasteboardItemID)promise.itemId, flavor, this);
209  }
210 
211  if(paste)
212  CFRelease(paste);
213 }
OSPasteboardRef paste
Definition: qt_mac_p.h:223
QList< Promise > promises
Definition: qt_mac_p.h:221
static OSStatus promiseKeeper(OSPasteboardRef, PasteboardItemID, CFStringRef, void *)

Functions

◆ clear()

void QMacPasteboard::clear ( )

Definition at line 606 of file qclipboard_mac.cpp.

Referenced by QClipboard::clear().

607 {
608 #ifdef DEBUG_PASTEBOARD
609  qDebug("PasteBoard: clear!");
610 #endif
611  clear_helper();
612 }
Q_CORE_EXPORT void qDebug(const char *,...)

◆ clear_helper()

void QMacPasteboard::clear_helper ( )
private

Definition at line 598 of file qclipboard_mac.cpp.

599 {
600  if (paste)
601  PasteboardClear(paste);
602  promises.clear();
603 }
OSPasteboardRef paste
Definition: qt_mac_p.h:223
QList< Promise > promises
Definition: qt_mac_p.h:221

◆ formats()

QStringList QMacPasteboard::formats ( ) const

Definition at line 434 of file qclipboard_mac.cpp.

Referenced by QMacPasteboardMimeSource::formats(), QDropData::formats_sys(), and QCocoaDropData::formats_sys().

435 {
436  if (!paste)
437  return QStringList();
438 
439  sync();
440 
441  QStringList ret;
442  ItemCount cnt = 0;
443  if(PasteboardGetItemCount(paste, &cnt) || !cnt)
444  return ret;
445 
446 #ifdef DEBUG_PASTEBOARD
447  qDebug("PasteBoard: Formats [%d]", (int)cnt);
448 #endif
449  for(uint index = 1; index <= cnt; ++index) {
450 
451  PasteboardItemID id;
452  if(PasteboardGetItemIdentifier(paste, index, &id) != noErr)
453  continue;
454 
456  if(PasteboardCopyItemFlavors(paste, id, &types ) != noErr)
457  continue;
458 
459  const int type_count = CFArrayGetCount(types);
460  for(int i = 0; i < type_count; ++i) {
461  const QString flavor = QCFString::toQString((CFStringRef)CFArrayGetValueAtIndex(types, i));
462 #ifdef DEBUG_PASTEBOARD
463  qDebug(" -%s", qPrintable(QString(flavor)));
464 #endif
466  if(!mimeType.isEmpty() && !ret.contains(mimeType)) {
467 #ifdef DEBUG_PASTEBOARD
468  qDebug(" -<%d> %s [%s]", ret.size(), qPrintable(mimeType), qPrintable(QString(flavor)));
469 #endif
470  ret << mimeType;
471  }
472  }
473  }
474  return ret;
475 }
const struct __CFString * CFStringRef
static QString toQString(CFStringRef cfstr)
Definition: qcore_mac.cpp:47
The QString class provides a Unicode character string.
Definition: qstring.h:83
OSPasteboardRef paste
Definition: qt_mac_p.h:223
uchar mime_type
Definition: qt_mac_p.h:224
Q_CORE_EXPORT void qDebug(const char *,...)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
unsigned int uint
Definition: qglobal.h:996
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
static const struct @32 types[]
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
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
quint16 index
bool sync() const
#define qPrintable(string)
Definition: qglobal.h:1750

◆ hasFlavor()

bool QMacPasteboard::hasFlavor ( QString  flavor) const

Definition at line 312 of file qclipboard_mac.cpp.

313 {
314  if (!paste)
315  return false;
316 
317  sync();
318 
319  ItemCount cnt = 0;
320  if(PasteboardGetItemCount(paste, &cnt) || !cnt)
321  return false;
322 
323 #ifdef DEBUG_PASTEBOARD
324  qDebug("PasteBoard: hasFlavor [%s]", qPrintable(c_flavor));
325 #endif
326  for(uint index = 1; index <= cnt; ++index) {
327 
328  PasteboardItemID id;
329  if(PasteboardGetItemIdentifier(paste, index, &id) != noErr)
330  return false;
331 
332  PasteboardFlavorFlags flags;
333  if(PasteboardGetItemFlavorFlags(paste, id, QCFString(c_flavor), &flags) == noErr) {
334 #ifdef DEBUG_PASTEBOARD
335  qDebug(" - Found!");
336 #endif
337  return true;
338  }
339  }
340 #ifdef DEBUG_PASTEBOARD
341  qDebug(" - NotFound!");
342 #endif
343  return false;
344 }
OSPasteboardRef paste
Definition: qt_mac_p.h:223
Q_CORE_EXPORT void qDebug(const char *,...)
unsigned int uint
Definition: qglobal.h:996
quint16 index
bool sync() const
#define qPrintable(string)
Definition: qglobal.h:1750

◆ hasFormat()

bool QMacPasteboard::hasFormat ( const QString format) const

Definition at line 478 of file qclipboard_mac.cpp.

Referenced by QDropData::hasFormat_sys(), and QCocoaDropData::hasFormat_sys().

479 {
480  if (!paste)
481  return false;
482 
483  sync();
484 
485  ItemCount cnt = 0;
486  if(PasteboardGetItemCount(paste, &cnt) || !cnt)
487  return false;
488 
489 #ifdef DEBUG_PASTEBOARD
490  qDebug("PasteBoard: hasFormat [%s]", qPrintable(format));
491 #endif
492  for(uint index = 1; index <= cnt; ++index) {
493 
494  PasteboardItemID id;
495  if(PasteboardGetItemIdentifier(paste, index, &id) != noErr)
496  continue;
497 
499  if(PasteboardCopyItemFlavors(paste, id, &types ) != noErr)
500  continue;
501 
502  const int type_count = CFArrayGetCount(types);
503  for(int i = 0; i < type_count; ++i) {
504  const QString flavor = QCFString::toQString((CFStringRef)CFArrayGetValueAtIndex(types, i));
505 #ifdef DEBUG_PASTEBOARD
506  qDebug(" -%s [0x%x]", qPrintable(QString(flavor)), mime_type);
507 #endif
509 #ifdef DEBUG_PASTEBOARD
510  if(!mimeType.isEmpty())
511  qDebug(" - %s", qPrintable(mimeType));
512 #endif
513  if(mimeType == format)
514  return true;
515  }
516  }
517  return false;
518 }
const struct __CFString * CFStringRef
static QString toQString(CFStringRef cfstr)
Definition: qcore_mac.cpp:47
The QString class provides a Unicode character string.
Definition: qstring.h:83
OSPasteboardRef paste
Definition: qt_mac_p.h:223
uchar mime_type
Definition: qt_mac_p.h:224
Q_CORE_EXPORT void qDebug(const char *,...)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
unsigned int uint
Definition: qglobal.h:996
static const struct @32 types[]
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
quint16 index
bool sync() const
#define qPrintable(string)
Definition: qglobal.h:1750

◆ hasOSType()

bool QMacPasteboard::hasOSType ( int  c_flavor) const

Definition at line 268 of file qclipboard_mac.cpp.

269 {
270  if (!paste)
271  return false;
272 
273  sync();
274 
275  ItemCount cnt = 0;
276  if(PasteboardGetItemCount(paste, &cnt) || !cnt)
277  return false;
278 
279 #ifdef DEBUG_PASTEBOARD
280  qDebug("PasteBoard: hasOSType [%c%c%c%c]", (c_flavor>>24)&0xFF, (c_flavor>>16)&0xFF,
281  (c_flavor>>8)&0xFF, (c_flavor>>0)&0xFF);
282 #endif
283  for(uint index = 1; index <= cnt; ++index) {
284 
285  PasteboardItemID id;
286  if(PasteboardGetItemIdentifier(paste, index, &id) != noErr)
287  return false;
288 
290  if(PasteboardCopyItemFlavors(paste, id, &types ) != noErr)
291  return false;
292 
293  const int type_count = CFArrayGetCount(types);
294  for(int i = 0; i < type_count; ++i) {
295  CFStringRef flavor = (CFStringRef)CFArrayGetValueAtIndex(types, i);
296  const int os_flavor = UTGetOSTypeFromString(UTTypeCopyPreferredTagWithClass(flavor, kUTTagClassOSType));
297  if(os_flavor == c_flavor) {
298 #ifdef DEBUG_PASTEBOARD
299  qDebug(" - Found!");
300 #endif
301  return true;
302  }
303  }
304  }
305 #ifdef DEBUG_PASTEBOARD
306  qDebug(" - NotFound!");
307 #endif
308  return false;
309 }
const struct __CFString * CFStringRef
OSPasteboardRef paste
Definition: qt_mac_p.h:223
Q_CORE_EXPORT void qDebug(const char *,...)
unsigned int uint
Definition: qglobal.h:996
static const struct @32 types[]
quint16 index
bool sync() const

◆ mimeData()

QMimeData * QMacPasteboard::mimeData ( ) const

Definition at line 356 of file qclipboard_mac.cpp.

Referenced by QClipboard::mimeData().

357 {
358  if(!mime) {
359  mac_mime_source = true;
360  mime = new QMacPasteboardMimeSource(this);
361 
362  }
363  return mime;
364 }
QPointer< QMimeData > mime
Definition: qt_mac_p.h:225
bool mac_mime_source
Definition: qt_mac_p.h:226

◆ pasteBoard()

PasteboardRef QMacPasteboard::pasteBoard ( ) const

Definition at line 216 of file qclipboard_mac.cpp.

Referenced by QDragManager::drag().

217 {
218  return paste;
219 }
OSPasteboardRef paste
Definition: qt_mac_p.h:223

◆ promiseKeeper()

OSStatus QMacPasteboard::promiseKeeper ( OSPasteboardRef  paste,
PasteboardItemID  id,
CFStringRef  flavor,
void *  _qpaste 
)
staticprivate

Definition at line 221 of file qclipboard_mac.cpp.

222 {
223  QMacPasteboard *qpaste = (QMacPasteboard*)_qpaste;
224  const long promise_id = (long)id;
225 
226  // Find the kept promise
227  const QString flavorAsQString = QCFString::toQString(flavor);
228  QMacPasteboard::Promise promise;
229  for (int i = 0; i < qpaste->promises.size(); i++){
230  QMacPasteboard::Promise tmp = qpaste->promises[i];
231  if (tmp.itemId == promise_id && tmp.convertor->canConvert(tmp.mime, flavorAsQString)){
232  promise = tmp;
233  break;
234  }
235  }
236 
237  if (!promise.itemId && flavorAsQString == QLatin1String("com.trolltech.qt.MimeTypeName")) {
238  // we have promised this data, but wont be able to convert, so return null data.
239  // This helps in making the application/x-qt-mime-type-name hidden from normal use.
240  QByteArray ba;
241  QCFType<CFDataRef> data = CFDataCreate(0, (UInt8*)ba.constData(), ba.size());
242  PasteboardPutItemFlavor(paste, id, flavor, data, kPasteboardFlavorNoFlags);
243  return noErr;
244  }
245 
246  if (!promise.itemId) {
247  // There was no promise that could deliver data for the
248  // given id and flavor. This should not happend.
249  qDebug("Pasteboard: %d: Request for %ld, %s, but no promise found!", __LINE__, promise_id, qPrintable(flavorAsQString));
250  return cantGetFlavorErr;
251  }
252 
253 #ifdef DEBUG_PASTEBOARD
254  qDebug("PasteBoard: Calling in promise for %s[%ld] [%s] (%s) [%d]", qPrintable(promise.mime), promise_id,
255  qPrintable(flavorAsQString), qPrintable(promise.convertor->convertorName()), promise.offset);
256 #endif
257 
258  QList<QByteArray> md = promise.convertor->convertFromMime(promise.mime, promise.data, flavorAsQString);
259  if (md.size() <= promise.offset)
260  return cantGetFlavorErr;
261  const QByteArray &ba = md[promise.offset];
262  QCFType<CFDataRef> data = CFDataCreate(0, (UInt8*)ba.constData(), ba.size());
263  PasteboardPutItemFlavor(paste, id, flavor, data, kPasteboardFlavorNoFlags);
264  return noErr;
265 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static QString toQString(CFStringRef cfstr)
Definition: qcore_mac.cpp:47
The QString class provides a Unicode character string.
Definition: qstring.h:83
OSPasteboardRef paste
Definition: qt_mac_p.h:223
Q_CORE_EXPORT void qDebug(const char *,...)
virtual QList< QByteArray > convertFromMime(const QString &mime, QVariant data, QString flav)=0
Returns data converted from MIME type mime to Mac UTI flav.
QList< Promise > promises
Definition: qt_mac_p.h:221
static const char * data(const QByteArray &arr)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
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...
QMacPasteboardMime * convertor
Definition: qt_mac_p.h:217
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
#define qPrintable(string)
Definition: qglobal.h:1750
virtual QString convertorName()=0
Returns a name for the convertor.

◆ retrieveData()

QVariant QMacPasteboard::retrieveData ( const QString format,
QVariant::Type   
) const

Definition at line 521 of file qclipboard_mac.cpp.

Referenced by QMacPasteboardMimeSource::retrieveData(), QDropData::retrieveData_sys(), and QCocoaDropData::retrieveData_sys().

522 {
523  if (!paste)
524  return QVariant();
525 
526  sync();
527 
528  ItemCount cnt = 0;
529  if(PasteboardGetItemCount(paste, &cnt) || !cnt)
530  return QByteArray();
531 
532 #ifdef DEBUG_PASTEBOARD
533  qDebug("Pasteboard: retrieveData [%s]", qPrintable(format));
534 #endif
536  for(int mime = 0; mime < mimes.size(); ++mime) {
537  QMacPasteboardMime *c = mimes.at(mime);
538  QString c_flavor = c->flavorFor(format);
539  if(!c_flavor.isEmpty()) {
540  // Handle text/plain a little differently. Try handling Unicode first.
541  bool checkForUtf16 = (c_flavor == QLatin1String("com.apple.traditional-mac-plain-text")
542  || c_flavor == QLatin1String("public.utf8-plain-text"));
543  if (checkForUtf16 || c_flavor == QLatin1String("public.utf16-plain-text")) {
544  // Try to get the NSStringPboardType from NSPasteboard, newlines are mapped
545  // correctly (as '\n') in this data. The 'public.utf16-plain-text' type
546  // usually maps newlines to '\r' instead.
548  if (!str.isEmpty())
549  return str;
550  }
551  if (checkForUtf16 && hasFlavor(QLatin1String("public.utf16-plain-text")))
552  c_flavor = QLatin1String("public.utf16-plain-text");
553 
554  QVariant ret;
555  QList<QByteArray> retList;
556  for(uint index = 1; index <= cnt; ++index) {
557  PasteboardItemID id;
558  if(PasteboardGetItemIdentifier(paste, index, &id) != noErr)
559  continue;
560 
562  if(PasteboardCopyItemFlavors(paste, id, &types ) != noErr)
563  continue;
564 
565  const int type_count = CFArrayGetCount(types);
566  for(int i = 0; i < type_count; ++i) {
567  CFStringRef flavor = static_cast<CFStringRef>(CFArrayGetValueAtIndex(types, i));
568  if(c_flavor == QCFString::toQString(flavor)) {
569  QCFType<CFDataRef> macBuffer;
570  if(PasteboardCopyItemFlavorData(paste, id, flavor, &macBuffer) == noErr) {
571  QByteArray buffer((const char *)CFDataGetBytePtr(macBuffer), CFDataGetLength(macBuffer));
572  if(!buffer.isEmpty()) {
573 #ifdef DEBUG_PASTEBOARD
574  qDebug(" - %s [%s] (%s)", qPrintable(format), qPrintable(QCFString::toQString(flavor)), qPrintable(c->convertorName()));
575 #endif
576  buffer.detach(); //detach since we release the macBuffer
577  retList.append(buffer);
578  break; //skip to next element
579  }
580  }
581  } else {
582 #ifdef DEBUG_PASTEBOARD
583  qDebug(" - NoMatch %s [%s] (%s)", qPrintable(c_flavor), qPrintable(QCFString::toQString(flavor)), qPrintable(c->convertorName()));
584 #endif
585  }
586  }
587  }
588 
589  if (!retList.isEmpty()) {
590  ret = c->convertToMime(format, retList, c_flavor);
591  return ret;
592  }
593  }
594  }
595  return QVariant();
596 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
const struct __CFString * CFStringRef
unsigned char c[8]
Definition: qnumeric_p.h:62
static QList< QMacPasteboardMime * > all(uchar)
Returns a list of all currently defined QMacPasteboardMime objects of type t.
Definition: qmime_mac.cpp:1244
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static QString toQString(CFStringRef cfstr)
Definition: qcore_mac.cpp:47
QString qt_mac_get_pasteboardString(OSPasteboardRef paste)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
OSPasteboardRef paste
Definition: qt_mac_p.h:223
uchar mime_type
Definition: qt_mac_p.h:224
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...
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QPointer< QMimeData > mime
Definition: qt_mac_p.h:225
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
unsigned int uint
Definition: qglobal.h:996
virtual QVariant convertToMime(const QString &mime, QList< QByteArray > data, QString flav)=0
Returns data converted from Mac UTI flav to MIME type mime.
static const struct @32 types[]
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool hasFlavor(QString flavor) const
quint16 index
bool sync() const
#define qPrintable(string)
Definition: qglobal.h:1750
The QMacPasteboardMime class converts between a MIME type and a.
Definition: qmime.h:141
virtual QString convertorName()=0
Returns a name for the convertor.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ setMimeData()

void QMacPasteboard::setMimeData ( QMimeData mime)

Definition at line 375 of file qclipboard_mac.cpp.

Referenced by QDragManager::drag(), and QClipboard::setMimeData().

376 {
377  if (!paste)
378  return;
379 
380  if (mime == mime_src || (!mime_src && mime && mac_mime_source))
381  return;
382  mac_mime_source = false;
383  delete mime;
384  mime = mime_src;
385 
387  if (mime != 0) {
388  clear_helper();
389  QStringList formats = mime_src->formats();
390 
391 #ifdef QT_MAC_USE_COCOA
392  // QMimeData sub classes reimplementing the formats() might not expose the
393  // temporary "application/x-qt-mime-type-name" mimetype. So check the existence
394  // of this mime type while doing drag and drop.
395  QString dummyMimeType(QLatin1String("application/x-qt-mime-type-name"));
396  if (!formats.contains(dummyMimeType)) {
397  QByteArray dummyType = mime_src->data(dummyMimeType);
398  if (!dummyType.isEmpty()) {
399  formats.append(dummyMimeType);
400  }
401  }
402 #endif
403  for(int f = 0; f < formats.size(); ++f) {
404  QString mimeType = formats.at(f);
405  for (QList<QMacPasteboardMime *>::Iterator it = availableConverters.begin(); it != availableConverters.end(); ++it) {
406  QMacPasteboardMime *c = (*it);
407  QString flavor(c->flavorFor(mimeType));
408  if(!flavor.isEmpty()) {
409  QVariant mimeData = static_cast<QMacMimeData*>(mime_src)->variantData(mimeType);
410 #if 0
411  //### Grrr, why didn't I put in a virtual int QMacPasteboardMime::count()? --Sam
412  const int numItems = c->convertFromMime(mimeType, mimeData, flavor).size();
413 #else
414  int numItems = 1; //this is a hack but it is much faster than allowing conversion above
415  if(c->convertorName() == QLatin1String("FileURL"))
416  numItems = mime_src->urls().count();
417 #endif
418  for(int item = 0; item < numItems; ++item) {
419  const int itemID = item+1; //id starts at 1
420  promises.append(QMacPasteboard::Promise(itemID, c, mimeType, mimeData, item));
421  PasteboardPutItemFlavor(paste, (PasteboardItemID)itemID, QCFString(flavor), 0, kPasteboardFlavorNoFlags);
422 #ifdef DEBUG_PASTEBOARD
423  qDebug(" - adding %d %s [%s] <%s> [%d]",
424  itemID, qPrintable(mimeType), qPrintable(flavor), qPrintable(c->convertorName()), item);
425 #endif
426  }
427  }
428  }
429  }
430  }
431 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
unsigned char c[8]
Definition: qnumeric_p.h:62
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
static QList< QMacPasteboardMime * > all(uchar)
Returns a list of all currently defined QMacPasteboardMime objects of type t.
Definition: qmime_mac.cpp:1244
#define it(className, varName)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
OSPasteboardRef paste
Definition: qt_mac_p.h:223
uchar mime_type
Definition: qt_mac_p.h:224
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.
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QList< Promise > promises
Definition: qt_mac_p.h:221
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
QPointer< QMimeData > mime
Definition: qt_mac_p.h:225
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
bool mac_mime_source
Definition: qt_mac_p.h:226
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
The QList::iterator class provides an STL-style non-const iterator for QList and QQueue.
Definition: qlist.h:181
QStringList formats() const
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
QMimeData * mimeData() const
#define qPrintable(string)
Definition: qglobal.h:1750
The QMacPasteboardMime class converts between a MIME type and a.
Definition: qmime.h:141
virtual QString convertorName()=0
Returns a name for the convertor.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ sync()

bool QMacPasteboard::sync ( ) const

Definition at line 615 of file qclipboard_mac.cpp.

Referenced by qt_mac_updateScrap().

616 {
617  if (!paste)
618  return false;
619  const bool fromGlobal = PasteboardSynchronize(paste) & kPasteboardModified;
620 
621  if (fromGlobal)
622  const_cast<QMacPasteboard *>(this)->setMimeData(0);
623 
624 #ifdef DEBUG_PASTEBOARD
625  if(fromGlobal)
626  qDebug("Pasteboard: Synchronize!");
627 #endif
628  return fromGlobal;
629 }
OSPasteboardRef paste
Definition: qt_mac_p.h:223
Q_CORE_EXPORT void qDebug(const char *,...)
void setMimeData(QMimeData *mime)

Properties

◆ mac_mime_source

bool QMacPasteboard::mac_mime_source
mutableprivate

Definition at line 226 of file qt_mac_p.h.

◆ mime

QPointer<QMimeData> QMacPasteboard::mime
mutableprivate

Definition at line 225 of file qt_mac_p.h.

◆ mime_type

uchar QMacPasteboard::mime_type
private

Definition at line 224 of file qt_mac_p.h.

◆ paste

OSPasteboardRef QMacPasteboard::paste
private

Definition at line 223 of file qt_mac_p.h.

◆ promises

QList<Promise> QMacPasteboard::promises
private

Definition at line 221 of file qt_mac_p.h.

Referenced by promiseKeeper().


The documentation for this class was generated from the following files: