1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_shell.hxx"
24 
25 #include "sysmailprov.hxx"
26 #include "sysmailclient.hxx"
27 #include "sysmapi.hxx"
28 
29 using com::sun::star::system::XMailClient;
30 using rtl::OUString;
31 
32 using namespace com::sun::star::uno;
33 
34 #define COMP_SERVICE_NAME  "com.sun.star.system.SystemMailProvider"
35 #define COMP_IMPL_NAME     "com.sun.star.comp.system.win.SystemMailProvider"
36 
37 
38 namespace shell
39 {
40 
WinSysMailProvider(const Reference<XComponentContext> & xContext)41 WinSysMailProvider::WinSysMailProvider(
42     const Reference< XComponentContext >& xContext )
43     : WinSysMailProvider_Base( m_aMutex )
44     , m_xContext( xContext )
45 {}
46 
~WinSysMailProvider()47 WinSysMailProvider::~WinSysMailProvider()
48 {
49     m_xContext.clear();
50 }
51 
52 Reference<XMailClient> SAL_CALL
queryMailClient()53 WinSysMailProvider::queryMailClient()
54 throw (RuntimeException)
55 {
56     /* We just try to load the MAPI dll as a test
57        if a mail client is available */
58     Reference<XMailClient> xMailClient;
59     HMODULE handle = LoadLibrary("mapi32.dll");
60     if ((handle != INVALID_HANDLE_VALUE) && (handle != NULL)) {
61 
62         FreeLibrary(handle);
63         xMailClient = Reference<XMailClient>(
64                 new WinSysMailClient() );
65     }
66 
67     return xMailClient;
68 }
69 
70 OUString SAL_CALL
getImplementationName()71 WinSysMailProvider::getImplementationName()
72 throw(RuntimeException)
73 {
74     return getImplementationName_static();
75 }
76 
77 sal_Bool SAL_CALL
supportsService(const OUString & ServiceName)78 WinSysMailProvider::supportsService(
79     const OUString& ServiceName )
80 throw(RuntimeException)
81 {
82     Sequence <OUString> SupportedServicesNames = getSupportedServiceNames_static();
83 
84     for (sal_Int32 n = SupportedServicesNames.getLength(); n--;)
85         if (SupportedServicesNames[n].compareTo(ServiceName) == 0)
86             return sal_True;
87 
88     return sal_False;
89 }
90 
91 Sequence< OUString > SAL_CALL
getSupportedServiceNames()92 WinSysMailProvider::getSupportedServiceNames()
93 throw( RuntimeException )
94 {
95     return getSupportedServiceNames_static();
96 }
97 
98 Reference< XInterface >
Create(const Reference<XComponentContext> & xContext)99 WinSysMailProvider::Create(
100     const Reference< XComponentContext > &xContext)
101 {
102     return Reference< XInterface >(
103         static_cast< cppu::OWeakObject *>(
104             new WinSysMailProvider( xContext ) ) );
105 }
106 
107 OUString
getImplementationName_static()108 WinSysMailProvider::getImplementationName_static()
109 {
110     return OUString( RTL_CONSTASCII_USTRINGPARAM( COMP_IMPL_NAME ) );
111 }
112 
113 Sequence< OUString >
getSupportedServiceNames_static()114 WinSysMailProvider::getSupportedServiceNames_static()
115 {
116     Sequence< OUString > aRet(1);
117     aRet[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( COMP_SERVICE_NAME ) );
118     return aRet;
119 }
120 
121 }
122