kplato

kptcontext.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005 Dag Andersen <danders@get2net.dk>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation;
7 version 2 of the License.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kptcontext.h"
21
22#include <tqdom.h>
23
24#include <kdebug.h>
25
26namespace KPlato
27{
28
29Context::Context()
30 : currentEstimateType(0),
31 currentSchedule(0) {
32}
33
34Context::~Context() {
35}
36
37bool Context::load(TQDomElement &element) {
38 currentView = element.attribute("current-view");
39 currentEstimateType = element.attribute("estimate-type").toInt();
40 currentSchedule = element.attribute("current-schedule").toLong();
41 actionViewExpected = element.attribute("view-expected").toInt();
42 actionViewOptimistic = element.attribute("view-optimistic").toInt();
43 actionViewPessimistic = element.attribute("view-pessimistic").toInt();
44
45 TQDomNodeList list = element.childNodes();
46 for (unsigned int i=0; i<list.count(); ++i) {
47 if (list.item(i).isElement()) {
48 TQDomElement e = list.item(i).toElement();
49 if (e.tagName() == "gantt-view") {
50 ganttview.ganttviewsize = e.attribute("ganttview-size").toInt();
51 ganttview.taskviewsize = e.attribute("taskview-size").toInt();
52 ganttview.currentNode = e.attribute("current-node");
53 ganttview.showResources = e.attribute("show-resources").toInt();
54 ganttview.showTaskName = e.attribute("show-taskname").toInt();
55 ganttview.showTaskLinks = e.attribute("show-tasklinks").toInt();
56 ganttview.showProgress = e.attribute("show-progress").toInt();
57 ganttview.showPositiveFloat = e.attribute("show-positivefloat").toInt();
58 ganttview.showCriticalTasks = e.attribute("show-criticaltasks").toInt();
59 ganttview.showCriticalPath = e.attribute("show-criticalpath").toInt();
60 ganttview.showNoInformation = e.attribute("show-noinformation").toInt();
61
62 TQDomNodeList list = e.childNodes();
63 for (unsigned int i=0; i<list.count(); ++i) {
64 if (list.item(i).isElement()) {
65 TQDomElement g = list.item(i).toElement();
66 if (g.tagName() == "closed-nodes") {
67 TQDomNodeList list = g.childNodes();
68 for (unsigned int i=0; i<list.count(); ++i) {
69 if (list.item(i).isElement()) {
70 TQDomElement ei = list.item(i).toElement();
71 if (ei.tagName() == "node") {
72 ganttview.closedNodes.append(ei.attribute("id"));
73 }
74 }
75 }
76 }
77 }
78 }
79 } else if (e.tagName() == "accounts-view") {
80 accountsview.accountsviewsize = e.attribute("accountsview-size").toInt();
81 accountsview.periodviewsize = e.attribute("periodview-size").toInt();
82 accountsview.date = TQDate::fromString(e.attribute("date"), TQt::ISODate);
83 accountsview.period = e.attribute("period").toInt();
84 accountsview.cumulative = e.attribute("cumulative").toInt();
85
86 TQDomNodeList list = e.childNodes();
87 for (unsigned int i=0; i<list.count(); ++i) {
88 if (list.item(i).isElement()) {
89 TQDomElement g = list.item(i).toElement();
90 if (g.tagName() == "closed-items") {
91 TQDomNodeList list = g.childNodes();
92 for (unsigned int i=0; i<list.count(); ++i) {
93 if (list.item(i).isElement()) {
94 TQDomElement ei = list.item(i).toElement();
95 if (ei.tagName() == "account") {
96 accountsview.closedItems.append(ei.attribute("name"));
97 }
98 }
99 }
100 }
101 }
102 }
103 } else {
104 kdError()<<k_funcinfo<<"Unknown tag: "<<e.tagName()<<endl;
105 }
106 }
107 }
108
109 return true;
110}
111
112void Context::save(TQDomElement &element) const {
113 TQDomElement me = element.ownerDocument().createElement("context");
114 element.appendChild(me);
115 me.setAttribute("current-view", currentView);
116 me.setAttribute("estimate-type", currentEstimateType);
117 me.setAttribute("current-schedule", currentSchedule);
118 me.setAttribute("view-expected", actionViewExpected);
119 me.setAttribute("view-optimistic", actionViewOptimistic);
120 me.setAttribute("view-pessimistic", actionViewPessimistic);
121 // Ganttview
122 TQDomElement g = me.ownerDocument().createElement("gantt-view");
123 me.appendChild(g);
124 g.setAttribute("ganttview-size", ganttview.ganttviewsize);
125 g.setAttribute("taskview-size", ganttview.taskviewsize);
126 g.setAttribute("current-node", ganttview.currentNode);
127 g.setAttribute("show-resources", ganttview.showResources);
128 g.setAttribute("show-taskname", ganttview.showTaskName);
129 g.setAttribute("show-tasklinks", ganttview.showTaskLinks);
130 g.setAttribute("show-progress", ganttview.showProgress);
131 g.setAttribute("show-positivefloat", ganttview.showPositiveFloat);
132 g.setAttribute("show-criticaltasks", ganttview.showCriticalTasks);
133 g.setAttribute("show-criticalpath", ganttview.showCriticalPath);
134 g.setAttribute("show-noinformation", ganttview.showNoInformation);
135 if (!ganttview.closedNodes.isEmpty()) {
136 TQDomElement e = g.ownerDocument().createElement("closed-nodes");
137 g.appendChild(e);
138 for (TQStringList::ConstIterator it = ganttview.closedNodes.begin(); it != ganttview.closedNodes.end(); ++it) {
139 TQDomElement c = e.ownerDocument().createElement("node");
140 e.appendChild(c);
141 c.setAttribute("id", (*it));
142 }
143 }
144 // Accountsview
145 TQDomElement a = me.ownerDocument().createElement("accounts-view");
146 me.appendChild(a);
147 a.setAttribute("accountsview-size", accountsview.accountsviewsize);
148 a.setAttribute("periodview-size", accountsview.periodviewsize);
149 a.setAttribute("date", accountsview.date.toString(TQt::ISODate));
150 a.setAttribute("period", accountsview.period);
151 a.setAttribute("cumulative", accountsview.cumulative);
152 if (!accountsview.closedItems.isEmpty()) {
153 TQDomElement e = a.ownerDocument().createElement("closed-items");
154 a.appendChild(e);
155 for (TQStringList::ConstIterator it = accountsview.closedItems.begin(); it != accountsview.closedItems.end(); ++it) {
156 TQDomElement c = e.ownerDocument().createElement("account");
157 e.appendChild(c);
158 c.setAttribute("name", (*it));
159 }
160 }
161}
162
163} //KPlato namespace