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

📄 dbhandler.cpp

📁 用于symbian手机的词典工具.绝对有用。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		i++;
	}
    return iActDBInt;
}


void CDBHandler::SetActDBInt(TInt i)
{
	if( i >=0 )
	{
		TPtr aAddress( iActDB->Des() );
		aAddress = iDicList->MdcaPoint(i);
		iActDBInt = i;
		DicSelected = ETrue;
	}
	else
	{ DicSelected = EFalse; }
}


void CDBHandler::SetActDB(HBufC* db)
{
	if( BaflUtils::FileExists(iFsSession, db->Des()) != EFalse )
	{
		TPtr aAddress( iActDB->Des() );
		aAddress = db->Des();
		DicSelected = ETrue;
	}
	else
	{ DicSelected = EFalse; }
}


void CDBHandler::SearchingDicL()
{
	//Searching the dictionary files
	TBuf<KDicPathLength> path;
	TBuf<KDicPathLength> tmp;
	TBuf<KDicPathLength> tmp2;

	CDesCArray* aDriveList = new (ELeave) CDesCArrayFlat(DRIVELIST_MAX_COUNT);
	CleanupStack::PushL(aDriveList);
	BaflUtils::UpdateDiskListL(iFsSession, *aDriveList, EFalse, EDriveC);

	for( TInt i=0; i<aDriveList->MdcaCount(); i++ )
	{
		path = aDriveList->MdcaPoint(i);
		path.Append(_L(":"));
		path.Append(KDBDirPath);

		if( BaflUtils::FolderExists(iFsSession, path) != EFalse )
		{
			CDir* aDirList;
			path.Append( FILEFILTER );
			iFsSession.GetDir(path, KEntryAttNormal, ESortByName, aDirList);
			for( TInt j=0; j<aDirList->Count(); j++ )
			{
				tmp2 = path;
				tmp2.Delete(path.Length()-FILEFILTERLENGTH, FILEFILTERLENGTH);
				tmp = tmp2;
				tmp.Append( (*aDirList)[j].iName );
				iDicList->AppendL( tmp );
			}
			delete aDirList;
		}
	}

	CleanupStack::Pop();
	delete aDriveList;

	if( iDicList->MdcaCount() == 0 )
	{
		DicExist = EFalse;
	}
	else
	{
		DicExist = ETrue;
	}
}



void CDBHandler::SetFormattedDicListL()
{
	TBuf<KDicPathLength> tmp1, tmp2;
	TInt v;
	iFormattedDicList->Reset();
	TPtr aAddress( iLine->Des() );

	for(TInt i=0; i<iDicList->Count(); i++)
	{
		tmp1 = iDicList->MdcaPoint(i);
		v = tmp1.Find(_L("-"));
		tmp1 = tmp1.Mid(v+1, 4);
		tmp2 = tmp1.Right(2);
		tmp1 = tmp1.Left(2);

		aAddress = tmp1;
		aAddress = iLang->GetLanguage( iLine )->Des();
		tmp1 = iLine->Des();
		tmp1.Append(_L("-"));
		aAddress = tmp2;
		aAddress = iLang->GetLanguage( iLine )->Des();
		tmp2 = iLine->Des();

		tmp1.Append(tmp2);
		iFormattedDicList->AppendL( tmp1 );
	}
}



