browserui/browser/FeedsSrc/FeedsFeedView.cpp
branchRCL_3
changeset 48 8e6fa1719340
equal deleted inserted replaced
47:6385c4c93049 48:8e6fa1719340
       
     1 /*
       
     2 * Copyright (c) 2005-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  A view to browse a given feed.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <aknviewappui.h>
       
    20 #include <aknutils.h>
       
    21 #include <AknToolbar.h>
       
    22 #include <brctlinterface.h>
       
    23 #include <eikbtgpc.h>
       
    24 #include <eikmenup.h>
       
    25 #include <hlplch.h>
       
    26 
       
    27 #include "BrowserAppUi.h"
       
    28 #include "CommonConstants.h"
       
    29 #include "Browser.hrh"
       
    30 #include <BrowserNG.rsg>
       
    31 #include "BrowserUtil.h"
       
    32 #include <feedattributes.h>
       
    33 #include <folderattributes.h>
       
    34 #include "FeedsFeedContainer.h"
       
    35 #include "FeedsFeedView.h"
       
    36 
       
    37 #include "Logger.h"
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CFeedsFeedView::NewL
       
    41 //
       
    42 // Two-phased constructor.
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CFeedsFeedView* CFeedsFeedView::NewL( MApiProvider& aApiProvider, TRect& aRect )
       
    46 
       
    47 	{
       
    48     CFeedsFeedView* self = new (ELeave) CFeedsFeedView(aApiProvider);
       
    49     
       
    50     CleanupStack::PushL(self);
       
    51     self->ConstructL(aRect);
       
    52     CleanupStack::Pop();
       
    53 
       
    54     return self;
       
    55 	}
       
    56 
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CFeedsFeedView::CFeedsFeedView
       
    60 //
       
    61 // C++ default constructor.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CFeedsFeedView::CFeedsFeedView(MApiProvider& aApiProvider)
       
    65 : CBrowserViewBase( aApiProvider ),iPageScalerEnabled(EFalse),iPenEnabled(EFalse)
       
    66 	{
       
    67     iPenEnabled = AknLayoutUtils::PenEnabled(); 
       
    68 	}
       
    69 
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CFeedsFeedView::ConstructL
       
    73 //
       
    74 // Symbian 2nd phase constructor can leave.
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 void CFeedsFeedView::ConstructL(TRect& aRect)
       
    78     {
       
    79     // this is here in case content view wasn't activated yet on browser startup.
       
    80     iApiProvider.SetViewToBeActivatedIfNeededL( KUidBrowserContentViewId );
       
    81             
       
    82     BaseConstructL(R_FEEDS_FEED_VIEW);
       
    83 
       
    84 	iContainer = CFeedsFeedContainer::NewL( this, ApiProvider() );
       
    85 	iContainer->SetRect( aRect );
       
    86     iOrigRect.iTl = aRect.iTl;
       
    87     iOrigRect.iBr = aRect.iBr;
       
    88     iContainer->MakeVisible(EFalse);
       
    89     
       
    90     if(iPenEnabled)
       
    91         {
       
    92         Toolbar()->SetToolbarObserver(this);;        
       
    93         }    
       
    94     }
       
    95 
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CFeedsFeedView::~CFeedsFeedView
       
    99 //
       
   100 // Deconstructor.
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 CFeedsFeedView::~CFeedsFeedView()
       
   104     {
       
   105     DoDeactivate();
       
   106 
       
   107     delete iContainer;
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CFeedsFeedView::Id
       
   112 //
       
   113 // Returns the id of the view.
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 TUid CFeedsFeedView::Id() const
       
   117     {
       
   118     return KUidBrowserFeedsFeedViewId;
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CFeedsFeedView::HandleCommandL
       
   123 //
       
   124 // Processes commands.
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CFeedsFeedView::HandleCommandL(TInt aCommand)
       
   128     {   
       
   129     TBool  handled = EFalse;
       
   130     
       
   131     // Handle softkeys and other Symbian commands first.
       
   132     switch (aCommand)
       
   133         {
       
   134 		case EAknSoftkeyBack:
       
   135 			iApiProvider.FeedsClientUtilities().ShowTopicViewLocalL(iContainer->CurrentItem());
       
   136             handled = ETrue;
       
   137             break;
       
   138             
       
   139         case EAknSoftkeyNext:
       
   140             iContainer->ShowNextItemL();
       
   141             handled = ETrue;
       
   142             break;
       
   143 
       
   144 #ifdef __SERIES60_HELP
       
   145         case EAknCmdHelp:
       
   146             {
       
   147             iApiProvider.SetLastActiveViewId(Id());
       
   148             HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), 
       
   149                     AppUi()->AppHelpContextL());
       
   150             handled = ETrue;
       
   151             break;
       
   152             }
       
   153 #endif //__SERIES60_HELP 
       
   154         }
       
   155         
       
   156     if (handled)
       
   157         {
       
   158         return;
       
   159         }
       
   160      
       
   161     switch (aCommand)
       
   162         {
       
   163         case EFeedsBack:
       
   164 		    iApiProvider.FeedsClientUtilities().ShowTopicViewLocalL(iContainer->CurrentItem());
       
   165             break;
       
   166             
       
   167         case EFeedsShowNextItem:
       
   168             iContainer->ShowNextItemL();
       
   169             break;
       
   170 
       
   171         case EFeedsShowPrevItem:
       
   172             iContainer->ShowPrevItemL();
       
   173             break;
       
   174 
       
   175 		case EFeedsSeeFullStory:
       
   176             iContainer->iBrowserControl->HandleCommandL((TBrCtlDefs::ECommandIdBase + TBrCtlDefs::ECommandOpen));
       
   177             break;
       
   178 
       
   179         default:
       
   180             iApiProvider.FeedsClientUtilities().HandleCommandL(Id(),aCommand);
       
   181             break;
       
   182         }
       
   183     }
       
   184 
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CFeedsFeedView::DoActivateL
       
   188 //
       
   189 // Called when the view is activated.
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 void CFeedsFeedView::DoActivateL(const TVwsViewId& /*aPrevViewId*/, 
       
   193         TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/)
       
   194     {
       
   195     // fix bug RFON-7FJS2Z: need to activate status pane going back from full story page to feeds view
       
   196    	StatusPane()->SwitchLayoutL( R_AVKON_STATUS_PANE_LAYOUT_USUAL );
       
   197   	StatusPane()->MakeVisible( ETrue );
       
   198     //Take Button group pointer
       
   199     CEikButtonGroupContainer* pButtonGroupContainer = CEikButtonGroupContainer::Current();
       
   200     if (!iContainerOnStack)
       
   201         {
       
   202         AppUi()->AddToViewStackL(*this, iContainer);        
       
   203         //Make button group invisible in order to let container have correct Rect.
       
   204         //Patch is based on comments received from AVKON
       
   205         if(pButtonGroupContainer) pButtonGroupContainer->MakeVisible(EFalse);
       
   206         iContainer->SetRect(iOrigRect);
       
   207         if(iContainer->iBrowserControl->BrowserSettingL(TBrCtlDefs::ESettingsPageOverview))
       
   208             {
       
   209             TRAP_IGNORE(iContainer->iBrowserControl->SetBrowserSettingL(TBrCtlDefs::ESettingsPageOverview, EFalse));
       
   210             iPageScalerEnabled = ETrue;
       
   211             }
       
   212         TRAP_IGNORE(iContainer->iBrowserControl->HandleCommandL( 
       
   213                 (TInt)TBrCtlDefs::ECommandIdBase + (TInt)TBrCtlDefs::ECommandGainFocus));
       
   214         
       
   215         iContainer->MakeVisible(ETrue);        
       
   216         //Again make Button group visible
       
   217         if(pButtonGroupContainer) pButtonGroupContainer->MakeVisible(ETrue);
       
   218         iContainerOnStack = ETrue;
       
   219         // resize screen after calling SetRect.  This way looks better
       
   220         iContainer->HandleResourceChange(KEikDynamicLayoutVariantSwitch);
       
   221         }
       
   222 
       
   223     // Set the current feed.
       
   224     iContainer->SetCurrentFeedL(*(iApiProvider.FeedsClientUtilities().CurrentFeed()), iInitialItem);
       
   225     
       
   226     iApiProvider.SetLastActiveViewId(Id());
       
   227     UpdateToolbarButtonsState();
       
   228     }
       
   229 
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // CFeedsFeedView::DoDeactivate
       
   233 //
       
   234 // Called when the view is deactivated.
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 void CFeedsFeedView::DoDeactivate()
       
   238     {
       
   239     if (iContainerOnStack)
       
   240         {
       
   241         iContainer->ClearNavigationPane();        
       
   242         
       
   243         if(iPageScalerEnabled)
       
   244             {
       
   245             TRAP_IGNORE(iContainer->iBrowserControl->SetBrowserSettingL(TBrCtlDefs::ESettingsPageOverview, ETrue));
       
   246             iPageScalerEnabled = EFalse;
       
   247             }
       
   248         TRAP_IGNORE(iContainer->iBrowserControl->HandleCommandL( 
       
   249                 (TInt)TBrCtlDefs::ECommandIdBase + (TInt)TBrCtlDefs::ECommandLoseFocus));
       
   250         
       
   251         AppUi()->RemoveFromViewStack(*this, iContainer);
       
   252         iContainer->MakeVisible(EFalse);
       
   253         
       
   254         iInitialItem = iContainer->CurrentItem();
       
   255         iContainerOnStack = EFalse;
       
   256         
       
   257         // when exit from feeds view, viewMgr might be deleted already
       
   258         if ( !ApiProvider().ExitInProgress() )
       
   259             {
       
   260             TRAP_IGNORE(iApiProvider.FeedsClientUtilities().ItemStatusWriteToServerL()); 
       
   261             }
       
   262         }
       
   263 	}
       
   264 
       
   265 
       
   266 // -----------------------------------------------------------------------------
       
   267 // CFeedsFeedView::DynInitMenuPaneL
       
   268 //
       
   269 // Disables unrelated menu options.
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 void CFeedsFeedView::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
       
   273     {
       
   274     __ASSERT_DEBUG( (aMenuPane != NULL), Util::Panic( Util::EUninitializedData ));
       
   275     
       
   276     // Handle the main menu.
       
   277     if (aResourceId == R_FEEDS_FEED_VIEW_MENU)
       
   278         {
       
   279         // Back to Page (if page loaded)
       
   280         if ( iApiProvider.IsPageLoaded() )
       
   281             {
       
   282             iApiProvider.FeedsClientUtilities().AddItemL( *aMenuPane, EWmlCmdBackToPage, R_BROWSER_MENU_ITEM_BACK_TO_PAGE );
       
   283             }
       
   284         }
       
   285         
       
   286     iApiProvider.FeedsClientUtilities().DynInitMenuPaneL(aResourceId, aMenuPane );
       
   287     }
       
   288 
       
   289 // -----------------------------------------------------------------------------
       
   290 // CFeedsFeedView::SetInitialItem
       
   291 //
       
   292 // Sets the initial item once the view is activated.
       
   293 // -----------------------------------------------------------------------------
       
   294 //
       
   295 void CFeedsFeedView::SetInitialItem(TInt aItemIndex)
       
   296     {
       
   297     iInitialItem = aItemIndex;
       
   298     }
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // CFeedsTopicView::UpdateToolbarButtonsState
       
   302 //
       
   303 // Updates the state of the toolbar buttons depending on the situation
       
   304 // -----------------------------------------------------------------------------
       
   305 //
       
   306 
       
   307 void CFeedsFeedView::UpdateToolbarButtonsState()
       
   308     {
       
   309     if ( iContainer->ItemCount()  > 1 )
       
   310         {
       
   311         Toolbar()->SetItemDimmed(EFeedsShowPrevItem, EFalse, ETrue);
       
   312         Toolbar()->SetItemDimmed(EFeedsShowNextItem, EFalse, ETrue);
       
   313         }
       
   314     else
       
   315         {
       
   316         Toolbar()->SetItemDimmed(EFeedsShowPrevItem, ETrue, ETrue);
       
   317         Toolbar()->SetItemDimmed(EFeedsShowNextItem, ETrue, ETrue);
       
   318         }
       
   319     Toolbar()->SetItemDimmed(EFeedsSeeFullStory, EFalse, ETrue);
       
   320     }
       
   321     
       
   322 // ---------------------------------------------------------------------------
       
   323 // CFeedsFeedView::CommandSetResourceIdL
       
   324 // ---------------------------------------------------------------------------
       
   325 TInt CFeedsFeedView::CommandSetResourceIdL()
       
   326     {
       
   327     // It is never called, but this function have to be implemented
       
   328     return KWmlEmptyResourceId;
       
   329     }
       
   330     
       
   331 // ---------------------------------------------------------
       
   332 // CFeedsFeedView::HandleClientRectChange
       
   333 // ---------------------------------------------------------
       
   334 //
       
   335 void CFeedsFeedView::HandleClientRectChange()
       
   336     {
       
   337     if( iContainer )
       
   338         {
       
   339         iContainer->MakeVisible(EFalse);
       
   340         iContainer->SetRect(ClientRect());
       
   341         iContainer->MakeVisible(ETrue);        
       
   342         }
       
   343     }
       
   344 
       
   345 // -----------------------------------------------------------------------------
       
   346 // CFeedsFeedView::DisconnectL
       
   347 // -----------------------------------------------------------------------------
       
   348 //
       
   349 void CFeedsFeedView::DisconnectL()
       
   350     {
       
   351     if( iContainer )
       
   352         {
       
   353         iContainer->iBrowserControl->HandleCommandL( TBrCtlDefs::ECommandDisconnect + TBrCtlDefs::ECommandIdBase );
       
   354         }
       
   355     }