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 "korder.hxx"
28 #include "kfields.hxx"
29
30 using namespace ::connectivity::kab;
31
~KabOrder()32 KabOrder::~KabOrder()
33 {
34 }
35 // -----------------------------------------------------------------------------
KabSimpleOrder(::rtl::OUString & sColumnName,sal_Bool bAscending)36 KabSimpleOrder::KabSimpleOrder(::rtl::OUString &sColumnName, sal_Bool bAscending)
37 : KabOrder(),
38 m_nFieldNumber(findKabField(sColumnName)),
39 m_bAscending(bAscending)
40 {
41 }
42 // -----------------------------------------------------------------------------
compare(const::KABC::Addressee & aAddressee1,const::KABC::Addressee & aAddressee2) const43 sal_Int32 KabSimpleOrder::compare(const ::KABC::Addressee &aAddressee1, const ::KABC::Addressee &aAddressee2) const
44 {
45 sal_Int32 result;
46
47 result = QString::compare(
48 valueOfKabField(aAddressee1, m_nFieldNumber),
49 valueOfKabField(aAddressee2, m_nFieldNumber));
50 // Timestamps should be compared differently than with their string value
51
52 if (!m_bAscending) result = -result;
53
54 return result;
55 }
56 // -----------------------------------------------------------------------------
KabComplexOrder()57 KabComplexOrder::KabComplexOrder()
58 : KabOrder(),
59 m_aOrders()
60 {
61 }
62 // -----------------------------------------------------------------------------
~KabComplexOrder()63 KabComplexOrder::~KabComplexOrder()
64 {
65 for (sal_uInt32 i = 0; i < m_aOrders.size(); i++)
66 delete m_aOrders[i];
67 }
68 // -----------------------------------------------------------------------------
addOrder(KabOrder * pOrder)69 void KabComplexOrder::addOrder(KabOrder *pOrder)
70 {
71 m_aOrders.push_back(pOrder);
72 }
73 // -----------------------------------------------------------------------------
compare(const::KABC::Addressee & aAddressee1,const::KABC::Addressee & aAddressee2) const74 sal_Int32 KabComplexOrder::compare(const ::KABC::Addressee &aAddressee1, const ::KABC::Addressee &aAddressee2) const
75 {
76 for (sal_uInt32 i = 0; i < m_aOrders.size(); i++)
77 {
78 const KabOrder *pOrder = m_aOrders[i];
79 sal_Int32 result = pOrder->compare(aAddressee1, aAddressee2);
80
81 if (result) return result;
82 }
83 return 0;
84 }
85