phonebookui/phonebookservices/src/cntserviceassigncontactcardview.cpp
author hgs
Fri, 23 Jul 2010 12:43:48 +0300
changeset 53 e6aff7b69165
parent 50 77bc263e1626
child 61 d30183af6ca6
permissions -rw-r--r--
201029

/*
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:
*
*/

#include "cntserviceassigncontactcardview.h"
#include "cntabstractserviceprovider.h"
#include "cntdebug.h"

#include <hbaction.h>
#include <hbdialog.h>
#include <hbpushbutton.h>
#include <hblabel.h>
#include <hbwidget.h>
#include <hbtoolbar.h>
#include <hbview.h>
#include <QGraphicsLinearLayout>
#include <QCoreApplication>

/*!
Constructor, initialize member variables.
\a viewManager is the parent that creates this view. \a parent is a pointer to parent QGraphicsItem (by default this is 0)
*/
CntServiceAssignContactCardView::CntServiceAssignContactCardView( CntAbstractServiceProvider& aServiceProvider ) : 
    CntContactCardView(true),
    mProvider( aServiceProvider )
{
    CNT_ENTRY
    connect(this, SIGNAL(backPressed()), this, SLOT(doCloseView()));
    connect(this, SIGNAL(viewActivated(CntAbstractViewManager*, const CntViewParameters)), this, SLOT(doViewActivated(CntAbstractViewManager*,const CntViewParameters)));
    connect(this, SIGNAL(addToContacts()), this, SLOT(addToContacts()));
    CNT_EXIT
}

/*!
Destructor
*/
CntServiceAssignContactCardView::~CntServiceAssignContactCardView()
{
    CNT_ENTRY
    CNT_EXIT
}

/*!
Opens the Add to Contacts popup
*/
void CntServiceAssignContactCardView::addToContacts()
{  
    CNT_ENTRY
    
    HbDialog* popup = new HbDialog();
    popup->setDismissPolicy(HbDialog::NoDismiss);
    popup->setHeadingWidget(
            new HbLabel(hbTrId("txt_phob_title_add_to_contacts"), popup));
    popup->setAttribute(Qt::WA_DeleteOnClose);
    popup->setTimeout( HbPopup::NoTimeout );
    popup->addAction(
            new HbAction(hbTrId("txt_common_button_cancel"), popup));

    HbWidget* buttonWidget = new HbWidget(popup);
    QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical);
    
    HbPushButton* addButton = new HbPushButton(buttonWidget);
    addButton->setStretched(true);
    addButton->setText(hbTrId("txt_phob_button_save_as_a_new_contact"));
    HbIcon plusIcon("qtg_mono_plus");
    addButton->setIcon(plusIcon);
    connect(addButton, SIGNAL(clicked()), popup, SLOT(close()));
    connect(addButton, SIGNAL(clicked()), this, SLOT(saveNew()));
    
    HbPushButton* updateButton = new HbPushButton(buttonWidget);
    updateButton->setStretched(true);
    updateButton->setText(hbTrId("txt_phob_button_update_existing_contact"));
    updateButton->setIcon(plusIcon);
    connect(updateButton, SIGNAL(clicked()), popup, SLOT(close()));
    connect(updateButton, SIGNAL(clicked()), this, SLOT(updateExisting()));
    
    layout->addItem(addButton);
    layout->addItem(updateButton);
    
    buttonWidget->setLayout(layout);
    popup->setContentWidget(buttonWidget);

    popup->open();
    
    CNT_EXIT
}

/*!
Create a new contact with the detail
*/
void CntServiceAssignContactCardView::saveNew()
{
    CNT_ENTRY
    CntViewParameters viewParameters;
    viewParameters.insert(EViewId, serviceEditView);
    QContactName contactName = mContact.detail<QContactName>();
    mContact.removeDetail(&contactName);
    QVariant var;
    var.setValue(mContact);
    viewParameters.insert(ESelectedContact, var);
    mViewManager->changeView(viewParameters);
    CNT_EXIT
}

/*!
Update an existing contact with the detail
*/
void CntServiceAssignContactCardView::updateExisting()
{
    CNT_ENTRY
    CntViewParameters viewParameters;
    viewParameters.insert(EViewId, serviceContactSelectionView);
    QVariant var;
    var.setValue(mDetail);
    viewParameters.insert(ESelectedDetail, var);
    mViewManager->changeView(viewParameters);
    CNT_EXIT
}

/*!
Called after the view has been activated
*/
void CntServiceAssignContactCardView::doViewActivated(CntAbstractViewManager* aMgr, const CntViewParameters aArgs)
{
    CNT_ENTRY
    mViewManager = aMgr;
    mContact = aArgs.value(ESelectedContact).value<QContact>();
    mDetail = aArgs.value(ESelectedDetail).value<QContactDetail>();
    CNT_EXIT
}

/*!
Close the view (quits the service as well)
*/
void CntServiceAssignContactCardView::doCloseView()
{
    CNT_ENTRY
    qApp->quit();
    CNT_EXIT
}

// end of file