phonebookui/Phonebook2/CommandsExtension/src/CPbk2InfoDialogCmd.cpp
changeset 0 e686773b3f54
child 21 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002-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:  A command for launching phonebook info dialog
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbk2InfoDialogCmd.h"
       
    22 
       
    23 // Phonebook 2
       
    24 #include <Pbk2Commands.rsg>
       
    25 #include <MPbk2CommandObserver.h>
       
    26 #include <CPbk2StoreListQuery.h>
       
    27 #include <CPbk2PhonebookInfoDlg.h>
       
    28 #include <CPbk2StoreProperty.h>
       
    29 #include <CPbk2StorePropertyArray.h>
       
    30 #include <CPbk2ApplicationServices.h>
       
    31 #include <MPbk2StoreValidityInformer.h>
       
    32 #include <MPbk2AppUi.h>
       
    33 
       
    34 // Virtual Phonebook
       
    35 #include <CVPbkContactStoreUriArray.h>
       
    36 
       
    37 // System includes
       
    38 #include <StringLoader.h>
       
    39 #include <avkon.hrh>
       
    40 
       
    41 /// Unnamed namespace for local definitions
       
    42 namespace {
       
    43 
       
    44 const TInt KOneValidStore = 1;
       
    45 
       
    46 enum TPbk2InfoDialogCmdState
       
    47     {
       
    48     EQuery,
       
    49     ELaunchDialog,
       
    50     EComplete
       
    51     };
       
    52    
       
    53 } /// namespace
       
    54 
       
    55 // --------------------------------------------------------------------------
       
    56 // CPbk2InfoDialogCmd::CPbk2InfoDialogCmd
       
    57 // --------------------------------------------------------------------------
       
    58 //
       
    59 CPbk2InfoDialogCmd::CPbk2InfoDialogCmd
       
    60         ( MPbk2ContactUiControl& /*aUiControl*/ ) :
       
    61             CActive( EPriorityStandard )
       
    62     {
       
    63     }
       
    64 
       
    65 // --------------------------------------------------------------------------
       
    66 // CPbk2InfoDialogCmd::~CPbk2InfoDialogCmd
       
    67 // --------------------------------------------------------------------------
       
    68 //
       
    69 CPbk2InfoDialogCmd::~CPbk2InfoDialogCmd()
       
    70     {
       
    71     Cancel();
       
    72     delete iValidStores;
       
    73     }
       
    74 
       
    75 // --------------------------------------------------------------------------
       
    76 // CPbk2InfoDialogCmd::NewL
       
    77 // --------------------------------------------------------------------------
       
    78 //
       
    79 CPbk2InfoDialogCmd* CPbk2InfoDialogCmd::NewL(
       
    80         MPbk2ContactUiControl& aUiControl)
       
    81     {
       
    82     CPbk2InfoDialogCmd* self = 
       
    83         new( ELeave ) CPbk2InfoDialogCmd(aUiControl);    
       
    84     CleanupStack::PushL( self );
       
    85     self->ConstructL();
       
    86     CleanupStack::Pop( self );
       
    87     return self;
       
    88     }
       
    89 
       
    90 // --------------------------------------------------------------------------
       
    91 // CPbk2InfoDialogCmd::ConstructL
       
    92 // --------------------------------------------------------------------------
       
    93 //
       
    94 void CPbk2InfoDialogCmd::ConstructL()
       
    95     {
       
    96     CActiveScheduler::Add(this);
       
    97     }
       
    98 
       
    99 // --------------------------------------------------------------------------
       
   100 // CPbk2InfoDialogCmd::ExecuteLD
       
   101 // --------------------------------------------------------------------------
       
   102 //
       
   103 void CPbk2InfoDialogCmd::ExecuteLD()
       
   104     {
       
   105     IssueRequest();
       
   106     }
       
   107 
       
   108 // --------------------------------------------------------------------------
       
   109 // CPbk2InfoDialogCmd::AddObserver
       
   110 // --------------------------------------------------------------------------
       
   111 //
       
   112 void CPbk2InfoDialogCmd::AddObserver(MPbk2CommandObserver& aObserver)
       
   113     {
       
   114     iCommandObserver = &aObserver;
       
   115     }
       
   116 
       
   117 // --------------------------------------------------------------------------
       
   118 // CPbk2InfoDialogCmd::ResetUiControl
       
   119 // --------------------------------------------------------------------------
       
   120 //
       
   121 void CPbk2InfoDialogCmd::ResetUiControl(
       
   122         MPbk2ContactUiControl& /*aUiControl*/)
       
   123     {
       
   124     // Do nothing
       
   125     }
       
   126 
       
   127 // --------------------------------------------------------------------------
       
   128 // CPbk2InfoDialogCmd::RunL
       
   129 // --------------------------------------------------------------------------
       
   130 //
       
   131 void CPbk2InfoDialogCmd::RunL()
       
   132     {
       
   133     switch (iState)
       
   134         {
       
   135         case EQuery:
       
   136             {
       
   137             QueryL();
       
   138             break;
       
   139             } 
       
   140         case ELaunchDialog:
       
   141             {
       
   142             LaunchDialogL();
       
   143             break;
       
   144             }
       
   145         case EComplete: // FALLTHROUGH
       
   146         default:
       
   147             {
       
   148             iCommandObserver->CommandFinished(*this);
       
   149             break;
       
   150             }
       
   151         }
       
   152     }
       
   153 
       
   154 // --------------------------------------------------------------------------
       
   155 // CPbk2InfoDialogCmd::DoCancel
       
   156 // --------------------------------------------------------------------------
       
   157 //        
       
   158 void CPbk2InfoDialogCmd::DoCancel()
       
   159     {
       
   160     }
       
   161 
       
   162 // --------------------------------------------------------------------------
       
   163 // CPbk2InfoDialogCmd::RunError
       
   164 // --------------------------------------------------------------------------
       
   165 //
       
   166 TInt CPbk2InfoDialogCmd::RunError(TInt aError)
       
   167     {
       
   168     HandleError(aError);
       
   169     return KErrNone;
       
   170     }
       
   171     
       
   172 // --------------------------------------------------------------------------
       
   173 // CPbk2InfoDialogCmd::IssueRequest
       
   174 // --------------------------------------------------------------------------
       
   175 //
       
   176 void CPbk2InfoDialogCmd::IssueRequest()
       
   177     {
       
   178     TRequestStatus* status = &iStatus;
       
   179     User::RequestComplete(status, KErrNone);
       
   180     SetActive();
       
   181     }
       
   182 
       
   183 // --------------------------------------------------------------------------
       
   184 // CPbk2InfoDialogCmd::HandleError
       
   185 // --------------------------------------------------------------------------
       
   186 //
       
   187 void CPbk2InfoDialogCmd::QueryL()
       
   188     {
       
   189     iState = EComplete;
       
   190     
       
   191     CPbk2ApplicationServices* appServices = CPbk2ApplicationServices::InstanceLC();
       
   192 
       
   193     iValidStores = appServices->StoreValidityInformer().CurrentlyValidStoresL();
       
   194     const CPbk2StorePropertyArray& props = appServices->StoreProperties();
       
   195 
       
   196     CleanupStack::PopAndDestroy(); // appServices
       
   197 
       
   198     TInt count = iValidStores->Count();
       
   199     // Remove stores that hasn't define memory info types
       
   200     for (TInt i = count - 1; i >= 0; --i)
       
   201         {
       
   202         const CPbk2StoreProperty* prop =
       
   203             props.FindProperty((*iValidStores)[i]);
       
   204         if (!prop || (prop && prop->MemoryInfoTypes() == 0))
       
   205             {
       
   206             iValidStores->Remove((*iValidStores)[i]);
       
   207             }
       
   208         }
       
   209         
       
   210     if (iValidStores->Count() > KOneValidStore)
       
   211         {
       
   212         HBufC* title = StringLoader::LoadLC
       
   213             (R_QTN_PHOB_QUERY_TITLE_SELECT_MEM);
       
   214         CPbk2StoreListQuery* query = CPbk2StoreListQuery::NewL();
       
   215         CleanupStack::PushL(query);
       
   216         HBufC* allText = StringLoader::LoadLC
       
   217             (R_QTN_PHOB_QUERY_SELECT_MEM_ALL);
       
   218         query->SetAllItemTextL(*allText, ETrue);
       
   219         CleanupStack::PopAndDestroy(allText);
       
   220         CleanupStack::Pop(query);
       
   221         
       
   222         // Query modifies iTargetStoreUris -array.
       
   223         // After the query the must be only one, the selected, store
       
   224         if (query->ExecuteLD(*title, *iValidStores) == EAknSoftkeyOk)
       
   225             {
       
   226             iState = ELaunchDialog;
       
   227             }
       
   228         CleanupStack::PopAndDestroy(title);
       
   229         }
       
   230     else
       
   231         {
       
   232         iState = ELaunchDialog;
       
   233         }
       
   234     IssueRequest();
       
   235     }
       
   236 
       
   237 // --------------------------------------------------------------------------
       
   238 // CPbk2InfoDialogCmd::LaunchDialogL
       
   239 // --------------------------------------------------------------------------
       
   240 //
       
   241 void CPbk2InfoDialogCmd::LaunchDialogL()
       
   242     {
       
   243     CPbk2PhonebookInfoDlg* dlg = CPbk2PhonebookInfoDlg::NewL();
       
   244     dlg->ExecuteLD(*iValidStores);
       
   245     iState = EComplete;
       
   246     IssueRequest();
       
   247     }
       
   248     
       
   249 // --------------------------------------------------------------------------
       
   250 // CPbk2InfoDialogCmd::HandleError
       
   251 // --------------------------------------------------------------------------
       
   252 //
       
   253 void CPbk2InfoDialogCmd::HandleError(TInt aError)
       
   254     {
       
   255     if (aError != KErrNone)
       
   256         {
       
   257         iCommandObserver->CommandFinished(*this);
       
   258         CCoeEnv::Static()->HandleError(aError);
       
   259         }
       
   260     }
       
   261     
       
   262 //  End of File