cleanup export of mime type strings

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24930 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Peter Kümmel 2008-05-25 07:49:16 +00:00
parent 4d188198ba
commit dcd8650998
3 changed files with 27 additions and 26 deletions

View File

@ -186,7 +186,7 @@ public:
QString flavorFor(QString const & mime) QString flavorFor(QString const & mime)
{ {
LYXERR(Debug::ACTION, "flavorFor " << mime); LYXERR(Debug::ACTION, "flavorFor " << mime);
if (mime == QLatin1String(pdf_mime_type)) if (mime == QLatin1String(pdfMimeType()))
return QLatin1String("com.adobe.pdf"); return QLatin1String("com.adobe.pdf");
return QString(); return QString();
} }
@ -195,7 +195,7 @@ public:
{ {
LYXERR(Debug::ACTION, "mimeFor " << flav); LYXERR(Debug::ACTION, "mimeFor " << flav);
if (flav == QLatin1String("com.adobe.pdf")) if (flav == QLatin1String("com.adobe.pdf"))
return QLatin1String(pdf_mime_type); return QLatin1String(pdfMimeType());
return QString(); return QString();
} }
@ -232,10 +232,10 @@ public:
static FORMATETC cfFromMime(QString const & mimetype) static FORMATETC cfFromMime(QString const & mimetype)
{ {
FORMATETC formatetc; FORMATETC formatetc;
if (mimetype == emf_mime_type) { if (mimetype == emfMimeType()) {
formatetc.cfFormat = CF_ENHMETAFILE; formatetc.cfFormat = CF_ENHMETAFILE;
formatetc.tymed = TYMED_ENHMF; formatetc.tymed = TYMED_ENHMF;
} else if (mimetype == wmf_mime_type) { } else if (mimetype == wmfMimeType()) {
formatetc.cfFormat = CF_METAFILEPICT; formatetc.cfFormat = CF_METAFILEPICT;
formatetc.tymed = TYMED_MFPICT; formatetc.tymed = TYMED_MFPICT;
} }
@ -259,7 +259,7 @@ public:
bool canConvertToMime(QString const & mimetype, bool canConvertToMime(QString const & mimetype,
IDataObject * pDataObj) const IDataObject * pDataObj) const
{ {
if (mimetype != emf_mime_type && mimetype != wmf_mime_type) if (mimetype != emfMimeType() && mimetype != wmfMimeType())
return false; return false;
FORMATETC formatetc = cfFromMime(mimetype); FORMATETC formatetc = cfFromMime(mimetype);
return pDataObj->QueryGetData(&formatetc) == S_OK; return pDataObj->QueryGetData(&formatetc) == S_OK;
@ -314,9 +314,9 @@ public:
{ {
switch (formatetc.cfFormat) { switch (formatetc.cfFormat) {
case CF_ENHMETAFILE: case CF_ENHMETAFILE:
return emf_mime_type; return emfMimeType();
case CF_METAFILEPICT: case CF_METAFILEPICT:
return wmf_mime_type; return wmfMimeType();
} }
return QString(); return QString();
} }

View File

@ -55,10 +55,11 @@ namespace lyx {
namespace frontend { namespace frontend {
char const * lyx_mime_type = "application/x-lyx";
char const * pdf_mime_type = "application/pdf"; QString const lyxMimeType(){ return "application/x-lyx"; }
char const * emf_mime_type = "image/x-emf"; QString const pdfMimeType(){ return "application/pdf"; }
char const * wmf_mime_type = "image/x-wmf"; QString const emfMimeType(){ return "image/x-emf"; }
QString const wmfMimeType(){ return "image/x-wmf"; }
GuiClipboard::GuiClipboard() GuiClipboard::GuiClipboard()
@ -82,9 +83,9 @@ string const GuiClipboard::getAsLyX() const
return string(); return string();
} }
if (source->hasFormat(lyx_mime_type)) { if (source->hasFormat(lyxMimeType())) {
// data from ourself or some other LyX instance // 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()); string const s(ar.data(), ar.count());
LYXERR(Debug::ACTION, s << "'"); LYXERR(Debug::ACTION, s << "'");
return s; return s;
@ -257,10 +258,10 @@ FileName GuiClipboard::getAsGraphics(Cursor const & cur, GraphicsType type) cons
// get mime for type // get mime for type
QString mime; QString mime;
switch (type) { switch (type) {
case PdfGraphicsType: mime = pdf_mime_type; break; case PdfGraphicsType: mime = pdfMimeType(); break;
case LinkBackGraphicsType: mime = pdf_mime_type; break; case LinkBackGraphicsType: mime = pdfMimeType(); break;
case EmfGraphicsType: mime = emf_mime_type; break; case EmfGraphicsType: mime = emfMimeType(); break;
case WmfGraphicsType: mime = wmf_mime_type; break; case WmfGraphicsType: mime = wmfMimeType(); break;
default: LASSERT(false, /**/); default: LASSERT(false, /**/);
} }
@ -323,7 +324,7 @@ void GuiClipboard::put(string const & lyx, docstring const & text)
QMimeData * data = new QMimeData; QMimeData * data = new QMimeData;
if (!lyx.empty()) { if (!lyx.empty()) {
QByteArray const qlyx(lyx.c_str(), lyx.size()); 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 // Don't test for text.empty() since we want to be able to clear the
// clipboard. // clipboard.
@ -337,7 +338,7 @@ bool GuiClipboard::hasLyXContents() const
{ {
QMimeData const * const source = QMimeData const * const source =
qApp->clipboard()->mimeData(QClipboard::Clipboard); qApp->clipboard()->mimeData(QClipboard::Clipboard);
return source && source->hasFormat(lyx_mime_type); return source && source->hasFormat(lyxMimeType());
} }
@ -376,9 +377,9 @@ bool GuiClipboard::hasGraphicsContents(Clipboard::GraphicsType type) const
// compute mime for type // compute mime for type
QString mime; QString mime;
switch (type) { switch (type) {
case EmfGraphicsType: mime = emf_mime_type; break; case EmfGraphicsType: mime = emfMimeType(); break;
case WmfGraphicsType: mime = wmf_mime_type; break; case WmfGraphicsType: mime = wmfMimeType(); break;
case PdfGraphicsType: mime = pdf_mime_type; break; case PdfGraphicsType: mime = pdfMimeType(); break;
default: LASSERT(false, /**/); default: LASSERT(false, /**/);
} }

View File

@ -58,10 +58,10 @@ private:
bool has_graphics_contents_; bool has_graphics_contents_;
}; };
extern char const * lyx_mime_type; QString const lyxMimeType();
extern char const * pdf_mime_type; QString const pdfMimeType();
extern char const * emf_mime_type; QString const emfMimeType();
extern char const * wmf_mime_type; QString const wmfMimeType();
} // namespace frontend } // namespace frontend
} // namespace lyx } // namespace lyx