📄 dbhandler.cpp
字号:
/*
* MDictionary - dictionary program for Symbian cellular phones
*
* Copyright (C) 2005 Egyeki Gergely
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <bautils.h> // file helpers
#include <s32file.h> // for opening a file
#include <eikenv.h>
#include "MDictionary.hrh"
#include "DBHandler.h"
#include "languages.h"
_LIT(KSeparator, "|");
_LIT(FILEFILTER, "mdic*");
CDBHandler::CDBHandler()
{
DicExist = EFalse;
DicSelected = EFalse;
iOpen = EFalse;
iSearchLang = 0;
iSearchType = 0;
iSearchSelectType = 0;
iWorking = EFalse;
}
CDBHandler::~CDBHandler()
{
delete iLine;
iLine = NULL;
delete iSearchWord;
iSearchWord = NULL;
delete iActDB;
iActDB = NULL;
delete iDicLang1;
iDicLang1 = NULL;
delete iDicLang2;
iDicLang2 = NULL;
delete iDicFont1;
iDicFont1 = NULL;
delete iDicFont2;
iDicFont2 = NULL;
delete iFLetterLang1;
iFLetterLang1 = NULL;
delete iFLetterLang2;
iFLetterLang2 = NULL;
delete iDicTitle1;
iDicTitle1 = NULL;
delete iDicTitle2;
iDicTitle2 = NULL;
delete iDicAuthors;
iDicAuthors = NULL;
delete iDicVersion;
iDicVersion = NULL;
delete iDicList;
iDicList = NULL;
delete iFormattedDicList;
iFormattedDicList = NULL;
delete iSelectList;
iSelectList = NULL;
delete iResultList;
iResultList = NULL;
delete iLang;
iLang = NULL;
iDicDB.Close();
iReader.Close();
iView.Close();
iFsSession.Close();
}
CDBHandler* CDBHandler::NewL()
{
CDBHandler* tmp = new (ELeave)CDBHandler();
CleanupStack::PushL( tmp );
tmp->ConstructL();
CleanupStack::Pop();
return tmp;
}
void CDBHandler::ConstructL()
{
User::LeaveIfError( iFsSession.Connect() );
iLine = HBufC::NewL(K2LangMaxLength);
iSearchWord = HBufC::NewL(KWordMaxLength);
iActDB = HBufC::NewL(KDicPathLength);
iDicLang1 = HBufC::NewL(KWordMaxLength);
iDicLang2 = HBufC::NewL(KWordMaxLength);
iDicFont1 = HBufC::NewL(KWordMaxLength);
iDicFont2 = HBufC::NewL(KWordMaxLength);
iFLetterLang1 = HBufC::NewL(1);
iFLetterLang2 = HBufC::NewL(1);
iDicTitle1 = HBufC::NewL(KWordMaxLength);
iDicTitle2 = HBufC::NewL(KWordMaxLength);
iDicAuthors = HBufC::NewL(KLangMaxLength);
iDicVersion = HBufC::NewL(KWordMaxLength);
TBuf<KDicPathLength> tmp = _L("c:\\system\\data\\init-IIII.III");
TPtr aAddress( iActDB->Des() );
aAddress = tmp;
// The Dic files list
iDicList = NULL;
iDicList = new (ELeave) CDesC16ArraySeg(DICLIST_ARRAY_LENGTH);
iFormattedDicList = NULL;
iFormattedDicList = new (ELeave) CDesC16ArraySeg(DICLIST_ARRAY_LENGTH);
iSelectList = NULL;
iSelectList = new (ELeave) CDesC16ArraySeg(LIST_ARRAY_LENGTH);
iResultList = NULL;
iResultList = new (ELeave) CDesC16ArraySeg(RESULT_ARRAY_LENGTH);
iLang = NULL;
iLang = CLanguages::NewL();
//Checking the installed dictionaries
SearchingDicL();
SetFormattedDicListL();
}
TInt CDBHandler::OpenDbL()
{
iDicDB.Close();
if( ! BaflUtils::FileExists(iFsSession, GetActDB()->Des()) )
{
return KErrNotFound;
}
User::LeaveIfError( iDicDB.Open(iFsSession, GetActDB()->Des()) );
iOpen = ETrue;
return KErrNone;
}
TInt CDBHandler::CloseDb()
{
iDicDB.Close();
iOpen = EFalse;
return KErrNone;
}
TBool CDBHandler::IsOpen() const
{
return iOpen;
}
HBufC* CDBHandler::GetDBTitle1L()
{
//reading from dictionay database
OpenDbL();
CleanupClosePushL(iDicDB);
TBuf<KSqlStringLength> sql;
sql.Append( _L("select ") );
sql.Append( KSysTableTitle1Col );
sql.Append( _L(" from ") );
sql.Append( KSysTable );
User::LeaveIfError( iView.Prepare(iDicDB, TDbQuery(sql)) );
CleanupClosePushL(iView);
User::LeaveIfError( iView.EvaluateAll() );
CDbColSet* colSet = iView.ColSetL();
CleanupStack::PushL(colSet);
iView.FirstL();
iView.GetL();
TPtr aAddress( iDicLang1->Des() );
aAddress = iView.ColDes( colSet->ColNo(KSysTableTitle1Col) );
CleanupStack::PopAndDestroy(colSet);
CleanupStack::PopAndDestroy(); // iView
CleanupStack::Pop(); // iDicDB
CloseDb();
return iDicLang1;
}
HBufC* CDBHandler::GetDBTitle2L()
{
//reading from dictionay database
OpenDbL();
CleanupClosePushL(iDicDB);
TBuf<KSqlStringLength> sql;
sql.Append( _L("select ") );
sql.Append( KSysTableTitle2Col );
sql.Append( _L(" from ") );
sql.Append( KSysTable );
User::LeaveIfError( iView.Prepare(iDicDB, TDbQuery(sql)) );
CleanupClosePushL(iView);
User::LeaveIfError( iView.EvaluateAll() );
CDbColSet* colSet = iView.ColSetL();
CleanupStack::PushL(colSet);
iView.FirstL();
iView.GetL();
TPtr aAddress( iDicLang2->Des() );
aAddress = iView.ColDes( colSet->ColNo(KSysTableTitle2Col) );
CleanupStack::PopAndDestroy(colSet);
CleanupStack::PopAndDestroy(); // iView
CleanupStack::Pop(); // iDicDB
CloseDb();
return iDicLang2;
}
HBufC* CDBHandler::GetFLetter1L()
{
//reading from dictionay database
OpenDbL();
CleanupClosePushL(iDicDB);
TBuf<KSqlStringLength> sql;
sql.Append( _L("select ") );
sql.Append( KSysTableFLetter1 );
sql.Append( _L(" from ") );
sql.Append( KSysTable );
User::LeaveIfError( iView.Prepare(iDicDB, TDbQuery(sql)) );
CleanupClosePushL(iView);
User::LeaveIfError( iView.EvaluateAll() );
CDbColSet* colSet = iView.ColSetL();
CleanupStack::PushL(colSet);
iView.FirstL();
iView.GetL();
TPtr aAddress( iFLetterLang1->Des() );
aAddress = iView.ColDes( colSet->ColNo(KSysTableFLetter1) );
CleanupStack::PopAndDestroy(colSet);
CleanupStack::PopAndDestroy(); // iView
CleanupStack::Pop(); // iDicDB
CloseDb();
return iFLetterLang1;
}
HBufC* CDBHandler::GetFLetter2L()
{
//reading from dictionay database
OpenDbL();
CleanupClosePushL(iDicDB);
TBuf<KSqlStringLength> sql;
sql.Append( _L("select ") );
sql.Append( KSysTableFLetter2 );
sql.Append( _L(" from ") );
sql.Append( KSysTable );
User::LeaveIfError( iView.Prepare(iDicDB, TDbQuery(sql)) );
CleanupClosePushL(iView);
User::LeaveIfError( iView.EvaluateAll() );
CDbColSet* colSet = iView.ColSetL();
CleanupStack::PushL(colSet);
iView.FirstL();
iView.GetL();
TPtr aAddress( iFLetterLang2->Des() );
aAddress = iView.ColDes( colSet->ColNo(KSysTableFLetter2) );
CleanupStack::PopAndDestroy(colSet);
CleanupStack::PopAndDestroy(); // iView
CleanupStack::Pop(); // iDicDB
CloseDb();
return iFLetterLang2;
}
HBufC* CDBHandler::GetFont1L()
{
//reading from dictionay database
OpenDbL();
CleanupClosePushL(iDicDB);
TBuf<KSqlStringLength> sql;
sql.Append( _L("select ") );
sql.Append( KSysTableFont1 );
sql.Append( _L(" from ") );
sql.Append( KSysTable );
User::LeaveIfError( iView.Prepare(iDicDB, TDbQuery(sql)) );
CleanupClosePushL(iView);
User::LeaveIfError( iView.EvaluateAll() );
CDbColSet* colSet = iView.ColSetL();
CleanupStack::PushL(colSet);
iView.FirstL();
iView.GetL();
TPtr aAddress( iDicFont1->Des() );
aAddress = iView.ColDes( colSet->ColNo(KSysTableFont1) );
CleanupStack::PopAndDestroy(colSet);
CleanupStack::PopAndDestroy(); // iView
CleanupStack::Pop(); // iDicDB
CloseDb();
return iDicFont1;
}
HBufC* CDBHandler::GetDicTitle1L()
{
//reading from dictionay database
OpenDbL();
CleanupClosePushL(iDicDB);
TBuf<KSqlStringLength> sql;
sql.Append( _L("select ") );
sql.Append( KSysTableLangsCol );
sql.Append( _L(" from ") );
sql.Append( KSysTable );
User::LeaveIfError( iView.Prepare(iDicDB, TDbQuery(sql)) );
CleanupClosePushL(iView);
User::LeaveIfError( iView.EvaluateAll() );
CDbColSet* colSet = iView.ColSetL();
CleanupStack::PushL(colSet);
iView.FirstL();
iView.GetL();
TPtr aAddress( iDicTitle1->Des() );
aAddress = iView.ColDes( colSet->ColNo(KSysTableLangsCol) );
TInt pos = iDicTitle1->Find( _L(",") );
aAddress = iDicTitle1->Left(pos);
aAddress = iLang->GetLanguage(iDicTitle1)->Des();
CleanupStack::PopAndDestroy(colSet);
CleanupStack::PopAndDestroy(); // iView
CleanupStack::Pop(); // iDicDB
CloseDb();
return iDicTitle1;
}
HBufC* CDBHandler::GetDicTitle2L()
{
//reading from dictionay database
OpenDbL();
CleanupClosePushL(iDicDB);
TBuf<KSqlStringLength> sql;
sql.Append( _L("select ") );
sql.Append( KSysTableLangsCol );
sql.Append( _L(" from ") );
sql.Append( KSysTable );
User::LeaveIfError( iView.Prepare(iDicDB, TDbQuery(sql)) );
CleanupClosePushL(iView);
User::LeaveIfError( iView.EvaluateAll() );
CDbColSet* colSet = iView.ColSetL();
CleanupStack::PushL(colSet);
iView.FirstL();
iView.GetL();
TPtr aAddress( iDicTitle2->Des() );
aAddress = iView.ColDes( colSet->ColNo(KSysTableLangsCol) );
TInt pos = iDicTitle2->Find( _L(",") );
aAddress = iDicTitle2->Mid(pos+1, iDicTitle2->Length()-pos-1);
aAddress = iLang->GetLanguage(iDicTitle2)->Des();
CleanupStack::PopAndDestroy(colSet);
CleanupStack::PopAndDestroy(); // iView
CleanupStack::Pop(); // iDicDB
CloseDb();
return iDicTitle2;
}
HBufC* CDBHandler::GetAuthorsL()
{
OpenDbL();
CleanupClosePushL(iDicDB);
TBuf<KSqlStringLength> sql;
sql.Append( _L("select ") );
sql.Append( KSysTableAuthorsCol );
sql.Append( _L(" from ") );
sql.Append( KSysTable );
User::LeaveIfError( iView.Prepare(iDicDB, TDbQuery(sql)) );
CleanupClosePushL(iView);
User::LeaveIfError( iView.EvaluateAll() );
CDbColSet* colSet = iView.ColSetL();
CleanupStack::PushL(colSet);
iView.FirstL();
iView.GetL();
TPtr aAddress( iDicAuthors->Des() );
aAddress = iView.ColDes( colSet->ColNo(KSysTableAuthorsCol) );
CleanupStack::PopAndDestroy(colSet);
CleanupStack::PopAndDestroy(); // iView
CleanupStack::Pop(); // iDicDB
CloseDb();
return iDicAuthors;
}
HBufC* CDBHandler::GetVersionL()
{
OpenDbL();
CleanupClosePushL(iDicDB);
TBuf<KSqlStringLength> sql;
sql.Append( _L("select ") );
sql.Append( KSysTableVersionCol );
sql.Append( _L(" from ") );
sql.Append( KSysTable );
User::LeaveIfError( iView.Prepare(iDicDB, TDbQuery(sql)) );
CleanupClosePushL(iView);
User::LeaveIfError( iView.EvaluateAll() );
CDbColSet* colSet = iView.ColSetL();
CleanupStack::PushL(colSet);
iView.FirstL();
iView.GetL();
TPtr aAddress( iDicVersion->Des() );
aAddress = iView.ColDes( colSet->ColNo(KSysTableVersionCol) );
CleanupStack::PopAndDestroy(colSet);
CleanupStack::PopAndDestroy(); // iView
CleanupStack::Pop(); // iDicDB
CloseDb();
return iDicVersion;
}
HBufC* CDBHandler::GetActDB()
{
return iActDB;
}
TInt CDBHandler::GetActDBInt()
{
TInt i = 0;
TBool ok = EFalse;
TBuf<KDicPathLength> tmp;
while( (i<iDicList->Count()) || (ok == EFalse) )
{
tmp = iDicList->MdcaPoint(i);
if( tmp.CompareC(iActDB->Des()) == 0 )
{
iActDBInt = i;
ok = ETrue;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -