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

src/klfmime.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   file klfmime.h
00003  *   This file is part of the KLatexFormula Project.
00004  *   Copyright (C) 2009 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: klfmime.h 541 2010-10-04 00:43:14Z philippe $ */
00023 
00024 #ifndef KLFMIME_H
00025 #define KLFMIME_H
00026 
00027 #include <QString>
00028 #include <QList>
00029 #include <QStringList>
00030 #include <QByteArray>
00031 #include <QMap>
00032 #include <QImage>
00033 #include <QImageWriter>
00034 #include <QMimeData>
00035 #include <QTemporaryFile>
00036 
00037 #include <klfdefs.h>
00038 #include <klfbackend.h>
00039 
00040 
00055 class KLF_EXPORT KLFMimeExporter
00056 {
00057 public:
00058   KLFMimeExporter() { }
00059   virtual ~KLFMimeExporter() { }
00060 
00061   virtual QString exporterName() const = 0;
00062 
00063   virtual QStringList keys() const = 0;
00064   virtual QByteArray data(const QString& key, const KLFBackend::klfOutput& klfoutput) = 0;
00065 
00066   /* \brief the MS Windows Format Name for the given mime-type \c key.
00067    *
00068    * The default implementation just returns \c key. You should reimplement
00069    * this function to return a useful standard name.
00070    */
00071   virtual QString windowsFormatName(const QString& key) const { return key; }
00072 
00076   virtual bool supportsKey(const QString& key) const;
00077 
00080   static KLFMimeExporter * mimeExporterLookup(const QString& key);
00081 
00086   static KLFMimeExporter * mimeExporterLookupByName(const QString& exporter, const QString& key = QString());
00087   
00088   static QList<KLFMimeExporter *> mimeExporterList();
00093   static void registerMimeExporter(KLFMimeExporter *exporter, bool overrides = true);
00094   static void unregisterMimeExporter(KLFMimeExporter *exporter);
00095 
00096 private:
00097   static void initMimeExporterList();
00098   static QList<KLFMimeExporter*> p_mimeExporterList;
00099 };
00100 
00103 class KLF_EXPORT KLFMimeExportProfile
00104 {
00105 public:
00106   struct ExportType {
00107     ExportType(const QString& mime = QString(), const QString& win = QString(), const QString& exp = QString())
00108       : mimetype(mime), wintype(win), exporter(exp)  { }
00109     QString mimetype;
00110     QString wintype; 
00111     QString exporter; 
00112   };
00113 
00114   KLFMimeExportProfile(const QString& pname, const QString& desc, const QList<ExportType>& exporttypes);
00115   KLFMimeExportProfile(const KLFMimeExportProfile& copy);
00116 
00117 
00118   QString profileName() const { return p_profileName; }
00119   QString description() const { return p_description; }
00120 
00122   inline QList<ExportType> exportTypes() const { return p_exportTypes; }
00124   inline int exportTypesCount() const { return p_exportTypes.size(); }
00126   inline ExportType exportType(int n) const { return p_exportTypes[n]; }
00127 
00132   KLFMimeExporter * exporterLookupFor(int n, bool warnNotFound = true) const;
00133 
00138   QStringList mimeTypes() const;
00139 
00141   int indexOfMimeType(const QString& mimeType) const;
00142 
00147   QStringList respectiveWinTypes() const;
00148 
00153   QString respectiveWinType(int k) const;
00154 
00155 
00160   QStringList availableExporterMimeTypes() const;
00161 
00162 
00163   static QList<KLFMimeExportProfile> exportProfileList();
00164   static void addExportProfile(const KLFMimeExportProfile& exportProfile);
00165 
00166   static KLFMimeExportProfile findExportProfile(const QString& pname);
00167 
00168 private:
00169 
00170   QString p_profileName;
00171   QString p_description;
00172   QList<ExportType> p_exportTypes;
00173 
00174   static void ensureLoadedExportProfileList();
00175   static void loadFromXMLFile(const QString& fname);
00176   static QList<KLFMimeExportProfile> p_exportProfileList;
00177 };
00178 
00179 
00180 
00188 class KLF_EXPORT KLFMimeData : public QMimeData
00189 {
00190   Q_OBJECT
00191 public:
00192   KLFMimeData(const QString& exportProfileName, const KLFBackend::klfOutput& output);
00193   virtual ~KLFMimeData();
00194 
00195   QStringList formats() const;
00196 
00197 protected:
00198   QVariant retrieveData(const QString &mimetype, QVariant::Type type) const;
00199 
00200 private:
00201   KLFMimeExportProfile pExportProfile;
00202   KLFBackend::klfOutput pOutput;
00203 
00204   void set_possible_qt_image_data();
00205 
00206   mutable QStringList pQtOwnedFormats;
00207 };
00208 
00209 
00210 
00211 
00212 
00213 #endif

Generated by doxygen 1.7.3