phonebookui/Phonebook/View/src/CPbkContactEditorSyncField.cpp
changeset 0 e686773b3f54
child 21 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002 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 *           Methods for phonebook Contact editor syncronization field.
       
    16 *           Needed to get radio button selection to dialog.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "CPbkContactEditorSyncField.h"
       
    23 #include "MPbkContactEditorUiBuilder.h"
       
    24 #include "MPbkFieldEditorVisitor.h"
       
    25 
       
    26 #include <PbkView.rsg>
       
    27 
       
    28 #include <eikdialg.h>
       
    29 #include <eikedwin.h>
       
    30 #include <AknUtils.h>
       
    31 #include <eikcapc.h>
       
    32 #include <featmgr.h>
       
    33 
       
    34 #include <AknPopupField.h>
       
    35 #include <AknQueryValueText.h>
       
    36 #include <badesca.h>
       
    37 #include <barsread.h>
       
    38 
       
    39 #include <CPbkSyncronizationConstants.h>
       
    40 #include <TPbkContactItemField.h>
       
    41 #include <CPbkContactItem.h>
       
    42 #include <CPbkFieldInfo.h>
       
    43 #include <CPbkConstants.h>
       
    44 
       
    45 
       
    46 /// Unnamed namespace for local definitons
       
    47 namespace {
       
    48 
       
    49 // LOCAL CONSTANTS AND MACROS
       
    50 
       
    51 #ifdef _DEBUG
       
    52 /// Panic codes for CPbkContactEditorSyncField
       
    53 enum TPanicCode
       
    54     {
       
    55     EPanicPreCond_ConstructL,
       
    56 	EPanicPreCond_SaveFieldL
       
    57     };
       
    58 #endif  // _DEBUG
       
    59 
       
    60 
       
    61 // ==================== LOCAL FUNCTIONS ====================
       
    62 
       
    63 #ifdef _DEBUG
       
    64 void Panic(TPanicCode aReason)
       
    65     {
       
    66     _LIT(KPanicText, "CPbkContactEditorSyncField");
       
    67     User::Panic(KPanicText, aReason);
       
    68     }
       
    69 #endif  // _DEBUG
       
    70 
       
    71 }  // namespace
       
    72 
       
    73 
       
    74 // ================= MEMBER FUNCTIONS =======================
       
    75 
       
    76 CPbkContactEditorSyncField::CPbkContactEditorSyncField
       
    77         (TPbkContactItemField& aField,
       
    78 		CPbkIconInfoContainer& aIconInfoContainer,
       
    79 		MPbkContactEditorUiBuilder& aUiBuilder) :
       
    80     CPbkContactEditorFieldBase(aField, aIconInfoContainer, aUiBuilder),
       
    81     iIsUsingDefaultSyncValue(EFalse),
       
    82     iInitialSyncConfSelection(-1)
       
    83     {
       
    84     }
       
    85 
       
    86 inline void CPbkContactEditorSyncField::ConstructL()
       
    87     {
       
    88     __ASSERT_DEBUG(ContactItemField().StorageType() == KStorageTypeText, 
       
    89         Panic(EPanicPreCond_ConstructL));
       
    90 
       
    91     // create textarray
       
    92     iSyncArrayText = CEikonEnv::Static()->ReadDesCArrayResourceL(
       
    93             R_PBK_SYNC_POPUP_ITEMS);
       
    94     iSyncArray = CAknQueryValueTextArray::NewL();
       
    95     iSyncArray->SetArray(*iSyncArrayText);
       
    96     iSyncTextValues = CAknQueryValueText::NewL();
       
    97     iSyncTextValues->SetArrayL(iSyncArray);
       
    98 
       
    99     // set selection to correct item, if aField contains some 
       
   100     DoSetFieldValueAsCurrentSelection();
       
   101 
       
   102     // Create and insert a line in the dialog
       
   103     iControl = static_cast<CAknPopupField*>(iUiBuilder.CreateLineL(
       
   104             FieldLabel(), ControlId(), EAknCtPopupField));
       
   105 
       
   106     // construct the CAknPopupField from resources
       
   107     TResourceReader reader;
       
   108     CEikonEnv::Static()->CreateResourceReaderLC(
       
   109             reader, R_PBK_SYNCRONIZATION_POPUP_DLG);
       
   110     iControl->ConstructFromResourceL(reader);
       
   111     CleanupStack::PopAndDestroy(1); // R_PBK_SYNCRONIZATION_POPUP_DLG
       
   112 
       
   113     // ctrl is now owned by the dialog
       
   114     iControl->SetQueryValueL(iSyncTextValues);
       
   115 
       
   116     iCaptionedCtrl = iUiBuilder.LineControl(ControlId());
       
   117     iCaptionedCtrl->SetTakesEnterKey(ETrue);
       
   118     iCaptionedCtrl->SetOfferHotKeys(ETrue);
       
   119     }
       
   120 
       
   121 CPbkContactEditorSyncField* CPbkContactEditorSyncField::NewL
       
   122         (TPbkContactItemField& aField,
       
   123         MPbkContactEditorUiBuilder& aUiBuilder,
       
   124 		CPbkIconInfoContainer& aIconInfoContainer)
       
   125     {
       
   126     CPbkContactEditorSyncField* self =
       
   127         new(ELeave) CPbkContactEditorSyncField(aField,
       
   128         aIconInfoContainer, aUiBuilder);
       
   129     CleanupStack::PushL(self);
       
   130     self->ConstructL();
       
   131     CleanupStack::Pop(self);
       
   132     return self;
       
   133     }
       
   134 
       
   135 CPbkContactEditorSyncField::~CPbkContactEditorSyncField()
       
   136     {
       
   137     delete iSyncArray;
       
   138     delete iSyncTextValues; 
       
   139     delete iSyncArrayText;   
       
   140     }
       
   141 
       
   142 void CPbkContactEditorSyncField::SaveFieldL()
       
   143     {
       
   144     __ASSERT_DEBUG(iControl && Field().StorageType() == KStorageTypeText, 
       
   145             Panic(EPanicPreCond_SaveFieldL));
       
   146 
       
   147     iContactDataHasChanged = EFalse;
       
   148     
       
   149     // retrieve the selected index
       
   150     const TInt selectedIndex = iSyncTextValues->CurrentValueIndex();
       
   151     // retrieve the syncronization setting text corresponding to the selection
       
   152     const TDesC* syncSetting = &KPbkContactSyncPrivate;
       
   153     // map setting indexes to sync settings
       
   154     switch(selectedIndex)
       
   155         {
       
   156         case EPbkSyncConfPrivate:
       
   157             {
       
   158             syncSetting = &KPbkContactSyncPrivate;
       
   159             break;
       
   160             }
       
   161         case EPbkSyncConfPublic:
       
   162             {
       
   163             syncSetting = &KPbkContactSyncPublic;
       
   164             break;
       
   165             }
       
   166         case EPbkSyncConfNoSync:
       
   167             {
       
   168             syncSetting = &KPbkContactSyncNoSync;
       
   169             break;
       
   170             }
       
   171         default:
       
   172             {
       
   173             syncSetting = &KPbkContactSyncPrivate;
       
   174             break;
       
   175             }
       
   176         }
       
   177 
       
   178     // compare sync setting to existing setting in field
       
   179     if (Field().TextStorage()->Text().CompareF(*syncSetting))
       
   180         {
       
   181         // store the text in the contact item
       
   182         Field().TextStorage()->SetTextL(*syncSetting);
       
   183         iContactDataHasChanged = ETrue;
       
   184         }
       
   185     }
       
   186 
       
   187 TBool CPbkContactEditorSyncField::FieldDataChanged() const
       
   188     {
       
   189     TBool result = EFalse;
       
   190     if (iContactDataHasChanged)
       
   191         {
       
   192         if (iIsUsingDefaultSyncValue && 
       
   193             iSyncTextValues->CurrentValueIndex() == iInitialSyncConfSelection)
       
   194             {
       
   195             // default value hasnt been changed
       
   196             result = EFalse;
       
   197             }
       
   198         else
       
   199             {
       
   200             result = ETrue;
       
   201             }
       
   202         }
       
   203     return result;
       
   204     }
       
   205 
       
   206 void CPbkContactEditorSyncField::AddFieldL(CPbkContactItem& aContact)
       
   207     {
       
   208     // create field to contact item with default sync value
       
   209     TPbkContactItemField* field = aContact.AddOrReturnUnusedFieldL
       
   210         (Field().FieldInfo());
       
   211     if (field)
       
   212         {
       
   213         field->TextStorage()->SetTextL(KPbkContactSyncPrivate);
       
   214         }
       
   215     }
       
   216 
       
   217 void CPbkContactEditorSyncField::ActivateL()
       
   218     {
       
   219     iCaptionedCtrl->ActivateL();
       
   220     }
       
   221 
       
   222 CEikEdwin* CPbkContactEditorSyncField::Control()
       
   223     {
       
   224     // not called by the visitor, doesnt contain a edwin
       
   225     return NULL;
       
   226     }
       
   227 
       
   228 TPbkFieldId CPbkContactEditorSyncField::FieldId()
       
   229     {
       
   230     return ContactItemField().FieldInfo().FieldId();
       
   231     }
       
   232 
       
   233 void CPbkContactEditorSyncField::AcceptL
       
   234         (MPbkFieldEditorVisitor& aVisitor)
       
   235     {
       
   236     aVisitor.VisitL(*this);
       
   237     }
       
   238 
       
   239 TBool CPbkContactEditorSyncField::ConsumesKeyEvent(
       
   240         const TKeyEvent& aKeyEvent, 
       
   241         TEventCode aType)
       
   242     {
       
   243     if (aType == EEventKey && aKeyEvent.iCode == EKeyOK)
       
   244         {
       
   245         return ETrue;
       
   246         }
       
   247     return EFalse;
       
   248     }
       
   249 
       
   250 void CPbkContactEditorSyncField::DoSetFieldValueAsCurrentSelection()
       
   251     {
       
   252     TInt selectedIndex = EPbkSyncConfPrivate;
       
   253     iIsUsingDefaultSyncValue = ETrue;
       
   254 
       
   255     // get the text from the field
       
   256     const TDesC& fieldText = Field().TextStorage()->Text();
       
   257     // safely detect whether theres syncronization setting in the field
       
   258     if (!fieldText.CompareF(KPbkContactSyncPrivate))
       
   259         {
       
   260         selectedIndex = EPbkSyncConfPrivate;
       
   261         iIsUsingDefaultSyncValue = EFalse;
       
   262         }
       
   263     else if (!fieldText.CompareF(KPbkContactSyncPublic))
       
   264         {
       
   265         selectedIndex = EPbkSyncConfPublic;
       
   266         iIsUsingDefaultSyncValue = EFalse;
       
   267         }
       
   268     else if (!fieldText.CompareF(KPbkContactSyncNoSync))
       
   269         {
       
   270         selectedIndex = EPbkSyncConfNoSync;
       
   271         iIsUsingDefaultSyncValue = EFalse;
       
   272         }
       
   273 
       
   274     // set default value
       
   275     iSyncTextValues->SetCurrentValueIndex(selectedIndex);
       
   276     // store initial sync selection index
       
   277     iInitialSyncConfSelection = selectedIndex;
       
   278     }
       
   279 
       
   280 // End of File
       
   281