kpilot

DOC-converter.h

Go to the documentation of this file.
00001 #ifndef _DOC_CONVERTER_H
00002 #define _DOC_CONVERTER_H
00003 /* DOC-converter.h                           KPilot
00004 **
00005 ** Copyright (C) 2002-2003 by Reinhold Kainhofer
00006 **
00007 */
00008 
00009 /*
00010 ** This program is free software; you can redistribute it and/or modify
00011 ** it under the terms of the GNU General Public License as published by
00012 ** the Free Software Foundation; either version 2 of the License, or
00013 ** (at your option) any later version.
00014 **
00015 ** This program is distributed in the hope that it will be useful,
00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018 ** GNU General Public License for more details.
00019 **
00020 ** You should have received a copy of the GNU General Public License
00021 ** along with this program in a file called COPYING; if not, write to
00022 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00023 ** MA 02110-1301, USA.
00024 */
00025 
00026 /*
00027 ** Bug reports and questions can be sent to kde-pim@kde.org
00028 */
00029 
00030 
00031 
00032 #define DOC_UNCOMPRESSED 1
00033 #define DOC_COMPRESSED 2
00034 
00035 
00036 #define BMK_SUFFIX ".bmk"
00037 #define PDBBMK_SUFFIX ".bm"
00038 
00039 #include <qptrlist.h>
00040 #include <qobject.h>
00041 
00042 class PilotDatabase;
00043 
00044 
00045 /****************************************************************************************************
00046  *  various bookmark classes. Most important is the bmkList  findMatches(QString, bmkList &) function,
00047  *  which needs to return a list of all bookmarks found for the given bookmark expression.
00048  *  A bookmark usually consists of a bookmark text and an offset into the text document.
00049  ****************************************************************************************************/
00050 
00051 class docBookmark;
00052 #define bmkList QPtrList<docBookmark>
00053 #define bmkSortedList QSortedList<docBookmark>
00054 
00055 class docBookmark {
00056 public:
00057     static bool compare_pos;
00058     docBookmark():bmkName(), position(0) { };
00059     docBookmark(QString name, long int pos):bmkName(name), position(pos) { };
00060     docBookmark(const docBookmark &bmk):bmkName(bmk.bmkName),position(bmk.position){};
00061     virtual ~ docBookmark() { };
00062     virtual int findMatches(QString, bmkList &fBookmarks) {
00063         FUNCTIONSETUP;
00064         fBookmarks.append(new docBookmark(*this));
00065         return 1;
00066     };
00067 
00068     QString bmkName;
00069     long int position;
00070 };
00071 
00072 class docMatchBookmark:public docBookmark {
00073  public:
00074     docMatchBookmark():docBookmark() { from=0; to=100;};
00075     docMatchBookmark(QString pattrn, int options=0):docBookmark(),
00076         pattern(pattrn), opts(options) { from=0; to=100; };
00077     docMatchBookmark(QString pattrn, QString bmkname,
00078         int options=0):docBookmark(bmkname, 0), pattern(pattrn),
00079         opts(options) { from=0; to=100; };
00080     virtual ~ docMatchBookmark() { };
00081 
00082     virtual int findMatches(QString, bmkList &fBookmarks);
00083     QString pattern;
00084     int opts;
00085     int from, to;
00086 };
00087 
00088 class docRegExpBookmark:public docMatchBookmark {
00089  public:
00090     docRegExpBookmark():docMatchBookmark() { capSubexpression=-1;};
00091     docRegExpBookmark(QString regexp, int cap=0,
00092         int options=0):docMatchBookmark(regexp, options) {capSubexpression=cap; };
00093     docRegExpBookmark(QString pattrn, QString bmkname,
00094         int options=0):docMatchBookmark(pattrn, bmkname, options) { capSubexpression=-1; };
00095     virtual ~ docRegExpBookmark() { };
00096 
00097     virtual int findMatches(QString, bmkList &fBookmarks);
00098     int capSubexpression;
00099 };
00100 
00101 
00102 /*************************************************************************************************************
00103  *  The converter class that does the real work for us.
00104  *************************************************************************************************************/
00105 
00106 class DOCConverter:public QObject {
00107 Q_OBJECT
00108 private:
00109     PilotDatabase * docdb;
00110     QString txtfilename;
00111     QString bmkfilename;
00112     bool compress;
00113 
00114     bmkList fBookmarks;
00115 public:
00116     enum eSortBookmarksEnum
00117     {
00118         eSortNone,
00119         eSortPos,
00120         eSortName
00121     } eSortBookmarks;
00122 
00123 public:
00124      DOCConverter(QObject *parent=0L, const char *name=0L);
00125      virtual ~ DOCConverter();
00126 
00127     QString readText();
00128     void setTXTpath(QString path, QString file);
00129     void setTXTpath(QString filename);
00130     void setPDB(PilotDatabase * dbi);
00131     QString txtFilename() const {return txtfilename;}
00132     QString bmkFilename() const {return bmkfilename;}
00133     void setBmkFilename(QString bmkf) { bmkfilename=bmkf;}
00134 
00135     bool getCompress() const { return compress; };
00136     void setCompress(bool newcomp) {compress=newcomp;};
00137 
00138     bool convertTXTtoPDB();
00139     bool convertPDBtoTXT();
00140 
00141     int setBookmarks(bmkList bookmarks) {
00142         fBookmarks = bookmarks;
00143         return fBookmarks.count();
00144     };
00145     int clearBookmarks() {
00146         fBookmarks.clear();
00147         return fBookmarks.count();
00148     };
00149     int addBookmark(docBookmark*bookmark) {
00150         fBookmarks.append(bookmark);
00151         return fBookmarks.count();
00152     };
00153 
00154     int findBmkEndtags(QString &, bmkList&);
00155     int findBmkInline(QString &, bmkList&);
00156     int findBmkFile(QString &, bmkList&);
00157 
00158 
00159     void setSort(enum eSortBookmarksEnum sort) {eSortBookmarks=sort;}
00160     enum eSortBookmarksEnum getSort() {return eSortBookmarks;}
00161 
00162     enum eBmkTypesEnum {
00163         eBmkNone = 0,
00164         eBmkFile = 1,
00165         eBmkInline = 2,
00166         eBmkEndtags = 4,
00167         eBmkDefaultBmkFile = 8
00168     } fBmkTypes;
00169     void setBookmarkTypes(int types) {
00170         fBmkTypes = (eBmkTypesEnum) types;
00171     };
00172 
00173 protected:
00174     int findBookmarks();
00175 
00176 private:
00177     void readConfig();
00178 signals:
00179     void logMessage(const QString &);
00180     void logError(const QString &);
00181 };
00182 
00183 #endif