⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 helloworldbasicappui.cpp

📁 这是Symbian平台下实现Base64编解码的源码.
💻 CPP
字号:
/*
* ==============================================================================
*  Name        : helloworldbasicappui.cpp
*  Part of     : Helloworldbasic
*  Interface   : 
*  Description : 
*  Version     : 
*
*  Copyright (c) 2005-2006 Nokia Corporation.
*  This material, including documentation and any related 
*  computer programs, is protected by copyright controlled by 
*  Nokia Corporation.
* ==============================================================================
*/

// INCLUDE FILES
#include <avkon.hrh>
#include <aknnotewrappers.h>
#include <stringloader.h>
#include <HelloWorldBasic.rsg>
#include <f32file.h>
#include <s32file.h>
#include <IMCVCODC.H>
#include "HelloWorldBasic.pan"
#include "HelloWorldBasicAppUi.h"
#include "HelloWorldBasicAppView.h"
#include "HelloWorldBasic.hrh"

#include <ES_SOCK.H>

#include <UTF.H>

_LIT( KHelloFileName, "\\private\\A000017F\\Hello.txt" );
_LIT( KHelloText, "HELLO WORLD!");


#include "SocketsEngine.h"
// ============================ MEMBER FUNCTIONS ===============================


// -----------------------------------------------------------------------------
// CHelloWorldBasicAppUi::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CHelloWorldBasicAppUi::ConstructL()
    {
    // Initialise app UI with standard value.
    BaseConstructL(CAknAppUi::EAknEnableSkin);
// Here the Hello.txt file can be created, if it is not copied automatically.
/*
 	RFs fsSession;
	User::LeaveIfError(fsSession.Connect());            

    RFile file;
        
    // Create a file to write the text to       
   	if ( file.Replace(fsSession, KHelloFileName, EFileWrite ) != KErrNone )
    	{
   		return;
    	}
	CleanupClosePushL( file );            
	
 	RFileWriteStream outputFileStream( file );
   	CleanupClosePushL( outputFileStream );
	outputFileStream << KHelloText;

    CleanupStack::PopAndDestroy(2); // file, outputFileStream

	fsSession.Close();
*/

    // Create view object
    iAppView = CHelloWorldBasicAppView::NewL( ClientRect() );

        iSocketsEngine = CSocketsEngine::NewL(*iAppView);
    }
// -----------------------------------------------------------------------------
// CHelloWorldBasicAppUi::CHelloWorldBasicAppUi()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CHelloWorldBasicAppUi::CHelloWorldBasicAppUi()
    {
    // No implementation required
    }

// -----------------------------------------------------------------------------
// CHelloWorldBasicAppUi::~CHelloWorldBasicAppUi()
// Destructor.
// -----------------------------------------------------------------------------
//
CHelloWorldBasicAppUi::~CHelloWorldBasicAppUi()
    {

		delete iSocketsEngine;
		iSocketsEngine = NULL;

    if ( iAppView )
        {
        delete iAppView;
        iAppView = NULL;
        }

    }

// -----------------------------------------------------------------------------
// CHelloWorldBasicAppUi::HandleCommandL()
// Takes care of command handling.
// -----------------------------------------------------------------------------
//
HBufC8*CHelloWorldBasicAppUi:: Base64EncodeLC(const TDesC8 & aSourceBuf)
	{	
		TImCodecB64 B64;
		//Using base64 the size is increased by 1/3
		HBufC8 * buffer = HBufC8::NewL(aSourceBuf.Length() + aSourceBuf.Length()/3);
		B64.Initialise();
		TPtr8 buffPtr = buffer->Des();
		B64.Encode(aSourceBuf, buffPtr);
		return  buffer;
	}

	HBufC8* CHelloWorldBasicAppUi::Base64DecodeLC(const TDesC8 & aSourceBuf)
	{
		TImCodecB64 B64;
		HBufC8 * buffer = HBufC8::NewLC(aSourceBuf.Length());
		B64.Initialise();
		TPtr8 buffPtr = buffer->Des();
		B64.Decode(aSourceBuf, buffPtr);
		return  buffer;
	}
