qtmobility/src/messaging/qmessagecontentcontainerid_qmf.cpp
changeset 1 2b40d63a9c3d
child 5 453da2cfceef
equal deleted inserted replaced
0:cfcbf08528c4 1:2b40d63a9c3d
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 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 "qmessagecontentcontainerid.h"
       
    42 
       
    43 #include <qmailmessage.h>
       
    44 
       
    45 QTM_BEGIN_NAMESPACE
       
    46 
       
    47 class QMessageContentContainerIdPrivate
       
    48 {
       
    49 public:
       
    50     QMailMessagePart::Location _location;
       
    51     bool _body;
       
    52 
       
    53     QMessageContentContainerIdPrivate() : _body(false) {}
       
    54     
       
    55     static QMessageContentContainerId convert(const QMailMessagePart::Location &location);
       
    56     static QMailMessagePart::Location convert(const QMessageContentContainerId &id);
       
    57 
       
    58     static QMessageContentContainerId bodyId(const QMailMessageId &id);
       
    59 };
       
    60 
       
    61 QMessageContentContainerId QMessageContentContainerIdPrivate::convert(const QMailMessagePart::Location &location)
       
    62 {
       
    63     QMessageContentContainerId result;
       
    64     result.d_ptr->_location = location;
       
    65     return result;
       
    66 }
       
    67 
       
    68 QMailMessagePart::Location QMessageContentContainerIdPrivate::convert(const QMessageContentContainerId &id)
       
    69 {
       
    70     return id.d_ptr->_location;
       
    71 }
       
    72 
       
    73 QMessageContentContainerId QMessageContentContainerIdPrivate::bodyId(const QMailMessageId &id)
       
    74 {
       
    75     QMessageContentContainerId result;
       
    76     result.d_ptr->_body = true;
       
    77 
       
    78     if (id.isValid()) {
       
    79         result.d_ptr->_location.setContainingMessageId(id);
       
    80     }
       
    81 
       
    82     return result;
       
    83 }
       
    84 
       
    85 namespace QmfHelpers {
       
    86 
       
    87 QMessageContentContainerId convert(const QMailMessagePart::Location &location)
       
    88 {
       
    89     return QMessageContentContainerIdPrivate::convert(location);
       
    90 }
       
    91 
       
    92 QMailMessagePart::Location convert(const QMessageContentContainerId &id)
       
    93 {
       
    94     return QMessageContentContainerIdPrivate::convert(id);
       
    95 }
       
    96 
       
    97 QMessageContentContainerId bodyId(const QMailMessageId &id)
       
    98 {
       
    99     return QMessageContentContainerIdPrivate::bodyId(id);
       
   100 }
       
   101 
       
   102 }
       
   103 
       
   104 QMessageContentContainerId::QMessageContentContainerId()
       
   105     : d_ptr(new QMessageContentContainerIdPrivate)
       
   106 {
       
   107 }
       
   108 
       
   109 QMessageContentContainerId::QMessageContentContainerId(const QMessageContentContainerId& other)
       
   110     : d_ptr(new QMessageContentContainerIdPrivate)
       
   111 {
       
   112     this->operator=(other);
       
   113 }
       
   114 
       
   115 QMessageContentContainerId::QMessageContentContainerId(const QString& id)
       
   116     : d_ptr(new QMessageContentContainerIdPrivate)
       
   117 {
       
   118     QString input(id);
       
   119 
       
   120     if (input.startsWith("body:")) {
       
   121         d_ptr->_body = true;
       
   122         input = input.mid(5);
       
   123     }
       
   124 
       
   125     if (!input.isEmpty()) {
       
   126         QMailMessagePart::Location loc(input);
       
   127         if (loc.isValid(false) || loc.containingMessageId().isValid()) {
       
   128             d_ptr->_location = loc;
       
   129         }
       
   130     }
       
   131 }
       
   132 
       
   133 QMessageContentContainerId::~QMessageContentContainerId()
       
   134 {
       
   135     delete d_ptr;
       
   136 }
       
   137 
       
   138 bool QMessageContentContainerId::operator==(const QMessageContentContainerId& other) const
       
   139 {
       
   140     if (isValid()) {
       
   141         return (other.isValid() && (toString() == other.toString()));
       
   142     } else {
       
   143         return !other.isValid();
       
   144     }
       
   145 }
       
   146 
       
   147 QMessageContentContainerId& QMessageContentContainerId::operator=(const QMessageContentContainerId& other)
       
   148 {
       
   149     if (&other != this) {
       
   150         d_ptr->_location = other.d_ptr->_location;
       
   151         d_ptr->_body = other.d_ptr->_body;
       
   152     }
       
   153 
       
   154     return *this;
       
   155 }
       
   156 
       
   157 QString QMessageContentContainerId::toString() const
       
   158 {
       
   159     QString location(d_ptr->_location.toString(true));
       
   160     if (d_ptr->_body) {
       
   161         location.prepend("body:");
       
   162     }
       
   163 
       
   164     return location;
       
   165 }
       
   166 
       
   167 bool QMessageContentContainerId::isValid() const
       
   168 {
       
   169     // Either we have a valid part locator, or we indicate a message body
       
   170     return (d_ptr->_body || d_ptr->_location.isValid(false));
       
   171 }
       
   172 
       
   173 QTM_END_NAMESPACE