[KLF Application][KLF Tools][KLF Backend][KLF Home]
KLatexFormula Project
klfmime.h
Go to the documentation of this file.
1 /***************************************************************************
2  * file klfmime.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: klfmime.h 603 2011-02-26 23:14:55Z phfaist $ */
23 
24 #ifndef KLFMIME_H
25 #define KLFMIME_H
26 
27 #include <QString>
28 #include <QList>
29 #include <QStringList>
30 #include <QByteArray>
31 #include <QMap>
32 #include <QImage>
33 #include <QImageWriter>
34 #include <QMimeData>
35 #include <QTemporaryFile>
36 
37 #include <klfdefs.h>
38 #include <klfbackend.h>
39 
40 
55 class KLF_EXPORT KLFMimeExporter
56 {
57 public:
59  virtual ~KLFMimeExporter() { }
60 
61  virtual QString exporterName() const = 0;
62 
63  virtual QStringList keys() const = 0;
64  virtual QByteArray data(const QString& key, const KLFBackend::klfOutput& klfoutput) = 0;
65 
66  /* \brief the MS Windows Format Name for the given mime-type \c key.
67  *
68  * The default implementation just returns \c key. You should reimplement
69  * this function to return a useful standard name.
70  */
71  virtual QString windowsFormatName(const QString& key) const { return key; }
72 
76  virtual bool supportsKey(const QString& key) const;
77 
80  static KLFMimeExporter * mimeExporterLookup(const QString& key);
81 
86  static KLFMimeExporter * mimeExporterLookupByName(const QString& exporter, const QString& key = QString());
87 
88  static QList<KLFMimeExporter *> mimeExporterList();
93  static void registerMimeExporter(KLFMimeExporter *exporter, bool overrides = true);
94  static void unregisterMimeExporter(KLFMimeExporter *exporter);
95 
96 private:
97  static void initMimeExporterList();
98  static QList<KLFMimeExporter*> p_mimeExporterList;
99 };
100 
103 class KLF_EXPORT KLFMimeExportProfile
104 {
105 public:
106  struct ExportType {
107  ExportType(const QString& mime = QString(), const QString& win = QString(), const QString& exp = QString())
108  : mimetype(mime), wintype(win), exporter(exp) { }
112  };
113 
114  KLFMimeExportProfile(const QString& pname, const QString& desc, const QList<ExportType>& exporttypes);
116 
117 
118  QString profileName() const { return p_profileName; }
119  QString description() const { return p_description; }
120 
122  inline QList<ExportType> exportTypes() const { return p_exportTypes; }
124  inline int exportTypesCount() const { return p_exportTypes.size(); }
126  inline ExportType exportType(int n) const { return p_exportTypes[n]; }
127 
132  KLFMimeExporter * exporterLookupFor(int n, bool warnNotFound = true) const;
133 
138  QStringList mimeTypes() const;
139 
141  int indexOfMimeType(const QString& mimeType) const;
142 
147  QStringList respectiveWinTypes() const;
148 
153  QString respectiveWinType(int k) const;
154 
155 
160  QStringList availableExporterMimeTypes() const;
161 
162 
163  static QList<KLFMimeExportProfile> exportProfileList();
164  static void addExportProfile(const KLFMimeExportProfile& exportProfile);
165 
166  static KLFMimeExportProfile findExportProfile(const QString& pname);
167 
168 private:
169 
170  QString p_profileName;
171  QString p_description;
172  QList<ExportType> p_exportTypes;
173 
174  static void ensureLoadedExportProfileList();
175  static void loadFromXMLFile(const QString& fname);
176  static QList<KLFMimeExportProfile> p_exportProfileList;
177 };
178 
179 
180 
188 class KLF_EXPORT KLFMimeData : public QMimeData
189 {
190  Q_OBJECT
191 public:
192  KLFMimeData(const QString& exportProfileName, const KLFBackend::klfOutput& output);
193  virtual ~KLFMimeData();
194 
195  QStringList formats() const;
196 
197 protected:
198  QVariant retrieveData(const QString &mimetype, QVariant::Type type) const;
199 
200 private:
201  KLFMimeExportProfile pExportProfile;
202  KLFBackend::klfOutput pOutput;
203 
204  void set_possible_qt_image_data();
205 
206  mutable QStringList pQtOwnedFormats;
207 };
208 
209 
210 
211 
212 
213 #endif
QString profileName() const
Definition: klfmime.h:118
int exportTypesCount() const
Definition: klfmime.h:124
ExportType exportType(int n) const
Definition: klfmime.h:126
An export profile grouping several mime types.
Definition: klfmime.h:103
ExportType(const QString &mime=QString(), const QString &win=QString(), const QString &exp=QString())
Definition: klfmime.h:107
QString wintype
May be left empty, to indicate to use KLFMimeExporter::windowsFormatName()
Definition: klfmime.h:110
virtual QString windowsFormatName(const QString &key) const
Definition: klfmime.h:71
const char * type
A helper class to export KLF output to other applications.
Definition: klfmime.h:55
const char * key
virtual ~KLFMimeExporter()
Definition: klfmime.h:59
QString description() const
Definition: klfmime.h:119
QString exporter
May be left empty.
Definition: klfmime.h:111
QList< ExportType > exportTypes() const
Definition: klfmime.h:122

Generated by doxygen 1.8.11