phonebookui/pbkcommonui/src/cntgroupactionsview.cpp
changeset 50 77bc263e1626
parent 40 b46a585f6909
child 53 e6aff7b69165
equal deleted inserted replaced
49:74b30151afd6 50:77bc263e1626
    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>
    37 
    41 
    38 CntGroupActionsView::CntGroupActionsView() :
    42 CntGroupActionsView::CntGroupActionsView() :
    39 mGroupContact(NULL),
    43 mGroupContact(NULL),
    40 mModel(NULL),
    44 mModel(NULL),
    41 mViewManager(NULL),
    45 mViewManager(NULL),
    42 mListView(NULL)
    46 mListView(NULL),
       
    47 mPopupCount(0)
    43 {
    48 {
    44     bool ok = false;
    49     bool ok = false;
    45     mDocumentLoader.load(CNT_GROUPACTIONSVIEW_XML, &ok);
    50     mDocumentLoader.load(CNT_GROUPACTIONSVIEW_XML, &ok);
    46   
    51   
    47     if (ok)
    52     if (ok)
   118         mView->setNavigationAction(mSoftkey);   
   123         mView->setNavigationAction(mSoftkey);   
   119     
   124     
   120     mGroupContact = new QContact(aArgs.value(ESelectedGroupContact).value<QContact>());
   125     mGroupContact = new QContact(aArgs.value(ESelectedGroupContact).value<QContact>());
   121     mViewManager = aMgr;
   126     mViewManager = aMgr;
   122 
   127 
   123     QContactName groupContactName = mGroupContact->detail( QContactName::DefinitionName );
   128     QString groupName = mGroupContact->displayLabel();
   124     QString groupName(groupContactName.value( QContactName::FieldCustomLabel ));
   129     if (groupName.isEmpty())
   125     
   130     {
       
   131         groupName = hbTrId("txt_phob_list_unnamed");
       
   132     }
   126     
   133     
   127     //group box
   134     //group box
   128     HbGroupBox* groupBox = static_cast<HbGroupBox *>(mDocumentLoader.findWidget(QString("groupBox")));
   135     HbGroupBox* groupBox = static_cast<HbGroupBox *>(mDocumentLoader.findWidget(QString("groupBox")));
   129     groupBox->setHeading(groupName);
   136     groupBox->setHeading(groupName);
   130     
   137     
   143     
   150     
   144     mModel = new QStandardItemModel();
   151     mModel = new QStandardItemModel();
   145     
   152     
   146     QContactPhoneNumber confCallNumber = mGroupContact->detail<QContactPhoneNumber>();
   153     QContactPhoneNumber confCallNumber = mGroupContact->detail<QContactPhoneNumber>();
   147     if(!confCallNumber.number().isEmpty())
   154     if(!confCallNumber.number().isEmpty())
   148         {
   155     {
   149         /*
   156         /*
   150          * Internationalization support, activate the following code 
   157          * Internationalization support, activate the following code 
   151          * when support available from Orbit
   158          * when support available from Orbit
   152          */
   159          */
   153         //populatelist(hbTrId("txt_phob_dblist_conference_call"), HbIcon("qtg_large_call_group"),HbNumberGrouping::formatPhoneNumber(confCallNumber.number()));
   160         //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());
   161         populatelist(hbTrId("txt_phob_dblist_conference_call"), HbIcon("qtg_large_call_group"),confCallNumber.number(),"call");
   155         }
   162     }
   156       
   163       
   157     populatelist(hbTrId("txt_phob_dblist_send_message"),HbIcon("qtg_large_message_group"),hbTrId("txt_phob_dblist_send_message_val_members"));
   164     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"));
   165     populatelist(hbTrId("txt_phob_dblist_email"),HbIcon("qtg_large_email_group"),hbTrId("txt_phob_dblist_send_message_val_members"),"email");
   159     
   166     
   160     mListView->setModel(mModel);
   167     mListView->setModel(mModel);
   161     mListView->setSelectionMode(HbAbstractItemView::NoSelection);
   168     mListView->setSelectionMode(HbAbstractItemView::NoSelection);
   162     
   169     
   163 }
   170     connect(mListView, SIGNAL(activated(const QModelIndex&)),
   164 
   171                 this, SLOT(listItemSelected(const QModelIndex&)));
   165 void CntGroupActionsView:: populatelist(QString primaryText,HbIcon icon,QString secondaryText)
   172     
       
   173 }
       
   174 
       
   175 void CntGroupActionsView::populatelist(QString primaryText,HbIcon icon,QString secondaryText,QString action)
   166 {
   176 {
   167     QList<QStandardItem*> items;
   177     QList<QStandardItem*> items;
   168     QStandardItem *labelItem = new QStandardItem();
   178     QStandardItem *labelItem = new QStandardItem();
   169     
   179     
   170     QStringList textList;
   180     QStringList textList;
   171    
   181    
   172     textList << primaryText << secondaryText;
   182     textList << primaryText << secondaryText;
   173     
   183     
   174     labelItem->setData(textList, Qt::DisplayRole);
   184     labelItem->setData(textList, Qt::DisplayRole);
   175     labelItem->setData(icon, Qt::DecorationRole);
   185     labelItem->setData(icon, Qt::DecorationRole);
       
   186     labelItem->setData(action, Qt::UserRole+1);
   176     
   187     
   177     items << labelItem ;
   188     items << labelItem ;
   178     mModel->appendRow(items);
   189     mModel->appendRow(items);
   179 }
   190 }
       
   191 
       
   192 void CntGroupActionsView::listItemSelected(const QModelIndex &index)
       
   193 {
       
   194     if (index.isValid()) {
       
   195         //reset flags
       
   196         mPopupCount=0;
       
   197         mActionParams.clear();
       
   198         
       
   199         QString action = mModel->item(index.row())->data(Qt::UserRole+1).toString();
       
   200         
       
   201         //conference call
       
   202         if (action.compare("call", Qt::CaseInsensitive) == 0 ) {
       
   203             CntActionLauncher* other = new CntActionLauncher(*mViewManager->contactManager(SYMBIAN_BACKEND), action);
       
   204             connect(other, SIGNAL(actionExecuted(CntActionLauncher*)), this, SLOT(actionExecuted(CntActionLauncher*)));
       
   205             other->execute(*mGroupContact, QContactDetail());
       
   206         }
       
   207         //group email, message
       
   208         else {
       
   209             QContactRelationshipFilter relationshipFilter;
       
   210             relationshipFilter.setRelationshipType(QContactRelationship::HasMember);
       
   211             relationshipFilter.setRelatedContactRole(QContactRelationship::First);
       
   212             relationshipFilter.setRelatedContactId(mGroupContact->id());   
       
   213             QList<QContactLocalId> groupMembers = mViewManager->contactManager(SYMBIAN_BACKEND)->contactIds(relationshipFilter);
       
   214             
       
   215             for (int i = 0;i<groupMembers.count();i++) {
       
   216                 QContact contact = mViewManager->contactManager(SYMBIAN_BACKEND)->contact(groupMembers.at(i));
       
   217                 QContactDetail preferredDetail = contact.preferredDetail(action);
       
   218                 //use preferred detail if exits
       
   219                 if (!preferredDetail.isEmpty()) {
       
   220                     if(action.compare("message", Qt::CaseInsensitive) == 0) {
       
   221                         QContactPhoneNumber phoneNumber = contact.detail<QContactPhoneNumber>();
       
   222                         mActionParams.append(phoneNumber.number());
       
   223                     }
       
   224                     else {
       
   225                         QContactEmailAddress email = contact.detail<QContactEmailAddress>();
       
   226                         mActionParams.append(email.emailAddress());
       
   227                     }
       
   228                 }
       
   229                 else {
       
   230                     CntActionPopup *actionPopup = new CntActionPopup(&contact);
       
   231                     if(actionPopup->showActionPopup(action)) {
       
   232                         //increment actionpopup counter
       
   233                         mPopupCount++;
       
   234                         
       
   235                         connect( actionPopup, SIGNAL(executeContactAction(QContact&, QContactDetail, QString)), this, 
       
   236                                                     SLOT(executeAction(QContact&, QContactDetail, QString)));
       
   237                         connect(actionPopup, SIGNAL(actionPopupCancelPressed()), this, SLOT(actionCancelled()));
       
   238                     }
       
   239                     else {
       
   240                         delete actionPopup;
       
   241                     }
       
   242                 }
       
   243             }
       
   244             //no popup dialog, execute action
       
   245             if (mPopupCount==0) {
       
   246                 QVariantMap map;
       
   247                 QVariant params;
       
   248                 params.setValue(mActionParams);
       
   249                 map.insert(action,params);
       
   250                 CntActionLauncher* other = new CntActionLauncher(*mViewManager->contactManager(SYMBIAN_BACKEND), action);
       
   251                 connect(other, SIGNAL(actionExecuted(CntActionLauncher*)), this, SLOT(actionExecuted(CntActionLauncher*)));
       
   252                 other->execute(*mGroupContact, QContactDetail(), map);
       
   253             }
       
   254         }
       
   255     }
       
   256 }
       
   257 
       
   258 void CntGroupActionsView::executeAction(QContact& contact, QContactDetail detail, QString action)
       
   259 {
       
   260     Q_UNUSED(contact);
       
   261     
       
   262     if (action.compare("message", Qt::CaseInsensitive) == 0) {
       
   263         QContactPhoneNumber phoneNumber = static_cast<QContactPhoneNumber>(detail);
       
   264         mActionParams.append(phoneNumber.number());
       
   265     }
       
   266     else if (action.compare("email", Qt::CaseInsensitive) == 0) {
       
   267         QContactEmailAddress email = static_cast<QContactEmailAddress>(detail);
       
   268         mActionParams.append(email.emailAddress());
       
   269     }
       
   270     
       
   271     //actionpopup executed, decrement counter
       
   272     mPopupCount--;
       
   273     if (mPopupCount==0) {
       
   274         QVariantMap map;
       
   275         QVariant params;
       
   276         params.setValue(mActionParams);
       
   277         map.insert(action,params);
       
   278         
       
   279         CntActionLauncher* other = new CntActionLauncher(*mViewManager->contactManager(SYMBIAN_BACKEND), action);
       
   280         connect(other, SIGNAL(actionExecuted(CntActionLauncher*)), this, SLOT(actionExecuted(CntActionLauncher*)));
       
   281         other->execute(*mGroupContact, QContactDetail(), map);
       
   282         }
       
   283 }
       
   284 
       
   285 void CntGroupActionsView::actionCancelled()
       
   286 {
       
   287     //actionpopup cancelled, decrement counter
       
   288     mPopupCount--;
       
   289 }
       
   290 
       
   291 
       
   292 void CntGroupActionsView::actionExecuted(CntActionLauncher* aAction)
       
   293 {
       
   294     //cleanup
       
   295     aAction->deleteLater();
       
   296 }
       
   297