phonebookui/Phonebook/View/src/CPbkGroupNameQueryDlg.cpp
changeset 0 e686773b3f54
child 68 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 *       Provides methods for Group name query dialog.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CPbkGroupNameQueryDlg.h"  // This class' declaration
       
    22 #include    <cntdb.h>
       
    23 #include    <cntitem.h>
       
    24 #include    <aknnotewrappers.h>
       
    25 #include    <StringLoader.h>
       
    26 #include    <PbkView.rsg>
       
    27 #include    <CPbkContactEngine.h>
       
    28 
       
    29 
       
    30 namespace {
       
    31 
       
    32 // ==================== LOCAL FUNCTIONS ====================
       
    33 
       
    34 /**
       
    35  * Returns true if aDesCArray contains aText by excact comparison.
       
    36  * Discards all directionality markings when comparing texts
       
    37  */
       
    38 TBool Contains(const MDesCArray& aDesCArray, const TDesC& aText)
       
    39     {
       
    40     TBool ret( EFalse );
       
    41     
       
    42     HBufC* text = aText.AllocLC();
       
    43     TPtr textPtr( text->Des() );
       
    44     
       
    45     // Strip any directionality markers to get pure text
       
    46     const TUint32 KPbkLeftToRightMarker = 0x200F;
       
    47     const TUint32 KPbkRightToLeftMarker = 0x200E;
       
    48     const TInt markersLength( 2 );
       
    49     TBuf<markersLength> bufMarkers;
       
    50     bufMarkers.Append( KPbkLeftToRightMarker );
       
    51     bufMarkers.Append( KPbkRightToLeftMarker );
       
    52     AknTextUtils::StripCharacters( textPtr, bufMarkers );
       
    53 
       
    54     const TInt count = aDesCArray.MdcaCount();
       
    55     for (TInt i=0; i < count && !ret; ++i)
       
    56         {
       
    57         HBufC* groupName = aDesCArray.MdcaPoint(i).AllocL();
       
    58         TPtr groupNamePtr( groupName->Des() );
       
    59         AknTextUtils::StripCharacters( groupNamePtr, bufMarkers );
       
    60         if ( groupNamePtr == textPtr)
       
    61             {
       
    62             ret =  ETrue;
       
    63             }
       
    64         delete groupName;
       
    65         }
       
    66     CleanupStack::PopAndDestroy( text );
       
    67     return ret;
       
    68     }
       
    69 
       
    70 }  // namespace
       
    71 
       
    72 
       
    73 // ================= MEMBER FUNCTIONS =======================
       
    74 
       
    75 inline CPbkGroupNameQueryDlg::CPbkGroupNameQueryDlg
       
    76         (TDes& aDataText, 
       
    77         CPbkContactEngine& aEngine) :
       
    78     CAknTextQueryDialog(aDataText),
       
    79     iEngine(aEngine)
       
    80     {
       
    81     }
       
    82 
       
    83 inline void CPbkGroupNameQueryDlg::ConstructL(TBool aNameGeneration)
       
    84     {
       
    85     // Create group name array
       
    86     iGroupLabelsArray = new(ELeave) CDesCArrayFlat(8);
       
    87     
       
    88     CContactIdArray* idArray = iEngine.Database().GetGroupIdListL();
       
    89     if (idArray)
       
    90         {
       
    91         CleanupStack::PushL(idArray);
       
    92         for (TInt i = 0; i < idArray->Count(); ++i)
       
    93             {
       
    94             CContactGroup* group = iEngine.ReadContactGroupL((*idArray)[i]);
       
    95             CleanupStack::PushL(group);
       
    96             iGroupLabelsArray->AppendL(group->GetGroupLabelL());
       
    97             CleanupStack::PopAndDestroy(); // group
       
    98             }
       
    99         CleanupStack::PopAndDestroy(idArray); 
       
   100 
       
   101         if (aNameGeneration)
       
   102             {
       
   103             UpdateGroupTitleL();
       
   104             }
       
   105         }
       
   106     }
       
   107 
       
   108 EXPORT_C CPbkGroupNameQueryDlg* CPbkGroupNameQueryDlg::NewL
       
   109         (TDes& aDataText, 
       
   110         CPbkContactEngine& aEngine, 
       
   111         TBool aNameGeneration /*=ETrue*/)
       
   112     {
       
   113     CPbkGroupNameQueryDlg* self = new(ELeave) CPbkGroupNameQueryDlg(aDataText, aEngine);
       
   114     CleanupStack::PushL(self);
       
   115     self->ConstructL(aNameGeneration);
       
   116     CleanupStack::Pop(self);
       
   117     return self;
       
   118     }
       
   119 
       
   120 CPbkGroupNameQueryDlg::~CPbkGroupNameQueryDlg()
       
   121     {
       
   122     // delete data members
       
   123     delete iGroupLabelsArray;
       
   124     }
       
   125 
       
   126 EXPORT_C TBool CPbkGroupNameQueryDlg::OkToExitL(TInt aButtonId)
       
   127     {
       
   128     TBool result = CAknTextQueryDialog::OkToExitL(aButtonId);
       
   129 
       
   130     // if entry with same name - not ok.
       
   131     if (Contains(*iGroupLabelsArray, Text()))
       
   132         {
       
   133         // display information note
       
   134         HBufC* prompt = StringLoader::LoadLC(R_QTN_FLDR_NAME_ALREADY_USED, Text());
       
   135         CAknInformationNote* dlg = new(ELeave) CAknInformationNote(ETrue);
       
   136         dlg->ExecuteLD(*prompt);
       
   137         CleanupStack::PopAndDestroy(); // prompt
       
   138         CAknQueryControl* queryControl = QueryControl();
       
   139         if (queryControl)
       
   140             {
       
   141             CEikEdwin* edwin = static_cast<CEikEdwin*>(queryControl->ControlByLayoutOrNull(EDataLayout));
       
   142             if (edwin)
       
   143                 {
       
   144                 edwin->SetSelectionL(edwin->TextLength(), 0);
       
   145                 }
       
   146             }
       
   147         result = EFalse;
       
   148         }
       
   149 
       
   150     return result;
       
   151     }
       
   152 
       
   153 void CPbkGroupNameQueryDlg::UpdateGroupTitleL()
       
   154     {
       
   155     TBool found = EFalse;
       
   156     for (TInt number = 1; !found; ++number)
       
   157         {
       
   158         HBufC* groupTitle = StringLoader::LoadLC(R_PBK_QTN_FLDR_DEFAULT_GROUP_NAME, number);
       
   159 		
       
   160 		// Convert the digits if necessary
       
   161 		TPtr ptr = groupTitle->Des();
       
   162 		AknTextUtils::DisplayTextLanguageSpecificNumberConversion(ptr);
       
   163 
       
   164         if (!Contains(*iGroupLabelsArray, *groupTitle))
       
   165             {
       
   166             Text().Copy(*groupTitle);
       
   167             found = ETrue;
       
   168             }
       
   169         CleanupStack::PopAndDestroy(groupTitle);
       
   170         }
       
   171     }
       
   172 
       
   173 
       
   174 //  End of File