19 |
19 |
20 |
20 |
21 |
21 |
22 namespace EmailClientApi |
22 namespace EmailClientApi |
23 { |
23 { |
24 NmApiEnvelopeListingPrivate::NmApiEnvelopeListingPrivate(QObject *parent) : |
24 NmApiEnvelopeListingPrivate::NmApiEnvelopeListingPrivate(const quint64 folderId, const quint64 mailboxId, QObject *parent) |
25 QObject(parent), mEngine(NULL) |
25 :QObject(parent), |
|
26 mFolderId(folderId), |
|
27 mMailboxId(mailboxId), |
|
28 mIsRunning(false), |
|
29 mEngine(NULL) |
26 { |
30 { |
27 NM_FUNCTION; |
31 NM_FUNCTION; |
|
32 mEngine = NmApiEngine::instance(); |
|
33 Q_CHECK_PTR(mEngine); |
28 } |
34 } |
29 |
35 |
30 NmApiEnvelopeListingPrivate::~NmApiEnvelopeListingPrivate() |
36 NmApiEnvelopeListingPrivate::~NmApiEnvelopeListingPrivate() |
31 { |
37 { |
32 NM_FUNCTION; |
38 NM_FUNCTION; |
33 |
39 NmApiEngine::releaseInstance(mEngine); |
34 releaseEngine(); |
40 } |
|
41 |
|
42 /*! |
|
43 \brief Fills envelopes to the input parameter. |
|
44 |
|
45 Caller gets ownership of envelopes. Returns true if results were available. |
|
46 */ |
|
47 bool NmApiEnvelopeListingPrivate::envelopes(QList<EmailClientApi::NmApiMessageEnvelope> &envelopes) |
|
48 { |
|
49 NM_FUNCTION; |
|
50 bool ret(mIsRunning); |
|
51 envelopes.clear(); |
|
52 while (!mEnvelopes.isEmpty()) { |
|
53 envelopes << mEnvelopes.takeFirst(); |
|
54 } |
|
55 mIsRunning = false; |
|
56 return ret; |
35 } |
57 } |
36 |
58 |
37 /*! |
59 /*! |
38 \brief It initialize engine for email operations. |
60 \brief It fetches envelopes from engine. |
39 |
61 |
40 When use initializeEngine need to remember release it. |
62 Because it uses NmApiMessageEnvelope with sharedData we don't need care about release memory. |
41 It return value if initialization go good. |
63 |
42 \sa releaseEngine |
64 \return Count of envelopes |
43 */ |
65 */ |
44 bool NmApiEnvelopeListingPrivate::initializeEngine() |
66 qint32 NmApiEnvelopeListingPrivate::listEnvelopes() |
45 { |
67 { |
46 NM_FUNCTION; |
68 NM_FUNCTION; |
47 |
69 mIsRunning = true; |
48 mEngine = NmApiEngine::instance(); |
70 mEnvelopes.clear(); |
49 return mEngine ? true : false; |
71 mEngine->listEnvelopes(mMailboxId, mFolderId, mEnvelopes); |
|
72 return mEnvelopes.count(); |
50 } |
73 } |
51 |
|
52 /*! |
74 /*! |
53 \brief It release engine for email operations. |
75 \brief Return info if listing is running |
54 |
|
55 \sa initializeEngine |
|
56 */ |
76 */ |
57 void NmApiEnvelopeListingPrivate::releaseEngine() |
77 bool NmApiEnvelopeListingPrivate::isRunning() const |
58 { |
78 { |
59 NM_FUNCTION; |
79 return mIsRunning; |
60 |
|
61 NmApiEngine::releaseInstance(mEngine); |
|
62 } |
80 } |
63 |
|
64 /*! |
81 /*! |
65 \brief It grab envelopes from engine. |
82 \brief Clears list of envelopes. |
66 |
|
67 When it start grabing, it release all old. |
|
68 Because it uses NmApiMessageEnvelope with sharedData we don't need care about release memory. |
|
69 |
|
70 \return Count of envelopes or "-1" if there is no engine initialised |
|
71 */ |
83 */ |
72 qint32 NmApiEnvelopeListingPrivate::grabEnvelopes() |
84 void NmApiEnvelopeListingPrivate::cancel() |
73 { |
85 { |
74 NM_FUNCTION; |
86 mIsRunning = false; |
75 |
|
76 if(!mEngine){ |
|
77 return -1; |
|
78 } |
|
79 |
|
80 mEnvelopes.clear(); |
87 mEnvelopes.clear(); |
81 mEngine->listEnvelopes(mailboxId, folderId, mEnvelopes); |
|
82 return mEnvelopes.count(); |
|
83 } |
88 } |
84 } |
89 } |
85 |
90 |