chxavplayerui.cpp

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

CPP
1,429
字号
/****************************************************************************
 * 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, "\n\n");

    // 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();
            }
        }

⌨️ 快捷键说明

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