src/messaging/qmessageaddress.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 #include "qmessageaddress.h"
       
    42 #include "qmessageaddress_p.h"
       
    43 #include "addresshelper_p.h"
       
    44 
       
    45 QTM_BEGIN_NAMESPACE
       
    46 
       
    47 /*!
       
    48     \class QMessageAddress
       
    49 
       
    50     \brief The QMessageAddress class provides an interface for a message address.
       
    51 
       
    52     \ingroup messaging
       
    53    
       
    54     A message address consists of an addressee string and a type.
       
    55 */    
       
    56 
       
    57 /*!
       
    58     \enum QMessageAddress::Type
       
    59 
       
    60     This enum type is used to describe the type of a message address.
       
    61     
       
    62     \value System             A system address.
       
    63     \value Phone              A telephony address.
       
    64     \value Email              An Email, Internet Message Format address.
       
    65     \value InstantMessage     An Instant Messaging address.
       
    66     
       
    67     \sa type(), setType()
       
    68 */
       
    69 
       
    70 /*!
       
    71     Constructs an empty message address.
       
    72 */
       
    73 QMessageAddress::QMessageAddress()
       
    74     : d_ptr(new QMessageAddressPrivate(this))
       
    75 {
       
    76     d_ptr->type = QMessageAddress::System;
       
    77 }
       
    78 
       
    79 /*!
       
    80     Constructs a message address with the given \a type and \a addressee.
       
    81 */
       
    82 QMessageAddress::QMessageAddress(Type type, const QString &addressee)
       
    83     : d_ptr(new QMessageAddressPrivate(this))
       
    84 {
       
    85     d_ptr->type = type;
       
    86     d_ptr->addressee = addressee;
       
    87 }
       
    88 
       
    89 /*!
       
    90     Constructs a copy of \a other.
       
    91 */
       
    92 QMessageAddress::QMessageAddress(const QMessageAddress &other)
       
    93     : d_ptr(new QMessageAddressPrivate(this))
       
    94 {
       
    95     this->operator=(other);
       
    96 }
       
    97 
       
    98 /*! \internal */
       
    99 QMessageAddress& QMessageAddress::operator=(const QMessageAddress& other)
       
   100 {
       
   101     if (&other != this) {
       
   102         d_ptr->addressee = other.d_ptr->addressee;
       
   103         d_ptr->type = other.d_ptr->type;
       
   104     }
       
   105 
       
   106     return *this;
       
   107 }
       
   108 
       
   109 /*!
       
   110     Destroys the message address.
       
   111 */
       
   112 QMessageAddress::~QMessageAddress()
       
   113 {
       
   114     delete d_ptr;
       
   115     d_ptr = 0;
       
   116 }
       
   117 
       
   118 /*! \internal */
       
   119 bool QMessageAddress::operator==(const QMessageAddress& other) const
       
   120 {
       
   121     return ((d_ptr->type == other.d_ptr->type) && (d_ptr->addressee == other.d_ptr->addressee));
       
   122 }
       
   123 
       
   124 /*! \internal */
       
   125 bool QMessageAddress::operator!=(const QMessageAddress& other) const
       
   126 {
       
   127     return !operator==(other);
       
   128 }
       
   129 
       
   130 /*!
       
   131     Returns the addressee.
       
   132 
       
   133     \sa setAddressee()
       
   134 */
       
   135 QString QMessageAddress::addressee() const
       
   136 {
       
   137     return d_ptr->addressee;
       
   138 }
       
   139 
       
   140 /*!
       
   141     Sets the addressee to \a addressee.
       
   142 
       
   143     \sa addressee()
       
   144 */
       
   145 void QMessageAddress::setAddressee(const QString &addressee)
       
   146 {
       
   147     d_ptr->addressee = addressee;
       
   148 }
       
   149 
       
   150 /*!
       
   151     Returns the type of the message address.
       
   152 
       
   153     \sa setType()
       
   154 */
       
   155 QMessageAddress::Type QMessageAddress::type() const
       
   156 {
       
   157     return d_ptr->type;
       
   158 }
       
   159 
       
   160 /*!
       
   161     Sets the type of the message address to \a type.
       
   162 
       
   163     \sa type()
       
   164 */
       
   165 void QMessageAddress::setType(Type type)
       
   166 {
       
   167     d_ptr->type = type;
       
   168 }
       
   169 
       
   170 /*!
       
   171     Parses an email address into name, address and suffix parts.
       
   172 
       
   173     * \a name is set to the name part of the email address.
       
   174     * \a address is set to the address part of the email address.
       
   175     * \a suffix is set to the suffix part of the email address.
       
   176     
       
   177     If the starting delimeter between the name and address part of the email address is found 
       
   178     then * \a startDelimeterFound is set to true; otherwise * \a startDelimeterFound is set to false;
       
   179 
       
   180     If the starting delimeter is not found, then the parsing is ambiguous and both * \a name and
       
   181     * \a address will be set to the input \a emailAddress.
       
   182 
       
   183     If the ending delimeter of the address part of the email address is found 
       
   184     then * \a endDelimeterFound is set to true; otherwise * \a endDelimeterFound is set to false;
       
   185 
       
   186 */
       
   187 void QMessageAddress::parseEmailAddress(const QString &emailAddress, QString *name, QString *address, QString *suffix, bool *startDelimeterFound, bool *endDelimeterFound)
       
   188 {
       
   189     QString *aName(name);
       
   190     QString strName;
       
   191     if (!aName)
       
   192         aName = &strName;
       
   193 
       
   194     QString *aAddress(address);
       
   195     QString strAddress;
       
   196     if (!aAddress)
       
   197         aAddress = &strAddress;
       
   198 
       
   199     QString *aSuffix(suffix);
       
   200     QString strSuffix;
       
   201     if (!aSuffix)
       
   202         aSuffix = &strSuffix;
       
   203 
       
   204     bool *aStartDelimeterFound(startDelimeterFound);
       
   205     bool ignored1;
       
   206     if (!aStartDelimeterFound)
       
   207         aStartDelimeterFound = &ignored1;
       
   208 
       
   209     bool *aEndDelimeterFound(endDelimeterFound);
       
   210     bool ignored2;
       
   211     if (!aEndDelimeterFound)
       
   212         aEndDelimeterFound = &ignored2;
       
   213 
       
   214     QString emailAddressCopy(emailAddress);
       
   215     qParseMailbox(emailAddressCopy, *aName, *aAddress, *aSuffix, *aStartDelimeterFound, *aEndDelimeterFound);
       
   216 }
       
   217 
       
   218 /*! \typedef QMessageAddressList
       
   219 
       
   220     Qt-style synonym for QList<QMessageAddress>
       
   221 */
       
   222 
       
   223 QTM_END_NAMESPACE