Qt 4.8
Public Functions | Properties | List of all members
QBuiltInMimes Class Reference
Inheritance diagram for QBuiltInMimes:
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, IDataObject *pDataObj, QVariant::Type preferredType) const
 Returns a QVariant containing the converted data for mimeType from pDataObj. More...
 
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...
 
 QBuiltInMimes ()
 
- Public Functions inherited from QWindowsMime
 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

QMap< int, QStringinFormats
 
QMap< int, QStringoutFormats
 

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 1035 of file qmime_win.cpp.

Constructors and Destructors

◆ QBuiltInMimes()

QBuiltInMimes::QBuiltInMimes ( )

Definition at line 1055 of file qmime_win.cpp.

1056 : QWindowsMime()
1057 {
1058  outFormats.insert(QWindowsMime::registerMimeType(QLatin1String("application/x-color")), QLatin1String("application/x-color"));
1059  inFormats.insert(QWindowsMime::registerMimeType(QLatin1String("application/x-color")), QLatin1String("application/x-color"));
1060 }
QMap< int, QString > inFormats
Definition: qmime_win.cpp:1052
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QWindowsMime()
Constructs a new conversion object, adding it to the globally accessed list of available converters...
Definition: qmime_win.cpp:264
QMap< int, QString > outFormats
Definition: qmime_win.cpp:1051
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
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

Functions

◆ canConvertFromMime()

bool QBuiltInMimes::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 1062 of file qmime_win.cpp.

Referenced by convertFromMime(), and QLastResortMimes::convertFromMime().

1063 {
1064  // really check
1065  return formatetc.tymed & TYMED_HGLOBAL
1066  && outFormats.contains(formatetc.cfFormat)
1067  && mimeData->formats().contains(outFormats.value(formatetc.cfFormat));
1068 }
virtual QStringList formats() const
Returns a list of formats supported by the object.
Definition: qmimedata.cpp:579
QMap< int, QString > outFormats
Definition: qmime_win.cpp:1051
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
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
bool contains(const Key &key) const
Returns true if the map contains an item with key key; otherwise returns false.
Definition: qmap.h:553

◆ canConvertToMime()

bool QBuiltInMimes::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 1125 of file qmime_win.cpp.

Referenced by convertToMime(), and QLastResortMimes::convertToMime().

1126 {
1127  return (!inFormats.keys(mimeType).isEmpty())
1128  && canGetData(inFormats.key(mimeType), pDataObj);
1129 }
const Key key(const T &value) const
Returns the first key with value value.
Definition: qmap.h:844
QMap< int, QString > inFormats
Definition: qmime_win.cpp:1052
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QList< Key > keys() const
Returns a list containing all the keys in the map in ascending order.
Definition: qmap.h:818
static bool canGetData(int cf, IDataObject *pDataObj)
Definition: qmime_win.cpp:191

◆ convertFromMime()

bool QBuiltInMimes::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 1070 of file qmime_win.cpp.

1071 {
1072  if (canConvertFromMime(formatetc, mimeData)) {
1073  QByteArray data;
1074  if (outFormats.value(getCf(formatetc)) == QLatin1String("text/html")) {
1075  // text/html is in wide chars on windows (compatible with mozillia)
1076  QString html = mimeData->html();
1077  // same code as in the text converter up above
1078  const QChar *u = html.unicode();
1079  QString res;
1080  const int s = html.length();
1081  int maxsize = s + s/40 + 3;
1082  res.resize(maxsize);
1083  int ri = 0;
1084  bool cr = false;
1085  for (int i=0; i < s; ++i) {
1086  if (*u == QLatin1Char('\r'))
1087  cr = true;
1088  else {
1089  if (*u == QLatin1Char('\n') && !cr)
1090  res[ri++] = QLatin1Char('\r');
1091  cr = false;
1092  }
1093  res[ri++] = *u;
1094  if (ri+3 >= maxsize) {
1095  maxsize += maxsize/4;
1096  res.resize(maxsize);
1097  }
1098  ++u;
1099  }
1100  res.truncate(ri);
1101  const int byteLength = res.length() * sizeof(ushort);
1102  QByteArray r(byteLength + 2, '\0');
1103  memcpy(r.data(), res.unicode(), byteLength);
1104  r[byteLength] = 0;
1105  r[byteLength+1] = 0;
1106  data = r;
1107  } else {
1108 #ifndef QT_NO_DRAGANDDROP
1109  data = QInternalMimeData::renderDataHelper(outFormats.value(getCf(formatetc)), mimeData);
1110 #endif //QT_NO_DRAGANDDROP
1111  }
1112  return setData(data, pmedium);
1113  }
1114  return false;
1115 }
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:1062
static int getCf(const FORMATETC &formatetc)
Definition: qmime_win.cpp:125
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
quint16 u
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QMap< int, QString > outFormats
Definition: qmime_win.cpp:1051
void truncate(int pos)
Truncates the string at the given position index.
Definition: qstring.cpp:4603
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
static bool setData(const QByteArray &data, STGMEDIUM *pmedium)
Definition: qmime_win.cpp:141
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
QString html() const
Returns a string if the data stored in the object is HTML (MIME type text/html); otherwise returns an...
Definition: qmimedata.cpp:400
static const char * data(const QByteArray &arr)
static QByteArray renderDataHelper(const QString &mimeType, const QMimeData *data)
Definition: qdnd.cpp:447
void resize(int size)
Sets the size of the string to size characters.
Definition: qstring.cpp:1353
unsigned short ushort
Definition: qglobal.h:995
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ convertToMime()