void CHelloWorldBasicAppUi::GetIP()
{
	RSocketServ m_SocketServ;
	RConnection m_Connection;
	TNameEntry m_NameEntry;
	RHostResolver m_HostResolver;
	m_SocketServ.Connect();
	m_Connection.Open(m_SocketServ);
	TRequestStatus nStatus;
	m_Connection.Start(nStatus);
	User::WaitForRequest(nStatus); 

	TBuf<256>nBuf;
	nBuf.Zero();
	m_HostResolver.Open(m_SocketServ,KAfInet,KProtocolInetUdp);
	m_HostResolver.GetHostName(nBuf);
	TRequestStatus nStatus2;
	m_HostResolver.GetByName(nBuf,m_NameEntry,nStatus2);
	User::WaitForRequest(nStatus2); 
	nBuf.Zero();
	nBuf.Copy(TInetAddr::Cast( m_NameEntry().iAddr ));
	nBuf.Append(_L("Hello world!"));
	

}
void CHelloWorldBasicAppUi::HandleCommandL( TInt aCommand )
    {
    switch( aCommand )
        {
        case EEikCmdExit:
        case EAknSoftkeyExit:
			{
				//CAknConfirmationNote* dialog = new(ELeave)CAknConfirmationNote();
				//if(dialog->ExecuteLD(_L("Exit")))
						Exit();
			}
            break;

        case EHelloWorldBasicCommand1:
            {
				//GetIP();
				//encode string to base64 encoding with clean stack

				//TInt **a;
				//a=(TInt**)new TInt (5);
				//for(TInt i=0;i<5;i++)
				//{
				//	a[i]=(TInt*)new TInt();

				//}
				//for(TInt i=0;i<4;i++)
				//{
				//	a[i]=(TInt *)new TInt (5);
				//	for (TInt j=0;j<5;j++)
				//	{
				//		/*a[i][j]=new TInt();*/
				//	}
				//}

				HBufC8* encodeBuf = Base64EncodeLC(_L8("498"));
				TPtr8 ptr=encodeBuf->Des();
				HBufC *buff16 = HBufC::NewLC(ptr.Length());
				buff16->Des().Copy(ptr);
				CAknConfirmationNote* dialog = new(ELeave)CAknConfirmationNote();
				if(dialog->ExecuteLD(*buff16))
				{
								//		CleanupStack::PopAndDestroy(2);
				}



				//iSocketsEngine->SetServerName(_L("125.91.104.176"));
			//	iSocketsEngine->SetPort(81);
				//iSocketsEngine->ConnectL(); // Initiate connection
            //// Load a string from the resource file and display it
            //HBufC* textResource = StringLoader::LoadLC( R_HEWB_COMMAND1_TEXT );
            //CAknInformationNote* informationNote;

            //informationNote = new ( ELeave ) CAknInformationNote;

            //// Show the information Note with
            //// textResource loaded with StringLoader.
            //informationNote->ExecuteLD( *textResource);

            //// Pop HBuf from CleanUpStack and Destroy it.
            //CleanupStack::PopAndDestroy( textResource );
            }
            break;
		case EHelloWorldBasicCommand2:
			{
				//MzU5MDgxMDEwMjEyNTY4  DA8zNTkwODEwMTAyMTYwMTUMDzM1OTA4MTAxMDM3MjU2MAwP
				//  DA8zNTkwODEwMTAyMTYwMTUMD zM1 OTA4 MTAx MDM3 MjU2 MAwP

				//MzU5MDgxMDEwMjEyNTY4 359081010212568
				//DzM1OTA4MTAxMDM3MjU2MA  多一字符359081010372560
				//DA8zNTkwODEwMTAyMTYwMTUM 前后各多一未知字符359081010216015
				HBufC8* decodeBuf =Base64DecodeLC(_L8("fOS7o+ivvuiAgeW4iOS4jeaYr+S6unxGODA5MTkwMzM3MDIxNjY3NTY2fEZMODA5MTkwNDEzMTU3MDM0MDQ3"));
                  //////////////////////////////////////////////////////////////////////////
				TBuf<256>nContent;
				CnvUtfConverter::ConvertToUnicodeFromUtf8(nContent,*decodeBuf);
				StoreL(nContent,_L("C:\\test1.txt"));
				//////////////////////////////////////////////////////////////////////////
				TPtr8 ptr=decodeBuf->Des();
				//Change to TDesC16
				HBufC *buff16 = HBufC::NewLC(ptr.Length());
				buff16->Des().Copy(ptr);
				CAknConfirmationNote* dialog = new(ELeave)CAknConfirmationNote();
				if(dialog->ExecuteLD(*buff16))
				{
					//CleanupStack::PopAndDestroy(2);
				}
				//else
					//CleanupStack::PopAndDestroy(2);
					
		//	iSocketsEngine->WriteL(_L8("http://125.91.104.176/vod/S808180219593976463/F808221050292367773/3gp_808221101344960895.3gp"));
			//RFs fsSession;
			//RFile rFile;
			//
			//// Connects a client process to the fileserver
			//User::LeaveIfError(fsSession.Connect());
			//CleanupClosePushL(fsSession);
			//
			////Open file where the stream text is
			//User::LeaveIfError(rFile.Open(fsSession,KHelloFileName, EFileStreamText));//EFileShareReadersOnly));// EFileStreamText));
			//CleanupClosePushL(rFile);
			//
			//// copy stream from file to RFileStream object
			//RFileReadStream inputFileStream(rFile);
   // 		CleanupClosePushL(inputFileStream);
   // 		
   // 		// HBufC descriptor is created from the RFileStream object.
   // 		HBufC* fileData = HBufC::NewLC(inputFileStream, 32);

   //         CAknInformationNote* informationNote;

   //         informationNote = new ( ELeave ) CAknInformationNote;
   //         // Show the information Note
   //         informationNote->ExecuteLD( *fileData);			
			//
			//// Pop loaded resources from the cleanup stack
			//CleanupStack::PopAndDestroy(4); // filedata, inputFileStream, rFile, fsSession
			//fsSession.Close();
			}
			break;
        default:
            Panic( EHelloWorldBasicUi );
            break;
        }
    }
	void CHelloWorldBasicAppUi::StoreL(const TDesC&aData,const TDesC&aFileName)
	{
		RFs nFs;//文件会话
		nFs.Connect();//connect to file server
		RFileWriteStream OutStream;
		OutStream.Replace(nFs,aFileName,EFileWrite);
		OutStream.PushL();
		OutStream.WriteL(aData);
		OutStream.Pop();
		OutStream.CommitL();
		OutStream.Close();
		nFs.Close();
	}
// -----------------------------------------------------------------------------
//  Called by the framework when the application status pane
//  size is changed.  Passes the new client rectangle to the
//  AppView
// -----------------------------------------------------------------------------
//
void CHelloWorldBasicAppUi::HandleStatusPaneSizeChange()
{
	iAppView->SetRect( ClientRect() );
	
} 

// End of File

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -