-char const * lyx_mime_type = "application/x-lyx";
-char const * pdf_mime_type = "application/pdf";
-char const * emf_mime_type = "image/x-emf";
-char const * wmf_mime_type = "image/x-wmf";
+static QMimeData const * read_clipboard()
+{
+ LYXERR(Debug::ACTION, "Getting Clipboard");
+ QMimeData const * source =
+ qApp->clipboard()->mimeData(QClipboard::Clipboard);
+ if (!source) {
+ LYXERR0("0 bytes (no QMimeData)");
+ return new QMimeData();
+ }
+ // It appears that doing IO between getting a mimeData object
+ // and using it can cause a crash (maybe Qt used IO
+ // as an excuse to free() it? Anyway let's not introduce
+ // any new IO here, so e.g. leave the following line commented.
+ // lyxerr << "Got Clipboard (" << (long) source << ")\n" ;
+ return source;
+}
+
+
+void CacheMimeData::update()
+{
+ time_t const start_time = current_time();
+ LYXERR(Debug::ACTION, "Creating CacheMimeData object");
+ cached_formats_ = read_clipboard()->formats();
+
+ // Qt times out after 5 seconds if it does not recieve a response.
+ if (current_time() - start_time > 3) {
+ LYXERR0("No timely response from clipboard, perhaps process "
+ << "holding clipboard is frozen?");
+ }
+}
+
+
+QByteArray CacheMimeData::data(QString const & mimeType) const
+{
+ return read_clipboard()->data(mimeType);
+}
+
+
+QString const lyxMimeType(){ return "application/x-lyx"; }
+QString const pdfMimeType(){ return "application/pdf"; }
+QString const emfMimeType(){ return "image/x-emf"; }
+QString const wmfMimeType(){ return "image/x-wmf"; }