Esempio n. 1
0
// ---------------------------------------------------------
// CWtaiHandler::VerifyWtaiSchemeL()
// ---------------------------------------------------------
//
TInt CWtaiHandler::VerifyWtaiSchemeL( TPtrC path )
    {
	TInt colonPos = path.Locate( ';' ); // first occurance

	if ( colonPos <= 0 )
		{
 		User::Leave( KErrGeneral );
		}
    else if( KErrNotFound == path.FindF( KWP() ) ) // check if it's valid library
        {
        User::Leave( KErrUnsuppLibrary );
        }
    else if( ( KErrNotFound != path.FindF( KMC() ) ) ||
             ( KErrNotFound != path.FindF( KSD() ) ) ||
             ( KErrNotFound != path.FindF( KAP() ) ) ) // check if it's valid function
        {
        return colonPos;
        }
    else
        {
        User::Leave( KErrUnsupFunction );
        }

    return colonPos;
    }
Esempio n. 2
0
TPtrC TLineBuffer::ReadLine()
	{
	// Class nvariant: iRemainder == iTail.Length()
	ASSERT(iRemainder == iTail.Length());

	TInt end = iTail.Locate('\n');
	if (end < 0)
		{
		// Buffer ends without ending '\n', treat as line
		end = iTail.Length();
		iRemainder = 0;
		}
	else
		{
		// 0 <= end < iTail.Length() => iTail.Length() > iRemainder >= 0
		// (remainder is always decreased at least by 1, skipping '\n',
		// and will never become negative, because end < remainder)
		iRemainder -= end + 1;		
		// Ignore CR before LF, if present
		if (end > 0 && iTail[end-1] == '\r')
			--end;
		}
	const TPtrC line(iTail.Left(end));
	iTail.Set(iTail.Right(iRemainder));
	return line;
	}
/**
Counts the number of substrings (separated by KSubStringSeparators) in the text. 
Needed for correct memory allocations.
*/
TInt CResourceLoader::GetSubStringCount(const TDesC& aText)
    {
    TInt subCount = 0;
    TInt i = 0;

    while (i < aText.Length())
        {
        TPtrC remainder = aText.Right(aText.Length() - i);
        TInt nextKey = remainder.Locate(KSubStringSeparator);
        i += nextKey;

        // Always increase subcount, as a string without any separators counts as one substring.
        // However, if string length is zero, then there are no substrings.
        subCount++;

        if (nextKey != KErrNotFound && i < aText.Length() - 1)
            {
            i++; // skip separator
            }
        else
            break;
        }

    return subCount;
    }
Esempio n. 4
0
TPtrC CEikListBoxTextEditor::EditableItemText(TRect* aRect)
	{
	_AKNTRACE_FUNC_ENTER;
    TPtrC itemtext = ItemText();
	if (iItemPos==0)	// not yet set (and even if set, cannot be zero)
		{
		iItemPos = itemtext.Locate('\n');	// loacte partly editable item start
	    if (iItemPos != KErrNotFound)
			{
			iItemPos++;		// jump over mark character
			iItemLen = itemtext.Mid( iItemPos ).Locate('\n');	// locate string end
			if ( iItemLen == KErrNotFound )
				Panic( ETUiklbedPanicEndMarkMissing );
			if ( iItemLen==0 )
				Panic( ETUiklbedPanicEmptyField );
			TPtrC head = itemtext.Left( iItemPos );
			TPtrC body = itemtext.Mid( iItemPos, iItemLen );
			if ( aRect ) // adjust the rect if it is given
				{
				aRect->iTl.iX += iFont->TextWidthInPixels( head );
				aRect->iBr.iX = aRect->iTl.iX + iFont->TextWidthInPixels( body ) + 4;
				}
			_AKNTRACE_FUNC_EXIT;
			return body;
			}
		iItemPos = 0; // partly editable text not found
		}
	_AKNTRACE_FUNC_EXIT;
	return itemtext;
	}
/**
The function parses thr database file name argument and extracts the SID from it (if the name contains SID).
The SID is expected to be found at position 0 of the file name and must have 8 hex digits.

@param aDbFileName Database file name

@return Database security UID or KNullUid if the database name does not contain SID.

@internalComponent
*/
static TUid ExtractSID(const TDesC& aDbFileName)
	{
	TParsePtrC parse(aDbFileName);//this call may panic if aDbFileName cannot be parsed, but SetL() already parsed it
	TPtrC dbName = parse.Name();
	TInt pos1 = dbName.Locate(TChar('['));
	TInt pos2 = dbName.Locate(TChar(']'));
	if(pos1 == 0 && pos2 == 9)	//position 0 for '[', 8 digits SID, position 9 for ']'
		{
		TLex lex(dbName.Mid(pos1 + 1, pos2 - pos1 - 1));
		TUid securityUid;
		TInt err = lex.Val(*(TUint32*)&securityUid, EHex);
		if(err == KErrNone)
			{
			return securityUid;	
			}
		}
	return KNullUid;
	}
Esempio n. 6
0
void CUrl::ConstructL(const TDesC& aUrl)
//
//	Non-trivial c'tor - can be used for all general urls
	{
	// Stripe any leading whitespace
	TPtrC url = aUrl;
	while( url.Locate(' ') == 0 )
		{
		// Remove the leading whitespace -> set pointer to second character
		url.Set(url.Mid(1));
		}
	iUrlDes = url.AllocL();

	// Check to see if there's ':' at start of aUrl
	TInt colonPos = aUrl.Locate(':');
	if (colonPos == 0)
		User::Leave(EWapErrCorruptUrl);
	TPtrC scheme(Component(EUrlScheme));
	CheckSchemeValidL(scheme);
	}
Esempio n. 7
0
EXPORT_C TInt TextUtils::ColumnText(TPtrC& aColumnText,TInt aColumn,const TDesC* aSourceText,TChar aColumnSeparator)
/** Gets a portion of text from a descriptor, corresponding to a requested column.

@param aColumnText On return, set to the portion of aSourceText that corresponds 
to the column aColumn.
@param aColumn The column to extract. The first column is numbered zero.
@param aSourceText The source text string that contains one or more column 
separators.
@param aColumnSeparator The character used in aSourceText to separate the columns. 
By default, a tab character.
@return KErrNotFound if the column number is invalid, otherwise KErrNone. */
	{
	aColumnText.Set(TPtrC());
	TInt end=0;
	TInt column=0;
	TPtrC text;
	if (aSourceText)
		text.Set(*aSourceText);
	while (text.Length())
		{
		end=text.Locate(aColumnSeparator);
		if (end==KErrNotFound)
			end=text.Length();
		if (column==aColumn)
			{
			aColumnText.Set(text.Left(end));
			return(KErrNone);
			}
		else if (++column>aColumn)
			break;
		if (end<text.Length())
			++end;
		text.Set(text.Mid(end));
		}
	return(KErrNotFound);
	}
Esempio n. 8
0
EXPORT_C void CSettingsListBoxItemDrawer::DrawItemText( TInt aItemIndex,
                                                        const TRect& aItemTextRect,
                                                        TBool aItemIsCurrent,
                                                        TBool /*aViewIsEmphasized*/,
                                                        TBool /*aItemIsSelected*/) const
    {
    _AKNTRACE_FUNC_ENTER;
    _AKNTRACE("DrawItemText: aItemIndex=%d, aItemTextRect=(%d,%d,%d,%d), aItemIsCurrent=%d",
            aItemIndex, aItemTextRect.iTl.iX, aItemTextRect.iTl.iY, aItemTextRect.iBr.iX,
            aItemTextRect.iBr.iY, aItemIsCurrent);
#ifdef RD_UI_TRANSITION_EFFECTS_LIST
    MAknListBoxTfxInternal* transApi = CAknListLoader::TfxApiInternal( iGc );
    if ( transApi )
        {
        transApi->StartDrawing( MAknListBoxTfxInternal::EListNotSpecified );
        }
#endif //RD_UI_TRANSITION_EFFECTS_LIST
    iGc->SetBrushColor( AKN_LAF_COLOR( 0 ) );
#ifdef RD_UI_TRANSITION_EFFECTS_LIST
    if ( transApi )
        {
        transApi->StopDrawing();
        }
#endif //RD_UI_TRANSITION_EFFECTS_LIST

    DrawBackgroundAndSeparatorLines( aItemTextRect );

    if ( aItemIsCurrent )
        {
        FormattedCellData()->SetCurrentItemIndex( aItemIndex );
        }
        
    FormattedCellData()->SetCurrentlyDrawnItemIndex( aItemIndex );

    FormattedCellData()->DrawSettingHighlight( *iGc, aItemTextRect, aItemIsCurrent );

    TBool drawBackground = ETrue;
    TPtrC temp = iModel->ItemText( aItemIndex );
    TPtrC columnText;

    TextUtils::ColumnText( columnText, 3, &temp );
    
    if ( columnText == KNullDesC )
        {
        drawBackground = EFalse;
        }

#ifdef RD_UI_TRANSITION_EFFECTS_LIST 
    if ( transApi )
        {
        transApi->StartDrawing( MAknListBoxTfxInternal::EListItem );
        iGc->SetClippingRect( iViewRect );
        }
#endif // RD_UI_TRANSITION_EFFECTS_LIST

    // draw setting item's background
    if ( drawBackground )
        {
        TAknLayoutRect outerRect;
        TAknWindowComponentLayout valuePane;
#ifdef RD_LIST_STRETCH                
        if ( Layout_Meta_Data::IsLandscapeOrientation() && 
             Layout_Meta_Data::IsListStretchingEnabled() &&
             FormattedCellData()->StretchingEnabled() )
            {
            valuePane = AknLayoutScalable_Avkon::set_value_pane_cp_vc( 0 );
            }
        else
#endif // RD_LIST_STRETCH
            {
            valuePane = AknLayoutScalable_Avkon::set_value_pane_cp( 0 );
            }
                
        outerRect.LayoutRect( aItemTextRect, TAknWindowComponentLayout::Compose(
                              valuePane,
                              AknLayoutScalable_Avkon::bg_set_opt_pane( 0 ) ).LayoutLine() );

        TBool frameDrawn = EFalse;
        MAknsControlContext *cc = AknsDrawUtils::ControlContext( FormattedCellData()->Control() );
        
        if ( !cc )
            {
            cc = FormattedCellData()->SkinBackgroundContext();
            }

        if ( cc )
            {
            TAknLayoutRect innerRect;
            innerRect.LayoutRect( aItemTextRect, TAknWindowComponentLayout::Compose(
                                  valuePane,
                                  AknLayoutScalable_Avkon::bg_set_opt_pane_g1() ).LayoutLine() );

            frameDrawn = AknsDrawUtils::DrawFrame( AknsUtils::SkinInstance(), 
                                                   *iGc, 
                                                   outerRect.Rect(), 
                                                   innerRect.Rect(),
                                                   KAknsIIDQsnFrSetOptFoc, 
                                                   KAknsIIDQsnFrSetOptFocCenter );
            }
                
        if ( !frameDrawn )
            {
            iGc->SetBrushColor( AKN_LAF_COLOR( 243 ) );
            iGc->Clear( outerRect.Rect() );
            }
        }

    SetupGc( aItemIndex );
        
    CFormattedCellListBoxData::TColors colors;
    
    TBufC<KMaxTotalDataLength> target;

    // Try to allocate buffer dynamically. If out of memory, use the fixed size stack buffer.
    // This size should be sufficient.
    TInt size = temp.Length() * 2;
    HBufC* buffer = NULL;
    
    if ( size > KMaxTotalDataLength )
        {
        buffer = HBufC::New( size );
        }

    TPtr des = ( buffer ? buffer->Des() : target.Des() );
    TDesC* targetptr = &temp;

    if ( columnText == KNullDesC )
        {
#ifdef RD_LIST_STRETCH
        // If list stretching is used and the device is in landscape orientation
        // there is only one text cell available. Therefore, word wrapping 
        // cannot be done. Instead the first text cell must be omitted and the 
        // possible text moved to the second cell. If both text cells contain 
        // data they are combined and the data is moved to the second cell (i.e. 
        // the first cell is never drawn in landscape if list stretching is 
        // turned on).
        if ( Layout_Meta_Data::IsLandscapeOrientation() &&
             Layout_Meta_Data::IsListStretchingEnabled() &&
             FormattedCellData()->StretchingEnabled() )
            {
            TBool swapCells = ETrue;
            TPtrC itemText;
            
            // check if cell swapping should be done at all
            for ( TInt i = 2; i <= 4; ++i )
                {
                if ( TextUtils::ColumnText( itemText, i, targetptr ) == KErrNotFound )
                    {
                    break;
                    }
                
                if ( itemText != KNullDesC )
                    {
                    swapCells = EFalse;
                    break;
                    }
                }
            
            TextUtils::ColumnText( itemText, 1, targetptr );

            if ( swapCells && itemText.Length() > 0 )
                {
                TPtrC secondaryText;
                TextUtils::ColumnText( secondaryText, 5, targetptr );
            
                // remove text from the first text cell
                AknLAFUtils::ReplaceColumn( des, targetptr, (TDesC16*)&KNullDesC, KColumnListSeparator, 1 );

                // ReplaceColumn does not update descriptor's length :(
                des.Set( buffer ? buffer->Des() : target.Des() ); 
                
                TInt secondaryPos = 0;
                TPtrC temp;
                temp.Set( des );

                // add separators if needed
                for ( TInt i = 0; i < 5; ++i )
                    {
                    TInt position = temp.Locate( KColumnListSeparator );
                    
                    if ( position != KErrNotFound )
                        {
                        if ( position < temp.Length() )
                            {
                            ++position;
                            }
                            
                        secondaryPos += position;
                        }
                    else
                        {
                        des.Append( KColumnListSeparator );
                        secondaryPos = des.Length();
                        }

                    temp.Set( des.Mid( secondaryPos ) );
                    }
                
                des.Insert( secondaryPos, itemText );

                if ( secondaryText != KNullDesC )
                    {
                    _LIT( KEmptySpace, " " );
                    des.Insert( secondaryPos + itemText.Length(), KEmptySpace );
                    }
                    
                targetptr = &des;
                }
            }
        else
            {
            WordWrapListItem( des, *targetptr, 1, 5, aItemIndex );
            // Set again because ReplaceColumn in WordWrapListItem does not update the length to 'des' !
            des.Set( buffer ? buffer->Des() : target.Des() );
            targetptr = &des;
            }
#else
        WordWrapListItem( des, temp, 1, 5, aItemIndex );
        // Set again because ReplaceColumn in WordWrapListItem does not update the length to 'des' !
        des.Set( buffer ? buffer->Des() : target.Des() );
        targetptr = &des;
#endif // RD_LIST_STRETCH
        }

#ifdef RD_UI_TRANSITION_EFFECTS_LIST 
    if ( transApi )
        {
        iGc->CancelClippingRect();
        transApi->StopDrawing();
        }
#endif // RD_UI_TRANSITION_EFFECTS_LIST
                
    if (FormattedCellData()->IsMarqueeOn() && 
            FormattedCellData()->CurrentMarqueeItemIndex() != aItemIndex && 
            aItemIsCurrent)
        {
        FormattedCellData()->ResetMarquee();
        FormattedCellData()->SetCurrentMarqueeItemIndex(aItemIndex);
        }

    SettingsData()->Draw( Properties( aItemIndex ), 
                          *iGc,
                          targetptr,
                          aItemTextRect,
                          aItemIsCurrent,
                          colors );

    delete buffer;
    _AKNTRACE_FUNC_EXIT;
    }
//
// Draws the item, which might contain an icon and a text.
// The format of the item text shall look like one of the following formats:
//		- "\ttext"				(text only)
//		- "icon\ttext"			(icon and text)
//		- "\theading\ttext"		(heading and text)
//		- "icon\theading\ttext"	(icon, heading and text)
//		
void CMediaScreenListItemDrawer::DrawActualItem(TInt aItemIndex,
		const TRect& aActualItemRect, TBool aItemIsCurrent,
		TBool /*aViewIsEmphasized*/, TBool /*aViewIsDimmed*/,
		TBool aItemIsSelected) const
	{
	const MDesCArray* itemArray = iListBox.Model()->ItemTextArray();
	if ((!itemArray) || (itemArray->MdcaCount() <= aItemIndex))
		return;
    
	// Gets the item text if the conditions above are met.
	TPtrC itemText = itemArray->MdcaPoint(aItemIndex);

	// We have to find the position of tabs to decide the components
	// available in the item text (icon, heading and text).
	TInt tabPosition1 = itemText.Locate('\t');
	TInt tabPosition2 = itemText.Mid(tabPosition1 + 1).Locate('\t');
	if (tabPosition2 >= 0)
		{
		// We need to add tabPosition1 because the return value of
		// Locate() is relative to tabPosition1.
		tabPosition2 += tabPosition1 + 1;
		}
	TInt tabPosition3 = itemText.Mid(tabPosition2 + 1).Locate('\t');
	if (tabPosition3 >= 0)
		{
		// We need to add tabPosition2 because the return value of
		// Locate() is relative to tabPosition2.
		tabPosition3 += tabPosition2 + 1;
		}
	TInt tabPosition4 = itemText.Mid(tabPosition3 + 1).Locate('\t');
	if (tabPosition4 >= 0)
		{
		// We need to add tabPosition2 because the return value of
		// Locate() is relative to tabPosition2.
		tabPosition4 += tabPosition3 + 1;
		}

	// Sets the attributes to draw the icon.
	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
	if ((aItemIsCurrent) || (aItemIsSelected))
		{
		iGc->SetBrushColor(iHighlightedBackColor);
		}
	else
		{
		iGc->SetBrushColor(iBackColor);
		}

	// Gets the icon index, i.e. the number in the text item before
	// the first tab.
	TInt iconIndex = 0;
	if (tabPosition1 > 0)
		{
		TLex(itemText.Mid(0, tabPosition1)).Val(iconIndex);
		}

		TRect aActualItemRect2 = aActualItemRect;

		aActualItemRect2.iBr.iX = aActualItemRect2.iBr.iX + 0;
		aActualItemRect2.iBr.iY = aActualItemRect2.iBr.iY + 0;
		aActualItemRect2.iTl.iX = aActualItemRect2.iTl.iX + 0;
		aActualItemRect2.iTl.iY = aActualItemRect2.iTl.iY + 10;

	if ((iIconArray) && (iIconArray->Count() > iconIndex)
		&& (tabPosition1 > 0))
		{
		// Draws the icon.
		CFbsBitmap* bitmap = (*iIconArray)[iconIndex]->Bitmap();
		iGc->BitBltMasked(
			aActualItemRect2.iTl,
			bitmap,
			TRect(TPoint(0, 0), bitmap->Header().iSizeInPixels),
			(*iIconArray)[iconIndex]->Mask(),
			ETrue);

		// Draws the rectangle, just in case there are some icons that are
		// smaller than the height of item width and/or height.
		iGc->SetPenStyle(CGraphicsContext::ENullPen);
		if (bitmap->Header().iSizeInPixels.iHeight < aActualItemRect2.Height())
			{
			TRect rect(
				aActualItemRect2.iTl.iX,
				aActualItemRect2.iTl.iY + bitmap->Header().iSizeInPixels.iHeight,
				aActualItemRect2.iTl.iX + iMaxIconSize.iWidth,
				aActualItemRect2.iBr.iY);
			
			TRect rect1(
				aActualItemRect2.iTl.iX,
				aActualItemRect2.iTl.iY - 10,
				aActualItemRect2.iTl.iX + iMaxIconSize.iWidth,
				aActualItemRect2.iBr.iY - 40 );

			    iGc->DrawRect(rect);
			    iGc->DrawRect(rect1);
			}

		if (bitmap->Header().iSizeInPixels.iWidth < iMaxIconSize.iWidth)
			{
			TRect rect = TRect(
				aActualItemRect2.iTl.iX + bitmap->Header().iSizeInPixels.iWidth,
				aActualItemRect2.iTl.iY,
				aActualItemRect2.iTl.iX + iMaxIconSize.iWidth,
				aActualItemRect2.iBr.iY);
			iGc->DrawRect(rect);
			}
		}
	else
		{
		iGc->SetPenStyle(CGraphicsContext::ENullPen);
		TRect rect(
			aActualItemRect.iTl.iX,
			aActualItemRect.iTl.iY,
			aActualItemRect.iTl.iX + iMaxIconSize.iWidth,
			aActualItemRect.iBr.iY);
		iGc->DrawRect(rect);
		}

	// Sets the attributes to draw text, except the font.
	const CFont* font = Font(aItemIndex);
	iGc->SetPenStyle(CGraphicsContext::ESolidPen);
	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
	if ((aItemIsCurrent) || (aItemIsSelected))
		{
		iGc->SetPenColor(iHighlightedTextColor);
		iGc->SetBrushColor(iHighlightedBackColor);
		}
	else
		{
		iGc->SetPenColor(iTextColor);
		iGc->SetBrushColor(iBackColor);
		}

	// If there is only one tab, it means we have to display single line item
	if (tabPosition2 < 0)
		{		
		if (!font)
			{
			font = CEikonEnv::Static()->TitleFont();
			}
		iGc->UseFont(font);
		TRect textRect(
			TPoint(aActualItemRect.iTl.iX + iMaxIconSize.iWidth,
					aActualItemRect.iTl.iY),
			aActualItemRect.iBr);
		TInt baseline =
			(textRect.iBr.iY - textRect.iTl.iY - font->HeightInPixels()) / 2
				+ font->AscentInPixels();

		TBuf<2000> text;
		text.Copy(_L("   "));

		if (tabPosition1 < 0)
			{
			text.Append(itemText);
			iGc->DrawText(text, textRect, baseline,	CGraphicsContext::ELeft, 1);
			}
		else
			{
			text.Append(itemText.Mid(tabPosition1 + 1));
			iGc->DrawText(text, textRect, baseline,CGraphicsContext::ELeft, 1);
			}
		}
	else
		{
		// If there are more than one tab, then we have to display double line
		// item text
		TRect textRect(
			TPoint(aActualItemRect.iTl.iX + iMaxIconSize.iWidth,
				aActualItemRect.iTl.iY),
			aActualItemRect.iBr);
		textRect.iBr.iY -= aActualItemRect.Height() / 2;

		// Draws the first line.
		if (!font)
			{
			font = CEikonEnv::Static()->LegendFont();
			}
		iGc->UseFont(font);
		TInt baseline =
			(textRect.iBr.iY - textRect.iTl.iY - font->HeightInPixels()) / 2
				+ font->AscentInPixels();

		TBuf<2000> text;
		text.Copy(_L(" "));
		text.Append(itemText.Mid(tabPosition1 + 1, tabPosition2 - tabPosition1 - 1));

		iGc->DrawText(text,textRect, baseline, CGraphicsContext::ELeft, 1);

		// Draws the second line. For the second line, we use normal font.
		font = CCoeEnv::Static()->NormalFont();
		iGc->UseFont(font);
		textRect.Move(0, aActualItemRect.Height() / 2);
		baseline =
			(textRect.iBr.iY - textRect.iTl.iY - font->HeightInPixels()) / 2
				+ font->AscentInPixels();///
		
		text.Copy(_L(" "));
		//text.Append(itemText.Mid(tabPosition2 + 1));		
		text.Append(itemText.Mid(tabPosition2 + 1, tabPosition3 - tabPosition2 - 1));

		iGc->DrawText(text, textRect, baseline,	CGraphicsContext::ELeft, 1);
		
		//Loads 2nd bitmap
		TRect aActualItemRect1 = aActualItemRect;

		aActualItemRect1.iBr.iX = aActualItemRect1.iBr.iX + 0;
		aActualItemRect1.iBr.iY = aActualItemRect1.iBr.iY + 0;
		
		if (tabPosition4 >= 0)
			aActualItemRect1.iTl.iX = aActualItemRect1.iTl.iX + 160;
		else
			aActualItemRect1.iTl.iX = aActualItemRect1.iTl.iX + 180;

		aActualItemRect1.iTl.iY = aActualItemRect1.iTl.iY + 0;
		
		text.Copy(_L(""));
		text.Append(itemText.Mid((tabPosition3 + 1),1));
		
		TInt type;

		TLex lex(text);
		lex.Val(type);

		// Draws the icon.
		CFbsBitmap* bitmap = (*iIconArray)[type]->Bitmap();

		iGc->BitBltMasked(aActualItemRect1.iTl,
			bitmap,TRect(TPoint(0,0), bitmap->Header().iSizeInPixels),
			(*iIconArray)[type]->Mask(),
			ETrue);

		// Draws the rectangle, just in case there are some icons that are
		// smaller than the height of item width and/or height.
		iGc->SetPenStyle(CGraphicsContext::ENullPen);
		if (bitmap->Header().iSizeInPixels.iHeight < aActualItemRect1.Height())
			{
			TRect rect(
				aActualItemRect1.iTl.iX,
				aActualItemRect1.iTl.iY + bitmap->Header().iSizeInPixels.iHeight,
				aActualItemRect1.iTl.iX + iMaxIconSize.iWidth,
				aActualItemRect1.iBr.iY);
			iGc->DrawRect(rect);
			}

		if (bitmap->Header().iSizeInPixels.iWidth < iMaxIconSize.iWidth)
			{
			TRect rect = TRect(
				aActualItemRect1.iTl.iX + bitmap->Header().iSizeInPixels.iWidth,
				aActualItemRect1.iTl.iY,
				aActualItemRect1.iTl.iX + iMaxIconSize.iWidth,
				aActualItemRect1.iBr.iY);
			iGc->DrawRect(rect);
			}	

		if (tabPosition4 >= 0)
		{
			//load 3rd bitmap
			TRect aActualItemRect2 = aActualItemRect;

			aActualItemRect2.iBr.iX = aActualItemRect2.iBr.iX + 0;
			aActualItemRect2.iBr.iY = aActualItemRect2.iBr.iY + 0;
			aActualItemRect2.iTl.iX = aActualItemRect2.iTl.iX + 180;
			aActualItemRect2.iTl.iY = aActualItemRect2.iTl.iY + 0;
			
			text.Copy(_L(""));
			text.Append(itemText.Mid((tabPosition4 + 1),1));
			
			type = 0;

			TLex lex1(text);
			lex1.Val(type);

			// Draws the icon.
			CFbsBitmap* bitmap1 = (*iIconArray)[type]->Bitmap();
			iGc->BitBltMasked(aActualItemRect2.iTl,
				bitmap1,TRect(TPoint(0,0), bitmap1->Header().iSizeInPixels),
				(*iIconArray)[type]->Mask(),
				ETrue);

			// Draws the rectangle, just in case there are some icons that are
			// smaller than the height of item width and/or height.
			iGc->SetPenStyle(CGraphicsContext::ENullPen);
			if (bitmap1->Header().iSizeInPixels.iHeight < aActualItemRect2.Height())
				{
				TRect rect(
					aActualItemRect2.iTl.iX,
					aActualItemRect2.iTl.iY + bitmap1->Header().iSizeInPixels.iHeight,
					aActualItemRect2.iTl.iX + iMaxIconSize.iWidth,
					aActualItemRect2.iBr.iY);
				iGc->DrawRect(rect);
				}

			if (bitmap1->Header().iSizeInPixels.iWidth < iMaxIconSize.iWidth)
				{
				TRect rect = TRect(
					aActualItemRect2.iTl.iX + bitmap1->Header().iSizeInPixels.iWidth,
					aActualItemRect2.iTl.iY,
					aActualItemRect2.iTl.iX + iMaxIconSize.iWidth,
					aActualItemRect2.iBr.iY);
				iGc->DrawRect(rect);
				}
			}
		}
	}
