chxaveditplaylistdialog.cpp

来自「symbian 下的helix player源代码」· C++ 代码 · 共 556 行 · 第 1/2 页

CPP
556
字号
// move from control to control and alter text (hence, we save
// all edwin text, not just the text for currently selected edwin)
void CHXAvEditPlaylistDialog::CreateRestoreListL()
{
    DPRINTF(SYMP_INFO, ("CHXAvEditPlaylistDialog::CreateRestoreListL(): saving backup items\n"));

    m_spRestoreList = new (ELeave) CDesCArrayFlat(20 /*granularity*/);
    
    ForEachEdwinL(&CHXAvEditPlaylistDialog::AppendRestoreListL);
}


////////////////////////////////////////////
// called after an item is edited and 'no' is selected by user
// when prompted to save changes (or if we determine url is invalid after 'yes')
//
void CHXAvEditPlaylistDialog::DoNotSaveFormDataL()
{
    DPRINTF(SYMP_INFO, ("CHXAvEditPlaylistDialog::DoNotSaveFormDataL(): restoring items\n"));
    
    // restore form data to pre-edit-mode state  
    HX_ASSERT(m_spRestoreList);
    ForEachEdwinL(&CHXAvEditPlaylistDialog::RestoreItemL);

    // done with these...
    m_spRestoreList = 0; 

    CAknForm::DoNotSaveFormDataL();
}

////////////////////////////////////////////
// called when edit mode is exited
TBool CHXAvEditPlaylistDialog::QuerySaveChangesL()
{
    DPRINTF(SYMP_INFO, ("CHXAvEditPlaylistDialog::QuerySaveChangesL()\n"));

    // prompts for save; expect SaveFormDataL() or DoNotSaveFormDataL() next...
    return CAknForm::QuerySaveChangesL();

}

////////////////////////////////////////////////////////
//
void CHXAvEditPlaylistDialog::DeleteCurrentItemL()
{
    DPRINTF(SYMP_INFO, ("CHXAvEditPlaylistDialog::DeleteCurrentItemL()\n"));

    // this posts confirmation dialog...
    CAknForm::DeleteCurrentItemL();
}

////////////////////////////////////////////////////////
//
void CHXAvEditPlaylistDialog::EditCurrentLabelL()
{
    DPRINTF(SYMP_INFO, ("CHXAvEditPlaylistDialog::EditCurrentLabelL()\n"));
    CAknForm::EditCurrentLabelL();
}

////////////////////////////////////////////////////////
//
void CHXAvEditPlaylistDialog::AddItemL()
{
    DPRINTF(SYMP_INFO, ("CHXAvEditPlaylistDialog::AddItemL()\n"));
    
    CHXAvCleanString caption(R_AVP_EDIT_PLAYLIST_LINK_CAPTION);
    CHXAvCleanString field(R_AVP_EDIT_PLAYLIST_NEW_ITEM_TEXT);

    bool bDoIt = false;
    TInt idxInsert = -1; // at end by default
    TInt count = GetNumberOfLinesOnPage(ActivePageId());
    if( count > 0 )
    {
        CEikCaptionedControl* pLine = CurrentLine();

        TInt idxCurrent = FindLineIndex(*pLine);

        TInt idxSel = 0;
        CAknListQueryDialog* pDlg = new (ELeave) CAknListQueryDialog(&idxSel);
        TInt ret = pDlg->ExecuteLD(R_AVP_SELECT_PLAYLIST_POS_DLG);
        if(ret != 0)
        {
            bDoIt = true;
            // before = 0; after = 1
            idxInsert = (idxSel == 0) ? idxCurrent : idxCurrent + 1;        
        }
    }
    else
    {
        // insert at end
        bDoIt = true;
    }

    if( bDoIt )
    {
        m_bListAlteredFromPreDialogState = true;
        InsertItemL(caption(), field(), idxInsert);
        UpdatePageL(ETrue);
    }
}

////////////////////////////////////////////////////////
//
void CHXAvEditPlaylistDialog::DynInitMenuPaneL( TInt id, CEikMenuPane* pPane )
{
    DPRINTF(SYMP_INFO, ("CHXAvEditPlaylistDialog::DynInitMenuPaneL()\n"));
    CAknForm::DynInitMenuPaneL( id, pPane );

    // see avkon.hrh

    if ( id == R_AVKON_FORM_MENUPANE )
    {
        // enable add; customize text
        pPane->SetItemDimmed(EAknFormCmdAdd, EFalse);
        pPane->SetItemTextL(EAknFormCmdAdd, CHXAvCleanString(R_AVP_EDITPLAYLIST_ADD_ITEM)());

        TInt idxPage = ActivePageId();
        TInt lineCount = GetNumberOfLinesOnPage(idxPage);

        if( lineCount > 0 )
        {
            // enable delete; customize text
            pPane->SetItemDimmed(EAknFormCmdDelete, EFalse);
            pPane->SetItemTextL(EAknFormCmdDelete, CHXAvCleanString(R_AVP_EDITPLAYLIST_DEL_ITEM)());
        }
        else
        {
            // disable delete
            pPane->SetItemDimmed(EAknFormCmdDelete, ETrue);
        }

        // always disable 'edit label'
        pPane->SetItemDimmed(EAknFormCmdLabel, ETrue);

        if(!m_bInEditMode && m_bListAlteredFromPreDialogState)
        {
            // add 'revert to pre-dialog state' menu item (note: this restore is not same as 'restore list' restore)
            CHXAvMisc::AddMenuItemL(pPane, ERestorePlaylist, R_AVP_M_RESTORE);
        }

        // help menu item (goes last)
        CHXAvMisc::AddMenuItemL(pPane, EAknCmdHelp, R_AVP_MENU_HELP);
        CHXAvMisc::InitHelpMenuItem(pPane);
        
    }
	
}

////////////////////////////////////////////////////////
// called for *all* cba presses
TBool CHXAvEditPlaylistDialog::OkToExitL(TInt aButtonId)
{
    bool bAllow = true;
    if(EAknSoftkeyBack == aButtonId)
    {
        if(!m_bInEditMode)
        {
            if( !VerifyFormL() )
            {
                // warn user
                bAllow = CHXAvMessageDialog::DoQueryL(CHXAvCleanString(R_AVP_Q_CONTINUE_WITH_BAD_PLAYLIST)(), CHXAvMessageDialog::QueryOkCancel);
            }

            // in case add/delete fields occurred
            SaveFormDataL();
        }
        else
        {
            m_bInEditMode = false;
        }
    }
        
    return bAllow ? CAknForm::OkToExitL(aButtonId) : EFalse;
}

////////////////////////////////////////////
// CCoeControl
void CHXAvEditPlaylistDialog::GetHelpContext(TCoeHelpContext& aContext) const
{
    aContext = TCoeHelpContext( CHXAvMisc::KHelpUID, KRP_HLP_EDIT_LINK );
}

////////////////////////////////////////////////////////
//
TKeyResponse CHXAvEditPlaylistDialog::OfferKeyEventL (const TKeyEvent &aKeyEvent, TEventCode aType)
{
    TKeyResponse response = EKeyWasNotConsumed;

    if(EEventKey == aType)
    {
        switch(aKeyEvent.iCode)
        {
        case EKeyOK:
        case EKeyEnter:
            response = EKeyWasConsumed;
            ProcessCommandL(EAknFormCmdEdit); 
            break;
        default:
            // everything else goes to the form
            response = CAknForm::OfferKeyEventL(aKeyEvent, aType);
        }

    }
    else
    {
        response = CAknForm::OfferKeyEventL(aKeyEvent, aType);
    }

    return response;
    
}

////////////////////////////////////////////////////////
// fill up form with playlist items
void 
CHXAvEditPlaylistDialog::PopulateL()
{
    m_idNextItem = EIdFirstLine;
    m_pLastLineAdded = 0;

    for(CHXAvPlaylistItr iter = *m_spPlaylist; iter.More(); iter.Next())
    {
        const CHXAvURLRep& url = iter.Current();

        // make sure url is unquoted, readable form
        //utString str = url.EscapedPath().GetUnEscapedStr();

        CHXAvEscapedString escUrl = CHXAvEscapedString(url.String());
        CHXString niceUrl = escUrl.GetUnEscapedStr();

        CHXAvCleanString caption(R_AVP_EDIT_PLAYLIST_LINK_CAPTION);
        CHXAvCleanString field(niceUrl);
        InsertItemL(caption(), field());
    }

}


////////////////////////////////////////////////////////
// helper; called from PopulateL()
void
CHXAvEditPlaylistDialog::InsertItemL(const TDesC& caption, const TDesC& text, TInt idxPos)
{
    TInt idxPage = ActivePageId();
    TInt idxLine = (idxPos != -1) ? idxPos : GetNumberOfLinesOnPage(idxPage);

    DPRINTF(SYMP_INFO, ("CHXAvEditPlaylistDialog::InsertItemL(): adding at idx %d\n", idxLine));

    // inserts a new line without doing auto redraw (like CreateLineByTypeL)
    InsertLineL(idxLine, R_AVP_FORM_EDWIN, idxPage);

    // get the line and control we just added (note that id is placeholder)
    CEikCaptionedControl* pLine = Line(EIdInsertLinePlaceHolder);
    CEikEdwin* pEditWin = reinterpret_cast<CEikEdwin*>(pLine->iControl);

    //pEditWin->SetTextLimit(cchLimit);
    pEditWin->SetTextL(&text);

    pLine->SetCaptionL(KNullDesC);
    pLine->SetCaptionL(caption);
    pLine->iId = m_idNextItem++;
    
    // pLine->SetDividerAfter(ETrue);

    TFileName* pImageFilePath = CHXAvFile::AllocAppFolderPathL(CHXAvUtil::KImagesMBMName);
    AUTO_PUSH_POP_DEL(pImageFilePath);

    // XXXLCM
    pLine->SetBitmapFromFileL(*pImageFilePath, EMbmRealplayerFile_network, EMbmRealplayerFile_network_mask); 
    
    // ready to draw
    pLine->ActivateL();

    m_pLastLineAdded = pLine;
}


⌨️ 快捷键说明

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