📄 s60internetradioappui.cpp
字号:
/*
* ==============================================================================
* Name : S60InternetRadioppUi.cpp
* Part of : S60 Internet Radio Application
* Interface :
* Description : Implementation of the application UI class
* Version : 1
*
* Copyright (c) 2006, Nokia Corporation All rights reserved. Redistribution
* and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met: Redistributions
* of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer. Redistributions in binary form
* must reproduce the above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other materials provided
* with the distribution. Neither the name of the Nokia Corporation nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. THIS
* SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* ==============================================================================
*/
// INCLUDE FILES
#include <eikenv.h>
#include <avkon.hrh>
#include <eikbtgpc.h>
#include <S60InternetRadio.rsg>
#include <eikspane.h>
#include <akntitle.h>
#include <CAknFileSelectionDialog.h>
#include "S60InternetRadio.pan"
#include "S60InternetRadio.hrh"
#include "S60InternetRadioAppUi.h"
#include "S60InternetRadioView.h"
#include "PlayerAdapter.h"
#include <PluginAdapter.h>
_LIT(KDriveC, "C:\\");
_LIT(KDriveE, "E:\\");
// -----------------------------------------------------------------------------
// CS60InternetRadioAppUi::CS60InternetRadioAppUi
// -----------------------------------------------------------------------------
//
CS60InternetRadioAppUi::CS60InternetRadioAppUi()
{
// No implementation required
}
// -----------------------------------------------------------------------------
// CS60InternetRadioAppUi::CS60InternetRadioAppUi
// Constructs the:
// - player adapter
// - the view
// - get a list of available plugins
// -----------------------------------------------------------------------------
//
void CS60InternetRadioAppUi::ConstructL()
{
BaseConstructL();
// Create and initialize adapter with null file.
iPlayerAdapter = CPlayerAdapter::NewL(KNullDesC, *this);
// Try to get a list of plugins that implements the MAudioAdapter interface
GetPlugins();
if ( iAudioPlugins.Count() ) // If plugin adapters were found, use the first one on the list.
{
iAudioAdapter = iAudioPlugins[0];
}
else // otherwise, we use the file player adapter
{
iAudioAdapter = iPlayerAdapter;
}
// construct a view
iAppView = CS60InternetRadioView::NewL(ClientRect(), iAudioAdapter->Identify(), iAudioAdapter->SupportMetadata());
iAppView->SetAppUi(this);
AddToStackL(iAppView);
CEikStatusPane *statusPane = StatusPane();
if ( statusPane && statusPane->PaneCapabilities(TUid::Uid(EEikStatusPaneUidTitle)).IsPresent() )
{
CAknTitlePane *titlePane=(CAknTitlePane*)(statusPane->ControlL(TUid::Uid(EEikStatusPaneUidTitle)));
titlePane->SetTextL(_L("S60 Internet Radio"));
}
}
// -----------------------------------------------------------------------------
// CS60InternetRadioAppUi::GetPlugins
// Get all plugins.
// -----------------------------------------------------------------------------
//
void CS60InternetRadioAppUi::GetPlugins()
{
TAny *impl; // pointer to interface implementation
TUid implementationUid;
RImplInfoPtrArray infoArray;
TRAP_IGNORE(
{
REComSession::ListImplementationsL(TUid::Uid(KAudioAdapterInterfaceUid), infoArray);
for ( TInt i = 0; i < infoArray.Count(); i++ )
{
implementationUid = infoArray[i]->ImplementationUid();
impl = REComSession::CreateImplementationL(implementationUid, _FOFF(CPluginAdapter,iDestructorIDKey), this);
if ( impl )
{
iAudioPlugins.Append((CPluginAdapter*)impl);
}
}
});
infoArray.ResetAndDestroy();
}
// -----------------------------------------------------------------------------
// CS60InternetRadioAppUi::~CS60InternetRadioAppUi
// -----------------------------------------------------------------------------
//
CS60InternetRadioAppUi::~CS60InternetRadioAppUi()
{
iEikonEnv->RemoveFromStack(iAppView);
delete iAppView;
iAppView = NULL;
delete iPlayerAdapter;
iPlayerAdapter = NULL;
iAudioAdapter = NULL;
//properly destroy the plugin array
iAudioPlugins.ResetAndDestroy();
REComSession::FinalClose();
}
// -----------------------------------------------------------------------------
// CS60InternetRadioAppUi::HandleCommandL
// -----------------------------------------------------------------------------
//
void CS60InternetRadioAppUi::HandleCommandL(TInt aCommand)
{
switch ( aCommand )
{
case ES60InternetRadioCmdPlayer:
SetAdapterL(iPlayerAdapter);
break;
case EEikCmdExit:
case EAknSoftkeyExit:
Exit();
break;
case ES60InternetRadioCmdPlay:
iAudioAdapter->PlayL();
break;
case ES60InternetRadioCmdStop:
iAudioAdapter->StopL();
break;
case ES60InternetRadioCmdDriveC:
SelectFileL(EDriveC);
SetAdapterL(iPlayerAdapter);
break;
case ES60InternetRadioCmdDriveE:
SelectFileL(EDriveE);
SetAdapterL(iPlayerAdapter);
break;
default:
RDebug::Print(_L("HandleCommandL - default"));
TBool found = EFalse;
// The user selected a plugin adapter.
// We check the command against each plugin found earlier. If the
// command matched the plugin's menu command, we found the adapter
// the user selected and can set the app to use the new adapter.
for ( TInt i=0; i<iAudioPlugins.Count(); i++ )
{
if ( iAudioPlugins[i]->GetMenuCommand() == aCommand )
{
// Set the adapter to the found plugin
SetAdapterL(iAudioPlugins[i]);
found = ETrue;
}
}
// If the command didn't match any plugins, this must be a command for the plugin adapter.
if ( !found )
{
// try to route the command.
if ( !iAudioAdapter->HandleCommandL(aCommand) )
{
User::Panic(KS60InternetRadio, KS60InternetRadioPanicUnexpectedCommand);
}
}
break;
}
}
// -----------------------------------------------------------------------------
// CS60InternetRadioAppUi::SelectFile
// -----------------------------------------------------------------------------
//
void CS60InternetRadioAppUi::SelectFileL(
TDriveNumber aDrive )
{
RDebug::Print(_L("SelectFile"));
TFileName path, fileName;
if ( aDrive == EDriveC )
{
path = KDriveC;
fileName = KDriveC;
}
else if ( aDrive == EDriveE )
{
path = KDriveE;
fileName = KDriveE;
}
if ( CAknFileSelectionDialog::RunDlgLD(fileName, path) )
{
delete iPlayerAdapter;
iPlayerAdapter = NULL;
iPlayerAdapter = CPlayerAdapter::NewL(fileName, *this);
}
}
// -----------------------------------------------------------------------------
// CS60InternetRadioAppUi::AudioAdapter
// -----------------------------------------------------------------------------
//
MAudioAdapter* CS60InternetRadioAppUi::AudioAdapter()
{
return iAudioAdapter;
}
// -----------------------------------------------------------------------------
// CS60InternetRadioAppUi::SetAdapterL
// -----------------------------------------------------------------------------
//
void CS60InternetRadioAppUi::SetAdapterL(MAudioAdapter* aAudioAdapter)
{
RDebug::Print(_L("SetAdapterL"));
iAudioAdapter = aAudioAdapter;
UpdateViewL();
}
// -----------------------------------------------------------------------------
// CS60InternetRadioAppUi::UpdateViewL
// -----------------------------------------------------------------------------
//
void CS60InternetRadioAppUi::UpdateViewL()
{
iAppView->NotifyStatus(iAudioAdapter->Identify(),iAudioAdapter->SupportMetadata());
iAppView->DrawNow();
}
// -----------------------------------------------------------------------------
// CS60InternetRadioAppUi::DynInitMenuPaneL
// Initialises the specified menu pane prior to activation.
// -----------------------------------------------------------------------------
//
void CS60InternetRadioAppUi::DynInitMenuPaneL(
TInt aResourceId,
CEikMenuPane* aMenuPane )
{
if (aResourceId == R_S60INTERNETRADIO_MENU)
{
aMenuPane->SetItemDimmed(ES60InternetRadioCmdExtra, ETrue);
iAudioAdapter->UpdateMenuL(aMenuPane);
}
else if ( aResourceId == R_S60INTERNETRADIO_UTILITY_MENU )
{
// Add any available plugins to the menu options
CEikMenuPaneItem::SData sd;
for ( TInt i = 0; i < iAudioPlugins.Count(); i++ )
{
sd.iCommandId=iAudioPlugins[i]->GetMenuCommand();
iAudioPlugins[i]->GetMenuText(sd.iText);
sd.iFlags = 0;
sd.iCascadeId = 0;
aMenuPane->AddMenuItemL(sd);
}
}
else if (aResourceId == R_S60INTERNETRADIO_EXTRA_MENU)
{
iAudioAdapter->AddExtraMenu(aMenuPane);
}
}
// -----------------------------------------------------------------------------
// CS60InternetRadioAppUi::SetMetadata
// -----------------------------------------------------------------------------
//
void CS60InternetRadioAppUi::SetMetadata(
TInt aIndex,
const TDesC& aValue,
TBool aCommit )
{
iAppView->UpdateMetadataLabel(aIndex,aValue, aCommit);
}
// -----------------------------------------------------------------------------
// CS60InternetRadioAppUi::ResetMetadata
// -----------------------------------------------------------------------------
//
void CS60InternetRadioAppUi::ResetMetadata()
{
iAppView->NotifyStatus(iAudioAdapter->Identify(), iAudioAdapter->SupportMetadata());
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -