Qt 4.8
Public Functions | Properties | List of all members
QWindowsMimeURI Class Reference
Inheritance diagram for QWindowsMimeURI:
QWindowsMime

Public Functions

bool canConvertFromMime (const FORMATETC &formatetc, const QMimeData *mimeData) const
 Returns true if the converter can convert from the mimeData to the format specified in formatetc. More...
 
bool canConvertToMime (const QString &mimeType, IDataObject *pDataObj) const
 Returns true if the converter can convert to the mimeType from the available formats in pDataObj. More...
 
bool convertFromMime (const FORMATETC &formatetc, const QMimeData *mimeData, STGMEDIUM *pmedium) const
 Convert the mimeData to the format specified in formatetc. More...
 
QVariant convertToMime (const QString &mime, LPDATAOBJECT pDataObj, QVariant::Type preferredType) const
 
QVector< FORMATETCformatsForMime (const QString &mimeType, const QMimeData *mimeData) const
 Returns a QVector of FORMATETC structures representing the different windows clipboard formats that can be provided for the mimeType from the mimeData. More...
 
QString mimeForFormat (const FORMATETC &formatetc) const
 Returns the mime type that will be created form the format specified in formatetc, or an empty string if this converter does not support formatetc. More...
 
 QWindowsMimeURI ()
 
- Public Functions inherited from QWindowsMime
virtual QVariant convertToMime (const QString &mimeType, IDataObject *pDataObj, QVariant::Type preferredType) const =0
 Returns a QVariant containing the converted data for mimeType from pDataObj. More...
 
 QWindowsMime ()
 Constructs a new conversion object, adding it to the globally accessed list of available converters. More...
 
virtual ~QWindowsMime ()
 Destroys a conversion object, removing it from the global list of available converters. More...
 

Properties

int CF_INETURL
 
int CF_INETURL_W
 

Additional Inherited Members

- Static Public Functions inherited from QWindowsMime
static int registerMimeType (const QString &mime)
 Registers the MIME type mime, and returns an ID number identifying the format on Windows. More...
 

Detailed Description

Definition at line 580 of file qmime_win.cpp.

Constructors and Destructors

◆ QWindowsMimeURI()

QWindowsMimeURI::QWindowsMimeURI ( )

Definition at line 595 of file qmime_win.cpp.

