phonebookui/Phonebook2/ccapplication/ccacontactorservice/src/ccacontactorpopuphandler.cpp
changeset 0 e686773b3f54
child 57 2666d9724c76
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 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:  Class for handling popup query.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <s32mem.h>
       
    21 #include <aknappui.h>
       
    22 #include <coemain.h> 
       
    23 
       
    24 #include "ccacontactorserviceheaders.h"
       
    25 
       
    26 // ================= MEMBER FUNCTIONS =======================
       
    27 //
       
    28 
       
    29 // --------------------------------------------------------------------------
       
    30 // CCCAContactorPopupHandler::NewL
       
    31 // --------------------------------------------------------------------------
       
    32 //
       
    33 CCCAContactorPopupHandler* CCCAContactorPopupHandler::NewL()
       
    34     {
       
    35     CCCAContactorPopupHandler* self = new (ELeave) CCCAContactorPopupHandler();
       
    36     CleanupStack::PushL(self);
       
    37     self->ConstructL();
       
    38     CleanupStack::Pop(self);
       
    39     return self;
       
    40     }
       
    41 
       
    42 // --------------------------------------------------------------------------
       
    43 // CCCAContactorPopupHandler::~CCCAContactorPopupHandler
       
    44 // --------------------------------------------------------------------------
       
    45 //
       
    46 CCCAContactorPopupHandler::~CCCAContactorPopupHandler()
       
    47     {
       
    48     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorPopupHandler::~CCCAContactorPopupHandler"));
       
    49     delete iServiceHandler;
       
    50     delete iSchedulerWait;
       
    51     iCoeEnv.DeleteResourceFile (iResourceOffset);
       
    52     delete iQueryResults;
       
    53     }
       
    54 
       
    55 // --------------------------------------------------------------------------
       
    56 // CCCAContactorPopupHandler::LaunchPopupL
       
    57 // --------------------------------------------------------------------------
       
    58 //
       
    59 TDesC& CCCAContactorPopupHandler::LaunchPopupL(
       
    60     const TDesC8& aContactLinkArray,
       
    61     TAiwCommAddressSelectType aCommAddressSelectType,
       
    62     TBool aUseDefaults )
       
    63     {
       
    64     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorPopupHandler::LaunchPopupL"));
       
    65 
       
    66     __ASSERT_ALWAYS (NULL != &aContactLinkArray, User::Leave (KErrArgument));
       
    67     __ASSERT_ALWAYS (0 < aContactLinkArray.Size(), User::Leave (KErrArgument));
       
    68 
       
    69     TUint fetchFlags = 0;
       
    70 
       
    71     // Stop scheduler just in case this is called while operation is still ongoing.
       
    72     AsyncStop();
       
    73     
       
    74     // Set service data
       
    75     TAiwSingleItemSelectionDataV3 data;
       
    76 
       
    77     if (!aUseDefaults)
       
    78         {
       
    79         fetchFlags |= ::EDoNotUseDefaultField;
       
    80         }
       
    81 
       
    82     data.SetFlags(fetchFlags);
       
    83     data.SetCommAddressSelectType(aCommAddressSelectType);
       
    84     CAiwGenericParamList& inParamList = iServiceHandler->InParamListL();
       
    85     inParamList.AppendL(TAiwGenericParam(EGenericParamContactSelectionData,
       
    86         TAiwVariant(TAiwSingleItemSelectionDataV3Pckg(data))));
       
    87 
       
    88     // Set contactlink
       
    89     inParamList.AppendL(TAiwGenericParam(EGenericParamContactLinkArray,
       
    90         TAiwVariant(aContactLinkArray)));
       
    91 
       
    92     iServiceHandler->ExecuteServiceCmdL(KAiwCmdSelect, inParamList,
       
    93         iServiceHandler->OutParamListL(), 0, this);
       
    94 
       
    95     CAknInputBlock* inputBlock = CAknInputBlock::NewCancelHandlerLC( this );
       
    96     iCloseApp = EFalse;
       
    97     
       
    98     // Waiting for popup selection.
       
    99     // Make this whole operation look synchronous
       
   100     iSchedulerWait->Start();
       
   101     
       
   102     CleanupStack::PopAndDestroy( inputBlock );
       
   103     
       
   104     // If error case occurred, leave
       
   105     if (KErrNone != iError)
       
   106         {
       
   107         if (iCloseApp)
       
   108             {
       
   109             // Send an exit command in order to close CCA and Phonebook2
       
   110             // once the end(red) key is pressed or Exit command 
       
   111             CAknAppUi* appUi = static_cast<CAknAppUi*>( iCoeEnv.AppUi() );
       
   112 
       
   113             if ( appUi )
       
   114                 {
       
   115                 appUi->ProcessCommandL( EAknCmdExit );
       
   116                 }
       
   117             }
       
   118         User::Leave(iError);
       
   119         }
       
   120 
       
   121     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorPopupHandler::LaunchPopupL: Done."));
       
   122 
       
   123     return *iQueryResults;
       
   124     }
       
   125 
       
   126 // --------------------------------------------------------------------------
       
   127 // CCCAContactorPopupHandler::HandleNotifyL
       
   128 // --------------------------------------------------------------------------
       
   129 //
       
   130 TInt CCCAContactorPopupHandler::HandleNotifyL(TInt aCmdId, TInt aEventId,
       
   131         CAiwGenericParamList& aEventParamList,
       
   132         const CAiwGenericParamList& /*aInParamList*/)
       
   133     {
       
   134     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorPopupHandler::HandleNotifyL"));
       
   135     TInt returnValue = KErrNone;
       
   136 
       
   137     if (aCmdId == KAiwCmdSelect)
       
   138         {
       
   139         switch(aEventId)
       
   140             {
       
   141             case KAiwEventCompleted:
       
   142                 {
       
   143                 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorPopupHandler::HandleNotifyL: KAiwEventCompleted"));
       
   144                 // Selection done.
       
   145                 // Read and store results
       
   146                 TRAP(iError, ReadFieldDataL(aEventParamList));
       
   147                 }
       
   148                 break;
       
   149 
       
   150             case KAiwEventCanceled:
       
   151                 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorPopupHandler::HandleNotifyL: KAiwEventCanceled"));
       
   152                 // Selection canceled.
       
   153                 iError = KErrCancel;
       
   154                 break;
       
   155 
       
   156             case KAiwEventError:
       
   157             case KAiwEventStopped:
       
   158                 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorPopupHandler::HandleNotifyL: KAiwEventError or KAiwEventStopped"));
       
   159                 // Error occurred.
       
   160                 iError = KErrGeneral;
       
   161                 break;
       
   162 
       
   163             case KAiwEventQueryExit:
       
   164                 // TODO: how should this work?
       
   165                 iError = KErrAbort;
       
   166                 iCloseApp = ETrue;
       
   167                 returnValue = ETrue;
       
   168                 break;
       
   169 
       
   170             default:
       
   171                 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorPopupHandler::HandleNotifyL: Unknown"));
       
   172                 iError = KErrGeneral;
       
   173                 break;
       
   174             }
       
   175         // if notify received, stop scheduler
       
   176         AsyncStop();
       
   177         }
       
   178 
       
   179     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorPopupHandler::HandleNotifyL: Done."));
       
   180     return returnValue;
       
   181     }
       
   182 
       
   183 // --------------------------------------------------------------------------
       
   184 // CCCAContactorPopupHandler::CCCAContactorPopupHandler
       
   185 // --------------------------------------------------------------------------
       
   186 //
       
   187 CCCAContactorPopupHandler::CCCAContactorPopupHandler() :
       
   188     iCoeEnv(*CCoeEnv::Static()),
       
   189     iError(KErrNone)
       
   190     {
       
   191     }
       
   192 
       
   193 // --------------------------------------------------------------------------
       
   194 // CCCAContactorPopupHandler::ConstructL
       
   195 // --------------------------------------------------------------------------
       
   196 //
       
   197 void CCCAContactorPopupHandler::ConstructL()
       
   198     {
       
   199     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorPopupHandler::ConstructL"));
       
   200 
       
   201     PrepareResourcesL();
       
   202 
       
   203     iServiceHandler = CAiwServiceHandler::NewL();
       
   204     iServiceHandler->AttachL(R_CCACONTACTORSERVICE_CONTACT_SELECTION_INTEREST);
       
   205 
       
   206     iSchedulerWait = new (ELeave) CActiveSchedulerWait();
       
   207 
       
   208     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorPopupHandler::ConstructL: Done."));
       
   209     }
       
   210 
       
   211 // --------------------------------------------------------------------------
       
   212 // CCCAContactorPopupHandler::PrepareResourcesL
       
   213 // --------------------------------------------------------------------------
       
   214 //
       
   215 void CCCAContactorPopupHandler::PrepareResourcesL()
       
   216     {
       
   217     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorPopupHandler::PrepareResourcesL"));
       
   218 
       
   219     // preparing resources for use
       
   220     TFileName fileName;
       
   221     fileName.Append (KCCAContactorServiceResourceFileName);
       
   222 
       
   223     BaflUtils::NearestLanguageFile (iCoeEnv.FsSession (), fileName);
       
   224     if (ConeUtils::FileExists (fileName))
       
   225         {
       
   226         iResourceOffset = iCoeEnv.AddResourceFileL (fileName);
       
   227         }
       
   228     else // not found from user drive, leave badly.
       
   229         {
       
   230         CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorPopupHandler::PrepareResourcesL: Resource file not exists."));
       
   231         User::Leave (KErrGeneral);
       
   232         }
       
   233 
       
   234     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorPopupHandler::PrepareResourcesL: Done."));
       
   235     }
       
   236 
       
   237 // --------------------------------------------------------------------------
       
   238 // CCCAContactorPopupHandler::ReadFieldDataL
       
   239 // --------------------------------------------------------------------------
       
   240 //
       
   241 void CCCAContactorPopupHandler::ReadFieldDataL(
       
   242     CAiwGenericParamList& aEventParamList)
       
   243     {
       
   244     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorPopupHandler::ReadFieldDataL"));
       
   245 
       
   246     if (iQueryResults)
       
   247         {
       
   248         delete iQueryResults;
       
   249         iQueryResults = NULL;
       
   250         }
       
   251 
       
   252     TInt index = 1; // Get field data from index 1
       
   253     const TAiwGenericParam* param =
       
   254          aEventParamList.FindFirst(index, EGenericParamContactFieldData);
       
   255     if (KErrNotFound != index)
       
   256         {
       
   257         TInt length = param->Value().AsDes().Length();
       
   258         iQueryResults = HBufC::NewL(length);
       
   259         iQueryResults->Des().Append(param->Value().AsDes());
       
   260 
       
   261         // Data must be found!
       
   262         if (0 >= iQueryResults->Length())
       
   263             {
       
   264             CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorPopupHandler::ReadFieldDataL: Failed to get field data!"));
       
   265             User::Leave(KErrGeneral);
       
   266             }
       
   267         }
       
   268     else
       
   269         {
       
   270         CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorPopupHandler::ReadFieldDataL: Not found!"));
       
   271         User::Leave(KErrNotFound);
       
   272         }
       
   273 
       
   274     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorPopupHandler::ReadFieldDataL: Done."));
       
   275     }
       
   276 
       
   277 // --------------------------------------------------------------------------
       
   278 // CCCAContactorPopupHandler::AsyncStop
       
   279 // --------------------------------------------------------------------------
       
   280 //
       
   281 void CCCAContactorPopupHandler::AsyncStop()
       
   282     {
       
   283     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorPopupHandler::AsyncStop"));
       
   284 
       
   285     if(iSchedulerWait->IsStarted())
       
   286         {
       
   287         iSchedulerWait->AsyncStop();
       
   288         }
       
   289 
       
   290     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorPopupHandler::AsyncStop: Done."));
       
   291     }
       
   292 
       
   293 // --------------------------------------------------------------------------
       
   294 // CCCAContactorPopupHandler::AknInputBlockCancel
       
   295 // --------------------------------------------------------------------------
       
   296 //
       
   297 void CCCAContactorPopupHandler::AknInputBlockCancel()
       
   298     {
       
   299     if ( iSchedulerWait->IsStarted() )
       
   300         {
       
   301         TRAPD( error, iServiceHandler->ExecuteServiceCmdL( KAiwCmdSelect, 
       
   302                                                            iServiceHandler->InParamListL(), 
       
   303                                                            iServiceHandler->OutParamListL(),
       
   304                                                            KAiwOptCancel,
       
   305                                                            this ) );
       
   306         if ( error == KErrNone )
       
   307             {
       
   308             iCloseApp = ETrue;
       
   309             }
       
   310         }
       
   311     }
       
   312 
       
   313 // End of file