src/messaging/qmessagestore_qmf_p.h
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 
       
    42 #include <qmobilityglobal.h>
       
    43 #include <qmailstore.h>
       
    44 #include "qmfhelpers_p.h"
       
    45 #include "qmessagestore.h"
       
    46 
       
    47 QTM_BEGIN_NAMESPACE
       
    48 
       
    49 class QMessageStorePrivate : public QObject
       
    50 {
       
    51     Q_OBJECT
       
    52 
       
    53 public:
       
    54     QMessageStorePrivate() 
       
    55         : QObject(), 
       
    56           _store(QMailStore::instance()), 
       
    57           _error(QMessageManager::NoError), 
       
    58           _notify(true),
       
    59           _filterId(0)
       
    60     {
       
    61     }
       
    62 
       
    63     QMailStore *_store;
       
    64     QMessageManager::Error _error;
       
    65     bool _notify;
       
    66     QMessageManager::NotificationFilterId _filterId;
       
    67     QMap<QMessageManager::NotificationFilterId, QMailMessageKey> _filters;
       
    68 
       
    69     static QMailStore *convert(QMessageStore *store);
       
    70     static QMailStore *convert(QMessageManager &manager);
       
    71 
       
    72     Q_SCOPED_STATIC_DECLARE(QMessageStore,storeInstance);
       
    73 
       
    74     static void registerMessageStatus(QMailStore *store, const QString &field);
       
    75     static void createNonexistentFolder(QMailStore *store, const QString &path, quint64 status);
       
    76     
       
    77 public slots:
       
    78     void messagesAdded(const QMailMessageIdList &ids);
       
    79     void messagesRemoved(const QMailMessageIdList &ids);
       
    80     void messagesUpdated(const QMailMessageIdList &ids);
       
    81 
       
    82 signals:
       
    83     void messageAdded(const QMessageId &id, const QMessageManager::NotificationFilterIdSet &matchingFilterIds);
       
    84     void messageRemoved(const QMessageId &id, const QMessageManager::NotificationFilterIdSet &matchingFilterIds);
       
    85     void messageUpdated(const QMessageId &id, const QMessageManager::NotificationFilterIdSet &matchingFilterIds);
       
    86 
       
    87 private:
       
    88     void processFilters(const QMailMessageIdList &ids, void (QMessageStorePrivate::*signal)(const QMessageId &, const QMessageManager::NotificationFilterIdSet &))
       
    89     {
       
    90         QMap<QMailMessageId, QMessageManager::NotificationFilterIdSet> matches;
       
    91 
       
    92         // Copy the filter map to protect against modification during traversal
       
    93         QMap<QMessageManager::NotificationFilterId, QMailMessageKey> filters(_filters);
       
    94         QMap<QMessageManager::NotificationFilterId, QMailMessageKey>::const_iterator it = filters.begin(), end = filters.end();
       
    95         for ( ; it != end; ++it) {
       
    96             const QMailMessageKey &key(it.value());
       
    97 
       
    98             QSet<QMailMessageId> filteredIds;
       
    99             if (!key.isEmpty()) {
       
   100                 // Empty key matches all messages; otherwise get the filtered set
       
   101                 filteredIds = QMailStore::instance()->queryMessages(key).toSet();
       
   102             }
       
   103 
       
   104             foreach (const QMailMessageId &id, ids) {
       
   105                 if (key.isEmpty() || filteredIds.contains(id)) {
       
   106                     matches[id].insert(it.key());
       
   107                 }
       
   108             }
       
   109         }
       
   110 
       
   111         QMap<QMailMessageId, QMessageManager::NotificationFilterIdSet>::const_iterator mit = matches.begin(), mend = matches.end();
       
   112         for ( ; mit != mend; ++mit) {
       
   113             emit (this->*signal)(QmfHelpers::convert(mit.key()), mit.value());
       
   114         }
       
   115     }
       
   116 };
       
   117 
       
   118 QTM_END_NAMESPACE
       
   119 
       
   120