Example #1
0
EXPORT_C HBufC* CScriptFile::ReplaceLC(const TDesC& aOld, const TDesC& aNew, const TDesC& aOldString)
	{
	HBufC* rString = aOldString.AllocLC();
	TInt oldLen = aOld.Length();
	TInt newLen = aNew.Length();

	if (!oldLen)
		return rString;

	for (TInt pos = 0; pos < rString->Length(); pos += newLen)
		{
		TPtrC ptrC = rString->Mid(pos);
		TInt find = ptrC.Find(aOld);

		if (find == KErrNotFound)
			return rString;
	
		pos += find;

		if (newLen > oldLen)
			{
			rString = rString->ReAllocL(rString->Length() + newLen - oldLen);
			CleanupStack::Pop();
			CleanupStack::PushL(rString);
			}

		TPtr ptr(rString->Des());
		ptr.Replace(pos, oldLen, aNew);
		}

	return rString;
	}
void CSmsStatusReplierImpl::SendStatus(const TDesC& aTo)
{

	TBuf<50> author;
	Settings().GetSettingL(SETTING_PUBLISH_AUTHOR, author);
	SetStatus(_L("authorname"), author);

	TInt count=iNames->Count(), size=30;

	TInt i=0;
	for (i=0; i<count; i++) {
		size += iNames->MdcaPoint(i).Length();
		size += iValues->MdcaPoint(i).Length();
		size += 4;
	}
	if (size > iBuf->Des().MaxLength() ) {
		iBuf=iBuf->ReAllocL(size);
	}
	iBuf->Des()=_L("status at ");
	TBBTime t(KTime); t()=GetTime();
	TPtr p=iBuf->Des();
	t.IntoStringL(p);
	iBuf->Des().Append(_L("\n"));

	for (i=0; i<count; i++) {
		iBuf->Des().Append(iNames->MdcaPoint(i));
		iBuf->Des().Append(_L(": "));
		iBuf->Des().Append(iValues->MdcaPoint(i));
		iBuf->Des().Append(_L("\n"));
	}

	iSms->send_message(aTo, *iBuf, false);
}
HBufC* TestUniDataModelVCalPlugin::ReadFromFileL(const TDesC& aFile)
{
		RFile file;
		TBuf8<1024> lineBuffer;
		TInt err = KErrNone;

		err = file.Open(iFs, aFile, EFileStreamText | EFileRead | EFileShareAny);

		if (err != KErrNone) // Didn't find the file, so leave - should only get valid filenames!
			{
				User::Leave(KErrNotFound);
			}

		HBufC* bioBuf = HBufC::NewLC(65535); // Create a new descriptor on the heap.
		HBufC* copyBuffer = HBufC::NewLC(1024);

		do // Read in the text from file, and also check if there is a name field:
			{
				err = file.Read(lineBuffer);// Read upto 256 chars, '\n' and all...
				//err = ReadLineL(file,lineBuffer);
				if (err == KErrNone) // Made a valid read,
					if (lineBuffer.Length() == 0) // but read 0 chars
                err = KErrEof; // so set err value to end processing

				if (err == KErrNone)
					{	
						copyBuffer->Des().Copy(lineBuffer);// Copy, and overwrite existing text
						if ( (bioBuf->Length() + copyBuffer->Length())
								> bioBuf->Des().MaxLength())
							{
								bioBuf = bioBuf->ReAllocL(bioBuf->Length()
										+ copyBuffer->Length());
							}
						bioBuf->Des().Append(*copyBuffer);
						//bioBuf->Des().Append(_L("\n"));
					}
    }while (err != KErrEof);

    CleanupStack::PopAndDestroy(); // Destroy the copyBuffer.
    CleanupStack::Pop();// Remove the bioBuf.

    file.Close();
    return bioBuf;
}
HBufC* CResourceLoader::ResolveSubStringDirsL(TDes& aText, TInt aCount, TBool* aMarker)
    {   
    // Allocating heap buffer for return string.
    TInt destlength(aText.Length());
    destlength = destlength + (KExtraSpaceForMainStringDirMarker) * aCount;
    HBufC* retbuf = HBufC::NewLC(destlength);
    TPtr retptr(retbuf->Des());
    TInt freeSpace(destlength); 
    TInt i(0);
    TInt j(0);
    TBuf<1> subsMarker;
    subsMarker.Append(KSubStringSeparator);
    TInt count(aCount - 1);

    while (i  < aCount)
        {
        // Resolve sub string
        HBufC* buffer = ResolveSubStringL(aText, aMarker);
        TPtr ptr = buffer->Des();
        CleanupStack::PushL(buffer); 
        
        // Restore sub string separators
        if (freeSpace >= ptr.Length()) 
            {
            retptr.Insert(j, ptr);
            freeSpace -= ptr.Length();
            j += ptr.Length();
            if (freeSpace > KExtraSpaceForMainStringDirMarker && i < count)
                {
                retptr.Append(subsMarker);
                j ++;
                }
            }    
        CleanupStack::PopAndDestroy(buffer);  
        i++;                       
        } 
    
    retbuf = retbuf->ReAllocL(retptr.Length());
    CleanupStack::Pop(); //retbuf  
    return retbuf;
    }
