viewmanagerappui.cpp

来自「series60 应用程序开发的源代码 series60 应用程序开发的源代码」· C++ 代码 · 共 477 行 · 第 1/2 页

CPP
477
字号
/**
*
* @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 <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    = { 0x101f4cce }; // Taken from KPbkUID3 - version 1.2 "PbkUID.h"
const TUid KWmlBrowserUid    = { 0x10008D39 };

// Application view ids
const TUid KPhoneBookContactsViewUid        = { 1 };
const TUid KPhoneBookGroupsViewUid            = { 2 };
const TUid KPhoneBookFocusedContactViewUid    = { 4 };
const TUid KPhoneBookMessageUID                = { 0x101f4ccf }; // Taken from KPbkViewStateUid - version 1.2 "PbkUID.h"

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;
            }

⌨️ 快捷键说明

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