Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / oox / source / ppt / comments.cxx
blob483a2a8f0d4d05ff1d59b0a9e676a47ccf99b2e4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <oox/ppt/comments.hxx>
11 #include <com/sun/star/lang/IllegalArgumentException.hpp>
12 #include <rtl/math.hxx>
14 namespace oox { namespace ppt {
16 void CommentAuthorList::setValues(const CommentAuthorList& list)
18 for (auto const& author : list.cmAuthorLst)
20 CommentAuthor temp;
21 // TODO JNA : why not doing push_back at the end instead of using back()?
22 cmAuthorLst.push_back(temp);
23 cmAuthorLst.back().clrIdx = author.clrIdx;
24 cmAuthorLst.back().id = author.id;
25 cmAuthorLst.back().initials = author.initials;
26 cmAuthorLst.back().lastIdx = author.lastIdx;
27 cmAuthorLst.back().name = author.name;
31 //DateTime is saved as : 2013-01-10T15:53:26.000
32 void Comment::setDateTime (const OUString& sDateTime)
34 sal_Int32 nIdx{ 0 };
35 aDateTime.Year = sDateTime.getToken(0, '-', nIdx).toInt32();
36 aDateTime.Month = sDateTime.getToken(0, '-', nIdx).toUInt32();
37 aDateTime.Day = sDateTime.getToken(0, 'T', nIdx).toUInt32();
38 aDateTime.Hours = sDateTime.getToken(0, ':', nIdx).toUInt32();
39 aDateTime.Minutes = sDateTime.getToken(0, ':', nIdx).toUInt32();
40 double seconds = sDateTime.copy(nIdx).toDouble();
41 aDateTime.Seconds = floor(seconds);
42 seconds -= aDateTime.Seconds;
43 aDateTime.NanoSeconds = ::rtl::math::round(seconds * 1000000000);
44 const int secondsOverflow = (aDateTime.Seconds == 60) ? 61 : 60;
45 // normalise time part of aDateTime
46 if (aDateTime.NanoSeconds == 1000000000)
48 aDateTime.NanoSeconds = 0;
49 ++aDateTime.Seconds;
51 if (aDateTime.Seconds == secondsOverflow)
53 aDateTime.Seconds = 0;
54 ++aDateTime.Minutes;
56 if (aDateTime.Minutes == 60)
58 aDateTime.Minutes = 0;
59 ++aDateTime.Hours;
61 // if overflow goes into date, I give up
64 OUString Comment::getAuthor ( const CommentAuthorList& list )
66 const sal_Int32 nId = authorId.toInt32();
67 for (auto const& author : list.cmAuthorLst)
69 if(author.id.toInt32() == nId)
70 return author.name;
72 return "Anonymous";
75 const Comment& CommentList::getCommentAtIndex (int index)
77 if(index >= static_cast<int>(cmLst.size()) || index < 0)
78 throw css::lang::IllegalArgumentException();
80 return cmLst.at(index)
84 } }
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */