phonebookui/Phonebook2/ccapplication/ccacontactorservice/src/ccacontactorserviceoperator.cpp
changeset 0 e686773b3f54
child 7 b3431bff8c19
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 service logic.
       
    15  *
       
    16 */
       
    17 
       
    18 #include <e32std.h>
       
    19 #include <s32mem.h>
       
    20 
       
    21 #include "ccacontactorserviceheaders.h"
       
    22 
       
    23 // ================= MEMBER FUNCTIONS =======================
       
    24 //
       
    25 
       
    26 // --------------------------------------------------------------------------
       
    27 // CCCAContactorServiceOperator::NewLC
       
    28 // --------------------------------------------------------------------------
       
    29 //
       
    30 CCCAContactorServiceOperator* CCCAContactorServiceOperator::NewLC()
       
    31     {
       
    32     CCCAContactorServiceOperator* self = new (ELeave) CCCAContactorServiceOperator();
       
    33     CleanupStack::PushL(self);
       
    34     self->ConstructL();
       
    35     return self;
       
    36     }
       
    37 
       
    38 // --------------------------------------------------------------------------
       
    39 // CCCAContactorServiceOperator::NewL
       
    40 // --------------------------------------------------------------------------
       
    41 //
       
    42 CCCAContactorServiceOperator* CCCAContactorServiceOperator::NewL()
       
    43     {
       
    44     CCCAContactorServiceOperator* self = CCCAContactorServiceOperator::NewLC();
       
    45     CleanupStack::Pop(self);
       
    46     return self;
       
    47     }
       
    48 
       
    49 // --------------------------------------------------------------------------
       
    50 // CCCAContactorServiceOperator::~CCCAContactorServiceOperator
       
    51 // --------------------------------------------------------------------------
       
    52 //
       
    53 CCCAContactorServiceOperator::~CCCAContactorServiceOperator()
       
    54     {
       
    55     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::~CCCAContactorServiceOperator"));
       
    56 
       
    57     delete iPopupHandler;
       
    58     }
       
    59 
       
    60 // --------------------------------------------------------------------------
       
    61 // CCCAContactorServiceOperator::Execute
       
    62 // --------------------------------------------------------------------------
       
    63 //
       
    64 void CCCAContactorServiceOperator::Execute(
       
    65     const CCAContactorService::TCSParameter& aParameter)
       
    66     {
       
    67     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::Execute"));
       
    68 
       
    69     iParameter = &aParameter;
       
    70 
       
    71     /**
       
    72      * LOGIC:
       
    73      * 1. Launch AIW popup
       
    74      * 2. Special cases: Find out serviceid for voip
       
    75      * 3. Launch communication service
       
    76      *
       
    77      * All actions are trapped here.
       
    78      */
       
    79     TDesC* result = NULL;
       
    80     TInt err( KErrNone );
       
    81     TBool hasSelectedField( EFalse );
       
    82     
       
    83     // Check use field control flag
       
    84     if (CCAContactorService::TCSParameter::EUseFieldParam &
       
    85         iParameter->iControlFlag)
       
    86         {
       
    87         hasSelectedField = ETrue;
       
    88         }
       
    89     
       
    90     if ( !hasSelectedField )
       
    91         {
       
    92         TBool useDefaults = EFalse;
       
    93 
       
    94         // Check default control flag
       
    95         if (CCAContactorService::TCSParameter::EEnableDefaults &
       
    96             iParameter->iControlFlag)
       
    97             {
       
    98             useDefaults = ETrue;
       
    99             }
       
   100 
       
   101         // Launch popup
       
   102         TRAP(err, result = &iPopupHandler->LaunchPopupL(
       
   103             iParameter->iContactLinkArray,
       
   104             CommunicationEnumMapper(iParameter->iCommTypeSelector),
       
   105             useDefaults));
       
   106         
       
   107         if (KErrNone != err)
       
   108             {
       
   109             CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ExecuteL: LaunchPopupL: Leaves %d."), err);
       
   110             return;
       
   111             }
       
   112         }
       
   113     else
       
   114         {
       
   115         __ASSERT_ALWAYS (NULL != iParameter->iSelectedField, User::Leave (KErrArgument));
       
   116         __ASSERT_ALWAYS (0 < iParameter->iSelectedField->Size(), User::Leave (KErrArgument));
       
   117         result = iParameter->iSelectedField;
       
   118         }
       
   119 
       
   120     // Resolve special cases
       
   121     TRAP(err, ResolveSpecialCasesL(*result));
       
   122 
       
   123     if (KErrNone != err)
       
   124         {
       
   125         CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ExecuteL: ResolveSpecialCasesL: Leaves %d."), err);
       
   126         return;
       
   127         }
       
   128 
       
   129     // Launch communication service
       
   130     TRAP(err, LaunchCommunicationMethodL(*result));
       
   131 
       
   132     if (KErrNone != err)
       
   133         {
       
   134         CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ExecuteL: LaunchCommunicationMethodL: Leaves %d."), err);
       
   135         return;
       
   136         }
       
   137 
       
   138     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::Execute: Done."));
       
   139     }
       
   140 
       
   141 // --------------------------------------------------------------------------
       
   142 // CCCAContactorServiceOperator::CCCAContactorServiceOperator
       
   143 // --------------------------------------------------------------------------
       
   144 //
       
   145 CCCAContactorServiceOperator::CCCAContactorServiceOperator():
       
   146     iServiceId((TUint32)KErrNotFound)
       
   147     {
       
   148     }
       
   149 
       
   150 // --------------------------------------------------------------------------
       
   151 // CCCAContactorServiceOperator::ConstructL
       
   152 // --------------------------------------------------------------------------
       
   153 //
       
   154 void CCCAContactorServiceOperator::ConstructL()
       
   155     {
       
   156     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ConstructL"));
       
   157 
       
   158     iPopupHandler = CCCAContactorPopupHandler::NewL();
       
   159 
       
   160     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ConstructL: Done."));
       
   161     }
       
   162 
       
   163 // --------------------------------------------------------------------------
       
   164 // CCCAContactorServiceOperator::ResolveSpecialCasesL
       
   165 // --------------------------------------------------------------------------
       
   166 //
       
   167 void CCCAContactorServiceOperator::ResolveSpecialCasesL(const TDesC& aFieldData)
       
   168     {
       
   169     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ResolveSpecialCasesL"));
       
   170 
       
   171     /*
       
   172      * Currently only VOIP ServiceId is needed to find out.
       
   173      */
       
   174     switch(iParameter->iCommTypeSelector)
       
   175         {
       
   176         case VPbkFieldTypeSelectorFactory::EVOIPCallSelector:
       
   177             iServiceId = ResolveServiceIdL(aFieldData);
       
   178             break;
       
   179         }
       
   180 
       
   181     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ResolveSpecialCasesL: Done."));
       
   182     }
       
   183 
       
   184 // --------------------------------------------------------------------------
       
   185 // CCCAContactorServiceOperator::ResolveServiceIdL
       
   186 // --------------------------------------------------------------------------
       
   187 //
       
   188 TUint32 CCCAContactorServiceOperator::ResolveServiceIdL(const TDesC& aFieldData)
       
   189     {
       
   190     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ResolveServiceIdL"));
       
   191 
       
   192     __ASSERT_ALWAYS (NULL != &aFieldData, User::Leave (KErrArgument));
       
   193     __ASSERT_ALWAYS (0 < aFieldData.Size(), User::Leave (KErrArgument));
       
   194 
       
   195     TUint32 ret = (TUint32)KErrNotFound;
       
   196 
       
   197     //LOGIC:
       
   198     /*
       
   199      * 1. Find out is there xSP prefix
       
   200      * 2. If there is, search service id
       
   201      * 3. If not, find out how many services support msisdn
       
   202      * 4. If only one, find use that service id
       
   203      * 5. If more than one, do not use service id.
       
   204      */
       
   205 
       
   206     TPtrC result;
       
   207 
       
   208     // 1. Find out is there xSP prefix
       
   209     if (ExtractServiceL(aFieldData, result))
       
   210         {
       
   211         CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ResolveServiceIdL: ExtractServiceL found."));
       
   212 
       
   213         // 2. If there is, search service id
       
   214         ret = SearchServiceIdL(result);
       
   215         }
       
   216     else
       
   217         {
       
   218         CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ResolveServiceIdL: ExtractServiceL not found."));
       
   219 
       
   220         // 3. If not, find out how many services support msisdn
       
   221         ret = ResolveMSISDNAddressingSupportedL();
       
   222         if ((TUint32)KErrNotFound != ret)
       
   223             {
       
   224             // 4. If only one, find use that service id
       
   225             CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ResolveServiceIdL: ResolveMSISDNAddressingSupportedL only one service."));
       
   226 
       
   227             }
       
   228         else
       
   229             {
       
   230             // 5. If more than one or none found, do not use service id.
       
   231             CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ResolveServiceIdL: ResolveMSISDNAddressingSupportedL more than one service."));
       
   232 
       
   233             }
       
   234         }
       
   235 
       
   236     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ResolveServiceIdL: Done."));
       
   237 
       
   238     return ret;
       
   239     }
       
   240 
       
   241 // --------------------------------------------------------------------------
       
   242 // CCCAContactorServiceOperator::ExtractServiceL
       
   243 // --------------------------------------------------------------------------
       
   244 //
       
   245 TBool CCCAContactorServiceOperator::ExtractServiceL(
       
   246     const TDesC& aFieldData, TPtrC& aXSPId)
       
   247     {
       
   248     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ExtractServiceL"));
       
   249 
       
   250     TBool found = EFalse;
       
   251 
       
   252     TInt pos = aFieldData.Find(KColon);
       
   253     if (pos >= 0)
       
   254         {
       
   255         // ok input
       
   256         aXSPId.Set(aFieldData.Left(pos));
       
   257         found = ETrue;
       
   258         }
       
   259 
       
   260     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ExtractServiceL: Done."));
       
   261 
       
   262     return found;
       
   263     }
       
   264 
       
   265 // --------------------------------------------------------------------------
       
   266 // CCCAContactorServiceOperator::SearchServiceIdL
       
   267 // --------------------------------------------------------------------------
       
   268 //
       
   269 TUint32 CCCAContactorServiceOperator::SearchServiceIdL(const TDesC& aFieldData)
       
   270     {
       
   271     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::SearchServiceIdL"));
       
   272 
       
   273     TUint32 ret = (TUint32)KErrNotFound;
       
   274     TInt err = KErrNone;
       
   275     CDesCArrayFlat* nameArray = NULL;
       
   276 
       
   277     RIdArray ids;
       
   278     CleanupClosePushL(ids);
       
   279 
       
   280     nameArray = new (ELeave) CDesCArrayFlat(2);
       
   281     CleanupStack::PushL(nameArray);
       
   282 
       
   283     CSPSettings* settings = CSPSettings::NewLC();
       
   284 
       
   285     err = settings->FindServiceIdsL(ids);
       
   286     User::LeaveIfError(err);
       
   287     err = settings->FindServiceNamesL(ids, *nameArray);
       
   288     User::LeaveIfError(err);
       
   289 
       
   290     TInt count = nameArray->MdcaCount();
       
   291     for (TInt i(0); i < count; i++)
       
   292         {
       
   293         // search the mathching service name
       
   294         TPtrC p = nameArray->MdcaPoint(i);
       
   295         if (!p.CompareF(aFieldData))
       
   296             {
       
   297             // Service found
       
   298             ret = ids[i];
       
   299 
       
   300             CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::SearchServiceIdL: Service found."));
       
   301             break;
       
   302             }
       
   303         }
       
   304     CleanupStack::PopAndDestroy(3); // ids, nameArray, settings
       
   305 
       
   306     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::SearchServiceIdL: Done."));
       
   307 
       
   308     return ret;
       
   309     }
       
   310 
       
   311 // --------------------------------------------------------------------------
       
   312 // CCCAContactorServiceOperator::ResolveMSISDNAddressingSupportedL
       
   313 // --------------------------------------------------------------------------
       
   314 //
       
   315 TUint32 CCCAContactorServiceOperator::ResolveMSISDNAddressingSupportedL()
       
   316     {
       
   317     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ResolveMSISDNAddressingSupportedL"));
       
   318 
       
   319     /*
       
   320      * LOGIC:
       
   321      * -Find out services
       
   322      * -If only 1 service, return the serviceid
       
   323      * -If services are more than 1, then do not use serviceid.
       
   324      */
       
   325 
       
   326     TInt err = KErrNone;
       
   327     TInt foundNo = 0;
       
   328     TUint32 ret = (TUint32)KErrNotFound;
       
   329 
       
   330     RIdArray ids;
       
   331     CleanupClosePushL(ids);
       
   332 
       
   333     CSPSettings* settings = CSPSettings::NewLC();
       
   334 
       
   335     err = settings->FindServiceIdsL(ids);
       
   336     User::LeaveIfError(err);
       
   337 
       
   338     TInt count = ids.Count();
       
   339     for (TInt i(0); i < count; i++)
       
   340         {
       
   341         CSPProperty* property = CSPProperty::NewLC();
       
   342 
       
   343         // Find out property
       
   344         err = settings->FindPropertyL(ids[i],
       
   345             EPropertyServiceAttributeMask, *property);
       
   346 
       
   347         // If service have property
       
   348         if (KErrNone == err)
       
   349             {
       
   350             // read the value of mask property
       
   351             TInt mask = 0;
       
   352             err = property->GetValue(mask);
       
   353             if (KErrNone == err)
       
   354                 {
       
   355                 if ((mask & ESupportsMSISDNAddressing) &&
       
   356                     (mask & ESupportsInternetCall))
       
   357                     {
       
   358                     // Found one.
       
   359                     ret = ids[i];
       
   360                     foundNo++;
       
   361 
       
   362                     }// if mask
       
   363                 }// if err
       
   364             }// if err
       
   365 
       
   366         CleanupStack::PopAndDestroy(property);
       
   367         }// for
       
   368 
       
   369     // If more than 1 service, do not use serviceid
       
   370 
       
   371     if (1 < foundNo)
       
   372     {
       
   373         ret = (TUint32)KErrNotFound;
       
   374     }
       
   375 
       
   376     CleanupStack::PopAndDestroy(2); // ids, settings
       
   377 
       
   378     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ResolveMSISDNAddressingSupportedL: Done."));
       
   379     return ret;
       
   380     }
       
   381 
       
   382 // --------------------------------------------------------------------------
       
   383 // CCCAContactorServiceOperator::LaunchCommunicationMethodL
       
   384 // --------------------------------------------------------------------------
       
   385 //
       
   386 void CCCAContactorServiceOperator::LaunchCommunicationMethodL(
       
   387     const TDesC& aFieldData)
       
   388     {
       
   389     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::LaunchCommunicationMethodL"));
       
   390 
       
   391     __ASSERT_ALWAYS (NULL != &iParameter->iFullName, User::Leave (KErrArgument));
       
   392     
       
   393     // If serviceid found, use it.
       
   394     if ((TUint32)KErrNotFound != iServiceId)
       
   395         {
       
   396         CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ExecuteL: ExecuteServiceL with serviceid"));
       
   397         CCAContactor::ExecuteServiceL(
       
   398             iParameter->iCommTypeSelector,
       
   399             aFieldData,
       
   400             iParameter->iFullName,
       
   401             iParameter->iContactLinkArray,
       
   402             iServiceId
       
   403             );
       
   404         }
       
   405     else
       
   406         {
       
   407         CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ExecuteL: ExecuteServiceL without serviceid"));
       
   408         CCAContactor::ExecuteServiceL(
       
   409             iParameter->iCommTypeSelector,
       
   410             aFieldData,
       
   411             iParameter->iFullName,
       
   412             iParameter->iContactLinkArray);
       
   413         }
       
   414 
       
   415     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::LaunchCommunicationMethodL: Done."));
       
   416     }
       
   417 
       
   418 // --------------------------------------------------------------------------
       
   419 // CCCAContactorServiceOperator::CommunicationEnumMapper
       
   420 // --------------------------------------------------------------------------
       
   421 //
       
   422 TAiwCommAddressSelectType CCCAContactorServiceOperator::CommunicationEnumMapper(
       
   423     VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aCommTypeSelector)
       
   424     {
       
   425     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::CommunicationEnumMapper"));
       
   426 
       
   427     TAiwCommAddressSelectType type;
       
   428 
       
   429     switch(aCommTypeSelector)
       
   430         {
       
   431         case VPbkFieldTypeSelectorFactory::EEmptySelector:
       
   432             type = EAiwCommEmpty;
       
   433             break;
       
   434 
       
   435         case VPbkFieldTypeSelectorFactory::EVoiceCallSelector:
       
   436             type = EAiwCommVoiceCall;
       
   437             break;
       
   438 
       
   439         case VPbkFieldTypeSelectorFactory::EUniEditorSelector:
       
   440             type = EAiwCommUniEditor;
       
   441             break;
       
   442 
       
   443         case VPbkFieldTypeSelectorFactory::EEmailEditorSelector:
       
   444             type = EAiwCommEmailEditor;
       
   445             break;
       
   446 
       
   447         case VPbkFieldTypeSelectorFactory::EInstantMessagingSelector:
       
   448             type = EAiwCommInstantMessaging;
       
   449             break;
       
   450 
       
   451         case VPbkFieldTypeSelectorFactory::EVOIPCallSelector:
       
   452             type = EAiwCommVOIPCall;
       
   453             break;
       
   454 
       
   455         case VPbkFieldTypeSelectorFactory::EURLSelector:
       
   456             type = EAiwCommURL;
       
   457             break;
       
   458 
       
   459         case VPbkFieldTypeSelectorFactory::EVideoCallSelector:
       
   460             type = EAiwCommVideoCall;
       
   461             break;
       
   462 
       
   463         default:
       
   464             CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::CommunicationEnumMapper: default -> Empty mapped."));
       
   465             type = EAiwCommEmpty;
       
   466             break;
       
   467         }
       
   468 
       
   469     CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::CommunicationEnumMapper: Done."));
       
   470 
       
   471     return type;
       
   472     }
       
   473 
       
   474 // End of file