File indexing completed on 2024-05-12 16:39:28
0001 /* This file is part of the KDE project 0002 Copyright (C) 2009 Dag Andersen <danders@get2net.dk> 0003 Copyright (C) 2019 Dag Andersen <danders@get2net.dk> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #ifndef KPLATOWORK_WORKPACKAGE_H 0022 #define KPLATOWORK_WORKPACKAGE_H 0023 0024 #include "kptxmlloaderobject.h" 0025 #include "kptcommand.h" 0026 #include "kpttask.h" 0027 0028 #include <KoDocument.h> 0029 0030 #include <QFileInfo> 0031 #include <QProcess> 0032 #include <QDebug> 0033 0034 class KoStore; 0035 0036 class QDomDocument; 0037 0038 namespace KPlato 0039 { 0040 class Project; 0041 class Document; 0042 class XMLLoaderObject; 0043 } 0044 0045 using namespace KPlato; 0046 0047 /// The main namespace for KPlato WorkPackage Handler 0048 namespace KPlatoWork 0049 { 0050 0051 class Part; 0052 class WorkPackage; 0053 class DocumentChild; 0054 0055 /** 0056 A work package consists of a Project node and one Task node 0057 along with scheduling information and assigned resources. 0058 */ 0059 class WorkPackage : public QObject 0060 { 0061 Q_OBJECT 0062 public: 0063 explicit WorkPackage(bool fromProjectStore); 0064 WorkPackage(Project *project, bool fromProjectStore); 0065 ~WorkPackage() override; 0066 0067 /// @return Package name 0068 QString name() const; 0069 0070 DocumentChild *findChild(const Document *doc) const; 0071 /// Called when loading a work package. Saves to Project store. 0072 /// Asks to save/overwrite if already there. 0073 /// Does nothing if opened from Projects store. 0074 void saveToProjects(Part *part); 0075 0076 bool contains(const DocumentChild* child) const { 0077 return m_childdocs.contains(const_cast<DocumentChild*>(child) ); 0078 } 0079 QList<DocumentChild*> childDocs() { return m_childdocs; } 0080 bool addChild(Part *part, const Document *doc); 0081 void removeChild(DocumentChild *child); 0082 0083 bool contains(const Document *doc) const; 0084 0085 QString nodeId() const; 0086 0087 /// Load the Plan work package document 0088 bool loadXML(const KoXmlElement &element, XMLLoaderObject &status); 0089 /// Load the old KPlato work package file format 0090 bool loadKPlatoXML(const KoXmlElement &element, XMLLoaderObject &status); 0091 0092 QDomDocument saveXML(); 0093 bool saveNativeFormat(Part *part, const QString &path); 0094 bool saveDocumentsToStore(KoStore *store); 0095 bool completeSaving(KoStore *store); 0096 0097 Node *node() const; 0098 Task *task() const; 0099 Project *project() const { return m_project; } 0100 0101 /// Remove document @p doc 0102 bool removeDocument(Part *part, Document *doc); 0103 0104 /// Set the file path to this package 0105 void setFilePath(const QString &name) { m_filePath = name; } 0106 /// Return the file path to this package 0107 QString filePath() const { return m_filePath; } 0108 0109 /// Construct file path to projects store 0110 QString fileName(const Part *part) const; 0111 /// Remove work package file 0112 void removeFile(); 0113 0114 /// Merge data from work package @p wp 0115 void merge(Part *part, const WorkPackage *wp, KoStore *store); 0116 0117 bool isModified() const; 0118 0119 int queryClose(Part *part); 0120 0121 QUrl extractFile(const Document *doc); 0122 QUrl extractFile(const Document *doc, KoStore *store); 0123 0124 QString id() const; 0125 0126 bool isValid() const { return m_project && node(); } 0127 0128 WorkPackageSettings &settings() { return m_settings; } 0129 void setSettings(const WorkPackageSettings &settings); 0130 0131 QMap<const Document*, QUrl> newDocuments() const { return m_newdocs; } 0132 void removeNewDocument(const Document *doc) { m_newdocs.remove(doc); } 0133 0134 QUrl sendUrl() const { return m_sendUrl; } 0135 QUrl fetchUrl() const { return m_fetchUrl; } 0136 0137 QString wbsCode() const { return m_wbsCode; } 0138 void setWbsCode(const QString &wbsCode) { m_wbsCode = wbsCode; } 0139 0140 Q_SIGNALS: 0141 void modified(bool); 0142 void saveWorkPackage(KPlatoWork::WorkPackage*); 0143 0144 public Q_SLOTS: 0145 void setModified(bool on) { m_modified = on; } 0146 0147 protected Q_SLOTS: 0148 void projectChanged(); 0149 void slotChildModified(bool mod); 0150 0151 protected: 0152 /// Copy file @p filename from old store @p from, to the new store @p to 0153 bool copyFile(KoStore *from, KoStore *to, const QString &filename); 0154 0155 bool saveToStream(QIODevice * dev); 0156 0157 void openNewDocument(const Document *doc, KoStore *store); 0158 0159 protected: 0160 Project *m_project; 0161 QString m_filePath; 0162 bool m_fromProjectStore; 0163 QList<DocumentChild*> m_childdocs; 0164 QMap<const Document*, QUrl> m_newdocs; /// new documents that does not exists in the project store (yet) 0165 QUrl m_sendUrl; /// Where to put the package. If not valid, transmit by mail 0166 QUrl m_fetchUrl; /// Plan will store package here 0167 bool m_modified; 0168 QString m_wbsCode; 0169 0170 WorkPackageSettings m_settings; 0171 0172 ConfigBase m_config; 0173 0174 }; 0175 0176 //----------------------------- 0177 class PackageRemoveCmd : public NamedCommand 0178 { 0179 public: 0180 PackageRemoveCmd(Part *part, WorkPackage *value, const KUndo2MagicString &name = KUndo2MagicString()); 0181 ~PackageRemoveCmd() override; 0182 void execute() override; 0183 void unexecute() override; 0184 0185 private: 0186 Part *m_part; 0187 WorkPackage *m_value; 0188 bool m_mine; 0189 }; 0190 0191 //----------------------------- 0192 class CopySchedulesCmd : public NamedCommand 0193 { 0194 public: 0195 CopySchedulesCmd(const Project &fromProject, Project &toProject, const KUndo2MagicString &name = KUndo2MagicString()); 0196 0197 void execute() override; 0198 void unexecute() override; 0199 0200 private: 0201 void load(const QString &doc); 0202 void clean(const QDomDocument &doc); 0203 void clearSchedules(); 0204 0205 private: 0206 Project &m_project; 0207 QString m_olddoc; 0208 QString m_newdoc; 0209 }; 0210 0211 //----------------------------- 0212 class ModifyWbsCodeCmd : public NamedCommand 0213 { 0214 public: 0215 ModifyWbsCodeCmd(WorkPackage *wp, QString wbsCode, const KUndo2MagicString &name = KUndo2MagicString()); 0216 0217 void execute() override; 0218 void unexecute() override; 0219 0220 private: 0221 WorkPackage *m_wp; 0222 QString m_old; 0223 QString m_new; 0224 }; 0225 0226 } //KPlatoWork namespace 0227 0228 QDebug operator<<(QDebug dbg, const KPlatoWork::WorkPackage *wp); 0229 QDebug operator<<(QDebug dbg, const KPlatoWork::WorkPackage &wp); 0230 0231 #endif