telephonyutils/dial/src/DIAL.CPP
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @publishedAll
       
    19  @deprecated 9.1
       
    20 */
       
    21 
       
    22 #include "DIALUTIL.H"
       
    23 
       
    24 /**
       
    25 @file
       
    26 @internalComponent
       
    27 */
       
    28 const TInt KCharacterLength=1;
       
    29 
       
    30 
       
    31 // TelephoneNumber General Parser
       
    32 
       
    33 /**
       
    34 @deprecated 9.1
       
    35 */
       
    36 TInt DialUtil::GeneralParse(
       
    37 			 TDialString& aDialString,
       
    38 			 const TDialLocation & aDialLocation , 
       
    39 			 const TChargeCard& aChargeCard ,
       
    40 			 const TDesC& aNumberToDial,
       
    41 			 TParseMode aParseMode,
       
    42  			 TCityDialOptions aOption )
       
    43 	{
       
    44 	
       
    45 	TPhoneNumber aPhoneNumToParse(aNumberToDial) ;
       
    46 
       
    47 //	if ( !DialUtil::PhoneFormatOK (aPhoneNumToParse) )
       
    48 //	return (KErrNotSupported) ;
       
    49 
       
    50 	// analysing dial string
       
    51 	TDialNumber dialNumber (aPhoneNumToParse,aDialLocation,aChargeCard) ;
       
    52    
       
    53 	aDialString.Zero(); // restart the dial string 
       
    54 	if (aDialLocation.IsDisableCallWaitingCode() )
       
    55 		{
       
    56 		if (!DialUtil::AppendDialString(aDialString,aDialLocation.DisableCallWaitingCode()))
       
    57 			return (KErrOverflow) ;
       
    58 		}
       
    59 	if (aDialLocation.IsWaitForDialingTone() && aParseMode==EForDialing)
       
    60 		{
       
    61 		if (!DialUtil::AppendDialString(aDialString,KCharW))
       
    62 			return (KErrOverflow) ;
       
    63 		}
       
    64 	if ( aDialLocation.IsDialOutRequired() ) 
       
    65 		{
       
    66 		if (aParseMode==EForDialing)
       
    67 			{
       
    68 			if (aDialLocation.IsPbxUsePulseDial())
       
    69 				{
       
    70 				if (!DialUtil::AppendDialString(aDialString,KCharP))
       
    71 					return (KErrOverflow) ;
       
    72 				}
       
    73 			else
       
    74 				{
       
    75 				if (!DialUtil::AppendDialString(aDialString,KCharT))
       
    76 					return (KErrOverflow) ;
       
    77 				}
       
    78 			}
       
    79 
       
    80 		if (dialNumber.CallType() == ELocalCall)
       
    81 			{
       
    82 			if (!DialUtil::AppendDialString(aDialString,aDialLocation.DialOutLocalCode()))
       
    83 				return (KErrOverflow) ;
       
    84 			}
       
    85 		else
       
    86 			{
       
    87 			if (!DialUtil::AppendDialString(aDialString,aDialLocation.DialOutLongDistanceCode()))
       
    88 				return (KErrOverflow) ;
       
    89 			}
       
    90 
       
    91 		TUint commas = aDialLocation.PauseAfterDialout() ;
       
    92 		if (commas > 0)		// we should add a comma if the last character in the string is not already a comma
       
    93 			{
       
    94 			TBuf<KCharacterLength> lastChar=aDialString.Right(KCharacterLength);
       
    95 			if (lastChar.Locate(KCharComma)!=KErrNone)		// if not a comma
       
    96 				{
       
    97 				if (!DialUtil::AppendDialString(aDialString,KCharComma))
       
    98 					return (KErrOverflow) ;
       
    99 				}	
       
   100 			}
       
   101 
       
   102 	/*	while (commas--)
       
   103 			{
       
   104 			if (!DialUtil::AppendDialString(aDialString,KCharComma))
       
   105 				return (KErrOverflow) ;
       
   106 			}
       
   107 	
       
   108 	  */}
       
   109 
       
   110 	if (aDialLocation.IsWaitForProceedTone() && aParseMode==EForDialing)
       
   111 		{
       
   112 		if (!DialUtil::AppendDialString(aDialString,KCharW))
       
   113 			return (KErrOverflow) ;
       
   114 		}
       
   115 
       
   116 	if ( !aDialLocation.IsDialOutRequired() || 
       
   117 		 aDialLocation.IsUsePulseDial () != aDialLocation.IsPbxUsePulseDial() )
       
   118 		{
       
   119 		if (aParseMode==EForDialing)
       
   120 			{
       
   121 			if (!aDialLocation.IsUsePulseDial ())
       
   122 				{
       
   123 				if (!DialUtil::AppendDialString(aDialString,KCharT))
       
   124 					return (KErrOverflow) ;
       
   125 				}
       
   126 			else
       
   127 				{
       
   128 				if (!DialUtil::AppendDialString(aDialString,KCharP))
       
   129 					return (KErrOverflow) ;
       
   130 				}
       
   131 			}
       
   132 		}
       
   133 	
       
   134 	if ( aDialLocation.IsMobile() && aChargeCard.ValidateChargeCardInfo() )
       
   135 		return (KErrNotSupported) ;
       
   136 		// do not know what to do with this scenario-currently not available !
       
   137     
       
   138 	else if ( aDialLocation.IsMobile() && !aChargeCard.ValidateChargeCardInfo() )
       
   139 	{
       
   140 		aDialString.Zero(); // restart the dial string 
       
   141         if (aDialLocation.IsReturnPhoneNumberWithPlusFormat()) // fix for release 012
       
   142         {
       
   143   			if (!DialUtil::AppendDialString(aDialString,KCharPlus))
       
   144 				return (KErrOverflow) ;
       
   145 			if (!DialUtil::AppendDialString(aDialString,dialNumber.NatCode()))
       
   146 				return (KErrOverflow) ;
       
   147 			if (!DialUtil::AppendDialString(aDialString,dialNumber.AreaCode()))
       
   148 				return (KErrOverflow) ;
       
   149         }
       
   150         else
       
   151         {
       
   152 		if ( dialNumber.IsNatCode() )  // Nat code supplied
       
   153 			{
       
   154 			if ( dialNumber.NatCode() != aDialLocation.NatCode() )
       
   155 				{// making interNat code 
       
   156 				if (!DialUtil::AppendDialString(aDialString,dialNumber.IntlPrefCode()))
       
   157 					return (KErrOverflow) ;
       
   158 
       
   159 				if (!DialUtil::AppendDialString(aDialString,dialNumber.NatCode()))
       
   160 					return (KErrOverflow) ;
       
   161 				}
       
   162 			else // call within the same country
       
   163 				{
       
   164 				if (!DialUtil::AppendDialString(aDialString,dialNumber.NatPrefCode()))
       
   165 					return (KErrOverflow) ;
       
   166 				}
       
   167 			}
       
   168 		else // must dial from the same country
       
   169 			{
       
   170 			if (!DialUtil::AppendDialString(aDialString,aDialLocation.NatPrefCode()))
       
   171 				return (KErrOverflow) ;
       
   172 			}
       
   173 
       
   174 		if ( dialNumber.IsAreaCode() )  // area code supplied
       
   175 		{
       
   176 			if (!DialUtil::AppendDialString(aDialString,dialNumber.AreaCode()))
       
   177 				return (KErrOverflow) ;
       
   178 		}
       
   179 		else
       
   180 		{
       
   181 			if (!DialUtil::AppendDialString(aDialString,aDialLocation.AreaCode()))
       
   182 				return (KErrOverflow) ;
       
   183 		}
       
   184      }
       
   185 		if (!DialUtil::AppendDialString(aDialString,dialNumber.PhoneNumber()) )
       
   186 			return (KErrOverflow) ;
       
   187 		
       
   188 	}
       
   189 	
       
   190 	//----------------------------------------------------
       
   191 	// Not a mobile phone and not using chargecard
       
   192 	//----------------------------------------------------
       
   193 	else if ( !aDialLocation.IsMobile() && !aChargeCard.ValidateChargeCardInfo() ) 
       
   194 	{
       
   195         if (aDialLocation.IsReturnPhoneNumberWithPlusFormat()) // fix for release 012
       
   196         {
       
   197   			 if (!DialUtil::AppendDialString(aDialString,KCharPlus))
       
   198 				return (KErrOverflow) ;
       
   199 			if (!DialUtil::AppendDialString(aDialString,dialNumber.NatCode()))
       
   200 				return (KErrOverflow) ;
       
   201 			if (!DialUtil::AppendDialString(aDialString,dialNumber.AreaCode()))
       
   202 				return (KErrOverflow) ;
       
   203     		if (!DialUtil::AppendDialString(aDialString,dialNumber.PhoneNumber()) )
       
   204 	    		return (KErrOverflow) ;
       
   205         }
       
   206         else
       
   207         {
       
   208 
       
   209         if (dialNumber.CallType() == ELocalCall)
       
   210 			{
       
   211 			// option to allow areacode 
       
   212 			if ( aOption==EDialCityAllowDuplicateAreaCode )
       
   213 				{
       
   214 				if (!DialUtil::AppendDialString(aDialString,dialNumber.NatPrefCode()))
       
   215 					return (KErrOverflow) ;
       
   216 				if (!DialUtil::AppendDialString(aDialString,dialNumber.AreaCode()))
       
   217 					return (KErrOverflow) ;
       
   218 				}
       
   219 			if (!DialUtil::AppendDialString(aDialString,dialNumber.PhoneNumber()))
       
   220 				return (KErrOverflow) ;
       
   221 			}
       
   222         if (dialNumber.CallType() == ELongDistanceCall) 
       
   223 			{
       
   224 			if (!DialUtil::AppendDialString(aDialString,dialNumber.NatPrefCode()))
       
   225 				return (KErrOverflow) ;
       
   226 
       
   227 			if (!DialUtil::AppendDialString(aDialString,dialNumber.AreaCode()))
       
   228 				return (KErrOverflow) ;
       
   229 
       
   230 			if (!DialUtil::AppendDialString(aDialString,dialNumber.PhoneNumber()))
       
   231 				return (KErrOverflow) ;
       
   232 			}
       
   233         if (dialNumber.CallType() == EInternationalCall) 
       
   234 			{
       
   235 			if (!DialUtil::AppendDialString(aDialString,dialNumber.IntlPrefCode()))
       
   236 				return (KErrOverflow) ;
       
   237 			if (!DialUtil::AppendDialString(aDialString,dialNumber.NatCode()))
       
   238 				return (KErrOverflow) ;
       
   239 			if (!DialUtil::AppendDialString(aDialString,dialNumber.AreaCode()))
       
   240 				return (KErrOverflow) ;
       
   241 			if (!DialUtil::AppendDialString(aDialString,dialNumber.PhoneNumber()))
       
   242 				return (KErrOverflow) ;
       
   243 			}
       
   244         }
       
   245 	}
       
   246 	else if ( !aDialLocation.IsMobile() && aChargeCard.ValidateChargeCardInfo() ) 
       
   247 		{
       
   248 		TChargeCardRule iRule=dialNumber.RuleToUse() ;
       
   249 
       
   250 		for ( TInt i=0 ; i < iRule.Length() ; i++) 
       
   251 			{ // for each character in rule 
       
   252 			switch (iRule[i] ) 
       
   253 				{
       
   254 			case KCharEUpper: // copy country code into aDialStr 
       
   255 			case KCharELower:
       
   256 			if (!DialUtil::AppendDialString(aDialString,dialNumber.NatCode()))
       
   257 				return (KErrOverflow) ;
       
   258 			break;
       
   259 			case KCharFUpper: // copy STD code into aDialStr 
       
   260 			case KCharFLower:
       
   261 			if (!DialUtil::AppendDialString(aDialString,dialNumber.AreaCode()))
       
   262 				return (KErrOverflow) ;
       
   263             break;
       
   264 			case KCharGUpper: // copy local phone number into aDialStr 
       
   265 			case KCharGLower:
       
   266 			if (!DialUtil::AppendDialString(aDialString,dialNumber.PhoneNumber()))
       
   267 				return (KErrOverflow) ;
       
   268             break;
       
   269 
       
   270 			case KCharHUpper: // copy chargecard account number & pin into aDialStr 
       
   271 			case KCharHLower:
       
   272 			if (!DialUtil::AppendDialString(aDialString,aChargeCard.Number()))
       
   273 				return (KErrOverflow) ;
       
   274 			if (!DialUtil::AppendDialString(aDialString,aChargeCard.Pin()))
       
   275 				return (KErrOverflow) ;
       
   276 			break;
       
   277 			case KCharJUpper: // copy chargecard account number into aDialStr 
       
   278 			case KCharJLower:
       
   279 			if (!DialUtil::AppendDialString(aDialString,aChargeCard.Number()))
       
   280 				return (KErrOverflow) ;
       
   281             break;
       
   282         
       
   283 			case KCharKUpper: // copy pin into aDialStr 
       
   284 			case KCharKLower:
       
   285 			if (!DialUtil::AppendDialString(aDialString,aChargeCard.Pin()))
       
   286 				return (KErrOverflow) ;
       
   287             break;
       
   288 		
       
   289 			default:  // copy character into aDialStr 
       
   290 			if (!DialUtil::AppendDialString(aDialString,iRule[i]))
       
   291 				return (KErrOverflow) ;
       
   292             break;
       
   293 				}	
       
   294 			}
       
   295 		}
       
   296 	DialUtil::RemoveSpace (aDialString) ;
       
   297 
       
   298 	// this is for dtmf dialling string so the string should not have 
       
   299 	// any undialable characters
       
   300 	if (aParseMode==EForDisplay) 
       
   301 		DialUtil::RemoveUndiallableChars (aDialString) ;
       
   302 	
       
   303 	
       
   304 	return(KErrNone) ;
       
   305 	}
       
   306 
       
   307 
       
   308 /**
       
   309 This parser resolves the phone number for Time/World application.
       
   310 
       
   311 @param aDialString The results of the telephone parser are stored here.
       
   312 @param aFrom Specifies the area code of the dialling location.
       
   313 @param aTo Specifies the area code of the city being dialled.
       
   314 @param aOption This option applies when the phone number being 
       
   315        dialled is in the same location as the dialler: 
       
   316        It controls whether the area code is included in the final dial string. 
       
   317 @param aCodeSeparator Specifies the code separator.
       
   318 @param aPlusFormatOption Specifies whether the dial string is in full 
       
   319        or in the ‘+’ char format.
       
   320 
       
   321 @publishedAll
       
   322 @deprecated 9.1
       
   323 */
       
   324 EXPORT_C TInt TelephoneNumber::CalculateDialCityPrefix(
       
   325 						TDialString& aDialString,
       
   326 						const TCityDialCodes& aFrom,
       
   327 						const TCityDialCodes& aTo,
       
   328 						TCityDialOptions aOption,
       
   329 						TChar aCodeSeparator ,
       
   330 						TPlusFormatDialOptions aPlusFormatOption )
       
   331 	{
       
   332 	aDialString.Zero(); // restart the dial string 
       
   333 	if (aFrom.iNatCode != aTo.iNatCode) // different country code
       
   334 		{
       
   335 		if (aPlusFormatOption==EPlusFormatDialNotAllow)
       
   336 			{
       
   337 			if (!DialUtil::AppendDialString(aDialString,aFrom.iIntlPref))
       
   338 				return (KErrOverflow) ;
       
   339 			if (!DialUtil::AppendDialString(aDialString,aCodeSeparator))
       
   340 				return (KErrOverflow) ;
       
   341 			} 
       
   342 		else
       
   343 			{
       
   344 			if (!DialUtil::AppendDialString(aDialString,KCharPlus))
       
   345 				return (KErrOverflow) ;
       
   346 			}
       
   347 		if (!DialUtil::AppendDialString(aDialString,aTo.iNatCode))
       
   348 			return (KErrOverflow) ;
       
   349 		if (!DialUtil::AppendDialString(aDialString,aCodeSeparator))
       
   350 			return (KErrOverflow) ;
       
   351 		if (!DialUtil::AppendDialString(aDialString,aTo.iAreaCode))
       
   352 			return (KErrOverflow) ;
       
   353 		return(KErrNone) ;
       
   354 		}
       
   355 	else if (aFrom.iAreaCode != aTo.iAreaCode) // same country code different area
       
   356 		{
       
   357 		if (!DialUtil::AppendDialString(aDialString,aFrom.iNatPref))
       
   358 			return (KErrOverflow) ;
       
   359 		if (!DialUtil::AppendDialString(aDialString,aCodeSeparator))
       
   360 			return (KErrOverflow) ;
       
   361 		if (!DialUtil::AppendDialString(aDialString,aTo.iAreaCode))
       
   362 			return (KErrOverflow) ;
       
   363 		return(KErrNone) ;
       
   364 		}
       
   365 	else if (	(aFrom.iIntlPref == aTo.iIntlPref) && 
       
   366 				(aFrom.iNatPref  == aTo.iNatPref) )
       
   367 				// must check they are exaclty the same for local call
       
   368 		{
       
   369 		if (aOption == EDialCityAllowDuplicateAreaCode)
       
   370 			{
       
   371 			if (!DialUtil::AppendDialString(aDialString,aFrom.iNatPref))
       
   372 				return (KErrOverflow) ;
       
   373 			if (!DialUtil::AppendDialString(aDialString,aCodeSeparator))
       
   374 				return (KErrOverflow) ;
       
   375 			if (!DialUtil::AppendDialString(aDialString,aTo.iAreaCode))
       
   376 				return (KErrOverflow) ;
       
   377 			return(KErrNone) ;
       
   378 			}
       
   379 		else
       
   380 			return(KErrNone) ;
       
   381 		}
       
   382 	else // in valid info in the structure
       
   383 		return (KErrOverflow) ;
       
   384 	}
       
   385 
       
   386 
       
   387 //
       
   388 // for DTMF dialing
       
   389 //
       
   390 
       
   391 /**
       
   392 This parser resolves a phone number.  
       
   393 It assumes that TCityDialOption is 
       
   394 always set to EDialCityStripDuplicateAreaCode
       
   395 
       
   396 @param aDialString The results of the telephone parser are stored here.
       
   397 @param aDialLocation Specifies the dialling location.
       
   398 @param aPhoneNumber Telephone number is to be parsed in the form of +44 20...
       
   399 
       
   400 @publishedAll
       
   401 @deprecated 9.1
       
   402 */
       
   403 EXPORT_C TInt TelephoneNumber::Parse( TDialString& aDialString ,
       
   404 								  const TDialLocation& aDialLocation, 
       
   405 								  const TDesC& aPhoneNumber ) 
       
   406 	{
       
   407 	TChargeCard chargeCard ; // a NULL charge card not used by DTMF
       
   408 	return (TelephoneNumber::Parse(
       
   409 							aDialString,
       
   410 							aDialLocation,
       
   411 							chargeCard,
       
   412 							aPhoneNumber,
       
   413 							EForDisplay	) ); 
       
   414 	}
       
   415 
       
   416 
       
   417 // It is for DTMF dialing with option to strip or allow the area code.
       
   418 
       
   419 /**
       
   420 This parser resolves a phone number.
       
   421 
       
   422 @param aDialString The results of the telephone parser are stored here.
       
   423 @param aDialLocation Specifies the dialling location.
       
   424 @param aPhoneNumber Telephone number is to be parsed in the form of +44 20 ...
       
   425 @param aOption This option applies when the phone number being dialled 
       
   426        is in the same location as the dialler: It controls whether the 
       
   427        area code is included in the final dial string. 
       
   428 
       
   429 @publishedAll
       
   430 @deprecated 9.1
       
   431 */
       
   432 EXPORT_C TInt TelephoneNumber::Parse( TDialString& aDialString ,
       
   433 								  const TDialLocation& aDialLocation, 
       
   434 								  const TDesC& aPhoneNumber , 
       
   435 								  TCityDialOptions aOption )
       
   436 	{
       
   437 	TChargeCard chargeCard ; // a NULL charge card not used by DTMF
       
   438 	return DialUtil::GeneralParse(
       
   439 							aDialString,
       
   440 							aDialLocation,
       
   441 							chargeCard,
       
   442 							aPhoneNumber,
       
   443 							EForDisplay	,
       
   444 							aOption ); 
       
   445 	}
       
   446 
       
   447 
       
   448 // Parse for dial up network
       
   449 
       
   450 /**
       
   451 This parser resolves a phone number with additional of a TChargeCard.
       
   452 
       
   453 @param aDialString The results of the telephone parser are stored here.
       
   454 @param aDialLocation Specifies the dialling location.
       
   455 @param aChargeCard Specifies charge card information. 
       
   456 @param aNumberToDial A telephone number is to be parsed in the form of +44 20 ...
       
   457 @param aParseMode Indicates whether the resulting string 
       
   458        is for display or for dialling.
       
   459 
       
   460 @publishedAll
       
   461 @deprecated 9.1
       
   462 */
       
   463 EXPORT_C TInt TelephoneNumber::Parse(
       
   464 			 TDialString& aDialString,
       
   465 			 const TDialLocation & aDialLocation , 
       
   466 			 const TChargeCard& aChargeCard ,
       
   467 			 const TDesC& aNumberToDial,
       
   468 			 TParseMode aParseMode )
       
   469 	{
       
   470 	return DialUtil::GeneralParse (	aDialString,
       
   471 							aDialLocation , 
       
   472 							aChargeCard ,
       
   473 							aNumberToDial,
       
   474 							aParseMode,
       
   475 							EDialCityStripDuplicateAreaCode ) ;
       
   476 	}