1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org>
3 Copyright (C) 2004 - 2010 Dag Andersen <danders@get2net.dk>
4 Copyright (C) 2006 Raphael Langerhorst <raphael.langerhorst@kdemail.net>
5 Copyright (C) 2007 Thorsten Zachmann <zachmann@kde.org>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20* Boston, MA 02110-1301, USA.
21*/
22
23#ifndef KPTMAINDOCUMENT_H
24#define KPTMAINDOCUMENT_H
25
26#include "kplato_export.h"
27
28#include "kpttask.h"
29#include "kptconfig.h"
30#include "kptwbsdefinition.h"
31#include "kptxmlloaderobject.h"
32#include "about/aboutpage.h"
33
34#include "KoDocument.h"
35
36#include <QFileInfo>
37
38#include <kdialog.h>
39
40class KoView;
41
42#define PLAN_MIME_TYPE "application/x-vnd.kde.plan"
43
44/// The main namespace.
45namespace KPlato
46{
47
48class DocumentChild;
49class Project;
50class Context;
51class GanttView;
52class SchedulerPlugin;
53class ViewListItem;
54class View;
55
56class Package;
57
58class KPLATO_EXPORT MainDocument : public KoDocument
59{
60 Q_OBJECT
61
62public:
63 explicit MainDocument(KoPart *part);
64 ~MainDocument();
65
66
67 /// reimplemented from KoDocument
68 virtual QByteArray nativeFormatMimeType() const { return PLAN_MIME_TYPE; }
69 /// reimplemented from KoDocument
70 virtual QByteArray nativeOasisMimeType() const { return ""; }
71 /// reimplemented from KoDocument
72 virtual QStringList extraNativeMimeTypes() const
73 {
74 return QStringList() << PLAN_MIME_TYPE;
75 }
76
77 void setReadWrite( bool rw );
78 void configChanged();
79
80 virtual void paintContent( QPainter& painter, const QRect& rect);
81
82 void setProject( Project *project );
83 Project &getProject() { return *m_project; }
84 const Project &getProject() const { return * m_project; }
85
86 /**
87 * Return the set of SupportedSpecialFormats that the kplato wants to
88 * offer in the "Save" file dialog.
89 * Note: SaveEncrypted is not supported.
90 */
91 virtual int supportedSpecialFormats() const { return SaveAsDirectoryStore; }
92
93 // The load and save functions. Look in the file kplato.dtd for info
94 virtual bool loadXML( const KoXmlDocument &document, KoStore *store );
95 virtual QDomDocument saveXML();
96 /// Save a workpackage file containing @p node with schedule identity @p id, owned by @p resource
97 QDomDocument saveWorkPackageXML( const Node *node, long id, Resource *resource = 0 );
98
99 bool saveOdf( SavingContext &/*documentContext */) { return false; }
100 bool loadOdf( KoOdfReadStore & odfStore );
101
102 Config &config() { return m_config; }
103 Context *context() const { return m_context; }
104
105 WBSDefinition &wbsDefinition() { return m_project->wbsDefinition(); }
106
107 const XMLLoaderObject &xmlLoader() const { return m_xmlLoader; }
108
109 DocumentChild *createChild( KoDocument *doc, const QRect &geometry = QRect() );
110
111 bool saveWorkPackageToStream( QIODevice * dev, const Node *node, long id, Resource *resource = 0 );
112 bool saveWorkPackageFormat( const QString &file, const Node *node, long id, Resource *resource = 0 );
113 bool saveWorkPackageUrl( const KUrl & _url, const Node *node, long id, Resource *resource = 0 );
114 void mergeWorkPackages();
115 void mergeWorkPackage( const Package *package );
116 void terminateWorkPackage( const Package *package );
117
118 /// Load the workpackage from @p url into @p project. Return true if successful, else false.
119 bool loadWorkPackage( Project &project, const KUrl &url );
120 Package *loadWorkPackageXML( Project& project, QIODevice*, const KoXmlDocument& document, const KUrl& url );
121 QMap<KDateTime, Package*> workPackages() const { return m_workpackages; }
122
123 void insertFile( const QString &filename, Node *parent, Node *after = 0 );
124 bool insertProject( Project &project, Node *parent, Node *after );
125
126 KPlatoAboutPage &aboutPage() { return m_aboutPage; }
127
128 bool extractFiles( KoStore *store, Package *package );
129 bool extractFile( KoStore *store, Package *package, const Document *doc );
130
131 void registerView( View *view );
132
133 /// Create a new project from this project
134 /// Generates new project id and task ids
135 /// Keeps resource- and calendar ids
136 void createNewProject();
137
138 using KoDocument::setModified;
139public slots:
140 void setModified( bool mod );
141
142 /// Inserts an item into all other views than @p view
143 void insertViewListItem( View *view, const ViewListItem *item, const ViewListItem *parent, int index );
144 /// Removes the view list item from all other views than @p view
145 void removeViewListItem( View *view, const ViewListItem *item );
146 /// View selector has been modified
147 void viewlistModified();
148 /// Check for workpackages
149 /// If @p keep is true, packages that has been refused will not be checked for again
150 void checkForWorkPackages( bool keep = false );
151
152 void setLoadingTemplate( bool );
153
154signals:
155 void changed();
156 void workPackageLoaded();
157 void viewlistModified( bool );
158 void viewListItemAdded(const ViewListItem *item, const ViewListItem *parent, int index);
159 void viewListItemRemoved(const ViewListItem *item);
160
161protected:
162 /// Load kplato specific files
163 virtual bool completeLoading( KoStore* store );
164 /// Save kplato specific files
165 virtual bool completeSaving( KoStore* store );
166
167 void mergeWorkPackage( Task *to, const Task *from, const Package *package );
168
169 // used by insert file
170 struct InsertFileInfo {
171 QString url;
172 Node *parent;
173 Node *after;
174 } m_insertFileInfo;
175
176
177protected slots:
178 void slotViewDestroyed();
179 void addSchedulerPlugin( const QString&, SchedulerPlugin *plugin );
180
181 void autoCheckForWorkPackages();
182 void checkForWorkPackage();
183
184 void insertFileCompleted();
185 void insertFileCancelled( const QString& );
186
187 void workPackageMergeDialogFinished( int result );
188
189private:
190 bool loadAndParse(KoStore* store, const QString& filename, KoXmlDocument& doc);
191
192 void loadSchedulerPlugins();
193
194private:
195 Project *m_project;
196 QWidget* m_parentWidget;
197
198 Config m_config;
199 Context *m_context;
200
201 XMLLoaderObject m_xmlLoader;
202 bool m_loadingTemplate;
203
204 QMap<QString, SchedulerPlugin*> m_schedulerPlugins;
205 QMap<KDateTime, Package*> m_workpackages;
206 QFileInfoList m_infoList;
207 QMap<KDateTime, Project*> m_mergedPackages;
208
209 KPlatoAboutPage m_aboutPage;
210
211 QDomDocument m_reports;
212
213 bool m_viewlistModified;
214 bool m_checkingForWorkPackages;
215
216 QList<QPointer<View> > m_views;
217};
218
219
220} //KPlato namespace
221
222#endif
223