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