src/contacts/qcontactid.cpp
changeset 0 876b1a06bc25
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     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 
       
    42 #include "qcontactid.h"
       
    43 #include "qcontactid_p.h"
       
    44 #include <QHash>
       
    45 #include <QDebug>
       
    46 
       
    47 QTM_BEGIN_NAMESPACE
       
    48 
       
    49 /*!
       
    50   \class QContactId
       
    51   \brief The QContactId class provides information that uniquely identifies
       
    52   a contact in a particular manager.
       
    53  
       
    54   It consists of a manager URI which identifies the manager which contains the contact,
       
    55   and the local id of the contact in that manager.
       
    56 
       
    57   A "null" QContactId has an empty manager URI, and an invalid QContactLocalId (0).
       
    58 
       
    59   \sa QContactLocalId
       
    60  */
       
    61 
       
    62 /*!
       
    63   \typedef QContactLocalId
       
    64   \relates QContactId
       
    65   \brief The QContactLocalId type represents the unique id of a contact within its manager.
       
    66 
       
    67   Most operations within a \l QContactManager accept a QContactLocalId.  Some operations
       
    68   (involving links to contacts outside a particular manager) also accept a manager URI - this
       
    69   combination is stored in a \l QContactId.
       
    70 
       
    71   An invalid QContactLocalId is represented by a zero (0) value.
       
    72 
       
    73   \sa QContactId
       
    74 */
       
    75 
       
    76 /*!
       
    77  * Constructs a new contact id
       
    78  */
       
    79 QContactId::QContactId()
       
    80         : d(new QContactIdPrivate)
       
    81 {
       
    82 }
       
    83 
       
    84 /*!
       
    85  * Cleans up the memory in use by the contact id
       
    86  */
       
    87 QContactId::~QContactId()
       
    88 {
       
    89 }
       
    90 
       
    91 /*! Constructs a new contact id as a copy of \a other */
       
    92 QContactId::QContactId(const QContactId& other)
       
    93         : d(other.d)
       
    94 {
       
    95 }
       
    96 
       
    97 /*! Assigns the contact id to be equal to \a other */
       
    98 QContactId& QContactId::operator=(const QContactId& other)
       
    99 {
       
   100     d = other.d;
       
   101     return *this;
       
   102 }
       
   103 
       
   104 /*! Returns true if the contact id has the same manager URI and local id as \a other */
       
   105 bool QContactId::operator==(const QContactId& other) const
       
   106 {
       
   107     if (d->m_managerUri != other.d->m_managerUri)
       
   108         return false;
       
   109     if (d->m_localId != other.d->m_localId)
       
   110         return false;
       
   111     return true;
       
   112 }
       
   113 
       
   114 /*! Returns true if either the manager URI or local id of the contact id is different to that of \a other */
       
   115 bool QContactId::operator!=(const QContactId& other) const
       
   116 {
       
   117     return !(*this == other);
       
   118 }
       
   119 
       
   120 /*! Returns true if this id is less than the \a other id.
       
   121     This id will be considered less than the \a other id if the
       
   122     manager URI of this id is alphabetically less than the manager
       
   123     URI of the \a other id.  If both ids have the same manager URI,
       
   124     this id will be considered less than the \a other id if the
       
   125     local id of this id is less than the local id of the \a other id.
       
   126 
       
   127     The invalid, empty id consists of an empty manager URI and the
       
   128     invalid, zero local id, and hence will be less than any non-invalid
       
   129     id.
       
   130 
       
   131     This operator is provided primarily to allow use of a QContactId
       
   132     as a key in a QMap.
       
   133  */
       
   134 bool QContactId::operator<(const QContactId& other) const
       
   135 {
       
   136     const int comp = this->managerUri().compare(other.managerUri());
       
   137     if (comp != 0)
       
   138         return comp < 0;
       
   139 
       
   140     return this->localId() < other.localId();
       
   141 }
       
   142 
       
   143 /*!
       
   144  * Returns the hash value for \a key.
       
   145  */
       
   146 uint qHash(const QContactId &key)
       
   147 {
       
   148     return QT_PREPEND_NAMESPACE(qHash)(key.managerUri())
       
   149             + QT_PREPEND_NAMESPACE(qHash)(key.localId());
       
   150 }
       
   151 
       
   152 #ifndef QT_NO_DEBUG_STREAM
       
   153 QDebug operator<<(QDebug dbg, const QContactId& id)
       
   154 {
       
   155     dbg.nospace() << "QContactId(" << id.managerUri() << ", " << id.localId() << ")";
       
   156     return dbg.maybeSpace();
       
   157 }
       
   158 #endif
       
   159 
       
   160 /*!
       
   161  * Returns the URI of the manager which contains the contact identified by this id
       
   162  */
       
   163 QString QContactId::managerUri() const
       
   164 {
       
   165     return d->m_managerUri;
       
   166 }
       
   167 
       
   168 /*!
       
   169  * Returns the manager-local id of the contact identified by this contact id
       
   170  */
       
   171 QContactLocalId QContactId::localId() const
       
   172 {
       
   173     return d->m_localId;
       
   174 }
       
   175 
       
   176 /*!
       
   177  * Sets the URI of the manager which contains the contact identified by this id to \a uri
       
   178  */
       
   179 void QContactId::setManagerUri(const QString& uri)
       
   180 {
       
   181     d->m_managerUri = uri;
       
   182 }
       
   183 
       
   184 /*!
       
   185  * Sets the manager-local id of the contact identified by this contact id to \a id
       
   186  */
       
   187 void QContactId::setLocalId(const QContactLocalId& id)
       
   188 {
       
   189     d->m_localId = id;
       
   190 }
       
   191 
       
   192 QTM_END_NAMESPACE