13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 #include <QtGui> |
17 #include <QtGui> |
|
18 #include <QTranslator> |
18 #include <QGraphicsLinearLayout> |
19 #include <QGraphicsLinearLayout> |
19 #include <hbcolorscheme.h> |
20 #include <hbcolorscheme.h> |
20 #include <hbdocumentloader.h> |
21 #include <hbdocumentloader.h> |
21 #include <QTranslator> |
|
22 #include <hbframedrawer.h> |
22 #include <hbframedrawer.h> |
23 #include <hbframeitem.h> |
23 #include <hbframeitem.h> |
24 #include <hblabel.h> |
24 #include <hblabel.h> |
|
25 #include <hbstyleloader.h> |
|
26 #include <hblistview.h> |
|
27 #include <hbdeviceprofile.h> |
25 #include "nmcommon.h" |
28 #include "nmcommon.h" |
|
29 #include "nmmessageenvelope.h" |
26 #include "nmhswidget.h" |
30 #include "nmhswidget.h" |
27 #include "nmhswidgetemailengine.h" |
31 #include "nmhswidgetemailengine.h" |
28 #include "nmmessageenvelope.h" |
|
29 #include "nmhswidgettitlerow.h" |
32 #include "nmhswidgettitlerow.h" |
30 #include "nmhswidgetemailrow.h" |
|
31 #include "nmhswidgetconsts.h" |
33 #include "nmhswidgetconsts.h" |
32 #include "nmhswidgetdatetimeobserver.h" |
34 #include "nmhswidgetdatetimeobserver.h" |
|
35 #include "nmhswidgetlistviewitem.h" |
|
36 #include "nmhswidgetlistmodel.h" |
33 #include "emailtrace.h" |
37 #include "emailtrace.h" |
|
38 |
34 |
39 |
35 NmHsWidget::NmHsWidget(QGraphicsItem *parent, Qt::WindowFlags flags) |
40 NmHsWidget::NmHsWidget(QGraphicsItem *parent, Qt::WindowFlags flags) |
36 : HbWidget(parent, flags), |
41 : HbWidget(parent, flags), |
37 mMainContainer(0), |
42 mMainContainer(0), |
38 mEmptySpaceContainer(0), |
43 mEmptySpaceContainer(0), |
147 mMainContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetMainContainer)); |
154 mMainContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetMainContainer)); |
148 mWidgetContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetContainer)); |
155 mWidgetContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetContainer)); |
149 mContentContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetContentContainer)); |
156 mContentContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetContentContainer)); |
150 mEmptySpaceContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetEmptySpaceContainer)); |
157 mEmptySpaceContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetEmptySpaceContainer)); |
151 mNoMailsLabel = static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetNoMailsLabel)); |
158 mNoMailsLabel = static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetNoMailsLabel)); |
|
159 mListView = static_cast<HbListView*> (loader.findWidget("mailListView")); |
152 if (!mMainContainer || !mWidgetContainer || !mContentContainer |
160 if (!mMainContainer || !mWidgetContainer || !mContentContainer |
153 || !mEmptySpaceContainer || !mNoMailsLabel ) { |
161 || !mEmptySpaceContainer || !mNoMailsLabel ) { |
154 //something failed in documentloader, no point to continue |
162 //something failed in documentloader, no point to continue |
155 NM_ERROR(1,"NmHsWidget::loadDocML fail @ containers or label"); |
163 NM_ERROR(1,"NmHsWidget::loadDocML fail @ containers or label"); |
156 ok = false; |
164 ok = false; |
168 NM_FUNCTION; |
176 NM_FUNCTION; |
169 |
177 |
170 //Use correct localisation |
178 //Use correct localisation |
171 mTranslator = new QTranslator(); |
179 mTranslator = new QTranslator(); |
172 QString lang = QLocale::system().name(); |
180 QString lang = QLocale::system().name(); |
173 mTranslator->load(KNmHsWidgetLocFileName + lang, KNmHsWidgetLocLocation); |
181 |
|
182 //try to load translation from c drive. If not found then try z. |
|
183 bool loadingSucceed = mTranslator->load(KNmHsWidgetLocFileName + lang, "c:" + KNmHsWidgetLocLocation); |
|
184 if(!loadingSucceed){ |
|
185 mTranslator->load(KNmHsWidgetLocFileName + lang, "z:" + KNmHsWidgetLocLocation); |
|
186 } |
|
187 |
174 QCoreApplication::installTranslator(mTranslator); |
188 QCoreApplication::installTranslator(mTranslator); |
175 } |
189 } |
|
190 |
176 |
191 |
177 /*! |
192 /*! |
178 Initializes UI. Everything that is not done in docml files should be here. |
193 Initializes UI. Everything that is not done in docml files should be here. |
179 return true if ok, in error false. |
194 return true if ok, in error false. |
180 */ |
195 */ |
210 mBackgroundFrameDrawer = NULL; |
225 mBackgroundFrameDrawer = NULL; |
211 mWidgetContainer->setBackgroundItem(backgroundLayoutItem); |
226 mWidgetContainer->setBackgroundItem(backgroundLayoutItem); |
212 } |
227 } |
213 |
228 |
214 /*! |
229 /*! |
|
230 Sets correct properties and mail item proto type for mail list view |
|
231 */ |
|
232 void NmHsWidget::createMailRowsList() |
|
233 { |
|
234 NM_FUNCTION; |
|
235 connect(mListView, SIGNAL(activated(const QModelIndex&)), this, |
|
236 SLOT(openMessage(const QModelIndex&))); |
|
237 |
|
238 // Set the list widget properties. |
|
239 NmHsWidgetListViewItem *prototype = new NmHsWidgetListViewItem(mListView); |
|
240 mListView->setItemPrototype(prototype); |
|
241 mListModel = new NmHsWidgetListModel(); |
|
242 mListView->setModel(mListModel); |
|
243 } |
|
244 |
|
245 /*! |
215 Initializes the widget. |
246 Initializes the widget. |
216 |
247 |
217 called by home screen fw when widget is added to home screen |
248 called by home screen fw when widget is added to home screen |
218 */ |
249 */ |
219 void NmHsWidget::onInitialize() |
250 void NmHsWidget::onInitialize() |
220 { |
251 { |
221 NM_FUNCTION; |
252 NM_FUNCTION; |
222 |
253 |
223 QT_TRY { |
254 QT_TRY { |
|
255 |
|
256 HbStyleLoader::registerFilePath(":/layout/nmhswidgetlistviewitem.widgetml"); |
|
257 HbStyleLoader::registerFilePath(":/layout/nmhswidgetlistviewitem.css"); |
|
258 |
224 // Use document loader to load the contents |
259 // Use document loader to load the contents |
225 HbDocumentLoader loader; |
260 HbDocumentLoader loader; |
226 //setup localization before docml loading |
261 //setup localization before docml loading |
227 setupLocalization(); |
262 setupLocalization(); |
228 |
263 |
255 NM_ERROR(1,"NmHsWidget::onInitialize fail @ engine"); |
290 NM_ERROR(1,"NmHsWidget::onInitialize fail @ engine"); |
256 emit error(); |
291 emit error(); |
257 return; |
292 return; |
258 } |
293 } |
259 |
294 |
|
295 //set account name to title row |
260 mTitleRow->updateAccountName(mEngine->accountName()); |
296 mTitleRow->updateAccountName(mEngine->accountName()); |
261 |
297 |
262 //create observer for date/time change events |
298 //create observer for date/time change events |
263 mDateObserver = new NmHsWidgetDateTimeObserver(); |
299 mDateObserver = new NmHsWidgetDateTimeObserver(); |
264 |
300 |
265 //Crete MailRows and associated connections |
301 //Crete list for mail items |
266 createMailRowsList(); |
302 createMailRowsList(); |
267 |
303 |
268 updateMailData(); |
304 updateMailData(); |
269 mTitleRow->updateUnreadCount(mEngine->unreadCount()); |
305 mTitleRow->updateUnreadCount(mEngine->unreadCount()); |
270 mTitleRow->setAccountIcon(mAccountIconName); |
306 mTitleRow->setAccountIcon(mAccountIconName); |
285 connect(mTitleRow, SIGNAL( mailboxLaunchTriggered() ) |
321 connect(mTitleRow, SIGNAL( mailboxLaunchTriggered() ) |
286 ,mEngine, SLOT( launchMailAppInboxView() ) ); |
322 ,mEngine, SLOT( launchMailAppInboxView() ) ); |
287 connect(mTitleRow, SIGNAL( expandCollapseButtonPressed() ) |
323 connect(mTitleRow, SIGNAL( expandCollapseButtonPressed() ) |
288 ,this, SLOT( handleExpandCollapseEvent() ) ); |
324 ,this, SLOT( handleExpandCollapseEvent() ) ); |
289 |
325 |
|
326 //Get date/time events from date observer |
|
327 connect(mDateObserver, SIGNAL(dateTimeChanged()) |
|
328 , this, SLOT(updateMailData())); |
290 setMinimumSize(mTitleRow->minimumWidth(), |
329 setMinimumSize(mTitleRow->minimumWidth(), |
291 mEmptySpaceContainer->minimumHeight() + mTitleRow->minimumHeight()); |
330 mEmptySpaceContainer->minimumHeight() + mTitleRow->minimumHeight()); |
292 } |
331 } |
293 QT_CATCH(...) { |
332 QT_CATCH(...) { |
294 NM_ERROR(1,"NmHsWidget::onInitialize fail @ catch"); |
333 NM_ERROR(1,"NmHsWidget::onInitialize fail @ catch"); |
295 emit error(); |
334 emit error(); |
296 } |
335 } |
297 } |
336 } |
298 |
337 |
299 /*! |
338 /*! |
|
339 Uninitializes the widget. |
|
340 |
|
341 called by home screen fw when widget is removed from home screen |
|
342 */ |
|
343 void NmHsWidget::onUninitialize() |
|
344 { |
|
345 NM_FUNCTION; |
|
346 HbStyleLoader::unregisterFilePath(":/layout/nmhswidgetlistviewitem.widgetml"); |
|
347 HbStyleLoader::unregisterFilePath(":/layout/nmhswidgetlistviewitem.css"); |
|
348 } |
|
349 |
|
350 /*! |
300 updateMailData slot |
351 updateMailData slot |
301 */ |
352 */ |
302 void NmHsWidget::updateMailData() |
353 void NmHsWidget::updateMailData() |
303 { |
354 { |
304 NM_FUNCTION; |
355 NM_FUNCTION; |
305 |
356 QT_TRY { |
306 QList<NmMessageEnvelope> envelopes; |
357 QList<NmMessageEnvelope*> envelopes; |
307 int count = 0; |
358 int count = 0; |
308 if (mIsExpanded) { |
359 if (mIsExpanded) { |
309 count = mEngine->getEnvelopes(envelopes, KMaxNumberOfMailsShown); |
360 count = mEngine->getEnvelopes(envelopes, KMaxNumberOfMailsShown); |
310 } |
361 } |
311 |
362 mListModel->refresh( envelopes ); |
312 updateLayout(count); |
363 updateLayout(count); |
313 //count is safe for envelopes and mMailRows |
364 }QT_CATCH(...) { |
314 for (int i = 0; i < count; i++) { |
365 NM_ERROR(1,"NmHsWidget::updateMailData fail @ catch"); |
315 mMailRows.at(i)->updateMailData(envelopes.at(i)); |
366 emit error(); |
316 } |
367 } |
317 } |
368 } |
318 |
369 |
319 /*! |
370 /*! |
320 Sets monitored account id from given string |
371 Sets monitored account id from given string |
420 else { |
471 else { |
421 return KNmHsWidgetStateCollapsed; |
472 return KNmHsWidgetStateCollapsed; |
422 } |
473 } |
423 } |
474 } |
424 |
475 |
425 /*! |
|
426 Updates mMailRows list to include KMaxNumberOfMailsShown mail row widgets |
|
427 /post mMailRows contains KMaxNumberOfMailsShown mailRows |
|
428 */ |
|
429 void NmHsWidget::createMailRowsList() |
|
430 { |
|
431 NM_FUNCTION; |
|
432 |
|
433 //make sure that there are as many email rows as needed |
|
434 while (mMailRows.count() < KMaxNumberOfMailsShown) { |
|
435 NmHsWidgetEmailRow *row = new NmHsWidgetEmailRow(this); |
|
436 if (!row->setupUI()) { |
|
437 NM_ERROR(1, "NmHsWidget::createMailRowsList row->setUpUI() fails"); |
|
438 //if setupUI fails no point to proceed |
|
439 emit error(); |
|
440 return; |
|
441 } |
|
442 connect(row, SIGNAL(mailViewerLaunchTriggered(const NmId&)), mEngine, |
|
443 SLOT(launchMailAppMailViewer(const NmId&))); |
|
444 connect(mDateObserver, SIGNAL(dateTimeChanged()), row, SLOT(updateDateTime())); |
|
445 mMailRows.append(row); |
|
446 } |
|
447 |
|
448 } |
|
449 |
476 |
450 /*! |
477 /*! |
451 Updates the Layout to contain the right items |
478 Updates the Layout to contain the right items |
452 /param mailCount defines how many emails is to be shown |
479 /param mailCount defines how many emails is to be shown |
453 /post If widget is collapsed, the layout contains only titleRow widget. |
480 /post If widget is collapsed, the layout contains only titleRow widget. |
458 emailrow(s) |
485 emailrow(s) |
459 */ |
486 */ |
460 void NmHsWidget::updateLayout(const int mailCount) |
487 void NmHsWidget::updateLayout(const int mailCount) |
461 { |
488 { |
462 NM_FUNCTION; |
489 NM_FUNCTION; |
463 |
490 |
|
491 //collapsed size |
|
492 qreal totalHeight = mEmptySpaceContainer->preferredHeight() + mTitleRow->containerHeight(); |
|
493 |
464 if (mIsExpanded) { |
494 if (mIsExpanded) { |
465 //set container height to content height |
495 //when expanded, grow as big as possible |
466 qreal contentHeight = KMaxNumberOfMailsShown |
496 totalHeight = KNmHsWidgetHSMaxWidgetHeightInUnits * HbDeviceProfile::current().unitValue(); |
467 * mMailRows.first()->maximumHeight(); |
|
468 mContentContainer->setMaximumHeight(contentHeight); |
|
469 mContentContainer->setVisible(true); |
497 mContentContainer->setVisible(true); |
470 if (mailCount == 0) { |
498 if (mailCount == 0) { |
471 addNoMailsLabelToLayout(); |
499 addNoMailsLabelToLayout(); |
472 removeEmailRowsFromLayout(); |
500 removeEmailRowsFromLayout(); |
473 } |
501 } |
477 } |
505 } |
478 } |
506 } |
479 else { |
507 else { |
480 removeNoMailsLabelFromLayout(); |
508 removeNoMailsLabelFromLayout(); |
481 removeEmailRowsFromLayout(); |
509 removeEmailRowsFromLayout(); |
482 mContentContainer->setVisible(false); |
510 mContentContainer->setVisible(false); |
483 mContentContainer->setMaximumHeight(0); |
511 } |
484 } |
512 |
485 |
|
486 //resize the widget to new layout size |
|
487 qreal totalHeight = mEmptySpaceContainer->preferredHeight() + mTitleRow->containerHeight() + mContentContainer->maximumHeight(); |
|
488 //set maximum sizes, otherwise widget will stay huge also when collapsed |
513 //set maximum sizes, otherwise widget will stay huge also when collapsed |
489 setMaximumHeight(totalHeight); |
514 setMaximumHeight(totalHeight); |
490 mMainContainer->setMaximumHeight(totalHeight); |
515 mMainContainer->setMaximumHeight(totalHeight); |
491 mWidgetContainer->setMaximumHeight(totalHeight - mEmptySpaceContainer->preferredHeight()); |
516 mWidgetContainer->setMaximumHeight(totalHeight - mEmptySpaceContainer->preferredHeight()); |
492 //resize here or widget cannot draw mail rows when expanding |
517 //resize here or widget cannot draw mail rows when expanding |
|
518 //TODO: check if this is still needed as list used |
493 resize(mTitleRow->maximumWidth(), totalHeight); |
519 resize(mTitleRow->maximumWidth(), totalHeight); |
494 mMainContainer->resize(mTitleRow->maximumWidth(), totalHeight); |
520 mMainContainer->resize(mTitleRow->maximumWidth(), totalHeight); |
495 mWidgetContainer->resize(mTitleRow->maximumWidth(), totalHeight - mEmptySpaceContainer->preferredHeight()); |
521 mWidgetContainer->resize(mTitleRow->maximumWidth(), totalHeight - mEmptySpaceContainer->preferredHeight()); |
496 |
|
497 updateMailRowsVisibility(mailCount); |
|
498 } |
522 } |
499 |
523 |
500 /*! |
524 /*! |
501 Updates mNoMailsLabel visibility based on widget state |
525 Updates mNoMailsLabel visibility based on widget state |
502 /param mailCount defines how many mail rows is needed |
526 /param mailCount defines how many mail rows is needed |
505 */ |
529 */ |
506 void NmHsWidget::addNoMailsLabelToLayout() |
530 void NmHsWidget::addNoMailsLabelToLayout() |
507 { |
531 { |
508 NM_FUNCTION; |
532 NM_FUNCTION; |
509 |
533 |
510 if (mNoMailsLabel->isVisible() || mMailRows.isEmpty()) { |
534 if ( mNoMailsLabel->isVisible() ) { |
511 return; |
535 return; |
512 } |
536 } |
513 //Add mNoMailsLabel to layout if not yet there and show it |
537 //Add mNoMailsLabel to layout if not yet there and show it |
514 mContentLayout->addItem(mNoMailsLabel); |
538 mContentLayout->addItem(mNoMailsLabel); |
515 //resize the widget to new layout size |
539 //resize the widget to new layout size |
527 mContentLayout->removeItem(mNoMailsLabel); |
551 mContentLayout->removeItem(mNoMailsLabel); |
528 mNoMailsLabel->hide(); |
552 mNoMailsLabel->hide(); |
529 } |
553 } |
530 |
554 |
531 /*! |
555 /*! |
532 addEmailRowsToLayout adds every emailrow to the layout |
556 addEmailRowsToLayout adds list widget to content layout |
533 /post all elements in mMailRows are added to mContentLayout |
|
534 */ |
557 */ |
535 void NmHsWidget::addEmailRowsToLayout() |
558 void NmHsWidget::addEmailRowsToLayout() |
536 { |
559 { |
537 NM_FUNCTION; |
560 NM_FUNCTION; |
538 foreach(NmHsWidgetEmailRow *row, mMailRows) |
561 |
539 { |
562 mContentLayout->addItem(mListView); |
540 mContentLayout->addItem(row); |
563 |
541 } |
564 mListView->setVisible(true); |
542 } |
565 |
543 |
566 } |
544 /*! |
567 |
545 removeEmailRowsFromLayout removes every emailrow from the layout |
568 /*! |
546 /post none of the elements in mMailRows are in mContentLayout |
569 removeEmailRowsFromLayout removes and hides list widget |
|
570 from content layout |
547 */ |
571 */ |
548 void NmHsWidget::removeEmailRowsFromLayout() |
572 void NmHsWidget::removeEmailRowsFromLayout() |
549 { |
573 { |
550 NM_FUNCTION; |
574 NM_FUNCTION; |
551 foreach(NmHsWidgetEmailRow *row, mMailRows) |
575 mContentLayout->removeItem(mListView); |
552 { |
576 mListView->setVisible(false); |
553 mContentLayout->removeItem(row); |
577 } |
554 } |
578 |
555 } |
579 /*! |
556 |
580 openMessage slot |
557 /*! |
581 */ |
558 Updates mail row visibilities in static widget |
582 void NmHsWidget::openMessage(const QModelIndex& index) |
559 /param visibleCount defines how many items do have mail data |
583 { |
560 /post all row items having mail data are visible, other rows are hidden |
584 QVariant var = mListModel->data(index,Qt::DisplayRole); |
561 */ |
585 if(!var.isNull()){ |
562 void NmHsWidget::updateMailRowsVisibility(const int visibleCount) |
586 NmMessageEnvelope *envelope = var.value<NmMessageEnvelope*>(); |
563 { |
587 mEngine->launchMailAppMailViewer(envelope->messageId()); |
564 NM_FUNCTION; |
588 } |
565 |
589 |
566 // set visible as many rows as requested by visibleCount param |
|
567 bool isVisible; |
|
568 |
|
569 for (int i = 0; i < mMailRows.count(); i++) { |
|
570 isVisible = false; |
|
571 if ((mIsExpanded) && (i < visibleCount)) { |
|
572 isVisible = true; |
|
573 } |
|
574 mMailRows.at(i)->setVisible(isVisible); |
|
575 } |
|
576 } |
590 } |
577 |
591 |
578 /*! |
592 /*! |
579 onEngineException (NmHsWidgetEmailEngineExceptionCode exc) |
593 onEngineException (NmHsWidgetEmailEngineExceptionCode exc) |
580 signals widget to be finalized |
594 signals widget to be finalized |