Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / shell / source / cmdmail / cmdmailmsg.cxx
blob312d1ad8016c23978d4cacda0749277f9da8d2d7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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::lang::IllegalArgumentException;
23 using com::sun::star::lang::WrappedTargetException;
24 using com::sun::star::container::NoSuchElementException;
25 using com::sun::star::container::XNameAccess;
26 using osl::MutexGuard;
28 using namespace cppu;
29 using namespace com::sun::star::uno;
32 void SAL_CALL CmdMailMsg::setBody( const OUString& aBody )
34 MutexGuard aGuard( m_aMutex );
35 m_aBody = aBody;
38 OUString SAL_CALL CmdMailMsg::getBody( )
40 MutexGuard aGuard( m_aMutex );
41 return m_aBody;
44 void SAL_CALL CmdMailMsg::setRecipient( const OUString& aRecipient )
46 MutexGuard aGuard( m_aMutex );
47 m_aRecipient = aRecipient;
50 OUString SAL_CALL CmdMailMsg::getRecipient( )
52 MutexGuard aGuard( m_aMutex );
53 return m_aRecipient;
56 void SAL_CALL CmdMailMsg::setCcRecipient( const Sequence< OUString >& aCcRecipient )
58 MutexGuard aGuard( m_aMutex );
59 m_CcRecipients = aCcRecipient;
62 Sequence< OUString > SAL_CALL CmdMailMsg::getCcRecipient( )
64 MutexGuard aGuard( m_aMutex );
65 return m_CcRecipients;
68 void SAL_CALL CmdMailMsg::setBccRecipient( const Sequence< OUString >& aBccRecipient )
70 MutexGuard aGuard( m_aMutex );
71 m_BccRecipients = aBccRecipient;
74 Sequence< OUString > SAL_CALL CmdMailMsg::getBccRecipient( )
76 MutexGuard aGuard( m_aMutex );
77 return m_BccRecipients;
80 void SAL_CALL CmdMailMsg::setOriginator( const OUString& aOriginator )
82 MutexGuard aGuard( m_aMutex );
83 m_aOriginator = aOriginator;
86 OUString SAL_CALL CmdMailMsg::getOriginator( )
88 MutexGuard aGuard( m_aMutex );
89 return m_aOriginator;
92 void SAL_CALL CmdMailMsg::setSubject( const OUString& aSubject )
94 MutexGuard aGuard( m_aMutex );
95 m_aSubject = aSubject;
98 OUString SAL_CALL CmdMailMsg::getSubject( )
100 MutexGuard aGuard( m_aMutex );
101 return m_aSubject;
104 void SAL_CALL CmdMailMsg::setAttachement( const Sequence< OUString >& aAttachment )
106 MutexGuard aGuard( m_aMutex );
107 m_Attachments = aAttachment;
110 Sequence< OUString > SAL_CALL CmdMailMsg::getAttachement( )
112 MutexGuard aGuard( m_aMutex );
113 return m_Attachments;
116 Any SAL_CALL CmdMailMsg::getByName( const OUString& aName )
118 MutexGuard aGuard( m_aMutex );
120 if( aName == "body" && !m_aBody.isEmpty() )
121 return makeAny( m_aBody );
123 if( aName == "from" && !m_aOriginator.isEmpty() )
124 return makeAny( m_aOriginator );
126 else if( aName == "to" && !m_aRecipient.isEmpty() )
127 return makeAny( m_aRecipient );
129 else if( aName == "cc" && m_CcRecipients.hasElements() )
130 return makeAny( m_CcRecipients );
132 else if( aName == "bcc" && m_BccRecipients.hasElements() )
133 return makeAny( m_BccRecipients );
135 else if( aName == "subject" && !m_aSubject.isEmpty() )
136 return makeAny( m_aSubject );
138 else if( aName == "attachment" && m_Attachments.hasElements() )
139 return makeAny( m_Attachments );
141 throw NoSuchElementException("key not found: " + aName,
142 static_cast < XNameAccess * > (this) );
145 Sequence< OUString > SAL_CALL CmdMailMsg::getElementNames( )
147 MutexGuard aGuard( m_aMutex );
149 sal_Int32 nItems = 0;
150 Sequence< OUString > aRet( 7 );
152 if( !m_aBody.isEmpty() )
153 aRet[nItems++] = "body";
155 if( !m_aOriginator.isEmpty() )
156 aRet[nItems++] = "from";
158 if( !m_aRecipient.isEmpty() )
159 aRet[nItems++] = "to";
161 if( m_CcRecipients.hasElements() )
162 aRet[nItems++] = "cc";
164 if( m_BccRecipients.hasElements() )
165 aRet[nItems++] = "bcc";
167 if( !m_aSubject.isEmpty() )
168 aRet[nItems++] = "subject";
170 if( m_Attachments.hasElements() )
171 aRet[nItems++] = "attachment";
173 aRet.realloc( nItems );
174 return aRet;
177 sal_Bool SAL_CALL CmdMailMsg::hasByName( const OUString& aName )
179 MutexGuard aGuard( m_aMutex );
181 if( aName == "body" && !m_aBody.isEmpty() )
182 return true;
184 if( aName == "from" && !m_aOriginator.isEmpty() )
185 return true;
187 else if( aName == "to" && !m_aRecipient.isEmpty() )
188 return true;
190 else if( aName == "cc" && m_CcRecipients.hasElements() )
191 return true;
193 else if( aName == "bcc" && m_BccRecipients.hasElements() )
194 return true;
196 else if( aName == "subject" && !m_aSubject.isEmpty() )
197 return true;
199 else if( aName == "attachment" && m_Attachments.hasElements() )
200 return true;
202 return false;
205 Type SAL_CALL CmdMailMsg::getElementType( )
207 // returning void for multi type container
208 return Type();
211 sal_Bool SAL_CALL CmdMailMsg::hasElements( )
213 return getElementNames().hasElements();
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */