--- a/phonebookui/pbkcommonui/src/cntcontactcardview_p.cpp Thu May 27 12:45:19 2010 +0300
+++ b/phonebookui/pbkcommonui/src/cntcontactcardview_p.cpp Fri Jun 11 13:29:23 2010 +0300
@@ -19,7 +19,12 @@
#include <QGraphicsLinearLayout>
#include <QGraphicsSceneResizeEvent>
#include <QStringList>
+#include <QStandardItemModel>
+#include <hblistview.h>
+#include <hblistviewitem.h>
#include <QDebug>
+#include <QKeyEvent>
+#include <QDir>
#include <qtcontacts.h>
#include <hbscrollarea.h>
@@ -52,6 +57,9 @@
#include "cntimagelabel.h"
#include "cntimageutility.h"
#include "cntfavourite.h"
+#include "cntactionlauncher.h"
+#include <hbselectiondialog.h>
+
const char *CNT_CONTACTCARDVIEW_XML = ":/xml/contacts_contactcard.docml";
@@ -76,7 +84,10 @@
mContactAction(NULL),
mBackKey(NULL),
mImageLabel(NULL),
- mVCardIcon(NULL)
+ mVCardIcon(NULL),
+ mShareUi(NULL),
+ mAcceptSendKey(true),
+ mSendKeyListModel(NULL)
{
bool ok;
document()->load(CNT_CONTACTCARDVIEW_XML, &ok);
@@ -106,6 +117,8 @@
*/
CntContactCardViewPrivate::~CntContactCardViewPrivate()
{
+ mView->deleteLater();
+
delete mContact;
mContact = 0;
@@ -118,8 +131,18 @@
delete mLoader;
mLoader = NULL;
- delete mVCardIcon;
- mVCardIcon = NULL;
+ if (mVCardIcon) {
+ delete mVCardIcon;
+ mVCardIcon = NULL;
+ }
+
+ if (mShareUi) {
+ delete mShareUi;
+ mShareUi = NULL;
+ }
+
+ delete mSendKeyListModel;
+ mSendKeyListModel = NULL;
}
/*!
@@ -159,6 +182,8 @@
HbMainWindow* window = mView->mainWindow();
connect(window, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(setOrientation(Qt::Orientation)));
+ connect(window, SIGNAL(keyPressed(QKeyEvent*)), this, SLOT(keyPressed(QKeyEvent*)));
+
setOrientation(window->orientation());
QContact contact = aArgs.value(ESelectedContact).value<QContact>();
@@ -218,16 +243,17 @@
for (int index = 0; index < mDataContainer->itemCount(); index++)
{
+ CntContactCardDataItem* dataItem = mDataContainer->dataItem(index);
+ int pos = dataItem->position();
+
// communication methods
- if (mDataContainer->separatorIndex() == -1 || index < mDataContainer->separatorIndex())
+ if (pos < CntContactCardDataItem::ESeparator && dataItem->isFocusable())
{
CntContactCardDetailItem* item = new CntContactCardDetailItem(index, mContainerWidget);
connect(item, SIGNAL(clicked()), this, SLOT(onItemActivated()));
connect(item, SIGNAL(longPressed(const QPointF&)), this, SLOT(onLongPressed(const QPointF&)));
-
- CntContactCardDataItem* dataItem = mDataContainer->dataItem(index);
-
+
if (mContact->isPreferredDetail(dataItem->action(), dataItem->detail()))
{
dataItem->setSecondaryIcon(HbIcon("qtg_mono_favourites"));
@@ -239,11 +265,11 @@
}
// separator
- else if (index == mDataContainer->separatorIndex())
+ else if (pos == CntContactCardDataItem::ESeparator)
{
HbFrameItem* frameItem = new HbFrameItem(QString("qtg_fr_list_separator"), HbFrameDrawer::NinePieces);
HbLabel* label = static_cast<HbLabel*>(document()->findWidget(QString("separator")));
- label->setPlainText(mDataContainer->dataItem(index)->titleText());
+ label->setPlainText(dataItem->titleText());
label->setBackgroundItem(frameItem);
mContainerLayout->addItem(label);
}
@@ -251,9 +277,9 @@
// details
else
{
- CntContactCardDataItem* dataItem = mDataContainer->dataItem(index);
- if (!dataItem->icon().isNull())
- {
+ //map support (image only)
+ if (pos >= CntContactCardDataItem::EAddress && pos <= CntContactCardDataItem::EAddressWork && !dataItem->icon().isNull())
+ {
HbLabel* iconLabel = new HbLabel(mView);
iconLabel->setIcon(dataItem->icon());
@@ -269,6 +295,7 @@
QSizePolicy::Fixed));
mContainerLayout->addItem(iconLabel);
}
+ //other details
else
{
CntContactCardDetailItem* item = new CntContactCardDetailItem(index, mContainerWidget, false);
@@ -278,15 +305,18 @@
}
}
- bool setAsFavorite( false );
- QContactLocalId favouriteGroupId = CntFavourite::favouriteGroupId( contactManager() );
- if( favouriteGroupId != 0 )
- {
- setAsFavorite = CntFavourite::isMemberOfFavouriteGroup( contactManager(), mContact );
- mHeadingItem->setSecondaryIcon( setAsFavorite ); // if contact is part of favourites group
+ if (!myCard)
+ {
+ bool setAsFavorite( false );
+ QContactLocalId favouriteGroupId = CntFavourite::favouriteGroupId( contactManager() );
+ if( favouriteGroupId != 0 )
+ {
+ setAsFavorite = CntFavourite::isMemberOfFavouriteGroup( contactManager(), mContact );
+ mHeadingItem->setSecondaryIcon( setAsFavorite ); // if contact is part of favourites group
+ }
+ qobject_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible( !setAsFavorite );
+ qobject_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible( setAsFavorite );
}
- qobject_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible( !setAsFavorite );
- qobject_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible( setAsFavorite );
// Menu items
connect(qobject_cast<HbAction *>(document()->findObject("cnt:sendbusinesscard")), SIGNAL(triggered()),
@@ -337,7 +367,7 @@
XQServiceRequest snd("com.nokia.services.hsapplication.IHomeScreenClient",
"addWidget(QString,QVariantHash)"
,false);
- snd << QString("hscontactwidgetplugin");
+ snd << QString("contactwidgethsplugin");
snd << preferences;
snd.send();
}
@@ -436,7 +466,7 @@
// Check if the contact has an image.
QList<QContactAvatar> avatars = mContact->details<QContactAvatar>();
bool imageExists( false );
- foreach(QContactAvatar a, mContact->details<QContactAvatar>())
+ /*foreach(QContactAvatar a, mContact->details<QContactAvatar>())
{
if (!a.imageUrl().isEmpty())
{
@@ -445,6 +475,7 @@
hbTrId("txt_phob_info_add_contact_card_image_to_business_c"),
HbMessageBox::MessageTypeQuestion);
note->setIcon(*mVCardIcon);
+ note->clearActions();
HbAction* ok = new HbAction(hbTrId("txt_common_button_ok"), note);
HbAction* cancel = new HbAction(hbTrId("txt_common_button_cancel"), note);
@@ -460,7 +491,7 @@
note->open( this, SLOT(handleSendBusinessCard(HbAction*)));
break;
}
- }
+ }*/
if ( !imageExists )
{
@@ -500,55 +531,38 @@
if(0 < actionDescriptors.count())
{
// These actions are considered internal(vendor=symbian and version=1)
- launchAction(*mContact, mDataContainer->dataItem(index)->detail(), action);
+ executeAction(*mContact, mDataContainer->dataItem(index)->detail(), action);
}
else
{
//Handle dynamic actions differently
- launchDynamicAction(*mContact, mDataContainer->dataItem(index)->detail(), mDataContainer->dataItem(index)->actionDescriptor());
+ executeDynamicAction(*mContact, mDataContainer->dataItem(index)->detail(), mDataContainer->dataItem(index)->actionDescriptor());
}
}
/*!
-Launch the call / message / email action
+Execute the call / message / email action
*/
-void CntContactCardViewPrivate::launchAction(QContact contact, QContactDetail detail, QString action)
+void CntContactCardViewPrivate::executeAction(QContact& aContact, QContactDetail aDetail, QString aAction)
{
- // detail might be empty -> in that case engine uses the preferred detail for the selected action
- QList<QContactActionDescriptor> actionDescriptors = QContactAction::actionDescriptors(action, "symbian");
- if (actionDescriptors.isEmpty())
- {
- return;
- }
- mContactAction = QContactAction::action(actionDescriptors.first());
- connect(mContactAction, SIGNAL(stateChanged(QContactAction::State)),
- this, SLOT(progress(QContactAction::State)));
- mContactAction->invokeAction(contact, detail);
+ CntActionLauncher* other = new CntActionLauncher( aAction );
+ connect(other, SIGNAL(actionExecuted(CntActionLauncher*)), this, SLOT(actionExecuted(CntActionLauncher*)));
+ other->execute(aContact, aDetail);
}
/*!
-Launch dynamic action
+Execute dynamic action
*/
-void CntContactCardViewPrivate::launchDynamicAction(QContact contact, QContactDetail detail, QContactActionDescriptor actionDescriptor)
+void CntContactCardViewPrivate::executeDynamicAction(QContact& aContact, QContactDetail aDetail, QContactActionDescriptor aActionDescriptor)
{
- // detail might be empty -> in that case engine uses the preferred detail for the selected action
- mContactAction = QContactAction::action(actionDescriptor);
- connect(mContactAction, SIGNAL(stateChanged(QContactAction::State)),
- this, SLOT(progress(QContactAction::State)));
- mContactAction->invokeAction(contact, detail);
+ CntActionLauncher* other = new CntActionLauncher( );
+ connect(other, SIGNAL(actionExecuted(CntAction*)), this, SLOT(actionExecuted(CntAction*)));
+ other->execute(aContact, aDetail, aActionDescriptor);
}
-void CntContactCardViewPrivate::progress(QContactAction::State status)
+void CntContactCardViewPrivate::actionExecuted(CntActionLauncher* aAction)
{
- switch(status)
- {
- case QContactAction::FinishedState:
- case QContactAction::FinishedWithErrorState:
- mContactAction->deleteLater();
- break;
- default:
- break;
- }
+ aAction->deleteLater();
}
/*!
@@ -588,10 +602,7 @@
QString subtype = number.subTypes().isEmpty() ? number.definitionName() : number.subTypes().first();
communicationAction = menu->addAction(stringMapper.getItemSpecificMenuLocString(subtype, context));
-
- // TODO : uncomment next line when videotelephony is released
- Q_UNUSED(videoCommunicationAction)
- //videoCommunicationAction = menu->addAction(QString("txt_phob_menu_call_video_number"));
+ videoCommunicationAction = menu->addAction(hbTrId("txt_phob_menu_call_video_number"));
}
}
else if (action.compare("message", Qt::CaseInsensitive) == 0)
@@ -650,6 +661,10 @@
{
communicationAction->setObjectName( "communicationAction" );
}
+ if ( videoCommunicationAction )
+ {
+ videoCommunicationAction->setObjectName( "videoCommunicationAction" );
+ }
if ( dynamicAction )
{
@@ -680,12 +695,17 @@
if ( name == "communicationAction" )
{
- launchAction( *mContact, detail, action );
+ executeAction( *mContact, detail, action );
}
+ if ( name == "videoCommunicationAction" )
+ {
+ //service name latter on should come from service table.
+ executeAction( *mContact, detail, "videocall" );
+ }
if ( name == "dynamicAction" )
{
- launchDynamicAction(*mContact, detail, mDataContainer->dataItem(index)->actionDescriptor());
+ executeDynamicAction(*mContact, detail, mDataContainer->dataItem(index)->actionDescriptor());
}
if ( name == "preferredAction" )
@@ -710,7 +730,7 @@
{
qDebug() << "CntContactCardViewPrivate::handleSendBusinessCard - IN";
QList<QContact> list;
- if ( aAction && aAction->objectName() == "cancel" )
+ /* if ( aAction && aAction->objectName() == "cancel" )
{
QContact tmpContact( *mContact );
foreach ( QContactAvatar a, tmpContact.details<QContactAvatar>() )
@@ -722,8 +742,15 @@
else
{
list.append( *mContact );
+ }*/
+
+ QContact tmpContact( *mContact );
+ foreach ( QContactAvatar a, tmpContact.details<QContactAvatar>() )
+ {
+ tmpContact.removeDetail( &a );
}
-
+ list.append( tmpContact );
+
QString tempDir = QDir::tempPath().append("/tempcntvcard");
QDir dir(tempDir);
@@ -769,39 +796,17 @@
ret = writer.waitForFinished();
// Create the vCard and send it to messaging service
- ShareUi s;
+ if (!mShareUi) {
+ mShareUi = new ShareUi();
+ }
QStringList l;
l << vCardPath;
- s.send(l,false);
+ mShareUi->send(l,false);
}
}
qDebug() << "CntContactCardViewPrivate::handleSendBusinessCard - OUT";
}
-/*!
-Event filter for green key
-*/
-bool CntContactCardViewPrivate::eventFilter(QObject *obj, QEvent *event)
-{
- if (event->type() == QEvent::KeyPress && static_cast<QKeyEvent*>(event)->key() == Qt::Key_Yes)
- {
- QList<QContactActionDescriptor> actionDescriptors = mContact->availableActions();
- QStringList availableActions;
- for (int i = 0; i < actionDescriptors.count();i++)
- {
- availableActions << actionDescriptors.at(i).actionName();
- }
- if (availableActions.contains("call", Qt::CaseInsensitive))
- {
- launchAction(*mContact, QContactDetail(), "call");
- }
- return true;
- }
- else
- {
- return QObject::eventFilter(obj,event);
- }
-}
/*!
Called after the user clicked "Change Image" from popup menu after
@@ -889,4 +894,110 @@
return mViewManager->contactManager(SYMBIAN_BACKEND);
}
+void CntContactCardViewPrivate::keyPressed(QKeyEvent *event)
+{
+ if (event->key() == Qt::Key_Yes )
+ {
+ sendKeyPressed();
+ }
+}
+
+void CntContactCardViewPrivate::sendKeyPressed()
+{
+ QContactDetail preferredDetail = mContact->preferredDetail("call");
+ if (!preferredDetail.isEmpty())
+ {
+ executeAction(*mContact, preferredDetail, "call");
+ }
+ else
+ {
+ if(!mSendKeyListModel)
+ {
+ mSendKeyListModel = new QStandardItemModel();
+ }
+ mSendKeyListModel->clear();
+ for (int index = 0; index < mDataContainer->itemCount(); index++)
+ {
+ CntContactCardDataItem* dataItem = mDataContainer->dataItem(index);
+ if (dataItem->action().compare("call", Qt::CaseInsensitive) == 0)
+ {
+ QStandardItem *labelItem = new QStandardItem();
+ QStringList textList;
+ textList << dataItem->titleText() << dataItem->valueText();
+ labelItem->setData(textList, Qt::DisplayRole);
+ labelItem->setData(dataItem->icon(), Qt::DecorationRole);
+ labelItem->setData(index, Qt::UserRole);
+ mSendKeyListModel->appendRow(labelItem);
+ }
+ }
+
+ if (mSendKeyListModel->rowCount() == 0)
+ {
+ XQServiceRequest snd("com.nokia.services.logsservices.starter", "start(int,bool)", false);
+ snd << 0; // all calls
+ snd << true; // show dialpad
+ snd.send();
+ }
+ else if (mSendKeyListModel->rowCount() ==1 )
+ {
+ QContactDetail detail = mDataContainer->dataItem(0)->detail();
+ executeAction( *mContact, detail, "call" );
+ }
+ else if (mSendKeyListModel->rowCount() >= 2 && mAcceptSendKey)
+ {
+ mAcceptSendKey = false;
+
+ // Instantiate a dialog
+ mSendKeyPopup = new HbSelectionDialog();
+ mSendKeyPopup->clearActions();
+ mSendKeyPopup->setAttribute(Qt::WA_DeleteOnClose, true);
+ mSendKeyPopup->setDismissPolicy(HbPopup::NoDismiss);
+ mSendKeyPopup->setTimeout(HbPopup::NoTimeout);
+ mSendKeyPopup->setModal(true);
+
+ HbListView* listView = new HbListView(mSendKeyPopup);
+ listView->setModel(mSendKeyListModel);
+ listView->setScrollingStyle(HbScrollArea::PanWithFollowOn);
+ listView->setFrictionEnabled(true);
+
+ connect(listView, SIGNAL(activated (const QModelIndex&)), this,
+ SLOT(launchSendKeyAction(const QModelIndex&)));
+
+ QString contactName = mContact->displayLabel();
+
+ HbLabel *headingText = new HbLabel(mSendKeyPopup);
+ headingText->setPlainText(contactName);
+
+ mSendKeyPopup->setHeadingWidget(headingText);
+ mSendKeyPopup->setContentWidget(listView);
+
+ HbAction *cancelAction = new HbAction(hbTrId("txt_phob_button_cancel"), mSendKeyPopup);
+ mSendKeyPopup->addAction(cancelAction);
+
+ // Launch dialog asyncronously
+ mSendKeyPopup->open(this, SLOT(sendKeyDialogSlot(HbAction*)));
+ }
+ }
+}
+
+void CntContactCardViewPrivate::sendKeyDialogSlot(HbAction* action)
+{
+ Q_UNUSED(action);
+ mAcceptSendKey = true;
+}
+
+void CntContactCardViewPrivate::launchSendKeyAction(const QModelIndex &index)
+{
+ mAcceptSendKey = true;
+ mSendKeyPopup->close();
+ if (index.isValid())
+ {
+ int row = index.row();
+ int selectedDetail = mSendKeyListModel->item(index.row())->data(Qt::UserRole).toInt();
+ executeAction(*mContact, mDataContainer->dataItem(selectedDetail)->detail(), "call");
+ }
+}
+
+
+
// end of file