qtmobility/src/messaging/qmfhelpers.cpp
changeset 1 2b40d63a9c3d
child 4 90517678cc4f
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 
       
    42 #include "qmfhelpers_p.h"
       
    43 #include "qmessagemanager.h"
       
    44 
       
    45 #include <QRegExp>
       
    46 
       
    47 
       
    48 QTM_BEGIN_NAMESPACE
       
    49 
       
    50 namespace {
       
    51 
       
    52 quint64 messageStatusMask(const QString &field)
       
    53 {
       
    54     QMessageManager mgr;
       
    55     return QmfHelpers::convert(mgr)->messageStatusMask(field);
       
    56 }
       
    57 
       
    58 }
       
    59 
       
    60 namespace QmfHelpers {
       
    61 
       
    62 QMessageId convert(const QMailMessageId &id)
       
    63 {
       
    64     return QMessageId(QString::number(id.toULongLong()));
       
    65 }
       
    66 
       
    67 QMailMessageId convert(const QMessageId &id)
       
    68 {
       
    69     return QMailMessageId(id.toString().toULongLong());
       
    70 }
       
    71 
       
    72 QMessageAccountId convert(const QMailAccountId &id)
       
    73 {
       
    74     return QMessageAccountId(QString::number(id.toULongLong()));
       
    75 }
       
    76 
       
    77 QMailAccountId convert(const QMessageAccountId &id)
       
    78 {
       
    79     return QMailAccountId(id.toString().toULongLong());
       
    80 }
       
    81 
       
    82 QMessageFolderId convert(const QMailFolderId &id)
       
    83 {
       
    84     return QMessageFolderId(QString::number(id.toULongLong()));
       
    85 }
       
    86 
       
    87 QMailFolderId convert(const QMessageFolderId &id)
       
    88 {
       
    89     return QMailFolderId(id.toString().toULongLong());
       
    90 }
       
    91 
       
    92 /* in qmessagecontentcontainerid_qmf.cpp
       
    93 QMessageContentContainerId convert(const QMailMessagePart::Location &location);
       
    94 
       
    95 QMailMessagePart::Location convert(const QMessageContentContainerId &id);
       
    96 
       
    97 QMessageContentContainerId bodyId(const QMailMessageId &id);
       
    98 */
       
    99 
       
   100 QMessageIdList convert(const QList<QMailMessageId> &ids)
       
   101 {
       
   102     QMessageIdList result;
       
   103 
       
   104     foreach (const QMailMessageId &id, ids) {
       
   105         result.append(convert(id));
       
   106     }
       
   107 
       
   108     return result;
       
   109 }
       
   110 
       
   111 QList<QMailMessageId> convert(const QMessageIdList &ids)
       
   112 {
       
   113     QList<QMailMessageId> result;
       
   114 
       
   115     foreach (const QMessageId &id, ids) {
       
   116         result.append(convert(id));
       
   117     }
       
   118 
       
   119     return result;
       
   120 }
       
   121 
       
   122 QMessageAccountIdList convert(const QList<QMailAccountId> &ids)
       
   123 {
       
   124     QMessageAccountIdList result;
       
   125 
       
   126     foreach (const QMailAccountId &id, ids) {
       
   127         result.append(convert(id));
       
   128     }
       
   129 
       
   130     return result;
       
   131 }
       
   132 
       
   133 QList<QMailAccountId> convert(const QMessageAccountIdList &ids)
       
   134 {
       
   135     QList<QMailAccountId> result;
       
   136 
       
   137     foreach (const QMessageAccountId &id, ids) {
       
   138         result.append(convert(id));
       
   139     }
       
   140 
       
   141     return result;
       
   142 }
       
   143 
       
   144 QMessageFolderIdList convert(const QList<QMailFolderId> &ids)
       
   145 {
       
   146     QMessageFolderIdList result;
       
   147 
       
   148     foreach (const QMailFolderId &id, ids) {
       
   149         result.append(convert(id));
       
   150     }
       
   151 
       
   152     return result;
       
   153 }
       
   154 
       
   155 QList<QMailFolderId> convert(const QMessageFolderIdList &ids)
       
   156 {
       
   157     QList<QMailFolderId> result;
       
   158 
       
   159     foreach (const QMessageFolderId &id, ids) {
       
   160         result.append(convert(id));
       
   161     }
       
   162 
       
   163     return result;
       
   164 }
       
   165 
       
   166 QMessageContentContainerIdList convert(const QList<QMailMessagePart::Location> &locations)
       
   167 {
       
   168     QMessageContentContainerIdList result;
       
   169 
       
   170     foreach (const QMailMessagePart::Location &location, locations) {
       
   171         result.append(convert(location));
       
   172     }
       
   173 
       
   174     return result;
       
   175 }
       
   176 
       
   177 /*
       
   178 QList<QMailMessagePart::Location> convert(const QMessageContentContainerIdList &ids)
       
   179 {
       
   180     QList<QMailMessagePart::Location> result;
       
   181 
       
   182     foreach (const QMessageContentContainerId &id, ids) {
       
   183         result.append(convert(id));
       
   184     }
       
   185 
       
   186     return result;
       
   187 }
       
   188 */
       
   189 
       
   190 QMailMessage::MessageType convert(QMessage::Type t)
       
   191 {
       
   192     QMailMessage::MessageType result(QMailMessage::None);
       
   193 
       
   194     // This could be a single value or a mask
       
   195     if (t & QMessage::Mms) {
       
   196         result = static_cast<QMailMessage::MessageType>(result | QMailMessage::Mms);
       
   197     }
       
   198     if (t & QMessage::Sms) {
       
   199         result = static_cast<QMailMessage::MessageType>(result | QMailMessage::Sms);
       
   200     }
       
   201     if (t & QMessage::Email) {
       
   202         result = static_cast<QMailMessage::MessageType>(result | QMailMessage::Email);
       
   203     }
       
   204     if (t & QMessage::Xmpp) {
       
   205         result = static_cast<QMailMessage::MessageType>(result | QMailMessage::Instant);
       
   206     }
       
   207 
       
   208     return result;
       
   209 }
       
   210 
       
   211 QMessage::Type convert(QMailMessage::MessageType t)
       
   212 {
       
   213     QMessage::Type result(QMessage::NoType);
       
   214 
       
   215     // This could be a single value or a mask
       
   216     if (t & QMailMessage::Mms) {
       
   217         result = static_cast<QMessage::Type>(static_cast<uint>(result | QMessage::Mms));
       
   218     }
       
   219     if (t & QMailMessage::Sms) {
       
   220         result = static_cast<QMessage::Type>(static_cast<uint>(result | QMessage::Sms));
       
   221     }
       
   222     if (t & QMailMessage::Email) {
       
   223         result = static_cast<QMessage::Type>(static_cast<uint>(result | QMessage::Email));
       
   224     }
       
   225     if (t & QMailMessage::Instant) {
       
   226         result = static_cast<QMessage::Type>(static_cast<uint>(result | QMessage::Xmpp));
       
   227     }
       
   228 
       
   229     return result;
       
   230 }
       
   231 
       
   232 QMailMessage::MessageType convert(QMessage::TypeFlags v)
       
   233 {
       
   234     return convert(static_cast<QMessage::Type>(static_cast<uint>(v)));
       
   235 }
       
   236 
       
   237 /*
       
   238 QMailStore::ErrorCode convert(QMessageManager::Error v)
       
   239 {
       
   240     switch (v) {
       
   241     case QMessageManager::InvalidId: return QMailStore::InvalidId;
       
   242     case QMessageManager::ConstraintFailure: return QMailStore::ConstraintFailure;
       
   243     case QMessageManager::ContentInaccessible: return QMailStore::ContentInaccessible;
       
   244     case QMessageManager::NotYetImplemented: return QMailStore::NotYetImplemented;
       
   245     case QMessageManager::FrameworkFault: return QMailStore::FrameworkFault;
       
   246     default: break;
       
   247     }
       
   248 
       
   249     return QMailStore::NoError;
       
   250 }
       
   251 */
       
   252 
       
   253 QMessageManager::Error convert(QMailStore::ErrorCode v)
       
   254 {
       
   255     switch (v) {
       
   256     case QMailStore::InvalidId: return QMessageManager::InvalidId;
       
   257     case QMailStore::ConstraintFailure: return QMessageManager::ConstraintFailure;
       
   258     case QMailStore::ContentInaccessible: return QMessageManager::ContentInaccessible;
       
   259     case QMailStore::NotYetImplemented: return QMessageManager::NotYetImplemented;
       
   260     case QMailStore::FrameworkFault: return QMessageManager::FrameworkFault;
       
   261     default: break;
       
   262     }
       
   263 
       
   264     return QMessageManager::NoError;
       
   265 }
       
   266 
       
   267 QMailStore::MessageRemovalOption convert(QMessageManager::RemovalOption v)
       
   268 {
       
   269     switch (v) {
       
   270     case QMessageManager::RemoveOnOriginatingServer: return QMailStore::CreateRemovalRecord;
       
   271     default: break;
       
   272     }
       
   273 
       
   274     return QMailStore::NoRemovalRecord;
       
   275 }
       
   276 
       
   277 /*
       
   278 QMessageManager::RemovalOption convert(QMailStore::MessageRemovalOption v)
       
   279 {
       
   280     switch (v) {
       
   281     case QMailStore::CreateRemovalRecord: return QMessageManager::RemoveOnOriginatingServer;
       
   282     default: break;
       
   283     }
       
   284 
       
   285     return QMessageManager::RemoveLocalCopyOnly;
       
   286 }
       
   287 */
       
   288 
       
   289 QMailServiceAction::Activity convert(QMessageService::State v)
       
   290 {
       
   291     switch (v) {
       
   292     case QMessageService::InactiveState: return QMailServiceAction::Pending;
       
   293     case QMessageService::ActiveState: return QMailServiceAction::InProgress;
       
   294     case QMessageService::CanceledState: return QMailServiceAction::Failed;
       
   295     case QMessageService::FinishedState: return QMailServiceAction::Successful;
       
   296     default: break;
       
   297     }
       
   298 
       
   299     return QMailServiceAction::Pending;
       
   300 }
       
   301 
       
   302 QMessageService::State convert(QMailServiceAction::Activity v)
       
   303 {
       
   304     switch (v) {
       
   305     case QMailServiceAction::Pending: return QMessageService::InactiveState;
       
   306     case QMailServiceAction::InProgress: return QMessageService::ActiveState;
       
   307     case QMailServiceAction::Successful: return QMessageService::FinishedState;
       
   308     case QMailServiceAction::Failed: return QMessageService::FinishedState;
       
   309     default: break;
       
   310     }
       
   311 
       
   312     return QMessageService::InactiveState;
       
   313 }
       
   314 
       
   315 QMessage::StatusFlags convert(quint64 v)
       
   316 {
       
   317     QMessage::StatusFlags result(0);
       
   318 
       
   319     if (v & (QMailMessage::Read | QMailMessage::ReadElsewhere)) {
       
   320         result |= QMessage::Read;
       
   321     }
       
   322     if (v & QMailMessage::HasAttachments) {
       
   323         result |= QMessage::HasAttachments;
       
   324     }
       
   325     if (v & QMailMessage::Incoming) {
       
   326         result |= QMessage::Incoming;
       
   327     }
       
   328     if (v & QMailMessage::Removed) {
       
   329         result |= QMessage::Removed;
       
   330     }
       
   331 
       
   332     return result;
       
   333 }
       
   334 
       
   335 quint64 convert(QMessage::Status v)
       
   336 {
       
   337     // We cannot rely on the QMailMessage status masks until the store has been initialized
       
   338     static QMailStore *store = QMailStore::instance();
       
   339     Q_UNUSED(store);
       
   340 
       
   341     quint64 result(0);
       
   342 
       
   343     if (v & QMessage::Read) {
       
   344         result |= QMailMessage::Read;
       
   345     }
       
   346     if (v & QMessage::HasAttachments) {
       
   347         result |= QMailMessage::HasAttachments;
       
   348     }
       
   349     if (v & QMessage::Incoming) {
       
   350         result |= QMailMessage::Incoming;
       
   351     }
       
   352     if (v & QMessage::Removed) {
       
   353         result |= QMailMessage::Removed;
       
   354     }
       
   355 
       
   356     return result;
       
   357 }
       
   358 
       
   359 quint64 convert(QMessage::StatusFlags v)
       
   360 {
       
   361     return convert(static_cast<QMessage::Status>(static_cast<uint>(v)));
       
   362 }
       
   363 
       
   364 QMessageAddress convert(const QMailAddress &address)
       
   365 {
       
   366     QString addr(address.toString());
       
   367     if (!addr.isEmpty()) {
       
   368         QMessageAddress::Type type(QMessageAddress::Email);
       
   369 
       
   370         QRegExp suffix("\\s+\\(TYPE=(\\w*)\\)$");
       
   371         int index = suffix.indexIn(addr);
       
   372         if (index != -1) {
       
   373             addr = addr.left(addr.length() - suffix.cap(0).length());
       
   374 
       
   375             QString spec(suffix.cap(1));
       
   376             if (spec == "System") {
       
   377                 type = QMessageAddress::System;
       
   378             } else if (spec == "Phone") {
       
   379                 type = QMessageAddress::Phone;
       
   380             } else if (spec == "XMPP") {
       
   381                 type = QMessageAddress::Xmpp;
       
   382             }
       
   383         }
       
   384 
       
   385         return QMessageAddress(type, addr);
       
   386     }
       
   387 
       
   388     return QMessageAddress();
       
   389 }
       
   390 
       
   391 QMailAddress convert(const QMessageAddress &address)
       
   392 {
       
   393     QString suffix;
       
   394     if (address.type() == QMessageAddress::System) {
       
   395         suffix = " (TYPE=System)";
       
   396     } else if (address.type() == QMessageAddress::Phone) {
       
   397         suffix = " (TYPE=Phone)";
       
   398     } else if (address.type() == QMessageAddress::Xmpp) {
       
   399         suffix = " (TYPE=XMPP)";
       
   400     }
       
   401 
       
   402     return QMailAddress(address.recipient() + suffix);
       
   403 }
       
   404 
       
   405 QMessageAddressList convert(const QList<QMailAddress> &list)
       
   406 {
       
   407     QList<QMessageAddress> result;
       
   408 
       
   409     foreach (const QMailAddress &address, list) {
       
   410         result.append(convert(address));
       
   411     }
       
   412 
       
   413     return result;
       
   414 }
       
   415 
       
   416 QList<QMailAddress> convert(const QMessageAddressList& list)
       
   417 {
       
   418     QList<QMailAddress> result;
       
   419 
       
   420     foreach (const QMessageAddress &address, list) {
       
   421         result.append(convert(address));
       
   422     }
       
   423 
       
   424     return result;
       
   425 }
       
   426 
       
   427 /*
       
   428 QMessageDataComparator::EqualityComparator convert(QMailDataComparator::EqualityComparator cmp)
       
   429 {
       
   430     switch (cmp)
       
   431     {
       
   432     case QMailDataComparator::Equal: return QMessageDataComparator::Equal;
       
   433     case QMailDataComparator::NotEqual: return QMessageDataComparator::NotEqual;
       
   434     default: break;
       
   435     }
       
   436 
       
   437     return QMessageDataComparator::Equal;
       
   438 }
       
   439 */
       
   440 
       
   441 QMailDataComparator::EqualityComparator convert(QMessageDataComparator::EqualityComparator cmp)
       
   442 {
       
   443     switch (cmp)
       
   444     {
       
   445     case QMessageDataComparator::Equal: return QMailDataComparator::Equal;
       
   446     case QMessageDataComparator::NotEqual: return QMailDataComparator::NotEqual;
       
   447     default: break;
       
   448     }
       
   449 
       
   450     return QMailDataComparator::Equal;
       
   451 }
       
   452 
       
   453 /*
       
   454 QMessageDataComparator::InclusionComparator convert(QMailDataComparator::InclusionComparator cmp)
       
   455 {
       
   456     switch (cmp)
       
   457     {
       
   458     case QMailDataComparator::Includes: return QMessageDataComparator::Includes;
       
   459     case QMailDataComparator::Excludes: return QMessageDataComparator::Excludes;
       
   460     default: break;
       
   461     }
       
   462     
       
   463     return QMessageDataComparator::Includes;
       
   464 }
       
   465 */
       
   466 
       
   467 QMailDataComparator::InclusionComparator convert(QMessageDataComparator::InclusionComparator cmp)
       
   468 {
       
   469     switch (cmp)
       
   470     {
       
   471     case QMessageDataComparator::Includes: return QMailDataComparator::Includes;
       
   472     case QMessageDataComparator::Excludes: return QMailDataComparator::Excludes;
       
   473     default: break;
       
   474     }
       
   475 
       
   476     return QMailDataComparator::Includes;
       
   477 }
       
   478 
       
   479 /*
       
   480 QMessageDataComparator::RelationComparator convert(QMailDataComparator::RelationComparator cmp)
       
   481 {
       
   482     switch (cmp)
       
   483     {
       
   484     case QMailDataComparator::LessThan: return QMessageDataComparator::LessThan;
       
   485     case QMailDataComparator::LessThanEqual: return QMessageDataComparator::LessThanEqual;
       
   486     case QMailDataComparator::GreaterThan: return QMessageDataComparator::GreaterThan;
       
   487     case QMailDataComparator::GreaterThanEqual: return QMessageDataComparator::GreaterThanEqual;
       
   488     default: break;
       
   489     }
       
   490     
       
   491     return QMessageDataComparator::LessThan;
       
   492 }
       
   493 */
       
   494 
       
   495 QMailDataComparator::RelationComparator convert(QMessageDataComparator::RelationComparator cmp)
       
   496 {
       
   497     switch (cmp)
       
   498     {
       
   499     case QMessageDataComparator::LessThan: return QMailDataComparator::LessThan;
       
   500     case QMessageDataComparator::LessThanEqual: return QMailDataComparator::LessThanEqual;
       
   501     case QMessageDataComparator::GreaterThan: return QMailDataComparator::GreaterThan;
       
   502     case QMessageDataComparator::GreaterThanEqual: return QMailDataComparator::GreaterThanEqual;
       
   503     default: break;
       
   504     }
       
   505 
       
   506     return QMailDataComparator::LessThan;
       
   507 }
       
   508 
       
   509 /* in qmessageaccountfilterkey_qmf.cpp
       
   510 QMessageAccountFilter convert(const QMailAccountKey &key);
       
   511 QMailAccountKey convert(const QMessageAccountFilter &filter);
       
   512 */
       
   513 
       
   514 /* in qmessagefolderfilterkey_qmf.cpp
       
   515 QMessageFolderFilter convert(const QMailFolderKey &key);
       
   516 QMailFolderKey convert(const QMessageFolderFilter &filter);
       
   517 */
       
   518 
       
   519 /* in qmessagefilterkey_qmf.cpp
       
   520 QMessageFilter convert(const QMailMessageKey &key);
       
   521 QMailMessageKey convert(const QMessageFilter &filter);
       
   522 */
       
   523 
       
   524 /* in qmessageaccountsortkey_qmf.cpp
       
   525 QMessageAccountSortOrder convert(const QMailAccountSortKey &key);
       
   526 QMailAccountSortKey convert(const QMessageAccountSortOrder &sortOrder);
       
   527 */
       
   528 
       
   529 /* in qmessagefoldersortkey_qmf.cpp
       
   530 QMessageFolderSortOrder convert(const QMailFolderSortKey &key);
       
   531 QMailFolderSortKey convert(const QMessageFolderSortOrder &sortOrder);
       
   532 */
       
   533 
       
   534 /* in qmessagesortkey_qmf.cpp
       
   535 QMessageSortOrder convert(const QMailMessageSortKey &key);
       
   536 QMailMessageSortKey convert(const QMessageSortOrder &sortOrder);
       
   537 */
       
   538 
       
   539 /* in qmessageaccount_qmf.cpp
       
   540 QMessageAccount convert(const QMailAccount &account);
       
   541 QMailAccount convert(const QMessageAccount &account);
       
   542 */
       
   543 
       
   544 /* in qmessagefolder_qmf.cpp
       
   545 QMessageFolder convert(const QMailFolder &folder);
       
   546 QMailFolder convert(const QMessageFolder &folder);
       
   547 */
       
   548 
       
   549 /* in qmessage_qmf.cpp
       
   550 QMessage convert(const QMailMessage &message);
       
   551 QMailMessage convert(const QMessage &message);
       
   552 QMailMessage* convert(QMessage *message);
       
   553 */
       
   554 
       
   555 /* in qmessagestore_qmf.cpp
       
   556 QMailStore *convert(QMessageStore *store);
       
   557 QMailStore *convert(QMessageManager &manager);
       
   558 */
       
   559 
       
   560 quint64 highPriorityMask()
       
   561 {
       
   562     static quint64 mask(messageStatusMask("QMessage::HighPriority"));
       
   563     return mask;
       
   564 }
       
   565 
       
   566 quint64 lowPriorityMask()
       
   567 {
       
   568     static quint64 mask(messageStatusMask("QMessage::LowPriority"));
       
   569     return mask;
       
   570 }
       
   571 
       
   572 }
       
   573 
       
   574 bool operator==(const QMailMessagePart::Location &lhs, const QMailMessagePart::Location &rhs)
       
   575 {
       
   576     return (lhs.toString(true) == rhs.toString(true));
       
   577 }
       
   578 
       
   579 
       
   580 QTM_END_NAMESPACE