~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to src/plugins/organizer/jsondb/qorganizerjsondbid.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 "qorganizerjsondbid.h"
 
43
#include "qorganizerjsondbstring.h"
 
44
 
 
45
QT_BEGIN_NAMESPACE_ORGANIZER
 
46
 
 
47
QOrganizerJsonDbItemId::QOrganizerJsonDbItemId()
 
48
    : QOrganizerItemEngineId()
 
49
    , m_jsonDbUuid(QString())
 
50
    , m_storageLocation(QOrganizerJsonDbEngine::UserDataStorage)
 
51
{
 
52
}
 
53
 
 
54
QOrganizerJsonDbItemId::QOrganizerJsonDbItemId(const QString &fullEngineId)
 
55
    : QOrganizerItemEngineId()
 
56
{
 
57
    splitId(fullEngineId, m_jsonDbUuid, m_storageLocation);
 
58
}
 
59
 
 
60
QOrganizerJsonDbItemId::QOrganizerJsonDbItemId(const QOrganizerJsonDbItemId &other)
 
61
    : QOrganizerItemEngineId(),
 
62
      m_jsonDbUuid(other.m_jsonDbUuid),
 
63
      m_storageLocation(other.m_storageLocation)
 
64
{
 
65
}
 
66
 
 
67
QOrganizerJsonDbItemId::~QOrganizerJsonDbItemId()
 
68
{
 
69
}
 
70
 
 
71
bool QOrganizerJsonDbItemId::isEqualTo(const QOrganizerItemEngineId *other) const
 
72
{
 
73
    const QOrganizerJsonDbItemId* id = static_cast<const QOrganizerJsonDbItemId *>(other);
 
74
    return ((m_jsonDbUuid == id->m_jsonDbUuid) && (m_storageLocation == id->m_storageLocation));
 
75
}
 
76
 
 
77
bool QOrganizerJsonDbItemId::isLessThan(const QOrganizerItemEngineId *other) const
 
78
{
 
79
    const QOrganizerJsonDbItemId* id = static_cast<const QOrganizerJsonDbItemId *>(other);
 
80
    if (m_storageLocation == id->m_storageLocation)
 
81
        return (m_jsonDbUuid < id->m_jsonDbUuid);
 
82
    else
 
83
        return (m_storageLocation < id->m_storageLocation);
 
84
}
 
85
 
 
86
QString QOrganizerJsonDbItemId::managerUri() const
 
87
{
 
88
    return QOrganizerJsonDbStr::jsonDbManagerUri();
 
89
}
 
90
 
 
91
QOrganizerItemEngineId *QOrganizerJsonDbItemId::clone() const
 
92
{
 
93
    QOrganizerJsonDbItemId *newId = new QOrganizerJsonDbItemId();
 
94
    newId->setJsonDbUuid(m_jsonDbUuid);
 
95
    newId->setStorageLocation(m_storageLocation);
 
96
    return newId;
 
97
}
 
98
 
 
99
#ifndef QT_NO_DEBUG_STREAM
 
100
QDebug &QOrganizerJsonDbItemId::debugStreamOut(QDebug &dbg) const
 
101
{
 
102
    dbg.nospace() << "QOrganizerJsonDbItemId(" << toString() << ")";
 
103
    return dbg.maybeSpace();
 
104
}
 
105
#endif
 
106
 
 
107
QString QOrganizerJsonDbItemId::toString() const
 
108
{
 
109
    return QString("%1/%2").arg(m_storageLocation).arg(m_jsonDbUuid);
 
110
}
 
111
 
 
112
uint QOrganizerJsonDbItemId::hash() const
 
113
{
 
114
    return QT_PREPEND_NAMESPACE(qHash)(this->toString());
 
115
}
 
116
 
 
117
void QOrganizerJsonDbItemId::setFullEngineId(const QString &fullEngineId)
 
118
{
 
119
    splitId(fullEngineId, m_jsonDbUuid, m_storageLocation);
 
120
}
 
121
 
 
122
QString QOrganizerJsonDbItemId::jsondbUuid() const
 
123
{
 
124
    return m_jsonDbUuid;
 
125
}
 
126
 
 
127
void QOrganizerJsonDbItemId::setJsonDbUuid(const QString &jsonDbUuid)
 
128
{
 
129
    m_jsonDbUuid = jsonDbUuid;
 
130
}
 
131
 
 
132
QOrganizerJsonDbEngine::StorageLocation QOrganizerJsonDbItemId::storageLocation() const
 
133
{
 
134
    return m_storageLocation;
 
135
}
 
136
 
 
137
void QOrganizerJsonDbItemId::setStorageLocation(QOrganizerJsonDbEngine::StorageLocation storageLocation)
 
138
{
 
139
    m_storageLocation = storageLocation;
 
140
}
 
141
 
 
142
void QOrganizerJsonDbItemId::splitId(const QString &fullId, QString &jsondbUuid, QOrganizerJsonDbEngine::StorageLocation &storageLocation)
 
143
{
 
144
    // separate engine id part, if full id given
 
145
    QString engineId = fullId.contains(":") ? fullId.mid(fullId.lastIndexOf(":")+1) : fullId;
 
146
    // separate storagelocation and collection id from each other
 
147
    const QStringList splittedEngineId = engineId.split(QStringLiteral("/"));
 
148
    storageLocation = (QOrganizerJsonDbEngine::StorageLocation)splittedEngineId.first().toInt();
 
149
    jsondbUuid = splittedEngineId.last();
 
150
}
 
