| 27 |      1 | /*
 | 
|  |      2 | * Copyright (c) 2002-2006 Nokia Corporation and/or its subsidiary(-ies).
 | 
|  |      3 | * All rights reserved.
 | 
|  |      4 | * This component and the accompanying materials are made available
 | 
|  |      5 | * under the terms of "Eclipse Public License v1.0"
 | 
|  |      6 | * which accompanies this distribution, and is available
 | 
|  |      7 | * at the URL "http://www.eclipse.org/legal/epl-v10.html".
 | 
|  |      8 | *
 | 
|  |      9 | * Initial Contributors:
 | 
|  |     10 | * Nokia Corporation - initial contribution.
 | 
|  |     11 | *
 | 
|  |     12 | * Contributors:
 | 
|  |     13 | *
 | 
|  |     14 | * Description:   BIO control for Ringing Tones.
 | 
|  |     15 | *
 | 
|  |     16 | */
 | 
|  |     17 | 
 | 
|  |     18 | 
 | 
|  |     19 | 
 | 
|  |     20 | // INCLUDE FILES
 | 
|  |     21 | 
 | 
|  |     22 | #include "RingingToneBioControl.h"      // for CRingingToneBioControl
 | 
|  |     23 | #include "RingBCToneConverter.h"             // for CComNSMConverter
 | 
|  |     24 | #include "RingBC.hrh"
 | 
|  |     25 | #include "RingBCLog.h"
 | 
|  |     26 | 
 | 
|  |     27 | #include <biocmtm.h>                    // for CBIOClientMtm
 | 
|  |     28 | #include <coeutils.h>                   // for ConeUtils
 | 
|  |     29 | #include <msgbiocontrolObserver.h>      // for MMsgBioControlObserver
 | 
|  |     30 | #include <StringLoader.h>               // for StringLoader
 | 
|  |     31 | #include <AknsUtils.h>
 | 
|  |     32 | #include <RingBC.rsg>                   // for resouce identifiers
 | 
|  |     33 | #include <ringbc.mbg>                   // for icons indexes
 | 
|  |     34 | #include <ProfileEngineSDKCRKeys.h>
 | 
|  |     35 | #include <MsgBioUtils.h>                // for MsgBioUtils
 | 
|  |     36 | #include <eikrted.h>                    // for CEikRichTextEditor
 | 
|  |     37 | #include <txtrich.h>                    // for CRichText
 | 
|  |     38 | #include <aknnotewrappers.h>            // for CAknInformationNote
 | 
|  |     39 | #include <Profile.hrh>                  // for EProfileRingingTypeSilent
 | 
|  |     40 | #include <bldvariant.hrh>
 | 
|  |     41 | #include <pathinfo.h>
 | 
|  |     42 | #include <featmgr.h>					// Feature manager
 | 
|  |     43 | #include <csxhelp/smart.hlp.hrh>
 | 
|  |     44 | #include <data_caging_path_literals.hrh>
 | 
|  |     45 | #include <applayout.cdl.h>				// LAF
 | 
|  |     46 | #include <aknlayoutscalable_apps.cdl.h>
 | 
|  |     47 | #include <mmsvattachmentmanager.h>
 | 
|  |     48 | 
 | 
|  |     49 | #include <msgaudiocontrol.h>	//AudioControl
 | 
|  |     50 | #include <MsgEditorCommon.h>	//MsgEditorCommons utilities
 | 
|  |     51 | 
 | 
|  |     52 | // CONSTANTS
 | 
|  |     53 | 
 | 
|  |     54 | _LIT(KRingingToneFileExtension,".rng");
 | 
|  |     55 | _LIT(KResourceName, "ringbc.rsc" );
 | 
|  |     56 | _LIT(KRingBCMbmFileName, "ringbc.mif");
 | 
|  |     57 | 
 | 
|  |     58 | // LOCAL CONSTANTS AND MACROS
 | 
|  |     59 | const TInt KComponentCountZero = 0;
 | 
|  |     60 | const TInt KNoOverWriteOrRecurse = 0;
 | 
|  |     61 | const TInt KLengthOfTitleRow = 100;
 | 
|  |     62 | const TInt KTextNameQueryMaxLength = 50;
 | 
|  |     63 | 
 | 
|  |     64 | 
 | 
|  |     65 | const TInt KRichEditor              = 1;
 | 
|  |     66 | const TInt KAudioControl            = 0;
 | 
|  |     67 | 
 | 
|  |     68 | const TInt KRingVolumeZero = 0;
 | 
|  |     69 | 
 | 
|  |     70 | const TInt KShowNoNotes = 0;
 | 
|  |     71 | const TInt KShowNotes = 1;
 | 
|  |     72 | 
 | 
|  |     73 | const TInt KFrameExpansion = 10;
 | 
|  |     74 | const TInt KMaxVolumeLevel = 10;
 | 
|  |     75 | 
 | 
|  |     76 | // MODULE DATA STRUCTURES
 | 
|  |     77 | 
 | 
|  |     78 | enum TOptionListLocation
 | 
|  |     79 |     {
 | 
|  |     80 |     EFirstMenuItem  = 0,
 | 
|  |     81 |     ESecondMenuItem
 | 
|  |     82 |     };
 | 
|  |     83 | 
 | 
|  |     84 | // ================= MEMBER FUNCTIONS =======================
 | 
|  |     85 | 
 | 
|  |     86 | // Two-phased constructor.
 | 
|  |     87 | EXPORT_C CMsgBioControl* CRingingToneBioControl::NewL(
 | 
|  |     88 |             MMsgBioControlObserver& aObserver,
 | 
|  |     89 |             CMsvSession* aSession,
 | 
|  |     90 |             TMsvId aId,
 | 
|  |     91 |             TMsgBioMode aEditorOrViewerMode,
 | 
|  |     92 |             const RFile* aFile)
 | 
|  |     93 |     {
 | 
|  |     94 |     CRingingToneBioControl* self =
 | 
|  |     95 |     	new( ELeave ) CRingingToneBioControl(
 | 
|  |     96 |     		aObserver,
 | 
|  |     97 |             aSession, aId, aEditorOrViewerMode,
 | 
|  |     98 |             aFile);
 | 
|  |     99 | 
 | 
|  |    100 |     CleanupStack::PushL( self );
 | 
|  |    101 |     self->ConstructL();
 | 
|  |    102 |     CleanupStack::Pop(self); // self
 | 
|  |    103 | 
 | 
|  |    104 |     return self;
 | 
|  |    105 | 
 | 
|  |    106 |     }
 | 
|  |    107 | 
 | 
|  |    108 | // Destructor
 | 
|  |    109 | CRingingToneBioControl::~CRingingToneBioControl()
 | 
|  |    110 |     {
 | 
|  |    111 |     FeatureManager::UnInitializeLib();
 | 
|  |    112 |     delete iRichEditor;
 | 
|  |    113 |     delete iAudioControl;    
 | 
|  |    114 |     delete iToneTitle;
 | 
|  |    115 |     }
 | 
|  |    116 | 
 | 
|  |    117 | // C++ default constructor.
 | 
|  |    118 | CRingingToneBioControl::CRingingToneBioControl(
 | 
|  |    119 |         MMsgBioControlObserver& aObserver,
 | 
|  |    120 |         CMsvSession* aSession,
 | 
|  |    121 |         TMsvId aId,
 | 
|  |    122 |         TMsgBioMode aEditorOrViewerMode,
 | 
|  |    123 |         const RFile* aFile):
 | 
|  |    124 |         CMsgBioControl(aObserver,
 | 
|  |    125 |             aSession,
 | 
|  |    126 |             aId,
 | 
|  |    127 |             aEditorOrViewerMode,
 | 
|  |    128 |             aFile)
 | 
|  |    129 |     {
 | 
|  |    130 |     }
 | 
|  |    131 | 
 | 
|  |    132 | // Symbian OS default constructor can leave.
 | 
|  |    133 | void CRingingToneBioControl::ConstructL()
 | 
|  |    134 |     {
 | 
|  |    135 |     if( IsEditor() )   //Editor mode is not supported
 | 
|  |    136 |         {
 | 
|  |    137 |         User::Leave( KErrNotSupported );
 | 
|  |    138 |         }
 | 
|  |    139 | 
 | 
|  |    140 | 	FeatureManager::InitializeLibL();
 | 
|  |    141 | 
 | 
|  |    142 |     LoadStandardBioResourceL();
 | 
|  |    143 |     LoadResourceL( KResourceName );
 | 
|  |    144 | 
 | 
|  |    145 |     // checks if the message is valid
 | 
|  |    146 |     CheckMsgValidityL();
 | 
|  |    147 |     TakeTitleL();
 | 
|  |    148 | 
 | 
|  |    149 |     }
 | 
|  |    150 | 
 | 
|  |    151 | // ----------------------------------------------------------------------------
 | 
|  |    152 | // CRingingToneBioControl::CheckMsgValidityL
 | 
|  |    153 | // ----------------------------------------------------------------------------
 | 
|  |    154 | //
 | 
|  |    155 | void CRingingToneBioControl::CheckMsgValidityL()
 | 
