1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "cmdmailmsg.hxx"
22 using com::sun::star::container::NoSuchElementException
;
23 using com::sun::star::container::XNameAccess
;
25 using namespace com::sun::star::uno
;
28 void SAL_CALL
CmdMailMsg::setBody( const OUString
& aBody
)
30 std::scoped_lock
aGuard( m_aMutex
);
34 OUString SAL_CALL
CmdMailMsg::getBody( )
36 std::scoped_lock
aGuard( m_aMutex
);
40 void SAL_CALL
CmdMailMsg::setRecipient( const OUString
& aRecipient
)
42 std::scoped_lock
aGuard( m_aMutex
);
43 m_aRecipient
= aRecipient
;
46 OUString SAL_CALL
CmdMailMsg::getRecipient( )
48 std::scoped_lock
aGuard( m_aMutex
);
52 void SAL_CALL
CmdMailMsg::setCcRecipient( const Sequence
< OUString
>& aCcRecipient
)
54 std::scoped_lock
aGuard( m_aMutex
);
55 m_CcRecipients
= aCcRecipient
;
58 Sequence
< OUString
> SAL_CALL
CmdMailMsg::getCcRecipient( )
60 std::scoped_lock
aGuard( m_aMutex
);
61 return m_CcRecipients
;
64 void SAL_CALL
CmdMailMsg::setBccRecipient( const Sequence
< OUString
>& aBccRecipient
)
66 std::scoped_lock
aGuard( m_aMutex
);
67 m_BccRecipients
= aBccRecipient
;
70 Sequence
< OUString
> SAL_CALL
CmdMailMsg::getBccRecipient( )
72 std::scoped_lock
aGuard( m_aMutex
);
73 return m_BccRecipients
;
76 void SAL_CALL
CmdMailMsg::setOriginator( const OUString
& aOriginator
)
78 std::scoped_lock
aGuard( m_aMutex
);
79 m_aOriginator
= aOriginator
;
82 OUString SAL_CALL
CmdMailMsg::getOriginator( )
84 std::scoped_lock
aGuard( m_aMutex
);
88 void SAL_CALL
CmdMailMsg::setSubject( const OUString
& aSubject
)
90 std::scoped_lock
aGuard( m_aMutex
);
91 m_aSubject
= aSubject
;
94 OUString SAL_CALL
CmdMailMsg::getSubject( )
96 std::scoped_lock
aGuard( m_aMutex
);
100 void SAL_CALL
CmdMailMsg::setAttachement( const Sequence
< OUString
>& aAttachment
)
102 std::scoped_lock
aGuard( m_aMutex
);
103 m_Attachments
= aAttachment
;
106 Sequence
< OUString
> SAL_CALL
CmdMailMsg::getAttachement( )
108 std::scoped_lock
aGuard( m_aMutex
);
109 return m_Attachments
;
112 Any SAL_CALL
CmdMailMsg::getByName( const OUString
& aName
)
114 std::scoped_lock
aGuard( m_aMutex
);
116 if( aName
== "body" && !m_aBody
.isEmpty() )
117 return Any( m_aBody
);
119 if( aName
== "from" && !m_aOriginator
.isEmpty() )
120 return Any( m_aOriginator
);
122 else if( aName
== "to" && !m_aRecipient
.isEmpty() )
123 return Any( m_aRecipient
);
125 else if( aName
== "cc" && m_CcRecipients
.hasElements() )
126 return Any( m_CcRecipients
);
128 else if( aName
== "bcc" && m_BccRecipients
.hasElements() )
129 return Any( m_BccRecipients
);
131 else if( aName
== "subject" && !m_aSubject
.isEmpty() )
132 return Any( m_aSubject
);
134 else if( aName
== "attachment" && m_Attachments
.hasElements() )
135 return Any( m_Attachments
);
137 throw NoSuchElementException("key not found: " + aName
,
138 static_cast < XNameAccess
* > (this) );
141 Sequence
< OUString
> SAL_CALL
CmdMailMsg::getElementNames( )
143 std::scoped_lock
aGuard( m_aMutex
);
145 sal_Int32 nItems
= 0;
146 Sequence
< OUString
> aRet( 7 );
147 auto pRet
= aRet
.getArray();
149 if( !m_aBody
.isEmpty() )
150 pRet
[nItems
++] = "body";
152 if( !m_aOriginator
.isEmpty() )
153 pRet
[nItems
++] = "from";
155 if( !m_aRecipient
.isEmpty() )
156 pRet
[nItems
++] = "to";
158 if( m_CcRecipients
.hasElements() )
159 pRet
[nItems
++] = "cc";
161 if( m_BccRecipients
.hasElements() )
162 pRet
[nItems
++] = "bcc";
164 if( !m_aSubject
.isEmpty() )
165 pRet
[nItems
++] = "subject";
167 if( m_Attachments
.hasElements() )
168 pRet
[nItems
++] = "attachment";
170 aRet
.realloc( nItems
);
174 sal_Bool SAL_CALL
CmdMailMsg::hasByName( const OUString
& aName
)
176 std::scoped_lock
aGuard( m_aMutex
);
178 if( aName
== "body" && !m_aBody
.isEmpty() )
181 if( aName
== "from" && !m_aOriginator
.isEmpty() )
184 else if( aName
== "to" && !m_aRecipient
.isEmpty() )
187 else if( aName
== "cc" && m_CcRecipients
.hasElements() )
190 else if( aName
== "bcc" && m_BccRecipients
.hasElements() )
193 else if( aName
== "subject" && !m_aSubject
.isEmpty() )
196 else if( aName
== "attachment" && m_Attachments
.hasElements() )
202 Type SAL_CALL
CmdMailMsg::getElementType( )
204 // returning void for multi type container
208 sal_Bool SAL_CALL
CmdMailMsg::hasElements( )
210 return getElementNames().hasElements();
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */