#include "FileDialog.h"
-#include "frontends/alert.h"
+#include "GuiClipboard.h"
+#include "qt_helpers.h"
#include "Buffer.h"
#include "BufferView.h"
#include "Cursor.h"
-#include "GuiClipboard.h"
-#include "qt_helpers.h"
+#include "support/lassert.h"
#include "support/convert.h"
#include "support/debug.h"
#include "support/filetools.h"
-#include "support/FileFilterList.h"
#include "support/gettext.h"
#include "support/lstrings.h"
+#ifdef Q_WS_MACX
+#include "support/linkback/LinkBackProxy.h"
+#endif // Q_WS_MACX
+
+#include "frontends/alert.h"
+
#include <QApplication>
#include <QBuffer>
#include <QClipboard>
#include <QDataStream>
#include <QFile>
#include <QImage>
-#include <QMacPasteboardMime>
#include <QMimeData>
#include <QString>
#include <QStringList>
-#include "boost/assert.hpp"
-
+#include <memory>
#include <map>
-#ifdef Q_WS_MACX
-#include "support/linkback/LinkBackProxy.h"
-#endif // Q_WS_MACX
-
using namespace std;
using namespace lyx::support;
-static char const * const lyx_mime_type = "application/x-lyx";
-static char const * const pdf_mime_type = "application/pdf";
namespace lyx {
namespace frontend {
-#ifdef Q_WS_MACX
-
-class QMacPasteboardMimeGraphics : public QMacPasteboardMime {
-public:
- QMacPasteboardMimeGraphics()
- : QMacPasteboardMime(MIME_QT_CONVERTOR|MIME_ALL) {}
- ~QMacPasteboardMimeGraphics() {}
- QString convertorName();
- QString flavorFor(const QString &mime);
- QString mimeFor(QString flav);
- bool canConvert(const QString &mime, QString flav);
- QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav);
- QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav);
-};
-
-
-QString QMacPasteboardMimeGraphics::convertorName()
-{
- return "Graphics";
-}
-
-
-QString QMacPasteboardMimeGraphics::flavorFor(const QString &mime)
-{
- LYXERR(Debug::ACTION, "flavorFor " << fromqstr(mime));
- if (mime == QLatin1String(pdf_mime_type))
- return QLatin1String("com.adobe.pdf");
- return QString();
-}
-
-
-QString QMacPasteboardMimeGraphics::mimeFor(QString flav)
-{
- LYXERR(Debug::ACTION, "mimeFor " << fromqstr(flav));
- if (flav == QLatin1String("com.adobe.pdf"))
- return QLatin1String(pdf_mime_type);
- return QString();
-}
-
-
-bool QMacPasteboardMimeGraphics::canConvert(const QString &mime, QString flav)
-{
- return mimeFor(flav) == mime;
-}
-
-
-QVariant QMacPasteboardMimeGraphics::convertToMime(const QString &mime, QList<QByteArray> data, QString)
-{
- if(data.count() > 1)
- qWarning("QMacPasteboardMimeGraphics: Cannot handle multiple member data");
- return data.first();
-}
-
-
-QList<QByteArray> QMacPasteboardMimeGraphics::convertFromMime(const QString &mime, QVariant data, QString)
-{
- QList<QByteArray> ret;
- ret.append(data.toByteArray());
- return ret;
-}
-
-static QMacPasteboardMimeGraphics * graphicsPasteboardMime;
-#endif // Q_WS_MACX
+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"; }
GuiClipboard::GuiClipboard()
this, SLOT(on_dataChanged()));
// initialize clipboard status.
on_dataChanged();
-
-#ifdef Q_WS_MACX
- if (!graphicsPasteboardMime)
- graphicsPasteboardMime = new QMacPasteboardMimeGraphics();
-#endif // Q_WS_MACX
-}
-
-
-GuiClipboard::~GuiClipboard()
-{
-#ifdef Q_WS_MACX
- closeAllLinkBackLinks();
-#endif // Q_WS_MACX
}
return string();
}
- if (source->hasFormat(lyx_mime_type)) {
+ if (source->hasFormat(lyxMimeType())) {
// data from ourself or some other LyX instance
- QByteArray const ar = source->data(lyx_mime_type);
+ QByteArray const ar = source->data(lyxMimeType());
string const s(ar.data(), ar.count());
LYXERR(Debug::ACTION, s << "'");
return s;
{
// create file dialog filter according to the existing types in the clipboard
vector<Clipboard::GraphicsType> types;
+ if (hasGraphicsContents(Clipboard::EmfGraphicsType))
+ types.push_back(Clipboard::EmfGraphicsType);
+ if (hasGraphicsContents(Clipboard::WmfGraphicsType))
+ types.push_back(Clipboard::WmfGraphicsType);
if (hasGraphicsContents(Clipboard::LinkBackGraphicsType))
types.push_back(Clipboard::LinkBackGraphicsType);
if (hasGraphicsContents(Clipboard::PdfGraphicsType))
if (hasGraphicsContents(Clipboard::JpegGraphicsType))
types.push_back(Clipboard::JpegGraphicsType);
- BOOST_ASSERT(!types.empty());
+ LASSERT(!types.empty(), /**/);
// select prefered type if AnyGraphicsType was passed
if (type == Clipboard::AnyGraphicsType)
map<Clipboard::GraphicsType, string> extensions;
map<Clipboard::GraphicsType, docstring> typeNames;
+ extensions[Clipboard::EmfGraphicsType] = "emf";
+ extensions[Clipboard::WmfGraphicsType] = "wmf";
extensions[Clipboard::LinkBackGraphicsType] = "linkback";
extensions[Clipboard::PdfGraphicsType] = "pdf";
extensions[Clipboard::PngGraphicsType] = "png";
extensions[Clipboard::JpegGraphicsType] = "jpeg";
+ typeNames[Clipboard::EmfGraphicsType] = _("Enhanced Metafile");
+ typeNames[Clipboard::WmfGraphicsType] = _("Windows Metafile");
typeNames[Clipboard::LinkBackGraphicsType] = _("LinkBack PDF");
typeNames[Clipboard::PdfGraphicsType] = _("PDF");
typeNames[Clipboard::PngGraphicsType] = _("PNG");
typeNames[Clipboard::JpegGraphicsType] = _("JPEG");
// find unused filename with primary extension
- string document_path = cur.buffer().fileName().onlyPath().absFilename();
+ string document_path = cur.buffer()->fileName().onlyPath().absFilename();
unsigned newfile_number = 0;
FileName filename;
do {
++newfile_number;
- filename
- = FileName(addName(document_path,
+ filename = FileName(addName(document_path,
to_utf8(_("pasted"))
+ convert<string>(newfile_number) + "."
+ extensions[type]));
while (true) {
// create file type filter, putting the prefered on to the front
- docstring filterSpec;
- for (unsigned i = 0; i < types.size(); ++i) {
+ QStringList filter;
+ for (size_t i = 0; i != types.size(); ++i) {
docstring s = bformat(_("%1$s Files"), typeNames[types[i]])
- + " (*." + from_ascii(extensions[types[i]]) + ")";
+ + " (*." + from_ascii(extensions[types[i]]) + ")";
if (types[i] == type)
- filterSpec = s + filterSpec;
+ filter.prepend(toqstr(s));
else
- filterSpec += ";;" + s;
+ filter.append(toqstr(s));
}
- FileFilterList const filter(filterSpec);
+ filter = fileFilters(filter.join(";;"));
// show save dialog for the graphic
- FileDialog dlg(_("Choose a filename to save the pasted graphic as"));
+ FileDialog dlg(qt_("Choose a filename to save the pasted graphic as"));
FileDialog::Result result =
- dlg.save(from_utf8(filename.onlyPath().absFilename()), filter,
- from_utf8(filename.onlyFileName()));
+ dlg.save(toqstr(filename.onlyPath().absFilename()), filter,
+ toqstr(filename.onlyFileName()));
if (result.first == FileDialog::Later)
return FileName();
- string newFilename = to_utf8(result.second);
+ string newFilename = fromqstr(result.second);
if (newFilename.empty()) {
cur.bv().message(_("Canceled."));
return FileName();
if (!suffixIs(ascii_lowercase(filename.absFilename()),
"." + extensions[type])) {
// the user changed the extension. Check if the type is available
- unsigned i;
- for (i = 1; i < types.size(); ++i) {
+ size_t i;
+ for (i = 1; i != types.size(); ++i) {
if (suffixIs(ascii_lowercase(filename.absFilename()),
"." + extensions[types[i]])) {
type = types[i];
break;
int ret = frontend::Alert::prompt(
_("Overwrite external file?"),
- bformat(_("File %1$s already exists, do you want to overwrite it"),
+ bformat(_("File %1$s already exists, do you want to overwrite it?"),
from_utf8(filename.absFilename())), 1, 1, _("&Overwrite"), _("&Cancel"));
if (ret == 0)
// overwrite, hence break the dialog loop
else if (type == JpegGraphicsType)
image.save(toqstr(filename.absFilename()), "JPEG");
else
- BOOST_ASSERT(false);
+ LASSERT(false, /**/);
return filename;
}
// get mime for type
QString mime;
switch (type) {
- case PdfGraphicsType: mime = pdf_mime_type; break;
- case LinkBackGraphicsType: mime = pdf_mime_type; break;
- default: BOOST_ASSERT(false);
+ case PdfGraphicsType: mime = pdfMimeType(); break;
+ case LinkBackGraphicsType: mime = pdfMimeType(); break;
+ case EmfGraphicsType: mime = emfMimeType(); break;
+ case WmfGraphicsType: mime = wmfMimeType(); break;
+ default: LASSERT(false, /**/);
}
// get data
ds << pdfLen; // big endian by default
#else
// only non-Mac this should never happen
- BOOST_ASSERT(false);
+ LASSERT(false, /**/);
#endif // Q_WS_MACX
}
// text data from other applications
QString const str = qApp->clipboard()->text(QClipboard::Clipboard)
.normalized(QString::NormalizationForm_C);
- LYXERR(Debug::ACTION, "GuiClipboard::getAsText(): `" << fromqstr(str) << "'");
+ LYXERR(Debug::ACTION, "GuiClipboard::getAsText(): `" << str << "'");
if (str.isNull())
return docstring();
- return internalLineEnding(qstring_to_ucs4(str));
+ return internalLineEnding(str);
}
QMimeData * data = new QMimeData;
if (!lyx.empty()) {
QByteArray const qlyx(lyx.c_str(), lyx.size());
- data->setData(lyx_mime_type, qlyx);
+ data->setData(lyxMimeType(), qlyx);
}
// Don't test for text.empty() since we want to be able to clear the
// clipboard.
{
QMimeData const * const source =
qApp->clipboard()->mimeData(QClipboard::Clipboard);
- return source && source->hasFormat(lyx_mime_type);
+ return source && source->hasFormat(lyxMimeType());
+}
+
+
+bool GuiClipboard::hasTextContents() const
+{
+ QMimeData const * const source =
+ qApp->clipboard()->mimeData(QClipboard::Clipboard);
+ return source && source->hasText();
}
return hasGraphicsContents(PdfGraphicsType)
|| hasGraphicsContents(PngGraphicsType)
|| hasGraphicsContents(JpegGraphicsType)
+ || hasGraphicsContents(EmfGraphicsType)
+ || hasGraphicsContents(WmfGraphicsType)
|| hasGraphicsContents(LinkBackGraphicsType);
}
QMimeData const * const source =
qApp->clipboard()->mimeData(QClipboard::Clipboard);
-
+
// handle image cases first
if (type == PngGraphicsType || type == JpegGraphicsType)
return source->hasImage();
// handle LinkBack for Mac
-#ifdef Q_WS_MACX
if (type == LinkBackGraphicsType)
+#ifdef Q_WS_MACX
return isLinkBackDataInPasteboard();
#else
- if (type == LinkBackGraphicsType)
return false;
#endif // Q_WS_MACX
// get mime data
QStringList const & formats = source->formats();
LYXERR(Debug::ACTION, "We found " << formats.size() << " formats");
- for (int i = 0; i < formats.size(); ++i) {
- LYXERR(Debug::ACTION, "Found format " << fromqstr(formats[i]));
- }
+ for (int i = 0; i < formats.size(); ++i)
+ LYXERR(Debug::ACTION, "Found format " << formats[i]);
// compute mime for type
QString mime;
switch (type) {
- case PdfGraphicsType: mime = pdf_mime_type; break;
- default: BOOST_ASSERT(false);
+ case EmfGraphicsType: mime = emfMimeType(); break;
+ case WmfGraphicsType: mime = wmfMimeType(); break;
+ case PdfGraphicsType: mime = pdfMimeType(); break;
+ default: LASSERT(false, /**/);
}
return source && source->hasFormat(mime);
qApp->clipboard()->mimeData(QClipboard::Clipboard);
QStringList l = source->formats();
LYXERR(Debug::ACTION, "Qt Clipboard changed. We found the following mime types:");
- for (int i = 0; i < l.count(); i++) {
- LYXERR(Debug::ACTION, fromqstr(l.value(i)));
- }
+ for (int i = 0; i < l.count(); i++)
+ LYXERR(Debug::ACTION, l.value(i));
text_clipboard_empty_ = qApp->clipboard()->
text(QClipboard::Clipboard).isEmpty();
} // namespace frontend
} // namespace lyx
-#include "GuiClipboard_moc.cpp"
+#include "moc_GuiClipboard.cpp"