/src/libreoffice/oox/source/ppt/comments.cxx
Line | Count | Source |
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 | | #include <o3tl/safeint.hxx> |
15 | | #include <o3tl/string_view.hxx> |
16 | | |
17 | | namespace oox::ppt |
18 | | { |
19 | | void CommentAuthorList::setValues(const CommentAuthorList& list) |
20 | 44 | { |
21 | 44 | for (auto const& author : list.cmAuthorLst) |
22 | 27 | { |
23 | 27 | CommentAuthor commentAuthor; |
24 | 27 | commentAuthor.clrIdx = author.clrIdx; |
25 | 27 | commentAuthor.id = author.id; |
26 | 27 | commentAuthor.initials = author.initials; |
27 | 27 | commentAuthor.lastIdx = author.lastIdx; |
28 | 27 | commentAuthor.name = author.name; |
29 | 27 | cmAuthorLst.push_back(commentAuthor); |
30 | 27 | } |
31 | 44 | } |
32 | | |
33 | | //DateTime is saved as : 2013-01-10T15:53:26.000 |
34 | | void Comment::setDateTime(const OUString& sDateTime) |
35 | 47 | { |
36 | 47 | sal_Int32 nIdx{ 0 }; |
37 | 47 | aDateTime.Year = o3tl::toInt32(o3tl::getToken(sDateTime, 0, '-', nIdx)); |
38 | 47 | aDateTime.Month = o3tl::toUInt32(o3tl::getToken(sDateTime, 0, '-', nIdx)); |
39 | 47 | aDateTime.Day = o3tl::toUInt32(o3tl::getToken(sDateTime, 0, 'T', nIdx)); |
40 | 47 | aDateTime.Hours = o3tl::toUInt32(o3tl::getToken(sDateTime, 0, ':', nIdx)); |
41 | 47 | aDateTime.Minutes = o3tl::toUInt32(o3tl::getToken(sDateTime, 0, ':', nIdx)); |
42 | 47 | double seconds = rtl_math_uStringToDouble(sDateTime.getStr() + nIdx, |
43 | 47 | sDateTime.getStr() + sDateTime.getLength(), '.', 0, |
44 | 47 | nullptr, nullptr); |
45 | 47 | aDateTime.Seconds = floor(seconds); |
46 | 47 | seconds -= aDateTime.Seconds; |
47 | 47 | aDateTime.NanoSeconds = ::rtl::math::round(seconds * 1000000000); |
48 | 47 | const int secondsOverflow = (aDateTime.Seconds == 60) ? 61 : 60; |
49 | | // normalise time part of aDateTime |
50 | 47 | if (aDateTime.NanoSeconds == 1000000000) |
51 | 0 | { |
52 | 0 | aDateTime.NanoSeconds = 0; |
53 | 0 | ++aDateTime.Seconds; |
54 | 0 | } |
55 | 47 | if (aDateTime.Seconds == secondsOverflow) |
56 | 0 | { |
57 | 0 | aDateTime.Seconds = 0; |
58 | 0 | ++aDateTime.Minutes; |
59 | 0 | } |
60 | 47 | if (aDateTime.Minutes == 60) |
61 | 0 | { |
62 | 0 | aDateTime.Minutes = 0; |
63 | 0 | ++aDateTime.Hours; |
64 | 0 | } |
65 | | // if overflow goes into date, I give up |
66 | 47 | } |
67 | | |
68 | | OUString Comment::getAuthor(const CommentAuthorList& list) |
69 | 47 | { |
70 | 47 | const sal_Int32 nId = authorId.toInt32(); |
71 | 47 | for (auto const& author : list.cmAuthorLst) |
72 | 23 | { |
73 | 23 | if (author.id.toInt32() == nId) |
74 | 22 | return author.name; |
75 | 23 | } |
76 | 25 | return u"Anonymous"_ustr; |
77 | 47 | } |
78 | | |
79 | | OUString Comment::getInitials(const CommentAuthorList& list) |
80 | 47 | { |
81 | 47 | const sal_Int32 nId = authorId.toInt32(); |
82 | 47 | for (auto const& author : list.cmAuthorLst) |
83 | 23 | { |
84 | 23 | if (author.id.toInt32() == nId) |
85 | 22 | return author.initials; |
86 | 23 | } |
87 | 25 | return u"A"_ustr; |
88 | 47 | } |
89 | | |
90 | | const Comment& CommentList::getCommentAtIndex(int index) |
91 | 47 | { |
92 | 47 | if (index < 0 || o3tl::make_unsigned(index) >= cmLst.size()) |
93 | 0 | throw css::lang::IllegalArgumentException(); |
94 | | |
95 | 47 | return cmLst.at(index); |
96 | 47 | } |
97 | | } |
98 | | |
99 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |