kplato

kptaccount.h
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#ifndef KPTACCOUNT_H
21#define KPTACCOUNT_H
22
23#include <tqdatetime.h>
24#include <tqdict.h>
25#include <tqptrlist.h>
26#include <tqstringlist.h>
27
28#include "kpteffortcostmap.h"
29#include "kptnode.h"
30
31#include <kdebug.h>
32
33class TQDomElement;
34class TQString;
35
36namespace KPlato
37{
38
39class Accounts;
40class Account;
41
42
49{
50public:
51
55 Account();
56
60 Account(TQString name, TQString description=TQString());
61
65 ~Account();
66
67
68 TQString name() const { return m_name; }
69 void setName(TQString name);
70
71 TQString description() const { return m_description; }
72 void setDescription(TQString desc) { m_description = desc; }
73
74 bool isElement() const { return m_accountList.isEmpty(); }
75
76 Accounts *list() const { return m_list; }
77 void setList(Accounts *list) { m_list = list; }
78 Account *parent() const { return m_parent; }
79 void setParent(Account *parent) { m_parent = parent; }
80 void clear() { m_accountList.clear(); }
81 void append(Account *account);
82 void take(Account *account);
83 void insertChildren();
84
85 bool load(TQDomElement &element, const Project &project);
86 void save(TQDomElement &element) const;
87
88 const TQPtrList<Account> &accountList() const { return m_accountList; }
89
90 Account *findAccount() const { return findAccount(m_name); }
91 Account *findAccount(const TQString &id) const;
92 bool removeId() { return removeId(m_name); }
93 bool removeId(const TQString &id);
94 bool insertId();
95 bool insertId(const Account *account);
96
97 class CostPlace {
98 public:
99 CostPlace()
100 : m_account(0), m_nodeId(), m_node(0), m_running(false), m_startup(false), m_shutdown(false)
101 {}
102 CostPlace(Account *acc)
103 : m_account(acc), m_nodeId(), m_node(0), m_running(false), m_startup(false), m_shutdown(false)
104 {}
105 CostPlace(Account *acc, Node *node, bool running=false, bool strtup=false, bool shutdown=false)
106 : m_account(acc), m_nodeId(node->id()), m_node(node) {
107 if (node) {
108 setRunning(running);
109 setStartup(strtup);
110 setShutdown(shutdown);
111 }
112 }
113 CostPlace(CostPlace *cp) {
114 m_account = cp->m_account;
115 m_nodeId = cp->m_nodeId;
116 m_node = cp->m_node;
117 m_running = cp->m_running;
118 m_startup = cp->m_startup;
119 m_shutdown = cp->m_shutdown;
120 }
121 ~CostPlace();
122
123 bool isEmpty() { return !(m_running || m_startup || m_shutdown); }
124 Node *node() const { return m_node; }
125
126 bool running() const { return m_running; }
127 void setRunning(bool on );
128 bool startup() const { return m_startup; }
129 void setStartup(bool on);
130 bool shutdown() const { return m_shutdown; }
131 void setShutdown(bool on);
132
133 bool load(TQDomElement &element, const Project &project);
134 void save(TQDomElement &element) const;
135
136 private:
137 Account *m_account;
138 TQString m_nodeId;
139 Node *m_node;
140 bool m_running;
141 bool m_startup;
142 bool m_shutdown;
143 };
144
145 void append(const CostPlace *cp) { m_costPlaces.append(cp); }
146 const TQPtrList<CostPlace> &costPlaces() const {return m_costPlaces; }
147 Account::CostPlace *findCostPlace(const Node &node) const;
148 CostPlace *findRunning(const Node &node) const;
149 void removeRunning(const Node &node);
150 void addRunning(Node &node);
151 CostPlace *findStartup(const Node &node) const;
152 void removeStartup(const Node &node);
153 void addStartup(Node &node);
154 CostPlace *findShutdown(const Node &node) const;
155 void removeShutdown(const Node &node);
156 void addShutdown(Node &node);
157
158private:
159 TQString m_name;
160 TQString m_description;
161 Accounts *m_list;
162 Account *m_parent;
163 TQPtrList<Account> m_accountList;
164 TQPtrList<CostPlace> m_costPlaces;
165
166#ifndef NDEBUG
167public:
168 void printDebug(TQString indent);
169#endif
170};
171
172typedef TQPtrList<Account> AccountList;
173typedef TQPtrListIterator<Account> AccountListIterator;
174
178
179class Accounts
180{
181public:
182 Accounts(Project &project);
183 ~Accounts();
184
185 Account *defaultAccount() const { return m_defaultAccount; }
186 void setDefaultAccount(Account *account) { m_defaultAccount = account; }
187
188 EffortCostMap plannedCost(const Account &account, const TQDate &start, const TQDate &end);
189
190 void clear() { m_accountList.clear(); m_idDict.clear(); }
191 void append(Account *account);
192 void take(Account *account);
193
194 bool load(TQDomElement &element, const Project &project);
195 void save(TQDomElement &element) const;
196
197 TQStringList costElements() const;
198 TQStringList nameList() const;
199
200 const AccountList &accountList() const { return m_accountList; }
201
202 Account *findRunningAccount(const Node &node) const;
203 Account *findStartupAccount(const Node &node) const;
204 Account *findShutdownAccount(const Node &node) const;
205 Account *findAccount(const TQString &id) const;
206 bool insertId(const Account *account);
207 bool removeId(const TQString &id);
208
209 void accountDeleted(Account *account)
210 { if (account == m_defaultAccount) m_defaultAccount = 0; }
211private:
212 Project &m_project;
213 AccountList m_accountList;
214 TQDict<Account> m_idDict;
215
216 Account *m_defaultAccount;
217
218#ifndef NDEBUG
219public:
220 void printDebug(TQString indent);
221#endif
222};
223
224} //namespace KPlato
225
226#endif
Account holds one account.
Definition kptaccount.h:49
~Account()
Destructor.
Account()
Constructor.
Accounts administrates all accounts.
Definition kptaccount.h:180
This class represents any node in the project, a node can be a project or a subproject or any task.
Definition kptnode.h:57
Project is the main node in a project, it contains child nodes and possibly sub-projects.
Definition kptproject.h:52