messagingapp/msgui/unifiededitor/src/msgunieditorview.cpp
changeset 27 e4592d119491
parent 25 84d9eb65b26f
child 47 5b14749788d7
equal deleted inserted replaced
25:84d9eb65b26f 27:e4592d119491
    34 #include <HbFrameBackground>
    34 #include <HbFrameBackground>
    35 #include <HbListViewItem>
    35 #include <HbListViewItem>
    36 #include <HbListWidgetItem>
    36 #include <HbListWidgetItem>
    37 #include <HbNotificationDialog>
    37 #include <HbNotificationDialog>
    38 #include <HbMessageBox>
    38 #include <HbMessageBox>
       
    39 #include <HbAbstractVkbHost>
       
    40 #include <HbMainWindow>
    39 #include <xqaiwrequest.h>
    41 #include <xqaiwrequest.h>
    40 #include <xqappmgr.h>
    42 #include <xqappmgr.h>
    41 
    43 #include <HbStyleLoader>
    42 // QT Mobility for fetching business card
    44 // QT Mobility for fetching business card
       
    45 #include <qmobilityglobal.h>
    43 #include <qversitwriter.h>
    46 #include <qversitwriter.h>
    44 #include <qversitdocument.h>
    47 #include <qversitdocument.h>
    45 #include <qcontact.h>
    48 #include <qcontact.h>
    46 #include <qcontactmanager.h>
    49 #include <qcontactmanager.h>
    47 #include <qversitcontactexporter.h>
    50 #include <qversitcontactexporter.h>
    48 #include <cntservicescontact.h>
    51 #include <cntservicescontact.h>
       
    52 
    49 
    53 
    50 // USER INCLUDES
    54 // USER INCLUDES
    51 #include "debugtraces.h"
    55 #include "debugtraces.h"
    52 #include "msgunieditorview.h"
    56 #include "msgunieditorview.h"
    53 #include "msgunieditoraddress.h"
    57 #include "msgunieditoraddress.h"
    58 #include "msgsendutil.h"
    62 #include "msgsendutil.h"
    59 #include "convergedmessageaddress.h"
    63 #include "convergedmessageaddress.h"
    60 #include "unieditorgenutils.h"
    64 #include "unieditorgenutils.h"
    61 #include "unieditorpluginloader.h"
    65 #include "unieditorpluginloader.h"
    62 #include "unieditorplugininterface.h"
    66 #include "unieditorplugininterface.h"
    63 
    67 #include "msgsettingsview.h"
       
    68 
       
    69 QTM_USE_NAMESPACE
    64 // Constants
    70 // Constants
    65 const QString SEND_ICON("qtg_mono_send");
    71 const QString SEND_ICON("qtg_mono_send");
    66 const QString ATTACH_ICON("qtg_mono_attach");
    72 const QString ATTACH_ICON("qtg_mono_attach");
    67 // temporary folder for unieditor
    73 // temporary folder for unieditor
    68 const QString UNIFIED_EDITOR_TEMP_FOLDER("unifiededitor");
    74 const QString UNIFIED_EDITOR_TEMP_FOLDER("unifiededitor");
   107 #define LOC_NOTE_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message")
   113 #define LOC_NOTE_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message")
   108 #define LOC_BUTTON_DELETE       hbTrId("txt_common_button_delete")
   114 #define LOC_BUTTON_DELETE       hbTrId("txt_common_button_delete")
   109 #define LOC_BUTTON_CANCEL       hbTrId("txt_common_button_cancel")
   115 #define LOC_BUTTON_CANCEL       hbTrId("txt_common_button_cancel")
   110 #define LOC_DIALOG_OK           hbTrId("txt_common_button_ok")
   116 #define LOC_DIALOG_OK           hbTrId("txt_common_button_ok")
   111 
   117 
       
   118 // attachment addition failure note
       
   119 #define LOC_UNABLE_TO_ADD_ATTACHMENTS hbTrId("txt_messaging_dpopinfo_unable_to_attach_l1_of_l2")
       
   120 
   112 //extension list item frame.
   121 //extension list item frame.
   113 const QString POPUP_LIST_FRAME("qtg_fr_popup_list_normal");
   122 const QString POPUP_LIST_FRAME("qtg_fr_popup_list_normal");
   114 
   123 
       
   124 //settings confirmation
       
   125 #define LOC_DIALOG_SMS_SETTINGS_INCOMPLETE hbTrId("txt_messaging_dialog_sms_settings_incomplete")
       
   126 #define LOC_DIALOG_MMS_SETTINGS_INCOMPLETE hbTrId("txt_messaging_dialog_mms_settings_incomplete")
   115 // LOCAL FUNCTIONS
   127 // LOCAL FUNCTIONS
   116 QString editorTempPath();
   128 
       
   129 //---------------------------------------------------------------
       
   130 // editorTempPath
       
   131 // @return fullPath of unified editor's temporary dir
       
   132 //---------------------------------------------------------------
       
   133 QString editorTempPath()
       
   134 {
       
   135     QDir tempDir;
       
   136     QString tempPath(QDir::toNativeSeparators(tempDir.tempPath()));
       
   137     tempPath.append(QDir::separator());
       
   138     tempPath.append(UNIFIED_EDITOR_TEMP_FOLDER);
       
   139     tempPath.append(QDir::separator());
       
   140     return tempPath;
       
   141 }
   117 
   142 
   118 //---------------------------------------------------------------
   143 //---------------------------------------------------------------
   119 // MsgUnifiedEditorView::MsgUnifiedEditorView
   144 // MsgUnifiedEditorView::MsgUnifiedEditorView
   120 // @see header file
   145 // @see header file
   121 //---------------------------------------------------------------
   146 //---------------------------------------------------------------
   131     mBody(0),
   156     mBody(0),
   132     mContentWidget(0),
   157     mContentWidget(0),
   133     mMsgMonitor(0),    
   158     mMsgMonitor(0),    
   134     mAttachmentContainer(0),
   159     mAttachmentContainer(0),
   135     mPluginLoader(0),
   160     mPluginLoader(0),
   136     mCanSaveToDrafts(true)
   161     mCanSaveToDrafts(true),
   137     {
   162     mVkbHost(NULL)
   138     addMenu();
   163     {
       
   164     connect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(doDelayedConstruction()));
       
   165     
   139     addToolBar();
   166     addToolBar();
   140 
   167     initView();
       
   168     }
       
   169 
       
   170 //---------------------------------------------------------------
       
   171 // MsgUnifiedEditorView::~MsgUnifiedEditorView
       
   172 // @see header file
       
   173 //---------------------------------------------------------------
       
   174 MsgUnifiedEditorView::~MsgUnifiedEditorView()
       
   175 {
       
   176     // clean editor's temporary contents before exiting
       
   177     removeTempFolder();
       
   178 }
       
   179 
       
   180 //---------------------------------------------------------------
       
   181 // MsgUnifiedEditorView::initView
       
   182 // @see header file
       
   183 //---------------------------------------------------------------
       
   184 void MsgUnifiedEditorView::initView()
       
   185 {
       
   186     if (!HbStyleLoader::registerFilePath(":/layouts")) {
       
   187         QDEBUG_WRITE("ERROR: MsgUnifiedEditorView -> HbStyleLoader::registerFilePath");
       
   188     }
   141     HbScrollArea* scrollArea = new HbScrollArea(this);
   189     HbScrollArea* scrollArea = new HbScrollArea(this);
   142     this->setWidget(scrollArea);
   190     this->setWidget(scrollArea);
   143 
   191 
   144     mContentWidget = new HbWidget(this);
   192     mContentWidget = new HbWidget(this);
   145     scrollArea->setContentWidget(mContentWidget);
   193     scrollArea->setContentWidget(mContentWidget);
   146 
       
   147     mPluginPath = pluginPath(); 
       
   148 
   194 
   149     mMainLayout = new QGraphicsLinearLayout(Qt::Vertical, mContentWidget);
   195     mMainLayout = new QGraphicsLinearLayout(Qt::Vertical, mContentWidget);
   150     qreal vTopSpacing = 0.0;
   196     qreal vTopSpacing = 0.0;
   151     qreal vItemSpacing = 0.0;
   197     qreal vItemSpacing = 0.0;
   152     style()->parameter("hb-param-margin-gene-top",vTopSpacing);    
   198     style()->parameter("hb-param-margin-gene-top",vTopSpacing);    
   155     mMainLayout->setContentsMargins(0,vTopSpacing,0,0);
   201     mMainLayout->setContentsMargins(0,vTopSpacing,0,0);
   156     mMainLayout->setSpacing(vItemSpacing);
   202     mMainLayout->setSpacing(vItemSpacing);
   157 
   203 
   158     mMsgMonitor = new MsgMonitor(this);    
   204     mMsgMonitor = new MsgMonitor(this);    
   159 
   205 
   160     mToField = new MsgUnifiedEditorAddress( LOC_TO, mPluginPath, mContentWidget );
   206     mToField = new MsgUnifiedEditorAddress( LOC_TO, mContentWidget );
   161     mBody = new MsgUnifiedEditorBody(mPluginPath, mContentWidget);
   207     
       
   208     mBody = new MsgUnifiedEditorBody( mContentWidget);
   162 
   209 
   163     mMainLayout->addItem(mToField);
   210     mMainLayout->addItem(mToField);
   164     mMainLayout->addItem(mBody);
   211     mMainLayout->addItem(mBody);
   165  
   212  
   166     //Set the invalid msg id
   213     //Set the invalid msg id
   167     mOpenedMessageId.setId(-1);
   214     mOpenedMessageId.setId(-1);
   168 
   215 
   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 
       
   184     connect(mToField, SIGNAL(sendMessage()), this, SLOT(send()));
   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     
   185     connect(mBody, SIGNAL(sendMessage()), this, SLOT(send()));
   221     connect(mBody, SIGNAL(sendMessage()), this, SLOT(send()));
       
   222     connect(mBody, SIGNAL(contentChanged()),this,SLOT(onContentChanged()));
   186     connect(mBody, SIGNAL(contentChanged()),
   223     connect(mBody, SIGNAL(contentChanged()),
   187             mMsgMonitor, SLOT(checkMsgTypeChange()));
   224             mMsgMonitor, SLOT(handleContentChange()));
   188     }
   225     
   189 
       
   190 //---------------------------------------------------------------
       
   191 // MsgUnifiedEditorView::~MsgUnifiedEditorView
       
   192 // @see header file
       
   193 //---------------------------------------------------------------
       
   194 MsgUnifiedEditorView::~MsgUnifiedEditorView()
       
   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);
       
   208 }
   226 }
   209 
   227 
   210 void MsgUnifiedEditorView::addMenu()
   228 void MsgUnifiedEditorView::addMenu()
   211 {
   229 {
   212     //Create Menu Options
   230     //Create Menu Options
   213     HbMenu* mainMenu = new HbMenu();
   231     HbMenu* mainMenu = new HbMenu();
   214 
   232     mainMenu->setFocusPolicy(Qt::NoFocus);
   215     //TODO:These 2 should be submenu option to Add
   233 	
   216     mSubjectAction = mainMenu->addAction(LOC_ADD_SUBJECT);
   234     //if subject field / cc,bcc fields are already present don't add corresponding actions.
   217     mCcBccAction = mainMenu->addAction(LOC_ADD_CC_BCC);
   235     if(!mSubjectField)
       
   236     {
       
   237         mSubjectAction = mainMenu->addAction(LOC_ADD_SUBJECT);
       
   238     }
       
   239     
       
   240     if(!mCcField)
       
   241     {
       
   242         mCcBccAction = mainMenu->addAction(LOC_ADD_CC_BCC);
       
   243     }
   218     
   244     
   219     HbMenu* prioritySubMenu = mainMenu->addMenu(LOC_PRIORITY);
   245     HbMenu* prioritySubMenu = mainMenu->addMenu(LOC_PRIORITY);
   220 
   246 
   221     HbAction* highPriorityAction = prioritySubMenu->addAction(LOC_HIGH);
   247     HbAction* highPriorityAction = prioritySubMenu->addAction(LOC_HIGH);
   222     highPriorityAction->setData(ConvergedMessage::High);
   248     highPriorityAction->setData(ConvergedMessage::High);
   272     {
   298     {
   273         //Populate the content inside editor
   299         //Populate the content inside editor
   274         populateContentIntoEditor(*msg);
   300         populateContentIntoEditor(*msg);
   275         delete msg;
   301         delete msg;
   276     }
   302     }
       
   303     
       
   304     mCanSaveToDrafts = false;  
   277 }
   305 }
   278 
   306 
   279 void MsgUnifiedEditorView::forwardMessage(ConvergedMessageId& messageId,
   307 void MsgUnifiedEditorView::forwardMessage(ConvergedMessageId& messageId,
   280     ConvergedMessage::MessageType messageType )
   308     ConvergedMessage::MessageType messageType )
   281 {
   309 {
   326     }
   354     }
   327 
   355 
   328     // population logic based on editor Operation command
   356     // population logic based on editor Operation command
   329     switch(editorOp)
   357     switch(editorOp)
   330     {
   358     {
   331         case MsgBaseView::ADD_RECIPIENTS:
       
   332         {
       
   333             addCcBcc();
       
   334         }
       
   335         break;
       
   336         case MsgBaseView::ADD_SUBJECT:
   359         case MsgBaseView::ADD_SUBJECT:
   337         {
   360         {
   338             addSubject();
   361             addSubject();
       
   362             setFocus(mSubjectField);
   339         }
   363         }
   340         break;
   364         break;
   341         case MsgBaseView::ADD_VCARD:
   365         case MsgBaseView::ADD_VCARD:
   342         {
   366         {
   343             contactsFetched(editorData.at(2));
   367             contactsFetched(editorData.at(2));
   353     }
   377     }
   354 
   378 
   355     // additional common operations for non-forwarded messages
   379     // additional common operations for non-forwarded messages
   356     if(editorOp != MsgBaseView::FORWARD_MSG)
   380     if(editorOp != MsgBaseView::FORWARD_MSG)
   357     {
   381     {
   358         mToField->setAddresses(messageDetails->toAddressList());
   382         if(editorOp == MsgBaseView::ADD_RECIPIENTS)
       
   383         {
       
   384             // CV sends contact card address as the first address
       
   385             ConvergedMessageAddressList toAddresses = 
       
   386                     messageDetails->toAddressList();
       
   387             int addrCount = toAddresses.count();
       
   388             if(addrCount > 0)
       
   389             {
       
   390                 // add contact card address first
       
   391                 ConvergedMessageAddress *firstAddress =
       
   392                         new ConvergedMessageAddress();
       
   393                 firstAddress->setAlias(toAddresses.at(0)->alias());
       
   394                 firstAddress->setAddress(toAddresses.at(0)->address());
       
   395                 ConvergedMessageAddressList firstList;
       
   396                 firstList << firstAddress;
       
   397                 mToField->setAddresses(firstList);
       
   398             
       
   399                 // add remaining contacts now
       
   400                 ConvergedMessageAddressList otherList;
       
   401                 for(int i=1; i<addrCount; i++)
       
   402                 {
       
   403                     otherList << toAddresses.at(i);
       
   404                 }
       
   405                 mToField->setAddresses(otherList);
       
   406             }
       
   407         }
       
   408         else
       
   409         {
       
   410             mToField->setAddresses(messageDetails->toAddressList());
       
   411         }
   359         QString bodyTxt = messageDetails->bodyText();
   412         QString bodyTxt = messageDetails->bodyText();
   360         mBody->setText(bodyTxt);
   413         mBody->setText(bodyTxt);
   361 
   414 
   362         int attachmentCount = messageDetails->attachments().count();
   415         int attachmentCount = messageDetails->attachments().count();
   363         QStringList pendingAttList;
   416         QStringList pendingAttList;
   374             switch(mediaType)
   427             switch(mediaType)
   375             {
   428             {
   376                 case EMsgMediaImage:
   429                 case EMsgMediaImage:
   377                 {
   430                 {
   378                     mBody->setImage(filePath);
   431                     mBody->setImage(filePath);
   379                     addSubject();
       
   380                 }
   432                 }
   381                 break;
   433                 break;
   382                 case EMsgMediaVideo:
   434                  case EMsgMediaAudio:
   383                 {
       
   384                     mBody->setVideo(filePath);
       
   385                     addSubject();
       
   386                 }
       
   387                 break;
       
   388                 case EMsgMediaAudio:
       
   389                 {
   435                 {
   390                     mBody->setAudio(filePath);
   436                     mBody->setAudio(filePath);
   391                     addSubject();
       
   392                 }
   437                 }
   393                 break;
   438                 break;
   394                 default:
   439                 default:
   395                 {
   440                 {
   396                     pendingAttList << filePath;
   441                     pendingAttList << filePath;
   399             }
   444             }
   400         }
   445         }
   401         // add pending attachments in bulk
   446         // add pending attachments in bulk
   402         addAttachments(pendingAttList);
   447         addAttachments(pendingAttList);
   403     }
   448     }
   404     delete messageDetails;
   449     delete messageDetails; 
   405 }
   450 }
   406 
   451 
   407 void MsgUnifiedEditorView::populateContentIntoEditor(
   452 void MsgUnifiedEditorView::populateContentIntoEditor(
   408     const ConvergedMessage& messageDetails)
   453     const ConvergedMessage& messageDetails)
   409 {
   454 {
   410     // skip first-time MMS type switch note for draft
   455     // skip first-time MMS type switch note for draft
   411     mMsgMonitor->setSkipNote(true);
   456     mMsgMonitor->setSkipNote(true);
       
   457     mToField->skipMaxRecipientQuery(true);
       
   458 
   412     mToField->setAddresses(messageDetails.toAddressList());
   459     mToField->setAddresses(messageDetails.toAddressList());
   413     if(messageDetails.ccAddressList().count() > 0 )
   460     if(messageDetails.ccAddressList().count() > 0 )
   414     {
   461     {
   415         if(!mCcField)
   462         if(!mCcField)
   416         {
   463         {
   471             switch(mediaType)
   518             switch(mediaType)
   472             {
   519             {
   473                 case EMsgMediaImage:
   520                 case EMsgMediaImage:
   474                 {
   521                 {
   475                     mBody->setImage(filePath);
   522                     mBody->setImage(filePath);
   476                     addSubject();
       
   477                     break;
       
   478                 }
       
   479                 case EMsgMediaVideo:
       
   480                 {
       
   481                     mBody->setVideo(filePath);
       
   482                     addSubject();
       
   483                     break;
   523                     break;
   484                 }
   524                 }
   485                 case EMsgMediaAudio:
   525                 case EMsgMediaAudio:
   486                 {
   526                 {
   487                     mBody->setAudio(filePath);
   527                     mBody->setAudio(filePath);
   488                     addSubject();
       
   489                     break;
   528                     break;
   490                 }
   529                 }
   491                 default:
   530                 default:
   492                 {
   531                 {
   493                     pendingAttList << filePath;
   532                     pendingAttList << filePath;
   503     // add pending attachments to editor
   542     // add pending attachments to editor
   504     addAttachments(pendingAttList);
   543     addAttachments(pendingAttList);
   505 
   544 
   506     delete genUtils;
   545     delete genUtils;
   507     // ensure that any msg-type change after this are shown
   546     // ensure that any msg-type change after this are shown
       
   547     mToField->skipMaxRecipientQuery(false);
   508     mMsgMonitor->setSkipNote(false);
   548     mMsgMonitor->setSkipNote(false);
   509 }
   549 }
   510 
   550 
   511 void MsgUnifiedEditorView::addToolBar()
   551 void MsgUnifiedEditorView::addToolBar()
   512 {
   552 {
   517     //tool bar extension for attach action.
   557     //tool bar extension for attach action.
   518     HbToolBarExtension* attachExtension = new HbToolBarExtension();
   558     HbToolBarExtension* attachExtension = new HbToolBarExtension();
   519     HbAction *attachAction = toolBar->addExtension(attachExtension);    
   559     HbAction *attachAction = toolBar->addExtension(attachExtension);    
   520     attachAction->setIcon(HbIcon(ATTACH_ICON));
   560     attachAction->setIcon(HbIcon(ATTACH_ICON));
   521     
   561     
   522     HbListWidget* extnList = new HbListWidget();
   562     mTBExtnContentWidget = new HbListWidget();
   523     extnList->addItem(LOC_PHOTO);
   563     mTBExtnContentWidget->addItem(LOC_PHOTO);
   524     extnList->addItem(LOC_SOUND);
   564     mTBExtnContentWidget->addItem(LOC_SOUND);
   525     extnList->addItem(LOC_BUSINESS_CARD);
   565     mTBExtnContentWidget->addItem(LOC_BUSINESS_CARD);
   526 
   566 
   527     HbListViewItem *prototype = extnList->listItemPrototype();
   567     HbListViewItem *prototype = mTBExtnContentWidget->listItemPrototype();
   528     HbFrameBackground frame(POPUP_LIST_FRAME, HbFrameDrawer::NinePieces);
   568     HbFrameBackground frame(POPUP_LIST_FRAME, HbFrameDrawer::NinePieces);
   529     prototype->setDefaultFrame(frame);
   569     prototype->setDefaultFrame(frame);
   530 
   570 
   531     connect(extnList, SIGNAL(activated(HbListWidgetItem*)), this,
   571     connect(mTBExtnContentWidget, SIGNAL(activated(HbListWidgetItem*)),
   532             SLOT(handleViewExtnActivated(HbListWidgetItem*)));
   572             this, SLOT(handleViewExtnActivated(HbListWidgetItem*)));
   533     connect(extnList, SIGNAL(activated(HbListWidgetItem*)), attachExtension, SLOT(close()));
   573     connect(mTBExtnContentWidget, SIGNAL(activated(HbListWidgetItem*)),
   534 
   574             attachExtension, SLOT(close()));
   535     attachExtension->setContentWidget(extnList);
   575 
       
   576     attachExtension->setContentWidget(mTBExtnContentWidget);
   536 
   577 
   537     //Add Action to the toolbar and show toolbar
   578     //Add Action to the toolbar and show toolbar
   538     toolBar->addAction(HbIcon(SEND_ICON),QString(),this,SLOT(send()));
   579     toolBar->addAction(HbIcon(SEND_ICON),QString(),this,SLOT(send()));
   539 
   580 
   540 
   581 
   545 {
   586 {
   546     if(mSubjectField)
   587     if(mSubjectField)
   547     { // do nothing if already present
   588     { // do nothing if already present
   548         return;
   589         return;
   549     }
   590     }
   550     // remove mainmenu's "Add Subject" action
       
   551     HbMenu* mainMenu = this->menu();
       
   552     mainMenu->removeAction(mSubjectAction);
       
   553     mSubjectAction->setParent(NULL);
       
   554     delete mSubjectAction;
       
   555 
   591 
   556     int index =0;
   592     int index =0;
   557     int offset = 1;
   593     int offset = 1;
   558     if(mAttachmentContainer)
   594     if(mAttachmentContainer)
   559     {
   595     {
   560         ++offset;
   596         ++offset;
   561     }
   597     }
   562     index = mMainLayout->count() - offset;
   598     index = mMainLayout->count() - offset;
   563 
   599 
   564     mSubjectField = new MsgUnifiedEditorSubject(mPluginPath, mContentWidget);
   600     mSubjectField = new MsgUnifiedEditorSubject( mContentWidget);
       
   601     
   565     mMainLayout->insertItem(index,mSubjectField);
   602     mMainLayout->insertItem(index,mSubjectField);
   566     connect(mSubjectField, SIGNAL(contentChanged()),
   603     connect(mSubjectField, SIGNAL(contentChanged()),
   567             mMsgMonitor, SLOT(checkMsgTypeChange()));    
   604             mMsgMonitor, SLOT(handleContentChange()));
       
   605     connect(mSubjectField, SIGNAL(contentChanged()),this,SLOT(onContentChanged()));
       
   606     
       
   607     //set focus to subject field.
       
   608     HbAction* subjectAction = qobject_cast<HbAction*>(this->sender());
       
   609     if(subjectAction)
       
   610     {
       
   611         setFocus(mSubjectField);
       
   612     }
       
   613     
       
   614     // remove mainmenu's "Add Subject" action
       
   615     if(mSubjectAction)
       
   616     {
       
   617         HbMenu* mainMenu = this->menu();
       
   618         mainMenu->removeAction(mSubjectAction);
       
   619         mSubjectAction->setParent(NULL);
       
   620         delete mSubjectAction;
       
   621     }
   568 }
   622 }
   569 
   623 
   570 void MsgUnifiedEditorView::addCcBcc()
   624 void MsgUnifiedEditorView::addCcBcc()
   571 {
   625 {
   572     if(mCcField && mBccField)
   626     if(mCcField && mBccField)
   573     { // do nothing if already present
   627     { // do nothing if already present
   574         return;
   628         return;
   575     }
   629     }
   576 
   630 
   577     // remove mainmenu's "Add Cc/Bcc" & "Add Subject" actions
   631     mCcField    = new MsgUnifiedEditorAddress( LOC_CC, mContentWidget );
   578     HbMenu* mainmenu = this->menu();
   632     mBccField   = new MsgUnifiedEditorAddress( LOC_BCC, mContentWidget );
   579     mainmenu->removeAction(mCcBccAction);
   633     mCcField->skipMaxRecipientQuery(true);
   580     mCcBccAction->setParent(NULL);
   634     mBccField->skipMaxRecipientQuery(true);
   581     delete mCcBccAction;
       
   582 
       
   583     mCcField    = new MsgUnifiedEditorAddress( LOC_CC, mPluginPath, mContentWidget );
       
   584     mBccField   = new MsgUnifiedEditorAddress( LOC_BCC, mPluginPath, mContentWidget );
       
   585 
   635 
   586     connect(mCcField, SIGNAL(sendMessage()), this, SLOT(send()));
   636     connect(mCcField, SIGNAL(sendMessage()), this, SLOT(send()));
   587     connect(mCcField, SIGNAL(contentChanged()), mMsgMonitor, SLOT(checkMsgTypeChange()));
   637     connect(mCcField, SIGNAL(contentChanged()), mMsgMonitor, SLOT(handleContentChange()));
       
   638     connect(mCcField, SIGNAL(contentChanged()),this,SLOT(onContentChanged()));
       
   639     
   588     connect(mBccField, SIGNAL(sendMessage()), this, SLOT(send()));
   640     connect(mBccField, SIGNAL(sendMessage()), this, SLOT(send()));
   589     connect(mBccField, SIGNAL(contentChanged()), mMsgMonitor, SLOT(checkMsgTypeChange()));
   641     connect(mBccField, SIGNAL(contentChanged()), mMsgMonitor, SLOT(handleContentChange()));
       
   642     connect(mBccField, SIGNAL(contentChanged()),this,SLOT(onContentChanged()));
   590 
   643 
   591     HbWidget* groupWidget = new HbWidget(mContentWidget);
   644     HbWidget* groupWidget = new HbWidget(mContentWidget);
   592     groupWidget->setContentsMargins(0,0,0,0);
   645     groupWidget->setContentsMargins(0,0,0,0);
   593     
   646     
   594     QGraphicsLinearLayout* ccBccLayout = new QGraphicsLinearLayout(Qt::Vertical, groupWidget);
   647     QGraphicsLinearLayout* ccBccLayout = new QGraphicsLinearLayout(Qt::Vertical, groupWidget);
   608     mMainLayout->insertItem(1,groupBox);
   661     mMainLayout->insertItem(1,groupBox);
   609     connect(groupBox, SIGNAL(toggled(bool)), this, SLOT(updateOtherRecipientCount(bool)));
   662     connect(groupBox, SIGNAL(toggled(bool)), this, SLOT(updateOtherRecipientCount(bool)));
   610     
   663     
   611     // add subject field too
   664     // add subject field too
   612     addSubject();
   665     addSubject();
       
   666 
       
   667     //set focus to Cc field.
       
   668     HbAction* ccBccAction = qobject_cast<HbAction*>(this->sender());
       
   669     if(mCcBccAction)
       
   670     {
       
   671         setFocus(mCcField);
       
   672     }
       
   673     
       
   674     // remove mainmenu's "Add Cc/Bcc" & "Add Subject" actions
       
   675     if(mCcBccAction)
       
   676     {
       
   677     HbMenu* mainmenu = this->menu();
       
   678     mainmenu->removeAction(mCcBccAction);
       
   679     mCcBccAction->setParent(NULL);
       
   680     delete mCcBccAction;
       
   681     }
   613     
   682     
   614     this->updateGeometry();
   683     this->updateGeometry();
   615 }
   684 }
   616 
   685 
   617 void MsgUnifiedEditorView::updateOtherRecipientCount(bool state)
   686 void MsgUnifiedEditorView::updateOtherRecipientCount(bool state)
   651 {
   720 {
   652 }
   721 }
   653 
   722 
   654 void MsgUnifiedEditorView::deleteMessage()
   723 void MsgUnifiedEditorView::deleteMessage()
   655 {
   724 {
   656     bool ok = HbMessageBox::question(LOC_NOTE_DELETE_MESSAGE,
   725     HbMessageBox::question(LOC_NOTE_DELETE_MESSAGE,this,SLOT(onDialogDeleteMsg(HbAction*)),
   657                                             LOC_BUTTON_DELETE, LOC_BUTTON_CANCEL);
   726                                             LOC_BUTTON_DELETE, LOC_BUTTON_CANCEL);
   658     
       
   659     if(ok)
       
   660         {
       
   661         mCanSaveToDrafts = false;
       
   662     
       
   663         //delete if draft entry opened
       
   664         if( mOpenedMessageId.getId() != -1)
       
   665             {    
       
   666             if(!mPluginLoader)
       
   667                 {
       
   668                 mPluginLoader = new UniEditorPluginLoader(this);
       
   669                 }
       
   670         
       
   671             UniEditorPluginInterface* pluginInterface =
       
   672                 mPluginLoader->getUniEditorPlugin(MsgMonitor::messageType());
       
   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         }
       
   684 }
   727 }
   685 
   728 
   686 void MsgUnifiedEditorView::removeAttachmentContainer()
   729 void MsgUnifiedEditorView::removeAttachmentContainer()
   687 {
   730 {
   688     if(mAttachmentContainer)
   731     if(mAttachmentContainer)
   698 {    
   741 {    
   699     int fcount = files.count();
   742     int fcount = files.count();
   700     int i=0;
   743     int i=0;
   701     for(i=0; i<fcount; i++)
   744     for(i=0; i<fcount; i++)
   702     {
   745     {
   703         if(MsgAttachmentContainer::EAddSizeExceed 
   746         int status = addAttachment(files.at(i));
   704                 == addAttachment(files.at(i)))
   747         if(status == MsgAttachmentContainer::EAddSizeExceed)
   705         {
   748         {
   706             // size already exceeds max mms size-limit
   749             QString displayStr = QString(LOC_UNABLE_TO_ADD_ATTACHMENTS)
       
   750                     .arg(fcount-i).arg(fcount);
       
   751             HbNotificationDialog::launchDialog(displayStr);
   707             break;
   752             break;
   708         }
   753         }
   709     }
   754     }
   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 }
   755 }
   717 
   756 
   718 int MsgUnifiedEditorView::addAttachment(const QString& filepath)
   757 int MsgUnifiedEditorView::addAttachment(const QString& filepath)
   719 {
   758 {
   720     if(!mAttachmentContainer)
   759     if(!mAttachmentContainer)
   721     {
   760     {
   722         mAttachmentContainer = new MsgAttachmentContainer(mPluginPath, mContentWidget);
   761         mAttachmentContainer = new MsgAttachmentContainer( mContentWidget);
   723         connect(mAttachmentContainer, SIGNAL(emptyAttachmentContainer()),
   762         connect(mAttachmentContainer, SIGNAL(emptyAttachmentContainer()),
   724                 this, SLOT(removeAttachmentContainer()));
   763                 this, SLOT(removeAttachmentContainer()));
   725         connect(mAttachmentContainer, SIGNAL(contentChanged()),
   764         connect(mAttachmentContainer, SIGNAL(contentChanged()),
   726                 mMsgMonitor, SLOT(checkMsgTypeChange()));
   765                 mMsgMonitor, SLOT(handleContentChange()));
       
   766         connect(mAttachmentContainer, SIGNAL(contentChanged()),
       
   767                 this,SLOT(onContentChanged()));
       
   768         
   727         int index = mMainLayout->count() - 1;
   769         int index = mMainLayout->count() - 1;
   728         mMainLayout->insertItem(index,mAttachmentContainer);
   770         mMainLayout->insertItem(index,mAttachmentContainer);
   729     }
   771     }
   730 
   772 
   731     int ret = mAttachmentContainer->addAttachment(filepath);
   773     int ret = mAttachmentContainer->addAttachment(filepath);
   735         if(mAttachmentContainer->count() == 0)
   777         if(mAttachmentContainer->count() == 0)
   736         {
   778         {
   737             removeAttachmentContainer();
   779             removeAttachmentContainer();
   738         }
   780         }
   739     }
   781     }
   740     else if(mAttachmentContainer->hasMMContent())
       
   741     {
       
   742         // when msg is converted to MMS, subject needs to be auto-inserted
       
   743         addSubject();
       
   744     }
       
   745     return ret;
   782     return ret;
   746 }
   783 }
   747 
   784 
   748 QString MsgUnifiedEditorView::pluginPath()
       
   749 {
       
   750     QString pluginPath;
       
   751     #ifdef Q_OS_WIN
       
   752     #define PLUGINPATH "../unifiededitorplugin/debug/unifiededitorplugind.dll"
       
   753     #endif
       
   754     #ifdef Q_OS_SYMBIAN
       
   755     #define PLUGINPATH "unifiededitorplugin.dll"
       
   756     #endif
       
   757     pluginPath.append(PLUGINPATH);
       
   758     return pluginPath;
       
   759 }
       
   760 
       
   761 void MsgUnifiedEditorView::send()
   785 void MsgUnifiedEditorView::send()
   762 {
   786 {
   763     activateInputBlocker();
   787     activateInputBlocker();
       
   788     
       
   789     // first run the address validation tests
       
   790     if( !mToField->validateContacts() ||
       
   791         (mCcField && !mCcField->validateContacts()) ||
       
   792         (mBccField && !mBccField->validateContacts()) )
       
   793     {
       
   794         deactivateInputBlocker();
       
   795         return;
       
   796     }
   764 
   797 
   765     // converged msg for sending
   798     // converged msg for sending
   766     ConvergedMessage msg;
   799     ConvergedMessage msg;
   767     ConvergedMessage::MessageType messageType = MsgMonitor::messageType();
   800     ConvergedMessage::MessageType messageType = MsgMonitor::messageType();
   768     msg.setMessageType(messageType);
   801     msg.setMessageType(messageType);
   769 
   802 
   770     ConvergedMessageAddressList addresses = mToField->addresses();
   803     // we need to remove duplicate addresses
       
   804     bool removeDuplicates = true;
       
   805     ConvergedMessageAddressList addresses =
       
   806             mToField->addresses(removeDuplicates);
   771     if(messageType == ConvergedMessage::Sms &&
   807     if(messageType == ConvergedMessage::Sms &&
   772        addresses.isEmpty())
   808        addresses.isEmpty())
   773     {
   809     {
   774         // no recipient specified for sms, do not send msg
   810         // no recipient specified for sms, do not send msg
   775         deactivateInputBlocker();
   811         deactivateInputBlocker();
   778 
   814 
   779     ConvergedMessageAddressList ccAddresses;
   815     ConvergedMessageAddressList ccAddresses;
   780     ConvergedMessageAddressList bccAddresses;
   816     ConvergedMessageAddressList bccAddresses;
   781     if(mCcField)
   817     if(mCcField)
   782     {
   818     {
   783         ccAddresses = mCcField->addresses();
   819         ccAddresses = mCcField->addresses(removeDuplicates);
   784     }
   820     }
   785     if(mBccField)
   821     if(mBccField)
   786     {
   822     {
   787         bccAddresses = mBccField->addresses();
   823         bccAddresses = mBccField->addresses(removeDuplicates);
   788     }
   824     }
   789     if( messageType == ConvergedMessage::Mms &&
   825     if( messageType == ConvergedMessage::Mms &&
   790             addresses.isEmpty() &&
   826             addresses.isEmpty() &&
   791             ccAddresses.isEmpty() &&
   827             ccAddresses.isEmpty() &&
   792             bccAddresses.isEmpty())
   828             bccAddresses.isEmpty())
   793     {
   829     {
   794         // no recipient specified for mms, do not send msg
   830         // no recipient specified for mms, do not send msg
   795         deactivateInputBlocker();
   831         deactivateInputBlocker();
   796         return;
   832         return;
   797     }
   833     }
       
   834     
       
   835     //close vkb before switching view.
       
   836     mVkbHost->closeKeypad(true);
   798 
   837 
   799     packMessage(msg);
   838     packMessage(msg);
   800     
   839     
   801     // send message
   840     // send message
   802     MsgSendUtil *sendUtil = new MsgSendUtil(this);
   841     MsgSendUtil *sendUtil = new MsgSendUtil(this);
   847             if(bccCount)
   886             if(bccCount)
   848             {
   887             {
   849                 receipient = addrList.at(0)->address();
   888                 receipient = addrList.at(0)->address();
   850             }
   889             }
   851         }
   890         }
   852 
   891         
   853 
       
   854     QVariantList params;
   892     QVariantList params;
   855 
   893 
   856     if(recepientCount == 1 )
   894     if(recepientCount == 1 )
   857         {
   895         {
   858         params << MsgBaseView::CV;  // target view
   896         params << MsgBaseView::CV;  // target view
   871     else
   909     else
   872     {
   910     {
   873         deactivateInputBlocker();
   911         deactivateInputBlocker();
   874         if(sendResult == KErrNotFound)
   912         if(sendResult == KErrNotFound)
   875         {
   913         {
   876         	  bool result = HbMessageBox::question("Settings not defined\nDefine now ?",
   914             if (messageType == ConvergedMessage::Sms)
   877                                          LOC_DIALOG_OK,
       
   878                                          LOC_BUTTON_CANCEL);
       
   879             if (result)
       
   880             {
   915             {
   881               QVariantList params;
   916                 HbMessageBox::question(LOC_DIALOG_SMS_SETTINGS_INCOMPLETE,
   882               params << MsgBaseView::MSGSETTINGS;// target view
   917                     this,SLOT(onDialogSmsSettings(HbAction*)),
   883               params << MsgBaseView::UNIEDITOR; // source view
   918                                                  LOC_DIALOG_OK,
   884               emit switchView(params);
   919                                                  LOC_BUTTON_CANCEL);
   885             }
   920             }
   886         }
   921             else
   887     }
   922             {
   888 }
   923                 HbMessageBox::question(LOC_DIALOG_MMS_SETTINGS_INCOMPLETE,
   889 
   924                     this,SLOT(onDialogMmsSettings(HbAction*)),                             
   890 void MsgUnifiedEditorView::packMessage(ConvergedMessage &msg)
   925                                                  LOC_DIALOG_OK,
       
   926                                                  LOC_BUTTON_CANCEL);
       
   927             }
       
   928         }
       
   929     }
       
   930 }
       
   931 
       
   932 void MsgUnifiedEditorView::packMessage(ConvergedMessage &msg, bool isSave)
   891 {
   933 {
   892     ConvergedMessage::MessageType messageType = MsgMonitor::messageType();
   934     ConvergedMessage::MessageType messageType = MsgMonitor::messageType();
   893     msg.setMessageType(messageType);
   935     msg.setMessageType(messageType);
   894 
   936     // If isSave is true (save to draft usecase), then don't remove duplicates
   895     ConvergedMessageAddressList addresses = mToField->addresses();
   937     // If isSave is false (send usecase), then remove duplicates
       
   938     bool removeDuplicates = !isSave;
       
   939     ConvergedMessageAddressList addresses = 
       
   940             mToField->addresses(removeDuplicates);
   896     ConvergedMessageAddressList ccAddresses;
   941     ConvergedMessageAddressList ccAddresses;
   897     ConvergedMessageAddressList bccAddresses;
   942     ConvergedMessageAddressList bccAddresses;
   898 
   943 
   899     msg.addToRecipients(addresses);
   944     msg.addToRecipients(addresses);
   900     msg.setBodyText(mBody->text());
   945     msg.setBodyText(mBody->text());
   904 
   949 
   905     if(messageType == ConvergedMessage::Mms)
   950     if(messageType == ConvergedMessage::Mms)
   906     {
   951     {
   907         if(mCcField)
   952         if(mCcField)
   908         {
   953         {
   909             ccAddresses = mCcField->addresses();
   954             ccAddresses = mCcField->addresses(removeDuplicates);
   910         }
   955         }
   911 
   956 
   912         if(mBccField)
   957         if(mBccField)
   913         {
   958         {
   914             bccAddresses = mBccField->addresses();
   959             bccAddresses = mBccField->addresses(removeDuplicates);
   915         }
   960         }
   916 
   961 
   917         int matchDigitsCount = MsgUnifiedEditorAddress::contactMatchDigits();
   962         if(removeDuplicates)
   918         //comapre cc and to field,remove duplicate from cc
   963         {
   919         foreach(ConvergedMessageAddress *ccAddress,ccAddresses)
   964             int matchDigitsCount = MsgUnifiedEditorAddress::contactMatchDigits();
   920         {
   965             //comapre cc and to field,remove duplicate from cc
   921           foreach(ConvergedMessageAddress *toAddress,addresses)
   966             foreach(ConvergedMessageAddress *ccAddress,ccAddresses)
   922           {
   967             {
   923              if(0 == ccAddress->address().right(matchDigitsCount).compare(toAddress->address().right(matchDigitsCount)))
   968                 foreach(ConvergedMessageAddress *toAddress,addresses)
   924              {
   969                 {
   925                 ccAddresses.removeOne(ccAddress);
   970                     if(0 == ccAddress->address().right(matchDigitsCount).compare(toAddress->address().right(matchDigitsCount)))
   926              }
   971                     {
   927           }
   972                         ccAddresses.removeOne(ccAddress);
   928         }
   973                     }
   929         //comapre bcc and cc field,remove duplicate from bcc
   974                 }
   930         foreach(ConvergedMessageAddress *bccAddress,bccAddresses)
   975             }
   931         {
   976             //comapre bcc and cc field,remove duplicate from bcc
   932           foreach(ConvergedMessageAddress *ccAddress,ccAddresses)
   977             foreach(ConvergedMessageAddress *bccAddress,bccAddresses)
   933           {
   978             {
   934              if(0 == bccAddress->address().right(matchDigitsCount).compare(ccAddress->address().right(matchDigitsCount)))
   979                 foreach(ConvergedMessageAddress *ccAddress,ccAddresses)
   935              {
   980                 {
   936                 bccAddresses.removeOne(bccAddress);
   981                     if(0 == bccAddress->address().right(matchDigitsCount).compare(ccAddress->address().right(matchDigitsCount)))
   937              }
   982                     {
   938           }
   983                         bccAddresses.removeOne(bccAddress);
   939         }
   984                     }
   940         //comapre bcc and to field,remove duplicate from bcc
   985                 }
   941         foreach(ConvergedMessageAddress *bccAddress,bccAddresses)
   986             }
   942         {
   987             //comapre bcc and to field,remove duplicate from bcc
   943           foreach(ConvergedMessageAddress *toAddress,addresses)
   988             foreach(ConvergedMessageAddress *bccAddress,bccAddresses)
   944           {
   989             {
   945              if(0 == bccAddress->address().right(matchDigitsCount).compare(toAddress->address().right(matchDigitsCount)))
   990                 foreach(ConvergedMessageAddress *toAddress,addresses)
   946              {
   991                 {
   947                 bccAddresses.removeOne(bccAddress);
   992                     if(0 == bccAddress->address().right(matchDigitsCount).compare(toAddress->address().right(matchDigitsCount)))
   948              }
   993                     {
   949           }
   994                         bccAddresses.removeOne(bccAddress);
       
   995                     }
       
   996                 }
       
   997             }
   950         }
   998         }
   951 
   999 
   952         if(ccAddresses.count()>0)
  1000         if(ccAddresses.count()>0)
   953         {
  1001         {
   954         msg.addCcRecipients(ccAddresses);
  1002         msg.addCcRecipients(ccAddresses);
  1075         // if empty msg, do not send
  1123         // if empty msg, do not send
  1076         deactivateInputBlocker();
  1124         deactivateInputBlocker();
  1077         return;
  1125         return;
  1078     }
  1126     }
  1079     ConvergedMessage msg;
  1127     ConvergedMessage msg;
  1080     packMessage(msg);
  1128     packMessage(msg, true);
  1081 
  1129 
  1082     // save to drafts
  1130     // save to drafts
  1083     MsgSendUtil *sendUtil = new MsgSendUtil(this);
  1131     MsgSendUtil *sendUtil = new MsgSendUtil(this);
  1084     int msgId = sendUtil->saveToDrafts(msg);
  1132     int msgId = sendUtil->saveToDrafts(msg);
  1085     delete sendUtil;
  1133     delete sendUtil;
  1111 
  1159 
  1112  mContentWidget->resize(this->rect().width(),this->rect().height()+1);
  1160  mContentWidget->resize(this->rect().width(),this->rect().height()+1);
  1113 }
  1161 }
  1114 
  1162 
  1115 //---------------------------------------------------------------
  1163 //---------------------------------------------------------------
  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
  1164 // MsgUnifiedEditorView::createVCards
  1131 // @see header file
  1165 // @see header file
  1132 //---------------------------------------------------------------
  1166 //---------------------------------------------------------------
  1133 int MsgUnifiedEditorView::createVCards(
  1167 int MsgUnifiedEditorView::createVCards(
  1134         const QVariant& value, QStringList& filelist)
  1168         const QVariant& value, QStringList& filelist)
  1135 {
  1169 {
  1136     // make sure that temp-folder is created for storing vcards
  1170     // make sure that temp-folder is created for storing vcards
  1137     QDir tempDir = QDir(QString());
  1171     if(!createTempFolder())
  1138     if(!tempDir.mkpath(editorTempPath()))
       
  1139     {
  1172     {
  1140         return KErrGeneral;
  1173         return KErrGeneral;
  1141     }
  1174     }
  1142     tempDir.cd(editorTempPath());
       
  1143 
       
  1144 
  1175 
  1145     // extract contact-list
  1176     // extract contact-list
  1146     QContactManager* contactManager = new QContactManager("symbian");
  1177     QContactManager* contactManager = new QContactManager("symbian");
  1147     CntServicesContactList cntServicesContacts = qVariantValue<CntServicesContactList>(value);
  1178     CntServicesContactList cntServicesContacts = qVariantValue<CntServicesContactList>(value);
  1148     int cntCount = cntServicesContacts.count();
  1179     int cntCount = cntServicesContacts.count();
  1214 // @algo For multiselected 'Unnamed' contacts, the filename should
  1245 // @algo For multiselected 'Unnamed' contacts, the filename should
  1215 // be synthesized as unnamed.vcf, unnamed1.vcf, unnamed2.vcf etc.
  1246 // be synthesized as unnamed.vcf, unnamed1.vcf, unnamed2.vcf etc.
  1216 //---------------------------------------------------------------
  1247 //---------------------------------------------------------------
  1217 QString MsgUnifiedEditorView::generateFileName(QString& suggestedName)
  1248 QString MsgUnifiedEditorView::generateFileName(QString& suggestedName)
  1218 {
  1249 {
  1219     QDir editorTempDir = QDir(QString());
  1250     QDir editorTempDir;
  1220     editorTempDir.cd(editorTempPath());
  1251     editorTempDir.cd(editorTempPath());
  1221 
  1252 
  1222     for(int i=0; i<MAX_VCARDS; i++)
  1253     for(int i=0; i<MAX_VCARDS; i++)
  1223     {
  1254     {
  1224         QString searchFileName = suggestedName;
  1255         QString searchFileName = suggestedName;
  1267     
  1298     
  1268     if(itemText == LOC_PHOTO)
  1299     if(itemText == LOC_PHOTO)
  1269         {
  1300         {
  1270         //launch photo picker.
  1301         //launch photo picker.
  1271         fetchImages();  
  1302         fetchImages();  
  1272     }
  1303         }
  1273     else if(itemText == LOC_SOUND)
  1304     else if(itemText == LOC_SOUND)
  1274         {
  1305         {
  1275         //launch audio picker
  1306         //launch audio picker
  1276         fetchAudio();
  1307         fetchAudio();
  1277     }
  1308         }
  1278     else if(itemText == LOC_BUSINESS_CARD)
  1309     else if(itemText == LOC_BUSINESS_CARD)
  1279         {
  1310         {
  1280         //launch contact card picker.
  1311         //launch contact card picker.
  1281         fetchContacts();
  1312         fetchContacts();
  1282     }
  1313         }
  1283    
  1314    
  1284 }
  1315 }
  1285 
  1316 
  1286 //---------------------------------------------------------------
  1317 //---------------------------------------------------------------
  1287 // MsgUnifiedEditorView::fetchContacts
  1318 // MsgUnifiedEditorView::fetchContacts
  1328     QString interface("Image");
  1359     QString interface("Image");
  1329     QString operation("fetch(QVariantMap,QVariant)");
  1360     QString operation("fetch(QVariantMap,QVariant)");
  1330     XQAiwRequest* request = NULL;
  1361     XQAiwRequest* request = NULL;
  1331     XQApplicationManager appManager;
  1362     XQApplicationManager appManager;
  1332     request = appManager.create(interface, operation, true);//embedded
  1363     request = appManager.create(interface, operation, true);//embedded
       
  1364     request->setSynchronous(true); // synchronous
  1333     if(!request)
  1365     if(!request)
  1334     {     
  1366     {     
  1335         QCRITICAL_WRITE("AIW-ERROR: NULL request");
  1367         QCRITICAL_WRITE("AIW-ERROR: NULL request");
  1336         return;
  1368         return;
  1337     }
  1369     }
  1338 
  1370 
  1339     connect(request, SIGNAL(requestOk(const QVariant&)),
  1371     connect(request, SIGNAL(requestOk(const QVariant&)),
  1340         this, SLOT(imagesFetched(const QVariant&)));
  1372         this, SLOT(imagesFetched(const QVariant&)));
  1341     connect(request, SIGNAL(requestError(int,const QString&)),
  1373     connect(request, SIGNAL(requestError(int,const QString&)),
  1342         this, SLOT(serviceRequestError(int,const QString&)));
  1374         this, SLOT(serviceRequestError(int,const QString&)));
  1343    
  1375     
       
  1376     // Set arguments for request
       
  1377     QList<QVariant> args;
       
  1378     args << QVariantMap();
       
  1379     args << QVariant();
       
  1380     request->setArguments(args);
  1344     // Make the request
  1381     // Make the request
  1345     if (!request->send())
  1382     if (!request->send())
  1346     {
  1383     {
  1347         QDEBUG_WRITE_FORMAT("AIW-ERROR: Request Send failed:" , request->lastError());
  1384         QDEBUG_WRITE_FORMAT("AIW-ERROR: Request Send failed:" , request->lastError());
  1348     }  
  1385     }  
  1353 // MsgUnifiedEditorView::fetchAudio
  1390 // MsgUnifiedEditorView::fetchAudio
  1354 // @see header file
  1391 // @see header file
  1355 //---------------------------------------------------------------
  1392 //---------------------------------------------------------------
  1356 void MsgUnifiedEditorView::fetchAudio()
  1393 void MsgUnifiedEditorView::fetchAudio()
  1357 {
  1394 {
  1358     QString service("Music Fetcher");
  1395     QString service("musicplayer");
  1359     QString interface("com.nokia.services.media.Music");
  1396     QString interface("com.nokia.symbian.IMusicFetch");
  1360     QString operation("fetch(QString)");
  1397     QString operation("fetch()");
  1361     XQAiwRequest* request = NULL;
  1398     XQAiwRequest* request = NULL;
  1362     XQApplicationManager appManager;
  1399     XQApplicationManager appManager;
  1363     request = appManager.create(service, interface, operation, true); //embedded
  1400     request = appManager.create(service, interface, operation, true); //embedded
       
  1401     request->setSynchronous(true); // synchronous
  1364     if(!request)
  1402     if(!request)
  1365     {
  1403     {
  1366         QCRITICAL_WRITE("AIW-ERROR: NULL request");
  1404         QCRITICAL_WRITE("AIW-ERROR: NULL request");
  1367         return;
  1405         return;
  1368     }
  1406     }
  1405         QStringList fileList = result.value<QStringList>();
  1443         QStringList fileList = result.value<QStringList>();
  1406         if ( fileList.size()>0 )
  1444         if ( fileList.size()>0 )
  1407         {
  1445         {
  1408             QString filepath(QDir::toNativeSeparators(fileList.at(0)));
  1446             QString filepath(QDir::toNativeSeparators(fileList.at(0)));
  1409             mBody->setImage(filepath);
  1447             mBody->setImage(filepath);
  1410             addSubject();
       
  1411         }
  1448         }
  1412     }
  1449     }
  1413 }
  1450 }
  1414 
  1451 
  1415 //---------------------------------------------------------------
  1452 //---------------------------------------------------------------
  1424         if ( fileList.size()>0 && !fileList.at(0).isEmpty())
  1461         if ( fileList.size()>0 && !fileList.at(0).isEmpty())
  1425         {
  1462         {
  1426             QString filepath(QDir::toNativeSeparators(fileList.at(0)));
  1463             QString filepath(QDir::toNativeSeparators(fileList.at(0)));
  1427             QDEBUG_WRITE_FORMAT("Received audio file path = ", fileList.at(0));
  1464             QDEBUG_WRITE_FORMAT("Received audio file path = ", fileList.at(0));
  1428             mBody->setAudio(filepath);
  1465             mBody->setAudio(filepath);
  1429             addSubject();
       
  1430         }
  1466         }
  1431     }
  1467     }
  1432 }
  1468 }
  1433 
  1469 
  1434 //---------------------------------------------------------------
  1470 //---------------------------------------------------------------
  1443 //---------------------------------------------------------------
  1479 //---------------------------------------------------------------
  1444 // MsgUnifiedEditorView::activateInputBlocker
  1480 // MsgUnifiedEditorView::activateInputBlocker
  1445 // @see header file
  1481 // @see header file
  1446 //--------------------------------------------------------------
  1482 //--------------------------------------------------------------
  1447 void MsgUnifiedEditorView::activateInputBlocker()
  1483 void MsgUnifiedEditorView::activateInputBlocker()
  1448     {
  1484 {
  1449         this->grabMouse();
  1485     this->grabMouse();
  1450         this->grabKeyboard();
  1486     this->grabKeyboard();
  1451     }
  1487 }
  1452 
  1488 
  1453 //---------------------------------------------------------------
  1489 //---------------------------------------------------------------
  1454 // MsgUnifiedEditorView::deactivateInputBlocker
  1490 // MsgUnifiedEditorView::deactivateInputBlocker
  1455 // @see header file
  1491 // @see header file
  1456 //--------------------------------------------------------------
  1492 //--------------------------------------------------------------
  1457 void MsgUnifiedEditorView::deactivateInputBlocker()
  1493 void MsgUnifiedEditorView::deactivateInputBlocker()
  1458     {    
  1494 {    
  1459         this->ungrabKeyboard();
  1495     this->ungrabKeyboard();
  1460         this->ungrabMouse();
  1496     this->ungrabMouse();
  1461     }
  1497 }
       
  1498 
       
  1499 //---------------------------------------------------------------
       
  1500 // MsgUnifiedEditorView::setAttachOptionEnabled
       
  1501 // @see header file
       
  1502 //--------------------------------------------------------------
       
  1503 void MsgUnifiedEditorView::setAttachOptionEnabled(
       
  1504         MsgUnifiedEditorView::TBE_AttachOption opt, bool enable)
       
  1505 {
       
  1506     HbListWidgetItem* wgtItem = mTBExtnContentWidget->item(opt);
       
  1507     wgtItem->setEnabled(enable);
       
  1508 }
       
  1509 
       
  1510 //---------------------------------------------------------------
       
  1511 // MsgUnifiedEditorView::vkbOpened
       
  1512 // @see header file
       
  1513 //---------------------------------------------------------------
       
  1514 void MsgUnifiedEditorView::vkbOpened()
       
  1515 {
       
  1516     hideChrome(true); 
       
  1517     
       
  1518     disconnect(mVkbHost,SIGNAL(keypadOpened()),this,SLOT(vkbOpened()));
       
  1519 }
       
  1520       
       
  1521 //---------------------------------------------------------------
       
  1522 // MsgUnifiedEditorView::vkbClosed
       
  1523 // @see header file
       
  1524 //---------------------------------------------------------------
       
  1525 void MsgUnifiedEditorView::vkbClosed()
       
  1526 {
       
  1527     hideChrome(false);
       
  1528     
       
  1529     connect(mVkbHost,SIGNAL(keypadOpened()),this,SLOT(vkbOpened()));
       
  1530 }
       
  1531 
       
  1532 //---------------------------------------------------------------
       
  1533 // MsgUnifiedEditorView::hideChrome
       
  1534 //
       
  1535 //---------------------------------------------------------------
       
  1536 void MsgUnifiedEditorView::hideChrome(bool hide)
       
  1537 {
       
  1538     if(hide)
       
  1539     {        
       
  1540         this->setContentFullScreen(true);
       
  1541         this->hideItems(Hb::StatusBarItem | Hb::TitleBarItem);
       
  1542     }
       
  1543     else
       
  1544     {
       
  1545         this->setContentFullScreen(false);
       
  1546         this->showItems(Hb::StatusBarItem | Hb::TitleBarItem);
       
  1547     }
       
  1548 }
       
  1549 
       
  1550 //---------------------------------------------------------------
       
  1551 // MsgUnifiedEditorView::doDelayedConstruction
       
  1552 //
       
  1553 //---------------------------------------------------------------
       
  1554 void MsgUnifiedEditorView::doDelayedConstruction()
       
  1555 {
       
  1556     addMenu();
       
  1557     createTempFolder();
       
  1558     
       
  1559     //Create VKB instance and listen to VKB open and close signals.
       
  1560     mVkbHost = new HbAbstractVkbHost(this);
       
  1561     connect(mVkbHost, SIGNAL(keypadOpened()), this, SLOT(vkbOpened()));
       
  1562     connect(mVkbHost, SIGNAL(keypadClosed()), this, SLOT(vkbClosed()));
       
  1563     
       
  1564     disconnect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(doDelayedConstruction()));
       
  1565     
       
  1566 }
       
  1567 
       
  1568 //---------------------------------------------------------------
       
  1569 // MsgUnifiedEditorView::createTempFolder
       
  1570 //
       
  1571 //---------------------------------------------------------------
       
  1572 bool MsgUnifiedEditorView::createTempFolder()
       
  1573 {
       
  1574     // create editor's temp folder
       
  1575     QDir tempDir;
       
  1576     QString tempPath(editorTempPath());
       
  1577     bool result = tempDir.mkpath(tempPath);    
       
  1578     return result;
       
  1579 }
       
  1580 
       
  1581 //---------------------------------------------------------------
       
  1582 // MsgUnifiedEditorView::removeTempFolder
       
  1583 //
       
  1584 //---------------------------------------------------------------
       
  1585 void MsgUnifiedEditorView::removeTempFolder()
       
  1586 {
       
  1587     QDir tempDir;
       
  1588     QString tempPath(editorTempPath());
       
  1589     tempDir.cd(tempPath);
       
  1590     QStringList contentList(tempDir.entryList());
       
  1591     
       
  1592     int contentCount = contentList.count();
       
  1593     for(int i=0; i<contentCount; i++)
       
  1594     {
       
  1595         tempDir.remove(contentList.at(i));
       
  1596     }
       
  1597     
       
  1598     tempDir.cdUp();
       
  1599     tempDir.rmdir(UNIFIED_EDITOR_TEMP_FOLDER); 
       
  1600 }
       
  1601 
       
  1602 //---------------------------------------------------------------
       
  1603 // MsgUnifiedEditorView::setFocus
       
  1604 //
       
  1605 //---------------------------------------------------------------
       
  1606 void MsgUnifiedEditorView::setFocus(MsgUnifiedEditorBaseWidget* item)
       
  1607 {
       
  1608     if(item)
       
  1609     {
       
  1610         item->setFocus();  
       
  1611     }
       
  1612 }
       
  1613 
       
  1614 //---------------------------------------------------------------
       
  1615 // MsgUnifiedEditorView::onContentChanged
       
  1616 //
       
  1617 //---------------------------------------------------------------
       
  1618 void MsgUnifiedEditorView::onContentChanged()
       
  1619 {
       
  1620     mCanSaveToDrafts = true; 
       
  1621 }
       
  1622 
       
  1623 //---------------------------------------------------------------
       
  1624 // MsgUnifiedEditorView::onDialogDeleteMsg
       
  1625 //---------------------------------------------------------------
       
  1626 void MsgUnifiedEditorView::onDialogDeleteMsg(HbAction* action)
       
  1627 {
       
  1628     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
       
  1629     if (action == dlg->actions().at(0)) {
       
  1630 
       
  1631         mCanSaveToDrafts = false;
       
  1632 
       
  1633         //delete if draft entry opened
       
  1634         if (mOpenedMessageId.getId() != -1) {
       
  1635             if (!mPluginLoader) {
       
  1636                 mPluginLoader = new UniEditorPluginLoader(this);
       
  1637             }
       
  1638 
       
  1639             UniEditorPluginInterface* pluginInterface = mPluginLoader->getUniEditorPlugin(
       
  1640                 MsgMonitor::messageType());
       
  1641 
       
  1642             pluginInterface->deleteDraftsEntry(mOpenedMessageId.getId());
       
  1643         }
       
  1644 
       
  1645         //trigger back action.
       
  1646         HbAction* backAction = this->navigationAction();
       
  1647         if (backAction) {
       
  1648             backAction->trigger();
       
  1649         }
       
  1650 
       
  1651     }
       
  1652 }
       
  1653 
       
  1654 //---------------------------------------------------------------
       
  1655 // MsgUnifiedEditorView::onDialogSmsSettings
       
  1656 //---------------------------------------------------------------
       
  1657 void MsgUnifiedEditorView::onDialogSmsSettings(HbAction* action)
       
  1658 {
       
  1659     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
       
  1660     if (action == dlg->actions().at(0)) {
       
  1661         
       
  1662         QVariantList params;
       
  1663         params << MsgBaseView::MSGSETTINGS;// target view
       
  1664         params << MsgBaseView::UNIEDITOR; // source view
       
  1665         params << MsgSettingsView::SMSView;
       
  1666         emit switchView(params);
       
  1667     
       
  1668     }
       
  1669 }
       
  1670 
       
  1671 //---------------------------------------------------------------
       
  1672 // MsgUnifiedEditorView::onDialogMmsSettings
       
  1673 //---------------------------------------------------------------
       
  1674 void MsgUnifiedEditorView::onDialogMmsSettings(HbAction* action)
       
  1675 {
       
  1676     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
       
  1677     if (action == dlg->actions().at(0)) {
       
  1678         
       
  1679         QVariantList params;
       
  1680         params << MsgBaseView::MSGSETTINGS;// target view
       
  1681         params << MsgBaseView::UNIEDITOR; // source view
       
  1682         params << MsgSettingsView::MMSView;
       
  1683         emit switchView(params); 
       
  1684     }
       
  1685 }
  1462 
  1686 
  1463 //EOF
  1687 //EOF