-rw-r--r-- | pwmanager/pwmanager/htmlgen.h | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/pwmanager/pwmanager/htmlgen.h b/pwmanager/pwmanager/htmlgen.h new file mode 100644 index 0000000..5ec9626 --- a/dev/null +++ b/pwmanager/pwmanager/htmlgen.h | |||
@@ -0,0 +1,136 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
3 | * copyright (C) 2004 by Michael Buesch * | ||
4 | * email: mbuesch@freenet.de * | ||
5 | * * | ||
6 | * This program is free software; you can redistribute it and/or modify * | ||
7 | * it under the terms of the GNU General Public License version 2 * | ||
8 | * as published by the Free Software Foundation. * | ||
9 | * * | ||
10 | ***************************************************************************/ | ||
11 | |||
12 | /*************************************************************************** | ||
13 | * copyright (C) 2004 by Ulf Schenk | ||
14 | * This file is originaly based on version 1.0.1 of pwmanager | ||
15 | * and was modified to run on embedded devices that run microkde | ||
16 | * | ||
17 | * $Id$ | ||
18 | **************************************************************************/ | ||
19 | |||
20 | #ifndef HTMLGEN_H | ||
21 | #define HTMLGEN_H | ||
22 | |||
23 | #include <qstring.h> | ||
24 | |||
25 | #include <utility> | ||
26 | #include <vector> | ||
27 | |||
28 | using std::vector; | ||
29 | using std::pair; | ||
30 | |||
31 | /** internal representation of the advanced HTML-comment */ | ||
32 | class HtmlComment | ||
33 | { | ||
34 | public: | ||
35 | class SubTable | ||
36 | { | ||
37 | public: | ||
38 | SubTable() {} | ||
39 | ~SubTable() {} | ||
40 | |||
41 | void clear() | ||
42 | { | ||
43 | title = ""; | ||
44 | entries.clear(); | ||
45 | } | ||
46 | void setTitle(const QString &_title) | ||
47 | { title = _title; } | ||
48 | QString getTitle() const | ||
49 | { return title; } | ||
50 | void addEntry(const pair<QString, QString> &entry) | ||
51 | { entries.push_back(entry); } | ||
52 | void setEntries(const vector< pair<QString, QString> > *_entries) | ||
53 | { entries = *_entries; } | ||
54 | const vector< pair<QString, QString> > * getEntryList() const | ||
55 | { return &entries; } | ||
56 | |||
57 | protected: | ||
58 | /** sub-title */ | ||
59 | QString title; | ||
60 | /** list of entries */ | ||
61 | vector< pair<QString, QString> > entries; | ||
62 | }; | ||
63 | |||
64 | public: | ||
65 | HtmlComment() {} | ||
66 | ~HtmlComment() {} | ||
67 | |||
68 | void clear() | ||
69 | { | ||
70 | title = ""; | ||
71 | subTables.clear(); | ||
72 | } | ||
73 | void setTitle(const QString &_title) | ||
74 | { title = _title; } | ||
75 | QString getTitle() const | ||
76 | { return title; } | ||
77 | void addSubtable(const SubTable &subTable) | ||
78 | { subTables.push_back(subTable); } | ||
79 | void eraseSubtable(int index) | ||
80 | { subTables.erase(subTables.begin() + index); } | ||
81 | const SubTable & subtableAt(int index) | ||
82 | { return subTables[index]; } | ||
83 | void setSubtblAt(int index, const SubTable &entry) | ||
84 | { subTables[index] = entry; } | ||
85 | const vector<SubTable> * getSubTableList() const | ||
86 | { return &subTables; } | ||
87 | |||
88 | protected: | ||
89 | /** global title */ | ||
90 | QString title; | ||
91 | /** list of sub-tables */ | ||
92 | vector<SubTable> subTables; | ||
93 | }; | ||
94 | |||
95 | /** HTML generator for the comment-box */ | ||
96 | class HtmlGen | ||
97 | { | ||
98 | public: | ||
99 | HtmlGen(); | ||
100 | ~HtmlGen(); | ||
101 | |||
102 | /** replace the @STYLESHEET@ dummy in the "doc" HTML document */ | ||
103 | static bool replaceSSDummy(QString *doc); | ||
104 | /** check whether "dta" is HTML-code */ | ||
105 | static bool isHtml(const QString &dta); | ||
106 | |||
107 | /** insert the stylesheet link as dummy? default is true */ | ||
108 | void styleSheetDummy(bool dummy) | ||
109 | { useSSDummy = dummy; } | ||
110 | /** generate a new html-comment */ | ||
111 | QString genHtmlComment(const HtmlComment *dta); | ||
112 | |||
113 | protected: | ||
114 | /** converts the string "str" into HTML-text and ensures | ||
115 | * that there are no collisions with HTML-tags | ||
116 | */ | ||
117 | QString escapeHtmlText(const QString &str); | ||
118 | /** get the "stylesheet-line" to import the CSS style in HTML */ | ||
119 | static QString getStyleSheetHtml(); | ||
120 | /** append the HTML header to the data stream */ | ||
121 | bool appendCommentHeader(QString *str); | ||
122 | /** append the HTML body for the comment */ | ||
123 | bool appendCommentBody(QString *str, const HtmlComment *dta); | ||
124 | /** append a global comment table */ | ||
125 | bool appendCommentGlobTbl(QString *str, const HtmlComment *dta); | ||
126 | /** append a comment subtable */ | ||
127 | bool appendCommentSubTbl(QString *str, const HtmlComment::SubTable *dta); | ||
128 | /** append a subtable entry */ | ||
129 | bool appendCommentSubTblEntry(QString *str, const pair<QString, QString> *dta); | ||
130 | |||
131 | protected: | ||
132 | /** use stylesheet dummy */ | ||
133 | bool useSSDummy; | ||
134 | }; | ||
135 | |||
136 | #endif | ||