emailuis/nmailui/src/nmmailboxserviceinterface.cpp
changeset 18 578830873419
child 20 ecc8def7944a
equal deleted inserted replaced
4:e7aa27f58ae1 18:578830873419
       
     1 /*
       
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description: NMail application service interface used for displaying the
       
    15  *              messages contained by the given mailbox. The service utilizes
       
    16  *              thr Qt highway framework.
       
    17  */
       
    18 
       
    19 //  INCLUDES
       
    20 #include "nmuiheaders.h" // Includes also the class header.
       
    21 
       
    22 
       
    23 /*!
       
    24     \class NmMailboxServiceInterface
       
    25     \brief A service interface for displaying the messages contained by the
       
    26            given mailbox.
       
    27 */
       
    28 
       
    29 
       
    30 /*!
       
    31     Class constructor.
       
    32 */
       
    33 NmMailboxServiceInterface::NmMailboxServiceInterface(QObject *parent,
       
    34         NmUiEngine &uiEngine,
       
    35         NmApplication *application)
       
    36 #ifndef NM_WINS_ENV
       
    37     : XQServiceProvider(QLatin1String("com.nokia.symbian.IEmailInboxView"), parent),
       
    38 #else
       
    39     : QObject(parent),
       
    40 #endif
       
    41       mUiEngine(uiEngine),
       
    42       mApplication(application),
       
    43       mAsyncReqId(0)
       
    44 {
       
    45 #ifndef NM_WINS_ENV
       
    46     publishAll();
       
    47 #endif
       
    48 }
       
    49 
       
    50 
       
    51 /*!
       
    52     Class desctructor.
       
    53 */
       
    54 NmMailboxServiceInterface::~NmMailboxServiceInterface()
       
    55 {
       
    56 }
       
    57 
       
    58 
       
    59 /*!
       
    60     Called by some external application when the content of a mailbox needs to
       
    61     be viewed.
       
    62     \param data The ID of the mailbox to open.
       
    63 */
       
    64 void NmMailboxServiceInterface::displayInboxByMailboxId(QVariant data)
       
    65 {
       
    66     NMLOG("NmMailboxServiceInterface::displayInboxByMailboxId()");
       
    67 
       
    68 #ifndef NM_WINS_ENV
       
    69 
       
    70     // Get the given ID and convert it into NmId type.
       
    71     NmId mailboxNmId(data.toULongLong());
       
    72 
       
    73     mAsyncReqId = setCurrentRequestAsync();
       
    74 
       
    75     // Verify that the ID matches one of the existing mailboxes.
       
    76     if (mailboxExistsById(mailboxNmId)) {
       
    77 
       
    78         // Get standard folder inbox id.
       
    79         const NmId inboxId = mUiEngine.standardFolderId(mailboxNmId, NmFolderInbox);
       
    80 
       
    81         // Bring the application to the foreground.
       
    82         XQServiceUtil::toBackground(false);
       
    83 
       
    84         // Launch the message list view.
       
    85         NmUiStartParam *startParam =
       
    86             new NmUiStartParam(NmUiViewMessageList,
       
    87                                mailboxNmId,
       
    88                                inboxId, // folder id
       
    89                                0, // message id
       
    90                                NmUiEditorCreateNew, // editor start mode
       
    91                                NULL, // address list
       
    92                                NULL, // attachment list
       
    93                                true); // start as service
       
    94         mApplication->enterNmUiView(startParam);
       
    95 
       
    96         completeRequest(mAsyncReqId, 0);
       
    97     }
       
    98     else {
       
    99         // No mailbox found with the given ID.
       
   100 
       
   101         // if started as embedded, do not hide the app
       
   102 		if (!XQServiceUtil::isEmbedded()) {
       
   103 			XQServiceUtil::toBackground(true);
       
   104 		}
       
   105 
       
   106         completeRequest(mAsyncReqId, 1);
       
   107 
       
   108         // Close the application if started as a service.
       
   109         if (XQServiceUtil::isService()) {
       
   110             connect(this, SIGNAL(returnValueDelivered()),
       
   111                     mApplication, SLOT(delayedExitApplication()));
       
   112         }
       
   113     }
       
   114 #endif
       
   115 }
       
   116 
       
   117 
       
   118 /*!
       
   119     Resolves whether a mailbox with the given ID exists or not.
       
   120     \param mailboxId The mailbox ID to look for.
       
   121     \return True if a mailbox with the given ID exists, false otherwise.
       
   122 */
       
   123 bool NmMailboxServiceInterface::mailboxExistsById(const NmId &mailboxId) const
       
   124 {
       
   125     NMLOG("NmMailboxServiceInterface::mailboxExistsById()");
       
   126 
       
   127     const NmMailboxListModel& mailboxListModel = mUiEngine.mailboxListModel();
       
   128     int mailboxCount = mailboxListModel.rowCount();
       
   129 
       
   130     QModelIndex modelIndex;
       
   131     QVariant mailbox;
       
   132     NmMailboxMetaData *mailboxMetaData = NULL;
       
   133     NmId currentId;
       
   134 
       
   135     // Try to find the mailbox with the given ID.
       
   136     for (int i = 0; i < mailboxCount; ++i) {
       
   137         modelIndex = mailboxListModel.index(i, 0);
       
   138         mailbox = mailboxListModel.data(modelIndex);
       
   139         mailboxMetaData = mailbox.value<NmMailboxMetaData*>();
       
   140         currentId = mailboxMetaData->id();
       
   141 
       
   142         if (currentId.id() == mailboxId.id()) {
       
   143             // Found a mailbox with the matching ID.
       
   144             return true;
       
   145         }
       
   146     }
       
   147 
       
   148     // No mailbox exist with the given ID.
       
   149     return false;
       
   150 }
       
   151 
       
   152 
       
   153 // End of file.