internetradio2.0/uisrc/iraddmanuallystationcontainer.cpp
changeset 3 ee64f059b8e1
parent 2 2e1adbfc62af
child 4 3f2d53f144fe
child 5 0930554dc389
equal deleted inserted replaced
2:2e1adbfc62af 3:ee64f059b8e1
     1 /*
       
     2 * Copyright (c) 2004 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:  Container class for channel list view
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <akniconutils.h>
       
    20 #include <aknindicatorcontainer.h>
       
    21 #include <aknutils.h>
       
    22 
       
    23 #include <akniconarray.h>
       
    24 #include <aknlists.h>
       
    25 #include <aknview.h>
       
    26 #include <barsread.h>
       
    27 #include <eikenv.h>
       
    28 #include <eiklabel.h>
       
    29 #include <eikmenub.h>
       
    30 #include <eikedwin.h>
       
    31 #include <gulicon.h>
       
    32 #include <stringloader.h>
       
    33 #include <internetradio.rsg>
       
    34 #include <internetradio.mbg>
       
    35 #include <baclipb.h>
       
    36 #include <aknsfld.h> //CAknSearchField
       
    37 #include <txtetext.h>
       
    38 #include <eikdialg.h> 
       
    39 #include <akntoolbar.h>
       
    40 #include <aknappui.h>
       
    41 #include <akntouchpane.h>
       
    42 #include <aknbutton.h>
       
    43 #include <f32file.h>
       
    44 #include <s32file.h>
       
    45 #include <eikmenub.h>                       
       
    46 #include <avkon.hrh>                        
       
    47 #include <avkon.rsg>  
       
    48 #include <aknnotewrappers.h>                     
       
    49 #include <aknpopupfieldtext.h>              
       
    50 #include <mgfetch.h> 
       
    51 /* the head file is really uplayer case, so we don't need to change it.  */
       
    52 #include <AknsConstants.h>
       
    53 #include <eikaufty.h>
       
    54 #include <hlplch.h>
       
    55 #include <aknnavi.h>
       
    56 #include <aknnavide.h> 
       
    57 
       
    58 #include "irui.h"
       
    59 #include "ir.hrh"
       
    60 #include "ircommon.h"
       
    61 #include "irdebug.h"
       
    62 #include "irbaseview.h"
       
    63 #include "iriconloader.h"
       
    64 #include "irfavoritesdb.h"
       
    65 #include "irdialoglauncher.h"
       
    66 #include "irpreset.h"
       
    67 #include "irhistory.h"
       
    68 
       
    69 #include "irisdspreset.h"
       
    70 #include "irchannelserverurl.h"
       
    71 #include "irnowplayingwrapper.h"
       
    72 #include "iraddmanuallystationview.h"
       
    73 #include "iraddmanuallystationcontainer.h"
       
    74 #include "irapplication.h"
       
    75 #include "iraap.hlp.hrh" //Added to implement HELP option SPP
       
    76 #include "irsettings.h"     //Added to maintain the IfAnyFav variable in settings
       
    77 
       
    78 
       
    79 const TInt KBeginning = 0;
       
    80 const TInt KMaxLength = 100;
       
    81 const TInt KbufMaxLength = 10;
       
    82 
       
    83 _LIT(KUnamedStation,"Unnamed station");
       
    84 _LIT(KNullStation,"");
       
    85 _LIT(KSpace," ");
       
    86 	
       
    87 const TInt KMaxSize = 256;	
       
    88 // -----------------------------------------------------------------------------
       
    89 // CIRAddManuallyStationContainer::NewL()
       
    90 // Two-phased constructor.
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 CIRAddManuallyStationContainer* CIRAddManuallyStationContainer::NewL(
       
    94 											CIRAddManuallyStationView* aView)  
       
    95     {
       
    96     IRLOG_DEBUG( "CIRAddManuallyStationContainer::NewL - Begin" );
       
    97 	CIRAddManuallyStationContainer* self = new ( ELeave ) CIRAddManuallyStationContainer(aView);//(aToolbar)
       
    98 	CleanupStack::PushL( self );
       
    99 	CleanupStack::Pop( self );
       
   100 	IRLOG_DEBUG( "CIRAddManuallyStationContainer::NewL - Exiting" );
       
   101 	return self;
       
   102     } 
       
   103     
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // C++ default constructor can NOT contain any code, that might leave.
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 CIRAddManuallyStationContainer::CIRAddManuallyStationContainer( CIRAddManuallyStationView* aView):
       
   110 								iView(aView)
       
   111     {
       
   112     IRLOG_DEBUG( "CIRAddManuallyStationContainer::CIRAddManuallyStationContainer" );
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // Destructor
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 CIRAddManuallyStationContainer::~CIRAddManuallyStationContainer()
       
   120     {
       
   121     IRLOG_DEBUG( "CIRAddManuallyStationContainer::~CIRAddManuallyStationContainer" );
       
   122 	if(iPreset)
       
   123 		{
       
   124 		delete iPreset;
       
   125 		iPreset=NULL;	
       
   126 		}
       
   127 	IRLOG_DEBUG( "CIRAddManuallyStationContainer::~CIRAddManuallyStationContainer" );
       
   128     }
       
   129 
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // From class CCoeControl.
       
   133 // Opens help by context.
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 EXPORT_C void CIRAddManuallyStationContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
   137     {
       
   138     IRLOG_DEBUG( "CIRAddManuallyStationContainer::GetHelpContext Begin" );
       
   139     aContext = TCoeHelpContext( KIRMCVUid, KIR_HELP_ADD_URL );
       
   140     IRLOG_DEBUG( "CIRAddManuallyStationContainer::GetHelpContext End" );
       
   141     }
       
   142 
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // CIRAddManuallyStationContainer::DynInitMenuPaneL()
       
   146 // Dynamically initialises a menu pane
       
   147 // ---------------------------------------------------------------------------
       
   148 //
       
   149 void CIRAddManuallyStationContainer::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )
       
   150     { 
       
   151     IRLOG_DEBUG( "CIRAddManuallyStationContainer::DynInitMenuPaneL - Begin " );
       
   152   	CAknForm::DynInitMenuPaneL( aResourceId, aMenuPane );
       
   153     if ( aResourceId == R_AVKON_FORM_MENUPANE )        //R_AVKON_FORM_MENUPANE
       
   154         {
       
   155         aMenuPane->SetItemDimmed( EAknFormCmdLabel, ETrue);
       
   156         aMenuPane->SetItemDimmed( EAknFormCmdAdd, ETrue );
       
   157         aMenuPane->SetItemDimmed( EAknFormCmdDelete, ETrue );
       
   158         aMenuPane->SetItemDimmed( EAknFormCmdSave, ETrue );
       
   159         aMenuPane->SetItemDimmed( EAknFormCmdEdit, ETrue );
       
   160         if(iView->iNowPlayingWrapper->iPlaying)
       
   161 			{
       
   162 			aMenuPane->SetItemDimmed(EGotoNowPlayingViewCmd,EFalse);
       
   163 			}
       
   164 		else
       
   165 			{
       
   166 			aMenuPane->SetItemDimmed(EGotoNowPlayingViewCmd,ETrue);
       
   167 			}
       
   168 	    }
       
   169     IRLOG_DEBUG( "CIRAddManuallyStationContainer::DynInitMenuPaneL - Exiting." );
       
   170     }
       
   171 
       
   172 //-------------------------------------------------------------------------------
       
   173 // CIRAddManuallyStationContainer::ProcessCommandL
       
   174 //  From CAknForm, takes care of command handling.
       
   175 //  @param aCommand Command to be handled
       
   176 //--------------------------------------------------------------------------------
       
   177 void CIRAddManuallyStationContainer::ProcessCommandL( TInt aCommand )    
       
   178     {
       
   179     IRLOG_DEBUG( "CIRAddManuallyStationContainer::ProcessCommandL - Begin " );
       
   180 	CIRUi* appUi = static_cast<CIRUi*>( iCoeEnv->AppUi() );
       
   181 	switch(aCommand)
       
   182 		{
       
   183 	   	case EGotoNowPlayingViewCmd:
       
   184 	   		 {
       
   185 	  	  	 iView->HandleCommandL(EGotoNowPlayingViewCmd);
       
   186 	       	 break;
       
   187 	      	 }
       
   188 	    case EHelpCmd:
       
   189 	         {
       
   190 	      	 iView->HandleCommandL(EHelpCmd);
       
   191 	       	 break;
       
   192 	      	 }
       
   193 	  	case EExitCmd:
       
   194 	  	  	 {
       
   195 	  		 iView->HandleCommandL(EExitCmd);
       
   196 	  		 break;
       
   197 	  		 }
       
   198 	  	default:
       
   199 		   	 iView->HandleCommandL( aCommand );
       
   200 	    	 
       
   201 	 	}
       
   202 	CAknForm::ProcessCommandL(aCommand);
       
   203     IRLOG_DEBUG( "CIRAddManuallyStationContainer::ProcessCommandL - Exiting " );
       
   204     }
       
   205     
       
   206 
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CIRAddManuallyStationContainer::OkToExitL
       
   210 // 
       
   211 // -----------------------------------------------------------------------------
       
   212 TBool CIRAddManuallyStationContainer::OkToExitL( TInt aButtonId )
       
   213     {
       
   214     IRLOG_DEBUG( "CIRAddManuallyStationContainer::OkToExitL - Begin " );
       
   215  	if ( aButtonId == EAknSoftkeyCancel)
       
   216 		{
       
   217 		iView->HandleCommandL(EAknSoftkeyBack);
       
   218 		}
       
   219 	if ( aButtonId == EAknSoftkeyOptions )
       
   220 		{
       
   221 		DisplayMenuL();
       
   222 		}
       
   223     if( aButtonId == EAddExit )
       
   224 	    {
       
   225 	  	iView->HandleCommandL(EAknSoftkeyBack);
       
   226 	  	return ETrue;
       
   227 	    }
       
   228 	TBool ret = CAknForm::OkToExitL( aButtonId );
       
   229 	
       
   230     IRLOG_DEBUG( "CIRAddManuallyStationContainer::OkToExitL - Exiting " );
       
   231     return ret;
       
   232     }    
       
   233 
       
   234 void CIRAddManuallyStationContainer::PreLayoutDynInitL()
       
   235 	{
       
   236 	CAknForm::PreLayoutDynInitL();
       
   237 	}
       
   238 
       
   239 // -----------------------------------------------------------------------------
       
   240 // CIRAddManuallyStationContainer::PostLayoutDynInitL
       
   241 // 
       
   242 // -----------------------------------------------------------------------------
       
   243 void CIRAddManuallyStationContainer::PostLayoutDynInitL()
       
   244 	{
       
   245 	IRLOG_DEBUG( "CIRAddManuallyStationContainer::PostLayoutDynInitL - Begin " );
       
   246 	CIRUi* appUi = static_cast<CIRUi*>( iCoeEnv->AppUi() );
       
   247 	//for enabling paste button if clipboard contains some data
       
   248 	RFs& fs = iEikonEnv->FsSession();
       
   249 	CClipboard* clipBoard = CClipboard::NewForReadingLC(fs);
       
   250 	TBuf<KMaxLength> pasteData;
       
   251 	CPlainText* plainText = CPlainText::NewL();
       
   252 	CleanupStack::PushL(plainText);
       
   253 	plainText->PasteFromStoreL(clipBoard->Store(), clipBoard->StreamDictionary(),KBeginning);
       
   254     plainText->Extract(pasteData,KBeginning,KMaxLength);
       
   255     TInt length=pasteData.Length() ;
       
   256     if(length)
       
   257      	{
       
   258     	iView->iIsCopied=ETrue;
       
   259     	iView->SetToolbarItems();
       
   260      	}
       
   261     CleanupStack::PopAndDestroy(plainText);
       
   262     CleanupStack::PopAndDestroy(clipBoard);
       
   263 	iIsEditStation=iView->iUi->GetEditStation();
       
   264 	if(iIsEditStation)
       
   265 	   	{
       
   266 		TInt urlCount = iView->iNowPlayingWrapper->iEditStationPreset->GetUrlCount();
       
   267 	   	if (urlCount <= 0)
       
   268 	  		{
       
   269 	  		DefaultVauleL();
       
   270 	  		iView->iIsTextEntered=EFalse;
       
   271 			}
       
   272 		else
       
   273 			{
       
   274 			SetEdwinTextL(EAddStaionURL,
       
   275 						  &iView->iNowPlayingWrapper->iEditStationPreset->GetChannelUrlAtL(0) );
       
   276 			TBuf<KMaxSize> unnamedStation(KUnamedStation);
       
   277 			TBuf<KMaxSize> stationName =	iView->iNowPlayingWrapper->iEditStationPreset->GetName();		  	
       
   278 			if(stationName == unnamedStation)
       
   279 				{
       
   280 				stationName.Copy(KNullStation);
       
   281 				}
       
   282 			SetEdwinTextL(EAddStaionName,
       
   283 			              &stationName);	
       
   284 			              
       
   285 			SetEdwinTextL(EAddStaionDescription,
       
   286 			              &iView->iNowPlayingWrapper->iEditStationPreset->GetDescription());
       
   287 						              
       
   288 			iView->iIsTextEntered=ETrue;
       
   289 			}
       
   290 		iView->SetAddStationsTitleL();
       
   291 		iView->SetToolbarItems();
       
   292 	   	}
       
   293 	else
       
   294 		{
       
   295 		DefaultVauleL();
       
   296 		iView->iIsTextEntered=EFalse;
       
   297 		iView->SetToolbarItems();
       
   298 		}
       
   299 
       
   300 //	CEikDialog::SetTitleL(R_IRAPP_ADDMANUALLY_TITLE)
       
   301 	CAknForm::PostLayoutDynInitL();
       
   302 	iView->iUi->HandleResourceChangeL(KEikDynamicLayoutVariantSwitch);
       
   303 	HandleResourceChange(KEikDynamicLayoutVariantSwitch);
       
   304 	IRLOG_DEBUG( "CIRAddManuallyStationContainer::PostLayoutDynInitL - Exiting " );
       
   305 	} 
       
   306 
       
   307 
       
   308 
       
   309 // -----------------------------------------------------------------------------
       
   310 // CIRAddManuallyStationContainer::DefaultVauleL()
       
   311 // 
       
   312 // -----------------------------------------------------------------------------
       
   313 void CIRAddManuallyStationContainer::DefaultVauleL()
       
   314 	{
       
   315 	IRLOG_DEBUG( "CIRAddManuallyStationContainer::DefaultVauleL - Begin " );
       
   316 	HBufC *httpstring = StringLoader::LoadLC(R_IRAPP_ADDMANUALLY_HTTP);
       
   317 	SetEdwinTextL( EAddStaionURL, httpstring );
       
   318 	CleanupStack::PopAndDestroy(httpstring);
       
   319 		    	
       
   320 	HBufC *unnamedstring = StringLoader::LoadLC(R_IRAPP_ADDMANUALLY_NONAME);
       
   321 	SetEdwinTextL( EAddStaionName, unnamedstring );
       
   322 	CleanupStack::PopAndDestroy(unnamedstring);
       
   323 	_LIT(blank,"");
       
   324 	TBuf<KbufMaxLength> buf(blank);  
       
   325 	SetEdwinTextL( EAddStaionDescription,&buf );
       
   326 	
       
   327 	CEikDialog::SetInitialCurrentLine();
       
   328     TryChangeFocusToL(EAddStaionURL);
       
   329     
       
   330     CCoeControl* cntrl = CEikDialog::Control(EAddStaionURL);
       
   331 	CEikEdwin* myEdwin = static_cast<CEikEdwin*> ( cntrl );
       
   332 	TInt txtLength=myEdwin->TextLength();	
       
   333 	myEdwin->SetCursorPosL (txtLength, EFalse);
       
   334     	
       
   335 	iView->SetAddStationsTitleL();
       
   336 	
       
   337 		
       
   338 	IRLOG_DEBUG( "CIRAddManuallyStationContainer::DefaultVauleL - Exiting " );
       
   339 	}
       
   340 	
       
   341 // -----------------------------------------------------------------------------
       
   342 // CIRAddManuallyStationContainer::CopyData
       
   343 // 
       
   344 // -----------------------------------------------------------------------------
       
   345 void CIRAddManuallyStationContainer::CopyDataL()
       
   346 	{
       
   347 	IRLOG_DEBUG( "CIRAddManuallyStationContainer::CopyDataL - Begin " );
       
   348 	RFs& fs = iEikonEnv->FsSession();
       
   349 	CClipboard*	clipBoard = CClipboard::NewForWritingLC(fs);
       
   350 	CPlainText*	plainText = CPlainText::NewL();
       
   351 	CleanupStack::PushL(plainText);
       
   352 	TInt idoffocused = CEikDialog::IdOfFocusControl();
       
   353 	CCoeControl* ictrl = CEikDialog::Control(idoffocused);
       
   354 	CEikEdwin* myEdwin = static_cast<CEikEdwin*> ( ictrl );
       
   355 	TCursorSelection sel=myEdwin->Selection();
       
   356 	GetEdwinText( iSelText, idoffocused );
       
   357 	TInt txtlength=myEdwin->TextLength();
       
   358 	TInt length = sel.Length();
       
   359 	if(length)
       
   360 		{
       
   361 		HBufC* number = HBufC::NewLC( length );
       
   362 		TPtr numberPtr = number->Des();
       
   363 		TInt pos=sel.LowerPos();
       
   364 		if (pos < iSelText.Length())
       
   365 			numberPtr.Copy(&iSelText[pos],length);		
       
   366 		plainText->InsertL(0, *number);
       
   367 		plainText->CopyToStoreL(clipBoard->Store(), clipBoard->StreamDictionary(),KBeginning, 
       
   368 		                        plainText->DocumentLength());
       
   369 		clipBoard->CommitL();
       
   370 		CleanupStack::PopAndDestroy(number);	
       
   371 		}
       
   372 	else
       
   373 		{
       
   374 		myEdwin->SetSelectionL(0,txtlength);
       
   375 		plainText->InsertL(0, iSelText);
       
   376 		plainText->CopyToStoreL(clipBoard->Store(), clipBoard->StreamDictionary(),KBeginning, 
       
   377 		                        plainText->DocumentLength());
       
   378 		clipBoard->CommitL();
       
   379 		}
       
   380 	CleanupStack::PopAndDestroy(plainText);
       
   381 	CleanupStack::PopAndDestroy(clipBoard);
       
   382 	IRLOG_DEBUG( "CIRAddManuallyStationContainer::CopyDataL - Exiting " );
       
   383 	}
       
   384 
       
   385 // -----------------------------------------------------------------------------
       
   386 // CIRAddManuallyStationContainer::PasteData
       
   387 // 
       
   388 // -----------------------------------------------------------------------------
       
   389 void CIRAddManuallyStationContainer::PasteDataL()
       
   390     {
       
   391     IRLOG_DEBUG( "CIRAddManuallyStationContainer::PasteDataL - Begin " );
       
   392     RFs& fs = iEikonEnv->FsSession();
       
   393 	CClipboard* clipBoard = CClipboard::NewForReadingLC(fs);
       
   394 	TBuf<KMaxLength> clipBoardText;
       
   395 	CPlainText* plainText = CPlainText::NewL();
       
   396 	CleanupStack::PushL(plainText);
       
   397 	plainText->PasteFromStoreL(clipBoard->Store(), clipBoard->StreamDictionary(),KBeginning);
       
   398     TInt idOfFocused=CEikDialog::IdOfFocusControl();
       
   399     CCoeControl* ictrl=CEikDialog::Control(idOfFocused);
       
   400     CEikEdwin* myEdwin = static_cast<CEikEdwin*> ( ictrl );
       
   401     TCursorSelection sel=myEdwin->Selection();
       
   402 	GetEdwinText( iSelText, idOfFocused );
       
   403 	HBufC* number = HBufC::NewLC(KMaxLength);
       
   404 	TPtr numberPtr = number->Des();
       
   405 	TInt length = sel.Length();
       
   406 	TInt txtLength=myEdwin->TextLength();
       
   407 	TInt diffLength=KMaxLength-(txtLength-length);
       
   408 	plainText->Extract(clipBoardText,KBeginning,diffLength);
       
   409 	if (txtLength!=0)
       
   410 		{
       
   411 		numberPtr.Copy(&iSelText[0],txtLength);	
       
   412 		if(length!=0)
       
   413 			{
       
   414 			TInt pos=sel.LowerPos();
       
   415 	
       
   416 			numberPtr.Delete(pos,length);
       
   417 			numberPtr.Insert(pos,clipBoardText);
       
   418 			SetEdwinTextL( idOfFocused, number ); 
       
   419 			}
       
   420 		else
       
   421 			{
       
   422 			TInt pos=myEdwin->CursorPos();
       
   423 			numberPtr.Insert(pos,clipBoardText);
       
   424 			SetEdwinTextL( idOfFocused, number ); 
       
   425 			}
       
   426 	    }
       
   427 	else
       
   428 		{
       
   429 		numberPtr.Insert(KBeginning,clipBoardText);
       
   430 		SetEdwinTextL( idOfFocused, number );	
       
   431 		}
       
   432 	TBool enable=ValidateUrlL();
       
   433 	if(enable)
       
   434 		{
       
   435 		iView->iIsTextEntered=ETrue;
       
   436 		iView->SetToolbarItems();			    
       
   437 		}
       
   438 	else
       
   439 		{
       
   440 		iView->iIsTextEntered=EFalse;
       
   441 	   	iView->SetToolbarItems();
       
   442 		}
       
   443 	TInt txtLengthAfterPaste=myEdwin->TextLength();	
       
   444 	myEdwin->SetSelectionL(0,0);
       
   445 	myEdwin->SetCursorPosL (txtLengthAfterPaste, EFalse);
       
   446 
       
   447 	CleanupStack::PopAndDestroy(number); 
       
   448 	CleanupStack::PopAndDestroy(plainText);
       
   449 	CleanupStack::PopAndDestroy(clipBoard);
       
   450 	IRLOG_DEBUG( "CIRAddManuallyStationContainer::PasteDataL - Exiting " );
       
   451 	}
       
   452 
       
   453 // -----------------------------------------------------------------------------
       
   454 // CIRAddManuallyStationContainer::SaveData
       
   455 // 
       
   456 // -----------------------------------------------------------------------------
       
   457 void CIRAddManuallyStationContainer::SaveDataL()
       
   458 	{
       
   459 	IRLOG_DEBUG( "CIRAddManuallyStationContainer::SaveDataL - Begin " );
       
   460 	CIRUi* appUi = static_cast<CIRUi*>( iCoeEnv->AppUi() );
       
   461 	GetEdwinText( iStationURL, EAddStaionURL );
       
   462 	GetEdwinText( iStationName, EAddStaionName );
       
   463 	GetEdwinText( iStationDescription, EAddStaionDescription );
       
   464 	
       
   465 	ReplaceUglyChar(iStationName);
       
   466 	ReplaceUglyChar(iStationDescription);
       
   467 	
       
   468 		
       
   469 	if(iIsEditStation)
       
   470 		{
       
   471 		EditStationL();
       
   472 		iView->iIsTextEntered=EFalse;
       
   473 		}
       
   474 		
       
   475     if(!iIsEditStation)
       
   476 		{
       
   477 		TBool urlStatus = iView->iUi->ParseAndPrepareUrl(iStationURL);
       
   478 		if( !urlStatus )
       
   479 			{
       
   480 			iIsSpaceEntered=ETrue;
       
   481 			iDialogLauncher->ShowErrorNoteL(R_IRAPP_ERROR_ADDRESS, ETrue);
       
   482 			return;	
       
   483 			}
       
   484 		else 
       
   485 			{
       
   486 			AddToFavouritesL();
       
   487 			iView->iIsTextEntered=EFalse;
       
   488 			iView->SetToolbarItems();
       
   489 			DefaultVauleL();
       
   490 			}
       
   491 		}
       
   492 	IRLOG_DEBUG( "CIRAddManuallyStationContainer::SaveDataL - Exiting " );
       
   493 	}
       
   494 
       
   495 /**
       
   496  * void CIRAddManuallyStationContainer::AddToFavouritesL()
       
   497  *
       
   498  * Description		: This method is used to Add the stations to Favourites
       
   499  *  
       
   500  * @Algorithm		: 
       
   501  *		      Step 1: Validate the Staion name by calling 'ReplaceEmptyName'
       
   502  *			          method
       
   503  *		      Step 2: Validate the entered url by calling 'ParseAndPrepareUrl'
       
   504  *                    method.
       
   505  *            Step 3: If Url is incorrect then display an error message, else
       
   506  *					  goto step4.
       
   507  *            Step 4: 
       
   508  *            Step 5: 
       
   509  *                                 
       
   510  * @Param			: [IN]  Nil
       
   511  *					  [OUT] Nil
       
   512  *
       
   513  * @Return		    :
       
   514  *
       
   515  * Example   Usage	: 
       
   516  */
       
   517 void CIRAddManuallyStationContainer::AddToFavouritesL()
       
   518 	{
       
   519 	IRLOG_DEBUG( "CIRAddManuallyStationContainer::AddToFavouritesL - Begin " );
       
   520 	
       
   521 	ReplaceEmptyName( iStationName );  
       
   522 	
       
   523 	TBool isInvalidChar = HasInvalidCharsInUrl(iStationURL);
       
   524 	if( !isInvalidChar)
       
   525 		{
       
   526 		iIsSpaceEntered=ETrue;
       
   527 		iDialogLauncher->ShowErrorNoteL(R_IRAPP_ERROR_ADDRESS, ETrue);
       
   528 		return;	
       
   529 		}
       
   530 		
       
   531 	/**
       
   532 	 * Validate the entered URL 
       
   533 	 */
       
   534 	TBool urlStatus = iView->iUi->ParseAndPrepareUrl(iStationURL);
       
   535 	
       
   536 	/**
       
   537 	 * If the entered URL is incorrect then display the error message
       
   538 	 * "Incorrect URL"
       
   539 	 */
       
   540 	if( !urlStatus )
       
   541 		{
       
   542 		iDialogLauncher = CIRDialogLauncher::NewL();
       
   543 		iView->iIsSpaceEntered=ETrue;
       
   544 		iDialogLauncher->ShowErrorNoteL(R_IRAPP_ERROR_ADDRESS, ETrue);
       
   545 		delete iDialogLauncher;
       
   546 		return;	
       
   547 		}
       
   548 	if(iPreset)
       
   549 		{
       
   550 		delete iPreset;
       
   551 		iPreset=NULL;	
       
   552 		}
       
   553 	   iPreset = CIRIsdsPreset::NewL();
       
   554 	   TInt err(KErrNoMemory);
       
   555 	   iPreset->SetName(iStationName);
       
   556 	   iPreset->SetShortDesc(iStationDescription);
       
   557 	   
       
   558 	   /**
       
   559 	    * only one url is saved for manually added channel
       
   560 	    */
       
   561 	   iPreset->SetUrlCount(1);
       
   562 	   
       
   563 	   _LIT(KNotAvailable,"NA");
       
   564 	   
       
   565 	   /**
       
   566 	    * bitrate set to zero so that it is accessible to all kinds of 
       
   567 	    * bitrate settings
       
   568 	    */
       
   569 	   iPreset->SetUrlL(KNotAvailable,iStationURL,0);
       
   570 	   
       
   571 	   /**
       
   572 	    * Set the Description
       
   573 	    */
       
   574 	   iPreset->SetDescription(iStationDescription);
       
   575 	   
       
   576 	   /**
       
   577 	    * Save into the favourites
       
   578 	    */
       
   579 	   iView->iUi->iFavPresets->AddPresetL(*iPreset,err);		
       
   580 	   
       
   581 	   /**
       
   582 	    * If there is no space in favourites display error note.	
       
   583 	    */
       
   584 	   if (err == KErrNoMemory)
       
   585 			{
       
   586 			iDialogLauncher->ShowErrorNoteL(R_IRAPP_ADDFAVOURITES_ERROR, ETrue);			
       
   587 			}
       
   588 	   else
       
   589 			{
       
   590 			if(iUnNamedFlag)
       
   591 				{
       
   592 				iStationName.Copy(KNullStation);
       
   593 				iUnNamedFlag = EFalse;
       
   594 				iDialogLauncher->ShowConfirmationNoteL( R_IRAPP_STATION_SAVED,ETrue );
       
   595 				}
       
   596 			else
       
   597 				{
       
   598 				iView->iUi->DisplayInformationL(R_IRAPP_STATIONS_POPUP_SAVED, iStationName);
       
   599 				}
       
   600 			iView->iUi->iIRSettings->SetFlagIfAnyFavL();
       
   601 			}
       
   602 	IRLOG_DEBUG( "CIRAddManuallyStationContainer::AddToFavouritesL - Exiting " );
       
   603 	}
       
   604 
       
   605 /**
       
   606  * void CIRAddManuallyStationContainer::EditStationL()
       
   607  *
       
   608  * Description		: This method is used to Edit the userdefined stations
       
   609  *  
       
   610  * @Algorithm		: 
       
   611  *		      Step 1: Validate the entered Url by using 'ParseAndPrepareUrl'
       
   612  *		      Step 2: If Entered Url is incorrect then display an error 
       
   613  *					  message, else goto step3.
       
   614  *            Step3 : calculate the Index of the station to be deleted
       
   615  *            Step4 : create an instance of 'CIRIsdsPreset'
       
   616  *            Step5 : Set the new name of the station
       
   617  *			  Step6 : Set the Short description to the station
       
   618  *			  Step7 : Set the Url 
       
   619  *			  Step8 : Set the Bitrate
       
   620  *			  Step9 : Set the UniqId of the Station to edited
       
   621  *			  Step10: Update the station with modifed values in favourites
       
   622  *                    by calling 'ReplaceUserDefinedPresetL'
       
   623  *			  Step11: Display a confirmation note that station saved
       
   624  *                                 
       
   625  * @Param			: [IN]
       
   626  *					  [OUT]
       
   627  *
       
   628  * @Return		    :
       
   629  *
       
   630  * Example Usage	:
       
   631  */
       
   632 void CIRAddManuallyStationContainer::EditStationL()
       
   633 	{
       
   634 	IRLOG_DEBUG( "CIRAddManuallyStationContainer::EditStationL - Entered" );
       
   635 	
       
   636 	ReplaceUglyChar(iStationName);
       
   637 	
       
   638 	TBool isInvalidChar = HasInvalidCharsInUrl(iStationURL);
       
   639 	if( !isInvalidChar)
       
   640 		{
       
   641 		iIsSpaceEntered=ETrue;
       
   642 		iDialogLauncher->ShowErrorNoteL(R_IRAPP_ERROR_ADDRESS, ETrue);
       
   643 		return;	
       
   644 		}
       
   645 		 
       
   646 	TBool urlStatus = iView->iUi->ParseAndPrepareUrl(iStationURL);
       
   647 	if( !urlStatus )
       
   648 		{
       
   649 		iIsSpaceEntered=ETrue;
       
   650 		iDialogLauncher->ShowErrorNoteL(R_IRAPP_ERROR_ADDRESS, ETrue);
       
   651 		return;	
       
   652 		}
       
   653 	else
       
   654 		{
       
   655 		TInt deleteIndex ;
       
   656 		if (iView->iUi->iLastPlayed->FileExists())
       
   657 			{
       
   658 			deleteIndex = iView->iUi->iEditStationIndex-1;
       
   659 			}
       
   660 		else
       
   661 			{
       
   662 			deleteIndex = iView->iUi->iEditStationIndex;
       
   663 			}
       
   664 		/**
       
   665 		 * prepare isdsPreset with the edited values
       
   666 		 */	
       
   667 		CIRIsdsPreset* isdsPreset =  CIRIsdsPreset::NewL();
       
   668 		
       
   669 		/**
       
   670 		 * Set the Station Name with new station name
       
   671 		 */
       
   672 		if(iStationName.Length()==0)
       
   673 			{
       
   674 			ReplaceEmptyName( iStationName );  
       
   675 			}
       
   676 		isdsPreset->SetName(iStationName);
       
   677 		
       
   678 		/**
       
   679 		 * Set Description with the new Description
       
   680 		 */
       
   681 		isdsPreset->SetShortDesc(iStationDescription);
       
   682 	    
       
   683 	    /**
       
   684 	     *only one url is saved for manually added channel
       
   685 	     */
       
   686 	    isdsPreset->SetUrlCount(1);
       
   687 	    
       
   688 	    _LIT(KNotAvailable,"NA");
       
   689 	    
       
   690 	    /**
       
   691 	     * bitrate set to zero so that it is accessible to all kinds of 
       
   692 	     * bitrate settings
       
   693 	     */
       
   694 	    isdsPreset->SetUrlL(KNotAvailable,iStationURL,0);
       
   695 	    
       
   696 	    isdsPreset->SetDescription(iStationDescription);
       
   697 	    
       
   698 	    /**
       
   699 	     * Set the UniqId of the Station to edit
       
   700 	     */
       
   701 	    if (deleteIndex < iView->iUi->iFavPresets->iFavPresetList.Count())
       
   702 	       isdsPreset->SetUniqId(iView->iUi->iFavPresets->
       
   703 	                          iFavPresetList[deleteIndex]->Id());
       
   704 	    /**
       
   705 	     * Replace the preset with the new values 
       
   706 	     */                      
       
   707 	   	iView->iUi->iFavPresets->ReplaceUserDefinedPresetL(*isdsPreset);
       
   708 		
       
   709 		/**
       
   710 		 * display a confirmation note
       
   711 		 */
       
   712 		if(iUnNamedFlag)
       
   713 			{
       
   714 			iStationName.Copy(KNullStation);
       
   715 			iUnNamedFlag = EFalse;
       
   716 			iDialogLauncher->ShowConfirmationNoteL( R_IRAPP_STATION_SAVED,ETrue );
       
   717 			}
       
   718 		else
       
   719 			{
       
   720 			iView->iUi->DisplayInformationL(R_IRAPP_STATIONS_POPUP_SAVED, 
       
   721 			                                iStationName);
       
   722 			}
       
   723 		if (isdsPreset)
       
   724 			{
       
   725 			delete isdsPreset;
       
   726 			isdsPreset = NULL;				
       
   727 			}
       
   728 		}
       
   729 	IRLOG_DEBUG( "CIRAddManuallyStationContainer::EditStationL - Exited " ); 
       
   730 	}
       
   731 
       
   732 // ----------------------------------------------------------------------------
       
   733 // CIRAddManuallyStationContainer::ReplaceEmptyName( TDes& aUrlName )
       
   734 // Checks whether the url name contains only spaces and if the descriptor really was.
       
   735 // empty replaces its content with default name
       
   736 // ----------------------------------------------------------------------------
       
   737 void CIRAddManuallyStationContainer::ReplaceEmptyName( TDes& aUrlName )
       
   738 	{
       
   739 	IRLOG_DEBUG( "CIRAddManuallyStationContainer::ReplaceEmptyName - Begin " );
       
   740 	TBool isEmpty = ETrue;
       
   741 	for( TInt i = 0; i < aUrlName.Length() && isEmpty; i++ )
       
   742 		{
       
   743 		( static_cast<TChar>( aUrlName[i] ) ).Fold();
       
   744 		if ( !( static_cast<TChar>( aUrlName[i] ) ).IsSpace() )
       
   745 			{
       
   746 			isEmpty = EFalse;
       
   747 			}
       
   748 	   	}
       
   749 	    if ( isEmpty )		
       
   750 	  		{
       
   751 	    	StringLoader::Load( aUrlName, R_IRAPP_ADDMANUALLY_NOTEXT );
       
   752 	    	iUnNamedFlag = ETrue;
       
   753 	  		}
       
   754 	    IRLOG_DEBUG( "CIRAddManuallyStationContainer::ReplaceEmptyName - Exiting " );
       
   755 	}
       
   756 
       
   757 
       
   758 void CIRAddManuallyStationContainer::ReplaceUglyChar(TDes& aUrlName)
       
   759 	{
       
   760 	for(TInt i = 0; i < aUrlName.Length(); i++)
       
   761 		{
       
   762 		TChar xChar(aUrlName[i]);
       
   763 		if (xChar.GetCategory() == TChar::EZpCategory)
       
   764 			{
       
   765 			aUrlName.Replace(i, 1, KSpace);				
       
   766 			}
       
   767 		}
       
   768 	}
       
   769 
       
   770 // ----------------------------------------------------------------------------
       
   771 // CIRAddManuallyStationContainer::HandlePointerEventL(const TPointerEvent&  
       
   772 // aPointerEvent)
       
   773 // This function is used handle pen input events 
       
   774 // ----------------------------------------------------------------------------
       
   775 void CIRAddManuallyStationContainer::HandlePointerEventL(const TPointerEvent &aPointerEvent) 
       
   776 	{
       
   777 	IRLOG_DEBUG( "CIRAddManuallyStationContainer::HandlePointerEventL - Begin " );
       
   778     CAknForm::HandlePointerEventL( aPointerEvent );
       
   779     IRLOG_DEBUG( "CIRAddManuallyStationContainer::HandlePointerEventL - Exiting " );
       
   780     }
       
   781 
       
   782 // ---------------------------------------------------------------------------
       
   783 //TBool CIRAddManuallyStationContainer::ValidateUrlL() 
       
   784 //Validates The entered URL Scheme 
       
   785 // ---------------------------------------------------------------------------
       
   786 TBool CIRAddManuallyStationContainer::ValidateUrlL()
       
   787 	{
       
   788 	IRLOG_DEBUG( "CIRAddManuallyStationContainer::ValidateUrlL - Begin " );
       
   789 	TBool retVal = EFalse;
       
   790 	_LIT(KMMSText, "mms://");
       
   791 	
       
   792 	TBuf<KbufMaxLength> iTextBoxValidateUrl;
       
   793 	HBufC *httpstring1 = StringLoader::LoadLC(R_IRAPP_ADDMANUALLY_HTTP);
       
   794 	iTextBoxValidateUrl = *httpstring1;
       
   795 
       
   796    	HBufC* mmsString  = HBufC::NewLC(KbufMaxLength);
       
   797 	*mmsString = KMMSText;
       
   798 	TBuf<KbufMaxLength> textBoxValidateMMS(*mmsString);
       
   799 
       
   800 	
       
   801 	GetEdwinText( iStationURL, EAddStaionURL );
       
   802 	
       
   803 	CleanupStack::PopAndDestroy(mmsString);
       
   804 	CleanupStack::PopAndDestroy(httpstring1);
       
   805 
       
   806     if ( iTextBoxValidateUrl.CompareF( iStationURL.Left( iTextBoxValidateUrl.Length()))== 0)
       
   807 		{
       
   808 		if ( iStationURL.Length() <= iTextBoxValidateUrl.Length() ||
       
   809     	     iTextBoxValidateUrl.CompareF( iStationURL.Left( iTextBoxValidateUrl.Length() ))) 
       
   810 			{
       
   811 			retVal = EFalse;
       
   812 			}
       
   813 	    else 
       
   814 	    	{
       
   815 			retVal = ETrue;
       
   816 			}
       
   817 		}
       
   818 	else if (textBoxValidateMMS.CompareF( iStationURL.Left( textBoxValidateMMS.Length()))==0)
       
   819 		{
       
   820 		if ( iStationURL.Length() <= textBoxValidateMMS.Length() ||
       
   821     	     textBoxValidateMMS.CompareF( iStationURL.Left( textBoxValidateMMS.Length() ))) 
       
   822 			{
       
   823 			retVal = EFalse;
       
   824 			}
       
   825 	    else 
       
   826 	    	{
       
   827 			retVal = ETrue;
       
   828 			}
       
   829 		}
       
   830 
       
   831     else
       
   832 	    {
       
   833 		//nothing	    	
       
   834 	    }
       
   835 	IRLOG_DEBUG( "CIRAddManuallyStationContainer::ValidateUrlL - Exiting " );	
       
   836 	return retVal;
       
   837 	}
       
   838 	
       
   839 	
       
   840 // ---------------------------------------------------------------------------
       
   841 // void CIRAddManuallyStationContainer::HandleControlEventL(CCoeControl* aControl, 
       
   842 //                                                          TCoeEvent aEventType)
       
   843 // To handle key events.
       
   844 // 
       
   845 // ---------------------------------------------------------------------------
       
   846 
       
   847 void CIRAddManuallyStationContainer::HandleControlEventL( 
       
   848                                                     CCoeControl* aControl, 
       
   849                                                     TCoeEvent aEventType)
       
   850 	{
       
   851 	IRLOG_DEBUG( "CIRAddManuallyStationContainer::HandleControlEventL - Begin " );
       
   852     CAknForm::HandleControlEventL(aControl, aEventType);
       
   853     if (aEventType == EEventStateChanged)
       
   854     	{
       
   855         if (aControl == Control(EAddStaionURL))
       
   856             {
       
   857 		  	TInt focus=CEikDialog::IdOfFocusControl();
       
   858 	      	CCoeControl* ictrl=CEikDialog::Control(focus);
       
   859 	      	TBool enable=ValidateUrlL();
       
   860 	      	iIsEnable = enable;
       
   861 	    	if(enable)
       
   862 	  			{
       
   863 	  			iView->iIsTextEntered=ETrue;
       
   864 	    	 	iView->SetToolbarItems();			    
       
   865 	  			}
       
   866 	  		else
       
   867 	  			{
       
   868 	  			iView->iIsTextEntered=EFalse;
       
   869 	    	 	iView->SetToolbarItems();
       
   870 	  			}
       
   871             }
       
   872         if (aControl == Control(EAddStaionName))
       
   873             {
       
   874             }  
       
   875     	}
       
   876     IRLOG_DEBUG( "CIRAddManuallyStationContainer::HandleControlEventL - Exiting " );
       
   877 	}
       
   878 	
       
   879 	
       
   880 // ---------------------------------------------------------------------------
       
   881 //void CIRAddManuallyStationContainer::HandleResourceChange (TInt aType)
       
   882 //
       
   883 // 
       
   884 // ---------------------------------------------------------------------------
       
   885 
       
   886 void CIRAddManuallyStationContainer::HandleResourceChange (TInt /*aType*/)
       
   887 	{
       
   888 	IRLOG_DEBUG( "CIRAddManuallyStationContainer::HandleResourceChange - Begin " );
       
   889     CAknForm::HandleResourceChange(KEikDynamicLayoutVariantSwitch);
       
   890     
       
   891     iView->RefreshView();
       
   892     
       
   893 	SizeChanged();
       
   894 	DrawDeferred();
       
   895     IRLOG_DEBUG( "CIRAddManuallyStationContainer::HandleResourceChange - Exiting " );   
       
   896 	}
       
   897 
       
   898 // ---------------------------------------------------------------------------
       
   899 //void CIRAddManuallyStationContainer::SizeChanged ()
       
   900 //
       
   901 // ---------------------------------------------------------------------------
       
   902 
       
   903 void CIRAddManuallyStationContainer::SizeChanged()
       
   904 	{
       
   905 	CAknForm::SizeChanged();		
       
   906 	}
       
   907 	
       
   908 // ---------------------------------------------------------------------------
       
   909 //TBool CIRAddManuallyStationContainer::HasInvalidCharsInUrl (TDes& aUrl)
       
   910 //
       
   911 // ---------------------------------------------------------------------------
       
   912 
       
   913 TBool CIRAddManuallyStationContainer::HasInvalidCharsInUrl(TDes& aUrl)
       
   914 	{
       
   915 	TBool retVal = EFalse;
       
   916 	for(TInt i = 0; i < aUrl.Length(); i++)
       
   917 		{
       
   918 		TChar xChar(aUrl[i]);
       
   919 		switch(xChar.GetCategory())
       
   920 			{
       
   921 			case TChar::ESeparatorGroup: 
       
   922 			case TChar::EControlGroup:
       
   923 			case TChar::EZpCategory:
       
   924 			case TChar::EWhitespace:
       
   925 			case TChar::EZlCategory:
       
   926 			case TChar::EParagraphSeparator:
       
   927 			case TChar::ESegmentSeparator:
       
   928 		  	case TChar::EPsCategory: 
       
   929 			case TChar::EPeCategory:
       
   930 				{
       
   931 				retVal = EFalse;
       
   932 				}
       
   933 			break;
       
   934 			default:
       
   935 				{
       
   936 				retVal = ETrue;
       
   937 				}
       
   938 			}
       
   939 		(static_cast<TChar>( aUrl[i] ) ).Fold();
       
   940 		if( ( static_cast<TChar>( aUrl[i] ) ) == '%' || 
       
   941 		    ( static_cast<TChar>( aUrl[i] ) ) == '^' ||
       
   942 		    ( static_cast<TChar>( aUrl[i] ) ) == '"' ||
       
   943 		    ( static_cast<TChar>( aUrl[i] ) ) == '\\'||
       
   944 		    ( static_cast<TChar>( aUrl[i] ) ) == '`' ||
       
   945 		    ( static_cast<TChar>( aUrl[i] ) ) == '|' ||
       
   946 		    ( static_cast<TChar>( aUrl[i] ) ) == '<' ||
       
   947 		    ( static_cast<TChar>( aUrl[i] ) ) == '>' ||
       
   948 		    ( static_cast<TChar>( aUrl[i] ) ) == '#' )
       
   949 			{
       
   950 			retVal = EFalse;					
       
   951 			}
       
   952 		
       
   953 		
       
   954 		if(!retVal)
       
   955 			{
       
   956 			i = aUrl.Length();							
       
   957 			}
       
   958 		}
       
   959 	return retVal;		
       
   960 	}
       
   961