emailuis/nmailui/src/nmmailboxserviceinterface.cpp
branchRCL_3
changeset 63 d189ee25cf9d
equal deleted inserted replaced
61:dcf0eedfc1a3 63:d189ee25cf9d
       
     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     : XQServiceProvider(emailFullServiceNameMailbox, parent),
       
    37       mUiEngine(uiEngine),
       
    38       mApplication(application),
       
    39       mAsyncReqId(0)
       
    40 {
       
    41     publishAll();
       
    42 }
       
    43 
       
    44 
       
    45 /*!
       
    46     Class desctructor.
       
    47 */
       
    48 NmMailboxServiceInterface::~NmMailboxServiceInterface()
       
    49 {
       
    50     NM_FUNCTION;
       
    51 }
       
    52 
       
    53 
       
    54 /*!
       
    55     Called by some external application when the content of a mailbox needs to
       
    56     be viewed.
       
    57     \param data The ID of the mailbox to open.
       
    58 */
       
    59 void NmMailboxServiceInterface::displayInboxByMailboxId(QVariant data)
       
    60 {
       
    61     NM_FUNCTION;
       
    62 
       
    63 
       
    64     // Get the given ID and convert it into NmId type.
       
    65     NmId mailboxNmId(data.toULongLong());
       
    66 
       
    67     mAsyncReqId = setCurrentRequestAsync();
       
    68 
       
    69     // Make sure that app stays background if user presses back in message list view
       
    70     bool visible = mApplication->updateVisibilityState();
       
    71 
       
    72     if (mailboxExistsById(mailboxNmId)) {
       
    73         // Fetch inbox id
       
    74         NmId inboxId = mUiEngine.standardFolderId(mailboxNmId, NmFolderInbox);
       
    75         // Bring the application to the foreground.
       
    76         if (!XQServiceUtil::isEmbedded()) {
       
    77             XQServiceUtil::toBackground(false);
       
    78         }
       
    79         if (mApplication) {
       
    80             HbMainWindow *mainWindow = mApplication->mainWindow();
       
    81             mainWindow->show();
       
    82 
       
    83             // Launch the message list view.
       
    84             NmUiStartParam *startParam =
       
    85                 new NmUiStartParam(NmUiViewMessageList,
       
    86                                    mailboxNmId,
       
    87                                    inboxId, // folder id
       
    88                                    0, // message id
       
    89                                    NmUiEditorCreateNew, // editor start mode
       
    90                                    NULL, // address list
       
    91                                    NULL, // attachment list
       
    92                                    true); // start as service
       
    93             mApplication->enterNmUiView(startParam);
       
    94         }
       
    95 
       
    96         completeRequest(mAsyncReqId, 0);
       
    97     }
       
    98     else {
       
    99         // No mailbox found with the given ID or Inbox ID is not known
       
   100 
       
   101         // if started as embedded, do not hide the app
       
   102 		if (!XQServiceUtil::isEmbedded() && !visible) {
       
   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 }
       
   115 
       
   116 
       
   117 /*!
       
   118     Resolves whether a mailbox with the given ID exists or not.
       
   119     \param mailboxId The mailbox ID to look for.
       
   120     \return True if a mailbox with the given ID exists, false otherwise.
       
   121 */
       
   122 bool NmMailboxServiceInterface::mailboxExistsById(const NmId &mailboxId) const
       
   123 {
       
   124     NM_FUNCTION;
       
   125 
       
   126     const NmMailboxListModel& mailboxListModel = mUiEngine.mailboxListModel();
       
   127     int mailboxCount = mailboxListModel.rowCount();
       
   128 
       
   129     QModelIndex modelIndex;
       
   130     QVariant mailbox;
       
   131     NmMailboxMetaData *mailboxMetaData = NULL;
       
   132     NmId currentId;
       
   133 
       
   134     // Try to find the mailbox with the given ID.
       
   135     for (int i = 0; i < mailboxCount; ++i) {
       
   136         modelIndex = mailboxListModel.index(i, 0);
       
   137         mailbox = mailboxListModel.data(modelIndex);
       
   138         mailboxMetaData = mailbox.value<NmMailboxMetaData*>();
       
   139         if (mailboxMetaData) {
       
   140             currentId = mailboxMetaData->id();
       
   141         }
       
   142 
       
   143         if (currentId.id() == mailboxId.id()) {
       
   144             // Found a mailbox with the matching ID.
       
   145             return true;
       
   146         }
       
   147     }
       
   148 
       
   149     // No mailbox exist with the given ID.
       
   150     return false;
       
   151 }
       
   152 
       
   153 
       
   154 // End of file.