messagingapp/msgui/unifiededitor/src/msgunieditorview.cpp
changeset 25 84d9eb65b26f
parent 23 238255e8b033
child 27 e4592d119491
child 37 518b245aa84c
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
    14  * Description:
    14  * Description:
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 // SYSTEM INCLUDES
    18 // SYSTEM INCLUDES
    19 #include <HbWidget>
    19 #include <e32base.h>
    20 #include <HbMenu>
    20 #include <HbMenu>
    21 #include <HbAction>
    21 #include <HbAction>
    22 #include <HbToolBar>
    22 #include <HbToolBar>
    23 #include <QGraphicsLinearLayout>
    23 #include <QGraphicsLinearLayout>
    24 #include <HbGroupBox>
    24 #include <HbGroupBox>
    25 #include <HbScrollArea>
    25 #include <HbScrollArea>
    26 #include <QDateTime>
    26 #include <QDateTime>
    27 #include <QDir>
    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 <HbMessageBox>
       
    39 #include <xqaiwrequest.h>
       
    40 #include <xqappmgr.h>
       
    41 
       
    42 // QT Mobility for fetching business card
       
    43 #include <qversitwriter.h>
       
    44 #include <qversitdocument.h>
       
    45 #include <qcontact.h>
       
    46 #include <qcontactmanager.h>
       
    47 #include <qversitcontactexporter.h>
       
    48 #include <cntservicescontact.h>
    28 
    49 
    29 // USER INCLUDES
    50 // USER INCLUDES
    30 #include "debugtraces.h"
    51 #include "debugtraces.h"
    31 #include "msgunieditorview.h"
    52 #include "msgunieditorview.h"
    32 #include "msgunieditoraddress.h"
    53 #include "msgunieditoraddress.h"
    33 #include "msgunieditorsubject.h"
    54 #include "msgunieditorsubject.h"
    34 #include "msgunieditorbody.h"
    55 #include "msgunieditorbody.h"
    35 #include "msgtypenotifier.h"
       
    36 #include "msgmonitor.h"
    56 #include "msgmonitor.h"
    37 #include "msgattachmentcontainer.h"
    57 #include "msgattachmentcontainer.h"
    38 #include "msguiutilsmanager.h"
    58 #include "msgsendutil.h"
    39 #include "convergedmessageaddress.h"
    59 #include "convergedmessageaddress.h"
    40 #include "matchphnumberutil.h"
       
    41 #include "unieditorgenutils.h"
    60 #include "unieditorgenutils.h"
    42 #include "unieditorpluginloader.h"
    61 #include "unieditorpluginloader.h"
    43 #include "unieditorplugininterface.h"
    62 #include "unieditorplugininterface.h"
    44 
    63 
    45 // Constants
    64 // Constants
    46 const QString SEND_ICON(":/qtg_mono_send.svg");
    65 const QString SEND_ICON("qtg_mono_send");
    47 const QString ATTACH_ICON(":/qtg_mono_attach.svg");
    66 const QString ATTACH_ICON("qtg_mono_attach");
       
    67 // temporary folder for unieditor
       
    68 const QString UNIFIED_EDITOR_TEMP_FOLDER("unifiededitor");
    48 
    69 
    49 const int INVALID_MSGID = -1;
    70 const int INVALID_MSGID = -1;
       
    71 // vcard file extn.
       
    72 const QString FILE_EXTN(".vcf");
       
    73 // Max vcards inside a msg. Using a very large number.
       
    74 // TODO: how we can avoid this?
       
    75 const int MAX_VCARDS(1000);
    50 
    76 
    51 // LOCALIZED CONSTANTS
    77 // LOCALIZED CONSTANTS
    52 #define LOC_TO hbTrId("txt_messaging_formlabel_to")
    78 //To,Cc.Bcc
       
    79 #define LOC_TO  hbTrId("txt_messaging_formlabel_to")
       
    80 #define LOC_CC hbTrId("txt_messaging_formlabel_cc")
       
    81 #define LOC_BCC hbTrId("txt_messaging_formlabel_bcc")
       
    82 
       
    83 //attach options
       
    84 #define LOC_PHOTO           hbTrId("txt_messaging_button_photo")
       
    85 #define LOC_SOUND           hbTrId("txt_messaging_button_sound")
       
    86 #define LOC_BUSINESS_CARD   hbTrId("txt_messaging_button_business_card")
       
    87 
       
    88 //options menu.
       
    89 #define LOC_ADD_SUBJECT     hbTrId("txt_messaging_opt_add_subject")
       
    90 #define LOC_ADD_CC_BCC      hbTrId("txt_messaging_opt_add_cc_bcc")
       
    91 #define LOC_PRIORITY        hbTrId("txt_messaging_setlabel_priority")
       
    92 #define LOC_SENDING_OPTIONS hbTrId("txt_messaging_opt_sending_options")
       
    93 #define LOC_DELETE_MESSAGE  hbTrId("txt_messaging_opt_delete_message")
       
    94 
       
    95 //priority sub menu
    53 #define LOC_HIGH hbTrId("txt_messaging_setlabel_priority_val_high")
    96 #define LOC_HIGH hbTrId("txt_messaging_setlabel_priority_val_high")
    54 #define LOC_NORMAL hbTrId("txt_messaging_setlabel_priority_val_normal")
    97 #define LOC_NORMAL hbTrId("txt_messaging_setlabel_priority_val_normal")
    55 #define LOC_LOW hbTrId("txt_messaging_setlabel_priority_val_low")
    98 #define LOC_LOW hbTrId("txt_messaging_setlabel_priority_val_low")
    56 #define LOC_SENDING_OPTIONS hbTrId("txt_messaging_opt_sending_options")
    99 
    57 
   100 //group box
    58 #define LOC_DELETE_MESSAGE hbTrId("txt_messaging_opt_delete_message")
   101 #define LOC_OTHER_RECIPIENTS(n) hbTrId("txt_messaging_group_title_ln_other_recipients",n)
    59 #define LOC_CC hbTrId("txt_messaging_formlabel_cc")
   102 
    60 #define LOC_BCC hbTrId("txt_messaging_formlabel_bcc")
   103 //saved to draft note
    61 #define LOC_OTHER_RECIPIENTS hbTrId("txt_messaging_group_title_ln_other_recipients")
   104 #define LOC_SAVED_TO_DRAFTS    hbTrId("txt_messaging_dpopinfo_saved_to_drafts")
    62 
   105 
    63 #define LOC_PHOTO hbTrId("txt_messaging_button_photo")
   106 //delete confermation
    64 #define LOC_VIDEO hbTrId("txt_messaging_button_video")
   107 #define LOC_NOTE_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message")
    65 #define LOC_SOUND hbTrId("txt_messaging_button_sound")
   108 #define LOC_BUTTON_DELETE       hbTrId("txt_common_button_delete")
    66 #define LOC_MORE hbTrId("txt_messaging_button_more")
   109 #define LOC_BUTTON_CANCEL       hbTrId("txt_common_button_cancel")
       
   110 #define LOC_DIALOG_OK           hbTrId("txt_common_button_ok")
       
   111 
       
   112 //extension list item frame.
       
   113 const QString POPUP_LIST_FRAME("qtg_fr_popup_list_normal");
       
   114 
       
   115 // LOCAL FUNCTIONS
       
   116 QString editorTempPath();
    67 
   117 
    68 //---------------------------------------------------------------
   118 //---------------------------------------------------------------
    69 // MsgUnifiedEditorView::MsgUnifiedEditorView
   119 // MsgUnifiedEditorView::MsgUnifiedEditorView
    70 // @see header file
   120 // @see header file
    71 //---------------------------------------------------------------
   121 //---------------------------------------------------------------
    72 MsgUnifiedEditorView::MsgUnifiedEditorView( QGraphicsItem *parent ) :
   122 MsgUnifiedEditorView::MsgUnifiedEditorView( QGraphicsItem *parent ) :
    73 MsgBaseView(parent),
   123     MsgBaseView(parent),
    74 mSubjectAction(0),
   124     mSubjectAction(0),
    75 mCcBccAction(0),
   125     mCcBccAction(0),
    76 mMainLayout(0),
   126     mMainLayout(0),
    77 mSubjectField(0),
   127     mSubjectField(0),
    78 mToField(0),
   128     mToField(0),
    79 mCcField(0),
   129     mCcField(0),
    80 mBccField(0),
   130     mBccField(0),
    81 mBody(0),
   131     mBody(0),
    82 mPrioritySubMenu(0),
   132     mContentWidget(0),
    83 mContentWidget(0),
   133     mMsgMonitor(0),    
    84 mNotifier(0),
   134     mAttachmentContainer(0),
    85 mMsgMonitor(0),
   135     mPluginLoader(0),
    86 mUtilsManager(0),
   136     mCanSaveToDrafts(true)
    87 mAttachmentContainer(0),
   137     {
    88 mPluginLoader(0)
       
    89 {
       
    90     addMenu();
   138     addMenu();
    91     addToolBar();
   139     addToolBar();
    92 
   140 
    93     HbScrollArea* scrollArea = new HbScrollArea(this);
   141     HbScrollArea* scrollArea = new HbScrollArea(this);
    94     this->setWidget(scrollArea);
   142     this->setWidget(scrollArea);
    95 
   143 
    96     mContentWidget = new HbWidget(this);
   144     mContentWidget = new HbWidget(this);
    97     scrollArea->setContentWidget(mContentWidget);
   145     scrollArea->setContentWidget(mContentWidget);
    98 
   146 
    99     mPluginPath = pluginPath();
   147     mPluginPath = pluginPath(); 
   100 
   148 
   101     mMainLayout = new QGraphicsLinearLayout(Qt::Vertical, mContentWidget);
   149     mMainLayout = new QGraphicsLinearLayout(Qt::Vertical, mContentWidget);
   102     mMainLayout->setContentsMargins(0,0,0,0);
   150     qreal vTopSpacing = 0.0;
   103 
       
   104     //Adding suitable spacing between the Custom Widgets
       
   105     qreal vItemSpacing = 0.0;
   151     qreal vItemSpacing = 0.0;
       
   152     style()->parameter("hb-param-margin-gene-top",vTopSpacing);    
   106     style()->parameter("hb-param-margin-gene-middle-vertical",vItemSpacing);
   153     style()->parameter("hb-param-margin-gene-middle-vertical",vItemSpacing);
       
   154     
       
   155     mMainLayout->setContentsMargins(0,vTopSpacing,0,0);
   107     mMainLayout->setSpacing(vItemSpacing);
   156     mMainLayout->setSpacing(vItemSpacing);
   108 
   157 
   109     // notifier for recording msg type transitions between sms & mms
   158     mMsgMonitor = new MsgMonitor(this);    
   110     mNotifier = new MsgTypeNotifier(this);
       
   111     mMsgMonitor = new MsgMonitor(this);
       
   112     mUtilsManager = new MsgUiUtilsManager(this);
       
   113 
   159 
   114     mToField = new MsgUnifiedEditorAddress( LOC_TO, mPluginPath, mContentWidget );
   160     mToField = new MsgUnifiedEditorAddress( LOC_TO, mPluginPath, mContentWidget );
   115     mBody = new MsgUnifiedEditorBody(mPluginPath, mContentWidget);
   161     mBody = new MsgUnifiedEditorBody(mPluginPath, mContentWidget);
   116 
   162 
   117     mMainLayout->addItem(mToField);
   163     mMainLayout->addItem(mToField);
   118     mMainLayout->addItem(mBody);
   164     mMainLayout->addItem(mBody);
   119  
   165  
   120     //Set the invalid msg id
   166     //Set the invalid msg id
   121     mOpenedMessageId.setId(-1);
   167     mOpenedMessageId.setId(-1);
   122     
   168 
       
   169     // create editor's temp folder
       
   170     QDir tempDir = QDir(QString());
       
   171     QString tempPath(editorTempPath());
       
   172     if(tempDir.mkpath(tempPath))
       
   173     {
       
   174         tempDir.cd(tempPath);
       
   175         // remove stale folder content when freshly launched
       
   176         QStringList contentList(tempDir.entryList());
       
   177         int contentCount = contentList.count();
       
   178         for(int i=0; i<contentCount; i++)
       
   179         {
       
   180             tempDir.remove(contentList.at(i));
       
   181         }
       
   182     }
       
   183 
   123     connect(mToField, SIGNAL(sendMessage()), this, SLOT(send()));
   184     connect(mToField, SIGNAL(sendMessage()), this, SLOT(send()));
   124     connect(mBody, SIGNAL(sendMessage()), this, SLOT(send()));
   185     connect(mBody, SIGNAL(sendMessage()), this, SLOT(send()));
   125     connect(mBody, SIGNAL(mmContentAdded(bool)),
   186     connect(mBody, SIGNAL(contentChanged()),
   126                      mNotifier, SLOT(onMMContentAdded(bool)));
   187             mMsgMonitor, SLOT(checkMsgTypeChange()));
   127     connect(mBody, SIGNAL(sizeChanged(int)),
   188     }
   128                      mMsgMonitor, SLOT(onSizeChanged(int)));
       
   129     connect(mUtilsManager, SIGNAL(imagesFetched(const QVariant&)),
       
   130                      this, SLOT(imagesFetched(const QVariant&)));
       
   131     connect(mUtilsManager, SIGNAL(audiosFetched(const QVariant&)),
       
   132                      this, SLOT(audiosFetched(const QVariant&)));
       
   133 }
       
   134 
   189 
   135 //---------------------------------------------------------------
   190 //---------------------------------------------------------------
   136 // MsgUnifiedEditorView::~MsgUnifiedEditorView
   191 // MsgUnifiedEditorView::~MsgUnifiedEditorView
   137 // @see header file
   192 // @see header file
   138 //---------------------------------------------------------------
   193 //---------------------------------------------------------------
   139 MsgUnifiedEditorView::~MsgUnifiedEditorView()
   194 MsgUnifiedEditorView::~MsgUnifiedEditorView()
   140 {
   195 {
       
   196     // clean editor's temporary contents before exiting
       
   197     QDir tempDir = QDir(QString());
       
   198     QString tempPath(editorTempPath());
       
   199     tempDir.cd(tempPath);
       
   200     QStringList contentList(tempDir.entryList());
       
   201     int contentCount = contentList.count();
       
   202     for(int i=0; i<contentCount; i++)
       
   203     {
       
   204         tempDir.remove(contentList.at(i));
       
   205     }
       
   206     tempDir.cdUp();
       
   207     tempDir.rmdir(UNIFIED_EDITOR_TEMP_FOLDER);
   141 }
   208 }
   142 
   209 
   143 void MsgUnifiedEditorView::addMenu()
   210 void MsgUnifiedEditorView::addMenu()
   144 {
   211 {
   145     //Create Menu Options
   212     //Create Menu Options
   146     HbMenu* mainMenu = new HbMenu();
   213     HbMenu* mainMenu = new HbMenu();
   147 
   214 
   148     //TODO:These 2 should be submenu option to Add
   215     //TODO:These 2 should be submenu option to Add
   149     mSubjectAction = mainMenu->addAction(tr("Add Subject"));
   216     mSubjectAction = mainMenu->addAction(LOC_ADD_SUBJECT);
   150     mCcBccAction = mainMenu->addAction(tr("Add Cc/Bcc"));
   217     mCcBccAction = mainMenu->addAction(LOC_ADD_CC_BCC);
   151     
   218     
   152     mPrioritySubMenu = mainMenu->addMenu(tr("Add Priority"));
   219     HbMenu* prioritySubMenu = mainMenu->addMenu(LOC_PRIORITY);
   153 
   220 
   154     HbAction* highPriorityAction = mPrioritySubMenu->addAction(LOC_HIGH);
   221     HbAction* highPriorityAction = prioritySubMenu->addAction(LOC_HIGH);
   155     highPriorityAction->setData(ConvergedMessage::High);
   222     highPriorityAction->setData(ConvergedMessage::High);
   156 
   223 
   157     HbAction* normalPriorityAction = mPrioritySubMenu->addAction(LOC_NORMAL);
   224     HbAction* normalPriorityAction = prioritySubMenu->addAction(LOC_NORMAL);
   158     normalPriorityAction->setData(ConvergedMessage::Normal);
   225     normalPriorityAction->setData(ConvergedMessage::Normal);
   159 
   226 
   160     HbAction* lowPriorityAction = mPrioritySubMenu->addAction(LOC_LOW);
   227     HbAction* lowPriorityAction = prioritySubMenu->addAction(LOC_LOW);
   161     lowPriorityAction->setData(ConvergedMessage::Low);
   228     lowPriorityAction->setData(ConvergedMessage::Low);
   162 
   229 
   163     HbAction* sendOptionsAction = mainMenu->addAction(LOC_SENDING_OPTIONS);
   230     HbAction* sendOptionsAction = mainMenu->addAction(LOC_SENDING_OPTIONS);
   164     HbAction* deleteMsgAction = mainMenu->addAction(LOC_DELETE_MESSAGE);
   231     HbAction* deleteMsgAction = mainMenu->addAction(LOC_DELETE_MESSAGE);
   165     HbAction* helpAction = mainMenu->addAction(tr("Help"));
       
   166 
   232 
   167     connect(mSubjectAction,SIGNAL(triggered()),this, SLOT(addSubject()));
   233     connect(mSubjectAction,SIGNAL(triggered()),this, SLOT(addSubject()));
   168     connect(mCcBccAction,SIGNAL(triggered()),this, SLOT(addCcBcc()));
   234     connect(mCcBccAction,SIGNAL(triggered()),this, SLOT(addCcBcc()));
   169     connect(highPriorityAction, SIGNAL(triggered()), this, SLOT(changePriority()));
   235     connect(highPriorityAction, SIGNAL(triggered()), this, SLOT(changePriority()));
   170     connect(normalPriorityAction, SIGNAL(triggered()), this, SLOT(changePriority()));
   236     connect(normalPriorityAction, SIGNAL(triggered()), this, SLOT(changePriority()));
   171     connect(lowPriorityAction, SIGNAL(triggered()), this, SLOT(changePriority()));
   237     connect(lowPriorityAction, SIGNAL(triggered()), this, SLOT(changePriority()));
   172     connect(sendOptionsAction,SIGNAL(triggered()),this, SLOT(sendingOptions()));
   238     connect(sendOptionsAction,SIGNAL(triggered()),this, SLOT(sendingOptions()));
   173     connect(deleteMsgAction,SIGNAL(triggered()),this, SLOT(deleteMessage()));
   239     connect(deleteMsgAction,SIGNAL(triggered()),this, SLOT(deleteMessage()));
   174     connect(helpAction,SIGNAL(triggered()),this, SLOT(launchHelp()));
       
   175 
   240 
   176     setMenu(mainMenu);
   241     setMenu(mainMenu);
   177 }
   242 }
   178 
   243 
   179 void MsgUnifiedEditorView::openDraftsMessage(ConvergedMessageId& messageId,
   244 void MsgUnifiedEditorView::openDraftsMessage(const QVariantList& editorData)
   180     ConvergedMessage::MessageType messageType )
   245 {
   181 {
   246     // unpack editor's data
       
   247     // first arg is convergedmessage
       
   248     QByteArray dataArray = editorData.at(0).toByteArray();
       
   249     ConvergedMessage* messageDetails = new ConvergedMessage;
       
   250     QDataStream stream(&dataArray, QIODevice::ReadOnly);
       
   251     messageDetails->deserialize(stream);
       
   252     ConvergedMessage::MessageType messageType = messageDetails->messageType();
       
   253     ConvergedMessageId messageId = *(messageDetails->id());
       
   254     delete messageDetails;
       
   255 
   182     if(!mPluginLoader)
   256     if(!mPluginLoader)
   183     {
   257     {
   184         mPluginLoader = new UniEditorPluginLoader(this);
   258         mPluginLoader = new UniEditorPluginLoader(this);
   185         mPluginLoader->loadPlugins();
   259     }
   186     }
   260 
   187     
       
   188     UniEditorPluginInterface* pluginInterface =
   261     UniEditorPluginInterface* pluginInterface =
   189         mPluginLoader->getUniEditorPlugin(messageType);
   262         mPluginLoader->getUniEditorPlugin(messageType);
   190     
   263 
   191     mOpenedMessageId.setId(messageId.getId());
   264     mOpenedMessageId.setId(messageId.getId());
   192     mmOpenedMessageType = messageType;
   265     mmOpenedMessageType = messageType;
   193 
   266 
   194     //Fetch the converged message from the msgId
   267     //Fetch the converged message from the msgId
   195     ConvergedMessage* msg;
   268     ConvergedMessage* msg;
   196     msg = pluginInterface->convertFrom(messageId.getId());
   269     msg = pluginInterface->convertFrom(messageId.getId());
   197     
   270 
   198     if( msg != NULL )
   271     if( msg != NULL )
   199     {    
   272     {
   200         //Populate the content inside editor
   273         //Populate the content inside editor
   201         populateDraftsContent(*msg);
   274         populateContentIntoEditor(*msg);
   202         delete msg;
   275         delete msg;
   203     }
   276     }
   204 }
   277 }
   205 
   278 
   206 void MsgUnifiedEditorView::populateContent(const ConvergedMessage& messageDetails, int editorFields)
   279 void MsgUnifiedEditorView::forwardMessage(ConvergedMessageId& messageId,
   207 {
   280     ConvergedMessage::MessageType messageType )
   208     mToField->setAddresses(messageDetails.toAddressList());
   281 {
   209     QString bodyTxt = messageDetails.bodyText();
   282     if(!mPluginLoader)
   210     mBody->setText(bodyTxt);
   283     {
   211 
   284         mPluginLoader = new UniEditorPluginLoader(this);
   212     int attachmentCount = messageDetails.attachments().count();
   285   
   213     if(attachmentCount == 1)
   286     }
   214     {
   287     UniEditorPluginInterface* pluginInterface = NULL;
   215         int imageSize=0;
   288     if( messageType == ConvergedMessage::Mms )
   216         QString mimeType;
   289     {
   217         TMsgMediaType mediaType = EMsgMediaUnknown;
   290         pluginInterface =
   218         QString filePath = messageDetails.attachments().at(0)->filePath();
   291                 mPluginLoader->getUniEditorPlugin(ConvergedMessage::Mms);
   219         UniEditorGenUtils* genUtils = new UniEditorGenUtils;
   292     }
   220         TRAP_IGNORE(genUtils->getFileInfoL(filePath,imageSize,
   293     else // For sms,vcard,vcal cases
       
   294     {
       
   295         pluginInterface =
       
   296                 mPluginLoader->getUniEditorPlugin(ConvergedMessage::Sms);
       
   297     }
       
   298 
       
   299     //Fetch the converged message from the msgId
       
   300     ConvergedMessage* msg;
       
   301     msg = pluginInterface->convertFrom(messageId.getId(),
       
   302         UniEditorPluginInterface::Forward);
       
   303 
       
   304     if( msg != NULL )
       
   305     {
       
   306         //Populate the content inside editor
       
   307         populateContentIntoEditor(*msg);
       
   308         delete msg;
       
   309     }
       
   310 }
       
   311 
       
   312 void MsgUnifiedEditorView::populateContent(const QVariantList& editorData)
       
   313 {
       
   314     // unpack editor's data
       
   315     // first arg is convergedmessage
       
   316     QByteArray dataArray = editorData.at(0).toByteArray();
       
   317     ConvergedMessage* messageDetails = new ConvergedMessage;
       
   318     QDataStream stream(&dataArray, QIODevice::ReadOnly);
       
   319     messageDetails->deserialize(stream);
       
   320 
       
   321     // get next arg i.e. editor operation command
       
   322     int editorOp = 0;
       
   323     if(editorData.length() > 1)
       
   324     {
       
   325         editorOp = editorData.at(1).toInt();
       
   326     }
       
   327 
       
   328     // population logic based on editor Operation command
       
   329     switch(editorOp)
       
   330     {
       
   331         case MsgBaseView::ADD_RECIPIENTS:
       
   332         {
       
   333             addCcBcc();
       
   334         }
       
   335         break;
       
   336         case MsgBaseView::ADD_SUBJECT:
       
   337         {
       
   338             addSubject();
       
   339         }
       
   340         break;
       
   341         case MsgBaseView::ADD_VCARD:
       
   342         {
       
   343             contactsFetched(editorData.at(2));
       
   344         }
       
   345         break;
       
   346         case MsgBaseView::FORWARD_MSG:
       
   347         {
       
   348             forwardMessage(*messageDetails->id(), messageDetails->messageType());
       
   349         }
       
   350         break;
       
   351         default:
       
   352         break;
       
   353     }
       
   354 
       
   355     // additional common operations for non-forwarded messages
       
   356     if(editorOp != MsgBaseView::FORWARD_MSG)
       
   357     {
       
   358         mToField->setAddresses(messageDetails->toAddressList());
       
   359         QString bodyTxt = messageDetails->bodyText();
       
   360         mBody->setText(bodyTxt);
       
   361 
       
   362         int attachmentCount = messageDetails->attachments().count();
       
   363         QStringList pendingAttList;
       
   364         for(int i=0; i<attachmentCount; i++)
       
   365         {
       
   366             int imageSize=0;
       
   367             QString mimeType;
       
   368             TMsgMediaType mediaType = EMsgMediaUnknown;
       
   369             QString filePath = messageDetails->attachments().at(i)->filePath();
       
   370             UniEditorGenUtils* genUtils = new UniEditorGenUtils;
       
   371             TRAP_IGNORE(genUtils->getFileInfoL(filePath,imageSize,
   221                                            mimeType,mediaType));
   372                                            mimeType,mediaType));
   222         delete genUtils;
   373             delete genUtils;
   223         switch(mediaType)
   374             switch(mediaType)
   224         {
       
   225             case EMsgMediaImage:
       
   226             {
   375             {
   227                 mBody->setImage(filePath);
   376                 case EMsgMediaImage:
       
   377                 {
       
   378                     mBody->setImage(filePath);
       
   379                     addSubject();
       
   380                 }
       
   381                 break;
       
   382                 case EMsgMediaVideo:
       
   383                 {
       
   384                     mBody->setVideo(filePath);
       
   385                     addSubject();
       
   386                 }
       
   387                 break;
       
   388                 case EMsgMediaAudio:
       
   389                 {
       
   390                     mBody->setAudio(filePath);
       
   391                     addSubject();
       
   392                 }
       
   393                 break;
       
   394                 default:
       
   395                 {
       
   396                     pendingAttList << filePath;
       
   397                 }
   228                 break;
   398                 break;
   229             }
   399             }
   230             case EMsgMediaVideo:
   400         }
   231             {
   401         // add pending attachments in bulk
   232                 mBody->setVideo(filePath);
   402         addAttachments(pendingAttList);
   233                 break;
   403     }
   234             }
   404     delete messageDetails;
   235             case EMsgMediaAudio:
   405 }
   236             {
   406 
   237                 mBody->setAudio(filePath);
   407 void MsgUnifiedEditorView::populateContentIntoEditor(
   238                 break;
       
   239             }
       
   240             case EMsgMediaUnknown:
       
   241             case EMsgMediaText:
       
   242             default:
       
   243             {
       
   244                 addAttachment(filePath);
       
   245                 break;
       
   246             }
       
   247         }
       
   248         
       
   249         addSubject();
       
   250 	}
       
   251 	else if(attachmentCount > 1)
       
   252 	{
       
   253 		for(int i=0; i<attachmentCount; i++)
       
   254 		{
       
   255 		    QString filePath = messageDetails.attachments().at(i)->filePath();
       
   256 		    //TODO: put size checks and show size exceeded msg when appropriate
       
   257 		    addAttachment(filePath);
       
   258 		}
       
   259 		
       
   260 		addSubject();
       
   261 	}
       
   262 
       
   263 	if(editorFields & MsgBaseView::ADD_RECIPIENTS)
       
   264 	{
       
   265 		addCcBcc();
       
   266 	}
       
   267 	else if(editorFields & MsgBaseView::ADD_SUBJECT)
       
   268   {
       
   269 		addSubject();
       
   270 	}    
       
   271 }
       
   272 
       
   273 void MsgUnifiedEditorView::populateDraftsContent(
       
   274     const ConvergedMessage& messageDetails)
   408     const ConvergedMessage& messageDetails)
   275 {
   409 {
   276     // skip first-time MMS type switch note for draft
   410     // skip first-time MMS type switch note for draft
   277     mNotifier->setSkipNote();
   411     mMsgMonitor->setSkipNote(true);
   278     mToField->setAddresses(messageDetails.toAddressList());
   412     mToField->setAddresses(messageDetails.toAddressList());
   279     if(messageDetails.ccAddressList().count() > 0 )
   413     if(messageDetails.ccAddressList().count() > 0 )
   280     {   
   414     {
   281         if(!mCcField)
   415         if(!mCcField)
   282         {    
   416         {
   283         addCcBcc();
   417         addCcBcc();
   284         }
   418         }
   285         mCcField->setAddresses(messageDetails.ccAddressList());
   419         mCcField->setAddresses(messageDetails.ccAddressList());
   286     }   
   420     }
   287     if(messageDetails.bccAddressList().count() > 0 )
   421     if(messageDetails.bccAddressList().count() > 0 )
   288     {   
   422     {
   289         if(!mBccField)
   423         if(!mBccField)
   290         {    
   424         {
   291         addCcBcc();
   425         addCcBcc();
   292         }
   426         }
   293         mBccField->setAddresses(messageDetails.bccAddressList());
   427         mBccField->setAddresses(messageDetails.bccAddressList());
   294     }    
   428     }
   295     if(messageDetails.subject().size() > 0)
   429     if(messageDetails.subject().size() > 0)
   296     {
   430     {
   297        if(!mSubjectField)
   431        if(!mSubjectField)
   298        {
   432        {
   299            addSubject();
   433            addSubject();
   300        }
   434        }
   301        mSubjectField->setText(messageDetails.subject());
   435        mSubjectField->setText(messageDetails.subject());
   302     }
   436     }
   303     
   437 
   304     if(messageDetails.priority()==ConvergedMessage::High || 
   438     if(messageDetails.priority()==ConvergedMessage::High ||
   305             messageDetails.priority() == ConvergedMessage::Low)
   439             messageDetails.priority() == ConvergedMessage::Low)
   306     {
   440     {
   307         if(!mSubjectField)
   441         if(!mSubjectField)
   308         {
   442         {
   309             addSubject();
   443             addSubject();
   310         }
   444         }
   311         mSubjectField->setPriority(messageDetails.priority());
   445         mSubjectField->setPriority(messageDetails.priority());
   312     }
   446     }
   313     
   447 
   314     QString bodyTxt = messageDetails.bodyText();
   448     QString bodyTxt = messageDetails.bodyText();
   315     mBody->setText(bodyTxt);
   449     mBody->setText(bodyTxt);
   316 
   450 
   317     ConvergedMessageAttachmentList attachmentList = 
   451     ConvergedMessageAttachmentList attachmentList =
   318         messageDetails.attachments();
   452         messageDetails.attachments();
   319     int attachmentCount = attachmentList.count();
   453     int attachmentCount = attachmentList.count();
   320     
   454 
   321     UniEditorGenUtils* genUtils = new UniEditorGenUtils;
   455     UniEditorGenUtils* genUtils = new UniEditorGenUtils;
   322                        
   456 
       
   457     QStringList pendingAttList;
   323     for( int i=0; i < attachmentCount; i++ )
   458     for( int i=0; i < attachmentCount; i++ )
   324     {
   459     {
   325         QString filePath = messageDetails.attachments().at(i)->filePath();
   460         QString filePath = messageDetails.attachments().at(i)->filePath();
   326 
   461 
   327         if(attachmentList.at(i)->attachmentType() == 
   462         if(attachmentList.at(i)->attachmentType() ==
   328             ConvergedMessageAttachment::EInline)
   463             ConvergedMessageAttachment::EInline)
   329         {
   464         {
   330             int imageSize=0;
   465             int imageSize=0;
   331             QString mimeType;
   466             QString mimeType;
   332             TMsgMediaType mediaType = EMsgMediaUnknown;    
   467             TMsgMediaType mediaType = EMsgMediaUnknown;
   333             TRAP_IGNORE(genUtils->getFileInfoL(filePath,imageSize,
   468             TRAP_IGNORE(genUtils->getFileInfoL(filePath,imageSize,
   334                 mimeType,mediaType));
   469                 mimeType,mediaType));
   335 
   470 
   336             switch(mediaType)
   471             switch(mediaType)
   337             {
   472             {
   338                 case EMsgMediaImage:
   473                 case EMsgMediaImage:
   339                 {
   474                 {
   340                     mBody->setImage(filePath);
   475                     mBody->setImage(filePath);
       
   476                     addSubject();
   341                     break;
   477                     break;
   342                 }
   478                 }
   343                 case EMsgMediaVideo:
   479                 case EMsgMediaVideo:
   344                 {
   480                 {
   345                     mBody->setVideo(filePath);
   481                     mBody->setVideo(filePath);
       
   482                     addSubject();
   346                     break;
   483                     break;
   347                 }
   484                 }
   348                 case EMsgMediaAudio:
   485                 case EMsgMediaAudio:
   349                 {
   486                 {
   350                     mBody->setAudio(filePath);
   487                     mBody->setAudio(filePath);
       
   488                     addSubject();
   351                     break;
   489                     break;
   352                 }
   490                 }
   353                 case EMsgMediaUnknown:
       
   354                 case EMsgMediaText:
       
   355                 default:
   491                 default:
   356                 {
   492                 {
   357                     addAttachment(filePath);
   493                     pendingAttList << filePath;
   358                     break;
   494                     break;
   359                 }
   495                 }
   360             }
   496             }
   361         }
   497         }
   362         else
   498         else
   363         {
   499         {
   364             addAttachment(filePath);
   500             pendingAttList << filePath;
   365         }
   501         }
   366     }    
   502     }
       
   503     // add pending attachments to editor
       
   504     addAttachments(pendingAttList);
       
   505 
   367     delete genUtils;
   506     delete genUtils;
       
   507     // ensure that any msg-type change after this are shown
       
   508     mMsgMonitor->setSkipNote(false);
   368 }
   509 }
   369 
   510 
   370 void MsgUnifiedEditorView::addToolBar()
   511 void MsgUnifiedEditorView::addToolBar()
   371 {
   512 {
   372     //Create Tool Bar
   513     //Create Tool Bar
   373     HbToolBar *toolBar = new HbToolBar();
   514     HbToolBar *toolBar = new HbToolBar();
   374     toolBar->setOrientation(Qt::Horizontal);
   515     toolBar->setOrientation(Qt::Horizontal);
       
   516     
       
   517     //tool bar extension for attach action.
       
   518     HbToolBarExtension* attachExtension = new HbToolBarExtension();
       
   519     HbAction *attachAction = toolBar->addExtension(attachExtension);    
       
   520     attachAction->setIcon(HbIcon(ATTACH_ICON));
       
   521     
       
   522     HbListWidget* extnList = new HbListWidget();
       
   523     extnList->addItem(LOC_PHOTO);
       
   524     extnList->addItem(LOC_SOUND);
       
   525     extnList->addItem(LOC_BUSINESS_CARD);
       
   526 
       
   527     HbListViewItem *prototype = extnList->listItemPrototype();
       
   528     HbFrameBackground frame(POPUP_LIST_FRAME, HbFrameDrawer::NinePieces);
       
   529     prototype->setDefaultFrame(frame);
       
   530 
       
   531     connect(extnList, SIGNAL(activated(HbListWidgetItem*)), this,
       
   532             SLOT(handleViewExtnActivated(HbListWidgetItem*)));
       
   533     connect(extnList, SIGNAL(activated(HbListWidgetItem*)), attachExtension, SLOT(close()));
       
   534 
       
   535     attachExtension->setContentWidget(extnList);
   375 
   536 
   376     //Add Action to the toolbar and show toolbar
   537     //Add Action to the toolbar and show toolbar
   377     HbAction* attachToolButton = toolBar->addAction(HbIcon(ATTACH_ICON), QString());
   538     toolBar->addAction(HbIcon(SEND_ICON),QString(),this,SLOT(send()));
   378     HbAction* sendToolButton = toolBar->addAction(HbIcon(SEND_ICON), QString());
   539 
   379 
       
   380     connect(attachToolButton, SIGNAL(triggered()), this, SLOT(showAttachmentPopup()));
       
   381     connect(sendToolButton, SIGNAL(triggered()), this, SLOT(send()));
       
   382 
   540 
   383     setToolBar(toolBar);
   541     setToolBar(toolBar);
   384 }
   542 }
   385 
   543 
   386 void MsgUnifiedEditorView::addSubject()
   544 void MsgUnifiedEditorView::addSubject()
   403     }
   561     }
   404     index = mMainLayout->count() - offset;
   562     index = mMainLayout->count() - offset;
   405 
   563 
   406     mSubjectField = new MsgUnifiedEditorSubject(mPluginPath, mContentWidget);
   564     mSubjectField = new MsgUnifiedEditorSubject(mPluginPath, mContentWidget);
   407     mMainLayout->insertItem(index,mSubjectField);
   565     mMainLayout->insertItem(index,mSubjectField);
   408     connect(mSubjectField, SIGNAL(mmContentAdded(bool)),
   566     connect(mSubjectField, SIGNAL(contentChanged()),
   409                      mNotifier, SLOT(onMMContentAdded(bool)));
   567             mMsgMonitor, SLOT(checkMsgTypeChange()));    
   410     connect(mSubjectField, SIGNAL(sizeChanged(int)),
       
   411                      mMsgMonitor, SLOT(onSizeChanged(int)));
       
   412 }
   568 }
   413 
   569 
   414 void MsgUnifiedEditorView::addCcBcc()
   570 void MsgUnifiedEditorView::addCcBcc()
   415 {
   571 {
   416     if(mCcField && mBccField)
   572     if(mCcField && mBccField)
   426 
   582 
   427     mCcField    = new MsgUnifiedEditorAddress( LOC_CC, mPluginPath, mContentWidget );
   583     mCcField    = new MsgUnifiedEditorAddress( LOC_CC, mPluginPath, mContentWidget );
   428     mBccField   = new MsgUnifiedEditorAddress( LOC_BCC, mPluginPath, mContentWidget );
   584     mBccField   = new MsgUnifiedEditorAddress( LOC_BCC, mPluginPath, mContentWidget );
   429 
   585 
   430     connect(mCcField, SIGNAL(sendMessage()), this, SLOT(send()));
   586     connect(mCcField, SIGNAL(sendMessage()), this, SLOT(send()));
   431     connect(mCcField, SIGNAL(mmContentAdded(bool)), mNotifier, SLOT(onMMContentAdded(bool)));
   587     connect(mCcField, SIGNAL(contentChanged()), mMsgMonitor, SLOT(checkMsgTypeChange()));
   432     connect(mBccField, SIGNAL(sendMessage()), this, SLOT(send()));
   588     connect(mBccField, SIGNAL(sendMessage()), this, SLOT(send()));
   433     connect(mBccField, SIGNAL(mmContentAdded(bool)), mNotifier, SLOT(onMMContentAdded(bool)));
   589     connect(mBccField, SIGNAL(contentChanged()), mMsgMonitor, SLOT(checkMsgTypeChange()));
   434 
   590 
   435     HbWidget* groupWidget = new HbWidget(mContentWidget);
   591     HbWidget* groupWidget = new HbWidget(mContentWidget);
   436     groupWidget->setContentsMargins(0,0,0,0);
   592     groupWidget->setContentsMargins(0,0,0,0);
       
   593     
   437     QGraphicsLinearLayout* ccBccLayout = new QGraphicsLinearLayout(Qt::Vertical, groupWidget);
   594     QGraphicsLinearLayout* ccBccLayout = new QGraphicsLinearLayout(Qt::Vertical, groupWidget);
       
   595     ccBccLayout->setContentsMargins(0,0,0,0);
       
   596 
       
   597     qreal vItemSpacing = 0.0;    
       
   598     style()->parameter("hb-param-margin-gene-middle-vertical",vItemSpacing);
       
   599     ccBccLayout->setSpacing(vItemSpacing);
   438     ccBccLayout->addItem(mCcField);
   600     ccBccLayout->addItem(mCcField);
   439     ccBccLayout->addItem(mBccField);
   601     ccBccLayout->addItem(mBccField);
   440 
   602 
   441     HbGroupBox* groupBox = new HbGroupBox(mContentWidget);
   603     HbGroupBox* groupBox = new HbGroupBox(0);    
   442     groupBox->setCollapsable(true);
   604     groupBox->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Preferred);
       
   605     
   443     groupBox->setContentWidget(groupWidget);
   606     groupBox->setContentWidget(groupWidget);
   444     groupBox->setHeading(tr("Other recipients"));    
   607     groupBox->setHeading(LOC_OTHER_RECIPIENTS(-1));
       
   608     mMainLayout->insertItem(1,groupBox);
   445     connect(groupBox, SIGNAL(toggled(bool)), this, SLOT(updateOtherRecipientCount(bool)));
   609     connect(groupBox, SIGNAL(toggled(bool)), this, SLOT(updateOtherRecipientCount(bool)));
   446 
   610     
   447     mMainLayout->insertItem(1,groupBox);
       
   448     // add subject field too
   611     // add subject field too
   449     addSubject();
   612     addSubject();
       
   613     
       
   614     this->updateGeometry();
   450 }
   615 }
   451 
   616 
   452 void MsgUnifiedEditorView::updateOtherRecipientCount(bool state)
   617 void MsgUnifiedEditorView::updateOtherRecipientCount(bool state)
   453 {
   618 {
   454     HbGroupBox* groupBox = qobject_cast<HbGroupBox*>(sender());
   619     HbGroupBox* groupBox = qobject_cast<HbGroupBox*>(sender());
   455     if(groupBox)
   620     if(groupBox)
   456     {
   621     {
   457         if(!state)
   622         if(!state)
   458         {
   623         {
   459             groupBox->setHeading(tr("Other recipients"));
   624            groupBox->setHeading(LOC_OTHER_RECIPIENTS(-1));
   460         }
   625         }
   461         else
   626         else
   462         {
   627         {
   463             int addrCount = mCcField->addressCount();
   628             int addrCount = mCcField->addressCount();
   464             addrCount += mBccField->addressCount();
   629             addrCount += mBccField->addressCount();
   465             QString str;
   630             groupBox->setHeading(LOC_OTHER_RECIPIENTS(addrCount));
   466             str = QString(tr("%1 Other recipients")).arg(addrCount);
       
   467             groupBox->setHeading(str);
       
   468         }
   631         }
   469     }
   632     }
   470 }
   633 }
   471 
   634 
   472 void MsgUnifiedEditorView::changePriority()
   635 void MsgUnifiedEditorView::changePriority()
   480         priority = ConvergedMessage::Priority(data);
   643         priority = ConvergedMessage::Priority(data);
   481         }
   644         }
   482 
   645 
   483     addSubject();
   646     addSubject();
   484     mSubjectField->setPriority(priority);
   647     mSubjectField->setPriority(priority);
   485     if(priority != ConvergedMessage::Normal)
       
   486     {
       
   487 		mPrioritySubMenu->setTitle("Change Priority");
       
   488 	}
       
   489    else
       
   490    {
       
   491        mPrioritySubMenu->setTitle("Add Priority");
       
   492    }
       
   493 }
   648 }
   494 
   649 
   495 void MsgUnifiedEditorView::sendingOptions()
   650 void MsgUnifiedEditorView::sendingOptions()
   496 {
   651 {
   497 }
   652 }
   498 
   653 
   499 void MsgUnifiedEditorView::deleteMessage()
   654 void MsgUnifiedEditorView::deleteMessage()
   500 {
   655 {
   501 }
   656     bool ok = HbMessageBox::question(LOC_NOTE_DELETE_MESSAGE,
   502 
   657                                             LOC_BUTTON_DELETE, LOC_BUTTON_CANCEL);
   503 void MsgUnifiedEditorView::launchHelp()
   658     
   504 {
   659     if(ok)
   505 }
   660         {
   506 
   661         mCanSaveToDrafts = false;
   507 void MsgUnifiedEditorView::showAttachmentPopup()
   662     
   508 {
   663         //delete if draft entry opened
   509     HbMenu* attachMenu = new HbMenu();
   664         if( mOpenedMessageId.getId() != -1)
   510     attachMenu->deleteLater();
   665             {    
   511     attachMenu->setFrameType(HbPopup::Strong);
   666             if(!mPluginLoader)
   512 
   667                 {
   513     HbAction* attachPhoto = attachMenu->addAction(LOC_PHOTO,mUtilsManager,SLOT(fetchImages()));
   668                 mPluginLoader = new UniEditorPluginLoader(this);
   514     HbAction* attachVideo = attachMenu->addAction(LOC_VIDEO,mUtilsManager,SLOT(fetchVideo()));
   669                 }
   515     HbAction* attachAudio = attachMenu->addAction(LOC_SOUND,mUtilsManager,SLOT(fetchAudio()));
   670         
   516     HbAction* attachOther = attachMenu->addAction(LOC_MORE,mUtilsManager,SLOT(fetchOther()));
   671             UniEditorPluginInterface* pluginInterface =
   517     attachMenu->exec(QPoint());
   672                 mPluginLoader->getUniEditorPlugin(MsgMonitor::messageType());
   518     delete attachMenu;
   673         
       
   674             pluginInterface->deleteDraftsEntry(mOpenedMessageId.getId());
       
   675             }
       
   676     
       
   677         //trigger back action.
       
   678         HbAction* backAction = this->navigationAction();
       
   679         if(backAction)
       
   680             {
       
   681             backAction->trigger();
       
   682             }
       
   683         }
   519 }
   684 }
   520 
   685 
   521 void MsgUnifiedEditorView::removeAttachmentContainer()
   686 void MsgUnifiedEditorView::removeAttachmentContainer()
   522 {
   687 {
   523     if(mAttachmentContainer)
   688     if(mAttachmentContainer)
   527         delete mAttachmentContainer;
   692         delete mAttachmentContainer;
   528         mAttachmentContainer = NULL;
   693         mAttachmentContainer = NULL;
   529     }
   694     }
   530 }
   695 }
   531 
   696 
   532 void MsgUnifiedEditorView::addAttachment(const QString& filepath)
   697 void MsgUnifiedEditorView::addAttachments(QStringList files)
       
   698 {    
       
   699     int fcount = files.count();
       
   700     int i=0;
       
   701     for(i=0; i<fcount; i++)
       
   702     {
       
   703         if(MsgAttachmentContainer::EAddSizeExceed 
       
   704                 == addAttachment(files.at(i)))
       
   705         {
       
   706             // size already exceeds max mms size-limit
       
   707             break;
       
   708         }
       
   709     }
       
   710     // check if some files failed to add
       
   711     // happens only when size exceeded during addition
       
   712     if(i<fcount)
       
   713     {
       
   714         // TODO: show a note for size exceed
       
   715     }
       
   716 }
       
   717 
       
   718 int MsgUnifiedEditorView::addAttachment(const QString& filepath)
   533 {
   719 {
   534     if(!mAttachmentContainer)
   720     if(!mAttachmentContainer)
   535     {
   721     {
   536         mAttachmentContainer = new MsgAttachmentContainer(mPluginPath, mContentWidget);
   722         mAttachmentContainer = new MsgAttachmentContainer(mPluginPath, mContentWidget);
   537         connect(mAttachmentContainer, SIGNAL(emptyAttachmentContainer()),
   723         connect(mAttachmentContainer, SIGNAL(emptyAttachmentContainer()),
   538                 this, SLOT(removeAttachmentContainer()));
   724                 this, SLOT(removeAttachmentContainer()));
   539         connect(mAttachmentContainer, SIGNAL(mmContentAdded(bool)),
   725         connect(mAttachmentContainer, SIGNAL(contentChanged()),
   540                 mNotifier, SLOT(onMMContentAdded(bool)));
   726                 mMsgMonitor, SLOT(checkMsgTypeChange()));
   541         connect(mAttachmentContainer, SIGNAL(sizeChanged(int)),
       
   542                          mMsgMonitor, SLOT(onSizeChanged(int)));
       
   543         int index = mMainLayout->count() - 1;
   727         int index = mMainLayout->count() - 1;
   544         mMainLayout->insertItem(index,mAttachmentContainer);
   728         mMainLayout->insertItem(index,mAttachmentContainer);
   545     }
   729     }
   546     mAttachmentContainer->addAttachment(filepath);
   730 
   547 }
   731     int ret = mAttachmentContainer->addAttachment(filepath);
   548 
   732     if(ret != MsgAttachmentContainer::EAddSuccess)
   549 void MsgUnifiedEditorView::imagesFetched(const QVariant& result )
   733     {
   550     {
   734         // delete container, if it is empty
   551     if(result.canConvert<QStringList>())
   735         if(mAttachmentContainer->count() == 0)
   552         {
   736         {
   553         QStringList fileList = result.value<QStringList>();
   737             removeAttachmentContainer();
   554         if ( fileList.size()>0 )
   738         }
   555             {
   739     }
   556             QString filepath(fileList.at(0));
   740     else if(mAttachmentContainer->hasMMContent())
   557             mBody->setImage(filepath);
   741     {
   558             addSubject();
   742         // when msg is converted to MMS, subject needs to be auto-inserted
   559             }
   743         addSubject();
   560         }
   744     }
   561     }
   745     return ret;
   562 
   746 }
   563 void MsgUnifiedEditorView::audiosFetched(const QVariant& result )
       
   564     {
       
   565     if(result.canConvert<QStringList>())
       
   566         {
       
   567         QStringList fileList = result.value<QStringList>();
       
   568         if ( fileList.size()>0 && !fileList.at(0).isEmpty())
       
   569             {
       
   570             QString filepath(QDir::toNativeSeparators(fileList.at(0)));
       
   571             QDEBUG_WRITE_FORMAT("Received audio file path = ", fileList.at(0));
       
   572             mBody->setAudio(filepath);
       
   573             addSubject();
       
   574             }
       
   575         }
       
   576     }
       
   577 
   747 
   578 QString MsgUnifiedEditorView::pluginPath()
   748 QString MsgUnifiedEditorView::pluginPath()
   579 {
   749 {
   580     QString pluginPath;
   750     QString pluginPath;
   581     #ifdef Q_OS_WIN
   751     #ifdef Q_OS_WIN
   588     return pluginPath;
   758     return pluginPath;
   589 }
   759 }
   590 
   760 
   591 void MsgUnifiedEditorView::send()
   761 void MsgUnifiedEditorView::send()
   592 {
   762 {
   593     mUtilsManager->activateInputBlocker(this);
   763     activateInputBlocker();
   594 
   764 
   595     // converged msg for sending
   765     // converged msg for sending
   596     ConvergedMessage msg;
   766     ConvergedMessage msg;
   597     ConvergedMessage::MessageType messageType = mNotifier->messageType();
   767     ConvergedMessage::MessageType messageType = MsgMonitor::messageType();
   598     msg.setMessageType(messageType);
   768     msg.setMessageType(messageType);
   599 
   769 
   600     ConvergedMessageAddressList addresses = mToField->addresses();
   770     ConvergedMessageAddressList addresses = mToField->addresses();
   601     if(messageType == ConvergedMessage::Sms &&
   771     if(messageType == ConvergedMessage::Sms &&
   602        addresses.isEmpty())
   772        addresses.isEmpty())
   603     {
   773     {
   604         // no recipient specified for sms, do not send msg
   774         // no recipient specified for sms, do not send msg
   605         mUtilsManager->deactivateInputBlocker();
   775         deactivateInputBlocker();
   606         return;
   776         return;
   607     }
   777     }
   608 
   778 
   609     ConvergedMessageAddressList ccAddresses;
   779     ConvergedMessageAddressList ccAddresses;
   610     ConvergedMessageAddressList bccAddresses;
   780     ConvergedMessageAddressList bccAddresses;
   620             addresses.isEmpty() &&
   790             addresses.isEmpty() &&
   621             ccAddresses.isEmpty() &&
   791             ccAddresses.isEmpty() &&
   622             bccAddresses.isEmpty())
   792             bccAddresses.isEmpty())
   623     {
   793     {
   624         // no recipient specified for mms, do not send msg
   794         // no recipient specified for mms, do not send msg
   625         mUtilsManager->deactivateInputBlocker();
   795         deactivateInputBlocker();
   626         return;
   796         return;
   627     }
   797     }
   628 
   798 
   629     packMessage(msg);
   799     packMessage(msg);
   630 
   800     
   631     int sendResult = mUtilsManager->send(msg);
   801     // send message
       
   802     MsgSendUtil *sendUtil = new MsgSendUtil(this);
       
   803     int sendResult = sendUtil->send(msg);
       
   804     delete sendUtil;
   632     
   805     
   633     // all checks and validations happen before send
   806     // all checks and validations happen before send
   634     if( sendResult == KErrNone)
   807     if( sendResult == KErrNone)
   635     {
   808     {
   636         //After sending the new content to drafts chk if the msg 
   809         //After sending the new content to drafts chk if the msg
   637         //was originally opened from drafts and delete the opened entry
   810         //was originally opened from drafts and delete the opened entry
   638         if( mOpenedMessageId.getId() != -1)
   811         if( mOpenedMessageId.getId() != -1)
   639         {
   812         {
   640 
   813 
   641             if(!mPluginLoader)
   814             if(!mPluginLoader)
   642             {
   815             {
   643                 mPluginLoader = new UniEditorPluginLoader(this);
   816                 mPluginLoader = new UniEditorPluginLoader(this);
   644                 mPluginLoader->loadPlugins();
       
   645             }
   817             }
   646 
   818 
   647             UniEditorPluginInterface* pluginInterface =
   819             UniEditorPluginInterface* pluginInterface =
   648                 mPluginLoader->getUniEditorPlugin(messageType);
   820                 mPluginLoader->getUniEditorPlugin(messageType);
   649             //TODO delete the entry
   821             //TODO delete the entry
   669                 receipient = addrList.at(0)->address();
   841                 receipient = addrList.at(0)->address();
   670             }
   842             }
   671 
   843 
   672             addrList = bccAddresses;
   844             addrList = bccAddresses;
   673             int bccCount = addrList.count();
   845             int bccCount = addrList.count();
   674             recepientCount += bccCount;        
   846             recepientCount += bccCount;
   675             if(bccCount)
   847             if(bccCount)
   676             {
   848             {
   677                 receipient = addrList.at(0)->address();
   849                 receipient = addrList.at(0)->address();
   678             }
   850             }
   679         }
   851         }
   683 
   855 
   684     if(recepientCount == 1 )
   856     if(recepientCount == 1 )
   685         {
   857         {
   686         params << MsgBaseView::CV;  // target view
   858         params << MsgBaseView::CV;  // target view
   687         params << MsgBaseView::UNIEDITOR; // source view
   859         params << MsgBaseView::UNIEDITOR; // source view
   688         
   860 
   689         params << receipient;
   861         params << receipient;
   690         }
   862         }
   691     else 
   863     else
   692         {
   864         {
   693         params << MsgBaseView::CLV;// target view
   865         params << MsgBaseView::CLV;// target view
   694         params << MsgBaseView::UNIEDITOR; // source view
   866         params << MsgBaseView::UNIEDITOR; // source view
   695         }
   867         }
   696         mUtilsManager->deactivateInputBlocker();
   868         deactivateInputBlocker();
   697     emit switchView(params);
   869         emit switchView(params);
   698     }
   870     }
   699     else
   871     else
   700     {
   872     {
   701         mUtilsManager->deactivateInputBlocker();
   873         deactivateInputBlocker();
   702         if(sendResult == KErrNotFound)
   874         if(sendResult == KErrNotFound)
   703         {
   875         {
   704             QVariantList params;
   876         	  bool result = HbMessageBox::question("Settings not defined\nDefine now ?",
   705             params << MsgBaseView::MSGSETTINGS;// target view
   877                                          LOC_DIALOG_OK,
   706             params << MsgBaseView::UNIEDITOR; // source view
   878                                          LOC_BUTTON_CANCEL);
   707             emit switchView(params);
   879             if (result)
       
   880             {
       
   881               QVariantList params;
       
   882               params << MsgBaseView::MSGSETTINGS;// target view
       
   883               params << MsgBaseView::UNIEDITOR; // source view
       
   884               emit switchView(params);
       
   885             }
   708         }
   886         }
   709     }
   887     }
   710 }
   888 }
   711 
   889 
   712 void MsgUnifiedEditorView::packMessage(ConvergedMessage &msg)
   890 void MsgUnifiedEditorView::packMessage(ConvergedMessage &msg)
   713 {
   891 {
   714     ConvergedMessage::MessageType messageType = mNotifier->messageType();
   892     ConvergedMessage::MessageType messageType = MsgMonitor::messageType();
   715     msg.setMessageType(messageType);
   893     msg.setMessageType(messageType);
   716 
   894 
   717     ConvergedMessageAddressList addresses = mToField->addresses();
   895     ConvergedMessageAddressList addresses = mToField->addresses();
   718     ConvergedMessageAddressList ccAddresses;
   896     ConvergedMessageAddressList ccAddresses;
   719     ConvergedMessageAddressList bccAddresses;
   897     ConvergedMessageAddressList bccAddresses;
   734         if(mBccField)
   912         if(mBccField)
   735         {
   913         {
   736             bccAddresses = mBccField->addresses();
   914             bccAddresses = mBccField->addresses();
   737         }
   915         }
   738 
   916 
   739         int matchDigitsCount = MatchPhNumberUtil::matchDigits();
   917         int matchDigitsCount = MsgUnifiedEditorAddress::contactMatchDigits();
   740         //comapre cc and to field,remove duplicate from cc
   918         //comapre cc and to field,remove duplicate from cc
   741         foreach(ConvergedMessageAddress *ccAddress,ccAddresses)
   919         foreach(ConvergedMessageAddress *ccAddress,ccAddresses)
   742         {
   920         {
   743           foreach(ConvergedMessageAddress *toAddress,addresses)
   921           foreach(ConvergedMessageAddress *toAddress,addresses)
   744           {
   922           {
   748              }
   926              }
   749           }
   927           }
   750         }
   928         }
   751         //comapre bcc and cc field,remove duplicate from bcc
   929         //comapre bcc and cc field,remove duplicate from bcc
   752         foreach(ConvergedMessageAddress *bccAddress,bccAddresses)
   930         foreach(ConvergedMessageAddress *bccAddress,bccAddresses)
   753         { 
   931         {
   754           foreach(ConvergedMessageAddress *ccAddress,ccAddresses)
   932           foreach(ConvergedMessageAddress *ccAddress,ccAddresses)
   755           {
   933           {
   756              if(0 == bccAddress->address().right(matchDigitsCount).compare(ccAddress->address().right(matchDigitsCount)))
   934              if(0 == bccAddress->address().right(matchDigitsCount).compare(ccAddress->address().right(matchDigitsCount)))
   757              {
   935              {
   758                 bccAddresses.removeOne(bccAddress);
   936                 bccAddresses.removeOne(bccAddress);
   759              }
   937              }
   760           }
   938           }
   761         }
   939         }
   762         //comapre bcc and to field,remove duplicate from bcc
   940         //comapre bcc and to field,remove duplicate from bcc
   763         foreach(ConvergedMessageAddress *bccAddress,bccAddresses)
   941         foreach(ConvergedMessageAddress *bccAddress,bccAddresses)
   764         { 
   942         {
   765           foreach(ConvergedMessageAddress *toAddress,addresses)
   943           foreach(ConvergedMessageAddress *toAddress,addresses)
   766           {
   944           {
   767              if(0 == bccAddress->address().right(matchDigitsCount).compare(toAddress->address().right(matchDigitsCount)))
   945              if(0 == bccAddress->address().right(matchDigitsCount).compare(toAddress->address().right(matchDigitsCount)))
   768              {
   946              {
   769                 bccAddresses.removeOne(bccAddress);
   947                 bccAddresses.removeOne(bccAddress);
   803         if(mediaList.count() > 0)
   981         if(mediaList.count() > 0)
   804         {
   982         {
   805             msg.addAttachments(mediaList);
   983             msg.addAttachments(mediaList);
   806         }
   984         }
   807     }
   985     }
   808     
   986 
   809     // sms/mms attachment list
   987     // sms/mms attachment list
   810     ConvergedMessageAttachmentList attachmentList;
   988     ConvergedMessageAttachmentList attachmentList;
   811         if(mAttachmentContainer)
   989         if(mAttachmentContainer)
   812         {
   990         {
   813             MsgUnifiedEditorAttachmentList editorAttachmentList = 
   991             MsgUnifiedEditorAttachmentList editorAttachmentList =
   814                 mAttachmentContainer->attachmentList(); 
   992                 mAttachmentContainer->attachmentList();
   815                 for (int i = 0; i < editorAttachmentList.count(); ++i)
   993                 for (int i = 0; i < editorAttachmentList.count(); ++i)
   816                 {
   994                 {
   817                     ConvergedMessageAttachment* attachment =
   995                     ConvergedMessageAttachment* attachment =
   818                         new ConvergedMessageAttachment(
   996                         new ConvergedMessageAttachment(
   819                             editorAttachmentList.at(i)->path(),
   997                             editorAttachmentList.at(i)->path(),
   825         {
  1003         {
   826             msg.addAttachments(attachmentList);
  1004             msg.addAttachments(attachmentList);
   827         }
  1005         }
   828 }
  1006 }
   829 
  1007 
   830 bool MsgUnifiedEditorView::saveContentToDrafts()
  1008 void MsgUnifiedEditorView::saveContentToDrafts()
   831 {
  1009 {
   832     mUtilsManager->activateInputBlocker(this);
  1010     if(!mCanSaveToDrafts)
   833     ConvergedMessage::MessageType messageType = mNotifier->messageType();
  1011         {
       
  1012         return;
       
  1013         }
       
  1014     activateInputBlocker();
       
  1015     ConvergedMessage::MessageType messageType = MsgMonitor::messageType();
   834 
  1016 
   835     ConvergedMessageAddressList addresses = mToField->addresses();
  1017     ConvergedMessageAddressList addresses = mToField->addresses();
   836 
  1018 
   837     UniEditorPluginInterface* pluginInterface = NULL;
  1019     UniEditorPluginInterface* pluginInterface = NULL;
   838     
  1020 
   839     if( mOpenedMessageId.getId() != -1)
  1021     if( mOpenedMessageId.getId() != -1)
   840     {    
  1022     {
   841         if(!mPluginLoader)
  1023         if(!mPluginLoader)
   842         {
  1024         {
   843             mPluginLoader = new UniEditorPluginLoader(this);
  1025             mPluginLoader = new UniEditorPluginLoader(this);
   844             mPluginLoader->loadPlugins();
       
   845         }
  1026         }
   846 
  1027 
   847         pluginInterface =
  1028         pluginInterface =
   848             mPluginLoader->getUniEditorPlugin(messageType);
  1029             mPluginLoader->getUniEditorPlugin(messageType);
   849     }
  1030     }
   850 
  1031 
   851     if(messageType == ConvergedMessage::Sms &&
  1032     if(messageType == ConvergedMessage::Sms &&
   852             addresses.isEmpty() && MsgMonitor::bodySize() <= 0)
  1033             addresses.isEmpty() &&
       
  1034             MsgMonitor::bodySize() <= 0 &&
       
  1035             MsgMonitor::containerSize() <= 0)
   853     {
  1036     {
   854         if(mOpenedMessageId.getId() != -1)
  1037         if(mOpenedMessageId.getId() != -1)
   855         {
  1038         {
   856         pluginInterface->deleteDraftsEntry(mOpenedMessageId.getId());
  1039         pluginInterface->deleteDraftsEntry(mOpenedMessageId.getId());
   857         }
  1040         }
   858 
  1041 
   859         // no recipient specified for sms, do not send msg
  1042         // if empty msg, do not save
   860         mUtilsManager->deactivateInputBlocker();
  1043         deactivateInputBlocker();
   861         return false;
  1044         return;
   862     }
  1045     }
   863 
  1046 
   864     ConvergedMessageAddressList ccAddresses;
  1047     ConvergedMessageAddressList ccAddresses;
   865     ConvergedMessageAddressList bccAddresses;
  1048     ConvergedMessageAddressList bccAddresses;
   866     if(mCcField)
  1049     if(mCcField)
   887     {
  1070     {
   888         if(mOpenedMessageId.getId() != -1)
  1071         if(mOpenedMessageId.getId() != -1)
   889         {
  1072         {
   890             pluginInterface->deleteDraftsEntry(mOpenedMessageId.getId());
  1073             pluginInterface->deleteDraftsEntry(mOpenedMessageId.getId());
   891         }
  1074         }
   892         // no recipient specified for mms, do not send msg
  1075         // if empty msg, do not send
   893         mUtilsManager->deactivateInputBlocker();
  1076         deactivateInputBlocker();
   894         return false;
  1077         return;
   895     }
  1078     }
   896     ConvergedMessage msg;
  1079     ConvergedMessage msg;
   897     packMessage(msg);
  1080     packMessage(msg);
   898     
  1081 
   899     int msgId = mUtilsManager->saveToDrafts(msg);
  1082     // save to drafts
   900 
  1083     MsgSendUtil *sendUtil = new MsgSendUtil(this);
   901     //After saving the new content to drafts chk if the msg 
  1084     int msgId = sendUtil->saveToDrafts(msg);
   902     //was originally opened from drafts and delete the opened entry
  1085     delete sendUtil;
   903     if(mOpenedMessageId.getId() != -1)
  1086 
       
  1087     // If saving new msg to draft succeeded and also if the originally
       
  1088     // opened msg was from drafts, then delete the original msg entry
       
  1089     if(msgId != -1 && mOpenedMessageId.getId() != -1)
   904     {
  1090     {
   905         pluginInterface->deleteDraftsEntry(mOpenedMessageId.getId());
  1091         pluginInterface->deleteDraftsEntry(mOpenedMessageId.getId());
   906         mOpenedMessageId.setId(INVALID_MSGID);
  1092         mOpenedMessageId.setId(INVALID_MSGID);
   907     }
  1093     }
   908     
  1094 
   909     mUtilsManager->deactivateInputBlocker();
  1095     deactivateInputBlocker();
   910 
  1096 
   911     return ((msgId > INVALID_MSGID)? true : false);
  1097     bool res = ((msgId > INVALID_MSGID)? true : false);
       
  1098     
       
  1099     if(res)
       
  1100         {
       
  1101         HbNotificationDialog::launchDialog(LOC_SAVED_TO_DRAFTS);
       
  1102         }
   912 }
  1103 }
   913 
  1104 
   914 void MsgUnifiedEditorView::resizeEvent( QGraphicsSceneResizeEvent * event )
  1105 void MsgUnifiedEditorView::resizeEvent( QGraphicsSceneResizeEvent * event )
   915 {
  1106 {
   916  Q_UNUSED(event)
  1107  Q_UNUSED(event)
   919 #endif
  1110 #endif
   920 
  1111 
   921  mContentWidget->resize(this->rect().width(),this->rect().height()+1);
  1112  mContentWidget->resize(this->rect().width(),this->rect().height()+1);
   922 }
  1113 }
   923 
  1114 
       
  1115 //---------------------------------------------------------------
       
  1116 // editorTempPath
       
  1117 // @return fullPath of unified editor's temporary dir
       
  1118 //---------------------------------------------------------------
       
  1119 QString editorTempPath()
       
  1120 {
       
  1121     QDir tempDir = QDir(QString());
       
  1122     QString tempPath(QDir::toNativeSeparators(tempDir.tempPath()));
       
  1123     tempPath.append(QDir::separator());
       
  1124     tempPath.append(UNIFIED_EDITOR_TEMP_FOLDER);
       
  1125     tempPath.append(QDir::separator());
       
  1126     return tempPath;
       
  1127 }
       
  1128 
       
  1129 //---------------------------------------------------------------
       
  1130 // MsgUnifiedEditorView::createVCards
       
  1131 // @see header file
       
  1132 //---------------------------------------------------------------
       
  1133 int MsgUnifiedEditorView::createVCards(
       
  1134         const QVariant& value, QStringList& filelist)
       
  1135 {
       
  1136     // make sure that temp-folder is created for storing vcards
       
  1137     QDir tempDir = QDir(QString());
       
  1138     if(!tempDir.mkpath(editorTempPath()))
       
  1139     {
       
  1140         return KErrGeneral;
       
  1141     }
       
  1142     tempDir.cd(editorTempPath());
       
  1143 
       
  1144 
       
  1145     // extract contact-list
       
  1146     QContactManager* contactManager = new QContactManager("symbian");
       
  1147     CntServicesContactList cntServicesContacts = qVariantValue<CntServicesContactList>(value);
       
  1148     int cntCount = cntServicesContacts.count();
       
  1149     QList<QtMobility::QContact> contactList;
       
  1150     for(int i = 0; i < cntCount; i++ )
       
  1151     {
       
  1152         contactList << contactManager->contact( cntServicesContacts.at(i).mContactId );
       
  1153     }
       
  1154     delete contactManager;
       
  1155 
       
  1156     // get list of all versit-documents
       
  1157     QVersitDocument::VersitType versitType(QVersitDocument::VCard21Type);
       
  1158     QVersitContactExporter* exporter = new QVersitContactExporter();
       
  1159     
       
  1160     bool ret_val = exporter->exportContacts(contactList, versitType);
       
  1161     QList<QtMobility::QVersitDocument> documentList = exporter->documents();    
       
  1162 
       
  1163     delete exporter;
       
  1164 
       
  1165     // loop though and create a vcard for each contact
       
  1166     QVersitWriter* writer = new QVersitWriter();
       
  1167     for(int i = 0; i < cntCount; i++ )
       
  1168     {
       
  1169         // buffer to hold vcard data fetched from contacts
       
  1170         QBuffer contactsbuf;
       
  1171         contactsbuf.open(QBuffer::ReadWrite);
       
  1172         writer->setDevice( &contactsbuf );
       
  1173 
       
  1174         //write document data to buffer
       
  1175         QList<QtMobility::QVersitDocument> currDoc;
       
  1176         currDoc << documentList.at(i);
       
  1177         writer->startWriting(currDoc);
       
  1178         if(writer->waitForFinished())
       
  1179         {
       
  1180             // generate file name
       
  1181             QString displayLabel = contactList.at(i).displayLabel();
       
  1182             QString filepath = generateFileName(displayLabel);
       
  1183             QFile file(filepath);
       
  1184             if(file.open(QIODevice::WriteOnly))
       
  1185             {
       
  1186                 // trap ignore so that, incase of multiselection, other vcards are still created
       
  1187                 QByteArray bufArr;
       
  1188                 TRAP_IGNORE(
       
  1189                 CBufBase* contactbufbase = CBufFlat::NewL(contactsbuf.size());
       
  1190                 CleanupStack::PushL(contactbufbase);
       
  1191                 contactbufbase->InsertL( contactbufbase->Size(),
       
  1192                         *XQConversions::qStringToS60Desc8( contactsbuf.data() ) );
       
  1193                 TPtr8 ptrbuf(contactbufbase->Ptr(0));
       
  1194                 bufArr = XQConversions::s60Desc8ToQByteArray(ptrbuf);
       
  1195                 CleanupStack::PopAndDestroy(contactbufbase);
       
  1196                 );
       
  1197                 file.write(bufArr);
       
  1198                 file.close();
       
  1199                 filelist << filepath;
       
  1200             }
       
  1201         }
       
  1202     }
       
  1203 
       
  1204     // cleanup & return
       
  1205     delete writer;
       
  1206     return KErrNone;
       
  1207 }
       
  1208 
       
  1209 
       
  1210 //---------------------------------------------------------------
       
  1211 // MsgUnifiedEditorView::generateFileName
       
  1212 // @param suggestedName suggested name of the file
       
  1213 // @return fullPath of the generated filename
       
  1214 // @algo For multiselected 'Unnamed' contacts, the filename should
       
  1215 // be synthesized as unnamed.vcf, unnamed1.vcf, unnamed2.vcf etc.
       
  1216 //---------------------------------------------------------------
       
  1217 QString MsgUnifiedEditorView::generateFileName(QString& suggestedName)
       
  1218 {
       
  1219     QDir editorTempDir = QDir(QString());
       
  1220     editorTempDir.cd(editorTempPath());
       
  1221 
       
  1222     for(int i=0; i<MAX_VCARDS; i++)
       
  1223     {
       
  1224         QString searchFileName = suggestedName;
       
  1225         if(i>0)
       
  1226         {
       
  1227             searchFileName.append(QString::number(i));
       
  1228         }
       
  1229         searchFileName.append(FILE_EXTN);
       
  1230 
       
  1231         // check if filename is already used by an attachment in container
       
  1232         bool alreadyExists = false;
       
  1233         if(mAttachmentContainer)
       
  1234         {
       
  1235             MsgUnifiedEditorAttachmentList attList =
       
  1236                     mAttachmentContainer->attachmentList();
       
  1237             int attCount = attList.count();
       
  1238             for(int j=0; j<attCount; j++)
       
  1239             {
       
  1240                 QFileInfo fileinfo(attList.at(j)->path());
       
  1241                 if(searchFileName == fileinfo.fileName())
       
  1242                 {
       
  1243                     alreadyExists = true;
       
  1244                     break;
       
  1245                 }
       
  1246             }
       
  1247         }
       
  1248 
       
  1249         if(!alreadyExists)
       
  1250         {
       
  1251             if(i>0)
       
  1252             {
       
  1253                 suggestedName.append(QString::number(i));
       
  1254             }
       
  1255             break;
       
  1256         }
       
  1257     }
       
  1258     QString filepath(editorTempPath());
       
  1259     filepath.append(suggestedName);
       
  1260     filepath.append(FILE_EXTN);
       
  1261     return filepath;
       
  1262 }
       
  1263 
       
  1264 void MsgUnifiedEditorView::handleViewExtnActivated(HbListWidgetItem* item)
       
  1265     {
       
  1266     QString itemText = item->text();
       
  1267     
       
  1268     if(itemText == LOC_PHOTO)
       
  1269         {
       
  1270         //launch photo picker.
       
  1271         fetchImages();  
       
  1272     }
       
  1273     else if(itemText == LOC_SOUND)
       
  1274         {
       
  1275         //launch audio picker
       
  1276         fetchAudio();
       
  1277     }
       
  1278     else if(itemText == LOC_BUSINESS_CARD)
       
  1279         {
       
  1280         //launch contact card picker.
       
  1281         fetchContacts();
       
  1282     }
       
  1283    
       
  1284 }
       
  1285 
       
  1286 //---------------------------------------------------------------
       
  1287 // MsgUnifiedEditorView::fetchContacts
       
  1288 // @see header file
       
  1289 //---------------------------------------------------------------
       
  1290 void MsgUnifiedEditorView::fetchContacts()
       
  1291 {
       
  1292     QList<QVariant> args;
       
  1293     QString serviceName("com.nokia.services.phonebookservices");
       
  1294     QString operation("fetch(QString,QString,QString)");
       
  1295     XQAiwRequest* request;
       
  1296     XQApplicationManager appManager;
       
  1297     request = appManager.create(serviceName, "Fetch", operation, true); //embedded
       
  1298     if ( request == NULL )
       
  1299     {
       
  1300         QCRITICAL_WRITE("AIW-ERROR: NULL request");
       
  1301         return;       
       
  1302     }
       
  1303 
       
  1304     // Result handlers
       
  1305     connect (request, SIGNAL(requestOk(const QVariant&)), 
       
  1306         this, SLOT(contactsFetched(const QVariant&)));
       
  1307     connect (request, SIGNAL(requestError(int,const QString&)), 
       
  1308         this, SLOT(serviceRequestError(int,const QString&)));
       
  1309 
       
  1310     args << QString(tr("Phonebook")); 
       
  1311     args << KCntActionAll;
       
  1312     args << KCntFilterDisplayAll;
       
  1313 
       
  1314     request->setArguments(args);
       
  1315     if(!request->send())
       
  1316     {
       
  1317         QDEBUG_WRITE_FORMAT("AIW-ERROR: Request Send failed:",request->lastError());
       
  1318     }
       
  1319     delete request;
       
  1320 }
       
  1321 
       
  1322 //---------------------------------------------------------------
       
  1323 // MsgUnifiedEditorView::fetchImages
       
  1324 // @see header file
       
  1325 //---------------------------------------------------------------
       
  1326 void MsgUnifiedEditorView::fetchImages()
       
  1327 {
       
  1328     QString interface("Image");
       
  1329     QString operation("fetch(QVariantMap,QVariant)");
       
  1330     XQAiwRequest* request = NULL;
       
  1331     XQApplicationManager appManager;
       
  1332     request = appManager.create(interface, operation, true);//embedded
       
  1333     if(!request)
       
  1334     {     
       
  1335         QCRITICAL_WRITE("AIW-ERROR: NULL request");
       
  1336         return;
       
  1337     }
       
  1338 
       
  1339     connect(request, SIGNAL(requestOk(const QVariant&)),
       
  1340         this, SLOT(imagesFetched(const QVariant&)));
       
  1341     connect(request, SIGNAL(requestError(int,const QString&)),
       
  1342         this, SLOT(serviceRequestError(int,const QString&)));
       
  1343    
       
  1344     // Make the request
       
  1345     if (!request->send())
       
  1346     {
       
  1347         QDEBUG_WRITE_FORMAT("AIW-ERROR: Request Send failed:" , request->lastError());
       
  1348     }  
       
  1349     delete request;
       
  1350 }
       
  1351 
       
  1352 //---------------------------------------------------------------
       
  1353 // MsgUnifiedEditorView::fetchAudio
       
  1354 // @see header file
       
  1355 //---------------------------------------------------------------
       
  1356 void MsgUnifiedEditorView::fetchAudio()
       
  1357 {
       
  1358     QString service("Music Fetcher");
       
  1359     QString interface("com.nokia.services.media.Music");
       
  1360     QString operation("fetch(QString)");
       
  1361     XQAiwRequest* request = NULL;
       
  1362     XQApplicationManager appManager;
       
  1363     request = appManager.create(service, interface, operation, true); //embedded
       
  1364     if(!request)
       
  1365     {
       
  1366         QCRITICAL_WRITE("AIW-ERROR: NULL request");
       
  1367         return;
       
  1368     }
       
  1369 
       
  1370     connect(request, SIGNAL(requestOk(const QVariant&)),
       
  1371         this, SLOT(audiosFetched(const QVariant&)));
       
  1372     connect(request, SIGNAL(requestError(int,const QString&)),
       
  1373         this, SLOT(serviceRequestError(int,const QString&)));
       
  1374 
       
  1375     // Make the request
       
  1376     if (!request->send())
       
  1377     {
       
  1378         QDEBUG_WRITE_FORMAT("AIW-ERROR: Request Send failed :",request->lastError());
       
  1379     }
       
  1380     delete request;
       
  1381 }
       
  1382 
       
  1383 //---------------------------------------------------------------
       
  1384 // MsgUnifiedEditorView::contactsFetched
       
  1385 // @see header file
       
  1386 //---------------------------------------------------------------
       
  1387 void MsgUnifiedEditorView::contactsFetched(const QVariant& value)
       
  1388 {
       
  1389     // create a vcard for each contact fetched and add as attachment
       
  1390     QStringList attachmentList;
       
  1391     if(createVCards(value, attachmentList) == KErrNone)
       
  1392     {
       
  1393         addAttachments(attachmentList);
       
  1394     }
       
  1395 }
       
  1396 
       
  1397 //---------------------------------------------------------------
       
  1398 // MsgUnifiedEditorView::imagesFetched
       
  1399 // @see header file
       
  1400 //---------------------------------------------------------------
       
  1401 void MsgUnifiedEditorView::imagesFetched(const QVariant& result )
       
  1402 {
       
  1403     if(result.canConvert<QStringList>())
       
  1404     {
       
  1405         QStringList fileList = result.value<QStringList>();
       
  1406         if ( fileList.size()>0 )
       
  1407         {
       
  1408             QString filepath(QDir::toNativeSeparators(fileList.at(0)));
       
  1409             mBody->setImage(filepath);
       
  1410             addSubject();
       
  1411         }
       
  1412     }
       
  1413 }
       
  1414 
       
  1415 //---------------------------------------------------------------
       
  1416 // MsgUnifiedEditorView::audiosFetched
       
  1417 // @see header file
       
  1418 //---------------------------------------------------------------
       
  1419 void MsgUnifiedEditorView::audiosFetched(const QVariant& result )
       
  1420 {
       
  1421     if(result.canConvert<QStringList>())
       
  1422     {
       
  1423         QStringList fileList = result.value<QStringList>();
       
  1424         if ( fileList.size()>0 && !fileList.at(0).isEmpty())
       
  1425         {
       
  1426             QString filepath(QDir::toNativeSeparators(fileList.at(0)));
       
  1427             QDEBUG_WRITE_FORMAT("Received audio file path = ", fileList.at(0));
       
  1428             mBody->setAudio(filepath);
       
  1429             addSubject();
       
  1430         }
       
  1431     }
       
  1432 }
       
  1433 
       
  1434 //---------------------------------------------------------------
       
  1435 // MsgUnifiedEditorView::serviceRequestError
       
  1436 // @see header file
       
  1437 //---------------------------------------------------------------
       
  1438 void MsgUnifiedEditorView::serviceRequestError(int errorCode, const QString& errorMessage)
       
  1439 {
       
  1440     QDEBUG_WRITE_FORMAT(errorMessage,errorCode);
       
  1441 }
       
  1442 
       
  1443 //---------------------------------------------------------------
       
  1444 // MsgUnifiedEditorView::activateInputBlocker
       
  1445 // @see header file
       
  1446 //--------------------------------------------------------------
       
  1447 void MsgUnifiedEditorView::activateInputBlocker()
       
  1448     {
       
  1449         this->grabMouse();
       
  1450         this->grabKeyboard();
       
  1451     }
       
  1452 
       
  1453 //---------------------------------------------------------------
       
  1454 // MsgUnifiedEditorView::deactivateInputBlocker
       
  1455 // @see header file
       
  1456 //--------------------------------------------------------------
       
  1457 void MsgUnifiedEditorView::deactivateInputBlocker()
       
  1458     {    
       
  1459         this->ungrabKeyboard();
       
  1460         this->ungrabMouse();
       
  1461     }
       
  1462 
   924 //EOF
  1463 //EOF