~ubuntu-branches/debian/sid/calligraplan/sid

« back to all changes in this revision

Viewing changes to src/kptcontext.cpp

  • Committer: Package Import Robot
  • Author(s): Pino Toscano
  • Date: 2018-02-01 18:20:19 UTC
  • Revision ID: package-import@ubuntu.com-20180201182019-1qo7qaim5wejm5k9
Tags: upstream-3.1.0
ImportĀ upstreamĀ versionĀ 3.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2005, 2007, 2011 Dag Andersen <danders@get2net.dk>
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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.
 
18
*/
 
19
 
 
20
#include "kptcontext.h"
 
21
#include "kptview.h"
 
22
#include "kptdebug.h"
 
23
 
 
24
#include <QDomDocument>
 
25
 
 
26
namespace KPlato
 
27
{
 
28
 
 
29
Context::Context()
 
30
    : currentEstimateType(0),
 
31
      currentSchedule(0),
 
32
      m_contextLoaded( false )
 
33
{
 
34
    ganttview.ganttviewsize = -1;
 
35
    ganttview.taskviewsize = -1;
 
36
 
 
37
    accountsview.accountsviewsize = -1;
 
38
    accountsview.periodviewsize = -1;
 
39
 
 
40
 
 
41
}
 
42
 
 
43
Context::~Context() {
 
44
}
 
45
 
 
46
const KoXmlElement &Context::context() const
 
47
{
 
48
    return m_context;
 
49
}
 
50
 
 
51
bool Context::setContent( const QString &str )
 
52
{
 
53
    KoXmlDocument doc;
 
54
    if ( doc.setContent( str ) ) {
 
55
        return load( doc );
 
56
    }
 
57
    return false;
 
58
}
 
59
 
 
60
bool Context::load( const KoXmlDocument &document ) {
 
61
    m_document = document; // create a copy, document is deleted under our feet
 
62
 
 
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." ) );
 
69
        return false;
 
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...
 
73
        } else {
 
74
            errorPlan << "Unknown mime type " << value;
 
75
//        setErrorMessage( i18n( "Invalid document. Expected mimetype application/x-vnd.kde.kplato, got %1", value ) );
 
76
            return false;
 
77
        }
 
78
    }
 
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" );
 
87
            return false;
 
88
        }
 
89
    }
 
90
*/
 
91
/*
 
92
#ifdef KOXML_USE_QDOM
 
93
    int numNodes = elm.childNodes().count();
 
94
#else
 
95
    int numNodes = elm.childNodesCount();
 
96
#endif
 
97
*/
 
98
    KoXmlNode n = elm.firstChild();
 
99
    for ( ; ! n.isNull(); n = n.nextSibling() ) {
 
100
        if ( ! n.isElement() ) {
 
101
            continue;
 
102
        }
 
103
        KoXmlElement element = n.toElement();
 
104
        if ( element.tagName() == "context" ) {
 
105
            m_context = element;
 
106
            m_contextLoaded = true;
 
107
        }
 
108
    }
 
109
    return true;
 
110
}
 
111
 
 
112
QDomDocument Context::save( const View *view ) const {
 
113
    QDomDocument document( "plan.context" );
 
114
 
 
115
    document.appendChild( document.createProcessingInstruction(
 
116
                              "xml",
 
117
                              "version=\"1.0\" encoding=\"UTF-8\"" ) );
 
118
 
 
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 );
 
124
 
 
125
    QDomElement e = doc.ownerDocument().createElement("context");
 
126
    doc.appendChild( e );
 
127
    view->saveContext( e );
 
128
 
 
129
    return document;
 
130
}
 
131
 
 
132
}  //KPlato namespace