File indexing completed on 2024-04-28 16:24:36
0001 /* This file is part of the KDE project 0002 * Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org> 0003 * Copyright (C) 2004 - 2010 Dag Andersen <danders@get2net.dk> 0004 * Copyright (C) 2006 Raphael Langerhorst <raphael.langerhorst@kdemail.net> 0005 * Copyright (C) 2007 Thorsten Zachmann <zachmann@kde.org> 0006 * Copyright (C) 2019 Dag Andersen <danders@get2net.dk> 0007 * 0008 * This library is free software; you can redistribute it and/or 0009 * modify it under the terms of the GNU Library General Public 0010 * License as published by the Free Software Foundation; either 0011 * version 2 of the License, or (at your option) any later version. 0012 * 0013 * This library is distributed in the hope that it will be useful, 0014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 * Library General Public License for more details. 0017 * 0018 * You should have received a copy of the GNU Library General Public License 0019 * along with this library; see the file COPYING.LIB. If not, write to 0020 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0021 * Boston, MA 02110-1301, USA. 0022 */ 0023 0024 #ifndef KPTMAINDOCUMENT_H 0025 #define KPTMAINDOCUMENT_H 0026 0027 #include "plan_export.h" 0028 0029 #include "kptpackage.h" 0030 #include "kpttask.h" 0031 #include "kptconfig.h" 0032 #include "kptwbsdefinition.h" 0033 #include "kptxmlloaderobject.h" 0034 0035 #include "KoDocument.h" 0036 0037 #include <QFileInfo> 0038 #include <QDomDocument> 0039 0040 0041 #define PLAN_MIME_TYPE "application/x-vnd.kde.plan" 0042 0043 class KDirWatch; 0044 0045 /// The main namespace. 0046 namespace KPlato 0047 { 0048 0049 class DocumentChild; 0050 class Project; 0051 class Context; 0052 class SchedulerPlugin; 0053 class ViewListItem; 0054 class View; 0055 0056 class Package; 0057 0058 class PLAN_EXPORT MainDocument : public KoDocument 0059 { 0060 Q_OBJECT 0061 0062 public: 0063 explicit MainDocument(KoPart *part); 0064 ~MainDocument() override; 0065 0066 void initEmpty() override; 0067 0068 /// reimplemented from KoDocument 0069 QByteArray nativeFormatMimeType() const override { return PLAN_MIME_TYPE; } 0070 /// reimplemented from KoDocument 0071 QByteArray nativeOasisMimeType() const override { return ""; } 0072 /// reimplemented from KoDocument 0073 QStringList extraNativeMimeTypes() const override 0074 { 0075 return QStringList() << PLAN_MIME_TYPE; 0076 } 0077 0078 void setReadWrite(bool rw) override; 0079 void configChanged(); 0080 0081 void paintContent(QPainter& painter, const QRect& rect) override; 0082 0083 void setProject(Project *project); 0084 Project *project() const override { return m_project; } 0085 Project &getProject() { return *m_project; } 0086 const Project &getProject() const { return * m_project; } 0087 QString projectName() const override { return m_project->name(); } 0088 0089 /** 0090 * Return the set of SupportedSpecialFormats that the kplato wants to 0091 * offer in the "Save" file dialog. 0092 * Note: SaveEncrypted is not supported. 0093 */ 0094 int supportedSpecialFormats() const override { return SaveAsDirectoryStore; } 0095 0096 // The load and save functions. Look in the file kplato.dtd for info 0097 bool loadXML(const KoXmlDocument &document, KoStore *store) override; 0098 QDomDocument saveXML() override; 0099 /// Save a workpackage file containing @p node with schedule identity @p id, owned by @p resource 0100 QDomDocument saveWorkPackageXML(const Node *node, long id, Resource *resource = 0); 0101 0102 bool saveOdf(SavingContext &/*documentContext */) override { return false; } 0103 bool loadOdf(KoOdfReadStore & odfStore) override; 0104 0105 Config &config() { return m_config; } 0106 Context *context() const { return m_context; } 0107 0108 WBSDefinition &wbsDefinition() { return m_project->wbsDefinition(); } 0109 0110 const XMLLoaderObject &xmlLoader() const { return m_xmlLoader; } 0111 0112 DocumentChild *createChild(KoDocument *doc, const QRect &geometry = QRect()); 0113 0114 bool saveWorkPackageToStream(QIODevice * dev, const Node *node, long id, Resource *resource = 0); 0115 bool saveWorkPackageFormat(const QString &file, const Node *node, long id, Resource *resource = 0); 0116 bool saveWorkPackageUrl(const QUrl & _url, const Node *node, long id, Resource *resource = 0 ); 0117 0118 /// Load the workpackage from @p url into @p project. Return true if successful, else false. 0119 bool loadWorkPackage(Project &project, const QUrl &url); 0120 Package *loadWorkPackageXML(Project& project, QIODevice*, const KoXmlDocument& document, const QUrl& url); 0121 QMap<QDateTime, Package*> workPackages() const { return m_workpackages; } 0122 void clearWorkPackages() { 0123 qDeleteAll(m_workpackages); 0124 m_workpackages.clear(); 0125 m_checkingForWorkPackages = false; 0126 } 0127 0128 void insertFile(const QUrl &url, Node *parent, Node *after = 0); 0129 bool insertProject(Project &project, Node *parent, Node *after); 0130 bool mergeResources(Project &project); 0131 0132 bool extractFiles(KoStore *store, Package *package); 0133 bool extractFile(KoStore *store, Package *package, const Document *doc); 0134 0135 void registerView(View *view); 0136 0137 /// Create a new project from this project 0138 /// Generates new project id and task ids 0139 /// Keeps resource- and calendar ids 0140 void createNewProject(); 0141 0142 bool isTaskModule() const; 0143 0144 /** 0145 * Returns true during loading (openUrl can be asynchronous) 0146 */ 0147 bool isLoading() const override; 0148 0149 using KoDocument::setModified; 0150 public Q_SLOTS: 0151 void setModified(bool mod) override; 0152 0153 /// Inserts an item into all other views than @p view 0154 void insertViewListItem(KPlato::View *view, const KPlato::ViewListItem *item, const KPlato::ViewListItem *parent, int index); 0155 /// Removes the view list item from all other views than @p view 0156 void removeViewListItem(KPlato::View *view, const KPlato::ViewListItem *item); 0157 /// View selector has been modified 0158 void slotViewlistModified(); 0159 /// Check for workpackages 0160 /// If @p keep is true, packages that has been refused will not be checked for again 0161 void checkForWorkPackages(bool keep); 0162 /// Remove @p package 0163 void terminateWorkPackage(const KPlato::Package *package); 0164 0165 void setLoadingTemplate(bool); 0166 void setLoadingSharedResourcesTemplate(bool); 0167 0168 void insertResourcesFile(const QUrl &url, const QUrl &projects = QUrl()); 0169 void slotProjectCreated(); 0170 0171 /// Prepare for insertion of resource assignments of shared resources from the project(s) in @p urls 0172 void insertSharedProjects(const QList<QUrl> &urls); 0173 0174 /// Prepare for insertion of resource assignments of shared resources from the project(s) in @p url 0175 void insertSharedProjects(const QUrl &url); 0176 0177 /// Clear resource assignments of shared resources 0178 void clearResourceAssignments(); 0179 /// Load resource assignments of shared resources from the project(s) in @p url 0180 void loadResourceAssignments(QUrl url); 0181 0182 void setIsTaskModule(bool value); 0183 0184 void autoCheckForWorkPackages(); 0185 0186 Q_SIGNALS: 0187 void changed(); 0188 void workPackageLoaded(); 0189 void viewlistModified(bool); 0190 void viewListItemAdded(const KPlato::ViewListItem *item, const KPlato::ViewListItem *parent, int index); 0191 void viewListItemRemoved(const KPlato::ViewListItem *item); 0192 0193 void insertSharedProject(); 0194 0195 protected: 0196 /// Load kplato specific files 0197 bool completeLoading(KoStore* store) override; 0198 /// Save kplato specific files 0199 bool completeSaving(KoStore* store) override; 0200 0201 // used by insert file 0202 struct InsertFileInfo { 0203 QUrl url; 0204 Node *parent; 0205 Node *after; 0206 } m_insertFileInfo; 0207 0208 0209 protected Q_SLOTS: 0210 void slotViewDestroyed(); 0211 void addSchedulerPlugin(const QString&, KPlato::SchedulerPlugin *plugin); 0212 0213 void checkForWorkPackage(); 0214 0215 void insertFileCompleted(); 0216 void insertResourcesFileCompleted(); 0217 void insertFileCancelled(const QString&); 0218 0219 void slotInsertSharedProject(); 0220 void insertSharedProjectCompleted(); 0221 void insertSharedProjectCancelled(const QString&); 0222 0223 void slotNodeChanged(KPlato::Node*, int); 0224 void slotScheduleManagerChanged(KPlato::ScheduleManager *sm, int property); 0225 void setCalculationNeeded(); 0226 void slotCalculationFinished(KPlato::Project *project, KPlato::ScheduleManager *sm); 0227 void slotStartCalculation(); 0228 0229 void setTaskModulesWatch(); 0230 void taskModuleDirChanged(); 0231 0232 private: 0233 bool loadAndParse(KoStore* store, const QString& filename, KoXmlDocument& doc); 0234 0235 void loadSchedulerPlugins(); 0236 0237 private: 0238 Project *m_project; 0239 QWidget* m_parentWidget; 0240 0241 Config m_config; 0242 Context *m_context; 0243 0244 XMLLoaderObject m_xmlLoader; 0245 bool m_loadingTemplate; 0246 bool m_loadingSharedResourcesTemplate; 0247 0248 QMap<QString, SchedulerPlugin*> m_schedulerPlugins; 0249 QMap<QDateTime, Package*> m_workpackages; 0250 QFileInfoList m_infoList; 0251 QList<QUrl> m_skipUrls; 0252 QMap<QDateTime, Project*> m_mergedPackages; 0253 0254 QDomDocument m_reports; 0255 0256 bool m_viewlistModified; 0257 bool m_checkingForWorkPackages; 0258 0259 QList<QPointer<View> > m_views; 0260 0261 bool m_loadingSharedProject; 0262 QList<QUrl> m_sharedProjectsFiles; 0263 bool m_skipSharedProjects; 0264 0265 bool m_isLoading; 0266 0267 bool m_isTaskModule; 0268 0269 KUndo2Command* m_calculationCommand; 0270 ScheduleManager* m_currentCalculationManager; 0271 ScheduleManager* m_nextCalculationManager; 0272 0273 KDirWatch *m_taskModulesWatch; 0274 }; 0275 0276 0277 } //KPlato namespace 0278 0279 #endif