[KLF Application][KLF Tools][KLF Backend][KLF Home]
KLatexFormula Project

src/klflib_p.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   file klflib_p.h
00003  *   This file is part of the KLatexFormula Project.
00004  *   Copyright (C) 2010 by Philippe Faist
00005  *   philippe.faist at bluewin.ch
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 /* $Id: klflib_p.h 455 2010-08-22 01:42:51Z philippe $ */
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() /*<< "application/x-klf-library-entries"*/
00049                          << "application/x-klf-libentries"
00050                          << "text/html"
00051                          << "text/plain"
00052       //<< "image/png"
00053       ;
00054   }
00055   virtual QStringList supportedDecodingMimeTypes() const
00056   {
00057     return QStringList()/* << "application/x-klf-library-entries"*/ << "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       // prepare the data through the stream in a separate block
00067       { QDataStream str(&data, QIODevice::WriteOnly);
00068         str.setVersion(QDataStream::Qt_4_4);
00069         // now dump the list in the bytearray
00070         str << QString("KLF_LIBENTRIES") << metaData << entryList;
00071       }
00072       // now the data is prepared, return it
00073       return data;
00074     }
00075     /*    if (mimeType == "application/x-klf-library-entries") {
00076           return QByteArray();
00077           } */
00078     if (mimeType == "text/html") {
00079       // prepare the data through the stream in a separate block
00080       { QTextStream htmlstr(&data, QIODevice::WriteOnly);
00081         // a header for HTML
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           //        << "    <style>\n"
00088           //        << "      div.klfpobj_entry { margin-bottom: 15px; }\n"
00089           //        << "      div.klfpobj_name { font-weight: bold; }\n"
00090           //        << "      div.klfpobj_propname { display: inline; }\n"
00091           //        << "      div.klfpobj_propvalue { display: inline; font-style: italic;\n"
00092           //        << "        padding-left: 10px; }\n"
00093           //        << "    </style>\n"
00094           << "  </head>\n"
00095           << "\n"
00096           << "  <body>\n"
00097           << "\n";
00098         KLFLibEntry de; // dummy entry for property querying
00099         QList<int> entryprops = de.registeredPropertyIdList();
00100         for (k = 0; k < entryList.size(); ++k) {
00101           htmlstr << entryList[k].toString(KLFLibEntry::ToStringUseHtml);
00102         }
00103         // HTML footer
00104         htmlstr << "\n"
00105                 << "  </body>\n"
00106                 << "</html>\n";
00107       }
00108       return data;
00109     }
00110     if (mimeType == "text/plain") {
00111       // prepare the data through the stream in a separate block
00112       { QTextStream textstr(&data, QIODevice::WriteOnly);
00113         // a header for text
00114         textstr << " *** KLFLibEntryList ***\n\n";
00115         // now dump the data in the appropriate streams
00116         KLFLibEntry de; // dummy entry for property querying
00117         QList<int> entryprops = de.registeredPropertyIdList();
00118         for (k = 0; k < entryList.size(); ++k) {
00119           textstr << entryList[k].toString(/*KLFLibEntry::ToStringQuoteValues*/);
00120         }
00121       }
00122       return data;
00123     }
00124     //     if (mimeType == "image/png") {
00125     //       if (entryList.size() != 1) {
00126     //  klfDbg("Can only encode image/png for an entry list of size ONE (!)");
00127     //  return QByteArray();
00128     //       }
00129     //       { // format data: write the PNG data for the preview
00130     //  QBuffer buf(&data);
00131     //  entryList[0].preview().save(&buf, "PNG");
00132     //       }
00133     //       return data;
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

Generated by doxygen 1.7.3