diff options
author | Jørgen Lind <jorgen.lind@nokia.com> | 2011-01-03 15:31:44 (GMT) |
---|---|---|
committer | Jørgen Lind <jorgen.lind@nokia.com> | 2011-01-04 14:18:30 (GMT) |
commit | 0ceed999bbf25d19b3ded8a1b300cf0c6129f775 (patch) | |
tree | 909678ee4196b61c346d29ef68444c2d4340be5a /src/plugins/platforms | |
parent | 6138bcd3543ac605731c9626191e7914f0995858 (diff) | |
download | Qt-0ceed999bbf25d19b3ded8a1b300cf0c6129f775.zip Qt-0ceed999bbf25d19b3ded8a1b300cf0c6129f775.tar.gz Qt-0ceed999bbf25d19b3ded8a1b300cf0c6129f775.tar.bz2 |
Create clearer sepperation between TestLiteMime and QTestliteClipboard
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r-- | src/plugins/platforms/testlite/qtestliteclipboard.cpp | 130 | ||||
-rw-r--r-- | src/plugins/platforms/testlite/qtestliteclipboard.h | 7 | ||||
-rw-r--r-- | src/plugins/platforms/testlite/qtestlitemime.cpp | 173 | ||||
-rw-r--r-- | src/plugins/platforms/testlite/qtestlitemime.h | 32 |
4 files changed, 181 insertions, 161 deletions
diff --git a/src/plugins/platforms/testlite/qtestliteclipboard.cpp b/src/plugins/platforms/testlite/qtestliteclipboard.cpp index 9e1b387..25c16ea 100644 --- a/src/plugins/platforms/testlite/qtestliteclipboard.cpp +++ b/src/plugins/platforms/testlite/qtestliteclipboard.cpp @@ -7,6 +7,104 @@ #include <QtCore/QDebug> +class QTestLiteClipboardMime : public QTestLiteMime +{ + Q_OBJECT +public: + QTestLiteClipboardMime(QClipboard::Mode mode, QTestLiteClipboard *clipboard) + : QTestLiteMime() + , m_clipboard(clipboard) + { + switch (mode) { + case QClipboard::Selection: + modeAtom = XA_PRIMARY; + break; + + case QClipboard::Clipboard: + modeAtom = QTestLiteStatic::atom(QTestLiteStatic::CLIPBOARD); + break; + + default: + qWarning("QTestLiteMime: Internal error: Unsupported clipboard mode"); + break; + } + } + +protected: + QStringList formats_sys() const + { + if (empty()) + return QStringList(); + + if (!formatList.count()) { + QTestLiteClipboardMime *that = const_cast<QTestLiteClipboardMime *>(this); + // get the list of targets from the current clipboard owner - we do this + // once so that multiple calls to this function don't require multiple + // server round trips... + that->format_atoms = m_clipboard->getDataInFormat(modeAtom,QTestLiteStatic::atom(QTestLiteStatic::TARGETS)); + + if (format_atoms.size() > 0) { + Atom *targets = (Atom *) format_atoms.data(); + int size = format_atoms.size() / sizeof(Atom); + + for (int i = 0; i < size; ++i) { + if (targets[i] == 0) + continue; + + QStringList formatsForAtom = mimeFormatsForAtom(m_clipboard->screen()->display(),targets[i]); + for (int j = 0; j < formatsForAtom.size(); ++j) { + if (!formatList.contains(formatsForAtom.at(j))) + that->formatList.append(formatsForAtom.at(j)); + } + } + } + } + + return formatList; + } + + bool hasFormat_sys(const QString &format) const + { + QStringList list = formats(); + return list.contains(format); + } + + QVariant retrieveData_sys(const QString &fmt, QVariant::Type requestedType) const + { + if (fmt.isEmpty() || empty()) + return QByteArray(); + + (void)formats(); // trigger update of format list + + QList<Atom> atoms; + Atom *targets = (Atom *) format_atoms.data(); + int size = format_atoms.size() / sizeof(Atom); + for (int i = 0; i < size; ++i) + atoms.append(targets[i]); + + QByteArray encoding; + Atom fmtatom = mimeAtomForFormat(m_clipboard->screen()->display(),fmt, requestedType, atoms, &encoding); + + if (fmtatom == 0) + return QVariant(); + + return mimeConvertToFormat(m_clipboard->screen()->display(),fmtatom, m_clipboard->getDataInFormat(modeAtom,fmtatom), fmt, requestedType, encoding); + } +private: + bool empty() const + { + Window win = XGetSelectionOwner(m_clipboard->screen()->display(), modeAtom); + + return win == XNone; + } + + + Atom modeAtom; + QTestLiteClipboard *m_clipboard; + QStringList formatList; + QByteArray format_atoms; +}; + const int QTestLiteClipboard::clipboard_timeout = 5000; QTestLiteClipboard::QTestLiteClipboard(QTestLiteScreen *screen) @@ -26,7 +124,7 @@ const QMimeData * QTestLiteClipboard::mimeData(QClipboard::Mode mode) const if (mode == QClipboard::Clipboard) { if (!m_xClipboard) { QTestLiteClipboard *that = const_cast<QTestLiteClipboard *>(this); - that->m_xClipboard = new QTestLiteMime(mode,that); + that->m_xClipboard = new QTestLiteClipboardMime(mode,that); } Window clipboardOwner = XGetSelectionOwner(screen()->display(),QTestLiteStatic::atom(QTestLiteStatic::CLIPBOARD)); if (clipboardOwner == owner()) { @@ -34,6 +132,17 @@ const QMimeData * QTestLiteClipboard::mimeData(QClipboard::Mode mode) const } else { return m_xClipboard; } + } else if (mode == QClipboard::Selection) { + if (!m_xSelection) { + QTestLiteClipboard *that = const_cast<QTestLiteClipboard *>(this); + that->m_xSelection = new QTestLiteClipboardMime(mode,that); + } + Window clipboardOwner = XGetSelectionOwner(screen()->display(),XA_PRIMARY); + if (clipboardOwner == owner()) { + return m_clientSelection; + } else { + return m_xSelection; + } } return 0; } @@ -71,14 +180,19 @@ void QTestLiteClipboard::setMimeData(QMimeData *data, QClipboard::Mode mode) XSetSelectionOwner(m_screen->display(), modeAtom, newOwner, CurrentTime); if (XGetSelectionOwner(m_screen->display(), modeAtom) != newOwner) { -// qWarning("QClipboard::setData: Cannot set X11 selection owner for %s", -// xdndAtomToString(atom).data()); - *d = 0; - return; + qWarning("QClipboard::setData: Cannot set X11 selection owner"); } } +bool QTestLiteClipboard::supportsMode(QClipboard::Mode mode) const +{ + if (mode == QClipboard::Clipboard || mode == QClipboard::Selection) + return true; + return false; +} + + QTestLiteScreen * QTestLiteClipboard::screen() const { return m_screen; @@ -153,14 +267,14 @@ Atom QTestLiteClipboard::sendSelection(QMimeData *d, Atom target, Window window, int dataFormat = 0; QByteArray data; - QString fmt = QTestLiteMime::xdndMimeAtomToString(screen()->display(), target); + QString fmt = QTestLiteMime::mimeAtomToString(screen()->display(), target); if (fmt.isEmpty()) { // Not a MIME type we have qDebug() << "QClipboard: send_selection(): converting to type '%s' is not supported" << fmt.data(); return XNone; } qDebug() << "QClipboard: send_selection(): converting to type '%s'" << fmt.data(); - if (QTestLiteMime::xdndMimeDataForAtom(screen()->display(),target, d, &data, &atomFormat, &dataFormat)) { + if (QTestLiteMime::mimeDataForAtom(screen()->display(),target, d, &data, &atomFormat, &dataFormat)) { // don't allow INCR transfers when using MULTIPLE or to // Motif clients (since Motif doesn't support INCR) @@ -517,3 +631,5 @@ QByteArray QTestLiteClipboard::getDataInFormat(Atom modeAtom, Atom fmtatom) return buf; } + +#include "qtestliteclipboard.moc" diff --git a/src/plugins/platforms/testlite/qtestliteclipboard.h b/src/plugins/platforms/testlite/qtestliteclipboard.h index 31e42b7..22d3734 100644 --- a/src/plugins/platforms/testlite/qtestliteclipboard.h +++ b/src/plugins/platforms/testlite/qtestliteclipboard.h @@ -5,7 +5,6 @@ #include "qtestlitestaticinfo.h" class QTestLiteScreen; -class QTestLiteMime; class QTestLiteClipboard : public QPlatformClipboard { public: @@ -14,6 +13,8 @@ public: const QMimeData *mimeData(QClipboard::Mode mode) const; void setMimeData(QMimeData *data, QClipboard::Mode mode); + bool supportsMode(QClipboard::Mode mode) const; + QTestLiteScreen *screen() const; Window requestor() const; @@ -36,10 +37,10 @@ private: QTestLiteScreen *m_screen; - QTestLiteMime *m_xClipboard; + QMimeData *m_xClipboard; QMimeData *m_clientClipboard; - QTestLiteMime *m_xSelection; + QMimeData *m_xSelection; QMimeData *m_clientSelection; Window m_requestor; diff --git a/src/plugins/platforms/testlite/qtestlitemime.cpp b/src/plugins/platforms/testlite/qtestlitemime.cpp index 6a08b8c..32cacce 100644 --- a/src/plugins/platforms/testlite/qtestlitemime.cpp +++ b/src/plugins/platforms/testlite/qtestlitemime.cpp @@ -4,98 +4,21 @@ #include "qtestlitescreen.h" #include <QtCore/QTextCodec> +#include <QtGui/QImageWriter> +#include <QtCore/QBuffer> -QTestLiteMime::QTestLiteMime(QClipboard::Mode mode, QTestLiteClipboard *clipboard) - : QInternalMimeData(), m_clipboard(clipboard) -{ - switch (mode) { - case QClipboard::Selection: - modeAtom = XA_PRIMARY; - break; - - case QClipboard::Clipboard: - modeAtom = QTestLiteStaticInfo::atom(QTestLiteStaticInfo::CLIPBOARD); - break; - - default: - qWarning("QTestLiteMime: Internal error: Unsupported clipboard mode"); - break; - } -} +QTestLiteMime::QTestLiteMime() + : QInternalMimeData() +{ } QTestLiteMime::~QTestLiteMime() -{ -} +{} -bool QTestLiteMime::empty() const -{ - Window win = XGetSelectionOwner(m_clipboard->screen()->display(), modeAtom); - - return win == XNone; -} -QStringList QTestLiteMime::formats_sys() const -{ - if (empty()) - return QStringList(); - if (!formatList.count()) { - // get the list of targets from the current clipboard owner - we do this - // once so that multiple calls to this function don't require multiple - // server round trips... - format_atoms = m_clipboard->getDataInFormat(modeAtom,QTestLiteStaticInfo::atom(QTestLiteStaticInfo::TARGETS)); - if (format_atoms.size() > 0) { - Atom *targets = (Atom *) format_atoms.data(); - int size = format_atoms.size() / sizeof(Atom); - - for (int i = 0; i < size; ++i) { - if (targets[i] == 0) - continue; - - QStringList formatsForAtom = xdndMimeFormatsForAtom(m_clipboard->screen()->display(),targets[i]); - for (int j = 0; j < formatsForAtom.size(); ++j) { - if (!formatList.contains(formatsForAtom.at(j))) - formatList.append(formatsForAtom.at(j)); - } - } - } - } - - return formatList; -} - -bool QTestLiteMime::hasFormat_sys(const QString &format) const -{ - QStringList list = formats(); - return list.contains(format); -} - -QVariant QTestLiteMime::retrieveData_sys(const QString &fmt, QVariant::Type requestedType) const -{ - if (fmt.isEmpty() || empty()) - return QByteArray(); - - (void)formats(); // trigger update of format list - - QList<Atom> atoms; - Atom *targets = (Atom *) format_atoms.data(); - int size = format_atoms.size() / sizeof(Atom); - for (int i = 0; i < size; ++i) - atoms.append(targets[i]); - - QByteArray encoding; - Atom fmtatom = xdndMimeAtomForFormat(m_clipboard->screen()->display(),fmt, requestedType, atoms, &encoding); - - if (fmtatom == 0) - return QVariant(); - - return xdndMimeConvertToFormat(m_clipboard->screen()->display(),fmtatom, m_clipboard->getDataInFormat(modeAtom,fmtatom), fmt, requestedType, encoding); -} - - -QString QTestLiteMime::xdndMimeAtomToString(Display *display, Atom a) +QString QTestLiteMime::mimeAtomToString(Display *display, Atom a) { if (!a) return 0; @@ -108,18 +31,18 @@ QString QTestLiteMime::xdndMimeAtomToString(Display *display, Atom a) return result; } -Atom QTestLiteMime::xdndMimeStringToAtom(Display *display, const QString &mimeType) +Atom QTestLiteMime::mimeStringToAtom(Display *display, const QString &mimeType) { if (mimeType.isEmpty()) return 0; return XInternAtom(display, mimeType.toLatin1().constData(), False); } -QStringList QTestLiteMime::xdndMimeFormatsForAtom(Display *display, Atom a) +QStringList QTestLiteMime::mimeFormatsForAtom(Display *display, Atom a) { QStringList formats; if (a) { - QString atomName = xdndMimeAtomToString(display, a); + QString atomName = mimeAtomToString(display, a); formats.append(atomName); // special cases for string type @@ -140,12 +63,12 @@ QStringList QTestLiteMime::xdndMimeFormatsForAtom(Display *display, Atom a) return formats; } -bool QTestLiteMime::xdndMimeDataForAtom(Display *display, Atom a, QMimeData *mimeData, QByteArray *data, Atom *atomFormat, int *dataFormat) +bool QTestLiteMime::mimeDataForAtom(Display *display, Atom a, QMimeData *mimeData, QByteArray *data, Atom *atomFormat, int *dataFormat) { bool ret = false; *atomFormat = a; *dataFormat = 8; - QString atomName = xdndMimeAtomToString(display, a); + QString atomName = mimeAtomToString(display, a); if (QInternalMimeData::hasFormatHelper(atomName, mimeData)) { *data = QInternalMimeData::renderDataHelper(atomName, mimeData); if (atomName == QLatin1String("application/x-color")) @@ -195,30 +118,16 @@ bool QTestLiteMime::xdndMimeDataForAtom(Display *display, Atom a, QMimeData *mim *data = QByteArray(reinterpret_cast<const char *>(mozUri.utf16()), mozUri.length() * 2); ret = true; } else if ((a == XA_PIXMAP || a == XA_BITMAP) && mimeData->hasImage()) { - QPixmap pm = qvariant_cast<QPixmap>(mimeData->imageData()); - if (a == XA_BITMAP && pm.depth() != 1) { - QImage img = pm.toImage(); - img = img.convertToFormat(QImage::Format_MonoLSB); - pm = QPixmap::fromImage(img); - } -// QDragManager *dm = QDragManager::self(); -// if (dm) { -// Pixmap handle = pm.handle(); -// *data = QByteArray((const char *) &handle, sizeof(Pixmap)); -// dm->xdndMimeTransferedPixmap[dm->xdndMimeTransferedPixmapIndex] = pm; -// dm->xdndMimeTransferedPixmapIndex = -// (dm->xdndMimeTransferedPixmapIndex + 1) % 2; -// ret = true; -// } + ret = true; } } return ret && data != 0; } -QList<Atom> QTestLiteMime::xdndMimeAtomsForFormat(Display *display, const QString &format) +QList<Atom> QTestLiteMime::mimeAtomsForFormat(Display *display, const QString &format) { QList<Atom> atoms; - atoms.append(xdndMimeStringToAtom(display, format)); + atoms.append(mimeStringToAtom(display, format)); // special cases for strings if (format == QLatin1String("text/plain")) { @@ -230,7 +139,7 @@ QList<Atom> QTestLiteMime::xdndMimeAtomsForFormat(Display *display, const QStrin // special cases for uris if (format == QLatin1String("text/uri-list")) { - atoms.append(xdndMimeStringToAtom(display,QLatin1String("text/x-moz-url"))); + atoms.append(mimeStringToAtom(display,QLatin1String("text/x-moz-url"))); } //special cases for images @@ -242,9 +151,9 @@ QList<Atom> QTestLiteMime::xdndMimeAtomsForFormat(Display *display, const QStrin return atoms; } -QVariant QTestLiteMime::xdndMimeConvertToFormat(Display *display, Atom a, const QByteArray &data, const QString &format, QVariant::Type requestedType, const QByteArray &encoding) +QVariant QTestLiteMime::mimeConvertToFormat(Display *display, Atom a, const QByteArray &data, const QString &format, QVariant::Type requestedType, const QByteArray &encoding) { - QString atomName = xdndMimeAtomToString(display,a); + QString atomName = mimeAtomToString(display,a); if (atomName == format) return data; @@ -288,25 +197,35 @@ QVariant QTestLiteMime::xdndMimeConvertToFormat(Display *display, Atom a, const // special cas for images if (format == QLatin1String("image/ppm")) { if (a == XA_PIXMAP && data.size() == sizeof(Pixmap)) { -// Pixmap xpm = *((Pixmap*)data.data()); -// if (!xpm) -// return QByteArray(); -// QPixmap qpm = QPixmap::fromX11Pixmap(xpm); -// QImageWriter imageWriter; -// imageWriter.setFormat("PPMRAW"); -// QImage imageToWrite = qpm.toImage(); -// QBuffer buf; -// buf.open(QIODevice::WriteOnly); -// imageWriter.setDevice(&buf); -// imageWriter.write(imageToWrite); -// return buf.buffer(); - return QVariant(); + Pixmap xpm = *((Pixmap*)data.data()); + if (!xpm) + return QByteArray(); + Window root; + int x; + int y; + uint width; + uint height; + uint border_width; + uint depth; + + XGetGeometry(display, xpm, &root, &x, &y, &width, &height, &border_width, &depth); + XImage *ximg = XGetImage(display,xpm,x,y,width,height,AllPlanes,depth==1 ? XYPixmap : ZPixmap); + QImage qimg = QTestLiteStatic::qimageFromXImage(ximg); + XDestroyImage(ximg); + + QImageWriter imageWriter; + imageWriter.setFormat("PPMRAW"); + QBuffer buf; + buf.open(QIODevice::WriteOnly); + imageWriter.setDevice(&buf); + imageWriter.write(qimg); + return buf.buffer(); } } return QVariant(); } -Atom QTestLiteMime::xdndMimeAtomForFormat(Display *display, const QString &format, QVariant::Type requestedType, const QList<Atom> &atoms, QByteArray *requestedEncoding) +Atom QTestLiteMime::mimeAtomForFormat(Display *display, const QString &format, QVariant::Type requestedType, const QList<Atom> &atoms, QByteArray *requestedEncoding) { requestedEncoding->clear(); @@ -324,10 +243,10 @@ Atom QTestLiteMime::xdndMimeAtomForFormat(Display *display, const QString &forma // find matches for uri types if (format == QLatin1String("text/uri-list")) { - Atom a = xdndMimeStringToAtom(display,format); + Atom a = mimeStringToAtom(display,format); if (a && atoms.contains(a)) return a; - a = xdndMimeStringToAtom(display,QLatin1String("text/x-moz-url")); + a = mimeStringToAtom(display,QLatin1String("text/x-moz-url")); if (a && atoms.contains(a)) return a; } @@ -347,14 +266,14 @@ Atom QTestLiteMime::xdndMimeAtomForFormat(Display *display, const QString &forma QString formatWithCharset = format; formatWithCharset.append(QLatin1String(";charset=utf-8")); - Atom a = xdndMimeStringToAtom(display,formatWithCharset); + Atom a = mimeStringToAtom(display,formatWithCharset); if (a && atoms.contains(a)) { *requestedEncoding = "utf-8"; return a; } } - Atom a = xdndMimeStringToAtom(display,format); + Atom a = mimeStringToAtom(display,format); if (a && atoms.contains(a)) return a; diff --git a/src/plugins/platforms/testlite/qtestlitemime.h b/src/plugins/platforms/testlite/qtestlitemime.h index e5ed7b0..449bbf3 100644 --- a/src/plugins/platforms/testlite/qtestlitemime.h +++ b/src/plugins/platforms/testlite/qtestlitemime.h @@ -11,32 +11,16 @@ class QTestLiteMime : public QInternalMimeData { Q_OBJECT public: - QTestLiteMime(QClipboard::Mode mode, QTestLiteClipboard *clipboard); + QTestLiteMime(); ~QTestLiteMime(); - bool empty() const; - static QList<Atom> xdndMimeAtomsForFormat(Display *display, const QString &format); - static QString xdndMimeAtomToString(Display *display, Atom a); - static bool xdndMimeDataForAtom(Display *display, Atom a, QMimeData *mimeData, QByteArray *data, Atom *atomFormat, int *dataFormat); - static QStringList xdndMimeFormatsForAtom(Display *display, Atom a); - static Atom xdndMimeStringToAtom(Display *display, const QString &mimeType); - - static QVariant xdndMimeConvertToFormat(Display *display, Atom a, const QByteArray &data, const QString &format, QVariant::Type requestedType, const QByteArray &encoding); - static Atom xdndMimeAtomForFormat(Display *display, const QString &format, QVariant::Type requestedType, const QList<Atom> &atoms, QByteArray *requestedEncoding); - - -protected: - virtual bool hasFormat_sys(const QString &mimetype) const; - virtual QStringList formats_sys() const; - - QVariant retrieveData_sys(const QString &mimetype, QVariant::Type type) const; - - -private: - QTestLiteClipboard *m_clipboard; - Atom modeAtom; - mutable QStringList formatList; - mutable QByteArray format_atoms; + static QList<Atom> mimeAtomsForFormat(Display *display, const QString &format); + static QString mimeAtomToString(Display *display, Atom a); + static bool mimeDataForAtom(Display *display, Atom a, QMimeData *mimeData, QByteArray *data, Atom *atomFormat, int *dataFormat); + static QStringList mimeFormatsForAtom(Display *display, Atom a); + static Atom mimeStringToAtom(Display *display, const QString &mimeType); + static QVariant mimeConvertToFormat(Display *display, Atom a, const QByteArray &data, const QString &format, QVariant::Type requestedType, const QByteArray &encoding); + static Atom mimeAtomForFormat(Display *display, const QString &format, QVariant::Type requestedType, const QList<Atom> &atoms, QByteArray *requestedEncoding); }; #endif // QTESTLITEMIME_H |