phonebookui/pbkcommonui/src/cntgroupactionsview.cpp
changeset 59 a642906a277a
parent 40 b46a585f6909
child 65 ae724a111993
equal deleted inserted replaced
47:7cbcb2896f0e 59:a642906a277a
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include "cntgroupactionsview.h"
    18 #include "cntgroupactionsview.h"
       
    19 #include "cntactionlauncher.h"
       
    20 #include "cntglobal.h"
       
    21 
       
    22 #include <cntactionpopup.h>
    19 
    23 
    20 #include <hblistview.h>
    24 #include <hblistview.h>
    21 #include <hbmenu.h>
    25 #include <hbmenu.h>
    22 #include <hbaction.h>
    26 #include <hbaction.h>
    23 #include <hblistview.h>
    27 #include <hblistview.h>
    28 #include <hbicon.h>
    32 #include <hbicon.h>
    29 #include <hbgroupbox.h>
    33 #include <hbgroupbox.h>
    30 #include <cntlistmodel.h>
    34 #include <cntlistmodel.h>
    31 #include <hbframebackground.h>
    35 #include <hbframebackground.h>
    32 #include <hbnumbergrouping.h>
    36 #include <hbnumbergrouping.h>
    33 
    37 #include <QKeyEvent> 
       
    38 #include <qtcontacts.h>
       
    39 #include <hbmainwindow.h>
       
    40 #include "cntactionlauncher.h"
       
    41 
       
    42 #include <QEvent>
    34 #include <QStandardItemModel>
    43 #include <QStandardItemModel>
    35 
    44 
    36 const char *CNT_GROUPACTIONSVIEW_XML = ":/xml/contacts_groupactions.docml";
    45 const char *CNT_GROUPACTIONSVIEW_XML = ":/xml/contacts_groupactions.docml";
    37 
    46 
    38 CntGroupActionsView::CntGroupActionsView() :
    47 CntGroupActionsView::CntGroupActionsView() :
    39 mGroupContact(NULL),
    48 mGroupContact(NULL),
    40 mModel(NULL),
    49 mModel(NULL),
    41 mViewManager(NULL),
    50 mViewManager(NULL),
    42 mListView(NULL)
    51 mListView(NULL),
       
    52 mPopupCount(0),
       
    53 mIsExecutingAction(false)
    43 {
    54 {
    44     bool ok = false;
    55     bool ok = false;
    45     mDocumentLoader.load(CNT_GROUPACTIONSVIEW_XML, &ok);
    56     mDocumentLoader.load(CNT_GROUPACTIONSVIEW_XML, &ok);
    46   
    57   
    47     if (ok)
    58     if (ok)
   118         mView->setNavigationAction(mSoftkey);   
   129         mView->setNavigationAction(mSoftkey);   
   119     
   130     
   120     mGroupContact = new QContact(aArgs.value(ESelectedGroupContact).value<QContact>());
   131     mGroupContact = new QContact(aArgs.value(ESelectedGroupContact).value<QContact>());
   121     mViewManager = aMgr;
   132     mViewManager = aMgr;
   122 
   133 
   123     QContactName groupContactName = mGroupContact->detail( QContactName::DefinitionName );
   134     QContactName contactName = mGroupContact->detail( QContactName::DefinitionName );
   124     QString groupName(groupContactName.value( QContactName::FieldCustomLabel ));
   135     QString groupName = contactName.value( QContactName::FieldCustomLabel );        
   125     
   136     if (groupName.isEmpty())
       
   137     {
       
   138         groupName = hbTrId("txt_phob_list_unnamed");
       
   139     }
   126     
   140     
   127     //group box
   141     //group box
   128     HbGroupBox* groupBox = static_cast<HbGroupBox *>(mDocumentLoader.findWidget(QString("groupBox")));
   142     HbGroupBox* groupBox = static_cast<HbGroupBox *>(mDocumentLoader.findWidget(QString("groupBox")));
   129     groupBox->setHeading(groupName);
   143     groupBox->setHeading(groupName);
   130     
   144     
   143     
   157     
   144     mModel = new QStandardItemModel();
   158     mModel = new QStandardItemModel();
   145     
   159     
   146     QContactPhoneNumber confCallNumber = mGroupContact->detail<QContactPhoneNumber>();
   160     QContactPhoneNumber confCallNumber = mGroupContact->detail<QContactPhoneNumber>();
   147     if(!confCallNumber.number().isEmpty())
   161     if(!confCallNumber.number().isEmpty())
   148         {
   162     {
   149         /*
   163         /*
   150          * Internationalization support, activate the following code 
   164          * Internationalization support, activate the following code 
   151          * when support available from Orbit
   165          * when support available from Orbit
   152          */
   166          */
   153         //populatelist(hbTrId("txt_phob_dblist_conference_call"), HbIcon("qtg_large_call_group"),HbNumberGrouping::formatPhoneNumber(confCallNumber.number()));
   167         //populatelist(hbTrId("txt_phob_dblist_conference_call"), HbIcon("qtg_large_call_group"),HbNumberGrouping::formatPhoneNumber(confCallNumber.number()));
   154         populatelist(hbTrId("txt_phob_dblist_conference_call"), HbIcon("qtg_large_call_group"),confCallNumber.number());
   168         populatelist(hbTrId("txt_phob_dblist_conference_call"), HbIcon("qtg_large_call_group"),confCallNumber.number(),"call");
   155         }
   169     }
   156       
   170       
   157     populatelist(hbTrId("txt_phob_dblist_send_message"),HbIcon("qtg_large_message_group"),hbTrId("txt_phob_dblist_send_message_val_members"));
   171     populatelist(hbTrId("txt_phob_dblist_send_message"),HbIcon("qtg_large_message_group"),hbTrId("txt_phob_dblist_send_message_val_members"),"message");
   158     populatelist(hbTrId("txt_phob_dblist_email"),HbIcon("qtg_large_email_group"),hbTrId("txt_phob_dblist_send_message_val_members"));
   172     populatelist(hbTrId("txt_phob_dblist_email"),HbIcon("qtg_large_email_group"),hbTrId("txt_phob_dblist_send_message_val_members"),"email");
   159     
   173     
   160     mListView->setModel(mModel);
   174     mListView->setModel(mModel);
   161     mListView->setSelectionMode(HbAbstractItemView::NoSelection);
   175     mListView->setSelectionMode(HbAbstractItemView::NoSelection);
   162     
   176     
   163 }
   177     connect(mListView, SIGNAL(activated(const QModelIndex&)),
   164 
   178                 this, SLOT(listItemSelected(const QModelIndex&)));
   165 void CntGroupActionsView:: populatelist(QString primaryText,HbIcon icon,QString secondaryText)
   179     
       
   180     HbMainWindow* window = mView->mainWindow();
       
   181     if (window)
       
   182     {
       
   183         window->installEventFilter(this);
       
   184     }
       
   185 }
       
   186 
       
   187 void CntGroupActionsView::populatelist(QString primaryText,HbIcon icon,QString secondaryText,QString action)
   166 {
   188 {
   167     QList<QStandardItem*> items;
   189     QList<QStandardItem*> items;
   168     QStandardItem *labelItem = new QStandardItem();
   190     QStandardItem *labelItem = new QStandardItem();
   169     
   191     
   170     QStringList textList;
   192     QStringList textList;
   171    
   193    
   172     textList << primaryText << secondaryText;
   194     textList << primaryText << secondaryText;
   173     
   195     
   174     labelItem->setData(textList, Qt::DisplayRole);
   196     labelItem->setData(textList, Qt::DisplayRole);
   175     labelItem->setData(icon, Qt::DecorationRole);
   197     labelItem->setData(icon, Qt::DecorationRole);
       
   198     labelItem->setData(action, Qt::UserRole+1);
   176     
   199     
   177     items << labelItem ;
   200     items << labelItem ;
   178     mModel->appendRow(items);
   201     mModel->appendRow(items);
   179 }
   202 }
       
   203 
       
   204 void CntGroupActionsView::listItemSelected(const QModelIndex &index)
       
   205 {
       
   206     if (index.isValid()) {
       
   207         //reset flags
       
   208         mPopupCount=0;
       
   209         mEmailActionParams.clear();
       
   210         mMessageActionParams.clear();
       
   211         
       
   212         QString action = mModel->item(index.row())->data(Qt::UserRole+1).toString();
       
   213         
       
   214         //conference call
       
   215         if (action.compare("call", Qt::CaseInsensitive) == 0 ) {
       
   216             CntActionLauncher* other = new CntActionLauncher(*mViewManager->contactManager(SYMBIAN_BACKEND), action);
       
   217             connect(other, SIGNAL(actionExecuted(CntActionLauncher*)), this, SLOT(actionExecuted(CntActionLauncher*)));
       
   218             other->execute(*mGroupContact, QContactDetail());
       
   219         }
       
   220         //group email, message
       
   221         else {
       
   222             QContactRelationshipFilter relationshipFilter;
       
   223             relationshipFilter.setRelationshipType(QContactRelationship::HasMember);
       
   224             relationshipFilter.setRelatedContactRole(QContactRelationship::First);
       
   225             relationshipFilter.setRelatedContactId(mGroupContact->id());   
       
   226             QList<QContactLocalId> groupMembers = mViewManager->contactManager(SYMBIAN_BACKEND)->contactIds(relationshipFilter);
       
   227             
       
   228             for (int i = 0;i<groupMembers.count();i++) {
       
   229                 QContact contact = mViewManager->contactManager(SYMBIAN_BACKEND)->contact(groupMembers.at(i));
       
   230                 QContactDetail preferredDetail = contact.preferredDetail(action);
       
   231                 //use preferred detail if exits
       
   232                 if (!preferredDetail.isEmpty()) {
       
   233                     if(action.compare("message", Qt::CaseInsensitive) == 0) {
       
   234                         QContactPhoneNumber phoneNumber = contact.detail<QContactPhoneNumber>();
       
   235                         mMessageActionParams.insert(phoneNumber.number(),QVariant(contact.displayLabel()));
       
   236                     }
       
   237                     else {
       
   238                         QContactEmailAddress email = contact.detail<QContactEmailAddress>();
       
   239                         mEmailActionParams.append(email.emailAddress());
       
   240                     }
       
   241                 }
       
   242                 else {
       
   243                     CntActionPopup *actionPopup = new CntActionPopup(&contact);
       
   244                     if(actionPopup->showActionPopup(action)) {
       
   245                         //increment actionpopup counter
       
   246                         mPopupCount++;
       
   247                         
       
   248                         connect( actionPopup, SIGNAL(executeContactAction(QContact&, QContactDetail, QString)), this, 
       
   249                                                     SLOT(executeAction(QContact&, QContactDetail, QString)));
       
   250                         connect(actionPopup, SIGNAL(actionPopupCancelPressed()), this, SLOT(actionCancelled()));
       
   251                     }
       
   252                     else {
       
   253                         delete actionPopup;
       
   254                     }
       
   255                 }
       
   256             }
       
   257             //no popup dialog, execute action
       
   258             if (mPopupCount==0) {
       
   259                 QVariantMap map;
       
   260                 QVariant params;
       
   261                 if (action.compare("message", Qt::CaseInsensitive) == 0) {
       
   262                     params.setValue(mMessageActionParams);
       
   263                 }
       
   264                 else if (action.compare("email", Qt::CaseInsensitive) == 0) {
       
   265                     params.setValue(mEmailActionParams);
       
   266                 }
       
   267                 map.insert(action,params);
       
   268                 CntActionLauncher* other = new CntActionLauncher(*mViewManager->contactManager(SYMBIAN_BACKEND), action);
       
   269                 connect(other, SIGNAL(actionExecuted(CntActionLauncher*)), this, SLOT(actionExecuted(CntActionLauncher*)));
       
   270                 other->execute(*mGroupContact, QContactDetail(), map);
       
   271             }
       
   272         }
       
   273     }
       
   274 }
       
   275 
       
   276 void CntGroupActionsView::executeAction(QContact& contact, QContactDetail detail, QString action)
       
   277 {
       
   278     Q_UNUSED(contact);
       
   279     
       
   280     if (action.compare("message", Qt::CaseInsensitive) == 0) {
       
   281         QContactPhoneNumber phoneNumber = static_cast<QContactPhoneNumber>(detail);
       
   282         mMessageActionParams.insert(phoneNumber.number(),QVariant(contact.displayLabel()));
       
   283     }
       
   284     else if (action.compare("email", Qt::CaseInsensitive) == 0) {
       
   285         QContactEmailAddress email = static_cast<QContactEmailAddress>(detail);
       
   286         mEmailActionParams.append(email.emailAddress());
       
   287     }
       
   288     
       
   289     //actionpopup executed, decrement counter
       
   290     mPopupCount--;
       
   291     if (mPopupCount==0) {
       
   292         QVariantMap map;
       
   293         QVariant params;
       
   294         if (action.compare("message", Qt::CaseInsensitive) == 0) {
       
   295             params.setValue(mMessageActionParams);
       
   296         }
       
   297         else if (action.compare("email", Qt::CaseInsensitive) == 0) {
       
   298             params.setValue(mEmailActionParams);
       
   299         }
       
   300         map.insert(action,params);
       
   301         
       
   302         CntActionLauncher* other = new CntActionLauncher(*mViewManager->contactManager(SYMBIAN_BACKEND), action);
       
   303         connect(other, SIGNAL(actionExecuted(CntActionLauncher*)), this, SLOT(actionExecuted(CntActionLauncher*)));
       
   304         other->execute(*mGroupContact, QContactDetail(), map);
       
   305         }
       
   306 }
       
   307 
       
   308 bool CntGroupActionsView::eventFilter(QObject *obj, QEvent *event)
       
   309 {
       
   310     if (event->type() == QEvent::KeyPress && obj == mView->mainWindow())
       
   311     {
       
   312         QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
       
   313         if (keyEvent->key() == Qt::Key_Yes)
       
   314         {
       
   315             return sendKeyPressed();
       
   316         }
       
   317     }
       
   318     return false;
       
   319 }
       
   320 
       
   321 bool CntGroupActionsView::sendKeyPressed()
       
   322 {   
       
   323     QList<QContactPhoneNumber> numberDetails = mGroupContact->details<QContactPhoneNumber>();
       
   324     bool keyConsumed = false;
       
   325         
       
   326     // check if conference call number is present
       
   327     if (!numberDetails.isEmpty()) 
       
   328     { 
       
   329         executeConferenceCallAction( *mGroupContact, mGroupContact->details<QContactPhoneNumber>().first(), "call");
       
   330         
       
   331         keyConsumed = true;
       
   332     }
       
   333     
       
   334     return keyConsumed;
       
   335 }
       
   336 
       
   337 void CntGroupActionsView::executeConferenceCallAction(QContact& aContact, const QContactDetail& aDetail, const QString& aAction)
       
   338 {
       
   339     if (mIsExecutingAction)
       
   340     {
       
   341         return;
       
   342     }
       
   343     else
       
   344     {
       
   345         mIsExecutingAction = true;
       
   346     }
       
   347     
       
   348     CntActionLauncher* other = new CntActionLauncher(*mViewManager->contactManager(SYMBIAN_BACKEND), aAction);
       
   349     connect(other, SIGNAL(actionExecuted(CntActionLauncher*)), this, SLOT(actionExecuted(CntActionLauncher*)));
       
   350     other->execute(aContact, aDetail);  
       
   351 }
       
   352 
       
   353 void CntGroupActionsView::actionCancelled()
       
   354 {
       
   355     //actionpopup cancelled, decrement counter
       
   356     mPopupCount--;
       
   357 }
       
   358 
       
   359 
       
   360 void CntGroupActionsView::actionExecuted(CntActionLauncher* aAction)
       
   361 {
       
   362     //cleanup
       
   363     aAction->deleteLater();
       
   364     mIsExecutingAction = false;
       
   365 }
       
   366