phonebookui/pbkcommonui/src/cntmycardview.cpp
changeset 24 0ba2181d7c28
child 25 76a2435edfd4
equal deleted inserted replaced
0:e686773b3f54 24:0ba2181d7c28
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cntmycardview.h"
       
    19 #include <hbpushbutton.h>
       
    20 
       
    21 const char *CNT_MYCARD_UI_XML = ":/xml/contacts_mc.docml";
       
    22 
       
    23 CntMyCardView::CntMyCardView(CntViewManager *viewManager, QGraphicsItem *parent) : CntBaseView(viewManager, parent), mContact(0)
       
    24 {   
       
    25     bool ok = false;
       
    26     ok=loadDocument(CNT_MYCARD_UI_XML);
       
    27 
       
    28     if (ok)
       
    29     {
       
    30     
       
    31         QGraphicsWidget *w = findWidget(QString("view"));
       
    32         setWidget(w);
       
    33     }
       
    34     else
       
    35     {
       
    36         qFatal("Unable to read :/xml/contacts_mc.docml");
       
    37     }
       
    38 }
       
    39 
       
    40 CntMyCardView::~CntMyCardView()
       
    41 {
       
    42     delete mContact;
       
    43 }
       
    44 
       
    45 /*!
       
    46 Activates a previous view
       
    47 */
       
    48 void CntMyCardView::aboutToCloseView()
       
    49 {
       
    50     viewManager()->onActivateView(CntViewParameters::namesView);
       
    51 }
       
    52 
       
    53 /*
       
    54 Activates a default view
       
    55 */
       
    56 void CntMyCardView::activateView(const CntViewParameters &aViewParameters)
       
    57 {
       
    58     mContact = new QContact(aViewParameters.selectedContact());
       
    59     
       
    60     HbPushButton *newButton = static_cast<HbPushButton*>(findWidget(QString("cnt_button_new")));
       
    61     connect(newButton, SIGNAL(clicked()), this, SLOT(openNameEditor()));
       
    62 
       
    63     HbPushButton *chooseButton = static_cast<HbPushButton*>(findWidget(QString("cnt_button_choose")));
       
    64     connect(chooseButton, SIGNAL(clicked()), this, SLOT(openMyCardSelectionView()));
       
    65 
       
    66     QContactDetailFilter filter;
       
    67     filter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType);
       
    68     filter.setValue(QLatin1String(QContactType::TypeContact));
       
    69     if (contactManager()->contacts(filter).isEmpty())
       
    70     {
       
    71         chooseButton->setEnabled(false);
       
    72     }
       
    73 }
       
    74 
       
    75 void CntMyCardView::setOrientation(Qt::Orientation orientation)
       
    76 {
       
    77     if( orientation == Qt::Vertical ) 
       
    78     {
       
    79         // reading "portrait" section
       
    80         loadDocument(CNT_MYCARD_UI_XML, "portrait");
       
    81     } 
       
    82     else 
       
    83     {
       
    84         // reading "landscape" section
       
    85         loadDocument(CNT_MYCARD_UI_XML, "landscape");
       
    86     }
       
    87 }
       
    88 
       
    89 /*!
       
    90 Opens the name detail editor view
       
    91 */
       
    92 void CntMyCardView::openNameEditor()
       
    93 {
       
    94     //create a new my card contact
       
    95     contactManager()->saveContact(mContact);
       
    96     contactManager()->setSelfContactId(mContact->localId());
       
    97     //open the contact editor
       
    98     CntViewParameters viewParameters(CntViewParameters::editView);
       
    99     viewParameters.setSelectedContact(*mContact);
       
   100     viewManager()->onActivateView(viewParameters);
       
   101 }
       
   102 
       
   103 /*!
       
   104 Opens the my card selection view
       
   105 */
       
   106 void CntMyCardView::openMyCardSelectionView()
       
   107 {
       
   108     CntViewParameters viewParameters(CntViewParameters::myCardSelectionView);
       
   109     viewManager()->onActivateView(viewParameters);
       
   110 }
       
   111 
       
   112 // EOF