chxavplayerui.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:41k
- /****************************************************************************
- * chxavplayerui.cpp
- * -----------------
- *
- * Synopsis:
- *
- * CHXAvPlayerUI derives from CAknViewAppUI. It manages the views (main view,
- * file list view, etc.).It contains UI helpers (info messes, notes) shared by
- * views and contains the implementation of UI commands that might be shared
- * among all views.
- *
- * Views themselves are persistent and wrap view windows. The view windows are
- * normally created/destroyed upon activation/deactivation of a view to save
- * resources.
- *
- *
- * Target:
- * Symbian OS
- *
- *
- * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
- *
- *****************************************************************************/
- #include <aknpopup.h>
- #include <akntitle.h>
- #include <stringloader.h>
- #include <eikenv.h>
- #include <bautils.h>
- #include <coemain.h>
- #include <bacntf.h> //CEnvironmentChangeNotifier
- //#include <hlplch.h>
- #include "chxavplayerdoc.h"
- #include "chxavvector.h"
- #include "player_uids.h"
- #include "chxavviewbase.h"
- #include "chxavplayer.h"
- #include "chxavfileview.h"
- #include "chxavplayview.h"
- #include "realplayer.rsg"
- #include "realplayer.hrh"
- #include "chxavutil.h"
- #include "chxavmisc.h"
- #include "chxavurllist.h"
- #include "chxavurlrep.h"
- #include "chxavurlinfo.h"
- #include "chxaveditplaylistdialog.h"
- #include "chxavstringutils.h"
- #include "chxavcleanstring.h"
- #include "chxavmessagedialog.h"
- #include "chxavrecentclipspopuplist.h"
- #include "chxavcleanupstack.h"
- #include "chxavplayerui.h"
- #include "chxavconfignames.h"
- #include "chxavmediafolderinfo.h"
- #include "chxavclipinfolist.h"
- #include "chxavsettingsview.h"
- #include "chxavselectsettingsview.h"
- #include "comptr_traits.h"
- #include "hxsym_debug.h"
- #include "hxsym_leaveutil.h"
- #include "hxsym_mmc_utils.h"
- #include "....symbianplayer.ver"
- #include "chxavaccesspointdb.h"
- #include <hal.h>
- #define NOKIA_7650 270487491
- namespace
- {
- //
- // enums for various shared data keys (see shareddatakeys.h):
- //
- //KSysApLightsControl
- enum BacklightState
- {
- BacklightNormal = 0,
- BacklightDisplayOn = 1, // keypad only on if needeed (depends on grip's state and light sensor)
- BacklightAlwaysOn = 2 // keypad forced on all the time
- };
- //KSysApMessageToneQuit
- enum MessageToneState
- {
-
- MessageTonesOff = 0,
- MessageTonesOn = 1
- };
- //KSysAudioStatus
- enum AudioStatus
- {
- AudioStatusNull = 0,
- AudioStatusPlaying = 1,
- AudioStatusRecording = 2
- };
- //KSysApAlarmLightActive
- enum AlarmLightState
- {
- AlarmNotFlashing = 0,
- AlarmFlashing = 1
- };
- /*
- * AllocAboutTextL
- * ---------------
- *
- */
- HBufC* AllocAboutTextL()
- {
- // load descriptors from char*
- CHXAvCleanString buildDate(__DATE__);
- CHXAvCleanString buildTime(__TIME__);
- CHXAvCleanString version(TARVER_STRING_VERSION);
- CHXAvCleanString buildName(TARVER_STR_BUILD_NAME);
- CHXAvCleanString profile(makestr(SYMBIANPLAYER_INSTALL_NAME));
-
- // load about resources
- CHXAvCleanString copyText(R_ABOUT_COPYRIGHT_TEXT);
- CHXAvCleanString voiceAgeText(R_ABOUT_VOICE_AGE_TEXT);
- CHXAvCleanString versionText(R_ABOUT_VERSION, version());
- CHXAvCleanString dateText(R_ABOUT_BUILD_DATE, buildDate());
- CHXAvCleanString timeText(R_ABOUT_BUILD_TIME, buildTime());
-
-
- // calculate buffer needed for full about text
- TUint32 cchTotal = copyText().Length()
- + voiceAgeText().Length()
- + versionText().Length()
- + buildName().Length()
- + profile().Length()
- + dateText().Length()
- + timeText().Length()
- ;
- // add for formatting spaces (newlines)
- cchTotal += 20;
- HBufC* pbuff = HBufC::NewL(cchTotal);
- AUTO_PUSH_POP(pbuff);
- TPtr ptr = pbuff->Des();
-
- // build text
- _LIT(KParagraphBreak, "nn");
- // version: xxx
- ptr.Copy(versionText());
- // date: xxx
- ptr.Append(KNewLine());
- ptr.Append(dateText());
- // time: xxx
- ptr.Append(KNewLine());
- ptr.Append(timeText());
-
- // build name
- if( buildName().Length() > 0)
- {
- ptr.Append(KNewLine());
- ptr.Append(buildName());
- }
- // profile
- ptr.Append(KNewLine);
- ptr.Append(profile());
- // copyright
- ptr.Append(KParagraphBreak());
- ptr.Append(copyText());
-
- // voice age
- ptr.Append(KParagraphBreak());
- ptr.Append(voiceAgeText());
-
- return pbuff;
- }
- /////////////////////////////////////////////////
- // helper
- CHXString GetRecentClipsFileName()
- {
- TFileName* pFullPathRecentClips = CHXAvFile::AllocAppFolderPathL(CHXAvUtil::KPlayerDataFolder);
- AUTO_PUSH_POP_DEL(pFullPathRecentClips);
- CHXAvFile::AppendPath(*pFullPathRecentClips, KRecentClipsName, CHXAvFile::ntFile);
- CHXString str = CHXAvStringUtils::DescToString(*pFullPathRecentClips);
- return str;
- }
- } // ns anon
-
- ////////////////////////////////////////////////
- // CEnvironmentChangeNotifier callback
- TInt HandleEnvChange_(TAny* p)
- {
- // forward this to the ui
- CHXAvPlayerUI* pUI = reinterpret_cast<CHXAvPlayerUI*>(p);
- pUI->HandleEnvChange();
- return EFalse; // don't call again
- }
- ////////////////////////////////////////////////
- //
- void CHXAvPlayerUI::HandleEnvChange()
- {
- HX_ASSERT(m_pEnvChange);
- TInt change = m_pEnvChange->Change();
- if( m_bIgnoreFirstEnvChange )
- {
- // ignore:
- //
- // this is an immediate notification sent after we initially request environment
- // change events; in this case 'change' has bits set for all event notifications
- // that we can receive
- //
- m_bIgnoreFirstEnvChange = false;
- }
- else if( EChangesOutOfMemory & change )
- {
- //
- // OOM:
- //
- // Helix core typically ends up in a weird state after allocation failure
- // because it does not expect/handle leave, so we just display error dialog
- // (if possible) and close app.
- //
- // free some reserve memory we allocated up front
- m_spMemoryReserve = 0;
- TRAPD(err, CHXAvMessageDialog::DoSystemErrorNoteL(KErrNoMemory));
- CloseApp();
- #if(0)
- // if play view is active
- CHXAvViewBase *pView = static_cast<CHXAvViewBase *>(iView);
- CHXAvPlayView* pPlayView = GetPlayView();
- if(pPlayView->Id() == pView->Id())
- {
- //pPlayView->FreeMemoryReserve();
- User::CompressAllHeaps();
- TRAP(err, DoBackFromCurrentViewL());
- if(KErrNone != err)
- {
- CloseApp();
- }
- }
- #endif
- }
- }
- /*
- * CHXAvPlayerUI
- * -------------
- * Player ui constructor.
- *
- */
- CHXAvPlayerUI::CHXAvPlayerUI()
- : m_recentClips(0)
- , m_pPrefChangeObserver(0)
- , m_bIsRunningEmbedded(false)
- , m_bLaunchAppWithClipPending(false)
- , m_pEnvChange(0)
- , m_bIgnoreFirstEnvChange(true)
- //, m_bIsActivePlaybackState(false)
- //, m_bDidScreenSaverSignal(false)
- //, m_pPinbModel(0)
- //, m_sysSdClient(this)
- //, m_sysApSdClient(this)
- {
- }
- /*
- * ~CHXAvPlayerUI
- * --------------
- * Player ui destructor.
- *
- */
- CHXAvPlayerUI::~CHXAvPlayerUI()
- {
- DPRINTF(SYMP_INFO, ("CHXAvPlayerUI::Dtor()n"));
- //m_sysSdClient.Close();
- //m_sysApSdClient.Close();
- HX_DELETE(m_pEnvChange);
- }
- /*
- * ConstructL
- * ----------
- * Perform all view object construction and anything else
- * needed for this class.
- *
- */
- void
- CHXAvPlayerUI::ConstructL()
- {
- DPRINTF(SYMP_INFO, ("CHXAvPlayerUI::ConstructL()n"));
- BaseConstructL();
- // only allow one ui instance
- EnsureUniqueInstanceL();
- // load client engine and services
- m_spEngineMgr = new (ELeave) CHXClientEngineManager();
- m_spEngineMgr->ConstructL();
- CHXAvPlayerDoc* pDoc = static_cast<CHXAvPlayerDoc*>(Document());
- pDoc->SetEngineManager(m_spEngineMgr);
- // reserve some memory to help with OOM handling
- const TUint K_MEMORY_RESERVE_BYTES = 0x0400 * 4; // 4K
- m_spMemoryReserve = HBufC::NewL(K_MEMORY_RESERVE_BYTES);
- // enable focus events so we can watch when focus window group changes
- RWindowGroup& rootWin = iCoeEnv->RootWin();
- rootWin.EnableFocusChangeEvents();
- //
- // two shared data client connections are needed because signals are auto-
- // canceled when you switch among shared data files
- //
- #if(0)
- // for enabling/disabling screen saver
- HXSYM_LEAVE_IF_ERR(m_sysSdClient.Connect());
- HXSYM_LEAVE_IF_ERR(m_sysSdClient.AssignToTemporaryFile(KSDUidSystem));
- // for enabling/disabling backlight
- HXSYM_LEAVE_IF_ERR(m_sysApSdClient.Connect());
- HXSYM_LEAVE_IF_ERR(m_sysApSdClient.AssignToTemporaryFile(KSDUidSysAp));
- m_sysSdClient.NotifyChange(KSDUidSystem);
- m_sysApSdClient.NotifyChange(KSDUidSysAp);
- // for "add to pinboard"
- m_pPinbModel = CPinbModel::NewL();
- #endif
- // locate full path to app image file
- m_spImageFilePath = CHXAvFile::AllocAppFolderPathL(CHXAvUtil::KImagesMBMName);
- // recent clips
- UINT32 maxRecentClipCount = prefs::GetUINT32(m_spEngineMgr->GetPrefs(), CHXAV_MaxRecentClipCount, 6);
- m_recentClips = new (ELeave) CHXAvURLList(maxRecentClipCount);
- m_recentClips->InitializeL();
- m_recentClips->ReadFile(GetRecentClipsFileName());
- // media store
- UpdateMediaStoreInfoL();
-
- // views
- CHXAvPlayView* pPlayerView = new (ELeave) CHXAvPlayView(VID_PlayerView, this);
- AUTO_PUSH_POP(pPlayerView);
- pPlayerView->ConstructL();
-
- CHXAvFileView* pFileView = new (ELeave) CHXAvFileView(VID_FileView, this);
- AUTO_PUSH_POP(pFileView);
- pFileView->ConstructL();
-
- CHXAvSettingsView *pSettingsView = new (ELeave) CHXAvSettingsView(VID_SettingsView, this);
- AUTO_PUSH_POP(pSettingsView);
- pSettingsView->ConstructL();
- CHXAvSelectSettingsView *pSelectSettingsView = new (ELeave) CHXAvSelectSettingsView(VID_SelectSettingsView, this);
- AUTO_PUSH_POP(pSelectSettingsView);
- pSelectSettingsView->ConstructL();
- // determine default view; add default view first
- m_bIsRunningEmbedded = ContainerAppUi() || iDoorObserver;
- DPRINTF(SYMP_INFO, ("CHXAvPlayerUI::ConstructL(): embedded = '%s'n", dbg::Bool(m_bIsRunningEmbedded)));
- if(m_bIsRunningEmbedded)
- {
- // embedded; start with player view
- m_idxDefaultView = VID_PlayerView;
- AddViewL(pPlayerView);
- AddViewL(pFileView);
- AddViewL(pSettingsView);
- AddViewL(pSelectSettingsView);
- SetDefaultViewL(*pPlayerView);
- }
- else
- {
- // not embedded; start with file view
- m_idxDefaultView = VID_FileView;
- AddViewL(pFileView);
- AddViewL(pPlayerView);
- AddViewL(pSettingsView);
- AddViewL(pSelectSettingsView);
-
- SetDefaultViewL(*pFileView);
- }
- // register to receive environment change notifications (for OOM)
- m_bIgnoreFirstEnvChange = true;
- HX_ASSERT(!m_pEnvChange);
- TCallBack cb(HandleEnvChange_, this);
- m_pEnvChange = CEnvironmentChangeNotifier::NewL(CActive::EPriorityHigh, cb);
- m_pEnvChange->Start();
-
- }
- bool CHXAvPlayerUI::EnsureUniqueInstanceHelperL()
- {
- DPRINTF(SYMP_INFO, ("CHXAvPlayerUI::EnsureUniqueInstanceHelperL(): acquiring instance token..."));
- bool bGotIt = m_instanceToken.TryAcquire();
- if( !bGotIt )
- {
- DPRINTF(SYMP_INFO, ("CHXAvPlayerUI::EnsureUniqueInstanceHelperL(): failed to acquire token (another app is running); broadcasting close..."));
- // another instance has the instance token
- //
- // send message to other instances to request that it stop and exit
- //
-
- //
- // broadcast 'close' message for other instance to see; other instances
- // receive this message via HandleApplicationSpecificEventL()
- //
- // we broadcast a close message to all apps because it is hard
- // to find embedded instances
- //
- HBufC8* pMsg = CHXAvMisc::MakeHXPlayerPrivateMessageL(KMessage_CloseApp);
- AUTO_PUSH_POP_DEL(pMsg);
- CHXAvMisc::BroadcastWsEventL(KHXPlayerWsEvent, pMsg);
-
- //
- // wait ~5 seconds for other instance
- // to close down before we give up
- //
- const TUint k_maxTryCount = 10;
- const TUint k_msBetweenAttempts = 500;
- const TUint k_showMessageTryIndex = 3; // show mesage after 3 tries (1.5 secs)
- for( TInt tryCount = 0; tryCount < k_maxTryCount && !bGotIt; ++tryCount)
- {
- // wait a bit before next attempt to try to acquire the token; use custom wait so dialogs have chance to draw
- CHXAvUtil::ActiveWait(k_msBetweenAttempts);
- //User::After(k_msBetweenAttempts * k_usecPerMs);
- bGotIt = m_instanceToken.TryAcquire();
- if( !bGotIt && (k_showMessageTryIndex == tryCount) )
- {
- // show note to user that we are shutting down other instance
- HX_ASSERT(m_spCloseAppWaitNote);
- m_spCloseAppWaitNote->StartAndKickL();
- }
- }
- m_spCloseAppWaitNote->EndL();
- if( !bGotIt )
- {
- CHXAvMessageDialog::DoAlertErrorL(CHXAvCleanString(R_AVP_N_FAILED_TO_CLOSE_OTHER_INSTANCE)());
- }
-
- }
- return bGotIt;
- }
- /*
- * EnsureUniqueInstanceL
- * ------------
- * ensure that we close any other app instances
- * that might be running
- *
- */
- void CHXAvPlayerUI::EnsureUniqueInstanceL()
- {
- m_spCloseAppWaitNote = new (ELeave) CHXAvWaitNote();
- m_spCloseAppWaitNote->SetTextL(CHXAvCleanString(R_AVP_N_CLOSING_OTHER_INSTANCE)());
- // token name for controlling single instance
- _LIT(KUniqueInstanceSemName, "HelixPlayer10009D06");
- m_instanceToken.ConstructL(KUniqueInstanceSemName);
- if(!EnsureUniqueInstanceHelperL())
- {
- DPRINTF(SYMP_INFO, ("CHXAvPlayerUI::EnsureUniqueInstanceL(): other instance failed to close"));
- HXSYM_LEAVE(KLeaveWithoutAlert);
- }
- }
- ////////////////////////////////////////////
- //
- TBool CHXAvPlayerUI::ProcessCommandParametersL(TApaCommand idCmd,
- TFileName& aDocumentName,
- const TDesC8& /*aTail*/)
- {
- DPRINTF(SYMP_INFO, ("CHXAvPlayerUI::ProcessCommandParametersL(%d))n", idCmd));
- DPRINTF(SYMP_INFO, ("doc = '%s'n", dbg::CharPtr(aDocumentName)()));
- // this (call to 2-arg override) causes doc name to be given a new name
- // return CAknViewAppUi::ProcessCommandParametersL(idCmd, aDocumentName);
-
- // this (default) results in CEikDocument::OpenFileL not being called
- // return CAknViewAppUi::ProcessCommandParametersL(idCmd, aDocumentName, aTail);
- // ensures that CEikDocument::OpenFileL is called if a command line arg was provided
- return EFalse;
-
- }
- ////////////////////////////////////////////
- // get here if:
- //
- // o click on file in file browser (while our app is running)
- // o click on app in file browser (while our app is running)
- // o someone calls TApaTask::SwitchOpenFile()
- // o our document calls us because it gets the openfile request
- //
- // all external ways of getting an argument, file, etc. end up
- // here
- //
- // fileArg can be in local path form ('c:myfolderfile.rm') or
- // url form ('rtsp://dfsd/sdf/foo.rm')
- //
- void CHXAvPlayerUI::OpenFileL(const TDesC& fileArg)
- {
- DPRINTF(SYMP_INFO,("avPlayerUI::OpenFileL(): '%s'n", dbg::CharPtr(fileArg)()));
-
- bool bIsUrl = CHXAvUtil::IsValidUrl(fileArg);
- if( bIsUrl )
- {
- // an URL was passed as the argument
- ActivatePlayViewL(fileArg);
- }
- else
- {
- // local file (most likely case)
- HBufC* pFile = CHXAvFile::AllocFileUrlL(fileArg);
- AUTO_PUSH_POP_DEL(pFile);
- ActivatePlayViewL(*pFile);
- }
- }
- #if(0)
- /*
- * CAknViewAppUi::HandleForegroundEventL
- * ----------------------
- *
- * Called when app gains/looses foreground (not when app views are switching)
- *
- */
- void CHXAvPlayerUI::HandleForegroundEventL(TBool bEnterForeground)
- {
- DPRINTF(SYMP_INFO, ("CHXAvPlayerUI::HandleForegroundEventL(): enter = '%s'n", dbg::Bool(bEnterForeground)));
- CAknViewAppUi::HandleForegroundEventL(bEnterForeground);
- }
- #endif
- /*
- * CAknViewAppUi::HandleViewDeactivation
- * ----------------------
- * Switch views. Set the correct back view index for future switches.
- * This is called, then DoActivate for new view, then DoDeactivate for old view.
- */
- void
- CHXAvPlayerUI::HandleViewDeactivation(const TVwsViewId& idOldView, const TVwsViewId& idNewView)
- {
- DPRINTF(SYMP_INFO, ("CHXAvPlayerUI::HandleViewDeactivation()n"));
- bool bIsInterAppViewSwitch = (idOldView.iAppUid != idNewView.iAppUid);
- if(!bIsInterAppViewSwitch)
- {
- // Activating another view in our own app...
- HX_ASSERT(idOldView.iAppUid == CHXAvMisc::KAppUID);
- TUid idNew = idNewView.iViewUid;
- TUid idOld = idOldView.iViewUid;
- // special case: if settings view is activating, tell player view not
- // to shut down the player so return gets user back to previous player state
- if(idOld == TUid::Uid(VID_PlayerView) && idNew == TUid::Uid(VID_SelectSettingsView))
- {
- CHXAvPlayView* pPlayView = GetPlayView();
- pPlayView->SetShutdownOnViewDeactivation(false);
- }
- CHXAvViewBase * pNewView = static_cast<CHXAvViewBase *>(View(idNew));
- CHXAvViewBase * pOldView = static_cast<CHXAvViewBase *>(View(idOld));
- HX_ASSERT(pNewView);
- HX_ASSERT(pOldView);
- DPRINTF(SYMP_INFO, ("CHXAvPlayerUI::HandleViewDeactivation(): old = %d; new = %dn", idOld.iUid, idNew.iUid));
-
- if( idNew == TUid::Uid(m_idxDefaultView) )
- {
- // Default view is activating; there is no "last view" to go back to...
- pNewView->SetBackView(-1);
- }
- else
- {
- // Do nothing if returning back to old view that 'launched' the new (now becoming old) view...
- bool bReturning = (pOldView->GetBackView() == pNewView->Id().iUid);
- // Don't set back view to self...
- bool bSame = (pNewView->Id() == pOldView->Id());
- if(!bReturning && !bSame)
- {
- pNewView->SetBackView(pOldView->Id().iUid);
- }
- }
- }
- CAknViewAppUi::HandleViewDeactivation(idOldView, idNewView);
- }
- /*
- * DoBackFromCurrentViewL
- * ----------------------
- * Go back to the previous view from here.
- *
- */
- void
- CHXAvPlayerUI::DoBackFromCurrentViewL()
- {
- HX_ASSERT(iView);
- CHXAvViewBase *pView = static_cast<CHXAvViewBase *>(iView);
- TInt idxBackView = pView->GetBackView();
- DPRINTF(SYMP_INFO, ("CHXAvPlayerUI::DoBackFromCurrentViewL(): back view = %dn", idxBackView));
- if (idxBackView == -1)
- {
- // If there's no view to go back to, exit...
- HX_ASSERT( TUid::Uid(m_idxDefaultView) == iView->Id());
- HandleCommandL(EEikCmdExit);
- }
- else
- {
- // note: call to base class is intentional
- HX_ASSERT( TUid::Uid(m_idxDefaultView) != iView->Id());
- ActivateLocalViewL(TUid::Uid(idxBackView));
- }
- }
- ////////////////////////////////////////
- // TWsEvent beyond EEventUser received...
- void CHXAvPlayerUI::HandleApplicationSpecificEventL(TInt aType,const TWsEvent& aEvent)
- {
- DPRINTF(SYMP_INFO, ("CHXAvPlayerUI::HandleApplicationSpecificEventL(): type = %dn", aType));
- // handle possible shutdown command coming from TWsEvent that we send
- if(aType == KHXPlayerWsEvent)
- {
- TUint8* pData = aEvent.EventData();
- if( pData )
- {
- TPtr8 msg(pData, TWsEvent::EWsEventDataSize);
- DPRINTF(SYMP_INFO, ("HandleApplicationSpecificEventL(): message is '%.*s'n", msg.Length(), msg.Ptr()));
-
- // make sure it is not from this thread
- HBufC8* pMsg = MakeHXPlayerPrivateMessageL(KMessage_CloseApp);
- AUTO_PUSH_POP_DEL(pMsg);
- // message will compare equal if it is a close app message from another instance
- if( 0 != pMsg->Compare(msg) )
- {
- DPRINTF(SYMP_INFO, ("HandlePossibleShutdownCommandL(): closing instancen"));
- CloseApp();
- }
- }
- }
- }
- /*
- * HandleCommandL
- * --------------
- * These are commands that are shared (or conceivably can be shared) among
- * several of the views
- *
- */
- void
- CHXAvPlayerUI::HandleCommandL(TInt aCommand)
- {
- switch (aCommand)
- {
- case EAknCmdExit:
- case EEikCmdExit:
- case EAknSoftkeyExit:
- CloseApp();
- break;
- case EAknSoftkeyBack:
- DoBackFromCurrentViewL();
- break;
- case EOpenGuide:
- DoOpenGuideL();
- break;
- case EViewSettings:
- DoSelectSettingsL();
- break;
- case EAboutDialog:
- DoAboutL();
- break;
- case EOpenRecentDialog:
- DoOpenRecentL();
- break;
- case EOpenURLDialog:
- DoOpenURLL();
- break;
-
- case ERestoreDefaultSettings:
- DoRestoreDefaultSettingsL();
- break;
- case EAknCmdHelp:
- //HlpLauncher::LaunchHelpApplicationL( iCoeEnv->WsSession(), AppHelpContextL() );
- break;
- default:
- // we don't expect any other commands (except possibly a click on an empty softkey)
- HX_ASSERT(EAknSoftkeyEmpty == aCommand);
- break;
- }
- }
- ////////////////////////////////////////////////////////////////
- // restore config to installation default
- void CHXAvPlayerUI::DoRestoreDefaultSettingsL()
- {
- if(CHXAvMessageDialog::DoQueryL(R_CONF_RESTORE_SETTINGS))
- {
- // user confirmed...
- comptr<CHXLitePrefs> spPrefs = m_spEngineMgr->GetPrefs();
- spPrefs->ResetPrefs(); //XXXLCM can fail
- if( m_pPrefChangeObserver )
- {
- m_pPrefChangeObserver->OnPrefsChanged();
- }
- CHXAvMessageDialog::DoAlertConfirmL(CHXAvCleanString(R_SETTINGS_RESTORED)());
- }
- }
- /*
- * DoSelectSettingsL
- * -----------------
- * Show the select settings view.
- *
- */
- void CHXAvPlayerUI::DoSelectSettingsL()
- {
- // prepare select settings view to launch with first item hilighted
- CAknView* pView = View(TUid::Uid(CHXAvPlayerUI::VID_SelectSettingsView));
- HX_ASSERT(pView);
- CHXAvSelectSettingsView* pSelectView = static_cast<CHXAvSelectSettingsView*>(pView);
- pSelectView->ResetCurrentIndex();
- ActivateLocalViewL(TUid::Uid(VID_SelectSettingsView));
- }
- ////////////////////////////////////////
- //
- void
- CHXAvPlayerUI::DoEditPlaylistL(const TDesC& playlistPath)
- {
- DPRINTF(SYMP_INFO, ("CHXAvPlayerUI::DoEditPlaylistL()n"));
- CHXAvEditPlaylistDialog* pDlg = new (ELeave) CHXAvEditPlaylistDialog();
- TInt err = KErrNone;
- // save cleanupstack init until LD
- {
- AUTO_PUSH_POP(pDlg);
- pDlg->ConstructL();
- // make sure read-only is clear so we can edit (we don't honor this attribute)
- CHXAvFile::EnsureClearReadOnlyAttributeL(playlistPath);
- err = pDlg->SetPlaylistL(playlistPath);
- }
- if(KErrNone == err)
- {
- pDlg->ExecuteLD(R_AVP_EDIT_PLAYLIST_DLG);
- }
- else
- {
- HX_DELETE(pDlg); // <-- since dialog will not delete itself
- CHXAvMessageDialog::DoAlertErrorL(CHXAvCleanString(R_ERR_UNABLE_TO_EDIT_PLAYLIST)());
- }
- }
- /*
- * DoOpenGuideL
- * ------------
- * Open the guide.
- *
- */
- void
- CHXAvPlayerUI::DoOpenGuideL()
- {
- const TDesC& guideUrl = GetGuideUrlL(false);
- TInt err = KErrGeneral;
- if( guideUrl.Length() > 0 )
- {
- const TInt KWmlBrowserUid = 0x10008D39;
-
- // format web browser message
- _LIT(KOpenUrlMessagePrefix, "4 ");
- TInt cchTotal = guideUrl.Length() + CHXAvUtil::litSize(KOpenUrlMessagePrefix);
-
- HBufC* pBuf = HBufC::NewL(cchTotal);
- AUTO_PUSH_POP_DEL(pBuf);
- TPtr ptr = pBuf->Des();
- ptr.Copy(KOpenUrlMessagePrefix);
- ptr.Append(guideUrl);
- // launch app with message argument
- TRAP(err, CHXAvMisc::LaunchAppL(KWmlBrowserUid, *pBuf));
- }
- if(KErrNone != err)
- {
- //XXXLCM
- CHXAvMessageDialog::DoAlertInfoL(_L("unable to launch guide"));
- }
- }
- /*
- * CloseApp
- * --------
- * Called when we receive exit command (from user or via system message)
- *
- */
- void
- CHXAvPlayerUI::CloseApp()
- {
- // Write out the recent clips and release...
- HX_ASSERT(m_recentClips);
- if (m_recentClips)
- {
- m_recentClips->WriteFile(GetRecentClipsFileName());
- }
- // this prevents mms app from hanging when we exit
- if(iDoorObserver)
- {
- iDoorObserver->NotifyExit(MApaEmbeddedDocObserver::EEmpty);
- }
- // Now we can exit...
- Exit();
- }
- ////////////////////////////
- //HandleWsEventL
- void CHXAvPlayerUI::HandleWsEventL(const TWsEvent& event, CCoeControl* pDest)
- {
- DPRINTF(SYMP_WSEVENTS, ("CHXAvPlayerUI::HandleWsEventL(): type = %ld; dest = 0x%08xn", event.Type(), pDest));
- switch(event.Type())
- {
- case EEventKeyUp:
- {
- DPRINTF(SYMP_WSEVENTS, ("CHXAvPlayerUI::HandleWsEventL(): key up eventn"));
- TKeyEvent* pKey = event.Key();
- if(pKey)
- {
- CHXAvViewBase *pActiveView = static_cast<CHXAvViewBase *>(iView);
- if(pActiveView)
- {
- //
- // special case: for some reason the left-shift up is not received by the CCoeControl
- // if you click on a softkey while the shift key is held down before releasing the shift key
- //
-
- // XXXLCM we should probably do more to avoid double-event notification
- if( pKey->iScanCode == EStdKeyLeftShift)
- {
- DPRINTF(SYMP_INFO, ("CHXAvPlayerUI::HandleWsEventL(): got shift key up eventn"));
- pActiveView->GetWindow()->OfferKeyEventL(*pKey, EEventKeyUp);
- }
- }
- }
- }
- break;
- case EEventFocusGroupChanged:
- {
- DPRINTF(SYMP_WSEVENTS, ("CHXAvPlayerUI::HandleWsEvent(): focus group changen"));
- TInt wgidFocus = iEikonEnv->WsSession().GetFocusWindowGroup();
- TUid uidFocus = CHXAvMisc::GetAppUidFromWgId(wgidFocus);
- bool bNeedToStopPlayback = !(uidFocus == CHXAvMisc::KScreenSaverUID ||
- uidFocus == CHXAvMisc::KAppUID );
- if( bNeedToStopPlayback )
- {
- DPRINTF(SYMP_WSEVENTS, ("CHXAvPlayerUI::HandleWsEvent(): new app focus is not screen saver or playern"));
- CHXAvViewBase* pActiveView = static_cast<CHXAvViewBase *>(iView);
- if( pActiveView )
- {
- pActiveView->HandleLosePlayFocus();
- }
- }
- }
- break;
- default:
- break;
- }
- CAknViewAppUi::HandleWsEventL(event, pDest);
- }
- ////////////////////////////////////
- // ensure play view is activated and attempt to play clip
- //
- void CHXAvPlayerUI::ActivatePlayViewL(const TDesC& url)
- {
- DPRINTF(SYMP_INFO, ("CHXAvPlayerUI::ActivatePlayViewL(): current view exists = '%s' n", dbg::Bool(iView)));
- if( iView && (TUid::Uid(VID_PlayerView) == iView->Id()) )
- {
- // play view is active view
- CHXAvPlayer* pPlayer = GetPlayer();
- HX_ASSERT(pPlayer);
- pPlayer->Play(url);
- }
- else
- {
- // we need to activate play view
- CHXAvPlayView* pPlayView = GetPlayView();
- // set clip to launch on view activation (view activates asynchronously)
- pPlayView->SetViewActivateClipL(url);
- //
- // Activate player view if not in process of app
- // startup (see OnViewForegroundActivateL()).
- // Otherwise wait for default view (file view) to launch.
- //
- // iView becomes non-0 sometime after first foreground event
- // for first activating view
- //
- m_bLaunchAppWithClipPending = (0 == iView);
- if( !m_bLaunchAppWithClipPending )
- {
- ActivateLocalViewL(TUid::Uid(VID_PlayerView));
- }
- }
- }
- //
- // Called when view receives first foreground event after activation
- //
- void CHXAvPlayerUI::OnViewForegroundActivateL(TInt idxView)
- {
- DPRINTF(SYMP_INFO, ("CHXAvPlayerUI::OnViewForegroundActivateL(): current view id = %dn", idxView));
- //
- // If this app instance was launched with a clip we get a call
- // to OpenFileL() before the default view (i.e., file view in
- // stand-alone launch case) is activated. If we activate the
- // player view at that time, the default view will immediately
- // activate after that (and yours truly has not found a good way
- // to prevent this). So to work around this, we wait for the default
- // view to activate before activating the play view.
- //
- if ( (VID_PlayerView != idxView) && m_bLaunchAppWithClipPending)
- {
- ActivateLocalViewL(TUid::Uid(VID_PlayerView));
- }
- m_bLaunchAppWithClipPending = false;
- }
- CHXAvPlayView* CHXAvPlayerUI::GetPlayView()
- {
- CHXAvPlayView* pPlayView = (CHXAvPlayView *)(View(TUid::Uid(VID_PlayerView)));
- HX_ASSERT(pPlayView);
- return pPlayView;
- }
- // player will be NULL if play view not activated
- comptr<CHXAvPlayer> CHXAvPlayerUI::GetPlayer()
- {
- CHXAvPlayView* pPlayView = GetPlayView();
- CHXAvPlayer* pPlayer = pPlayView->GetPlayer();
- HX_ASSERT(pPlayer);
- return pPlayer;
- }
- /*
- * DoAboutL
- * --------
- * Do about screen.
- *
- */
- void
- CHXAvPlayerUI::DoAboutL()
- {
- HBufC* pText = AllocAboutTextL();
- AUTO_PUSH_POP_DEL(pText);
- CHXAvMessageDialog::DoLongTextInfoPromptL(CHXAvCleanString(R_ABOUT_CAPTION)(), *pText, CHXAvMessageDialog::PromptBack);
- }
- /*
- * DoOpenURLL
- * ----------
- * Show the open url dialog.
- *
- */
- void
- CHXAvPlayerUI::DoOpenURLL()
- {
- CHXAvCleanString promptText(R_PROMPT_ENTER_URL);
-
- //
- // keep prompting until user: a) cancels; or b) enters a valid URL
- //
-
- for(;;)
- {
- HBufC* pDefaultText = 0;
- if(m_lastClipEntered.IsEmpty())
- {
- // fill with default protocol prefix
- pDefaultText = CHXAvUtil::KRTSPProtocolPrefix().AllocL();
- }
- else
- {
- // fill with last text entered by the user
- pDefaultText = CHXAvStringUtils::AllocTextL(m_lastClipEntered);
- }
- AUTO_PUSH_POP_DEL(pDefaultText);
- // Query the user for the url...
- HBufC* pUrl = CHXAvMessageDialog::DoQueryTextL(promptText(), *pDefaultText, KMaxFileName);
- if (pUrl != NULL)
- {
- AUTO_PUSH_POP_DEL(pUrl);
-
- // remember what user entered (even if it turns out to be bad)
- CHXAvStringUtils::DesToString(*pUrl, m_lastClipEntered);
- ValidateUrlResult res = ValidateUrl(*pUrl);
- if (CHXAvUtil::vuGood == res)
- {
- ActivatePlayViewL(*pUrl);
- break;
- }
- else if(CHXAvUtil::vuMissingScheme == res)
- {
- //
- // no scheme
- //
- // try with 'rtsp' or 'file' appended, depending on whether url looks
- // like a local or remote url
- //
- HBufC* pAlt = 0;
- TInt idxDrive = CHXAvFile::GetDriveIndex(*pUrl);
- if(-1 != idxDrive)
- {
- // begins with a drive letter, looks like a file path...
- pAlt = CHXAvFile::AllocFileUrlL(*pUrl);
- }
- else
- {
- // guess that this is a remote rtsp URL...
- pAlt = CHXAvStringUtils::AllocTextL(KRTSPProtocolPrefix, *pUrl);
- }
- AUTO_PUSH_POP_DEL(pAlt);
- if(CHXAvUtil::IsValidUrl(*pAlt))
- {
- ActivatePlayViewL(*pAlt);
- break;
- }
- }
-
- // assume typo; let user edit and try again...
- CHXAvMessageDialog::DoAlertInfoL(CHXAvCleanString(R_ERR_INVALID_URL)());
- }
- else
- {
- // user cancelled
- break;
- }
- }
- }
- /*
- * DoOpenRecentL
- * -------------
- * Show the open recent url dialog. Launch the item that the user selected.
- *
- */
- void
- CHXAvPlayerUI::DoOpenRecentL()
- {
- if (m_recentClips->NumURLs() > 0)
- {
- TInt idxSelectedItem = 0;
-
- CHXAvRecentClipsPopupList* pPopup = new (ELeave) CHXAvRecentClipsPopupList(idxSelectedItem);
-
- // save cleanupstack init until LD
- {
- AUTO_PUSH_POP(pPopup);
- pPopup->ConstructL(m_recentClips.raw_ptr());
- }
- if (pPopup->ExecuteLD())
- {
- // Launch the item that the user selected
- if ((idxSelectedItem >= 0) && (idxSelectedItem < m_recentClips->NumURLs()))
- {
- ActivatePlayViewL((m_recentClips->GetURL(idxSelectedItem))->URL());
- }
- }
- }
- else
- {
- CHXAvMessageDialog::DoAlertInfoL(CHXAvCleanString(R_RECENT_CLIPS_EMPTY)());
- }
- }
- /*
- * GetMediaStoreInfoL
- * ------------------
- * Return the list of media information..
- *
- */
- const CHXAvVector<CHXAvMediaFolderInfoPtr>&
- CHXAvPlayerUI::GetMediaStoreInfoL(bool bForceUpdate)
- {
- if( 0 == m_mediaStoreInfo.Nelements() || bForceUpdate )
- {
- UpdateMediaStoreInfoL();
- }
- return m_mediaStoreInfo;
- }
- /*
- * UpdateMediaStoreInfoL
- * ---------------------
- * Rebuild media store list
- *
- */
- void CHXAvPlayerUI::UpdateMediaStoreInfoL()
- {
- m_mediaStoreInfo.Resize(0);
- CHXString strLocalMediaFolder = prefs::GetString(m_spEngineMgr->GetPrefs(),
- CHXAV_LocalMediaFolder);
- HXSYM_LEAVE_IF_TRUE(strLocalMediaFolder.IsEmpty());
- AppendMediaStoreInfoL(strLocalMediaFolder, CHXAvMediaFolderInfo::PATH_ENSURE);
- CHXString strMmcMediaFolder = prefs::GetString(m_spEngineMgr->GetPrefs(),
- CHXAV_MmcMediaFolder);
- if(!strMmcMediaFolder.IsEmpty())
- {
- //Do not try this on a 7650, It will crash the phone.
- TInt nModelNumber = 0;
- TInt nManufacture = 0;
- HAL::Get(HAL::EModel, nModelNumber);
- HAL::Get(HAL::EManufacturer, nManufacture);
- if( nManufacture != HAL::EManufacturer_Nokia || nModelNumber != NOKIA_7650 )
- {
- AppendMediaStoreInfoL(strMmcMediaFolder, CHXAvMediaFolderInfo::PATH_OPTIONAL);
- }
- }
- }
- /*
- * AppendMediaStoreInfoL
- * ---------------------
- * Here we create each media store, and call routines to find out what's in those locations.
- *
- */
- void
- CHXAvPlayerUI::AppendMediaStoreInfoL(const CHXString& strRootPath, CHXAvMediaFolderInfo::PathCreateType pathType)
- {
- TFileName* pPath = CHXAvFile::AllocFileNameL(CHXAvCleanString(strRootPath)(), CHXAvFile::ntFolder);
- AUTO_PUSH_POP_DEL(pPath);
- CHXAvMediaFolderInfoPtr spInfo = new (ELeave) CHXAvMediaFolderInfo();
- CHXAvUtil::Append(m_mediaStoreInfo, spInfo);
- spInfo->InitL(*pPath, pathType);
- }
- ////////////////////////////////////////
- //
- // Guide can be specified in config/preferences as:
- //
- // 1) local file name relative to local guide folder path
- // e.g., 'index.html', 'germanindex.wmlc'
- //
- // 3) http url
- // e.g., 'http://www.real.com/mobile/home.html'
- //
- // In either case this returns a properly formed 'file'
- // or 'http' url.
- //
- TPtrC CHXAvPlayerUI::GetGuideUrlL(bool bForceUpdate)
- {
- TPtrC out(KNullDesC);
- if( bForceUpdate )
- {
- // ensure url is reset
- m_spGuideUrl = 0;
- }
- if( !m_spGuideUrl )
- {
- DPRINTF(SYMP_INFO, ("GetGuideUrlL(): current locale is %dn", User::Language()));
- // look at 'guide'
- CHXString strGuide = prefs::GetString(m_spEngineMgr->GetPrefs(), CHXAV_Guide);
- if( !strGuide.IsEmpty() )
- {
- bool bLocalize = prefs::GetBool(m_spEngineMgr->GetPrefs(), CHXAV_GuideLocalize);
-
- // see if guide is specified as an 'http' url
- if(CHXAvUtil::IsHttpUrl(strGuide))
- {
- // assume config entry is valid http url...
- if( bLocalize )
- {
- // append '?locale=NN' to url to tell server to retrieve localized guide page
- _LIT(KQuestionMark, "?");
- _LIT(KGuideLocaleQuery, "locale=%d");
- const TLanguage locale = User::Language();
- CHXAvCleanString urlText(strGuide);
- CHXAvCleanString urlQuery(KGuideLocaleQuery, locale);
- m_spGuideUrl = CHXAvStringUtils::AllocTextL(urlText(), KQuestionMark, urlQuery());
- }
- else
- {
- m_spGuideUrl = CHXAvStringUtils::AllocTextL(strGuide);
- }
- }
- else
- {
- // looks like we are dealing with a local guide
-
- TFileName* pFullPathGuide = CHXAvFile::AllocFullPrefPathL(m_spEngineMgr->GetPrefs(), CHXAV_Guide);
- HXSYM_LEAVE_IF_FALSE(pFullPathGuide != 0);
- AUTO_PUSH_POP_DEL(pFullPathGuide);
- if(bLocalize)
- {
-
- // find localized version, based on TLanguage enum in extension (e.g., for '*.rsc', '*.r01' == English, '*.r10' == American, etc.)
- DPRINTF(SYMP_INFO, ("GetGuideUrlL(): default guide is '%s'n", dbg::CharPtr(*pFullPathGuide)()));
-
- // appears to require drive in path (despite docs); path is not modified if path is invalid
- BaflUtils::NearestLanguageFile(iCoeEnv->FsSession(), *pFullPathGuide);
- DPRINTF(SYMP_INFO, ("GetGuideUrlL(): localized guide is '%s'n", dbg::CharPtr(*pFullPathGuide)()));
- }
- // ensure path exists
- bool bExists = CHXAvFile::PathExists(*pFullPathGuide);
- HX_ASSERT(bExists);
- if(bExists)
- {
- // save path fixed up so it is a 'file:///' url
- m_spGuideUrl = CHXAvFile::AllocFileUrlL(*pFullPathGuide);
- }
- }
- }
- }
- if( m_spGuideUrl )
- {
- out.Set(*m_spGuideUrl);
- }
-
- DPRINTF(SYMP_INFO, ("GetGuideUrlL(): url is '%s'n", dbg::CharPtr(out)()));
- return out;
- }
- #if(0)
- ////////////////////////////////////////////////
- // shared data client notifier
- void CHXAvPlayerUI::HandleNotifyL(const TUid uid, const TDesC& key, const TDesC& val)
- {
- DPRINTF(SYMP_INFO, ("avPlayerUI::HandleNotifyL(): uid = 0x%08x, key = '%s', val = '%s'n", uid.iUid, dbg::CharPtr(key)(), dbg::CharPtr(val)()));
- // note: we should not get notifications in cases where we are the source of the change
- if(KSDUidSysAp == uid)
- {
- if (0 == key.CompareF(KSysApLightsControl))
- {
- if( !IsEqual(val, BacklightAlwaysOn) )
- {
- DPRINTF(SYMP_INFO, ("CHXAvPlayerUI::HandleNotifyL(): backlight resetn"));
- // some events (e.g., incoming sms) reset backlight behavior; ensure this is set correctly
- SetActivePlaybackState(m_bIsActivePlaybackState);
- }
- }
- else if(0 == key.CompareF(KSysApAlarmLightActive))
- {
- // also see RAlarmServer
- if( IsEqual(val, AlarmFlashing) )
- {
- DPRINTF(SYMP_INFO, ("CHXAvPlayerUI::HandleNotifyL(): alarm firingn"));
- // handle this same way as if we loose app focus
- CHXAvViewBase *pActiveView = static_cast<CHXAvViewBase *>(iView);
- pActiveView->HandleLosePlayFocus();
- }
- }
- else if(0 == key.CompareF(KSysApMessageToneQuit))
- {
- if( IsEqual(val, MessageTonesOff) )
- {
- // we get this when a message comes in in silent mode
- DPRINTF(SYMP_INFO, ("CHXAvPlayerUI::HandleNotifyL(): msg tone offn"));
-
- // in silent mode this resets volume; now we (possibly) reset volume back
- m_player->SetVolume(m_player->GetVolume());
- }
- }
- }
- }
- #endif
- /*
- * GetRecentClipCount
- * ------------------
- * Returns the count of urls.
- *
- */
- TInt
- CHXAvPlayerUI::GetRecentClipCount() const
- {
- TInt count = 0;
- if (m_recentClips)
- {
- count = m_recentClips->NumURLs();
- }
- return count;
- }