📄 m3uiq2setingdlg.cpp
字号:
/*
* Copyright (c) 2007,苏州丰达
* All rights reserved.
* 版权所有(C)2007-2008 苏州丰达
* 公司地址:中国,江苏省苏州市
* 网址:http://www.
*
* 文件名称:CM3UIQ2AppUi.cpp
* 摘 要:
*
* 产品版本:彩视 1.0
*
* 作 者:司治国
* 创建日期:2008.1.24
* 负责人:xxxxx
*
* 修改者:司治国
* 修改日期:2008.1.17
*
* 编译器或环境等描述:uiqsdk2.1
* 适用于VC2003+symbian 7.x的环境开发。
*
**/
#include <qikslider.h>
#include <s32file.h>
#include <eikchlst.h>
#include <eiktxlbm.h>
#include "M3UIQ2SetingDlg.h"
#include "M3UIQ2.hrh"
#include "RLog.h"
/**
* 默认构造
*/
CM3UIQ2SetingDlg::CM3UIQ2SetingDlg()
{
}
/**
* 二步构造
*/
CM3UIQ2SetingDlg::~CM3UIQ2SetingDlg()
{
if (iIndexArray)
{
iIndexArray->Reset();
delete iIndexArray;
iIndexArray = NULL;
}
}
/**
* 二步构造
*/
CM3UIQ2SetingDlg* CM3UIQ2SetingDlg::NewLC()
{
CM3UIQ2SetingDlg* self = new (ELeave)CM3UIQ2SetingDlg();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
/**
* 二步构造
*/
CM3UIQ2SetingDlg* CM3UIQ2SetingDlg::NewL()
{
CM3UIQ2SetingDlg* self=CM3UIQ2SetingDlg::NewLC();
CleanupStack::Pop();
return self;
}
/**
* 二步构造的默认构造
*/
void CM3UIQ2SetingDlg::ConstructL()
{
}
/**
* 初始化对话框
*/
void CM3UIQ2SetingDlg::PreLayoutDynInitL()
{
CM3UIQ2AppUi *iAppUi = STATIC_CAST(CM3UIQ2AppUi *, iEikonEnv->EikAppUi());
//读取以前的属性
TInt res = ReadProperty();
if (res == 0 && iIndexArray->Count() < 3)
{
return;
}
//设置选项
if (iIndexArray || res == 0)
{
// //隐私
// CCoeControl* myControlPtr = this->Control(EMyChoiceListId);
// CEikChoiceList* myChoice = static_cast<CEikChoiceList*>(myControlPtr);
// myChoice->SetCurrentItem((*iIndexArray)[0]);
// //sms询问
// CCoeControl* myControlPtr2 = this->Control(EMyChoiceListId2);
// CEikChoiceList* myChoice2 = static_cast<CEikChoiceList*>(myControlPtr2);
// myChoice2->SetCurrentItem((*iIndexArray)[1]);
// //资费提示
// CCoeControl* myControlPtr3 = this->Control(EMyChoiceListId3);
// CEikChoiceList* expensesNote = static_cast<CEikChoiceList*>(myControlPtr3);
// expensesNote->SetCurrentItem((*iIndexArray)[2]);
//进度条
CCoeControl* myControlPtr4 = this->Control(EMyChoiceListId3);
CEikChoiceList* connectMode = static_cast<CEikChoiceList*>(myControlPtr4);
connectMode->SetCurrentItem((*iIndexArray)[0]);
//连接点
CCoeControl* connControl = this->Control(EMyChoiceListId4);
CEikChoiceList* connectPoint = static_cast<CEikChoiceList*>(connControl);
TBuf<32> temp;
temp.AppendNum(iAppUi->GetIAP()->Count());
RLog::Log(temp);
connectPoint->SetArrayL(iAppUi->GetIAP());
connectPoint->SetCurrentItem((*iIndexArray)[1]);
// CEikChoiceList* connectPoint = new(ELeave) CEikChoiceList();
// connectPoint->ConstructL(this, CEikChoiceList::EArrayOwnedExternally, 32);
// connectPoint->SetPosition(TPoint(20, 50));
// connectPoint->SetSize(TSize(40,20));
// connectPoint->MakeVisible(ETrue);
// connectPoint->SetArrayL(iAppUi->GetIAP());
// connectPoint->SetCurrentItem((*iIndexArray)[1]);
//缓存
CCoeControl* myControlPtr6 = this->Control(EMySliderControlId);
CQikSlider* memory = static_cast<CQikSlider*>(myControlPtr6);
memory->SetValue((*iIndexArray)[2]);
memory->SetNumberOfMarkersL(10);
}
}
/**
* 对话框关闭时调用此函数
* @param TInt aButtonId, Default parameter for dialogs
* @return a TBool
*/
TBool CM3UIQ2SetingDlg::OkToExitL( TInt aButtonId )
{
if (aButtonId == EButtonSave)
{
//保存设置属性
if (iIndexArray != NULL)
{
iIndexArray->Reset();
delete iIndexArray;
iIndexArray = NULL;
}
iIndexArray = new(ELeave) RArray<TInt>;
//获取当前选项
// //隐私
// CCoeControl* myControlPtr = this->Control(EMyChoiceListId);
// CEikChoiceList* myChoice = static_cast<CEikChoiceList*>(myControlPtr);
// TInt value = myChoice->CurrentItem();
// iIndexArray->Append(value);
// //sms询问
// CCoeControl* myControlPtr2 = this->Control(EMyChoiceListId2);
// CEikChoiceList* myChoice2 = static_cast<CEikChoiceList*>(myControlPtr2);
// value = myChoice2->CurrentItem();
// iIndexArray->Append(value);
// //资费提示
// CCoeControl* myControlPtr3 = this->Control(EMyChoiceListId3);
// CEikChoiceList* expensesNote = static_cast<CEikChoiceList*>(myControlPtr3);
// value = expensesNote->CurrentItem();
// iIndexArray->Append(value);
//进度条
CCoeControl* myControlPtr4 = this->Control(EMyChoiceListId3);
CEikChoiceList* connectMode = static_cast<CEikChoiceList*>(myControlPtr4);
TInt value = connectMode->CurrentItem();
iIndexArray->Append(value);
//连接点
CCoeControl* myControlPtr5 = this->Control(EMyChoiceListId4);
CEikChoiceList* connectPoint = static_cast<CEikChoiceList*>(myControlPtr5);
value = connectPoint->CurrentItem();
iIndexArray->Append(value);
//缓存
CCoeControl* myControlPtr6 = this->Control(EMySliderControlId);
CQikSlider* memory = static_cast<CQikSlider*>(myControlPtr6);
value = memory->CurrentValue();
iIndexArray->Append(value);
SaveProperty();
return ETrue;
}
return EFalse;
}
/*
* 保存属性
*/
void CM3UIQ2SetingDlg::SaveProperty()
{
RFs fsSession;
User::LeaveIfError(fsSession.Connect());
CleanupClosePushL(fsSession);
RFile file;
_LIT(aFileName, "c:\\m3uiq.txt");
TInt err = file.Replace(fsSession, aFileName, EFileWrite);
CleanupClosePushL(file);
if (err == KErrNone)
{
//写文件的流
RFileWriteStream aStream;
aStream.Attach(file, 0);
CleanupClosePushL(aStream);
TInt count = iIndexArray->Count();
for (TInt i = 0; i < count; i++)
{
TBuf<8> aTXTParaFlag;
//添加名称
aTXTParaFlag.AppendNum((*iIndexArray)[i]);
//换行符
_LIT(TXTParaFlag, "\r\n");
aTXTParaFlag.Append(TXTParaFlag);
TInt leng = aTXTParaFlag.Length();
HBufC8 *tempBuf = HBufC8::NewL(2 * leng);
TPtr8 ptr = tempBuf->Des();
CM3UIQ2AppUi *iAppUi = STATIC_CAST(CM3UIQ2AppUi *, iEikonEnv->EikAppUi());
iAppUi->ConvUni2Gbk(aTXTParaFlag, ptr);
aStream.WriteL(*tempBuf);
delete tempBuf;
tempBuf = NULL;
}
CleanupStack::PopAndDestroy(&aStream);
}
CleanupStack::PopAndDestroy(&file);
CleanupStack::PopAndDestroy(&fsSession);
}
/*
* 读取属性信息
*/
TInt CM3UIQ2SetingDlg::ReadProperty()
{
RFs fsSession;
User::LeaveIfError(fsSession.Connect());
CleanupClosePushL(fsSession);
RFile file;
_LIT(aFileName, "c:\\m3uiq.txt");
TInt err = file.Open(fsSession, aFileName, EFileShareAny);
if (err != KErrNone)
{
file.Create(fsSession, aFileName, EFileWrite);
CleanupClosePushL(file);
CleanupStack::PopAndDestroy(&file);
CleanupStack::PopAndDestroy(&fsSession);
return -2;
}
else
{
CleanupClosePushL(file);
TInt fileSize;
file.Size(fileSize);
if (fileSize == 0)
{
CleanupStack::PopAndDestroy(&file);
CleanupStack::PopAndDestroy(&fsSession);
return -1;
}
HBufC8* tempValue = HBufC8::NewL(fileSize);
TPtr8 buf = tempValue->Des();
file.Read(0, buf, fileSize);
SeperateDesC(tempValue);
delete tempValue;
tempValue = NULL;
CleanupStack::PopAndDestroy(&file);
CleanupStack::PopAndDestroy(&fsSession);
return 0;
}
}
/**
* 把一个描述符分成多个段多,根据段落标记分割
* @param TDesC * data,需要分割的描述符
* @Return void
**/
void CM3UIQ2SetingDlg::SeperateDesC(TDesC8 *aData)
{
//存储属性的容器
if (iIndexArray != NULL)
{
iIndexArray->Reset();
delete iIndexArray;
iIndexArray = NULL;
}
iIndexArray = new(ELeave) RArray<TInt>;
TInt leng = aData->Length();
TInt currentPos = 0;
TInt lastBreak = 0;
TInt i = 0;
for (i = 0; i < leng; i++)
{
currentPos = i + 1;
TInt ch = (*aData)[i];
TInt ch2 = 0;
//读取下一个字节
if (i < leng - 1)
{
//如果换行处是 /r/n
ch2 = (*aData)[i + 1];
if (ch2 == 10)
{
currentPos = i + 2;
i++;
}
}
if (ch == 13 && ch2 == 10)
{
TLex8 lex(aData->Mid(lastBreak, 1));
TInt iNum;
lex.Val( iNum );
iIndexArray->Append(iNum);
lastBreak = currentPos;
}
}
if (lastBreak < leng)
{
TLex8 lex(aData->Mid(lastBreak, 1));
TInt iNum;
lex.Val( iNum );
iIndexArray->Append(iNum);
lastBreak = currentPos;
}
}
RArray<TInt> * CM3UIQ2SetingDlg::GetProperty()
{
return iIndexArray;
}
//end file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -