viewmanagerappui.cpp

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

CPP
477
字号
            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 + =
减小字号Ctrl + -
显示快捷键?