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 <svtools/addresstemplate.hxx>
21 #include <svtools/genericunodialog.hxx>
22 #include <cppuhelper/typeprovider.hxx>
23 #include <comphelper/extract.hxx>
24 #include <comphelper/property.hxx>
25 #include <comphelper/processfactory.hxx>
26 #include <com/sun/star/sdbc/XDataSource.hpp>
27 #include <rtl/ref.hxx>
33 #define UNODIALOG_PROPERTY_ID_ALIASES 100
34 #define UNODIALOG_PROPERTY_ALIASES "FieldMapping"
36 using namespace com::sun::star::uno
;
37 using namespace com::sun::star::lang
;
38 using namespace com::sun::star::util
;
39 using namespace com::sun::star::beans
;
40 using namespace com::sun::star::sdbc
;
42 typedef OGenericUnoDialog OAddressBookSourceDialogUnoBase
;
43 class OAddressBookSourceDialogUno
44 :public OAddressBookSourceDialogUnoBase
45 ,public ::comphelper::OPropertyArrayUsageHelper
< OAddressBookSourceDialogUno
>
48 Sequence
< AliasProgrammaticPair
> m_aAliases
;
49 Reference
< XDataSource
> m_xDataSource
;
50 OUString m_sDataSourceName
;
54 OAddressBookSourceDialogUno(const Reference
< XComponentContext
>& _rxORB
);
57 virtual Sequence
<sal_Int8
> SAL_CALL
getImplementationId( ) throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
60 virtual OUString SAL_CALL
getImplementationName() throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
61 virtual ::comphelper::StringSequence SAL_CALL
getSupportedServiceNames() throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
64 virtual Reference
< XPropertySetInfo
> SAL_CALL
getPropertySetInfo() throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
65 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper() SAL_OVERRIDE
;
67 // OPropertyArrayUsageHelper
68 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const SAL_OVERRIDE
;
70 virtual void SAL_CALL
initialize(const Sequence
< Any
>& aArguments
) throw(Exception
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
73 // OGenericUnoDialog overridables
74 virtual VclPtr
<Dialog
> createDialog(vcl::Window
* _pParent
) SAL_OVERRIDE
;
76 virtual void implInitialize(const com::sun::star::uno::Any
& _rValue
) SAL_OVERRIDE
;
78 virtual void executedDialog(sal_Int16 _nExecutionResult
) SAL_OVERRIDE
;
82 OAddressBookSourceDialogUno::OAddressBookSourceDialogUno(const Reference
< XComponentContext
>& _rxORB
)
83 :OGenericUnoDialog(_rxORB
)
85 registerProperty(OUString(UNODIALOG_PROPERTY_ALIASES
), UNODIALOG_PROPERTY_ID_ALIASES
, PropertyAttribute::READONLY
,
86 &m_aAliases
, cppu::UnoType
<decltype(m_aAliases
)>::get());
90 Sequence
<sal_Int8
> SAL_CALL
OAddressBookSourceDialogUno::getImplementationId( ) throw(RuntimeException
, std::exception
)
92 return css::uno::Sequence
<sal_Int8
>();
96 OUString SAL_CALL
OAddressBookSourceDialogUno::getImplementationName() throw(RuntimeException
, std::exception
)
98 return OUString( "com.sun.star.comp.svtools.OAddressBookSourceDialogUno" );
102 ::comphelper::StringSequence SAL_CALL
OAddressBookSourceDialogUno::getSupportedServiceNames() throw(RuntimeException
, std::exception
)
104 ::comphelper::StringSequence
aSupported(1);
105 aSupported
.getArray()[0] = "com.sun.star.ui.AddressBookSourceDialog";
110 Reference
<XPropertySetInfo
> SAL_CALL
OAddressBookSourceDialogUno::getPropertySetInfo() throw(RuntimeException
, std::exception
)
112 Reference
<XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
117 ::cppu::IPropertyArrayHelper
& OAddressBookSourceDialogUno::getInfoHelper()
119 return *getArrayHelper();
123 ::cppu::IPropertyArrayHelper
* OAddressBookSourceDialogUno::createArrayHelper( ) const
125 Sequence
< Property
> aProps
;
126 describeProperties(aProps
);
127 return new ::cppu::OPropertyArrayHelper(aProps
);
131 void OAddressBookSourceDialogUno::executedDialog(sal_Int16 _nExecutionResult
)
133 OAddressBookSourceDialogUnoBase::executedDialog(_nExecutionResult
);
135 if ( _nExecutionResult
)
137 static_cast< AddressBookSourceDialog
* >( m_pDialog
.get() )->getFieldMapping( m_aAliases
);
140 void SAL_CALL
OAddressBookSourceDialogUno::initialize(const Sequence
< Any
>& rArguments
) throw(Exception
, RuntimeException
, std::exception
)
142 if( rArguments
.getLength() == 5 )
144 Reference
<com::sun::star::awt::XWindow
> xParentWindow
;
145 Reference
<com::sun::star::beans::XPropertySet
> xDataSource
;
146 OUString sDataSourceName
;
149 if ( (rArguments
[0] >>= xParentWindow
)
150 && (rArguments
[1] >>= xDataSource
)
151 && (rArguments
[2] >>= sDataSourceName
)
152 && (rArguments
[3] >>= sCommand
)
153 && (rArguments
[4] >>= sTitle
) )
156 // convert the parameters for creating the dialog to PropertyValues
157 Sequence
< Any
> aArguments(5);
158 Any
* pArguments
= aArguments
.getArray();
160 *pArguments
++ <<= PropertyValue(OUString( "ParentWindow" ), -1, makeAny( xParentWindow
), PropertyState_DIRECT_VALUE
);
161 // the data source to use
162 *pArguments
++ <<= PropertyValue(OUString( "DataSource" ), -1, makeAny( xDataSource
), PropertyState_DIRECT_VALUE
);
163 *pArguments
++ <<= PropertyValue(OUString( "DataSourceName" ), -1, makeAny( sDataSourceName
), PropertyState_DIRECT_VALUE
);
165 *pArguments
++ <<= PropertyValue(OUString( "Command" ), -1, makeAny( sCommand
), PropertyState_DIRECT_VALUE
);
167 *pArguments
++ <<= PropertyValue(OUString( "Title" ), -1, makeAny( sTitle
), PropertyState_DIRECT_VALUE
);
168 OGenericUnoDialog::initialize(aArguments
);
172 OGenericUnoDialog::initialize(rArguments
);
175 void OAddressBookSourceDialogUno::implInitialize(const com::sun::star::uno::Any
& _rValue
)
178 if (_rValue
>>= aVal
)
180 if (aVal
.Name
== "DataSource")
182 #if OSL_DEBUG_LEVEL > 0
185 aVal
.Value
>>= m_xDataSource
;
186 OSL_ENSURE( bSuccess
, "OAddressBookSourceDialogUno::implInitialize: invalid type for DataSource!" );
190 if (aVal
.Name
== "DataSourceName")
192 #if OSL_DEBUG_LEVEL > 0
195 aVal
.Value
>>= m_sDataSourceName
;
196 OSL_ENSURE( bSuccess
, "OAddressBookSourceDialogUno::implInitialize: invalid type for DataSourceName!" );
200 if (aVal
.Name
== "Command")
202 #if OSL_DEBUG_LEVEL > 0
205 aVal
.Value
>>= m_sTable
;
206 OSL_ENSURE( bSuccess
, "OAddressBookSourceDialogUno::implInitialize: invalid type for Command!" );
211 OAddressBookSourceDialogUnoBase::implInitialize( _rValue
);
215 VclPtr
<Dialog
> OAddressBookSourceDialogUno::createDialog(vcl::Window
* _pParent
)
217 if ( m_xDataSource
.is() && !m_sTable
.isEmpty() )
218 return VclPtr
<AddressBookSourceDialog
>::Create(_pParent
, m_aContext
, m_xDataSource
, m_sDataSourceName
, m_sTable
, m_aAliases
);
220 return VclPtr
<AddressBookSourceDialog
>::Create( _pParent
, m_aContext
);
225 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
226 com_sun_star_comp_svtools_OAddressBookSourceDialogUno_get_implementation(
227 css::uno::XComponentContext
* context
,
228 css::uno::Sequence
<css::uno::Any
> const &)
230 return cppu::acquire(new OAddressBookSourceDialogUno(context
));
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */