emailservices/nmailagent/inc/nmmailagent.h
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 14 May 2010 15:41:10 +0300
changeset 23 2dc6caa42ec3
parent 20 ecc8def7944a
child 27 9ba4404ef423
permissions -rw-r--r--
Revision: 201017 Kit: 201019

/*
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:
*
*/

#ifndef NMMAILAGENT_H
#define NMMAILAGENT_H

#include <nmcommon.h>

class NmMailbox;
class NmDataPluginFactory;
class NmDataPluginInterface;

class NmMailboxInfo
{
public:
    NmId mId;
    int mIndicatorIndex;
    QString mName;
    QString mIconName;
    NmId mInboxFolderId;
    NmId mOutboxFolderId;
    NmSyncState mSyncState;
    NmConnectState mConnectState;
    int mInboxCreatedMessages;
    int mInboxChangedMessages;
    int mInboxDeletedMessages;
    QList<NmId> mUnreadMailIdList;
    int mOutboxMails;
    bool mActive;

    NmMailboxInfo();
};

class NmMailAgent : public QObject
{
    Q_OBJECT

public:

    NmMailAgent();

    ~NmMailAgent();

    bool init();

public slots:

    void handleMailboxEvent(NmMailboxEvent event,
            const QList<NmId> &mailboxIds);

    void handleMessageEvent(
            NmMessageEvent event,
            const NmId &folderId,
            const QList<NmId> &messageIds,
            const NmId& mailboxId);

    void handleSyncStateEvent(
            NmSyncState state,
            const NmOperationCompletionEvent &event);

    void handleConnectionEvent(NmConnectState state, const NmId mailboxId);

    void delayedStart();
    
    void enableAlertTone();

private:

    void initMailboxStatus();

    bool updateUnreadCount(const NmId &mailboxId, NmMailboxInfo &mailboxInfo);

    int getOutboxCount(const NmId& mailboxId);

    int getIndicatorIndex();

    bool updateIndicator(bool active,
        const NmMailboxInfo& mailboxInfo);

    NmMailboxInfo* getMailboxInfo(const NmId &id);

    NmMailboxInfo* createMailboxInfo(const NmId &id);

    NmMailboxInfo* createMailboxInfo(const NmMailbox &mailbox,
        NmDataPluginInterface *plugin);

    bool removeMailboxInfo(const NmId &id);

    bool updateMailboxState(const NmId &mailboxId,
        bool active, bool refreshAlways);

    static QStringList pluginFolders();
    
    bool getMessageUnreadInfo(const NmId &folderId, 
        const NmId &messageId, const NmId &mailboxId, bool &unreadMessage);
    
    void playAlertTone();
    
private: // data

    NmDataPluginFactory *mPluginFactory;
    QList<NmMailboxInfo*> mMailboxes;
    bool mSendingState;
    bool mAlertToneAllowed;
};


#endif // NMMAILAGENT_H