void CDBHandler::ListSelectL()
{
	//Select world list into iSelectList 
	//and filter it with aFilter
	//from dictionay database
	// aLang = 0,1
	iSelectList->Reset();
	OpenDbL();
	CleanupClosePushL(iDicDB);

	//Getting the table name
	//Getting table name
	TBuf<1> aLetter;
	aLetter = iSearchWord->Left(1);
	aLetter.Collate();

	TBuf<KSqlStringLength> sql;
	sql = _L("select * from ");
	if( iSearchLang == 0 )
	{ sql.Append( KLetters1Table ); }
	else
	{ sql.Append( KLetters2Table ); }
	sql.Append( _L(" where ") );
	if( iSearchLang == 0 )
	{ sql.Append(KLetters1TableLetterCol); }
	else
	{ sql.Append(KLetters2TableLetterCol); }	
	sql.Append( _L(" = ") );
	sql.Append( _L("'") );
	sql.Append( aLetter );
	sql.Append( _L("'") );

	User::LeaveIfError( iView.Prepare(iDicDB, TDbQuery(sql, EDbCompareCollated)) );
	CleanupClosePushL(iView);
	User::LeaveIfError( iView.EvaluateAll() );

	if( iView.IsEmptyL() == EFalse )
	{
		iView.FirstL();
		iView.GetL();

		CDbColSet* colSet = iView.ColSetL();
	    CleanupStack::PushL(colSet);
		TBuf<KWordMaxLength> table;
		if( iSearchLang == 0 )
		{ table = iView.ColDes( colSet->ColNo(KLetters1TableNameCol) ); }
		else
		{ table = iView.ColDes( colSet->ColNo(KLetters2TableNameCol) ); }
		CleanupStack::PopAndDestroy(colSet);
		CleanupStack::PopAndDestroy();	//iView

		//Selecting the words
		if( iSearchLang == 0 )
		{
			sql = _L("select ");
			sql.Append( KLangTableWordCol );
			sql.Append( _L(" from ") );
			sql.Append( table );
			if( iSearchWord->Length() > 0 )
			{
				sql.Append( _L(" where ") );
				sql.Append( KLangTableWordCol );
				sql.Append( _L(" like '") );
				sql.Append( iSearchWord->Des() );
				sql.Append( _L("*'") );
			}
		}
		else
		{
			sql = _L("select ");
			sql.Append( KLangTableWordCol );
			sql.Append( _L(" from ") );
			sql.Append( table );
			if( iSearchWord->Length() > 0 )
			{
				sql.Append( _L(" where ") );
				sql.Append( KLangTableWordCol );
				sql.Append( _L(" like '") );
				sql.Append( iSearchWord->Des() );
				sql.Append( _L("*'") );
			}
		}

//		TDbWindow aWindow(0,50);
//		TDbWindow aWindow(TDbWindow::EUnlimited);
		User::LeaveIfError( 
			iView.Prepare(iDicDB, TDbQuery(sql, EDbCompareCollated)) );
		CleanupClosePushL(iView);
		colSet = iView.ColSetL();
	    CleanupStack::PushL(colSet);

		User::LeaveIfError( iView.EvaluateAll() );
		TDbColNo colNox = colSet->ColNo(KLangTableWordCol);
		while( iView.NextL() )
		{		
			iView.GetL();
			iSelectList->AppendL( iView.ColDes(colNox) );
		}
		//SQL order by select not pretty fast
		iSelectList->Sort();
		iSelectList->Compress();

	    CleanupStack::PopAndDestroy(colSet);
	}

	CleanupStack::PopAndDestroy();		// iView
	CleanupStack::Pop();				// iDicDB
	CloseDb();

	iWorking = EFalse;
}




