Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <stdio.h>
31 : : #include <svtools/addresstemplate.hxx>
32 : : #include "addresstemplate.hrc"
33 : : #include <svtools/svtools.hrc>
34 : : #include <svtools/helpid.hrc>
35 : : #include <svtools/svtresid.hxx>
36 : : #include <tools/debug.hxx>
37 : : #include <comphelper/extract.hxx>
38 : : #include <comphelper/interaction.hxx>
39 : : #include <comphelper/processfactory.hxx>
40 : : #include <comphelper/stl_types.hxx>
41 : : #include <comphelper/string.hxx>
42 : : #include <vcl/stdtext.hxx>
43 : : #include <vcl/waitobj.hxx>
44 : : #include <vcl/msgbox.hxx>
45 : : #include <toolkit/helper/vclunohelper.hxx>
46 : : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
47 : : #include <com/sun/star/awt/XWindow.hpp>
48 : : #include <com/sun/star/beans/PropertyValue.hpp>
49 : : #include <com/sun/star/beans/XPropertySet.hpp>
50 : : #include <com/sun/star/sdb/XCompletedConnection.hpp>
51 : : #include <com/sun/star/sdb/SQLContext.hpp>
52 : : #include <com/sun/star/sdbc/SQLWarning.hpp>
53 : : #include <com/sun/star/sdbc/XConnection.hpp>
54 : : #include <com/sun/star/task/XInteractionHandler.hpp>
55 : : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
56 : : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
57 : : #include <com/sun/star/sdb/CommandType.hpp>
58 : : #include <svtools/localresaccess.hxx>
59 : : #include "svl/filenotation.hxx"
60 : : #include <tools/urlobj.hxx>
61 : : #include <algorithm>
62 : :
63 : : // .......................................................................
64 : : namespace svt
65 : : {
66 : : // .......................................................................
67 : :
68 : : using namespace ::com::sun::star::uno;
69 : : using namespace ::com::sun::star::lang;
70 : : using namespace ::com::sun::star::container;
71 : : using namespace ::com::sun::star::ui::dialogs;
72 : : using namespace ::com::sun::star::util;
73 : : using namespace ::com::sun::star::beans;
74 : : using namespace ::com::sun::star::sdb;
75 : : using namespace ::com::sun::star::sdbc;
76 : : using namespace ::com::sun::star::sdbcx;
77 : : using namespace ::com::sun::star::task;
78 : : using namespace ::comphelper;
79 : : using namespace ::utl;
80 : :
81 : : DECLARE_STL_VECTOR( String, StringArray );
82 : : DECLARE_STL_STDKEY_SET( ::rtl::OUString, StringBag );
83 : : DECLARE_STL_USTRINGACCESS_MAP( ::rtl::OUString, MapString2String );
84 : :
85 : : namespace
86 : : {
87 : 0 : String lcl_getSelectedDataSource( const ComboBox& _dataSourceCombo )
88 : : {
89 : 0 : String selectedDataSource = _dataSourceCombo.GetText();
90 [ # # ][ # # ]: 0 : if ( _dataSourceCombo.GetEntryPos( selectedDataSource ) == LISTBOX_ENTRY_NOTFOUND )
91 : : {
92 : : // none of the pre-selected entries -> assume a path to a database document
93 [ # # ][ # # ]: 0 : OFileNotation aFileNotation( selectedDataSource, OFileNotation::N_SYSTEM );
94 [ # # ][ # # ]: 0 : selectedDataSource = aFileNotation.get( OFileNotation::N_URL );
[ # # ]
95 : : }
96 : 0 : return selectedDataSource;
97 : : }
98 : : }
99 : :
100 : : // ===================================================================
101 : : // = IAssigmentData
102 : : // ===================================================================
103 : 0 : class IAssigmentData
104 : : {
105 : : public:
106 : : virtual ~IAssigmentData();
107 : :
108 : : /// the data source to use for the address book
109 : : virtual ::rtl::OUString getDatasourceName() const = 0;
110 : :
111 : : /// the command to use for the address book
112 : : virtual ::rtl::OUString getCommand() const = 0;
113 : :
114 : : /** the command type to use for the address book
115 : : @return
116 : : a <type scope="com.sun.star.sdb">CommandType</type> value
117 : : */
118 : : virtual sal_Int32 getCommandType() const = 0;
119 : :
120 : : /// checks whether or not there is an assignment for a given logical field
121 : : virtual sal_Bool hasFieldAssignment(const ::rtl::OUString& _rLogicalName) = 0;
122 : : /// retrieves the assignment for a given logical field
123 : : virtual ::rtl::OUString getFieldAssignment(const ::rtl::OUString& _rLogicalName) = 0;
124 : :
125 : : /// set the assignment for a given logical field
126 : : virtual void setFieldAssignment(const ::rtl::OUString& _rLogicalName, const ::rtl::OUString& _rAssignment) = 0;
127 : : /// clear the assignment for a given logical field
128 : : virtual void clearFieldAssignment(const ::rtl::OUString& _rLogicalName) = 0;
129 : :
130 : : virtual void setDatasourceName(const ::rtl::OUString& _rName) = 0;
131 : : virtual void setCommand(const ::rtl::OUString& _rCommand) = 0;
132 : : };
133 : :
134 : : // -------------------------------------------------------------------
135 : 0 : IAssigmentData::~IAssigmentData()
136 : : {
137 [ # # ]: 0 : }
138 : :
139 : : // ===================================================================
140 : : // = AssigmentTransientData
141 : : // ===================================================================
142 [ # # ]: 0 : class AssigmentTransientData : public IAssigmentData
143 : : {
144 : : protected:
145 : : Reference< XDataSource > m_xDataSource;
146 : : ::rtl::OUString m_sDSName;
147 : : ::rtl::OUString m_sTableName;
148 : : MapString2String m_aAliases;
149 : :
150 : : public:
151 : : AssigmentTransientData(
152 : : const Reference< XDataSource >& _rxDataSource,
153 : : const ::rtl::OUString& _rDataSourceName,
154 : : const ::rtl::OUString& _rTableName,
155 : : const Sequence< AliasProgrammaticPair >& _rFields
156 : : );
157 : :
158 : : // IAssigmentData overridables
159 : : virtual ::rtl::OUString getDatasourceName() const;
160 : : virtual ::rtl::OUString getCommand() const;
161 : : virtual sal_Int32 getCommandType() const;
162 : :
163 : : virtual sal_Bool hasFieldAssignment(const ::rtl::OUString& _rLogicalName);
164 : : virtual ::rtl::OUString getFieldAssignment(const ::rtl::OUString& _rLogicalName);
165 : : virtual void setFieldAssignment(const ::rtl::OUString& _rLogicalName, const ::rtl::OUString& _rAssignment);
166 : : virtual void clearFieldAssignment(const ::rtl::OUString& _rLogicalName);
167 : :
168 : : virtual void setDatasourceName(const ::rtl::OUString& _rName);
169 : : virtual void setCommand(const ::rtl::OUString& _rCommand);
170 : : };
171 : :
172 : : // -------------------------------------------------------------------
173 : 0 : AssigmentTransientData::AssigmentTransientData( const Reference< XDataSource >& _rxDataSource,
174 : : const ::rtl::OUString& _rDataSourceName, const ::rtl::OUString& _rTableName,
175 : : const Sequence< AliasProgrammaticPair >& _rFields )
176 : : :m_xDataSource( _rxDataSource )
177 : : ,m_sDSName( _rDataSourceName )
178 [ # # ]: 0 : ,m_sTableName( _rTableName )
179 : : {
180 : : // fill our aliaes structure
181 : : // first collect all known programmatic names
182 [ # # ]: 0 : StringBag aKnownNames;
183 : :
184 [ # # ][ # # ]: 0 : rtl::OUString sLogicalFieldNames(SVT_RESSTR(STR_LOGICAL_FIELD_NAMES));
185 : 0 : sal_Int32 nIndex = 0;
186 [ # # ]: 0 : do
187 : : {
188 : 0 : rtl::OUString aToken = sLogicalFieldNames.getToken(0, ';', nIndex);
189 [ # # ]: 0 : aKnownNames.insert(aToken);
190 : : }
191 : : while ( nIndex >= 0);
192 : :
193 : : // loop throuzh the given names
194 : 0 : const AliasProgrammaticPair* pFields = _rFields.getConstArray();
195 : 0 : const AliasProgrammaticPair* pFieldsEnd = pFields + _rFields.getLength();
196 [ # # ]: 0 : for (;pFields != pFieldsEnd; ++pFields)
197 : : {
198 [ # # ]: 0 : StringBagIterator aKnownPos = aKnownNames.find( pFields->ProgrammaticName );
199 [ # # ]: 0 : if ( aKnownNames.end() != aKnownPos )
200 : : {
201 [ # # ]: 0 : m_aAliases[ pFields->ProgrammaticName ] = pFields->Alias;
202 : : }
203 : : else
204 : : {
205 : : OSL_FAIL( ( ::rtl::OString("AssigmentTransientData::AssigmentTransientData: unknown programmatic name (")
206 : : += ::rtl::OString(pFields->ProgrammaticName.getStr(), pFields->ProgrammaticName.getLength(), RTL_TEXTENCODING_ASCII_US)
207 : : += ::rtl::OString(")!")
208 : : ).getStr()
209 : : );
210 : : }
211 : 0 : }
212 : 0 : }
213 : :
214 : : // -------------------------------------------------------------------
215 : 0 : ::rtl::OUString AssigmentTransientData::getDatasourceName() const
216 : : {
217 : 0 : return m_sDSName;
218 : : }
219 : :
220 : : // -------------------------------------------------------------------
221 : 0 : ::rtl::OUString AssigmentTransientData::getCommand() const
222 : : {
223 : 0 : return m_sTableName;
224 : : }
225 : :
226 : : // -------------------------------------------------------------------
227 : 0 : sal_Int32 AssigmentTransientData::getCommandType() const
228 : : {
229 : 0 : return CommandType::TABLE;
230 : : }
231 : :
232 : : // -------------------------------------------------------------------
233 : 0 : sal_Bool AssigmentTransientData::hasFieldAssignment(const ::rtl::OUString& _rLogicalName)
234 : : {
235 [ # # ]: 0 : ConstMapString2StringIterator aPos = m_aAliases.find( _rLogicalName );
236 [ # # ]: 0 : return ( m_aAliases.end() != aPos )
237 [ # # ][ # # ]: 0 : && ( !aPos->second.isEmpty() );
238 : : }
239 : :
240 : : // -------------------------------------------------------------------
241 : 0 : ::rtl::OUString AssigmentTransientData::getFieldAssignment(const ::rtl::OUString& _rLogicalName)
242 : : {
243 : 0 : ::rtl::OUString sReturn;
244 [ # # ]: 0 : ConstMapString2StringIterator aPos = m_aAliases.find( _rLogicalName );
245 [ # # ]: 0 : if ( m_aAliases.end() != aPos )
246 : 0 : sReturn = aPos->second;
247 : :
248 : 0 : return sReturn;
249 : : }
250 : :
251 : : // -------------------------------------------------------------------
252 : 0 : void AssigmentTransientData::setFieldAssignment(const ::rtl::OUString& _rLogicalName, const ::rtl::OUString& _rAssignment)
253 : : {
254 : 0 : m_aAliases[ _rLogicalName ] = _rAssignment;
255 : 0 : }
256 : :
257 : : // -------------------------------------------------------------------
258 : 0 : void AssigmentTransientData::clearFieldAssignment(const ::rtl::OUString& _rLogicalName)
259 : : {
260 [ # # ]: 0 : MapString2StringIterator aPos = m_aAliases.find( _rLogicalName );
261 [ # # ]: 0 : if ( m_aAliases.end() != aPos )
262 [ # # ]: 0 : m_aAliases.erase( aPos );
263 : 0 : }
264 : :
265 : : // -------------------------------------------------------------------
266 : 0 : void AssigmentTransientData::setDatasourceName(const ::rtl::OUString&)
267 : : {
268 : : OSL_FAIL( "AssigmentTransientData::setDatasourceName: cannot be implemented for transient data!" );
269 : 0 : }
270 : :
271 : : // -------------------------------------------------------------------
272 : 0 : void AssigmentTransientData::setCommand(const ::rtl::OUString&)
273 : : {
274 : : OSL_FAIL( "AssigmentTransientData::setCommand: cannot be implemented for transient data!" );
275 : 0 : }
276 : :
277 : : // ===================================================================
278 : : // = AssignmentPersistentData
279 : : // ===================================================================
280 : : class AssignmentPersistentData
281 : : :public ::utl::ConfigItem
282 : : ,public IAssigmentData
283 : : {
284 : : protected:
285 : : StringBag m_aStoredFields;
286 : :
287 : : protected:
288 : : ::com::sun::star::uno::Any
289 : : getProperty(const ::rtl::OUString& _rLocalName) const;
290 : : ::com::sun::star::uno::Any
291 : : getProperty(const sal_Char* _pLocalName) const;
292 : :
293 : : ::rtl::OUString getStringProperty(const sal_Char* _pLocalName) const;
294 : : sal_Int32 getInt32Property(const sal_Char* _pLocalName) const;
295 : :
296 : : ::rtl::OUString getStringProperty(const ::rtl::OUString& _rLocalName) const;
297 : :
298 : : void setStringProperty(const sal_Char* _pLocalName, const ::rtl::OUString& _rValue);
299 : :
300 : : public:
301 : : AssignmentPersistentData();
302 : : ~AssignmentPersistentData();
303 : :
304 : : // IAssigmentData overridables
305 : : virtual ::rtl::OUString getDatasourceName() const;
306 : : virtual ::rtl::OUString getCommand() const;
307 : : virtual sal_Int32 getCommandType() const;
308 : :
309 : : virtual sal_Bool hasFieldAssignment(const ::rtl::OUString& _rLogicalName);
310 : : virtual ::rtl::OUString getFieldAssignment(const ::rtl::OUString& _rLogicalName);
311 : : virtual void setFieldAssignment(const ::rtl::OUString& _rLogicalName, const ::rtl::OUString& _rAssignment);
312 : : virtual void clearFieldAssignment(const ::rtl::OUString& _rLogicalName);
313 : :
314 : : virtual void setDatasourceName(const ::rtl::OUString& _rName);
315 : : virtual void setCommand(const ::rtl::OUString& _rCommand);
316 : :
317 : : virtual void Notify( const com::sun::star::uno::Sequence<rtl::OUString>& aPropertyNames);
318 : : virtual void Commit();
319 : : };
320 : :
321 : :
322 : 0 : void AssignmentPersistentData::Notify( const com::sun::star::uno::Sequence<rtl::OUString>& )
323 : : {
324 : 0 : }
325 : :
326 : 0 : void AssignmentPersistentData::Commit()
327 : : {
328 : 0 : }
329 : :
330 : : // -------------------------------------------------------------------
331 : 0 : AssignmentPersistentData::AssignmentPersistentData()
332 [ # # ][ # # ]: 0 : :ConfigItem( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Office.DataAccess/AddressBook" )))
333 : : {
334 [ # # ][ # # ]: 0 : Sequence< ::rtl::OUString > aStoredNames = GetNodeNames(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Fields")));
335 : 0 : const ::rtl::OUString* pStoredNames = aStoredNames.getConstArray();
336 [ # # ]: 0 : for (sal_Int32 i=0; i<aStoredNames.getLength(); ++i, ++pStoredNames)
337 [ # # ][ # # ]: 0 : m_aStoredFields.insert(*pStoredNames);
338 : 0 : }
339 : :
340 : : // -------------------------------------------------------------------
341 : 0 : AssignmentPersistentData::~AssignmentPersistentData()
342 : : {
343 [ # # ]: 0 : }
344 : :
345 : : // -------------------------------------------------------------------
346 : 0 : sal_Bool AssignmentPersistentData::hasFieldAssignment(const ::rtl::OUString& _rLogicalName)
347 : : {
348 : 0 : return (m_aStoredFields.end() != m_aStoredFields.find(_rLogicalName));
349 : : }
350 : :
351 : : // -------------------------------------------------------------------
352 : 0 : ::rtl::OUString AssignmentPersistentData::getFieldAssignment(const ::rtl::OUString& _rLogicalName)
353 : : {
354 : 0 : ::rtl::OUString sAssignment;
355 [ # # ][ # # ]: 0 : if (hasFieldAssignment(_rLogicalName))
356 : : {
357 [ # # ]: 0 : ::rtl::OUString sFieldPath(RTL_CONSTASCII_USTRINGPARAM("Fields/"));
358 : 0 : sFieldPath += _rLogicalName;
359 [ # # ]: 0 : sFieldPath += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/AssignedFieldName"));
360 [ # # ]: 0 : sAssignment = getStringProperty(sFieldPath);
361 : : }
362 : 0 : return sAssignment;
363 : : }
364 : :
365 : : // -------------------------------------------------------------------
366 : 0 : Any AssignmentPersistentData::getProperty(const sal_Char* _pLocalName) const
367 : : {
368 [ # # ]: 0 : return getProperty(::rtl::OUString::createFromAscii(_pLocalName));
369 : : }
370 : :
371 : : // -------------------------------------------------------------------
372 : 0 : Any AssignmentPersistentData::getProperty(const ::rtl::OUString& _rLocalName) const
373 : : {
374 [ # # ]: 0 : Sequence< ::rtl::OUString > aProperties(&_rLocalName, 1);
375 [ # # ]: 0 : Sequence< Any > aValues = const_cast<AssignmentPersistentData*>(this)->GetProperties(aProperties);
376 : : DBG_ASSERT(aValues.getLength() == 1, "AssignmentPersistentData::getProperty: invalid sequence length!");
377 [ # # ][ # # ]: 0 : return aValues[0];
[ # # ]
378 : : }
379 : :
380 : : // -------------------------------------------------------------------
381 : 0 : ::rtl::OUString AssignmentPersistentData::getStringProperty(const ::rtl::OUString& _rLocalName) const
382 : : {
383 : 0 : ::rtl::OUString sReturn;
384 [ # # ]: 0 : getProperty( _rLocalName ) >>= sReturn;
385 : 0 : return sReturn;
386 : : }
387 : :
388 : : // -------------------------------------------------------------------
389 : 0 : ::rtl::OUString AssignmentPersistentData::getStringProperty(const sal_Char* _pLocalName) const
390 : : {
391 : 0 : ::rtl::OUString sReturn;
392 [ # # ]: 0 : getProperty( _pLocalName ) >>= sReturn;
393 : 0 : return sReturn;
394 : : }
395 : :
396 : : // -------------------------------------------------------------------
397 : 0 : sal_Int32 AssignmentPersistentData::getInt32Property(const sal_Char* _pLocalName) const
398 : : {
399 : 0 : sal_Int32 nReturn = 0;
400 [ # # ]: 0 : getProperty( _pLocalName ) >>= nReturn;
401 : 0 : return nReturn;
402 : : }
403 : :
404 : : // -------------------------------------------------------------------
405 : 0 : void AssignmentPersistentData::setStringProperty(const sal_Char* _pLocalName, const ::rtl::OUString& _rValue)
406 : : {
407 [ # # ]: 0 : Sequence< ::rtl::OUString > aNames(1);
408 [ # # ]: 0 : Sequence< Any > aValues(1);
409 [ # # ]: 0 : aNames[0] = ::rtl::OUString::createFromAscii(_pLocalName);
410 [ # # ][ # # ]: 0 : aValues[0] <<= _rValue;
411 [ # # ][ # # ]: 0 : PutProperties(aNames, aValues);
[ # # ]
412 : 0 : }
413 : :
414 : : // -------------------------------------------------------------------
415 : 0 : void AssignmentPersistentData::setFieldAssignment(const ::rtl::OUString& _rLogicalName, const ::rtl::OUString& _rAssignment)
416 : : {
417 [ # # ]: 0 : if (_rAssignment.isEmpty())
418 : : {
419 [ # # ][ # # ]: 0 : if (hasFieldAssignment(_rLogicalName))
420 : : // the assignment exists but it should be reset
421 [ # # ]: 0 : clearFieldAssignment(_rLogicalName);
422 : 0 : return;
423 : : }
424 : :
425 : : // Fields
426 [ # # ]: 0 : ::rtl::OUString sDescriptionNodePath(RTL_CONSTASCII_USTRINGPARAM("Fields"));
427 : :
428 : : // Fields/<field>
429 : 0 : ::rtl::OUString sFieldElementNodePath(sDescriptionNodePath);
430 [ # # ]: 0 : sFieldElementNodePath += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
431 : 0 : sFieldElementNodePath += _rLogicalName;
432 : :
433 [ # # ]: 0 : Sequence< PropertyValue > aNewFieldDescription(2);
434 : : // Fields/<field>/ProgrammaticFieldName
435 [ # # ]: 0 : aNewFieldDescription[0].Name = sFieldElementNodePath;
436 [ # # ][ # # ]: 0 : aNewFieldDescription[0].Name += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/ProgrammaticFieldName"));
437 [ # # ][ # # ]: 0 : aNewFieldDescription[0].Value <<= _rLogicalName;
438 : : // Fields/<field>/AssignedFieldName
439 [ # # ]: 0 : aNewFieldDescription[1].Name = sFieldElementNodePath;
440 [ # # ][ # # ]: 0 : aNewFieldDescription[1].Name += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/AssignedFieldName"));
441 [ # # ][ # # ]: 0 : aNewFieldDescription[1].Value <<= _rAssignment;
442 : :
443 : : // just set the new value
444 : : #ifdef DBG_UTIL
445 : : sal_Bool bSuccess =
446 : : #endif
447 [ # # ][ # # ]: 0 : SetSetProperties(sDescriptionNodePath, aNewFieldDescription);
[ # # ]
448 [ # # ]: 0 : DBG_ASSERT(bSuccess, "AssignmentPersistentData::setFieldAssignment: could not commit the changes a field!");
449 : : }
450 : :
451 : : // -------------------------------------------------------------------
452 : 0 : void AssignmentPersistentData::clearFieldAssignment(const ::rtl::OUString& _rLogicalName)
453 : : {
454 [ # # ][ # # ]: 0 : if (!hasFieldAssignment(_rLogicalName))
455 : : // nothing to do
456 : 0 : return;
457 : :
458 [ # # ]: 0 : ::rtl::OUString sDescriptionNodePath(RTL_CONSTASCII_USTRINGPARAM("Fields"));
459 [ # # ]: 0 : Sequence< ::rtl::OUString > aNames(&_rLogicalName, 1);
460 [ # # ][ # # ]: 0 : ClearNodeElements(sDescriptionNodePath, aNames);
461 : : }
462 : :
463 : : // -------------------------------------------------------------------
464 : 0 : ::rtl::OUString AssignmentPersistentData::getDatasourceName() const
465 : : {
466 : 0 : return getStringProperty( "DataSourceName" );
467 : : }
468 : :
469 : : // -------------------------------------------------------------------
470 : 0 : ::rtl::OUString AssignmentPersistentData::getCommand() const
471 : : {
472 : 0 : return getStringProperty( "Command" );
473 : : }
474 : :
475 : : // -------------------------------------------------------------------
476 : 0 : void AssignmentPersistentData::setDatasourceName(const ::rtl::OUString& _rName)
477 : : {
478 : 0 : setStringProperty( "DataSourceName", _rName );
479 : 0 : }
480 : :
481 : : // -------------------------------------------------------------------
482 : 0 : void AssignmentPersistentData::setCommand(const ::rtl::OUString& _rCommand)
483 : : {
484 : 0 : setStringProperty( "Command", _rCommand );
485 : 0 : }
486 : :
487 : : // -------------------------------------------------------------------
488 : 0 : sal_Int32 AssignmentPersistentData::getCommandType() const
489 : : {
490 : 0 : return getInt32Property( "CommandType" );
491 : : }
492 : :
493 : : // ===================================================================
494 : : // = AddressBookSourceDialogData
495 : : // ===================================================================
496 : : struct AddressBookSourceDialogData
497 : : {
498 : : FixedText* pFieldLabels[FIELD_PAIRS_VISIBLE * 2];
499 : : ListBox* pFields[FIELD_PAIRS_VISIBLE * 2];
500 : :
501 : : /// when working transient, we need the data source
502 : : Reference< XDataSource >
503 : : m_xTransientDataSource;
504 : : /// current scroll pos in the field list
505 : : sal_Int32 nFieldScrollPos;
506 : : /// the index within m_pFields of the last visible list box. This is redundant, it could be extracted from other members
507 : : sal_Int32 nLastVisibleListIndex;
508 : : /// indicates that we've an odd field number. This member is for efficiency only, it's redundant.
509 : : sal_Bool bOddFieldNumber : 1;
510 : : /// indicates that we're working with the real persistent configuration
511 : : sal_Bool bWorkingPersistent : 1;
512 : :
513 : : /// the strings to use as labels for the field selection listboxes
514 : : StringArray aFieldLabels;
515 : : // the current field assignment
516 : : StringArray aFieldAssignments;
517 : : /// the logical field names
518 : : StringArray aLogicalFieldNames;
519 : :
520 : : IAssigmentData* pConfigData;
521 : :
522 : : // ................................................................
523 : 0 : AddressBookSourceDialogData( )
524 : : :nFieldScrollPos(0)
525 : : ,nLastVisibleListIndex(0)
526 : : ,bOddFieldNumber(sal_False)
527 : : ,bWorkingPersistent( sal_True )
528 [ # # ][ # # ]: 0 : ,pConfigData( new AssignmentPersistentData )
[ # # ][ # # ]
[ # # ][ # # ]
529 : : {
530 : 0 : }
531 : :
532 : : // ................................................................
533 : 0 : AddressBookSourceDialogData( const Reference< XDataSource >& _rxTransientDS, const ::rtl::OUString& _rDataSourceName,
534 : : const ::rtl::OUString& _rTableName, const Sequence< AliasProgrammaticPair >& _rFields )
535 : : :m_xTransientDataSource( _rxTransientDS )
536 : : ,nFieldScrollPos(0)
537 : : ,nLastVisibleListIndex(0)
538 : : ,bOddFieldNumber(sal_False)
539 : : ,bWorkingPersistent( sal_False )
540 [ # # ][ # # ]: 0 : ,pConfigData( new AssigmentTransientData( m_xTransientDataSource, _rDataSourceName, _rTableName, _rFields ) )
[ # # ][ # # ]
[ # # ]
541 : : {
542 : 0 : }
543 : :
544 : 0 : ~AddressBookSourceDialogData()
545 : 0 : {
546 [ # # ][ # # ]: 0 : delete pConfigData;
547 : 0 : }
548 : :
549 : : };
550 : :
551 : : // ===================================================================
552 : : // = AddressBookSourceDialog
553 : : // ===================================================================
554 : : #define INIT_FIELDS() \
555 : : ModalDialog(_pParent, SvtResId( DLG_ADDRESSBOOKSOURCE ))\
556 : : ,m_aDatasourceFrame (this, SvtResId(FL_DATASOURCEFRAME))\
557 : : ,m_aDatasourceLabel (this, SvtResId(FT_DATASOURCE))\
558 : : ,m_aDatasource (this, SvtResId(CB_DATASOURCE))\
559 : : ,m_aAdministrateDatasources (this, SvtResId(PB_ADMINISTATE_DATASOURCES))\
560 : : ,m_aTableLabel (this, SvtResId(FT_TABLE))\
561 : : ,m_aTable (this, SvtResId(CB_TABLE))\
562 : : ,m_aFieldsTitle (this, SvtResId(FT_FIELDS))\
563 : : ,m_aFieldsFrame (this, SvtResId(CT_BORDER))\
564 : : ,m_aFieldScroller (&m_aFieldsFrame, SvtResId(SB_FIELDSCROLLER))\
565 : : ,m_aOK (this, SvtResId(PB_OK))\
566 : : ,m_aCancel (this, SvtResId(PB_CANCEL))\
567 : : ,m_aHelp (this, SvtResId(PB_HELP))\
568 : : ,m_sNoFieldSelection(SVT_RESSTR(STR_NO_FIELD_SELECTION))\
569 : : ,m_xORB(_rxORB)
570 : :
571 : : // -------------------------------------------------------------------
572 : 0 : AddressBookSourceDialog::AddressBookSourceDialog(Window* _pParent,
573 : : const Reference< XMultiServiceFactory >& _rxORB )
574 : : :INIT_FIELDS()
575 [ # # ][ # # ]: 0 : ,m_pImpl( new AddressBookSourceDialogData )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
576 : : {
577 [ # # ]: 0 : implConstruct();
578 : 0 : }
579 : :
580 : : // -------------------------------------------------------------------
581 : 0 : AddressBookSourceDialog::AddressBookSourceDialog( Window* _pParent, const Reference< XMultiServiceFactory >& _rxORB,
582 : : const Reference< XDataSource >& _rxTransientDS, const ::rtl::OUString& _rDataSourceName,
583 : : const ::rtl::OUString& _rTable, const Sequence< AliasProgrammaticPair >& _rMapping )
584 : : :INIT_FIELDS()
585 [ # # ][ # # ]: 0 : ,m_pImpl( new AddressBookSourceDialogData( _rxTransientDS, _rDataSourceName, _rTable, _rMapping ) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
586 : : {
587 [ # # ]: 0 : implConstruct();
588 : 0 : }
589 : :
590 : : // -------------------------------------------------------------------
591 : 0 : void AddressBookSourceDialog::implConstruct()
592 : : {
593 [ # # ]: 0 : for (sal_Int32 row=0; row<FIELD_PAIRS_VISIBLE; ++row)
594 : : {
595 [ # # ]: 0 : for (sal_Int32 column=0; column<2; ++column)
596 : : {
597 : : // the label
598 [ # # ][ # # ]: 0 : m_pImpl->pFieldLabels[row * 2 + column] = new FixedText(&m_aFieldsFrame, SvtResId((sal_uInt16)(FT_FIELD_BASE + row * 2 + column)));
[ # # ]
599 : : // the listbox
600 [ # # ][ # # ]: 0 : m_pImpl->pFields[row * 2 + column] = new ListBox(&m_aFieldsFrame, SvtResId((sal_uInt16)(LB_FIELD_BASE + row * 2 + column)));
[ # # ]
601 [ # # ]: 0 : m_pImpl->pFields[row * 2 + column]->SetDropDownLineCount(15);
602 [ # # ]: 0 : m_pImpl->pFields[row * 2 + column]->SetSelectHdl(LINK(this, AddressBookSourceDialog, OnFieldSelect));
603 : :
604 [ # # ]: 0 : m_pImpl->pFields[row * 2 + column]->SetHelpId(HID_ADDRTEMPL_FIELD_ASSIGNMENT);
605 : : }
606 : : }
607 : :
608 [ # # ][ # # ]: 0 : m_aFieldsFrame.SetStyle((m_aFieldsFrame.GetStyle() | WB_TABSTOP | WB_DIALOGCONTROL) & ~WB_NODIALOGCONTROL);
609 : :
610 : : // correct the z-order
611 [ # # ]: 0 : m_aFieldScroller.SetZOrder(m_pImpl->pFields[FIELD_CONTROLS_VISIBLE - 1], WINDOW_ZORDER_BEHIND);
612 [ # # ]: 0 : m_aOK.SetZOrder(&m_aFieldsFrame, WINDOW_ZORDER_BEHIND);
613 [ # # ]: 0 : m_aCancel.SetZOrder(&m_aOK, WINDOW_ZORDER_BEHIND);
614 : :
615 [ # # ]: 0 : initializeDatasources();
616 : :
617 : : // for the moment, we have a hard coded list of all known fields.
618 : : // A better solution would be to store all known field translations in the configuration, which could be
619 : : // extensible by the user in an arbitrary way.
620 : : // But for the moment we need a quick solution ...
621 : : // (the main thing would be to store the translations to use here in the user interface, besides that, the code
622 : : // should be adjustable with a rather small effort.)
623 : :
624 : : // initialize the strings for the field labels
625 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_FIRSTNAME ));
[ # # ][ # # ]
[ # # ]
626 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_LASTNAME ));
[ # # ][ # # ]
[ # # ]
627 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_COMPANY));
[ # # ][ # # ]
[ # # ]
628 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_DEPARTMENT ));
[ # # ][ # # ]
[ # # ]
629 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_STREET ));
[ # # ][ # # ]
[ # # ]
630 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_ZIPCODE ));
[ # # ][ # # ]
[ # # ]
631 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_CITY ));
[ # # ][ # # ]
[ # # ]
632 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_STATE));
[ # # ][ # # ]
[ # # ]
633 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_COUNTRY ));
[ # # ][ # # ]
[ # # ]
634 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_HOMETEL ));
[ # # ][ # # ]
[ # # ]
635 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_WORKTEL ));
[ # # ][ # # ]
[ # # ]
636 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_OFFICETEL));
[ # # ][ # # ]
[ # # ]
637 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_MOBILE));
[ # # ][ # # ]
[ # # ]
638 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_TELOTHER));
[ # # ][ # # ]
[ # # ]
639 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_PAGER));
[ # # ][ # # ]
[ # # ]
640 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_FAX ));
[ # # ][ # # ]
[ # # ]
641 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_EMAIL ));
[ # # ][ # # ]
[ # # ]
642 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_URL ));
[ # # ][ # # ]
[ # # ]
643 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_TITLE ));
[ # # ][ # # ]
[ # # ]
644 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_POSITION ));
[ # # ][ # # ]
[ # # ]
645 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_INITIALS ));
[ # # ][ # # ]
[ # # ]
646 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_ADDRFORM ));
[ # # ][ # # ]
[ # # ]
647 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_SALUTATION ));
[ # # ][ # # ]
[ # # ]
648 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_ID));
[ # # ][ # # ]
[ # # ]
649 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_CALENDAR));
[ # # ][ # # ]
[ # # ]
650 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_INVITE));
[ # # ][ # # ]
[ # # ]
651 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_NOTE));
[ # # ][ # # ]
[ # # ]
652 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_USER1));
[ # # ][ # # ]
[ # # ]
653 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_USER2));
[ # # ][ # # ]
[ # # ]
654 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_USER3));
[ # # ][ # # ]
[ # # ]
655 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( SVT_RESSTR( STR_FIELD_USER4));
[ # # ][ # # ]
[ # # ]
656 : :
657 : : // force a even number of known fields
658 : 0 : m_pImpl->bOddFieldNumber = (m_pImpl->aFieldLabels.size() % 2) != 0;
659 [ # # ]: 0 : if (m_pImpl->bOddFieldNumber)
660 [ # # ][ # # ]: 0 : m_pImpl->aFieldLabels.push_back( String() );
[ # # ]
661 : :
662 : : // limit the scrollbar range accordingly
663 : 0 : sal_Int32 nOverallFieldPairs = m_pImpl->aFieldLabels.size() / 2;
664 [ # # ]: 0 : m_aFieldScroller.SetRange( Range(0, nOverallFieldPairs - FIELD_PAIRS_VISIBLE) );
665 : 0 : m_aFieldScroller.SetLineSize(1);
666 : 0 : m_aFieldScroller.SetPageSize(FIELD_PAIRS_VISIBLE);
667 : :
668 : : // reset the current field assignments
669 [ # # ]: 0 : m_pImpl->aFieldAssignments.resize(m_pImpl->aFieldLabels.size());
670 : : // (empty strings mean "no assignment")
671 : :
672 : : // some knittings
673 [ # # ]: 0 : m_aFieldScroller.SetScrollHdl(LINK(this, AddressBookSourceDialog, OnFieldScroll));
674 [ # # ]: 0 : m_aAdministrateDatasources.SetClickHdl(LINK(this, AddressBookSourceDialog, OnAdministrateDatasources));
675 [ # # ]: 0 : m_aDatasource.EnableAutocomplete(sal_True);
676 [ # # ]: 0 : m_aTable.EnableAutocomplete(sal_True);
677 [ # # ]: 0 : m_aTable.SetGetFocusHdl(LINK(this, AddressBookSourceDialog, OnComboGetFocus));
678 [ # # ]: 0 : m_aDatasource.SetGetFocusHdl(LINK(this, AddressBookSourceDialog, OnComboGetFocus));
679 [ # # ]: 0 : m_aTable.SetLoseFocusHdl(LINK(this, AddressBookSourceDialog, OnComboLoseFocus));
680 [ # # ]: 0 : m_aDatasource.SetLoseFocusHdl(LINK(this, AddressBookSourceDialog, OnComboLoseFocus));
681 [ # # ]: 0 : m_aTable.SetSelectHdl(LINK(this, AddressBookSourceDialog, OnComboSelect));
682 [ # # ]: 0 : m_aDatasource.SetSelectHdl(LINK(this, AddressBookSourceDialog, OnComboSelect));
683 [ # # ]: 0 : m_aOK.SetClickHdl(LINK(this, AddressBookSourceDialog, OnOkClicked));
684 : :
685 [ # # ]: 0 : m_aDatasource.SetDropDownLineCount(15);
686 : :
687 : : // initialize the field controls
688 [ # # ]: 0 : resetFields();
689 [ # # ]: 0 : m_aFieldScroller.SetThumbPos(0);
690 : 0 : m_pImpl->nFieldScrollPos = -1;
691 [ # # ]: 0 : implScrollFields(0, sal_False, sal_False);
692 : :
693 : : // the logical names
694 [ # # ][ # # ]: 0 : rtl::OUString sLogicalFieldNames(SVT_RESSTR(STR_LOGICAL_FIELD_NAMES));
695 [ # # ]: 0 : sal_Int32 nAdjustedTokenCount = comphelper::string::getTokenCount(sLogicalFieldNames, ';') + (m_pImpl->bOddFieldNumber ? 1 : 0);
696 : : DBG_ASSERT(nAdjustedTokenCount == (sal_Int32)m_pImpl->aFieldLabels.size(),
697 : : "AddressBookSourceDialog::AddressBookSourceDialog: inconsistence between logical and UI field names!");
698 [ # # ]: 0 : m_pImpl->aLogicalFieldNames.reserve(nAdjustedTokenCount);
699 [ # # ]: 0 : for (sal_Int32 i = 0; i<nAdjustedTokenCount; ++i)
700 [ # # ][ # # ]: 0 : m_pImpl->aLogicalFieldNames.push_back(comphelper::string::getToken(sLogicalFieldNames, i, ';'));
[ # # ]
701 : :
702 [ # # ][ # # ]: 0 : PostUserEvent(LINK(this, AddressBookSourceDialog, OnDelayedInitialize));
703 : : // so the dialog will at least show up before we do the loading of the
704 : : // configuration data and the (maybe time consuming) analysis of the data source/table to select
705 : :
706 [ # # ]: 0 : FreeResource();
707 : :
708 [ # # ]: 0 : if ( !m_pImpl->bWorkingPersistent )
709 : : {
710 [ # # ]: 0 : StyleSettings aSystemStyle = GetSettings().GetStyleSettings();
711 : 0 : const Color& rNewColor = aSystemStyle.GetDialogColor();
712 : :
713 [ # # ]: 0 : m_aDatasource.SetReadOnly( sal_True );
714 [ # # ][ # # ]: 0 : m_aDatasource.SetBackground( Wallpaper( rNewColor ) );
[ # # ]
715 [ # # ]: 0 : m_aDatasource.SetControlBackground( rNewColor );
716 : :
717 [ # # ]: 0 : m_aTable.SetReadOnly( sal_True );
718 [ # # ][ # # ]: 0 : m_aTable.SetBackground( Wallpaper( rNewColor ) );
[ # # ]
719 [ # # ]: 0 : m_aTable.SetControlBackground( rNewColor );
720 : :
721 [ # # ][ # # ]: 0 : m_aAdministrateDatasources.Hide( );
722 : 0 : }
723 : 0 : }
724 : :
725 : : // -------------------------------------------------------------------
726 : 0 : void AddressBookSourceDialog::getFieldMapping(Sequence< AliasProgrammaticPair >& _rMapping) const
727 : : {
728 [ # # ]: 0 : _rMapping.realloc( m_pImpl->aLogicalFieldNames.size() );
729 [ # # ]: 0 : AliasProgrammaticPair* pPair = _rMapping.getArray();
730 : :
731 : 0 : ::rtl::OUString sCurrent;
732 [ # # # # ]: 0 : for ( ConstStringArrayIterator aProgrammatic = m_pImpl->aLogicalFieldNames.begin();
[ # # ][ # # ]
733 : 0 : aProgrammatic != m_pImpl->aLogicalFieldNames.end();
734 : : ++aProgrammatic
735 : : )
736 : : {
737 [ # # ][ # # ]: 0 : sCurrent = *aProgrammatic;
738 [ # # ][ # # ]: 0 : if ( m_pImpl->pConfigData->hasFieldAssignment( sCurrent ) )
739 : : {
740 : : // the user gave us an assignment for this field
741 [ # # ][ # # ]: 0 : pPair->ProgrammaticName = *aProgrammatic;
742 [ # # ][ # # ]: 0 : pPair->Alias = m_pImpl->pConfigData->getFieldAssignment( *aProgrammatic );
[ # # ]
743 : 0 : ++pPair;
744 : : }
745 : : }
746 : :
747 [ # # ][ # # ]: 0 : _rMapping.realloc( pPair - _rMapping.getArray() );
748 : 0 : }
749 : :
750 : : // -------------------------------------------------------------------
751 : 0 : void AddressBookSourceDialog::loadConfiguration()
752 : : {
753 [ # # ]: 0 : ::rtl::OUString sName = m_pImpl->pConfigData->getDatasourceName();
754 [ # # ]: 0 : INetURLObject aURL( sName );
755 [ # # ]: 0 : if( aURL.GetProtocol() != INET_PROT_NOT_VALID )
756 : : {
757 [ # # ][ # # ]: 0 : OFileNotation aFileNotation( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
758 [ # # ][ # # ]: 0 : sName = aFileNotation.get(OFileNotation::N_SYSTEM);
759 : : }
760 : :
761 [ # # ][ # # ]: 0 : m_aDatasource.SetText(sName);
[ # # ]
762 [ # # ][ # # ]: 0 : m_aTable.SetText(m_pImpl->pConfigData->getCommand());
[ # # ][ # # ]
763 : : // we ignore the CommandType: only tables are supported
764 : :
765 : : // the logical names for the fields
766 : : DBG_ASSERT(m_pImpl->aLogicalFieldNames.size() == m_pImpl->aFieldAssignments.size(),
767 : : "AddressBookSourceDialog::loadConfiguration: inconsistence between field names and field assignments!");
768 : :
769 [ # # ]: 0 : ConstStringArrayIterator aLogical = m_pImpl->aLogicalFieldNames.begin();
770 : 0 : StringArrayIterator aAssignment = m_pImpl->aFieldAssignments.begin();
771 [ # # # # ]: 0 : for ( ;
[ # # ][ # # ]
772 : 0 : aLogical < m_pImpl->aLogicalFieldNames.end();
773 : : ++aLogical, ++aAssignment
774 : : )
775 [ # # ][ # # ]: 0 : *aAssignment = m_pImpl->pConfigData->getFieldAssignment(*aLogical);
[ # # ][ # # ]
[ # # ][ # # ]
776 : 0 : }
777 : :
778 : : // -------------------------------------------------------------------
779 [ # # ][ # # ]: 0 : AddressBookSourceDialog::~AddressBookSourceDialog()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
780 : : {
781 : : sal_Int32 i;
782 [ # # ]: 0 : for (i=0; i<FIELD_CONTROLS_VISIBLE; ++i)
783 : : {
784 [ # # ][ # # ]: 0 : delete m_pImpl->pFieldLabels[i];
785 [ # # ][ # # ]: 0 : delete m_pImpl->pFields[i];
786 : : }
787 : :
788 [ # # ][ # # ]: 0 : delete m_pImpl;
789 [ # # ]: 0 : }
790 : :
791 : : // -------------------------------------------------------------------
792 : 0 : void AddressBookSourceDialog::initializeDatasources()
793 : : {
794 [ # # ]: 0 : if (!m_xDatabaseContext.is())
795 : : {
796 : : DBG_ASSERT(m_xORB.is(), "AddressBookSourceDialog::initializeDatasources: no service factory!");
797 [ # # ]: 0 : if (!m_xORB.is())
798 : : return;
799 : :
800 : 0 : const rtl::OUString sContextServiceName("com.sun.star.sdb.DatabaseContext");
801 : : try
802 : : {
803 [ # # ][ # # ]: 0 : m_xDatabaseContext = Reference< XNameAccess >(m_xORB->createInstance(sContextServiceName), UNO_QUERY);
[ # # ][ # # ]
[ # # ]
804 : : }
805 [ # # ]: 0 : catch(Exception&) { }
806 [ # # ]: 0 : if (!m_xDatabaseContext.is())
807 : : {
808 [ # # ][ # # ]: 0 : ShowServiceNotAvailableError( this, sContextServiceName, sal_False);
[ # # ]
809 : : return;
810 [ # # ]: 0 : }
811 : : }
812 [ # # ]: 0 : m_aDatasource.Clear();
813 : :
814 : : // fill the datasources listbox
815 [ # # ]: 0 : Sequence< ::rtl::OUString > aDatasourceNames;
816 : : try
817 : : {
818 [ # # ][ # # ]: 0 : aDatasourceNames = m_xDatabaseContext->getElementNames();
[ # # ][ # # ]
[ # # ]
819 : : }
820 [ # # ]: 0 : catch(Exception&)
821 : : {
822 : : OSL_FAIL("AddressBookSourceDialog::initializeDatasources: caught an exception while asking for the data source names!");
823 : : }
824 : 0 : const ::rtl::OUString* pDatasourceNames = aDatasourceNames.getConstArray();
825 : 0 : const ::rtl::OUString* pEnd = pDatasourceNames + aDatasourceNames.getLength();
826 [ # # ]: 0 : for (; pDatasourceNames < pEnd; ++pDatasourceNames)
827 [ # # ][ # # ]: 0 : m_aDatasource.InsertEntry(*pDatasourceNames);
[ # # ][ # # ]
828 : : }
829 : :
830 : : // -------------------------------------------------------------------
831 : 0 : IMPL_LINK(AddressBookSourceDialog, OnFieldScroll, ScrollBar*, _pScrollBar)
832 : : {
833 : 0 : implScrollFields( _pScrollBar->GetThumbPos(), sal_True, sal_True );
834 : 0 : return 0L;
835 : : }
836 : :
837 : : // -------------------------------------------------------------------
838 : 0 : void AddressBookSourceDialog::resetTables()
839 : : {
840 [ # # ]: 0 : if (!m_xDatabaseContext.is())
841 : : return;
842 : :
843 [ # # ]: 0 : WaitObject aWaitCursor(this);
844 : :
845 : : // no matter what we do here, we handled the currently selected data source (no matter if successfull or not)
846 [ # # ]: 0 : m_aDatasource.SaveValue();
847 : :
848 : : // create an interaction handler (may be needed for connecting)
849 : 0 : const rtl::OUString sInteractionHandlerServiceName("com.sun.star.task.InteractionHandler");
850 : 0 : Reference< XInteractionHandler > xHandler;
851 : : try
852 : : {
853 [ # # ][ # # ]: 0 : xHandler = Reference< XInteractionHandler >(m_xORB->createInstance(sInteractionHandlerServiceName), UNO_QUERY);
[ # # ][ # # ]
[ # # ]
854 : : }
855 [ # # ]: 0 : catch(Exception&) { }
856 [ # # ]: 0 : if (!xHandler.is())
857 : : {
858 [ # # ][ # # ]: 0 : ShowServiceNotAvailableError(this, sInteractionHandlerServiceName, sal_True);
[ # # ]
859 : : return;
860 : : }
861 : :
862 : : // the currently selected table
863 [ # # ][ # # ]: 0 : ::rtl::OUString sOldTable = m_aTable.GetText();
[ # # ]
864 : :
865 [ # # ]: 0 : m_aTable.Clear();
866 : :
867 [ # # ]: 0 : m_xCurrentDatasourceTables= NULL;
868 : :
869 : : // get the tables of the connection
870 [ # # ]: 0 : Sequence< ::rtl::OUString > aTableNames;
871 : 0 : Any aException;
872 : : try
873 : : {
874 : 0 : Reference< XCompletedConnection > xDS;
875 [ # # ]: 0 : if ( m_pImpl->bWorkingPersistent )
876 : : {
877 [ # # ]: 0 : String sSelectedDS = lcl_getSelectedDataSource( m_aDatasource );
878 : :
879 : : // get the data source the user has chosen and let it build a connection
880 [ # # ][ # # ]: 0 : INetURLObject aURL( sSelectedDS );
881 [ # # ][ # # ]: 0 : if ( aURL.GetProtocol() != INET_PROT_NOT_VALID || m_xDatabaseContext->hasByName(sSelectedDS) )
[ # # ][ # # ]
[ # # ]
[ # # # # ]
[ # # ]
882 [ # # ][ # # ]: 0 : m_xDatabaseContext->getByName( sSelectedDS ) >>= xDS;
[ # # ][ # # ]
[ # # ][ # # ]
883 : : }
884 : : else
885 : : {
886 [ # # ][ # # ]: 0 : xDS = xDS.query( m_pImpl->m_xTransientDataSource );
887 : : }
888 : :
889 : : // build the connection
890 : 0 : Reference< XConnection > xConn;
891 [ # # ]: 0 : if (xDS.is())
892 [ # # ][ # # ]: 0 : xConn = xDS->connectWithCompletion(xHandler);
[ # # ]
893 : :
894 : : // get the table names
895 [ # # ]: 0 : Reference< XTablesSupplier > xSupplTables(xConn, UNO_QUERY);
896 [ # # ]: 0 : if (xSupplTables.is())
897 : : {
898 [ # # ][ # # ]: 0 : m_xCurrentDatasourceTables = Reference< XNameAccess >(xSupplTables->getTables(), UNO_QUERY);
[ # # ][ # # ]
899 [ # # ]: 0 : if (m_xCurrentDatasourceTables.is())
900 [ # # ][ # # ]: 0 : aTableNames = m_xCurrentDatasourceTables->getElementNames();
[ # # ][ # # ]
901 : 0 : }
902 : : }
903 [ # # # # ]: 0 : catch(const SQLContext& e) { aException <<= e; }
904 [ # # # # ]: 0 : catch(const SQLWarning& e) { aException <<= e; }
905 [ # # # # : 0 : catch(const SQLException& e) { aException <<= e; }
# # # #
# ]
906 [ # # ]: 0 : catch(Exception&)
907 : : {
908 : : OSL_FAIL("AddressBookSourceDialog::resetTables: could not retrieve the table!");
909 : : }
910 : :
911 [ # # ]: 0 : if (aException.hasValue())
912 : : {
913 [ # # ][ # # ]: 0 : Reference< XInteractionRequest > xRequest = new OInteractionRequest(aException);
[ # # # # ]
914 : : try
915 : : {
916 [ # # ][ # # ]: 0 : xHandler->handle(xRequest);
917 : : }
918 [ # # ]: 0 : catch(Exception&) { }
919 : 0 : return;
920 : : }
921 : :
922 : 0 : sal_Bool bKnowOldTable = sal_False;
923 : : // fill the table list
924 : 0 : const ::rtl::OUString* pTableNames = aTableNames.getConstArray();
925 : 0 : const ::rtl::OUString* pEnd = pTableNames + aTableNames.getLength();
926 [ # # ]: 0 : for (;pTableNames != pEnd; ++pTableNames)
927 : : {
928 [ # # ][ # # ]: 0 : m_aTable.InsertEntry(*pTableNames);
[ # # ]
929 [ # # ]: 0 : if (0 == pTableNames->compareTo(sOldTable))
930 : 0 : bKnowOldTable = sal_True;
931 : : }
932 : :
933 : : // set the old table, if the new data source knows a table with this name, too. Else reset the tables edit field.
934 [ # # ]: 0 : if (!bKnowOldTable)
935 : 0 : sOldTable = ::rtl::OUString();
936 [ # # ][ # # ]: 0 : m_aTable.SetText(sOldTable);
[ # # ]
937 : :
938 [ # # ][ # # ]: 0 : resetFields();
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
939 : : }
940 : :
941 : : // -------------------------------------------------------------------
942 : 0 : void AddressBookSourceDialog::resetFields()
943 : : {
944 [ # # ]: 0 : WaitObject aWaitCursor(this);
945 : :
946 : : // no matter what we do here, we handled the currently selected table (no matter if successfull or not)
947 [ # # ]: 0 : m_aDatasource.SaveValue();
948 : :
949 [ # # ]: 0 : String sSelectedTable = m_aTable.GetText();
950 [ # # ]: 0 : Sequence< ::rtl::OUString > aColumnNames;
951 : : try
952 : : {
953 [ # # ]: 0 : if (m_xCurrentDatasourceTables.is())
954 : : {
955 : : // get the table and the columns
956 : 0 : Reference< XColumnsSupplier > xSuppTableCols;
957 [ # # ][ # # ]: 0 : if (m_xCurrentDatasourceTables->hasByName(sSelectedTable))
[ # # ][ # # ]
958 [ # # ][ # # ]: 0 : ::cppu::extractInterface(xSuppTableCols, m_xCurrentDatasourceTables->getByName(sSelectedTable));
[ # # ][ # # ]
959 : 0 : Reference< XNameAccess > xColumns;
960 [ # # ]: 0 : if (xSuppTableCols.is())
961 [ # # ][ # # ]: 0 : xColumns = xSuppTableCols->getColumns();
[ # # ]
962 [ # # ]: 0 : if (xColumns.is())
963 [ # # ][ # # ]: 0 : aColumnNames = xColumns->getElementNames();
[ # # ][ # # ]
[ # # ]
964 : : }
965 : : }
966 [ # # ]: 0 : catch(Exception&)
967 : : {
968 : : OSL_FAIL("AddressBookSourceDialog::resetFields: could not retrieve the table columns!");
969 : : }
970 : :
971 : :
972 : 0 : const ::rtl::OUString* pColumnNames = aColumnNames.getConstArray();
973 : 0 : const ::rtl::OUString* pEnd = pColumnNames + aColumnNames.getLength();
974 : :
975 : : // for quicker access
976 [ # # ]: 0 : ::std::set< String > aColumnNameSet;
977 [ # # ]: 0 : for (pColumnNames = aColumnNames.getConstArray(); pColumnNames != pEnd; ++pColumnNames)
978 [ # # ][ # # ]: 0 : aColumnNameSet.insert(*pColumnNames);
[ # # ]
979 : :
980 [ # # ]: 0 : std::vector<String>::iterator aInitialSelection = m_pImpl->aFieldAssignments.begin() + m_pImpl->nFieldScrollPos;
981 : :
982 : 0 : ListBox** pListbox = m_pImpl->pFields;
983 [ # # ]: 0 : String sSaveSelection;
984 [ # # ][ # # ]: 0 : for (sal_Int32 i=0; i<FIELD_CONTROLS_VISIBLE; ++i, ++pListbox, ++aInitialSelection)
985 : : {
986 [ # # ][ # # ]: 0 : sSaveSelection = (*pListbox)->GetSelectEntry();
[ # # ]
987 : :
988 [ # # ]: 0 : (*pListbox)->Clear();
989 : :
990 : : // the one entry for "no selection"
991 [ # # ]: 0 : (*pListbox)->InsertEntry(m_sNoFieldSelection, 0);
992 : : // as it's entry data, set the index of the list box in our array
993 [ # # ]: 0 : (*pListbox)->SetEntryData(0, reinterpret_cast<void*>(i));
994 : :
995 : : // the field names
996 [ # # ]: 0 : for (pColumnNames = aColumnNames.getConstArray(); pColumnNames != pEnd; ++pColumnNames)
997 [ # # ][ # # ]: 0 : (*pListbox)->InsertEntry(*pColumnNames);
[ # # ]
998 : :
999 [ # # ][ # # ]: 0 : if (aInitialSelection->Len() && (aColumnNameSet.end() != aColumnNameSet.find(*aInitialSelection)))
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # #
# # ]
1000 : : // we can select the entry as specified in our field assignment array
1001 [ # # ][ # # ]: 0 : (*pListbox)->SelectEntry(*aInitialSelection);
1002 : : else
1003 : : // try to restore the selection
1004 [ # # ][ # # ]: 0 : if (aColumnNameSet.end() != aColumnNameSet.find(sSaveSelection))
[ # # ]
1005 : : // the old selection is a valid column name
1006 [ # # ]: 0 : (*pListbox)->SelectEntry(sSaveSelection);
1007 : : else
1008 : : // select the <none> entry
1009 [ # # ]: 0 : (*pListbox)->SelectEntryPos(0);
1010 : : }
1011 : :
1012 : : // adjust m_pImpl->aFieldAssignments
1013 [ # # # # ]: 0 : for ( StringArrayIterator aAdjust = m_pImpl->aFieldAssignments.begin();
[ # # ]
1014 : 0 : aAdjust != m_pImpl->aFieldAssignments.end();
1015 : : ++aAdjust
1016 : : )
1017 [ # # ][ # # ]: 0 : if (aAdjust->Len())
1018 [ # # ][ # # ]: 0 : if (aColumnNameSet.end() == aColumnNameSet.find(*aAdjust))
[ # # ][ # # ]
1019 [ # # ][ # # ]: 0 : aAdjust->Erase();
[ # # ][ # # ]
[ # # ][ # # ]
1020 : 0 : }
1021 : :
1022 : : // -------------------------------------------------------------------
1023 : 0 : IMPL_LINK(AddressBookSourceDialog, OnFieldSelect, ListBox*, _pListbox)
1024 : : {
1025 : : // the index of the affected list box in our array
1026 : 0 : sal_IntPtr nListBoxIndex = reinterpret_cast<sal_IntPtr>(_pListbox->GetEntryData(0));
1027 : : DBG_ASSERT(nListBoxIndex >= 0 && nListBoxIndex < FIELD_CONTROLS_VISIBLE,
1028 : : "AddressBookSourceDialog::OnFieldScroll: invalid list box entry!");
1029 : :
1030 : : // update the array where we remember the field selections
1031 [ # # ]: 0 : if (0 == _pListbox->GetSelectEntryPos())
1032 : : // it's the "no field selection" entry
1033 [ # # ][ # # ]: 0 : m_pImpl->aFieldAssignments[m_pImpl->nFieldScrollPos * 2 + nListBoxIndex] = String();
1034 : : else
1035 : : // it's a regular field entry
1036 [ # # ][ # # ]: 0 : m_pImpl->aFieldAssignments[m_pImpl->nFieldScrollPos * 2 + nListBoxIndex] = _pListbox->GetSelectEntry();
1037 : :
1038 : 0 : return 0L;
1039 : : }
1040 : :
1041 : : // -------------------------------------------------------------------
1042 : 0 : void AddressBookSourceDialog::implScrollFields(sal_Int32 _nPos, sal_Bool _bAdjustFocus, sal_Bool _bAdjustScrollbar)
1043 : : {
1044 [ # # ]: 0 : if (_nPos == m_pImpl->nFieldScrollPos)
1045 : : // nothing to do
1046 : 0 : return;
1047 : :
1048 : : // loop through our field control rows and do some adjustments
1049 : : // for the new texts
1050 : 0 : FixedText** pLeftLabelControl = m_pImpl->pFieldLabels;
1051 : 0 : FixedText** pRightLabelControl = pLeftLabelControl + 1;
1052 [ # # ][ # # ]: 0 : ConstStringArrayIterator pLeftColumnLabel = m_pImpl->aFieldLabels.begin() + 2 * _nPos;
1053 [ # # ]: 0 : ConstStringArrayIterator pRightColumnLabel = pLeftColumnLabel + 1;
1054 : :
1055 : : // for the focus movement and the selection scroll
1056 : 0 : ListBox** pLeftListControl = m_pImpl->pFields;
1057 : 0 : ListBox** pRightListControl = pLeftListControl + 1;
1058 : :
1059 : : // for the focus movement
1060 : 0 : sal_Int32 nOldFocusRow = -1;
1061 : 0 : sal_Int32 nOldFocusColumn = 0;
1062 : :
1063 : : // for the selection scroll
1064 [ # # ][ # # ]: 0 : ConstStringArrayIterator pLeftAssignment = m_pImpl->aFieldAssignments.begin() + 2 * _nPos;
1065 [ # # ]: 0 : ConstStringArrayIterator pRightAssignment = pLeftAssignment + 1;
1066 : :
1067 : 0 : m_pImpl->nLastVisibleListIndex = -1;
1068 : : // loop
1069 [ # # ]: 0 : for (sal_Int32 i=0; i<FIELD_PAIRS_VISIBLE; ++i)
1070 : : {
1071 [ # # ][ # # ]: 0 : if ((*pLeftListControl)->HasChildPathFocus())
1072 : : {
1073 : 0 : nOldFocusRow = i;
1074 : 0 : nOldFocusColumn = 0;
1075 : : }
1076 [ # # ][ # # ]: 0 : else if ((*pRightListControl)->HasChildPathFocus())
1077 : : {
1078 : 0 : nOldFocusRow = i;
1079 : 0 : nOldFocusColumn = 1;
1080 : : }
1081 : :
1082 : : // the new texts of the label controls
1083 [ # # ][ # # ]: 0 : (*pLeftLabelControl)->SetText(*pLeftColumnLabel);
1084 [ # # ][ # # ]: 0 : (*pRightLabelControl)->SetText(*pRightColumnLabel);
1085 : :
1086 : : // we may have to hide the controls in the right column, if we have no label text for it
1087 : : // (which means we have an odd number of fields, though we forced our internal arrays to
1088 : : // be even-sized for easier handling)
1089 : : // (If sometimes we support an arbitrary number of field assignments, we would have to care for
1090 : : // an invisible left hand side column, too. But right now, the left hand side controls are always
1091 : : // visible)
1092 [ # # ]: 0 : sal_Bool bHideRightColumn = (0 == pRightColumnLabel->Len());
1093 [ # # ]: 0 : (*pRightLabelControl)->Show(!bHideRightColumn);
1094 [ # # ]: 0 : (*pRightListControl)->Show(!bHideRightColumn);
1095 : : // the new selections of the listboxes
1096 [ # # ][ # # ]: 0 : implSelectField(*pLeftListControl, *pLeftAssignment);
1097 [ # # ][ # # ]: 0 : implSelectField(*pRightListControl, *pRightAssignment);
1098 : :
1099 : : // the index of the last visible list box
1100 : 0 : ++m_pImpl->nLastVisibleListIndex; // the left hand side box is always visible
1101 [ # # ]: 0 : if (!bHideRightColumn)
1102 : 0 : ++m_pImpl->nLastVisibleListIndex;
1103 : :
1104 : : // increment ...
1105 [ # # ]: 0 : if ( i < FIELD_PAIRS_VISIBLE - 1 )
1106 : : { // (not in the very last round, here the +=2 could result in an invalid
1107 : : // iterator position, which causes an abort in a non-product version
1108 : 0 : pLeftLabelControl += 2;
1109 : 0 : pRightLabelControl += 2;
1110 [ # # ]: 0 : pLeftColumnLabel += 2;
1111 [ # # ]: 0 : pRightColumnLabel += 2;
1112 : :
1113 : 0 : pLeftListControl += 2;
1114 : 0 : pRightListControl += 2;
1115 [ # # ]: 0 : pLeftAssignment += 2;
1116 [ # # ]: 0 : pRightAssignment += 2;
1117 : : }
1118 : : }
1119 : :
1120 [ # # ][ # # ]: 0 : if (_bAdjustFocus && (nOldFocusRow >= 0))
1121 : : { // we have to adjust the focus and one of the list boxes has the focus
1122 : 0 : sal_Int32 nDelta = m_pImpl->nFieldScrollPos - _nPos;
1123 : : // the new row for the focus
1124 : 0 : sal_Int32 nNewFocusRow = nOldFocusRow + nDelta;
1125 : : // normalize
1126 [ # # ]: 0 : nNewFocusRow = std::min(nNewFocusRow, (sal_Int32)(FIELD_PAIRS_VISIBLE - 1), ::std::less< sal_Int32 >());
1127 [ # # ]: 0 : nNewFocusRow = std::max(nNewFocusRow, (sal_Int32)0, ::std::less< sal_Int32 >());
1128 : : // set the new focus (in the same column)
1129 [ # # ]: 0 : m_pImpl->pFields[nNewFocusRow * 2 + nOldFocusColumn]->GrabFocus();
1130 : : }
1131 : :
1132 : 0 : m_pImpl->nFieldScrollPos = _nPos;
1133 : :
1134 [ # # ]: 0 : if (_bAdjustScrollbar)
1135 [ # # ]: 0 : m_aFieldScroller.SetThumbPos(m_pImpl->nFieldScrollPos);
1136 : : }
1137 : :
1138 : : // -------------------------------------------------------------------
1139 : 0 : void AddressBookSourceDialog::implSelectField(ListBox* _pBox, const String& _rText)
1140 : : {
1141 [ # # ]: 0 : if (_rText.Len())
1142 : : // a valid field name
1143 : 0 : _pBox->SelectEntry(_rText);
1144 : : else
1145 : : // no selection for this item
1146 : 0 : _pBox->SelectEntryPos(0);
1147 : 0 : }
1148 : :
1149 : : // -------------------------------------------------------------------
1150 : 0 : IMPL_LINK_NOARG(AddressBookSourceDialog, OnDelayedInitialize)
1151 : : {
1152 : : // load the initial data from the configuration
1153 : 0 : loadConfiguration();
1154 : 0 : resetTables();
1155 : : // will reset the tables/fields implicitly
1156 : :
1157 [ # # ]: 0 : if ( !m_pImpl->bWorkingPersistent )
1158 [ # # ]: 0 : if ( m_pImpl->pFields[0] )
1159 : 0 : m_pImpl->pFields[0]->GrabFocus();
1160 : :
1161 : 0 : return 0L;
1162 : : }
1163 : :
1164 : : // -------------------------------------------------------------------
1165 : 0 : IMPL_LINK(AddressBookSourceDialog, OnComboSelect, ComboBox*, _pBox)
1166 : : {
1167 [ # # ]: 0 : if (_pBox == &m_aDatasource)
1168 : 0 : resetTables();
1169 : : else
1170 : 0 : resetFields();
1171 : 0 : return 0;
1172 : : }
1173 : :
1174 : : // -------------------------------------------------------------------
1175 : 0 : IMPL_LINK(AddressBookSourceDialog, OnComboGetFocus, ComboBox*, _pBox)
1176 : : {
1177 : 0 : _pBox->SaveValue();
1178 : 0 : return 0L;
1179 : : }
1180 : :
1181 : : // -------------------------------------------------------------------
1182 : 0 : IMPL_LINK(AddressBookSourceDialog, OnComboLoseFocus, ComboBox*, _pBox)
1183 : : {
1184 [ # # ][ # # ]: 0 : if (_pBox->GetSavedValue() != _pBox->GetText())
1185 : : {
1186 [ # # ]: 0 : if (_pBox == &m_aDatasource)
1187 : 0 : resetTables();
1188 : : else
1189 : 0 : resetFields();
1190 : : }
1191 : 0 : return 0L;
1192 : : }
1193 : :
1194 : : // -------------------------------------------------------------------
1195 : 0 : IMPL_LINK_NOARG(AddressBookSourceDialog, OnOkClicked)
1196 : : {
1197 [ # # ]: 0 : String sSelectedDS = lcl_getSelectedDataSource( m_aDatasource );
1198 [ # # ]: 0 : if ( m_pImpl->bWorkingPersistent )
1199 : : {
1200 [ # # ][ # # ]: 0 : m_pImpl->pConfigData->setDatasourceName(sSelectedDS);
1201 [ # # ][ # # ]: 0 : m_pImpl->pConfigData->setCommand(m_aTable.GetText());
[ # # ][ # # ]
1202 : : }
1203 : :
1204 : : // set the field assignments
1205 [ # # ]: 0 : ConstStringArrayIterator aLogical = m_pImpl->aLogicalFieldNames.begin();
1206 [ # # ]: 0 : ConstStringArrayIterator aAssignment = m_pImpl->aFieldAssignments.begin();
1207 [ # # ]: 0 : for ( ;
[ # # # # ]
[ # # ]
1208 : 0 : aLogical < m_pImpl->aLogicalFieldNames.end();
1209 : : ++aLogical, ++aAssignment
1210 : : )
1211 [ # # ][ # # ]: 0 : m_pImpl->pConfigData->setFieldAssignment(*aLogical, *aAssignment);
[ # # ][ # # ]
[ # # ]
1212 : :
1213 : :
1214 [ # # ]: 0 : EndDialog(RET_OK);
1215 [ # # ]: 0 : return 0L;
1216 : : }
1217 : :
1218 : : // -------------------------------------------------------------------
1219 : 0 : IMPL_LINK_NOARG(AddressBookSourceDialog, OnAdministrateDatasources)
1220 : : {
1221 : : // collect some initial arguments for the dialog
1222 [ # # ]: 0 : Sequence< Any > aArgs(1);
1223 [ # # ][ # # ]: 0 : aArgs[0] <<= PropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParentWindow")), 0, makeAny(VCLUnoHelper::GetInterface(this)), PropertyState_DIRECT_VALUE);
[ # # ][ # # ]
[ # # ]
1224 : :
1225 : : // create the dialog object
1226 : 0 : const rtl::OUString sDialogServiceName("com.sun.star.ui.dialogs.AddressBookSourcePilot");
1227 : 0 : Reference< XExecutableDialog > xAdminDialog;
1228 : : try
1229 : : {
1230 [ # # ][ # # ]: 0 : xAdminDialog = Reference< XExecutableDialog >(m_xORB->createInstanceWithArguments(sDialogServiceName, aArgs), UNO_QUERY);
[ # # ][ # # ]
[ # # ]
1231 : : }
1232 [ # # ]: 0 : catch(Exception&) { }
1233 [ # # ]: 0 : if (!xAdminDialog.is())
1234 : : {
1235 [ # # ][ # # ]: 0 : ShowServiceNotAvailableError(this, sDialogServiceName, sal_True);
[ # # ]
1236 : 0 : return 1L;
1237 : : }
1238 : :
1239 : : // excute the dialog
1240 : : try
1241 : : {
1242 [ # # ][ # # ]: 0 : if ( xAdminDialog->execute() == RET_OK )
[ # # ]
1243 : : {
1244 [ # # ]: 0 : Reference<XPropertySet> xProp(xAdminDialog,UNO_QUERY);
1245 [ # # ]: 0 : if ( xProp.is() )
1246 : : {
1247 : 0 : ::rtl::OUString sName;
1248 [ # # ][ # # ]: 0 : xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataSourceName"))) >>= sName;
[ # # ]
1249 : :
1250 [ # # ]: 0 : INetURLObject aURL( sName );
1251 [ # # ]: 0 : if( aURL.GetProtocol() != INET_PROT_NOT_VALID )
1252 : : {
1253 [ # # ][ # # ]: 0 : OFileNotation aFileNotation( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
1254 [ # # ][ # # ]: 0 : sName = aFileNotation.get(OFileNotation::N_SYSTEM);
1255 : : }
1256 [ # # ][ # # ]: 0 : m_aDatasource.InsertEntry(sName);
[ # # ]
1257 [ # # ][ # # ]: 0 : delete m_pImpl->pConfigData;
1258 [ # # ][ # # ]: 0 : m_pImpl->pConfigData = new AssignmentPersistentData();
[ # # ]
1259 [ # # ]: 0 : loadConfiguration();
1260 [ # # ][ # # ]: 0 : resetTables();
1261 : : // will reset the fields implicitly
1262 [ # # ]: 0 : }
1263 : : }
1264 : : }
1265 [ # # ]: 0 : catch(Exception&)
1266 : : {
1267 : : OSL_FAIL("AddressBookSourceDialog::OnAdministrateDatasources: an error occurred while executing the administration dialog!");
1268 : : }
1269 : :
1270 : : // re-fill the data source list
1271 : : // try to preserve the current selection
1272 : :
1273 : : // initializeDatasources();
1274 : :
1275 [ # # ]: 0 : return 0L;
1276 : : }
1277 : :
1278 : : // -------------------------------------------------------------------
1279 : 0 : long AddressBookSourceDialog::PreNotify( NotifyEvent& _rNEvt )
1280 : : {
1281 [ # # ]: 0 : switch (_rNEvt.GetType())
1282 : : {
1283 : : case EVENT_KEYINPUT:
1284 : : {
1285 : 0 : const KeyEvent* pKeyEvent = _rNEvt.GetKeyEvent();
1286 : 0 : sal_uInt16 nCode = pKeyEvent->GetKeyCode().GetCode();
1287 : 0 : sal_Bool bShift = pKeyEvent->GetKeyCode().IsShift();
1288 : 0 : sal_Bool bCtrl = pKeyEvent->GetKeyCode().IsMod1();
1289 : 0 : sal_Bool bAlt = pKeyEvent->GetKeyCode().IsMod2();
1290 : :
1291 [ # # ]: 0 : if (KEY_TAB == nCode)
1292 : : { // somebody pressed the tab key
1293 [ # # ][ # # ]: 0 : if (!bAlt && !bCtrl && !bShift)
[ # # ]
1294 : : { // it's really the only the key (no modifiers)
1295 [ # # ]: 0 : if (m_pImpl->pFields[m_pImpl->nLastVisibleListIndex]->HasChildPathFocus())
1296 : : // the last of our visible list boxes has the focus
1297 [ # # ]: 0 : if (m_pImpl->nFieldScrollPos < m_aFieldScroller.GetRangeMax())
1298 : : { // we can still scroll down
1299 : 0 : sal_Int32 nNextFocusList = m_pImpl->nLastVisibleListIndex + 1 - 2;
1300 : : // -> scroll down
1301 : 0 : implScrollFields(m_pImpl->nFieldScrollPos + 1, sal_False, sal_True);
1302 : : // give the left control in the "next" line the focus
1303 : 0 : m_pImpl->pFields[nNextFocusList]->GrabFocus();
1304 : : // return saying "have handled this"
1305 : 0 : return 1;
1306 : 0 : }
1307 : : }
1308 [ # # ][ # # ]: 0 : else if (!bAlt && !bCtrl && bShift)
[ # # ]
1309 : : { // it's shift-tab
1310 [ # # ]: 0 : if (m_pImpl->pFields[0]->HasChildPathFocus())
1311 : : // our first list box has the focus
1312 [ # # ]: 0 : if (m_pImpl->nFieldScrollPos > 0)
1313 : : { // we can still scroll up
1314 : : // -> scroll up
1315 : 0 : implScrollFields(m_pImpl->nFieldScrollPos - 1, sal_False, sal_True);
1316 : : // give the right control in the "prebious" line the focus
1317 : 0 : m_pImpl->pFields[0 - 1 + 2]->GrabFocus();
1318 : : // return saying "have handled this"
1319 : 0 : return 1;
1320 : : }
1321 : : }
1322 : : }
1323 : : }
1324 : 0 : break;
1325 : : }
1326 : 0 : return ModalDialog::PreNotify(_rNEvt);
1327 : : }
1328 : :
1329 : : // .......................................................................
1330 : : } // namespace svt
1331 : : // .......................................................................
1332 : :
1333 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|