email_plat/nmail_client_api/nmapieventnotifier.h
changeset 18 578830873419
child 23 2dc6caa42ec3
equal deleted inserted replaced
4:e7aa27f58ae1 18:578830873419
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:
       
    15  *
       
    16  */
       
    17 
       
    18 #ifndef NMAPIEVENTNOTIFIER_H
       
    19 #define NMAPIEVENTNOTIFIER_H
       
    20 
       
    21 #include <QtCore>
       
    22 #include "nmapimessagetask.h"
       
    23 #include "nmenginedef.h"
       
    24 #include "nmcommon_api.h"
       
    25 
       
    26 struct NmApiMessage;
       
    27 
       
    28 namespace EmailClientApi
       
    29 {
       
    30 class NmEventNotifierPrivate;
       
    31 
       
    32 /*
       
    33  * Notifier for mailbox and message events
       
    34  * 
       
    35  * Example of use:
       
    36  * NmEventNotifier *notifier = new NmEventNotifier(this);
       
    37  * notifier->start();
       
    38  * connect(notifier,SIGNAL(messageEvent(MessageEvent,quint64,quint64,QList<quint64>)),this,
       
    39  *                  SLOT(processMessage(MessageEvent,quint64,quint64,QList<quint64>)),Qt::QueuedConnection);
       
    40  * 
       
    41  * And then when want to end need to do:
       
    42  * notifier->cancel();
       
    43  * delete notifier; // or notifier->deleteLater();
       
    44  */
       
    45 class NMENGINE_EXPORT NmEventNotifier : public NmMessageTask
       
    46 {
       
    47     Q_OBJECT
       
    48 public:
       
    49     /*!
       
    50      * Constructor
       
    51      */
       
    52     NmEventNotifier(QObject *parent);
       
    53 
       
    54     /*!
       
    55      * Destructor
       
    56      */
       
    57     virtual ~NmEventNotifier();
       
    58 
       
    59     /*!
       
    60      * Start monitoring email events
       
    61      * 
       
    62      * Return value tells about monitoring system running
       
    63      */
       
    64     virtual bool start();
       
    65 
       
    66     /*!
       
    67      * Cancels monitoring.
       
    68      * 
       
    69      * In user responsibility is to cancel monitoring.
       
    70      * On end it clear buffer events and emits \sa NmMessageTask::canceled() signal.
       
    71      */
       
    72     virtual void cancel();
       
    73 
       
    74     /*!
       
    75      * It check if if event notifier is running.
       
    76      */
       
    77     bool isRunning() const;
       
    78 
       
    79     signals:
       
    80     /*!
       
    81      * This signal is emited when buffer of maiblox events is ready to send. Buffer is list of mailbox events with id.
       
    82      * 
       
    83      * 
       
    84      * It emits signals grouped by events. So there will be as much signals as much there are events.
       
    85      * For safety when connect it need to use \sa Qt::QueuedConnection.
       
    86      * After that use \sa EmailClientApi::NmEmailService::getMailbox to get object.
       
    87      * \arg Event of mailbox
       
    88      * \arg List of mailbox ids where event occur.
       
    89      */
       
    90     void mailboxEvent(MailboxEvent event,QList<quint64> id);
       
    91 
       
    92     /*!
       
    93      * This signal is emited when buffer of messages events is ready to send. Buffer is list of messages events with id.
       
    94      *
       
    95      * It emits signals grouped by events, mailbox and folder. So there will be as much signals as much there are events.
       
    96      * For safety when connect it need to use \sa Qt::QueuedConnection.
       
    97      * After that use \sa EmailClientApi::NmEmailService::getEnvelope to get object.
       
    98      * 
       
    99      * \arg Event of messages
       
   100      * \arg Message mailbox
       
   101      * \arg Message folder
       
   102      * \arg List of messages ids where event occur
       
   103      */
       
   104     void messageEvent(MessageEvent event,quint64 mailboxId,quint64 folderId,QList<quint64> envelopeIdList);
       
   105 
       
   106 public slots:
       
   107     /*!
       
   108      * It check each object in buffer and emit signal with it.
       
   109      * 
       
   110      * After end of work of this function buffer is empty.
       
   111      * It is called by timeout signal from timer.
       
   112      */
       
   113     void sendEventsFromBuffer();
       
   114 
       
   115 private:
       
   116     NmEventNotifierPrivate *mNmEventNotifierPrivate;
       
   117 };
       
   118 
       
   119 }
       
   120 
       
   121 Q_DECLARE_METATYPE(QList<quint64>)
       
   122 
       
   123 #endif