phonebookui/Phonebook2/ServerApplication/src/CPbk2AssignCreateNewProperty.cpp
changeset 0 e686773b3f54
child 68 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Phonebook 2 contact field property selector
       
    15 *              : for new contact creation.
       
    16 *
       
    17 */
       
    18 
       
    19 #include "CPbk2AssignCreateNewProperty.h"
       
    20 
       
    21 // Phonebook 2
       
    22 #include "TPbk2AssignNoteService.h"
       
    23 #include <Pbk2UIControls.rsg>
       
    24 #include <Pbk2ServerApp.rsg>
       
    25 #include <MPbk2FieldProperty.h>
       
    26 #include <TPbk2AddItemWrapper.h>
       
    27 
       
    28 // Virtual Phonebook
       
    29 #include <MVPbkContactStoreProperties.h>
       
    30 #include <VPbkContactStoreUris.h>
       
    31 #include <MVPbkContactStore.h>
       
    32 #include <MVPbkContactStoreInfo.h>
       
    33 #include <MVPbkContactStoreList.h>
       
    34 #include <CVPbkContactManager.h>
       
    35 
       
    36 // System includes
       
    37 #include <StringLoader.h>
       
    38 #include <AknQueryDialog.h>
       
    39 
       
    40 /// Unnamed namespace for local definitions
       
    41 namespace {
       
    42 
       
    43 /**
       
    44  * Checks is the given contact store full.
       
    45  *
       
    46  * @param aTargetStore      Store to inspect.
       
    47  * @return  ETrue if store is full.
       
    48  */
       
    49 TBool StoreFullL( const MVPbkContactStore& aTargetStore )
       
    50     {
       
    51     TBool ret( EFalse );
       
    52 
       
    53     const MVPbkContactStoreInfo& storeInfo = aTargetStore.StoreInfo();
       
    54     if ( storeInfo.MaxNumberOfContactsL() != KVPbkStoreInfoUnlimitedNumber &&
       
    55          storeInfo.MaxNumberOfContactsL() <= storeInfo.NumberOfContactsL() )
       
    56         {
       
    57         ret = ETrue;
       
    58         }
       
    59 
       
    60     return ret;
       
    61     }
       
    62 
       
    63 } /// namespace
       
    64 
       
    65 
       
    66 // --------------------------------------------------------------------------
       
    67 // CPbk2AssignCreateNewProperty::CPbk2AssignCreateNewProperty
       
    68 // --------------------------------------------------------------------------
       
    69 //
       
    70 CPbk2AssignCreateNewProperty::CPbk2AssignCreateNewProperty
       
    71         ( HBufC8& aSelector, TInt aResourceId,
       
    72           MVPbkContactStore*& aContactStore,
       
    73           const CPbk2StorePropertyArray& aStoreProperties,
       
    74           CVPbkContactManager& aContactManager ) :
       
    75             CPbk2SelectFieldPropertyBase( aSelector, aResourceId ),
       
    76             iContactStore( aContactStore ),
       
    77             iStoreProperties( aStoreProperties ),
       
    78             iContactManager ( aContactManager )
       
    79     {
       
    80     }
       
    81 
       
    82 // --------------------------------------------------------------------------
       
    83 // CPbk2AssignCreateNewProperty::~CPbk2AssignCreateNewProperty
       
    84 // --------------------------------------------------------------------------
       
    85 //
       
    86 CPbk2AssignCreateNewProperty::~CPbk2AssignCreateNewProperty()
       
    87     {
       
    88     }
       
    89 
       
    90 // --------------------------------------------------------------------------
       
    91 // CPbk2AssignCreateNewProperty::NewL
       
    92 // --------------------------------------------------------------------------
       
    93 //
       
    94 CPbk2AssignCreateNewProperty* CPbk2AssignCreateNewProperty::NewL
       
    95         ( HBufC8& aSelector, MVPbkContactStore*& aContactStore,
       
    96           const CPbk2StorePropertyArray& aStoreProperties,
       
    97           CVPbkContactManager& aContactManager )
       
    98     {
       
    99     CPbk2AssignCreateNewProperty* self =
       
   100         new ( ELeave ) CPbk2AssignCreateNewProperty
       
   101             ( aSelector, R_QTN_PHOB_QTL_ENTRY_CREATE, aContactStore,
       
   102               aStoreProperties, aContactManager );
       
   103     CleanupStack::PushL( self );
       
   104     self->ConstructL();
       
   105     CleanupStack::Pop( self );
       
   106     return self;
       
   107     }
       
   108 
       
   109 // --------------------------------------------------------------------------
       
   110 // CPbk2AssignCreateNewProperty::ConstructL
       
   111 // --------------------------------------------------------------------------
       
   112 //
       
   113 void CPbk2AssignCreateNewProperty::ConstructL()
       
   114     {
       
   115     BaseConstructL();
       
   116     }
       
   117 
       
   118 // --------------------------------------------------------------------------
       
   119 // CPbk2AssignCreateNewProperty::PrepareL
       
   120 // --------------------------------------------------------------------------
       
   121 //
       
   122 void CPbk2AssignCreateNewProperty::PrepareL()
       
   123     {
       
   124     TPbk2AssignNoteService noteService;
       
   125     TVPbkContactStoreUriPtr storeUri =
       
   126         iContactStore->StoreProperties().Uri();
       
   127 
       
   128     if ( StoreFullL( *iContactStore ) )
       
   129         {
       
   130         noteService.ShowStoreFullNoteL( *iContactStore, iStoreProperties );
       
   131 
       
   132         if ( noteService.ShowCreateNewToPhoneQueryL() )
       
   133             {
       
   134             // Safe to assume that phone memory store never gets full
       
   135             storeUri.Set( VPbkContactStoreUris::DefaultCntDbUri() );
       
   136             CreateWrappersL( storeUri );
       
   137             // Change target store
       
   138             iContactStore =
       
   139                 iContactManager.ContactStoresL().Find( storeUri );
       
   140             }
       
   141         }
       
   142     else
       
   143         {
       
   144         CreateWrappersL( storeUri );
       
   145 
       
   146         if ( iWrappers.Count() <= 0 )
       
   147             {
       
   148             TInt compare = storeUri.Compare
       
   149                 ( VPbkContactStoreUris::DefaultCntDbUri(),
       
   150                   TVPbkContactStoreUriPtr::EContactStoreUriAllComponents );
       
   151 
       
   152             // Show create new entry to phone memory query
       
   153             if ( ( compare  != 0 ) &&
       
   154                  noteService.ShowCreateNewToPhoneQueryL() )
       
   155                 {
       
   156                 storeUri.Set( VPbkContactStoreUris::DefaultCntDbUri() );
       
   157                 CreateWrappersL( storeUri  );
       
   158                 // Change target store
       
   159                 iContactStore =
       
   160                     iContactManager.ContactStoresL().Find( storeUri );
       
   161                 }
       
   162             }
       
   163         }
       
   164     }
       
   165 
       
   166 // --------------------------------------------------------------------------
       
   167 // CPbk2AssignCreateNewProperty::ExecuteL
       
   168 // --------------------------------------------------------------------------
       
   169 //
       
   170 TInt CPbk2AssignCreateNewProperty::ExecuteL()
       
   171     {
       
   172     TInt result = ShowSelectFieldQueryL();
       
   173 
       
   174     if ( result > KErrNotFound &&
       
   175          iWrappers.Count() > 0 &&
       
   176          iWrappers.Count() > result )
       
   177         {
       
   178         iSelectedFieldType = &iWrappers[result].PropertyAt( 0 ).FieldType();
       
   179         // ShowSelectFieldQuery returns the index of field, anyhow
       
   180         // this method should return an error code.
       
   181         result = KErrNone;
       
   182         }
       
   183 
       
   184     return result;
       
   185     }
       
   186 
       
   187 // --------------------------------------------------------------------------
       
   188 // CPbk2AssignCreateNewProperty::SelectedFieldIndex
       
   189 // --------------------------------------------------------------------------
       
   190 //
       
   191 TInt CPbk2AssignCreateNewProperty::SelectedFieldIndex() const
       
   192     {
       
   193     return KErrNotSupported;
       
   194     }
       
   195 
       
   196 // End of File