/**
Resolves sub string and directionality of the sub string.
Adds no dir marker if directionality of the string not found.
*/
HBufC* CResourceLoader::ResolveSubStringL(TDes& aText, TBool* aMarker)
    {
    // Allocating heap buffer for return string.
    TInt destlength(aText.Length());
    HBufC* retbuf = HBufC::NewLC(destlength + 1); // no dir marker
    TPtr retptr(retbuf->Des());
    
    TBuf<1> marker;
    marker.Append(KDirNotFound);
        
    TPtrC remainder = aText.Right(aText.Length());
    TInt nextKey = remainder.Locate(KSubStringSeparator);
    
    if (nextKey == 0)
        {
        remainder.Set(remainder.Mid(1));
        nextKey = remainder.Locate(KSubStringSeparator);
        if (nextKey != KErrNotFound)
            {
            retptr.Insert(0, aText.Mid(1, nextKey));           
            // Remove string from aText
            aText.Delete(0, nextKey + 1);
            }
        else
            {
            TInt length = aText.Length();
            retptr.Insert(0, aText.Mid(1, length - 1));
            // Remove string from aText
            aText.Delete(0, length);
            }
        }
    else if (nextKey == KErrNotFound)
        {
        retptr.Insert(0, aText); 
        // Remove string from aText
        aText.Delete(0, aText.Length());
        }
    else
        {
        retptr.Insert(0, aText.Mid(0, nextKey));
        // Remove string from aText
        aText.Delete(0, nextKey);
        }
     
    // Resolve directionality of sub string
    HBufC* dirbuf = retbuf->AllocL();
    TPtr dirptr = dirbuf->Des();
    TBool found(EFalse);
    TBidiText::TDirectionality mainDir = ResolveDirectionality(dirptr, &found);
    delete dirbuf;
    
    if (!found)
        {
        retptr.Insert(0, marker);
        *aMarker = ETrue;
        }
    else
        {
        *aMarker = EFalse;
        }
        
    retbuf = retbuf->ReAllocL(retptr.Length());
    CleanupStack::Pop(); //retbuf
    // If the key string wasn't found, retbuf is empty.
    return retbuf;     
    }
