phonebookui/pbkcommonui/src/cntbaseview.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 19 Mar 2010 09:27:18 +0200
changeset 24 0ba2181d7c28
child 25 76a2435edfd4
permissions -rw-r--r--
Revision: 201007 Kit: 201011

/*
* 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 "cntbaseview.h"
#include "cntmainwindow.h"
#include "cntdocumentloader.h"
          
#include <hbtoolbar.h>

CntBaseView::CntBaseView(CntViewManager *viewManager, QGraphicsItem *parent) :
    HbView(parent),
    mViewManager(viewManager),
    mActions(0),
    mCommands(0),
    mSoftKeyBackAction(new HbAction(Hb::BackAction, this))
{
    mModelProvider=CntModelProvider::instance();
    setTitle(hbTrId("txt_phob_title_contacts"));
    connect(mViewManager->mainWindow(), SIGNAL(keyPressed(QKeyEvent*)), this, SLOT(keyPressEvent(QKeyEvent*)));
    connect(mViewManager->mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(setOrientation(Qt::Orientation)));
    
    mSoftKeyBackAction->setText(hbTrId("Back"));
    connect(mSoftKeyBackAction, SIGNAL(triggered()), this, SLOT(aboutToCloseView()));
}

CntBaseView::~CntBaseView()
{
    mModelProvider->release();
}

void CntBaseView::setupView()
{
    addToolBar();
    addMenuItems();
    addSoftkeyAction();
}

CntViewManager* CntBaseView::viewManager()
{
    return mViewManager;
}


/*!
\return pointer to MobCntModel
*/
MobCntModel *CntBaseView::contactModel()
{
    return mModelProvider->contactModel();
}

QContactManager *CntBaseView::contactManager()
{
    return mModelProvider->contactManager();
}

CntCommands *CntBaseView::commands()
{
    if (mCommands == 0)
    {
        mCommands = new CntCommands(*viewManager(), mModelProvider->contactManager(),
                mModelProvider->contactSimManager(), this);
    }
    return mCommands;
}

void CntBaseView::addSoftkeyAction()
{
    HbAction *action = viewManager()->mainWindow()->softKeyAction(Hb::SecondarySoftKey);
    viewManager()->mainWindow()->removeSoftKeyAction(Hb::SecondarySoftKey, action);

    viewManager()->mainWindow()->addSoftKeyAction(Hb::SecondarySoftKey, mSoftKeyBackAction);
}

void CntBaseView::keyPressEvent(QKeyEvent *event)
{
    if (this == viewManager()->mainWindow()->currentView() && event->key() == Qt::Key_Yes)
    {
        event->accept();
        commands()->launchDialer();
    }
    else if (this == viewManager()->mainWindow()->currentView() && event->key() == Qt::Key_No)
    {
        event->accept();
        qApp->quit();
    }
    else
    {
        HbView::keyPressEvent(event);
    }
}

/*!
Clears toolbar items.
*/
void CntBaseView::clearToolBar()
{
    toolBar()->clearActions();
}

/*!
Adds toolbar control.
*/
void CntBaseView::addToolBar()
{
    clearToolBar();

    //Add Action to the toolbar and set its orientation (default horizontal always)
    addActionsToToolBar();
    setToolBarOrientation();
}

void CntBaseView::setToolBarOrientation()
{
    toolBar()->setOrientation(Qt::Horizontal);
}

CntActions *CntBaseView::actions()
{
    if (mActions == 0)
    {
        mActions = new CntActions(this);
    }
    return mActions;
}

bool CntBaseView::loadDocument(const char *aDocument)
{
    bool ok = false;
    documentLoader().load(aDocument, &ok);
    return ok;
}

bool CntBaseView::loadDocument(const char *aDocument, const char *aSection)
{
    bool ok = false;
    documentLoader().load(aDocument, aSection, &ok);
    return ok;
}

CntDocumentLoader &CntBaseView::documentLoader()
{
    return mDocumentLoader;
}

QGraphicsWidget* CntBaseView::findWidget(const QString& aWidget)
{
    return documentLoader().findWidget(aWidget);
}

QObject* CntBaseView::findObject(const QString& aObject)
{
    return documentLoader().findObject(aObject);
}
// end of file