1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
|
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtContacts module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qcontactfilter.h"
#include "qcontactfilter_p.h"
#ifndef QT_NO_DATASTREAM
#include <QtCore/qdatastream.h>
#endif
#ifndef QT_NO_DEBUG_STREAM
#include <QtCore/qdebug.h>
#endif
#include "qcontactfilters.h"
#include "qcontactmanager.h"
/*!
\class QContactFilter
\brief The QContactFilter class is used to select contacts made available
through a QContactManager.
\inmodule QtContacts
\ingroup contacts-main
This class is used as a parameter to various functions offered by QContactManager, to allow
selection of contacts which have certain details or properties.
*/
/*!
\enum QContactFilter::FilterType
Describes the type of the filter
\value InvalidFilter An invalid filter which matches nothing
\value ContactDetailFilter A filter which matches contacts containing one or more details of a particular definition with a particular value
\value ContactDetailRangeFilter A filter which matches contacts containing one or more details of a particular definition whose values are within a particular range
\value ChangeLogFilter A filter which matches contacts whose timestamps have been updated since some particular date and time
\value ActionFilter A filter which matches contacts for which a particular action is available, or which contain a detail with a particular value for which a particular action is available
\value RelationshipFilter A filter which matches contacts which participate in a particular type of relationship, or relationship with a specified contact
\value IntersectionFilter A filter which matches all contacts that are matched by all filters it includes
\value UnionFilter A filter which matches any contact that is matched by any of the filters it includes
\value IdFilter A filter which matches any contact whose id is contained in a particular list of contact ids
\value DefaultFilter A filter which matches everything
*/
/*!
\enum QContactFilter::MatchFlag
Describes the semantics of matching followed by the filter
\value MatchExactly Performs QVariant-based matching , combination of MatchExactly with other flags is not supported
\value MatchContains The search term is contained in the item
\value MatchStartsWith The search term matches the start of the item
\value MatchEndsWith The search term matches the end of the item
\value MatchFixedString Performs string-based matching. String-based comparisons are case-insensitive unless the \c MatchCaseSensitive flag is also specified
\value MatchCaseSensitive The search is case sensitive
\value MatchPhoneNumber The search term is considered to be in the form of a phone number, and special processing (removing dialing prefixes, non significant
characters like '-'. ')' etc). may be performed when matching the item.
\value MatchKeypadCollation The search term is in the form of text entered by a numeric phone keypad (such as ITU-T E.161 compliant keypads). Each digit in the
search term can represent a number of alphanumeric symbols. For example, the search string "43556" would match items "HELLO", "GEKKO", "HELL6" and "43556" among others.
Accented characters and other punctuation characters may additionally be matched by the QContactManager in a way consistent with the platform.
*/
/*!
\fn QContactFilter::operator!=(const QContactFilter& other) const
Returns true if this filter is not identical to the \a other filter.
\sa operator==()
*/
#if !defined(Q_CC_MWERKS)
template<> QTCONTACTS_PREPEND_NAMESPACE(QContactFilterPrivate) *QSharedDataPointer<QTCONTACTS_PREPEND_NAMESPACE(QContactFilterPrivate)>::clone()
{
return d->clone();
}
#endif
QT_BEGIN_NAMESPACE_CONTACTS
/*! Constructs an empty filter */
QContactFilter::QContactFilter()
: d_ptr(0)
{
}
/*! Constructs a new copy of \a other */
QContactFilter::QContactFilter(const QContactFilter& other)
: d_ptr(other.d_ptr)
{
}
/*! Assigns this filter to be \a other
*/
QContactFilter& QContactFilter::operator=(const QContactFilter& other)
{
if (this != &other) {
d_ptr = other.d_ptr;
}
return *this;
}
/*! Cleans up the memory used by this filter */
QContactFilter::~QContactFilter()
{
}
/*! Returns the type of the filter */
QContactFilter::FilterType QContactFilter::type() const
{
if (!d_ptr)
return QContactFilter::DefaultFilter;
return d_ptr->type();
}
/*! Returns true if the filter has the same type and criteria as \a other
*/
bool QContactFilter::operator==(const QContactFilter& other) const
{
/* A default filter is only equal to other default filters */
if (!d_ptr)
return !other.d_ptr;
/* Different types can't be equal */
if (other.type() != type())
return false;
/* Otherwise, use the virtual op == */
return d_ptr->compare(other.d_ptr);
}
#ifndef QT_NO_DATASTREAM
/*!
* Writes \a filter to the stream \a out.
*/
QDataStream& operator<<(QDataStream& out, const QContactFilter& filter)
{
quint8 formatVersion = 1; // Version of QDataStream format for QContactDetailFilter
out << formatVersion << static_cast<quint32>(filter.type());
if (filter.d_ptr)
filter.d_ptr->outputToStream(out, formatVersion);
return out;
}
/*!
* Reads a contact filter from stream \a in into \a filter.
*/
QDataStream& operator>>(QDataStream& in, QContactFilter& filter)
{
filter = QContactFilter();
quint8 formatVersion;
in >> formatVersion;
if (formatVersion == 1) {
quint32 type;
in >> type;
switch (type) {
case QContactFilter::InvalidFilter:
filter = QContactInvalidFilter();
break;
case QContactFilter::ContactDetailFilter:
filter = QContactDetailFilter();
break;
case QContactFilter::ContactDetailRangeFilter:
filter = QContactDetailRangeFilter();
break;
case QContactFilter::ChangeLogFilter:
filter = QContactChangeLogFilter();
break;
case QContactFilter::ActionFilter:
filter = QContactActionFilter();
break;
case QContactFilter::RelationshipFilter:
filter = QContactRelationshipFilter();
break;
case QContactFilter::IntersectionFilter:
filter = QContactIntersectionFilter();
break;
case QContactFilter::UnionFilter:
filter = QContactUnionFilter();
break;
case QContactFilter::IdFilter:
filter = QContactIdFilter();
break;
case QContactFilter::DefaultFilter:
filter = QContactFilter();
break;
}
if (filter.d_ptr)
filter.d_ptr->inputFromStream(in, formatVersion);
} else {
in.setStatus(QDataStream::ReadCorruptData);
}
return in;
}
#endif
#ifndef QT_NO_DEBUG_STREAM
/*!
Outputs \a filter to the debug stream \a dbg
*/
QDebug operator<<(QDebug dbg, const QContactFilter& filter)
{
dbg.nospace() << "QContactFilter(";
if (filter.d_ptr)
filter.d_ptr->debugStreamOut(dbg);
else
dbg.nospace() << "(null)";
dbg.nospace() << ")";
return dbg.maybeSpace();
}
#endif
/*!
\internal
Constructs a new filter from the given data pointer \a d
*/
QContactFilter::QContactFilter(QContactFilterPrivate *d)
: d_ptr(d)
{
}
/*!
\relates QContactFilter
Returns a filter which is the intersection of the \a left and \a right filters
\sa QContactIntersectionFilter
*/
const QContactFilter operator&(const QContactFilter& left, const QContactFilter& right)
{
// XXX TODO: empty intersection/union operations are not well defined yet.
//if (left.type() == QContactFilter::Intersection) {
// QContactIntersectionFilter bf(left);
// /* we can just add the right to this one */
// bf.append(right);
// return bf;
//}
//if (right.type() == QContactFilter::Intersection) {
// QContactIntersectionFilter bf(right);
// /* we can prepend the left to this one */
// bf.prepend(left);
// return bf;
//}
/* usual fallback case */
QContactIntersectionFilter nif;
nif << left << right;
return nif;
}
/*!
\relates QContactFilter
Returns a filter which is the union of the \a left and \a right filters
\sa QContactUnionFilter
*/
const QContactFilter operator|(const QContactFilter& left, const QContactFilter& right)
{
if (left.type() == QContactFilter::UnionFilter) {
QContactUnionFilter bf(left);
/* we can just add the right to this one */
bf.append(right);
return bf;
}
if (right.type() == QContactFilter::UnionFilter) {
QContactUnionFilter bf(right);
/* we can prepend the left to this one */
bf.prepend(left);
return bf;
}
/* usual fallback case */
QContactUnionFilter nif;
nif << left << right;
return nif;
}
QT_END_NAMESPACE_CONTACTS
|