~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to src/organizer/qorganizeritemfetchhint.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 QtOrganizer 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 "qorganizeritemfetchhint_p.h"
 
43
 
 
44
#include <QtCore/QDataStream>
 
45
#ifndef QT_NO_DEBUG_STREAM
 
46
#include <QtCore/qdebug.h>
 
47
#endif // QT_NO_DEBUG_STREAM
 
48
 
 
49
QT_BEGIN_NAMESPACE_ORGANIZER
 
50
 
 
51
/*!
 
52
    \class QOrganizerItemFetchHint
 
53
    \brief The QOrganizerItemFetchHint class provides hints to the manager about which organizer item
 
54
           information needs to be retrieved.
 
55
    \inmodule QtOrganizer
 
56
    \ingroup organizer-filters
 
57
 
 
58
    All of the hints may be ignored at the discretion of the manager, however if a manager
 
59
    is able to optimize retrieval of organizer items due to hints, it may do so.  If a manager
 
60
    ignores a hint, it must retrieve the full set of data that the hint refers to.
 
61
 
 
62
    The fetch hint contains:
 
63
    \list
 
64
    \li a list of detail definition names which the client is interested
 
65
       in (empty if interested in all detail definitions)
 
66
    \li some optimization flags which allow the client to tell the backend if they are
 
67
       not interested in binary blobs (images etc).
 
68
    \endlist
 
69
 
 
70
    Important note: if certain organizer item is retrieved with fetch hint set, normal saving will
 
71
    result in the loss of information that is not retrieved. Partial save should be used to avoid
 
72
    information loss.
 
73
 */
 
74
 
 
75
/*!
 
76
    \enum QOrganizerItemFetchHint::OptimizationHint
 
77
 
 
78
    This enum defines flags which may be set to inform the backend that the client does
 
79
    not require certain information.
 
80
 
 
81
    \value AllRequired          Tells the backend that all information is required.
 
82
    \value NoActionPreferences  Tells the backend that the client does not require retrieved
 
83
                                organizer items to include a cache of action preferences.
 
84
    \value NoBinaryBlobs        Tells the backend that the client does not require retrieved
 
85
                                organizer items to include binary blobs such as thumbnail images.
 
86
 */
 
87
 
 
88
/*!
 
89
    Constructs a new organizer item fetch hint which requests that the backend fetch all information.
 
90
 */
 
91
QOrganizerItemFetchHint::QOrganizerItemFetchHint()
 
92
    : d(new QOrganizerItemFetchHintPrivate)
 
93
{
 
94
}
 
95
 
 
96
/*!
 
97
    Constructs a new organizer item fetch hint as a copy of \a other.
 
98
 */
 
99
QOrganizerItemFetchHint::QOrganizerItemFetchHint(const QOrganizerItemFetchHint &other)
 
100
    : d(other.d)
 
101
{
 
102
}
 
103
 
 
104
/*!
 
105
    Frees any memory in use by the fetch hint.
 
106
 */
 
107
QOrganizerItemFetchHint::~QOrganizerItemFetchHint()
 
108
{
 
109
}
 
110
 
 
111
/*!
 
112
    Assigns this fetch hint to the \a other.
 
113
 */
 
114
QOrganizerItemFetchHint& QOrganizerItemFetchHint::operator=(const QOrganizerItemFetchHint &other)
 
115
{
 
116
    d = other.d;
 
117
    return *this;
 
118
}
 
119
 
 
120
/*!
 
121
    Returns the list of detail types that identify details which should be retrieved by the manager
 
122
    when fetching items.
 
123
 
 
124
    \sa setDetailTypesHint()
 
125
 */
 
126
QList<QOrganizerItemDetail::DetailType> QOrganizerItemFetchHint::detailTypesHint() const
 
127
{
 
128
    return d->m_detailTypesHint;
 
129
}
 
