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
;
26 using namespace com::sun::star::uno
;
29 void SAL_CALL
CmdMailMsg::setBody( const OUString
& aBody
)
31 std::scoped_lock
aGuard( m_aMutex
);
35 OUString SAL_CALL
CmdMailMsg::getBody( )
37 std::scoped_lock
aGuard( m_aMutex
);
41 void SAL_CALL
CmdMailMsg::setRecipient( const OUString
& aRecipient
)
43 std::scoped_lock
aGuard( m_aMutex
);
44 m_aRecipient
= aRecipient
;
47 OUString SAL_CALL
CmdMailMsg::getRecipient( )
49 std::scoped_lock
aGuard( m_aMutex
);
53 void SAL_CALL
CmdMailMsg::setCcRecipient( const Sequence
< OUString
>& aCcRecipient
)
55 std::scoped_lock
aGuard( m_aMutex
);
56 m_CcRecipients
= aCcRecipient
;
59 Sequence
< OUString
> SAL_CALL
CmdMailMsg::getCcRecipient( )
61 std::scoped_lock
aGuard( m_aMutex
);
62 return m_CcRecipients
;
65 void SAL_CALL
CmdMailMsg::setBccRecipient( const Sequence
< OUString
>& aBccRecipient
)
67 std::scoped_lock
aGuard( m_aMutex
);
68 m_BccRecipients
= aBccRecipient
;
71 Sequence
< OUString
> SAL_CALL
CmdMailMsg::getBccRecipient( )
73 std::scoped_lock
aGuard( m_aMutex
);
74 return m_BccRecipients
;
77 void SAL_CALL
CmdMailMsg::setOriginator( const OUString
& aOriginator
)
79 std::scoped_lock
aGuard( m_aMutex
);
80 m_aOriginator
= aOriginator
;
83 OUString SAL_CALL
CmdMailMsg::getOriginator( )
85 std::scoped_lock
aGuard( m_aMutex
);
89 void SAL_CALL
CmdMailMsg::setSubject( const OUString
& aSubject
)
91 std::scoped_lock
aGuard( m_aMutex
);
92 m_aSubject
= aSubject
;
95 OUString SAL_CALL
CmdMailMsg::getSubject( )
97 std::scoped_lock
aGuard( m_aMutex
);
101 void SAL_CALL
CmdMailMsg::setAttachement( const Sequence
< OUString
>& aAttachment
)
103 std::scoped_lock
aGuard( m_aMutex
);
104 m_Attachments
= aAttachment
;
107 Sequence
< OUString
> SAL_CALL
CmdMailMsg::getAttachement( )
109 std::scoped_lock
aGuard( m_aMutex
);
110 return m_Attachments
;
113 Any SAL_CALL
CmdMailMsg::getByName( const OUString
& aName
)
115 std::scoped_lock
aGuard( m_aMutex
);
117 if( aName
== "body" && !m_aBody
.isEmpty() )
118 return Any( m_aBody
);
120 if( aName
== "from" && !m_aOriginator
.isEmpty() )
121 return Any( m_aOriginator
);
123 else if( aName
== "to" && !m_aRecipient
.isEmpty() )
124 return Any( m_aRecipient
);
126 else if( aName
== "cc" && m_CcRecipients
.hasElements() )
127 return Any( m_CcRecipients
);
129 else if( aName
== "bcc" && m_BccRecipients
.hasElements() )
130 return Any( m_BccRecipients
);
132 else if( aName
== "subject" && !m_aSubject
.isEmpty() )
133 return Any( m_aSubject
);
135 else if( aName
== "attachment" && m_Attachments
.hasElements() )
136 return Any( m_Attachments
);
138 throw NoSuchElementException("key not found: " + aName
,
139 static_cast < XNameAccess
* > (this) );
142 Sequence
< OUString
> SAL_CALL
CmdMailMsg::getElementNames( )
144 std::scoped_lock
aGuard( m_aMutex
);
146 sal_Int32 nItems
= 0;
147 Sequence
< OUString
> aRet( 7 );
148 auto pRet
= aRet
.getArray();
150 if( !m_aBody
.isEmpty() )
151 pRet
[nItems
++] = "body";
153 if( !m_aOriginator
.isEmpty() )
154 pRet
[nItems
++] = "from";
156 if( !m_aRecipient
.isEmpty() )
157 pRet
[nItems
++] = "to";
159 if( m_CcRecipients
.hasElements() )
160 pRet
[nItems
++] = "cc";
162 if( m_BccRecipients
.hasElements() )
163 pRet
[nItems
++] = "bcc";
165 if( !m_aSubject
.isEmpty() )
166 pRet
[nItems
++] = "subject";
168 if( m_Attachments
.hasElements() )
169 pRet
[nItems
++] = "attachment";
171 aRet
.realloc( nItems
);
175 sal_Bool SAL_CALL
CmdMailMsg::hasByName( const OUString
& aName
)
177 std::scoped_lock
aGuard( m_aMutex
);
179 if( aName
== "body" && !m_aBody
.isEmpty() )
182 if( aName
== "from" && !m_aOriginator
.isEmpty() )
185 else if( aName
== "to" && !m_aRecipient
.isEmpty() )
188 else if( aName
== "cc" && m_CcRecipients
.hasElements() )
191 else if( aName
== "bcc" && m_BccRecipients
.hasElements() )
194 else if( aName
== "subject" && !m_aSubject
.isEmpty() )
197 else if( aName
== "attachment" && m_Attachments
.hasElements() )
203 Type SAL_CALL
CmdMailMsg::getElementType( )
205 // returning void for multi type container
209 sal_Bool SAL_CALL
CmdMailMsg::hasElements( )
211 return getElementNames().hasElements();
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */