📄 m3uiq2appui.cpp
字号:
/*
* Copyright (c) 2007,苏州丰达
* All rights reserved.
* 版权所有(C)2007-2008 苏州丰达
* 公司地址:中国,江苏省苏州市
* 网址:http://www.
*
* 文件名称:CM3UIQ2AppUi.cpp
* 摘 要:
*
* 产品版本:彩视 1.0
*
* 作 者:xxxx
* 创建日期:xxxxx
* 负责人:xxxxx
*
* 修改者:司治国
* 修改日期:2008.1.17
*
* 编译器或环境等描述:uiqsdk2.1
* 适用于VC2003+symbian 7.x的环境开发。
*
**/
#include <qikon.hrh>
#include <M3UIQ2.rsg>
#include <qikSendAs.h>
#include <QMappExtInterface.h>
#include <cntuifinddlg.h>
////
#include <commdb.h>
#include <AgentClient.h>
#include <cdbstore.h>
#include <cdbcols.h>
////
#include <txtetext.h>
#include <eikchlst.h>
#include <QikMediaFileFolderUtils.h>
#include "M3UIQ2App.h"
#include "M3UIQ2Appui.h"
#include "M3UIQ2AppView.h"
#include "M3UIQ2.hrh"
#include "RLog.h"
const TInt KMaxReqestLength = 1024;
/**
* 两段构造
**/
void CM3UIQ2AppUi::ConstructL()
{
BaseConstructL();
//ReadIniFile();
//用户信息结构
iCurUser = new(ELeave) TUserStruct;
iCurUser->isLogon = EFalse;
// iCurUser->iNick.SetLength(0);
iCurUser->iName.Copy(_L("keper"));
iCurUser->iPassword.SetLength(0);
//主视图
iAppView = new (ELeave) CM3UIQ2AppView(iCurUser, this);
iAppView->ConstructL(ClientRect());
AddToStackL(*iAppView, iAppView);
RegisterViewL(*iAppView);
//手机空间view
iStorageView = CMobileStorageView::NewL(ClientRect());
AddToStackL(*iStorageView, iStorageView);
RegisterViewL(*iStorageView);
RLog::Log(_L("appui 75"));
//发送视图
iSendView = CM3UIQSendView::NewL(ClientRect(), NULL);
AddToStackL(*iSendView, iSendView);
RegisterViewL(*iSendView);
//设置默认视图
SetDefaultViewL(*iAppView);
//call exist iap
CCommsDatabase* CommDb = CCommsDatabase::NewL(EDatabaseTypeIAP);
CleanupStack::PushL(CommDb);
CCommsDbTableView* tableIAP = CommDb->OpenTableLC(TPtrC(IAP));
if (tableIAP->GotoFirstRecord()==KErrNone)
{
do
{
TUint32 uid(0);
tableIAP->ReadUintL(TPtrC(COMMDB_ID),uid);
TBuf<256> name;
tableIAP->ReadTextL(TPtrC(COMMDB_NAME),name);
descflat = new (ELeave) CDesCArrayFlat(4);
descflat->AppendL(name);
TBuf<32> cmwap;
cmwap.Append(_L("cmwap"));
name.Trim();
if (name.Compare(cmwap) == 0)
{
CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref;
//pref.iRanking = 1;
pref.iDirection = ECommDbConnectionDirectionOutgoing;
pref.iDialogPref = ECommDbDialogPrefDoNotPrompt;
pref.iBearer.iBearerSet = ECommDbBearerGPRS;
pref.iBearer.iIapId = uid;
break;
}
//CStoreableOverrideSettings* cs = CStoreableOverrideSettings::NewL(CStoreableOverrideSettings::EParamListFull);
//cs->SetConnectionPreferenceOverride(pref);
//RGenericAgent m_connMgr;
//m_connMgr.Open();
//TRequestStatus istatus;
//m_connMgr.StartOutgoing(*cs,istatus);
}
while(tableIAP->GotoNextRecord() == KErrNone);
}
CleanupStack::PopAndDestroy(tableIAP);
CleanupStack::PopAndDestroy(CommDb);
//上传文件核心类
iUserUID = ReadUserUID();
TInt UID = (iUserUID < 0) ? 0: iUserUID;
iHttpEngine = CHTTPClientEngine::NewL(*this);
iHttpEngine->LunachRegister(UID);
iCurrentAction = CHTTPClientEngine::ERegister;
//消息发送引擎
iMessageEngline = CMessageEngine::NewL(iAppView);
CM3UIQ2SetingDlg* iSetdialog = CM3UIQ2SetingDlg::NewL();
iSetdialog->ReadProperty();
RArray<TInt> *array = iSetdialog->GetProperty();
if (array && array->Count() >= 3)
{
iIsShow = (*array)[0];
iCatche = (*array)[2];
}
delete iSetdialog;
iSetdialog = NULL;
}
/**
* 析构函数,释放内存
**/
CM3UIQ2AppUi::~CM3UIQ2AppUi()
{
delete iCurUser;
if (iHttpEngine)
{
delete iHttpEngine;
iHttpEngine = NULL;
}
if (iMessageEngline)
{
delete iMessageEngline;
iMessageEngline = NULL;
}
if (iAppView)
{
RemoveFromStack(iAppView);
delete iAppView;
}
if (iStorageView)
{
RemoveFromStack(iStorageView);
delete iStorageView;
}
if (iSendView)
{
RemoveFromStack(iSendView);
delete iSendView;
}
if (iSPID)
{
delete iSPID;
iSPID = NULL;
}
if (iSMSContent)
{
delete iSMSContent;
iSMSContent = NULL;
}
if (iServerURL)
{
delete iServerURL;
iServerURL = NULL;
}
if (dialog)
{
delete dialog;
dialog = NULL;
}
}
TKeyResponse CM3UIQ2AppUi::HandleKeyEventL(const TKeyEvent& /*aKeyEvent*/, TEventCode /*aType*/)
{
return EKeyWasNotConsumed;
}
/**
* 菜单事件
* @param aCommand 菜单命令
**/
void CM3UIQ2AppUi::HandleCommandL(TInt aCommand)
{
// if (!iIsLogined)
// {
// TBuf<32> infoTitle;
// CEikonEnv::Static()->ReadResource(infoTitle, R_STR_JUSTHANDLE_LABEL);
// iEikonEnv->InfoMsg(infoTitle);
// }
switch (aCommand)
{
case EEikCmdExit:
{
Exit();
break;
}
case ECmdM3UIQ2ContineUpload://处理续传事件
{
_LIT(KAUPLOAD,"upload?%d@%d@%d@%d");//pos,fid,aid,uid
TBuf<64> continueUrl;
continueUrl.Format(KAUPLOAD, iPos, iFid, iAID, iUserUID);//upload?1024@10842@2@2444
iCurrentAction = CHTTPClientEngine::EGeneral;
iHttpEngine->ContinueUpload(continueUrl.Alloc());
break;
}
case ECmdM3UIQ2SystemSeting://处理系统设置
{
//call exist iap
CCommsDatabase* CommDb = CCommsDatabase::NewL(EDatabaseTypeIAP);
CleanupStack::PushL(CommDb);
CCommsDbTableView* tableIAP = CommDb->OpenTableLC(TPtrC(IAP));
if (tableIAP->GotoFirstRecord()==KErrNone)
{
descflat = new (ELeave) CDesCArrayFlat(4);
do
{
TUint32 uid(0);
tableIAP->ReadUintL(TPtrC(COMMDB_ID),uid);
TBuf<256> name;
tableIAP->ReadTextL(TPtrC(COMMDB_NAME),name);
descflat->AppendL(name);
RLog::Log(name);
// CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref;
// pref.iRanking = 1;
// pref.iDirection = ECommDbConnectionDirectionOutgoing;
// pref.iDialogPref = ECommDbDialogPrefDoNotPrompt;
// pref.iBearer.iBearerSet = ECommDbBearerGPRS;
// pref.iBearer.iIapId = uid;
}
while(tableIAP->GotoNextRecord() == KErrNone);
}
CleanupStack::PopAndDestroy(tableIAP);
CleanupStack::PopAndDestroy(CommDb);
//显示设置对话框
CM3UIQ2SetingDlg* iSetdialog = CM3UIQ2SetingDlg::NewL();
iSetdialog->ExecuteLD(R_CONTROLS3_DIALOG);
// RGenericAgent netAgent;
// if (netAgent.Open() == KErrNone)
// {
// CleanupClosePushL(netAgent);
// CCommsDatabase* db = CCommsDatabase::NewL();
// CleanupStack::PushL(db);
// CCommsDbConnectionPrefTableView* view;
// view = db->OpenConnectionPrefTableViewOnRankLC(ECommDbConnectionDirectionOutgoing,1);
// view->GotoFirstRecord();
// view->UpdateDialogPrefL(ECommDbDialogPrefDoNotPrompt);
// TRequestStatus status;
// netAgent.StartOutgoing(status);
// User::WaitForRequest(status);
// CleanupStack::PopAndDestroy(3); // view, db, netAgent
// }
break;
}
case ECmdM3UIQ2CheckUpdate://处理检查更新
{
iHttpEngine->CheckUpdate();
iCurrentAction = CHTTPClientEngine::ECheckUpdate;
break;
}
case ECmdM3UIQ2FileInfo://手机空间
{
TDesC* fileName = iStorageView->FileName();
TInt fsize = iStorageView->GetM3Directory()->GetFileSizeL(*fileName);
TInt pos = fileName->LocateReverse('\\');
TPtrC fname = fileName->Mid(pos + 1);//文件的文件名
TBuf<256> info;
TBuf<32> temp;
info.Append(fname);
info.Append(_L("\r\n"));
CEikonEnv::Static()->ReadResource(temp, R_STR_SIZE);
info.Append(temp);
info.AppendNum((fsize/1024 == 0) ? 1 : fsize / 1024);
info.Append(_L("kb"));
TBuf<32> infoTitle;
CEikonEnv::Static()->ReadResource(infoTitle, R_STR_INFOMATION);
iEikonEnv->InfoWinL(infoTitle, info);
break;
}
case EReturnToListView: //切换主界面
{
SwitchViewL(iUpView);
break;
}
case ECmdM3UIQ2SendAs://切换发送界面
{
if (iStorageView->IsDir())
{
iEikonEnv->InfoWinL(R_STR_INFOMATION, R_STR_FILE_DIR);
break;
}
SwitchViewL(ESEND_VIEW);
//参数
TDesC* filePath = iStorageView->FileName();
iSendView->SetFile(filePath);
delete filePath;
filePath = NULL;
break;
}
case ECmdM3UIQ2SendFile://处理发送
{
TDesC* names = iSendView->Receiver();
TDesC* content = iSendView->Content();
if (names == NULL || content == NULL || names->Length() < 11)
{
iEikonEnv->InfoWinL(_L("note"), _L("please push receiver!"));
delete names;
names = NULL;
delete content;
content = NULL;
break;
}
HandleUpload(-1, names, content);
break;
}
default:
break;
}
}
/**
* 下载数据
**/
void CM3UIQ2AppUi::ResponseReceivedDownL(const HBufC8 *aResponse)
{
}
/**
* 信息接收状态
**/
void CM3UIQ2AppUi::ResponseStatusL(TInt aStatusCode, const TDesC &aStatusText)
{
if (aStatusCode < 0)
{
if (iIsShow)
{
//dialog->Increase(101);
if (dialog)
{
delete dialog;
dialog = NULL;
}
}
iEikonEnv->InfoWinL(_L("Wrong"), _L("Connect error!"));
iIsLogined = ETrue;
// // Application UID for Settings Application
// const TUid KSettingsUid = { 0x100058EC };
// // UID of the display view in the Settings Application
// const TUid KSettListDisplViewId = { 5 };
// ActivateViewL( TVwsViewId(KSettingsUid, KSettListDisplViewId));
}
else
{
if (iCurrentAction == CHTTPClientEngine::ERegister)
{
TBuf<64> content;
CEikonEnv::Static()->ReadResource(content, STR_RELOGON);
content.Append(_L("..."));
iEikonEnv->InfoMsg(content);
}
else
{
if (dialog && iIsShow)
{
dialog->Increase(1);
}
}
}
}
/**
* 信息接收完毕
**/
void CM3UIQ2AppUi::ResponseReceivedL(const TDesC &aResponseBuffer)
{
if (iCurrentAction == CHTTPClientEngine::ERegister)
{
AnalysisRegister(aResponseBuffer);
iIsLogined = ETrue;
TBuf<64> content;
CEikonEnv::Static()->ReadResource(content, STR_RELOGON);
iEikonEnv->InfoMsg(content);
}
else if (iCurrentAction == CHTTPClientEngine::ECheckUpdate)
{
AnalysisUpdate(aResponseBuffer);
}
else if (iCurrentAction == CHTTPClientEngine::EUp)
{
AnalysisUpload(aResponseBuffer);
}
else
{
AnalysisContinueUpload(aResponseBuffer);
}
}
/**
* 处理上传
*
**/
void CM3UIQ2AppUi::HandleUpload(TInt sel, TDesC* aReceiver, TDesC* aContent)
{
CM3UIQ2SetingDlg* iSetdialog = CM3UIQ2SetingDlg::NewL();
iSetdialog->ReadProperty();
RArray<TInt> *array = iSetdialog->GetProperty();
if (array && array->Count() >= 3)
{
iIsShow = (*array)[0];
iCatche = (*array)[2];
}
delete iSetdialog;
iSetdialog = NULL;
//处理文件信息
TBuf<256> txt2;
TDesC* fullName = iSendView->GetFile();
TInt fsize = iStorageView->GetM3Directory()->GetFileSizeL(*fullName);
TInt pos = fullName->LocateReverse('\\');
TPtrC fname = fullName->Mid(pos + 1);//文件的文件名
TInt fsizek = 0;
TBuf<32> temp;
TBuf<256> info;
info.Append(fname);
info.Append(_L("\r"));
CEikonEnv::Static()->ReadResource(temp, R_STR_SIZE);
info.Append(temp);
info.AppendNum((fsize/1024 == 0) ? 1 : fsize / 1024);
info.Append(_L("kb"));
info.Append(_L("\r"));
CEikonEnv::Static()->ReadResource(temp, R_STR_TIME);
info.Append(temp);
info.AppendNum((fsize < 10240) ? 1 : (fsize / 10240));
CEikonEnv::Static()->ReadResource(temp, R_STR_SECOND);
info.Append(temp);
TBuf<32> infoTitle;
CEikonEnv::Static()->ReadResource(infoTitle, R_STR_INFOMATION);
if (!iEikonEnv->QueryWinL(infoTitle, info))
{
return;
}
//处理上传
iSizePart = 1;
TInt block = iCatche * 102400;
if (fsize > block)
{
iSizePart = fsize / 409600;
if (0 != fsize % block)
{
iSizePart++;
}
}
_LIT(KAUPFILE,"%d@%d@%d");//fsize,aid,uid
// [POST]
// FName\n\t\nTos\n\t\nTEXT[file]
//测试文件.3gp\n\t\n13900000001;13900000002;\n\t\n任意短消息内容
reqId = 5;
TBuf<KMaxReqestLength> reqs;
reqs.Format(KAUPFILE, fsize, iAID + 1, iUserUID);
//post内容
HBufC* postContent = HBufC::NewL(KMaxReqestLength);
TPtr des = postContent->Des();
des.Append(fname);
_LIT(Blank, "\n\t\n");
des.Append(Blank);
des.Append(*aReceiver);
des.Append(Blank);
des.Append(*aContent);
delete aReceiver;
aReceiver = NULL;
delete aContent;
aContent = NULL;
iCurrentAction = CHTTPClientEngine::EUp;
TDesC* tempReq = reqs.AllocL();
iHttpEngine->PostUploadRequestL(*tempReq, fullName, postContent, fsize, 0, iCatche);
SwitchViewL(EAPP_VIEW);
if (iIsShow)
{
dialog = CProgressDlg::NewL();
dialog->PrepareLC(R_PROGRESSINFO_DEMO_DIALOG);
dialog->RunLD();
dialog->SetFinalval(iSizePart * 3);
}
}
/**
* 切换视图
* @param aAppView 需要切换到的视图
**/
void CM3UIQ2AppUi::SwitchViewL(TUint8 aAppView)
{
if (aAppView == ESTORAGE_VIEW)
{
TVwsViewId id(KUidM3UIQ2, iStorageView->ViewUid());
ActivateViewL(id);
iActiveView = ESTORAGE_VIEW;
iUpView = EAPP_VIEW;
}
else if (aAppView == ESEND_VIEW)
{
iUpView = (iActiveView == EAPP_VIEW ? EAPP_VIEW : ESTORAGE_VIEW);
TVwsViewId id(KUidM3UIQ2, iSendView->ViewUid());
ActivateViewL(id);
iActiveView = ESEND_VIEW;
}
else if (aAppView == EAPP_VIEW)
{
TVwsViewId id(KUidM3UIQ2, iAppView->ViewUid());
ActivateViewL(id);
iActiveView = EAPP_VIEW;
iUpView = EAPP_VIEW;
}
}
/**
* 得到发送视图
**/
CM3UIQSendView* CM3UIQ2AppUi::GetCM3UIQSendView()
{
return iSendView;
}
/**
* 处理推荐朋友
**/
void CM3UIQ2AppUi::HandleFriend()
{
CreateTestFile();
_LIT(folder, "c:\\Documents\\Media files\\document\\unfiled");
TBuf<512> content;
content.Append(folder);
content.Append('\\');
content.Append(*iName);
//调用系统的发送窗口
TDesC* subject = iCoeEnv->AllocReadResourceLC(R_EXAPPSENDAS_SUBJECT); // Sets the subject to "Document"
RLog::Log(*subject);
// Create an empty body text
CRichText* richText = CRichText::NewL(iEikonEnv->SystemParaFormatLayerL(), iEikonEnv->SystemCharFormatLayerL());
richText->ImportTextFileL(0, content, CPlainText::EOrganiseByLine);
//初识附件
TBuf<64> attachFile;
attachFile.Append(folder);
attachFile.Append('\\');
attachFile.Append(_L("m3uiq.SIS"));
TParsePtrC parse(attachFile);
TFileName attachName(parse.NameAndExt()); // Separate the filename and extent from the full path
RLog::Log(attachFile);
RLog::Log(attachName);
//启动对话框
CQikSendAsDialog::RunDlgLD(richText, content, attachName, *subject); // Launch the SendAs dialog
CleanupStack::PopAndDestroy(subject);
if (iName != NULL)
{
delete iName;
iName = NULL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -