emailuis/nmailui/src/nmmessagelistview.cpp
changeset 54 997a02608b3a
parent 53 bf7eb7911fc5
child 59 16ed8d08d0b1
equal deleted inserted replaced
53:bf7eb7911fc5 54:997a02608b3a
    18 static const char *NMUI_MESSAGE_LIST_VIEW_XML = ":/docml/nmmessagelistview.docml";
    18 static const char *NMUI_MESSAGE_LIST_VIEW_XML = ":/docml/nmmessagelistview.docml";
    19 static const char *NMUI_MESSAGE_LIST_VIEW = "NmMessageListView";
    19 static const char *NMUI_MESSAGE_LIST_VIEW = "NmMessageListView";
    20 static const char *NMUI_MESSAGE_LIST_TREE_LIST = "MessageTreeList";
    20 static const char *NMUI_MESSAGE_LIST_TREE_LIST = "MessageTreeList";
    21 static const char *NMUI_MESSAGE_LIST_NO_MESSAGES = "MessageListNoMessages";
    21 static const char *NMUI_MESSAGE_LIST_NO_MESSAGES = "MessageListNoMessages";
    22 static const char *NMUI_MESSAGE_LIST_FOLDER_LABEL = "labelGroupBox";
    22 static const char *NMUI_MESSAGE_LIST_FOLDER_LABEL = "labelGroupBox";
    23 // Old sync icon implementation commented out but preserved so it could be put back if need be
       
    24 // static const char *NMUI_MESSAGE_LIST_SYNC_ICON = "syncIcon";
       
    25 
    23 
    26 #include "nmuiheaders.h"
    24 #include "nmuiheaders.h"
       
    25 
       
    26 const QString syncIndicatorName = "com.nokia.nmail.indicatorplugin.sync/1.0";
    27 
    27 
    28 /*! 
    28 /*! 
    29 	\class NmMessageListView
    29 	\class NmMessageListView
    30 	\brief Message list view
    30 	\brief Message list view
    31 */
    31 */
    50 mDocumentLoader(documentLoader),
    50 mDocumentLoader(documentLoader),
    51 mItemContextMenu(NULL),
    51 mItemContextMenu(NULL),
    52 mLongPressedItem(NULL),
    52 mLongPressedItem(NULL),
    53 mNoMessagesLabel(NULL),
    53 mNoMessagesLabel(NULL),
    54 mFolderLabel(NULL),
    54 mFolderLabel(NULL),
    55 mSyncIcon(NULL),
       
    56 mViewReady(false),
    55 mViewReady(false),
    57 mCurrentFolderType(NmFolderInbox),
    56 mCurrentFolderType(NmFolderInbox),
    58 mSettingsLaunched(false),
    57 mSettingsLaunched(false),
    59 mPreviousModelCount(0)
    58 mPreviousModelCount(0),
    60 {
    59 mIsFirstSyncInMessageList(true)
    61     NM_FUNCTION;
    60 {
    62 
    61     NM_FUNCTION;
    63     // Load view layout
    62 
    64     loadViewLayout();
    63     loadViewLayout();
    65     //create toolbar
       
    66     createToolBar();
    64     createToolBar();
    67     // Init tree view
       
    68     initTreeView();
    65     initTreeView();
    69     // set title
       
    70     setMailboxName();
    66     setMailboxName();
    71     // Set folder name
       
    72     setFolderName();
    67     setFolderName();
    73 }
    68 }
    74 
    69 
    75 /*!
    70 /*!
    76     Destructor
    71     Destructor
    93 void NmMessageListView::loadViewLayout()
    88 void NmMessageListView::loadViewLayout()
    94 {
    89 {
    95     NM_FUNCTION;
    90     NM_FUNCTION;
    96 
    91 
    97     // Use document loader to load the view
    92     // Use document loader to load the view
    98     bool ok = false;
    93     bool ok(false);
    99     setObjectName(QString(NMUI_MESSAGE_LIST_VIEW));
    94     setObjectName(QString(NMUI_MESSAGE_LIST_VIEW));
   100     QObjectList objectList;
    95     QObjectList objectList;
   101     objectList.append(this);
    96     objectList.append(this);
   102     // Pass the view to documentloader. Document loader uses this view
    97     // Pass the view to documentloader. Document loader uses this view
   103     // when docml is parsed, instead of creating new view.
    98     // when docml is parsed, instead of creating new view.
   104     if (mDocumentLoader) {
    99     if (mDocumentLoader) {
   105         mDocumentLoader->setObjectTree(objectList);
   100         mDocumentLoader->setObjectTree(objectList);
   106         mWidgetList = mDocumentLoader->load(NMUI_MESSAGE_LIST_VIEW_XML, &ok);
   101         mWidgetList = mDocumentLoader->load(NMUI_MESSAGE_LIST_VIEW_XML, &ok);
   107     }
   102     }
   108 
   103 
   109     if (ok == true && mWidgetList.count()) {
   104     if (ok) {
   110         // Get message list widget
   105         // Get message list widget
   111         mMessageListWidget = qobject_cast<HbTreeView *>
   106         mMessageListWidget = qobject_cast<HbTreeView *>
   112             (mDocumentLoader->findWidget(NMUI_MESSAGE_LIST_TREE_LIST));
   107             (mDocumentLoader->findWidget(NMUI_MESSAGE_LIST_TREE_LIST));
   113 
   108 
   114         if (mMessageListWidget) {
   109         if (mMessageListWidget) {
   142             NM_ERROR(1,"nmailui: (no messages) object loading failed");
   137             NM_ERROR(1,"nmailui: (no messages) object loading failed");
   143         }
   138         }
   144 
   139 
   145         mFolderLabel = qobject_cast<HbGroupBox *>(mDocumentLoader->findWidget(NMUI_MESSAGE_LIST_FOLDER_LABEL));
   140         mFolderLabel = qobject_cast<HbGroupBox *>(mDocumentLoader->findWidget(NMUI_MESSAGE_LIST_FOLDER_LABEL));
   146 
   141 
   147         // Disable the old sync icon implementation for the time being (commment out loading the icon here)
       
   148         //mSyncIcon = qobject_cast<HbLabel *>(mDocumentLoader->findWidget(NMUI_MESSAGE_LIST_SYNC_ICON));
       
   149         if (mSyncIcon) {
       
   150             mSyncIcon->setIcon(NmIcons::getIcon(NmIcons::NmIconOffline));
       
   151         }
       
   152 
       
   153         // Connect options menu about to show to create options menu function
   142         // Connect options menu about to show to create options menu function
   154         QObject::connect(menu(), SIGNAL(aboutToShow()),
   143         QObject::connect(menu(), SIGNAL(aboutToShow()),
   155                          this, SLOT(createOptionsMenu()));
   144                          this, SLOT(createOptionsMenu()));
   156         QObject::connect(&mUiEngine, SIGNAL(syncStateEvent(NmSyncState, const NmId &)),
   145         QObject::connect(&mUiEngine, SIGNAL(syncStateEvent(NmSyncState, const NmId &)),
   157                          this, SLOT(handleSyncStateEvent(NmSyncState, const NmId &)));
   146                          this, SLOT(handleSyncStateEvent(NmSyncState, const NmId &)));
   158         QObject::connect(&mUiEngine, SIGNAL(connectionEvent(NmConnectState, const NmId &)),
       
   159                                         this, SLOT(handleConnectionEvent(NmConnectState, const NmId &)));
       
   160 
   147 
   161         // Menu needs one dummy item so that aboutToShow signal is emitted.
   148         // Menu needs one dummy item so that aboutToShow signal is emitted.
   162         NmAction *dummy = new NmAction(0);
   149         NmAction *dummy = new NmAction(0);
   163         menu()->addAction(dummy);
   150         menu()->addAction(dummy);
   164     }
   151     }
   233 
   220 
   234 
   221 
   235 /*!
   222 /*!
   236     Reload view contents with new start parameters
   223     Reload view contents with new start parameters
   237     Typically when view is already open and external view activation occurs
   224     Typically when view is already open and external view activation occurs
   238     for this same view
   225     for this same view. Startparam ownership is transferred to this view
   239 */
   226 */
   240 void NmMessageListView::reloadViewContents(NmUiStartParam* startParam)
   227 void NmMessageListView::reloadViewContents(NmUiStartParam* startParam)
   241 {
   228 {
   242     NM_FUNCTION;
   229     NM_FUNCTION;
   243 
   230 
   279 */
   266 */
   280 void NmMessageListView::refreshList()
   267 void NmMessageListView::refreshList()
   281 {
   268 {
   282     NM_FUNCTION;
   269     NM_FUNCTION;
   283 
   270 
   284     NmId mailboxId = mMessageListModel->currentMailboxId();
   271     if (mMessageListModel) {
   285     if (mSyncIcon && mailboxId == mMessageListModel->currentMailboxId()) {
   272         NmId mailboxId = mMessageListModel->currentMailboxId();    
   286         if (mUiEngine.syncState(mailboxId) == Synchronizing) {
   273         // In each refresh, e.g. in folder change the UI signals
   287             mSyncIcon->setIcon(NmIcons::getIcon(NmIcons::NmIconSynching));
   274         // lower layer about the folder that has been opened.
   288         }
   275         if (mStartParam){
   289         else {
   276             mUiEngine.updateActiveFolder(mailboxId, mStartParam->folderId());
   290             if (mUiEngine.connectionState(mailboxId) == Connected) {
   277             
   291                 mSyncIcon->setIcon(NmIcons::getIcon(NmIcons::NmIconOnline));
   278             NmFolderType folderType = mUiEngine.folderTypeById(mStartParam->mailboxId(),
   292             }
   279                                               mStartParam->folderId());
   293             else {
   280             if (folderType == NmFolderInbox) { // If the new folder is an inbox, first automatic sync should be shown
   294                 mSyncIcon->setIcon(NmIcons::getIcon(NmIcons::NmIconOffline));
   281                 mIsFirstSyncInMessageList = true; 
   295             }
   282             }
   296         }
   283         }
   297     }
   284 
   298 
   285         // Set item model to message list widget
   299     // In each refresh, e.g. in folder change the UI signals
   286         if (mMessageListWidget) {
   300     // lower layer about the folder that has been opened.
   287             mMessageListWidget->setModel(static_cast<QStandardItemModel*>(mMessageListModel));
   301     if (mStartParam){
   288             QObject::connect(mMessageListModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)),
   302         mUiEngine.updateActiveFolder(mailboxId, mStartParam->folderId());
   289                     this, SLOT(itemsAdded(const QModelIndex&,int,int)));
   303     }
   290             QObject::connect(mMessageListModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)),
   304 
   291                     this, SLOT(itemsRemoved()));
   305     // Set item model to message list widget
   292             QObject::connect(mMessageListModel, SIGNAL(setNewParam(NmUiStartParam*)),
   306     if (mMessageListWidget) {
   293                     this, SLOT(reloadViewContents(NmUiStartParam*)));
   307         mMessageListWidget->setModel(static_cast<QStandardItemModel*>(mMessageListModel));
   294 
   308         QObject::connect(mMessageListModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)),
   295             mPreviousModelCount=mMessageListModel->rowCount();
   309                 this, SLOT(itemsAdded(const QModelIndex&,int,int)));
   296             if (mPreviousModelCount==0){
   310         QObject::connect(mMessageListModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)),
   297                 showNoMessagesText();
   311                 this, SLOT(itemsRemoved()));
   298             }
   312         QObject::connect(mMessageListModel, SIGNAL(setNewParam(NmUiStartParam*)),
   299             else{
   313                 this, SLOT(reloadViewContents(NmUiStartParam*)));
   300                 hideNoMessagesText();
   314 
   301             }
   315         mPreviousModelCount=mMessageListModel->rowCount();
   302         }    
   316         if (mPreviousModelCount==0){
       
   317             showNoMessagesText();
       
   318         }
       
   319         else{
       
   320             hideNoMessagesText();
       
   321         }
       
   322     }
   303     }
   323 }
   304 }
   324 
   305 
   325 /*!
   306 /*!
   326     Sync state event handling
   307     Sync state event handling
   327 */
   308 */
   328 void NmMessageListView::handleSyncStateEvent(NmSyncState syncState, const NmId & mailboxId)
   309 void NmMessageListView::handleSyncStateEvent(NmSyncState syncState, const NmId & mailboxId)
   329 {
   310 {
   330     NM_FUNCTION;
   311     NM_FUNCTION;
   331 
   312     if (mMessageListModel && mailboxId == mMessageListModel->currentMailboxId()) {
   332     if (mSyncIcon && mailboxId == mMessageListModel->currentMailboxId()) {
       
   333         if (syncState == Synchronizing) {
   313         if (syncState == Synchronizing) {
   334             mSyncIcon->setIcon(NmIcons::getIcon(NmIcons::NmIconSynching));
   314              // before first sync inbox id might be zero
   335             // before first sync inbox id might be zero
       
   336             if (mStartParam->folderId() == 0) {
   315             if (mStartParam->folderId() == 0) {
   337                 // after sync inbox id should be updated to correct value
   316                 // after sync inbox id should be updated to correct value
   338                 NmId folderId = mUiEngine.standardFolderId(
   317                 NmId folderId = mUiEngine.standardFolderId(
   339                     mStartParam->mailboxId(),
   318                     mStartParam->mailboxId(),
   340                     NmFolderInbox);
   319                     NmFolderInbox);
   341                 mStartParam->setFolderId(folderId);
   320                 mStartParam->setFolderId(folderId);
   342             }
   321             }
   343         }
   322             // Show sync icon only for the first automatic sync after opening message list.
   344         else {
   323             // Sync icon for manual sync is shown in NmUiEngine::refreshMailbox, not here.
   345             if (mUiEngine.connectionState(mailboxId) == Connected) {
   324             if (mIsFirstSyncInMessageList) {
   346                 mSyncIcon->setIcon(NmIcons::getIcon(NmIcons::NmIconOnline));
   325                 HbIndicator indicator;
   347             }
   326                 indicator.activate(syncIndicatorName, QVariant());
   348             else {
   327                 mIsFirstSyncInMessageList = false;
   349                 mSyncIcon->setIcon(NmIcons::getIcon(NmIcons::NmIconOffline));
   328             }
   350             }
       
   351         }
       
   352     }
       
   353 }
       
   354 
       
   355 /*!
       
   356     Connection event handling
       
   357 */
       
   358 void NmMessageListView::handleConnectionEvent(NmConnectState connectState, const NmId &mailboxId)
       
   359 {
       
   360     NM_FUNCTION;
       
   361 
       
   362     if (mSyncIcon && mailboxId == mMessageListModel->currentMailboxId() && mUiEngine.syncState(mailboxId) != Synchronizing) {
       
   363         if (connectState == Connected) {
       
   364             mSyncIcon->setIcon(NmIcons::getIcon(NmIcons::NmIconOnline));
       
   365         }
       
   366         else {
       
   367             mSyncIcon->setIcon(NmIcons::getIcon(NmIcons::NmIconOffline));
       
   368         }
   329         }
   369     }
   330     }
   370 }
   331 }
   371 
   332 
   372 /*! 
   333 /*!