qtmobility/src/contacts/qcontactdetail.cpp
changeset 5 453da2cfceef
parent 4 90517678cc4f
child 11 06b8e2af4411
equal deleted inserted replaced
4:90517678cc4f 5:453da2cfceef
    54 Q_DEFINE_LATIN1_CONSTANT(QContactDetail::FieldLinkedDetailUris, "LinkedDetailUris");
    54 Q_DEFINE_LATIN1_CONSTANT(QContactDetail::FieldLinkedDetailUris, "LinkedDetailUris");
    55 Q_DEFINE_LATIN1_CONSTANT(QContactDetail::FieldContext, "Context");
    55 Q_DEFINE_LATIN1_CONSTANT(QContactDetail::FieldContext, "Context");
    56 Q_DEFINE_LATIN1_CONSTANT(QContactDetail::ContextOther, "Other");
    56 Q_DEFINE_LATIN1_CONSTANT(QContactDetail::ContextOther, "Other");
    57 Q_DEFINE_LATIN1_CONSTANT(QContactDetail::ContextHome, "Home");
    57 Q_DEFINE_LATIN1_CONSTANT(QContactDetail::ContextHome, "Home");
    58 Q_DEFINE_LATIN1_CONSTANT(QContactDetail::ContextWork, "Work");
    58 Q_DEFINE_LATIN1_CONSTANT(QContactDetail::ContextWork, "Work");
    59 
       
    60 static uint qHash(const QContactStringHolder& holder)
       
    61 {
       
    62     if (!holder.m_str)
       
    63         return 0;
       
    64     uint h = 0;
       
    65     uint g;
       
    66     const register uchar*p = (const uchar*)holder.m_str;
       
    67 
       
    68     while (*p) {
       
    69         h = (h << 4) + *p++;
       
    70         if ((g = (h & 0xf0000000)) != 0)
       
    71             h ^= g >> 23;
       
    72         h &= ~g;
       
    73     }
       
    74     return h;
       
    75 }
       
    76 
    59 
    77 /* Storage */
    60 /* Storage */
    78 QHash<QString, char*> QContactStringHolder::s_allocated;
    61 QHash<QString, char*> QContactStringHolder::s_allocated;
    79 QHash<const char *, QString> QContactStringHolder::s_qstrings;
    62 QHash<const char *, QString> QContactStringHolder::s_qstrings;
    80 
    63 
    99   \ingroup contacts-main
    82   \ingroup contacts-main
   100  
    83  
   101   All of the information for a contact is stored in one or more QContactDetail objects.
    84   All of the information for a contact is stored in one or more QContactDetail objects.
   102  
    85  
   103   A detail is a group of logically related bits of data - for example, a street address is a single
    86   A detail is a group of logically related bits of data - for example, a street address is a single
   104   detail that has multiple fields (number, region, country etc).  Every QContactDetail has an
    87   detail that has multiple fields (number, region, country etc).  Every QContactDetail has the name of an
   105   associated QContactDetailDefinition id that describes the fields, their data type, any
    88   associated QContactDetailDefinition that describes the fields, their data type, and any
   106   restrictions on their values, and any restrictions on creating or updating details of that
    89   restrictions on their values.  Different contact managers might have different detail definitions
   107   definition.
    90   for the same name, depending on their capabilities.  For example, for the QContactName definition name,
   108  
    91   one manager might not support the middle name field, while a different manager may add an extra field for
   109   One field which is common to all details is the context field.  This field is intended to store the
    92   specific extra information not present in the default schema.
   110   context or contexts that this detail is associated with.  Commonly this will be something like
    93 
       
    94   Both the names of all the fields, and the name of the associated QContactDetailDefinition are stored
       
    95   as 8-bit strings encoded in Latin 1 for memory conservation.  Note, however, that the values stored
       
    96   in each field are not constrained in this way, and full unicode QStrings or QVariant data can be stored.
       
    97 
       
    98   One field which is common to all details is the context field.  This field is intended to store one or
       
    99   more contexts that this detail is associated with.  Commonly this will be something like
   111   "Home" and/or "Work", although no limitations are placed on which values may be stored in this field
   100   "Home" and/or "Work", although no limitations are placed on which values may be stored in this field
   112   in the default schema.
   101   in the default schema.
   113 
   102 
   114   There are two other, related fields which are common to all details.  The first is
   103   There are two other, related fields which are common to all details.  The first is
   115   \a QContactDetail::FieldDetailUri, which stores the unique URI of the detail if one exists.
   104   \a QContactDetail::FieldDetailUri, which stores the unique URI of the detail if one exists.
   116   The field is not mandatory, and backends are not required to verify that the given URI is indeed
   105   The field is not mandatory, and backends are not required to verify that the given URI is indeed
   117   unique within the contact.  The second field is \a QContactDetail::LinkedDetailUris, which stores
   106   unique within the contact.  The second field is \a QContactDetail::LinkedDetailUris, which stores
   118   a list of detail URIs to which this detail is linked.  The link is one-way, and intended mainly
   107   a list of detail URIs to which this detail is linked.  The link is one-way, and can be used to show
   119   for use by read-only details which are populated by the backend (for example, a presence detail
   108   how or where a detail was derived.  This is useful for things like presence information and avatars,
   120   which is linked to a particular online account detail of the contact).
   109   which are linked to a particular online account detail of the contact.
   121  
   110 
       
   111   When a QContactDetail has been retrieved in a QContact from a QContactManager, it may have certain
       
   112   access constraints provided with it, like \l ReadOnly or \l Irremovable.  This might mean that the
       
   113   supplied detail is calculated or otherwise not modifiable by the user - presence information is a
       
   114   good example.  Also, some details may be marked \l Irremovable.  These are typically things that
       
   115   a contact has to have - like a QContactDisplayLabel or a QContactType.
       
   116 
   122   It is possible to inherit from QContactDetail to provide convenience or
   117   It is possible to inherit from QContactDetail to provide convenience or
   123   standardized access to values.  For example, \l QContactPhoneNumber provides
   118   standardized access to values.  For example, \l QContactPhoneNumber provides
   124   a convenient API for manipulating a QContactDetail as a phone number, according
   119   a convenient API for manipulating a QContactDetail as a phone number, according
   125   to the schema.
   120   to the schema.
   126  
   121  
       
   122   In general, QContactDetail and the built in subclasses (like \l QContactPhoneNumber) provide
       
   123   constants for the names of fields (like \l QContactPhoneNumber::FieldNumber), and for predefined
       
   124   common values like \l QContactDetail::ContextHome.  Typically the constants for field names start
       
   125   with \c Field, and the constants for predefined values of a field start with the name of that field
       
   126   (e.g. \c ContextHome is a predefined constant for \c FieldContext).
       
   127 
   127   If you wish to create your own, customized contact detail, you should use
   128   If you wish to create your own, customized contact detail, you should use
   128   the \l Q_DECLARE_CUSTOM_CONTACT_DETAIL macro in order to ensure proper
   129   the \l Q_DECLARE_CUSTOM_CONTACT_DETAIL macro in order to ensure proper
   129   operation.  See the predefined leaf classes (like \l QContactPhoneNumber,
   130   operation, and declare your own field constants with \l Q_DECLARE_LATIN1_CONSTANT.
       
   131   See the predefined detail subclasses (like \l QContactPhoneNumber,
   130   \l QContactAddress) for more information.
   132   \l QContactAddress) for more information.
   131  
   133  
   132   QContactDetail objects act like values.  In general, you can assign them
   134   QContactDetail objects act like type checked values.  In general, you can assign them
   133   to and fro and have reasonable behaviour, like the following example.
   135   to and fro and have reasonable behaviour, like the following example.
   134  
   136  
   135   \code
   137   \code
   136  
   138  
   137   QContactPhoneNumber number;
   139   QContactPhoneNumber number;
   138   number.setNumber("555-1212");
   140   number.setNumber("555-1212");
   139   // number.value(QContactPhoneNumber::FieldNumber) == "555-1212";
   141   // number.value(QContactPhoneNumber::FieldNumber) == "555-1212";
   140   // number.definitionName() == QContactPhoneNumber::staticType()
   142   // number.definitionName() == QContactPhoneNumber::DefinitionName
   141  
   143  
   142   QContactDetail detail = number;
   144   QContactDetail detail = number;
   143   // detail.value(QContactPhoneNumber::FieldNumber) == "555-1212";
   145   // detail.value(QContactPhoneNumber::FieldNumber) == "555-1212";
   144   // detail.definitionName() == QContactPhoneNumber::staticType()
   146   // detail.definitionName() == QContactPhoneNumber::DefinitionName
   145  
   147  
   146   QContactPhoneNumber otherNumber = detail;
   148   QContactPhoneNumber otherNumber = detail;
   147   // otherNumber.number() == "555-1212";
   149   // otherNumber.number() == "555-1212";
   148   // otherNumber.definitionName() == QContactPhoneNumber::staticType()
   150   // otherNumber.definitionName() == QContactPhoneNumber::DefinitionName
   149  
   151  
   150   QContactAddress address = detail;
   152   QContactAddress address = detail;
   151   // address is now a default constructed QContactAddress
   153   // address is now a default constructed QContactAddress
   152   // address.error() == QContactDetail::IncompatibleAssignmentError
       
   153   // address.value(QContactPhoneNumber::FieldNumber) is empty
   154   // address.value(QContactPhoneNumber::FieldNumber) is empty
   154   // address.definitionName() == QContactAddress::staticType()
   155   // address.definitionName() == QContactAddress::DefinitionName
   155  
   156  
   156   QContactAddress otherAddress = number;
   157   QContactAddress otherAddress = number;
   157   // otherAddress is now a default constructed QContactAddress
   158   // otherAddress is now a default constructed QContactAddress
   158   // otherAddress.error() == QContactDetail::IncompatibleAssignmentError
       
   159   // otherAddress.value(QContactPhoneNumber::FieldNumber) is empty
   159   // otherAddress.value(QContactPhoneNumber::FieldNumber) is empty
   160   // otherAddress.definitionName() == QContactAddress::staticType()
   160   // otherAddress.definitionName() == QContactAddress::DefinitionName
   161   \endcode
   161   \endcode
   162  
   162  
   163   \sa QContact, QContactDetailDefinition, QContactDetailFilter, QContactDetailRangeFilter, Q_DECLARE_CUSTOM_CONTACT_DETAIL
   163   \sa QContact, QContactDetailDefinition, QContactDetailFilter, QContactDetailRangeFilter, Q_DECLARE_CUSTOM_CONTACT_DETAIL
   164  */
   164  */
   165 
   165 
   166 /*!
   166 /*!
   167   \macro Q_DECLARE_CUSTOM_CONTACT_DETAIL
   167   \macro Q_DECLARE_CUSTOM_CONTACT_DETAIL
   168   \relates QContactDetail
   168   \relates QContactDetail
   169 
   169 
   170   Macro for simplifying declaring custom (leaf) detail classes.
   170   Macro for simplifying declaring custom (leaf) detail classes.
       
   171 
       
   172   The first argument is the name of the class, and the second argument
       
   173   is a Latin-1 string literal naming the detail type.
   171 
   174 
   172   If you are creating a convenience class for a type of QContactDetail,
   175   If you are creating a convenience class for a type of QContactDetail,
   173   you should use this macro when declaring your class to ensure that
   176   you should use this macro when declaring your class to ensure that
   174   it interoperates with other contact functionality.
   177   it interoperates with other contact functionality.
   175 
   178 
   180 
   183 
   181   \snippet ../../src/contacts/details/qcontactphonenumber.h 0
   184   \snippet ../../src/contacts/details/qcontactphonenumber.h 0
   182  */
   185  */
   183 
   186 
   184 /*!
   187 /*!
       
   188     \class QLatin1Constant
       
   189     \headerfile
       
   190     \brief The QLatin1Constant class holds a Latin 1 string constant
       
   191 
       
   192 */
       
   193 
       
   194 /*!
       
   195     \fn QLatin1Constant::operator QString() const
       
   196     \internal
       
   197  */
       
   198 /*!
       
   199     \fn QLatin1Constant::operator QLatin1String() const
       
   200     \internal
       
   201  */
       
   202 /*!
       
   203     \fn QLatin1Constant::operator QVariant() const
       
   204     \internal
       
   205  */
       
   206 /*!
       
   207     \fn bool QLatin1Constant::operator ==(const QLatin1Constant& other) const
       
   208 
       
   209     Returns true if this QLatin1Constant is the same as \a other (either same object or
       
   210     same string literal), and false otherwise.
       
   211  */
       
   212 /*!
       
   213     \fn bool QLatin1Constant::operator !=(const QLatin1Constant& other) const
       
   214 
       
   215     Returns false if this QLatin1Constant is the same as \a other (either same object or
       
   216     same string literal), and true otherwise.
       
   217 */
       
   218 /*!
       
   219     \fn inline const char * QLatin1Constant::latin1() const
       
   220 
       
   221     Returns the value of this literal as a C style string (null terminated).
       
   222 */
       
   223 
       
   224 
       
   225 /*!
       
   226   \macro Q_DECLARE_LATIN1_CONSTANT
       
   227   \relates QLatin1Constant
       
   228 
       
   229   This macro, along with the related Q_DEFINE_LATIN1_CONSTANT macro,
       
   230   allows you to describe a "Latin 1 string constant".
       
   231 
       
   232   The resulting constant can be passed to functions accepting a
       
   233   QLatin1String, a QString, or a QVariant.
       
   234 
       
   235   The first parameter is the name of the variable to declare.  The
       
   236   second parameter is the value of the constant, as a string literal.
       
   237 
       
   238   For example:
       
   239   \code
       
   240   // in a header file
       
   241   Q_DECLARE_LATIN1_CONSTANT(MyConstant, "MYCONSTANT");
       
   242   \endcode
       
   243 
       
   244   The declaration should be paired with a matching Q_DEFINE_LATIN1_CONSTANT
       
   245   with the same arguments to actually define the constant.
       
   246 
       
   247   \sa Q_DEFINE_LATIN1_CONSTANT
       
   248 */
       
   249 
       
   250 /*!
       
   251   \macro Q_DEFINE_LATIN1_CONSTANT
       
   252   \relates QLatin1Constant
       
   253 
       
   254   This macro, along with the related Q_DECLARE_LATIN1_CONSTANT macro,
       
   255   allows you to describe a "Latin 1 string constant".
       
   256 
       
   257   The resulting constant can be passed to functions accepting a
       
   258   QLatin1String, a QString, or a QVariant.
       
   259 
       
   260   The first parameter is the name of the variable to define.  The
       
   261   second parameter is the value of the constant, as a string literal.
       
   262 
       
   263   For example:
       
   264   \code
       
   265   // in a header file
       
   266   Q_DECLARE_LATIN1_CONSTANT(MyConstant, "MYCONSTANT");
       
   267 
       
   268   // in source file
       
   269   Q_DEFINE_LATIN1_CONSTANT(MyConstant, "MYCONSTANT");
       
   270   \endcode
       
   271 
       
   272   You can use this macro without the matching DECLARE macro if
       
   273   you are using the constant only in a single compilation unit.
       
   274 
       
   275   \sa Q_DECLARE_LATIN1_CONSTANT
       
   276 */
       
   277 
       
   278 /*!
   185   \fn QContactDetail::operator!=(const QContactDetail& other) const
   279   \fn QContactDetail::operator!=(const QContactDetail& other) const
   186   Returns true if the values or id of this detail is different to those of the \a other detail
   280   Returns true if the values or id of this detail is different to those of the \a other detail
   187  */
   281  */
   188 
   282 
   189 /*!
   283 /*!
   202     : d(new QContactDetailPrivate)
   296     : d(new QContactDetailPrivate)
   203 {
   297 {
   204     d->m_definitionName = thisDefinitionId;
   298     d->m_definitionName = thisDefinitionId;
   205 }
   299 }
   206 
   300 
   207 /*! Constructs a new, empty detail of the definition identified by \a thisDefinitionId */
   301 /*!
       
   302     Constructs a new, empty detail of the definition identified by \a thisDefinitionId
       
   303 
       
   304     The supplied pointer must be valid for the lifetime of the program.  In general
       
   305     this means it should be a constant, and not allocated on the stack.  If you cannot
       
   306     meet this requirement, use the alternative constructor that takes a QString instead.
       
   307 */
   208 QContactDetail::QContactDetail(const char* thisDefinitionId)
   308 QContactDetail::QContactDetail(const char* thisDefinitionId)
   209     : d(new QContactDetailPrivate)
   309     : d(new QContactDetailPrivate)
   210 {
   310 {
   211     d->m_definitionName = thisDefinitionId;
   311     d->m_definitionName = thisDefinitionId;
   212 }
   312 }
   216     : d(other.d)
   316     : d(other.d)
   217 {
   317 {
   218 }
   318 }
   219 
   319 
   220 /*!
   320 /*!
       
   321     \internal
       
   322 
   221     Constructs a detail that is a copy of \a other if \a other is of the expected definition
   323     Constructs a detail that is a copy of \a other if \a other is of the expected definition
   222     identified by \a expectedDefinitionId, else constructs a new, empty detail of the
   324     identified by \a expectedDefinitionId, else constructs a new, empty detail of the
   223     definition identified by the \a expectedDefinitionId
   325     definition identified by the \a expectedDefinitionId.
       
   326 
       
   327     The \a expectedDefinitionId pointer must be valid for the lifetime of the program.
   224 */
   328 */
   225 QContactDetail::QContactDetail(const QContactDetail& other, const char* expectedDefinitionId)
   329 QContactDetail::QContactDetail(const QContactDetail& other, const char* expectedDefinitionId)
   226 {
   330 {
   227     if (other.d->m_definitionName == expectedDefinitionId) {
   331     if (other.d->m_definitionName == expectedDefinitionId) {
   228         d = other.d;
   332         d = other.d;
   231         d->m_definitionName = expectedDefinitionId;
   335         d->m_definitionName = expectedDefinitionId;
   232     }
   336     }
   233 }
   337 }
   234 
   338 
   235 /*!
   339 /*!
       
   340     \internal
       
   341 
   236     Constructs a detail that is a copy of \a other if \a other is of the expected definition
   342     Constructs a detail that is a copy of \a other if \a other is of the expected definition
   237     identified by \a expectedDefinitionId, else constructs a new, empty detail of the
   343     identified by \a expectedDefinitionId, else constructs a new, empty detail of the
   238     definition identified by the \a expectedDefinitionId
   344     definition identified by the \a expectedDefinitionId
   239 */
   345 */
   240 QContactDetail::QContactDetail(const QContactDetail& other, const QString& expectedDefinitionId)
   346 QContactDetail::QContactDetail(const QContactDetail& other, const QString& expectedDefinitionId)
   254         d = other.d;
   360         d = other.d;
   255     return *this;
   361     return *this;
   256 }
   362 }
   257 
   363 
   258 /*!
   364 /*!
       
   365     \internal
       
   366 
   259     Assigns this detail to \a other if the definition of \a other is that identified
   367     Assigns this detail to \a other if the definition of \a other is that identified
   260     by the given \a expectedDefinitionId, else assigns this detail to be a new, empty
   368     by the given \a expectedDefinitionId, else assigns this detail to be a new, empty
   261     detail of the definition identified by the given \a expectedDefinitionId
   369     detail of the definition identified by the given \a expectedDefinitionId
   262 */
   370 */
   263 QContactDetail& QContactDetail::assign(const QContactDetail& other, const char* expectedDefinitionId)
   371 QContactDetail& QContactDetail::assign(const QContactDetail& other, const char* expectedDefinitionId)
   272     }
   380     }
   273     return *this;
   381     return *this;
   274 }
   382 }
   275 
   383 
   276 /*!
   384 /*!
       
   385     \internal
       
   386 
   277     Assigns this detail to \a other if the definition of \a other is that identified
   387     Assigns this detail to \a other if the definition of \a other is that identified
   278     by the given \a expectedDefinitionId, else assigns this detail to be a new, empty
   388     by the given \a expectedDefinitionId, else assigns this detail to be a new, empty
   279     detail of the definition identified by the given \a expectedDefinitionId
   389     detail of the definition identified by the given \a expectedDefinitionId
   280 */
   390 */
   281 QContactDetail& QContactDetail::assign(const QContactDetail& other, const QString& expectedDefinitionId)
   391 QContactDetail& QContactDetail::assign(const QContactDetail& other, const QString& expectedDefinitionId)
   294 /*! Frees the memory used by this detail */
   404 /*! Frees the memory used by this detail */
   295 QContactDetail::~QContactDetail()
   405 QContactDetail::~QContactDetail()
   296 {
   406 {
   297 }
   407 }
   298 
   408 
   299 /*! Returns the (unique) name of the definition which defines the semantics and structure of this detail */
   409 /*!
       
   410     Returns the (unique) name of the definition which defines the semantics and structure of this detail.
       
   411     The actual QContactDetailDefinition should be retrieved from the relevant QContactManager using this name.
       
   412  */
   300 QString QContactDetail::definitionName() const
   413 QString QContactDetail::definitionName() const
   301 {
   414 {
   302     return d.constData()->m_definitionName;
   415     return d.constData()->m_definitionName.toQString();
   303 }
   416 }
   304 
   417 
   305 /*! Compares this detail to \a other.  Returns true if the definition and values of \a other are equal to those of this detail.
   418 /*!
       
   419     Compares this detail to \a other.  Returns true if the definition, access constraints and values of \a other are equal to those of this detail.
   306     The keys of each detail are not considered during the comparison, in order to allow details from different contacts to
   420     The keys of each detail are not considered during the comparison, in order to allow details from different contacts to
   307     be compared according to their values. */
   421     be compared according to their values.
       
   422  */
   308 bool QContactDetail::operator==(const QContactDetail& other) const
   423 bool QContactDetail::operator==(const QContactDetail& other) const
   309 {
   424 {
   310     if (! (d.constData()->m_definitionName == other.d.constData()->m_definitionName))
   425     if (! (d.constData()->m_definitionName == other.d.constData()->m_definitionName))
   311         return false;
   426         return false;
   312 
   427 
   317         return false;
   432         return false;
   318 
   433 
   319     return true;
   434     return true;
   320 }
   435 }
   321 
   436 
       
   437 uint qHash(const QContactStringHolder& key)
       
   438 {
       
   439     if (!key.m_str)
       
   440         return 0;
       
   441     uint h = 0;
       
   442     uint g;
       
   443     const register uchar*p = (const uchar*)key.m_str;
       
   444 
       
   445     while (*p) {
       
   446         h = (h << 4) + *p++;
       
   447         if ((g = (h & 0xf0000000)) != 0)
       
   448             h ^= g >> 23;
       
   449         h &= ~g;
       
   450     }
       
   451     return h;
       
   452 }
       
   453 
   322 /*! Returns the hash value for \a key. */
   454 /*! Returns the hash value for \a key. */
   323 uint qHash(const QContactDetail &key)
   455 uint qHash(const QContactDetail &key)
   324 {
   456 {
   325     const QContactDetailPrivate* dptr= QContactDetailPrivate::detailPrivate(key);
   457     const QContactDetailPrivate* dptr= QContactDetailPrivate::detailPrivate(key);
   326     uint hash = QT_PREPEND_NAMESPACE(qHash)(dptr->m_definitionName)
   458     uint hash = qHash(dptr->m_definitionName)
   327                 + QT_PREPEND_NAMESPACE(qHash)(dptr->m_access);
   459                 + QT_PREPEND_NAMESPACE(qHash)(dptr->m_access);
   328     QHash<QContactStringHolder, QVariant>::const_iterator it = dptr->m_values.constBegin();
   460     QHash<QContactStringHolder, QVariant>::const_iterator it = dptr->m_values.constBegin();
   329     while(it != dptr->m_values.constEnd()) {
   461     while(it != dptr->m_values.constEnd()) {
   330         hash += QT_PREPEND_NAMESPACE(qHash)(it.key())
   462         hash += qHash(it.key())
   331                 + QT_PREPEND_NAMESPACE(qHash)(it.value().toString());
   463                 + QT_PREPEND_NAMESPACE(qHash)(it.value().toString());
   332         ++it;
   464         ++it;
   333     }
   465     }
   334     return hash;
   466     return hash;
   335 }
   467 }
   346     dbg.nospace() << ')';
   478     dbg.nospace() << ')';
   347     return dbg.maybeSpace();
   479     return dbg.maybeSpace();
   348 }
   480 }
   349 #endif
   481 #endif
   350 
   482 
   351 /*! Returns true if no values are contained in this detail.  Note that context is stored as a value; hence, if a context is set, this function will return false. */
   483 /*!
       
   484     Returns true if no values are contained in this detail.  Note that context is stored as a value; hence, if a context is set, this function will return false.
       
   485  */
   352 bool QContactDetail::isEmpty() const
   486 bool QContactDetail::isEmpty() const
   353 {
   487 {
   354     if (!d.constData()->m_values.isEmpty())
   488     if (!d.constData()->m_values.isEmpty())
   355         return false;
   489         return false;
   356     return true;
   490     return true;
   373 /*! \overload
   507 /*! \overload
   374   Returns the value stored in this detail for the given \a key as a QString, or an empty QString if
   508   Returns the value stored in this detail for the given \a key as a QString, or an empty QString if
   375   no value for the given \a key exists */
   509   no value for the given \a key exists */
   376 QString QContactDetail::value(const QString& key) const
   510 QString QContactDetail::value(const QString& key) const
   377 {
   511 {
   378     return d.constData()->m_values.value(key.toLatin1().constData()).toString();
   512     return d.constData()->m_values.value(QContactStringHolder(key)).toString();
   379 }
   513 }
   380 
   514 
   381 
   515 /*!
   382 /*! \overload
   516     \internal
   383   Returns the value stored in this detail for the given \a key as a QString, or an empty QString if
   517     \overload
   384   no value for the given \a key exists */
   518     Returns the value stored in this detail for the given \a key as a QString, or an empty QString if
       
   519     no value for the given \a key exists
       
   520 */
   385 QString QContactDetail::value(const char* key) const
   521 QString QContactDetail::value(const char* key) const
   386 {
   522 {
   387     return d.constData()->m_values.value(key).toString();
   523     return d.constData()->m_values.value(key).toString();
   388 }
   524 }
   389 
   525 
   390 // A bug in qdoc means this comment needs to appear below the comment for the other value().
   526 /*!
   391 /*!
   527     \fn T QContactDetail::value(const char* key) const
   392   \fn T QContactDetail::value(const QString& key) const
   528     \internal
   393   Returns the value of the template type associated with the given \a key
   529     \overload
   394  */
   530 */
   395 
   531 
   396 /*! Returns the value stored in this detail for the given \a key as a QVariant, or an invalid QVariant if no value for the given \a key exists */
   532 /*! Returns the value stored in this detail for the given \a key as a QVariant, or an invalid QVariant if no value for the given \a key exists */
   397 QVariant QContactDetail::variantValue(const QString& key) const
   533 QVariant QContactDetail::variantValue(const QString& key) const
   398 {
   534 {
   399     return d.constData()->m_values.value(key.toLatin1().constData());
   535     return d.constData()->m_values.value(QContactStringHolder(key));
   400 }
   536 }
   401 
   537 
   402 /*! Returns the value stored in this detail for the given \a key as a QVariant, or an invalid QVariant if no value for the given \a key exists */
   538 /*!
       
   539     \internal
       
   540     Returns the value stored in this detail for the given \a key as a QVariant, or an invalid QVariant if no value for the given \a key exists
       
   541  */
   403 QVariant QContactDetail::variantValue(const char* key) const
   542 QVariant QContactDetail::variantValue(const char* key) const
   404 {
   543 {
   405     return d.constData()->m_values.value(key);
   544     return d.constData()->m_values.value(key);
   406 }
   545 }
   407 
   546 
   408 /*!
   547 /*!
   409   Returns true if this detail has a field with the given \a key, or false otherwise.
   548   Returns true if this detail has a field with the given \a key, or false otherwise.
   410  */
   549  */
   411 bool QContactDetail::hasValue(const QString& key) const
   550 bool QContactDetail::hasValue(const QString& key) const
   412 {
   551 {
   413     return d.constData()->m_values.contains(key.toLatin1().constData());
   552     return d.constData()->m_values.contains(QContactStringHolder(key));
   414 }
   553 }
   415 
   554 
   416 /*!
   555 /*!
       
   556   \internal
   417   Returns true if this detail has a field with the given \a key, or false otherwise.
   557   Returns true if this detail has a field with the given \a key, or false otherwise.
   418  */
   558  */
   419 bool QContactDetail::hasValue(const char * key) const
   559 bool QContactDetail::hasValue(const char * key) const
   420 {
   560 {
   421     return d.constData()->m_values.contains(key);
   561     return d.constData()->m_values.contains(key);
   432 
   572 
   433     d->m_values.insert(QContactStringHolder(key), value);
   573     d->m_values.insert(QContactStringHolder(key), value);
   434     return true;
   574     return true;
   435 }
   575 }
   436 
   576 
   437 /*! Inserts \a value into the detail for the given \a key if \a value is valid.  If \a value is invalid,
   577 /*!
       
   578     \internal
       
   579 
       
   580     Inserts \a value into the detail for the given \a key if \a value is valid.  If \a value is invalid,
   438     removes the field with the given \a key from the detail.  Returns true if the given \a value was set
   581     removes the field with the given \a key from the detail.  Returns true if the given \a value was set
   439     for the \a key (if the \a value was valid), or if the given \a key was removed from detail (if the
   582     for the \a key (if the \a value was valid), or if the given \a key was removed from detail (if the
   440     \a value was invalid), and returns false if the key was unable to be removed (and the \a value was invalid) */
   583     \a value was invalid), and returns false if the key was unable to be removed (and the \a value was invalid)
       
   584 */
   441 bool QContactDetail::setValue(const char* key, const QVariant& value)
   585 bool QContactDetail::setValue(const char* key, const QVariant& value)
   442 {
   586 {
   443     if (!value.isValid())
   587     if (!value.isValid())
   444         return removeValue(key);
   588         return removeValue(key);
   445 
   589 
   446     d->m_values.insert(key, value);
   590     d->m_values.insert(key, value);
   447     return true;
   591     return true;
   448 }
   592 }
   449 
   593 
   450 /*! Removes the value stored in this detail for the given \a key.  Returns true if a value was stored for the given \a key and the operation succeeded, and false otherwise */
   594 /*!
       
   595     Removes the value stored in this detail for the given \a key.  Returns true if a value was stored
       
   596     for the given \a key and the operation succeeded, and false otherwise.
       
   597 */
   451 bool QContactDetail::removeValue(const QString& key)
   598 bool QContactDetail::removeValue(const QString& key)
   452 {
   599 {
   453     if(d->m_values.remove(key.toLatin1().constData()))
   600     if(d->m_values.remove(QContactStringHolder(key)))
   454         return true;
   601         return true;
   455     return false;
   602     return false;
   456 }
   603 }
   457 /*! Removes the value stored in this detail for the given \a key.  Returns true if a value was stored for the given \a key and the operation succeeded, and false otherwise */
   604 
       
   605 /*!
       
   606     \internal
       
   607     Removes the value stored in this detail for the given \a key.  Returns true if a value was stored
       
   608     for the given \a key and the operation succeeded, and false otherwise.
       
   609 */
   458 bool QContactDetail::removeValue(const char * key)
   610 bool QContactDetail::removeValue(const char * key)
   459 {
   611 {
   460     if(d->m_values.remove(key))
   612     if(d->m_values.remove(key))
   461         return true;
   613         return true;
   462     return false;
   614     return false;
   468 QVariantMap QContactDetail::variantValues() const
   620 QVariantMap QContactDetail::variantValues() const
   469 {
   621 {
   470     QVariantMap ret;
   622     QVariantMap ret;
   471     QHash<QContactStringHolder, QVariant>::const_iterator it = d.constData()->m_values.constBegin();
   623     QHash<QContactStringHolder, QVariant>::const_iterator it = d.constData()->m_values.constBegin();
   472     while(it != d.constData()->m_values.constEnd()) {
   624     while(it != d.constData()->m_values.constEnd()) {
   473         ret.insert(it.key(), it.value());
   625         ret.insert(it.key().toQString(), it.value());
   474         ++it;
   626         ++it;
   475     }
   627     }
   476 
   628 
   477     return ret;
   629     return ret;
   478 }
   630 }
       
   631 
       
   632 
       
   633 /*!
       
   634     \fn bool QContactDetail::setValue(const QLatin1Constant& key, const QVariant& value)
       
   635 
       
   636     Inserts \a value into the detail for the given \a key if \a value is valid.  If \a value is invalid,
       
   637     removes the field with the given \a key from the detail.  Returns true if the given \a value was set
       
   638     for the \a key (if the \a value was valid), or if the given \a key was removed from detail (if the
       
   639     \a value was invalid), and returns false if the key was unable to be removed (and the \a value was invalid)
       
   640 */
       
   641 /*!
       
   642     \fn bool QContactDetail::removeValue(const QLatin1Constant& key)
       
   643 
       
   644     Removes the value stored in this detail for the given \a key.  Returns true if a value was stored
       
   645     for the given \a key and the operation succeeded, and false otherwise.
       
   646 */
       
   647 
       
   648 /*!
       
   649     \fn bool QContactDetail::hasValue(const QLatin1Constant& key) const
       
   650     Returns true if this detail has a field with the given \a key, or false otherwise.
       
   651  */
       
   652 
       
   653 /*!
       
   654     \fn QVariant QContactDetail::variantValue(const QLatin1Constant& key) const
       
   655     Returns the value stored in this detail for the given \a key as a QVariant, or an invalid QVariant if no value for the given \a key exists
       
   656  */
       
   657 
       
   658 /*!
       
   659     \fn T QContactDetail::value(const QLatin1Constant& key) const
       
   660     \overload
       
   661     Returns the value of the template type associated with the given \a key
       
   662  */
       
   663 /*!
       
   664     \fn QString QContactDetail::value(const QLatin1Constant& key) const
       
   665     Returns the value stored in this detail for the given \a key as a QString, or an empty QString if
       
   666     no value for the given \a key exists
       
   667 */
       
   668 /*!
       
   669     \fn T QContactDetail::value(const QString& key) const
       
   670     Returns the value of the template type associated with the given \a key
       
   671  */
   479 
   672 
   480 /*!
   673 /*!
   481   \enum QContactDetail::AccessConstraint
   674   \enum QContactDetail::AccessConstraint
   482 
   675 
   483   This enum defines the access constraints for a detail.  This information is typically provided by
   676   This enum defines the access constraints for a detail.  This information is typically provided by