emailuis/nmailui/src/nmsendserviceinterface.cpp
changeset 27 9ba4404ef423
parent 23 2dc6caa42ec3
child 30 759dc5235cdb
equal deleted inserted replaced
23:2dc6caa42ec3 27:9ba4404ef423
    52         \param data QVariant containing the data.
    52         \param data QVariant containing the data.
    53         \return True if success, false otherwise.
    53         \return True if success, false otherwise.
    54     */
    54     */
    55     inline bool extractData(const QVariant &data)
    55     inline bool extractData(const QVariant &data)
    56     {
    56     {
    57         QVariant::Type dataType = data.type();
       
    58         bool success = false;
    57         bool success = false;
    59 
    58 
    60         switch (dataType) {
    59         if (data.canConvert(QVariant::Map)) {
    61             case QVariant::String: {
    60             // The given data may contain a mail subject and recipient lists.
    62                 // The given data contains a single attachment.
    61             QMap<QString, QVariant> map = data.toMap();
    63                 QString attachment = data.toString();
    62             success = processMap(map);
    64                 mAttachmentList = new QStringList(attachment);
    63         }
    65                 success = true;
    64         else if (data.canConvert(QVariant::StringList)) {
    66                 break;
    65             QStringList attachmentList = data.toStringList();
    67             }
    66             mAttachmentList = new QStringList(attachmentList);
    68             case QVariant::StringList: {
    67             success = true;
    69                 // The given data contains a list of attachments.
    68         }
    70                 QStringList attachmentList = data.toStringList();
    69         else {
    71                 mAttachmentList = new QStringList(attachmentList);
    70             // Data type not supported!
    72                 success = true;
    71             NMLOG(QString("NmStartParamDataHelper::extractData(): Data type %1 not supported!").
    73                 break;
    72                 arg(data.type()));
    74             }
    73         }
    75             case QVariant::Map: {
       
    76                 // The given data may contain a mail subject and recipient lists.
       
    77                 QMap<QString, QVariant> map = data.toMap();
       
    78                 success = processMap(map);
       
    79                 break;
       
    80             }
       
    81             default: {
       
    82                 // Data type not supported!
       
    83                 NMLOG("NmStartParamDataHelper::extractData(): Data type not supported!");
       
    84                 break;
       
    85             }
       
    86         } // switch ()
       
    87 
    74 
    88         // Determine the editor start mode.
    75         // Determine the editor start mode.
    89         if (mToAddresses || mCcAddresses || mBccAddresses) {
    76         if (mToAddresses || mCcAddresses || mBccAddresses) {
    90             mEditorStartMode = NmUiEditorMailto;
    77             mEditorStartMode = NmUiEditorMailto;
    91         }
    78         }
   287     \param mailboxId Where the ID of the selected mailbox is set.
   274     \param mailboxId Where the ID of the selected mailbox is set.
   288     \return True if a mailbox was selected, false otherwise.
   275     \return True if a mailbox was selected, false otherwise.
   289 */
   276 */
   290 void NmSendServiceInterface::selectionDialogClosed(NmId &mailboxId)
   277 void NmSendServiceInterface::selectionDialogClosed(NmId &mailboxId)
   291 {
   278 {
   292     NMLOG("NmSendServiceInterface::selectionDialogClosed");
   279     NMLOG(QString("NmSendServiceInterface::selectionDialogClosed %1").arg(mailboxId.id()));
   293     if (mailboxId.id()) { // mailbox selected
   280     if (mailboxId.id()) { // mailbox selected
   294         launchEditorView(mailboxId);
   281         launchEditorView(mailboxId);
   295     }
   282     }
   296     else {
   283     else {
   297         cancelService();
   284         cancelService();
   329     NmMailboxListModel &mailboxListModel = mUiEngine.mailboxListModel();
   316     NmMailboxListModel &mailboxListModel = mUiEngine.mailboxListModel();
   330     const int count = mailboxListModel.rowCount();
   317     const int count = mailboxListModel.rowCount();
   331     NmId mailboxId(0);
   318     NmId mailboxId(0);
   332 
   319 
   333     mAsyncReqId = setCurrentRequestAsync();
   320     mAsyncReqId = setCurrentRequestAsync();
   334     
   321 
   335     if (!validData) {
   322     if (!validData) {
   336         // Failed to extract the data!
   323         // Failed to extract the data!
   337         NMLOG("NmSendServiceInterface::send(): Failed to process the given data!");
   324         NMLOG("NmSendServiceInterface::send(): Failed to process the given data!");
   338         cancelService();
   325         cancelService();
   339     }
   326     }
   340     else if (count == 0) {
   327     else if (count == 0) {
   341         // No mailboxes.
       
   342         if (mainWindow) {
       
   343             mainWindow->hide();
       
   344         }
       
   345 
       
   346         // Hide the app if it not embedded
       
   347         if (!XQServiceUtil::isEmbedded()) {
       
   348             XQServiceUtil::toBackground(true);
       
   349         }
       
   350 
       
   351         HbDeviceMessageBox note(hbTrId("txt_mail_dialog_no_mailboxes_defined"),
   328         HbDeviceMessageBox note(hbTrId("txt_mail_dialog_no_mailboxes_defined"),
   352                           HbMessageBox::MessageTypeInformation);
   329                           HbMessageBox::MessageTypeInformation);
   353         note.setTimeout(HbMessageBox::NoTimeout);
   330         note.setTimeout(HbMessageBox::NoTimeout);
   354         note.exec();
   331         note.show();
   355         if (mainWindow) {
       
   356             mainWindow->show();
       
   357         }
       
   358         cancelService();
   332         cancelService();
   359     }
   333     }
   360     else { // count > 0
   334     else { // count > 0
   361         // Make sure the NMail application is in the foreground.
   335         // Make sure the NMail application is in the foreground.
   362         XQServiceUtil::toBackground(false);
   336         XQServiceUtil::toBackground(false);
       
   337         mainWindow->show();
   363 
   338 
   364     	mStartParam = new NmUiStartParam(
   339     	mStartParam = new NmUiStartParam(
   365         	NmUiViewMessageEditor,
   340         	NmUiViewMessageEditor,
   366 	        0, // account id
   341 	        0, // account id
   367 	        0, // folder id
   342 	        0, // folder id
   399 
   374 
   400 /*!
   375 /*!
   401     Called when mailbox id is know and editor can be opened
   376     Called when mailbox id is know and editor can be opened
   402     \param mailboxId mailbox using in editor
   377     \param mailboxId mailbox using in editor
   403  */
   378  */
   404 void NmSendServiceInterface::launchEditorView(NmId mailboxId) 
   379 void NmSendServiceInterface::launchEditorView(NmId mailboxId)
   405 {
   380 {
   406     NMLOG(QString("NmSendServiceInterface::launchEditorView %1").arg(mailboxId.id()));
   381     NMLOG(QString("NmSendServiceInterface::launchEditorView %1").arg(mailboxId.id()));
   407     // Make the previous view visible again.
   382     // Make the previous view visible again.
   408     if (mCurrentView) {
   383     if (mCurrentView) {
   409         mCurrentView->show();
   384         mCurrentView->show();
   410         mCurrentView = NULL;        
   385         mCurrentView = NULL;
   411     }
   386     }
   412     
   387 
   413     if (mStartParam) {
   388     if (mStartParam) {
   414         mStartParam->setMailboxId(mailboxId);
   389         mStartParam->setMailboxId(mailboxId);
   415         mApplication->enterNmUiView(mStartParam);
   390         mApplication->enterNmUiView(mStartParam);
   416         mStartParam = NULL; // ownership passed
   391         mStartParam = NULL; // ownership passed
   417     }
   392     }
   418     completeRequest(mAsyncReqId, 1);
   393     completeRequest(mAsyncReqId, 1);
   419 }
   394     mAsyncReqId = 0;
   420 
   395 }
   421 void NmSendServiceInterface::cancelService() 
   396 
       
   397 void NmSendServiceInterface::cancelService()
   422 {
   398 {
   423     NMLOG("NmSendServiceInterface::cancelService");
   399     NMLOG("NmSendServiceInterface::cancelService");
   424     delete mStartParam;
   400     delete mStartParam;
   425     mStartParam = NULL;
   401     mStartParam = NULL;
   426 
   402 
   428     if (!XQServiceUtil::isEmbedded()) {
   404     if (!XQServiceUtil::isEmbedded()) {
   429         XQServiceUtil::toBackground(true);
   405         XQServiceUtil::toBackground(true);
   430     }
   406     }
   431 
   407 
   432     completeRequest(mAsyncReqId, 0);
   408     completeRequest(mAsyncReqId, 0);
       
   409     mAsyncReqId = 0;
   433 
   410 
   434     // If started as service, the application must be closed now.
   411     // If started as service, the application must be closed now.
   435     if (XQServiceUtil::isService()) {
   412     if (XQServiceUtil::isService()) {
   436         connect(this, SIGNAL(returnValueDelivered()),
   413         connect(this, SIGNAL(returnValueDelivered()),
   437             mApplication, SLOT(delayedExitApplication()));
   414             mApplication, SLOT(delayedExitApplication()));