void CSmsStatusReplierImpl::SetStatus(const TDesC& aName, const MBBData* aValue)
{
	TInt err=KErrNone;
	iBuf->Des().Zero();
	if (aValue)
	do {
		TPtr p=iBuf->Des();
		CC_TRAP(err, aValue->IntoStringL(p));
		if (err==KErrOverflow) {
			iBuf->Des().Zero();
			iBuf=iBuf->ReAllocL(iBuf->Des().MaxLength()*2);
		}
	} while (err==KErrOverflow);

	if (err!=KErrNone) {
		iBuf->Des().Zero();
		iBuf->Des()=_L("Error in reading data: ");
		iBuf->Des().AppendNum(err);
	}
	SetStatus(aName, *iBuf);
}
void CDesktopHotKeyAppUi::About()
	{
	TFileName filename;
	GetAppPath(filename);
	HBufC* textResource = StringLoader::LoadLC(R_ABOUT_FILE);
	filename.Append(textResource->Des());
	CleanupStack::PopAndDestroy(textResource);

	RFile file;
	TInt nErr = file.Open(CEikonEnv::Static()->FsSession(), filename, EFileRead
			| EFileShareAny);
	if (nErr != KErrNone)
		return;

	TFileText fileText;
	fileText.Set(file);
	TBuf<128> linePtr;
	HBufC* iText = NULL;

	while (fileText.Read(linePtr) == KErrNone)
		{
		if (iText!=NULL)
			{
			iText = iText->ReAllocL(iText->Length() + linePtr.Length() + 2);
			iText->Des().Append(linePtr);
			}
		else
			{
			iText = HBufC::NewL(linePtr.Length() + 2);
			iText->Des().Append(linePtr);
			}
		iText->Des().Append(CEditableText::ELineBreak);
		}
	file.Close();

	ShowModalAboutDlgL(R_ABOUT_DIALOG_TITLE,iText->Des());
	
	
	delete iText;
	}
HBufC* CAknIconArray::GetBmpNameLC(TResourceReader& aReader)
    {
    HBufC* bmpName = aReader.ReadHBufCL();
    CleanupStack::PushL(bmpName);

    TBool drivePresent =
        (bmpName->Length() >= 3 &&
        (*bmpName)[1] == ':' &&
        (*bmpName)[2] == '\\' );

    RFs& fs = CCoeEnv::Static()->FsSession();

    TBool found = EFalse;
    if ( drivePresent )
        {
        found = BaflUtils::FileExists( fs, *bmpName );
        }

    // If drive letter is not specified, or not found in the specified drive,
    // FindByDir scans the drives in order E:, D:, C:, Z:

    if (!found)
        {
        TFindFile find( fs );
        if (find.FindByDir(*bmpName, KNullDesC) == KErrNone)
            {
            if (bmpName->Length() < find.File().Length())
                {
                bmpName = bmpName->ReAllocL(find.File().Length());
                CleanupStack::Pop(); // old bmpName
                CleanupStack::PushL( bmpName );
                }
    
            *bmpName = find.File();
            }
        }

    return bmpName;
    }
Example #8
0
// ---------------------------------------------------------------------------
// CBSServer::DisplaySessionInfoL display the info for each open session,
// except for the one that called this method
// ---------------------------------------------------------------------------
//
void CBSServer::DisplaySessionInfoL( CBSSession* aSession, TInt aErrorCode )
	{
    TRACE( T_LIT( "CBSServer::DisplaySessionInfoL() begin aSession[%d], aErrorCode[%d]"),aSession,aErrorCode );

    User::LeaveIfNull( aSession );
    // some constants
    const TInt KStringLength = 512;
    const TInt KNumberLength = 16;
    _LIT( KMessage0,"Operation failed.Errorcode:");    
    _LIT( KMessage1," Info on open sessions [ProcessFileName|ThreadId|ProcessId|Caption]:");
    _LIT( KBracketOpen, " [");
    _LIT( KBracketClose, "]");
    _LIT( KSeparator, "|");
    

    HBufC* outputString = HBufC::NewLC( KStringLength );
    TPtr outputStringPtr( outputString->Des() );

    TBuf<KNumberLength> number;
    number.Num( aErrorCode );
    
    //make sure the string is long enough
    TInt newLength = outputString->Length() +
                     KMessage0().Length() +
                     number.Length() + 
                     KMessage1().Length();
    
    //reallocate if necessary
    if ( outputStringPtr.MaxLength() < newLength )
        {
        CleanupStack::Pop( outputString );
        outputString = outputString->ReAllocL( newLength );
        outputStringPtr.Set( outputString->Des() );
        CleanupStack::PushL( outputString );
        }    
        
    outputStringPtr.Append( KMessage0 );
    outputStringPtr.Append( number );
    outputStringPtr.Append( KMessage1 );
    
        
    TInt count = iSessions.Count();
	TRACE( T_LIT( "CBSServer::DisplaySessionInfoL() numberSessions=%d"),count );
	CBSSession* currentSession;
	for( TInt i = 0; i < count; i++ )
		{		
		currentSession = iSessions[i];
        TRACE( T_LIT( "CBSServer::DisplaySessionInfoL() iteration=%d session=%d"),i,currentSession );
    	if ( currentSession 
    	     && currentSession->InfoAvailable()
    	     && currentSession != aSession )
    	    {
    		TBuf<KNumberLength> threadIdStr;
    		TThreadId threadId;
    		if ( KErrNone == currentSession->ThreadId( threadId ) )
    		    {
    		    threadIdStr.NumUC( threadId.Id(), EDecimal );
    		    }    		
    		TBuf<KNumberLength> processIdStr;
    		TProcessId processId;
    		if ( KErrNone == currentSession->ProcessId( processId ) )
    		    {
    		    processIdStr.NumUC( processId.Id(), EDecimal );
    		    }
            
            //make sure the string is long enough
            newLength = outputString->Length() +
                        KBracketOpen().Length() +
                        currentSession->FileName().Length() + 
                        threadIdStr.Length() + 
                        processIdStr.Length() +
                        currentSession->Caption().Length() +                        
                        ( 3 * KSeparator().Length() ) +                        
                        KBracketClose().Length();

            //reallocate if necessary
            if ( outputStringPtr.MaxLength() < newLength )
                {
                CleanupStack::Pop( outputString );
                outputString = outputString->ReAllocL( newLength );
                outputStringPtr.Set( outputString->Des() );
                CleanupStack::PushL( outputString );
                }

  		    outputStringPtr.Append( KBracketOpen );
    		
    		//processfilename
    		outputStringPtr.Append( currentSession->FileName() );
    		outputStringPtr.Append( KSeparator );
    		    		
    		//threadid    		
    		outputStringPtr.Append( threadIdStr );
    		outputStringPtr.Append( KSeparator );
    		
    		//processid    		
    		outputStringPtr.Append( processIdStr );
    		outputStringPtr.Append( KSeparator );	
    		
    		//caption
    		outputStringPtr.Append( currentSession->Caption() );    		

    		outputStringPtr.Append( KBracketClose );
    	    }
		}     
	
	TRACE( T_LIT( "CBSServer::DisplaySessionInfoL() string creation OK") );
	TRACE( T_LIT( "%S"), outputString );
	CleanupStack::PopAndDestroy( outputString );
	TRACE( T_LIT( "CBSServer::DisplaySessionInfoL() end") );
	}
/**
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;     
    }