1 /* |
1 /* |
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2009 - 2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include "emailtrace.h" |
18 #include "nmapiheaders.h" |
19 |
|
20 #include "nmapiengine.h" |
|
21 #include "nmapieventnotifier_p.h" |
|
22 |
|
23 #include <QTimer> |
|
24 |
19 |
25 namespace EmailClientApi |
20 namespace EmailClientApi |
26 { |
21 { |
|
22 const quint32 IntervalEmitingSignals = 10000; |
|
23 |
27 /*! |
24 /*! |
28 Constructor |
25 Constructor |
29 */ |
26 */ |
30 NmApiEventNotifierPrivate::NmApiEventNotifierPrivate(QObject *parent) : |
27 NmApiEventNotifierPrivate::NmApiEventNotifierPrivate(QObject *parent) : |
31 QObject(parent), mEmitSignals(NULL), mEngine(NULL), mIsRunning(false) |
28 QObject(parent), mEmitSignals(NULL), mEngine(NULL), mIsRunning(false) |
32 { |
29 { |
33 NM_FUNCTION; |
30 NM_FUNCTION; |
|
31 mEmitSignals = new QTimer(this); |
|
32 mEmitSignals->setInterval(IntervalEmitingSignals); |
|
33 connect(mEmitSignals, SIGNAL(timeout()), this, SIGNAL( |
|
34 timedOut())); |
|
35 mEngine = NmApiEngine::instance(); |
34 } |
36 } |
35 |
37 |
36 /*! |
38 /*! |
37 Destructor |
39 Destructor |
38 */ |
40 */ |
39 NmApiEventNotifierPrivate::~NmApiEventNotifierPrivate() |
41 NmApiEventNotifierPrivate::~NmApiEventNotifierPrivate() |
40 { |
42 { |
41 NM_FUNCTION; |
43 NM_FUNCTION; |
|
44 mEmitSignals->stop(); |
|
45 NmApiEngine::releaseInstance(mEngine); |
42 } |
46 } |
43 |
47 |
44 /*! |
48 /*! |
45 \brief It initialize engine for email operations. |
49 Returns true if the |
|
50 */ |
|
51 bool NmApiEventNotifierPrivate::isRunning() const |
|
52 { |
|
53 return mIsRunning; |
|
54 } |
|
55 |
|
56 /*! |
|
57 Start monitoring email events |
46 |
58 |
47 When use initializeEngine need to remember release it. |
59 \return Value tells about monitoring system running |
48 It return value if initialization go good. |
|
49 \sa releaseEngine |
|
50 \return Return true if engine works. |
|
51 */ |
60 */ |
52 bool NmApiEventNotifierPrivate::initializeEngine() |
61 bool NmApiEventNotifierPrivate::start() |
53 { |
62 { |
54 NM_FUNCTION; |
63 NM_FUNCTION; |
55 |
64 |
56 if (!mEngine) { |
65 bool result(false); |
57 mEngine = NmApiEngine::instance(); |
66 |
|
67 if (mIsRunning) { |
|
68 result = true; |
58 } |
69 } |
|
70 else { |
|
71 qRegisterMetaType<QList<quint64> > ("QList<quint64>"); |
|
72 qRegisterMetaType<NmApiMessage> ("NmApiMessage"); |
59 |
73 |
60 return mEngine ? true : false; |
74 connect(mEngine, SIGNAL(emailStoreEvent(NmApiMessage)), this, |
|
75 SLOT(emailStoreEvent(NmApiMessage))); |
|
76 |
|
77 mEngine->startCollectingEvents(); |
|
78 |
|
79 mEmitSignals->start(); |
|
80 mIsRunning = true; |
|
81 result = true; |
|
82 } |
|
83 return result; |
|
84 } |
|
85 /*! |
|
86 \brief Stop listening events. |
|
87 */ |
|
88 void NmApiEventNotifierPrivate::stop() |
|
89 { |
|
90 mIsRunning = false; |
|
91 mEmitSignals->stop(); |
|
92 disconnect(mEngine, SIGNAL(emailStoreEvent(NmApiMessage)), this, |
|
93 SLOT(emailStoreEvent(NmApiMessage))); |
61 } |
94 } |
62 |
95 |
63 /*! |
96 /*! |
64 \brief It release engine for email operations. |
97 Returns event buffer, after function call the buffer is empty |
65 |
|
66 \sa initializeEngine |
|
67 */ |
98 */ |
68 void NmApiEventNotifierPrivate::releaseEngine() |
99 void NmApiEventNotifierPrivate::events(QList<NmApiMessage> &events) |
69 { |
100 { |
70 NM_FUNCTION; |
101 while (!mBufferOfEvents.isEmpty()) { |
71 |
102 events << mBufferOfEvents.takeFirst(); |
72 if (mIsRunning) { |
|
73 cancel(); |
|
74 } |
|
75 else { |
|
76 NmApiEngine::releaseInstance(mEngine); |
|
77 } |
103 } |
78 } |
104 } |
79 |
105 |
80 /*! |
106 /*! |
81 Add one email event into buffer. |
107 Add one email event into buffer. |