emailuis/nmailui/src/nmsendserviceinterface.cpp
changeset 68 83cc6bae1de8
parent 62 a8c646b56683
equal deleted inserted replaced
67:459da34cdb45 68:83cc6bae1de8
    17 */
    17 */
    18 
    18 
    19 //  INCLUDES
    19 //  INCLUDES
    20 #include "nmuiheaders.h"
    20 #include "nmuiheaders.h"
    21 
    21 
       
    22 
       
    23 
    22 /*!
    24 /*!
    23     \class NmStartParamDataHelper
    25     \class NmStartParamDataHelper
    24     \brief A helper class for processing the data given to the actual service.
    26     \brief A helper class for processing the data given to the actual service.
    25 */
    27 */
    26 class NmStartParamDataHelper
    28 class NmStartParamDataHelper
    29 
    31 
    30     /*!
    32     /*!
    31         Class constructor.
    33         Class constructor.
    32     */
    34     */
    33     inline NmStartParamDataHelper()
    35     inline NmStartParamDataHelper()
    34     : mSubject(0),
    36     : mSubject(NULL),
    35       mToAddresses(0),
    37       mToAddresses(NULL),
    36       mCcAddresses(0),
    38       mCcAddresses(NULL),
    37       mBccAddresses(0),
    39       mBccAddresses(NULL),
    38       mAttachmentList(0),
    40       mAttachmentList(NULL),
    39       mEditorStartMode(NmUiEditorCreateNew)
    41       mEditorStartMode(NmUiEditorCreateNew),
       
    42 	  mBodyText(NULL),
       
    43 	  mMimeType(NULL)
    40     {
    44     {
    41         NM_FUNCTION;
    45         NM_FUNCTION;
    42     }
    46     }
    43 
    47 
    44     /*!
    48     /*!
    55         \return True if success, false otherwise.
    59         \return True if success, false otherwise.
    56     */
    60     */
    57     inline bool extractData(const QVariant &data)
    61     inline bool extractData(const QVariant &data)
    58     {
    62     {
    59         NM_FUNCTION;
    63         NM_FUNCTION;
    60         
    64 
    61         bool success(false);
    65         bool success(false);
    62 
    66 
    63         if (data.canConvert(QVariant::Map)) {
    67         if (data.canConvert(QVariant::Map)) {
    64             // The given data may contain a mail subject and recipient lists.
    68             // The given data may contain a mail subject and recipient lists.
    65             QMap<QString, QVariant> map = data.toMap();
    69             QMap<QString, QVariant> map = data.toMap();
    91         take ownership of the members.
    95         take ownership of the members.
    92     */
    96     */
    93     inline void deleteData()
    97     inline void deleteData()
    94     {
    98     {
    95         NM_FUNCTION;
    99         NM_FUNCTION;
    96         
   100 
    97         delete mSubject;
   101         delete mSubject;
    98         mSubject = 0;
   102         mSubject = NULL;
    99 
   103 
   100         if (mToAddresses) {
   104         if (mToAddresses) {
   101             qDeleteAll(*mToAddresses);
   105             qDeleteAll(*mToAddresses);
   102             delete mToAddresses;
   106             delete mToAddresses;
   103             mToAddresses = 0;
   107             mToAddresses = NULL;
   104         }
   108         }
   105 
   109 
   106         if (mCcAddresses) {
   110         if (mCcAddresses) {
   107             qDeleteAll(*mCcAddresses);
   111             qDeleteAll(*mCcAddresses);
   108             delete mCcAddresses;
   112             delete mCcAddresses;
   109             mCcAddresses = 0;
   113             mCcAddresses = NULL;
   110         }
   114         }
   111 
   115 
   112         if (mBccAddresses) {
   116         if (mBccAddresses) {
   113             qDeleteAll(*mBccAddresses);
   117             qDeleteAll(*mBccAddresses);
   114             delete mBccAddresses;
   118             delete mBccAddresses;
   115             mBccAddresses = 0;
   119             mBccAddresses = NULL;
   116         }
   120         }
   117 
   121 
   118         delete mAttachmentList;
   122         delete mAttachmentList;
   119         mAttachmentList = 0;
   123         mAttachmentList = NULL;
       
   124 
       
   125         delete mBodyText;
       
   126         mBodyText = NULL;
       
   127 		
       
   128 		delete mMimeType;
       
   129 		mMimeType = NULL;
   120     }
   130     }
   121 
   131 
   122 
   132 
   123 private:
   133 private:
   124 
   134 
   128         \return True if success, false otherwise.
   138         \return True if success, false otherwise.
   129     */
   139     */
   130     inline bool processMap(const QMap<QString, QVariant> &map)
   140     inline bool processMap(const QMap<QString, QVariant> &map)
   131     {
   141     {
   132         NM_FUNCTION;
   142         NM_FUNCTION;
   133         
   143 
   134         QMap<QString, QVariant>::const_iterator i = map.constBegin();
   144         QMap<QString, QVariant>::const_iterator i = map.constBegin();
   135         QString key;
   145         QString key;
   136         QVariant value;
   146         QVariant value;
   137 
   147 
   138         while (i != map.constEnd()) {
   148         while (i != map.constEnd()) {
   160             }
   170             }
   161             else if (!key.compare(emailSendBccKey, Qt::CaseInsensitive)) {
   171             else if (!key.compare(emailSendBccKey, Qt::CaseInsensitive)) {
   162                 // Extract the "bcc" recipients.
   172                 // Extract the "bcc" recipients.
   163                 addAddressesToList(value, &mBccAddresses);
   173                 addAddressesToList(value, &mBccAddresses);
   164             }
   174             }
       
   175             else if (!key.compare(emailSendBodyTextKey, Qt::CaseInsensitive)) {
       
   176                 // Make sure only the last bodytext is used
       
   177                 delete mBodyText;
       
   178                 mBodyText = NULL;
       
   179                 // Extract the "body" text
       
   180                 mBodyText = new QString(value.toString());
       
   181             }
       
   182             else if (!key.compare(emailSendAttachmentKey, Qt::CaseInsensitive)) {
       
   183                 // Extract the "attachment" part
       
   184                 if(!mAttachmentList) {
       
   185 				    mAttachmentList = new QStringList();
       
   186 				}
       
   187 				mAttachmentList->append(value.toStringList());
       
   188             }
       
   189             else if (!key.compare(emailSendBodyMimeTypeKey, Qt::CaseInsensitive)) {
       
   190 			    delete mMimeType;
       
   191 				mMimeType = NULL;
       
   192                 // Extract the "mime type" part
       
   193 				mMimeType = new QString(value.toString());
       
   194             }
   165 
   195 
   166             ++i;
   196             ++i;
   167         }
   197         }
   168 
   198 
   169         // In principle it is ok even if the map does not contain any data e.g.
   199         // In principle it is ok even if the map does not contain any data e.g.
   179     */
   209     */
   180     inline void addAddressesToList(const QVariant &addresses,
   210     inline void addAddressesToList(const QVariant &addresses,
   181                                    QList<NmAddress*> **list)
   211                                    QList<NmAddress*> **list)
   182     {
   212     {
   183         NM_FUNCTION;
   213         NM_FUNCTION;
   184         
   214 
   185         if (!list) {
   215         if (!list) {
   186             // Invalid argument!
   216             // Invalid argument!
   187             return;
   217             return;
   188         }
   218         }
   189 
   219 
   191         QList<NmAddress*> foundAddresses;
   221         QList<NmAddress*> foundAddresses;
   192 
   222 
   193         switch (dataType) {
   223         switch (dataType) {
   194             case QVariant::String: {
   224             case QVariant::String: {
   195                 // A single address.
   225                 // A single address.
   196                 NmAddress *address = new NmAddress(addresses.toString());
   226                 NmAddress *address = NmUtilities::qstringToNmAddress(addresses.toString());
   197                 foundAddresses.append(address);
   227                 foundAddresses.append(address);
   198                 break;
   228                 break;
   199             }
   229             }
   200             case QVariant::StringList: {
   230             case QVariant::StringList: {
   201                 // A list of addresses.
   231                 // A list of addresses.
   202                 QStringList addressList = addresses.toStringList();
   232                 QStringList addressList = addresses.toStringList();
   203 
   233 
   204                 foreach (QString addressAsString, addressList) {
   234                 foreach (QString addressAsString, addressList) {
   205                     NmAddress *address = new NmAddress(addressAsString);
   235                     NmAddress *address = NmUtilities::qstringToNmAddress(addressAsString);
   206                     foundAddresses.append(address);
   236                     foundAddresses.append(address);
   207                 }
   237                 }
   208 
   238 
   209                 break;
   239                 break;
   210             }
   240             }
   230     QList<NmAddress*> *mToAddresses; // Not owned.
   260     QList<NmAddress*> *mToAddresses; // Not owned.
   231     QList<NmAddress*> *mCcAddresses; // Not owned.
   261     QList<NmAddress*> *mCcAddresses; // Not owned.
   232     QList<NmAddress*> *mBccAddresses; // Not owned.
   262     QList<NmAddress*> *mBccAddresses; // Not owned.
   233     QStringList *mAttachmentList; // Not owned.
   263     QStringList *mAttachmentList; // Not owned.
   234     NmUiEditorStartMode mEditorStartMode;
   264     NmUiEditorStartMode mEditorStartMode;
       
   265     QString *mBodyText;
       
   266     QString *mMimeType;
   235 };
   267 };
   236 
   268 
   237 
   269 
   238 
   270 
   239 /*!
   271 /*!
   265     Class desctructor.
   297     Class desctructor.
   266 */
   298 */
   267 NmSendServiceInterface::~NmSendServiceInterface()
   299 NmSendServiceInterface::~NmSendServiceInterface()
   268 {
   300 {
   269     NM_FUNCTION;
   301     NM_FUNCTION;
   270     
   302 
   271     delete mStartParam;
   303     delete mStartParam;
   272     delete mSelectionDialog;
   304     delete mSelectionDialog;
   273 }
   305 }
   274 
   306 
   275 
   307 
   279     \return True if a mailbox was selected, false otherwise.
   311     \return True if a mailbox was selected, false otherwise.
   280 */
   312 */
   281 void NmSendServiceInterface::selectionDialogClosed(NmId &mailboxId)
   313 void NmSendServiceInterface::selectionDialogClosed(NmId &mailboxId)
   282 {
   314 {
   283     NM_FUNCTION;
   315     NM_FUNCTION;
   284     
   316 
   285     if (mailboxId.id()) { // mailbox selected
   317     if (mailboxId.id()) { // mailbox selected
   286         launchEditorView(mailboxId);
   318         launchEditorView(mailboxId);
   287     }
   319     }
   288     else {
   320     else {
   289         cancelService();
   321         cancelService();
   302                 subject and recipient data.
   334                 subject and recipient data.
   303 */
   335 */
   304 void NmSendServiceInterface::send(QVariant data)
   336 void NmSendServiceInterface::send(QVariant data)
   305 {
   337 {
   306     NM_FUNCTION;
   338     NM_FUNCTION;
   307     
   339 
   308     HbMainWindow *mainWindow(NULL);
   340     HbMainWindow *mainWindow(NULL);
   309     
   341 
   310     // Make sure that qmail stays background if user presses back in editorview
   342     // Make sure that qmail stays background if user presses back in editorview
   311     if (mApplication) {
   343     if (mApplication) {
   312         mApplication->updateVisibilityState();
   344         mApplication->updateVisibilityState();
   313         
   345 
   314         mainWindow = mApplication->mainWindow();
   346         mainWindow = mApplication->mainWindow();
   315         mCurrentView = mainWindow->currentView();
   347         mCurrentView = mainWindow->currentView();
   316     
   348 
   317         // Hide the current view.
   349         // Hide the current view.
   318         if (mCurrentView) {
   350         if (mCurrentView) {
   319             mCurrentView->hide();
   351             mCurrentView->hide();
   320         }    
   352         }
   321     }
   353     }
   322 
   354 
   323     // Check the given data.
   355     // Check the given data.
   324     NmStartParamDataHelper dataHelper;
   356     NmStartParamDataHelper dataHelper;
   325     bool validData = dataHelper.extractData(data);
   357     bool validData = dataHelper.extractData(data);
   356 	        dataHelper.mToAddresses, // address list
   388 	        dataHelper.mToAddresses, // address list
   357     	    dataHelper.mAttachmentList, // attachment list
   389     	    dataHelper.mAttachmentList, // attachment list
   358         	true, // start as service
   390         	true, // start as service
   359 	        dataHelper.mSubject, // message subject
   391 	        dataHelper.mSubject, // message subject
   360 	        dataHelper.mCcAddresses, // list containing cc recipient addresses
   392 	        dataHelper.mCcAddresses, // list containing cc recipient addresses
   361     	    dataHelper.mBccAddresses // list containing bcc recipient addresses
   393     	    dataHelper.mBccAddresses, // list containing bcc recipient addresses
       
   394     	    dataHelper.mBodyText, // body text
       
   395     	    dataHelper.mMimeType // body text mime type
   362 	    );
   396 	    );
   363 
   397 
   364         if (count == 1) {
   398         if (count == 1) {
   365             // A single mailbox exists.
   399             // A single mailbox exists.
   366             QModelIndex modelIndex = mailboxListModel.index(0, 0);
   400             QModelIndex modelIndex = mailboxListModel.index(0, 0);
   376             }
   410             }
   377 
   411 
   378             if (!XQServiceUtil::isEmbedded()) {
   412             if (!XQServiceUtil::isEmbedded()) {
   379                 XQServiceUtil::toBackground(false);
   413                 XQServiceUtil::toBackground(false);
   380             }
   414             }
   381             
   415 
   382             connect(mSelectionDialog, SIGNAL(selectionDialogClosed(NmId&)),
   416             connect(mSelectionDialog, SIGNAL(selectionDialogClosed(NmId&)),
   383                     this, SLOT(selectionDialogClosed(NmId&)));
   417                     this, SLOT(selectionDialogClosed(NmId&)));
   384             mSelectionDialog->open();
   418             mSelectionDialog->open();
   385 
   419 
   386             // launch the editor when the dialog is closed
   420             // launch the editor when the dialog is closed
   394  */
   428  */
   395 void NmSendServiceInterface::launchEditorView(NmId mailboxId)
   429 void NmSendServiceInterface::launchEditorView(NmId mailboxId)
   396 {
   430 {
   397     NM_FUNCTION;
   431     NM_FUNCTION;
   398     NM_COMMENT(QString("NmSendServiceInterface::launchEditorView(): mailboxId=%1").arg(mailboxId.id()));
   432     NM_COMMENT(QString("NmSendServiceInterface::launchEditorView(): mailboxId=%1").arg(mailboxId.id()));
   399     
   433 
   400     // Make the previous view visible again.
   434     // Make the previous view visible again.
   401     if (mCurrentView) {
   435     if (mCurrentView) {
   402         mCurrentView->show();
   436         mCurrentView->show();
   403         mCurrentView = NULL;
   437         mCurrentView = NULL;
   404     }
   438     }
   405 
   439 
   406     if (mStartParam) {
   440     if (mStartParam) {
   407         // Make sure the NMail application is in the foreground
   441         // Make sure the NMail application is in the foreground
   408         if (!XQServiceUtil::isEmbedded()) {
   442         if (!XQServiceUtil::isEmbedded()) {
   409             XQServiceUtil::toBackground(false);    
   443             XQServiceUtil::toBackground(false);
   410         }
   444         }
   411         
   445 
   412         mStartParam->setMailboxId(mailboxId);
   446         mStartParam->setMailboxId(mailboxId);
   413         mApplication->enterNmUiView(mStartParam);
   447         mApplication->enterNmUiView(mStartParam);
   414         mStartParam = NULL; // ownership passed
   448         mStartParam = NULL; // ownership passed
   415     }
   449     }
   416     completeRequest(mAsyncReqId, 1);
   450     completeRequest(mAsyncReqId, 1);
   418 }
   452 }
   419 
   453 
   420 void NmSendServiceInterface::cancelService()
   454 void NmSendServiceInterface::cancelService()
   421 {
   455 {
   422     NM_FUNCTION;
   456     NM_FUNCTION;
   423     
   457 
   424     delete mStartParam;
   458     delete mStartParam;
   425     mStartParam = NULL;
   459     mStartParam = NULL;
   426 
   460 
   427     // If the service was started as embedded, do not hide the app.
   461     // If the service was started as embedded, do not hide the app.
   428     if (!XQServiceUtil::isEmbedded()) {
   462     if (!XQServiceUtil::isEmbedded()) {