1
/* This file is part of the KDE project
2
Copyright (C) 2005, 2007, 2011 Dag Andersen <danders@get2net.dk>
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; either
7
version 2 of the License, or (at your option) any later version.
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.
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.
20
#include "kptcontext.h"
24
#include <QDomDocument>
30
: currentEstimateType(0),
32
m_contextLoaded( false )
34
ganttview.ganttviewsize = -1;
35
ganttview.taskviewsize = -1;
37
accountsview.accountsviewsize = -1;
38
accountsview.periodviewsize = -1;
46
const KoXmlElement &Context::context() const
51
bool Context::setContent( const QString &str )
54
if ( doc.setContent( str ) ) {
60
bool Context::load( const KoXmlDocument &document ) {
61
m_document = document; // create a copy, document is deleted under our feet
63
// Check if this is the right app
64
KoXmlElement elm = m_document.documentElement();
65
QString value = elm.attribute( "mime", QString() );
66
if ( value.isEmpty() ) {
67
errorPlan << "No mime type specified!";
68
// setErrorMessage( i18n( "Invalid document. No mimetype specified." ) );
70
} else if ( value != "application/x-vnd.kde.plan" ) {
71
if ( value == "application/x-vnd.kde.kplato" ) {
72
// accept, since we forgot to change kplato to plan for so long...
74
errorPlan << "Unknown mime type " << value;
75
// setErrorMessage( i18n( "Invalid document. Expected mimetype application/x-vnd.kde.kplato, got %1", value ) );
79
/* QString m_syntaxVersion = elm.attribute( "version", "0.0" );
80
if ( m_syntaxVersion > "0.0" ) {
81
KMessageBox::ButtonCode ret = KMessageBox::warningContinueCancel(
82
0, i18n( "This document was created with a newer version of Plan (syntax version: %1)\n"
83
"Opening it in this version of Plan will lose some information.", m_syntaxVersion ),
84
i18n( "File-Format Mismatch" ), KGuiItem( i18n( "Continue" ) ) );
85
if ( ret == KMessageBox::Cancel ) {
86
setErrorMessage( "USER_CANCELED" );
93
int numNodes = elm.childNodes().count();
95
int numNodes = elm.childNodesCount();
98
KoXmlNode n = elm.firstChild();
99
for ( ; ! n.isNull(); n = n.nextSibling() ) {
100
if ( ! n.isElement() ) {
103
KoXmlElement element = n.toElement();
104
if ( element.tagName() == "context" ) {
106
m_contextLoaded = true;
112
QDomDocument Context::save( const View *view ) const {
113
QDomDocument document( "plan.context" );
115
document.appendChild( document.createProcessingInstruction(
117
"version=\"1.0\" encoding=\"UTF-8\"" ) );
119
QDomElement doc = document.createElement( "context" );
120
doc.setAttribute( "editor", "Plan" );
121
doc.setAttribute( "mime", "application/x-vnd.kde.plan" );
122
doc.setAttribute( "version", QString::number(0.0) );
123
document.appendChild( doc );
125
QDomElement e = doc.ownerDocument().createElement("context");
126
doc.appendChild( e );
127
view->saveContext( e );