update credits
[LibreOffice.git] / shell / source / cmdmail / cmdmailmsg.cxx
blobca56e0f2e18df51dfc0962b6582f81af10228a34
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 <osl/diagnose.h>
21 #include "cmdmailmsg.hxx"
22 #include <com/sun/star/uri/XExternalUriReferenceTranslator.hpp>
23 #include <com/sun/star/uri/ExternalUriReferenceTranslator.hpp>
24 #include <com/sun/star/uno/Reference.hxx>
25 #include <com/sun/star/uno/RuntimeException.hpp>
27 //------------------------------------------------------------------------
28 // namespace directives
29 //------------------------------------------------------------------------
31 using com::sun::star::lang::IllegalArgumentException;
32 using com::sun::star::lang::WrappedTargetException;
33 using com::sun::star::container::NoSuchElementException;
34 using com::sun::star::container::XNameAccess;
35 using osl::MutexGuard;
37 using namespace cppu;
38 using namespace com::sun::star::uno;
41 //------------------------------------------------
43 void SAL_CALL CmdMailMsg::setRecipient( const OUString& aRecipient )
44 throw (RuntimeException)
46 MutexGuard aGuard( m_aMutex );
47 m_aRecipient = aRecipient;
50 //------------------------------------------------
52 OUString SAL_CALL CmdMailMsg::getRecipient( )
53 throw (RuntimeException)
55 MutexGuard aGuard( m_aMutex );
56 return m_aRecipient;
59 //------------------------------------------------
61 void SAL_CALL CmdMailMsg::setCcRecipient( const Sequence< OUString >& aCcRecipient )
62 throw (RuntimeException)
64 MutexGuard aGuard( m_aMutex );
65 m_CcRecipients = aCcRecipient;
68 //------------------------------------------------
70 Sequence< OUString > SAL_CALL CmdMailMsg::getCcRecipient( )
71 throw (RuntimeException)
73 MutexGuard aGuard( m_aMutex );
74 return m_CcRecipients;
77 //------------------------------------------------
79 void SAL_CALL CmdMailMsg::setBccRecipient( const Sequence< OUString >& aBccRecipient )
80 throw (RuntimeException)
82 MutexGuard aGuard( m_aMutex );
83 m_BccRecipients = aBccRecipient;
86 //------------------------------------------------
88 Sequence< OUString > SAL_CALL CmdMailMsg::getBccRecipient( )
89 throw (RuntimeException)
91 MutexGuard aGuard( m_aMutex );
92 return m_BccRecipients;
95 //------------------------------------------------
97 void SAL_CALL CmdMailMsg::setOriginator( const OUString& aOriginator )
98 throw (RuntimeException)
100 MutexGuard aGuard( m_aMutex );
101 m_aOriginator = aOriginator;
104 //------------------------------------------------
106 OUString SAL_CALL CmdMailMsg::getOriginator( )
107 throw (RuntimeException)
109 MutexGuard aGuard( m_aMutex );
110 return m_aOriginator;
113 //------------------------------------------------
115 void SAL_CALL CmdMailMsg::setSubject( const OUString& aSubject )
116 throw (RuntimeException)
118 MutexGuard aGuard( m_aMutex );
119 m_aSubject = aSubject;
122 //------------------------------------------------
124 OUString SAL_CALL CmdMailMsg::getSubject( )
125 throw (RuntimeException)
127 MutexGuard aGuard( m_aMutex );
128 return m_aSubject;
131 //------------------------------------------------
133 void SAL_CALL CmdMailMsg::setAttachement( const Sequence< OUString >& aAttachment )
134 throw (IllegalArgumentException, RuntimeException)
136 MutexGuard aGuard( m_aMutex );
137 m_Attachments = aAttachment;
140 //------------------------------------------------
142 Sequence< OUString > SAL_CALL CmdMailMsg::getAttachement( )
143 throw (RuntimeException)
145 MutexGuard aGuard( m_aMutex );
146 return m_Attachments;
149 //------------------------------------------------
151 Any SAL_CALL CmdMailMsg::getByName( const OUString& aName )
152 throw (NoSuchElementException, WrappedTargetException, RuntimeException)
154 MutexGuard aGuard( m_aMutex );
156 if( 0 == aName.compareToAscii( "from" ) && !m_aOriginator.isEmpty() )
157 return makeAny( m_aOriginator );
159 else if( 0 == aName.compareToAscii( "to" ) && !m_aRecipient.isEmpty() )
160 return makeAny( m_aRecipient );
162 else if( 0 == aName.compareToAscii( "cc" ) && m_CcRecipients.getLength() )
163 return makeAny( m_CcRecipients );
165 else if( 0 == aName.compareToAscii( "bcc" ) && m_BccRecipients.getLength() )
166 return makeAny( m_BccRecipients );
168 else if( 0 == aName.compareToAscii( "subject" ) && !m_aSubject.isEmpty() )
169 return makeAny( m_aSubject );
171 else if( 0 == aName.compareToAscii( "attachment" ) && m_Attachments.getLength() )
172 return makeAny( m_Attachments );
174 throw NoSuchElementException( OUString("key not found: ") + aName,
175 static_cast < XNameAccess * > (this) );
178 //------------------------------------------------
180 Sequence< OUString > SAL_CALL CmdMailMsg::getElementNames( )
181 throw (::com::sun::star::uno::RuntimeException)
183 MutexGuard aGuard( m_aMutex );
185 sal_Int32 nItems = 0;
186 Sequence< OUString > aRet( 6 );
188 if( !m_aOriginator.isEmpty() )
189 aRet[nItems++] = OUString("from");
191 if( !m_aRecipient.isEmpty() )
192 aRet[nItems++] = OUString("to");
194 if( m_CcRecipients.getLength() )
195 aRet[nItems++] = OUString("cc");
197 if( m_BccRecipients.getLength() )
198 aRet[nItems++] = OUString("bcc");
200 if( !m_aSubject.isEmpty() )
201 aRet[nItems++] = OUString("subject");
203 if( m_Attachments.getLength() )
204 aRet[nItems++] = OUString("attachment");
206 aRet.realloc( nItems );
207 return aRet;
210 //------------------------------------------------
212 sal_Bool SAL_CALL CmdMailMsg::hasByName( const OUString& aName )
213 throw (RuntimeException)
215 MutexGuard aGuard( m_aMutex );
217 if( 0 == aName.compareToAscii( "from" ) && !m_aOriginator.isEmpty() )
218 return sal_True;
220 else if( 0 == aName.compareToAscii( "to" ) && !m_aRecipient.isEmpty() )
221 return sal_True;
223 else if( 0 == aName.compareToAscii( "cc" ) && m_CcRecipients.getLength() )
224 return sal_True;
226 else if( 0 == aName.compareToAscii( "bcc" ) && m_BccRecipients.getLength() )
227 return sal_True;
229 else if( 0 == aName.compareToAscii( "subject" ) && !m_aSubject.isEmpty() )
230 return sal_True;
232 else if( 0 == aName.compareToAscii( "attachment" ) && m_Attachments.getLength() )
233 return sal_True;
235 return sal_False;
238 //------------------------------------------------
240 Type SAL_CALL CmdMailMsg::getElementType( )
241 throw (RuntimeException)
243 // returning void for multi type container
244 return Type();
247 //------------------------------------------------
249 sal_Bool SAL_CALL CmdMailMsg::hasElements( )
250 throw (RuntimeException)
252 return 0 != getElementNames().getLength();
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */