Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00028 #ifndef KLFLIB_P_H
00029 #define KLFLIB_P_H
00030
00031 #include <QDomDocument>
00032 #include <QDomNode>
00033 #include <QDomElement>
00034
00035 #include "klflib.h"
00036
00037
00038
00040 class KLFLibEntryMimeEncoder : public KLFAbstractLibEntryMimeEncoder
00041 {
00042 public:
00043 KLFLibEntryMimeEncoder() { }
00044 virtual ~KLFLibEntryMimeEncoder() { }
00045
00046 virtual QStringList supportedEncodingMimeTypes() const
00047 {
00048 return QStringList()
00049 << "application/x-klf-libentries"
00050 << "text/html"
00051 << "text/plain"
00052
00053 ;
00054 }
00055 virtual QStringList supportedDecodingMimeTypes() const
00056 {
00057 return QStringList() << "application/x-klf-libentries";
00058 }
00059
00060 virtual QByteArray encodeMime(const KLFLibEntryList& entryList, const QVariantMap& metaData,
00061 const QString& mimeType) const
00062 {
00063 int k;
00064 QByteArray data;
00065 if (mimeType == "application/x-klf-libentries") {
00066
00067 { QDataStream str(&data, QIODevice::WriteOnly);
00068 str.setVersion(QDataStream::Qt_4_4);
00069
00070 str << QString("KLF_LIBENTRIES") << metaData << entryList;
00071 }
00072
00073 return data;
00074 }
00075
00076
00077
00078 if (mimeType == "text/html") {
00079
00080 { QTextStream htmlstr(&data, QIODevice::WriteOnly);
00081
00082 htmlstr
00083 << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"
00084 << "<html>\n"
00085 << " <head>\n"
00086 << " <title>KLatexFormula Library Entry List</title>\n"
00087
00088
00089
00090
00091
00092
00093
00094 << " </head>\n"
00095 << "\n"
00096 << " <body>\n"
00097 << "\n";
00098 KLFLibEntry de;
00099 QList<int> entryprops = de.registeredPropertyIdList();
00100 for (k = 0; k < entryList.size(); ++k) {
00101 htmlstr << entryList[k].toString(KLFLibEntry::ToStringUseHtml);
00102 }
00103
00104 htmlstr << "\n"
00105 << " </body>\n"
00106 << "</html>\n";
00107 }
00108 return data;
00109 }
00110 if (mimeType == "text/plain") {
00111
00112 { QTextStream textstr(&data, QIODevice::WriteOnly);
00113
00114 textstr << " *** KLFLibEntryList ***\n\n";
00115
00116 KLFLibEntry de;
00117 QList<int> entryprops = de.registeredPropertyIdList();
00118 for (k = 0; k < entryList.size(); ++k) {
00119 textstr << entryList[k].toString();
00120 }
00121 }
00122 return data;
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 qWarning()<<KLF_FUNC_NAME<<": unsupported mime type requested: "<<mimeType;
00136 return QByteArray();
00137 }
00138
00139 virtual bool decodeMime(const QByteArray& data, const QString& mimeType,
00140 KLFLibEntryList *entryList, QVariantMap *metaData) const
00141 {
00142 if (mimeType == "application/x-klf-libentries") {
00143 QDataStream str(data);
00144 str.setVersion(QDataStream::Qt_4_4);
00145 QString header;
00146 str >> header;
00147 if (header != QLatin1String("KLF_LIBENTRIES")) {
00148 qWarning()<<KLF_FUNC_NAME<<": data has invalid header: "<<header;
00149 return false;
00150 }
00151 str >> *metaData >> *entryList;
00152 return true;
00153 }
00154 qWarning()<<KLF_FUNC_NAME<<": Unsupported mime type: "<<mimeType;
00155 return false;
00156 }
00157
00158 };
00159
00160
00161
00162
00163
00208 #endif