1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9b5730f6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9b5730f6SAndrew Rist  * distributed with this work for additional information
6*9b5730f6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9b5730f6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist  * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9b5730f6SAndrew Rist  *
11*9b5730f6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist  *
13*9b5730f6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist  * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9b5730f6SAndrew Rist  * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist  * under the License.
19*9b5730f6SAndrew Rist  *
20*9b5730f6SAndrew Rist  *************************************************************/
21*9b5730f6SAndrew Rist 
22*9b5730f6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "kfields.hxx"
28cdf0e10cSrcweir #include "resource/common_res.hrc"
29cdf0e10cSrcweir #include "resource/sharedresources.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir using namespace ::connectivity::kab;
32cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace connectivity
35cdf0e10cSrcweir {
36cdf0e10cSrcweir 	namespace kab
37cdf0e10cSrcweir 	{
38cdf0e10cSrcweir // -----------------------------------------------------------------------------
39cdf0e10cSrcweir // return the value of a KDE address book field, given an addressee and a field number
valueOfKabField(const::KABC::Addressee & aAddressee,sal_Int32 nFieldNumber)40cdf0e10cSrcweir QString valueOfKabField(const ::KABC::Addressee &aAddressee, sal_Int32 nFieldNumber)
41cdf0e10cSrcweir {
42cdf0e10cSrcweir 	switch (nFieldNumber)
43cdf0e10cSrcweir 	{
44cdf0e10cSrcweir 		case KAB_FIELD_REVISION:
45cdf0e10cSrcweir 			return aAddressee.revision().toString("yyyy-MM-dd hh:mm:ss");
46cdf0e10cSrcweir 		default:
47cdf0e10cSrcweir 			::KABC::Field::List aFields = ::KABC::Field::allFields();
48cdf0e10cSrcweir 			return aFields[nFieldNumber - KAB_DATA_FIELDS]->value(aAddressee);
49cdf0e10cSrcweir 	}
50cdf0e10cSrcweir }
51cdf0e10cSrcweir // ------------------------------------------------------------------------------
52cdf0e10cSrcweir // search the KDE address book field number of a given column name
findKabField(const::rtl::OUString & columnName)53cdf0e10cSrcweir sal_uInt32 findKabField(const ::rtl::OUString& columnName) throw(SQLException)
54cdf0e10cSrcweir {
55cdf0e10cSrcweir 	QString aQtName;
56cdf0e10cSrcweir 	::rtl::OUString aName;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 	aQtName = KABC::Addressee::revisionLabel();
59cdf0e10cSrcweir 	aName = ::rtl::OUString((const sal_Unicode *) aQtName.ucs2());
60cdf0e10cSrcweir 	if (columnName == aName)
61cdf0e10cSrcweir 		return KAB_FIELD_REVISION;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 	::KABC::Field::List aFields = ::KABC::Field::allFields();
64cdf0e10cSrcweir 	::KABC::Field::List::iterator aField;
65cdf0e10cSrcweir 	sal_uInt32 nResult;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 	for (	aField = aFields.begin(), nResult = KAB_DATA_FIELDS;
68cdf0e10cSrcweir 			aField != aFields.end();
69cdf0e10cSrcweir 			++aField, ++nResult)
70cdf0e10cSrcweir 	{
71cdf0e10cSrcweir 		aQtName = (*aField)->label();
72cdf0e10cSrcweir 		aName = ::rtl::OUString((const sal_Unicode *) aQtName.ucs2());
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 		if (columnName == aName)
75cdf0e10cSrcweir 			return nResult;
76cdf0e10cSrcweir 	}
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     ::connectivity::SharedResources aResources;
79cdf0e10cSrcweir     const ::rtl::OUString sError( aResources.getResourceStringWithSubstitution(
80cdf0e10cSrcweir             STR_INVALID_COLUMNNAME,
81cdf0e10cSrcweir             "$columnname$",columnName
82cdf0e10cSrcweir          ) );
83cdf0e10cSrcweir 	::dbtools::throwGenericSQLException(sError,NULL);
84cdf0e10cSrcweir     // Unreachable:
85cdf0e10cSrcweir     OSL_ASSERT(false);
86cdf0e10cSrcweir     return 0;
87cdf0e10cSrcweir }
88cdf0e10cSrcweir // ------------------------------------------------------------------------------
89cdf0e10cSrcweir 	}
90cdf0e10cSrcweir }
91