228 { |
228 { |
229 NM_FUNCTION; |
229 NM_FUNCTION; |
230 |
230 |
231 // Check start parameter validity, message view cannot |
231 // Check start parameter validity, message view cannot |
232 // be updated if given parameter is zero. |
232 // be updated if given parameter is zero. |
233 if (startParam&&startParam->viewId()==NmUiViewMessageList&& |
233 if (startParam&&startParam->viewId()==NmUiViewMessageList && |
234 startParam->folderId()!=0) { |
234 startParam->folderId()!=0) { |
235 // Delete existing start parameter data |
235 // Delete existing start parameter data |
236 delete mStartParam; |
236 delete mStartParam; |
237 mStartParam=NULL; |
237 mStartParam = NULL; |
238 // Store new start parameter data |
238 // Store new start parameter data |
239 mStartParam=startParam; |
239 mStartParam = startParam; |
240 // Update the model with new parameters |
240 // Disconnect signals from previous model |
|
241 QObject::disconnect(mMessageListModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), |
|
242 this, SLOT(itemsAdded(const QModelIndex&,int,int))); |
|
243 QObject::disconnect(mMessageListModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), |
|
244 this, SLOT(itemsRemoved())); |
|
245 QObject::disconnect(mMessageListModel, SIGNAL(setNewParam(NmUiStartParam*)), |
|
246 this, SLOT(reloadViewContents(NmUiStartParam*))); |
|
247 // Update model pointer and refresh mailbox with new model |
241 mMessageListModel = &mUiEngine.messageListModel(startParam->mailboxId(), startParam->folderId()); |
248 mMessageListModel = &mUiEngine.messageListModel(startParam->mailboxId(), startParam->folderId()); |
|
249 |
242 refreshList(); |
250 refreshList(); |
243 // Refresh the mailboxname |
251 |
|
252 // Refresh the mailbox name |
244 setMailboxName(); |
253 setMailboxName(); |
|
254 |
|
255 // Store active folder type |
|
256 mCurrentFolderType = mUiEngine.folderTypeById(startParam->mailboxId(),startParam->folderId()); |
|
257 |
|
258 // Update folder name |
|
259 setFolderName(); |
|
260 |
|
261 // Set sync icon if needed |
|
262 updateSyncIcon(); |
245 } |
263 } |
246 else { |
264 else { |
247 NM_ERROR(1,"nmailui: invalid message list start parameter"); |
265 NM_ERROR(1,"nmailui: invalid message list start parameter"); |
248 // Unused start parameter needs to be deleted |
266 // Unused start parameter needs to be deleted |
249 delete startParam; |
267 delete startParam; |
250 } |
268 } |
251 } |
269 } |
252 |
270 |
253 |
271 |
254 /*! |
272 /*! |
255 Return view id |
273 Return view id |
256 */ |
274 */ |
257 NmUiViewId NmMessageListView::nmailViewId() const |
275 NmUiViewId NmMessageListView::nmailViewId() const |
258 { |
276 { |
267 void NmMessageListView::refreshList() |
285 void NmMessageListView::refreshList() |
268 { |
286 { |
269 NM_FUNCTION; |
287 NM_FUNCTION; |
270 |
288 |
271 if (mMessageListModel) { |
289 if (mMessageListModel) { |
272 NmId mailboxId = mMessageListModel->currentMailboxId(); |
290 NmId mailboxId = mMessageListModel->currentMailboxId(); |
273 // In each refresh, e.g. in folder change the UI signals |
291 // In each refresh, e.g. in folder change the UI signals |
274 // lower layer about the folder that has been opened. |
292 // lower layer about the folder that has been opened. |
275 if (mStartParam){ |
293 if (mStartParam){ |
276 mUiEngine.updateActiveFolder(mailboxId, mStartParam->folderId()); |
294 mUiEngine.updateActiveFolder(mailboxId, mStartParam->folderId()); |
277 |
295 |
278 NmFolderType folderType = mUiEngine.folderTypeById(mStartParam->mailboxId(), |
296 NmFolderType folderType = mUiEngine.folderTypeById(mStartParam->mailboxId(), |
279 mStartParam->folderId()); |
297 mStartParam->folderId()); |
280 if (folderType == NmFolderInbox) { // If the new folder is an inbox, first automatic sync should be shown |
298 if (folderType == NmFolderInbox) { // If the new folder is an inbox, first automatic sync should be shown |
281 mIsFirstSyncInMessageList = true; |
299 mIsFirstSyncInMessageList = true; |
282 } |
300 } |
283 } |
301 } |
284 |
302 |
285 // Set item model to message list widget |
303 // Set item model to message list widget |
286 if (mMessageListWidget) { |
304 if (mMessageListWidget) { |
287 mMessageListWidget->setModel(static_cast<QStandardItemModel*>(mMessageListModel)); |
305 mMessageListWidget->setModel(static_cast<QStandardItemModel*>(mMessageListModel)); |
288 QObject::connect(mMessageListModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), |
306 QObject::connect(mMessageListModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), |
289 this, SLOT(itemsAdded(const QModelIndex&,int,int))); |
307 this, SLOT(itemsAdded(const QModelIndex&,int,int)),Qt::UniqueConnection); |
290 QObject::connect(mMessageListModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), |
308 QObject::connect(mMessageListModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), |
291 this, SLOT(itemsRemoved())); |
309 this, SLOT(itemsRemoved()),Qt::UniqueConnection); |
292 QObject::connect(mMessageListModel, SIGNAL(setNewParam(NmUiStartParam*)), |
310 QObject::connect(mMessageListModel, SIGNAL(setNewParam(NmUiStartParam*)), |
293 this, SLOT(reloadViewContents(NmUiStartParam*))); |
311 this, SLOT(reloadViewContents(NmUiStartParam*)),Qt::UniqueConnection); |
294 |
312 |
295 mPreviousModelCount=mMessageListModel->rowCount(); |
313 mPreviousModelCount=mMessageListModel->rowCount(); |
296 if (mPreviousModelCount==0){ |
314 if (mPreviousModelCount==0){ |
297 showNoMessagesText(); |
315 showNoMessagesText(); |
298 } |
316 } |
299 else{ |
317 else{ |
300 hideNoMessagesText(); |
318 hideNoMessagesText(); |
301 } |
319 } |
302 } |
320 } |
303 } |
321 } |
304 } |
322 } |
305 |
323 |
306 /*! |
324 /*! |
307 Sync state event handling |
325 Sync state event handling |
308 */ |
326 */ |
309 void NmMessageListView::handleSyncStateEvent(NmSyncState syncState, const NmId & mailboxId) |
327 void NmMessageListView::handleSyncStateEvent(NmSyncState syncState, const NmId &mailboxId) |
310 { |
328 { |
311 NM_FUNCTION; |
329 NM_FUNCTION; |
312 if (mMessageListModel && mailboxId == mMessageListModel->currentMailboxId()) { |
330 if (mMessageListModel && mailboxId == mMessageListModel->currentMailboxId()) { |
313 if (syncState == Synchronizing) { |
331 if (syncState == Synchronizing) { |
314 // before first sync inbox id might be zero |
332 // before first sync inbox id might be zero |
320 mStartParam->setFolderId(folderId); |
338 mStartParam->setFolderId(folderId); |
321 } |
339 } |
322 // Show sync icon only for the first automatic sync after opening message list. |
340 // Show sync icon only for the first automatic sync after opening message list. |
323 // Sync icon for manual sync is shown in NmUiEngine::refreshMailbox, not here. |
341 // Sync icon for manual sync is shown in NmUiEngine::refreshMailbox, not here. |
324 if (mIsFirstSyncInMessageList) { |
342 if (mIsFirstSyncInMessageList) { |
325 HbIndicator indicator; |
343 mUiEngine.enableSyncIndicator(true); |
326 indicator.activate(syncIndicatorName, QVariant()); |
|
327 mIsFirstSyncInMessageList = false; |
344 mIsFirstSyncInMessageList = false; |
328 } |
345 } |
329 } |
346 } |
330 } |
347 } |
331 } |
348 } |
332 |
349 |
333 /*! |
350 /*! |
334 folder selection handling within current mailbox |
351 folder selection handling within current mailbox |
335 */ |
352 */ |
336 void NmMessageListView::folderSelected() |
353 void NmMessageListView::folderSelected() |
337 { |
354 { |
338 NM_FUNCTION; |
355 NM_FUNCTION; |
348 // Store active folder type |
365 // Store active folder type |
349 mCurrentFolderType = mUiEngine.folderTypeById(startParam->mailboxId(),startParam->folderId()); |
366 mCurrentFolderType = mUiEngine.folderTypeById(startParam->mailboxId(),startParam->folderId()); |
350 // Reload view, ownership of the startparams is passed and old startparams |
367 // Reload view, ownership of the startparams is passed and old startparams |
351 // are deleted within reloadViewContents function |
368 // are deleted within reloadViewContents function |
352 reloadViewContents(startParam); |
369 reloadViewContents(startParam); |
353 //Set folder text to status bar |
370 // Set folder text to status bar |
354 setFolderName(); |
371 setFolderName(); |
355 } |
372 } |
356 } |
373 } |
357 |
374 |
358 |
375 |
359 /*! |
376 /*! |
360 Long keypress handling |
377 Long keypress handling |
361 */ |
378 */ |
362 void NmMessageListView::showItemContextMenu(HbAbstractViewItem *listViewItem, const QPointF &coords) |
379 void NmMessageListView::showItemContextMenu(HbAbstractViewItem *listViewItem, const QPointF &coords) |
363 { |
380 { |
364 NM_FUNCTION; |
381 NM_FUNCTION; |
365 |
382 |
366 if (listViewItem) { |
383 if (listViewItem) { |
367 // Recreate item context menu each time it is called |
384 // Recreate item context menu each time it is called |
368 if (mItemContextMenu){ |
385 if (mItemContextMenu){ |
369 mItemContextMenu->clearActions(); |
386 mItemContextMenu->clearActions(); |
370 delete mItemContextMenu; |
387 delete mItemContextMenu; |
371 mItemContextMenu=NULL; |
388 mItemContextMenu=NULL; |
372 } |
389 } |
373 mItemContextMenu = new HbMenu(); |
390 mItemContextMenu = new HbMenu(); |
374 // Store long press item for later use with response |
391 // Store long press item for later use with response |
375 mLongPressedItem = mMessageListModel->data( |
392 mLongPressedItem = mMessageListModel->data( |