summaryrefslogtreecommitdiffstats
path: root/kjots/kjotsentry.h
blob: 96e5086353df52030dff2b53c7a7dfbcfc906dd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//
//  kjots
//
//  Copyright (C) 1997 Christoph Neerfeld
//  Copyright (C) 2002, 2003 Aaron J. Seigo
//  Copyright (C) 2003 Stanislav Kljuhhin
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//

#ifndef __KJOTSENTRY_H
#define __KJOTSENTRY_H

#include <klistview.h>
#include <kprinter.h>

//
// class KJotsEntryBase
//

class KURL;
class KJotsPage;
class KProgressDialog;
class KJotsEdit;
class TQTextCodec;
class TQDomDocument;
class TQDomElement;
class TQFile;

class KJotsBook;

namespace KIO
{
    class Job;
}

class KJotsEntryBase : public TQObject, public KListViewItem
{
    Q_OBJECT
  
    public:
        KJotsEntryBase(KListView*, TQListViewItem*);
        KJotsEntryBase(KListViewItem*, TQListViewItem*);

    public:
        virtual void setSubject(const TQString&);
        TQString subject() { return text(0); }
        void setText(int,const TQString&);
        virtual void saveToFile(KURL, bool plainText, const TQString& encoding) = 0;
        virtual void print(TQFont& defaultFont) = 0;
        virtual int  print(KPrinter&, TQPainter&, int) = 0;
        virtual TQString defaultSubject() = 0; //!< "subject" is the caption name
        virtual void rename() = 0;
        virtual void generateXml( TQDomDocument&, TQDomElement& );
        virtual void parseXml( TQDomElement& );
        virtual TQString generateHtml( KJotsEntryBase*, bool ) = 0;
        virtual TQString generateText( void ) = 0;

        void setDirty(bool d) { m_dirty = d; } //!< Toggles the dirty flag.
        virtual bool isDirty() { return m_dirty; }; //!< Accessor for dirty flag.

        TQ_UINT64 id() { return m_id; }
        void setId(TQ_UINT64);

        KJotsBook *parentBook() { return m_parent; }
        void resetParent();

        bool isBook() const { return m_isBook; }
        bool isPage() const { return !m_isBook; }

    protected:
        int printTitleBox(TQString, KPrinter&, TQPainter&, int);

        bool m_saveInProgress; //!< Toggled during a manual disk save.
        bool m_isBook; //!< used for speed and code clarity.

    private:
        TQ_UINT64 m_id; //!< unique ID for this entry
        bool m_dirty; //!< Set when this entry has been changed.
        KJotsBook *m_parent; //!< used during drag-n-drop moving
};

//
// class KjotsBook
//

class KJotsBook : public KJotsEntryBase
{
    Q_OBJECT
  
    public:
        KJotsBook(KListView*, TQListViewItem* after = 0);
        KJotsBook(KListViewItem*, TQListViewItem* after = 0);
        ~KJotsBook();

        static bool isBookFile(const TQString& book);
        bool openBook(const TQString&);
        void saveBook();
        void deleteBook();
        void rename();
        void saveToFile(KURL, bool plainText, const TQString& encoding);
        KJotsPage* addPage(); //!< Add a new page to this book.
        void print(TQFont& defaultFont);
        int  print(KPrinter&, TQPainter&, int);
        bool isDirty();
        TQString defaultSubject();
        void generateXml( TQDomDocument&, TQDomElement& );
        void parseXml( TQDomElement& );
        TQString generateHtml( KJotsEntryBase*, bool );
        TQString generateText( void );

    protected slots:
        void saveDataReq(KIO::Job* job, TQByteArray& data);
        void slotSaveResult(KIO::Job*);

    private:
        TQString getToc();
        bool loadOldBook(TQFile &);
        void init();

        bool m_open;
        TQString m_fileName;
        bool m_saveToPlainText;
        TQTextCodec* m_saveEncoding;
        KProgressDialog* m_saveProgressDialog;
};

//
// class KJotsPage
//
class KJotsPage : public KJotsEntryBase
{
    Q_OBJECT
  
    public:
        KJotsPage(KJotsBook* parent, TQListViewItem* after = 0);
        ~KJotsPage();

    public:
        TQString body();
        void setBody(const TQString&);
        void saveToFile(KURL, bool plainText, const TQString& encoding);
        void print(TQFont& defaultFont);
        int  print(KPrinter&, TQPainter&, int);
        TQString defaultSubject();
        void rename();

        void setEditor(KJotsEdit*);
        bool isDirty();
        void generateXml( TQDomDocument&, TQDomElement& );
        void parseXml( TQDomElement& );
        void initNewPage(void);
        TQString generateHtml( KJotsEntryBase*, bool );
        TQString generateText( void );

    protected slots:
        void saveDataReq(KIO::Job* job, TQByteArray& data);
        void slotSaveResult(KIO::Job*);

    private:
        TQString m_text;
        TQTextCodec* m_saveEncoding;
        bool    m_saveToPlainText;
        KJotsEdit *m_editor; //!< ptr to editor if this is the active subject
        int m_paraPos; //< used to remrmber the cursor position
        int m_indexPos; //< used to remrmber the cursor position
};

#endif // __KJOTSENTRY_H
/* ex: set tabstop=4 softtabstop=4 shiftwidth=4 expandtab: */