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