Esempio n. 11
0
void CUrl::PartOfAuthority(TComponent aComponent, const TDesC& aUrl, TInt& aStartPos, TInt& aEndPos) const
	{
	if (aEndPos < aStartPos)
		{
		// We don't have what the user asked for
		aStartPos = KCUrlInvalidCharPos;
		aEndPos = KCUrlInvalidCharPos;
		return;
		}

	TPtrC authority = aUrl.Mid(aStartPos, aEndPos - aStartPos);
	TInt endPos = aEndPos - aStartPos;
	TInt colonPos = authority.Locate(':');
	TInt atPos = authority.Locate('@');
	if (atPos == KErrNotFound)
		{
		// There isn't a username or password.
		if (aComponent != EUrlLocation)
			{
			// We don't have what the user asked for
			aStartPos = KCUrlInvalidCharPos;
			aEndPos = KCUrlInvalidCharPos;
			}
		// Else all we've got is the location, so we can return
		// without doing anything
		return;
		}

	// We have an @.
	if (aComponent == EUrlLocation)
		{
		if (atPos != endPos - 1)
			{
			// We have a location of non-zero length
			aStartPos += atPos + 1;
			return;
			}
		else
			{
			aStartPos = KCUrlInvalidCharPos;
			aEndPos = KCUrlInvalidCharPos;			
			}
		}
	else
		{
		// Either username or password
		if (aComponent == EUrlUsername)
			{
			if (colonPos == KErrNotFound || colonPos > atPos)
				{
				// No password
				aEndPos = aStartPos + atPos - 1;
				return;
				}
			else
				{
				aEndPos = aStartPos + colonPos - 1;
				return;
				}
			}
		else
			{
			// They want the password
			if (colonPos == KErrNotFound || colonPos > atPos)
				{
				// There isn't a password
				aStartPos = KCUrlInvalidCharPos;
				aEndPos = KCUrlInvalidCharPos;
				}
			else
				{
				aEndPos = aStartPos + atPos - 1;
				aStartPos += colonPos + 1;
				}
			}
		}
	}
/**
Resolves directionality of the given source text.
Place-holder strings are removed so that they don't affect the result.
*/
TBidiText::TDirectionality CResourceLoader::ResolveDirectionality(TDes& aText, TBool* aFound)
    {
    TInt i = 0;

    // Remove place-holders from string so they don't affect directionality
    // length parameters e.g. "[29]" do not contain strongly directional
    // characters so can ignore them.
    while (i < aText.Length())
        {
        TPtrC remainder = aText.Right(aText.Length() - i);
        TInt nextKey = remainder.Locate(KKeyPrefix);
        i += nextKey;

        if (nextKey != KErrNotFound && i < aText.Length() - 1)
            {
            TInt lastCharInKey = i + 1;

            // skip possible key index
            TText t = aText[lastCharInKey];
            if (t >= '0' && t <= '9')
                {
                lastCharInKey++;

                if (lastCharInKey < aText.Length())
                    {
                    t = aText[lastCharInKey];
                    if (t >= '0' && t <= '9')
                        {
                        lastCharInKey++;
                        }
                    }
                }

            // lastCharInKey is now the index of 'N' or 'U' in the key

            if (lastCharInKey < aText.Length())
                {
                TText t = aText[lastCharInKey];
                if (t == 'U' || t == 'N')
                    {
                    // found key, delete it and continue loop to
                    // search for the next key
                    aText.Delete(i, lastCharInKey - i + 1);
                    }
                // This was not a proper key - check the remaining string
                else
                    {
                    i = lastCharInKey + 1;
                    }
                }
            // end of string encountered - stop
            else
                {
                break;
                }
            }
        // no key found - stop
        else
            {
            break;
            }
        }

    return TBidiText::TextDirectionality(aText, aFound);
    }
Esempio n. 13
0
void ParseCommandLine ()
	{
	TBuf<64> c;
	
	User::CommandLine(c);
	c.LowerCase();

	if (c != KNullDesC)
		{
		TLex lex(c);
		TPtrC token;

		while (token.Set(lex.NextToken()), token != KNullDesC)
			{
			if (token.Mid(0) == _L("quiet"))
				{
				gQuiet = ETrue;
				continue;
				}

			if (token.Mid(0) == _L("verbose"))
				{
				gQuiet = EFalse;
				continue;
				}

			if (token.Left(5) == _L("chunk"))
				{
				TInt equalPos;
				equalPos = token.Locate('=');
				if (equalPos > 0 && (equalPos+1) < token.Length())
					{
					TLex lexNum(token.Mid(equalPos+1));
					lexNum.Val(gChunkSize,EDecimal);	
					}
				continue;
				}

			if (token.Left(3) == _L("low"))
				{
				TInt equalPos;
				equalPos = token.Locate('=');
				if (equalPos > 0 && (equalPos+1) < token.Length())
					{
					TLex lexNum(token.Mid(equalPos+1));
					lexNum.Val(gMin,EDecimal);	
					}
				continue;
				}

			if (token.Left(5) == _L("high"))
				{
				TInt equalPos;
				equalPos = token.Locate('=');
				if (equalPos > 0 && (equalPos+1) < token.Length())
					{
					TLex lexNum(token.Mid(equalPos+1));
					lexNum.Val(gMax,EDecimal);	
					}
				continue;
				}

			if (token.Left(6) == _L("period"))
				{
				TInt equalPos;
				equalPos = token.Locate('=');
				if (equalPos > 0 && (equalPos+1) < token.Length())
					{
					TLex lexNum(token.Mid(equalPos+1));
					lexNum.Val(gPeriod,EDecimal);	
					}
				continue;
				}

			if (token.Left(3) == _L("mem"))
				{
				TInt equalPos;
				equalPos = token.Locate('=');
				if (equalPos > 0 && (equalPos+1) < token.Length())
					{
					TLex lexNum(token.Mid(equalPos+1));
					lexNum.Val(gMemScheme,EDecimal);	
					}
				continue;
				}

			}
		}
	}
