LibreOffice Module oox (master)  1
comments.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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  */
9 
10 #include <oox/ppt/comments.hxx>
11 #include <com/sun/star/lang/IllegalArgumentException.hpp>
12 #include <rtl/math.h>
13 #include <rtl/math.hxx>
14 
15 namespace oox::ppt
16 {
18 {
19  for (auto const& author : list.cmAuthorLst)
20  {
21  CommentAuthor temp;
22  // TODO JNA : why not doing push_back at the end instead of using back()?
23  cmAuthorLst.push_back(temp);
24  cmAuthorLst.back().clrIdx = author.clrIdx;
25  cmAuthorLst.back().id = author.id;
26  cmAuthorLst.back().initials = author.initials;
27  cmAuthorLst.back().lastIdx = author.lastIdx;
28  cmAuthorLst.back().name = author.name;
29  }
30 }
31 
32 //DateTime is saved as : 2013-01-10T15:53:26.000
33 void Comment::setDateTime(const OUString& sDateTime)
34 {
35  sal_Int32 nIdx{ 0 };
36  aDateTime.Year = sDateTime.getToken(0, '-', nIdx).toInt32();
37  aDateTime.Month = sDateTime.getToken(0, '-', nIdx).toUInt32();
38  aDateTime.Day = sDateTime.getToken(0, 'T', nIdx).toUInt32();
39  aDateTime.Hours = sDateTime.getToken(0, ':', nIdx).toUInt32();
40  aDateTime.Minutes = sDateTime.getToken(0, ':', nIdx).toUInt32();
41  double seconds = rtl_math_uStringToDouble(sDateTime.getStr() + nIdx,
42  sDateTime.getStr() + sDateTime.getLength(), '.', 0,
43  nullptr, nullptr);
44  aDateTime.Seconds = floor(seconds);
45  seconds -= aDateTime.Seconds;
46  aDateTime.NanoSeconds = ::rtl::math::round(seconds * 1000000000);
47  const int secondsOverflow = (aDateTime.Seconds == 60) ? 61 : 60;
48  // normalise time part of aDateTime
49  if (aDateTime.NanoSeconds == 1000000000)
50  {
51  aDateTime.NanoSeconds = 0;
52  ++aDateTime.Seconds;
53  }
54  if (aDateTime.Seconds == secondsOverflow)
55  {
56  aDateTime.Seconds = 0;
57  ++aDateTime.Minutes;
58  }
59  if (aDateTime.Minutes == 60)
60  {
61  aDateTime.Minutes = 0;
62  ++aDateTime.Hours;
63  }
64  // if overflow goes into date, I give up
65 }
66 
68 {
69  const sal_Int32 nId = authorId.toInt32();
70  for (auto const& author : list.cmAuthorLst)
71  {
72  if (author.id.toInt32() == nId)
73  return author.name;
74  }
75  return "Anonymous";
76 }
77 
79 {
80  if (index >= static_cast<int>(cmLst.size()) || index < 0)
81  throw css::lang::IllegalArgumentException();
82 
83  return cmLst.at(index);
84 }
85 }
86 
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString authorId
Definition: comments.hxx:50
std::vector< Comment > cmLst
Definition: comments.hxx:105
sal_Int16 nId
Definition: olehelper.cxx:97
OUString getAuthor(const CommentAuthorList &list)
Definition: comments.cxx:67
std::vector< CommentAuthor > cmAuthorLst
Definition: comments.hxx:34
const Comment & getCommentAtIndex(int index)
Definition: comments.cxx:78
void setValues(const CommentAuthorList &list)
Definition: comments.cxx:17
void setDateTime(const OUString &datetime)
Definition: comments.cxx:33
css::util::DateTime aDateTime
Definition: comments.hxx:56