messagingapp/msgui/unifiededitor/src/msgunieditorview.cpp
branchRCL_3
changeset 26 ebe688cedc25
equal deleted inserted replaced
25:fa1df4b99609 26:ebe688cedc25
       
     1 /*
       
     2  * Copyright (c) 2009 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:
       
    15  *
       
    16  */
       
    17 
       
    18 // SYSTEM INCLUDES
       
    19 #include <e32base.h>
       
    20 #include <HbMenu>
       
    21 #include <HbAction>
       
    22 #include <HbToolBar>
       
    23 #include <QGraphicsLinearLayout>
       
    24 #include <HbGroupBox>
       
    25 #include <HbScrollArea>
       
    26 #include <QDateTime>
       
    27 #include <QDir>
       
    28 #include <QBuffer>
       
    29 #include <QFile>
       
    30 #include <QFileInfo>
       
    31 #include <xqconversions.h>
       
    32 #include <HbToolBarExtension>
       
    33 #include <HbListWidget>
       
    34 #include <HbFrameBackground>
       
    35 #include <HbListViewItem>
       
    36 #include <HbListWidgetItem>
       
    37 #include <HbNotificationDialog>
       
    38 #include <HbDeviceNotificationDialog>
       
    39 #include <HbMessageBox>
       
    40 #include <HbAbstractVkbHost>
       
    41 #include <HbMainWindow>
       
    42 #include <xqaiwrequest.h>
       
    43 #include <xqappmgr.h>
       
    44 #include <HbStyleLoader>
       
    45 // QT Mobility for fetching business card
       
    46 #include <qmobilityglobal.h>
       
    47 #include <qversitwriter.h>
       
    48 #include <qversitdocument.h>
       
    49 #include <qcontact.h>
       
    50 #include <qcontactmanager.h>
       
    51 #include <qversitcontactexporter.h>
       
    52 #include <cntservicescontact.h>
       
    53 #include <commonphoneparser.h>      // Common phone number validity checker
       
    54 
       
    55 // USER INCLUDES
       
    56 #include "debugtraces.h"
       
    57 #include "msgunieditorview.h"
       
    58 #include "msgunieditoraddress.h"
       
    59 #include "msgunieditorsubject.h"
       
    60 #include "msgunieditorbody.h"
       
    61 #include "msgunieditormonitor.h"
       
    62 #include "msgunieditorattachmentcontainer.h"
       
    63 #include "msgsendutil.h"
       
    64 #include "convergedmessageaddress.h"
       
    65 #include "UniEditorGenUtils.h"
       
    66 #include "unieditorpluginloader.h"
       
    67 #include "unieditorplugininterface.h"
       
    68 #include "msgsettingsview.h"
       
    69 
       
    70 QTM_USE_NAMESPACE
       
    71 // Constants
       
    72 const QString SEND_ICON("qtg_mono_send");
       
    73 const QString ATTACH_ICON("qtg_mono_attach");
       
    74 // temporary folder for unieditor
       
    75 const QString UNIFIED_EDITOR_TEMP_FOLDER("unifiededitor");
       
    76 
       
    77 const int INVALID_MSGID = -1;
       
    78 // vcard file extn.
       
    79 const QString FILE_EXTN(".vcf");
       
    80 // Max vcards inside a msg. Using a very large number.
       
    81 // TODO: how we can avoid this?
       
    82 const int MAX_VCARDS(1000);
       
    83 
       
    84 // LOCALIZED CONSTANTS
       
    85 //To,Cc.Bcc
       
    86 #define LOC_TO  hbTrId("txt_messaging_formlabel_to")
       
    87 #define LOC_CC hbTrId("txt_messaging_formlabel_cc")
       
    88 #define LOC_BCC hbTrId("txt_messaging_formlabel_bcc")
       
    89 
       
    90 //attach options
       
    91 #define LOC_PHOTO           hbTrId("txt_messaging_opt_attach_sub_photo")
       
    92 #define LOC_SOUND           hbTrId("txt_messaging_opt_attach_sub_sound")
       
    93 #define LOC_BUSINESS_CARD   hbTrId("txt_messaging_opt_sub_business_card")
       
    94 
       
    95 //options menu.
       
    96 #define LOC_ADD_SUBJECT     hbTrId("txt_messaging_opt_add_subject")
       
    97 #define LOC_ADD_CC_BCC      hbTrId("txt_messaging_opt_add_cc_bcc")
       
    98 #define LOC_PRIORITY        hbTrId("txt_messaging_opt_priority")
       
    99 #define LOC_DELETE_MESSAGE  hbTrId("txt_messaging_opt_delete_message")
       
   100 
       
   101 //priority sub menu
       
   102 #define LOC_HIGH hbTrId("txt_messaging_opt_attach_sub_high")
       
   103 #define LOC_NORMAL hbTrId("txt_messaging_opt_attach_sub_normal")
       
   104 #define LOC_LOW hbTrId("txt_messaging_opt_attach_sub_low")
       
   105 
       
   106 //group box
       
   107 #define LOC_OTHER_RECIPIENTS(n) hbTrId("txt_messaging_title_ln_other_recipients",n)
       
   108 #define LOC_OTHER_RECIPIENTS_EXPAND hbTrId("txt_messaging_title_other_recipients")
       
   109 
       
   110 //saved to draft note
       
   111 #define LOC_SAVED_TO_DRAFTS    hbTrId("txt_messaging_dpopinfo_saved_to_drafts")
       
   112 
       
   113 //delete confermation
       
   114 #define LOC_NOTE_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message")
       
   115 
       
   116 // attachment addition failure note
       
   117 #define LOC_UNABLE_TO_ADD_ATTACHMENTS hbTrId("txt_messaging_dpopinfo_unable_to_attach_l1_of_l2")
       
   118 
       
   119 //extension list item frame.
       
   120 const QString POPUP_LIST_FRAME("qtg_fr_popup_list_normal");
       
   121 
       
   122 //settings confirmation
       
   123 #define LOC_DIALOG_SMS_SETTINGS_INCOMPLETE hbTrId("txt_messaging_dialog_sms_message_centre_does_not_e")
       
   124 #define LOC_DIALOG_MMS_SETTINGS_INCOMPLETE hbTrId("txt_messaging_dialog_mms_access_point_not_defined")
       
   125 // LOCAL FUNCTIONS
       
   126 
       
   127 //---------------------------------------------------------------
       
   128 // editorTempPath
       
   129 // @return fullPath of unified editor's temporary dir
       
   130 //---------------------------------------------------------------
       
   131 QString editorTempPath()
       
   132 {
       
   133     QDir tempDir;
       
   134     QString tempPath(QDir::toNativeSeparators(tempDir.tempPath()));
       
   135     tempPath.append(QDir::separator());
       
   136     tempPath.append(UNIFIED_EDITOR_TEMP_FOLDER);
       
   137     tempPath.append(QDir::separator());
       
   138     return tempPath;
       
   139 }
       
   140 
       
   141 //---------------------------------------------------------------
       
   142 // MsgUnifiedEditorView::MsgUnifiedEditorView
       
   143 // @see header file
       
   144 //---------------------------------------------------------------
       
   145 MsgUnifiedEditorView::MsgUnifiedEditorView( QGraphicsItem *parent ) :
       
   146     MsgBaseView(parent),
       
   147     mSubjectAction(0),
       
   148     mCcBccAction(0),
       
   149     mSendAction(0),
       
   150     mMainLayout(0),
       
   151     mSubjectField(0),
       
   152     mToField(0),
       
   153     mCcField(0),
       
   154     mBccField(0),
       
   155     mBody(0),
       
   156     mContentWidget(0),
       
   157     mMsgMonitor(0),    
       
   158     mAttachmentContainer(0),
       
   159     mPluginLoader(0),
       
   160     mCanSaveToDrafts(true),
       
   161     mVkbHost(NULL)
       
   162     {
       
   163     connect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(doDelayedConstruction()));
       
   164     
       
   165     addToolBar();
       
   166     initView();
       
   167     }
       
   168 
       
   169 //---------------------------------------------------------------
       
   170 // MsgUnifiedEditorView::~MsgUnifiedEditorView
       
   171 // @see header file
       
   172 //---------------------------------------------------------------
       
   173 MsgUnifiedEditorView::~MsgUnifiedEditorView()
       
   174 {
       
   175     // clean editor's temporary contents before exiting
       
   176     removeTempFolder();
       
   177 }
       
   178 
       
   179 //---------------------------------------------------------------
       
   180 // MsgUnifiedEditorView::initView
       
   181 // @see header file
       
   182 //---------------------------------------------------------------
       
   183 void MsgUnifiedEditorView::initView()
       
   184 {
       
   185     if (!HbStyleLoader::registerFilePath(":/layouts")) {
       
   186         QDEBUG_WRITE("ERROR: MsgUnifiedEditorView -> HbStyleLoader::registerFilePath");
       
   187     }
       
   188     HbScrollArea* scrollArea = new HbScrollArea(this);
       
   189     this->setWidget(scrollArea);
       
   190 
       
   191     mContentWidget = new HbWidget(this);
       
   192     scrollArea->setContentWidget(mContentWidget);
       
   193 
       
   194     mMainLayout = new QGraphicsLinearLayout(Qt::Vertical, mContentWidget);
       
   195     qreal vTopSpacing = 0.0;
       
   196     qreal vItemSpacing = 0.0;
       
   197     style()->parameter("hb-param-margin-gene-top",vTopSpacing);    
       
   198     style()->parameter("hb-param-margin-gene-middle-vertical",vItemSpacing);
       
   199     
       
   200     mMainLayout->setContentsMargins(0,vTopSpacing,0,0);
       
   201     mMainLayout->setSpacing(vItemSpacing);
       
   202 
       
   203     mMsgMonitor = new MsgUnifiedEditorMonitor(this);
       
   204     connect(mMsgMonitor, SIGNAL(enableSend(bool)), this, SLOT(enableSendButton(bool)));
       
   205 
       
   206     mToField = new MsgUnifiedEditorAddress( LOC_TO, mContentWidget );
       
   207     
       
   208     mBody = new MsgUnifiedEditorBody( mContentWidget);
       
   209 
       
   210     mMainLayout->addItem(mToField);
       
   211     mMainLayout->addItem(mBody);
       
   212  
       
   213     //Set the invalid msg id
       
   214     mOpenedMessageId.setId(-1);
       
   215 
       
   216     connect(mToField, SIGNAL(sendMessage()), this, SLOT(send()));
       
   217     connect(mToField, SIGNAL(contentChanged()),
       
   218             mMsgMonitor, SLOT(handleContentChange()));
       
   219     connect(mToField, SIGNAL(contentChanged()),this,SLOT(onContentChanged()));
       
   220     
       
   221     connect(mBody, SIGNAL(sendMessage()), this, SLOT(send()));
       
   222     connect(mBody, SIGNAL(contentChanged()),this,SLOT(onContentChanged()));
       
   223     connect(mBody, SIGNAL(contentChanged()),
       
   224             mMsgMonitor, SLOT(handleContentChange()));
       
   225     connect(mBody, SIGNAL(enableSendButton(bool)), this, SLOT(enableSendButton(bool)));    
       
   226     
       
   227 }
       
   228 
       
   229 void MsgUnifiedEditorView::addMenu()
       
   230 {
       
   231     //Create Menu Options
       
   232     HbMenu* mainMenu = new HbMenu();
       
   233     mainMenu->setFocusPolicy(Qt::NoFocus);
       
   234 	
       
   235     //if subject field / cc,bcc fields are already present don't add corresponding actions.
       
   236     if(!mSubjectField)
       
   237     {
       
   238         mSubjectAction = mainMenu->addAction(LOC_ADD_SUBJECT);
       
   239     }
       
   240     
       
   241     if(!mCcField)
       
   242     {
       
   243         mCcBccAction = mainMenu->addAction(LOC_ADD_CC_BCC);
       
   244     }
       
   245     
       
   246     HbMenu* prioritySubMenu = mainMenu->addMenu(LOC_PRIORITY);
       
   247 
       
   248     HbAction* highPriorityAction = prioritySubMenu->addAction(LOC_HIGH);
       
   249     highPriorityAction->setData(ConvergedMessage::High);
       
   250 
       
   251     HbAction* normalPriorityAction = prioritySubMenu->addAction(LOC_NORMAL);
       
   252     normalPriorityAction->setData(ConvergedMessage::Normal);
       
   253 
       
   254     HbAction* lowPriorityAction = prioritySubMenu->addAction(LOC_LOW);
       
   255     lowPriorityAction->setData(ConvergedMessage::Low);
       
   256 
       
   257     HbAction* deleteMsgAction = mainMenu->addAction(LOC_DELETE_MESSAGE);
       
   258 
       
   259     connect(mSubjectAction,SIGNAL(triggered()),this, SLOT(addSubject()));
       
   260     connect(mCcBccAction,SIGNAL(triggered()),this, SLOT(addCcBcc()));
       
   261     connect(highPriorityAction, SIGNAL(triggered()), this, SLOT(changePriority()));
       
   262     connect(normalPriorityAction, SIGNAL(triggered()), this, SLOT(changePriority()));
       
   263     connect(lowPriorityAction, SIGNAL(triggered()), this, SLOT(changePriority()));
       
   264     connect(deleteMsgAction,SIGNAL(triggered()),this, SLOT(deleteMessage()));
       
   265 
       
   266     setMenu(mainMenu);
       
   267 }
       
   268 
       
   269 void MsgUnifiedEditorView::openDraftsMessage(const QVariantList& editorData)
       
   270 {
       
   271     // unpack editor's data
       
   272     // first arg is convergedmessage
       
   273     QByteArray dataArray = editorData.at(0).toByteArray();
       
   274     ConvergedMessage* messageDetails = new ConvergedMessage;
       
   275     QDataStream stream(&dataArray, QIODevice::ReadOnly);
       
   276     messageDetails->deserialize(stream);
       
   277     ConvergedMessage::MessageType messageType = messageDetails->messageType();
       
   278     ConvergedMessageId messageId = *(messageDetails->id());
       
   279     delete messageDetails;
       
   280 
       
   281     if(!mPluginLoader)
       
   282     {
       
   283         mPluginLoader = new UniEditorPluginLoader(this);
       
   284     }
       
   285 
       
   286     UniEditorPluginInterface* pluginInterface =
       
   287         mPluginLoader->getUniEditorPlugin(messageType);
       
   288 
       
   289     mOpenedMessageId.setId(messageId.getId());
       
   290     mmOpenedMessageType = messageType;
       
   291 
       
   292     //Fetch the converged message from the msgId
       
   293     ConvergedMessage* msg;
       
   294     msg = pluginInterface->convertFrom(messageId.getId());
       
   295 
       
   296     if( msg != NULL )
       
   297     {
       
   298         //Populate the content inside editor
       
   299         populateContentIntoEditor(*msg,true); // true as it is  draft message
       
   300         delete msg;
       
   301     }
       
   302     
       
   303     mCanSaveToDrafts = false;  
       
   304 }
       
   305 
       
   306 void MsgUnifiedEditorView::fetchMessageFromStore(
       
   307         ConvergedMessageId& messageId,
       
   308         ConvergedMessage::MessageType messageType,
       
   309         int editorOperation)
       
   310 {
       
   311     if(!mPluginLoader)
       
   312     {
       
   313         mPluginLoader = new UniEditorPluginLoader(this);
       
   314     }
       
   315     UniEditorPluginInterface* pluginInterface = NULL;
       
   316     if( messageType == ConvergedMessage::Mms )
       
   317     {
       
   318         pluginInterface =
       
   319                 mPluginLoader->getUniEditorPlugin(ConvergedMessage::Mms);
       
   320     }
       
   321     else // For sms,vcard,vcal cases
       
   322     {
       
   323         pluginInterface =
       
   324                 mPluginLoader->getUniEditorPlugin(ConvergedMessage::Sms);
       
   325     }
       
   326 
       
   327     //Fetch the converged message from the msgId
       
   328     ConvergedMessage* msg;
       
   329     msg = pluginInterface->convertFrom(messageId.getId(),
       
   330                     (UniEditorPluginInterface::EditorOperation)editorOperation);
       
   331     if( msg != NULL )
       
   332     {
       
   333         //Populate the content inside editor
       
   334         populateContentIntoEditor(*msg);
       
   335         delete msg;
       
   336     }
       
   337 }
       
   338 
       
   339 void MsgUnifiedEditorView::populateContent(const QVariantList& editorData)
       
   340 {
       
   341     // unpack editor's data
       
   342     // first arg is convergedmessage
       
   343     QByteArray dataArray = editorData.at(0).toByteArray();
       
   344     ConvergedMessage* messageDetails = new ConvergedMessage;
       
   345     QDataStream stream(&dataArray, QIODevice::ReadOnly);
       
   346     messageDetails->deserialize(stream);
       
   347 
       
   348     // get next arg i.e. editor operation command
       
   349     int editorOp = 0;
       
   350     if(editorData.length() > 1)
       
   351     {
       
   352         editorOp = editorData.at(1).toInt();
       
   353     }
       
   354 
       
   355     // population logic based on editor Operation command
       
   356     switch(editorOp)
       
   357     {
       
   358         case MsgBaseView::ADD_SUBJECT:
       
   359         {
       
   360             addSubject();
       
   361             setFocus(mSubjectField);
       
   362         }
       
   363         break;
       
   364         case MsgBaseView::ADD_VCARD:
       
   365         {
       
   366             contactsFetched(editorData.at(2));
       
   367         }
       
   368         break;
       
   369         case MsgBaseView::FORWARD_MSG:
       
   370         {
       
   371             fetchMessageFromStore(*messageDetails->id(),
       
   372                                    messageDetails->messageType(),
       
   373                                    UniEditorPluginInterface::Forward);
       
   374         }
       
   375         break;
       
   376         case MsgBaseView::REPLY_MSG:
       
   377         {
       
   378             fetchMessageFromStore(*messageDetails->id(),
       
   379                                    messageDetails->messageType(),
       
   380                                    UniEditorPluginInterface::Reply);
       
   381         }
       
   382         break;
       
   383         case MsgBaseView::REPLY_ALL_MSG:
       
   384         {
       
   385             fetchMessageFromStore(*messageDetails->id(),
       
   386                                    messageDetails->messageType(),
       
   387                                    UniEditorPluginInterface::ReplyAll);
       
   388         }
       
   389         break;
       
   390         default:
       
   391         break;
       
   392     }
       
   393 
       
   394     // additional common operations for non-forwarded messages
       
   395     if(editorOp != MsgBaseView::FORWARD_MSG)
       
   396     {
       
   397         if(editorOp == MsgBaseView::ADD_RECIPIENTS)
       
   398         {
       
   399             // CV sends contact card address as the first address
       
   400             ConvergedMessageAddressList toAddresses = 
       
   401                     messageDetails->toAddressList();
       
   402             int addrCount = toAddresses.count();
       
   403             if(addrCount > 0)
       
   404             {
       
   405                 // add contact card address first
       
   406                 ConvergedMessageAddress *firstAddress =
       
   407                         new ConvergedMessageAddress();
       
   408                 firstAddress->setAlias(toAddresses.at(0)->alias());
       
   409                 firstAddress->setAddress(toAddresses.at(0)->address());
       
   410                 ConvergedMessageAddressList firstList;
       
   411                 firstList << firstAddress;
       
   412                 mToField->setAddresses(firstList);
       
   413             
       
   414                 // add remaining contacts now
       
   415                 ConvergedMessageAddressList otherList;
       
   416                 for(int i=1; i<addrCount; i++)
       
   417                 {
       
   418                     otherList << toAddresses.at(i);
       
   419                 }
       
   420                 mToField->setAddresses(otherList);
       
   421             }
       
   422         }
       
   423         else
       
   424         {
       
   425             mToField->setAddresses(messageDetails->toAddressList());
       
   426         }
       
   427         QString bodyTxt = messageDetails->bodyText();
       
   428         mBody->setText(bodyTxt);
       
   429 
       
   430         int attachmentCount = messageDetails->attachments().count();
       
   431         QStringList pendingAttList;
       
   432         for(int i=0; i<attachmentCount; i++)
       
   433         {
       
   434             int imageSize=0;
       
   435             QString mimeType;
       
   436             TMsgMediaType mediaType = EMsgMediaUnknown;
       
   437             QString filePath = messageDetails->attachments().at(i)->filePath();
       
   438             
       
   439            
       
   440             UniEditorGenUtils* genUtils = q_check_ptr(new UniEditorGenUtils);
       
   441             
       
   442             TRAP_IGNORE(genUtils->getFileInfoL(filePath,imageSize,
       
   443                                            mimeType,mediaType));
       
   444             delete genUtils;
       
   445             switch(mediaType)
       
   446             {
       
   447                 case EMsgMediaImage:
       
   448                 {
       
   449                     mBody->setImage(filePath);
       
   450                 }
       
   451                 break;
       
   452                  case EMsgMediaAudio:
       
   453                 {
       
   454                     mBody->setAudio(filePath);
       
   455                 }
       
   456                 break;
       
   457                 default:
       
   458                 {
       
   459                     pendingAttList << filePath;
       
   460                 }
       
   461                 break;
       
   462             }
       
   463         }
       
   464         // add pending attachments in bulk
       
   465         addAttachments(pendingAttList);
       
   466     }
       
   467     delete messageDetails; 
       
   468 }
       
   469 
       
   470 void MsgUnifiedEditorView::populateContentIntoEditor(
       
   471     const ConvergedMessage& messageDetails,bool draftMessage)
       
   472 {
       
   473     // skip first-time MMS type switch note for draft
       
   474     mMsgMonitor->setSkipNote(true);
       
   475     mToField->skipMaxRecipientQuery(true);
       
   476 
       
   477     mToField->setAddresses(messageDetails.toAddressList());
       
   478     if(messageDetails.ccAddressList().count() > 0 )
       
   479     {
       
   480         if(!mCcField)
       
   481         {
       
   482         addCcBcc();
       
   483         }
       
   484         mCcField->setAddresses(messageDetails.ccAddressList());
       
   485     }
       
   486     if(messageDetails.bccAddressList().count() > 0 )
       
   487     {
       
   488         if(!mBccField)
       
   489         {
       
   490         addCcBcc();
       
   491         }
       
   492         mBccField->setAddresses(messageDetails.bccAddressList());
       
   493     }
       
   494     if(messageDetails.subject().size() > 0)
       
   495     {
       
   496        if(!mSubjectField)
       
   497        {
       
   498            addSubject();
       
   499        }
       
   500        mSubjectField->setText(messageDetails.subject());
       
   501     }
       
   502 
       
   503     if(messageDetails.priority()==ConvergedMessage::High ||
       
   504             messageDetails.priority() == ConvergedMessage::Low)
       
   505     {
       
   506         if(!mSubjectField)
       
   507         {
       
   508             addSubject();
       
   509         }
       
   510         mSubjectField->setPriority(messageDetails.priority());
       
   511     }
       
   512 
       
   513     QString bodyTxt = messageDetails.bodyText();
       
   514     mBody->setText(bodyTxt);
       
   515 
       
   516     ConvergedMessageAttachmentList attachmentList =
       
   517         messageDetails.attachments();
       
   518     int attachmentCount = attachmentList.count();
       
   519      
       
   520     UniEditorGenUtils* genUtils = q_check_ptr(new UniEditorGenUtils);
       
   521 
       
   522     QStringList pendingAttList;
       
   523     for( int i=0; i < attachmentCount; i++ )
       
   524     {
       
   525         QString filePath = messageDetails.attachments().at(i)->filePath();
       
   526 
       
   527         if(attachmentList.at(i)->attachmentType() ==
       
   528             ConvergedMessageAttachment::EInline)
       
   529         {
       
   530             int imageSize=0;
       
   531             QString mimeType;
       
   532             TMsgMediaType mediaType = EMsgMediaUnknown;
       
   533             TRAP_IGNORE(genUtils->getFileInfoL(filePath,imageSize,
       
   534                 mimeType,mediaType));
       
   535 
       
   536             switch(mediaType)
       
   537             {
       
   538                 case EMsgMediaImage:
       
   539                 {
       
   540                     mBody->setImage(filePath,draftMessage);
       
   541                     break;
       
   542                 }
       
   543                 case EMsgMediaAudio:
       
   544                 {
       
   545                     mBody->setAudio(filePath);
       
   546                     break;
       
   547                 }
       
   548                 default:
       
   549                 {
       
   550                     pendingAttList << filePath;
       
   551                     break;
       
   552                 }
       
   553             }
       
   554         }
       
   555         else
       
   556         {
       
   557             pendingAttList << filePath;
       
   558         }
       
   559     }
       
   560     // add pending attachments to editor
       
   561     addAttachments(pendingAttList);
       
   562 
       
   563     delete genUtils;
       
   564     // ensure that any msg-type change after this are shown
       
   565     mToField->skipMaxRecipientQuery(false);
       
   566     mMsgMonitor->setSkipNote(false);
       
   567 }
       
   568 
       
   569 void MsgUnifiedEditorView::addToolBar()
       
   570 {
       
   571     //Create Tool Bar
       
   572     HbToolBar *toolBar = new HbToolBar();
       
   573     toolBar->setOrientation(Qt::Horizontal);
       
   574     
       
   575     //tool bar extension for attach action.
       
   576     HbToolBarExtension* attachExtension = new HbToolBarExtension();
       
   577     mAttachAction = toolBar->addExtension(attachExtension);    
       
   578     mAttachAction->setIcon(HbIcon(ATTACH_ICON));
       
   579     
       
   580     mTBExtnContentWidget = new HbListWidget();
       
   581     mTBExtnContentWidget->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Fixed);
       
   582     mTBExtnContentWidget->addItem(LOC_PHOTO);
       
   583     mTBExtnContentWidget->addItem(LOC_SOUND);
       
   584     mTBExtnContentWidget->addItem(LOC_BUSINESS_CARD);
       
   585 
       
   586     HbListViewItem *prototype = mTBExtnContentWidget->listItemPrototype();
       
   587     HbFrameBackground frame(POPUP_LIST_FRAME, HbFrameDrawer::NinePieces);
       
   588     prototype->setDefaultFrame(frame);
       
   589 
       
   590     connect(mTBExtnContentWidget, SIGNAL(activated(HbListWidgetItem*)),
       
   591             this, SLOT(handleViewExtnActivated(HbListWidgetItem*)));
       
   592     connect(mTBExtnContentWidget, SIGNAL(activated(HbListWidgetItem*)),
       
   593             attachExtension, SLOT(close()));
       
   594 
       
   595     attachExtension->setContentWidget(mTBExtnContentWidget);
       
   596 
       
   597     //Add Action to the toolbar and show toolbar
       
   598     mSendAction = toolBar->addAction(HbIcon(SEND_ICON),QString(),this,SLOT(send()));
       
   599     mSendAction->setDisabled(true);
       
   600 
       
   601     setToolBar(toolBar);
       
   602 }
       
   603 
       
   604 void MsgUnifiedEditorView::addSubject()
       
   605 {
       
   606     if(mSubjectField)
       
   607     { // do nothing if already present
       
   608         return;
       
   609     }
       
   610 
       
   611     int index =0;
       
   612     int offset = 1;
       
   613     if(mAttachmentContainer)
       
   614     {
       
   615         ++offset;
       
   616     }
       
   617     index = mMainLayout->count() - offset;
       
   618 
       
   619     mSubjectField = new MsgUnifiedEditorSubject( mContentWidget);
       
   620     
       
   621     mMainLayout->insertItem(index,mSubjectField);
       
   622     connect(mSubjectField, SIGNAL(contentChanged()),
       
   623             mMsgMonitor, SLOT(handleContentChange()));
       
   624     connect(mSubjectField, SIGNAL(contentChanged()),this,SLOT(onContentChanged()));
       
   625     
       
   626     //set focus to subject field.
       
   627     HbAction* subjectAction = qobject_cast<HbAction*>(this->sender());
       
   628     if(subjectAction)
       
   629     {
       
   630         setFocus(mSubjectField);
       
   631     }
       
   632     
       
   633     // remove mainmenu's "Add Subject" action
       
   634     if(mSubjectAction)
       
   635     {
       
   636         HbMenu* mainMenu = this->menu();
       
   637         mainMenu->removeAction(mSubjectAction);
       
   638         mSubjectAction->setParent(NULL);
       
   639         delete mSubjectAction;
       
   640     }
       
   641 }
       
   642 
       
   643 void MsgUnifiedEditorView::addCcBcc()
       
   644 {
       
   645     if(mCcField && mBccField)
       
   646     { // do nothing if already present
       
   647         return;
       
   648     }
       
   649 
       
   650     mCcField    = new MsgUnifiedEditorAddress( LOC_CC, mContentWidget );
       
   651     mBccField   = new MsgUnifiedEditorAddress( LOC_BCC, mContentWidget );
       
   652     mCcField->skipMaxRecipientQuery(true);
       
   653     mBccField->skipMaxRecipientQuery(true);
       
   654 
       
   655     connect(mCcField, SIGNAL(sendMessage()), this, SLOT(send()));
       
   656     connect(mCcField, SIGNAL(contentChanged()), mMsgMonitor, SLOT(handleContentChange()));
       
   657     connect(mCcField, SIGNAL(contentChanged()),this,SLOT(onContentChanged()));
       
   658     
       
   659     connect(mBccField, SIGNAL(sendMessage()), this, SLOT(send()));
       
   660     connect(mBccField, SIGNAL(contentChanged()), mMsgMonitor, SLOT(handleContentChange()));
       
   661     connect(mBccField, SIGNAL(contentChanged()),this,SLOT(onContentChanged()));
       
   662 
       
   663     HbWidget* groupWidget = new HbWidget(mContentWidget);
       
   664     groupWidget->setContentsMargins(0,0,0,0);
       
   665     
       
   666     QGraphicsLinearLayout* ccBccLayout = new QGraphicsLinearLayout(Qt::Vertical, groupWidget);
       
   667     ccBccLayout->setContentsMargins(0,0,0,0);
       
   668 
       
   669     qreal vItemSpacing = 0.0;    
       
   670     style()->parameter("hb-param-margin-gene-middle-vertical",vItemSpacing);
       
   671     ccBccLayout->setSpacing(vItemSpacing);
       
   672     ccBccLayout->addItem(mCcField);
       
   673     ccBccLayout->addItem(mBccField);
       
   674 
       
   675     HbGroupBox* groupBox = new HbGroupBox(0);  
       
   676     groupBox->setObjectName("groupBox");
       
   677     
       
   678     groupBox->setContentWidget(groupWidget);
       
   679     groupBox->setHeading(LOC_OTHER_RECIPIENTS_EXPAND);
       
   680     mMainLayout->insertItem(1,groupBox);
       
   681     connect(groupBox, SIGNAL(toggled(bool)), this, SLOT(updateOtherRecipientCount(bool)));
       
   682     
       
   683     // add subject field too
       
   684     addSubject();
       
   685 
       
   686     //set focus to Cc field.
       
   687     HbAction* ccBccAction = qobject_cast<HbAction*>(this->sender());
       
   688     if(mCcBccAction)
       
   689     {
       
   690         setFocus(mCcField);
       
   691     }
       
   692     
       
   693     // remove mainmenu's "Add Cc/Bcc" & "Add Subject" actions
       
   694     if(mCcBccAction)
       
   695     {
       
   696     HbMenu* mainmenu = this->menu();
       
   697     mainmenu->removeAction(mCcBccAction);
       
   698     mCcBccAction->setParent(NULL);
       
   699     delete mCcBccAction;
       
   700     }
       
   701     
       
   702     this->updateGeometry();
       
   703 }
       
   704 
       
   705 void MsgUnifiedEditorView::updateOtherRecipientCount(bool state)
       
   706 {
       
   707     HbGroupBox* groupBox = qobject_cast<HbGroupBox*>(sender());
       
   708     if(groupBox)
       
   709     {
       
   710         if(!state)
       
   711         {
       
   712            groupBox->setHeading(LOC_OTHER_RECIPIENTS_EXPAND);
       
   713         }
       
   714         else
       
   715         {
       
   716             int addrCount = mCcField->addressCount();
       
   717             addrCount += mBccField->addressCount();
       
   718             if(addrCount > 0)
       
   719             {
       
   720                 groupBox->setHeading(LOC_OTHER_RECIPIENTS(addrCount));    
       
   721             }
       
   722         }
       
   723     }
       
   724 }
       
   725 
       
   726 void MsgUnifiedEditorView::changePriority()
       
   727 {
       
   728     HbAction* action = qobject_cast<HbAction*>(sender());
       
   729 
       
   730     ConvergedMessage::Priority priority = ConvergedMessage::Normal;
       
   731    if(action)
       
   732         {
       
   733         int data = action->data().toInt();
       
   734         priority = ConvergedMessage::Priority(data);
       
   735         }
       
   736 
       
   737     addSubject();
       
   738     mSubjectField->setPriority(priority);
       
   739 }
       
   740 
       
   741 void MsgUnifiedEditorView::deleteMessage()
       
   742 {
       
   743     HbMessageBox::question(LOC_NOTE_DELETE_MESSAGE,this,
       
   744                            SLOT(onDialogDeleteMsg(HbAction*)),
       
   745                            HbMessageBox::Delete | HbMessageBox::Cancel);
       
   746 }
       
   747 
       
   748 void MsgUnifiedEditorView::removeAttachmentContainer()
       
   749 {
       
   750     if(mAttachmentContainer)
       
   751     {
       
   752         mMainLayout->removeItem(mAttachmentContainer);
       
   753         mAttachmentContainer->setParent(NULL);
       
   754         delete mAttachmentContainer;
       
   755         mAttachmentContainer = NULL;
       
   756     }
       
   757 }
       
   758 
       
   759 void MsgUnifiedEditorView::addAttachments(QStringList files)
       
   760 {    
       
   761     int fcount = files.count();
       
   762     int i=0;
       
   763     for(i=0; i<fcount; i++)
       
   764     {
       
   765         int status = addAttachment(files.at(i));
       
   766         if(status == MsgAttachmentContainer::EAddSizeExceed)
       
   767         {
       
   768             QString displayStr = QString(LOC_UNABLE_TO_ADD_ATTACHMENTS)
       
   769                     .arg(fcount-i).arg(fcount);
       
   770             HbNotificationDialog::launchDialog(displayStr);
       
   771             break;
       
   772         }
       
   773     }
       
   774 }
       
   775 
       
   776 int MsgUnifiedEditorView::addAttachment(const QString& filepath)
       
   777 {
       
   778     // do nothing if filepath is empty
       
   779     if(filepath.isEmpty())
       
   780     {
       
   781         return MsgAttachmentContainer::EAddSuccess;
       
   782     }
       
   783 
       
   784     if(!mAttachmentContainer)
       
   785     {
       
   786         mAttachmentContainer = new MsgAttachmentContainer( mContentWidget);
       
   787         connect(mAttachmentContainer, SIGNAL(emptyAttachmentContainer()),
       
   788                 this, SLOT(removeAttachmentContainer()));
       
   789         connect(mAttachmentContainer, SIGNAL(contentChanged()),
       
   790                 mMsgMonitor, SLOT(handleContentChange()));
       
   791         connect(mAttachmentContainer, SIGNAL(contentChanged()),
       
   792                 this,SLOT(onContentChanged()));
       
   793         
       
   794         int index = mMainLayout->count() - 1;
       
   795         mMainLayout->insertItem(index,mAttachmentContainer);
       
   796     }
       
   797 
       
   798     int ret = mAttachmentContainer->addAttachment(filepath);
       
   799     if(ret != MsgAttachmentContainer::EAddSuccess)
       
   800     {
       
   801         // delete container, if it is empty
       
   802         if(mAttachmentContainer->count() == 0)
       
   803         {
       
   804             removeAttachmentContainer();
       
   805         }
       
   806     }
       
   807     return ret;
       
   808 }
       
   809 
       
   810 void MsgUnifiedEditorView::send()
       
   811 {
       
   812     activateInputBlocker();
       
   813     
       
   814     // first run the address validation tests
       
   815     if( !mToField->validateContacts() ||
       
   816         (mCcField && !mCcField->validateContacts()) ||
       
   817         (mBccField && !mBccField->validateContacts()) )
       
   818     {
       
   819         deactivateInputBlocker();
       
   820         return;
       
   821     }
       
   822 
       
   823     // converged msg for sending
       
   824     ConvergedMessage msg;
       
   825     ConvergedMessage::MessageType messageType = MsgUnifiedEditorMonitor::messageType();
       
   826     msg.setMessageType(messageType);
       
   827 
       
   828     // we need to remove duplicate addresses
       
   829     bool removeDuplicates = true;
       
   830     ConvergedMessageAddressList addresses =
       
   831             mToField->addresses(removeDuplicates);
       
   832     if(messageType == ConvergedMessage::Sms &&
       
   833        addresses.isEmpty())
       
   834     {
       
   835         // no recipient specified for sms, do not send msg
       
   836         deactivateInputBlocker();
       
   837         return;
       
   838     }
       
   839 
       
   840     ConvergedMessageAddressList ccAddresses;
       
   841     ConvergedMessageAddressList bccAddresses;
       
   842     if(mCcField)
       
   843     {
       
   844         ccAddresses = mCcField->addresses(removeDuplicates);
       
   845     }
       
   846     if(mBccField)
       
   847     {
       
   848         bccAddresses = mBccField->addresses(removeDuplicates);
       
   849     }
       
   850     if( messageType == ConvergedMessage::Mms &&
       
   851             addresses.isEmpty() &&
       
   852             ccAddresses.isEmpty() &&
       
   853             bccAddresses.isEmpty())
       
   854     {
       
   855         // no recipient specified for mms, do not send msg
       
   856         deactivateInputBlocker();
       
   857         return;
       
   858     }
       
   859     
       
   860     //close vkb before switching view.
       
   861     mVkbHost->closeKeypad(true);
       
   862 
       
   863     packMessage(msg);
       
   864     
       
   865     // send message
       
   866     MsgSendUtil *sendUtil = new MsgSendUtil(this);
       
   867     int sendResult = sendUtil->send(msg);
       
   868     delete sendUtil;
       
   869     
       
   870     // all checks and validations happen before send
       
   871     if( sendResult == KErrNone)
       
   872     {
       
   873         //After sending the new content to drafts chk if the msg
       
   874         //was originally opened from drafts and delete the opened entry
       
   875         if( mOpenedMessageId.getId() != -1)
       
   876         {
       
   877 
       
   878             if(!mPluginLoader)
       
   879             {
       
   880                 mPluginLoader = new UniEditorPluginLoader(this);
       
   881             }
       
   882 
       
   883             UniEditorPluginInterface* pluginInterface =
       
   884                 mPluginLoader->getUniEditorPlugin(messageType);
       
   885             //TODO delete the entry
       
   886             pluginInterface->deleteDraftsEntry(mOpenedMessageId.getId());
       
   887         }
       
   888 
       
   889         ConvergedMessageAddressList addrList = addresses;
       
   890         QString receipient;
       
   891 
       
   892         int recepientCount = addrList.count();
       
   893         if(recepientCount)
       
   894         {
       
   895             receipient = addrList.at(0)->address();
       
   896         }
       
   897 
       
   898         if( mCcField && mBccField)
       
   899         {
       
   900             addrList = ccAddresses;
       
   901             int ccCount = addrList.count();
       
   902             recepientCount += ccCount;
       
   903             if(ccCount)
       
   904             {
       
   905                 receipient = addrList.at(0)->address();
       
   906             }
       
   907 
       
   908             addrList = bccAddresses;
       
   909             int bccCount = addrList.count();
       
   910             recepientCount += bccCount;
       
   911             if(bccCount)
       
   912             {
       
   913                 receipient = addrList.at(0)->address();
       
   914             }
       
   915         }
       
   916         
       
   917     QVariantList params;
       
   918 
       
   919     if(recepientCount == 1 )
       
   920         {
       
   921         params << MsgBaseView::CV;  // target view
       
   922         params << MsgBaseView::UNIEDITOR; // source view
       
   923 
       
   924         params << receipient;
       
   925         }
       
   926     else
       
   927         {
       
   928         params << MsgBaseView::CLV;// target view
       
   929         params << MsgBaseView::UNIEDITOR; // source view
       
   930         }
       
   931         deactivateInputBlocker();
       
   932         emit switchView(params);
       
   933     }
       
   934     else
       
   935     {
       
   936         deactivateInputBlocker();
       
   937         if(sendResult == KErrNotFound)
       
   938         {
       
   939             if (messageType == ConvergedMessage::Sms)
       
   940             {
       
   941                 HbMessageBox::question(LOC_DIALOG_SMS_SETTINGS_INCOMPLETE,
       
   942                                        this,SLOT(onDialogSmsSettings(HbAction*)),
       
   943                                        HbMessageBox::Ok | HbMessageBox::Cancel);
       
   944             }
       
   945             else
       
   946             {
       
   947                 HbMessageBox::question(LOC_DIALOG_MMS_SETTINGS_INCOMPLETE,
       
   948                                        this,SLOT(onDialogMmsSettings(HbAction*)),                             
       
   949                                        HbMessageBox::Ok | HbMessageBox::Cancel);
       
   950             }
       
   951         }
       
   952     }
       
   953 }
       
   954 
       
   955 void MsgUnifiedEditorView::packMessage(ConvergedMessage &msg, bool isSave)
       
   956 {
       
   957     ConvergedMessage::MessageType messageType = MsgUnifiedEditorMonitor::messageType();
       
   958     msg.setMessageType(messageType);
       
   959     // If isSave is true (save to draft usecase), then don't remove duplicates
       
   960     // If isSave is false (send usecase), then remove duplicates
       
   961     bool removeDuplicates = !isSave;
       
   962     ConvergedMessageAddressList addresses = 
       
   963             mToField->addresses(removeDuplicates);
       
   964     ConvergedMessageAddressList ccAddresses;
       
   965     ConvergedMessageAddressList bccAddresses;
       
   966     
       
   967 	//Don't format the addresses for save to drfats case
       
   968 	if(!isSave)
       
   969 	{
       
   970        formatAddresses(addresses);
       
   971     }
       
   972 	
       
   973     msg.addToRecipients(addresses);
       
   974     msg.setBodyText(mBody->text());
       
   975     msg.setDirection(ConvergedMessage::Outgoing);
       
   976     QDateTime time = QDateTime::currentDateTime();
       
   977     msg.setTimeStamp(time.toTime_t());
       
   978 
       
   979     if(messageType == ConvergedMessage::Mms)
       
   980     {
       
   981         if(mCcField)
       
   982         {
       
   983             ccAddresses = mCcField->addresses(removeDuplicates);
       
   984         }
       
   985 
       
   986         if(mBccField)
       
   987         {
       
   988             bccAddresses = mBccField->addresses(removeDuplicates);
       
   989         }
       
   990 
       
   991         if(removeDuplicates)
       
   992         {
       
   993             int matchDigitsCount = MsgUnifiedEditorAddress::contactMatchDigits();
       
   994             //comapre cc and to field,remove duplicate from cc
       
   995             foreach(ConvergedMessageAddress *ccAddress,ccAddresses)
       
   996             {
       
   997                 foreach(ConvergedMessageAddress *toAddress,addresses)
       
   998                 {
       
   999                     if(0 == ccAddress->address().right(matchDigitsCount).compare(toAddress->address().right(matchDigitsCount)))
       
  1000                     {
       
  1001                         ccAddresses.removeOne(ccAddress);
       
  1002                     }
       
  1003                 }
       
  1004             }
       
  1005             //comapre bcc and cc field,remove duplicate from bcc
       
  1006             foreach(ConvergedMessageAddress *bccAddress,bccAddresses)
       
  1007             {
       
  1008                 foreach(ConvergedMessageAddress *ccAddress,ccAddresses)
       
  1009                 {
       
  1010                     if(0 == bccAddress->address().right(matchDigitsCount).compare(ccAddress->address().right(matchDigitsCount)))
       
  1011                     {
       
  1012                         bccAddresses.removeOne(bccAddress);
       
  1013                     }
       
  1014                 }
       
  1015             }
       
  1016             //comapre bcc and to field,remove duplicate from bcc
       
  1017             foreach(ConvergedMessageAddress *bccAddress,bccAddresses)
       
  1018             {
       
  1019                 foreach(ConvergedMessageAddress *toAddress,addresses)
       
  1020                 {
       
  1021                     if(0 == bccAddress->address().right(matchDigitsCount).compare(toAddress->address().right(matchDigitsCount)))
       
  1022                     {
       
  1023                         bccAddresses.removeOne(bccAddress);
       
  1024                     }
       
  1025                 }
       
  1026             }
       
  1027         }
       
  1028 
       
  1029         if(ccAddresses.count()>0)
       
  1030         {
       
  1031 		//Don't format the addresses for save to drfats case
       
  1032 	    if(!isSave)
       
  1033 	    {
       
  1034            formatAddresses(ccAddresses);
       
  1035         }        
       
  1036         msg.addCcRecipients(ccAddresses);
       
  1037         }
       
  1038         if(bccAddresses.count()>0)
       
  1039         {
       
  1040 		//Don't format the addresses for save to drfats case
       
  1041 	    if(!isSave)
       
  1042 	    {
       
  1043            formatAddresses(bccAddresses);        
       
  1044 		}
       
  1045         msg.addBccRecipients(bccAddresses);
       
  1046         }
       
  1047         if(mSubjectField)
       
  1048         {
       
  1049             msg.setSubject(mSubjectField->text());
       
  1050             msg.setPriority(mSubjectField->priority());
       
  1051         }
       
  1052 
       
  1053         ConvergedMessageAttachmentList mediaList;
       
  1054 
       
  1055         QStringList mediafiles(mBody->mediaContent());
       
  1056         if (!mediafiles.isEmpty())
       
  1057         {
       
  1058             for (int i = 0; i < mediafiles.size(); ++i)
       
  1059             {
       
  1060                 ConvergedMessageAttachment* attachment =
       
  1061                     new ConvergedMessageAttachment(
       
  1062                         mediafiles.at(i),
       
  1063                         ConvergedMessageAttachment::EInline);
       
  1064                 mediaList << attachment;
       
  1065             }
       
  1066 
       
  1067         }
       
  1068         if(mediaList.count() > 0)
       
  1069         {
       
  1070             msg.addAttachments(mediaList);
       
  1071         }
       
  1072     }
       
  1073 
       
  1074     // sms/mms attachment list
       
  1075     ConvergedMessageAttachmentList attachmentList;
       
  1076         if(mAttachmentContainer)
       
  1077         {
       
  1078             MsgUnifiedEditorAttachmentList editorAttachmentList =
       
  1079                 mAttachmentContainer->attachmentList();
       
  1080                 for (int i = 0; i < editorAttachmentList.count(); ++i)
       
  1081                 {
       
  1082                     ConvergedMessageAttachment* attachment =
       
  1083                         new ConvergedMessageAttachment(
       
  1084                             editorAttachmentList.at(i)->path(),
       
  1085                             ConvergedMessageAttachment::EAttachment);
       
  1086                     attachmentList << attachment;
       
  1087                 }
       
  1088             }
       
  1089         if(attachmentList.count() > 0)
       
  1090         {
       
  1091             msg.addAttachments(attachmentList);
       
  1092         }
       
  1093 }
       
  1094 
       
  1095 int MsgUnifiedEditorView::saveContentToDrafts()
       
  1096 {
       
  1097     if(!mCanSaveToDrafts)
       
  1098         {
       
  1099         return mOpenedMessageId.getId(); // return currently opened message id
       
  1100         }
       
  1101     
       
  1102     activateInputBlocker();
       
  1103     ConvergedMessage::MessageType messageType = MsgUnifiedEditorMonitor::messageType();
       
  1104 
       
  1105     ConvergedMessageAddressList addresses = mToField->addresses();
       
  1106 
       
  1107     UniEditorPluginInterface* pluginInterface = NULL;
       
  1108 
       
  1109     if( mOpenedMessageId.getId() != -1)
       
  1110     {
       
  1111         if(!mPluginLoader)
       
  1112         {
       
  1113             mPluginLoader = new UniEditorPluginLoader(this);
       
  1114         }
       
  1115 
       
  1116         pluginInterface =
       
  1117             mPluginLoader->getUniEditorPlugin(messageType);
       
  1118     }
       
  1119 
       
  1120     if(messageType == ConvergedMessage::Sms &&
       
  1121             addresses.isEmpty() &&
       
  1122             MsgUnifiedEditorMonitor::bodySize() <= 0 &&
       
  1123             MsgUnifiedEditorMonitor::containerSize() <= 0)
       
  1124     {
       
  1125         if(mOpenedMessageId.getId() != -1)
       
  1126         {
       
  1127         pluginInterface->deleteDraftsEntry(mOpenedMessageId.getId());
       
  1128         }
       
  1129 
       
  1130         // if empty msg, do not save
       
  1131         deactivateInputBlocker();
       
  1132         return INVALID_MSGID;
       
  1133     }
       
  1134 
       
  1135     ConvergedMessageAddressList ccAddresses;
       
  1136     ConvergedMessageAddressList bccAddresses;
       
  1137     if(mCcField)
       
  1138     {
       
  1139         ccAddresses = mCcField->addresses();
       
  1140     }
       
  1141     if(mBccField)
       
  1142     {
       
  1143         bccAddresses = mBccField->addresses();
       
  1144     }
       
  1145     int subectSize =0;
       
  1146     if(mSubjectField)
       
  1147     {
       
  1148         subectSize = mSubjectField->text().size();
       
  1149     }
       
  1150 
       
  1151     if( messageType == ConvergedMessage::Mms &&
       
  1152             addresses.isEmpty() &&
       
  1153             ccAddresses.isEmpty() &&
       
  1154             bccAddresses.isEmpty() &&
       
  1155             subectSize <= 0 &&
       
  1156             MsgUnifiedEditorMonitor::bodySize() <= 0 &&
       
  1157             MsgUnifiedEditorMonitor::containerSize() <= 0)
       
  1158     {
       
  1159         if(mOpenedMessageId.getId() != -1)
       
  1160         {
       
  1161             pluginInterface->deleteDraftsEntry(mOpenedMessageId.getId());
       
  1162         }
       
  1163         // if empty msg, do not send
       
  1164         deactivateInputBlocker();
       
  1165         return INVALID_MSGID;
       
  1166     }
       
  1167     ConvergedMessage msg;
       
  1168     packMessage(msg, true);
       
  1169 
       
  1170     // save to drafts
       
  1171     MsgSendUtil *sendUtil = new MsgSendUtil(this);
       
  1172     int msgId = sendUtil->saveToDrafts(msg);
       
  1173     delete sendUtil;
       
  1174 
       
  1175     // If saving new msg to draft succeeded and also if the originally
       
  1176     // opened msg was from drafts, then delete the original msg entry
       
  1177     if(msgId != -1 && mOpenedMessageId.getId() != -1)
       
  1178     {
       
  1179         pluginInterface->deleteDraftsEntry(mOpenedMessageId.getId());
       
  1180         mOpenedMessageId.setId(INVALID_MSGID);
       
  1181     }
       
  1182 
       
  1183     deactivateInputBlocker();
       
  1184 
       
  1185     bool res = ((msgId > INVALID_MSGID)? true : false);
       
  1186     
       
  1187     if(res)
       
  1188         {
       
  1189         HbDeviceNotificationDialog::notification("", LOC_SAVED_TO_DRAFTS);
       
  1190         }
       
  1191     return msgId;
       
  1192 }
       
  1193 
       
  1194 void MsgUnifiedEditorView::resizeEvent( QGraphicsSceneResizeEvent * event )
       
  1195 {
       
  1196  Q_UNUSED(event)
       
  1197  #ifdef _DEBUG_TRACES_
       
  1198  qDebug()<<"resize event";
       
  1199 #endif
       
  1200 
       
  1201  mContentWidget->resize(this->rect().width(),this->rect().height()+1);
       
  1202 }
       
  1203 
       
  1204 //---------------------------------------------------------------
       
  1205 // MsgUnifiedEditorView::createVCards
       
  1206 // @see header file
       
  1207 //---------------------------------------------------------------
       
  1208 int MsgUnifiedEditorView::createVCards(
       
  1209         const QVariant& value, QStringList& filelist)
       
  1210 {
       
  1211     // make sure that temp-folder is created for storing vcards
       
  1212     if(!createTempFolder())
       
  1213     {
       
  1214         return KErrGeneral;
       
  1215     }
       
  1216 
       
  1217     // extract contact-list
       
  1218     QContactManager* contactManager = new QContactManager("symbian");
       
  1219     CntServicesContactList cntServicesContacts = qVariantValue<CntServicesContactList>(value);
       
  1220     int cntCount = cntServicesContacts.count();
       
  1221     QList<QtMobility::QContact> contactList;
       
  1222     for(int i = 0; i < cntCount; i++ )
       
  1223     {
       
  1224         contactList << contactManager->contact( cntServicesContacts.at(i).mContactId );
       
  1225     }
       
  1226     delete contactManager;
       
  1227 
       
  1228     // get list of all versit-documents
       
  1229     QVersitDocument::VersitType versitType(QVersitDocument::VCard21Type);
       
  1230     QVersitContactExporter* exporter = new QVersitContactExporter();
       
  1231     
       
  1232     bool ret_val = exporter->exportContacts(contactList, versitType);
       
  1233     QList<QtMobility::QVersitDocument> documentList = exporter->documents();    
       
  1234 
       
  1235     delete exporter;
       
  1236 
       
  1237     // loop though and create a vcard for each contact
       
  1238     QVersitWriter* writer = new QVersitWriter();
       
  1239     for(int i = 0; i < cntCount; i++ )
       
  1240     {
       
  1241         // buffer to hold vcard data fetched from contacts
       
  1242         QBuffer contactsbuf;
       
  1243         contactsbuf.open(QBuffer::ReadWrite);
       
  1244         writer->setDevice( &contactsbuf );
       
  1245 
       
  1246         //write document data to buffer
       
  1247         QList<QtMobility::QVersitDocument> currDoc;
       
  1248         currDoc << documentList.at(i);
       
  1249         writer->startWriting(currDoc);
       
  1250         if(writer->waitForFinished())
       
  1251         {
       
  1252             // generate file name
       
  1253             QString displayLabel = contactList.at(i).displayLabel();
       
  1254             QString filepath = generateFileName(displayLabel);
       
  1255             QFile file(filepath);
       
  1256             if(file.open(QIODevice::WriteOnly))
       
  1257             {
       
  1258                 // trap ignore so that, incase of multiselection, other vcards are still created
       
  1259                 QByteArray bufArr;
       
  1260                 TRAP_IGNORE(
       
  1261                 CBufBase* contactbufbase = CBufFlat::NewL(contactsbuf.size());
       
  1262                 CleanupStack::PushL(contactbufbase);
       
  1263                 contactbufbase->InsertL( contactbufbase->Size(),
       
  1264                         *XQConversions::qStringToS60Desc8( contactsbuf.data() ) );
       
  1265                 TPtr8 ptrbuf(contactbufbase->Ptr(0));
       
  1266                 bufArr = XQConversions::s60Desc8ToQByteArray(ptrbuf);
       
  1267                 CleanupStack::PopAndDestroy(contactbufbase);
       
  1268                 );
       
  1269                 file.write(bufArr);
       
  1270                 file.close();
       
  1271                 filelist << filepath;
       
  1272             }
       
  1273         }
       
  1274     }
       
  1275 
       
  1276     // cleanup & return
       
  1277     delete writer;
       
  1278     return KErrNone;
       
  1279 }
       
  1280 
       
  1281 
       
  1282 //---------------------------------------------------------------
       
  1283 // MsgUnifiedEditorView::generateFileName
       
  1284 // @param suggestedName suggested name of the file
       
  1285 // @return fullPath of the generated filename
       
  1286 // @algo For multiselected 'Unnamed' contacts, the filename should
       
  1287 // be synthesized as unnamed.vcf, unnamed1.vcf, unnamed2.vcf etc.
       
  1288 //---------------------------------------------------------------
       
  1289 QString MsgUnifiedEditorView::generateFileName(QString& suggestedName)
       
  1290 {
       
  1291     QDir editorTempDir;
       
  1292     editorTempDir.cd(editorTempPath());
       
  1293 
       
  1294     for(int i=0; i<MAX_VCARDS; i++)
       
  1295     {
       
  1296         QString searchFileName = suggestedName;
       
  1297         if(i>0)
       
  1298         {
       
  1299             searchFileName.append(QString::number(i));
       
  1300         }
       
  1301         searchFileName.append(FILE_EXTN);
       
  1302 
       
  1303         // check if filename is already used by an attachment in container
       
  1304         bool alreadyExists = false;
       
  1305         if(mAttachmentContainer)
       
  1306         {
       
  1307             MsgUnifiedEditorAttachmentList attList =
       
  1308                     mAttachmentContainer->attachmentList();
       
  1309             int attCount = attList.count();
       
  1310             for(int j=0; j<attCount; j++)
       
  1311             {
       
  1312                 QFileInfo fileinfo(attList.at(j)->path());
       
  1313                 if(searchFileName == fileinfo.fileName())
       
  1314                 {
       
  1315                     alreadyExists = true;
       
  1316                     break;
       
  1317                 }
       
  1318             }
       
  1319         }
       
  1320 
       
  1321         if(!alreadyExists)
       
  1322         {
       
  1323             if(i>0)
       
  1324             {
       
  1325                 suggestedName.append(QString::number(i));
       
  1326             }
       
  1327             break;
       
  1328         }
       
  1329     }
       
  1330     QString filepath(editorTempPath());
       
  1331     filepath.append(suggestedName);
       
  1332     filepath.append(FILE_EXTN);
       
  1333     return filepath;
       
  1334 }
       
  1335 
       
  1336 void MsgUnifiedEditorView::handleViewExtnActivated(HbListWidgetItem* item)
       
  1337     {
       
  1338     QString itemText = item->text();
       
  1339     
       
  1340     if(itemText == LOC_PHOTO)
       
  1341         {
       
  1342         //launch photo picker.
       
  1343         fetchImages();  
       
  1344         }
       
  1345     else if(itemText == LOC_SOUND)
       
  1346         {
       
  1347         //launch audio picker
       
  1348         fetchAudio();
       
  1349         }
       
  1350     else if(itemText == LOC_BUSINESS_CARD)
       
  1351         {
       
  1352         //launch contact card picker.
       
  1353         fetchContacts();
       
  1354         }
       
  1355    
       
  1356 }
       
  1357 
       
  1358 //---------------------------------------------------------------
       
  1359 // MsgUnifiedEditorView::fetchContacts
       
  1360 // @see header file
       
  1361 //---------------------------------------------------------------
       
  1362 void MsgUnifiedEditorView::fetchContacts()
       
  1363 {
       
  1364     QList<QVariant> args;
       
  1365     QString serviceName("com.nokia.services.phonebookservices");
       
  1366     QString operation("fetch(QString,QString,QString)");
       
  1367     XQAiwRequest* request;
       
  1368     XQApplicationManager appManager;
       
  1369     request = appManager.create(serviceName, "Fetch", operation, true); //embedded
       
  1370     if ( request == NULL )
       
  1371     {
       
  1372         QCRITICAL_WRITE("AIW-ERROR: NULL request");
       
  1373         return;       
       
  1374     }
       
  1375 
       
  1376     // Result handlers
       
  1377     connect (request, SIGNAL(requestOk(const QVariant&)), 
       
  1378         this, SLOT(contactsFetched(const QVariant&)));
       
  1379     connect (request, SIGNAL(requestError(int,const QString&)), 
       
  1380         this, SLOT(serviceRequestError(int,const QString&)));
       
  1381 
       
  1382     args << QString(tr("Phonebook")); 
       
  1383     args << KCntActionAll;
       
  1384     args << KCntFilterDisplayAll;
       
  1385 
       
  1386     request->setArguments(args);
       
  1387     if(!request->send())
       
  1388     {
       
  1389         QDEBUG_WRITE_FORMAT("AIW-ERROR: Request Send failed:",request->lastError());
       
  1390     }
       
  1391     delete request;
       
  1392 }
       
  1393 
       
  1394 //---------------------------------------------------------------
       
  1395 // MsgUnifiedEditorView::fetchImages
       
  1396 // @see header file
       
  1397 //---------------------------------------------------------------
       
  1398 void MsgUnifiedEditorView::fetchImages()
       
  1399 {
       
  1400     QString service("photos");
       
  1401     QString interface("com.nokia.symbian.IImageFetch");
       
  1402     QString operation("fetch()");
       
  1403     XQAiwRequest* request = NULL;
       
  1404     XQApplicationManager appManager;
       
  1405     request = appManager.create(service,interface, operation, true);//embedded
       
  1406     request->setSynchronous(true); // synchronous
       
  1407     if(!request)
       
  1408     {     
       
  1409         QCRITICAL_WRITE("AIW-ERROR: NULL request");
       
  1410         return;
       
  1411     }
       
  1412 
       
  1413     connect(request, SIGNAL(requestOk(const QVariant&)),
       
  1414         this, SLOT(imagesFetched(const QVariant&)));
       
  1415     connect(request, SIGNAL(requestError(int,const QString&)),
       
  1416         this, SLOT(serviceRequestError(int,const QString&)));
       
  1417     
       
  1418     // Make the request
       
  1419     if (!request->send())
       
  1420     {
       
  1421         QDEBUG_WRITE_FORMAT("AIW-ERROR: Request Send failed:" , request->lastError());
       
  1422     }  
       
  1423     delete request;
       
  1424 }
       
  1425 
       
  1426 //---------------------------------------------------------------
       
  1427 // MsgUnifiedEditorView::fetchAudio
       
  1428 // @see header file
       
  1429 //---------------------------------------------------------------
       
  1430 void MsgUnifiedEditorView::fetchAudio()
       
  1431 {
       
  1432     // Launch Audio fetcher view
       
  1433     QVariantList params;
       
  1434     params << MsgBaseView::AUDIOFETCHER; // target view
       
  1435     params << MsgBaseView::UNIEDITOR; // source view
       
  1436     emit switchView(params);
       
  1437 }
       
  1438 
       
  1439 //---------------------------------------------------------------
       
  1440 // MsgUnifiedEditorView::contactsFetched
       
  1441 // @see header file
       
  1442 //---------------------------------------------------------------
       
  1443 void MsgUnifiedEditorView::contactsFetched(const QVariant& value)
       
  1444 {
       
  1445     // create a vcard for each contact fetched and add as attachment
       
  1446     QStringList attachmentList;
       
  1447     if(createVCards(value, attachmentList) == KErrNone)
       
  1448     {
       
  1449         addAttachments(attachmentList);
       
  1450     }
       
  1451 }
       
  1452 
       
  1453 //---------------------------------------------------------------
       
  1454 // MsgUnifiedEditorView::imagesFetched
       
  1455 // @see header file
       
  1456 //---------------------------------------------------------------
       
  1457 void MsgUnifiedEditorView::imagesFetched(const QVariant& result )
       
  1458 {
       
  1459     if(result.canConvert<QStringList>())
       
  1460     {
       
  1461         QStringList fileList = result.value<QStringList>();
       
  1462         if ( fileList.size()>0 )
       
  1463         {
       
  1464             QString filepath(QDir::toNativeSeparators(fileList.at(0)));
       
  1465             mBody->setImage(filepath);
       
  1466         }
       
  1467     }
       
  1468 }
       
  1469 
       
  1470 //---------------------------------------------------------------
       
  1471 // MsgUnifiedEditorView::serviceRequestError
       
  1472 // @see header file
       
  1473 //---------------------------------------------------------------
       
  1474 void MsgUnifiedEditorView::serviceRequestError(int errorCode, const QString& errorMessage)
       
  1475 {
       
  1476     QDEBUG_WRITE_FORMAT(errorMessage,errorCode);
       
  1477 }
       
  1478 
       
  1479 //---------------------------------------------------------------
       
  1480 // MsgUnifiedEditorView::activateInputBlocker
       
  1481 // @see header file
       
  1482 //--------------------------------------------------------------
       
  1483 void MsgUnifiedEditorView::activateInputBlocker()
       
  1484 {
       
  1485     mainWindow()->setInteractive(false);
       
  1486 }
       
  1487 
       
  1488 //---------------------------------------------------------------
       
  1489 // MsgUnifiedEditorView::deactivateInputBlocker
       
  1490 // @see header file
       
  1491 //--------------------------------------------------------------
       
  1492 void MsgUnifiedEditorView::deactivateInputBlocker()
       
  1493 {
       
  1494     mainWindow()->setInteractive(true);
       
  1495 }
       
  1496 
       
  1497 //---------------------------------------------------------------
       
  1498 // MsgUnifiedEditorView::setAttachOptionEnabled
       
  1499 // @see header file
       
  1500 //--------------------------------------------------------------
       
  1501 void MsgUnifiedEditorView::setAttachOptionEnabled(
       
  1502         MsgUnifiedEditorView::TBE_AttachOption opt, bool enable)
       
  1503 {
       
  1504     HbListWidgetItem* wgtItem = mTBExtnContentWidget->item(opt);
       
  1505     wgtItem->setEnabled(enable);
       
  1506 }
       
  1507 
       
  1508 //---------------------------------------------------------------
       
  1509 // MsgUnifiedEditorView::vkbOpened
       
  1510 // @see header file
       
  1511 //---------------------------------------------------------------
       
  1512 void MsgUnifiedEditorView::vkbOpened()
       
  1513 {
       
  1514     hideChrome(true); 
       
  1515     
       
  1516     disconnect(mVkbHost,SIGNAL(keypadOpened()),this,SLOT(vkbOpened()));
       
  1517 }
       
  1518       
       
  1519 //---------------------------------------------------------------
       
  1520 // MsgUnifiedEditorView::vkbClosed
       
  1521 // @see header file
       
  1522 //---------------------------------------------------------------
       
  1523 void MsgUnifiedEditorView::vkbClosed()
       
  1524 {
       
  1525     hideChrome(false);
       
  1526     
       
  1527     connect(mVkbHost,SIGNAL(keypadOpened()),this,SLOT(vkbOpened()));
       
  1528 }
       
  1529 
       
  1530 //---------------------------------------------------------------
       
  1531 // MsgUnifiedEditorView::vkbAboutToOpen
       
  1532 // @see header file
       
  1533 //---------------------------------------------------------------
       
  1534 void MsgUnifiedEditorView::vkbAboutToOpen()
       
  1535 {    
       
  1536 	  //This is done to avoid user action on attachment
       
  1537 	  //toolbar button when vkb is opening
       
  1538     mAttachAction->setDisabled(true);
       
  1539     disconnect(mVkbHost,SIGNAL(aboutToOpen()),
       
  1540             this,SLOT(vkbAboutToOpen()));
       
  1541 }
       
  1542       
       
  1543 //---------------------------------------------------------------
       
  1544 // MsgUnifiedEditorView::vkbAboutToClose
       
  1545 // @see header file
       
  1546 //---------------------------------------------------------------
       
  1547 void MsgUnifiedEditorView::vkbAboutToClose()
       
  1548 {      
       
  1549     mAttachAction->setDisabled(false);
       
  1550     connect(mVkbHost,SIGNAL(aboutToOpen()),
       
  1551             this,SLOT(vkbAboutToOpen()));
       
  1552 }
       
  1553 //---------------------------------------------------------------
       
  1554 // MsgUnifiedEditorView::hideChrome
       
  1555 //
       
  1556 //---------------------------------------------------------------
       
  1557 void MsgUnifiedEditorView::hideChrome(bool hide)
       
  1558 {
       
  1559     if(hide)
       
  1560     {        
       
  1561         this->setContentFullScreen(true);
       
  1562         this->hideItems(Hb::StatusBarItem | Hb::TitleBarItem);
       
  1563     }
       
  1564     else
       
  1565     {
       
  1566         this->setContentFullScreen(false);
       
  1567         this->showItems(Hb::StatusBarItem | Hb::TitleBarItem);
       
  1568     }
       
  1569 }
       
  1570 
       
  1571 //---------------------------------------------------------------
       
  1572 // MsgUnifiedEditorView::doDelayedConstruction
       
  1573 //
       
  1574 //---------------------------------------------------------------
       
  1575 void MsgUnifiedEditorView::doDelayedConstruction()
       
  1576 {
       
  1577     addMenu();
       
  1578     createTempFolder();
       
  1579     
       
  1580     //Create VKB instance and listen to VKB open and close signals.
       
  1581     mVkbHost = new HbAbstractVkbHost(this);
       
  1582     connect(mVkbHost, SIGNAL(keypadOpened()), this, SLOT(vkbOpened()));
       
  1583     connect(mVkbHost, SIGNAL(keypadClosed()), this, SLOT(vkbClosed()));
       
  1584     connect(mVkbHost,SIGNAL(aboutToOpen()),this,SLOT(vkbAboutToOpen()));
       
  1585     connect(mVkbHost,SIGNAL(aboutToClose()),this,SLOT(vkbAboutToClose()));
       
  1586     
       
  1587     disconnect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(doDelayedConstruction()));
       
  1588     
       
  1589 }
       
  1590 
       
  1591 //---------------------------------------------------------------
       
  1592 // MsgUnifiedEditorView::createTempFolder
       
  1593 //
       
  1594 //---------------------------------------------------------------
       
  1595 bool MsgUnifiedEditorView::createTempFolder()
       
  1596 {
       
  1597     // create editor's temp folder
       
  1598     QDir tempDir;
       
  1599     QString tempPath(editorTempPath());
       
  1600     bool result = tempDir.mkpath(tempPath);    
       
  1601     return result;
       
  1602 }
       
  1603 
       
  1604 //---------------------------------------------------------------
       
  1605 // MsgUnifiedEditorView::removeTempFolder
       
  1606 //
       
  1607 //---------------------------------------------------------------
       
  1608 void MsgUnifiedEditorView::removeTempFolder()
       
  1609 {
       
  1610     QDir tempDir;
       
  1611     QString tempPath(editorTempPath());
       
  1612     tempDir.cd(tempPath);
       
  1613     QStringList contentList(tempDir.entryList());
       
  1614     
       
  1615     int contentCount = contentList.count();
       
  1616     for(int i=0; i<contentCount; i++)
       
  1617     {
       
  1618         tempDir.remove(contentList.at(i));
       
  1619     }
       
  1620     
       
  1621     tempDir.cdUp();
       
  1622     tempDir.rmdir(UNIFIED_EDITOR_TEMP_FOLDER); 
       
  1623 }
       
  1624 
       
  1625 //---------------------------------------------------------------
       
  1626 // MsgUnifiedEditorView::setFocus
       
  1627 //
       
  1628 //---------------------------------------------------------------
       
  1629 void MsgUnifiedEditorView::setFocus(MsgUnifiedEditorBaseWidget* item)
       
  1630 {
       
  1631     if(item)
       
  1632     {
       
  1633         item->setFocus();  
       
  1634     }
       
  1635 }
       
  1636 
       
  1637 //---------------------------------------------------------------
       
  1638 // MsgUnifiedEditorView::onContentChanged
       
  1639 //
       
  1640 //---------------------------------------------------------------
       
  1641 void MsgUnifiedEditorView::onContentChanged()
       
  1642 {
       
  1643     mCanSaveToDrafts = true; 
       
  1644 }
       
  1645 
       
  1646 //---------------------------------------------------------------
       
  1647 // MsgUnifiedEditorView::onDialogDeleteMsg
       
  1648 //---------------------------------------------------------------
       
  1649 void MsgUnifiedEditorView::onDialogDeleteMsg(HbAction* action)
       
  1650 {
       
  1651     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
       
  1652     if (action == dlg->actions().at(0)) {
       
  1653 
       
  1654         mCanSaveToDrafts = false;
       
  1655 
       
  1656         //delete if draft entry opened
       
  1657         if (mOpenedMessageId.getId() != -1) {
       
  1658             if (!mPluginLoader) {
       
  1659                 mPluginLoader = new UniEditorPluginLoader(this);
       
  1660             }
       
  1661 
       
  1662             UniEditorPluginInterface* pluginInterface = mPluginLoader->getUniEditorPlugin(
       
  1663                 MsgUnifiedEditorMonitor::messageType());
       
  1664 
       
  1665             pluginInterface->deleteDraftsEntry(mOpenedMessageId.getId());
       
  1666         }
       
  1667 
       
  1668         //trigger back action.
       
  1669         HbAction* backAction = this->navigationAction();
       
  1670         if (backAction) {
       
  1671             backAction->trigger();
       
  1672         }
       
  1673 
       
  1674     }
       
  1675 }
       
  1676 
       
  1677 //---------------------------------------------------------------
       
  1678 // MsgUnifiedEditorView::onDialogSmsSettings
       
  1679 //---------------------------------------------------------------
       
  1680 void MsgUnifiedEditorView::onDialogSmsSettings(HbAction* action)
       
  1681 {
       
  1682     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
       
  1683     if (action == dlg->actions().at(0)) {
       
  1684         
       
  1685         QVariantList params;
       
  1686         params << MsgBaseView::MSGSETTINGS;// target view
       
  1687         params << MsgBaseView::UNIEDITOR; // source view
       
  1688         params << MsgSettingsView::SMSView;
       
  1689         emit switchView(params);
       
  1690     
       
  1691     }
       
  1692 }
       
  1693 
       
  1694 //---------------------------------------------------------------
       
  1695 // MsgUnifiedEditorView::onDialogMmsSettings
       
  1696 //---------------------------------------------------------------
       
  1697 void MsgUnifiedEditorView::onDialogMmsSettings(HbAction* action)
       
  1698 {
       
  1699     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
       
  1700     if (action == dlg->actions().at(0)) {
       
  1701         
       
  1702         QVariantList params;
       
  1703         params << MsgBaseView::MSGSETTINGS;// target view
       
  1704         params << MsgBaseView::UNIEDITOR; // source view
       
  1705         params << MsgSettingsView::MMSView;
       
  1706         emit switchView(params); 
       
  1707     }
       
  1708 }
       
  1709 
       
  1710 //---------------------------------------------------------------
       
  1711 // MsgUnifiedEditorView::enableSendButton
       
  1712 // @see header file
       
  1713 //--------------------------------------------------------------
       
  1714 void MsgUnifiedEditorView::enableSendButton(bool enable)
       
  1715     {
       
  1716     if(mSendAction)
       
  1717         {
       
  1718          // enable/disable based on only if its disabled/enabled.
       
  1719          // this check is to avoid unnecessary calls to mSendAction->setEnabled(enable);
       
  1720         if(mSendAction->isEnabled() != enable )
       
  1721             mSendAction->setEnabled(enable);
       
  1722         }
       
  1723     }
       
  1724 
       
  1725 // ----------------------------------------------------------------------------
       
  1726 // MsgUnifiedEditorView::formatAddresses
       
  1727 // @see header
       
  1728 // ----------------------------------------------------------------------------
       
  1729 void MsgUnifiedEditorView::formatAddresses(
       
  1730         ConvergedMessageAddressList& addresses)
       
  1731 {       
       
  1732 
       
  1733     for(int i=0; i < addresses.count() ;i++ )
       
  1734     {
       
  1735         QString addr = addresses[i]->address();
       
  1736         
       
  1737         HBufC *tempAddr = XQConversions::qStringToS60Desc(addr);     
       
  1738             
       
  1739         TPtr ptr = tempAddr->Des();
       
  1740                     
       
  1741          // Note: This is just to parse spaces etc away from phonenumbers.
       
  1742          //       Ignore EFalse returned for email addresses.   
       
  1743         CommonPhoneParser::ParsePhoneNumber(ptr , 
       
  1744                                             CommonPhoneParser::ESMSNumber );        
       
  1745        
       
  1746         addr = XQConversions::s60DescToQString(tempAddr->Des()); 
       
  1747         
       
  1748         addresses[i]->setAddress(addr);
       
  1749         
       
  1750         delete tempAddr;                                                       
       
  1751     }       
       
  1752 }
       
  1753 //EOF