// -----------------------------------------------------------------------------
// CNSmlDsProvisioningAdapter::SaveL
// -----------------------------------------------------------------------------
void CNSmlDsProvisioningAdapter::SaveL(TInt aItem)
	{
	_DBG_FILE("CNSmlDsProvisioningAdapter::SaveL(): begin");
	TPckgBuf<TUint32> uid;
	
	RSyncMLDataSyncProfile profile;
	TBool ret = EFalse;
	
	if(iProfiles[aItem]->iServerId != NULL)
	{
	RSyncMLDataSyncProfile ProfileToSearch;
	RArray<TSmlProfileId> arr;
    iSession.ListProfilesL( arr, ESmlDataSync );
    
    TInt ProfileId = KErrNotFound;
    CleanupClosePushL(arr);   	
	for ( TInt index = 0; index < arr.Count(); index++ )
		{
	    TRAPD( error, ProfileToSearch.OpenL(iSession, arr[index], ESmlOpenRead ) );
	    if ( error == KErrNone )
	        {	            	            	        
    	        if ( ( iProfiles[aItem]->iServerId->Des()).Compare(ProfileToSearch.ServerId() ) == 0 )
    	            {
    	            
                    ret = ETrue;                    
                    ProfileId = (TInt)arr[index];
                    ProfileToSearch.Close();
                    break;
                    }	            		    
	        }
	      ProfileToSearch.Close();  
		}
    CleanupStack::PopAndDestroy( &arr );
	
	if( ret )
		{
		profile.OpenL(iSession, ProfileId , ESmlOpenReadWrite );	
		}
	else
		{
	profile.CreateL( iSession );
		}
	CleanupClosePushL( profile );	
	}
	else
	{
		
		profile.CreateL( iSession );
		CleanupClosePushL( profile );	
	}
	
	// ui needs this to be set 0
	profile.SetCreatorId(0);//iProfiles[aItem]->iProfile.SetCreatorId(0);
	profile.SetSanUserInteractionL( iProfiles[aItem]->iServerAlertedAction );
	
	if ( iProfiles[aItem]->iDisplayName )
	    {
	    profile.SetDisplayNameL( iProfiles[aItem]->iDisplayName->Des() );    
	    }
	
	if ( iProfiles[aItem]->iServerId )
	    {
	    profile.SetServerIdL( iProfiles[aItem]->iServerId->Des() );    
	    }
	    
	if ( iProfiles[aItem]->iUsername )   
	    {
	    profile.SetUserNameL( iProfiles[aItem]->iUsername->Des() );    
	    }
	
	if ( iProfiles[aItem]->iPassword )
	    {
	    profile.SetPasswordL( iProfiles[aItem]->iPassword->Des() );    
	    }
	    
	// creates profile -> must be done before opening the connection
	profile.UpdateL();
		
	RSyncMLConnection connection;
	connection.OpenL( profile, KUidNSmlMediumTypeInternet.iUid );
	CleanupClosePushL( connection );
		
    if ( (iProfiles[aItem]->iVisitParameter
            && iProfiles[aItem]->iVisitParameter->Data().Length() == uid.MaxLength() )
            || iToNapIDInternetIndicator)
		{
        TUint apId = 0;
        TInt ERROR = KErrNone;
        TInt err1 = KErrNone;

        if (iToNapIDInternetIndicator)
            {
            //Get Access Point from DB or SNAP
            TRAP(err1, apId = WPAdapterUtil::GetAPIDL());
            }

        else
            {
            uid.Copy(iProfiles[aItem]->iVisitParameter->Data() );

            RCmManagerExt  cmmanagerExt;
		    cmmanagerExt.OpenL();
		    CleanupClosePushL(cmmanagerExt);
		    RCmConnectionMethodExt cm;
		    cm = cmmanagerExt.ConnectionMethodL( uid());
		    CleanupClosePushL( cm );

            TRAP( ERROR, apId = cm.GetIntAttributeL(CMManager::ECmIapId) );
            CleanupStack::PopAndDestroy(2); //cmmanager,cm
            }

        //Get default access point in failure of getting AP
        if (ERROR != KErrNone || err1 != KErrNone)
			{
			apId = GetDefaultIAPL();
			}
		
		HBufC8* iapBuf = HBufC8::NewLC( 8 );
		TPtr8 ptrBuf = iapBuf->Des();
		ptrBuf.Num( apId );
		
		connection.SetPropertyL( KNSmlIAPId, *iapBuf );
			
        CleanupStack::PopAndDestroy(); //iapBuf	
		}
		
	if( iProfiles[aItem]->iHostAddress )
		{
		// see if address contains also port
		TBool portFound = EFalse;
		TInt startPos(0);
		if(iProfiles[aItem]->iHostAddress->Find(KNSmlDsProvisioningHTTP)==0)
		    {
		    startPos=KNSmlDsProvisioningHTTP().Length();		    		    
		    }
		else if(iProfiles[aItem]->iHostAddress->Find(KNSmlDsProvisioningHTTPS)==0)
		    {
		    startPos=KNSmlDsProvisioningHTTPS().Length();		    		    
		    }
		TPtrC uriPtr = iProfiles[aItem]->iHostAddress->Mid(startPos);
		
		if(uriPtr.Locate(KNSmlDMColon)!=KErrNotFound)
		    {
			portFound = ETrue;
		    }
	
		if( portFound == EFalse )
			{
			HBufC *uri = 0;
			// port not found from URI -> see if it is given separately				
			if( iProfiles[aItem]->iPort )
				{
				// parse address and port into URI
			
				if( CombineURILC( iProfiles[aItem]->iHostAddress->Des(),
							  iProfiles[aItem]->iPort->Des(), uri ) == KErrNone )
					{
					if(iProfiles[aItem]->iHostAddress)
					{
						delete iProfiles[aItem]->iHostAddress;
						iProfiles[aItem]->iHostAddress = NULL;
					}
					iProfiles[aItem]->iHostAddress = uri->Des().AllocL();
					}
				CleanupStack::PopAndDestroy(); // uri		  
				}
			else
				{
				// use default port
				if( CombineURILC( iProfiles[aItem]->iHostAddress->Des(),
							  KNSmlDsDefaultPort(), uri ) == KErrNone )
					{
					if(iProfiles[aItem]->iHostAddress)
					{
						delete iProfiles[aItem]->iHostAddress;
						iProfiles[aItem]->iHostAddress = NULL;
					}
					iProfiles[aItem]->iHostAddress = uri->Des().AllocL();
					}
				CleanupStack::PopAndDestroy(); // uri		  
				}
			}
		

		connection.SetServerURIL( ConvertTo8LC( iProfiles[aItem]->iHostAddress->Des() ) );
		CleanupStack::PopAndDestroy(); // ConvertTo8LC
		}
		
	// set authtype, HTTPUserName, HTTPPassword
	if( iProfiles[aItem]->iHTTPUserName ||
	    iProfiles[aItem]->iHTTPPassword )
		{
		connection.SetPropertyL( KNSmlHTTPAuth, KNSmlTrueVal );
		
		if( iProfiles[aItem]->iHTTPUserName )
			{
			connection.SetPropertyL( KNSmlHTTPUsername, iProfiles[aItem]->iHTTPUserName->Des() );
			}
		if( iProfiles[aItem]->iHTTPPassword )
			{
			connection.SetPropertyL( KNSmlHTTPPassword, iProfiles[aItem]->iHTTPPassword->Des() );
			}
		}
	else
		{
		connection.SetPropertyL( KNSmlHTTPAuth, KNSmlFalseVal );
		}
		
	connection.UpdateL();
	CleanupStack::PopAndDestroy(); // connection
	
	
		
	
	
	if(iProfiles[aItem]->iProtocolVersion == ESmlVersion1_1_2 || 
			iProfiles[aItem]->iProtocolVersion == ESmlVersion1_2 )
	{
		profile.SetProtocolVersionL(iProfiles[aItem]->iProtocolVersion);
	}

	
	
	
	
		
	TInt iDataProvElementCount = iProfiles[aItem]->iDataProvElement.Count();
	_DBG_FILE("CNSmlDsProvisioningAdapter::SaveL(): Resource For loop: before Start");
	for ( TInt i = 0; i < iDataProvElementCount; i++ )
		{
        _DBG_FILE(
                "CNSmlDsProvisioningAdapter::SaveL(): Resource For loop: In");
		RSyncMLDataProvider dataProvider;

        TRAPD(error, dataProvider.OpenL(iSession,
                iProfiles[aItem]->iDataProvElement[i]->iUid));
		if (!error)
		    {
		    CleanupClosePushL(dataProvider);
            if (ret)
                {
                RArray<TSmlTaskId> providers;
                profile.ListTasksL(providers);
                TInt dataprovcount = providers.Count();

                for (TInt i = 0; i < dataprovcount; i++)
                    {
                    TSmlTaskId taskID = providers[i];
                    RSyncMLTask task;
                    task.OpenL(profile, taskID);
                    CleanupClosePushL(task);

                    if (dataProvider.Identifier() == task.DataProvider())
                        {
                        profile.DeleteTaskL(taskID);
                        CleanupStack::PopAndDestroy();
                        break;
                        }

                    CleanupStack::PopAndDestroy();

                    }
                providers.Reset();
                providers.Close();

                }
            HBufC* localDB = dataProvider.DefaultDataStoreName().AllocLC();
            _DBG_FILE("CNSmlDsProvisioningAdapter::SaveL(): DB value");
            DBG_ARGS(
                    iProfiles[aItem]->iDataProvElement[i]->iRemoteDBUri->Des().Ptr());

            RSyncMLTask task;
            task.CreateL(
                    profile,
                    iProfiles[aItem]->iDataProvElement[i]->iUid,
                    iProfiles[aItem]->iDataProvElement[i]->iRemoteDBUri->Des(),
                    localDB->Des());
            CleanupClosePushL(task);
            TRAPD(err, task.UpdateL());
            if (err != KErrAlreadyExists && err != KErrNone)
                {
                User::Leave(err);
                }
            CleanupStack::PopAndDestroy(3); // task, localDB, dataProvider
		    }
		
		}
	_DBG_FILE("CNSmlDsProvisioningAdapter::SaveL(): Resource For loop: after End");
				
	profile.UpdateL();
	iProfiles[aItem]->iProfileId = profile.Identifier();
	CleanupStack::PopAndDestroy( &profile );
	_DBG_FILE("CNSmlDsProvisioningAdapter::SaveL(): end");
	}
