summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/advcommeditimpl.cpp
Unidiff
Diffstat (limited to 'pwmanager/pwmanager/advcommeditimpl.cpp') (more/less context) (show whitespace changes)
-rw-r--r--pwmanager/pwmanager/advcommeditimpl.cpp149
1 files changed, 149 insertions, 0 deletions
diff --git a/pwmanager/pwmanager/advcommeditimpl.cpp b/pwmanager/pwmanager/advcommeditimpl.cpp
new file mode 100644
index 0000000..59e5e5b
--- a/dev/null
+++ b/pwmanager/pwmanager/advcommeditimpl.cpp
@@ -0,0 +1,149 @@
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/***************************************************************************
14 * copyright (C) 2004 by Ulf Schenk
15 * This file is originaly based on version 1.0.1 of pwmanager
16 * and was modified to run on embedded devices that run microkde
17 *
18 * $Id$
19 **************************************************************************/
20
21#include "advcommeditimpl.h"
22#include "htmlgen.h"
23#include "htmlparse.h"
24#include "pwmexception.h"
25#include "subtbleditimpl.h"
26
27#include <qlineedit.h>
28#include <qlabel.h>
29
30#include <khtml_part.h>
31#include <khtmlview.h>
32
33
34AdvCommEditImpl::AdvCommEditImpl(QWidget* parent,
35 const char* name,
36 WFlags fl)
37 : advCommEdit(parent, name, fl)
38{
39 dta = new HtmlComment;
40 preview = new KHTMLPart(previewDummy);
41 preview->view()->resize(previewDummy->size());
42 preview->show();
43}
44
45AdvCommEditImpl::~AdvCommEditImpl()
46{
47 delete dta;
48 delete preview;
49}
50
51void AdvCommEditImpl::okButton_slot()
52{
53 updateTitle();
54 done(0);
55}
56
57void AdvCommEditImpl::cancelButton_slot()
58{
59 done(1);
60}
61
62void AdvCommEditImpl::addSubtblButton_slot()
63{
64 SubTblEditImpl editor(this);
65 if (editor.exec())
66 return;
67 QString subTitle(editor.getTitle());
68 HtmlComment::SubTable subTbl;
69 subTbl.setTitle(subTitle);
70 subTbl.setEntries(editor.getEntries());
71 dta->addSubtable(subTbl);
72 entryListBox->insertItem(subTitle);
73 updatePreview();
74}
75
76void AdvCommEditImpl::editButton_slot()
77{
78 int index = curIndex();
79 if (index == -1)
80 return;
81 SubTblEditImpl editor(this);
82 HtmlComment::SubTable subTbl = dta->subtableAt(index);
83 editor.setContent(subTbl.getTitle(), subTbl.getEntryList());
84 if (editor.exec())
85 return;
86 QString subTitle(editor.getTitle());
87 subTbl.setTitle(subTitle);
88 subTbl.setEntries(editor.getEntries());
89 dta->setSubtblAt(index, subTbl);
90 entryListBox->changeItem(subTitle, index);
91 updatePreview();
92}
93
94void AdvCommEditImpl::delButton_slot()
95{
96 int index = curIndex();
97 if (index == -1)
98 return;
99 dta->eraseSubtable(index);
100 entryListBox->removeItem(index);
101 updatePreview();
102}
103
104void AdvCommEditImpl::updatePreview()
105{
106 updateTitle();
107 HtmlGen htmlGen;
108 htmlGen.styleSheetDummy(false);
109 QString code(htmlGen.genHtmlComment(dta));
110 if (code.isEmpty())
111 return;
112 preview->begin();
113 preview->write(code);
114 preview->end();
115}
116
117void AdvCommEditImpl::updateTitle()
118{
119 dta->setTitle(titleLineEdit->text());
120}
121
122QString AdvCommEditImpl::getHtmlDta()
123{
124 HtmlGen htmlGen;
125 return htmlGen.genHtmlComment(dta);
126}
127
128void AdvCommEditImpl::setHtmlDta(const QString &str)
129{
130 if (str.isEmpty())
131 return;
132 PWM_ASSERT(HtmlGen::isHtml(str));
133 HtmlParse htmlParse;
134 if (!htmlParse.parseHtmlComment(str, dta)) {
135 printWarn("AdvCommEditImpl::setHtmlDta(): parseHtmlComment() failed!");
136 return;
137 }
138 titleLineEdit->setText(dta->getTitle());
139 const vector<HtmlComment::SubTable> *subTbls = dta->getSubTableList();
140 vector<HtmlComment::SubTable>::const_iterator i = subTbls->begin(),
141 end = subTbls->end();
142 while (i != end) {
143 entryListBox->insertItem(i->getTitle());
144 ++i;
145 }
146 updatePreview();
147}
148
149#include "advcommeditimpl.moc"