update emoji autocorrect entries from po-files
[LibreOffice.git] / connectivity / source / drivers / kab / kcondition.cxx
blobc5b6879b3f8e6a0d4ec95a4dbbff2caeac47f165
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "kcondition.hxx"
22 #include "kfields.hxx"
23 #include <connectivity/CommonTools.hxx>
25 using namespace ::connectivity::kab;
26 using namespace ::com::sun::star::sdbc;
28 KabCondition::~KabCondition()
32 KabConditionConstant::KabConditionConstant(const bool bValue)
33 : KabCondition(),
34 m_bValue(bValue)
38 bool KabConditionConstant::isAlwaysTrue() const
40 return m_bValue;
43 bool KabConditionConstant::isAlwaysFalse() const
45 return !m_bValue;
48 bool KabConditionConstant::eval(const ::KABC::Addressee &) const
50 return m_bValue;
53 KabConditionColumn::KabConditionColumn(const OUString &sColumnName) throw(SQLException)
54 : KabCondition(),
55 m_nFieldNumber(findKabField(sColumnName))
59 bool KabConditionColumn::isAlwaysTrue() const
61 // Sometimes true, sometimes false
62 return false;
65 bool KabConditionColumn::isAlwaysFalse() const
67 // Sometimes true, sometimes false
68 return false;
71 KabConditionNull::KabConditionNull(const OUString &sColumnName) throw(SQLException)
72 : KabConditionColumn(sColumnName)
76 bool KabConditionNull::eval(const ::KABC::Addressee &aAddressee) const
78 QString aQtName = valueOfKabField(aAddressee, m_nFieldNumber);
80 return aQtName.isNull();
81 // KDE address book currently does not use NULL values.
82 // But it might do it someday
85 KabConditionNotNull::KabConditionNotNull(const OUString &sColumnName) throw(SQLException)
86 : KabConditionColumn(sColumnName)
90 bool KabConditionNotNull::eval(const ::KABC::Addressee &aAddressee) const
92 QString aQtName = valueOfKabField(aAddressee, m_nFieldNumber);
94 return !aQtName.isNull();
95 // KDE address book currently does not use NULL values.
96 // But it might do it someday
99 KabConditionCompare::KabConditionCompare(const OUString &sColumnName, const OUString &sMatchString) throw(SQLException)
100 : KabConditionColumn(sColumnName),
101 m_sMatchString(sMatchString)
105 KabConditionEqual::KabConditionEqual(const OUString &sColumnName, const OUString &sMatchString) throw(SQLException)
106 : KabConditionCompare(sColumnName, sMatchString)
110 bool KabConditionEqual::eval(const ::KABC::Addressee &aAddressee) const
112 QString aQtName = valueOfKabField(aAddressee, m_nFieldNumber);
113 // Timestamps should not be compared according to their string value
114 // The syntax for such queries should be like
115 // {ts '2004-03-29 12:55:00.000000'}
116 // They should also support operators like '<' or '>='
118 if (aQtName.isNull()) return false;
120 OUString sValue((const sal_Unicode *) aQtName.ucs2());
121 return sValue == m_sMatchString;
124 KabConditionDifferent::KabConditionDifferent(const OUString &sColumnName, const OUString &sMatchString) throw(SQLException)
125 : KabConditionCompare(sColumnName, sMatchString)
129 bool KabConditionDifferent::eval(const ::KABC::Addressee &aAddressee) const
131 QString aQtName = valueOfKabField(aAddressee, m_nFieldNumber);
133 if (aQtName.isNull()) return false;
135 OUString sValue((const sal_Unicode *) aQtName.ucs2());
136 return sValue != m_sMatchString;
139 KabConditionSimilar::KabConditionSimilar(const OUString &sColumnName, const OUString &sMatchString) throw(SQLException)
140 : KabConditionCompare(sColumnName, sMatchString)
144 bool KabConditionSimilar::eval(const ::KABC::Addressee &aAddressee) const
146 QString aQtName = valueOfKabField(aAddressee, m_nFieldNumber);
148 if (aQtName.isNull()) return false;
150 OUString sValue((const sal_Unicode *) aQtName.ucs2());
151 return match(m_sMatchString, sValue, '\0');
154 KabConditionBoolean::KabConditionBoolean(KabCondition *pLeft, KabCondition *pRight)
155 : KabCondition(),
156 m_pLeft(pLeft),
157 m_pRight(pRight)
161 KabConditionBoolean::~KabConditionBoolean()
163 delete m_pLeft;
164 delete m_pRight;
167 KabConditionOr::KabConditionOr(KabCondition *pLeft, KabCondition *pRight)
168 : KabConditionBoolean(pLeft, pRight)
172 bool KabConditionOr::isAlwaysTrue() const
174 return m_pLeft->isAlwaysTrue() || m_pRight->isAlwaysTrue();
177 bool KabConditionOr::isAlwaysFalse() const
179 return m_pLeft->isAlwaysFalse() && m_pRight->isAlwaysFalse();
182 bool KabConditionOr::eval(const ::KABC::Addressee &aAddressee) const
184 // We avoid evaluating terms as much as we can
185 if (m_pLeft->isAlwaysTrue() || m_pRight->isAlwaysTrue()) return true;
186 if (m_pLeft->isAlwaysFalse() && m_pRight->isAlwaysFalse()) return false;
188 if (m_pLeft->eval(aAddressee)) return true;
189 if (m_pRight->eval(aAddressee)) return true;
191 return false;
194 KabConditionAnd::KabConditionAnd(KabCondition *pLeft, KabCondition *pRight)
195 : KabConditionBoolean(pLeft, pRight)
199 bool KabConditionAnd::isAlwaysTrue() const
201 return m_pLeft->isAlwaysTrue() && m_pRight->isAlwaysTrue();
204 bool KabConditionAnd::isAlwaysFalse() const
206 return m_pLeft->isAlwaysFalse() || m_pRight->isAlwaysFalse();
209 bool KabConditionAnd::eval(const ::KABC::Addressee &aAddressee) const
211 // We avoid evaluating terms as much as we can
212 if (m_pLeft->isAlwaysFalse() || m_pRight->isAlwaysFalse()) return false;
213 if (m_pLeft->isAlwaysTrue() && m_pRight->isAlwaysTrue()) return true;
215 if (!m_pLeft->eval(aAddressee)) return false;
216 if (!m_pRight->eval(aAddressee)) return false;
218 return true;
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */