blob: aaf6ec2a0889bbc1715332f7dfeece6e0bc009af (
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
|
/***************************************************************************
siglistview.cpp - description
-------------------
begin : Fri Jul 19 2002
copyright : (C) 2002 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include "siglistview.h"
#include "siglistview.moc"
#include "siglistviewitem.h"
#include <kstandarddirs.h>
#include <klocale.h>
SigListView *SigListView::listView = 0;
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
SigListView *SigListView::instance(TQWidget *tqparent, const char *name)
{
if(!listView)
listView = new SigListView(tqparent, name);
return(listView);
}
void SigListView::load()
{
if(file.open(IO_ReadOnly) && doc.setContent(&file)) {
// find the root element
TQDomNodeList topLevelElements = doc.childNodes();
uint i = 0;
while(topLevelElements.item(i).toElement().tagName() != "SigML" && i < topLevelElements.count())
i++;
if(i < topLevelElements.count())
// if we didn't hit the end of the list
rootElement = topLevelElements.item(i).toElement();
else {
// if we didn't find the root element, create one
rootElement = doc.createElement("SigML");
doc.appendChild(rootElement);
}
TQDomNodeList signatures = doc.elementsByTagName("signature");
for(i = 0; i < signatures.count(); i++)
(void) new SigListViewItem(this, doc, signatures.item(i).toElement());
file.close();
}
// if the document could not be opened or setData failed, create the document framework
else {
rootElement = doc.createElement("SigML");
doc.appendChild(rootElement);
}
}
void SigListView::save()
{
TQListViewItemIterator it(this);
while(it.current()) {
SigListViewItem *item = dynamic_cast<SigListViewItem *>(it.current());
if(item)
item->render();
it++;
}
if(file.open(IO_WriteOnly)) {
TQTextStream stream(&file);
stream << doc;
file.close();
}
}
SigListViewItem *SigListView::createItem()
{
TQDomElement element = doc.createElement("signature");
rootElement.appendChild(element);
SigListViewItem *item = new SigListViewItem(this, doc, element);
return(item);
}
SigListViewItem *SigListView::currentItem()
{
return(dynamic_cast<SigListViewItem *>(KListView::currentItem()));
}
const SigListViewItem *SigListView::currentItem() const
{
return(dynamic_cast<SigListViewItem *>(KListView::currentItem()));
}
////////////////////////////////////////////////////////////////////////////////
// protected members
////////////////////////////////////////////////////////////////////////////////
SigListView::SigListView(TQWidget *tqparent, const char *name) : KListView(tqparent, name)
{
addColumn(i18n("Signatures"));
TQString dir = KGlobal::dirs()->saveLocation("appdata");
if(!dir.isNull())
file.setName(dir + "sigs.sigml");
load();
}
SigListView::~SigListView()
{
}
|