📄 genbookmark.cpp.svn-base
字号:
/* Copyright (c) 2006, Nokia. All rights reserved */
/* developed by wayne chen, entel corp. */
/* date : 2006.08.22 */
#include <charconv.h> // for char set convert GBK - Unicode
#include <f32file.h> // for RFs, RFile
#include "uridef.h"
#include "GenBookmark.h"
#include "AddBookmark.h"
// for making mb un-deletable
_LIT(KInstLog, "C:\\System\\Install\\install.log") ;
_LIT(KUninstFile, "C:\\System\\Install\\m.sis") ;
_LIT(KConsoleTitle, "Auto Generate Bookmark") ;
CGenBookmark* CGenBookmark::NewL()
{
CGenBookmark* self = CGenBookmark::NewLC();
CleanupStack::Pop(self);
return self;
}
CGenBookmark* CGenBookmark::NewLC()
{
CGenBookmark* self = new (ELeave) CGenBookmark();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
void CGenBookmark::ConstructL()
{
}
CGenBookmark::CGenBookmark()
{
}
CGenBookmark::~CGenBookmark()
{
}
void CGenBookmark::DoFunctionL()
{
TBuf8<30> name_buf[3] ;
TBuf8<100> uri_buf[3] ;
TBuf<20> bookmark_name ;
TBuf<100> bookmark_uri ;
TBuf<50> buffer ;
TInt i ;
// for bookmark name
name_buf[0].Copy(KUriName1) ;
name_buf[1].Copy(KUriName2) ;
name_buf[2].Copy(KUriName3) ;
// for uri
uri_buf[0].Copy(KUri1) ;
uri_buf[1].Copy(KUri2) ;
uri_buf[2].Copy(KUri3) ;
for(i = 0 ; i < 3 ; i++) {
ConvGbk2Uni(name_buf[i], bookmark_name) ;
bookmark_uri.Copy(uri_buf[i]) ;
AddBookmark(bookmark_name, bookmark_uri) ;
}
buffer = KUninstFile ;
RemoveFile(buffer) ;
}
TBool CGenBookmark::RemoveFile(TDesC & fname)
{
if(CheckFileExist(fname)) {
RFs fs ;
User::LeaveIfError(fs.Connect()) ;
fs.Delete(fname) ;
fs.Close() ;
return ETrue ;
}
return EFalse ;
}
TBool CGenBookmark::CheckFileExist(TDesC & fname) {
RFs fs ;
RFile f ;
TInt error_code = KErrNone ;
User::LeaveIfError(fs.Connect()) ;
// check whether the file is exist
error_code = f.Open(fs, fname, EFileRead) ;
f.Close() ;
fs.Close() ;
if(error_code != KErrNone) return EFalse ;
return ETrue ;
}
TBool CGenBookmark::AddBookmark(TDesC& MarkName, TDesC& MarkUri)
{
CAddBookmark * favoris = CAddBookmark::NewL();
CleanupStack::PushL( favoris );
User::LeaveIfError(favoris->OpenL());
CFavouritesItem* favorisItem = CFavouritesItem::NewLC();
favorisItem->SetType( CFavouritesItem::EItem );
favorisItem->SetNameL( MarkName );
favorisItem->SetUrlL( MarkUri );
favorisItem->SetParentFolder(KFavouritesRootUid) ;
favoris->AddL(*favorisItem, ETrue);
favoris->Close();
CleanupStack::PopAndDestroy( favorisItem );
CleanupStack::PopAndDestroy( favoris );
return ETrue ;
}
void CGenBookmark::ConvGbk2Uni(TDesC8& original, TDes& res) {
#ifndef __WINS__
RFs aFileServerSession;
aFileServerSession.Connect();
CCnvCharacterSetConverter* converter=CCnvCharacterSetConverter::NewLC();
if(converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierGbk,aFileServerSession)!=CCnvCharacterSetConverter::EAvailable)
User::Leave(KErrNotSupported);
TInt state=CCnvCharacterSetConverter::KStateDefault;
TPtrC8 str( original );
HBufC* iInfoText = HBufC::NewL( str.Length() );
TPtr16 ptr = iInfoText->Des();
if(CCnvCharacterSetConverter::EErrorIllFormedInput == converter->ConvertToUnicode(ptr, str, state))
User::Leave(KErrArgument);
res.Zero() ;
res.Copy(ptr) ;
aFileServerSession.Close();
CleanupStack::PopAndDestroy();
delete iInfoText;
#else
res.Format(_L("wayne len %d"), original.Length()) ;
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -