messagingapp/msgui/unifiededitor/src/msgunieditorview.cpp
changeset 76 60a8a215b0ec
parent 73 ecf6a73a9186
equal deleted inserted replaced
73:ecf6a73a9186 76:60a8a215b0ec
    17 
    17 
    18 // SYSTEM INCLUDES
    18 // SYSTEM INCLUDES
    19 #include <e32base.h>
    19 #include <e32base.h>
    20 #include <HbMenu>
    20 #include <HbMenu>
    21 #include <HbAction>
    21 #include <HbAction>
    22 #include <HbToolBar>
       
    23 #include <QGraphicsLinearLayout>
    22 #include <QGraphicsLinearLayout>
    24 #include <HbGroupBox>
       
    25 #include <HbScrollArea>
       
    26 #include <QDateTime>
    23 #include <QDateTime>
    27 #include <QDir>
    24 #include <QDir>
    28 #include <QBuffer>
    25 #include <QBuffer>
    29 #include <QFile>
    26 #include <QFile>
    30 #include <QFileInfo>
    27 #include <QFileInfo>
       
    28 #include <QApplication>
    31 #include <xqconversions.h>
    29 #include <xqconversions.h>
    32 #include <HbToolBarExtension>
       
    33 #include <HbListWidget>
       
    34 #include <HbFrameBackground>
       
    35 #include <HbListViewItem>
       
    36 #include <HbListWidgetItem>
       
    37 #include <HbNotificationDialog>
    30 #include <HbNotificationDialog>
    38 #include <HbDeviceNotificationDialog>
    31 #include <HbDeviceNotificationDialog>
    39 #include <HbMessageBox>
    32 #include <HbMessageBox>
    40 #include <HbAbstractVkbHost>
       
    41 #include <HbMainWindow>
    33 #include <HbMainWindow>
    42 #include <xqaiwrequest.h>
    34 #include <xqaiwrequest.h>
    43 #include <xqappmgr.h>
    35 #include <xqappmgr.h>
    44 #include <HbStyleLoader>
    36 #include <HbStyleLoader>
       
    37 #include<HbInputMethod>
       
    38 #include <QTimer>
       
    39 #include<QInputContext>
       
    40 
    45 // QT Mobility for fetching business card
    41 // QT Mobility for fetching business card
    46 #include <qmobilityglobal.h>
    42 #include <qmobilityglobal.h>
    47 #include <qversitwriter.h>
    43 #include <qversitwriter.h>
    48 #include <qversitdocument.h>
    44 #include <qversitdocument.h>
    49 #include <qcontact.h>
    45 #include <qcontact.h>
    53 #include <commonphoneparser.h>      // Common phone number validity checker
    49 #include <commonphoneparser.h>      // Common phone number validity checker
    54 
    50 
    55 // USER INCLUDES
    51 // USER INCLUDES
    56 #include "debugtraces.h"
    52 #include "debugtraces.h"
    57 #include "msgunieditorview.h"
    53 #include "msgunieditorview.h"
    58 #include "msgunieditoraddress.h"
       
    59 #include "msgunieditorsubject.h"
       
    60 #include "msgunieditorbody.h"
       
    61 #include "msgunieditormonitor.h"
    54 #include "msgunieditormonitor.h"
    62 #include "msgunieditorattachmentcontainer.h"
       
    63 #include "msgsendutil.h"
    55 #include "msgsendutil.h"
    64 #include "convergedmessageaddress.h"
    56 #include "convergedmessageaddress.h"
    65 #include "UniEditorGenUtils.h"
    57 #include "UniEditorGenUtils.h"
    66 #include "unieditorpluginloader.h"
    58 #include "unieditorpluginloader.h"
    67 #include "unieditorplugininterface.h"
    59 #include "unieditorplugininterface.h"
    68 #include "msgsettingsview.h"
    60 #include "msgsettingsview.h"
    69 #include "msgcontacthandler.h"
    61 #include "msgcontacthandler.h"
    70 #include "msgaudiofetcherdialog.h"
    62 #include "msgaudiofetcherdialog.h"
       
    63 #include "msgunieditorscrollarea.h"
       
    64 #include "msgunieditorbodyeditor.h"
    71 
    65 
    72 QTM_USE_NAMESPACE
    66 QTM_USE_NAMESPACE
    73 // Constants
    67 // Constants
    74 const QString SEND_ICON("qtg_mono_send");
    68 
    75 const QString ATTACH_ICON("qtg_mono_attach");
       
    76 // temporary folder for unieditor
    69 // temporary folder for unieditor
    77 const QString UNIFIED_EDITOR_TEMP_FOLDER("unifiededitor");
    70 const QString UNIFIED_EDITOR_TEMP_FOLDER("unifiededitor");
    78 // invalid chars in vcard
    71 // invalid chars in vcard
    79 const QString INVALID_FILENAME_CHARS("[?*<>/\"|\\:]");
    72 const QString INVALID_FILENAME_CHARS("[?*<>/\"|\\:]");
    80 // replacement char for invalid char
    73 // replacement char for invalid char
    87 // TODO: how we can avoid this?
    80 // TODO: how we can avoid this?
    88 const int MAX_VCARDS(1000);
    81 const int MAX_VCARDS(1000);
    89 
    82 
    90 // LOCALIZED CONSTANTS
    83 // LOCALIZED CONSTANTS
    91 #define LOC_TITLE hbTrId("txt_messaging_title_messaging")
    84 #define LOC_TITLE hbTrId("txt_messaging_title_messaging")
    92 //To,Cc.Bcc
       
    93 #define LOC_TO  hbTrId("txt_messaging_formlabel_to")
       
    94 #define LOC_CC hbTrId("txt_messaging_formlabel_cc")
       
    95 #define LOC_BCC hbTrId("txt_messaging_formlabel_bcc")
       
    96 
    85 
    97 //attach options
    86 //attach options
    98 #define LOC_PHOTO           hbTrId("txt_messaging_opt_attach_sub_photo")
    87 #define LOC_PHOTO           hbTrId("txt_messaging_opt_attach_sub_photo")
    99 #define LOC_SOUND           hbTrId("txt_messaging_opt_attach_sub_sound")
    88 #define LOC_SOUND           hbTrId("txt_messaging_opt_attach_sub_sound")
   100 #define LOC_BUSINESS_CARD   hbTrId("txt_messaging_opt_sub_business_card")
    89 #define LOC_BUSINESS_CARD   hbTrId("txt_messaging_opt_sub_business_card")
   101 
    90 
   102 //options menu.
    91 ////options menu.
       
    92 #define LOC_ATTACH          hbTrId("txt_messaging_opt_attach")
   103 #define LOC_ADD_SUBJECT     hbTrId("txt_messaging_opt_add_subject")
    93 #define LOC_ADD_SUBJECT     hbTrId("txt_messaging_opt_add_subject")
   104 #define LOC_ADD_CC_BCC      hbTrId("txt_messaging_opt_add_cc_bcc")
    94 #define LOC_ADD_CC_BCC      hbTrId("txt_messaging_opt_add_cc_bcc")
   105 #define LOC_PRIORITY        hbTrId("txt_messaging_opt_priority")
    95 #define LOC_PRIORITY        hbTrId("txt_messaging_opt_priority")
   106 #define LOC_DELETE_MESSAGE  hbTrId("txt_messaging_opt_delete_message")
    96 #define LOC_DELETE_MESSAGE  hbTrId("txt_messaging_opt_delete_message")
   107 
    97 
   108 //priority sub menu
    98 //priority sub menu
   109 #define LOC_HIGH hbTrId("txt_messaging_opt_attach_sub_high")
    99 #define LOC_HIGH hbTrId("txt_messaging_opt_attach_sub_high")
   110 #define LOC_NORMAL hbTrId("txt_messaging_opt_attach_sub_normal")
   100 #define LOC_NORMAL hbTrId("txt_messaging_opt_attach_sub_normal")
   111 #define LOC_LOW hbTrId("txt_messaging_opt_attach_sub_low")
   101 #define LOC_LOW hbTrId("txt_messaging_opt_attach_sub_low")
   112 
   102 
   113 //group box
       
   114 #define LOC_OTHER_RECIPIENTS(n) hbTrId("txt_messaging_title_ln_other_recipients",n)
       
   115 #define LOC_OTHER_RECIPIENTS_EXPAND hbTrId("txt_messaging_title_other_recipients")
       
   116 
       
   117 //saved to draft note
   103 //saved to draft note
   118 #define LOC_SAVED_TO_DRAFTS    hbTrId("txt_messaging_dpopinfo_saved_to_drafts")
   104 #define LOC_SAVED_TO_DRAFTS    hbTrId("txt_messaging_dpopinfo_saved_to_drafts")
   119 
   105 
   120 //delete confermation
   106 //delete confermation
   121 #define LOC_NOTE_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message")
   107 #define LOC_NOTE_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message")
   122 
   108 
   123 // attachment addition failure note
       
   124 #define LOC_UNABLE_TO_ADD_ATTACHMENTS hbTrId("txt_messaging_dpopinfo_unable_to_attach_l1_of_l2")
       
   125 
       
   126 //extension list item frame.
       
   127 const QString POPUP_LIST_FRAME("qtg_fr_popup_list_normal");
       
   128 
   109 
   129 //settings confirmation
   110 //settings confirmation
   130 #define LOC_DIALOG_SMS_SETTINGS_INCOMPLETE hbTrId("txt_messaging_dialog_sms_message_centre_does_not_e")
   111 #define LOC_DIALOG_SMS_SETTINGS_INCOMPLETE hbTrId("txt_messaging_dialog_sms_message_centre_does_not_e")
   131 #define LOC_DIALOG_MMS_SETTINGS_INCOMPLETE hbTrId("txt_messaging_dialog_mms_access_point_not_defined")
   112 #define LOC_DIALOG_MMS_SETTINGS_INCOMPLETE hbTrId("txt_messaging_dialog_mms_access_point_not_defined")
   132 #define LOC_NOTE_FILES_MISSED_DRAFTS hbTrId("txt_messaging_dpopinfo_some_files_in_the_message")
   113 #define LOC_NOTE_FILES_MISSED_DRAFTS hbTrId("txt_messaging_dpopinfo_some_files_in_the_message")
   151 // MsgUnifiedEditorView::MsgUnifiedEditorView
   132 // MsgUnifiedEditorView::MsgUnifiedEditorView
   152 // @see header file
   133 // @see header file
   153 //---------------------------------------------------------------
   134 //---------------------------------------------------------------
   154 MsgUnifiedEditorView::MsgUnifiedEditorView( QGraphicsItem *parent ) :
   135 MsgUnifiedEditorView::MsgUnifiedEditorView( QGraphicsItem *parent ) :
   155     MsgBaseView(parent),
   136     MsgBaseView(parent),
   156     mSubjectAction(0),
       
   157     mCcBccAction(0),
       
   158     mSendAction(0),
       
   159     mMainLayout(0),
   137     mMainLayout(0),
   160     mSubjectField(0),
       
   161     mToField(0),
       
   162     mCcField(0),
       
   163     mBccField(0),
       
   164     mBody(0),
       
   165     mContentWidget(0),
       
   166     mMsgMonitor(0),    
   138     mMsgMonitor(0),    
   167     mAttachmentContainer(0),
       
   168     mPluginLoader(0),
   139     mPluginLoader(0),
   169     mCanSaveToDrafts(true),
   140     mCanSaveToDrafts(true),
   170     mVkbHost(NULL),
   141     mVkbHost(NULL),
   171 	mDialog(NULL),
   142 	mDialog(NULL),
   172     mOriginatingSC(0),
   143     mOriginatingSC(0),
   173     mOriginatingSME(0),
   144     mOriginatingSME(0),
   174     mReplyPath(false)
   145     mReplyPath(false),
   175     {
   146     mSubjectAction(0),
   176     connect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(doDelayedConstruction()));
   147     mCcBccAction(0),
   177     
   148     mPhotoAction(0),
   178     addToolBar();
   149     mSoundAction(0),
       
   150     mFocusedWidget(0),
       
   151     mMinHeight(0.0),
       
   152     mMaxHeight(0.0)
       
   153     {    
       
   154     connect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(doDelayedConstruction()));    
   179     initView();
   155     initView();
       
   156     addMenu();    
   180     }
   157     }
   181 
   158 
   182 //---------------------------------------------------------------
   159 //---------------------------------------------------------------
   183 // MsgUnifiedEditorView::~MsgUnifiedEditorView
   160 // MsgUnifiedEditorView::~MsgUnifiedEditorView
   184 // @see header file
   161 // @see header file
   199 void MsgUnifiedEditorView::initView()
   176 void MsgUnifiedEditorView::initView()
   200 {
   177 {
   201     if (!HbStyleLoader::registerFilePath(":/layouts")) {
   178     if (!HbStyleLoader::registerFilePath(":/layouts")) {
   202         QDEBUG_WRITE("ERROR: MsgUnifiedEditorView -> HbStyleLoader::registerFilePath");
   179         QDEBUG_WRITE("ERROR: MsgUnifiedEditorView -> HbStyleLoader::registerFilePath");
   203     }
   180     }
   204     HbScrollArea* scrollArea = new HbScrollArea(this);
   181 
   205     this->setWidget(scrollArea);
   182     //message monitor.
   206 
   183     mMsgMonitor = new MsgUnifiedEditorMonitor(this);
   207     mContentWidget = new HbWidget(this);
   184     
   208     scrollArea->setContentWidget(mContentWidget);
   185     //Set the invalid msg id
   209 
   186     mOpenedMessageId.setId(-1);
   210     mMainLayout = new QGraphicsLinearLayout(Qt::Vertical, mContentWidget);
   187 
       
   188     mMainLayout = new QGraphicsLinearLayout(Qt::Vertical, this);
   211     qreal vTopSpacing = 0.0;
   189     qreal vTopSpacing = 0.0;
   212     qreal vItemSpacing = 0.0;
   190     qreal vItemSpacing = 0.0;
   213     style()->parameter("hb-param-margin-gene-top",vTopSpacing);    
   191     style()->parameter("hb-param-margin-gene-top",vTopSpacing);    
   214     style()->parameter("hb-param-margin-gene-middle-vertical",vItemSpacing);
   192     style()->parameter("hb-param-margin-gene-middle-vertical",vItemSpacing);    
   215     
       
   216     mMainLayout->setContentsMargins(0,vTopSpacing,0,0);
   193     mMainLayout->setContentsMargins(0,vTopSpacing,0,0);
   217     mMainLayout->setSpacing(vItemSpacing);
   194     mMainLayout->setSpacing(vItemSpacing); 
   218 
   195     
   219     mMsgMonitor = new MsgUnifiedEditorMonitor(this);
   196     mScrollArea = new MsgUnifiedEditorScrollArea(mMsgMonitor,this);
   220     connect(mMsgMonitor, SIGNAL(enableSend(bool)), this, SLOT(enableSendButton(bool)));
   197     mMainLayout->addItem(mScrollArea); 
   221 
   198     
   222     mToField = new MsgUnifiedEditorAddress( LOC_TO, mContentWidget );
   199     mBodyEditor = new MsgUnifiedEditorBodyEditor(this);
   223     
   200     
   224     mBody = new MsgUnifiedEditorBody( mContentWidget);
   201     connect(mScrollArea,SIGNAL(enableMenuAction(int,bool)),this,SLOT(enableMenuAction(int,bool)));
   225 
   202     
   226     mMainLayout->addItem(mToField);
   203     connect(mBodyEditor, SIGNAL(contentsChanged(const QVariant&)),
   227     mMainLayout->addItem(mBody);
   204             mMsgMonitor,SLOT(handleContentsChanged(const QVariant&)));
   228  
   205     
   229     //Set the invalid msg id
   206     connect(mMsgMonitor,SIGNAL(enableSend(bool)),
   230     mOpenedMessageId.setId(-1);
   207             mBodyEditor,SLOT(enableSendButton(bool)));
   231 
   208     
   232     connect(mToField, SIGNAL(sendMessage()), this, SLOT(send()));
   209     connect(mBodyEditor,SIGNAL(sendMessage()),this,SLOT(send()));
   233     connect(mToField, SIGNAL(contentChanged()),
   210     
   234             mMsgMonitor, SLOT(handleContentChange()));
   211     connect(mMsgMonitor,SIGNAL(contentsChanged()),this,SLOT(onContentChanged()));
   235     connect(mToField, SIGNAL(contentChanged()),this,SLOT(onContentChanged()));
   212     
   236     
   213     mMainLayout->addItem(mBodyEditor);
   237     connect(mBody, SIGNAL(sendMessage()), this, SLOT(send()));
   214     
   238     connect(mBody, SIGNAL(contentChanged()),this,SLOT(onContentChanged()));
   215 }
   239     connect(mBody, SIGNAL(contentChanged()),
   216 
   240             mMsgMonitor, SLOT(handleContentChange()));
   217 //---------------------------------------------------------------
   241     connect(mBody, SIGNAL(enableSendButton(bool)), this, SLOT(enableSendButton(bool)));    
   218 // MsgUnifiedEditorView::addMenu
   242     
   219 // @see header file
   243 }
   220 //---------------------------------------------------------------
   244 
       
   245 void MsgUnifiedEditorView::addMenu()
   221 void MsgUnifiedEditorView::addMenu()
   246 {
   222 {
   247     //Create Menu Options
   223     //Create Menu Options
   248     HbMenu* mainMenu = this->menu();
   224     HbMenu* mainMenu = this->menu();
   249     mainMenu->setFocusPolicy(Qt::NoFocus);
   225     mainMenu->setFocusPolicy(Qt::NoFocus); 
   250 	
   226     
   251     //if subject field / cc,bcc fields are already present don't add corresponding actions.
   227     //attach sub menu
   252     if(!mSubjectField)
   228     HbMenu* attachMenu = mainMenu->addMenu(LOC_ATTACH);
   253     {
   229     mPhotoAction = attachMenu->addAction(LOC_PHOTO,this,SLOT(fetchImages()));
   254         mSubjectAction = mainMenu->addAction(LOC_ADD_SUBJECT);
   230     mSoundAction = attachMenu->addAction(LOC_SOUND,this,SLOT(fetchAudio()));
   255     }
   231     attachMenu->addAction(LOC_BUSINESS_CARD,this,SLOT(fetchContacts()));
   256     
   232     
   257     if(!mCcField)
   233     //subject action
   258     {
   234     mSubjectAction = mainMenu->addAction(LOC_ADD_SUBJECT);
   259         mCcBccAction = mainMenu->addAction(LOC_ADD_CC_BCC);
   235     //CcBcc action
   260     }
   236     mCcBccAction = mainMenu->addAction(LOC_ADD_CC_BCC);
   261     
   237     connect(mSubjectAction,SIGNAL(triggered()),this, SLOT(addSubject()));
       
   238     connect(mCcBccAction,SIGNAL(triggered()),this, SLOT(addCcBcc()));
       
   239     
       
   240     //priority sub menu
   262     HbMenu* prioritySubMenu = mainMenu->addMenu(LOC_PRIORITY);
   241     HbMenu* prioritySubMenu = mainMenu->addMenu(LOC_PRIORITY);
   263 
   242 
   264     HbAction* highPriorityAction = prioritySubMenu->addAction(LOC_HIGH);
   243     HbAction* highPriorityAction = prioritySubMenu->addAction(LOC_HIGH);
   265     highPriorityAction->setData(ConvergedMessage::High);
   244     highPriorityAction->setData(ConvergedMessage::High);
   266 
   245 
   267     HbAction* normalPriorityAction = prioritySubMenu->addAction(LOC_NORMAL);
   246     HbAction* normalPriorityAction = prioritySubMenu->addAction(LOC_NORMAL);
   268     normalPriorityAction->setData(ConvergedMessage::Normal);
   247     normalPriorityAction->setData(ConvergedMessage::Normal);
   269 
   248 
   270     HbAction* lowPriorityAction = prioritySubMenu->addAction(LOC_LOW);
   249     HbAction* lowPriorityAction = prioritySubMenu->addAction(LOC_LOW);
   271     lowPriorityAction->setData(ConvergedMessage::Low);
   250     lowPriorityAction->setData(ConvergedMessage::Low);    
   272 
   251 
       
   252     connect(highPriorityAction, SIGNAL(triggered()), mScrollArea, SLOT(changePriority()));
       
   253     connect(normalPriorityAction, SIGNAL(triggered()), mScrollArea, SLOT(changePriority()));
       
   254     connect(lowPriorityAction, SIGNAL(triggered()), mScrollArea, SLOT(changePriority()));
       
   255     
       
   256 	
   273     HbAction* deleteMsgAction = mainMenu->addAction(LOC_DELETE_MESSAGE);
   257     HbAction* deleteMsgAction = mainMenu->addAction(LOC_DELETE_MESSAGE);
   274 
       
   275     connect(mSubjectAction,SIGNAL(triggered()),this, SLOT(addSubject()));
       
   276     connect(mCcBccAction,SIGNAL(triggered()),this, SLOT(addCcBcc()));
       
   277     connect(highPriorityAction, SIGNAL(triggered()), this, SLOT(changePriority()));
       
   278     connect(normalPriorityAction, SIGNAL(triggered()), this, SLOT(changePriority()));
       
   279     connect(lowPriorityAction, SIGNAL(triggered()), this, SLOT(changePriority()));
       
   280     connect(deleteMsgAction,SIGNAL(triggered()),this, SLOT(deleteMessage()));
   258     connect(deleteMsgAction,SIGNAL(triggered()),this, SLOT(deleteMessage()));
   281 
   259 
   282 }
   260 }
   283 
   261 
       
   262 //---------------------------------------------------------------
       
   263 // MsgUnifiedEditorView::openDraftsMessage
       
   264 // @see header file
       
   265 //---------------------------------------------------------------
   284 void MsgUnifiedEditorView::openDraftsMessage(const QVariantList& editorData)
   266 void MsgUnifiedEditorView::openDraftsMessage(const QVariantList& editorData)
   285 {
   267 {
   286     // unpack editor's data
   268     // unpack editor's data
   287     // first arg is convergedmessage
   269     // first arg is convergedmessage
   288     QByteArray dataArray = editorData.at(0).toByteArray();
   270     QByteArray dataArray = editorData.at(0).toByteArray();
   300 
   282 
   301     UniEditorPluginInterface* pluginInterface =
   283     UniEditorPluginInterface* pluginInterface =
   302         mPluginLoader->getUniEditorPlugin(messageType);
   284         mPluginLoader->getUniEditorPlugin(messageType);
   303 
   285 
   304     mOpenedMessageId.setId(messageId.getId());
   286     mOpenedMessageId.setId(messageId.getId());
   305     mmOpenedMessageType = messageType;
       
   306 
   287 
   307     //Fetch the converged message from the msgId
   288     //Fetch the converged message from the msgId
   308     ConvergedMessage* msg;
   289     ConvergedMessage* msg = pluginInterface->convertFrom(messageId.getId());
   309     msg = pluginInterface->convertFrom(messageId.getId());
       
   310 
   290 
   311     if( msg != NULL )
   291     if( msg != NULL )
   312     {
   292     {
   313         mReplyPath = msg->replyPath();
   293         mReplyPath = msg->replyPath();
   314         if(mReplyPath)
   294         if(mReplyPath)
   315         {
   295         {
   316             mOriginatingSC = msg->originatingSC();
   296             mOriginatingSC = msg->originatingSC();
   317             mOriginatingSME = msg->toAddressList().at(0)->address();
   297             mOriginatingSME = msg->toAddressList().at(0)->address();
   318         }
   298         }
   319         //Populate the content inside editor
   299         //Populate the content inside editor
   320         populateContentIntoEditor(*msg,true); // true as it is  draft message
   300         populateContentIntoEditor(*msg,true,true); // true as it is  draft message
   321         delete msg;
   301         delete msg;
   322     }
   302     }
   323     
   303     
   324     mCanSaveToDrafts = false;  
   304     mCanSaveToDrafts = false;  
   325 }
   305 }
   326 
   306 
   327 void MsgUnifiedEditorView::fetchMessageFromStore(
   307 //---------------------------------------------------------------
   328         ConvergedMessageId& messageId,
   308 // MsgUnifiedEditorView::fetchMessageFromStore
   329         ConvergedMessage::MessageType messageType,
   309 // @see header file
   330         int editorOperation)
   310 //---------------------------------------------------------------
       
   311 void MsgUnifiedEditorView::fetchMessageFromStore(ConvergedMessageId& messageId,
       
   312     ConvergedMessage::MessageType messageType, int editorOperation)
   331 {
   313 {
   332     if(!mPluginLoader)
   314     if(!mPluginLoader)
   333     {
   315     {
   334         mPluginLoader = new UniEditorPluginLoader(this);
   316         mPluginLoader = new UniEditorPluginLoader(this);
   335     }
   317     }
   336     UniEditorPluginInterface* pluginInterface = NULL;
   318     UniEditorPluginInterface* pluginInterface = NULL;
   337     if( messageType == ConvergedMessage::Mms )
   319     if( messageType == ConvergedMessage::Mms )
   338     {
   320     {
   339         pluginInterface =
   321         pluginInterface = mPluginLoader->getUniEditorPlugin(ConvergedMessage::Mms);
   340                 mPluginLoader->getUniEditorPlugin(ConvergedMessage::Mms);
       
   341     }
   322     }
   342     else // For sms,vcard,vcal cases
   323     else // For sms,vcard,vcal cases
   343     {
   324     {
   344         pluginInterface =
   325         pluginInterface = mPluginLoader->getUniEditorPlugin(ConvergedMessage::Sms);
   345                 mPluginLoader->getUniEditorPlugin(ConvergedMessage::Sms);
       
   346     }
   326     }
   347 
   327 
   348     //Fetch the converged message from the msgId
   328     //Fetch the converged message from the msgId
   349     ConvergedMessage* msg;
   329     ConvergedMessage* msg;
   350     msg = pluginInterface->convertFrom(messageId.getId(),
   330     msg = pluginInterface->convertFrom(messageId.getId(),
   359                 mOriginatingSC = msg->originatingSC();
   339                 mOriginatingSC = msg->originatingSC();
   360                 mOriginatingSME = msg->toAddressList().at(0)->address();
   340                 mOriginatingSME = msg->toAddressList().at(0)->address();
   361             }
   341             }
   362         }
   342         }
   363         //Populate the content inside editor
   343         //Populate the content inside editor
   364         populateContentIntoEditor(*msg);
   344         populateContentIntoEditor(*msg,false,true);
   365         delete msg;
   345         delete msg;
   366     }
   346     }
   367 }
   347 }
   368 
   348 
       
   349 //---------------------------------------------------------------
       
   350 // MsgUnifiedEditorView::populateContent
       
   351 // @see header file
       
   352 //---------------------------------------------------------------
   369 void MsgUnifiedEditorView::populateContent(const QVariantList& editorData)
   353 void MsgUnifiedEditorView::populateContent(const QVariantList& editorData)
   370 {
   354 {
   371     // unpack editor's data
   355     // unpack editor's data
   372     // first arg is convergedmessage
   356     // first arg is convergedmessage
   373     QByteArray dataArray = editorData.at(0).toByteArray();
   357     QByteArray dataArray = editorData.at(0).toByteArray();
   385     // population logic based on editor Operation command
   369     // population logic based on editor Operation command
   386     switch(editorOp)
   370     switch(editorOp)
   387     {
   371     {
   388         case MsgBaseView::ADD_SUBJECT:
   372         case MsgBaseView::ADD_SUBJECT:
   389         {
   373         {
   390             addSubject();
   374             //setfocus also.
   391             setFocus(mSubjectField);
   375             addSubject(true);
   392         }
   376         }
   393         break;
   377         break;
   394         case MsgBaseView::ADD_VCARD:
   378         case MsgBaseView::ADD_VCARD:
   395         {
   379         {
   396             contactsFetched(editorData.at(2));
   380             contactsFetched(editorData.at(2));
   399         case MsgBaseView::FORWARD_MSG:
   383         case MsgBaseView::FORWARD_MSG:
   400         {
   384         {
   401             fetchMessageFromStore(*messageDetails->id(),
   385             fetchMessageFromStore(*messageDetails->id(),
   402                                    messageDetails->messageType(),
   386                                    messageDetails->messageType(),
   403                                    UniEditorPluginInterface::Forward);
   387                                    UniEditorPluginInterface::Forward);
   404         }
   388             return;
   405         break;
   389         }
   406         case MsgBaseView::REPLY_MSG:
   390         case MsgBaseView::REPLY_MSG:
   407         {
   391         {
   408             fetchMessageFromStore(*messageDetails->id(),
   392             fetchMessageFromStore(*messageDetails->id(),
   409                                    messageDetails->messageType(),
   393                                    messageDetails->messageType(),
   410                                    UniEditorPluginInterface::Reply);
   394                                    UniEditorPluginInterface::Reply);
   411         }
   395             return;
   412         break;
   396         }
   413         case MsgBaseView::REPLY_ALL_MSG:
   397         case MsgBaseView::REPLY_ALL_MSG:
   414         {
   398         {
   415             fetchMessageFromStore(*messageDetails->id(),
   399             fetchMessageFromStore(*messageDetails->id(),
   416                                    messageDetails->messageType(),
   400                                    messageDetails->messageType(),
   417                                    UniEditorPluginInterface::ReplyAll);
   401                                    UniEditorPluginInterface::ReplyAll);
   418         }
   402             return;
   419         break;
   403         }
   420         default:
   404         default:
   421         break;
   405         break;
   422     }
   406     }
   423 
   407 
   424     // additional common operations for non-forwarded messages
   408     populateContentIntoEditor(*messageDetails,false,false);
   425     if(editorOp != MsgBaseView::FORWARD_MSG)
   409 
   426     {
       
   427         if(editorOp == MsgBaseView::ADD_RECIPIENTS)
       
   428         {
       
   429             // CV sends contact card address as the first address
       
   430             ConvergedMessageAddressList toAddresses = 
       
   431                     messageDetails->toAddressList();
       
   432             int addrCount = toAddresses.count();
       
   433             if(addrCount > 0)
       
   434             {
       
   435                 // add contact card address first
       
   436                 ConvergedMessageAddress *firstAddress =
       
   437                         new ConvergedMessageAddress();
       
   438                 firstAddress->setAlias(toAddresses.at(0)->alias());
       
   439                 firstAddress->setAddress(toAddresses.at(0)->address());
       
   440                 ConvergedMessageAddressList firstList;
       
   441                 firstList << firstAddress;
       
   442                 mToField->setAddresses(firstList);
       
   443             
       
   444                 // add remaining contacts now
       
   445                 ConvergedMessageAddressList otherList;
       
   446                 for(int i=1; i<addrCount; i++)
       
   447                 {
       
   448                     otherList << toAddresses.at(i);
       
   449                 }
       
   450                 mToField->setAddresses(otherList);
       
   451             }
       
   452         }
       
   453         else
       
   454         {
       
   455             mToField->setAddresses(messageDetails->toAddressList());
       
   456         }
       
   457         QString bodyTxt = messageDetails->bodyText();
       
   458         mBody->setText(bodyTxt);
       
   459 
       
   460         int attachmentCount = messageDetails->attachments().count();
       
   461         QStringList pendingAttList;
       
   462         for(int i=0; i<attachmentCount; i++)
       
   463         {
       
   464             int imageSize=0;
       
   465             QString mimeType;
       
   466             TMsgMediaType mediaType = EMsgMediaUnknown;
       
   467             QString filePath = messageDetails->attachments().at(i)->filePath();
       
   468             
       
   469            
       
   470             UniEditorGenUtils* genUtils = q_check_ptr(new UniEditorGenUtils);
       
   471             
       
   472             TRAP_IGNORE(genUtils->getFileInfoL(filePath,imageSize,
       
   473                                            mimeType,mediaType));
       
   474             delete genUtils;
       
   475             switch(mediaType)
       
   476             {
       
   477                 case EMsgMediaImage:
       
   478                 {
       
   479                     mBody->setImage(filePath);
       
   480                 }
       
   481                 break;
       
   482                  case EMsgMediaAudio:
       
   483                 {
       
   484                     mBody->setAudio(filePath);
       
   485                 }
       
   486                 break;
       
   487                 default:
       
   488                 {
       
   489                     pendingAttList << filePath;
       
   490                 }
       
   491                 break;
       
   492             }
       
   493         }
       
   494         // add pending attachments in bulk
       
   495         addAttachments(pendingAttList);
       
   496     }
       
   497     delete messageDetails; 
   410     delete messageDetails; 
   498 }
   411 }
   499 
   412 
   500 void MsgUnifiedEditorView::populateContentIntoEditor(
   413 //---------------------------------------------------------------
   501     const ConvergedMessage& messageDetails,bool draftMessage)
   414 // MsgUnifiedEditorView::populateContentIntoEditor
       
   415 // @see header file
       
   416 //---------------------------------------------------------------
       
   417 void MsgUnifiedEditorView::populateContentIntoEditor(const ConvergedMessage& messageDetails,
       
   418                                                      bool draftMessage,
       
   419                                                      bool checkForInline)
   502 {
   420 {
   503     // skip first-time MMS type switch note for draft
   421     // skip first-time MMS type switch note for draft
       
   422     if(draftMessage)
       
   423     {
   504     mMsgMonitor->setSkipNote(true);
   424     mMsgMonitor->setSkipNote(true);
   505     mToField->skipMaxRecipientQuery(true);
   425     }
   506 
   426 
   507     mToField->setAddresses(messageDetails.toAddressList(),draftMessage);
   427     //scrollarea populate contents
   508     if(messageDetails.ccAddressList().count() > 0 )
   428     mScrollArea->populateContent(messageDetails,draftMessage,checkForInline);
   509     {
   429 
   510         if(!mCcField)
   430     //body editor populate contents
   511         {
   431     mBodyEditor->populateContent(messageDetails);
   512         addCcBcc();
   432 
   513         }
       
   514         mCcField->setAddresses(messageDetails.ccAddressList(),draftMessage);
       
   515     }
       
   516     if(messageDetails.bccAddressList().count() > 0 )
       
   517     {
       
   518         if(!mBccField)
       
   519         {
       
   520         addCcBcc();
       
   521         }
       
   522         mBccField->setAddresses(messageDetails.bccAddressList(),draftMessage);
       
   523     }
       
   524     if(messageDetails.subject().size() > 0)
       
   525     {
       
   526        if(!mSubjectField)
       
   527        {
       
   528            addSubject();
       
   529        }
       
   530        mSubjectField->setText(messageDetails.subject());
       
   531     }
       
   532 
       
   533     if(messageDetails.priority()==ConvergedMessage::High ||
       
   534             messageDetails.priority() == ConvergedMessage::Low)
       
   535     {
       
   536         if(!mSubjectField)
       
   537         {
       
   538             addSubject();
       
   539         }
       
   540         mSubjectField->setPriority(messageDetails.priority());
       
   541     }
       
   542 
       
   543     QString bodyTxt = messageDetails.bodyText();
       
   544     mBody->setText(bodyTxt);
       
   545 
       
   546     ConvergedMessageAttachmentList attachmentList =
       
   547         messageDetails.attachments();
       
   548     int attachmentCount = attachmentList.count();
       
   549      
       
   550     UniEditorGenUtils* genUtils = q_check_ptr(new UniEditorGenUtils);
       
   551 
       
   552     QStringList pendingAttList;
       
   553     for( int i=0; i < attachmentCount; i++ )
       
   554     {
       
   555         QString filePath = messageDetails.attachments().at(i)->filePath();
       
   556 
       
   557         if(attachmentList.at(i)->attachmentType() ==
       
   558             ConvergedMessageAttachment::EInline)
       
   559         {
       
   560             int imageSize=0;
       
   561             QString mimeType;
       
   562             TMsgMediaType mediaType = EMsgMediaUnknown;
       
   563             TRAP_IGNORE(genUtils->getFileInfoL(filePath,imageSize,
       
   564                 mimeType,mediaType));
       
   565 
       
   566             switch(mediaType)
       
   567             {
       
   568                 case EMsgMediaImage:
       
   569                 {
       
   570                     mBody->setImage(filePath,draftMessage);
       
   571                     break;
       
   572                 }
       
   573                 case EMsgMediaAudio:
       
   574                 {
       
   575                     mBody->setAudio(filePath);
       
   576                     break;
       
   577                 }
       
   578                 default:
       
   579                 {
       
   580                     pendingAttList << filePath;
       
   581                     break;
       
   582                 }
       
   583             }
       
   584         }
       
   585         else
       
   586         {
       
   587             pendingAttList << filePath;
       
   588         }
       
   589     }
       
   590     // add pending attachments to editor
       
   591     addAttachments(pendingAttList);
       
   592 
       
   593     delete genUtils;
       
   594     // ensure that any msg-type change after this are shown
       
   595     mToField->skipMaxRecipientQuery(false);
       
   596     mMsgMonitor->setSkipNote(false);
   433     mMsgMonitor->setSkipNote(false);
   597 }
   434 }
   598 
   435 
   599 void MsgUnifiedEditorView::addToolBar()
   436 //---------------------------------------------------------------
   600 {
   437 // MsgUnifiedEditorView::addSubject
   601     //Create Tool Bar
   438 // @see header file
   602     HbToolBar *toolBar = new HbToolBar();
   439 //---------------------------------------------------------------
   603     toolBar->setOrientation(Qt::Horizontal);
   440 void MsgUnifiedEditorView::addSubject(bool needFocus)
   604     
   441 {
   605     //tool bar extension for attach action.
   442     //triggered from menu so need a focus.
   606     HbToolBarExtension* attachExtension = new HbToolBarExtension();
       
   607     mAttachAction = toolBar->addExtension(attachExtension);    
       
   608     mAttachAction->setIcon(HbIcon(ATTACH_ICON));
       
   609     
       
   610     mTBExtnContentWidget = new HbListWidget();
       
   611     mTBExtnContentWidget->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Fixed);
       
   612     mTBExtnContentWidget->addItem(LOC_PHOTO);
       
   613     mTBExtnContentWidget->addItem(LOC_SOUND);
       
   614     mTBExtnContentWidget->addItem(LOC_BUSINESS_CARD);
       
   615 
       
   616     HbListViewItem *prototype = mTBExtnContentWidget->listItemPrototype();
       
   617     HbFrameBackground frame(POPUP_LIST_FRAME, HbFrameDrawer::NinePieces);
       
   618     prototype->setDefaultFrame(frame);
       
   619 
       
   620     connect(mTBExtnContentWidget, SIGNAL(activated(HbListWidgetItem*)),
       
   621             this, SLOT(handleViewExtnActivated(HbListWidgetItem*)));
       
   622     connect(mTBExtnContentWidget, SIGNAL(activated(HbListWidgetItem*)),
       
   623             attachExtension, SLOT(close()));
       
   624 
       
   625     attachExtension->setContentWidget(mTBExtnContentWidget);
       
   626 
       
   627     //Add Action to the toolbar and show toolbar
       
   628     mSendAction = toolBar->addAction(HbIcon(SEND_ICON),QString(),this,SLOT(send()));
       
   629     mSendAction->setDisabled(true);
       
   630 
       
   631     setToolBar(toolBar);
       
   632 }
       
   633 
       
   634 void MsgUnifiedEditorView::addSubject()
       
   635 {
       
   636     if(mSubjectField)
       
   637     { // do nothing if already present
       
   638         return;
       
   639     }
       
   640 
       
   641     int index =0;
       
   642     int offset = 1;
       
   643     if(mAttachmentContainer)
       
   644     {
       
   645         ++offset;
       
   646     }
       
   647     index = mMainLayout->count() - offset;
       
   648 
       
   649     mSubjectField = new MsgUnifiedEditorSubject( mContentWidget);
       
   650     
       
   651     mMainLayout->insertItem(index,mSubjectField);
       
   652     connect(mSubjectField, SIGNAL(contentChanged()),
       
   653             mMsgMonitor, SLOT(handleContentChange()));
       
   654     connect(mSubjectField, SIGNAL(contentChanged()),this,SLOT(onContentChanged()));
       
   655     
       
   656     //set focus to subject field.
       
   657     HbAction* subjectAction = qobject_cast<HbAction*>(this->sender());
   443     HbAction* subjectAction = qobject_cast<HbAction*>(this->sender());
   658     if(subjectAction)
   444     if(subjectAction)
   659     {
   445     {
   660         setFocus(mSubjectField);
   446         needFocus = true;
   661     }
   447     }
   662     
   448     mScrollArea->addSubject(needFocus);
   663     // remove mainmenu's "Add Subject" action
   449 }
   664     if(mSubjectAction)
   450 
   665     {
   451 //---------------------------------------------------------------
   666         HbMenu* mainMenu = this->menu();
   452 // MsgUnifiedEditorView::addCcBcc
   667         mainMenu->removeAction(mSubjectAction);
   453 // @see header file
   668         mSubjectAction->setParent(NULL);
   454 //---------------------------------------------------------------
   669         delete mSubjectAction;
   455 void MsgUnifiedEditorView::addCcBcc(bool needFocus)
   670     }
   456 {
   671 }
       
   672 
       
   673 void MsgUnifiedEditorView::addCcBcc()
       
   674 {
       
   675     if(mCcField && mBccField)
       
   676     { // do nothing if already present
       
   677         return;
       
   678     }
       
   679 
       
   680     mCcField    = new MsgUnifiedEditorAddress( LOC_CC, mContentWidget );
       
   681     mBccField   = new MsgUnifiedEditorAddress( LOC_BCC, mContentWidget );
       
   682     mCcField->skipMaxRecipientQuery(true);
       
   683     mBccField->skipMaxRecipientQuery(true);
       
   684 
       
   685     connect(mCcField, SIGNAL(sendMessage()), this, SLOT(send()));
       
   686     connect(mCcField, SIGNAL(contentChanged()), mMsgMonitor, SLOT(handleContentChange()));
       
   687     connect(mCcField, SIGNAL(contentChanged()),this,SLOT(onContentChanged()));
       
   688     
       
   689     connect(mBccField, SIGNAL(sendMessage()), this, SLOT(send()));
       
   690     connect(mBccField, SIGNAL(contentChanged()), mMsgMonitor, SLOT(handleContentChange()));
       
   691     connect(mBccField, SIGNAL(contentChanged()),this,SLOT(onContentChanged()));
       
   692 
       
   693     HbWidget* groupWidget = new HbWidget(mContentWidget);
       
   694     groupWidget->setContentsMargins(0,0,0,0);
       
   695     
       
   696     QGraphicsLinearLayout* ccBccLayout = new QGraphicsLinearLayout(Qt::Vertical, groupWidget);
       
   697     ccBccLayout->setContentsMargins(0,0,0,0);
       
   698 
       
   699     qreal vItemSpacing = 0.0;    
       
   700     style()->parameter("hb-param-margin-gene-middle-vertical",vItemSpacing);
       
   701     ccBccLayout->setSpacing(vItemSpacing);
       
   702     ccBccLayout->addItem(mCcField);
       
   703     ccBccLayout->addItem(mBccField);
       
   704 
       
   705     HbGroupBox* groupBox = new HbGroupBox(0);  
       
   706     groupBox->setObjectName("groupBox");
       
   707     
       
   708     groupBox->setContentWidget(groupWidget);
       
   709     groupBox->setHeading(LOC_OTHER_RECIPIENTS_EXPAND);
       
   710     mMainLayout->insertItem(1,groupBox);
       
   711     connect(groupBox, SIGNAL(toggled(bool)), this, SLOT(updateOtherRecipientCount(bool)));
       
   712     
       
   713     // add subject field too
       
   714     addSubject();
       
   715 
       
   716     //set focus to Cc field.
   457     //set focus to Cc field.
   717     HbAction* ccBccAction = qobject_cast<HbAction*>(this->sender());
   458     HbAction* ccBccAction = qobject_cast<HbAction*>(this->sender());
   718     if(mCcBccAction)
   459     if(ccBccAction)
   719     {
   460     {
   720         setFocus(mCcField);
   461         needFocus = true;
   721     }
   462     }
   722     
   463 
   723     // remove mainmenu's "Add Cc/Bcc" & "Add Subject" actions
   464     mScrollArea->addCcBcc(needFocus);
   724     if(mCcBccAction)
       
   725     {
       
   726     HbMenu* mainmenu = this->menu();
       
   727     mainmenu->removeAction(mCcBccAction);
       
   728     mCcBccAction->setParent(NULL);
       
   729     delete mCcBccAction;
       
   730     }
       
   731     
       
   732     this->updateGeometry();
       
   733 }
       
   734 
       
   735 void MsgUnifiedEditorView::updateOtherRecipientCount(bool state)
       
   736 {
       
   737     HbGroupBox* groupBox = qobject_cast<HbGroupBox*>(sender());
       
   738     if(groupBox)
       
   739     {
       
   740         if(!state)
       
   741         {
       
   742            groupBox->setHeading(LOC_OTHER_RECIPIENTS_EXPAND);
       
   743         }
       
   744         else
       
   745         {
       
   746             int addrCount = mCcField->addressCount();
       
   747             addrCount += mBccField->addressCount();
       
   748             if(addrCount > 0)
       
   749             {
       
   750                 groupBox->setHeading(LOC_OTHER_RECIPIENTS(addrCount));    
       
   751             }
       
   752         }
       
   753     }
       
   754 }
       
   755 
       
   756 void MsgUnifiedEditorView::changePriority()
       
   757 {
       
   758     HbAction* action = qobject_cast<HbAction*>(sender());
       
   759 
       
   760     ConvergedMessage::Priority priority = ConvergedMessage::Normal;
       
   761    if(action)
       
   762         {
       
   763         int data = action->data().toInt();
       
   764         priority = ConvergedMessage::Priority(data);
       
   765         }
       
   766 
       
   767     addSubject();
   465     addSubject();
   768     mSubjectField->setPriority(priority);
   466 }
   769 }
   467 
   770 
   468 //---------------------------------------------------------------
       
   469 // MsgUnifiedEditorView::deleteMessage
       
   470 // @see header file
       
   471 //---------------------------------------------------------------
   771 void MsgUnifiedEditorView::deleteMessage()
   472 void MsgUnifiedEditorView::deleteMessage()
   772 {
   473 {
   773     HbMessageBox::question(LOC_NOTE_DELETE_MESSAGE,this,
   474     HbMessageBox::question(LOC_NOTE_DELETE_MESSAGE,this,
   774                            SLOT(onDialogDeleteMsg(HbAction*)),
   475                            SLOT(onDialogDeleteMsg(HbAction*)),
   775                            HbMessageBox::Delete | HbMessageBox::Cancel);
   476                            HbMessageBox::Delete | HbMessageBox::Cancel);
   776 }
   477 }
   777 
   478 
   778 void MsgUnifiedEditorView::removeAttachmentContainer()
   479 //---------------------------------------------------------------
   779 {
   480 // MsgUnifiedEditorView::addAttachments
   780     if(mAttachmentContainer)
   481 // @see header file
   781     {
   482 //---------------------------------------------------------------
   782         mMainLayout->removeItem(mAttachmentContainer);
       
   783         mAttachmentContainer->setParent(NULL);
       
   784         delete mAttachmentContainer;
       
   785         mAttachmentContainer = NULL;
       
   786     }
       
   787 }
       
   788 
       
   789 void MsgUnifiedEditorView::addAttachments(QStringList files)
   483 void MsgUnifiedEditorView::addAttachments(QStringList files)
   790 {    
   484 {    
   791     int fcount = files.count();
   485     mScrollArea->addAttachments(files);
   792     int i=0;
   486 }
   793     for(i=0; i<fcount; i++)
   487 
   794     {
   488 //---------------------------------------------------------------
   795         int status = addAttachment(files.at(i));
   489 // MsgUnifiedEditorView::send
   796         if(status == MsgAttachmentContainer::EAddSizeExceed)
   490 // @see header file
   797         {
   491 //---------------------------------------------------------------
   798             QString displayStr = QString(LOC_UNABLE_TO_ADD_ATTACHMENTS)
       
   799                     .arg(fcount-i).arg(fcount);
       
   800             HbNotificationDialog::launchDialog(displayStr);
       
   801             break;
       
   802         }
       
   803     }
       
   804 }
       
   805 
       
   806 int MsgUnifiedEditorView::addAttachment(const QString& filepath)
       
   807 {
       
   808     // do nothing if filepath is empty
       
   809     if(filepath.isEmpty())
       
   810     {
       
   811         return MsgAttachmentContainer::EAddSuccess;
       
   812     }
       
   813 
       
   814     if(!mAttachmentContainer)
       
   815     {
       
   816         mAttachmentContainer = new MsgAttachmentContainer( mContentWidget);
       
   817         connect(mAttachmentContainer, SIGNAL(emptyAttachmentContainer()),
       
   818                 this, SLOT(removeAttachmentContainer()));
       
   819         connect(mAttachmentContainer, SIGNAL(contentChanged()),
       
   820                 mMsgMonitor, SLOT(handleContentChange()));
       
   821         connect(mAttachmentContainer, SIGNAL(contentChanged()),
       
   822                 this,SLOT(onContentChanged()));
       
   823         
       
   824         int index = mMainLayout->count() - 1;
       
   825         mMainLayout->insertItem(index,mAttachmentContainer);
       
   826     }
       
   827 
       
   828     int ret = mAttachmentContainer->addAttachment(filepath);
       
   829     if(ret != MsgAttachmentContainer::EAddSuccess)
       
   830     {
       
   831         // delete container, if it is empty
       
   832         if(mAttachmentContainer->count() == 0)
       
   833         {
       
   834             removeAttachmentContainer();
       
   835         }
       
   836     }
       
   837     return ret;
       
   838 }
       
   839 
       
   840 void MsgUnifiedEditorView::send()
   492 void MsgUnifiedEditorView::send()
   841 {
   493 {
   842     activateInputBlocker();
   494     activateInputBlocker();
   843     
   495 
   844     // first run the address validation tests
   496     // first run the address validation tests
   845     if( !mToField->validateContacts() ||
   497     if(!mScrollArea->contactsValid() ||
   846         (mCcField && !mCcField->validateContacts()) ||
   498        !MsgUnifiedEditorMonitor::readyForSend())
   847         (mBccField && !mBccField->validateContacts()) )
       
   848     {
   499     {
   849         deactivateInputBlocker();
   500         deactivateInputBlocker();
   850         return;
   501         return;
   851     }
   502     }
   852 
   503 
   853     // converged msg for sending
   504     // converged msg for sending
   854     ConvergedMessage msg;
   505     ConvergedMessage msg;
   855     ConvergedMessage::MessageType messageType = MsgUnifiedEditorMonitor::messageType();
   506     ConvergedMessage::MessageType messageType = MsgUnifiedEditorMonitor::messageType();
   856     msg.setMessageType(messageType);
   507     msg.setMessageType(messageType);
   857 
   508 
   858     // we need to remove duplicate addresses
   509 
   859     bool removeDuplicates = true;
       
   860     ConvergedMessageAddressList addresses =
       
   861             mToField->addresses(removeDuplicates);
       
   862     if(messageType == ConvergedMessage::Sms &&
       
   863        addresses.isEmpty())
       
   864     {
       
   865         // no recipient specified for sms, do not send msg
       
   866         deactivateInputBlocker();
       
   867         return;
       
   868     }
       
   869 
       
   870     ConvergedMessageAddressList ccAddresses;
       
   871     ConvergedMessageAddressList bccAddresses;
       
   872     if(mCcField)
       
   873     {
       
   874         ccAddresses = mCcField->addresses(removeDuplicates);
       
   875     }
       
   876     if(mBccField)
       
   877     {
       
   878         bccAddresses = mBccField->addresses(removeDuplicates);
       
   879     }
       
   880     if( messageType == ConvergedMessage::Mms &&
       
   881             addresses.isEmpty() &&
       
   882             ccAddresses.isEmpty() &&
       
   883             bccAddresses.isEmpty())
       
   884     {
       
   885         // no recipient specified for mms, do not send msg
       
   886         deactivateInputBlocker();
       
   887         return;
       
   888     }
       
   889     
       
   890     //close vkb before switching view.
   510     //close vkb before switching view.
   891     mVkbHost->closeKeypad(true);
   511     mVkbHost->closeKeypad(true);
   892 
   512 
   893     int result = packMessage(msg);
   513     int result = packMessage(msg);
   894     if(result == KErrNotFound)
   514     if(result == KErrNotFound)
   899     }
   519     }
   900     // send message
   520     // send message
   901     MsgSendUtil *sendUtil = new MsgSendUtil(this);
   521     MsgSendUtil *sendUtil = new MsgSendUtil(this);
   902     int sendResult = sendUtil->send(msg);
   522     int sendResult = sendUtil->send(msg);
   903     delete sendUtil;
   523     delete sendUtil;
   904     
   524 
   905     // all checks and validations happen before send
   525     // all checks and validations happen before send
   906     if( sendResult == KErrNone)
   526     if( sendResult == KErrNone)
   907     {
   527     {
   908         //After sending the new content to drafts chk if the msg
   528         //After sending the new content to drafts chk if the msg
   909         //was originally opened from drafts and delete the opened entry
   529         //was originally opened from drafts and delete the opened entry
   915                 mPluginLoader = new UniEditorPluginLoader(this);
   535                 mPluginLoader = new UniEditorPluginLoader(this);
   916             }
   536             }
   917 
   537 
   918             UniEditorPluginInterface* pluginInterface =
   538             UniEditorPluginInterface* pluginInterface =
   919                 mPluginLoader->getUniEditorPlugin(messageType);
   539                 mPluginLoader->getUniEditorPlugin(messageType);
   920             //TODO delete the entry
   540             //delete the entry
   921             pluginInterface->deleteDraftsEntry(mOpenedMessageId.getId());
   541             pluginInterface->deleteDraftsEntry(mOpenedMessageId.getId());
   922         }
   542         }
   923 
   543 
   924         ConvergedMessageAddressList addrList = addresses;
   544         ConvergedMessageAddressList addrList = msg.toAddressList() +
   925         QString receipient;
   545                                                msg.ccAddressList() + 
   926 
   546                                                msg.bccAddressList();
       
   547         
   927         int recepientCount = addrList.count();
   548         int recepientCount = addrList.count();
   928         if(recepientCount)
   549 
   929         {
   550         QVariantList params;
   930             receipient = addrList.at(0)->address();
   551 
   931         }
   552         if(recepientCount == 1 )
   932 
   553         {
   933         if( mCcField && mBccField)
   554             params << MsgBaseView::CV;  // target view
   934         {
   555             params << MsgBaseView::UNIEDITOR; // source view
   935             addrList = ccAddresses;
   556             QString receipient = addrList.at(0)->address();
   936             int ccCount = addrList.count();
   557             params << receipient;
   937             recepientCount += ccCount;
   558         }
   938             if(ccCount)
   559         else
   939             {
   560         {
   940                 receipient = addrList.at(0)->address();
   561             params << MsgBaseView::CLV;// target view
   941             }
   562             params << MsgBaseView::UNIEDITOR; // source view
   942 
       
   943             addrList = bccAddresses;
       
   944             int bccCount = addrList.count();
       
   945             recepientCount += bccCount;
       
   946             if(bccCount)
       
   947             {
       
   948                 receipient = addrList.at(0)->address();
       
   949             }
       
   950         }
       
   951         
       
   952     QVariantList params;
       
   953 
       
   954     if(recepientCount == 1 )
       
   955         {
       
   956         params << MsgBaseView::CV;  // target view
       
   957         params << MsgBaseView::UNIEDITOR; // source view
       
   958 
       
   959         params << receipient;
       
   960         }
       
   961     else
       
   962         {
       
   963         params << MsgBaseView::CLV;// target view
       
   964         params << MsgBaseView::UNIEDITOR; // source view
       
   965         }
   563         }
   966         deactivateInputBlocker();
   564         deactivateInputBlocker();
   967         emit switchView(params);
   565         emit switchView(params);
       
   566         
       
   567         mCanSaveToDrafts = false;
   968     }
   568     }
   969     else
   569     else
   970     {
   570     {
   971         deactivateInputBlocker();
   571         deactivateInputBlocker();
   972         if(sendResult == KErrNotFound)
   572         if(sendResult == KErrNotFound)
   973         {
   573         {
   974             if (messageType == ConvergedMessage::Sms)
   574             if (messageType == ConvergedMessage::Sms)
   975             {
   575             {
   976                 HbMessageBox::question(LOC_DIALOG_SMS_SETTINGS_INCOMPLETE,
   576                 HbMessageBox::question(LOC_DIALOG_SMS_SETTINGS_INCOMPLETE,
   977                                        this,SLOT(onDialogSmsSettings(HbAction*)),
   577                     this,SLOT(onDialogSmsSettings(HbAction*)),
   978                                        HbMessageBox::Ok | HbMessageBox::Cancel);
   578                     HbMessageBox::Ok | HbMessageBox::Cancel);
   979             }
   579             }
   980             else
   580             else
   981             {
   581             {
   982                 HbMessageBox::question(LOC_DIALOG_MMS_SETTINGS_INCOMPLETE,
   582                 HbMessageBox::question(LOC_DIALOG_MMS_SETTINGS_INCOMPLETE,
   983                                        this,SLOT(onDialogMmsSettings(HbAction*)),                             
   583                     this,SLOT(onDialogMmsSettings(HbAction*)),                             
   984                                        HbMessageBox::Ok | HbMessageBox::Cancel);
   584                     HbMessageBox::Ok | HbMessageBox::Cancel);
   985             }
   585             }
   986         }
   586         }
   987     }
   587     }
   988 }
   588 }
   989 
   589 
       
   590 //---------------------------------------------------------------
       
   591 // MsgUnifiedEditorView::packMessage
       
   592 // @see header file
       
   593 //---------------------------------------------------------------
   990 int MsgUnifiedEditorView::packMessage(ConvergedMessage &msg, bool isSave)
   594 int MsgUnifiedEditorView::packMessage(ConvergedMessage &msg, bool isSave)
   991 {
   595 {
   992     // reset reply-path if originating SME constraint is broken
   596     // reset reply-path if originating SME constraint is broken
   993     if(mReplyPath && isReplyPathBroken())
   597     if(mReplyPath && isReplyPathBroken())
   994     {
   598     {
  1001         msg.setOriginatingSC(mOriginatingSC);
   605         msg.setOriginatingSC(mOriginatingSC);
  1002     }
   606     }
  1003 
   607 
  1004     ConvergedMessage::MessageType messageType = MsgUnifiedEditorMonitor::messageType();
   608     ConvergedMessage::MessageType messageType = MsgUnifiedEditorMonitor::messageType();
  1005     msg.setMessageType(messageType);
   609     msg.setMessageType(messageType);
  1006     // If isSave is true (save to draft usecase), then don't remove duplicates
       
  1007     // If isSave is false (send usecase), then remove duplicates
       
  1008     bool removeDuplicates = !isSave;
       
  1009     ConvergedMessageAddressList addresses = 
       
  1010             mToField->addresses(removeDuplicates);
       
  1011     ConvergedMessageAddressList ccAddresses;
       
  1012     ConvergedMessageAddressList bccAddresses;
       
  1013     ConvergedMessageAttachmentList mediaList;
       
  1014     int errorCode = 0;
       
  1015 	//Don't format the addresses for save to drfats case
       
  1016 	if(!isSave)
       
  1017 	{
       
  1018        formatAddresses(addresses);
       
  1019     }
       
  1020 	
       
  1021     msg.addToRecipients(addresses);
       
  1022     msg.setBodyText(mBody->text());
       
  1023     msg.setDirection(ConvergedMessage::Outgoing);
   610     msg.setDirection(ConvergedMessage::Outgoing);
  1024     QDateTime time = QDateTime::currentDateTime();
   611     QDateTime time = QDateTime::currentDateTime();
  1025     msg.setTimeStamp(time.toTime_t());
   612     msg.setTimeStamp(time.toTime_t());
  1026 
   613     
  1027     if(messageType == ConvergedMessage::Mms)
   614     
  1028     {
   615     //pack message data from mscrollarea.
  1029         if(mCcField)
   616     int errorCode = mScrollArea->packMessage(msg,isSave);
  1030         {
   617     
  1031             ccAddresses = mCcField->addresses(removeDuplicates);
   618     //pack message data from body editor.
  1032         }
   619     mBodyEditor->packMessage(msg);
  1033 
   620     
  1034         if(mBccField)
   621     return errorCode;
  1035         {
   622 }
  1036             bccAddresses = mBccField->addresses(removeDuplicates);
   623 
  1037         }
   624 //---------------------------------------------------------------
  1038 
   625 // MsgUnifiedEditorView::saveContentToDrafts
  1039         if(removeDuplicates)
   626 // @see header file
  1040         {
   627 //---------------------------------------------------------------
  1041             int matchDigitsCount = MsgUnifiedEditorAddress::contactMatchDigits();
       
  1042             //comapre cc and to field,remove duplicate from cc
       
  1043             foreach(ConvergedMessageAddress *ccAddress,ccAddresses)
       
  1044             {
       
  1045                 foreach(ConvergedMessageAddress *toAddress,addresses)
       
  1046                 {
       
  1047                     if(0 == ccAddress->address().right(matchDigitsCount).compare(toAddress->address().right(matchDigitsCount)))
       
  1048                     {
       
  1049                         ccAddresses.removeOne(ccAddress);
       
  1050                     }
       
  1051                 }
       
  1052             }
       
  1053             //comapre bcc and cc field,remove duplicate from bcc
       
  1054             foreach(ConvergedMessageAddress *bccAddress,bccAddresses)
       
  1055             {
       
  1056                 foreach(ConvergedMessageAddress *ccAddress,ccAddresses)
       
  1057                 {
       
  1058                     if(0 == bccAddress->address().right(matchDigitsCount).compare(ccAddress->address().right(matchDigitsCount)))
       
  1059                     {
       
  1060                         bccAddresses.removeOne(bccAddress);
       
  1061                     }
       
  1062                 }
       
  1063             }
       
  1064             //comapre bcc and to field,remove duplicate from bcc
       
  1065             foreach(ConvergedMessageAddress *bccAddress,bccAddresses)
       
  1066             {
       
  1067                 foreach(ConvergedMessageAddress *toAddress,addresses)
       
  1068                 {
       
  1069                     if(0 == bccAddress->address().right(matchDigitsCount).compare(toAddress->address().right(matchDigitsCount)))
       
  1070                     {
       
  1071                         bccAddresses.removeOne(bccAddress);
       
  1072                     }
       
  1073                 }
       
  1074             }
       
  1075         }
       
  1076 
       
  1077         if(ccAddresses.count()>0)
       
  1078         {
       
  1079 		//Don't format the addresses for save to drfats case
       
  1080 	    if(!isSave)
       
  1081 	    {
       
  1082            formatAddresses(ccAddresses);
       
  1083         }        
       
  1084         msg.addCcRecipients(ccAddresses);
       
  1085         }
       
  1086         if(bccAddresses.count()>0)
       
  1087         {
       
  1088 		//Don't format the addresses for save to drfats case
       
  1089 	    if(!isSave)
       
  1090 	    {
       
  1091            formatAddresses(bccAddresses);        
       
  1092 		}
       
  1093         msg.addBccRecipients(bccAddresses);
       
  1094         }
       
  1095         if(mSubjectField)
       
  1096         {
       
  1097             msg.setSubject(mSubjectField->text());
       
  1098             msg.setPriority(mSubjectField->priority());
       
  1099         }
       
  1100 
       
  1101         QStringList mediafiles(mBody->mediaContent());
       
  1102         if (!mediafiles.isEmpty())
       
  1103         {
       
  1104             for (int i = 0; i < mediafiles.size(); ++i)
       
  1105             {
       
  1106                 if(QFile::exists(mediafiles.at(i)))
       
  1107                 {
       
  1108                 ConvergedMessageAttachment* attachment =
       
  1109                     new ConvergedMessageAttachment(
       
  1110                         mediafiles.at(i),
       
  1111                         ConvergedMessageAttachment::EInline);
       
  1112                 mediaList << attachment;
       
  1113                 }
       
  1114                 else
       
  1115                 {   mBody->removeMediaContent(mediafiles.at(i));
       
  1116                     errorCode = KErrNotFound;
       
  1117                 }
       
  1118             }
       
  1119 
       
  1120         }
       
  1121         if(mediaList.count() > 0)
       
  1122         {
       
  1123             msg.addAttachments(mediaList);
       
  1124         }
       
  1125     }
       
  1126 
       
  1127     // sms/mms attachment list
       
  1128     ConvergedMessageAttachmentList attachmentList;
       
  1129         if(mAttachmentContainer)
       
  1130         {
       
  1131             MsgUnifiedEditorAttachmentList editorAttachmentList =
       
  1132                 mAttachmentContainer->attachmentList();
       
  1133                 for (int i = 0; i < editorAttachmentList.count(); ++i)
       
  1134                 {
       
  1135                     if(QFile::exists(editorAttachmentList.at(i)->path()))
       
  1136                     {
       
  1137                         ConvergedMessageAttachment* attachment =
       
  1138                                                 new ConvergedMessageAttachment(
       
  1139                                                     editorAttachmentList.at(i)->path(),
       
  1140                                                     ConvergedMessageAttachment::EAttachment);
       
  1141                                             attachmentList << attachment;    
       
  1142                     }
       
  1143                     else
       
  1144                     {
       
  1145                         mAttachmentContainer->deleteAttachment(editorAttachmentList.at(i));
       
  1146                         errorCode = KErrNotFound;
       
  1147                     }   
       
  1148                 }
       
  1149             }
       
  1150         if(attachmentList.count() > 0)
       
  1151         {
       
  1152             msg.addAttachments(attachmentList);
       
  1153         }
       
  1154         return errorCode;
       
  1155 }
       
  1156 
       
  1157 int MsgUnifiedEditorView::saveContentToDrafts()
   628 int MsgUnifiedEditorView::saveContentToDrafts()
  1158 {
   629 {
  1159     if(!mCanSaveToDrafts)
   630     if(!mCanSaveToDrafts)
  1160         {
   631         {
  1161         return mOpenedMessageId.getId(); // return currently opened message id
   632         return mOpenedMessageId.getId(); // return currently opened message id
  1162         }
   633         }
  1163     
   634     
  1164     activateInputBlocker();
   635     activateInputBlocker();
  1165     ConvergedMessage::MessageType messageType = MsgUnifiedEditorMonitor::messageType();
   636     ConvergedMessage::MessageType messageType = MsgUnifiedEditorMonitor::messageType();
  1166 
   637 
  1167     ConvergedMessageAddressList addresses = mToField->addresses();
       
  1168 
       
  1169     UniEditorPluginInterface* pluginInterface = NULL;
   638     UniEditorPluginInterface* pluginInterface = NULL;
  1170 
   639 
  1171     if( mOpenedMessageId.getId() != -1)
   640     if( mOpenedMessageId.getId() != -1)
  1172     {
   641     {
  1173         if(!mPluginLoader)
   642         if(!mPluginLoader)
  1174         {
   643         {
  1175             mPluginLoader = new UniEditorPluginLoader(this);
   644             mPluginLoader = new UniEditorPluginLoader(this);
  1176         }
   645         }
  1177 
   646 
  1178         pluginInterface =
   647         pluginInterface = mPluginLoader->getUniEditorPlugin(messageType);
  1179             mPluginLoader->getUniEditorPlugin(messageType);
   648     }
  1180     }
   649 
  1181 
   650     // if empty msg, do not save
  1182     if(messageType == ConvergedMessage::Sms &&
   651     if( MsgUnifiedEditorMonitor::messageSize() <= 0 && 
  1183             addresses.isEmpty() &&
   652         MsgUnifiedEditorMonitor::msgAddressCount() <= 0 )
  1184             MsgUnifiedEditorMonitor::bodySize() <= 0 &&
       
  1185             MsgUnifiedEditorMonitor::containerSize() <= 0)
       
  1186     {
   653     {
  1187         if(mOpenedMessageId.getId() != -1)
   654         if(mOpenedMessageId.getId() != -1)
  1188         {
   655         {
  1189         pluginInterface->deleteDraftsEntry(mOpenedMessageId.getId());
   656             pluginInterface->deleteDraftsEntry(mOpenedMessageId.getId());
  1190         }
   657         }
  1191 
   658         
  1192         // if empty msg, do not save
       
  1193         deactivateInputBlocker();
   659         deactivateInputBlocker();
  1194         return INVALID_MSGID;
   660         return INVALID_MSGID;
  1195     }
   661     }
  1196 
   662     
  1197     ConvergedMessageAddressList ccAddresses;
       
  1198     ConvergedMessageAddressList bccAddresses;
       
  1199     if(mCcField)
       
  1200     {
       
  1201         ccAddresses = mCcField->addresses();
       
  1202     }
       
  1203     if(mBccField)
       
  1204     {
       
  1205         bccAddresses = mBccField->addresses();
       
  1206     }
       
  1207     int subectSize =0;
       
  1208     if(mSubjectField)
       
  1209     {
       
  1210         subectSize = mSubjectField->text().size();
       
  1211     }
       
  1212 
       
  1213     if( messageType == ConvergedMessage::Mms &&
       
  1214             addresses.isEmpty() &&
       
  1215             ccAddresses.isEmpty() &&
       
  1216             bccAddresses.isEmpty() &&
       
  1217             subectSize <= 0 &&
       
  1218             MsgUnifiedEditorMonitor::bodySize() <= 0 &&
       
  1219             MsgUnifiedEditorMonitor::containerSize() <= 0)
       
  1220     {
       
  1221         if(mOpenedMessageId.getId() != -1)
       
  1222         {
       
  1223             pluginInterface->deleteDraftsEntry(mOpenedMessageId.getId());
       
  1224         }
       
  1225         // if empty msg, do not send
       
  1226         deactivateInputBlocker();
       
  1227         return INVALID_MSGID;
       
  1228     }
       
  1229     ConvergedMessage msg;
   663     ConvergedMessage msg;
  1230     int result = packMessage(msg, true);
   664     int result = packMessage(msg, true);
  1231     if(result == KErrNotFound)
   665     if(result == KErrNotFound)
  1232         {
   666         {
  1233         HbNotificationDialog::launchDialog(LOC_NOTE_FILES_MISSED_DRAFTS);
   667         HbNotificationDialog::launchDialog(LOC_NOTE_FILES_MISSED_DRAFTS);
  1234         if(messageType == ConvergedMessage::Sms &&
   668         }
  1235                     addresses.isEmpty() &&
   669     
  1236                     MsgUnifiedEditorMonitor::bodySize() <= 0 &&
       
  1237                     MsgUnifiedEditorMonitor::containerSize() <= 0)
       
  1238             {
       
  1239                 if(mOpenedMessageId.getId() != -1)
       
  1240                 {
       
  1241                 pluginInterface->deleteDraftsEntry(mOpenedMessageId.getId());
       
  1242                 }
       
  1243 
       
  1244                 // if empty msg, do not save
       
  1245                 deactivateInputBlocker();
       
  1246                 return INVALID_MSGID;
       
  1247             }
       
  1248         }
       
  1249     // save to drafts
   670     // save to drafts
  1250     MsgSendUtil *sendUtil = new MsgSendUtil(this);
   671     MsgSendUtil *sendUtil = new MsgSendUtil(this);
  1251     int msgId = sendUtil->saveToDrafts(msg);
   672     int msgId = sendUtil->saveToDrafts(msg);
  1252     delete sendUtil;
   673     delete sendUtil;
  1253 
   674 
  1265     
   686     
  1266     if(res)
   687     if(res)
  1267         {
   688         {
  1268         HbDeviceNotificationDialog::notification("", LOC_SAVED_TO_DRAFTS);
   689         HbDeviceNotificationDialog::notification("", LOC_SAVED_TO_DRAFTS);
  1269         }
   690         }
       
   691     
       
   692     mCanSaveToDrafts = false;
       
   693     
  1270     return msgId;
   694     return msgId;
  1271 }
   695 }
  1272 
   696 
       
   697 
       
   698 //---------------------------------------------------------------
       
   699 // MsgUnifiedEditorView::handleKeyEvent
       
   700 // @see header file
       
   701 //---------------------------------------------------------------
  1273 bool MsgUnifiedEditorView::handleKeyEvent(int key)
   702 bool MsgUnifiedEditorView::handleKeyEvent(int key)
  1274 {
   703 {
  1275     bool eventHandled = false;
   704     bool eventHandled = false;
  1276     if (Qt::Key_Yes == key && mSendAction->isEnabled()) {
   705     if (Qt::Key_Yes == key) {
  1277         eventHandled = true;
   706         eventHandled = true;
  1278         send();
   707         send();
  1279     }
   708     }
  1280 
   709 
  1281     return eventHandled;
   710     return eventHandled;
  1282 }
       
  1283 
       
  1284 void MsgUnifiedEditorView::resizeEvent( QGraphicsSceneResizeEvent * event )
       
  1285 {
       
  1286  Q_UNUSED(event)
       
  1287  #ifdef _DEBUG_TRACES_
       
  1288  qDebug()<<"resize event";
       
  1289 #endif
       
  1290 
       
  1291  mContentWidget->resize(this->rect().width(),this->rect().height()+1);
       
  1292 }
   711 }
  1293 
   712 
  1294 //---------------------------------------------------------------
   713 //---------------------------------------------------------------
  1295 // MsgUnifiedEditorView::createVCards
   714 // MsgUnifiedEditorView::createVCards
  1296 // @see header file
   715 // @see header file
  1413             searchFileName.append(QString::number(i));
   832             searchFileName.append(QString::number(i));
  1414         }
   833         }
  1415         searchFileName.append(FILE_EXTN);
   834         searchFileName.append(FILE_EXTN);
  1416 
   835 
  1417         // check if filename is already used by an attachment in container
   836         // check if filename is already used by an attachment in container
  1418         bool alreadyExists = false;
   837         if(!mScrollArea->fileNameInUse(searchFileName))
  1419         if(mAttachmentContainer)
       
  1420         {
       
  1421             MsgUnifiedEditorAttachmentList attList =
       
  1422                     mAttachmentContainer->attachmentList();
       
  1423             int attCount = attList.count();
       
  1424             for(int j=0; j<attCount; j++)
       
  1425             {
       
  1426                 QFileInfo fileinfo(attList.at(j)->path());
       
  1427                 if(searchFileName == fileinfo.fileName())
       
  1428                 {
       
  1429                     alreadyExists = true;
       
  1430                     break;
       
  1431                 }
       
  1432             }
       
  1433         }
       
  1434 
       
  1435         if(!alreadyExists)
       
  1436         {
   838         {
  1437             if(i>0)
   839             if(i>0)
  1438             {
   840             {
  1439                 suggestedName.append(QString::number(i));
   841                 suggestedName.append(QString::number(i));
  1440             }
   842             }
  1445     filepath.append(suggestedName);
   847     filepath.append(suggestedName);
  1446     filepath.append(FILE_EXTN);
   848     filepath.append(FILE_EXTN);
  1447     return filepath;
   849     return filepath;
  1448 }
   850 }
  1449 
   851 
  1450 void MsgUnifiedEditorView::handleViewExtnActivated(HbListWidgetItem* item)
       
  1451     {
       
  1452     QString itemText = item->text();
       
  1453     
       
  1454     if(itemText == LOC_PHOTO)
       
  1455         {
       
  1456         //launch photo picker.
       
  1457         fetchImages();  
       
  1458         }
       
  1459     else if(itemText == LOC_SOUND)
       
  1460         {
       
  1461         //launch audio picker
       
  1462         fetchAudio();
       
  1463         }
       
  1464     else if(itemText == LOC_BUSINESS_CARD)
       
  1465         {
       
  1466         //launch contact card picker.
       
  1467         fetchContacts();
       
  1468         }
       
  1469    
       
  1470 }
       
  1471 
   852 
  1472 //---------------------------------------------------------------
   853 //---------------------------------------------------------------
  1473 // MsgUnifiedEditorView::fetchContacts
   854 // MsgUnifiedEditorView::fetchContacts
  1474 // @see header file
   855 // @see header file
  1475 //---------------------------------------------------------------
   856 //---------------------------------------------------------------
  1486     {
   867     {
  1487         QCRITICAL_WRITE("AIW-ERROR: NULL request");
   868         QCRITICAL_WRITE("AIW-ERROR: NULL request");
  1488         return;
   869         return;
  1489     }
   870     }
  1490 	
   871 	
  1491     request->setSynchronous(false); // synchronous
   872     request->setSynchronous(false); // asynchronous
  1492 	
   873 	
  1493     // Result handlers
   874     // Result handlers
  1494     connect (request, SIGNAL(requestOk(const QVariant&)),
   875     connect (request, SIGNAL(requestOk(const QVariant&)),
  1495         this, SLOT(contactsFetched(const QVariant&)));
   876         this, SLOT(contactsFetched(const QVariant&)));
  1496     connect (request, SIGNAL(requestError(int,const QString&)),
   877     connect (request, SIGNAL(requestError(int,const QString&)),
  1522     if(!request)
   903     if(!request)
  1523     {     
   904     {     
  1524         QCRITICAL_WRITE("AIW-ERROR: NULL request");
   905         QCRITICAL_WRITE("AIW-ERROR: NULL request");
  1525         return;
   906         return;
  1526     }
   907     }
  1527     request->setSynchronous(false); // synchronous
   908     request->setSynchronous(false); // asynchronous
  1528 
   909 
  1529     connect(request, SIGNAL(requestOk(const QVariant&)),
   910     connect(request, SIGNAL(requestOk(const QVariant&)),
  1530         this, SLOT(imagesFetched(const QVariant&)));
   911         this, SLOT(imagesFetched(const QVariant&)));
  1531     connect(request, SIGNAL(requestError(int,const QString&)),
   912     connect(request, SIGNAL(requestError(int,const QString&)),
  1532         this, SLOT(serviceRequestError(int,const QString&)));
   913         this, SLOT(serviceRequestError(int,const QString&)));
  1594     {
   975     {
  1595         QStringList fileList = result.value<QStringList>();
   976         QStringList fileList = result.value<QStringList>();
  1596         if ( fileList.size()>0 )
   977         if ( fileList.size()>0 )
  1597         {
   978         {
  1598             QString filepath(QDir::toNativeSeparators(fileList.at(0)));
   979             QString filepath(QDir::toNativeSeparators(fileList.at(0)));
  1599             mBody->setImage(filepath);
   980             mScrollArea->setImage(filepath);
  1600         }
   981         }
  1601     }
   982     }
  1602 }
   983 }
  1603 
   984 
  1604 //---------------------------------------------------------------
   985 //---------------------------------------------------------------
  1635 {
  1016 {
  1636     mainWindow()->setInteractive(true);
  1017     mainWindow()->setInteractive(true);
  1637 }
  1018 }
  1638 
  1019 
  1639 //---------------------------------------------------------------
  1020 //---------------------------------------------------------------
  1640 // MsgUnifiedEditorView::setAttachOptionEnabled
  1021 // MsgUnifiedEditorView::enableMenuAction
  1641 // @see header file
  1022 // @see header file
  1642 //--------------------------------------------------------------
  1023 //--------------------------------------------------------------
  1643 void MsgUnifiedEditorView::setAttachOptionEnabled(
  1024 void MsgUnifiedEditorView::enableMenuAction(int action, bool enable)
  1644         MsgUnifiedEditorView::TBE_AttachOption opt, bool enable)
  1025 {
  1645 {
  1026     switch(action)
  1646     HbListWidgetItem* wgtItem = mTBExtnContentWidget->item(opt);
  1027     {
  1647     wgtItem->setEnabled(enable);
  1028     case SOUND:
       
  1029     {
       
  1030         if(mSoundAction)
       
  1031         {
       
  1032             mSoundAction->setEnabled(enable);
       
  1033         }
       
  1034         break;
       
  1035     }
       
  1036     case PHOTO:
       
  1037     {
       
  1038         if(mPhotoAction)
       
  1039         {
       
  1040             mPhotoAction->setEnabled(enable);
       
  1041         }
       
  1042         break;
       
  1043     }  
       
  1044     case SUBJECT: //subject action has to be removed
       
  1045     {
       
  1046         // remove mainmenu's "Add Subject" action
       
  1047         if(mSubjectAction)
       
  1048         {
       
  1049             this->menu()->removeAction(mSubjectAction);
       
  1050             mSubjectAction->setParent(NULL);
       
  1051             delete mSubjectAction;
       
  1052             mSubjectAction = NULL;
       
  1053         }
       
  1054         break;
       
  1055     }
       
  1056     case CCBCC: //CcBcc action has to be removed
       
  1057     {
       
  1058         // remove mainmenu's "Add Cc/Bcc" & "Add Subject" actions
       
  1059         if(mCcBccAction)
       
  1060         {
       
  1061             this->menu()->removeAction(mCcBccAction);
       
  1062             mCcBccAction->setParent(NULL);
       
  1063             delete mCcBccAction;
       
  1064             mCcBccAction = NULL;
       
  1065         }
       
  1066         break;
       
  1067     }
       
  1068     
       
  1069     default:
       
  1070         break;
       
  1071     }
  1648 }
  1072 }
  1649 
  1073 
  1650 //---------------------------------------------------------------
  1074 //---------------------------------------------------------------
  1651 // MsgUnifiedEditorView::vkbOpened
  1075 // MsgUnifiedEditorView::vkbOpened
  1652 // @see header file
  1076 // @see header file
  1653 //---------------------------------------------------------------
  1077 //---------------------------------------------------------------
  1654 void MsgUnifiedEditorView::vkbOpened()
  1078 void MsgUnifiedEditorView::vkbOpened()
  1655 {
  1079 {
  1656     hideChrome(true); 
  1080     hideChrome(true); 
  1657     
  1081     
       
  1082     //get focussed object.
       
  1083     HbInputMethod* im =   HbInputMethod::activeInputMethod(); 
       
  1084     HbInputFocusObject* focusObj =   im->focusObject();
       
  1085     if(focusObj)
       
  1086     {
       
  1087         QObject* obj =   focusObj->object(); 
       
  1088         mFocusedWidget = qobject_cast<QGraphicsWidget*>(obj); 
       
  1089         HbAbstractEdit* editor = qobject_cast<HbAbstractEdit*>(obj);
       
  1090         if(editor)
       
  1091         {
       
  1092             connect(editor,SIGNAL(contentsChanged()),this,SLOT(ensureVisibility()));
       
  1093         }
       
  1094     }
       
  1095     
       
  1096     QRectF appRect = mVkbHost->applicationArea();
       
  1097     
       
  1098     if(this->mainWindow()->orientation() == Qt::Vertical)
       
  1099     {
       
  1100         this->setMaximumHeight(appRect.height());
       
  1101         mScrollArea->resize(-1,-1);
       
  1102     }
       
  1103     else
       
  1104     {
       
  1105         if(mFocusedWidget)
       
  1106         {
       
  1107             qreal vItemSpacing = 0.0;
       
  1108             style()->parameter("hb-param-margin-gene-middle-vertical",vItemSpacing); 
       
  1109             
       
  1110             mMinHeight = mFocusedWidget->minimumHeight();
       
  1111             mMaxHeight = mFocusedWidget->maximumHeight();
       
  1112             qreal newHeight = appRect.height()-vItemSpacing-1;
       
  1113             mFocusedWidget->setMinimumHeight(newHeight);
       
  1114             mFocusedWidget->setMaximumHeight(newHeight);
       
  1115             mFocusedWidget->resize(mFocusedWidget->rect().width(),newHeight);
       
  1116 
       
  1117         }
       
  1118     }
       
  1119     
       
  1120     //do layouting after some delay.
       
  1121     QTimer::singleShot(50,this,SLOT(doLayout()));
       
  1122     
  1658     disconnect(mVkbHost,SIGNAL(keypadOpened()),this,SLOT(vkbOpened()));
  1123     disconnect(mVkbHost,SIGNAL(keypadOpened()),this,SLOT(vkbOpened()));
  1659 }
  1124     connect(this->mainWindow(),SIGNAL(aboutToChangeOrientation()),this,SLOT(resetLayout()));
  1660       
  1125 }
       
  1126 
  1661 //---------------------------------------------------------------
  1127 //---------------------------------------------------------------
  1662 // MsgUnifiedEditorView::vkbClosed
  1128 // MsgUnifiedEditorView::vkbClosed
  1663 // @see header file
  1129 // @see header file
  1664 //---------------------------------------------------------------
  1130 //---------------------------------------------------------------
  1665 void MsgUnifiedEditorView::vkbClosed()
  1131 void MsgUnifiedEditorView::vkbClosed()
  1666 {
  1132 {
  1667     hideChrome(false);
  1133     hideChrome(false); 
  1668     
  1134     
       
  1135     resetLayout();
       
  1136    
  1669     connect(mVkbHost,SIGNAL(keypadOpened()),this,SLOT(vkbOpened()));
  1137     connect(mVkbHost,SIGNAL(keypadOpened()),this,SLOT(vkbOpened()));
  1670 }
  1138     
  1671 
  1139     disconnect(this->mainWindow(),SIGNAL(aboutToChangeOrientation()),this,SLOT(resetLayout()));    
  1672 //---------------------------------------------------------------
  1140 }
  1673 // MsgUnifiedEditorView::vkbAboutToOpen
  1141 
  1674 // @see header file
  1142 //---------------------------------------------------------------
  1675 //---------------------------------------------------------------
  1143 // MsgUnifiedEditorView::doLayout
  1676 void MsgUnifiedEditorView::vkbAboutToOpen()
  1144 // @see header file
  1677 {    
  1145 //---------------------------------------------------------------
  1678 	  //This is done to avoid user action on attachment
  1146 void MsgUnifiedEditorView::doLayout()
  1679 	  //toolbar button when vkb is opening
  1147 {
  1680     mAttachAction->setDisabled(true);
  1148     if(mFocusedWidget && mVkbHost->keypadStatus() == HbVkbHost::HbVkbStatusOpened)
  1681     disconnect(mVkbHost,SIGNAL(aboutToOpen()),
  1149     {
  1682             this,SLOT(vkbAboutToOpen()));
  1150         if(this->mainWindow()->orientation() == Qt::Vertical)
  1683 }
  1151         {
  1684       
  1152             ensureVisibility();
  1685 //---------------------------------------------------------------
  1153         }
  1686 // MsgUnifiedEditorView::vkbAboutToClose
  1154         else 
  1687 // @see header file
  1155         {
  1688 //---------------------------------------------------------------
  1156             qreal vItemSpacing = 0.0;
  1689 void MsgUnifiedEditorView::vkbAboutToClose()
  1157             style()->parameter("hb-param-margin-gene-middle-vertical",vItemSpacing); 
  1690 {      
  1158             
  1691     mAttachAction->setDisabled(false);
  1159             if(mScrollArea->isAncestorOf(mFocusedWidget))
  1692     connect(mVkbHost,SIGNAL(aboutToOpen()),
  1160             {
  1693             this,SLOT(vkbAboutToOpen()));
  1161                 QPointF p = mScrollArea->mapFromScene(mFocusedWidget->scenePos());
       
  1162                 mScrollArea->scrollContentsTo(p,0);
       
  1163                 mScrollArea->enableScrolling(false);
       
  1164                 mScrollArea->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
       
  1165             }
       
  1166 
       
  1167             QPointF pp = mapFromScene(mFocusedWidget->scenePos());
       
  1168             qreal delta = pp.y() - vItemSpacing;
       
  1169             this->setTransform(QTransform::fromTranslate(0, -delta), true);
       
  1170         }
       
  1171     }
       
  1172 }
       
  1173 
       
  1174 //---------------------------------------------------------------
       
  1175 // MsgUnifiedEditorView::resetLayout
       
  1176 // @see header file
       
  1177 //---------------------------------------------------------------
       
  1178 void MsgUnifiedEditorView::resetLayout()
       
  1179 {
       
  1180     //disconnect signal from previously focused object.
       
  1181     if(mFocusedWidget)
       
  1182     {
       
  1183         HbAbstractEdit* editor = qobject_cast<HbAbstractEdit*>(mFocusedWidget);
       
  1184         disconnect(editor,SIGNAL(contentsChanged()),this,SLOT(ensureVisibility()));
       
  1185     }
       
  1186 
       
  1187     if(this->mainWindow()->orientation() == Qt::Vertical)
       
  1188     {
       
  1189         this->setMaximumHeight(-1);
       
  1190         mScrollArea->scrollContentsTo(QPointF(0,0),0);
       
  1191         mScrollArea->resize(-1,-1);
       
  1192     }
       
  1193     else
       
  1194     {
       
  1195         this->resetTransform(); 
       
  1196 
       
  1197         if(mFocusedWidget)
       
  1198         {
       
  1199             if(mMinHeight >0)
       
  1200             {
       
  1201                 mFocusedWidget->setMinimumHeight(mMinHeight);
       
  1202                 mMinHeight = 0.0;
       
  1203             }
       
  1204             if(mMaxHeight >0)
       
  1205             {
       
  1206                 mFocusedWidget->setMaximumHeight(mMaxHeight);
       
  1207                 mMaxHeight = 0.0;
       
  1208             }
       
  1209 
       
  1210             if(mScrollArea->isAncestorOf(mFocusedWidget))
       
  1211             {
       
  1212                 mScrollArea->enableScrolling(true);
       
  1213                 mScrollArea->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAutoHide); 
       
  1214                 mScrollArea->scrollContentsTo(QPointF(0,0),0);
       
  1215             }
       
  1216 
       
  1217             mFocusedWidget = NULL;
       
  1218         }
       
  1219 
       
  1220     }
       
  1221 }
       
  1222 
       
  1223 //---------------------------------------------------------------
       
  1224 // MsgUnifiedEditorView::ensureVisibility
       
  1225 // @see header file
       
  1226 //---------------------------------------------------------------
       
  1227 void MsgUnifiedEditorView::ensureVisibility()
       
  1228 {
       
  1229     if(mFocusedWidget && mVkbHost->keypadStatus() == HbVkbHost::HbVkbStatusOpened)
       
  1230     {
       
  1231         if(this->mainWindow()->orientation() == Qt::Vertical)
       
  1232         {
       
  1233             if ( mScrollArea->isAncestorOf(mFocusedWidget)) 
       
  1234             {
       
  1235                 QRectF scrollRect = mScrollArea->sceneBoundingRect();
       
  1236                 QRectF editorRect = mFocusedWidget->sceneBoundingRect();
       
  1237 
       
  1238                 if (!scrollRect.contains(editorRect) ||
       
  1239                     scrollRect.intersects(editorRect))
       
  1240                 {
       
  1241 
       
  1242                     if (editorRect.height() < scrollRect.height()) {
       
  1243                         // Whole editor rect fits into scroll area. Move it there.
       
  1244                         if (editorRect.bottom() > scrollRect.bottom()) {
       
  1245                             // Scroll upwards.                    
       
  1246                             mScrollArea->ensureVisible(mScrollArea->contentWidget()->mapFromScene(editorRect.bottomLeft()));
       
  1247                         } else {
       
  1248                             // Scroll downwards.                        
       
  1249                             mScrollArea->ensureVisible(mScrollArea->contentWidget()->mapFromScene(editorRect.topLeft()));
       
  1250                         }
       
  1251                     } 
       
  1252                 }
       
  1253             }
       
  1254         }
       
  1255     }
       
  1256 }
       
  1257 
       
  1258 //---------------------------------------------------------------
       
  1259 // MsgUnifiedEditorView::focusChanged
       
  1260 // @see header file
       
  1261 //---------------------------------------------------------------
       
  1262 void MsgUnifiedEditorView::focusChanged()
       
  1263 {
       
  1264     //disconnect signal from previously focused object.
       
  1265     if(mFocusedWidget)
       
  1266     {
       
  1267         HbAbstractEdit* editor = qobject_cast<HbAbstractEdit*>(mFocusedWidget);
       
  1268         disconnect(editor,SIGNAL(contentsChanged()),this,SLOT(ensureVisibility()));
       
  1269     }
       
  1270     
       
  1271     //connect signal for newly focused object.
       
  1272     HbInputMethod* im =   HbInputMethod::activeInputMethod(); 
       
  1273     HbInputFocusObject* focusObj =   im->focusObject();
       
  1274     if(focusObj)
       
  1275     {
       
  1276         QObject* obj =   focusObj->object(); 
       
  1277         mFocusedWidget = qobject_cast<QGraphicsWidget*>(obj); 
       
  1278         HbAbstractEdit* editor = qobject_cast<HbAbstractEdit*>(obj);
       
  1279         if(editor)
       
  1280         {
       
  1281             connect(editor,SIGNAL(contentsChanged()),this,SLOT(ensureVisibility()));
       
  1282         }
       
  1283     }
  1694 }
  1284 }
  1695 
  1285 
  1696 //---------------------------------------------------------------
  1286 //---------------------------------------------------------------
  1697 // MsgUnifiedEditorView::onAudioSelected
  1287 // MsgUnifiedEditorView::onAudioSelected
  1698 // @see header file
  1288 // @see header file
  1699 //---------------------------------------------------------------
  1289 //---------------------------------------------------------------
  1700 void 
  1290 void MsgUnifiedEditorView::onAudioSelected(QString& filePath)
  1701 MsgUnifiedEditorView::onAudioSelected(QString& filePath)
       
  1702 {
  1291 {
  1703     if (!filePath.isEmpty())
  1292     if (!filePath.isEmpty())
  1704         {
  1293     {
  1705             mBody->setAudio(filePath);
  1294         mScrollArea->setAudio(filePath);
  1706         }    
  1295     }    
  1707 }
  1296 }
  1708 
  1297 
  1709 //---------------------------------------------------------------
  1298 //---------------------------------------------------------------
  1710 // MsgUnifiedEditorView::hideChrome
  1299 // MsgUnifiedEditorView::hideChrome
  1711 //
  1300 //
  1728 // MsgUnifiedEditorView::doDelayedConstruction
  1317 // MsgUnifiedEditorView::doDelayedConstruction
  1729 //
  1318 //
  1730 //---------------------------------------------------------------
  1319 //---------------------------------------------------------------
  1731 void MsgUnifiedEditorView::doDelayedConstruction()
  1320 void MsgUnifiedEditorView::doDelayedConstruction()
  1732 {
  1321 {
  1733     addMenu();
       
  1734     createTempFolder();
  1322     createTempFolder();
  1735     
  1323     
  1736     //Create VKB instance and listen to VKB open and close signals.
  1324     //Create VKB instance and listen to VKB open and close signals.
  1737     mVkbHost = new HbAbstractVkbHost(this);
  1325     mVkbHost = new MsgUniEditorVkbHost(this);
       
  1326     
       
  1327     connect(mVkbHost, SIGNAL(focusChanged()), this, SLOT(focusChanged()));
  1738     connect(mVkbHost, SIGNAL(keypadOpened()), this, SLOT(vkbOpened()));
  1328     connect(mVkbHost, SIGNAL(keypadOpened()), this, SLOT(vkbOpened()));
  1739     connect(mVkbHost, SIGNAL(keypadClosed()), this, SLOT(vkbClosed()));
  1329     connect(mVkbHost, SIGNAL(keypadClosed()), this, SLOT(vkbClosed()));
  1740     connect(mVkbHost,SIGNAL(aboutToOpen()),this,SLOT(vkbAboutToOpen()));
       
  1741     connect(mVkbHost,SIGNAL(aboutToClose()),this,SLOT(vkbAboutToClose()));
       
  1742     
  1330     
  1743     disconnect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(doDelayedConstruction()));
  1331     disconnect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(doDelayedConstruction()));
  1744     
       
  1745 }
  1332 }
  1746 
  1333 
  1747 //---------------------------------------------------------------
  1334 //---------------------------------------------------------------
  1748 // MsgUnifiedEditorView::createTempFolder
  1335 // MsgUnifiedEditorView::createTempFolder
  1749 //
  1336 //
  1824         //trigger back action.
  1411         //trigger back action.
  1825         HbAction* backAction = this->navigationAction();
  1412         HbAction* backAction = this->navigationAction();
  1826         if (backAction) {
  1413         if (backAction) {
  1827             backAction->trigger();
  1414             backAction->trigger();
  1828         }
  1415         }
  1829 
       
  1830     }
  1416     }
  1831 }
  1417 }
  1832 
  1418 
  1833 //---------------------------------------------------------------
  1419 //---------------------------------------------------------------
  1834 // MsgUnifiedEditorView::onDialogSmsSettings
  1420 // MsgUnifiedEditorView::onDialogSmsSettings
  1835 //---------------------------------------------------------------
  1421 //---------------------------------------------------------------
  1836 void MsgUnifiedEditorView::onDialogSmsSettings(HbAction* action)
  1422 void MsgUnifiedEditorView::onDialogSmsSettings(HbAction* action)
  1837 {
  1423 {
  1838     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
  1424     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
  1839     if (action == dlg->actions().at(0)) {
  1425     if (action == dlg->actions().at(0))
  1840         
  1426     {
  1841         QVariantList params;
  1427         QVariantList params;
  1842         params << MsgBaseView::MSGSETTINGS;// target view
  1428         params << MsgBaseView::MSGSETTINGS;// target view
  1843         params << MsgBaseView::UNIEDITOR; // source view
  1429         params << MsgBaseView::UNIEDITOR; // source view
  1844         params << MsgSettingsView::SMSView;
  1430         params << MsgSettingsView::SMSView;
  1845         emit switchView(params);
  1431         emit switchView(params);
  1846     
       
  1847     }
  1432     }
  1848 }
  1433 }
  1849 
  1434 
  1850 //---------------------------------------------------------------
  1435 //---------------------------------------------------------------
  1851 // MsgUnifiedEditorView::onDialogMmsSettings
  1436 // MsgUnifiedEditorView::onDialogMmsSettings
  1861         params << MsgSettingsView::MMSView;
  1446         params << MsgSettingsView::MMSView;
  1862         emit switchView(params); 
  1447         emit switchView(params); 
  1863     }
  1448     }
  1864 }
  1449 }
  1865 
  1450 
  1866 //---------------------------------------------------------------
       
  1867 // MsgUnifiedEditorView::enableSendButton
       
  1868 // @see header file
       
  1869 //--------------------------------------------------------------
       
  1870 void MsgUnifiedEditorView::enableSendButton(bool enable)
       
  1871     {
       
  1872     if(mSendAction)
       
  1873         {
       
  1874          // enable/disable based on only if its disabled/enabled.
       
  1875          // this check is to avoid unnecessary calls to mSendAction->setEnabled(enable);
       
  1876         if(mSendAction->isEnabled() != enable )
       
  1877             mSendAction->setEnabled(enable);
       
  1878         }
       
  1879     }
       
  1880 
       
  1881 // ----------------------------------------------------------------------------
       
  1882 // MsgUnifiedEditorView::formatAddresses
       
  1883 // @see header
       
  1884 // ----------------------------------------------------------------------------
       
  1885 void MsgUnifiedEditorView::formatAddresses(
       
  1886         ConvergedMessageAddressList& addresses)
       
  1887 {       
       
  1888 
       
  1889     for(int i=0; i < addresses.count() ;i++ )
       
  1890     {
       
  1891         QString addr = addresses[i]->address();
       
  1892         
       
  1893         HBufC *tempAddr = XQConversions::qStringToS60Desc(addr);     
       
  1894             
       
  1895         TPtr ptr = tempAddr->Des();
       
  1896                     
       
  1897          // Note: This is just to parse spaces etc away from phonenumbers.
       
  1898          //       Ignore EFalse returned for email addresses.   
       
  1899         CommonPhoneParser::ParsePhoneNumber(ptr , 
       
  1900                                             CommonPhoneParser::ESMSNumber );        
       
  1901        
       
  1902         addr = XQConversions::s60DescToQString(tempAddr->Des()); 
       
  1903         
       
  1904         addresses[i]->setAddress(addr);
       
  1905         
       
  1906         delete tempAddr;                                                       
       
  1907     }       
       
  1908 }
       
  1909 
       
  1910 // ----------------------------------------------------------------------------
  1451 // ----------------------------------------------------------------------------
  1911 // MsgUnifiedEditorView::isReplyPathBroken
  1452 // MsgUnifiedEditorView::isReplyPathBroken
  1912 // @see header
  1453 // @see header
  1913 // ----------------------------------------------------------------------------
  1454 // ----------------------------------------------------------------------------
  1914 bool MsgUnifiedEditorView::isReplyPathBroken()
  1455 bool MsgUnifiedEditorView::isReplyPathBroken()
  1915 {
  1456 {
  1916     // 1. Never set for MMS
  1457     // 1. Never set for MMS
  1917     // 2. if additional recipients exits
  1458     // 2. if additional recipients exits
  1918     if( (MsgUnifiedEditorMonitor::messageType() == ConvergedMessage::Mms) ||
  1459     if( (MsgUnifiedEditorMonitor::messageType() == ConvergedMessage::Mms) ||
  1919         (mToField->addressCount() != 1) )
  1460         (MsgUnifiedEditorMonitor::msgAddressCount() != 1) )
  1920     {
  1461     {
  1921         // broken
  1462         // broken
  1922         return true;
  1463         return true;
  1923     }
  1464     }
  1924 
  1465 
  1925     // 3. if only recipient is not same as originating SME
  1466     // 3. if only recipient is not same as originating SME
  1926     QString dispName;
  1467     QString dispName;
  1927     int phCount;
  1468     int phCount;
  1928     int origCntLocalId = MsgContactHandler::resolveContactDisplayName(
  1469     int origCntLocalId = MsgContactHandler::resolveContactDisplayName(
  1929             mOriginatingSME, dispName, phCount);
  1470         mOriginatingSME, dispName, phCount);
  1930     int currCntLocalId = -1;
  1471     int currCntLocalId = -1;
  1931     QString currAddress(mToField->addresses().at(0)->address());
  1472     QString currAddress;
       
  1473     ConvergedMessageAddress* currentAdd = mScrollArea->currentAddress();
       
  1474     if(currentAdd)
       
  1475     {
       
  1476         currAddress = currentAdd->address();
       
  1477         delete currentAdd;
       
  1478     }
       
  1479     
  1932     if(origCntLocalId != -1)
  1480     if(origCntLocalId != -1)
  1933     {
  1481     {
  1934         currCntLocalId = MsgContactHandler::resolveContactDisplayName(
  1482         currCntLocalId = MsgContactHandler::resolveContactDisplayName(
  1935             currAddress, dispName, phCount);
  1483             currAddress, dispName, phCount);
  1936     }
  1484     }
  1942             return true;
  1490             return true;
  1943         }
  1491         }
  1944     }
  1492     }
  1945     else
  1493     else
  1946     { // atleast one contact is not present in contacts db
  1494     { // atleast one contact is not present in contacts db
  1947       // direct compare
  1495         // direct compare
  1948         UniEditorGenUtils* genUtils = q_check_ptr(new UniEditorGenUtils);
  1496         UniEditorGenUtils* genUtils = q_check_ptr(new UniEditorGenUtils);
  1949         bool compareResult = false;
  1497         bool compareResult = false;
  1950         TRAP_IGNORE(
  1498         TRAP_IGNORE(
  1951         compareResult = genUtils->MatchPhoneNumberL(
  1499             compareResult = genUtils->MatchPhoneNumberL(
  1952                 *XQConversions::qStringToS60Desc(mOriginatingSME),
  1500                 *XQConversions::qStringToS60Desc(mOriginatingSME),
  1953                 *XQConversions::qStringToS60Desc(currAddress))
  1501                 *XQConversions::qStringToS60Desc(currAddress))
  1954         );
  1502         );
  1955         delete genUtils;
  1503         delete genUtils;
  1956         if(!compareResult)
  1504         if(!compareResult)