596 {
597  CF_INETURL_W = QWindowsMime::registerMimeType(QLatin1String("UniformResourceLocatorW"));
598  CF_INETURL = QWindowsMime::registerMimeType(QLatin1String("UniformResourceLocator"));
599 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static int registerMimeType(const QString &mime)
Registers the MIME type mime, and returns an ID number identifying the format on Windows.
Definition: qmime_win.cpp:283

Functions

◆ canConvertFromMime()

bool QWindowsMimeURI::canConvertFromMime ( const FORMATETC formatetc,
const QMimeData mimeData 
) const
virtual

Returns true if the converter can convert from the mimeData to the format specified in formatetc.

All subclasses must reimplement this pure virtual function.

Implements QWindowsMime.

Definition at line 601 of file qmime_win.cpp.

602 {
603  if (getCf(formatetc) == CF_HDROP) {
604  QList<QUrl> urls = mimeData->urls();
605  for (int i=0; i<urls.size(); i++) {
606  if (!urls.at(i).toLocalFile().isEmpty())
607  return true;
608  }
609  }
610  return (getCf(formatetc) == CF_INETURL_W || getCf(formatetc) == CF_INETURL) && mimeData->hasFormat(QLatin1String("text/uri-list"));
611 }
static int getCf(const FORMATETC &formatetc)
Definition: qmime_win.cpp:125
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QList< QUrl > urls() const
Returns a list of URLs contained within the MIME data object.
Definition: qmimedata.cpp:310
QString toLocalFile() const
Returns the path of this URL formatted as a local file path.
Definition: qurl.cpp:6412
virtual bool hasFormat(const QString &mimetype) const
Returns true if the object can return data for the MIME type specified by mimeType; otherwise returns...
Definition: qmimedata.cpp:563
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
#define CF_HDROP

◆ canConvertToMime()

bool QWindowsMimeURI::canConvertToMime ( const QString mimeType,
IDataObject *  pDataObj 
) const
virtual

Returns true if the converter can convert to the mimeType from the available formats in pDataObj.

All subclasses must reimplement this pure virtual function.

Implements QWindowsMime.

Definition at line 668 of file qmime_win.cpp.

669 {
670  return mimeType == QLatin1String("text/uri-list")
671  && (canGetData(CF_HDROP, pDataObj) || canGetData(CF_INETURL_W, pDataObj) || canGetData(CF_INETURL, pDataObj));
672 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define CF_HDROP
static bool canGetData(int cf, IDataObject *pDataObj)
Definition: qmime_win.cpp:191

◆ convertFromMime()

bool QWindowsMimeURI::convertFromMime ( const FORMATETC formatetc,
const QMimeData mimeData,
STGMEDIUM pmedium 
) const
virtual

Convert the mimeData to the format specified in formatetc.

The converted data should then be placed in pmedium structure.

Return true if the conversion was successful.

All subclasses must reimplement this pure virtual function.

Implements QWindowsMime.

Definition at line 613 of file qmime_win.cpp.

614 {
615  if (canConvertFromMime(formatetc, mimeData)) {
616  if (getCf(formatetc) == CF_HDROP) {
617  QList<QUrl> urls = mimeData->urls();
618  QStringList fileNames;
619  int size = sizeof(DROPFILES)+2;
620  for (int i=0; i<urls.size(); i++) {
622  if (!fn.isEmpty()) {
623  size += sizeof(ushort) * (fn.length() + 1);
624  fileNames.append(fn);
625  }
626  }
627 
628  QByteArray result(size, '\0');
629  DROPFILES* d = (DROPFILES*)result.data();
630  d->pFiles = sizeof(DROPFILES);
631  GetCursorPos(&d->pt); // try
632  d->fNC = true;
633  char* files = ((char*)d) + d->pFiles;
634 
635  d->fWide = true;
636  wchar_t* f = (wchar_t*)files;
637  for (int i=0; i<fileNames.size(); i++) {
638  int l = fileNames.at(i).length();
639  memcpy(f, fileNames.at(i).utf16(), l * sizeof(ushort));
640  f += l;
641  *f++ = 0;
642  }
643  *f = 0;
644 
645  return setData(result, pmedium);
646  } else if (getCf(formatetc) == CF_INETURL_W) {
647  QList<QUrl> urls = mimeData->urls();
648  QByteArray result;
649  if (!urls.isEmpty()) {
650  QString url = urls.at(0).toString();
651  result = QByteArray((const char *)url.utf16(), url.length() * sizeof(ushort));
652  }
653  result.append('\0');
654  result.append('\0');
655  return setData(result, pmedium);
656  } else if (getCf(formatetc) == CF_INETURL) {
657  QList<QUrl> urls = mimeData->urls();
658  QByteArray result;
659  if (!urls.isEmpty())
660  result = urls.at(0).toString().toLocal8Bit();
661  return setData(result, pmedium);
662  }
663  }
664 
665  return false;
666 }
double d
Definition: qnumeric_p.h:62
static int getCf(const FORMATETC &formatetc)
Definition: qmime_win.cpp:125
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
Definition: qurl.cpp:5896
QByteArray & append(char c)
Appends the character ch to this byte array.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
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
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
static bool setData(const QByteArray &data, STGMEDIUM *pmedium)
Definition: qmime_win.cpp:141
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
QList< QUrl > urls() const
Returns a list of URLs contained within the MIME data object.
Definition: qmimedata.cpp:310
QString toLocalFile() const
Returns the path of this URL formatted as a local file path.
Definition: qurl.cpp:6412
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
unsigned short ushort
Definition: qglobal.h:995
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QFactoryLoader * l
bool canConvertFromMime(const FORMATETC &formatetc, const QMimeData *mimeData) const
Returns true if the converter can convert from the mimeData to the format specified in formatetc...
Definition: qmime_win.cpp:601
static QString toNativeSeparators(const QString &pathName)
Returns pathName with the &#39;/&#39; separators converted to separators that are appropriate for the underly...
Definition: qdir.cpp:812
#define CF_HDROP
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ convertToMime()

QVariant QWindowsMimeURI::convertToMime ( const QString mime,
LPDATAOBJECT  pDataObj,
QVariant::Type  preferredType 
) const

Definition at line 696 of file qmime_win.cpp.

697 {
698  if (mimeType == QLatin1String("text/uri-list")) {
699  if (canGetData(CF_HDROP, pDataObj)) {
700  QByteArray texturi;
701  QList<QVariant> urls;
702 
703  QByteArray data = getData(CF_HDROP, pDataObj);
704  if (data.isEmpty())
705  return QVariant();
706 
707  LPDROPFILES hdrop = (LPDROPFILES)data.data();
708  if (hdrop->fWide) {
709  const wchar_t* filesw = (const wchar_t *)(data.data() + hdrop->pFiles);
710  int i = 0;
711  while (filesw[i]) {
712  QString fileurl = QString::fromWCharArray(filesw + i);
713  urls += QUrl::fromLocalFile(fileurl);
714  i += fileurl.length()+1;
715  }
716  } else {
717  const char* files = (const char *)data.data() + hdrop->pFiles;
718  int i=0;
719  while (files[i]) {
721  i += int(strlen(files+i))+1;
722  }
723  }
724 
725  if (preferredType == QVariant::Url && urls.size() == 1)
726  return urls.at(0);
727  else if (!urls.isEmpty())
728  return urls;
729  } else if (canGetData(CF_INETURL_W, pDataObj)) {
730  QByteArray data = getData(CF_INETURL_W, pDataObj);
731  if (data.isEmpty())
732  return QVariant();
733  return QUrl(QString::fromWCharArray((const wchar_t *)data.constData()));
734  } else if (canGetData(CF_INETURL, pDataObj)) {
735  QByteArray data = getData(CF_INETURL, pDataObj);
736  if (data.isEmpty())
737  return QVariant();
738  return QUrl(QString::fromLocal8Bit(data.constData()));
739  }
740  }
741  return QVariant();
742 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
Definition: qstring.cpp:4245
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
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
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static const char * data(const QByteArray &arr)
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition: qurl.cpp:6374
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
#define CF_HDROP
static QByteArray getData(int cf, IDataObject *pDataObj)
Definition: qmime_win.cpp:156
static bool canGetData(int cf, IDataObject *pDataObj)
Definition: qmime_win.cpp:191

◆ formatsForMime()

QVector< FORMATETC > QWindowsMimeURI::formatsForMime ( const QString mimeType,
const QMimeData mimeData 
) const
virtual

Returns a QVector of FORMATETC structures representing the different windows clipboard formats that can be provided for the mimeType from the mimeData.

All subclasses must reimplement this pure virtual function.

Implements QWindowsMime.

Definition at line 682 of file qmime_win.cpp.

683 {
684  QVector<FORMATETC> formatics;
685  if (mimeType == QLatin1String("text/uri-list")) {
686  if (canConvertFromMime(setCf(CF_HDROP), mimeData))
687  formatics += setCf(CF_HDROP);
688  if (canConvertFromMime(setCf(CF_INETURL_W), mimeData))
689  formatics += setCf(CF_INETURL_W);
690  if (canConvertFromMime(setCf(CF_INETURL), mimeData))
691  formatics += setCf(CF_INETURL);
692  }
693  return formatics;
694 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
static FORMATETC setCf(int cf)
Definition: qmime_win.cpp:130
bool canConvertFromMime(const FORMATETC &formatetc, const QMimeData *mimeData) const
Returns true if the converter can convert from the mimeData to the format specified in formatetc...
Definition: qmime_win.cpp:601
#define CF_HDROP

◆ mimeForFormat()

QString QWindowsMimeURI::mimeForFormat ( const FORMATETC formatetc) const
virtual

Returns the mime type that will be created form the format specified in formatetc, or an empty string if this converter does not support formatetc.

All subclasses must reimplement this pure virtual function.

Implements QWindowsMime.

Definition at line 674 of file qmime_win.cpp.

675 {
676  QString format;
677  if (getCf(formatetc) == CF_HDROP || getCf(formatetc) == CF_INETURL_W || getCf(formatetc) == CF_INETURL)
678  format = QLatin1String("text/uri-list");
679  return format;
680 }
static int getCf(const FORMATETC &formatetc)
Definition: qmime_win.cpp:125
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define CF_HDROP

Properties

◆ CF_INETURL

int QWindowsMimeURI::CF_INETURL
private

Definition at line 592 of file qmime_win.cpp.

◆ CF_INETURL_W

int QWindowsMimeURI::CF_INETURL_W
private

Definition at line 591 of file qmime_win.cpp.


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