21#include <com/sun/star/beans/XPropertySet.hpp>
22#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
23#include <com/sun/star/ui/AddressBookSourceDialog.hpp>
24#include <com/sun/star/awt/XWindow.hpp>
25#include <com/sun/star/sdb/CommandType.hpp>
29#include <com/sun/star/util/AliasProgrammaticPair.hpp>
40 using namespace ::
utl;
51 const char16_t sDriverSettingsNodeName[] =
u"/org.openoffice.Office.DataAccess/DriverSettings/com.sun.star.comp.sdbc.MozabDriver";
54 namespace fieldmapping
57 const Reference< XPropertySet >& _rxDataSource,
AddressSettings& _rSettings )
61 DBG_ASSERT( _rxORB.is(),
"fieldmapping::invokeDialog: invalid service factory!" );
62 DBG_ASSERT( _rxDataSource.is(),
"fieldmapping::invokeDialog: invalid data source!" );
63 if ( !_rxORB.is() || !_rxDataSource.is() )
70 Reference< XWindow > xDialogParent = _pParent->
GetXWindow();
72 Reference< XExecutableDialog > xDialog = AddressBookSourceDialog::createWithDataSource(_rxORB,
82 if ( xDialog->execute() )
85 Reference< XPropertySet > xDialogProps( xDialog, UNO_QUERY );
87 Sequence< AliasProgrammaticPair > aMapping;
89 xDialogProps->getPropertyValue(
"FieldMapping") >>= aMapping;
90 DBG_ASSERT( bSuccess,
"fieldmapping::invokeDialog: invalid property type for FieldMapping!" );
93 const AliasProgrammaticPair*
pMapping = aMapping.getConstArray();
94 const AliasProgrammaticPair* pMappingEnd =
pMapping + aMapping.getLength();
105 "caught an exception while executing the dialog!");
113 _rFieldAssignment.clear();
125 const char* pMappingProgrammatics[] =
127 "FirstName",
"FirstName",
128 "LastName",
"LastName",
129 "Street",
"HomeAddress",
130 "Zip",
"HomeZipCode",
132 "State",
"HomeState",
133 "Country",
"HomeCountry",
134 "PhonePriv",
"HomePhone",
135 "PhoneComp",
"WorkPhone",
136 "PhoneCell",
"CellularNumber",
137 "Pager",
"PagerNumber",
139 "EMail",
"PrimaryEmail",
142 "Altfield1",
"Custom1",
143 "Altfield2",
"Custom2",
144 "Altfield3",
"Custom3",
145 "Altfield4",
"Custom4",
147 "Company",
"Company",
148 "Department",
"Department"
155 OUString sDriverAliasesNodeName(
160 OConfigurationTreeRoot aDriverFieldAliasing = OConfigurationTreeRoot::createWithComponentContext(
161 _rxContext, sDriverAliasesNodeName, -1, OConfigurationTreeRoot::CM_READONLY);
164 DBG_ASSERT( 0 == std::size( pMappingProgrammatics ) % 2,
165 "fieldmapping::defaultMapping: invalid programmatic map!" );
167 sal_Int32
const nIntersectedProgrammatics = std::size( pMappingProgrammatics ) / 2;
169 const char** pProgrammatic = pMappingProgrammatics;
170 OUString sAddressProgrammatic;
171 OUString sDriverProgrammatic;
174 i < nIntersectedProgrammatics;
178 sAddressProgrammatic = OUString::createFromAscii( *pProgrammatic++ );
179 sDriverProgrammatic = OUString::createFromAscii( *pProgrammatic++ );
181 if ( aDriverFieldAliasing.hasByName( sDriverProgrammatic ) )
183 aDriverFieldAliasing.getNodeValue( sDriverProgrammatic ) >>= sDriverUI;
184 if ( 0 == sDriverUI.getLength() )
186 OSL_FAIL(
"fieldmapping::defaultMapping: invalid driver UI column name!");
189 _rFieldAssignment[ sAddressProgrammatic ] = sDriverUI;
193 OSL_FAIL(
"fieldmapping::defaultMapping: invalid driver programmatic name!" );
200 "code is assumed to throw no exceptions!");
211 OConfigurationTreeRoot aAddressBookSettings = OConfigurationTreeRoot::createWithComponentContext(
214 OConfigurationNode aFields = aAddressBookSettings.openNode( OUString(
"Fields" ) );
217 Sequence< OUString > aExistentFields = aFields.getNodeNames();
218 const OUString* pExistentFields = aExistentFields.getConstArray();
219 const OUString* pExistentFieldsEnd = pExistentFields + aExistentFields.getLength();
221 static constexpr OUStringLiteral sProgrammaticNodeName(
u"ProgrammaticFieldName" );
222 static constexpr OUStringLiteral sAssignedNodeName(
u"AssignedFieldName" );
224 for ( ; pExistentFields != pExistentFieldsEnd; ++pExistentFields )
227 ((aFields.openNode(*pExistentFields)
228 .getNodeValue(sProgrammaticNodeName).get<OUString>())
229 != *pExistentFields),
230 "extensions.abpilot",
231 "fieldmapping::writeTemplateAddressFieldMapping: inconsistent config data!");
235 MapString2String::iterator aPos = aFieldAssignment.find( *pExistentFields );
236 if ( aFieldAssignment.end() != aPos )
239 OConfigurationNode aExistentField = aFields.openNode( *pExistentFields );
240 aExistentField.setNodeValue( sAssignedNodeName,
Any( aPos->second ) );
242 aFieldAssignment.erase( *pExistentFields );
247 aFields.removeNode( *pExistentFields );
253 for (
auto const& elem : aFieldAssignment)
256 "fieldmapping::writeTemplateAddressFieldMapping: inconsistence!" );
259 OConfigurationNode aNewField = aFields.createNode( elem.first );
260 aNewField.setNodeValue( sProgrammaticNodeName,
Any( elem.first ) );
261 aNewField.setNodeValue( sAssignedNodeName,
Any( elem.second ) );
265 aAddressBookSettings.commit();
272 namespace addressconfig
277 const OUString& _rDataSourceName,
const OUString& _rTableName )
282 OConfigurationTreeRoot aAddressBookSettings = OConfigurationTreeRoot::createWithComponentContext(
285 aAddressBookSettings.setNodeValue( OUString(
"DataSourceName" ),
Any( _rDataSourceName ) );
286 aAddressBookSettings.setNodeValue( OUString(
"Command" ),
Any( _rTableName ) );
287 aAddressBookSettings.setNodeValue( OUString(
"CommandType" ),
Any( sal_Int16(CommandType::TABLE) ) );
290 aAddressBookSettings.commit();
299 OConfigurationTreeRoot aAddressBookSettings = OConfigurationTreeRoot::createWithComponentContext(
303 aAddressBookSettings.setNodeValue( OUString(
"AutoPilotCompleted" ),
Any(
true ) );
306 aAddressBookSettings.commit();
virtual css::uno::Reference< css::awt::XWindow > GetXWindow()=0
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define SAL_WARN_IF(condition, area, stream)
void markPilotSuccess(const Reference< XComponentContext > &_rxContext)
void writeTemplateAddressSource(const Reference< XComponentContext > &_rxContext, const OUString &_rDataSourceName, const OUString &_rTableName)
bool invokeDialog(const Reference< XComponentContext > &_rxORB, class weld::Window *_pParent, const Reference< XPropertySet > &_rxDataSource, AddressSettings &_rSettings)
void defaultMapping(const Reference< XComponentContext > &_rxContext, MapString2String &_rFieldAssignment)
void writeTemplateAddressFieldMapping(const Reference< XComponentContext > &_rxContext, MapString2String &&aFieldAssignment)
constexpr OUStringLiteral sAddressBookNodeName
const char16_t sDriverSettingsNodeName[]
std::map< OUString, OUString > MapString2String
OUString ModuleRes(TranslateId pId)
MapString2String aFieldMapping
OUString sRegisteredDataSourceName