~smartboyhw/ubuntu/raring/calligra/2.6.0-0ubuntu1

« back to all changes in this revision

Viewing changes to plugins/variables/DateVariable.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-07-16 10:51:29 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20120716105129-es1ebubwiwlsfvv0
Tags: 1:2.4.92-0ubuntu1
New upstream RC release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* This file is part of the KDE project
2
2
 * Copyright (C) 2006-2007 Thomas Zander <zander@kde.org>
3
3
 * Copyright (C) 2008,2010 Thorsten Zachmann <zachmann@kde.org>
 
4
 * Copyright 2012 Friedrich W. H. Kossebau <kossebau@kde.org>
4
5
 *
5
6
 * This library is free software; you can redistribute it and/or
6
7
 * modify it under the terms of the GNU Library General Public
29
30
#include <KoShapeSavingContext.h>
30
31
#include <KoOdfLoadingContext.h>
31
32
#include <KoOdfStylesReader.h>
 
33
#include <KoOdfWorkaround.h>
32
34
 
33
35
DateVariable::DateVariable(DateType type)
34
36
        : KoVariable()
35
37
        , m_type(type)
36
38
        , m_displayType(Date)
 
39
        , m_valueType(DateTime)
37
40
        , m_daysOffset(0)
38
41
        , m_monthsOffset(0)
39
42
        , m_yearsOffset(0)
40
43
        , m_secsOffset(0)
41
44
{
42
 
    m_time = QDateTime::currentDateTime();
 
45
    m_datetime = QDateTime::currentDateTime();
43
46
}
44
47
 
45
48
DateVariable::~DateVariable()
63
66
 
64
67
    if (m_type == Fixed) {
65
68
        writer->addAttribute("text:fixed", "true");
 
69
        // only write as much information as we read: just date/time or datetime
66
70
        if (m_displayType == Time) {
67
 
            // if only the time is set QDateTime::toString returns an empty so add the data by hand
68
 
            writer->addAttribute("text:time-value", "0-00-00T" + m_time.time().toString(Qt::ISODate));
 
71
            const QString timeValue = (m_valueType == DateTime) ?
 
72
                m_datetime.toString(Qt::ISODate) :
 
73
                m_datetime.time().toString(Qt::ISODate);
 
74
            writer->addAttribute("text:time-value", timeValue);
69
75
        } else {
70
 
            writer->addAttribute("text:date-value", m_time.toString(Qt::ISODate));
 
76
            const QString dateValue = (m_valueType == DateTime) ?
 
77
                m_datetime.toString(Qt::ISODate) :
 
78
                m_datetime.date().toString(Qt::ISODate);
 
79
            writer->addAttribute("text:date-value", dateValue);
71
80
        }
72
81
    } else {
73
82
        writer->addAttribute("text:fixed", "false");
95
104
        m_type = AutoUpdate;
96
105
    }
97
106
 
 
107
    if (localName == "time") {
 
108
        m_displayType = Time;
 
109
    } else {
 
110
        m_displayType = Date;
 
111
    }
 
112
 
98
113
    //dateProperties.setProperty("time", element.attributeNS(KoXmlNS::text, localName + "-value"));
99
114
    QString value(element.attributeNS(KoXmlNS::text, localName + "-value", ""));
100
115
    if (!value.isEmpty()) {
101
 
        if (value.startsWith("0-00-00T")) {
102
 
            value.prepend("000");
 
116
#ifndef NWORKAROUND_ODF_BUGS
 
117
        KoOdfWorkaround::fixBadDateForTextTime(value);
 
118
#endif
 
119
        // hopefully this simple detection works in all cases
 
120
        const bool isDateTime = (value.indexOf(QLatin1Char('T')) != -1);
 
121
 
 
122
        if (isDateTime) {
 
123
            m_datetime = QDateTime::fromString(value, Qt::ISODate);
 
124
            m_valueType = DateTime;
 
125
        } else {
 
126
            if (m_displayType == Time) {
 
127
                const QTime time = QTime::fromString(value, Qt::ISODate);
 
128
                m_datetime = QDateTime(QDate::currentDate(), time);
 
129
            } else {
 
130
                const QDate date = QDate::fromString(value, Qt::ISODate);
 
131
                m_datetime = QDateTime(date);
 
132
            }
 
133
            m_valueType = DateOrTime;
103
134
        }
104
 
        m_time = QDateTime::fromString(value, Qt::ISODate);
105
135
    } else {
106
136
        // if value is not set current time is assumed  ODF 19.881 text:time-value
107
137
        m_type = AutoUpdate;
110
140
    //dateProperties.setProperty("definition", dateFormat);
111
141
    m_definition = dateFormat;
112
142
 
113
 
    if (localName == "time") {
114
 
        m_displayType = Time;
115
 
    } else {
116
 
        m_displayType = Date;
117
 
    }
118
 
 
119
143
    //dateProperties.setProperty("adjust", element.attributeNS(KoXmlNS::text, localName + "-adjust"));
120
144
    const QString adjust(element.attributeNS(KoXmlNS::text, localName + "-adjust", ""));
121
145
    adjustTime(adjust);
127
151
{
128
152
    m_definition = props->stringProperty("definition");
129
153
    if (!props->stringProperty("time").isEmpty())
130
 
        m_time = QDateTime::fromString(props->stringProperty("time"), Qt::ISODate);
 
154
        m_datetime = QDateTime::fromString(props->stringProperty("time"), Qt::ISODate);
131
155
    if (props->intProperty("id") == Fixed)
132
156
        m_type = Fixed;
133
157
    else
139
163
    else {
140
164
        m_displayType = Date;
141
165
    }
 
166
    m_valueType = DateTime;
142
167
    adjustTime(props->stringProperty("adjust"));
143
168
    update();
144
169
}
188
213
    QDateTime target;
189
214
    switch (m_type) {
190
215
    case Fixed:
191
 
        target = m_time;
 
216
        target = m_datetime;
192
217
        break;
193
218
    case AutoUpdate:
194
219
        target = QDateTime::currentDateTime();