Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svtools / source / uno / addrtempuno.cxx
blob54cb28afc07d8b325973966cc405220cea3c5a28
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 <svtools/addresstemplate.hxx>
21 #include <svtools/genericunodialog.hxx>
22 #include <comphelper/proparrhlp.hxx>
23 #include <comphelper/propertysequence.hxx>
24 #include <com/sun/star/awt/XWindow.hpp>
25 #include <com/sun/star/beans/PropertyAttribute.hpp>
26 #include <com/sun/star/util/AliasProgrammaticPair.hpp>
27 #include <com/sun/star/sdbc/XDataSource.hpp>
28 #include <vcl/svapp.hxx>
30 using namespace svt;
32 namespace {
34 #define UNODIALOG_PROPERTY_ID_ALIASES 100
35 constexpr OUStringLiteral UNODIALOG_PROPERTY_ALIASES = u"FieldMapping";
37 using namespace css::uno;
38 using namespace css::lang;
39 using namespace css::util;
40 using namespace css::beans;
41 using namespace css::sdbc;
43 class OAddressBookSourceDialogUno
44 :public OGenericUnoDialog
45 ,public ::comphelper::OPropertyArrayUsageHelper< OAddressBookSourceDialogUno >
47 private:
48 Sequence< AliasProgrammaticPair > m_aAliases;
49 Reference< XDataSource > m_xDataSource;
50 OUString m_sDataSourceName;
51 OUString m_sTable;
53 public:
54 explicit OAddressBookSourceDialogUno(const Reference< XComponentContext >& _rxORB);
56 // XTypeProvider
57 virtual Sequence<sal_Int8> SAL_CALL getImplementationId( ) override;
59 // XServiceInfo
60 virtual OUString SAL_CALL getImplementationName() override;
61 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
63 // XPropertySet
64 virtual Reference< XPropertySetInfo> SAL_CALL getPropertySetInfo() override;
65 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override;
67 // OPropertyArrayUsageHelper
68 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override;
70 virtual void SAL_CALL initialize(const Sequence< Any >& aArguments) override;
72 protected:
73 // OGenericUnoDialog overridables
74 virtual std::unique_ptr<weld::DialogController> createDialog(const css::uno::Reference<css::awt::XWindow>& rParent) override;
76 virtual void implInitialize(const css::uno::Any& _rValue) override;
78 virtual void executedDialog(sal_Int16 _nExecutionResult) override;
82 OAddressBookSourceDialogUno::OAddressBookSourceDialogUno(const Reference< XComponentContext >& _rxORB)
83 :OGenericUnoDialog(_rxORB)
85 registerProperty(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( )
92 return css::uno::Sequence<sal_Int8>();
96 OUString SAL_CALL OAddressBookSourceDialogUno::getImplementationName()
98 return "com.sun.star.comp.svtools.OAddressBookSourceDialogUno";
102 css::uno::Sequence<OUString> SAL_CALL OAddressBookSourceDialogUno::getSupportedServiceNames()
104 return { "com.sun.star.ui.AddressBookSourceDialog" };
108 Reference<XPropertySetInfo> SAL_CALL OAddressBookSourceDialogUno::getPropertySetInfo()
110 Reference<XPropertySetInfo> xInfo( createPropertySetInfo( getInfoHelper() ) );
111 return xInfo;
114 ::cppu::IPropertyArrayHelper& OAddressBookSourceDialogUno::getInfoHelper()
116 return *getArrayHelper();
119 ::cppu::IPropertyArrayHelper* OAddressBookSourceDialogUno::createArrayHelper( ) const
121 Sequence< Property > aProps;
122 describeProperties(aProps);
123 return new ::cppu::OPropertyArrayHelper(aProps);
126 void OAddressBookSourceDialogUno::executedDialog(sal_Int16 _nExecutionResult)
128 OGenericUnoDialog::executedDialog(_nExecutionResult);
130 if ( _nExecutionResult && m_xDialog )
131 static_cast<AddressBookSourceDialog*>(m_xDialog.get())->getFieldMapping(m_aAliases);
134 void SAL_CALL OAddressBookSourceDialogUno::initialize(const Sequence< Any >& rArguments)
136 if( rArguments.getLength() == 5 )
138 Reference<css::awt::XWindow> xParentWindow;
139 Reference<css::beans::XPropertySet> xDataSource;
140 OUString sDataSourceName;
141 OUString sCommand;
142 OUString sTitle;
143 if ( (rArguments[0] >>= xParentWindow)
144 && (rArguments[1] >>= xDataSource)
145 && (rArguments[2] >>= sDataSourceName)
146 && (rArguments[3] >>= sCommand)
147 && (rArguments[4] >>= sTitle) )
150 // convert the parameters for creating the dialog to PropertyValues
151 Sequence<Any> aArguments(comphelper::InitAnyPropertySequence(
153 {"ParentWindow", Any(xParentWindow)},
154 {"DataSource", Any(xDataSource)},
155 {"DataSourceName", Any(sDataSourceName)},
156 {"Command", Any(sCommand)}, // the table to use
157 {"Title", Any(sTitle)}
158 }));
159 OGenericUnoDialog::initialize(aArguments);
160 return;
163 OGenericUnoDialog::initialize(rArguments);
166 void OAddressBookSourceDialogUno::implInitialize(const css::uno::Any& _rValue)
168 PropertyValue aVal;
169 if (_rValue >>= aVal)
171 if (aVal.Name == "DataSource")
173 bool bSuccess = aVal.Value >>= m_xDataSource;
174 OSL_ENSURE( bSuccess, "OAddressBookSourceDialogUno::implInitialize: invalid type for DataSource!" );
175 return;
178 if (aVal.Name == "DataSourceName")
180 bool bSuccess = aVal.Value >>= m_sDataSourceName;
181 OSL_ENSURE( bSuccess, "OAddressBookSourceDialogUno::implInitialize: invalid type for DataSourceName!" );
182 return;
185 if (aVal.Name == "Command")
187 bool bSuccess = aVal.Value >>= m_sTable;
188 OSL_ENSURE( bSuccess, "OAddressBookSourceDialogUno::implInitialize: invalid type for Command!" );
189 return;
193 OGenericUnoDialog::implInitialize( _rValue );
196 std::unique_ptr<weld::DialogController> OAddressBookSourceDialogUno::createDialog(const css::uno::Reference<css::awt::XWindow>& rParent)
198 weld::Window* pParent = Application::GetFrameWeld(rParent);
199 if ( m_xDataSource.is() && !m_sTable.isEmpty() )
200 return std::make_unique<AddressBookSourceDialog>(pParent, m_aContext, m_xDataSource, m_sDataSourceName, m_sTable, m_aAliases);
201 return std::make_unique<AddressBookSourceDialog>(pParent, m_aContext);
205 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
206 com_sun_star_comp_svtools_OAddressBookSourceDialogUno_get_implementation(
207 css::uno::XComponentContext * context,
208 css::uno::Sequence<css::uno::Any> const &)
210 return cppu::acquire(new OAddressBookSourceDialogUno(context));
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */