?? recorderview.cpp
字號:
/*
* ============================================================================
* Name : RecorderView.cpp
* Part of : RecorderExample
* Created : 20.03.2005 by Forum Nokia
* Version : 1.0.0
* Copyright: Nokia Corporation
* ============================================================================
*/
// INCLUDE FILES
#include <aknviewappui.h>
#include "recorderadapter.h"
#include <recorder.rsg>
#include "RecorderView.h"
#include "RecorderContainer.h"
#include "ScreenUpdateTimer.h"
#include "phoneobserver.h"
#include <aknselectionlist.h> //cba
#include <eikcmbut.h> //button
const TInt KInitIncrement = 0;
const TInt KTimerModelHundredths = 100;
const TInt KTimerModelIncrement = 1;
const TBool KTimerModelRunning = ETrue;
_LIT (KTsyName,"phonetsy.tsy");
// ================= MEMBER FUNCTIONS =======================
//----------------------------------------------------------
// C++ default constructor
// ---------------------------------------------------------
CRecorderView::CRecorderView()
: iContainer( NULL ),
iTimer( NULL )
{
}
// ---------------------------------------------------------
// CRecorderView::ConstructL( const TRect& aRect )
// EPOC two-phased constructor
// ---------------------------------------------------------
void CRecorderView::ConstructL()
{
BaseConstructL( R_RECORDER_VIEW1 );
}
// ---------------------------------------------------------
// CRecorderView::~CRecorderView()
// Destructor.
// ---------------------------------------------------------
CRecorderView::~CRecorderView()
{
if ( iContainer )
{
AppUi()->RemoveFromStack( iContainer );
}
delete iTimer;
iTimer = NULL;
delete iContainer;
iContainer = NULL;
delete iRecorderAdapter;
iRecorderAdapter = NULL;
if (iPhoneObserver != NULL)
{
iPhoneObserver -> Deactivate();
delete iPhoneObserver;
iPhoneObserver = NULL;
}
//Close line, phone and server
UnRegisterLine();
}
// ---------------------------------------------------------
// TUid CRecorderView::Id()
// returns view Id.
// ---------------------------------------------------------
TUid CRecorderView::Id() const
{
return KViewId;
}
// ---------------------------------------------------------
// CRecorderView::HandleCommandL( TInt aCommand )
// handles commands.
// ---------------------------------------------------------
void CRecorderView::HandleCommandL( TInt aCommand )
{
switch ( aCommand )
{
case EAknCmdExit:
case EAknSoftkeyBack:
case EEikCmdExit:
//To ensure destroying of the timer object
delete iTimer;
iTimer = NULL;
AppUi()->HandleCommandL( EEikCmdExit );
return; // Returns if exit
case EProgCmdPlay:
//Start timer to update progressbar.
ConstructTimerModel();
ConstructTimerL();
//Start playback from begin
iRecorderAdapter -> StopL(EPause);
iRecorderAdapter -> PlayL();
//Set progressbar to start position
iContainer -> ResetAllValues( 0, iRecorderAdapter -> GetMaxDuration() );
break;
case EProgCmdRecord:
ConstructTimerModel();
ConstructTimerL();
iRecorderAdapter -> RecordL();
iContainer -> ResetAllValues( iRecorderAdapter -> GetDuration(), iRecorderAdapter -> GetMaxDuration() );
break;
case EProgCmdStop:
iRecorderAdapter -> StopL(EStop);
delete iTimer;
iTimer = NULL;
break;
case ERecordActivate:
iContainer -> SetInfo(ETrue);
//If ETel is not activated
if (iPhoneObserver == NULL)
{
//If registering don't success, server,line and phone are closed
TRAPD(error, RegisterLineL());
if(error)
{
UnRegisterLine();
User::Leave(error);
}
iPhoneObserver = CPhoneObserver::NewL(this, &iLine);
iPhoneObserver -> Start();
}
break;
case ERecordDeactivate:
iContainer -> SetInfo(EFalse);
if (iPhoneObserver != NULL)
{
iPhoneObserver -> Deactivate();
delete iPhoneObserver;
iPhoneObserver = NULL;
UnRegisterLine();
}
break;
//Pause is also used from SoftkeyNext
case EProgCmdPause:
case EProgSoftkeyNext:
{
//Depending on recorder's status, different functionality is chosen
if (iRecorderAdapter -> GetRecorderStatus() == EPause)
{
ConstructTimerModel();
ConstructTimerL();
iRecorderAdapter -> PlayCurrentPositionL();
iContainer -> ResetAllValues( iRecorderAdapter -> GetDuration(), iRecorderAdapter -> GetMaxDuration() );
}
else if(iRecorderAdapter -> GetRecorderStatus() == EPlaying)
{
delete iTimer;
iTimer = NULL;
iRecorderAdapter -> StopL(EPause);
}
else
{
ConstructTimerModel();
ConstructTimerL();
iRecorderAdapter -> StopL(EPause);
iRecorderAdapter -> PlayL();
iContainer -> ResetAllValues(iRecorderAdapter -> GetDuration(), iRecorderAdapter -> GetMaxDuration() );
}
break;
}
default:
AppUi()->HandleCommandL( aCommand );
return; // returns if default
} // End switch ( aCommand )
}
// ---------------------------------------------------------
// CRecorderView::HandleClientRectChange()
//
// ---------------------------------------------------------
void CRecorderView::HandleClientRectChange()
{
if ( iContainer )
{
iContainer->SetRect( ClientRect() );
}
}
// ---------------------------------------------------------
// CRecorderView::DoActivateL(...)
//
// ---------------------------------------------------------
void CRecorderView::DoActivateL(
const TVwsViewId& /*aPrevViewId*/, TUid /*aCustomMessageId*/,
const TDesC8& /*aCustomMessage*/ )
{
iContainer = new( ELeave ) CRecorderContainer;
iContainer->SetMopParent(this);
iContainer->ConstructL( ClientRect() );
AppUi()->AddToStackL( *this, iContainer );
iRecorderAdapter = CRecorderAdapter::NewL(iContainer);
//RLine can't be used in debugger
#ifdef __WINS__
#else
//initialize iRLine
TRAPD(error, RegisterLineL());
if(error)
{
UnRegisterLine();
User::Leave(error);
}
iPhoneObserver = CPhoneObserver::NewL(this, &iLine);
iPhoneObserver -> Start();
#endif
}
// ---------------------------------------------------------
// CRecorderView::HandleCommandL( TInt aCommand )
//
// ---------------------------------------------------------
void CRecorderView::DoDeactivate()
{
if ( iContainer )
{
AppUi()->RemoveFromStack( iContainer );
}
delete iTimer;
iTimer = NULL;
delete iContainer;
iContainer = NULL;
delete iRecorderAdapter;
iRecorderAdapter = NULL;
if ( iPhoneObserver )
iPhoneObserver -> Deactivate();
delete iPhoneObserver;
iPhoneObserver = NULL;
}
// ----------------------------------------------------
// CRecorderView::ConstructTimerModel()
// Set Timer Model
// ----------------------------------------------------
void CRecorderView::ConstructTimerModel()
{
iTimerModel.iHundredths = KTimerModelHundredths;
iTimerModel.iIncrement = KTimerModelIncrement;
iTimerModel.iRunning = KTimerModelRunning;
}
// ----------------------------------------------------
// CRecorderView::ConstructTimerL()
// Set Timer
// ----------------------------------------------------
void CRecorderView::ConstructTimerL()
{
delete iTimer;
iTimer = NULL;
iTimer = new( ELeave ) CScreenUpdateTimer;
iTimer->ConstructL( &iTimerModel, iContainer, iRecorderAdapter );
}
// ----------------------------------------------------
// CRecorderView::SetText()
// Set text in error label in container
// ----------------------------------------------------
void CRecorderView::SetText(TDesC& aText)
{
iContainer -> SetText(aText);
}
// ----------------------------------------------------
// CRecorderView::UnregisterLine()
// Line, phone and server are closed
// ----------------------------------------------------
void CRecorderView::UnRegisterLine()
{
iLine.Close();
iPhone.Close();
iServer.Close();
}
// ----------------------------------------------------
// CRecorderView::RegisterLine()
// Line is activated for later use
// ----------------------------------------------------
void CRecorderView::RegisterLineL()
{
//Create a connection to the tel server
User::LeaveIfError(iServer.Connect());
//Load in the phone device driver
User::LeaveIfError(iServer.LoadPhoneModule(KTsyName));
//Find the number of phones available from the tel server
TInt numberPhones;
User::LeaveIfError(iServer.EnumeratePhones(numberPhones));
//Check there are available phones
if (numberPhones < 1)
{
User::Leave(KErrNotFound);
}
//Get info about the first available phone
RTelServer::TPhoneInfo info;
User::LeaveIfError(iServer.GetPhoneInfo(0, info));
//Use this info to open a connection to the phone, the phone is identified by its name
User::LeaveIfError(iPhone.Open(iServer, info.iName));
//Get info about the first line from the phone
RPhone::TLineInfo lineInfo;
User::LeaveIfError(iPhone.GetLineInfo(0, lineInfo));
User::LeaveIfError(iLine.Open(iPhone, lineInfo.iName));
}
//End of File
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -