kplato

kptaccount.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Dag Andersen <danders@get2net.dk>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation;
00007    version 2 of the License.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef KPTACCOUNT_H
00021 #define KPTACCOUNT_H
00022 
00023 #include <qdatetime.h>
00024 #include <qdict.h>
00025 #include <qptrlist.h>
00026 #include <qstringlist.h>
00027 
00028 #include "kpteffortcostmap.h"
00029 #include "kptnode.h"
00030 
00031 #include <kdebug.h>
00032 
00033 class QDomElement;
00034 class QString;
00035 
00036 namespace KPlato
00037 {
00038 
00039 class Accounts;
00040 class Account;
00041 
00042 
00048 class Account
00049 {
00050 public:
00051     Account();
00052     Account(QString name, QString description=QString::null);
00053     ~Account();
00054     
00055     QString name() const { return m_name; }
00056     void setName(QString name);
00057     
00058     QString description() const { return m_description; }
00059     void setDescription(QString desc) { m_description = desc; }
00060 
00061     bool isElement() const { return m_accountList.isEmpty(); }
00062     
00063     Accounts *list() const { return m_list; }
00064     void setList(Accounts *list) { m_list = list; }
00065     Account *parent() const { return m_parent; }
00066     void setParent(Account *parent) { m_parent = parent; }
00067     void clear() { m_accountList.clear(); }
00068     void append(Account *account);
00069     void take(Account *account);
00070     void insertChildren();
00071     
00072     bool load(QDomElement &element, const Project &project);
00073     void save(QDomElement &element) const;
00074     
00075     const QPtrList<Account> &accountList() const { return m_accountList; }
00076     
00077     Account *findAccount() const { return findAccount(m_name); }
00078     Account *findAccount(const QString &id) const;
00079     bool removeId() { return removeId(m_name); }
00080     bool removeId(const QString &id);
00081     bool insertId();
00082     bool insertId(const Account *account);
00083     
00084     class CostPlace {
00085     public:
00086         CostPlace() 
00087             : m_account(0), m_nodeId(), m_node(0), m_running(false), m_startup(false), m_shutdown(false)
00088         {}
00089         CostPlace(Account *acc) 
00090             : m_account(acc), m_nodeId(), m_node(0), m_running(false), m_startup(false), m_shutdown(false)
00091         {}
00092         CostPlace(Account *acc, Node *node, bool running=false, bool strtup=false, bool shutdown=false)
00093             : m_account(acc), m_nodeId(node->id()), m_node(node) {
00094             if (node) {
00095                 setRunning(running);
00096                 setStartup(strtup);
00097                 setShutdown(shutdown);
00098             }
00099         }
00100         CostPlace(CostPlace *cp) {
00101             m_account = cp->m_account;
00102             m_nodeId = cp->m_nodeId;
00103             m_node = cp->m_node;
00104             m_running = cp->m_running;
00105             m_startup = cp->m_startup;
00106             m_shutdown = cp->m_shutdown;
00107         }
00108         ~CostPlace();
00109         
00110         bool isEmpty() { return !(m_running || m_startup || m_shutdown); }
00111         Node *node() const { return m_node; }
00112         
00113         bool running() const { return m_running; }
00114         void setRunning(bool on );
00115         bool startup() const  { return m_startup; }
00116         void setStartup(bool on);
00117         bool shutdown() const  { return m_shutdown; }
00118         void setShutdown(bool on);
00119     
00120         bool load(QDomElement &element, const Project &project);
00121         void save(QDomElement &element) const;
00122     
00123     private:
00124         Account *m_account;
00125         QString m_nodeId;
00126         Node *m_node;
00127         bool m_running;
00128         bool m_startup;
00129         bool m_shutdown;
00130     };
00131     
00132     void append(const CostPlace *cp) { m_costPlaces.append(cp); }
00133     const QPtrList<CostPlace> &costPlaces() const {return m_costPlaces; }
00134     Account::CostPlace *findCostPlace(const Node &node) const;
00135     CostPlace *findRunning(const Node &node) const;
00136     void removeRunning(const Node &node);
00137     void addRunning(Node &node);
00138     CostPlace *findStartup(const Node &node) const;
00139     void removeStartup(const Node &node);
00140     void addStartup(Node &node);
00141     CostPlace *findShutdown(const Node &node) const;
00142     void removeShutdown(const Node &node);
00143     void addShutdown(Node &node);
00144 
00145 private:
00146     QString m_name;
00147     QString m_description;
00148     Accounts *m_list;
00149     Account *m_parent;
00150     QPtrList<Account> m_accountList;
00151     QPtrList<CostPlace> m_costPlaces;
00152     
00153 #ifndef NDEBUG
00154 public:
00155     void printDebug(QString indent);
00156 #endif
00157 };
00158 
00159 typedef QPtrList<Account> AccountList;
00160 typedef QPtrListIterator<Account> AccountListIterator;
00161 
00166 class Accounts
00167 {
00168 public:
00169     Accounts(Project &project);
00170     ~Accounts();
00171     
00172     Account *defaultAccount() const { return m_defaultAccount; }
00173     void setDefaultAccount(Account *account) { m_defaultAccount = account; }
00174     
00175     EffortCostMap plannedCost(const Account &account, const QDate &start, const QDate &end);
00176     
00177     void clear() { m_accountList.clear(); m_idDict.clear(); }
00178     void append(Account *account);
00179     void take(Account *account);
00180     
00181     bool load(QDomElement &element, const Project &project);
00182     void save(QDomElement &element) const;
00183 
00184     QStringList costElements() const;
00185     QStringList nameList() const;
00186         
00187     const AccountList &accountList() const { return m_accountList; }
00188     
00189     Account *findRunningAccount(const Node &node) const;
00190     Account *findStartupAccount(const Node &node) const;
00191     Account *findShutdownAccount(const Node &node) const;
00192     Account *findAccount(const QString &id) const;
00193     bool insertId(const Account *account);
00194     bool removeId(const QString &id);
00195     
00196     void accountDeleted(Account *account) 
00197         { if (account == m_defaultAccount) m_defaultAccount = 0; }
00198 private:
00199     Project &m_project;
00200     AccountList m_accountList;
00201     QDict<Account> m_idDict;
00202 
00203     Account *m_defaultAccount;
00204 
00205 #ifndef NDEBUG
00206 public:
00207     void printDebug(QString indent);
00208 #endif
00209 };
00210 
00211 } //namespace KPlato
00212 
00213 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys