phonebookui/Phonebook/View/src/CPbkContactEditorUrlField.cpp
changeset 0 e686773b3f54
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 URL field.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbkContactEditorUrlField.h"
       
    22 #include "MPbkContactEditorUiBuilder.h"
       
    23 
       
    24 #include <eikdialg.h>
       
    25 #include <eikedwin.h>
       
    26 #include <AknUtils.h>
       
    27 #include <eikcapc.h>
       
    28 
       
    29 #include <TPbkContactItemField.h>
       
    30 #include <CPbkContactItem.h>
       
    31 #include <CPbkFieldInfo.h>
       
    32 #include <CPbkConstants.h>
       
    33 
       
    34 
       
    35 /// Unnamed namespace for local definitons
       
    36 namespace {
       
    37 
       
    38 // LOCAL CONSTANTS AND MACROS
       
    39 
       
    40 #ifdef _DEBUG
       
    41 /// Panic codes for CPbkContactEditorUrlField
       
    42 enum TPanicCode
       
    43     {
       
    44     EPanicPreCond_ConstructL,
       
    45     EPanicPreCond_SaveFieldL
       
    46     };
       
    47 #endif  // _DEBUG
       
    48 
       
    49 // ==================== LOCAL FUNCTIONS ====================
       
    50 
       
    51 #ifdef _DEBUG
       
    52 void Panic(TPanicCode aReason)
       
    53     {
       
    54     _LIT(KPanicText, "CPbkContactEditorUrlField");
       
    55     User::Panic(KPanicText, aReason);
       
    56     }
       
    57 #endif  // _DEBUG
       
    58 
       
    59 }  // namespace
       
    60 
       
    61 _LIT(KHttp, "http://");
       
    62 
       
    63 // ================= MEMBER FUNCTIONS =======================
       
    64 
       
    65 inline CPbkContactEditorUrlField::CPbkContactEditorUrlField
       
    66         (TPbkContactItemField& aField,
       
    67         CPbkIconInfoContainer& aIconInfoContainer,
       
    68         MPbkContactEditorUiBuilder& aUiBuilder) :
       
    69     CPbkContactEditorTextField(aField, aIconInfoContainer, aUiBuilder)
       
    70     {
       
    71     }
       
    72 
       
    73 inline void CPbkContactEditorUrlField::ConstructL()
       
    74     {
       
    75     __ASSERT_DEBUG(ContactItemField().StorageType() == KStorageTypeText,
       
    76         Panic(EPanicPreCond_ConstructL));
       
    77 
       
    78     // Create and insert a line in the dialog
       
    79     iControl = static_cast<CEikEdwin*>(iUiBuilder.CreateLineL(
       
    80             FieldLabel(), ControlId(), EEikCtEdwin));
       
    81 
       
    82     // ctrl is now owned by the dialog
       
    83     AknEditUtils::ConstructEditingL(iControl, ContactItemField().FieldInfo().MaxLength(),
       
    84             CPbkConstants::FieldEditorLength(),
       
    85             EAknEditorTextCase | EAknEditorCharactersUpperCase | EAknEditorCharactersLowerCase, EAknEditorAlignLeft,
       
    86             ETrue, ETrue, EFalse);
       
    87 
       
    88     iControl->SetAknEditorSpecialCharacterTable(
       
    89         R_AVKON_URL_SPECIAL_CHARACTER_TABLE_DIALOG);
       
    90 
       
    91     if (ContactItemField().FieldInfo().EditMode() == EPbkFieldEditModeLatinOnly)
       
    92         {
       
    93         iControl->SetAknEditorFlags(EAknEditorFlagLatinInputModesOnly);
       
    94         }
       
    95 
       
    96     switch (ContactItemField().FieldInfo().DefaultCase())
       
    97         {
       
    98         case EPbkFieldDefaultCaseLower:
       
    99             {
       
   100             iControl->SetAknEditorCase(EAknEditorLowerCase);
       
   101             break;
       
   102             }
       
   103         case EPbkFieldDefaultCaseText:
       
   104             {
       
   105             iControl->SetAknEditorCase(EAknEditorTextCase);
       
   106             break;
       
   107             }
       
   108         default:
       
   109             break;
       
   110         }
       
   111 
       
   112     // Set formatted text to editor control
       
   113     TPtrC text = ContactItemField().Text();
       
   114     if (text.Length() == 0)
       
   115         {
       
   116         // Insert http:// prefix to URL fields
       
   117         iControl->SetTextL(&KHttp());
       
   118         }
       
   119     else
       
   120         {
       
   121         iControl->SetTextL(&text);
       
   122         }
       
   123 
       
   124     LoadBitmapToFieldL(iUiBuilder);
       
   125 
       
   126     // Place cursor to the end of the line
       
   127     iControl->AddFlagToUserFlags(CEikEdwin::EJustAutoCurEnd);
       
   128 
       
   129     // CreateTextViewL() is flagged as deprecated but if it is not
       
   130     // called here the ActivateL() below crashes sometimes.
       
   131     iControl->CreateTextViewL();
       
   132     iCaptionedCtrl = iUiBuilder.LineControl(ControlId());
       
   133     iCaptionedCtrl->SetTakesEnterKey(ETrue);
       
   134     }
       
   135 
       
   136 CPbkContactEditorUrlField* CPbkContactEditorUrlField::NewL
       
   137         (TPbkContactItemField& aField,
       
   138         MPbkContactEditorUiBuilder& aUiBuilder,
       
   139         CPbkIconInfoContainer& aIconInfoContainer)
       
   140     {
       
   141     CPbkContactEditorUrlField* self = new(ELeave) CPbkContactEditorUrlField(
       
   142             aField, aIconInfoContainer, aUiBuilder);
       
   143     CleanupStack::PushL(self);
       
   144     self->ConstructL();
       
   145     CleanupStack::Pop(self);
       
   146     return self;
       
   147     }
       
   148 
       
   149 CPbkContactEditorUrlField::~CPbkContactEditorUrlField()
       
   150     {
       
   151     }
       
   152 
       
   153 void CPbkContactEditorUrlField::SaveFieldL()
       
   154     {
       
   155     __ASSERT_DEBUG(iControl && Field().StorageType() == KStorageTypeText,
       
   156             Panic(EPanicPreCond_SaveFieldL));
       
   157 
       
   158     iContactDataHasChanged = EFalse;
       
   159 
       
   160     HBufC* text = iControl->GetTextInHBufL();
       
   161     if (text)
       
   162         {
       
   163         if (!text->Compare(KHttp))
       
   164             {
       
   165             // field contains only the http:// prefix
       
   166             // do not save
       
   167             Field().TextStorage()->SetTextL(KNullDesC);
       
   168             iContactDataHasChanged = ETrue;
       
   169             }
       
   170         else if (Field().TextStorage()->Text() != *text)
       
   171             {
       
   172             // store the text in the contact item
       
   173             Field().TextStorage()->SetText(text);
       
   174             text = NULL;
       
   175             iContactDataHasChanged = ETrue;
       
   176             }
       
   177         delete text;
       
   178         }
       
   179     else
       
   180         {
       
   181         // Ensure field text is empty
       
   182         if (Field().TextStorage()->Text().Length() > 0)
       
   183             {
       
   184             Field().TextStorage()->SetTextL(KNullDesC);
       
   185             iContactDataHasChanged = ETrue;
       
   186             }
       
   187         }
       
   188     }
       
   189 
       
   190 // End of File