[KLF Application][KLF Tools][KLF Backend][KLF Home]
KLatexFormula Project
klflib_p.h
Go to the documentation of this file.
1 /***************************************************************************
2  * file klflib_p.h
3  * This file is part of the KLatexFormula Project.
4  * Copyright (C) 2011 by Philippe Faist
5  * philippe.faist at bluewin.ch
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 /* $Id: klflib_p.h 603 2011-02-26 23:14:55Z phfaist $ */
23 
28 #ifndef KLFLIB_P_H
29 #define KLFLIB_P_H
30 
31 #include <QDomDocument>
32 #include <QDomNode>
33 #include <QDomElement>
34 
35 #include "klflib.h"
36 
37 
38 
41 {
42 public:
45 
47  {
48  return QStringList() /*<< "application/x-klf-library-entries"*/
49  << "application/x-klf-libentries"
50  << "text/html"
51  << "text/plain"
52  //<< "image/png"
53  ;
54  }
56  {
57  return QStringList()/* << "application/x-klf-library-entries"*/ << "application/x-klf-libentries";
58  }
59 
60  virtual QByteArray encodeMime(const KLFLibEntryList& entryList, const QVariantMap& metaData,
61  const QString& mimeType) const
62  {
63  int k;
64  QByteArray data;
65  if (mimeType == "application/x-klf-libentries") {
66  // prepare the data through the stream in a separate block
67  { QDataStream str(&data, QIODevice::WriteOnly);
68  str.setVersion(QDataStream::Qt_4_4);
69  // now dump the list in the bytearray
70  str << QString("KLF_LIBENTRIES") << metaData << entryList;
71  }
72  // now the data is prepared, return it
73  return data;
74  }
75  /* if (mimeType == "application/x-klf-library-entries") {
76  return QByteArray();
77  } */
78  if (mimeType == "text/html") {
79  // prepare the data through the stream in a separate block
80  { QTextStream htmlstr(&data, QIODevice::WriteOnly);
81  // a header for HTML
82  htmlstr
83  << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"
84  << "<html>\n"
85  << " <head>\n"
86  << " <title>KLatexFormula Library Entry List</title>\n"
87  // << " <style>\n"
88  // << " div.klfpobj_entry { margin-bottom: 15px; }\n"
89  // << " div.klfpobj_name { font-weight: bold; }\n"
90  // << " div.klfpobj_propname { display: inline; }\n"
91  // << " div.klfpobj_propvalue { display: inline; font-style: italic;\n"
92  // << " padding-left: 10px; }\n"
93  // << " </style>\n"
94  << " </head>\n"
95  << "\n"
96  << " <body>\n"
97  << "\n";
98  KLFLibEntry de; // dummy entry for property querying
99  QList<int> entryprops = de.registeredPropertyIdList();
100  for (k = 0; k < entryList.size(); ++k) {
101  htmlstr << entryList[k].toString(KLFLibEntry::ToStringUseHtml);
102  }
103  // HTML footer
104  htmlstr << "\n"
105  << " </body>\n"
106  << "</html>\n";
107  }
108  return data;
109  }
110  if (mimeType == "text/plain") {
111  // prepare the data through the stream in a separate block
112  { QTextStream textstr(&data, QIODevice::WriteOnly);
113  // a header for text
114  textstr << " *** KLFLibEntryList ***\n\n";
115  // now dump the data in the appropriate streams
116  KLFLibEntry de; // dummy entry for property querying
117  QList<int> entryprops = de.registeredPropertyIdList();
118  for (k = 0; k < entryList.size(); ++k) {
119  textstr << entryList[k].toString(/*KLFLibEntry::ToStringQuoteValues*/);
120  }
121  }
122  return data;
123  }
124  // if (mimeType == "image/png") {
125  // if (entryList.size() != 1) {
126  // klfDbg("Can only encode image/png for an entry list of size ONE (!)");
127  // return QByteArray();
128  // }
129  // { // format data: write the PNG data for the preview
130  // QBuffer buf(&data);
131  // entryList[0].preview().save(&buf, "PNG");
132  // }
133  // return data;
134  // }
135  qWarning()<<KLF_FUNC_NAME<<": unsupported mime type requested: "<<mimeType;
136  return QByteArray();
137  }
138 
139  virtual bool decodeMime(const QByteArray& data, const QString& mimeType,
140  KLFLibEntryList *entryList, QVariantMap *metaData) const
141  {
142  if (mimeType == "application/x-klf-libentries") {
143  QDataStream str(data);
144  str.setVersion(QDataStream::Qt_4_4);
145  QString header;
146  str >> header;
147  if (header != QLatin1String("KLF_LIBENTRIES")) {
148  qWarning()<<KLF_FUNC_NAME<<": data has invalid header: "<<header;
149  return false;
150  }
151  str >> *metaData >> *entryList;
152  return true;
153  }
154  qWarning()<<KLF_FUNC_NAME<<": Unsupported mime type: "<<mimeType;
155  return false;
156  }
157 
158 };
159 
160 
161 
162 
163 
208 #endif
virtual QStringList supportedEncodingMimeTypes() const
Definition: klflib_p.h:46
QList< int > registeredPropertyIdList() const
virtual QByteArray encodeMime(const KLFLibEntryList &entryList, const QVariantMap &metaData, const QString &mimeType) const
Definition: klflib_p.h:60
virtual QStringList supportedDecodingMimeTypes() const
Definition: klflib_p.h:55
setVersion(int v)
#define KLF_FUNC_NAME
virtual ~KLFLibEntryMimeEncoder()
Definition: klflib_p.h:44
An entry (single formula) in the library.
Definition: klflib.h:55
Helper class to encode an entry list as mime data (abstract interface)
Definition: klflib.h:1841
virtual bool decodeMime(const QByteArray &data, const QString &mimeType, KLFLibEntryList *entryList, QVariantMap *metaData) const
Definition: klflib_p.h:139

Generated by doxygen 1.8.11