|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 #include "qmessagefolderid_p.h" |
|
42 #include "winhelpers_p.h" |
|
43 #include <QByteArray> |
|
44 #include <QDataStream> |
|
45 #include <MAPIUtil.h> |
|
46 #include <QDebug> |
|
47 #include <messagingutil_p.h> |
|
48 |
|
49 QTM_BEGIN_NAMESPACE |
|
50 |
|
51 #ifdef _WIN32_WCE |
|
52 |
|
53 QMessageFolderId QMessageFolderIdPrivate::from(const MapiRecordKey &folderKey, const MapiEntryId &storeKey, const MapiEntryId &entryId) |
|
54 { |
|
55 QMessageFolderId result; |
|
56 result.d_ptr->_valid = true; |
|
57 result.d_ptr->_folderRecordKey = folderKey; |
|
58 result.d_ptr->_storeRecordKey = storeKey; |
|
59 result.d_ptr->_entryId = entryId; |
|
60 return result; |
|
61 } |
|
62 |
|
63 MapiEntryId QMessageFolderIdPrivate::storeRecordKey(const QMessageFolderId &id) |
|
64 { |
|
65 return id.d_ptr->_storeRecordKey; |
|
66 } |
|
67 |
|
68 #else |
|
69 |
|
70 QMessageFolderId QMessageFolderIdPrivate::from(const MapiRecordKey &folderKey, const MapiRecordKey &storeKey, const MapiEntryId &entryId) |
|
71 { |
|
72 QMessageFolderId result; |
|
73 result.d_ptr->_valid = true; |
|
74 result.d_ptr->_folderRecordKey = folderKey; |
|
75 result.d_ptr->_storeRecordKey = storeKey; |
|
76 result.d_ptr->_entryId = entryId; |
|
77 return result; |
|
78 } |
|
79 |
|
80 MapiRecordKey QMessageFolderIdPrivate::storeRecordKey(const QMessageFolderId &id) |
|
81 { |
|
82 return id.d_ptr->_storeRecordKey; |
|
83 } |
|
84 |
|
85 #endif |
|
86 |
|
87 MapiRecordKey QMessageFolderIdPrivate::folderRecordKey(const QMessageFolderId &id) |
|
88 { |
|
89 return id.d_ptr->_folderRecordKey; |
|
90 } |
|
91 |
|
92 MapiEntryId QMessageFolderIdPrivate::entryId(const QMessageFolderId &id) |
|
93 { |
|
94 return id.d_ptr->_entryId; |
|
95 } |
|
96 |
|
97 QMessageFolderId::QMessageFolderId() |
|
98 : d_ptr(new QMessageFolderIdPrivate(this)) |
|
99 { |
|
100 d_ptr->_valid = false; |
|
101 } |
|
102 |
|
103 QMessageFolderId::QMessageFolderId(const QMessageFolderId& other) |
|
104 : d_ptr(new QMessageFolderIdPrivate(this)) |
|
105 { |
|
106 this->operator=(other); |
|
107 } |
|
108 |
|
109 QMessageFolderId::QMessageFolderId(const QString& id) |
|
110 : d_ptr(new QMessageFolderIdPrivate(this)) |
|
111 { |
|
112 QDataStream idStream(QByteArray::fromBase64(MessagingUtil::stripIdPrefix(id).toLatin1())); |
|
113 d_ptr->_valid = true; |
|
114 #ifdef _WIN32_WCE |
|
115 idStream >> d_ptr->_entryId; |
|
116 #else |
|
117 idStream >> d_ptr->_folderRecordKey; |
|
118 #endif |
|
119 idStream >> d_ptr->_storeRecordKey; |
|
120 if (!idStream.atEnd()) |
|
121 #ifdef _WIN32_WCE |
|
122 idStream >> d_ptr->_folderRecordKey; |
|
123 #else |
|
124 idStream >> d_ptr->_entryId; |
|
125 #endif |
|
126 } |
|
127 |
|
128 QMessageFolderId::~QMessageFolderId() |
|
129 { |
|
130 delete d_ptr; |
|
131 } |
|
132 |
|
133 QMessageFolderId& QMessageFolderId::operator=(const QMessageFolderId& other) |
|
134 { |
|
135 if (&other != this) { |
|
136 d_ptr->_valid = other.d_ptr->_valid; |
|
137 d_ptr->_folderRecordKey = other.d_ptr->_folderRecordKey; |
|
138 d_ptr->_storeRecordKey = other.d_ptr->_storeRecordKey; |
|
139 d_ptr->_entryId = other.d_ptr->_entryId; |
|
140 } |
|
141 |
|
142 return *this; |
|
143 } |
|
144 |
|
145 bool QMessageFolderId::operator==(const QMessageFolderId& other) const |
|
146 { |
|
147 if (isValid()) { |
|
148 if (other.isValid()) { |
|
149 bool result(true); |
|
150 #ifdef _WIN32_WCE |
|
151 QMessageManager::Error ignoredError(QMessageManager::NoError); |
|
152 MapiSessionPtr session(MapiSession::createSession(&ignoredError)); |
|
153 if (ignoredError == QMessageManager::NoError) { |
|
154 result &= session->equal(d_ptr->_entryId, other.d_ptr->_entryId); |
|
155 } else { |
|
156 result = false; |
|
157 qWarning() << "Unable to compare entry IDs."; |
|
158 } |
|
159 #else |
|
160 result &= (d_ptr->_folderRecordKey == other.d_ptr->_folderRecordKey); |
|
161 #endif |
|
162 result &= (d_ptr->_storeRecordKey == other.d_ptr->_storeRecordKey); |
|
163 return result; |
|
164 } |
|
165 return false; |
|
166 } else { |
|
167 return !other.isValid(); |
|
168 } |
|
169 } |
|
170 |
|
171 bool QMessageFolderId::operator<(const QMessageFolderId& other) const |
|
172 { |
|
173 if (isValid() && other.isValid()) { |
|
174 if (d_ptr->_storeRecordKey == other.d_ptr->_storeRecordKey) { |
|
175 return (d_ptr->_folderRecordKey < other.d_ptr->_folderRecordKey); |
|
176 } |
|
177 |
|
178 return (d_ptr->_storeRecordKey < other.d_ptr->_storeRecordKey); |
|
179 } else if (!isValid() && other.isValid()) { |
|
180 return true; // Arbitrarily define invalid ids to be less than valid ids |
|
181 } |
|
182 |
|
183 return false; |
|
184 } |
|
185 |
|
186 QString QMessageFolderId::toString() const |
|
187 { |
|
188 if (!isValid()) |
|
189 return MessagingUtil::addIdPrefix(QString()); |
|
190 QByteArray encodedId; |
|
191 QDataStream encodedIdStream(&encodedId, QIODevice::WriteOnly); |
|
192 #ifdef _WIN32_WCE |
|
193 encodedIdStream << d_ptr->_entryId; |
|
194 #else |
|
195 encodedIdStream << d_ptr->_folderRecordKey; |
|
196 #endif |
|
197 encodedIdStream << d_ptr->_storeRecordKey; |
|
198 #ifdef _WIN32_WCE |
|
199 if (d_ptr->_folderRecordKey.count()) |
|
200 encodedIdStream << d_ptr->_folderRecordKey; |
|
201 #else |
|
202 if (d_ptr->_entryId.count()) |
|
203 encodedIdStream << d_ptr->_entryId; |
|
204 #endif |
|
205 return MessagingUtil::addIdPrefix(encodedId.toBase64()); |
|
206 } |
|
207 |
|
208 bool QMessageFolderId::isValid() const |
|
209 { |
|
210 #ifdef _WIN32_WCE |
|
211 return (d_ptr->_valid && !d_ptr->_entryId.isEmpty() && !d_ptr->_storeRecordKey.isEmpty()); |
|
212 #else |
|
213 return (d_ptr->_valid && !d_ptr->_folderRecordKey.isEmpty() && !d_ptr->_storeRecordKey.isEmpty()); |
|
214 #endif |
|
215 } |
|
216 |
|
217 uint QtMobility::qHash(const QTM_PREPEND_NAMESPACE(QMessageFolderId) &id) |
|
218 { |
|
219 #ifdef _WIN32_WCE |
|
220 return (QT_PREPEND_NAMESPACE(qHash)(id.d_ptr->_valid) ^ qHash(id.d_ptr->_entryId) ^ qHash(id.d_ptr->_storeRecordKey)); |
|
221 #else |
|
222 return (QT_PREPEND_NAMESPACE(qHash)(id.d_ptr->_valid) ^ qHash(id.d_ptr->_folderRecordKey) ^ qHash(id.d_ptr->_storeRecordKey)); |
|
223 #endif |
|
224 } |
|
225 QTM_END_NAMESPACE |
|
226 |
|
227 |