12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
|
17 |
|
18 #include <nmapimailboxlisting.h> |
|
19 |
|
20 #include <QObject> |
|
21 |
|
22 #include <nmapimailbox.h> |
17 #include "nmapiengine.h" |
23 #include "nmapiengine.h" |
18 #include "nmapimailboxlisting_p.h" |
24 #include "nmapimailboxlisting_p.h" |
19 #include "nmapimailboxlisting.h" |
25 |
20 |
26 |
21 namespace EmailClientApi |
27 namespace EmailClientApi |
22 { |
28 { |
23 |
29 |
24 /*! |
30 /*! |
25 * \class Class for creating list of all mailboxes |
31 \class Class for creating list of all mailboxes |
26 */ |
32 */ |
27 |
33 |
28 /*! |
34 /*! |
29 * Constructor of class. It set start values. |
35 Constructor of class. It set start values. |
30 */ |
36 */ |
31 NmMailboxListing::NmMailboxListing(QObject *parent) : |
37 NmApiMailboxListing::NmApiMailboxListing(QObject *parent) : |
32 NmMessageTask(parent) |
38 NmApiMessageTask(parent) |
33 { |
39 { |
34 mNmMailboxListingPrivate = new NmMailboxListingPrivate(this); |
40 mNmApiMailboxListingPrivate = new NmApiMailboxListingPrivate(this); |
35 mNmMailboxListingPrivate->mIsRunning = false; |
41 mNmApiMailboxListingPrivate->mIsRunning = false; |
36 } |
42 } |
37 |
43 |
38 /*! |
44 /*! |
39 * Destructor of class. It release engine to be safe if manual releasing won't work. |
45 Destructor of class. It release engine to be safe if manual releasing won't work. |
40 */ |
46 */ |
41 NmMailboxListing::~NmMailboxListing() |
47 NmApiMailboxListing::~NmApiMailboxListing() |
42 { |
48 { |
43 if (mNmMailboxListingPrivate->mIsRunning) { |
49 if (mNmApiMailboxListingPrivate->mIsRunning) { |
44 mNmMailboxListingPrivate->releaseEngine(); |
50 mNmApiMailboxListingPrivate->releaseEngine(); |
45 } |
51 } |
46 delete mNmMailboxListingPrivate; |
|
47 } |
52 } |
48 |
53 |
49 /*! |
54 /*! |
50 * \brief Returns results after mailboxesListed signal is received. |
55 \brief Returns results after mailboxesListed signal is received. |
51 * |
56 |
52 * Caller gets ownership of messages. Returns true if results were available. |
57 Caller gets ownership of messages. Returns true if results were available. |
53 * It clears list of mailboxes (in private members) after be called. |
58 It clears list of mailboxes (in private members) after be called. |
54 * It also at start clear inputlist of NmMailbox. |
59 It also at start clear inputlist of NmApiMailbox. |
55 * |
60 |
56 * \return Return true if results were avaible |
61 \return Return true if results were avaible |
57 * \arg List of mailboxes to filled. On start is cleared. |
62 \param mailboxes List of mailboxes to filled. On start is cleared. |
58 */ |
63 */ |
59 bool NmMailboxListing::getMailboxes(QList<EmailClientApi::NmMailbox> &mailboxes) |
64 bool NmApiMailboxListing::getMailboxes(QList<EmailClientApi::NmApiMailbox> &mailboxes) |
60 { |
65 { |
61 mailboxes.clear(); |
66 mailboxes.clear(); |
62 |
67 |
63 bool result = false; |
68 bool result = false; |
64 |
69 |
65 if (!mNmMailboxListingPrivate->mIsRunning) { |
70 if (!mNmApiMailboxListingPrivate->mIsRunning) { |
66 result = false; |
71 result = false; |
67 } |
72 } |
68 else |
73 else |
69 if (mNmMailboxListingPrivate->mMailboxes.isEmpty()) { |
74 if (mNmApiMailboxListingPrivate->mMailboxes.isEmpty()) { |
70 result = false; |
75 result = false; |
71 } |
76 } |
72 else { |
77 else { |
73 mailboxes = mNmMailboxListingPrivate->mMailboxes; |
78 mailboxes = mNmApiMailboxListingPrivate->mMailboxes; |
74 |
79 |
75 mNmMailboxListingPrivate->mMailboxes.clear(); |
80 mNmApiMailboxListingPrivate->mMailboxes.clear(); |
76 |
81 |
77 result = true; |
82 result = true; |
78 } |
83 } |
79 return result; |
84 return result; |
80 } |
85 } |
81 |
86 |
82 /*! |
87 /*! |
83 * \brief Starts gathering mailbox list. |
88 \brief Starts gathering mailbox list. |
84 * |
89 |
85 * In first turn it will get whole mailboxlist. |
90 In first turn it will get whole mailboxlist. |
86 * Then it initialize core arguments and emits signal when ready. |
91 Then it initialize core arguments and emits signal when ready. |
87 * |
92 |
88 * To asynchronous operation can be used \sa QTimer::singleShot on this method. |
93 To asynchronous operation can be used \sa QTimer::singleShot on this method. |
89 * Example: |
94 Example: |
90 * <code> |
95 <code> |
91 * QTimer::singleShot(0,nmMailboxListing,SLOT(start()); |
96 QTimer::singleShot(0,nmMailboxListing,SLOT(start()); |
92 * </code> |
97 </code> |
93 * |
98 |
94 * \return Return true if everything go good and core of listing works good. |
99 \return Return true if everything go good and core of listing works good. |
95 * |
100 |
96 */ |
101 */ |
97 bool NmMailboxListing::start() |
102 bool NmApiMailboxListing::start() |
98 { |
103 { |
99 bool result = false; |
104 bool result = false; |
100 if (mNmMailboxListingPrivate->mIsRunning) { |
105 if (mNmApiMailboxListingPrivate->mIsRunning) { |
101 result = true; |
106 result = true; |
102 } |
107 } |
103 else |
108 else |
104 if (!mNmMailboxListingPrivate->initializeEngine()) { |
109 if (!mNmApiMailboxListingPrivate->initializeEngine()) { |
105 QMetaObject::invokeMethod(this, "mailboxesListed", Qt::QueuedConnection, Q_ARG(qint32, |
110 QMetaObject::invokeMethod(this, "mailboxesListed", Qt::QueuedConnection, Q_ARG(qint32, |
106 (qint32) MailboxListingFailed)); |
111 (qint32) MailboxListingFailed)); |
107 result = false; |
112 result = false; |
108 } |
113 } |
109 else { |
114 else { |
110 quint64 mailboxCount = mNmMailboxListingPrivate->grabMailboxes(); |
115 qint32 mailboxCount = mNmApiMailboxListingPrivate->grabMailboxes(); |
111 |
116 |
112 mNmMailboxListingPrivate->mIsRunning = true; |
117 mNmApiMailboxListingPrivate->mIsRunning = true; |
113 |
118 |
114 QMetaObject::invokeMethod(this, "mailboxesListed", Qt::QueuedConnection, Q_ARG(qint32, |
119 QMetaObject::invokeMethod(this, "mailboxesListed", Qt::QueuedConnection, Q_ARG(qint32, |
115 mailboxCount)); |
120 mailboxCount)); |
116 |
121 |
117 result = true; |
122 result = true; |
118 } |
123 } |
119 return result; |
124 return result; |
120 } |
125 } |
121 |
126 |
122 /*! |
127 /*! |
123 * \brief Stop gathering mailbox list. |
128 \brief Stop gathering mailbox list. |
124 * |
129 |
125 * In first it change state of listing. |
130 In first it change state of listing. |
126 * Then it release engine. |
131 Then it release engine. |
127 * On end it clears list of mailboxes and emits \sa NmMessageTask::canceled() signal. |
132 On end it clears list of mailboxes and emits \sa NmApiMessageTask::canceled() signal. |
128 */ |
133 */ |
129 void NmMailboxListing::cancel() |
134 void NmApiMailboxListing::cancel() |
130 { |
135 { |
131 if (mNmMailboxListingPrivate->mIsRunning) { |
136 if (mNmApiMailboxListingPrivate->mIsRunning) { |
132 |
137 |
133 mNmMailboxListingPrivate->mIsRunning = false; |
138 mNmApiMailboxListingPrivate->mIsRunning = false; |
134 mNmMailboxListingPrivate->releaseEngine(); |
139 mNmApiMailboxListingPrivate->releaseEngine(); |
135 mNmMailboxListingPrivate->mMailboxes.clear(); |
140 mNmApiMailboxListingPrivate->mMailboxes.clear(); |
136 |
141 |
137 QMetaObject::invokeMethod(this, "canceled", Qt::QueuedConnection); |
142 QMetaObject::invokeMethod(this, "canceled", Qt::QueuedConnection); |
138 } |
143 } |
139 } |
144 } |
140 |
145 |
141 /*! |
146 /*! |
142 * \brief Return info if listing is running |
147 \brief Return info if listing is running |
143 * |
148 |
144 * \return Return true if listing is running |
149 \return Return true if listing is running |
145 */ |
150 */ |
146 bool NmMailboxListing::isRunning() const |
151 bool NmApiMailboxListing::isRunning() const |
147 { |
152 { |
148 return mNmMailboxListingPrivate->mIsRunning; |
153 return mNmApiMailboxListingPrivate->mIsRunning; |
149 } |
154 } |
150 |
155 |
151 } |
156 } |
152 |
157 |
153 #include "moc_nmapimailboxlisting.cpp" |
158 #include "moc_nmapimailboxlisting.cpp" |