| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. |
| 4 | ** Copyright (C) 2015 Canonical Ltd |
| 5 | ** Contact: http://www.qt.io/licensing/ |
| 6 | ** |
| 7 | ** This file is part of the QtContacts module of the Qt Toolkit. |
| 8 | ** |
| 9 | ** $QT_BEGIN_LICENSE:LGPL21$ |
| 10 | ** Commercial License Usage |
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 12 | ** accordance with the commercial license agreement provided with the |
| 13 | ** Software or, alternatively, in accordance with the terms contained in |
| 14 | ** a written agreement between you and The Qt Company. For licensing terms |
| 15 | ** and conditions see http://www.qt.io/terms-conditions. For further |
| 16 | ** information use the contact form at http://www.qt.io/contact-us. |
| 17 | ** |
| 18 | ** GNU Lesser General Public License Usage |
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 20 | ** General Public License version 2.1 or version 3 as published by the Free |
| 21 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and |
| 22 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the |
| 23 | ** following information to ensure the GNU Lesser General Public License |
| 24 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and |
| 25 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 26 | ** |
| 27 | ** As a special exception, The Qt Company gives you certain additional |
| 28 | ** rights. These rights are described in The Qt Company LGPL Exception |
| 29 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 30 | ** |
| 31 | ** $QT_END_LICENSE$ |
| 32 | ** |
| 33 | ****************************************************************************/ |
| 34 | |
| 35 | #ifndef QCONTACTCOLLECTIONID_H |
| 36 | #define QCONTACTCOLLECTIONID_H |
| 37 | |
| 38 | #include <QtCore/qvariant.h> |
| 39 | |
| 40 | #include <QtContacts/qcontactsglobal.h> |
| 41 | |
| 42 | QT_BEGIN_NAMESPACE_CONTACTS |
| 43 | |
| 44 | class QContactManagerEngine; |
| 45 | |
| 46 | class Q_CONTACTS_EXPORT QContactCollectionId |
| 47 | { |
| 48 | public: |
| 49 | inline QContactCollectionId() {} |
| 50 | inline QContactCollectionId(const QString &_managerUri, const QByteArray &_localId) |
| 51 | : m_managerUri(_localId.isEmpty() ? QString() : _managerUri), |
| 52 | m_localId(m_managerUri.isEmpty() ? QByteArray() : _localId) |
| 53 | {} |
| 54 | // compiler-generated dtor and copy/move ctors/assignment operators are fine! |
| 55 | |
| 56 | inline bool operator==(const QContactCollectionId &other) const |
| 57 | { return localId() == other.localId() && managerUri() == other.managerUri(); } |
| 58 | inline bool operator!=(const QContactCollectionId &other) const |
| 59 | { return !operator==(other); } |
| 60 | |
| 61 | inline bool isNull() const { return m_localId.isEmpty(); } |
| 62 | |
| 63 | inline QString managerUri() const { return m_managerUri; } |
| 64 | inline QByteArray localId() const { return m_localId; } |
| 65 | |
| 66 | QString toString() const; |
| 67 | static QContactCollectionId fromString(const QString &idString); |
| 68 | |
| 69 | QByteArray toByteArray() const; |
| 70 | static QContactCollectionId fromByteArray(const QByteArray &idData); |
| 71 | |
| 72 | private: |
| 73 | QString m_managerUri; |
| 74 | QByteArray m_localId; |
| 75 | }; |
| 76 | |
| 77 | inline bool operator<(const QContactCollectionId &id1, const QContactCollectionId &id2) |
| 78 | { return id1.managerUri() != id2.managerUri() ? id1.managerUri() < id2.managerUri() : id1.localId() < id2.localId(); } |
| 79 | |
| 80 | inline uint qHash(const QContactCollectionId &id) |
| 81 | { return qHash(key: id.localId()); } |
| 82 | |
| 83 | #ifndef QT_NO_DATASTREAM |
| 84 | Q_CONTACTS_EXPORT QDataStream &operator<<(QDataStream &out, const QContactCollectionId &id); |
| 85 | Q_CONTACTS_EXPORT QDataStream &operator>>(QDataStream &in, QContactCollectionId &id); |
| 86 | #endif |
| 87 | |
| 88 | #ifndef QT_NO_DEBUG_STREAM |
| 89 | Q_CONTACTS_EXPORT QDebug operator<<(QDebug dbg, const QContactCollectionId &id); |
| 90 | #endif |
| 91 | |
| 92 | QT_END_NAMESPACE_CONTACTS |
| 93 | |
| 94 | QT_BEGIN_NAMESPACE |
| 95 | Q_DECLARE_TYPEINFO(QTCONTACTS_PREPEND_NAMESPACE(QContactCollectionId), Q_MOVABLE_TYPE); |
| 96 | QT_END_NAMESPACE |
| 97 | |
| 98 | Q_DECLARE_METATYPE(QTCONTACTS_PREPEND_NAMESPACE(QContactCollectionId)) |
| 99 | #endif // QCONTACTCOLLECTIONID_H |
| 100 | |