--- a/phonebookui/pbkcommonui/src/cntdetaileditor.cpp Tue Jul 06 14:05:47 2010 +0300
+++ b/phonebookui/pbkcommonui/src/cntdetaileditor.cpp Wed Aug 18 09:39:00 2010 +0300
@@ -17,7 +17,9 @@
#include "cntdetaileditor.h"
#include "cnteditorfactory.h"
#include "cntgroupeditormodel.h"
+#include "cntsavemanager.h"
#include "cntglobal.h"
+
#include <cntviewparams.h>
#include <hbmenu.h>
#include <hbaction.h>
@@ -29,6 +31,13 @@
#include <hbinputeditorinterface.h>
#include <hbinputstandardfilters.h>
#include <cntdebug.h>
+#include <hbscrollarea.h>
+#include <hbscrollbar.h>
+#include <hbdevicenotificationdialog.h>
+#include <hbparameterlengthlimiter.h>
+
+#include <QApplication>
+#include <QTimer>
const char *CNT_DETAILEDITOR_XML = ":/xml/contacts_detail_editor.docml";
@@ -41,7 +50,8 @@
mLoader(NULL),
mViewManager(NULL),
mEditorFactory(NULL),
- mCancel(NULL)
+ mCancel(NULL),
+ mSaveManager(NULL)
{
bool ok;
document()->load(CNT_DETAILEDITOR_XML, &ok);
@@ -57,16 +67,27 @@
mSoftkey = new HbAction(Hb::BackNaviAction, mView);
connect( mSoftkey, SIGNAL(triggered()), this, SLOT(saveChanges()) );
+
+ // closing the application from task swapper or end key will cause the contact to be saved
+ connect( qApp, SIGNAL(aboutToQuit()), this, SLOT(saveContact()));
}
CntDetailEditor::~CntDetailEditor()
{
mView->deleteLater();
+
delete mDataForm;
+ mDataForm = NULL;
delete mDataFormModel;
+ mDataFormModel = NULL;
delete mHeader;
+ mHeader = NULL;
delete mLoader;
+ mLoader = NULL;
delete mEditorFactory;
+ mEditorFactory = NULL;
+ delete mSaveManager;
+ mSaveManager = NULL;
}
void CntDetailEditor::setViewId( int aId )
@@ -106,8 +127,31 @@
selectedContact = aArgs.value(ESelectedContact).value<QContact>();
connect( mDataForm, SIGNAL(itemShown(const QModelIndex&)), this, SLOT(handleItemShown(const QModelIndex&)) );
}
+
+ QContactManager* cm = mViewManager->contactManager(SYMBIAN_BACKEND);
+ connect(cm, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)),
+ this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&)));
+
mEditorFactory->setupEditorView(*this, selectedContact);
+ QString myCard = mArgs.value( EMyCard ).toString();
+ QContactLocalId localId = selectedContact.localId();
+ QContactLocalId selfContactId = mViewManager->contactManager(SYMBIAN_BACKEND)->selfContactId();
+ bool isMyCard = ( localId == selfContactId && localId != 0 ) || !myCard.isEmpty();
+
+ if (isMyCard)
+ {
+ mSaveManager = new CntSaveManager(CntSaveManager::EMyCard);
+ }
+ else if ( mId == groupEditorView )
+ {
+ mSaveManager = new CntSaveManager(CntSaveManager::EGroup);
+ }
+ else
+ {
+ mSaveManager = new CntSaveManager();
+ }
+
mDataForm->setItemRecycling(true);
// add new field if required
@@ -115,6 +159,9 @@
{
mDataFormModel->insertDetailField();
}
+ mDataForm->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded);
+ mDataForm->setScrollingStyle(HbScrollArea::PanWithFollowOn);
+ mDataForm->verticalScrollBar()->setInteractive(true);
}
void CntDetailEditor::deactivate()
@@ -123,6 +170,10 @@
QContactManager* mgr = mViewManager->contactManager(SYMBIAN_BACKEND);
mgr->saveContact( mDataFormModel->contact() );
}
+
+ QContactManager *cm = mViewManager->contactManager(SYMBIAN_BACKEND);
+ disconnect(cm, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)),
+ this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&)));
}
bool CntDetailEditor::isDefault() const
@@ -151,27 +202,42 @@
void CntDetailEditor::handleItemShown(const QModelIndex& aIndex )
{
- if ( mId == groupEditorView )
- {
- CntGroupEditorModel* groupModel = static_cast<CntGroupEditorModel*>( mDataFormModel );
- if ( groupModel->isConferenceNumber(aIndex) )
- {
- HbDataFormViewItem* viewItem = static_cast<HbDataFormViewItem*>(mDataForm->itemByIndex( aIndex ));
- HbLineEdit* edit = static_cast<HbLineEdit*>( viewItem->dataItemContentWidget() );
- edit->setInputMethodHints( Qt::ImhDialableCharactersOnly );
- }
- }
- else
+ HbDataFormModelItem* modelItem = mDataFormModel->itemFromIndex( aIndex );
+
+ if ( modelItem->type() == HbDataFormModelItem::TextItem )
{
HbDataFormViewItem* viewItem = static_cast<HbDataFormViewItem*>(mDataForm->itemByIndex( aIndex ));
HbLineEdit* edit = static_cast<HbLineEdit*>( viewItem->dataItemContentWidget() );
- edit->setInputMethodHints( Qt::ImhNoPredictiveText );
+ QString objName;
- HbDataFormModelItem* modelItem = mDataFormModel->itemFromIndex( aIndex );
- if (modelItem->contentWidgetData( "preferDigits" ).toBool())
+ if ( mId == groupEditorView )
{
- edit->setInputMethodHints( Qt::ImhPreferNumbers );
+ CntGroupEditorModel* groupModel = static_cast<CntGroupEditorModel*>( mDataFormModel );
+ if ( groupModel->isConferenceNumber(aIndex) )
+ {
+ edit->setInputMethodHints( Qt::ImhDialableCharactersOnly );
+ objName = "Conference number line edit %1";
+ }
+ else
+ {
+ edit->setInputMethodHints( Qt::ImhNoPredictiveText );
+ objName = "Group name line edit %1";
+ }
}
+ else
+ {
+ edit->setInputMethodHints( Qt::ImhNoPredictiveText );
+
+ if (modelItem->contentWidgetData( "preferDigits" ).toBool())
+ {
+ edit->setInputMethodHints( Qt::ImhPreferNumbers );
+ }
+
+ objName = mDataFormModel->detail().definitionName() + " line edit %1";
+ }
+
+ // Naming UI components for automation testability
+ edit->setObjectName(objName.arg(aIndex.row()));
}
}
@@ -184,6 +250,10 @@
mViewManager->back( mArgs );
}
+/*!
+ Saves all changes made to details (type of details depends on
+ in which editor we are) of a contact. Doesn't save the contact.
+*/
void CntDetailEditor::saveChanges()
{
mDataFormModel->saveContactDetails();
@@ -208,6 +278,46 @@
mViewManager->back( mArgs );
}
+/*!
+ First saves all changes made to details (type of details depends on
+ in which editor we are) of a contact and then saves the contact. This
+ is only called when phonebook is being closed either from task swapper
+ or by end key.
+*/
+void CntDetailEditor::saveContact()
+{
+ mDataFormModel->saveContactDetails();
+
+ QString name = mViewManager->contactManager(SYMBIAN_BACKEND)->synthesizedContactDisplayLabel(*mDataFormModel->contact());
+
+ if (name.isEmpty())
+ {
+ name = hbTrId("txt_phob_list_unnamed");
+ }
+
+ CntSaveManager::CntSaveResult result = mSaveManager->saveContact(mDataFormModel->contact(), mViewManager->contactManager(SYMBIAN_BACKEND));
+
+ if (mId != groupEditorView)
+ {
+ switch (result)
+ {
+ case CntSaveManager::ESaved:
+ HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_contact_1_saved")).arg(name));
+ break;
+ case CntSaveManager::EUpdated:
+ HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_contacts_1_updated")).arg(name));
+ break;
+ case CntSaveManager::EFailed:
+ HbDeviceNotificationDialog::notification(QString(),hbTrId("SAVING FAILED!"));
+ break;
+ case CntSaveManager::EDeleted:
+ case CntSaveManager::ENothingDone:
+ default:
+ break;
+ }
+ }
+}
+
void CntDetailEditor::setHeader(QString aHeader)
{
if (!mHeader) {
@@ -236,4 +346,28 @@
return mId;
}
+/*!
+Go back to the root view
+*/
+void CntDetailEditor::showRootView()
+{
+ mViewManager->back( mArgs, true );
+}
+
+
+void CntDetailEditor::contactDeletedFromOtherSource(const QList<QContactLocalId>& contactIds)
+{
+ CNT_ENTRY
+
+ QContact normalContact = mArgs.value(ESelectedContact).value<QContact>();
+ QContact groupContact = mArgs.value(ESelectedGroupContact).value<QContact>();
+ if ( contactIds.contains(normalContact.localId()) || contactIds.contains(groupContact.localId()) )
+ {
+ // Do not switch to the previous view immediately. List views are
+ // not updated properly if this is not done in the event loop
+ QTimer::singleShot(0, this, SLOT(showRootView()));
+ }
+ CNT_EXIT
+}
+
// End of File