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.hxx>
13 
14 namespace oox::ppt
15 {
17 {
18  for (auto const& author : list.cmAuthorLst)
19  {
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;
28  }
29 }
30 
31 //DateTime is saved as : 2013-01-10T15:53:26.000
32 void Comment::setDateTime(const OUString& sDateTime)
33 {
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)
47  {
48  aDateTime.NanoSeconds = 0;
49  ++aDateTime.Seconds;
50  }
51  if (aDateTime.Seconds == secondsOverflow)
52  {
53  aDateTime.Seconds = 0;
54  ++aDateTime.Minutes;
55  }
56  if (aDateTime.Minutes == 60)
57  {
58  aDateTime.Minutes = 0;
59  ++aDateTime.Hours;
60  }
61  // if overflow goes into date, I give up
62 }
63 
65 {
66  const sal_Int32 nId = authorId.toInt32();
67  for (auto const& author : list.cmAuthorLst)
68  {
69  if (author.id.toInt32() == nId)
70  return author.name;
71  }
72  return "Anonymous";
73 }
74 
76 {
77  if (index >= static_cast<int>(cmLst.size()) || index < 0)
78  throw css::lang::IllegalArgumentException();
79 
80  return cmLst.at(index);
81 }
82 }
83 
84 /* 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:64
std::vector< CommentAuthor > cmAuthorLst
Definition: comments.hxx:34
const Comment & getCommentAtIndex(int index)
Definition: comments.cxx:75
void setValues(const CommentAuthorList &list)
Definition: comments.cxx:16
void setDateTime(const OUString &datetime)
Definition: comments.cxx:32
css::util::DateTime aDateTime
Definition: comments.hxx:56