/**
 * Finds the java attribute specified by
 * aAttributeName from aJad and returns the value of that attribute
 * in HBufC.
 * @param[in] aJad contents of Jad file
 * @param[in] aAttributeName the name of a java attribute
 * @return the value of the attribute. Caller gets the ownership of the
 * returned HBufC.
 * If the attribute is not found, returns NULL
 */
HBufC *CSilentMIDletInstall::ParseAttribute(const HBufC *aJad, const TDesC& aAttributeName)
{
    JELOG2(EJavaPreinstaller);

    TInt    nInd(0);
    TBool   fullNameFound(EFalse);
    TUint32 ch;

    // Start parsing from the beginning of the Jad file
    TPtrC parsePtr = aJad->Mid(nInd);

    do
    {
        // Find attribute name
        nInd = parsePtr.Find(aAttributeName);
        if (nInd < 0)
        {
            // Returns NULL if the attribute cannot be found
            return NULL;
        }

        // Check that the attribute name was preceded by line break or
        // it was at the beginning of the Jad file
        if (nInd == 0)
        {
            fullNameFound = ETrue;
        }
        else
        {
            ch = parsePtr[nInd-1];
            if ((ch == CR) || (ch == LF))
            {
                fullNameFound = ETrue;
            }
            else
            {
                // Name was just a part of longer string (not 'word match')
                fullNameFound = EFalse;
                // Skip to the last character of the found match.
                // We can skip because we are insterested only in 'word' matches
                // so the next cannot start inside the area we are skipping now.
                parsePtr.Set(parsePtr.Mid(nInd + aAttributeName.Length() - 1));
                continue;
            }
        }

        // Check whether Jad file ends after attribute name
        if (nInd + aAttributeName.Length() >= parsePtr.Length())
        {
            // Jad file ends immediately after the found
            // attribute name instance. No attribute value
            return NULL;
        }

        // Check that there is a white space character or colon after
        // attribute name
        ch = parsePtr[nInd + aAttributeName.Length()];
        if ((ch == COLON) || (ch == SP) || (ch == HT))
        {
            fullNameFound = ETrue;
        }
        else
        {
            // Name was just a part of longer string (not 'word match')
            fullNameFound = EFalse;
            // Skip to the next character after the found match
            parsePtr.Set(parsePtr.Mid(nInd + aAttributeName.Length()));
            continue;
        }
    }
    while (!fullNameFound);

    // Skip to the end of the attribute name and find ':' after the name.
    // The skipped characters must be white space chacraters, otherwise
    // the attribute name is illegal and Java Installer will not accept
    // the Jad file.
    parsePtr.Set(parsePtr.Mid(nInd + aAttributeName.Length() - 1));
    nInd = parsePtr.Locate(COLON);
    if (nInd < 0)
    {
        return NULL;
    }
    nInd++;

    // Parse attribute value (CR or LF ends)
    TInt nEndInd = parsePtr.Locate(CR);
    TInt nTmpInd = parsePtr.Locate(LF);

    if (KErrNotFound == nEndInd)
    {
        nEndInd = parsePtr.Length() - 1;
    }
    if (KErrNotFound == nTmpInd)
    {
        nTmpInd = parsePtr.Length() - 1;
    }

    if (nTmpInd < nEndInd)
    {
        nEndInd = nTmpInd;
    }

    if (nEndInd < nInd)
    {
        return NULL;
    }

    TPtrC attributeValue = parsePtr.Mid(nInd, (nEndInd - nInd));

    // Remove possible white space from the beginning and end of the value
    HBufC *bufValue = attributeValue.Alloc();
    if (NULL == bufValue)
    {
        return NULL;
    }
    TPtr value = bufValue->Des();
    value.Trim();

    return bufValue;
} // parseAttribute
/**
Counts the number of parameters in the text. 
Needed for correct memory allocations.
*/
TInt CResourceLoader::GetParamCount(const TDesC& aText, TInt aIndex)
    {
    TInt paramCount(0);
    TInt i(0);
    TBool singleIndex((aIndex < 0) || (aIndex > KNumOfParams) ? EFalse : ETrue);

    while (i < aText.Length())
        {
        TPtrC remainder = aText.Right(aText.Length() - i);
        TInt nextKey = remainder.Locate(KKeyPrefix);
        i += nextKey;

        if (nextKey != KErrNotFound && i < aText.Length() - 1)
            {
            TInt lastCharInKey = i + 1;

            // skip possible key index
            TText t = aText[lastCharInKey];
            TInt foundIndex(-1);
            
            if (t >= '0' && t <= '9')
                {
                lastCharInKey++;
                foundIndex = t - '0';

                if (lastCharInKey < aText.Length())
                    {
                    t = aText[lastCharInKey];
                    if (t >= '0' && t <= '9')
                        {
                        foundIndex *= 10;
                        foundIndex += t - '0';
                        lastCharInKey++;
                        }
                    }
                }

            // lastCharInKey is now the index of 'N' or 'U' in the key

            if (lastCharInKey < aText.Length())
                {
                // Only count parameter, if index matches
                if (!singleIndex || (foundIndex == aIndex))
                    {
                    TText t = aText[lastCharInKey];
                    if (t == 'U' || t == 'N')
                        {
                        // found legit key, count it
                        paramCount++;
                        // continue search after index
                        i = lastCharInKey + 1;
                        }
                    else if (t == '%')
                        i = lastCharInKey;
                    else    // continue search after index
                        i = lastCharInKey + 1;
                    }
                else    // continue search after index
                    i = lastCharInKey + 1;
                }
            else    // end of string encountered - stop
                break;
            }
        else     // no key found - stop
            break;
        }

    return paramCount;
    }