151
 
 
152
QOrganizerJsonDbCollectionId::QOrganizerJsonDbCollectionId()
 
153
    : QOrganizerCollectionEngineId()
 
154
    , m_jsonDbUuid(QString())
 
155
    , m_storageLocation(QOrganizerJsonDbEngine::UserDataStorage)
 
156
{
 
157
}
 
158
 
 
159
QOrganizerJsonDbCollectionId::QOrganizerJsonDbCollectionId(const QString &fullEngineId)
 
160
    : QOrganizerCollectionEngineId()
 
161
{
 
162
    splitId(fullEngineId, m_jsonDbUuid, m_storageLocation);
 
163
}
 
164
 
 
165
QOrganizerJsonDbCollectionId::QOrganizerJsonDbCollectionId(const QOrganizerJsonDbCollectionId &other)
 
166
    : QOrganizerCollectionEngineId()
 
167
    , m_jsonDbUuid(other.m_jsonDbUuid)
 
168
    , m_storageLocation(other.m_storageLocation)
 
169
{
 
170
}
 
171
 
 
172
QOrganizerJsonDbCollectionId::~QOrganizerJsonDbCollectionId()
 
173
{
 
174
}
 
175
 
 
176
bool QOrganizerJsonDbCollectionId::isEqualTo(const QOrganizerCollectionEngineId *other) const
 
177
{
 
178
    const QOrganizerJsonDbCollectionId* collId = static_cast<const QOrganizerJsonDbCollectionId *>(other);
 
179
    return ((m_jsonDbUuid == collId->m_jsonDbUuid) && (m_storageLocation == collId->m_storageLocation));
 
180
}
 
181
 
 
182
bool QOrganizerJsonDbCollectionId::isLessThan(const QOrganizerCollectionEngineId *other) const
 
183
{
 
184
    const QOrganizerJsonDbCollectionId* collId = static_cast<const QOrganizerJsonDbCollectionId *>(other);
 
185
    if (m_storageLocation == collId->m_storageLocation)
 
186
        return (m_jsonDbUuid < collId->m_jsonDbUuid);
 
187
    else
 
188
        return (m_storageLocation < collId->m_storageLocation);
 
189
}
 
190
 
 
191
QString QOrganizerJsonDbCollectionId::managerUri() const
 
192
{
 
193
    return QOrganizerJsonDbStr::jsonDbManagerUri();
 
194
}
 
195
 
 
196
QOrganizerCollectionEngineId *QOrganizerJsonDbCollectionId::clone() const
 
197
{
 
198
    QOrganizerJsonDbCollectionId *newId = new QOrganizerJsonDbCollectionId();
 
199
    newId->setJsonDbUuid(m_jsonDbUuid);
 
200
    newId->setStorageLocation(m_storageLocation);
 
201
    return newId;
 
202
}
 
203
 
 
204
#ifndef QT_NO_DEBUG_STREAM
 
205
QDebug &QOrganizerJsonDbCollectionId::debugStreamOut(QDebug &dbg) const
 
206
{
 
207
    dbg.nospace() << "QOrganizerJsonDbCollectionId(" << toString() << ")";
 
208
    return dbg.maybeSpace();
 
209
}
 
210
#endif
 
211
 
 
212
QString QOrganizerJsonDbCollectionId::toString() const
 
213
{
 
214
    return QString("%1/%2").arg(m_storageLocation).arg(m_jsonDbUuid);
 
215
}
 
216
 
 
217
uint QOrganizerJsonDbCollectionId::hash() const
 
218
{
 
219
    return QT_PREPEND_NAMESPACE(qHash)(toString());
 
220
}
 
221
 
 
222
void QOrganizerJsonDbCollectionId::setFullEngineId(const QString &fullEngineId)
 
223
{
 
224
    splitId(fullEngineId, m_jsonDbUuid, m_storageLocation);
 
225
}
 
226
 
 
227
QString QOrganizerJsonDbCollectionId::jsondbUuid() const
 
228
{
 
229
    return m_jsonDbUuid;
 
230
}
 
231
 
 
232
void QOrganizerJsonDbCollectionId::setJsonDbUuid(const QString &jsonDbUuid)
 
233
{
 
234
    m_jsonDbUuid = jsonDbUuid;
 
235
}
 
236
 
 
237
QOrganizerJsonDbEngine::StorageLocation QOrganizerJsonDbCollectionId::storageLocation() const
 
238
{
 
239
    return m_storageLocation;
 
240
}
 
241
 
 
242
void QOrganizerJsonDbCollectionId::setStorageLocation(QOrganizerJsonDbEngine::StorageLocation storageLocation)
 
243
{
 
244
    m_storageLocation = storageLocation;
 
245
}
 
246
 
 
247
void QOrganizerJsonDbCollectionId::splitId(const QString &fullId, QString &jsondbUuid, QOrganizerJsonDbEngine::StorageLocation &storageLocation)
 
248
{
 
249
    // separate engine id part, if full id given
 
250
    QString engineId = fullId.contains(":") ? fullId.mid(fullId.lastIndexOf(":")+1) : fullId;
 
251
    // separate storagelocation and collection id from each other
 
252
    const QStringList splittedEngineId = engineId.split(QStringLiteral("/"));
 
253
    storageLocation = QOrganizerJsonDbEngine::StorageLocation(splittedEngineId.first().toInt());
 
254
    jsondbUuid = splittedEngineId.last();
 
255
}
 
256
 
 
257
QT_END_NAMESPACE_ORGANIZER