phonebookui/pbkcommonui/src/cntgroupdeletepopup.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Wed, 23 Jun 2010 18:02:44 +0300
changeset 46 efe85016a067
parent 40 b46a585f6909
child 54 47627ab5d7a4
permissions -rw-r--r--
Revision: 201023 Kit: 2010125

/*
* 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 "cntgroupdeletepopup.h"

#include <hbgroupbox.h>
#include <hbaction.h>
#include <hblistview.h>
#include <hblistviewitem.h>
#include <qtcontacts.h>

CntGroupDeletePopup::CntGroupDeletePopup(QContactManager *manager, QGraphicsItem *parent):
    HbSelectionDialog(parent),
    mListView(0),
    mContactManager(manager),
    mModel(0)
{
    mModel = new CntGroupDeletePopupModel(mContactManager, this);
}

CntGroupDeletePopup::~CntGroupDeletePopup()
{
    delete mModel;
    mModel = 0;
}

void CntGroupDeletePopup::populateListOfGroup()
{
    HbGroupBox *headingLabel = new HbGroupBox(this);   
    headingLabel->setHeading(hbTrId("txt_phob_opt_delete_groups"));
    
    setHeadingWidget(headingLabel);
    
    mListView = new HbListView(this);
    
    mModel->initializeGroupsList();

    //Get the index of the contacts
    // Set the select option for those contacts in the selectionModel
    mListView->setModel(mModel);
    // set the listview to multiSelection mode, this will bring MarkAll functionality (from Orbit)
    mListView->setSelectionMode(HbAbstractItemView::MultiSelection);
    mListView->setFrictionEnabled(true);
    mListView->setScrollingStyle(HbScrollArea::PanWithFollowOn);
    
    HbListViewItem *prototype = mListView->listItemPrototype();
    prototype->setGraphicsSize(HbListViewItem::Thumbnail);
    prototype->setStretchingStyle(HbListViewItem::StretchLandscape);
    
    setContentWidget(mListView);
    
    setTimeout(HbDialog::NoTimeout);
    setDismissPolicy(HbDialog::NoDismiss);
    setModal(true);
    setAttribute(Qt::WA_DeleteOnClose, true);
    
    clearActions(); 
    HbAction *mPrimaryAction = new HbAction(hbTrId("txt_phob_button_delete_selected"), this);
    addAction(mPrimaryAction);
    
    HbAction *mSecondaryAction = new HbAction(hbTrId("txt_common_button_cancel"), this);
    addAction(mSecondaryAction);
}

QList<QContactLocalId> CntGroupDeletePopup::deleteGroup() const
{
    QModelIndexList indexes = mListView->selectionModel()->selection().indexes();
    QList<QContactLocalId> selectionList;
    for (int i = 0; i < indexes.count(); i++)
    {
        QContact contact = mModel->contact(indexes[i]);
        QContactLocalId locId = contact.localId();
        selectionList.append(locId); 
    }
    
    QMap<int, QContactManager::Error> errors;
    mContactManager->removeContacts(selectionList, &errors);
    
    return selectionList;
}