Qt 4.8
Public Functions | Properties | Static Private Attributes | List of all members
QLastResortMimes Class Reference
Inheritance diagram for QLastResortMimes:
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...
 
 QLastResortMimes ()
 
- 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, QStringformats
 

Static Private Attributes

static QStringList excludeList
 
static QStringList ianaTypes
 

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

Constructors and Destructors

◆ QLastResortMimes()

QLastResortMimes::QLastResortMimes ( )

Definition at line 1181 of file qmime_win.cpp.

1182 {
1183  //MIME Media-Types
1184  if (!ianaTypes.size()) {
1185  ianaTypes.append(QLatin1String("application/"));
1186  ianaTypes.append(QLatin1String("audio/"));
1187  ianaTypes.append(QLatin1String("example/"));
1188  ianaTypes.append(QLatin1String("image/"));
1189  ianaTypes.append(QLatin1String("message/"));
1190  ianaTypes.append(QLatin1String("model/"));
1191  ianaTypes.append(QLatin1String("multipart/"));
1192  ianaTypes.append(QLatin1String("text/"));
1193  ianaTypes.append(QLatin1String("video/"));
1194  }
1195  //Types handled by other classes
1196  if (!excludeList.size()) {
1197  excludeList.append(QLatin1String("HTML Format"));
1198  excludeList.append(QLatin1String("UniformResourceLocator"));
1199  excludeList.append(QLatin1String("text/html"));
1200  excludeList.append(QLatin1String("text/plain"));
1201  excludeList.append(QLatin1String("text/uri-list"));
1202  excludeList.append(QLatin1String("application/x-qt-image"));
1203  excludeList.append(QLatin1String("application/x-color"));
1204  }
1205 }
static QStringList excludeList
Definition: qmime_win.cpp:1175
static QStringList ianaTypes
Definition: qmime_win.cpp:1174
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
int size() const
Returns the number of items in the list.
Definition: qlist.h:137

Functions

◆ canConvertFromMime()

bool QLastResortMimes::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 1207 of file qmime_win.cpp.

1208 {
1209  // really check
1210 #ifndef QT_NO_DRAGANDDROP
1211  return formatetc.tymed & TYMED_HGLOBAL
1212  && (formats.contains(formatetc.cfFormat)
1213  && QInternalMimeData::hasFormatHelper(formats.value(formatetc.cfFormat), mimeData));
1214 #else
1215  Q_UNUSED(mimeData);
1216  Q_UNUSED(formatetc);
1217  return formatetc.tymed & TYMED_HGLOBAL
1218  && formats.contains(formatetc.cfFormat);
1219 #endif //QT_NO_DRAGANDDROP
1220 }
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
static bool hasFormatHelper(const QString &mimeType, const QMimeData *data)
Definition: qdnd.cpp:428
bool contains(const Key &key) const
Returns true if the map contains an item with key key; otherwise returns false.
Definition: qmap.h:553
QMap< int, QString > formats
Definition: qmime_win.cpp:1173
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ canConvertToMime()

bool QLastResortMimes::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 1263 of file qmime_win.cpp.

1264 {
1265  if (isCustomMimeType(mimeType)) {
1266  QString clipFormat = customMimeType(mimeType);
1267  int cf = RegisterClipboardFormat(reinterpret_cast<const wchar_t *> (clipFormat.utf16()));
1268  return canGetData(cf, pDataObj);
1269  } else if (formats.keys(mimeType).isEmpty()) {
1270  // if it is not in there then register it an see if we can get it
1271  int cf = QWindowsMime::registerMimeType(mimeType);
1272  return canGetData(cf, pDataObj);
1273  } else {
1274  return canGetData(formats.key(mimeType), pDataObj);
1275  }
1276  return false;
1277 }
static QString customMimeType(const QString &mimeType)
Definition: qmime_win.cpp:1256
const Key key(const T &value) const
Returns the first key with value value.
Definition: qmap.h:844
static bool isCustomMimeType(const QString &mimeType)
Definition: qmime_win.cpp:1251
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
QList< Key > keys() const
Returns a list containing all the keys in the map in ascending order.
Definition: qmap.h:818
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
QMap< int, QString > formats
Definition: qmime_win.cpp:1173
static bool canGetData(int cf, IDataObject *pDataObj)
Definition: qmime_win.cpp:191
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ convertFromMime()

bool QLastResortMimes::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 1222 of file qmime_win.cpp.

1223 {
1224 #ifndef QT_NO_DRAGANDDROP
1225  return canConvertFromMime(formatetc, mimeData)
1226  && setData(QInternalMimeData::renderDataHelper(formats.value(getCf(formatetc)), mimeData), pmedium);
1227 #else
1228  Q_UNUSED(mimeData);
1229  Q_UNUSED(formatetc);
1230  Q_UNUSED(pmedium);
1231  return false;
1232 #endif //QT_NO_DRAGANDDROP
1233 }
static int getCf(const FORMATETC &formatetc)
Definition: qmime_win.cpp:125
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
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:1207
static QByteArray renderDataHelper(const QString &mimeType, const QMimeData *data)
Definition: qdnd.cpp:447
QMap< int, QString > formats
Definition: qmime_win.cpp:1173
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ convertToMime()

