65 delete mDateObserver; |
66 delete mDateObserver; |
66 mDateObserver = NULL; |
67 mDateObserver = NULL; |
67 } |
68 } |
68 |
69 |
69 /*! |
70 /*! |
70 \fn void NmHsWidget::onShow() |
71 \fn QPainterPath NmHsWidget::shape() |
71 |
72 |
72 called by home screen fw when widget gets visible |
73 Called by home screen fw to check widget boundaries, needed to draw |
73 */ |
74 outside widget boundingRect. |
|
75 /return QPainterPath path describing actual boundaries of widget |
|
76 including child items |
|
77 */ |
|
78 QPainterPath NmHsWidget::shape() const |
|
79 { |
|
80 NM_FUNCTION; |
|
81 |
|
82 QPainterPath path; |
|
83 path.setFillRule(Qt::WindingFill); |
|
84 |
|
85 path.addRect(this->rect()); |
|
86 if (mTitleRow){ |
|
87 path.addPath(mTitleRow->shape()); |
|
88 } |
|
89 return path.simplified(); |
|
90 } |
|
91 |
|
92 /*! |
|
93 \fn void NmHsWidget::onShow() |
|
94 |
|
95 called by home screen fw when widget gets visible |
|
96 */ |
74 void NmHsWidget::onShow() |
97 void NmHsWidget::onShow() |
75 { |
98 { |
76 NM_FUNCTION; |
99 NM_FUNCTION; |
77 if (mEngine) |
100 if (mEngine) { |
78 { |
|
79 mEngine->activate(); |
101 mEngine->activate(); |
80 } |
102 } |
81 } |
103 } |
82 |
104 |
83 /*! |
105 /*! |
84 \fn void NmHsWidget::onHide() |
106 \fn void NmHsWidget::onHide() |
85 |
107 |
86 called by home screen fw when widget gets hidden |
108 called by home screen fw when widget gets hidden |
87 */ |
109 */ |
88 void NmHsWidget::onHide() |
110 void NmHsWidget::onHide() |
89 { |
111 { |
90 NM_FUNCTION; |
112 NM_FUNCTION; |
91 if (mEngine) |
113 if (mEngine) { |
92 { |
|
93 mEngine->suspend(); |
114 mEngine->suspend(); |
94 } |
115 } |
95 } |
116 } |
96 |
117 |
97 /*! |
118 /*! |
98 Initializes Localization. |
119 Initializes Localization. |
99 /post mTranslator constructed & localization file loaded |
120 /post mTranslator constructed & localization file loaded |
100 returns false in failure, otherwise true |
121 */ |
101 */ |
122 void NmHsWidget::setupLocalization() |
102 bool NmHsWidget::setupLocalization() |
123 { |
103 { |
124 NM_FUNCTION; |
104 NM_FUNCTION; |
125 |
105 |
|
106 //Use correct localisation |
126 //Use correct localisation |
107 bool ret(false); |
|
108 mTranslator = new QTranslator(); |
127 mTranslator = new QTranslator(); |
109 QString lang = QLocale::system().name(); |
128 QString lang = QLocale::system().name(); |
110 ret = mTranslator->load(KNmHsWidgetLocFileName + lang, KNmHsWidgetLocLocation); |
129 mTranslator->load(KNmHsWidgetLocFileName + lang, KNmHsWidgetLocLocation); |
111 QCoreApplication::installTranslator(mTranslator); |
130 QCoreApplication::installTranslator(mTranslator); |
112 |
131 } |
113 return ret; |
132 |
114 } |
133 /*! |
115 |
134 Initializes UI. Everything that is not done in docml files should be here. |
116 /*! |
135 return true if ok, in error false. |
117 Initializes UI. Everything that is not done in docml files should be here. |
136 */ |
118 return true if ok, in error false. |
|
119 */ |
|
120 void NmHsWidget::setupUi() |
137 void NmHsWidget::setupUi() |
121 { |
138 { |
122 NM_FUNCTION; |
139 NM_FUNCTION; |
123 |
140 |
124 setContentsMargins( KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin, |
141 setContentsMargins(KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin, |
125 KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin); |
142 KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin); |
126 |
143 |
127 //Setup layout |
144 //Setup layout |
128 mRowLayout = new QGraphicsLinearLayout(Qt::Vertical); |
145 mRowLayout = new QGraphicsLinearLayout(Qt::Vertical); |
129 |
146 |
130 mRowLayout->setContentsMargins(KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin, |
147 mRowLayout->setContentsMargins(KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin, |
131 KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin); |
148 KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin); |
132 mRowLayout->setSpacing(KNmHsWidgetContentsMargin); |
149 mRowLayout->setSpacing(KNmHsWidgetContentsMargin); |
133 setLayout(mRowLayout); |
150 setLayout(mRowLayout); |
134 |
151 |
135 //background |
152 //background |
136 mBackgroundFrameDrawer = new HbFrameDrawer( KNmHsWidgetBackgroundImage, HbFrameDrawer::NinePieces ); |
153 mBackgroundFrameDrawer = new HbFrameDrawer(KNmHsWidgetBackgroundImage, |
137 HbFrameItem* backgroundLayoutItem = new HbFrameItem( mBackgroundFrameDrawer ); |
154 HbFrameDrawer::NinePieces); |
138 //set to NULL to indicate that ownership transferred |
155 HbFrameItem* backgroundLayoutItem = new HbFrameItem(mBackgroundFrameDrawer); |
139 mBackgroundFrameDrawer = NULL; |
156 //set to NULL to indicate that ownership transferred |
140 setBackgroundItem( backgroundLayoutItem ); |
157 mBackgroundFrameDrawer = NULL; |
141 } |
158 setBackgroundItem(backgroundLayoutItem); |
142 |
|
143 /*! |
|
144 Initializes the widget. |
|
145 |
159 |
146 called by home screen fw when widget is added to home screen |
160 //Create NoMails Label. |
147 */ |
161 mNoMailsLabel = new HbLabel(this); |
|
162 mNoMailsLabel->setPlainText(hbTrId("txt_mail_widget_info_no_messages")); |
|
163 HbFontSpec fontSpec(HbFontSpec::Secondary); |
|
164 HbStyle style; |
|
165 qreal size; |
|
166 bool found = style.parameter(QString("hb-param-text-height-tiny"), size); |
|
167 if (found) { |
|
168 fontSpec.setTextHeight(size); |
|
169 } |
|
170 mNoMailsLabel->setFontSpec(fontSpec); |
|
171 QColor newFontColor; |
|
172 newFontColor = HbColorScheme::color("qtc_hs_list_item_content_normal"); |
|
173 mNoMailsLabel->setTextColor(newFontColor); |
|
174 mNoMailsLabel->setAlignment(Qt::AlignCenter); |
|
175 mNoMailsLabel->setVisible(false); |
|
176 |
|
177 } |
|
178 |
|
179 /*! |
|
180 Initializes the widget. |
|
181 |
|
182 called by home screen fw when widget is added to home screen |
|
183 */ |
148 void NmHsWidget::onInitialize() |
184 void NmHsWidget::onInitialize() |
149 { |
185 { |
150 NM_FUNCTION; |
186 NM_FUNCTION; |
151 |
187 |
152 QT_TRY{ |
188 QT_TRY { |
153 setupUi(); |
189 setupUi(); |
154 //emit error if localization fails |
190 setupLocalization(); |
155 if(!setupLocalization()){ |
191 |
156 emit error(); |
|
157 return; |
|
158 } |
|
159 |
|
160 //Engine construction is 2 phased. |
192 //Engine construction is 2 phased. |
161 mEngine = new NmHsWidgetEmailEngine( mAccountId ); |
193 mEngine = new NmHsWidgetEmailEngine(mAccountId); |
162 //Client must connect to exception signals before calling the initialize function |
194 //Client must connect to exception signals before calling the initialize function |
163 //because we don't want to miss any signals. |
195 //because we don't want to miss any signals. |
164 connect(mEngine, SIGNAL( exceptionOccured(const int&) ) |
196 connect(mEngine, SIGNAL( exceptionOccured(const int&) ), this, |
165 ,this, SLOT( onEngineException(const int&) ) ); |
197 SLOT( onEngineException(const int&) )); |
166 if(!mEngine->initialize()) |
198 if (!mEngine->initialize()) { |
167 { |
|
168 //engine construction failed. Give up. |
199 //engine construction failed. Give up. |
169 emit error(); |
200 emit error(); |
170 return; |
201 return; |
171 } |
202 } |
172 |
203 |
173 //construct and load docml for title row |
204 //construct and load docml for title row |
174 mTitleRow = new NmHsWidgetTitleRow(); |
205 mTitleRow = new NmHsWidgetTitleRow(this); |
175 if( !mTitleRow->loadDocML()){ |
206 if (!mTitleRow->setupUI()) { |
176 //if docml loading fails no point to proceed |
207 //if docml loading fails no point to proceed |
177 //but memoryleak must be prevented |
|
178 delete mTitleRow; |
|
179 mTitleRow = NULL; |
|
180 emit error(); |
208 emit error(); |
181 return; |
209 return; |
182 } |
210 } |
183 mRowLayout->addItem(mTitleRow); |
211 mRowLayout->addItem(mTitleRow); |
184 mTitleRow->updateAccountName(mEngine->accountName()); |
212 mTitleRow->updateAccountName(mEngine->accountName()); |
185 |
213 |
186 //create observer for date/time change events |
214 //create observer for date/time change events |
187 mDateObserver = new NmHsWidgetDateTimeObserver(); |
215 mDateObserver = new NmHsWidgetDateTimeObserver(); |
188 |
216 |
|
217 //Crete MailRows and associated connections |
|
218 createMailRowsList(); |
|
219 |
189 updateMailData(); |
220 updateMailData(); |
190 mTitleRow->updateUnreadCount(mEngine->unreadCount()); |
221 mTitleRow->updateUnreadCount(mEngine->unreadCount()); |
191 mTitleRow->setAccountIcon(mAccountIconName); |
222 mTitleRow->setAccountIcon(mAccountIconName); |
192 mTitleRow->setExpandCollapseIcon(mIsExpanded); |
223 mTitleRow->setExpandCollapseIcon(mIsExpanded); |
193 |
224 |
194 //Get signals about changes in mail data |
225 //Get signals about changes in mail data |
195 connect(mEngine, SIGNAL( mailDataChanged() ) |
226 connect(mEngine, SIGNAL( mailDataChanged() ), this, SLOT( updateMailData() )); |
196 ,this, SLOT( updateMailData() ) ); |
227 |
197 |
|
198 //Get Signals about changes in unread count |
228 //Get Signals about changes in unread count |
199 connect(mEngine, SIGNAL( unreadCountChanged(const int&) ) |
229 connect(mEngine, SIGNAL( unreadCountChanged(const int&) ) |
200 ,mTitleRow, SLOT( updateUnreadCount(const int&) ) ); |
230 ,mTitleRow, SLOT( updateUnreadCount(const int&) ) ); |
201 |
231 |
202 //Get signals about account name changes |
232 //Get signals about account name changes |
207 connect(mTitleRow, SIGNAL( mailboxLaunchTriggered() ) |
237 connect(mTitleRow, SIGNAL( mailboxLaunchTriggered() ) |
208 ,mEngine, SLOT( launchMailAppInboxView() ) ); |
238 ,mEngine, SLOT( launchMailAppInboxView() ) ); |
209 connect(mTitleRow, SIGNAL( expandCollapseButtonPressed() ) |
239 connect(mTitleRow, SIGNAL( expandCollapseButtonPressed() ) |
210 ,this, SLOT( handleExpandCollapseEvent() ) ); |
240 ,this, SLOT( handleExpandCollapseEvent() ) ); |
211 |
241 |
212 //resize here so homescreen will place widget correctly on screen |
242 } |
213 setPreferredSize( mRowLayout->preferredSize() ); |
243 QT_CATCH(...) { |
214 if (parentWidget()) { |
|
215 //to place widget properly after adding to homescreen |
|
216 parentWidget()->resize(preferredSize()); |
|
217 } |
|
218 } |
|
219 QT_CATCH(...){ |
|
220 emit error(); |
244 emit error(); |
221 } |
245 } |
222 |
246 |
223 } |
247 } |
224 |
248 |
225 /*! |
249 |
226 Uninitializes the widget. |
250 /*! |
227 |
251 updateMailData slot |
228 called by home screen fw when widget is removed from home screen |
252 */ |
229 */ |
|
230 void NmHsWidget::onUninitialize() |
|
231 { |
|
232 NM_FUNCTION; |
|
233 } |
|
234 |
|
235 /*! |
|
236 updateMailData slot |
|
237 */ |
|
238 void NmHsWidget::updateMailData() |
253 void NmHsWidget::updateMailData() |
239 { |
254 { |
240 NM_FUNCTION; |
255 NM_FUNCTION; |
241 |
256 |
242 QList<NmMessageEnvelope> envelopes; |
257 QList<NmMessageEnvelope> envelopes; |
243 int count = 0; |
258 int count = 0; |
244 if (mIsExpanded) { |
259 if (mIsExpanded) { |
245 count = mEngine->getEnvelopes(envelopes, KMaxNumberOfMailsShown); |
260 count = mEngine->getEnvelopes(envelopes, KMaxNumberOfMailsShown); |
246 } |
261 } |
247 |
262 |
248 updateMailRowsList(count); |
263 updateLayout(count); |
249 |
264 //count is safe for envelopes and mMailRows |
250 for(int i=0; i<envelopes.count(); i++) |
265 for (int i = 0; i < count; i++) { |
251 { |
266 mMailRows.at(i)->updateMailData(envelopes.at(i)); |
252 mMailRows[i]->updateMailData( envelopes[i] ); |
267 } |
253 } |
268 } |
254 } |
269 |
255 |
270 /*! |
256 /*! |
271 Sets monitored account id from given string |
257 Sets monitored account id from given string |
272 Needed for home screen framework which supports only QString type properties |
258 Needed for home screen framework which supports only QString type properties |
273 */ |
259 */ |
|
260 void NmHsWidget::setAccountId(const QString &text) |
274 void NmHsWidget::setAccountId(const QString &text) |
261 { |
275 { |
262 NM_FUNCTION; |
276 NM_FUNCTION; |
263 |
277 |
264 bool ok; |
278 bool ok; |
265 quint64 id = text.toULongLong(&ok); |
279 quint64 id = text.toULongLong(&ok); |
266 if (!ok) |
280 if (!ok) { |
267 { |
281 NM_ERROR(1, "NmHsWidget::setAccountId: invalid account ID data, signal finished()!!!"); |
268 NM_ERROR(1,"NmHsWidget::setAccountId: invalid account ID data, signal finished()!!!"); |
|
269 //No valid account id so give up |
282 //No valid account id so give up |
270 emit finished(); |
283 emit finished(); |
271 } |
284 return; |
272 else |
285 } |
273 { |
286 |
274 mAccountId.setId(id); |
287 mAccountId.setId(id); |
275 } |
288 } |
276 } |
289 |
277 |
290 /*! |
278 /*! |
291 Returns monitored account id as a string |
279 Returns monitored account id as a string |
292 Needed for home screen framework which supports only QString type properties |
280 Needed for home screen framework which supports only QString type properties |
293 */ |
281 */ |
|
282 QString NmHsWidget::accountId() const |
294 QString NmHsWidget::accountId() const |
283 { |
295 { |
284 NM_FUNCTION; |
296 NM_FUNCTION; |
285 return QString::number(mAccountId.id()); |
297 return QString::number(mAccountId.id()); |
286 } |
298 } |
287 |
299 |
288 /*! |
300 /*! |
289 Sets monitored account icon name from given string |
301 Sets monitored account icon name from given string |
290 */ |
302 */ |
291 void NmHsWidget::setAccountIconName(const QString &text) |
303 void NmHsWidget::setAccountIconName(const QString &text) |
292 { |
304 { |
293 NM_FUNCTION; |
305 NM_FUNCTION; |
294 mAccountIconName = text; |
306 mAccountIconName = text; |
295 } |
307 } |
296 |
308 |
297 /*! |
309 /*! |
298 Returns monitored account icon name |
310 Returns monitored account icon name |
299 */ |
311 */ |
300 QString NmHsWidget::accountIconName() const |
312 QString NmHsWidget::accountIconName() const |
301 { |
313 { |
302 NM_FUNCTION; |
314 NM_FUNCTION; |
303 return mAccountIconName; |
315 return mAccountIconName; |
304 } |
316 } |
305 |
317 |
306 /*! |
318 /*! |
307 Slot to handle expand/collapse trigger event |
319 Slot to handle expand/collapse trigger event |
308 */ |
320 */ |
309 void NmHsWidget::handleExpandCollapseEvent() |
321 void NmHsWidget::handleExpandCollapseEvent() |
310 { |
322 { |
311 NM_FUNCTION; |
323 NM_FUNCTION; |
312 toggleExpansionState(); |
324 toggleExpansionState(); |
313 } |
325 } |
314 |
326 |
315 /*! |
327 /*! |
316 Sets widget expand/collapse state |
328 Sets widget expand/collapse state |
317 /post widget expansion state is changed |
329 /post widget expansion state is changed |
318 */ |
330 */ |
319 void NmHsWidget::toggleExpansionState() |
331 void NmHsWidget::toggleExpansionState() |
320 { |
332 { |
321 NM_FUNCTION; |
333 NM_FUNCTION; |
322 |
334 |
323 mIsExpanded = !mIsExpanded; |
335 mIsExpanded = !mIsExpanded; |
324 |
336 |
325 //save new state to home screen |
337 //save new state to home screen |
326 QStringList propertiesList; |
338 QStringList propertiesList; |
327 propertiesList.append("widgetState"); |
339 propertiesList.append("widgetState"); |
328 emit setPreferences(propertiesList); |
340 emit setPreferences(propertiesList); |
329 |
341 |
330 //handle state change drawing |
342 //handle state change drawing |
331 updateMailData(); |
343 updateMailData(); |
332 |
344 |
333 mTitleRow->setExpandCollapseIcon(mIsExpanded); |
345 mTitleRow->setExpandCollapseIcon(mIsExpanded); |
334 } |
346 } |
335 |
347 |
336 /*! |
348 /*! |
337 Sets expand/collapse state from given string (needed by homescreen) |
349 Sets expand/collapse state from given string (needed by homescreen) |
338 */ |
350 */ |
339 void NmHsWidget::setWidgetStateProperty(QString value) |
351 void NmHsWidget::setWidgetStateProperty(QString value) |
340 { |
352 { |
341 NM_FUNCTION; |
353 NM_FUNCTION; |
342 if (value == KNmHsWidgetStateCollapsed) |
354 if (value == KNmHsWidgetStateCollapsed) { |
|
355 mIsExpanded = false; |
|
356 } |
|
357 else { |
|
358 mIsExpanded = true; |
|
359 } |
|
360 } |
|
361 |
|
362 /*! |
|
363 Returns widget expand/collapse state as string (needed by homescreen) |
|
364 */ |
|
365 QString NmHsWidget::widgetStateProperty() |
|
366 { |
|
367 NM_FUNCTION; |
|
368 if (mIsExpanded) { |
|
369 return KNmHsWidgetStateExpanded; |
|
370 } |
|
371 else { |
|
372 return KNmHsWidgetStateCollapsed; |
|
373 } |
|
374 } |
|
375 |
|
376 /*! |
|
377 Updates mMailRows list to include KMaxNumberOfMailsShown mail row widgets |
|
378 /post mMailRows contains KMaxNumberOfMailsShown mailRows |
|
379 */ |
|
380 void NmHsWidget::createMailRowsList() |
|
381 { |
|
382 NM_FUNCTION; |
|
383 |
|
384 //make sure that there are as many email rows as needed |
|
385 while (mMailRows.count() < KMaxNumberOfMailsShown) { |
|
386 NmHsWidgetEmailRow *row = new NmHsWidgetEmailRow(this); |
|
387 if (!row->setupUI()) { |
|
388 NM_ERROR(1, "NmHsWidget::createMailRowsList row->setUpUI() fails"); |
|
389 //if setupUI fails no point to proceed |
|
390 emit error(); |
|
391 return; |
|
392 } |
|
393 connect(row, SIGNAL(mailViewerLaunchTriggered(const NmId&)), mEngine, |
|
394 SLOT(launchMailAppMailViewer(const NmId&))); |
|
395 connect(mDateObserver, SIGNAL(dateTimeChanged()), row, SLOT(updateDateTime())); |
|
396 mMailRows.append(row); |
|
397 } |
|
398 |
|
399 } |
|
400 |
|
401 /*! |
|
402 Updates the Layout to contain the right items |
|
403 /param mailCount defines how many emails is to be shown |
|
404 /post If widget is collapsed, the layout contains only titleRow widget. |
|
405 If widget is expanded and mailCount is 0 layout will contain |
|
406 titlerow & noMailsLabel. |
|
407 If widget is expanded and mailCount is greter |
|
408 than zero, layout will contain titlerow and KMaxNumberOfMailsShown times |
|
409 emailrow(s) |
|
410 */ |
|
411 void NmHsWidget::updateLayout(const int mailCount) |
|
412 { |
|
413 NM_FUNCTION; |
|
414 if (mIsExpanded) { |
|
415 if (mailCount == 0) { |
|
416 addNoMailsLabelToLayout(); |
|
417 removeEmailRowsFromLayout(); |
|
418 } |
|
419 else { |
|
420 removeNoMailsLabelFromLayout(); |
|
421 addEmailRowsToLayout(); |
|
422 } |
|
423 } |
|
424 else { |
|
425 removeNoMailsLabelFromLayout(); |
|
426 removeEmailRowsFromLayout(); |
|
427 } |
|
428 |
|
429 //resize the widget to new layout size |
|
430 setPreferredSize(mRowLayout->preferredSize()); |
|
431 |
|
432 updateMailRowsVisibility(mailCount); |
|
433 } |
|
434 |
|
435 /*! |
|
436 Updates mNoMailsLabel visibility based on widget state |
|
437 /param mailCount defines how many mail rows is needed |
|
438 /post if mail count is 0 and mIsExpanded equals true, then |
|
439 the mNoMailLabel is added to the mRowLayout. |
|
440 */ |
|
441 void NmHsWidget::addNoMailsLabelToLayout() |
|
442 { |
|
443 NM_FUNCTION; |
|
444 //Use sizes defined for titlerow and mailrow docml to indentify the correct size |
|
445 //for the mNoMailslabel |
|
446 if (mNoMailsLabel->isVisible() || mMailRows.isEmpty()) { |
|
447 return; |
|
448 } |
|
449 QSizeF mailLabelSize(mTitleRow->maximumWidth(), KMaxNumberOfMailsShown |
|
450 * mMailRows.first()->maximumHeight()); |
|
451 mNoMailsLabel->setPreferredSize(mailLabelSize); |
|
452 mNoMailsLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); |
|
453 //Add mNoMailsLabel to layout if not yet there and show it |
|
454 mRowLayout->addItem(mNoMailsLabel); |
|
455 //resize the widget to new layout size |
|
456 mNoMailsLabel->show(); |
|
457 } |
|
458 |
|
459 /*! |
|
460 removeNoMailsLabelFromLayout removes mNoMailsLabel from the layout |
|
461 /post mNoMailsLabel is not in mRowLayout |
|
462 */ |
|
463 void NmHsWidget::removeNoMailsLabelFromLayout() |
|
464 { |
|
465 NM_FUNCTION; |
|
466 //remove mNoMailsLabel from Layout and hide it |
|
467 mRowLayout->removeItem(mNoMailsLabel); |
|
468 mNoMailsLabel->hide(); |
|
469 } |
|
470 |
|
471 /*! |
|
472 addEmailRowsToLayout adds every emailrow to the layout |
|
473 /post all elements in mMailRows are added to mRowLayout |
|
474 */ |
|
475 void NmHsWidget::addEmailRowsToLayout() |
|
476 { |
|
477 NM_FUNCTION; |
|
478 foreach(NmHsWidgetEmailRow *row, mMailRows) |
343 { |
479 { |
344 mIsExpanded = false; |
480 mRowLayout->addItem(row); |
345 } |
481 } |
346 else |
482 } |
|
483 |
|
484 /*! |
|
485 removeEmailRowsFromLayout removes every emailrow from the layout |
|
486 /post none of the elements in mMailRows are in mRowLayout |
|
487 */ |
|
488 void NmHsWidget::removeEmailRowsFromLayout() |
|
489 { |
|
490 NM_FUNCTION; |
|
491 foreach(NmHsWidgetEmailRow *row, mMailRows) |
347 { |
492 { |
348 mIsExpanded = true; |
493 mRowLayout->removeItem(row); |
349 } |
494 } |
350 } |
495 } |
351 |
496 |
352 /*! |
497 /*! |
353 Returns widget expand/collapse state as string (needed by homescreen) |
498 Updates mail row visibilities in static widget |
354 */ |
499 /param visibleCount defines how many items do have mail data |
355 QString NmHsWidget::widgetStateProperty() |
500 /post all row items having mail data are visible, other rows are hidden |
356 { |
501 */ |
357 NM_FUNCTION; |
|
358 if (mIsExpanded) |
|
359 { |
|
360 return KNmHsWidgetStateExpanded; |
|
361 } |
|
362 else |
|
363 { |
|
364 return KNmHsWidgetStateCollapsed; |
|
365 } |
|
366 } |
|
367 |
|
368 /*! |
|
369 Updates mMailRows list to include correct amount of mail row widgets |
|
370 /param mailCount defines how many mail rows is needed |
|
371 /post mMailRows list includes NmHsWidgetEmailRow for each mail item |
|
372 */ |
|
373 void NmHsWidget::updateMailRowsList(const int mailCount) |
|
374 { |
|
375 NM_FUNCTION; |
|
376 |
|
377 int neededRowsCount = mailCount; |
|
378 //force size when static and expanded |
|
379 if (mStaticWidget && mIsExpanded) |
|
380 { |
|
381 neededRowsCount = KMaxNumberOfMailsShown; |
|
382 } |
|
383 |
|
384 while (mMailRows.count() != neededRowsCount) |
|
385 { |
|
386 //more mails to show than rows |
|
387 if (mMailRows.count() < neededRowsCount) |
|
388 { |
|
389 NmHsWidgetEmailRow *row = new NmHsWidgetEmailRow(); |
|
390 if( !row->loadDocML()){ |
|
391 NM_ERROR(1,"NmHsWidget::updateMailRowsList row->loadDocML() fails"); |
|
392 //if docml loading fails no point to proceed |
|
393 //but memoryleak must be prevented |
|
394 delete row; |
|
395 row = NULL; |
|
396 emit error(); |
|
397 return; |
|
398 } |
|
399 connect(row, SIGNAL(mailViewerLaunchTriggered(const NmId&)) |
|
400 ,mEngine, SLOT(launchMailAppMailViewer(const NmId&))); |
|
401 connect( mDateObserver, SIGNAL(dateTimeChanged()) |
|
402 ,row, SLOT(updateDateTime()) ); |
|
403 mMailRows.append(row); |
|
404 mRowLayout->addItem(row); |
|
405 } |
|
406 //too many rows |
|
407 else if (mMailRows.count() > neededRowsCount) |
|
408 { |
|
409 mRowLayout->removeItem(mMailRows.last()); |
|
410 delete mMailRows.takeLast(); |
|
411 } |
|
412 } |
|
413 __ASSERT_ALWAYS( mMailRows.count() == neededRowsCount, User::Panic(_L("Invalid"), 500) ); |
|
414 |
|
415 //resize the widget to new layout size |
|
416 setPreferredSize( mRowLayout->preferredSize() ); |
|
417 |
|
418 if (mStaticWidget) |
|
419 { |
|
420 this->updateMailRowsVisibility(mailCount); |
|
421 } |
|
422 } |
|
423 |
|
424 /*! |
|
425 Updates mail row visibilities in static widget |
|
426 /param visibleCount defines how many items do have mail data |
|
427 /post all row items having mail data are visible, other rows are hidden |
|
428 */ |
|
429 void NmHsWidget::updateMailRowsVisibility(const int visibleCount) |
502 void NmHsWidget::updateMailRowsVisibility(const int visibleCount) |
430 { |
503 { |
431 NM_FUNCTION; |
504 NM_FUNCTION; |
432 |
505 |
433 // set visible as many rows as requested by visibleCount param |
506 // set visible as many rows as requested by visibleCount param |
434 bool isVisible; |
507 bool isVisible; |
435 for (int i=0; i < mMailRows.count(); i++) |
508 |
436 { |
509 for (int i = 0; i < mMailRows.count(); i++) { |
437 isVisible = false; |
510 isVisible = false; |
438 if ((mIsExpanded) && (i < visibleCount)) |
511 if ((mIsExpanded) && (i < visibleCount)) { |
439 { |
|
440 isVisible = true; |
512 isVisible = true; |
441 } |
513 } |
442 mMailRows.at(i)->setVisible(isVisible); |
514 mMailRows.at(i)->setVisible(isVisible); |
443 } |
515 } |
444 } |
516 } |
445 |
517 |
446 /*! |
518 /*! |
447 onEngineException (NmHsWidgetEmailEngineExceptionCode exc) |
519 onEngineException (NmHsWidgetEmailEngineExceptionCode exc) |
448 signals widget to be finalized |
520 signals widget to be finalized |
449 /param exc exception type |
521 /param exc exception type |
450 */ |
522 */ |
451 void NmHsWidget::onEngineException(const int& exc) |
523 void NmHsWidget::onEngineException(const int& exc) |
452 { |
524 { |
453 NM_FUNCTION; |
525 NM_FUNCTION; |
454 switch (exc) |
526 switch (exc) { |
455 { |
|
456 case (NmEngineExcAccountDeleted): |
527 case (NmEngineExcAccountDeleted): |
457 emit finished(); //succesful ending |
528 emit finished(); //succesful ending |
458 break; |
529 break; |
459 case (NmEngineExcFailure): |
530 case (NmEngineExcFailure): |
460 emit error(); //failure |
531 emit error(); //failure |
461 break; |
532 break; |
462 default: |
533 default: |
463 break; |
534 break; |
464 } |
535 } |
465 } |
536 } |