Esempio n. 17
0
void CUrl::Part(TComponent aComponent, const TDesC& aUrl, TInt& aStartPos, TInt& aEndPos) const
//
// Takes a descriptor as a url and parses it for the start and end positions of a particular component. 
// KCUrlInvalidCharPos is used to indicate that component is not in url.
// 
// Based on RFC2396
	{
	aStartPos = aEndPos = KCUrlInvalidCharPos;

	TPtrC url = aUrl;
	// search for first of ':' | '/' | '?' | '#'
	TInt stripped =0;

	TInt colonPos = aUrl.Locate(':');
	__ASSERT_ALWAYS(colonPos != 0,Panic(EInvalidUrl));		// if ':' is first character then it is invalid
	TInt hashPos = aUrl.Locate('#');
	TInt slashPos = aUrl.Locate('/');
	TInt queryPos = aUrl.Locate('?');

	colonPos = colonPos == KErrNotFound ? KMaxTInt : colonPos;
	hashPos = hashPos == KErrNotFound ? KMaxTInt : hashPos;
	slashPos = slashPos == KErrNotFound ? KMaxTInt : slashPos;
	queryPos = queryPos == KErrNotFound ? KMaxTInt : queryPos;

	// if ':' is before others then there is a scheme so extract it
	if (colonPos < hashPos && colonPos < slashPos && colonPos < queryPos)
		{
		if (aComponent == EUrlScheme)
			{
			aStartPos = stripped;
			aEndPos = colonPos -1;
			return;
			}

		if (url.Length() == colonPos + 1) // reached the end of the url
			return;	
		url.Set(url.Mid(colonPos+1));
		stripped += colonPos+1;
		hashPos -= colonPos+1;
		slashPos -= colonPos+1;
		queryPos -= colonPos+1;
		}

	// if first 2 characters are '//' then a host exists, 
	if (url.Find(KUrlLoc) == 0)
		{
		TInt urlLocLength = KUrlLoc().Length();
		if (url.Length() == urlLocLength) // reached the end of the url
			return;
		// extract '//' and rescan for '/'
		url.Set(url.Mid(urlLocLength));
		stripped += urlLocLength;
		hashPos -= urlLocLength;
		queryPos -= urlLocLength;
		slashPos = url.Locate('/');
		slashPos = slashPos == KErrNotFound ? KMaxTInt : slashPos;

		// host is ended by first of '#' | '?' | '/' | end of url
		TInt hostEndCharPos = slashPos;
		hostEndCharPos = hashPos < hostEndCharPos ? hashPos : hostEndCharPos;
		hostEndCharPos = queryPos < hostEndCharPos ? queryPos : hostEndCharPos;
		hostEndCharPos = url.Length() < hostEndCharPos ? url.Length() : hostEndCharPos;
	
		if (aComponent == EUrlAuthority)
			{
			aStartPos = stripped;
			aEndPos = hostEndCharPos+stripped-1;
			return;
			}
		if (aComponent == EUrlLocation ||
			aComponent == EUrlUsername ||
			aComponent == EUrlPassword)
			{
			aStartPos = stripped;
			aEndPos = hostEndCharPos+stripped-1;
			// We need part of the authority. Extract it
			PartOfAuthority(aComponent, aUrl, aStartPos, aEndPos);
			return;
			}
		//	Have we reached the end of the url
		if (url.Length() == hostEndCharPos)
			return; 
		// extract host	
		url.Set(url.Mid(hostEndCharPos));
		stripped += hostEndCharPos;
		slashPos -= hostEndCharPos;
		hashPos -= hostEndCharPos;
		queryPos -= hostEndCharPos;		
		}

	//	If first character is '/' | this is the start of a relative url | there is no authority then path exists
	//	as long as it isn't just a query or fragment
	if ((slashPos == 0 || stripped == 0 || stripped == colonPos +1 ) && hashPos != 0 && queryPos !=0)
		{ 
		TInt pathEndCharPos = queryPos;
		pathEndCharPos = hashPos < pathEndCharPos ? hashPos : pathEndCharPos;
		pathEndCharPos = url.Length() < pathEndCharPos ? url.Length() : pathEndCharPos;
		if (aComponent == EUrlPath)
			{
			aStartPos = stripped;
			aEndPos = pathEndCharPos+stripped-1;
			return;
			}
		if (url.Length() == pathEndCharPos) // reached the end of the url
			return;
		//	extractPath
		url.Set(url.Mid(pathEndCharPos));
		stripped += pathEndCharPos ;
		queryPos -= pathEndCharPos ;
		hashPos -= pathEndCharPos ;
		}

	// if first is '?' then query exists
	if (queryPos == 0) 	
		{
		// extract ?, query is ended by '#' | end of url
		if (url.Length() == 1)	// reached the end of the url
			return;
		url.Set(url.Mid(1));
		stripped += 1;
		hashPos -= 1;
		// extract query
		TInt queryEndCharPos = hashPos;
		queryEndCharPos = url.Length() < queryEndCharPos ? url.Length() : queryEndCharPos;
		if (aComponent == EUrlQuery)
			{
			aStartPos = stripped;
			aEndPos = queryEndCharPos+stripped-1;
			return;
			}
		if (url.Length() == queryEndCharPos) // reached the end of the url
			return;
		url.Set(url.Mid(queryEndCharPos));
		stripped += queryEndCharPos;
		hashPos -= queryEndCharPos;
		}

	if (hashPos == 0)
		{
		if (url.Length() == 1)	// reached the end of the url
			return;
		// extract hash
		url.Set(url.Mid(1));
		stripped += 1;
		// fragment left
		if (aComponent == EUrlFragment)
			{
			aStartPos = stripped;
			aEndPos = stripped + url.Length() -1;
			return;
			}
		}
	__ASSERT_DEBUG(	aStartPos == aEndPos && aEndPos == KCUrlInvalidCharPos, Panic(EInvalidUrl));
	}