emailservices/nmailbase/src/nmaddress.cpp
changeset 18 578830873419
child 30 759dc5235cdb
equal deleted inserted replaced
4:e7aa27f58ae1 18:578830873419
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QString>
       
    19 
       
    20 #include "nmaddress.h"
       
    21 
       
    22 /*!
       
    23   Constructor of NmAddressPrivate object
       
    24  */
       
    25 NmAddressPrivate::NmAddressPrivate()
       
    26 :mDisplayName(""),
       
    27 mAddress("")
       
    28 {
       
    29 }
       
    30 
       
    31 /*!
       
    32   Destructor of NmAddressPrivate object
       
    33  */
       
    34 NmAddressPrivate::~NmAddressPrivate()
       
    35 {
       
    36 }
       
    37 
       
    38 /*!
       
    39     \class NmMailAddress
       
    40     \brief Container class for email address having displayname and address
       
    41     strings separated
       
    42 
       
    43     NmMailAddress class encapsulates RFC 2822 style email adrress - display name
       
    44     pair. Example: "FirstName LastName" <FirstName.LastName(at)email.com> where display name is
       
    45     'FirstName LastName' and address is 'FirstName.LastName(at)email.com' Class does not parse 
       
    46     " and < marks away, those marks should be removed before setting data to
       
    47     NmMailAddress object
       
    48 
       
    49  */
       
    50 
       
    51 /*!
       
    52   Constructs new empty NmAddress object
       
    53  */
       
    54 NmAddress::NmAddress()
       
    55 {
       
    56     d = new NmAddressPrivate();
       
    57 }
       
    58 
       
    59 /*!
       
    60   Constructs new NmAddress object with \a displayName and \a address
       
    61  */
       
    62 NmAddress::NmAddress(const QString &displayName, const QString &address)
       
    63 {
       
    64     d = new NmAddressPrivate();
       
    65     d->mDisplayName = displayName;
       
    66     d->mAddress = address;
       
    67 }
       
    68 
       
    69 /*!
       
    70   Constructs new NmAddress object with \a address display name is leaved empty
       
    71  */
       
    72 NmAddress::NmAddress(const QString &address)
       
    73 {
       
    74     d = new NmAddressPrivate();
       
    75     d->mAddress = address;
       
    76 }
       
    77 
       
    78 /*!
       
    79   Constructs new NmAddress object by copying data from \a nmAddress
       
    80  */
       
    81 NmAddress::NmAddress(const NmAddress &nmAddress) : d(nmAddress.d)
       
    82 {
       
    83 }
       
    84 
       
    85 /*!
       
    86   Constructs new NmAddress object from private address data
       
    87  */
       
    88 NmAddress::NmAddress(QExplicitlySharedDataPointer<NmAddressPrivate> nmPrivateAddress)
       
    89 {
       
    90     d = nmPrivateAddress;
       
    91 }
       
    92 
       
    93 /*!
       
    94   Copy operator sets data from \a nmAddress
       
    95  */
       
    96 NmAddress &NmAddress::operator=(const NmAddress &nmAddress)
       
    97 {
       
    98     if (this != &nmAddress) {
       
    99       d = nmAddress.d;
       
   100     }
       
   101     return *this;
       
   102 }
       
   103 
       
   104 /*!
       
   105   Destructor
       
   106  */
       
   107 NmAddress::~NmAddress()
       
   108 {
       
   109 }
       
   110 
       
   111 
       
   112 /*!
       
   113   Equal operator returns true if display name and address are same,
       
   114   function is case insensitive
       
   115  */
       
   116 bool NmAddress::operator==(const NmAddress &otherAddress) const
       
   117 {
       
   118     bool ret = false;
       
   119     if (otherAddress.address().compare(d->mAddress, Qt::CaseInsensitive) == 0 &&
       
   120         otherAddress.displayName().compare(
       
   121         d->mDisplayName, Qt::CaseInsensitive) == 0) {
       
   122         ret = true;
       
   123     }
       
   124     return ret;
       
   125 }
       
   126 
       
   127 /*!
       
   128   Not equal operator return true if address or display name is not equal,
       
   129   function is case insensitive
       
   130  */
       
   131 bool NmAddress::operator!=(const NmAddress &otherAddress) const
       
   132 {
       
   133     bool ret = true;
       
   134     if (otherAddress.address().compare(d->mAddress, Qt::CaseInsensitive) == 0 &&
       
   135         otherAddress.displayName().compare(
       
   136         d->mDisplayName, Qt::CaseInsensitive) == 0) {
       
   137         ret = false;
       
   138     }
       
   139     return ret;
       
   140 }
       
   141 
       
   142 /*!
       
   143   Sets display name from \a displayName
       
   144  */
       
   145 void NmAddress::setDisplayName(const QString &displayName)
       
   146 {
       
   147     d->mDisplayName = displayName;
       
   148 }
       
   149 
       
   150 /*!
       
   151   Returns display name string
       
   152  */
       
   153 QString NmAddress::displayName() const
       
   154 {
       
   155     return d->mDisplayName;
       
   156 }
       
   157 
       
   158 /*!
       
   159   Sets address from \a address
       
   160  */
       
   161 void NmAddress::setAddress(const QString &address)
       
   162 {
       
   163     d->mAddress = address;
       
   164 }
       
   165 
       
   166 /*!
       
   167   Returns address string
       
   168  */
       
   169 QString NmAddress::address() const
       
   170 {
       
   171     return d->mAddress;
       
   172 }