qtmobility/src/messaging/messagingutil.cpp
changeset 8 71781823f776
child 11 06b8e2af4411
equal deleted inserted replaced
5:453da2cfceef 8:71781823f776
       
     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 
       
    42 #include "messagingutil_p.h"
       
    43 #include "qmessageid.h"
       
    44 #include "qmessageaccountid.h"
       
    45 #include "qmessagefolderid.h"
       
    46 #include <qmessageglobal.h>
       
    47 
       
    48 #include <QDebug>
       
    49 
       
    50 
       
    51 
       
    52 QTM_BEGIN_NAMESPACE
       
    53 
       
    54 namespace SymbianHelpers {
       
    55 
       
    56     EngineType idType(const QString& id)
       
    57     {
       
    58         if (id.startsWith(mtmPrefix)) {
       
    59             return EngineTypeMTM;
       
    60         } else if (id.startsWith(freestylePrefix)) {
       
    61             return EngineTypeFreestyle;
       
    62         } else {
       
    63             return EngineTypeMTM;
       
    64         }
       
    65     }
       
    66 
       
    67     EngineType idType(const QMessageId& id)
       
    68     {
       
    69         if (id.toString().startsWith(mtmPrefix)) {
       
    70             return EngineTypeMTM;
       
    71         } else if (id.toString().startsWith(freestylePrefix)) {
       
    72             return EngineTypeFreestyle;
       
    73         } else {
       
    74             return EngineTypeMTM;
       
    75         }
       
    76     }
       
    77     
       
    78     EngineType idType(const QMessageAccountId& id)
       
    79     {
       
    80         if (id.toString().startsWith(mtmPrefix)) {
       
    81             return EngineTypeMTM;
       
    82         } else if (id.toString().startsWith(freestylePrefix)) {
       
    83             return EngineTypeFreestyle;
       
    84         } else {
       
    85             return EngineTypeMTM;
       
    86         }
       
    87     }
       
    88     
       
    89     EngineType idType(const QMessageFolderId& id)
       
    90     {
       
    91         if (id.toString().startsWith(mtmPrefix)) {
       
    92             return EngineTypeMTM;
       
    93         } else if (id.toString().startsWith(freestylePrefix)) {
       
    94             return EngineTypeFreestyle;
       
    95         } else {
       
    96             return EngineTypeMTM;
       
    97         }
       
    98     }
       
    99 
       
   100     
       
   101     QString addIdPrefix(const QString& id, const EngineType& type)
       
   102     {
       
   103         switch (type) {
       
   104         case EngineTypeFreestyle:
       
   105             Q_ASSERT(!id.startsWith(freestylePrefix));
       
   106             return QString(freestylePrefix) + id;
       
   107             break;
       
   108         case EngineTypeMTM:
       
   109             Q_ASSERT(!id.startsWith(mtmPrefix));
       
   110             return QString(mtmPrefix) + id;
       
   111         default:
       
   112             return QString(id);
       
   113             break;
       
   114         }
       
   115     }
       
   116 
       
   117     QMessageAccountId addIdPrefix(const QMessageAccountId& id, const EngineType& type)
       
   118     {
       
   119         switch (type) {
       
   120         case EngineTypeFreestyle:
       
   121             Q_ASSERT(!id.toString().startsWith(freestylePrefix));
       
   122             return QMessageAccountId(QString(freestylePrefix) + id.toString());
       
   123             break;
       
   124         case EngineTypeMTM:
       
   125             Q_ASSERT(!id.toString().startsWith(mtmPrefix));
       
   126             return QMessageAccountId(QString(mtmPrefix) + id.toString());
       
   127             break;
       
   128         default:
       
   129             return QMessageAccountId(id);
       
   130             break;
       
   131         }
       
   132     }
       
   133 
       
   134     QMessageFolderId addIdPrefix(const QMessageFolderId& id, const EngineType& type)
       
   135     {
       
   136         switch (type) {
       
   137         case EngineTypeFreestyle:
       
   138             Q_ASSERT(!id.toString().startsWith(freestylePrefix));
       
   139             return QMessageFolderId(QString(freestylePrefix) + id.toString());
       
   140             break;
       
   141         case EngineTypeMTM:
       
   142             Q_ASSERT(!id.toString().startsWith(mtmPrefix));
       
   143             return QMessageFolderId(QString(mtmPrefix) + id.toString());
       
   144             break;
       
   145         default:
       
   146             return QMessageFolderId(id);
       
   147             break;
       
   148         }
       
   149     }
       
   150 
       
   151     QMessageId addIdPrefix(const QMessageId& id, const EngineType& type)
       
   152     {
       
   153         switch (type) {
       
   154         case EngineTypeFreestyle:
       
   155             Q_ASSERT(!id.toString().startsWith(freestylePrefix));
       
   156             return QMessageId(freestylePrefix + id.toString());
       
   157             break;
       
   158         case EngineTypeMTM:
       
   159             Q_ASSERT(!id.toString().startsWith(mtmPrefix));
       
   160             return QMessageId(mtmPrefix + id.toString());
       
   161             break;
       
   162         default:
       
   163             return QMessageId(id);
       
   164             break;
       
   165         }
       
   166     }
       
   167 
       
   168     QString stripIdPrefix(const QString& id)
       
   169     {
       
   170         if (id.startsWith(freestylePrefix))
       
   171             return id.right(id.length() - QString(freestylePrefix).length());
       
   172         else if (id.startsWith(mtmPrefix))
       
   173             return id.right(id.length() - QString(mtmPrefix).length());
       
   174         else
       
   175             return QString(id);
       
   176     }
       
   177 
       
   178     QMessageId stripIdPrefix(const QMessageId& id)
       
   179     {
       
   180         if (id.toString().startsWith(freestylePrefix))
       
   181             return QMessageId(id.toString().right(id.toString().length() - QString(freestylePrefix).length()));
       
   182         else if (id.toString().startsWith(mtmPrefix))
       
   183             return QMessageId(id.toString().right(id.toString().length() - QString(mtmPrefix).length()));
       
   184         else
       
   185             return QMessageId(id);
       
   186     }
       
   187 
       
   188     QMessageAccountId stripIdPrefix(const QMessageAccountId& id)
       
   189     {
       
   190         if (id.toString().startsWith(freestylePrefix))
       
   191             return QMessageAccountId(id.toString().right(id.toString().length() - QString(freestylePrefix).length()));
       
   192         else if (id.toString().startsWith(mtmPrefix))
       
   193             return QMessageAccountId(id.toString().right(id.toString().length() - QString(mtmPrefix).length()));
       
   194         else
       
   195             return QMessageAccountId(id);
       
   196     }
       
   197 
       
   198     QMessageFolderId stripIdPrefix(const QMessageFolderId& id)
       
   199     {
       
   200         if (id.toString().startsWith(freestylePrefix))
       
   201             return QMessageFolderId(id.toString().right(id.toString().length() - QString(freestylePrefix).length()));
       
   202         else if (id.toString().startsWith(mtmPrefix))
       
   203             return QMessageFolderId(id.toString().right(id.toString().length() - QString(mtmPrefix).length()));
       
   204         else
       
   205             return QMessageFolderId(id);
       
   206     }
       
   207 
       
   208 }
       
   209 
       
   210 namespace MessagingUtil {
       
   211 
       
   212     QString addIdPrefix(const QString& id)
       
   213     {
       
   214         if(id.startsWith(idPrefix()))
       
   215 			qWarning() << "ID already prefixed";
       
   216 
       
   217         return idPrefix() + id;
       
   218     }
       
   219 
       
   220     QString stripIdPrefix(const QString& id)
       
   221     {
       
   222 		if(!id.startsWith(idPrefix()))
       
   223 			qWarning() << "ID not prefixed";
       
   224 
       
   225 		return id.right(id.length() - idPrefix().length());
       
   226     }
       
   227 
       
   228     QString idPrefix()
       
   229     {
       
   230 #ifdef Q_OS_SYMBIAN
       
   231         static QString prefix(SymbianHelpers::mtmPrefix);
       
   232 #elif defined(Q_OS_WIN)
       
   233         static QString prefix("WIN_");
       
   234 #else
       
   235         static QString prefix("QMF_");
       
   236 #endif
       
   237         return prefix;
       
   238     }
       
   239 
       
   240 }
       
   241 
       
   242 QTM_END_NAMESPACE