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

src/klfliblegacyengine.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   file klfliblegacyengine.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: klfliblegacyengine.h 562 2010-11-21 19:01:41Z philippe $ */
00023 
00024 #ifndef KLFLIBLEGACYENGINE_H
00025 #define KLFLIBLEGACYENGINE_H
00026 
00027 
00028 #include <QDateTime>
00029 #include <QList>
00030 #include <QDataStream>
00031 #include <QPixmap>
00032 #include <QMap>
00033 #include <QMetaType>
00034 #include <QFile>
00035 #include <QTimer>
00036 
00037 #include <klflib.h>
00038 #include <klflibview.h> // scheme guesser
00039 
00040 
00046 class KLF_EXPORT KLFLegacyData {
00047 public:
00048 
00049   struct KLFStyle {
00050     KLFStyle(QString nm = QString(), unsigned long fgcol = qRgba(0,0,0,255),
00051              unsigned long bgcol = qRgba(255,255,255,0),
00052              const QString& mmode = QString(),
00053              const QString& pre = QString(),
00054              int dotsperinch = -1)
00055       : name(nm), fg_color(fgcol), bg_color(bgcol), mathmode(mmode), preamble(pre),
00056         dpi(dotsperinch) { }
00057     QString name; // this may not always be set, it's only important in saved style list.
00058     unsigned long fg_color;
00059     unsigned long bg_color;
00060     QString mathmode;
00061     QString preamble;
00062     int dpi;
00063   };
00064 
00065   // THESE VALUES MUST NOT CHANGE FROM ONE VERSION TO ANOTHER OF KLATEXFORMULA :
00066   enum {
00067     LibResource_History = 0,
00068     LibResource_Archive = 1,
00069     // user resources must be in the following range:
00070     LibResourceUSERMIN = 100,
00071     LibResourceUSERMAX = 99999
00072   };
00073 
00074   struct KLFLibraryResource {
00075     quint32 id;
00076     QString name;
00077   };
00078 
00079   struct KLFLibraryItem {
00080     quint32 id;
00081     static quint32 MaxId;
00082 
00083     QDateTime datetime;
00086     QString latex;
00087     QPixmap preview;
00088 
00089     QString category;
00090     QString tags;
00091 
00092     KLFLegacyData::KLFStyle style;
00093   };
00094 
00095   typedef QList<KLFLibraryItem> KLFLibraryList;
00096   typedef QList<KLFLibraryResource> KLFLibraryResourceList;
00097   typedef QMap<KLFLibraryResource, KLFLibraryList> KLFLibrary;
00098 
00099 private:
00100 
00101   KLFLegacyData();
00102 };
00103 
00104 KLF_EXPORT QDataStream& operator<<(QDataStream& stream, const KLFLegacyData::KLFStyle& style);
00105 KLF_EXPORT QDataStream& operator>>(QDataStream& stream, KLFLegacyData::KLFStyle& style);
00106 KLF_EXPORT bool operator==(const KLFLegacyData::KLFStyle& a, const KLFLegacyData::KLFStyle& b);
00107 
00108 // it is important to note that the >> operator imports in a compatible way to KLF 2.0
00109 KLF_EXPORT QDataStream& operator<<(QDataStream& stream, const KLFLegacyData::KLFLibraryItem& item);
00110 KLF_EXPORT QDataStream& operator>>(QDataStream& stream, KLFLegacyData::KLFLibraryItem& item);
00111 
00112 KLF_EXPORT QDataStream& operator<<(QDataStream& stream, const KLFLegacyData::KLFLibraryResource& item);
00113 KLF_EXPORT QDataStream& operator>>(QDataStream& stream, KLFLegacyData::KLFLibraryResource& item);
00114 
00115 // exact matches, style included, but excluding ID and datetime
00116 KLF_EXPORT bool operator==(const KLFLegacyData::KLFLibraryItem& a, const KLFLegacyData::KLFLibraryItem& b);
00117 
00118 // is needed for QMap : these operators compare ID only.
00119 KLF_EXPORT bool operator<(const KLFLegacyData::KLFLibraryResource a, const KLFLegacyData::KLFLibraryResource b);
00120 KLF_EXPORT bool operator==(const KLFLegacyData::KLFLibraryResource a, const KLFLegacyData::KLFLibraryResource b);
00121 // name comparision
00122 KLF_EXPORT bool resources_equal_for_import(const KLFLegacyData::KLFLibraryResource a,
00123                                            const KLFLegacyData::KLFLibraryResource b);
00124 
00125 
00126 
00127 class KLFLibLegacyFileDataPrivate;
00128 
00130 
00135 class KLF_EXPORT KLFLibLegacyEngine : public KLFLibResourceSimpleEngine
00136 {
00137   Q_OBJECT
00138 public:
00146   static KLFLibLegacyEngine * openUrl(const QUrl& url, QObject *parent = NULL);
00147 
00158   static KLFLibLegacyEngine * createDotKLF(const QString& fileName, QString legacyResourceName,
00159                                            QObject *parent = NULL);
00160 
00161   virtual ~KLFLibLegacyEngine();
00162 
00163   virtual uint compareUrlTo(const QUrl& other, uint interestFlags = 0xfffffff) const;
00164 
00165   virtual bool canModifyData(const QString& subRes, ModifyType modifytype) const;
00166   virtual bool canModifyProp(int propid) const;
00167   virtual bool canRegisterProperty(const QString& propName) const;
00168 
00169   virtual KLFLibEntry entry(const QString& resource, entryId id);
00170   virtual QList<KLFLibEntryWithId> allEntries(const QString& resource,
00171                                               const QList<int>& wantedEntryProperties = QList<int>());
00172 
00173   virtual QStringList subResourceList() const;
00174 
00175   virtual bool canCreateSubResource() const;
00176   virtual bool canRenameSubResource(const QString& subResource) const;
00177   virtual bool canDeleteSubResource(const QString& subResource) const;
00178 
00179 public slots:
00180 
00181   virtual bool createSubResource(const QString& subResource, const QString& subResourceTitle);
00182   virtual bool renameSubResource(const QString& subResource, const QString& subResourceName);
00183   virtual bool deleteSubResource(const QString& subResource);
00184 
00185   virtual bool save();
00186   virtual void setAutoSaveInterval(int intervalms);
00187 
00188   virtual QList<entryId> insertEntries(const QString& subResource, const KLFLibEntryList& entries);
00189   virtual bool changeEntries(const QString& subResource, const QList<entryId>& idlist,
00190                              const QList<int>& properties, const QList<QVariant>& values);
00191   virtual bool deleteEntries(const QString& subResource, const QList<entryId>& idlist);
00192 
00193   virtual bool saveTo(const QUrl& newPath);
00194 
00195 protected:
00196   virtual bool saveResourceProperty(int propId, const QVariant& value);
00197 
00198 protected slots:
00199   void updateResourceProperty(int propId);
00200 
00201 private:
00202   KLFLibLegacyEngine(const QString& fileName, const QString& resname, const QUrl& url, QObject *parent);
00203 
00204   KLFLibLegacyFileDataPrivate *d;
00205 };
00206 
00207 
00208 
00209 
00210 
00211 class KLF_EXPORT KLFLibLegacyLocalFileSchemeGuesser : public QObject, public KLFLibLocalFileSchemeGuesser
00212 {
00213 public:
00214   KLFLibLegacyLocalFileSchemeGuesser(QObject *parent) : QObject(parent) { }
00215 
00216   QString guessScheme(const QString& fileName) const;
00217 };
00218 
00219 
00221 class KLF_EXPORT KLFLibLegacyEngineFactory : public KLFLibEngineFactory
00222 {
00223   Q_OBJECT
00224 public:
00225   KLFLibLegacyEngineFactory(QObject *parent = NULL);
00226   virtual ~KLFLibLegacyEngineFactory() { }
00227 
00228   virtual QStringList supportedTypes() const;
00229   virtual QString schemeTitle(const QString& scheme) const ;
00230 
00231   virtual uint schemeFunctions(const QString& scheme) const;
00232 
00233   virtual QString correspondingWidgetType(const QString& scheme) const;
00234 
00236   virtual KLFLibResourceEngine *openResource(const QUrl& location, QObject *parent = NULL);
00237 
00238   virtual KLFLibResourceEngine *createResource(const QString& scheme, const Parameters& parameters,
00239                                                QObject *parent = NULL);
00240 };
00241 
00242 
00243 
00244 
00245 
00246 #endif

Generated by doxygen 1.7.3