25 #include <QCoreApplication> |
25 #include <QCoreApplication> |
26 |
26 |
27 #include <HbStringUtil> |
27 #include <HbStringUtil> |
28 |
28 |
29 const int NmMailboxInfoItemCount = 8; |
29 const int NmMailboxInfoItemCount = 8; |
30 const int NmSendingStateDelay = 2000; // delay for 'send in progress' indicator |
|
31 const int NmMaxOutboxCount = 99; |
30 const int NmMaxOutboxCount = 99; |
|
31 const int NmActivationDelay = 100; // 0.1s |
32 |
32 |
33 /*! |
33 /*! |
34 \class NmMailboxInfo |
34 \class NmMailboxInfo |
35 \brief Stores info that indicator displays |
35 \brief Stores info that indicator displays |
36 */ |
36 */ |
59 NmIndicator::NmIndicator(const QString &indicatorType) |
60 NmIndicator::NmIndicator(const QString &indicatorType) |
60 :HbIndicatorInterface(indicatorType, |
61 :HbIndicatorInterface(indicatorType, |
61 HbIndicatorInterface::NotificationCategory, |
62 HbIndicatorInterface::NotificationCategory, |
62 InteractionActivated) |
63 InteractionActivated) |
63 { |
64 { |
64 NMLOG("NmIndicator::NmIndicator"); |
65 NM_FUNCTION; |
65 mShowIndicator = false; |
|
66 mSendingState = false; |
|
67 mShowSendProgress = false; |
|
68 mActive = false; |
66 mActive = false; |
69 } |
67 } |
70 |
68 |
71 /*! |
69 /*! |
72 Class destructor. |
70 Class destructor. |
73 */ |
71 */ |
74 NmIndicator::~NmIndicator() |
72 NmIndicator::~NmIndicator() |
75 { |
73 { |
76 NMLOG("NmIndicator::~NmIndicator"); |
74 NM_FUNCTION; |
77 } |
75 } |
78 |
76 |
79 /*! |
77 /*! |
80 called by the framework, when the user interacts with the indicator. |
78 called by the framework, when the user interacts with the indicator. |
81 \a type is a type of the interaction. |
79 \a type is a type of the interaction. |
88 |
86 |
89 \sa interactionTypes |
87 \sa interactionTypes |
90 */ |
88 */ |
91 bool NmIndicator::handleInteraction(InteractionType type) |
89 bool NmIndicator::handleInteraction(InteractionType type) |
92 { |
90 { |
93 NMLOG("NmIndicator::handleInteraction"); |
91 NM_FUNCTION; |
|
92 |
94 bool handled = false; |
93 bool handled = false; |
95 if (type == InteractionActivated) { |
94 if (type == InteractionActivated) { |
96 mActive = false; |
95 mActive = false; |
97 handled = true; |
96 handled = true; |
98 |
97 |
99 // This indicator is responsible showing the status bar icon |
98 QVariantMap data; |
100 if (mShowIndicator) { |
99 emit userActivated(data); |
101 // Do not show any indicators anymore |
100 |
102 mShowIndicator = false; |
101 // The action will be delayed to improve the usability |
103 emit dataChanged(); |
102 QTimer::singleShot(NmActivationDelay, this, SLOT(delayedAction())); |
104 |
|
105 // Notify that the icon will be lost now |
|
106 emit indicatorIconLost(); |
|
107 } |
|
108 emit mailboxLaunched(mMailbox.mId.id()); |
|
109 emit deactivate(); |
|
110 } |
103 } |
111 return handled; |
104 return handled; |
|
105 } |
|
106 |
|
107 /*! |
|
108 Deactivate the indicator |
|
109 */ |
|
110 void NmIndicator::delayedAction() |
|
111 { |
|
112 emit deactivate(); |
112 } |
113 } |
113 |
114 |
114 /*! |
115 /*! |
115 \fn QVariant HbIndicatorInterface::indicatorData(int role) const = 0 |
116 \fn QVariant HbIndicatorInterface::indicatorData(int role) const = 0 |
116 |
117 |
125 |
126 |
126 For the roles not supported by the plugin, empty QVariant should be returned. |
127 For the roles not supported by the plugin, empty QVariant should be returned. |
127 */ |
128 */ |
128 QVariant NmIndicator::indicatorData(int role) const |
129 QVariant NmIndicator::indicatorData(int role) const |
129 { |
130 { |
130 NMLOG(QString("NmIndicator::indicatorData %1").arg(role)); |
131 NM_FUNCTION; |
|
132 |
131 switch(role) { |
133 switch(role) { |
132 case PrimaryTextRole: |
134 case PrimaryTextRole: |
133 { |
135 if (mActive) { |
134 return mMailbox.mName; |
136 return mMailbox.mName; |
135 } |
137 } |
|
138 break; |
136 case SecondaryTextRole: |
139 case SecondaryTextRole: |
137 { |
140 if (mActive) { |
138 if (mMailbox.mOutboxMails>0) { |
141 if (mMailbox.mOutboxMails>0) { |
139 int outboxCount = mMailbox.mOutboxMails; |
142 int outboxCount = mMailbox.mOutboxMails; |
140 if (outboxCount>NmMaxOutboxCount) { |
143 if (outboxCount>NmMaxOutboxCount) { |
141 outboxCount = NmMaxOutboxCount; |
144 outboxCount = NmMaxOutboxCount; |
142 } |
145 } |
143 QString text = QString(hbTrId("txt_mail_status_menu_waiting_to_send")). |
146 QString text = QString(hbTrId("txt_mail_status_menu_waiting_to_send")). |
144 arg(HbStringUtil::convertDigits(QString::number(outboxCount))); |
147 arg(HbStringUtil::convertDigits(QString::number(outboxCount))); |
145 return text; |
148 return text; |
146 } |
149 } |
147 else if (mMailbox.mUnreadMails>0) { |
150 else if (mMailbox.mUnreadMails>0) { |
148 return hbTrId("txt_mail_status_menu_new_mail"); |
151 return hbTrId("txt_mail_status_menu_new_mail"); |
149 } |
152 } |
150 break; |
153 } |
151 } |
154 break; |
152 case DecorationNameRole: |
155 case DecorationNameRole: |
153 { |
156 { |
154 // Icon for the mailbox in the menu |
157 // Icon for the mailbox in the menu |
155 if (mActive) { |
158 if (mActive) { |
156 if (!mMailbox.mMailboxIconName.isEmpty()) { |
159 if (!mMailbox.mMailboxIconName.isEmpty()) { |
160 return QString("qtg_large_email"); |
163 return QString("qtg_large_email"); |
161 } |
164 } |
162 } |
165 } |
163 break; |
166 break; |
164 } |
167 } |
165 case MonoDecorationNameRole: |
|
166 if (mShowIndicator) { |
|
167 return QString("qtg_status_new_email"); |
|
168 } |
|
169 break; |
|
170 default: |
168 default: |
171 break; |
169 break; |
172 } |
170 } |
173 return QVariant(); |
171 return QVariant(); |
174 } |
|
175 |
|
176 /*! |
|
177 Timer callback for hiding 'send in progress' indicator |
|
178 */ |
|
179 void NmIndicator::hideSendIndicator() |
|
180 { |
|
181 if (mShowSendProgress) { |
|
182 NMLOG("NmIndicator::hideSendIndicator - hide progress state"); |
|
183 mShowSendProgress = false; |
|
184 emit dataChanged(); |
|
185 } |
|
186 } |
|
187 |
|
188 /*! |
|
189 Checks if any mailbox is in sending state at the moment |
|
190 \return true if any mailbox is in sending state |
|
191 */ |
|
192 bool NmIndicator::isSending() const |
|
193 { |
|
194 return mSendingState; |
|
195 } |
|
196 |
|
197 /*! |
|
198 Return type of the indicator |
|
199 \sa HbIndicatorInterface |
|
200 */ |
|
201 HbIndicatorInterface::Category NmIndicator::category() const |
|
202 { |
|
203 NMLOG("NmIndicatorPlugin::Category"); |
|
204 if (mMailbox.mOutboxMails>0 && mShowSendProgress) { |
|
205 return HbIndicatorInterface::ProgressCategory; |
|
206 } |
|
207 return HbIndicatorInterface::NotificationCategory; |
|
208 } |
172 } |
209 |
173 |
210 /*! |
174 /*! |
211 Handles the requests sent from the client |
175 Handles the requests sent from the client |
212 \a type is a type of the request. |
176 \a type is a type of the request. |
237 mActive = false; |
202 mActive = false; |
238 |
203 |
239 // also the deactivation may give updated data |
204 // also the deactivation may give updated data |
240 storeMailboxData(parameter); |
205 storeMailboxData(parameter); |
241 |
206 |
242 // This indicator was responsible showing the status bar icon |
|
243 if (mShowIndicator) { |
|
244 // Notify that the icon will be lost now |
|
245 emit indicatorIconLost(); |
|
246 } |
|
247 |
|
248 emit deactivate(); |
207 emit deactivate(); |
249 } |
208 } |
250 break; |
209 break; |
251 default: |
210 default: |
252 break; |
211 break; |
253 } |
212 } |
254 return handled; |
213 return handled; |
255 } |
|
256 |
|
257 /*! |
|
258 Start showing the 'send in progress' indicator |
|
259 */ |
|
260 void NmIndicator::showSendProgress() |
|
261 { |
|
262 // Activate the progress indicator |
|
263 if (!mShowSendProgress && mActive) { |
|
264 mShowSendProgress = true; |
|
265 |
|
266 // Hide the progress state after some delay |
|
267 QTimer::singleShot(NmSendingStateDelay, this, SLOT(hideSendIndicator())); |
|
268 } |
|
269 } |
214 } |
270 |
215 |
271 /*! |
216 /*! |
272 Stores mailbox data to member variable mMailbox. |
217 Stores mailbox data to member variable mMailbox. |
273 */ |
218 */ |
274 void NmIndicator::storeMailboxData(QVariant mailboxData) |
219 void NmIndicator::storeMailboxData(QVariant mailboxData) |
275 { |
220 { |
276 NMLOG("NmIndicator::storeMailboxData"); |
221 NM_FUNCTION; |
|
222 |
277 QList<QVariant> infoList = mailboxData.toList(); |
223 QList<QVariant> infoList = mailboxData.toList(); |
278 |
224 |
279 if (infoList.count() >= NmMailboxInfoItemCount) { |
225 if (infoList.count() >= NmMailboxInfoItemCount) { |
280 mMailbox.mId.setId(infoList.at(0).value<quint64>()); |
226 mMailbox.mId.setId(infoList.at(0).value<quint64>()); |
281 mMailbox.mName = infoList.at(1).toString(); |
227 mMailbox.mName = infoList.at(1).toString(); |
282 mMailbox.mUnreadMails = infoList.at(2).toInt(); |
228 mMailbox.mUnreadMails = infoList.at(2).toInt(); |
283 mMailbox.mSyncState = infoList.at(3).value<NmSyncState>(); |
229 mMailbox.mSyncState = infoList.at(3).value<NmSyncState>(); |
284 mMailbox.mConnectState = infoList.at(4).value<NmConnectState>(); |
230 mMailbox.mConnectState = infoList.at(4).value<NmConnectState>(); |
285 mMailbox.mOutboxMails = infoList.at(5).toInt(); |
231 mMailbox.mOutboxMails = infoList.at(5).toInt(); |
286 mMailbox.mMailboxIconName = infoList.at(6).toString(); |
232 mMailbox.mMailboxIconName = infoList.at(6).toString(); |
287 |
233 bool sendingState = infoList.at(7).toInt(); |
288 bool oldSendingState = mSendingState; |
234 } |
289 mSendingState = infoList.at(7).toInt(); |
235 } |
290 |
|
291 // Sending state now activated |
|
292 if (!oldSendingState && mSendingState) { |
|
293 showSendProgress(); |
|
294 } |
|
295 |
|
296 // Notify the global state |
|
297 emit globalStatusChanged(mSendingState); |
|
298 } |
|
299 } |
|
300 |
|
301 /*! |
|
302 Used for asking if this indicator can take status bar icon responsibility. |
|
303 \param sending global sending state |
|
304 \return true if the icon was accepted |
|
305 */ |
|
306 bool NmIndicator::acceptIcon(bool sending) |
|
307 { |
|
308 mSendingState = sending; |
|
309 |
|
310 if (mActive) { |
|
311 mShowIndicator = true; |
|
312 emit dataChanged(); |
|
313 } |
|
314 return mActive; |
|
315 } |
|
316 |
|