--- a/phonebookui/phonebookservices/src/cntservicecontactfetchview.cpp Tue Jul 06 14:05:47 2010 +0300
+++ b/phonebookui/phonebookservices/src/cntservicecontactfetchview.cpp Wed Aug 18 09:39:00 2010 +0300
@@ -19,25 +19,25 @@
#include <cntservicescontact.h>
#include <cntlistmodel.h>
-#include "cntservicehandler.h"
+#include "cntserviceviewparams.h"
#include <hbmenu.h>
#include <hbview.h>
#include <hblistview.h>
#include <hbdocumentloader.h>
#include <hbaction.h>
+#include "cntactionpopup.h"
#include <QCoreApplication>
-CntServiceContactFetchView::CntServiceContactFetchView(CntServiceHandler *aServiceHandler):
+CntServiceContactFetchView::CntServiceContactFetchView( CntAbstractServiceProvider& aServiceProvider ):
CntBaseSelectionView(),
-mServiceHandler(aServiceHandler)
-{
+mProvider( aServiceProvider )
+ {
HbAction* cancel = static_cast<HbAction*>( mDocument->findObject( "cnt:cancel" ) );
mView->menu()->addAction( cancel );
-
connect(cancel, SIGNAL(triggered()), this, SLOT(cancelFetch()) );
- connect( this, SIGNAL(viewClosed()), this, SLOT(aboutToCloseView()) );
+ connect( this, SIGNAL(viewClosed()), this, SLOT(closeFetchView()) );
connect( this, SIGNAL(viewOpened(CntAbstractViewManager*, const CntViewParameters)), this, SLOT(aboutToOpenView(CntAbstractViewManager*, const CntViewParameters)) );
}
@@ -47,51 +47,182 @@
void CntServiceContactFetchView::cancelFetch()
-{
- connect(mServiceHandler, SIGNAL(returnValueDelivered()), qApp, SLOT(quit()));
+ {
CntServicesContactList serviceList;
- mServiceHandler->completeFetch(serviceList);
-}
+ QVariant variant;
+ variant.setValue(serviceList);
+ mProvider.CompleteServiceAndCloseApp(variant);
+ }
-void CntServiceContactFetchView::aboutToCloseView()
+
+
+void CntServiceContactFetchView::closeFetchView()
{
- CntServicesContactList serviceList;
QContactManager* mgr = mMgr->contactManager(SYMBIAN_BACKEND);
QModelIndexList temp = mListView->selectionModel()->selection().indexes();
+ mIndex = 0;
for(int i = 0; i < temp.count(); i++ )
{
QContact contact = mListModel->contact(temp.at(i));
- CntServicesContact servicesContact;
-
- //get the name
- servicesContact.mDisplayName = contact.displayLabel();
-
- //get the phonenumber
- QList<QContactPhoneNumber> phonenumbers = contact.details<QContactPhoneNumber>();
- if(phonenumbers.count() > 0)
+ if (mAction == KCntActionCall)
+ {
+ serviceCallMessageAction(contact, KCntActionCall);
+ }
+ else if (mAction == KCntActionSms )
{
- servicesContact.mPhoneNumber = phonenumbers.first().number();
+ serviceCallMessageAction(contact, "message");
+ }
+ else if (mAction == KCntActionEmail)
+ {
+ serviceEmailAction(contact);
}
else
{
- servicesContact.mPhoneNumber = "";
+ serviceAllAction(contact);
}
+ }
+ showPreviousView();
+}
+
+void CntServiceContactFetchView::serviceCallMessageAction(QContact& aContact, QString aAction)
+{
+ CntServicesContact servicesContact;
+ //get the phonenumber
+ QList<QContactPhoneNumber> phonenumbers = aContact.details<QContactPhoneNumber>();
+
+ Q_ASSERT_X( phonenumbers.count() > 0, "serviceCallMessageAction", "Number count is zero");
+
+ QContactDetail detail = aContact.preferredDetail(aAction);
+ if (!detail.isEmpty())
+ {
+ //Set preferred detail for services
+ QContactPhoneNumber number = detail;
+ servicesContact.mDisplayName = aContact.displayLabel();
+ servicesContact.mPhoneNumber = number.number();
+ servicesContact.mEmailAddress = "";
+ servicesContact.mContactId = aContact.localId();
+ mServiceList.append(servicesContact);
+ }
+ else
+ {
+ // show popup for call numbers
+ CntActionPopup *actionPopup = new CntActionPopup(&aContact);
+ bool popup = actionPopup->showActionPopup(aAction);
+ if(popup)
+ {
+ //if call numbers are present wait for signals
+ mIndex++;
+ connect( actionPopup, SIGNAL(executeContactAction(QContact&,QContactDetail, QString)), this,
+ SLOT(popupContactAction(QContact&, QContactDetail, QString)));
+ connect( actionPopup, SIGNAL(actionPopupCancelPressed()), this,
+ SLOT(actionPopupCancelSlot()));
+ }
+ else
+ {
+ //else delete popup if no call number present
+ delete actionPopup;
+ }
+ }
+}
+void CntServiceContactFetchView::serviceEmailAction(QContact& aContact)
+{
+ CntServicesContact servicesContact;
+ //get the email address
+ QList<QContactEmailAddress> emailAddresses = aContact.details<QContactEmailAddress>();
+
+ Q_ASSERT_X( emailAddresses.count() > 0, "serviceEmailAction", "email address count is zero");
+
+ QContactDetail detail = aContact.preferredDetail("email");
+ if (!detail.isEmpty())
+ {
+ //Set preferred detail for services
+ QContactEmailAddress email = detail;
+ servicesContact.mDisplayName = aContact.displayLabel();
+ servicesContact.mPhoneNumber = "";
+ servicesContact.mEmailAddress = email.emailAddress();
+ servicesContact.mContactId = aContact.localId();
+ mServiceList.append(servicesContact);
+
+ }
+ else
+ {
+ // show popup for email id's
+ CntActionPopup *actionPopup = new CntActionPopup(&aContact);
+ bool popup = actionPopup->showActionPopup("email");
+ if(popup)
+ {
+ //if email id's are present wait for signals
+ mIndex++;
+ connect( actionPopup, SIGNAL(executeContactAction(QContact&,QContactDetail, QString)), this,
+ SLOT(popupContactAction(QContact&, QContactDetail, QString)));
+ connect( actionPopup, SIGNAL(actionPopupCancelPressed()), this,
+ SLOT(actionPopupCancelSlot()));
+ }
+ else
+ {
+ //else delete popup if no email present
+ delete actionPopup;
+ }
+ }
+}
+
+void CntServiceContactFetchView::serviceAllAction(QContact& aContact)
+{
+ CntServicesContact servicesContact;
+ servicesContact.mDisplayName = aContact.displayLabel();
+ QContactDetail callDetail = aContact.preferredDetail("call");
+ //Check for preferredDetail from call
+ // if not present check for preferredDetail for message
+ // if not present pick first phone number
+ if (!callDetail.isEmpty())
+ {
+ QContactPhoneNumber number = callDetail;
+ servicesContact.mPhoneNumber = number.number();
+ }
+ else
+ {
+ QContactDetail smsDetail = aContact.preferredDetail("message");
+ if (!callDetail.isEmpty())
+ {
+ QContactPhoneNumber number = smsDetail;
+ servicesContact.mPhoneNumber = number.number();
+ }
+ else
+ {
+ QList<QContactPhoneNumber> phonenumbers = aContact.details<QContactPhoneNumber>();
+ if(phonenumbers.count() > 0)
+ {
+ servicesContact.mPhoneNumber = phonenumbers.first().number();
+ }
+ else
+ {
+ servicesContact.mPhoneNumber = "";
+ }
+ }
+ }
+
+ QContactDetail emailDetail = aContact.preferredDetail("email");
+ if (!emailDetail.isEmpty())
+ {
+ QContactEmailAddress email = emailDetail;
+ servicesContact.mEmailAddress = email.emailAddress();
+ }
+ else
+ {
//get first email address
- QList<QContactEmailAddress> emailAddresses = contact.details<QContactEmailAddress>();
+ QList<QContactEmailAddress> emailAddresses = aContact.details<QContactEmailAddress>();
if(emailAddresses.count() > 0)
{
servicesContact.mEmailAddress = emailAddresses.first().emailAddress();
}
- //contact id
- servicesContact.mContactId = contact.localId();
-
- //append it to the list
- serviceList.append(servicesContact);
+ else
+ {
+ servicesContact.mEmailAddress = "";
+ }
}
-
- connect(mServiceHandler, SIGNAL(returnValueDelivered()), qApp, SLOT(quit()));
- mServiceHandler->completeFetch(serviceList);
+ servicesContact.mContactId = aContact.localId();
+ mServiceList.append(servicesContact);
}
void CntServiceContactFetchView::aboutToOpenView(CntAbstractViewManager* aMgr, const CntViewParameters aArgs)
@@ -99,25 +230,30 @@
mMgr = aMgr;
// Set title of the view.
- QString title = aArgs.value(CntServiceHandler::ETitle).toString();
+ QString title = aArgs.value(KCntServiceViewParamTitle).toString();
mView->setTitle(title);
// Set action filter
- QString filter = aArgs.value(CntServiceHandler::EFilter).toString();
- QString action = aArgs.value(CntServiceHandler::EAction).toString();
- if (action == KCntActionSms)
+ mAction = aArgs.value(ESelectedAction).toString();
+ // ESelectedAction is defined in cntviewparams.h
+
+ // Has never been implemented.
+ //QString filterStr = aArgs.value(KCntServiceViewParamFilter).toString();
+ // KCntServiceViewParamFilter is defined in cntserviceviewparams.h
+
+ if (mAction == KCntActionSms)
{
QContactActionFilter actionFilter;
actionFilter.setActionName("message");
mListModel->setFilter(actionFilter);
}
- else if (action == KCntActionCall)
+ else if (mAction == KCntActionCall)
{
QContactActionFilter actionFilter;
actionFilter.setActionName("call");
mListModel->setFilter(actionFilter);
}
- else if (action == KCntActionEmail)
+ else if (mAction == KCntActionEmail)
{
QContactActionFilter actionFilter;
actionFilter.setActionName("email");
@@ -139,4 +275,59 @@
}
}
+void CntServiceContactFetchView::popupContactAction(QContact& aContact,QContactDetail contactDetail, QString aAction)
+{
+ if (aAction.compare("call", Qt::CaseInsensitive) == 0
+ || aAction.compare("message", Qt::CaseInsensitive) == 0 )
+ {
+ CntServicesContact servicesContact;
+ QContactPhoneNumber number = static_cast<QContactPhoneNumber>(contactDetail);
+ QString name = aContact.displayLabel();
+ servicesContact.mDisplayName = aContact.displayLabel();
+ servicesContact.mPhoneNumber = number.number();
+ servicesContact.mEmailAddress = "";
+ servicesContact.mContactId = aContact.localId();
+ mServiceList.append(servicesContact);
+ mIndex--;
+ }
+ else if (aAction.compare("email", Qt::CaseInsensitive) == 0 )
+ {
+ CntServicesContact servicesContact;
+ QContactEmailAddress email = static_cast<QContactEmailAddress>(contactDetail);
+ servicesContact.mDisplayName = aContact.displayLabel();
+ servicesContact.mPhoneNumber = "";
+ servicesContact.mEmailAddress = email.emailAddress();
+ servicesContact.mContactId = aContact.localId();
+ mServiceList.append(servicesContact);
+ mIndex--;
+ }
+
+ if (aContact.preferredDetail(aAction).isEmpty() && (aAction == "call" || aAction == "message" || aAction == "email"))
+ {
+ aContact.setPreferredDetail(aAction, contactDetail);
+ //return value will be ignored because we cannot do anything if it fails.
+ mMgr->contactManager(SYMBIAN_BACKEND)->saveContact(&aContact);
+ }
+
+ showPreviousView();
+}
+
+void CntServiceContactFetchView::actionPopupCancelSlot()
+{
+ mIndex--;
+ showPreviousView();
+}
+
+void CntServiceContactFetchView::showPreviousView()
+{
+ if(mIndex==0)
+ {
+ QVariant variant;
+ variant.setValue(mServiceList);
+ mProvider.CompleteServiceAndCloseApp(variant);
+
+ CntViewParameters args;
+ mMgr->back( args );
+ }
+}
// EOF