QVariant QBuiltInMimes::convertToMime ( const QString mimeType,
IDataObject *  pDataObj,
QVariant::Type  preferredType 
) const
virtual

Returns a QVariant containing the converted data for mimeType from pDataObj.

If possible the QVariant should be of the preferredType to avoid needless conversions.

All subclasses must reimplement this pure virtual function.

Implements QWindowsMime.

Definition at line 1131 of file qmime_win.cpp.

1132 {
1133  QVariant val;
1134  if (canConvertToMime(mimeType, pDataObj)) {
1135  QByteArray data = getData(inFormats.key(mimeType), pDataObj);
1136  if (!data.isEmpty()) {
1137 #ifdef QMIME_DEBUG
1138  qDebug("QBuiltInMimes::convertToMime()");
1139 #endif
1140  if (mimeType == QLatin1String("text/html") && preferredType == QVariant::String) {
1141  // text/html is in wide chars on windows (compatible with Mozilla)
1142  val = QString::fromWCharArray((const wchar_t *)data.data());
1143  } else {
1144  val = data; // it should be enough to return the data and let QMimeData do the rest.
1145  }
1146  }
1147  }
1148  return val;
1149 }
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
const Key key(const T &value) const
Returns the first key with value value.
Definition: qmap.h:844
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
QMap< int, QString > inFormats
Definition: qmime_win.cpp:1052
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
Q_CORE_EXPORT void qDebug(const char *,...)
static const char * data(const QByteArray &arr)
bool canConvertToMime(const QString &mimeType, IDataObject *pDataObj) const
Returns true if the converter can convert to the mimeType from the available formats in pDataObj...
Definition: qmime_win.cpp:1125
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
static QByteArray getData(int cf, IDataObject *pDataObj)
Definition: qmime_win.cpp:156

◆ formatsForMime()

QVector< FORMATETC > QBuiltInMimes::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 1117 of file qmime_win.cpp.

1118 {
1119  QVector<FORMATETC> formatetcs;
1120  if (!outFormats.keys(mimeType).isEmpty() && mimeData->formats().contains(mimeType))
1121  formatetcs += setCf(outFormats.key(mimeType));
1122  return formatetcs;
1123 }
virtual QStringList formats() const
Returns a list of formats supported by the object.
Definition: qmimedata.cpp:579
const Key key(const T &value) const
Returns the first key with value value.
Definition: qmap.h:844
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
static FORMATETC setCf(int cf)
Definition: qmime_win.cpp:130
QMap< int, QString > outFormats
Definition: qmime_win.cpp:1051
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
QList< Key > keys() const
Returns a list containing all the keys in the map in ascending order.
Definition: qmap.h:818

◆ mimeForFormat()

QString QBuiltInMimes::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 1151 of file qmime_win.cpp.

1152 {
1153  return inFormats.value(getCf(formatetc));
1154 }
static int getCf(const FORMATETC &formatetc)
Definition: qmime_win.cpp:125
QMap< int, QString > inFormats
Definition: qmime_win.cpp:1052
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499

Properties

◆ inFormats

QMap<int, QString> QBuiltInMimes::inFormats
private

Definition at line 1052 of file qmime_win.cpp.

Referenced by canConvertToMime(), convertToMime(), mimeForFormat(), and QBuiltInMimes().

◆ outFormats

QMap<int, QString> QBuiltInMimes::outFormats
private

Definition at line 1051 of file qmime_win.cpp.

Referenced by canConvertFromMime(), convertFromMime(), formatsForMime(), and QBuiltInMimes().


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