QVariant QLastResortMimes::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 1279 of file qmime_win.cpp.

1280 {
1281  Q_UNUSED(preferredType);
1282  QVariant val;
1283  if (canConvertToMime(mimeType, pDataObj)) {
1284  QByteArray data;
1285  if (isCustomMimeType(mimeType)) {
1286  QString clipFormat = customMimeType(mimeType);
1287  int cf = RegisterClipboardFormat(reinterpret_cast<const wchar_t *> (clipFormat.utf16()));
1288  data = getData(cf, pDataObj);
1289  } else if (formats.keys(mimeType).isEmpty()) {
1290  int cf = QWindowsMime::registerMimeType(mimeType);
1291  data = getData(cf, pDataObj);
1292  } else {
1293  data = getData(formats.key(mimeType), pDataObj);
1294  }
1295  if (!data.isEmpty())
1296  val = data; // it should be enough to return the data and let QMimeData do the rest.
1297  }
1298  return val;
1299 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static QString customMimeType(const QString &mimeType)
Definition: qmime_win.cpp:1256
const Key key(const T &value) const
Returns the first key with value value.
Definition: qmap.h:844
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static bool isCustomMimeType(const QString &mimeType)
Definition: qmime_win.cpp:1251
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
static const char * data(const QByteArray &arr)
QList< Key > keys() const
Returns a list containing all the keys in the map in ascending order.
Definition: qmap.h:818
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:1263
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
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
QMap< int, QString > formats
Definition: qmime_win.cpp:1173
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
static QByteArray getData(int cf, IDataObject *pDataObj)
Definition: qmime_win.cpp:156
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ formatsForMime()

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

1236 {
1237  QVector<FORMATETC> formatetcs;
1238  if (!formats.keys(mimeType).isEmpty()) {
1239  formatetcs += setCf(formats.key(mimeType));
1240  } else if (!excludeList.contains(mimeType, Qt::CaseInsensitive)){
1241  // register any other available formats
1242  int cf = QWindowsMime::registerMimeType(mimeType);
1243  QLastResortMimes *that = const_cast<QLastResortMimes *>(this);
1244  that->formats.insert(cf, mimeType);
1245  formatetcs += setCf(cf);
1246  }
1247  return formatetcs;
1248 }
const Key key(const T &value) const
Returns the first key with value value.
Definition: qmap.h:844
static QStringList excludeList
Definition: qmime_win.cpp:1175
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
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
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
QMap< int, QString > formats
Definition: qmime_win.cpp:1173

◆ mimeForFormat()

QString QLastResortMimes::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 1301 of file qmime_win.cpp.

1302 {
1303  QString format = formats.value(getCf(formatetc));
1304  if (!format.isEmpty())
1305  return format;
1306 
1307  wchar_t buffer[256];
1308  int len = GetClipboardFormatName(getCf(formatetc), buffer, 256);
1309 
1310  if (len) {
1311  QString clipFormat = QString::fromWCharArray(buffer, len);
1312 #ifndef QT_NO_DRAGANDDROP
1313  if (QInternalMimeData::canReadData(clipFormat))
1314  format = clipFormat;
1315  else if((formatetc.cfFormat >= 0xC000)){
1316  //create the mime as custom. not registered.
1317  if (!excludeList.contains(clipFormat, Qt::CaseInsensitive)) {
1318  //check if this is a mime type
1319  bool ianaType = false;
1320  int sz = ianaTypes.size();
1321  for (int i = 0; i < sz; i++) {
1322  if (clipFormat.startsWith(ianaTypes[i], Qt::CaseInsensitive)) {
1323  ianaType = true;
1324  break;
1325  }
1326  }
1327  if (!ianaType)
1328  format = QLatin1String(x_qt_windows_mime) + clipFormat + QLatin1Char('\"');
1329  else
1330  format = clipFormat;
1331  }
1332  }
1333 #endif //QT_NO_DRAGANDDROP
1334  }
1335 
1336  return format;
1337 }
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 int getCf(const FORMATETC &formatetc)
Definition: qmime_win.cpp:125
static QStringList excludeList
Definition: qmime_win.cpp:1175
static QStringList ianaTypes
Definition: qmime_win.cpp:1174
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
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 string has no characters; otherwise returns false.
Definition: qstring.h:704
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
static bool canReadData(const QString &mimeType)
Definition: qdnd.cpp:408
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static const char x_qt_windows_mime[]
Definition: qmime_win.cpp:1249
QMap< int, QString > formats
Definition: qmime_win.cpp:1173
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

Properties

◆ excludeList

QStringList QLastResortMimes::excludeList
staticprivate

Definition at line 1175 of file qmime_win.cpp.

◆ formats

QMap<int, QString> QLastResortMimes::formats
private

Definition at line 1173 of file qmime_win.cpp.

Referenced by formatsForMime().

◆ ianaTypes

QStringList QLastResortMimes::ianaTypes
staticprivate

Definition at line 1174 of file qmime_win.cpp.


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