📄 viewmanagerappui.cpp
字号:
/**
*
* @brief Definition of CViewManagerAppUi
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
// INCLUDE FILES
// Class include
#include "ViewManagerAppUi.h"
// System includes
#include <apgcli.h> // RApaLsSession
#include <barsread.h> // TResourceReader
#include <cntdb.h> // CContactDatabase
#include <CPbkContactEngine.h> // CPbkContactEngine
#include <CPbkViewState.h> // CPbkViewState
#include <msvstd.hrh> // KMsvGlobalInBoxIndexEntryIdValue & KMsvGlobalOutBoxIndexEntryIdValue
#include <PbkUID.h> // Phonebook UIDs
#include <s32mem.h> // RDesWriteStream
#include <ViewManager.rsg> // R_VIEWMANAGER_DIALOG
#include <aknnotewrappers.h> // CAknErrorNote
#include <stringloader.h> // StringLoader
// User includes
#include "ViewManager.hrh" // TViewManagerViewNumber
#include "ViewManagerDialog.h" // CViewManagerDialog
// CONSTANTS
//Application Uids
const TUid KCalendarUid = { 0x10005901 };
const TUid KPhotoAlbumUid = { 0x101F4CD1 };
const TUid KLogUid = { 0x101f4CD5 };
const TUid KMessagingUid = { 0x100058C5 };
const TUid KServicesUid = { 0x10008D39 };
const TUid KProfileUid = { 0x100058F8 };
const TUid KToDoUid = { 0x10005900 };
const TUid KCameraUid = { 0x1000593F };
const TUid KBlueToothUid = { 0x10005951 };
const TUid KRecorderUid = { 0x100058CA };
const TUid KPhoneBookUid = { KPbkUID3 };
const TUid KWmlBrowserUid = { 0x10008D39 };
// Application view ids
const TUid KPhoneBookContactsViewUid = { 1 };
const TUid KPhoneBookGroupsViewUid = { 2 };
const TUid KPhoneBookFocusedContactViewUid = { 4 };
const TUid KPhoneBookMessageUID = { KPbkViewStateUid };
const TUid KMessagingMainViewUid = { 1 };
const TUid KMessagingFolderViewUid = { 2 };
const TUid KMsvGlobalInBoxIndexEntryUid = { KMsvGlobalInBoxIndexEntryIdValue };
const TUid KMsvGlobalOutBoxIndexEntryUid = { KMsvGlobalOutBoxIndexEntryIdValue };
const TUid KCameraStandby = { 1 };
const TUid KCameraViewfinder = { 2 };
const TUid KCameraSettings = { 4 };
// Panic messages
_LIT(KPanicViewManager, "Invalid view selction");
// Browser message command sequence.
_LIT(KCharacterFourPlusSpace, "4 ");
// ================= MEMBER FUNCTIONS =======================
/**
* Symbian OS 2nd phase constructor. Constructs the application's views,
* transferring ownership of them to the superclass.
* Sets the view as the default and remembers that this is the current view id.
*/
void CViewManagerAppUi::ConstructL()
{
BaseConstructL();
iAppDialog = CViewManagerDialog::NewL();
iAppDialog->SetMopParent(this);
iAppDialog->ExecuteLD(R_VIEWMANAGER_DIALOG);
AddToStackL(iAppDialog);
}
/**
* Destructor
*/
CViewManagerAppUi::~CViewManagerAppUi()
{
if (iAppDialog)
{
RemoveFromStack(iAppDialog);
delete iAppDialog;
}
}
/**
* From CEikAppUi, takes care of command handling for both views.
*
* @param aCommand command to be handled
*/
void CViewManagerAppUi::HandleCommandL(TInt aCommand)
{
switch (aCommand)
{
case EEikCmdExit:
case EAknCmdExit:
{
Exit();
break;
}
case ESwitchToCalendarApp:
{
SwitchToCalendarL();
break;
}
case ESwitchToPhoneBookApp:
{
SwitchToPhonebookL();
break;
}
case ESwitchToCameraApp:
{
SwitchToCameraL();
break;
}
case ESwitchToPhotoAlbum:
{
SwitchToPhotoAlbumL();
break;
}
case ESwitchToProfile:
{
SwitchToProfileL();
break;
}
case ESwitchToMessaging:
{
SwitchToMessagingL();
break;
}
case ELaunchBrowser:
{
LaunchBrowserL(iViewIndex);
break;
}
default:
break;
}
}
/**
* Sets the view index
* @param aViewIndex Index of relevent view
*/
void CViewManagerAppUi::SetViewIndex(TInt aViewIndex)
{
iViewIndex = aViewIndex;
}
/**
* Switch to the Phonebook application
*/
void CViewManagerAppUi::SwitchToPhonebookL()
{
// Note that on some devices the phonebook application must be running in the background
// when the view switch occurs or the view will switch to the (default) contacts view after a short delay.
// View ids of the phonebook application
// 0x01 contacts view
// 0x02 groups view
switch (iViewIndex)
{
case EPhoneBookContactsView:
{
ActivateViewL(TVwsViewId(KPhoneBookUid, KPhoneBookContactsViewUid));
break;
}
case EPhoneBookGroupsView:
{
ActivateViewL(TVwsViewId(KPhoneBookUid, KPhoneBookGroupsViewUid));
break;
}
case EPhoneBookFirstContactView:
{
// This shows the cleanest method to switch to a contact (by using CPbkViewState).
// This introduces an extra dependency that can be avoided by using the equivalent
// method shown in case EPhoneBookLastContactView.
// Get Id of first contact
CPbkContactEngine* phonebook = CPbkContactEngine::NewL(); // Create a connection to the default phonebook database.
CleanupStack::PushL(phonebook);
TContactIter iter(phonebook->Database()); // Iterate to the first item.
TContactItemId firstItemId = iter.FirstL();
CleanupStack::PopAndDestroy(phonebook);
if (firstItemId < KErrNone)
{
HBufC* message = StringLoader::LoadLC(R_NO_DATA_AVAILABLE);
CAknErrorNote* errorNote = new (ELeave) CAknErrorNote;
errorNote->ExecuteLD(*message);
CleanupStack::PopAndDestroy (message);
break;
}
// Package first contact information
CPbkViewState* pbkViewParam = CPbkViewState::NewLC();
pbkViewParam->SetFocusedContactId(firstItemId); // Id of first contact
pbkViewParam->SetFocusedFieldIndex(4); // Focus on the fourth field in the contact
HBufC8* paramBuf = pbkViewParam->PackLC();
// Make view id with Phonebook's app uid and Contact Info View's id
const TVwsViewId viewId(KPhoneBookUid, KPhoneBookFocusedContactViewUid);
// Activate the view
ActivateViewL(viewId, CPbkViewState::Uid(), *paramBuf);
// Cleanup
CleanupStack::PopAndDestroy(2, pbkViewParam); // pbkViewParam and paramBuf
break;
}
case EPhoneBookLastContactView:
{
// This shows an alternative method to switch to a contact, without using CPbkViewState.
// The dependency on PbkView.dll can be removed by using this method rather than that
// shown in case EPhoneBookFirstContactView.
// Get Id of last contact
CPbkContactEngine* phonebook = CPbkContactEngine::NewL(); // Create a connection to the default phonebook database.
CleanupStack::PushL(phonebook);
if (phonebook->Database().CountL() <= 0)
{
CleanupStack::PopAndDestroy(phonebook);
HBufC* message = StringLoader::LoadLC(R_NO_DATA_AVAILABLE);
CAknErrorNote* errorNote = new (ELeave) CAknErrorNote;
errorNote->ExecuteLD(*message);
CleanupStack::PopAndDestroy (message);
break;
}
TContactIter iter(phonebook->Database()); // Iterate to the last item.
TContactItemId lastItemId = iter.LastL();
CleanupStack::PopAndDestroy(phonebook);
// Write parameters in a buffer
TBuf8<16> param;
RDesWriteStream stream(param);
stream.PushL();
stream.WriteInt8L(CPbkViewState::EFocusedContactId);
stream.WriteInt32L(lastItemId); // Contact id of last contact
stream.WriteInt8L(CPbkViewState::EFocusedFieldIndex);
stream.WriteInt32L(4); // Focus on the fourth field in the contact
stream.CommitL();
CleanupStack::PopAndDestroy(); // stream
// Make view id with Phonebook's app UID3 and Contact Info View's id
const TVwsViewId viewId(KPhoneBookUid, KPhoneBookFocusedContactViewUid);
// Activate the view
ActivateViewL(viewId, KPhoneBookMessageUID, param);
break;
}
default:
{
#ifdef _DEBUG
// We should never reach this point, so panic
User::Panic(KPanicViewManager, KPhoneBookUid.iUid);
#endif // _DEBUG
break;
}
}
}
/**
* Switch to the Camera application
*/
void CViewManagerAppUi::SwitchToCameraL()
{
// View Uid of the camera application
// 0x01 Standby mode
// 0x02 ViewFinder mode
// 0x04 Settings mode
switch (iViewIndex)
{
case ECameraStandby:
ActivateViewL(TVwsViewId(KCameraUid, KCameraStandby));
break;
case ECameraViewfinder:
ActivateViewL(TVwsViewId(KCameraUid, KCameraViewfinder));
break;
case ECameraSettings:
// Switching to the camera settings view can cause an error when closing the view!
ActivateViewL(TVwsViewId(KCameraUid, KCameraSettings));
break;
default:
#ifdef _DEBUG
// We should never reach this point, so panic
User::Panic(KPanicViewManager, KCameraUid.iUid);
#endif // _DEBUG
break;
}
}
/**
* Switch to the Calendar application
*/
void CViewManagerAppUi::SwitchToCalendarL()
{
// Note that on some devices the calendar application must be running in the background
// when the view switch occurs or the view will switch to the (default) day view.
// View Uid of the calendar application
// 0x01 Month view
// 0x02 Week view
// 0x03 Day view
TUid calendarViewUid = { iViewIndex + 1 };
ActivateViewL(TVwsViewId(KCalendarUid, calendarViewUid));
}
/**
* Switch to the PhotoAlbum application
*/
void CViewManagerAppUi::SwitchToPhotoAlbumL()
{
// View Uid of the Photoalbum application
// 0x01 Imagelist view the default view
// 0x03 Messaging Picture Grid view ,
// 0x04 Messaging Picture view
TInt viewUid = 1;
switch (iViewIndex)
{
case EPhotoAlbumImageList:
viewUid = 1; // Imagelist view
break;
case EPhotoAlbumPictureGrid:
// This will crash the photoAlbum application
// if there are no photos.
viewUid = 3; // Picture grid view
break;
case EPhotoAlbumPictureView:
viewUid = 4; // Picture view
break;
default:
{
#ifdef _DEBUG
// We should never reach this point, so panic
User::Panic(KPanicViewManager, KPhotoAlbumUid.iUid);
#endif // _DEBUG
break;
}
}
TUid photoAlbumViewUid = { viewUid };
ActivateViewL(TVwsViewId(KPhotoAlbumUid, photoAlbumViewUid));
}
/**
* Switch to the Profile application
*/
void CViewManagerAppUi::SwitchToProfileL()
{
// View Uid of the Profile application
// 0x01 main view
// 0x02 settings view
TUid profileViewUid = { iViewIndex + 1 };
ActivateViewL(TVwsViewId(KProfileUid, profileViewUid));
}
/**
* Switch to the Messaging application
*/
void CViewManagerAppUi::SwitchToMessagingL()
{
switch (iViewIndex)
{
case EMessagingMainView:
{
ActivateViewL(TVwsViewId(KMessagingUid, KMessagingMainViewUid));
break;
}
case EMessagingInboxView:
{
TBuf8<255> customMessage;
ActivateViewL(TVwsViewId(KMessagingUid, KMessagingFolderViewUid), KMsvGlobalInBoxIndexEntryUid, customMessage);
break;
}
case EMessagingOutboxView:
{
TBuf8<255> customMessage;
ActivateViewL(TVwsViewId(KMessagingUid, KMessagingFolderViewUid), KMsvGlobalOutBoxIndexEntryUid, customMessage);
break;
}
default:
{
#ifdef _DEBUG
// We should never reach this point, so panic
User::Panic(KPanicViewManager, KMessagingUid.iUid);
#endif // _DEBUG
break;
}
}
}
/**
* Launchs the browser with a URL loaded
* @param iPageIndex Index of which page to load
*/
void CViewManagerAppUi::LaunchBrowserL(TInt aPageIndex)
{
// Read from the resource file, the url corresponding to aPageIndex
TResourceReader reader;
// CreateResourceReaderLC sets a TResourceReader's buffer to a HBufC which
// the required resource has been read into.
iEikonEnv->CreateResourceReaderLC(reader, R_BROWSER_VIEWLIST);
reader.ReadInt16(); // command
reader.ReadInt16(); // count
HBufC* unExtendedLink;
for (TInt ii = 0; ii < aPageIndex; ++ii)
{
reader.ReadTPtrC();
}
unExtendedLink = reader.ReadHBufCL();
CleanupStack::PopAndDestroy(); // reader's HBufC buffer, allocated using CreateResourceReaderLC
// if unExtendedLink was pushed to the cleanupstack earlier,
// we would have to maintain reader until the we popanddestroy link.
CleanupStack::PushL(unExtendedLink);
// Extend the HBufC containing the link so we can add two characters at the
// beginning. The 4 is part of the internal sequence for the browser.
// ReAllocL creates a new heap descriptor,copies the original data into the new descriptor
// then deletes the original descriptor.
HBufC* link = unExtendedLink->ReAllocL(unExtendedLink->Length() + 2);
// When we get here, unExtendedLink has already been deleted by ReAllocL
CleanupStack::Pop(unExtendedLink);
// Push link on to the CleanupStack
CleanupStack::PushL(link);
// insert a 4 and a space at the beginning.
// The 4 is part of the internal sequence for the browser.
link->Des().Insert(0, KCharacterFourPlusSpace);
// Find the browser in the tasklist
TApaTaskList taskList(iEikonEnv->WsSession());
TApaTask task = taskList.FindApp(KWmlBrowserUid);
if (task.Exists())
{
// If the browser is running, send the url to load as a message
HBufC8* param8 = HBufC8::NewLC(link->Length()); // convert unicode text to 8-bit text
param8->Des().Append(*link);
task.SendMessage(TUid::Uid(0), *param8); // Uid is not used
CleanupStack::PopAndDestroy(param8);
}
else
{
// If the browser is not running, start the browser with
// the URLpassed as the document to load.
RApaLsSession appArcSession;
User::LeaveIfError(appArcSession.Connect()); // connect to AppArc server
TThreadId id;
appArcSession.StartDocument(*link, KWmlBrowserUid, id);
appArcSession.Close();
}
CleanupStack::PopAndDestroy(link);
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -