phonebookui/pbkcommonui/src/cntfavoritesview.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 14 May 2010 15:42:23 +0300
changeset 31 2a11b5b00470
parent 27 de1630741fbe
child 37 fd64c38c277d
permissions -rw-r--r--
Revision: 201017 Kit: 201019

/*
* 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 "cntfavoritesview.h"
#include "cntgroupselectionpopup.h"
#include "qtpbkglobal.h"
#include <hbpushbutton.h>
#include <hbaction.h>
#include <hbview.h>
#include <hbmainwindow.h>

const char *CNT_FAVORITE_UI_XML = ":/xml/contacts_favorite.docml";

CntFavoritesView::CntFavoritesView() :
    mContact(NULL),
    mView(NULL),
    mSoftkey(NULL),
    mViewManager(NULL)
{
    bool ok = false;
    mDocumentLoader.load(CNT_FAVORITE_UI_XML, &ok);

    if (ok)
    {
        mView = static_cast<HbView*>(mDocumentLoader.findWidget(QString("favoritesView")));
    }
    else
    {
        qFatal("Unable to read :/xml/contacts_favorite.docml");
    }
    
    //back button
    mSoftkey = new HbAction(Hb::BackNaviAction, mView);
    connect(mSoftkey, SIGNAL(triggered()), this, SLOT(showPreviousView()));
}
/*!
Destructor
*/
CntFavoritesView::~CntFavoritesView()
{
    mView->deleteLater();
    
    delete mContact;
    mContact = 0;
}

void CntFavoritesView::activate( CntAbstractViewManager* aMgr, const CntViewParameters aArgs )
{
    if (mView->navigationAction() != mSoftkey)
        mView->setNavigationAction(mSoftkey);
    
    HbMainWindow* window = mView->mainWindow();
    connect(window, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(setOrientation(Qt::Orientation)));
    setOrientation(window->orientation());
    
    mContact = new QContact(aArgs.value(ESelectedContact).value<QContact>());
    mViewManager = aMgr;

    HbPushButton *addButton = static_cast<HbPushButton*>(mDocumentLoader.findWidget(QString("cnt_button_add")));
    connect(addButton, SIGNAL(clicked()), this, SLOT(openSelectionPopup()));
}

void CntFavoritesView::deactivate()
{

}

void CntFavoritesView::openSelectionPopup()
{
   // call a dialog to display the contacts
   CntGroupSelectionPopup *groupSelectionPopup = new CntGroupSelectionPopup(mViewManager->contactManager(SYMBIAN_BACKEND), mContact);
   groupSelectionPopup->populateListOfContact();
   groupSelectionPopup->open(this, SLOT(handleMemberSelection(HbAction*)));
}

void CntFavoritesView::handleMemberSelection(HbAction *action)
{
    CntGroupSelectionPopup *groupSelectionPopup = static_cast<CntGroupSelectionPopup*>(sender());
    
    if (groupSelectionPopup && action == groupSelectionPopup->actions().first())
    {
        bool membersSaved = groupSelectionPopup->saveOldGroup();
        
        if (membersSaved)
        {
            CntViewParameters viewParameters;
            viewParameters.insert(EViewId, FavoritesMemberView);
            QVariant var;
            var.setValue(*mContact);
            viewParameters.insert(ESelectedContact, var);
            mViewManager->changeView(viewParameters);
        }
        else
        {
            showPreviousView();
        }
    }
    else if (groupSelectionPopup && action == groupSelectionPopup->actions().at(1))
    {
        showPreviousView();
    }
}

void CntFavoritesView::setOrientation(Qt::Orientation orientation)
{
    if (orientation == Qt::Vertical) 
    {
        // reading "portrait" section
        mDocumentLoader.load(CNT_FAVORITE_UI_XML, "portrait");
    } 
    else 
    {
        // reading "landscape" section
        mDocumentLoader.load(CNT_FAVORITE_UI_XML, "landscape");
    }
}

void CntFavoritesView::showPreviousView()
{
    CntViewParameters args;
    mViewManager->back(args);
}

// end of file