Qt 4.8
Public Functions | Properties | List of all members
QWindowsMimeHtml Class Reference
Inheritance diagram for QWindowsMimeHtml:
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...
 
 QWindowsMimeHtml ()
 
- 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

int CF_HTML
 

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

Constructors and Destructors

◆ QWindowsMimeHtml()

QWindowsMimeHtml::QWindowsMimeHtml ( )

Definition at line 763 of file qmime_win.cpp.

764 {
766 }
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 QWindowsMimeHtml::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 789 of file qmime_win.cpp.

790 {
791  return getCf(formatetc) == CF_HTML && (!mimeData->html().isEmpty());
792 }
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
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

◆ canConvertToMime()

bool QWindowsMimeHtml::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 783 of file qmime_win.cpp.

784 {
785  return mimeType == QLatin1String("text/html") && canGetData(CF_HTML, pDataObj);
786 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static bool canGetData(int cf, IDataObject *pDataObj)
Definition: qmime_win.cpp:191

◆ convertFromMime()

bool QWindowsMimeHtml::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 848 of file qmime_win.cpp.

849 {
850  if (canConvertFromMime(formatetc, mimeData)) {
851  QByteArray data = mimeData->html().toUtf8();
852  QByteArray result =
853  "Version:1.0\r\n" // 0-12
854  "StartHTML:0000000105\r\n" // 13-35
855  "EndHTML:0000000000\r\n" // 36-55
856  "StartFragment:0000000000\r\n" // 58-86
857  "EndFragment:0000000000\r\n\r\n"; // 87-105
858 
859  if (data.indexOf("<!--StartFragment-->") == -1)
860  result += "<!--StartFragment-->";
861  result += data;
862  if (data.indexOf("<!--EndFragment-->") == -1)
863  result += "<!--EndFragment-->";
864 
865  // set the correct number for EndHTML
866  QByteArray pos = QString::number(result.size()).toLatin1();
867  memcpy((char *)(result.data() + 53 - pos.length()), pos.constData(), pos.length());
868 
869  // set correct numbers for StartFragment and EndFragment
870  pos = QString::number(result.indexOf("<!--StartFragment-->") + 20).toLatin1();
871  memcpy((char *)(result.data() + 79 - pos.length()), pos.constData(), pos.length());
872  pos = QString::number(result.indexOf("<!--EndFragment-->")).toLatin1();
873  memcpy((char *)(result.data() + 103 - pos.length()), pos.constData(), pos.length());
874 
875  return setData(result, pmedium);
876  }
877  return false;
878 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static bool setData(const QByteArray &data, STGMEDIUM *pmedium)
Definition: qmime_win.cpp:141
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)
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
int length() const
Same as size().
Definition: qbytearray.h:356
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 bytes in this byte array.
Definition: qbytearray.h:402
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:789

◆ convertToMime()

QVariant QWindowsMimeHtml::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 806 of file qmime_win.cpp.

807 {
808  Q_UNUSED(preferredType);
809  QVariant result;
810  if (canConvertToMime(mime, pDataObj)) {
811  QByteArray html = getData(CF_HTML, pDataObj);
812 #ifdef QMIME_DEBUG
813  qDebug("QWindowsMimeHtml::convertToMime");
814  qDebug("raw :");
815  qDebug(html);
816 #endif
817  int start = html.indexOf("StartFragment:");
818  int end = html.indexOf("EndFragment:");
819 
820  if (start != -1) {
821  int startOffset = start + 14;
822  int i = startOffset;
823  while (html.at(i) != '\r' && html.at(i) != '\n')
824  ++i;
825  QByteArray bytecount = html.mid(startOffset, i - startOffset);
826  start = bytecount.toInt();
827  }
828 
829  if (end != -1) {
830  int endOffset = end + 12;
831  int i = endOffset ;
832  while (html.at(i) != '\r' && html.at(i) != '\n')
833  ++i;
834  QByteArray bytecount = html.mid(endOffset , i - endOffset);
835  end = bytecount.toInt();
836  }
837 
838  if (end > start && start > 0) {
839  html = "<!--StartFragment-->" + html.mid(start, end - start);
840  html += "<!--EndFragment-->";
841  html.replace('\r', "");
842  result = QString::fromUtf8(html);
843  }
844  }
845  return result;
846 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const char * mime
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:783
Q_CORE_EXPORT void qDebug(const char *,...)
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
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
int toInt(bool *ok=0, int base=10) const
Returns the byte array converted to an int using base base, which is 10 by default and must be betwee...
QByteArray & replace(int index, int len, const char *s)
This is an overloaded member function, provided for convenience. It differs from the above function o...
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413
static const KeyPair *const end
#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

◆ formatsForMime()

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

769 {
770  QVector<FORMATETC> formatetcs;
771  if (mimeType == QLatin1String("text/html") && (!mimeData->html().isEmpty()))
772  formatetcs += setCf(CF_HTML);
773  return formatetcs;
774 }
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 isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
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

◆ mimeForFormat()

QString QWindowsMimeHtml::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 776 of file qmime_win.cpp.

777 {
778  if (getCf(formatetc) == CF_HTML)
779  return QLatin1String("text/html");
780  return QString();
781 }
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

Properties

◆ CF_HTML

int QWindowsMimeHtml::CF_HTML
private

Definition at line 760 of file qmime_win.cpp.


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