130
 
 
131
/*!
 
132
    Sets the list of detail types to \a detailTypes that identify details which should be retrieved'
 
133
    by the manager when fetching items.
 
134
 
 
135
    \sa detailTypesHint()
 
136
 */
 
137
void QOrganizerItemFetchHint::setDetailTypesHint(const QList<QOrganizerItemDetail::DetailType> &detailTypes)
 
138
{
 
139
    d->m_detailTypesHint = detailTypes;
 
140
}
 
141
 
 
142
/*!
 
143
    Returns the optimization hint flags specified by the client.
 
144
 
 
145
    \sa setOptimizationHints()
 
146
 */
 
147
QOrganizerItemFetchHint::OptimizationHints QOrganizerItemFetchHint::optimizationHints() const
 
148
{
 
149
    return d->m_optimizationHints;
 
150
}
 
151
 
 
152
/*!
 
153
    Sets the optimization hint flags specified by the client to \a hints.
 
154
 
 
155
    \sa optimizationHints()
 
156
 */
 
157
void QOrganizerItemFetchHint::setOptimizationHints(OptimizationHints hints)
 
158
{
 
159
    d->m_optimizationHints = hints;
 
160
}
 
161
 
 
162
#ifndef QT_NO_DATASTREAM
 
163
/*!
 
164
    \relates QOrganizerItemFetchHint
 
165
    Streams \a hint to the data stream \a out.
 
166
 */
 
167
QDataStream &operator<<(QDataStream &out, const QOrganizerItemFetchHint &hint)
 
168
{
 
169
    quint8 formatVersion = 1;
 
170
    return out << formatVersion
 
171
               << hint.detailTypesHint()
 
172
               << static_cast<quint32>(hint.optimizationHints());
 
173
}
 
174
 
 
175
/*!
 
176
    \relates QOrganizerItemFetchHint
 
177
    Streams \a hint in from the data stream \a in.
 
178
 */
 
179
QDataStream &operator>>(QDataStream &in, QOrganizerItemFetchHint &hint)
 
180
{
 
181
    quint8 formatVersion;
 
182
    in >> formatVersion;
 
183
    if (formatVersion == 1) {
 
184
        QList<quint32> detailTypesHint;
 
185
        quint32 optimizations;
 
186
        in >> detailTypesHint >> optimizations;
 
187
 
 
188
        QList<QOrganizerItemDetail::DetailType> types;
 
189
        foreach (quint32 detailType, detailTypesHint)
 
190
            types.append(static_cast<QOrganizerItemDetail::DetailType>(detailType));
 
191
        hint.setDetailTypesHint(types);
 
192
 
 
193
        hint.setOptimizationHints(static_cast<QOrganizerItemFetchHint::OptimizationHints>(optimizations));
 
194
    } else {
 
195
        in.setStatus(QDataStream::ReadCorruptData);
 
196
    }
 
197
    return in;
 
198
}
 
199
#endif // QT_NO_DATASTREAM
 
200
 
 
201
#ifndef QT_NO_DEBUG_STREAM
 
202
/*!
 
203
    \relates QOrganizerItemFetchHint
 
204
    Outputs \a hint to the debug stream \a dbg.
 
205
 */
 
206
QDebug operator<<(QDebug dbg, const QOrganizerItemFetchHint &hint)
 
207
{
 
208
    dbg.nospace() << "QOrganizerItemFetchHint(";
 
209
    dbg.nospace() << "detailDefinitionsHint=";
 
210
    dbg.nospace() << hint.detailTypesHint();
 
211
    dbg.nospace() << ",";
 
212
    dbg.nospace() << "optimizationHints=";
 
213
    dbg.nospace() << static_cast<quint32>(hint.optimizationHints());
 
214
    dbg.nospace() << ")";
 
215
    return dbg.maybeSpace();
 
216
}
 
217
#endif // QT_NO_DEBUG_STREAM
 
218
 
 
219
QT_END_NAMESPACE_ORGANIZER