chxaveditplaylistdialog.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:16k
源码类别:
Symbian
开发平台:
Visual C++
- /*============================================================================*
- *
- * (c) 1995-2002 RealNetworks, Inc. Patents pending. All rights reserved.
- *
- *============================================================================*/
- #include <eikcapc.h>
- #include <aknquerydialog.h>
- //#include <hlplch.h>
- #include "hxsym_debug.h"
- #include "chxavmisc.h"
- #include "chxavutil.h"
- #include "chxavcleanupstack.h"
- #include "chxavcleanstring.h"
- #include "chxavescapedstring.h"
- #include "player_uids.h"
- #include "chxaveditplaylistdialog.h"
- #include "realplayer.hrh"
- #include "hxsym_leaveutil.h"
- #include "realplayer.mbg"
- #include "r1p.hlp.hrh"
- CHXAvEditPlaylistDialog::CHXAvEditPlaylistDialog()
- : m_idNextItem(0)
- , m_pLastLineAdded(0)
- , m_bInEditMode(false)
- , m_bListAlteredFromPreDialogState(false)
- {
- }
- CHXAvEditPlaylistDialog::~CHXAvEditPlaylistDialog()
- {
- m_file.Close();
- }
- ////////////////////////////////////////////
- //
- TInt CHXAvEditPlaylistDialog::SetPlaylistL(const TDesC& playListPath)
- {
- TInt err = KErrGeneral;
- // we don't allow empty/invalid playlists (for now)
- CHXString strPath;
- CHXAvStringUtils::DesToString(playListPath, strPath);
- m_spPlaylist = CHXAvRAMParser::Parse(strPath);
- if( m_spPlaylist && (0 != m_spPlaylist->Length()) )
- {
- // open/lock file while dialog is active
- err = m_file.Open(CEikonEnv::Static()->FsSession(),
- playListPath, EFileWrite|EFileShareExclusive);
- }
- return err;
- }
- ////////////////////////////////////////////
- //
- void
- CHXAvEditPlaylistDialog::PreLayoutDynInitL()
- {
- PopulateL();
- }
- ////////////////////////////////////////////
- //
- void CHXAvEditPlaylistDialog::ProcessCommandL(TInt id)
- {
- DPRINTF(SYMP_INFO, ("CHXAvEditPlaylistDialog::ProcessCommandL(): id = %dn", id));
- switch(id)
- {
- case EAknFormCmdEdit:
- {
- HX_ASSERT(!m_bInEditMode);
- m_bInEditMode = true;
- CreateRestoreListL();
- break;
- }
- case EAknFormCmdAdd:
- case EAknFormCmdDelete:
- //XXXLCM the delete case is hard because we get no notification if user says no to are you sure? we assume yes...
- m_bListAlteredFromPreDialogState = true;
- break;
- case ERestorePlaylist:
- DoRestorePreDialogStateL();
- break;
- case EAknCmdHelp:
- {
- //CCoeAppUi* pUi = static_cast<CCoeAppUi*>(iCoeEnv->AppUi());
- //HlpLauncher::LaunchHelpApplicationL( iCoeEnv->WsSession(), pUi->AppHelpContextL() );
- }
- break;
- default:
- break;
- }
- CAknForm::ProcessCommandL(id);
- }
- ////////////////////////////////////////////
- // check all urls for proper syntax
- bool CHXAvEditPlaylistDialog::VerifyFormL()
- {
- return ForEachEdwinL(&CHXAvEditPlaylistDialog::VerifyUrlL);
- }
- ///////////////////////////////////////////
- //ForEachEdwinL helper
- bool CHXAvEditPlaylistDialog::WriteUrlL(TInt /*idx*/, CEikEdwin* pEdwin)
- {
- HBufC* pText = pEdwin->GetTextInHBufL();
- if(pText)
- {
- AUTO_PUSH_POP_DEL(pText);
- //bool bIsValid = CHXAvUtil::ValidURL(*pText);
- const TUint cchNewLine = CHXAvUtil::litSize(CHXAvUtil::KNewline);
- HBufC8* pText8 = HBufC8::NewL(pText->Length() + cchNewLine);
- AUTO_PUSH_POP_DEL(pText8);
- TPtr8 ptr = pText8->Des();
- ptr.Copy(*pText); // note: converts
- ptr.Append(CHXAvUtil::KNewline);
- m_file.Write(*pText8);
- }
- return true;
- }
- ////////////////////////////////////////////
- // confirm restore operation with user and do if user agrees
- void CHXAvEditPlaylistDialog::DoRestorePreDialogStateL()
- {
- bool bDoRestore = CHXAvMessageDialog::DoQueryL(CHXAvCleanString(R_AVP_Q_RESTORE_PLAYLIST)(), CHXAvMessageDialog::QueryOkCancel);
- if( bDoRestore )
- {
- // clear
- for( TInt idx = EIdFirstLine; idx < m_idNextItem; ++idx )
- {
- // delete line with this id (if it exists)
- CCoeControl* pControl = ControlOrNull(idx);
- if(pControl)
- {
- DeleteLine(idx, EFalse /*no redraw*/);
- }
- }
- // re-populate
- PopulateL();
- UpdatePageL(ETrue);
- SaveFormDataL();
- SetInitialCurrentLine();
- m_bListAlteredFromPreDialogState = false;
- }
- }
- ////////////////////////////////////////////
- // called after items are edited and 'yes' is selected by user
- // when prompted to save changes
- //
- TBool CHXAvEditPlaylistDialog::SaveFormDataL()
- {
- DPRINTF(SYMP_INFO, ("CHXAvEditPlaylistDialog::SaveFormDataL(): writing filen"));
- // done with these...
- m_spRestoreList = 0;
- m_bListAlteredFromPreDialogState = true;
- m_bInEditMode = false;
- // write the file
- TInt offset = 0;
- m_file.Seek(ESeekStart, offset);
- ForEachEdwinL(&CHXAvEditPlaylistDialog::WriteUrlL);
- // set size based on current position
- offset = 0;
- m_file.Seek(ESeekCurrent, offset);
- m_file.SetSize(offset);
- // flush
- HXSYM_LEAVE_IF_ERR(m_file.Flush());
- return ETrue;
- }
- ////////////////////////////////////////////
- // called when you go back from edit mode and when switch to new item in the list
- void CHXAvEditPlaylistDialog::PrepareForFocusTransitionL()
- {
- DPRINTF(SYMP_INFO, ("CHXAvEditPlaylistDialog::PrepareForFocusTransitionL()n"));
- CAknForm::PrepareForFocusTransitionL();
- };
- ///////////////////////////////////////////
- //
- bool CHXAvEditPlaylistDialog::ForEachEdwinL(PMFNForEach pfn)
- {
- bool bGood = true;
- TInt idxPage = ActivePageId();
- TInt lineCount = GetNumberOfLinesOnPage(idxPage);
- for( TInt idx = 0; idx < lineCount; ++idx )
- {
- CEikCaptionedControl* pLine = GetLineByLineAndPageIndex(idx, idxPage);
- HX_ASSERT( (pLine->iId >= EIdFirstLine) && (pLine->iId < m_idNextItem) );
- CEikEdwin* pEdwin = reinterpret_cast<CEikEdwin*>(pLine->iControl);
- bGood = (this->*pfn)(idx, pEdwin);
- if( !bGood )
- {
- break;
- }
- }
- return bGood;
- }
- ///////////////////////////////////////////
- //ForEachEdwinL helper
- bool CHXAvEditPlaylistDialog::VerifyUrlL(TInt /*idx*/, CEikEdwin* pEdwin)
- {
- bool bIsValid = false;
- HBufC* pText = pEdwin->GetTextInHBufL();
- if(pText)
- {
- AUTO_PUSH_POP_DEL(pText);
- bIsValid = CHXAvUtil::IsValidUrl(*pText);
- if(!bIsValid)
- {
- DPRINTF(SYMP_INFO, ("CHXAvEditPlaylistDialog::VerifyUrl(): bad url: %sn", dbg::CharPtr(*pText)()));
- }
- }
- return bIsValid;
- }
- ///////////////////////////////////////////
- //ForEachEdwinL helper
- bool CHXAvEditPlaylistDialog::AppendRestoreListL(TInt /*idx*/, CEikEdwin* pEdwin)
- {
- HX_ASSERT(m_spRestoreList);
- HBufC* pText = pEdwin->GetTextInHBufL();
- if(pText)
- {
- AUTO_PUSH_POP_DEL(pText);
- m_spRestoreList->AppendL(*pText); // this copies buffer
- }
- else
- {
- m_spRestoreList->AppendL(KNullDesC);
- }
- return true;
- }
- ///////////////////////////////////////////
- //ForEachEdwinL helper
- bool CHXAvEditPlaylistDialog::RestoreItemL(TInt idx, CEikEdwin* pEdwin)
- {
- HX_ASSERT(idx < m_spRestoreList->MdcaCount());
- TPtrC ptr = m_spRestoreList->MdcaPoint(idx);
- pEdwin->SetTextL(&ptr);
- return true;
- }
- ////////////////////////////////////////////
- // save list of items before going into edit-text-mode state,
- // in case we need to revert back; once in edit mode, user can
- // 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 itemsn"));
- 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 itemsn"));
- // 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 %dn", 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;
- }