~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to src/contacts/qcontactfilter.cpp

  • Committer: chris.gagnon
  • Date: 2013-12-10 23:09:37 UTC
  • Revision ID: chris.gagnon@canonical.com-20131210230937-2akf1ft1edcttk87
first post

Show diffs side-by-side

added added

removed removed

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