browserui/browser/FeedsSrc/FeedsFolderContainer.cpp
branchRCL_3
changeset 65 8e6fa1719340
equal deleted inserted replaced
64:6385c4c93049 65:8e6fa1719340
       
     1 /*
       
     2 * Copyright (c) 2005-2008 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 the License "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:  A view to browse a user's list of feeds.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <Browser_platform_variant.hrh>
       
    19 #include <AknNavi.h>
       
    20 #include <AknNaviDe.h>
       
    21 #include <AknNaviLabel.h>
       
    22 #include <akniconarray.h>
       
    23 #include <aknlists.h>
       
    24 #include <aknpopup.h>
       
    25 #include <aknsconstants.h>
       
    26 #include <aknsutils.h>
       
    27 #include <AknToolbar.h>
       
    28 #include <avkon.mbg>
       
    29 #include <data_caging_path_literals.hrh>
       
    30 #include <eikclbd.h>
       
    31 #include <f32file.h>
       
    32 #include <gulicon.h>
       
    33 #include <aknconsts.h>
       
    34 #include <StringLoader.h>
       
    35 
       
    36 #ifdef __SERIES60_HELP
       
    37 // Context-Sensitve Help File
       
    38 #include <csxhelp/browser.hlp.hrh>
       
    39 #include "BrowserApplication.h"
       
    40 #endif // __SERIES60_HELP
       
    41 
       
    42 #include "Browser.hrh"
       
    43 #include <BrowserNG.rsg>
       
    44 #include <browser.mbg>
       
    45 #include <brctldialogsprovider.h>
       
    46 #include <browserdialogsprovider.h>
       
    47 
       
    48 #include <feedattributes.h>
       
    49 #include <folderattributes.h>
       
    50 
       
    51 #include <feedsentity.h>
       
    52 #include "FeedsFolderContainer.h"
       
    53 #include "FeedsFolderView.h"
       
    54 #include "ApiProvider.h"
       
    55 #include "Display.h"
       
    56 #include "BrowserAppUi.h"
       
    57 #include "BrowserDialogs.h"
       
    58 #include "BrowserUtil.h"
       
    59 #include <AknUtils.h>
       
    60 // It's also the size of the icon array without favicon
       
    61 const TInt KFirstFaviconIndex = 6;
       
    62 const TInt KDateSize = 30;          // Size of Date strings
       
    63 const TInt KTimeSize = 30;          // Size of Time strings
       
    64 
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CFeedsFolderContainer::NewL
       
    68 //
       
    69 // Two-phased constructor.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CFeedsFolderContainer* CFeedsFolderContainer::NewL( CFeedsFolderView* aView,
       
    73             MApiProvider& aApiProvider, const TRect& aRect)
       
    74 
       
    75     {
       
    76     CFeedsFolderContainer* self = new (ELeave) CFeedsFolderContainer(aView, aApiProvider);
       
    77     
       
    78     CleanupStack::PushL(self);
       
    79     self->ConstructL(aRect);
       
    80     CleanupStack::Pop();
       
    81 
       
    82     return self;
       
    83     }
       
    84 
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CFeedsFolderContainer::CFeedsFolderContainer
       
    88 //
       
    89 // C++ default constructor.
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 CFeedsFolderContainer::CFeedsFolderContainer(CFeedsFolderView* aView,
       
    93                              MApiProvider& aApiProvider ) :
       
    94     iView( aView ),
       
    95     iApiProvider( aApiProvider ),
       
    96     iOwnsListBoxIcons(ETrue)
       
    97     {
       
    98     }
       
    99 
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CFeedsFolderContainer::ConstructL
       
   103 //
       
   104 // Symbian 2nd phase constructor can leave.
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void CFeedsFolderContainer::ConstructL(const TRect& aRect)
       
   108     {
       
   109     // Set up the control.
       
   110     CreateWindowL();
       
   111 	SetMopParent( iView );
       
   112     InitContainerL(aRect);
       
   113     SetRect(aRect);
       
   114     ActivateL();
       
   115     }
       
   116 
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CFeedsFolderContainer::~CFeedsFolderContainer
       
   120 //
       
   121 // Deconstructor.
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 CFeedsFolderContainer::~CFeedsFolderContainer()
       
   125     {
       
   126     iTargetFolderList.Close();
       
   127     if (iOwnsListBoxIcons)
       
   128         {
       
   129         delete iListBoxIcons;
       
   130         }
       
   131         
       
   132     delete iListBox;
       
   133     delete iListBoxRows;
       
   134     if(iNaviDecorator)
       
   135        {
       
   136        delete iNaviDecorator;
       
   137        iNaviDecorator = NULL;
       
   138        }
       
   139     }
       
   140 
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CFeedsFolderContainer::OfferKeyEventL
       
   144 //
       
   145 // Handles key event.
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 TKeyResponse CFeedsFolderContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, 
       
   149         TEventCode aType)
       
   150     {
       
   151     TKeyResponse isConsumed = EKeyWasConsumed;
       
   152 
       
   153     if (aType != EEventKey) 
       
   154         {
       
   155         return EKeyWasNotConsumed;
       
   156         }
       
   157         
       
   158     // handle # key press by marking current unmarked item or unmarking current marked item.        
       
   159     if ((aType == EEventKey) && (aKeyEvent.iScanCode == EStdKeyHash))
       
   160         {
       
   161         
       
   162         // Check if current item is marked
       
   163         const CArrayFix<TInt>* markedIndexes = MarkedItems();
       
   164         TInt i;
       
   165         TBool currentMarked = EFalse;
       
   166         
       
   167         // check to see if there are any items in the list, if not ignore the #
       
   168         if (iListBoxRows->Count() > 0)
       
   169         	{
       
   170 	        for ( i = 0; i < MarkedItems()->Count(); i++ )
       
   171 	            {
       
   172 	            if ( CurrentItemIndex() == (*markedIndexes)[i] )
       
   173 	                {
       
   174 	                currentMarked = ETrue;
       
   175 	                break;
       
   176 	                }
       
   177 	            }
       
   178 	            
       
   179 	        if (currentMarked)
       
   180 	            {
       
   181 	            HandleMarkL( EAknCmdUnmark );
       
   182 	            }
       
   183 	        else
       
   184 	            {
       
   185 	            HandleMarkL( EAknCmdMark );
       
   186 	            }
       
   187 	        UpdateCbaL();	                	
       
   188         	}
       
   189 
       
   190         return EKeyWasConsumed;
       
   191         }
       
   192 
       
   193     // If a move is active process the move.
       
   194     else if (iMoveActive && ((aKeyEvent.iCode == EKeyOK) || (aKeyEvent.iCode == EKeyEnter)))
       
   195         {
       
   196         PostHandleMoveL();
       
   197 
       
   198         iMoveActive = EFalse;
       
   199         UpdateCbaL();
       
   200         // Undim Toolbar
       
   201         DimToolbar(EFalse);
       
   202         
       
   203         return isConsumed;
       
   204         }
       
   205 
       
   206     // If the C-Key was pressed then delete the current item.
       
   207     else if (aKeyEvent.iCode == EKeyBackspace)
       
   208         {
       
   209         HandleDeleteL();
       
   210         return isConsumed;
       
   211         }
       
   212         
       
   213     isConsumed = EKeyWasNotConsumed;    
       
   214     // For handling Enter key in emulator / Keyboard ( Enter key should behave similar to MSK )
       
   215 	if(EStdKeyEnter == aKeyEvent.iScanCode && EEventKey == aType && AknLayoutUtils::MSKEnabled())
       
   216 		{
       
   217 		CEikButtonGroupContainer* myCba = CEikButtonGroupContainer::Current();
       
   218 		if(myCba != NULL)
       
   219 			{
       
   220 			TInt cmdId = myCba->ButtonGroup()->CommandId(CEikButtonGroupContainer::EMiddleSoftkeyPosition);
       
   221 			if(EAknSoftkeyContextOptions  == cmdId)
       
   222 				{
       
   223 				iView->MenuBar()->TryDisplayContextMenuBarL();
       
   224 				isConsumed = EKeyWasConsumed;
       
   225 				}
       
   226 			else if(iListBox->Model()->ItemTextArray()->MdcaCount() == 0)
       
   227 				{
       
   228 				iView->HandleCommandL(cmdId);
       
   229 				isConsumed = EKeyWasConsumed;
       
   230 				}
       
   231 			}
       
   232 		}
       
   233     // Otherwise let the listbox handle it.
       
   234     if(isConsumed != EKeyWasConsumed)
       
   235         {
       
   236         isConsumed = iListBox->OfferKeyEventL(aKeyEvent, aType);
       
   237         
       
   238         // Toolbar buttons should be updated when focus moves from feed to folder or vice versa
       
   239         if((aType == EEventKey) && ((aKeyEvent.iScanCode == EStdKeyUpArrow)||(aKeyEvent.iScanCode == EStdKeyDownArrow)) )
       
   240     		{
       
   241     		UpdateToolbarButtonsState();
       
   242       		}        
       
   243         }
       
   244     return isConsumed;
       
   245     }
       
   246 
       
   247 
       
   248 // -----------------------------------------------------------------------------
       
   249 // CFeedsFolderContainer::GetHelpContext
       
   250 //
       
   251 // Get help context for the control.
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 #ifdef __SERIES60_HELP
       
   255 void CFeedsFolderContainer::GetHelpContext(TCoeHelpContext& aContext) const
       
   256     {
       
   257     // This must be the Browser's uid becasue the help texts are under Browser topics.
       
   258     aContext.iMajor = KUidBrowserApplication;
       
   259     aContext.iContext = KOSS_HLP_RSS_MAIN;
       
   260     }
       
   261 #endif // __SERIES60_HELP
       
   262 
       
   263 
       
   264 // -----------------------------------------------------------------------------
       
   265 // CFeedsFolderContainer::SizeChanged
       
   266 //
       
   267 // Called by framework when the view size is changed.
       
   268 // -----------------------------------------------------------------------------
       
   269 //
       
   270 void CFeedsFolderContainer::SizeChanged()
       
   271     {
       
   272     iListBox->SetRect(Rect());
       
   273     }
       
   274 
       
   275 
       
   276 // -----------------------------------------------------------------------------
       
   277 // CFeedsFolderContainer::HandleResourceChange
       
   278 //
       
   279 // Called by the framework when a display resource changes (i.e. skin or layout).
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 void CFeedsFolderContainer::HandleResourceChange(TInt aType)
       
   283     {
       
   284     CCoeControl::HandleResourceChange(aType);
       
   285     iListBox->HandleResourceChange(aType);
       
   286     
       
   287     if (aType == KEikDynamicLayoutVariantSwitch)
       
   288         {
       
   289         TRect  rect;
       
   290         
       
   291         if (AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect))
       
   292             {
       
   293             SetRect(rect);
       
   294             }
       
   295         }
       
   296     }
       
   297 
       
   298 
       
   299 // -----------------------------------------------------------------------------
       
   300 // CFeedsFolderContainer::CountComponentControls
       
   301 //
       
   302 // Returns number of components.
       
   303 // -----------------------------------------------------------------------------
       
   304 //
       
   305 TInt CFeedsFolderContainer::CountComponentControls() const
       
   306     {
       
   307     return 1;
       
   308     }
       
   309 
       
   310 
       
   311 // -----------------------------------------------------------------------------
       
   312 // CFeedsFolderContainer::ComponentControl
       
   313 //
       
   314 // Returns pointer to particular component.
       
   315 // -----------------------------------------------------------------------------
       
   316 //
       
   317 CCoeControl* CFeedsFolderContainer::ComponentControl(TInt aIndex) const
       
   318     {
       
   319     switch (aIndex)
       
   320         {
       
   321         case 0:
       
   322             return iListBox;
       
   323 
       
   324         default:
       
   325             return NULL;
       
   326         }
       
   327     }
       
   328 
       
   329 
       
   330 // -----------------------------------------------------------------------------
       
   331 // CFeedsFolderContainer::HandleListBoxEventL
       
   332 //
       
   333 // Processes key events from the listbox.
       
   334 // -----------------------------------------------------------------------------
       
   335 //
       
   336 void CFeedsFolderContainer::HandleListBoxEventL(CEikListBox* /*aListBox*/, 
       
   337         TListBoxEvent aEventType)
       
   338     {
       
   339 #ifdef BRDO_SINGLE_CLICK_ENABLED_FF    
       
   340     if (aEventType == MEikListBoxObserver::EEventEmptyListClicked)
       
   341         {
       
   342             return;
       
   343         }
       
   344 #endif    
       
   345     // An item was selected.
       
   346     if ((aEventType == MEikListBoxObserver::EEventEnterKeyPressed) ||
       
   347         (aEventType == MEikListBoxObserver::EEventItemDoubleClicked)
       
   348 #ifdef BRDO_SINGLE_CLICK_ENABLED_FF		
       
   349 		 || (aEventType == MEikListBoxObserver::EEventItemSingleClicked)
       
   350 #endif		 
       
   351 		 )
       
   352         {
       
   353         if ( iMoveActive )
       
   354             {
       
   355             HandleOkL();
       
   356             }
       
   357         else 
       
   358             {
       
   359             HandleSelectionL();
       
   360             }
       
   361         }
       
   362     // Toolbar buttons status should be changed when focus is moved from feed to folder or viceversa
       
   363     else if ( (aEventType == MEikListBoxObserver::EEventItemClicked)
       
   364 #ifdef BRDO_TOUCH_ENABLED_FF
       
   365             ||(aEventType == MEikListBoxObserver::EEventFlickStopped)
       
   366 #endif // BRDO_TOUCH_ENABLED_FF            
       
   367             )
       
   368       	{
       
   369 		UpdateToolbarButtonsState();
       
   370       	}
       
   371     }
       
   372 
       
   373 // -----------------------------------------------------------------------------
       
   374 // CFeedsFolderContainer::SearchForFeed
       
   375 //
       
   376 // Recursive loop to find a feed
       
   377 // -----------------------------------------------------------------------------
       
   378 // 
       
   379 TBool CFeedsFolderContainer::SearchForFeedL(const CFeedsEntity* aCurrent)
       
   380     {
       
   381     TBool isFeed = EFalse;
       
   382     
       
   383     __ASSERT_DEBUG( (aCurrent != NULL), Util::Panic( Util::EUninitializedData ));
       
   384 
       
   385     for (int i = 0; i < (aCurrent->GetChildren().Count()); i++)
       
   386         {      
       
   387         const CFeedsEntity* item = aCurrent->GetChildren()[i];
       
   388 
       
   389         if ( !(item->GetType() == EFolder ))
       
   390             {
       
   391             return ETrue;
       
   392             }
       
   393         else
       
   394             {
       
   395             // is folder empty?
       
   396             if ( item->GetChildren().Count() == 0 )
       
   397                 {
       
   398                 continue;
       
   399                 }
       
   400             else
       
   401                 {
       
   402                 isFeed = SearchForFeedL(item); // recursive
       
   403 
       
   404                 if ( isFeed )
       
   405                     {
       
   406                     return ETrue;
       
   407                     }
       
   408                 }
       
   409             }
       
   410 
       
   411         }
       
   412     return EFalse;
       
   413     }
       
   414 
       
   415 // -----------------------------------------------------------------------------
       
   416 // CFeedsFolderContainer::UpdateToolbarButtons
       
   417 //
       
   418 // Updates the state of the toolbar buttons depending on the situation
       
   419 // -----------------------------------------------------------------------------
       
   420 //
       
   421 
       
   422 void CFeedsFolderContainer::UpdateToolbarButtonsState()
       
   423     {
       
   424     TBool isFeed = EFalse;
       
   425     TBool feedInFocus = EFalse;
       
   426  
       
   427 
       
   428     if (iMoveActive || !iCurrentFolder)
       
   429         {
       
   430         return;        
       
   431         }
       
   432 
       
   433  
       
   434     TInt num = iCurrentFolder->GetChildren().Count();
       
   435 
       
   436     if ( iCurrentFolder->GetChildren().Count() == 0 )
       
   437         {
       
   438         iView->Toolbar()->SetItemDimmed(EFeedsUpdate, ETrue, ETrue);
       
   439         iView->Toolbar()->SetItemDimmed(EFeedsUpdateAll, ETrue, ETrue);
       
   440         iView->Toolbar()->SetItemDimmed(EFeedsOpen, ETrue, ETrue);             
       
   441         }
       
   442     else
       
   443         {
       
   444         TRAP_IGNORE(
       
   445         {
       
   446         isFeed = SearchForFeedL(iRootFolder);
       
   447         });
       
   448 
       
   449 		// if feed is not in focus in the current view, then dim the 'update' button
       
   450         const CFeedsEntity*  fItem = NULL;
       
   451 		// Get the current item.
       
   452 		fItem = CurrentItem();
       
   453         if ( !(fItem->GetType() == EFolder ))
       
   454             {
       
   455         	feedInFocus = ETrue;
       
   456             }
       
   457 
       
   458         if ( isFeed && feedInFocus )
       
   459             {
       
   460             iView->Toolbar()->SetItemDimmed(EFeedsUpdate,IsMarkedItemFolder()?ETrue:EFalse, ETrue);
       
   461             iView->Toolbar()->SetItemDimmed(EFeedsUpdateAll, EFalse, ETrue);
       
   462             iView->Toolbar()->SetItemDimmed(EFeedsOpen, EFalse, ETrue);
       
   463             }
       
   464         else if ( isFeed && !feedInFocus )
       
   465             {
       
   466             iView->Toolbar()->SetItemDimmed(EFeedsUpdate, ETrue, ETrue);
       
   467             iView->Toolbar()->SetItemDimmed(EFeedsUpdateAll, EFalse, ETrue);
       
   468             iView->Toolbar()->SetItemDimmed(EFeedsOpen, EFalse, ETrue);
       
   469             }
       
   470         else
       
   471             {
       
   472             iView->Toolbar()->SetItemDimmed(EFeedsUpdate, ETrue, ETrue);
       
   473             iView->Toolbar()->SetItemDimmed(EFeedsUpdateAll, ETrue, ETrue);
       
   474             iView->Toolbar()->SetItemDimmed(EFeedsOpen, EFalse, ETrue);
       
   475             }
       
   476         }
       
   477     }
       
   478 
       
   479 
       
   480 
       
   481 // -----------------------------------------------------------------------------
       
   482 // CFeedsFolderContainer::UpdateFeedL
       
   483 //
       
   484 // Called when a feed's name and/or url is changed -- this is called after both
       
   485 // IsValidFeedName and IsValidFeedUrl are called.
       
   486 // -----------------------------------------------------------------------------
       
   487 //
       
   488 void CFeedsFolderContainer::UpdateFeedL(const TDesC& aName, const TDesC& aUrl, TInt aFreq)
       
   489     {
       
   490     UpdateCurrentItemL(&aName, &aUrl, aFreq);
       
   491     }
       
   492 
       
   493 
       
   494 // -----------------------------------------------------------------------------
       
   495 // CFeedsFolderContainer::NewFeedL
       
   496 //
       
   497 // Called when a new feed is created -- this is called after both
       
   498 // IsValidFeedName and IsValidFeedUrl are called.
       
   499 // -----------------------------------------------------------------------------
       
   500 //
       
   501 void CFeedsFolderContainer::NewFeedL(const TDesC& aName, const TDesC& aUrl, TInt aFreq)
       
   502     {
       
   503     AddNewFeedL(aName, aUrl, aFreq);
       
   504     }
       
   505 
       
   506 
       
   507 // -----------------------------------------------------------------------------
       
   508 // CFeedsFolderContainer::IsFeedNameValidL
       
   509 //
       
   510 // Validates the Feed's updated name.
       
   511 // -----------------------------------------------------------------------------
       
   512 //
       
   513 TBool CFeedsFolderContainer::IsFeedNameValidL(const TDesC* aName, TBool aIsEditing)
       
   514     {
       
   515     TBool  valid = ETrue;
       
   516     TInt pos(0);
       
   517     
       
   518     // If aName is NULL show an info dialog and reject it.
       
   519     if (aName == NULL)
       
   520         {
       
   521         TBrowserDialogs::ErrorNoteL( R_FEEDS_TITLE_NEEDED );
       
   522         valid = EFalse;
       
   523         }
       
   524 
       
   525     //If aName contains single quote character, then show an info dialog and reject it
       
   526     else if ((pos = aName->Locate('\'')) != KErrNotFound)
       
   527         {
       
   528         TBrowserDialogs::ErrorNoteL( R_FEEDS_TITLE_SINGLE_QUOTE_NOT_ALLOWED );
       
   529         valid = EFalse;
       
   530         }
       
   531 
       
   532     // If the name is a duplicate show an info dialog and reject it.
       
   533     else
       
   534         {
       
   535         const CFeedsEntity*  otherItem;
       
   536 
       
   537         // Reject it if _some other_ item has the same name.
       
   538         if ((iRootFolder != NULL) && ((otherItem = iApiProvider.FeedsClientUtilities().Search(*aName,*iRootFolder)) != NULL))
       
   539             {            
       
   540             if (!((otherItem == CurrentItem()) && aIsEditing))
       
   541                 {
       
   542                 TBrowserDialogs::ErrorNoteL( R_FEEDS_NAME_ALREADY_IN_USE );
       
   543                 valid = EFalse;
       
   544                 }
       
   545             }
       
   546         }
       
   547 
       
   548     return valid;
       
   549     }
       
   550 
       
   551 
       
   552 // -----------------------------------------------------------------------------
       
   553 // CFeedsFolderContainer::IsFeedUrlValidL
       
   554 //
       
   555 // Validates the Feed's updated url.
       
   556 // -----------------------------------------------------------------------------
       
   557 //
       
   558 TBool CFeedsFolderContainer::IsFeedUrlValidL(const TDesC* aUrl)
       
   559     {
       
   560     TBool  valid = ETrue;
       
   561 
       
   562     // If aUrl is NULL show an info dialog and reject it.
       
   563     if (aUrl == NULL)
       
   564         {
       
   565         valid = EFalse;
       
   566         }
       
   567         
       
   568     // Otherwise if the user didn't change the default url (i.e. "http://"
       
   569     // then reject it too.
       
   570     else
       
   571         {
       
   572     	HBufC*  defaultUrl = NULL;
       
   573 	
       
   574         // Load the label
       
   575         defaultUrl = CCoeEnv::Static()->AllocReadResourceAsDes16L(R_FEEDS_NEW_FEED_URL_ITEM);
       
   576         if (defaultUrl->Compare(*aUrl) == 0)
       
   577             {
       
   578             valid = EFalse;
       
   579             }
       
   580             
       
   581         delete defaultUrl;
       
   582         }
       
   583 
       
   584     // Show the error.
       
   585     if (!valid)
       
   586         {
       
   587         TBrowserDialogs::ErrorNoteL( R_FEEDS_ADDRESS_NEEDED );
       
   588         }
       
   589 
       
   590     return valid;
       
   591     }
       
   592 
       
   593 
       
   594 // -----------------------------------------------------------------------------
       
   595 // CFeedsFolderContainer::UpdateFolderL
       
   596 //
       
   597 // Called when a folder's name is changed -- this is called 
       
   598 // after IsValidFolderName is called.
       
   599 // -----------------------------------------------------------------------------
       
   600 //
       
   601 void CFeedsFolderContainer::UpdateFolderL(const TDesC& aName)
       
   602     {
       
   603     UpdateCurrentItemL(&aName, NULL,0); 
       
   604     }
       
   605 
       
   606 
       
   607 // -----------------------------------------------------------------------------
       
   608 // CFeedsFolderContainer::NewFolderL
       
   609 //
       
   610 // Called when a new folder is created -- this is called 
       
   611 // after IsValidFolderName is called.
       
   612 // -----------------------------------------------------------------------------
       
   613 //
       
   614 void CFeedsFolderContainer::NewFolderL(const TDesC& aName)
       
   615     {
       
   616     AddNewFolderL(aName);
       
   617     }
       
   618 
       
   619 
       
   620 // -----------------------------------------------------------------------------
       
   621 // CFeedsFolderContainer::IsFolderNameValidL
       
   622 //
       
   623 // Validates the folder's updated name.
       
   624 // -----------------------------------------------------------------------------
       
   625 //
       
   626 TBool CFeedsFolderContainer::IsFolderNameValidL(const TDesC* aName, TBool aIsEditing)
       
   627     {
       
   628     // IsFeedNameValidL does the same thing...
       
   629     return IsFeedNameValidL(aName, aIsEditing);
       
   630     }
       
   631 
       
   632 
       
   633 // -----------------------------------------------------------------------------
       
   634 // CFolderView::RootFolderChangedL
       
   635 //
       
   636 // Called to notify the view the that root folder has changed.
       
   637 // -----------------------------------------------------------------------------
       
   638 //
       
   639 void CFeedsFolderContainer::RootFolderChangedL(const CFeedsEntity& aRootFolder)
       
   640     {
       
   641     // Set the new root folder.
       
   642     iRootFolder = &aRootFolder;
       
   643     
       
   644     // Restore the previous current folder.
       
   645     SetCurrentFolder(iApiProvider.FeedsClientUtilities().Search(iCurrentFolderId,aRootFolder));
       
   646     
       
   647     // Update the list box to reflect the new root folder.
       
   648     UpdateListBoxL(CurrentItemIndex());
       
   649     
       
   650     // Update the Cba to reflect the new state.
       
   651     UpdateCbaL();
       
   652     }
       
   653 
       
   654 
       
   655 // -----------------------------------------------------------------------------
       
   656 // CFeedsFolderContainer::UpdateTitleL
       
   657 //
       
   658 // Update the view's title.
       
   659 // -----------------------------------------------------------------------------
       
   660 //
       
   661 void CFeedsFolderContainer::UpdateTitleL()
       
   662     {
       
   663 
       
   664 	TPtrC title;
       
   665     // Set the view's title.
       
   666     if (iCurrentFolder != NULL && iCurrentFolder != iRootFolder)
       
   667         {
       
   668         if (iCurrentFolder->GetStringValue(EFolderAttributeTitle,title) != KErrNotFound && title.Length() != 0)
       
   669             {
       
   670             iApiProvider.Display().SetTitleL(title);
       
   671             }
       
   672         else
       
   673             {
       
   674             iApiProvider.Display().SetTitleL(KNullDesC);
       
   675             }
       
   676         }
       
   677     else
       
   678         {
       
   679         iApiProvider.Display().SetTitleL(R_FEEDS_FOLDER_VIEW_TITLE);
       
   680         }
       
   681     }
       
   682 
       
   683 
       
   684 // -----------------------------------------------------------------------------
       
   685 // CFeedsFolderContainer::CurrentItem
       
   686 //
       
   687 // Returns the current folder-item.
       
   688 // -----------------------------------------------------------------------------
       
   689 //
       
   690 CFeedsEntity* CFeedsFolderContainer::CurrentItem() const
       
   691     {
       
   692     CFeedsEntity*  item = NULL;
       
   693     TInt                index;
       
   694 
       
   695     index = iListBox->CurrentItemIndex();
       
   696     if (index >= 0)
       
   697         {
       
   698         item = iCurrentFolder->GetChildren()[index];
       
   699         }
       
   700 
       
   701     return item;
       
   702     }
       
   703 
       
   704 
       
   705 // -----------------------------------------------------------------------------
       
   706 // CFeedsFolderContainer::CurrentItemIndex
       
   707 //
       
   708 // Returns the index of the current folder-item.
       
   709 // -----------------------------------------------------------------------------
       
   710 //
       
   711 TInt CFeedsFolderContainer::CurrentItemIndex() const
       
   712     {
       
   713     return iListBox->CurrentItemIndex();
       
   714     }
       
   715 
       
   716 
       
   717 // -----------------------------------------------------------------------------
       
   718 // CFeedsFolderContainer::UpdateCurrentItemL
       
   719 //
       
   720 // Updates the current folder-item.
       
   721 // -----------------------------------------------------------------------------
       
   722 //
       
   723 void CFeedsFolderContainer::UpdateCurrentItemL(const TDesC* aName, const TDesC* aUrl, TInt aFreq)
       
   724     {
       
   725     TPtrC  name(KNullDesC);
       
   726     TPtrC  url(KNullDesC);
       
   727 
       
   728     if (aName != NULL)
       
   729         {
       
   730         name.Set(*aName);
       
   731         }
       
   732     if (aUrl != NULL)
       
   733         {
       
   734         url.Set(*aUrl);
       
   735         }
       
   736 
       
   737     // Update the folder item.
       
   738     CFeedsEntity *aCurrentItem = CurrentItem();
       
   739     __ASSERT_DEBUG( (aCurrentItem != NULL), Util::Panic( Util::EUninitializedData ) );
       
   740     iApiProvider.FeedsClientUtilities().ChangeFolderItemL(*(aCurrentItem), name, url, aFreq);
       
   741     }
       
   742 
       
   743 
       
   744 // -----------------------------------------------------------------------------
       
   745 // CFeedsFolderContainer::AddNewFeedL
       
   746 //
       
   747 // Add a new feed.
       
   748 // -----------------------------------------------------------------------------
       
   749 //
       
   750 void CFeedsFolderContainer::AddNewFeedL(const TDesC& aName, const TDesC& aUrl, TInt aFreq)
       
   751     {
       
   752     // Add the new feed.
       
   753     iApiProvider.FeedsClientUtilities().AddFolderItemL(aName, aUrl, EFalse, *iCurrentFolder, aFreq);
       
   754     }
       
   755 
       
   756 
       
   757 // -----------------------------------------------------------------------------
       
   758 // CFeedsFolderContainer::AddNewFolderL
       
   759 //
       
   760 // Add a new folder.
       
   761 // -----------------------------------------------------------------------------
       
   762 //
       
   763 void CFeedsFolderContainer::AddNewFolderL(const TDesC& aName)
       
   764     {
       
   765     // Add the new folder.
       
   766     iApiProvider.FeedsClientUtilities().AddFolderItemL(aName, KNullDesC, ETrue, *iCurrentFolder, 0);
       
   767     }
       
   768 
       
   769 
       
   770 // -----------------------------------------------------------------------------
       
   771 // CFeedsFolderContainer::DeleteItemL
       
   772 //
       
   773 // Delete the current feed or folder
       
   774 // -----------------------------------------------------------------------------
       
   775 //
       
   776 void CFeedsFolderContainer::DeleteCurrentItemL()
       
   777     {
       
   778     RPointerArray<const CFeedsEntity>  markedItems(10);
       
   779     const CArrayFix<TInt>*            markedIndexes = NULL;
       
   780     const CFeedsEntity*                folder = NULL;
       
   781 
       
   782     CleanupClosePushL(markedItems);
       
   783 
       
   784     // Get the array of marked items.
       
   785     markedIndexes = MarkedItems();
       
   786     if ((markedIndexes == NULL) || (markedIndexes->Count() == 0))
       
   787         {
       
   788         iListBox->View()->SelectItemL(CurrentItemIndex());
       
   789         markedIndexes = MarkedItems();
       
   790         }
       
   791 
       
   792     // Copy the marked items into a temp array.
       
   793     for (TInt i = 0; i < markedIndexes->Count(); i++)
       
   794         {
       
   795         folder = iCurrentFolder->GetChildren()[(*markedIndexes)[i]];
       
   796         User::LeaveIfError(markedItems.Append(folder));
       
   797         }
       
   798     
       
   799     // Delete the items.
       
   800     iApiProvider.FeedsClientUtilities().DeleteFolderItemsL(markedItems);
       
   801         
       
   802     // Clean up
       
   803     CleanupStack::PopAndDestroy(/*markedItems*/);
       
   804     }
       
   805 
       
   806 
       
   807 // -----------------------------------------------------------------------------
       
   808 // CFeedsFolderContainer::HasMarkedItem
       
   809 //
       
   810 // Returns an array containing the indexes of the marked items.
       
   811 // -----------------------------------------------------------------------------
       
   812 //
       
   813 const CArrayFix<TInt>* CFeedsFolderContainer::MarkedItems()
       
   814     {
       
   815     return iListBox->View()->SelectionIndexes();
       
   816     }
       
   817 
       
   818 
       
   819 // -----------------------------------------------------------------------------
       
   820 // CFeedsFolderContainer::HandleShowParentFolderL
       
   821 //
       
   822 // Replaces the current folder with its parent.
       
   823 // -----------------------------------------------------------------------------
       
   824 //
       
   825 TBool CFeedsFolderContainer::HandleShowParentFolderL(void)
       
   826     {
       
   827     TBool  handled = ETrue;
       
   828 
       
   829     if (iCurrentFolder && ( iCurrentFolder != iRootFolder))
       
   830         {
       
   831         const CFeedsEntity*  oldItem = NULL;
       
   832 
       
   833         // Refresh the list-box with the parent's contents.
       
   834         oldItem = iCurrentFolder;
       
   835         SetCurrentFolder(iCurrentFolder->GetParent());
       
   836         UpdateListBoxL();
       
   837 
       
   838         // Restore the old selection.
       
   839          __ASSERT_DEBUG( (oldItem != NULL), Util::Panic( Util::EUninitializedData ));
       
   840         TInt index = 0;
       
   841         for(TInt i=0;i<iCurrentFolder->GetChildren().Count();i++)
       
   842         {
       
   843         	if(iCurrentFolder->GetChildren()[i] == oldItem)
       
   844         	{
       
   845         		index = i;
       
   846         	}
       
   847         }
       
   848       	iListBox->SetCurrentItemIndex(index);
       
   849 		iListBox->DrawDeferred();
       
   850         
       
   851         // Update the Cba to reflect the new state.
       
   852         UpdateCbaL();
       
   853         }
       
   854     else
       
   855         {
       
   856         handled = EFalse;
       
   857         }
       
   858 
       
   859     return handled;
       
   860     }
       
   861 
       
   862 
       
   863 // -----------------------------------------------------------------------------
       
   864 // CFeedsFolderContainer::HandleSelectionL
       
   865 //
       
   866 // Processes key events from the listbox.
       
   867 // -----------------------------------------------------------------------------
       
   868 //
       
   869 void CFeedsFolderContainer::HandleSelectionL(void)
       
   870     {
       
   871     TInt                index;
       
   872     const CFeedsEntity*  item;
       
   873 
       
   874     index = iListBox->CurrentItemIndex();
       
   875     item = const_cast<CFeedsEntity*>(iCurrentFolder->GetChildren()[index]);
       
   876     User::LeaveIfNull((void*) item);
       
   877 
       
   878     // If a folder was selected - show it.
       
   879     if (item->GetType() == EFolder)
       
   880         {
       
   881         SetCurrentFolder(item);
       
   882         UpdateListBoxL();
       
   883         UpdateCbaL();
       
   884         UpdateToolbarButtonsState();
       
   885         }
       
   886 
       
   887     // Otherwise show the Feed.
       
   888     else 
       
   889         {
       
   890         ShowFeedL(*item);
       
   891         }
       
   892     }
       
   893 
       
   894 
       
   895 // -----------------------------------------------------------------------------
       
   896 // CFeedsFolderContainer::HandleUpdateFeedL
       
   897 //
       
   898 // Handles updating the current Feed.
       
   899 // -----------------------------------------------------------------------------
       
   900 //
       
   901 void CFeedsFolderContainer::HandleUpdateFeedL(TBool aUpdateAll)
       
   902     {
       
   903     // Update the selected items if "Update" was selected.
       
   904     if (!aUpdateAll)
       
   905         {        
       
   906         const CArrayFix<TInt>*            markedIndexes = NULL;
       
   907         RPointerArray<const CFeedsEntity>  folderItems(10);
       
   908 
       
   909         CleanupClosePushL(folderItems);
       
   910 
       
   911         // Get the marked indexes.
       
   912         markedIndexes = MarkedItems();
       
   913 
       
   914         // If nothing is marked then use the current item.
       
   915         if ((markedIndexes == NULL) || (markedIndexes->Count() == 0))
       
   916             {
       
   917             folderItems.AppendL(iCurrentFolder->GetChildren()[
       
   918                     CurrentItemIndex()]);
       
   919             }
       
   920 
       
   921         // Otherwise copy the marked items into a temp array.
       
   922         else
       
   923             {            
       
   924             for (TInt i = 0; i < markedIndexes->Count(); i++)
       
   925                 {
       
   926                 folderItems.AppendL(iCurrentFolder->GetChildren()[
       
   927                         (*markedIndexes)[i]]);
       
   928                 }
       
   929             }
       
   930             
       
   931         // Update the items.
       
   932         iApiProvider.FeedsClientUtilities().UpdateFolderItemsL(folderItems);
       
   933             
       
   934         // Clean up
       
   935         CleanupStack::PopAndDestroy(/*folderItems*/);
       
   936         }        
       
   937 
       
   938     // Otherwise update all of the items in the current FolderList.
       
   939     else
       
   940         {
       
   941         iApiProvider.FeedsClientUtilities().UpdateFolderItemsL();
       
   942         }
       
   943     }
       
   944     
       
   945     
       
   946 // -----------------------------------------------------------------------------
       
   947 // CFeedsFolderContainer::HandleNewFeedL
       
   948 //
       
   949 // Handles the add-feed command.
       
   950 // -----------------------------------------------------------------------------
       
   951 //
       
   952 void CFeedsFolderContainer::HandleNewFeedL()
       
   953     {
       
   954     // Display the edit feed folder
       
   955     CFeedsEditFeedDialog*  dialog = NULL;
       
   956 
       
   957     dialog = CFeedsEditFeedDialog::NewL(*this, iView->AppUi());
       
   958     
       
   959     DimToolbar(ETrue);
       
   960     // Note: The result is handled in the MEditFeedDialogObserver methods.
       
   961     dialog->ExecuteLD(R_FEEDS_EDIT_FEED_DIALOG);
       
   962     dialog = NULL;
       
   963     DimToolbar(EFalse);
       
   964     }
       
   965 
       
   966 
       
   967 // -----------------------------------------------------------------------------
       
   968 // CFeedsFolderContainer::HandleNewFolderL
       
   969 //
       
   970 // Handles the add-folder command.
       
   971 // -----------------------------------------------------------------------------
       
   972 //
       
   973 void CFeedsFolderContainer::HandleNewFolderL()
       
   974     {
       
   975     // Display the edit feed folder
       
   976     CFeedsEditFolderDialog*  dialog = NULL;
       
   977 
       
   978     dialog = CFeedsEditFolderDialog::NewL(*this, iView->AppUi());
       
   979     
       
   980     DimToolbar(ETrue);
       
   981     // Note: The result is handled in the MEditFolderDialogObserver methods.
       
   982     dialog->ExecuteLD(R_FEEDS_EDIT_FOLDER_DIALOG);
       
   983     dialog = NULL;
       
   984     
       
   985     DimToolbar(EFalse);
       
   986 
       
   987     }
       
   988 
       
   989 
       
   990 // -----------------------------------------------------------------------------
       
   991 // CFeedsFolderContainer::HandleEditL
       
   992 //
       
   993 // Handles the edit command.
       
   994 // -----------------------------------------------------------------------------
       
   995 //
       
   996 void CFeedsFolderContainer::HandleEditL()
       
   997     {
       
   998     const CFeedsEntity*  item = NULL;
       
   999 
       
  1000     // Get the current item.
       
  1001     item = CurrentItem();
       
  1002 	TPtrC title;
       
  1003 	TPtrC url;
       
  1004         TInt freq;
       
  1005 
       
  1006 	if(item->GetType() == EFolder)
       
  1007 	   {
       
  1008 	   item->GetStringValue(EFolderAttributeTitle,title);
       
  1009 	   }
       
  1010 	else
       
  1011 	   {
       
  1012 	   item->GetStringValue(EFeedAttributeTitle,title);	
       
  1013 	   item->GetStringValue(EFeedAttributeLink,url);
       
  1014        item->GetIntegerValue(EFeedAttributeAutoUpdateFreq,freq);
       
  1015 	   }
       
  1016 
       
  1017 	__ASSERT_DEBUG( (item != NULL), Util::Panic( Util::EUninitializedData ));
       
  1018 
       
  1019     DimToolbar(ETrue);
       
  1020 
       
  1021     // Display the edit feed dialog
       
  1022     if (!(item->GetType() == EFolder))
       
  1023         {
       
  1024         CFeedsEditFeedDialog*  dialog = NULL;
       
  1025 
       
  1026         dialog = CFeedsEditFeedDialog::NewL(*this, iView->AppUi(), title, url, freq);
       
  1027 
       
  1028 	 	__ASSERT_DEBUG( (dialog != NULL), Util::Panic( Util::EUninitializedData ));
       
  1029         
       
  1030         // Note: The result is handled in the MEditFeedDialogObserver methods.
       
  1031         dialog->ExecuteLD(R_FEEDS_EDIT_FEED_DIALOG);
       
  1032         dialog = NULL;
       
  1033         }
       
  1034     
       
  1035     // Display the edit folder dialog.
       
  1036     else
       
  1037         {
       
  1038         CFeedsEditFolderDialog*  dialog = NULL;
       
  1039 
       
  1040         dialog = CFeedsEditFolderDialog::NewL(*this, iView->AppUi(), title);
       
  1041         
       
  1042 	 	__ASSERT_DEBUG( (dialog != NULL), Util::Panic( Util::EUninitializedData ));
       
  1043 
       
  1044         // Note: The result is handled in the MEditFolderDialogObserver methods.
       
  1045         dialog->ExecuteLD(R_FEEDS_EDIT_FOLDER_DIALOG);
       
  1046         dialog = NULL;
       
  1047         }
       
  1048         
       
  1049     DimToolbar(EFalse);
       
  1050         
       
  1051     }
       
  1052 
       
  1053 
       
  1054 // -----------------------------------------------------------------------------
       
  1055 // CFeedsFolderContainer::HandleDelete
       
  1056 //
       
  1057 // Handles the delete command.
       
  1058 // -----------------------------------------------------------------------------
       
  1059 //
       
  1060 void CFeedsFolderContainer::HandleDeleteL()
       
  1061     {
       
  1062     TBool                   deleteIt = EFalse;
       
  1063     TBool                   clearOnCancel = EFalse;
       
  1064     const CArrayFix<TInt>*  markedIndexes = NULL;
       
  1065 
       
  1066     // Return if there are no items in the folder
       
  1067     if (CurrentItem() == NULL)
       
  1068         {
       
  1069         return;
       
  1070         }
       
  1071 
       
  1072     // Get the marked items.
       
  1073     markedIndexes = MarkedItems();
       
  1074     
       
  1075     // If none are marked then mark the current one.
       
  1076     if ((markedIndexes == NULL) || (markedIndexes->Count() == 0))
       
  1077         {
       
  1078         iListBox->View()->SelectItemL(CurrentItemIndex());
       
  1079         clearOnCancel = ETrue;
       
  1080         markedIndexes = MarkedItems();
       
  1081         }
       
  1082 
       
  1083 
       
  1084     // Multiple items are being deleted.
       
  1085     if (markedIndexes->Count() > 1)
       
  1086         {
       
  1087 		if(TBrowserDialogs::ConfirmQueryYesNoL(R_FEEDS_DELETE_MULTIPLE_FEED))
       
  1088             {
       
  1089             deleteIt = ETrue;
       
  1090             }
       
  1091         }
       
  1092 
       
  1093     // Otherwise only a single item is being deleted.
       
  1094     else
       
  1095         {
       
  1096         const CFeedsEntity*  item = NULL;
       
  1097         
       
  1098         // Get the item.
       
  1099         item = iCurrentFolder->GetChildren()[((*markedIndexes)[0])];
       
  1100 
       
  1101 		TPtrC title;
       
  1102 		if (item->GetType() == EFolder)
       
  1103 		    {
       
  1104 			item->GetStringValue(EFolderAttributeTitle,title);
       
  1105 	    	}
       
  1106 	    else
       
  1107 	        {
       
  1108 			item->GetStringValue(EFeedAttributeTitle,title);
       
  1109 	        }
       
  1110     	if(TBrowserDialogs::ConfirmQueryYesNoL(R_FEEDS_DELETE_FEED, title))
       
  1111             {
       
  1112             deleteIt = ETrue;
       
  1113             }
       
  1114         }
       
  1115 
       
  1116     // Delete it
       
  1117     if (deleteIt)
       
  1118         {
       
  1119         DeleteCurrentItemL();
       
  1120         }
       
  1121     else if (clearOnCancel)
       
  1122         {
       
  1123         iListBox->View()->ClearSelection();
       
  1124         }        
       
  1125     }
       
  1126     
       
  1127     
       
  1128 // -----------------------------------------------------------------------------
       
  1129 // CFeedsFolderContainer::HandleMove
       
  1130 //
       
  1131 // Handles the move command.
       
  1132 // -----------------------------------------------------------------------------
       
  1133 //
       
  1134 void CFeedsFolderContainer::HandleMoveL()
       
  1135     {
       
  1136     const CArrayFix<TInt>* markedItems = NULL;
       
  1137 
       
  1138     // Set the move flag.
       
  1139     iMoveActive = ETrue;
       
  1140 
       
  1141     // If nothing was marked then mark the current item.
       
  1142     markedItems = MarkedItems();
       
  1143     if ((markedItems == NULL) || (markedItems->Count() == 0))
       
  1144         {
       
  1145         iListBox->View()->SelectItemL(CurrentItemIndex());
       
  1146         }
       
  1147 
       
  1148     UpdateCbaL();
       
  1149     // Dim Toolbar
       
  1150     DimToolbar(ETrue);
       
  1151     }
       
  1152     
       
  1153     
       
  1154 // -----------------------------------------------------------------------------
       
  1155 // CFeedsFolderContainer::HandleMoveToFolderL
       
  1156 //
       
  1157 // Handles the move to folder command.
       
  1158 // -----------------------------------------------------------------------------
       
  1159 //
       
  1160 void CFeedsFolderContainer::HandleMoveToFolderL()
       
  1161     {
       
  1162     CAknSingleGraphicPopupMenuStyleListBox*  listBox = NULL;
       
  1163     CAknPopupList*                           popupList = NULL;
       
  1164     const CFeedsEntity*                       targetFolder = NULL;
       
  1165 
       
  1166     // Construct the basic Pop-up
       
  1167     MoveToFolderInitL(listBox, popupList);
       
  1168     CleanupStack::PushL(listBox);
       
  1169 
       
  1170     // Show the pop-up.
       
  1171     if (popupList->ExecuteLD())
       
  1172         {
       
  1173         TInt  selected;
       
  1174 
       
  1175         selected = listBox->CurrentItemIndex();
       
  1176 
       
  1177         if (selected >= 0)
       
  1178             {
       
  1179             targetFolder = iTargetFolderList[selected];
       
  1180             }
       
  1181         }
       
  1182 
       
  1183     CleanupStack::PopAndDestroy(listBox);
       
  1184 
       
  1185     // Moved the marked items into the targeted folder.
       
  1186     if (targetFolder != NULL)
       
  1187         {
       
  1188         MoveToFolderMoveL(*targetFolder);
       
  1189         }
       
  1190     }
       
  1191     
       
  1192     
       
  1193 // -----------------------------------------------------------------------------
       
  1194 // CFeedsFolderContainer::HandleMarkL
       
  1195 //
       
  1196 // Handles the mark-related commands.
       
  1197 // -----------------------------------------------------------------------------
       
  1198 //
       
  1199 void CFeedsFolderContainer::HandleMarkL(TInt aCommand)
       
  1200     {
       
  1201     AknSelectionService::HandleMarkableListProcessCommandL(aCommand, iListBox);
       
  1202     }
       
  1203 
       
  1204 
       
  1205 // -----------------------------------------------------------------------------
       
  1206 // CFeedsFolderContainer::HandleOkL
       
  1207 //
       
  1208 // Handles the ok commands.
       
  1209 // -----------------------------------------------------------------------------
       
  1210 //
       
  1211 void CFeedsFolderContainer::HandleOkL()
       
  1212     {
       
  1213     // If a move is active process the move.
       
  1214     if (iMoveActive)
       
  1215         {
       
  1216         PostHandleMoveL();
       
  1217 
       
  1218         iMoveActive = EFalse;
       
  1219         UpdateCbaL();
       
  1220         // Un-Dim Toolbar
       
  1221         DimToolbar(EFalse);
       
  1222         }
       
  1223     }
       
  1224     
       
  1225     
       
  1226 // -----------------------------------------------------------------------------
       
  1227 // CFeedsFolderContainer::HandleCancelL
       
  1228 //
       
  1229 // Handles the cancel commands.
       
  1230 // -----------------------------------------------------------------------------
       
  1231 //
       
  1232 void CFeedsFolderContainer::HandleCancelL()
       
  1233     {
       
  1234     if (iMoveActive)
       
  1235         {
       
  1236         // Clear the move state and update the Cba.
       
  1237         iMoveActive = EFalse;
       
  1238 		// Remove the marks.
       
  1239         iListBox->View()->ClearSelection();
       
  1240         UpdateCbaL();
       
  1241         // Un-Dim Toolbar
       
  1242         DimToolbar(EFalse);
       
  1243         }
       
  1244     }
       
  1245 
       
  1246 // -----------------------------------------------------------------------------
       
  1247 // CFeedsFolderContainer::HandleExportL
       
  1248 //
       
  1249 // Handles the export commands.
       
  1250 // -----------------------------------------------------------------------------
       
  1251 //
       
  1252 void CFeedsFolderContainer::HandleExportL()
       
  1253     {
       
  1254     RPointerArray<const CFeedsEntity>  markedItems(10);
       
  1255     const CArrayFix<TInt>*            markedIndexes = NULL;
       
  1256     const CFeedsEntity*                folder = NULL;
       
  1257 
       
  1258     CleanupClosePushL(markedItems);
       
  1259 
       
  1260     // Get the array of marked items.
       
  1261     markedIndexes = MarkedItems();
       
  1262     if ((markedIndexes == NULL) || (markedIndexes->Count() == 0))
       
  1263         {
       
  1264         iListBox->View()->SelectItemL(CurrentItemIndex());
       
  1265         markedIndexes = MarkedItems();
       
  1266         }
       
  1267 
       
  1268     // Copy the marked items into an array.
       
  1269     for (TInt i = 0; i < markedIndexes->Count(); i++)
       
  1270         {
       
  1271         folder = iCurrentFolder->GetChildren()[((*markedIndexes)[i])];
       
  1272         User::LeaveIfError(markedItems.Append(folder));
       
  1273         }
       
  1274        
       
  1275     _LIT(KOpmlExt, ".opml");
       
  1276     HBufC* prompt = StringLoader::LoadLC( R_FEEDS_NAME_EXPORTED_FILE );
       
  1277 	TBuf<KBrowserMaxPrompt+1> retString;
       
  1278 	retString.Copy( KNullDesC );
       
  1279 	
       
  1280 	TInt result = TBrowserDialogs::DialogPromptReqL(
       
  1281 		prompt->Des(),
       
  1282 		&retString,
       
  1283         EFalse,
       
  1284 		KFavouritesMaxBookmarkNameDefine );
       
  1285 	
       
  1286 	if( result )
       
  1287 		{
       
  1288 		// only append .opml if user has not already done so
       
  1289 		TInt dotPos = retString.LocateReverse( '.' );
       
  1290 		
       
  1291 		if ( dotPos != KErrNotFound )
       
  1292 			{
       
  1293 			// dot found, now check extension
       
  1294             TInt extLength = retString.Length() - dotPos;
       
  1295             HBufC* ext = retString.Right( extLength ).AllocL();
       
  1296             CleanupStack::PushL( ext );
       
  1297 
       
  1298             // if not .opml append extension
       
  1299             if ( ext->CompareF( KOpmlExt ) != 0)
       
  1300             	{
       
  1301 				retString.Append(KOpmlExt);
       
  1302             	}
       
  1303 			
       
  1304 			CleanupStack::PopAndDestroy(); // ext buffer
       
  1305 			}
       
  1306 		else
       
  1307 			{
       
  1308 			// no dot, definitely append			
       
  1309 			retString.Append(KOpmlExt);
       
  1310 			}
       
  1311 
       
  1312 		// Pass folder array to feeds utilities to export
       
  1313 		iApiProvider.FeedsClientUtilities().ExportFeedsL(markedItems, retString);
       
  1314 		}
       
  1315 			
       
  1316 	CleanupStack::PopAndDestroy();  // prompt
       
  1317 		       
       
  1318     // Clean up
       
  1319     CleanupStack::PopAndDestroy(/*markedItems*/);
       
  1320    
       
  1321    	// Clear the selection
       
  1322    	iListBox->View()->ClearSelection();
       
  1323    	UpdateCbaL();
       
  1324     }
       
  1325 
       
  1326 
       
  1327 // -----------------------------------------------------------------------------
       
  1328 // CFeedsFolderContainer::ShowFeedL
       
  1329 //
       
  1330 // Show the feed in the TopicView.
       
  1331 // -----------------------------------------------------------------------------
       
  1332 //
       
  1333 void CFeedsFolderContainer::ShowFeedL(const CFeedsEntity& aFolderItem)
       
  1334     {
       
  1335     iApiProvider.FeedsClientUtilities().ShowTopicViewL(aFolderItem);
       
  1336     }
       
  1337 
       
  1338 
       
  1339 // -----------------------------------------------------------------------------
       
  1340 // CFeedsFolderContainer::InitContainerL
       
  1341 //
       
  1342 // Inits the container.
       
  1343 // -----------------------------------------------------------------------------
       
  1344 //
       
  1345 void CFeedsFolderContainer::InitContainerL(const TRect& aRect)
       
  1346     {
       
  1347     // Init the basic list-box
       
  1348     iListBox = new (ELeave) CAknDoubleGraphicStyleListBox;
       
  1349     iListBox->ConstructL(this, EAknListBoxMarkableList);
       
  1350     iListBox->SetContainerWindowL(*this);
       
  1351     iListBox->SetRect(aRect.Size());
       
  1352     iListBox->SetListBoxObserver(this);
       
  1353 
       
  1354     HBufC* emptyText = iCoeEnv->AllocReadResourceLC(R_FEEDS_NO_FEEDS);
       
  1355     iListBox->View()->SetListEmptyTextL(*emptyText);
       
  1356     CleanupStack::PopAndDestroy(emptyText);
       
  1357 
       
  1358     // Init the list-box's model.
       
  1359     iListBoxRows = new (ELeave) CDesCArraySeg(10);
       
  1360     iListBox->Model()->SetItemTextArray(iListBoxRows);
       
  1361     iListBox->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray);
       
  1362 
       
  1363     // Add scrollbars.
       
  1364     iListBox->ActivateL();
       
  1365     iListBox->CreateScrollBarFrameL(ETrue);
       
  1366     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto);
       
  1367 
       
  1368     // Add the needed icons.
       
  1369     InitIconArrayL();
       
  1370 
       
  1371     // Enable marquee.
       
  1372 	iListBox->ItemDrawer()->ColumnData()->EnableMarqueeL(ETrue);
       
  1373 
       
  1374     UpdateCbaL();
       
  1375     }
       
  1376     
       
  1377 
       
  1378 // -----------------------------------------------------------------------------
       
  1379 // CFeedsFolderContainer::InitIconArrayL
       
  1380 //
       
  1381 // Inits the array of needed icons.
       
  1382 // -----------------------------------------------------------------------------
       
  1383 //
       
  1384 void CFeedsFolderContainer::InitIconArrayL()
       
  1385     {
       
  1386     _LIT(KDirAndFile,"z:browser.mbm");
       
  1387     
       
  1388     TParse*  fp = NULL;
       
  1389     
       
  1390     // Build the path to the feeds resource file.
       
  1391     fp = new (ELeave) TParse();     
       
  1392     CleanupStack::PushL(fp);
       
  1393     
       
  1394     User::LeaveIfError(fp->Set(KDirAndFile, &KDC_APP_BITMAP_DIR, NULL)); 
       
  1395     TBuf<KMaxFileName> iconFile= fp->FullName();
       
  1396     CleanupStack::PopAndDestroy(fp);
       
  1397 
       
  1398     // Create the icon array.    
       
  1399     iListBoxIcons = new (ELeave) CAknIconArray( KFirstFaviconIndex );
       
  1400 
       
  1401     // Add the mark icon.
       
  1402     AppendIconL(iListBoxIcons, KAknsIIDQgnIndiMarkedAdd, KAvkonBitmapFile(),
       
  1403             EMbmAvkonQgn_indi_marked_add, EMbmAvkonQgn_indi_marked_add_mask);
       
  1404 
       
  1405     // Add the folder icon.
       
  1406     AppendIconL(iListBoxIcons, KAknsIIDQgnPropFolderRss, iconFile,
       
  1407             EMbmBrowserQgn_prop_folder_rss, EMbmBrowserQgn_prop_folder_rss_mask);
       
  1408 
       
  1409     // Add the folder error icon       
       
  1410     AppendIconL(iListBoxIcons, KAknsIIDQgnPropFolderRssError, iconFile,
       
  1411             EMbmBrowserQgn_prop_folder_rss_error, EMbmBrowserQgn_prop_folder_rss_error_mask);            
       
  1412 
       
  1413     // Add the feed icon for feed having unread count as 0.
       
  1414     AppendIconL(iListBoxIcons, KAknsIIDQgnPropFileRss, iconFile,
       
  1415             EMbmBrowserQgn_prop_file_rss, EMbmBrowserQgn_prop_file_rss_mask);
       
  1416 
       
  1417     // Add the feed icon for feed having unread count as non-0.
       
  1418     AppendIconL(iListBoxIcons, KAknsIIDQgnPropFileRssNew, iconFile,
       
  1419             EMbmBrowserQgn_prop_file_rss_new, EMbmBrowserQgn_prop_file_rss_new_mask);
       
  1420    
       
  1421     // Add the feed error icon
       
  1422     AppendIconL(iListBoxIcons, KAknsIIDQgnPropFileRssError, iconFile,
       
  1423             EMbmBrowserQgn_prop_file_rss_error, EMbmBrowserQgn_prop_file_rss_error_mask);            
       
  1424 
       
  1425     // Set the icons and cleanup
       
  1426     iListBox->ItemDrawer()->ColumnData()->SetIconArray(iListBoxIcons);
       
  1427     iOwnsListBoxIcons = EFalse;
       
  1428     }
       
  1429 
       
  1430 
       
  1431 // -----------------------------------------------------------------------------
       
  1432 // CFeedsFolderContainer::AppendIconL
       
  1433 //
       
  1434 // Loads and appends an icon to the icon array.
       
  1435 // -----------------------------------------------------------------------------
       
  1436 //
       
  1437 void CFeedsFolderContainer::AppendIconL(CArrayPtr<CGulIcon>* aIcons, 
       
  1438         const TAknsItemID& aID, const TDesC& aFilename, const TInt aFileBitmapId, 
       
  1439         const TInt aFileMaskId)
       
  1440     {
       
  1441 	CGulIcon*    newIcon;
       
  1442 	CFbsBitmap*  newIconBmp;
       
  1443 	CFbsBitmap*  newIconMaskBmp;
       
  1444 
       
  1445 	__ASSERT_DEBUG( (aIcons != NULL), Util::Panic( Util::EUninitializedData ));
       
  1446 
       
  1447 
       
  1448     // Create the bitmaps: the bitmaps are left on the cleanup stack.
       
  1449 	AknsUtils::CreateIconL(AknsUtils::SkinInstance(), aID, newIconBmp, 
       
  1450             newIconMaskBmp, aFilename, aFileBitmapId, aFileMaskId);
       
  1451 
       
  1452     CleanupStack::PushL(newIconBmp);
       
  1453     CleanupStack::PushL(newIconMaskBmp);
       
  1454 
       
  1455 	newIcon = CGulIcon::NewL(newIconBmp, newIconMaskBmp);
       
  1456     CleanupStack::Pop(newIconMaskBmp);
       
  1457     CleanupStack::Pop(newIconBmp);
       
  1458     CleanupStack::PushL(newIcon);
       
  1459 
       
  1460 	aIcons->AppendL(newIcon);
       
  1461     CleanupStack::Pop(newIcon);
       
  1462     }
       
  1463 
       
  1464 
       
  1465 // -----------------------------------------------------------------------------
       
  1466 // CFeedsFolderContainer::UpdateListBoxL
       
  1467 //
       
  1468 // Sets the list-box's values.
       
  1469 // -----------------------------------------------------------------------------
       
  1470 //
       
  1471 void CFeedsFolderContainer::UpdateListBoxL(TInt aInitialSelection)
       
  1472     {
       
  1473     //0\t\1st Line of text\t2nd Line of text\t0
       
  1474     TBuf<255>                     listBoxtxt;
       
  1475 
       
  1476     if (iCurrentFolder == NULL)
       
  1477         {
       
  1478         return;
       
  1479         }
       
  1480 
       
  1481     // Clear the list.
       
  1482     iListBoxRows->Reset();
       
  1483     
       
  1484     // Delete the old favicons.
       
  1485     iListBoxIcons->Delete(KFirstFaviconIndex, iListBoxIcons->Count() - KFirstFaviconIndex);
       
  1486 
       
  1487 	// Remove the marks.
       
  1488     iListBox->View()->ClearSelection();
       
  1489 
       
  1490     if (iView->iContainer->IsVisible())
       
  1491         {
       
  1492         // Update the title.
       
  1493         UpdateTitleL();
       
  1494         }
       
  1495 
       
  1496     // Add the feeds.
       
  1497     for (int i = 0; i < iCurrentFolder->GetChildren().Count(); i++)
       
  1498         {
       
  1499         const CFeedsEntity*  item = NULL;
       
  1500         TInt iconIndex;
       
  1501         
       
  1502         item = iCurrentFolder->GetChildren()[i];
       
  1503 		TPtrC itemName;
       
  1504 		TInt statusCode;
       
  1505 		
       
  1506 		if (item->GetType() == EFolder)
       
  1507 		    {
       
  1508         	item->GetStringValue(EFolderAttributeTitle,itemName);
       
  1509 	    	}
       
  1510 		else
       
  1511 		    {
       
  1512         	item->GetStringValue(EFeedAttributeTitle,itemName);
       
  1513 		    }
       
  1514         item->GetIntegerValue(EFolderAttributeStatus, statusCode);
       
  1515 
       
  1516         // Set the name.
       
  1517         TInt len;
       
  1518 
       
  1519         len = itemName.Length();
       
  1520         if (len > 253)
       
  1521             {
       
  1522             len = 253;
       
  1523             }
       
  1524 
       
  1525         // Build the item's string.
       
  1526         if (item->GetType() == EFolder)
       
  1527             {
       
  1528 		   	   if (statusCode == KErrNone)
       
  1529 		   		   {
       
  1530 		           listBoxtxt.Zero();
       
  1531 		           listBoxtxt.AppendFormat(_L("%d\t%S\t"), EIconFolder, &itemName);
       
  1532 		           listBoxtxt.Append(KNullDesC());
       
  1533 		           }
       
  1534 		       else
       
  1535 		           {
       
  1536 		           listBoxtxt.Zero();
       
  1537 		           listBoxtxt.AppendFormat(_L("%d\t%S\t"), EIconErrorFolder, &itemName);
       
  1538 		           listBoxtxt.Append(KNullDesC());
       
  1539 		           } 
       
  1540             }
       
  1541         else
       
  1542         	{
       
  1543             if(statusCode == KErrNone)
       
  1544                 {
       
  1545                 CGulIcon*  favicon = NULL;
       
  1546                 iconIndex = EIconFeed;
       
  1547                            
       
  1548                 // Convert the item's timestamp into a localized string.
       
  1549                 TBuf<KDateSize + KTimeSize + 1>  timestamp;
       
  1550                 TBuf<KTimeSize>  temp;    
       
  1551                 TTime  date;                       
       
  1552         		TInt unreadCount;
       
  1553         	    item->GetIntegerValue(EFolderAttributeUnreadCount,unreadCount);
       
  1554                 
       
  1555                 // Since the folder list isn't updated after it is fetched
       
  1556                 // the FeedsClientUtilities tracks the update times for feeds
       
  1557                 // the user visits in the current session.
       
  1558                 date = iApiProvider.FeedsClientUtilities().FeedUpdatedTime(*item);
       
  1559                     
       
  1560                 // If the date isn't zero then format the date
       
  1561                 if (date.Int64() != 0)
       
  1562                     {                
       
  1563                     // Translate from UTC to local time.
       
  1564                     TTime                 local;
       
  1565                     TTime                 utc;
       
  1566                     TTimeIntervalSeconds  delta;
       
  1567                     
       
  1568                     local.HomeTime();
       
  1569                     utc.UniversalTime();
       
  1570                     utc.SecondsFrom(local, delta);                
       
  1571                     date -= delta;
       
  1572 
       
  1573                     //Set time
       
  1574                     HBufC* timeFormat = iEikonEnv->AllocReadResourceLC( R_QTN_TIME_USUAL_WITH_ZERO );
       
  1575                     date.FormatL( timestamp, *timeFormat );
       
  1576                     CleanupStack::PopAndDestroy( timeFormat );//timeFormat
       
  1577                     //
       
  1578                     timestamp.Append(_L("  "));                    
       
  1579                     //Set date
       
  1580                     HBufC* dateFormat = iEikonEnv->AllocReadResourceLC( R_QTN_DATE_USUAL_WITH_ZERO );
       
  1581                     date.FormatL( temp, *dateFormat );
       
  1582                     CleanupStack::PopAndDestroy( dateFormat );//dateFormat
       
  1583                     //
       
  1584                     timestamp.Append(temp);
       
  1585                     // Convert to locale specific numbers 
       
  1586                     if (TBidiText::ERightToLeft == AknTextUtils::CurrentScriptDirectionality ())
       
  1587                         {
       
  1588                         AknTextUtils::DisplayTextLanguageSpecificNumberConversion(timestamp); 
       
  1589                         }
       
  1590                     }
       
  1591                     
       
  1592                 // If there is a favicon for this url then add it to the icon list
       
  1593                 // set the icon's index.
       
  1594         		TPtrC url;
       
  1595 		    	item->GetStringValue(EFeedAttributeLink,url);
       
  1596                 favicon = iApiProvider.FeedsClientUtilities().FaviconL(url);
       
  1597                 // favicon exist, no matter unread count is 0 or not, use favicon
       
  1598                 if (favicon != NULL)
       
  1599                     {
       
  1600                     iListBoxIcons->AppendL(favicon);
       
  1601                     iconIndex = iListBoxIcons->Count() - 1;
       
  1602                     }
       
  1603                 // no favicon, and unread count > 0, use unread icon
       
  1604                 else if (unreadCount > 0)
       
  1605                     {
       
  1606                     iconIndex = EIconFeedUnread;
       
  1607                     }
       
  1608                 // else: no favicon, and unread count == 0, use read icon
       
  1609 
       
  1610                 // Add the line.
       
  1611                 listBoxtxt.Zero();
       
  1612 
       
  1613                 if (unreadCount > 0)
       
  1614                     {
       
  1615                     listBoxtxt.AppendFormat(_L("%d\t%S(%d)\t%S"), iconIndex, &itemName, unreadCount, &timestamp);
       
  1616                     }
       
  1617                 else
       
  1618                     {
       
  1619                     listBoxtxt.AppendFormat(_L("%d\t%S\t%S"), iconIndex, &itemName, &timestamp);
       
  1620                     }
       
  1621 
       
  1622                 listBoxtxt.Append(KNullDesC());
       
  1623                 }
       
  1624             else if(((statusCode >= 20400 )&& (statusCode < 20500 )) || (statusCode == KErrBadName))   
       
  1625             	{
       
  1626                 iconIndex = EIconErrorFeed;
       
  1627                 HBufC* text = NULL;
       
  1628                     
       
  1629                 text = iCoeEnv->AllocReadResourceL(R_FEEDS_INVALID_URL);
       
  1630                 TPtr txtPtr = text->Des();
       
  1631                 CleanupStack::PushL(text);
       
  1632     		    listBoxtxt.Zero();
       
  1633                 listBoxtxt.AppendFormat(_L("%d\t%S\t%S"), iconIndex, &itemName, &txtPtr);
       
  1634                 listBoxtxt.Append(KNullDesC());
       
  1635                 CleanupStack::PopAndDestroy();
       
  1636            		}
       
  1637             else if( statusCode == KErrNotSupported)
       
  1638             	{
       
  1639                 iconIndex = EIconErrorFeed;
       
  1640                 HBufC* text = NULL;
       
  1641                     
       
  1642                 text = iCoeEnv->AllocReadResourceL(R_FEEDS_UNSUPPORTED_FEED);
       
  1643                 TPtr txtPtr = text->Des();
       
  1644                 CleanupStack::PushL(text);
       
  1645     		    listBoxtxt.Zero();
       
  1646                 listBoxtxt.AppendFormat(_L("%d\t%S\t%S"), iconIndex, &itemName, &txtPtr);
       
  1647                 listBoxtxt.Append(KNullDesC());
       
  1648                 CleanupStack::PopAndDestroy();
       
  1649            		} 
       
  1650             else if ( statusCode == KErrTimedOut)
       
  1651             	{
       
  1652                 iconIndex = EIconErrorFeed;
       
  1653                 HBufC* text = NULL;
       
  1654                     
       
  1655                 text = iCoeEnv->AllocReadResourceL(R_FEEDS_NETWORK_ERROR);
       
  1656                 TPtr txtPtr = text->Des();
       
  1657                 CleanupStack::PushL(text);
       
  1658     		    listBoxtxt.Zero();
       
  1659                 listBoxtxt.AppendFormat(_L("%d\t%S\t%S"), iconIndex, &itemName, &txtPtr);
       
  1660                 listBoxtxt.Append(KNullDesC());
       
  1661                 CleanupStack::PopAndDestroy();                
       
  1662             	}
       
  1663             else if ( statusCode == KErrCorrupt)
       
  1664             	{
       
  1665                 iconIndex = EIconErrorFeed;
       
  1666                 HBufC* text = NULL;
       
  1667                     
       
  1668                 text = iCoeEnv->AllocReadResourceL(R_FEEDS_MALFORMED_FEED);
       
  1669                 TPtr txtPtr = text->Des();
       
  1670                 CleanupStack::PushL(text);
       
  1671     		    listBoxtxt.Zero();
       
  1672                 listBoxtxt.AppendFormat(_L("%d\t%S\t%S"), iconIndex, &itemName, &txtPtr);
       
  1673                 listBoxtxt.Append(KNullDesC());
       
  1674                 CleanupStack::PopAndDestroy();                
       
  1675             	}
       
  1676             else if(statusCode> 0)
       
  1677             	{
       
  1678                 iconIndex = EIconErrorFeed;
       
  1679                 HBufC* text = NULL;
       
  1680                     
       
  1681                 text = iCoeEnv->AllocReadResourceL(R_FEEDS_NETWORK_ERROR);
       
  1682                 TPtr txtPtr = text->Des();
       
  1683                 CleanupStack::PushL(text);
       
  1684     		    listBoxtxt.Zero();
       
  1685                 listBoxtxt.AppendFormat(_L("%d\t%S\t%S"), iconIndex, &itemName, &txtPtr);
       
  1686                 listBoxtxt.Append(KNullDesC());
       
  1687                 CleanupStack::PopAndDestroy();                
       
  1688             	}
       
  1689             else
       
  1690             	{
       
  1691                 iconIndex = EIconErrorFeed;
       
  1692                 HBufC* text = NULL;
       
  1693                     
       
  1694                 text = iCoeEnv->AllocReadResourceL(R_FEEDS_GENERAL_ERROR_MAIN_PANE);
       
  1695                 TPtr txtPtr = text->Des();
       
  1696                 CleanupStack::PushL(text);
       
  1697     		    listBoxtxt.Zero();
       
  1698                 listBoxtxt.AppendFormat(_L("%d\t%S\t%S"), iconIndex, &itemName, &txtPtr);
       
  1699                 listBoxtxt.Append(KNullDesC());            	
       
  1700                 CleanupStack::PopAndDestroy();                
       
  1701             	}
       
  1702         	}
       
  1703        		
       
  1704         // Add the row.
       
  1705         iListBoxRows->AppendL(listBoxtxt);    
       
  1706         }
       
  1707 
       
  1708     // Restore the selection -- the best it can that is.
       
  1709     if (iCurrentFolder->GetChildren().Count() > 0)
       
  1710         {
       
  1711         if (aInitialSelection > (iCurrentFolder->GetChildren().Count() - 1))
       
  1712             {
       
  1713             aInitialSelection = iCurrentFolder->GetChildren().Count() - 1;
       
  1714             }
       
  1715         if (aInitialSelection < 0)
       
  1716             {
       
  1717             aInitialSelection = 0;
       
  1718             }
       
  1719 
       
  1720         iListBox->SetCurrentItemIndex(aInitialSelection);
       
  1721         }
       
  1722 
       
  1723     iListBox->HandleItemAdditionL();
       
  1724     }
       
  1725 
       
  1726 
       
  1727 // -----------------------------------------------------------------------------
       
  1728 // CFeedsFolderContainer::MoveToFolderInitL
       
  1729 //
       
  1730 // Inits the move-to-folder pop-up.
       
  1731 // -----------------------------------------------------------------------------
       
  1732 //
       
  1733 void CFeedsFolderContainer::MoveToFolderInitL(CAknSingleGraphicPopupMenuStyleListBox*&
       
  1734         aListBox, CAknPopupList*& aPopupList)
       
  1735     {
       
  1736     CDesCArraySeg*        listBoxRows = NULL;
       
  1737     CTextListBoxModel*    listboxModel = NULL;
       
  1738     HBufC*                title = NULL;
       
  1739     CArrayPtr<CGulIcon>*  icons = NULL;
       
  1740 
       
  1741     // Construct the basic Pop-up
       
  1742     aListBox = new (ELeave) CAknSingleGraphicPopupMenuStyleListBox();
       
  1743     CleanupStack::PushL(aListBox);
       
  1744 
       
  1745 	aPopupList = CAknPopupList::NewL(aListBox, 
       
  1746             R_FEEDS_FOLDER_VIEW_CBA_MOVETOFOLDER_MOVECANCEL);
       
  1747     CleanupStack::PushL(aPopupList);
       
  1748 
       
  1749     aListBox->ConstructL(aPopupList, EAknListBoxSelectionList | EAknListBoxLoopScrolling);
       
  1750 
       
  1751     // Set the title.
       
  1752     title = CCoeEnv::Static()->AllocReadResourceLC(R_FEEDS_FOLDER_VIEW_MOVE_TO_PRMPT);
       
  1753     aPopupList->SetTitleL(*title);
       
  1754     CleanupStack::PopAndDestroy(title);
       
  1755 
       
  1756     // Construct the list-box's model.
       
  1757     listBoxRows = new (ELeave) CDesCArraySeg(10);
       
  1758 
       
  1759     listboxModel = aListBox->Model();
       
  1760     listboxModel->SetItemTextArray(listBoxRows);
       
  1761     listboxModel->SetOwnershipType(ELbmOwnsItemArray);
       
  1762 
       
  1763     // Add scrollbars.
       
  1764     aListBox->CreateScrollBarFrameL(ETrue);
       
  1765     aListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, 
       
  1766             CEikScrollBarFrame::EAuto);
       
  1767 
       
  1768     // Enable item marqueeing.
       
  1769 	aListBox->ItemDrawer()->ColumnData()->EnableMarqueeL(ETrue);
       
  1770     
       
  1771     // Add the folders to the list-box.
       
  1772     MoveToFolderSetItemsL(*listBoxRows);
       
  1773     aListBox->HandleItemAdditionL();
       
  1774 
       
  1775     // Set the icons
       
  1776     icons = new (ELeave) CAknIconArray(1);
       
  1777     CleanupStack::PushL(icons);
       
  1778 
       
  1779     // Add the folder icon.
       
  1780     AppendIconL(icons, KAknsIIDQgnPropFolderSmall, KAvkonBitmapFile(),
       
  1781             EMbmAvkonQgn_prop_folder_small, EMbmAvkonQgn_prop_folder_small_mask);
       
  1782 
       
  1783     // Set the icons and cleanup
       
  1784     aListBox->ItemDrawer()->ColumnData()->SetIconArray(icons);
       
  1785 	CleanupStack::Pop(icons);
       
  1786 
       
  1787     CleanupStack::Pop(aPopupList);
       
  1788     CleanupStack::Pop(aListBox);
       
  1789     }
       
  1790 
       
  1791 
       
  1792 // -----------------------------------------------------------------------------
       
  1793 // CFeedsFolderContainer::MoveToFolderSetItemsL
       
  1794 //
       
  1795 // Sets the move-to-folder list-box's values.
       
  1796 // -----------------------------------------------------------------------------
       
  1797 //
       
  1798 void CFeedsFolderContainer::MoveToFolderSetItemsL(CDesCArraySeg& aListBoxRows)
       
  1799     {
       
  1800     iTargetFolderList.Reset();
       
  1801     //0\t\1st Line of text\t2nd Line of text\t0
       
  1802     TBuf<255>  listBoxtxt;
       
  1803 
       
  1804     // If need be add an entry for the root-level.
       
  1805     if (iCurrentFolder != iRootFolder)
       
  1806         {
       
  1807         TDesC*  text = NULL;
       
  1808 
       
  1809         text = CCoeEnv::Static()->AllocReadResourceLC(R_FEEDS_TEXT_FLDR_ROOT_LEVEL);
       
  1810 
       
  1811         listBoxtxt.Zero();
       
  1812         listBoxtxt.AppendFormat(_L("0\t%S"), text);
       
  1813         aListBoxRows.AppendL(listBoxtxt);
       
  1814         iTargetFolderList.Append(iRootFolder);
       
  1815 
       
  1816         CleanupStack::PopAndDestroy(text);
       
  1817         }
       
  1818 
       
  1819     if (iRootFolder)
       
  1820         {
       
  1821         AddFoldersToListL(*iRootFolder,aListBoxRows);
       
  1822         }
       
  1823     }
       
  1824 
       
  1825 // Recursive loop to find all folders
       
  1826 void CFeedsFolderContainer::AddFoldersToListL(const CFeedsEntity& aFolder, CDesCArraySeg& aListBoxRows)
       
  1827     {
       
  1828     TBuf<255>  listBoxtxt;
       
  1829     
       
  1830     for (int i = 0; i < aFolder.GetChildren().Count(); i++)
       
  1831         {
       
  1832         const CFeedsEntity*  item = NULL;
       
  1833         
       
  1834         item = aFolder.GetChildren()[i];
       
  1835         
       
  1836                 
       
  1837         // Skip all feeds and current folder
       
  1838         if (!(item->GetType()==EFolder) || iCurrentFolder == item)
       
  1839             {
       
  1840             if(iCurrentFolder == item)
       
  1841         	    {
       
  1842 		        AddFoldersToListL(*item,aListBoxRows);// recursive            	
       
  1843             	}
       
  1844             continue;
       
  1845             }
       
  1846 
       
  1847 		TPtrC itemName;
       
  1848 		item->GetStringValue(EFolderAttributeTitle,itemName);
       
  1849 
       
  1850         // Set the name.
       
  1851         TInt len;
       
  1852 
       
  1853         len = itemName.Length();
       
  1854         if (len > 253)
       
  1855             {
       
  1856             len = 253;
       
  1857             }
       
  1858 
       
  1859         listBoxtxt.Zero();
       
  1860         listBoxtxt.AppendFormat(_L("0\t%S"), &itemName);
       
  1861         aListBoxRows.AppendL(listBoxtxt);
       
  1862         iTargetFolderList.Append(item);// save pointers to items to make selection easier
       
  1863         
       
  1864         AddFoldersToListL(*item,aListBoxRows);// recursive
       
  1865         }
       
  1866     
       
  1867     }
       
  1868 
       
  1869 // -----------------------------------------------------------------------------
       
  1870 // CFeedsFolderContainer::MoveToFolderMoveL
       
  1871 //
       
  1872 // Moves the marked items into the target-folder.
       
  1873 // -----------------------------------------------------------------------------
       
  1874 //
       
  1875 void CFeedsFolderContainer::MoveToFolderMoveL(const CFeedsEntity& aTargetFolder)
       
  1876     {
       
  1877     RPointerArray<const CFeedsEntity>  markedItems(10);
       
  1878     RPointerArray<const CFeedsEntity>  removedItems(10);
       
  1879     const RPointerArray<CFeedsEntity>&  folderItems = aTargetFolder.GetChildren();
       
  1880     const CArrayFix<TInt>*            markedIndexes = NULL;
       
  1881     const CFeedsEntity*                folder = NULL;
       
  1882 
       
  1883     CleanupClosePushL(markedItems);
       
  1884     CleanupClosePushL(removedItems);
       
  1885     // Get the array of marked items.
       
  1886     markedIndexes = MarkedItems();
       
  1887     if ((markedIndexes == NULL) || (markedIndexes->Count() == 0))
       
  1888         {
       
  1889         iListBox->View()->SelectItemL(CurrentItemIndex());
       
  1890         markedIndexes = MarkedItems();
       
  1891         }
       
  1892 
       
  1893     // Copy the marked items into a temp array.
       
  1894     for (TInt i = 0; i < markedIndexes->Count(); i++)
       
  1895         {
       
  1896         folder = iCurrentFolder->GetChildren()[((*markedIndexes)[i])];
       
  1897         // if the target folder already has some feed
       
  1898         if(folderItems.Count() > 0)
       
  1899             {
       
  1900             TPtrC item;
       
  1901             TPtrC url;
       
  1902             folder->GetStringValue(EFeedAttributeTitle, item);
       
  1903             const CFeedsEntity*  otherItem = iApiProvider.FeedsClientUtilities().Search(item, aTargetFolder);
       
  1904             if(!(otherItem == CurrentItem())&& otherItem != NULL)
       
  1905                 {
       
  1906                 otherItem->GetStringValue(EFeedAttributeLink, url);
       
  1907                 iApiProvider.FeedsClientUtilities().AddFolderItemL(item,url,EFalse,aTargetFolder,0);
       
  1908                 User::LeaveIfError(removedItems.Append(folder));
       
  1909                 }
       
  1910             else
       
  1911                 {
       
  1912                 // feed not present in target folder
       
  1913                 User::LeaveIfError(markedItems.Append(folder));
       
  1914                 }
       
  1915             }
       
  1916         // if the target folder is empty
       
  1917         else
       
  1918             {
       
  1919             // Move the items.
       
  1920             User::LeaveIfError(markedItems.Append(folder));
       
  1921             }
       
  1922         }
       
  1923     if(removedItems.Count())
       
  1924         {
       
  1925         iApiProvider.FeedsClientUtilities().DeleteFolderItemsL(removedItems);
       
  1926         }
       
  1927     if(markedItems.Count())
       
  1928         {
       
  1929         // Move the items.
       
  1930         iApiProvider.FeedsClientUtilities().MoveFolderItemsToL(markedItems, aTargetFolder);
       
  1931         }
       
  1932     // Clean up
       
  1933     CleanupStack::PopAndDestroy(/*removedItems*/);
       
  1934     CleanupStack::PopAndDestroy(/*markedItems*/);
       
  1935     }
       
  1936 
       
  1937 
       
  1938 // -----------------------------------------------------------------------------
       
  1939 // CFeedsFolderContainer::PostHandleMoveL
       
  1940 //
       
  1941 // Moves the current or marked items -- called after the move-cmd is confirmed.
       
  1942 // -----------------------------------------------------------------------------
       
  1943 //
       
  1944 void CFeedsFolderContainer::PostHandleMoveL()
       
  1945     {
       
  1946     const CArrayFix<TInt>*            markedIndexes = NULL;
       
  1947     RPointerArray<const CFeedsEntity>  markedItems(10);
       
  1948     TInt                              targetIndex;
       
  1949 
       
  1950     CleanupClosePushL(markedItems);
       
  1951 
       
  1952     // Get the marked indexes.
       
  1953     markedIndexes = MarkedItems();
       
  1954 
       
  1955     // Return if there is nothing to do.
       
  1956     if ((markedIndexes == NULL) || (markedIndexes->Count() == 0))
       
  1957         {
       
  1958         return;
       
  1959         }
       
  1960 
       
  1961     // Get the target index.
       
  1962     targetIndex = CurrentItemIndex();
       
  1963 
       
  1964     // Copy the marked items into a temp array.
       
  1965     for (TInt i = 0; i < markedIndexes->Count(); i++)
       
  1966         {
       
  1967         User::LeaveIfError(markedItems.Append(
       
  1968                 iCurrentFolder->GetChildren()[((*markedIndexes)[i])]));
       
  1969         }
       
  1970     
       
  1971     // Move the items.
       
  1972     iApiProvider.FeedsClientUtilities().MoveFolderItemsL(markedItems, targetIndex);
       
  1973         
       
  1974     // Clean up
       
  1975     CleanupStack::PopAndDestroy(/*markedItems*/);
       
  1976     }
       
  1977 
       
  1978 
       
  1979 // -----------------------------------------------------------------------------
       
  1980 // CFeedsFolderContainer::UpdateCba
       
  1981 //
       
  1982 // Updates the options softkey to reflect the current state.
       
  1983 // -----------------------------------------------------------------------------
       
  1984 //
       
  1985 void CFeedsFolderContainer::UpdateCbaL()
       
  1986     {
       
  1987     TInt  commandSet;
       
  1988 
       
  1989     // Set default menu type and resource    
       
  1990     iView->MenuBar()->SetMenuTitleResourceId( R_FEEDS_FOLDER_VIEW_MENUBAR);
       
  1991     iView->MenuBar()->SetMenuType(CEikMenuBar::EMenuOptions);
       
  1992 
       
  1993     if ((MarkedItems() != NULL) && (MarkedItems()->Count() > 0))
       
  1994         {
       
  1995         // Change menu configuration to context-sensitive menu if any items are marked
       
  1996         iView->MenuBar()->SetContextMenuTitleResourceId( R_FEEDS_FOLDER_MENU_BAR_CONTEXT_MENU);
       
  1997         iView->MenuBar()->SetMenuType(CEikMenuBar::EMenuContext);
       
  1998         iView->MenuBar()->SetMenuTitleResourceId( R_FEEDS_FOLDER_VIEW_MENUBAR);
       
  1999         iView->MenuBar()->SetMenuType(CEikMenuBar::EMenuOptions);
       
  2000 
       
  2001         // normally, we use the back rsk unless we launched directly into feeds (in which case, exit)
       
  2002 		if ( !iApiProvider.BrowserWasLaunchedIntoFeeds() )
       
  2003 			{
       
  2004             commandSet = R_FEEDS_FOLDER_VIEW_CBA_OPTIONS_BACK_CONTEXT_MENU;
       
  2005 			}
       
  2006         else
       
  2007             {
       
  2008             commandSet = R_FEEDS_FOLDER_VIEW_CBA_OPTIONS_EXIT_CONTEXT_MENU;
       
  2009             }
       
  2010         }
       
  2011     else if (iCurrentFolder && (iCurrentFolder->GetChildren().Count() > 0))
       
  2012         {
       
  2013         // normally, we use the back rsk unless we launched directly into feeds (in which case, exit)
       
  2014 		if ( !iApiProvider.BrowserWasLaunchedIntoFeeds() )
       
  2015 			{
       
  2016             commandSet = R_FEEDS_FOLDER_VIEW_CBA_OPTIONS_BACK_OPEN;
       
  2017 			}
       
  2018 	    else
       
  2019 	        {
       
  2020 			if ( iCurrentFolder == iRootFolder )
       
  2021 	        	{
       
  2022             	commandSet = R_FEEDS_FOLDER_VIEW_CBA_OPTIONS_EXIT_OPEN;
       
  2023 	        	}
       
  2024 	        else
       
  2025 	        	{
       
  2026             	commandSet = R_FEEDS_FOLDER_VIEW_CBA_OPTIONS_BACK_OPEN;
       
  2027 	        	}
       
  2028 	        }
       
  2029 	        UpdateToolbarButtonsState();
       
  2030         } 
       
  2031     else
       
  2032         {
       
  2033         // normally, we use the back rsk unless we launched directly into feeds (in which case, exit)
       
  2034 		if ( !iApiProvider.BrowserWasLaunchedIntoFeeds() )
       
  2035 			{
       
  2036             commandSet = R_FEEDS_FOLDER_VIEW_CBA_OPTIONS_BACK_ADDFEED;
       
  2037 			}
       
  2038 	    else
       
  2039 	        {
       
  2040             commandSet = R_FEEDS_FOLDER_VIEW_CBA_OPTIONS_EXIT_ADDFEED;
       
  2041 	        }
       
  2042         }
       
  2043 
       
  2044     if (iMoveActive)
       
  2045         {
       
  2046 #ifndef BRDO_SINGLE_CLICK_ENABLED_FF
       
  2047         commandSet = R_AVKON_SOFTKEYS_OK_CANCEL__OK;
       
  2048 #else        
       
  2049         commandSet = R_AVKON_SOFTKEYS_CANCEL;
       
  2050 #endif        
       
  2051         }
       
  2052 
       
  2053     iView->UpdateCbaL(commandSet);
       
  2054     }        
       
  2055 
       
  2056 
       
  2057 // -----------------------------------------------------------------------------
       
  2058 // CFeedsFolderContainer::SetCurrentFolder
       
  2059 //
       
  2060 // Changes the current folder.
       
  2061 // -----------------------------------------------------------------------------
       
  2062 //
       
  2063 void CFeedsFolderContainer::SetCurrentFolder(const CFeedsEntity* aFolder, 
       
  2064         TBool aResetSelection)
       
  2065     {
       
  2066     iCurrentFolder = aFolder;
       
  2067     
       
  2068     if (aFolder != NULL)
       
  2069         {
       
  2070         iCurrentFolderId = aFolder->GetId();
       
  2071         }
       
  2072     else
       
  2073         {        
       
  2074         iCurrentFolderId = -1;
       
  2075         }
       
  2076         
       
  2077     if (aResetSelection && (iListBox != NULL))
       
  2078         {
       
  2079         iListBox->SetCurrentItemIndex(0);
       
  2080         }
       
  2081     }
       
  2082 
       
  2083 // -----------------------------------------------------------------------------
       
  2084 // CFeedsFolderContainer::CountFolderFolders
       
  2085 //
       
  2086 // Count the number of subfolders within a folder
       
  2087 //
       
  2088 // -----------------------------------------------------------------------------
       
  2089 void CFeedsFolderContainer::CountFolderFolders(const CFeedsEntity* aFolder, TInt& aFolderCount)
       
  2090     {
       
  2091     if (aFolder)
       
  2092         {
       
  2093         for(TInt index = 0; index < aFolder->GetChildren().Count(); index++)
       
  2094             {
       
  2095             if ((aFolder->GetChildren()[index])->GetType() == EFolder)
       
  2096                 {
       
  2097                 aFolderCount++;
       
  2098                 CountFolderFolders(aFolder->GetChildren()[index], aFolderCount);
       
  2099                 }
       
  2100             }
       
  2101         }
       
  2102     }
       
  2103     
       
  2104 // -----------------------------------------------------------------------------
       
  2105 // CFeedsFolderContainer::UnreadCountChangedL
       
  2106 //
       
  2107 // Calculate the unread count based on delta, return the calculated value.
       
  2108 // -----------------------------------------------------------------------------
       
  2109 //
       
  2110 TInt CFeedsFolderContainer::UnreadCountChangedL( TInt aUnreadCountDelta )
       
  2111     {
       
  2112     TInt     unreadCount = 0;
       
  2113     TInt                index;
       
  2114     CFeedsEntity*  item = NULL;
       
  2115 
       
  2116     index = iListBox->CurrentItemIndex();
       
  2117     item = const_cast<CFeedsEntity*>(iCurrentFolder->GetChildren()[index]);
       
  2118     User::LeaveIfNull((void*) item);
       
  2119 
       
  2120     // If it's a feed - update its unread count.
       
  2121     if (item->GetType() != EFolder)
       
  2122         {
       
  2123         // calculate how many are unread for the current feed
       
  2124         item->GetIntegerValue(EFolderAttributeUnreadCount, unreadCount );
       
  2125         unreadCount += aUnreadCountDelta;
       
  2126         if (unreadCount < 0)
       
  2127             {
       
  2128             unreadCount = 0;
       
  2129             }
       
  2130         CFeedsMap* map = CFeedsMap::NewL();
       
  2131         map->SetIntegerAttribute(EFolderAttributeUnreadCount,unreadCount);
       
  2132    
       
  2133       //  item->ChangeValue(*map);
       
  2134         delete map;
       
  2135         }
       
  2136     return unreadCount;
       
  2137     }
       
  2138 
       
  2139 
       
  2140 // -----------------------------------------------------------------------------
       
  2141 // CFeedsFolderContainer::SetUnreadCountL
       
  2142 //
       
  2143 // Set the unread count.
       
  2144 // -----------------------------------------------------------------------------
       
  2145 //
       
  2146 void CFeedsFolderContainer::SetUnreadCountL( TInt aUnreadCount )
       
  2147 {
       
  2148     TInt                index;
       
  2149     CFeedsEntity*  item = NULL;
       
  2150 
       
  2151     index = iListBox->CurrentItemIndex();
       
  2152     item = const_cast<CFeedsEntity*>(iCurrentFolder->GetChildren()[index]);
       
  2153     User::LeaveIfNull((void*) item);
       
  2154 
       
  2155     // If it's a feed - update its unread count.
       
  2156     if (item->GetType() == EFalse)
       
  2157         {
       
  2158         CFeedsMap* map = CFeedsMap::NewL();
       
  2159         map->SetIntegerAttribute(EFolderAttributeUnreadCount,aUnreadCount);
       
  2160    
       
  2161        // item->ChangeValue(*map);
       
  2162         delete map;
       
  2163         }
       
  2164 }
       
  2165 
       
  2166 
       
  2167 // -----------------------------------------------------------------------------
       
  2168 // CFeedsFolderContainer::DynInitMarkUnmarkMenuPane
       
  2169 //
       
  2170 // Dynamically Initialize the Mark/Unmark sub-menu
       
  2171 // -----------------------------------------------------------------------------
       
  2172 //
       
  2173 void CFeedsFolderContainer::DynInitMarkUnmarkMenuPane( CEikMenuPane *aMenuPane )
       
  2174 {
       
  2175     AknSelectionService::HandleMarkableListDynInitMenuPane(R_AVKON_MENUPANE_MARKABLE_LIST_IMPLEMENTATION, aMenuPane, iListBox);
       
  2176 }
       
  2177 
       
  2178 
       
  2179 // -----------------------------------------------------------------------------
       
  2180 // CFeedsFolderContainer::DimToolbar
       
  2181 //
       
  2182 // Dim or UnDim Toolbar
       
  2183 // if aDim is ETrue, then dim toolbar
       
  2184 // else undim toolbar
       
  2185 // -----------------------------------------------------------------------------
       
  2186 //
       
  2187 void CFeedsFolderContainer::DimToolbar(TBool aDim)
       
  2188 {
       
  2189     iView->Toolbar()->SetItemDimmed(EFeedsNewFeed, aDim, ETrue);
       
  2190     iView->Toolbar()->SetItemDimmed(EFeedsUpdateAll, aDim, ETrue);
       
  2191     iView->Toolbar()->SetItemDimmed(EWmlCmdPreferences, aDim, ETrue);
       
  2192     iView->Toolbar()->DrawNow();
       
  2193 }
       
  2194 
       
  2195 
       
  2196 // -----------------------------------------------------------------------------
       
  2197 // CFeedsFolderContainer::IsMarkedItemFolder
       
  2198 //
       
  2199 // To Check Marked items contains Folder or Feed
       
  2200 // -----------------------------------------------------------------------------
       
  2201 //
       
  2202 TBool CFeedsFolderContainer::IsMarkedItemFolder()
       
  2203 {
       
  2204     const CArrayFix<TInt>*  markedIndexes = NULL;
       
  2205 
       
  2206     // Get the marked items.
       
  2207     markedIndexes = MarkedItems();
       
  2208     
       
  2209     // Check for Folder is marked or not
       
  2210     for(TInt i=0 ; i< markedIndexes->Count(); i++)
       
  2211     {
       
  2212         if(iCurrentFolder->GetChildren()[(*markedIndexes)[i]] -> GetType() == EFolder)
       
  2213         {
       
  2214             return ETrue;
       
  2215         }
       
  2216         
       
  2217     }
       
  2218     return EFalse;
       
  2219 }
       
  2220 
       
  2221 // -----------------------------------------------------------------------------
       
  2222 // CFeedsFolderContainer::ClearNavigationPane
       
  2223 //
       
  2224 // Clears the navigation pane.
       
  2225 // -----------------------------------------------------------------------------
       
  2226 //
       
  2227 void CFeedsFolderContainer::ClearNavigationPane()
       
  2228     {
       
  2229     if (iNaviDecorator)
       
  2230         {
       
  2231         delete iNaviDecorator;
       
  2232         iNaviDecorator = NULL;
       
  2233         }
       
  2234     }
       
  2235 
       
  2236 // -----------------------------------------------------------------------------
       
  2237 // CFeedsFolderContainer::UpdateNavigationPaneL
       
  2238 //
       
  2239 // Handles the changes needed to the Navigation Pane.
       
  2240 // -----------------------------------------------------------------------------
       
  2241 //
       
  2242 void CFeedsFolderContainer::UpdateNavigationPaneL()
       
  2243     {
       
  2244     CAknNavigationControlContainer*  naviPane = NULL;
       
  2245 
       
  2246     // Get the navigation sub-pane.
       
  2247     CAknViewAppUi*  appUi;
       
  2248     TUid            uid;
       
  2249     TBuf<1>  string;
       
  2250 
       
  2251     string.Append(_L(" "));
       
  2252 
       
  2253     // Get the title sub-pane.
       
  2254     appUi = static_cast<CAknViewAppUi*>(CCoeEnv::Static()->AppUi());
       
  2255 
       
  2256     uid.iUid = EEikStatusPaneUidNavi;
       
  2257 
       
  2258     CEikStatusPaneBase::TPaneCapabilities subPane = appUi->StatusPane()->
       
  2259             PaneCapabilities(uid);
       
  2260 
       
  2261     // Set the title if the pane belongs to the app.
       
  2262     if (subPane.IsPresent() && subPane.IsAppOwned())
       
  2263         {
       
  2264         naviPane = (CAknNavigationControlContainer*) appUi->StatusPane()->ControlL(uid);
       
  2265         }
       
  2266     else
       
  2267         {
       
  2268         User::Leave(KErrNotSupported);
       
  2269         }
       
  2270 
       
  2271     // Ensure the NaviDecorator was created.
       
  2272     if (!iNaviDecorator)
       
  2273         {
       
  2274         iNaviDecorator = naviPane->CreateNavigationLabelL( string );
       
  2275         }
       
  2276 
       
  2277 
       
  2278     // If not yet pushed, this will do the push; if already there, this brings
       
  2279     // it to top and draws.
       
  2280     naviPane->PushL(*iNaviDecorator);
       
  2281     }
       
  2282 
       
  2283