From kde-commits Fri Feb 12 17:12:27 2010 From: Boudewijn Rempt Date: Fri, 12 Feb 2010 17:12:27 +0000 To: kde-commits Subject: koffice/kpresenter Message-Id: <1265994747.179944.22158.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=126599475608591 SVN commit 1089204 by rempt: Start implementing date/time for presentations M +52 -8 part/KPrDeclarations.cpp M +22 -21 part/KPrDeclarations.h M +3 -0 plugins/variable/PresentationVariable.cpp --- trunk/koffice/kpresenter/part/KPrDeclarations.cpp #1089203:1089204 @@ -22,12 +22,16 @@ * Boston, MA 02110-1301, USA. */ #include "KPrDeclarations.h" - +#include +#include #include #include #include #include #include +#include +#include +#include KPrDeclarations::KPrDeclarations() { @@ -53,9 +57,25 @@ m_declarations[Footer].insert(name, element.text()); } else if(element.tagName() == "date-time-decl") { - const QString name = element.attributeNS(KoXmlNS::presentation, "name", QString()); - m_declarations[DateTime].insert(name, element.text()); - // TODO needs more work there are other attributes to keep. + QMap data; + data["name"] = element.attributeNS(KoXmlNS::presentation, "name", QString()); + data["fixed"] = element.attributeNS(KoXmlNS::presentation, "source", "fixed") == "fixed"; + + QString styleName = element.attributeNS(KoXmlNS::style, "data-style-name", ""); + if (!styleName.isEmpty()) { + KoOdfStylesReader::DataFormatsMap::const_iterator it = context.odfLoadingContext().stylesReader().dataFormats().constFind(styleName); + if (it != context.odfLoadingContext().stylesReader().dataFormats().constEnd()) { + + QString formatString = (*it).prefix + (*it).formatStr + (*it).suffix; + data["format"] = formatString; + } + } + else { + data["format"] = QString(""); + data["fixed value"] = element.text(); + } + + } } else if (element.tagName() == "page" && element.namespaceURI() == KoXmlNS::draw) { @@ -76,9 +96,9 @@ */ KoXmlWriter &writer(paContext.xmlWriter()); - QHash >::const_iterator typeIt(m_declarations.constBegin()); + QHash >::const_iterator typeIt(m_declarations.constBegin()); for (; typeIt != m_declarations.constEnd(); ++typeIt) { - QHash::const_iterator keyIt(typeIt.value().begin()); + QHash::const_iterator keyIt(typeIt.value().begin()); for (; keyIt != typeIt.value().constEnd(); ++keyIt) { switch (typeIt.key()) { case Footer: @@ -97,7 +117,7 @@ //TODO } else { - writer.addTextNode(keyIt.value()); + writer.addTextNode(keyIt.value().value()); } writer.endElement(); } @@ -107,5 +127,29 @@ const QString KPrDeclarations::declaration(Type type, const QString &key) { - return m_declarations.value(type).value(key); + QString retVal; + if (type == DateTime) { + QMap dateTimeDefinition = + m_declarations.value(type).value(key).value >(); + + if (dateTimeDefinition["fixed"].toBool()) { + retVal = dateTimeDefinition["fixed value"].toString(); + } + else { + QDateTime target = QDateTime::currentDateTime(); + + QString formatString = dateTimeDefinition["format"].toString(); + if (!formatString.isEmpty()) { + retVal = target.toString(formatString); + } + else { + // XXX: What do we do here? + retVal = target.date().toString(Qt::ISODate); + } + } + } + else { + retVal = m_declarations.value(type).value(key).toString(); + } + return retVal; } --- trunk/koffice/kpresenter/part/KPrDeclarations.h #1089203:1089204 @@ -1,30 +1,31 @@ /* This file is part of the KDE project -* Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -* -* Contact: Amit Aggarwal -* + * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). + * Contact: Amit Aggarwal + * + * Copyright (C) 2010 Thorsten Zachmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU Library General Public -* License as published by the Free Software Foundation; either -* version 2 of the License, or (at your option) any later version. - -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* Library General Public License for more details. - -* You should have received a copy of the GNU Library General Public License -* along with this library; see the file COPYING.LIB. If not, write to -* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301, USA. -*/ - #ifndef KPRDECLARATIONS_H #define KPRDECLARATIONS_H #include #include +#include class KoXmlElement; class KoPALoadingContext; @@ -72,7 +73,7 @@ const QString declaration(Type type, const QString &key); private: - QHash > m_declarations; + QHash > m_declarations; }; #endif /* KPRDECLARATIONS_H */ --- trunk/koffice/kpresenter/plugins/variable/PresentationVariable.cpp #1089203:1089204 @@ -53,6 +53,9 @@ case 2: m_type = KPrDeclarations::Footer; break; + case 3: + m_type = KPrDeclarations::DateTime; + break; default: Q_ASSERT(false); break;