|  |    156 |     {
 | 
|  |    157 |     RFile file;
 | 
|  |    158 | 
 | 
|  |    159 |     CMsvEntry* entry = this->MsvSession(). GetEntryL(iId);
 | 
|  |    160 |     CleanupStack::PushL( entry );
 | 
|  |    161 | 
 | 
|  |    162 |     CMsvStore* store = entry->ReadStoreL();
 | 
|  |    163 | 	CleanupStack::PushL(store);
 | 
|  |    164 | 
 | 
|  |    165 | 	MMsvAttachmentManager& manager = store->AttachmentManagerL();
 | 
|  |    166 | 	file = manager.GetAttachmentFileL(0);
 | 
|  |    167 | 
 | 
|  |    168 |     CleanupClosePushL(file);
 | 
|  |    169 | 
 | 
|  |    170 |     TInt size;
 | 
|  |    171 |     User::LeaveIfError(file.Size(size));
 | 
|  |    172 |     if (!size)
 | 
|  |    173 |         {
 | 
|  |    174 |         //the empty ringing tone is considered a corrupted message
 | 
|  |    175 |         User::Leave(KErrMsgBioMessageNotValid);
 | 
|  |    176 |         }
 | 
|  |    177 | 	
 | 
|  |    178 | 	HBufC8* dataBuf = HBufC8::NewLC(size);
 | 
|  |    179 |     TPtr8 data(dataBuf->Des());
 | 
|  |    180 |     User::LeaveIfError(file.Read(data, size));
 | 
|  |    181 | 
 | 
|  |    182 |     CRingBCNSMConverter* conv = CRingBCNSMConverter::NewL();
 | 
|  |    183 |     CleanupStack::PushL( conv );
 | 
|  |    184 |     TBool res = conv->IsRingToneMimeTypeL(data);
 | 
|  |    185 | 
 | 
|  |    186 |     if (!res)
 | 
|  |    187 |         {
 | 
|  |    188 |         User::Leave(KErrMsgBioMessageNotValid);
 | 
|  |    189 |         }
 | 
|  |    190 |         
 | 
|  |    191 |     CleanupStack::PopAndDestroy(5,entry); // entry,conv,store,file,dataBuf
 | 
|  |    192 |     }
 | 
|  |    193 | 
 | 
|  |    194 | 
 | 
|  |    195 | // ----------------------------------------------------------------------------
 | 
|  |    196 | // CRingingToneBioControl::ProcessCommandL
 | 
|  |    197 | // ----------------------------------------------------------------------------
 | 
|  |    198 | //
 | 
|  |    199 | void CRingingToneBioControl::ProcessCommandL( TInt aCommandId )
 | 
|  |    200 |     {
 | 
|  |    201 |     if ( aCommandId == ESoftkeyStop )
 | 
|  |    202 | 		{
 | 
|  |    203 | 		StopPlayback();
 | 
|  |    204 |         }
 | 
|  |    205 |     }
 | 
|  |    206 | 
 | 
|  |    207 | // ----------------------------------------------------------------------------
 | 
|  |    208 | // CRingingToneBioControl::SetAndGetSizeL
 | 
|  |    209 | // ----------------------------------------------------------------------------
 | 
|  |    210 | //
 | 
|  |    211 | void CRingingToneBioControl::SetAndGetSizeL( TSize& aSize )
 | 
|  |    212 |     {
 | 
|  |    213 | 	//the heightadjustment calculates the height for the header elements and 
 | 
|  |    214 | 	//the space between components
 | 
|  |    215 |    	TInt heightAdjustment = (MsgEditorCommons::MsgBaseLineDelta()*2)+
 | 
|  |    216 |    							MsgEditorCommons::MsgBaseLineOffset();
 | 
|  |    217 |    	
 | 
|  |    218 |    	aSize.iHeight -= heightAdjustment;
 | 
|  |    219 |    	SetSizeWithoutNotification( aSize  );
 | 
|  |    220 |     }
 | 
|  |    221 | 
 | 
|  |    222 | // ----------------------------------------------------------------------------
 | 
|  |    223 | // CRingingToneBioControl::SetMenuCommandSetL
 | 
|  |    224 | // ----------------------------------------------------------------------------
 | 
|  |    225 | //
 | 
|  |    226 | void CRingingToneBioControl::SetMenuCommandSetL( CEikMenuPane& aMenuPane )
 | 
|  |    227 |     {
 | 
|  |    228 |     // if playing, do not show context sensitive menu.
 | 
|  |    229 |     if ( iPlayerState != EMsgAsyncControlStatePlaying )
 | 
|  |    230 |         {
 | 
|  |    231 | 		//removing the playback option from options menu, single click will do the playing
 | 
|  |    232 |         //AddMenuItemL(aMenuPane, R_SM_PLAYBACK, ERingtPlayback, EFirstMenuItem);
 | 
|  |    233 |         AddMenuItemL(aMenuPane,
 | 
|  |    234 |         	R_SM_ADD_COMPOSER, ERingtAddComposer, ESecondMenuItem);
 | 
|  |    235 |         }
 | 
|  |    236 | 	}
 | 
|  |    237 | 
 | 
|  |    238 | // ----------------------------------------------------------------------------
 | 
|  |    239 | // CRingingToneBioControl::CurrentLineRect
 | 
|  |    240 | // ----------------------------------------------------------------------------
 | 
|  |    241 | //
 | 
|  |    242 | TRect CRingingToneBioControl::CurrentLineRect() const
 | 
|  |    243 |     {
 | 
|  |    244 |     return iAudioControl->CurrentLineRect();
 | 
|  |    245 |     }
 | 
|  |    246 | 
 | 
|  |    247 | // ----------------------------------------------------------------------------
 | 
|  |    248 | // CRingingToneBioControl::IsFocusChangePossible
 | 
|  |    249 | // ----------------------------------------------------------------------------
 | 
|  |    250 | //
 | 
|  |    251 | TBool CRingingToneBioControl::IsFocusChangePossible(
 | 
|  |    252 |         TMsgFocusDirection aDirection ) const
 | 
|  |    253 |     {
 | 
|  |    254 |     return iAudioControl->IsFocusChangePossible( aDirection );
 | 
|  |    255 | 	}
 | 
|  |    256 | 
 | 
|  |    257 | // ----------------------------------------------------------------------------
 | 
|  |    258 | // CRingingToneBioControl::HeaderTextL
 | 
|  |    259 | // ----------------------------------------------------------------------------
 | 
|  |    260 | //
 | 
|  |    261 | HBufC* CRingingToneBioControl::HeaderTextL() const
 | 
|  |    262 |     {
 | 
|  |    263 |     return iCoeEnv->AllocReadResourceL( R_SM_TITLE_RINGING_TONE );
 | 
|  |    264 |     }
 | 
|  |    265 | 
 | 
|  |    266 | // ----------------------------------------------------------------------------
 | 
|  |    267 | // CRingingToneBioControl::HandleBioCommandL
 | 
|  |    268 | // ----------------------------------------------------------------------------
 | 
|  |    269 | //
 | 
|  |    270 | TBool CRingingToneBioControl::HandleBioCommandL(TInt aCommand)
 | 
|  |    271 |     {
 | 
|  |    272 |     aCommand -= iBioControlObserver.FirstFreeCommand();
 | 
|  |    273 |     TBool retValue(EFalse);
 | 
|  |    274 |     switch ( aCommand )
 | 
|  |    275 |         {
 | 
|  |    276 |         case ERingtPlayback:
 | 
|  |    277 |             PlaybackL();
 | 
|  |    278 |             retValue = ETrue;
 | 
|  |    279 |             break;
 | 
|  |    280 |         case ERingtAddComposer:
 | 
|  |    281 |             TrySaveToneL();
 | 
|  |    282 |             retValue = ETrue;
 | 
|  |    283 |             break;
 | 
|  |    284 |         default:
 | 
|  |    285 |             retValue = EFalse;
 | 
|  |    286 |             break;
 | 
|  |    287 |         }
 | 
|  |    288 | 	return retValue;
 | 
|  |    289 |     }
 | 
|  |    290 | 
 | 
|  |    291 | // ----------------------------------------------------------------------------
 | 
|  |    292 | // CRingingToneLogoBioControl::OptionMenuPermissionsL
 | 
|  |    293 | // ----------------------------------------------------------------------------
 | 
|  |    294 | //
 | 
|  |    295 | TUint32 CRingingToneBioControl::OptionMenuPermissionsL() const
 | 
|  |    296 |     {
 | 
|  |    297 |     if ( iPlayerState != EMsgAsyncControlStatePlaying )
 | 
|  |    298 |         {
 | 
|  |    299 |         return EMsgBioDelete
 | 
|  |    300 |         | EMsgBioMessInfo
 | 
|  |    301 |         | EMsgBioMove
 | 
|  |    302 |         | EMsgBioHelp
 | 
|  |    303 |         | EMsgBioExit;
 | 
|  |    304 |         }
 | 
|  |    305 |     else 
 | 
|  |    306 |         {
 | 
|  |    307 |         // do not show context sensitive menu.
 | 
|  |    308 |         return 0;
 | 
|  |    309 |         }
 | 
|  |    310 |     }
 | 
|  |    311 | 
 | 
|  |    312 | 
 | 
|  |    313 | 
 | 
|  |    314 | // ----------------------------------------------------------------------------
 | 
|  |    315 | // CRingingToneBioControl::OfferKeyEventL
 | 
|  |    316 | // ----------------------------------------------------------------------------
 | 
|  |    317 | //
 | 
|  |    318 | TKeyResponse CRingingToneBioControl::OfferKeyEventL(
 | 
|  |    319 |         const TKeyEvent& /*aKeyEvent*/,
 | 
|  |    320 |         TEventCode /*aType*/ )
 | 
|  |    321 |     {
 | 
|  |    322 |     return EKeyWasConsumed;
 | 
|  |    323 |     }
 | 
|  |    324 | 
 | 
|  |    325 | // ----------------------------------------------------------------------------
 | 
|  |    326 | // CRingingToneBioControl::GetHelpContext
 | 
|  |    327 | // ----------------------------------------------------------------------------
 | 
|  |    328 | //
 | 
|  |    329 | void CRingingToneBioControl::GetHelpContext(
 | 
|  |    330 | 	TCoeHelpContext& aHelpContext) const
 | 
|  |    331 | 	{
 | 
|  |    332 | 	if ( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
 | 
|  |    333 | 		{
 | 
|  |    334 | 		const TUid KUidSmart = {0x101F4CDA};
 | 
|  |    335 | 
 | 
|  |    336 | 		aHelpContext.iContext = KSMART_HLP_RINGVIEWER();
 | 
|  |    337 | 		aHelpContext.iMajor = KUidSmart;
 | 
|  |    338 | 		}
 | 
|  |    339 | 	}
 | 
|  |    340 | 
 | 
|  |    341 | // ----------------------------------------------------------------------------
 | 
|  |    342 | // CRingingToneBioControl::CountComponentControls
 | 
|  |    343 | // ----------------------------------------------------------------------------
 | 
|  |    344 | //
 | 
|  |    345 | TInt CRingingToneBioControl::CountComponentControls() const
 | 
|  |    346 |     {
 | 
|  |    347 |     TInt componentCount( KComponentCountZero );
 | 
|  |    348 |     if ( iAudioControl )
 | 
|  |    349 |         {
 | 
|  |    350 |         componentCount++;
 | 
|  |    351 |         }
 | 
|  |    352 | 	if ( iRichEditor )        
 | 
|  |    353 | 		{
 | 
|  |    354 | 		componentCount++;
 | 
|  |    355 | 		}
 | 
|  |    356 |     return componentCount;
 | 
|  |    357 |     }
 | 
|  |    358 | 
 | 
|  |    359 | // ----------------------------------------------------------------------------
 | 
|  |    360 | // CRingingToneBioControl::ComponentControl
 | 
|  |    361 | // ----------------------------------------------------------------------------
 | 
|  |    362 | //
 | 
|  |    363 | CCoeControl* CRingingToneBioControl::ComponentControl( TInt aIndex ) const
 | 
|  |    364 |     {
 | 
|  |    365 |     if ( aIndex == KRichEditor )
 | 
|  |    366 |     	{
 | 
|  |    367 |     	return iRichEditor;
 | 
|  |    368 |     	}
 | 
|  |    369 |     if ( aIndex == KAudioControl )
 | 
|  |    370 |         {
 | 
|  |    371 |         return iAudioControl;
 | 
|  |    372 |         }
 | 
|  |    373 |     else
 | 
|  |    374 |     	{
 | 
|  |    375 |     	return NULL;
 | 
|  |    376 |     	}
 | 
|  |    377 | 	}
 | 
|  |    378 | 
 | 
|  |    379 | // ----------------------------------------------------------------------------
 | 
|  |    380 | // CRingingToneBioControl::HandleResourceChange
 | 
|  |    381 | // ----------------------------------------------------------------------------
 | 
|  |    382 | //
 | 
|  |    383 | void CRingingToneBioControl::HandleResourceChange( TInt aType )
 | 
|  |    384 |     {
 | 
|  |    385 |     if(aType == KEikDynamicLayoutVariantSwitch)
 | 
|  |    386 |     	{
 | 
|  |    387 |         TRAP_IGNORE(
 | 
|  |    388 |        		CorrectFormatToRichEditorL();
 | 
|  |    389 |         	iRichEditor->SetTextL( iToneTitle );
 | 
|  |    390 |         	FillBitmapMaskL();
 | 
|  |    391 |         	);
 | 
|  |    392 |         }
 | 
|  |    393 |     iAudioControl->HandleResourceChange( aType );
 | 
|  |    394 |     }
 | 
|  |    395 | 
 | 
|  |    396 | // ----------------------------------------------------------------------------
 | 
|  |    397 | // CRingingToneBioControl::SizeChanged
 | 
|  |    398 | // ----------------------------------------------------------------------------
 | 
|  |    399 | //
 | 
|  |    400 | void CRingingToneBioControl::SizeChanged()
 | 
|  |    401 |     {
 | 
|  |    402 |     TRect rect = Rect();
 | 
|  |    403 |     TRect bitmapRect;
 | 
|  |    404 |     TAknWindowComponentLayout layout =
 | 
|  |    405 | 	   	AknLayoutScalable_Apps::mce_image_pane_g5();
 | 
|  |    406 |     TAknLayoutRect LayoutRect;
 | 
|  |    407 | 	LayoutRect.LayoutRect( rect, layout.LayoutLine() );
 | 
|  |    408 | 	bitmapRect = LayoutRect.Rect();
 | 
|  |    409 | 	TInt formattedHeight = iRichEditor->TextLayout()->FormattedHeightInPixels();
 | 
|  |    410 | 	bitmapRect.Move(0,formattedHeight);
 | 
|  |    411 | 
 | 
|  |    412 | 	//the rectangle is grown to so that focused frame is visible
 | 
|  |    413 | 	bitmapRect.Grow( KFrameExpansion, KFrameExpansion );
 | 
|  |    414 | 	
 | 
|  |    415 | 	// rect for richtext is positioned on the top of audio control
 | 
|  |    416 | 	rect.iBr.iY = bitmapRect.iTl.iY;
 | 
|  |    417 | 	iRichEditor->SetRect( rect );
 | 
|  |    418 |     iAudioControl->SetRect( bitmapRect );
 | 
|  |    419 |     }
 | 
|  |    420 | 
 | 
|  |    421 | // ----------------------------------------------------------------------------
 | 
|  |    422 | // CRingingToneBioControl::FocusChanged
 | 
|  |    423 | // ----------------------------------------------------------------------------
 | 
|  |    424 | //
 | 
|  |    425 | void CRingingToneBioControl::FocusChanged( TDrawNow aDrawNow )
 | 
|  |    426 |     {
 | 
|  |    427 | 	iAudioControl->SetFocus(IsFocused());
 | 
|  |    428 | 	iRichEditor->FocusChanged(aDrawNow);
 | 
|  |    429 |     }
 | 
|  |    430 | 
 | 
|  |    431 | // ----------------------------------------------------------------------------
 | 
|  |    432 | // CRingingToneBioControl::SetContainerWindowL
 | 
|  |    433 | // ----------------------------------------------------------------------------
 | 
|  |    434 | //
 | 
|  |    435 | void CRingingToneBioControl::SetContainerWindowL(
 | 
|  |    436 | 	const CCoeControl& aContainer )
 | 
|  |    437 |     {
 | 
|  |    438 |     CCoeControl::SetContainerWindowL( aContainer );
 | 
|  |    439 | 
 | 
|  |    440 |     //The reason for creating the audio control here is that the construction
 | 
|  |    441 |     //requires a parent with a window. So it cannot be done in ConstructL()
 | 
|  |    442 |     iAudioControl = CMsgAudioControl::NewL( *reinterpret_cast<CMsgEditorView*>(this), this, EMdaPriorityNormal, EMdaPriorityPreferenceQuality );
 | 
|  |    443 | 	FillBitmapMaskL();
 | 
|  |    444 | 
 | 
|  |    445 |     CreateRichEditorL();
 | 
|  |    446 |     }
 | 
|  |    447 | 
 | 
|  |    448 | // ----------------------------------------------------------------------------
 | 
|  |    449 | // CRingingToneBioControl ::Draw()
 | 
|  |    450 | // ----------------------------------------------------------------------------
 | 
|  |    451 | //
 | 
|  |    452 | void CRingingToneBioControl::Draw(const TRect& /*aRect*/) const
 | 
|  |    453 |     {
 | 
|  |    454 |     }
 | 
|  |    455 | 
 | 
|  |    456 | // ----------------------------------------------------------------------------
 | 
|  |    457 | // CRingingToneBioControl ::CorrectFormatToRichEditorL()
 | 
|  |    458 | // ----------------------------------------------------------------------------
 | 
|  |    459 | //
 | 
|  |    460 | void CRingingToneBioControl::CorrectFormatToRichEditorL()
 | 
|  |    461 |     {
 | 
|  |    462 |     CRichText* rich = iRichEditor->RichText();
 | 
|  |    463 |     TInt pos(rich->DocumentLength());
 | 
|  |    464 | 
 | 
|  |    465 |     // font correction.
 | 
|  |    466 |     TCharFormat format;
 | 
|  |    467 |     TCharFormatMask mask;
 | 
|  |    468 | 
 | 
|  |    469 | 	TAknTextLineLayout editorLayout = AppLayout::Smart_Messages_Line_2( 0 );
 | 
|  |    470 | 	const CFont* editorFont = AknLayoutUtils::FontFromId( editorLayout.FontId() );
 | 
|  |    471 | 	format.iFontSpec = editorFont->FontSpecInTwips();
 | 
|  |    472 | 
 | 
|  |    473 |     TRgb textColor;
 | 
|  |    474 |     if ( AknsUtils::GetCachedColor(
 | 
|  |    475 | 	    AknsUtils::SkinInstance(),
 | 
|  |    476 |         textColor,
 | 
|  |    477 |         KAknsIIDQsnTextColors,
 | 
|  |    478 |         EAknsCIQsnTextColorsCG6 ) != KErrNone )
 | 
|  |    479 | 	    {
 | 
|  |    480 | 	    textColor = AKN_LAF_COLOR_STATIC( 215 );
 | 
|  |    481 | 	    }
 | 
|  |    482 | 
 | 
|  |    483 |     format.iFontPresentation.iTextColor = textColor;
 | 
|  |    484 | 
 | 
|  |    485 |     mask.ClearAll();
 | 
|  |    486 |     mask.SetAttrib( EAttColor );
 | 
|  |    487 |     mask.SetAttrib(EAttFontStrokeWeight);
 | 
|  |    488 |     mask.SetAttrib(EAttFontHeight);
 | 
|  |    489 |     mask.SetAttrib(EAttFontTypeface);
 | 
|  |    490 | 
 | 
|  |    491 |     rich->SetInsertCharFormatL(format, mask, pos);
 | 
|  |    492 | 
 | 
|  |    493 |     // this is needed to set ringing tone title centered.
 | 
|  |    494 |     CParaFormat* paraFormat = CParaFormat::NewLC();
 | 
|  |    495 |     TParaFormatMask paraMask;
 | 
|  |    496 | 
 | 
|  |    497 |     paraFormat->Reset();
 | 
|  |    498 |     paraFormat->iHorizontalAlignment = CParaFormat::ECenterAlign;
 | 
|  |    499 |     paraFormat->iVerticalAlignment = CParaFormat::ECenterAlign;
 | 
|  |    500 | 
 | 
|  |    501 |     paraMask.SetAttrib(EAttAlignment);
 | 
|  |    502 |     paraMask.SetAttrib(EAttFontHeight);
 | 
|  |    503 |     paraMask.SetAttrib(EAttColor);
 | 
|  |    504 | 
 | 
|  |    505 |     rich->ApplyParaFormatL(paraFormat, paraMask, 0, pos);
 | 
|  |    506 | 
 | 
|  |    507 |     CleanupStack::PopAndDestroy(paraFormat);
 | 
|  |    508 |     }
 | 
|  |    509 | 
 | 
|  |    510 | void CRingingToneBioControl::OpenFileL()
 | 
|  |    511 | 	{
 | 
|  |    512 | 	RFile file;
 | 
|  |    513 | 
 | 
|  |    514 | 	CMsvEntry* entry = this->MsvSession(). GetEntryL(iId);
 | 
|  |    515 | 	CleanupStack::PushL( entry );
 | 
|  |    516 | 
 | 
|  |    517 | 	CMsvStore* store = entry->ReadStoreL();
 | 
|  |    518 | 	CleanupStack::PushL(store);
 | 
|  |    519 | 
 | 
|  |    520 | 	MMsvAttachmentManager& manager = store->AttachmentManagerL();
 | 
|  |    521 | 	file = manager.GetAttachmentFileL(0);
 | 
|  |    522 | 	CleanupClosePushL(file);
 | 
|  |    523 | 
 | 
|  |    524 | 	//asynchronous loading of file
 | 
|  |    525 | 	//the audio control takes a copy of the file
 | 
|  |    526 | 	iAudioControl->LoadL(file);
 | 
|  |    527 | 
 | 
|  |    528 | 	//wait for the opening of file to complete
 | 
|  |    529 | 	//in MsgMediaControlStateChanged
 | 
|  |    530 |     CActiveScheduler::Start();
 | 
|  |    531 | 
 | 
|  |    532 | 	CleanupStack::PopAndDestroy(3, entry);
 | 
|  |    533 | 	}
 | 
|  |    534 | 
 | 
|  |    535 | // ----------------------------------------------------------------------------
 | 
|  |    536 | // CRingingToneBioControl::PlaybackL
 | 
|  |    537 | // ----------------------------------------------------------------------------
 | 
|  |    538 | //
 | 
|  |    539 | void CRingingToneBioControl::PlaybackL()
 | 
|  |    540 |     {
 | 
|  |    541 |     if( iPlayerState != EMsgAsyncControlStateOpening ||
 | 
|  |    542 | 		iPlayerState != EMsgAsyncControlStateAboutToPlay ||
 | 
|  |    543 | 		iPlayerState != EMsgAsyncControlStatePlaying ||
 | 
|  |    544 | 		iPlayerState != EMsgAsyncControlStateBuffering )
 | 
|  |    545 |     	{
 | 
|  |    546 |     	
 | 
|  |    547 |     	OpenFileL();
 | 
|  |    548 |     	
 | 
|  |    549 |     	//any other state than EMsgAsyncControlStateReady
 | 
|  |    550 |     	//constitutes a failed opening of media file
 | 
|  |    551 |     	if(iPlayerState == EMsgAsyncControlStateReady)
 | 
|  |    552 |     		{
 | 
|  |    553 |     		GetAndSetRingingToneVolumeL();
 | 
|  |    554 | 		    iAudioControl->PlayL();
 | 
|  |    555 | 
 | 
|  |    556 | 		    iStopCba = CEikButtonGroupContainer::NewL (
 | 
|  |    557 | 		    CEikButtonGroupContainer::ECba, CEikButtonGroupContainer::EHorizontal,
 | 
|  |    558 | 		        this, R_RINGCONTROL_SOFTKEYS_STOP );
 | 
|  |    559 | 
 | 
|  |    560 | 		    const TSize screenSize = CCoeEnv::Static()->ScreenDevice()->SizeInPixels();
 | 
|  |    561 | 		    iStopCba->SetBoundingRect( TRect( screenSize ) );
 | 
|  |    562 |     		}
 | 
|  |    563 |     	}
 | 
|  |    564 |     }
 | 
|  |    565 | 
 | 
|  |    566 | void CRingingToneBioControl::StopPlayback()
 | 
|  |    567 | 	{
 | 
|  |    568 | 	iAudioControl->Stop();
 | 
|  |    569 | 	
 | 
|  |    570 | 	//after playback the file must be closed so that moving the ring tone
 | 
|  |    571 | 	//message to another folder is possible 
 | 
|  |    572 | 	iAudioControl->Close();
 | 
|  |    573 | 	}
 | 
|  |    574 | 
 | 
|  |    575 | // ----------------------------------------------------------------------------
 | 
|  |    576 | // CRingingToneBioControl::GetAndSetRingingToneVolumeL
 | 
|  |    577 | // ----------------------------------------------------------------------------
 | 
|  |    578 | //
 | 
|  |    579 | void CRingingToneBioControl::GetAndSetRingingToneVolumeL()
 | 
|  |    580 |     {
 | 
|  |    581 |     TInt ringingVol;
 | 
|  |    582 |     TInt ringingType;
 | 
|  |    583 |     TInt aMaxVolume;
 | 
|  |    584 | 	aMaxVolume = iAudioControl->MaxVolume();
 | 
|  |    585 | 	CRepository* repository = CRepository::NewLC( KCRUidProfileEngine );
 | 
|  |    586 | 
 | 
|  |    587 | 	User::LeaveIfError( repository->Get( KProEngActiveRingingVolume, ringingVol ));
 | 
|  |    588 | 	User::LeaveIfError(	repository->Get( KProEngActiveRingingType, ringingType ));
 | 
|  |    589 | 
 | 
|  |    590 | 	CleanupStack::PopAndDestroy(repository); //repository
 | 
|  |    591 | 
 | 
|  |    592 | 	//Some emulator versions crash in volume setting
 | 
|  |    593 | #ifndef __WINS__
 | 
|  |    594 |     if (ringingType == EProfileRingingTypeSilent)
 | 
|  |    595 |         {
 | 
|  |    596 |         RDebug::Print(_L("Profile: Ring type silent"));
 | 
|  |    597 |         iAudioControl->SetVolume(KRingVolumeZero);
 | 
|  |    598 |         }
 | 
|  |    599 |     else
 | 
|  |    600 |         {
 | 
|  |    601 |         TInt result( aMaxVolume * ringingVol / KMaxVolumeLevel ); 
 | 
|  |    602 |         RDebug::Print(_L("Ringing volume : %d"), ringingVol);
 | 
|  |    603 |         iAudioControl->SetVolume(result);
 | 
|  |    604 |         }
 | 
|  |    605 | #endif
 | 
|  |    606 |     }
 | 
|  |    607 | 
 | 
|  |    608 | 
 | 
|  |    609 | 
 | 
|  |    610 | // ----------------------------------------------------------------------------
 | 
|  |    611 | // CRingingToneBioControl::CreateRichEditorL
 | 
|  |    612 | // ----------------------------------------------------------------------------
 | 
|  |    613 | //
 | 
|  |    614 | void CRingingToneBioControl::CreateRichEditorL()
 | 
|  |    615 |     {
 | 
|  |    616 |     iRichEditor = new( ELeave ) CEikRichTextEditor(TGulBorder::ENone);
 | 
|  |    617 | 
 | 
|  |    618 |     TInt edwinFlags =
 | 
|  |    619 |     	CEikEdwin::ENoHorizScrolling |
 | 
|  |    620 |     	CEikEdwin::ENoAutoSelection |
 | 
|  |    621 |         CEikEdwin::EWidthInPixels |
 | 
|  |    622 |         CEikEdwin::EReadOnly |
 | 
|  |    623 |         CEikEdwin::EEdwinAlternativeWrapping;
 | 
|  |    624 | 
 | 
|  |    625 |     iRichEditor->ConstructL(this,2 , 0, edwinFlags);
 | 
|  |    626 | 
 | 
|  |    627 |     iRichEditor->SetMaximumHeightInLines(2);
 | 
|  |    628 | 
 | 
|  |    629 |     // corrects font and alignment to centered.
 | 
|  |    630 |     CorrectFormatToRichEditorL();
 | 
|  |    631 | 
 | 
|  |    632 |     iRichEditor->SetTextL( iToneTitle );    
 | 
|  |    633 |     }
 | 
|  |    634 | 
 | 
|  |    635 | // ----------------------------------------------------------------------------
 | 
|  |    636 | // CRingingToneBioControl::FillBitmapMaskL
 | 
|  |    637 | // ----------------------------------------------------------------------------
 | 
|  |    638 | //
 | 
|  |    639 | void CRingingToneBioControl::FillBitmapMaskL()
 | 
|  |    640 |     {
 | 
|  |    641 |     
 | 
|  |    642 |     TParse *fp = new(ELeave) TParse();
 | 
|  |    643 | 	fp->Set( KRingBCMbmFileName, &KDC_APP_BITMAP_DIR, NULL );
 | 
|  |    644 | 	CleanupStack::PushL( fp );
 | 
|  |    645 |     
 | 
|  |    646 |     iAudioControl->LoadIconL(  fp->FullName(),
 | 
|  |    647 |                                 KAknsIIDQgnPropOtaTone,
 | 
|  |    648 |                                 EMbmRingbcQgn_prop_ota_tone,
 | 
|  |    649 |                                 EMbmRingbcQgn_prop_ota_tone_mask);
 | 
|  |    650 |     
 | 
|  |    651 |     CleanupStack::PopAndDestroy(fp);
 | 
|  |    652 |                                     
 | 
|  |    653 |     TAknWindowComponentLayout layout =
 | 
|  |    654 |         		AknLayoutScalable_Apps::mce_image_pane_g5();
 | 
|  |    655 |     TAknLayoutRect LayoutRect;
 | 
|  |    656 | 	LayoutRect.LayoutRect( Rect(), layout.LayoutLine() );
 | 
|  |    657 | 	TRect bitmapRect;
 | 
|  |    658 | 	bitmapRect = LayoutRect.Rect();                                
 | 
|  |    659 | 	iAudioControl->SetIconSizeL(bitmapRect.Size());
 | 
|  |    660 | 	iAudioControl->SetIconVisible(ETrue);
 | 
|  |    661 |     }
 | 
|  |    662 | 
 | 
|  |    663 | 
 | 
|  |    664 | // ----------------------------------------------------------------------------
 | 
|  |    665 | // CRingingToneBioControl::AddSongTitleToArrayL
 | 
|  |    666 | // ----------------------------------------------------------------------------
 | 
|  |    667 | //
 | 
|  |    668 | void CRingingToneBioControl::AddSongTitleToArrayL(CDesCArray& aItemArray) const
 | 
|  |    669 |     {
 | 
|  |    670 |     //Add titlerow to array
 | 
|  |    671 |     HBufC* dataRow = HBufC::NewLC(KLengthOfTitleRow);
 | 
|  |    672 |     TPtr rowPtr = dataRow->Des();
 | 
|  |    673 |     HBufC* baseString = StringLoader::LoadLC( R_BASE_STRING );
 | 
|  |    674 | 
 | 
|  |    675 |     TInt maxLength(KLengthOfTitleRow - baseString->Length());
 | 
|  |    676 | 
 | 
|  |    677 |     HBufC* tempName = HBufC::NewLC(KMaxFileName);
 | 
|  |    678 | 
 | 
|  |    679 |     TPtr tempTPtr = tempName->Des();
 | 
|  |    680 |     tempTPtr.Copy(iToneTitle->Des());
 | 
|  |    681 | 
 | 
|  |    682 |     if (iToneTitle->Length() > maxLength)
 | 
|  |    683 |         {
 | 
|  |    684 |         tempTPtr = iToneTitle->Des().Left(maxLength);
 | 
|  |    685 |         }
 | 
|  |    686 | 
 | 
|  |    687 |     rowPtr.Format(*baseString, tempName);
 | 
|  |    688 |     CleanupStack::PopAndDestroy( 2, baseString );  //tempName, baseString
 | 
|  |    689 |     aItemArray.AppendL( rowPtr );
 | 
|  |    690 |     CleanupStack::PopAndDestroy(dataRow);  //dataRow
 | 
|  |    691 |     }
 | 
|  |    692 | 
 | 
|  |    693 | // ----------------------------------------------------------------------------
 | 
|  |    694 | // CRingingToneBioControl ::IsOnlyDots
 | 
|  |    695 | // ----------------------------------------------------------------------------
 | 
|  |    696 | //
 | 
|  |    697 | TBool CRingingToneBioControl::IsOnlyDots(TDes& aTitle)
 | 
|  |    698 |     {
 | 
|  |    699 |     const TChar KSingleDot = '.';
 | 
|  |    700 | 	_LIT(KDoubleDots,"..");
 | 
|  |    701 | 
 | 
|  |    702 |     if(aTitle.Length()==1)
 | 
|  |    703 |         {
 | 
|  |    704 | 
 | 
|  |    705 |         if( aTitle.Locate(KSingleDot) != KErrNotFound )
 | 
|  |    706 |             {
 | 
|  |    707 |             return ETrue;
 | 
|  |    708 |             }
 | 
|  |    709 |         }
 | 
|  |    710 | 
 | 
|  |    711 |     else if(aTitle.Length()==2)
 | 
|  |    712 |         {
 | 
|  |    713 | 
 | 
|  |    714 |         if( aTitle.Find(KDoubleDots) != KErrNotFound )
 | 
|  |    715 |             {
 | 
|  |    716 |             return ETrue;
 | 
|  |    717 |             }
 | 
|  |    718 |         }
 | 
|  |    719 | 
 | 
|  |    720 |     return EFalse;
 | 
|  |    721 |     }
 | 
|  |    722 | 
 | 
|  |    723 | // ----------------------------------------------------------------------------
 | 
|  |    724 | // CRingingToneBioControl::IsValidL
 | 
|  |    725 | // ----------------------------------------------------------------------------
 | 
|  |    726 | //
 | 
|  |    727 | TBool CRingingToneBioControl::IsValidL(TDes& aTitle, TBool aNotes)
 | 
|  |    728 |     {
 | 
|  |    729 |     RFs fileServer;
 | 
|  |    730 |     User::LeaveIfError( fileServer.Connect() );
 | 
|  |    731 | 
 | 
|  |    732 |     //If name includes solely single dot or double dot, this note should be
 | 
|  |    733 |     //showed (Folders spec)
 | 
|  |    734 |     if( IsOnlyDots(aTitle) )
 | 
|  |    735 |         {
 | 
|  |    736 | 
 | 
|  |    737 |         fileServer.Close();
 | 
|  |    738 |         if(aNotes)
 | 
|  |    739 |             {
 | 
|  |    740 |             InformationNoteL(R_FLDR_BAD_FILE_NAME);
 | 
|  |    741 |             }
 | 
|  |    742 |         return EFalse;
 | 
|  |    743 | 
 | 
|  |    744 |         }
 | 
|  |    745 | 
 | 
|  |    746 |     //only because of IsValidName does not check backslash, but file
 | 
|  |    747 |     //is not valid with it.
 | 
|  |    748 |     if( aTitle.Locate('\\') != KErrNotFound )
 | 
|  |    749 |         {
 | 
|  |    750 | 
 | 
|  |    751 |         fileServer.Close();
 | 
|  |    752 |         if(aNotes)
 | 
|  |    753 |             {
 | 
|  |    754 |             InformationNoteL(R_FLDR_ILLEGAL_CHARACTERS);
 | 
|  |    755 |             }
 | 
|  |    756 |         return EFalse;
 | 
|  |    757 | 
 | 
|  |    758 |         }
 | 
|  |    759 |     if( aTitle.Locate('\n') != KErrNotFound )
 | 
|  |    760 |         {
 | 
|  |    761 |         fileServer.Close();
 | 
|  |    762 |         if(aNotes)
 | 
|  |    763 |             {
 | 
|  |    764 |             InformationNoteL(R_FLDR_ILLEGAL_CHARACTERS);
 | 
|  |    765 |             }
 | 
|  |    766 |         return EFalse;
 | 
|  |    767 |         }
 | 
|  |    768 | 
 | 
|  |    769 |     // check is there any special chars between 00h to 1Fh
 | 
|  |    770 |     for (TInt i=0; i<32; i++)
 | 
|  |    771 |         {
 | 
|  |    772 |         if (aTitle.Locate(i) !=KErrNotFound )
 | 
|  |    773 |             {
 | 
|  |    774 |             fileServer.Close();
 | 
|  |    775 |             if(aNotes)
 | 
|  |    776 |                 {
 | 
|  |    777 |                 InformationNoteL(R_FLDR_ILLEGAL_CHARACTERS);
 | 
|  |    778 |                 }
 | 
|  |    779 |             return EFalse;
 | 
|  |    780 | 
 | 
|  |    781 |             }
 | 
|  |    782 | 
 | 
|  |    783 |         }
 | 
|  |    784 | 
 | 
|  |    785 |     //Checking if filename is valid for saving purpose
 | 
|  |    786 |     if( !fileServer.IsValidName(aTitle) )
 | 
|  |    787 |         {
 | 
|  |    788 | 
 | 
|  |    789 |         fileServer.Close();
 | 
|  |    790 |         if(aNotes)
 | 
|  |    791 |             {
 | 
|  |    792 |             InformationNoteL(R_FLDR_ILLEGAL_CHARACTERS);
 | 
|  |    793 |             }
 | 
|  |    794 |         return EFalse;
 | 
|  |    795 | 
 | 
|  |    796 |         }
 | 
|  |    797 | 
 | 
|  |    798 |     fileServer.Close();
 | 
|  |    799 |     return ETrue; //File name is valid
 | 
|  |    800 | 
 | 
|  |    801 |     }
 | 
|  |    802 | 
 | 
|  |    803 | // ----------------------------------------------------------------------------
 | 
|  |    804 | // CRingingToneBioControl::InformationNoteL
 | 
|  |    805 | // ----------------------------------------------------------------------------
 | 
|  |    806 | //
 | 
|  |    807 | void CRingingToneBioControl::InformationNoteL(TInt aStringResource)
 | 
|  |    808 |     {
 | 
|  |    809 |     HBufC* buf = StringLoader::LoadLC(aStringResource);
 | 
|  |    810 | 
 | 
|  |    811 |     CAknInformationNote* note = new (ELeave) CAknInformationNote(ETrue);
 | 
|  |    812 |     note->ExecuteLD(*buf);
 | 
|  |    813 | 
 | 
|  |    814 |     CleanupStack::PopAndDestroy(buf); //buf
 | 
|  |    815 |     }
 | 
|  |    816 | 
 | 
|  |    817 | 
 | 
|  |    818 | // ----------------------------------------------------------------------------
 | 
|  |    819 | // CRingingToneBioControl::ExistsL
 | 
|  |    820 | // ----------------------------------------------------------------------------
 | 
|  |    821 | //
 | 
|  |    822 | TBool CRingingToneBioControl::ExistsL(TDes& aTitle)
 | 
|  |    823 |     {
 | 
|  |    824 |     HBufC* path = CreatePathForSavingLC(aTitle);
 | 
|  |    825 | 
 | 
|  |    826 |     if ( ConeUtils::FileExists(*path) )
 | 
|  |    827 |         {
 | 
|  |    828 |         CleanupStack::PopAndDestroy(path); //path;
 | 
|  |    829 | 
 | 
|  |    830 |         return ETrue;
 | 
|  |    831 |         }
 | 
|  |    832 | 
 | 
|  |    833 |     CleanupStack::PopAndDestroy(path); //path;
 | 
|  |    834 |     return EFalse;
 | 
|  |    835 |     }
 | 
|  |    836 | 
 | 
|  |    837 | // ----------------------------------------------------------------------------
 | 
|  |    838 | // CRingingToneBioControl::AskNameL
 | 
|  |    839 | // ----------------------------------------------------------------------------
 | 
|  |    840 | //
 | 
|  |    841 | TBool CRingingToneBioControl::AskNameL(TDes& aTitle)
 | 
|  |    842 |     {
 | 
|  |    843 |     IncrementFileNameL( aTitle );
 | 
|  |    844 | 
 | 
|  |    845 |     if (!NameQueryL(aTitle))
 | 
|  |    846 |         {
 | 
|  |    847 |         return EFalse;
 | 
|  |    848 |         }
 | 
|  |    849 | 
 | 
|  |    850 |     return ETrue;
 | 
|  |    851 |     }
 | 
|  |    852 | 
 | 
|  |    853 | // ----------------------------------------------------------------------------
 | 
|  |    854 | // CRingingToneBioControl::AskNameAndValidNameL
 | 
|  |    855 | // ----------------------------------------------------------------------------
 | 
|  |    856 | //
 | 
|  |    857 | TBool CRingingToneBioControl::AskAndValidNameL(TDes& aTitle)
 | 
|  |    858 |     {
 | 
|  |    859 |     do
 | 
|  |    860 |         {
 | 
|  |    861 |         if(!AskNameL(aTitle))
 | 
|  |    862 |             {
 | 
|  |    863 |             return EFalse;
 | 
|  |    864 |             }
 | 
|  |    865 | 
 | 
|  |    866 |         } while (!IsValidL(aTitle,KShowNotes)) ;
 | 
|  |    867 | 
 | 
|  |    868 |     return ETrue;
 | 
|  |    869 |     }
 | 
|  |    870 | 
 | 
|  |    871 | 
 | 
|  |    872 | // ----------------------------------------------------------------------------
 | 
|  |    873 | // CRingingToneBioControl::TrySaveToneL
 | 
|  |    874 | // ----------------------------------------------------------------------------
 | 
|  |    875 | //
 | 
|  |    876 | void CRingingToneBioControl::TrySaveToneL()
 | 
|  |    877 |     {
 | 
|  |    878 |     HBufC* saveTitle = HBufC::NewLC(KMaxFileName);
 | 
|  |    879 |     TPtr saveTitlePtr(saveTitle->Des());
 | 
|  |    880 | 
 | 
|  |    881 |     saveTitlePtr.Copy(*iToneTitle); //initialize saveTitle
 | 
|  |    882 | 
 | 
|  |    883 |     TBool okSave = ETrue; //No cancel pressed
 | 
|  |    884 | 
 | 
|  |    885 |     //First case is special, cause if message have wrong kind of title,
 | 
|  |    886 |     //there will be default name in data query and no rename query.
 | 
|  |    887 |     if( !IsValidL(saveTitlePtr,KShowNoNotes) )
 | 
|  |    888 |         {
 | 
|  |    889 |         SetDefaultNameL(saveTitlePtr);
 | 
|  |    890 | 
 | 
|  |    891 |         okSave = AskAndValidNameL(saveTitlePtr);
 | 
|  |    892 |         }
 | 
|  |    893 | 
 | 
|  |    894 |     //Have to check if title already exists. If not, then save. But if
 | 
|  |    895 |     //it exists already, should ask if rename (rename query) and then ask
 | 
|  |    896 |     //for new name until user press cancel or give valid name. After that
 | 
|  |    897 |     //we should check if that already exists...
 | 
|  |    898 |     if(okSave)
 | 
|  |    899 |         {
 | 
|  |    900 |         while (ExistsL(saveTitlePtr))
 | 
|  |    901 |             {
 | 
|  |    902 |             if (!RenameQueryL(saveTitlePtr))
 | 
|  |    903 |                 {
 | 
|  |    904 |                 okSave = EFalse;
 | 
|  |    905 |                 break;
 | 
|  |    906 |                 }
 | 
|  |    907 | 
 | 
|  |    908 |             if(!AskAndValidNameL(saveTitlePtr))
 | 
|  |    909 |                 {
 | 
|  |    910 |                 okSave = EFalse;
 | 
|  |    911 |                 break;
 | 
|  |    912 |                 }
 | 
|  |    913 |             };
 | 
|  |    914 |         }
 | 
|  |    915 | 
 | 
|  |    916 |     //User did not press cancel in any place and it is saving time.
 | 
|  |    917 |     if(okSave)
 | 
|  |    918 |         {
 | 
|  |    919 |         SaveToneL(saveTitlePtr);
 | 
|  |    920 |         MsgBioUtils::ConfirmationNoteL(R_SM_NOTE_TONE_COPIED);
 | 
|  |    921 |         }
 | 
|  |    922 | 
 | 
|  |    923 |     CleanupStack::PopAndDestroy(saveTitle); //saveTitle
 | 
|  |    924 |     }
 | 
|  |    925 | 
 | 
|  |    926 | // ----------------------------------------------------------------------------
 | 
|  |    927 | // CRingingToneBioControl::CreatePathForSavingLC
 | 
|  |    928 | // ----------------------------------------------------------------------------
 | 
|  |    929 | //
 | 
|  |    930 | HBufC* CRingingToneBioControl::CreatePathForSavingLC(const TDesC& aName)
 | 
|  |    931 |     {
 | 
|  |    932 |     HBufC* targetPathAndName = TargetPathLC();
 | 
|  |    933 | 
 | 
|  |    934 |     TPtr targetPathAndNamePtr = targetPathAndName->Des();
 | 
|  |    935 | 
 | 
|  |    936 |     targetPathAndNamePtr.Append(aName);
 | 
|  |    937 |     targetPathAndNamePtr.Append(KRingingToneFileExtension);
 | 
|  |    938 | 
 | 
|  |    939 |     return targetPathAndName;
 | 
|  |    940 |     }
 | 
|  |    941 | 
 | 
|  |    942 | // ----------------------------------------------------------------------------
 | 
|  |    943 | // CRingingToneBioControl::RenameQueryL
 | 
|  |    944 | // ----------------------------------------------------------------------------
 | 
|  |    945 | //
 | 
|  |    946 | TBool CRingingToneBioControl::RenameQueryL(TDes& aTitle)
 | 
|  |    947 |     {
 | 
|  |    948 |     if ( !MsgBioUtils::ConfirmationQueryOkCancelL(
 | 
|  |    949 |     	*StringLoader::LoadLC( R_FLDR_RENAME_QUERY, aTitle ) ) )
 | 
|  |    950 |         {
 | 
|  |    951 | 
 | 
|  |    952 |         CleanupStack::PopAndDestroy(); //StringLoader;
 | 
|  |    953 |         return EFalse;
 | 
|  |    954 | 
 | 
|  |    955 |         }
 | 
|  |    956 |     CleanupStack::PopAndDestroy(); //StringLoader;
 | 
|  |    957 | 
 | 
|  |    958 |     return ETrue;
 | 
|  |    959 |     }
 | 
|  |    960 | 
 | 
|  |    961 | // ----------------------------------------------------------------------------
 | 
|  |    962 | // CRingingToneBioControl::SaveToneL
 | 
|  |    963 | // ----------------------------------------------------------------------------
 | 
|  |    964 | //
 | 
|  |    965 | TBool CRingingToneBioControl::SaveToneL(TDes& aTitle)
 | 
|  |    966 |     {
 | 
|  |    967 |     CFileMan* files = CFileMan::NewL(CCoeEnv::Static()->FsSession());
 | 
|  |    968 |     CleanupStack::PushL( files );
 | 
|  |    969 | 
 | 
|  |    970 |     HBufC* targetPathAndName = CreatePathForSavingLC(aTitle);
 | 
|  |    971 | 
 | 
|  |    972 |     CMsvEntry* entry = this->MsvSession(). GetEntryL(iId);
 | 
|  |    973 |     CleanupStack::PushL( entry );
 | 
|  |    974 | 
 | 
|  |    975 |     CMsvStore* store = entry->ReadStoreL();
 | 
|  |    976 | 	CleanupStack::PushL(store);
 | 
|  |    977 | 
 | 
|  |    978 | 	MMsvAttachmentManager& manager = store->AttachmentManagerL();
 | 
|  |    979 | 
 | 
|  |    980 | 	RFile ringFile;
 | 
|  |    981 | 	ringFile = manager.GetAttachmentFileL(0);
 | 
|  |    982 | 
 | 
|  |    983 |     CleanupStack::PopAndDestroy(2, entry);
 | 
|  |    984 |     CleanupClosePushL(ringFile);
 | 
|  |    985 | 
 | 
|  |    986 |     TInt err = files->Copy(
 | 
|  |    987 |     	ringFile, *targetPathAndName, KNoOverWriteOrRecurse );
 | 
|  |    988 |     User::LeaveIfError(err);
 | 
|  |    989 | 
 | 
|  |    990 |     CleanupStack::PopAndDestroy(3, files); //targetPathAndName, ringFile, files
 | 
|  |    991 |     return ETrue;
 | 
|  |    992 |     }
 | 
|  |    993 | 
 | 
|  |    994 | // ----------------------------------------------------------------------------
 | 
|  |    995 | // CRingingToneBioControl::SetDefaultNameL
 | 
|  |    996 | // ----------------------------------------------------------------------------
 | 
|  |    997 | //
 | 
|  |    998 | void CRingingToneBioControl::SetDefaultNameL(TDes& aName)
 | 
|  |    999 |     {
 | 
|  |   1000 |     aName.Copy(*StringLoader::LoadLC( R_SM_TONE_NAME ));
 | 
|  |   1001 |     CleanupStack::PopAndDestroy(); //stringloader
 | 
|  |   1002 |     }
 | 
|  |   1003 | 
 | 
|  |   1004 | // ----------------------------------------------------------------------------
 | 
|  |   1005 | // CRingingToneBioControl::NameQueryL
 | 
|  |   1006 | // ----------------------------------------------------------------------------
 | 
|  |   1007 | //
 | 
|  |   1008 | TBool CRingingToneBioControl::NameQueryL(TDes& aName)
 | 
|  |   1009 |     {
 | 
|  |   1010 |     if (aName.Length() > KTextNameQueryMaxLength)
 | 
|  |   1011 |         {
 | 
|  |   1012 |         User::Leave(KErrOverflow);
 | 
|  |   1013 |         }
 | 
|  |   1014 | 
 | 
|  |   1015 |     CAknTextQueryDialog* queryDlg = new ( ELeave )
 | 
|  |   1016 |                                      CAknTextQueryDialog( aName );
 | 
|  |   1017 |     return queryDlg->ExecuteLD( R_SM_QUERY_RINGING_TONE );
 | 
|  |   1018 |     }
 | 
|  |   1019 | 
 | 
|  |   1020 | // ----------------------------------------------------------------------------
 | 
|  |   1021 | // CRingingToneBioControl::TakeTitleL
 | 
|  |   1022 | // ----------------------------------------------------------------------------
 | 
|  |   1023 | //
 | 
|  |   1024 | void CRingingToneBioControl::TakeTitleL()
 | 
|  |   1025 |     {
 | 
|  |   1026 |     //Read stream from file
 | 
|  |   1027 | 
 | 
|  |   1028 |     RFile ringFile;
 | 
|  |   1029 | 
 | 
|  |   1030 |     CMsvEntry* entry = this->MsvSession(). GetEntryL(iId);
 | 
|  |   1031 |     CleanupStack::PushL( entry );
 | 
|  |   1032 | 
 | 
|  |   1033 |     CMsvStore* store = entry->ReadStoreL();
 | 
|  |   1034 | 	CleanupStack::PushL(store);
 | 
|  |   1035 | 
 | 
|  |   1036 | 	MMsvAttachmentManager& manager = store->AttachmentManagerL();
 | 
|  |   1037 | 	ringFile = manager.GetAttachmentFileL(0);
 | 
|  |   1038 | 
 | 
|  |   1039 |     CleanupStack::PopAndDestroy(2,entry);    //entry, store
 | 
|  |   1040 |     CleanupClosePushL(ringFile);
 | 
|  |   1041 | 
 | 
|  |   1042 | 
 | 
|  |   1043 |     TInt filelen;
 | 
|  |   1044 |     User::LeaveIfError(ringFile.Size(filelen));
 | 
|  |   1045 | 
 | 
|  |   1046 |     HBufC8* filedata8 = HBufC8::NewMaxLC(filelen);
 | 
|  |   1047 |     TPtr8 dataPtr8 = filedata8->Des();
 | 
|  |   1048 |     User::LeaveIfError(ringFile.Read(dataPtr8,filelen));
 | 
|  |   1049 | 
 | 
|  |   1050 |     CleanupStack::Pop( filedata8 ); // pop the filedata temporarily
 | 
|  |   1051 |     CleanupStack::PopAndDestroy(); // close and destory ringFile
 | 
|  |   1052 |     CleanupStack::PushL( filedata8 ); // put the filedata back
 | 
|  |   1053 | 
 | 
|  |   1054 |     CRingBCNSMConverter* conv = CRingBCNSMConverter::NewL();
 | 
|  |   1055 |     CleanupStack::PushL( conv );
 | 
|  |   1056 | 
 | 
|  |   1057 | 	if ( iToneTitle )
 | 
|  |   1058 | 		{
 | 
|  |   1059 | 		delete iToneTitle;
 | 
|  |   1060 | 		iToneTitle = NULL;
 | 
|  |   1061 | 		}
 | 
|  |   1062 | 	iToneTitle = conv->TitleLC(dataPtr8); //The ownership changes here
 | 
|  |   1063 | 
 | 
|  |   1064 |     CleanupStack::Pop(iToneTitle);
 | 
|  |   1065 |     CleanupStack::PopAndDestroy(2, filedata8);  //conv, filedata8
 | 
|  |   1066 | 
 | 
|  |   1067 |     // checks if there is no name for ringing tone
 | 
|  |   1068 |     if (iToneTitle->Length() == 0)
 | 
|  |   1069 |         {
 | 
|  |   1070 |         delete iToneTitle;
 | 
|  |   1071 |         iToneTitle = NULL;
 | 
|  |   1072 | 
 | 
|  |   1073 |         // sets default name
 | 
|  |   1074 |         iToneTitle = StringLoader::LoadL( R_SM_TONE_NAME );
 | 
|  |   1075 | 
 | 
|  |   1076 |         // check that default name is not too long.
 | 
|  |   1077 |         if (iToneTitle->Length() > KMaxFileName )
 | 
|  |   1078 |             {
 | 
|  |   1079 | 
 | 
|  |   1080 |             HBufC* tempName = HBufC::NewLC(KMaxFileName);
 | 
|  |   1081 |             TPtr tempTPtr = tempName->Des();
 | 
|  |   1082 | 
 | 
|  |   1083 |             tempTPtr.Copy(iToneTitle->Des().Left(KMaxFileName));
 | 
|  |   1084 | 
 | 
|  |   1085 |             CleanupStack::Pop(tempName);
 | 
|  |   1086 | 
 | 
|  |   1087 | 	        delete iToneTitle;
 | 
|  |   1088 |             iToneTitle = tempName;
 | 
|  |   1089 |             }
 | 
|  |   1090 |         }
 | 
|  |   1091 |     }
 | 
|  |   1092 | // ----------------------------------------------------------------------------
 | 
|  |   1093 | // CRingingToneBioControl::IncrementFileName
 | 
|  |   1094 | // ----------------------------------------------------------------------------
 | 
|  |   1095 | //
 | 
|  |   1096 | void CRingingToneBioControl::IncrementFileNameL(TDes& aFileName)
 | 
|  |   1097 |     {
 | 
|  |   1098 |     HBufC* path = CreatePathForSavingLC(aFileName);
 | 
|  |   1099 | 
 | 
|  |   1100 |     while (ConeUtils::FileExists(*path))
 | 
|  |   1101 |         {
 | 
|  |   1102 | 
 | 
|  |   1103 |         MsgBioUtils::IncrementNameL(aFileName,KMaxFileName);
 | 
|  |   1104 | 
 | 
|  |   1105 |         CleanupStack::PopAndDestroy(path);  //path
 | 
|  |   1106 |         path = CreatePathForSavingLC(aFileName);
 | 
|  |   1107 | 
 | 
|  |   1108 |         }
 | 
|  |   1109 | 
 | 
|  |   1110 |     CleanupStack::PopAndDestroy(path); //path;
 | 
|  |   1111 |     }
 | 
|  |   1112 | 
 | 
|  |   1113 | 
 | 
|  |   1114 | // ----------------------------------------------------------------------------
 | 
|  |   1115 | // CRingingToneBioControl ::TargetPathLC
 | 
|  |   1116 | // ----------------------------------------------------------------------------
 | 
|  |   1117 | //
 | 
|  |   1118 | HBufC* CRingingToneBioControl::TargetPathLC()
 | 
|  |   1119 |     {
 | 
|  |   1120 | 	TFileName path = PathInfo::PhoneMemoryRootPath();
 | 
|  |   1121 | 	path.Append( PathInfo::SimpleSoundsPath() );
 | 
|  |   1122 |     ConeUtils::EnsurePathExistsL(path);
 | 
|  |   1123 |     HBufC* savePath = HBufC::NewLC(KMaxPath + KMaxFileName);
 | 
|  |   1124 | 	TPtr ptr = savePath->Des();
 | 
|  |   1125 | 	ptr = path;
 | 
|  |   1126 | 	return savePath;
 | 
|  |   1127 |     }
 | 
|  |   1128 | 
 | 
|  |   1129 | // ----------------------------------------------------------------------------
 | 
|  |   1130 | // CRingingToneBioControl ::VirtualHeight
 | 
|  |   1131 | // ----------------------------------------------------------------------------
 | 
|  |   1132 | //
 | 
|  |   1133 | TInt CRingingToneBioControl::VirtualHeight()
 | 
|  |   1134 | 	{
 | 
|  |   1135 |     return 0;
 | 
|  |   1136 | 	}
 | 
|  |   1137 | 
 | 
|  |   1138 | // ----------------------------------------------------------------------------
 | 
|  |   1139 | // CRingingToneBioControl ::VirtualVisibleTop
 | 
|  |   1140 | // ----------------------------------------------------------------------------
 | 
|  |   1141 | //
 | 
|  |   1142 | TInt CRingingToneBioControl::VirtualVisibleTop()
 | 
|  |   1143 | 	{
 | 
|  |   1144 |     return 0;
 | 
|  |   1145 | 	}
 | 
|  |   1146 | 
 | 
|  |   1147 | void CRingingToneBioControl::MsgAsyncControlStateChanged( CMsgBaseControl& /*aControl*/,
 | 
|  |   1148 |                                               TMsgAsyncControlState aNewState,
 | 
|  |   1149 |                                               TMsgAsyncControlState aOldState )
 | 
|  |   1150 |     {
 | 
|  |   1151 |     iPlayerState = aNewState;
 | 
|  |   1152 |     
 | 
|  |   1153 |     if(aOldState == EMsgAsyncControlStateOpening)
 | 
|  |   1154 | 		{
 | 
|  |   1155 | 		//last state was opening so we go ahead with playing by stopping 
 | 
|  |   1156 | 		//the active scheduler that was started in OpenFileL -function
 | 
|  |   1157 | 		CActiveScheduler::Stop();
 | 
|  |   1158 | 		}
 | 
|  |   1159 |     
 | 
|  |   1160 |     switch( aNewState )
 | 
|  |   1161 |     	{
 | 
|  |   1162 | 			//intentional fallthrough    			
 | 
|  |   1163 | 			case EMsgAsyncControlStateIdle:
 | 
|  |   1164 |     		case EMsgAsyncControlStateStopped:
 | 
|  |   1165 |     		case EMsgAsyncControlStateCorrupt:
 | 
|  |   1166 |     		case EMsgAsyncControlStateNoRights:
 | 
|  |   1167 |     			{
 | 
|  |   1168 |     			//the Stop CBA has to be removed here because
 | 
|  |   1169 |     			//playing could be stopped when the tune has finished or
 | 
|  |   1170 |     			//the tune is corrupt
 | 
|  |   1171 |     			delete iStopCba;
 | 
|  |   1172 |     			iStopCba = NULL;
 | 
|  |   1173 |     			break;
 | 
|  |   1174 |     			}
 | 
|  |   1175 |     	}
 | 
|  |   1176 |     }
 | 
|  |   1177 | 
 | 
|  |   1178 | 
 | 
|  |   1179 | #ifdef RD_SCALABLE_UI_V2    
 | 
|  |   1180 | void CRingingToneBioControl::HandlePointerEventL( const TPointerEvent& aPointerEvent )
 | 
|  |   1181 |     {
 | 
|  |   1182 | 
 | 
|  |   1183 | 
 | 
|  |   1184 |     if ( AknLayoutUtils::PenEnabled() )
 | 
|  |   1185 |         {
 | 
|  |   1186 |         switch ( aPointerEvent.iType )
 | 
|  |   1187 |             {
 | 
|  |   1188 |             case TPointerEvent::EButton1Down:
 | 
|  |   1189 |             	{
 | 
|  |   1190 |             	//nothing to do here
 | 
|  |   1191 |             	}
 | 
|  |   1192 |             break;
 | 
|  |   1193 |             case TPointerEvent::EButton1Up:
 | 
|  |   1194 |                 {
 | 
|  |   1195 | 				TBool hitted = iAudioControl->HitRegionContains( aPointerEvent.iPosition, *this );
 | 
|  |   1196 |                 if( hitted )
 | 
|  |   1197 |                     {
 | 
|  |   1198 |                         if ( iPlayerState != EMsgAsyncControlStatePlaying )
 | 
|  |   1199 |                             {
 | 
|  |   1200 |                             //playback is triggered when focused control is touched with stylus
 | 
|  |   1201 |                             iAudioControl->SetFocus(EFalse);
 | 
|  |   1202 |                             PlaybackL();
 | 
|  |   1203 |                             }
 | 
|  |   1204 |                         else if ( iPlayerState == EMsgAsyncControlStatePlaying )
 | 
|  |   1205 |                             {
 | 
|  |   1206 |                             //stylus hit to audio control when playback is in 
 | 
|  |   1207 |                             //progress stops the playing 
 | 
|  |   1208 |                             StopPlayback();
 | 
|  |   1209 |                             }
 | 
|  |   1210 |                     }
 | 
|  |   1211 |             	}
 | 
|  |   1212 |               break;
 | 
|  |   1213 |             default:
 | 
|  |   1214 |                 break;
 | 
|  |   1215 |             }
 | 
|  |   1216 |         }
 | 
|  |   1217 |     }
 | 
|  |   1218 | #else   
 | 
|  |   1219 | void CRingingToneBioControl::HandlePointerEventL( const TPointerEvent& /*aPointerEvent*/ )
 | 
|  |   1220 |     {
 | 
|  |   1221 |     //no op
 | 
|  |   1222 |     }
 | 
|  |   1223 | #endif // RD_SCALABLE_UI_V2    
 | 
|  |   1224 | 
 | 
|  |   1225 | void CRingingToneBioControl::MsgAsyncControlResourceChanged( CMsgBaseControl& /*aControl*/,
 | 
|  |   1226 | 											 				 TInt /*aType*/ )
 | 
|  |   1227 | 	{
 | 
|  |   1228 | 	//no op
 | 
|  |   1229 | 	}
 | 
|  |   1230 | //  End of File
 |