void CDBHandler::SearchSelectL()
{
	//Select the result from DB and load into iSelectList
	// Type == 0 -> search,
	// Type == 1 -> exact search,
	// Lang == 0 -> Lang1, 
	// Lang == 1 -> Lang2

	OpenDbL();
	CleanupClosePushL(iDicDB);

	TBuf<KSqlStringLength> sql;
	sql.Append( _L("select * ") );
	sql.Append( _L("from ") );
	sql.Append( KDicTable );
	sql.Append( _L(" where ") );
	if( iSearchType == 0 )
	{
		sql.Append( KDicTableLangsCol );
		sql.Append( _L(" like '*") );
		sql.Append( iSearchWord->Des() );
		sql.Append( _L("*' ") );
	}
	else
	{
		//at the begin of line
		sql.Append( KDicTableLangsCol );
		sql.Append( _L(" like '") );
		sql.Append(iSearchWord->Des());
		sql.Append( _L(" *' ") );
		sql.Append( _L(" or ") );
		//at the end of line
		sql.Append( KDicTableLangsCol );
		sql.Append( _L(" like '* ") );
		sql.Append(iSearchWord->Des());
		sql.Append( _L("' ") );
		sql.Append( _L(" or ") );
		//before the delimiter
		sql.Append( KDicTableLangsCol );
		sql.Append( _L(" like '* ") );
		sql.Append(iSearchWord->Des());
		sql.Append(KSeparator);
		sql.Append( _L("*' ") );
		sql.Append( _L(" or ") );
		//before the delimiter and only this word
		sql.Append( KDicTableLangsCol );
		sql.Append( _L(" like '") );
		sql.Append(iSearchWord->Des());
		sql.Append(KSeparator);
		sql.Append( _L("*' ") );
		sql.Append( _L(" or ") );
		//after the delimiter
		sql.Append( KDicTableLangsCol );
		sql.Append( _L(" like '*") );
		sql.Append(KSeparator);
		sql.Append(iSearchWord->Des());
		sql.Append( _L(" *' ") );
		sql.Append( _L(" or ") );
		//after the delimiter and only this word
		sql.Append( KDicTableLangsCol );
		sql.Append( _L(" like '*") );
		sql.Append(KSeparator);
		sql.Append(iSearchWord->Des());
		sql.Append( _L("' ") );
		sql.Append( _L(" or ") );
		//after the word there is .
		sql.Append( KDicTableLangsCol );
		sql.Append( _L(" like '*") );
		sql.Append(iSearchWord->Des());
		sql.Append( _L(".*'") );
		sql.Append( _L(" or ") );
		//after the word there is !
		sql.Append( KDicTableLangsCol );
		sql.Append( _L(" like '*") );
		sql.Append(iSearchWord->Des());
		sql.Append( _L("!*'") );
		sql.Append( _L(" or ") );
		//after the word there is ?
		sql.Append( KDicTableLangsCol );
		sql.Append( _L(" like '*") );
		sql.Append(iSearchWord->Des());
		sql.Append( _L("{?}*'") );
		sql.Append( _L(" or ") );
		//beetwean the words
		sql.Append( KDicTableLangsCol );
		sql.Append( _L(" like ' ") );
		sql.Append(iSearchWord->Des());
		sql.Append( _L(" '") );
	}

//	TDbWindow aWindow(0,50);
//	TDbWindow aWindow(TDbWindow::EUnlimited);
	User::LeaveIfError( iView.Prepare(iDicDB, TDbQuery(sql)) );

	CleanupClosePushL(iView);
    CDbColSet* colSet = iView.ColSetL();
    CleanupStack::PushL(colSet);

	User::LeaveIfError( iView.EvaluateAll() );
	TDbColNo colNo1 = colSet->ColNo(KDicTableLangsCol);
	iResultList->Reset();
	while( (iView.NextL()) && (iResultList->Count() <= RESULT_ARRAY_LENGTH) )
	{		
		iView.GetL();
		iResultList->AppendL( iView.ColDes(colNo1) );
	}

    CleanupStack::PopAndDestroy(colSet);
	CleanupStack::PopAndDestroy();		// iView
	CleanupStack::Pop();				// iDicDB
	CloseDb();

	//Cleaning up the result
	TBuf<K2LangMaxLength> tmp;
	TBuf<KLangMaxLength> tmpLeft;
	TBuf<KLangMaxLength> tmpRight;
	if( iResultList->Count() > 0 )
	{
		if( iSearchLang == 0 )
		{
			TInt i = 0;
			TInt delim;
			while( i<iResultList->Count() )
			{
				tmp = iResultList->MdcaPoint(i);
				delim = tmp.Find(KSeparator);
				tmpLeft = tmp.Left( delim );
				if( tmpLeft.Find(iSearchWord->Des()) == KErrNotFound )
				{
					iResultList->Delete(i);
					i--;
				}
				i++;
			}
		}
		else
		{
			TInt i = 0;
			TInt delim;
			while( i<iResultList->Count() )
			{
				tmp = iResultList->MdcaPoint(i);
				delim = tmp.Find(KSeparator);
				tmpRight = tmp.Right( tmp.Length() - delim - 1 );
				if( tmpRight.Find(iSearchWord->Des()) == KErrNotFound )
				{
					iResultList->Delete(i);
					i--;
				}
				i++;
			}
		}
	}
	iResultList->Compress();
	//SQL order by select not pretty fast
	iWorking = EFalse;
}



void CDBHandler::SetParameters(HBufC* aWord, TInt aLang, TInt aType, TInt aSelectType)
{
	TPtr aAddress( iSearchWord->Des() );
	aAddress = aWord->Des();
	iSearchLang = aLang;
	iSearchType = aType;
	iSearchSelectType = aSelectType;

	iWorking = ETrue;
}



//MAknBackgroundProcess
void CDBHandler::StepL()
{
	if( iSearchSelectType == 0 )
	{
		ListSelectL();
	}
	else
	{
		SearchSelectL();
	}
}


//MAknBackgroundProcess
TBool CDBHandler::IsProcessDone() const
{
	if( iWorking == EFalse )
	{
		return ETrue;
	}
	return EFalse;
}


//MAknBackgroundProcess
void CDBHandler::ProcessFinished()
{
	// no implementation required
}

//MAknBackgroundProcess
void CDBHandler::DialogDismissedL(TInt)
{
	// no implementation required
}

//MAknBackgroundProcess
TInt CDBHandler::CycleError(TInt aError)
{
	return aError;
}


⌨️ 快捷键说明

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