browserui/browser/FeedsSrc/FeedsTopicView.cpp
changeset 0 84ad3b177aa3
child 24 868cceedabd3
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 feed's topics.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <aknviewappui.h>
       
    21 #include <aknutils.h>
       
    22 #include <AknToolbar.h>
       
    23 #include <eikbtgpc.h>
       
    24 #include <eikmenup.h>
       
    25 #include <hlplch.h>
       
    26 
       
    27 #include "Browser.hrh"
       
    28 #include <BrowserNG.rsg>
       
    29 #include <FeedAttributes.h>
       
    30 #include <FolderAttributes.h>
       
    31 #include "BrowserAppUi.h"
       
    32 #include "CommonConstants.h"
       
    33 
       
    34 #include "FeedsTopicView.h"
       
    35 #include "FeedsTopicContainer.h"
       
    36 
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CFeedsTopicView::NewL
       
    40 //
       
    41 // Two-phased constructor.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CFeedsTopicView* CFeedsTopicView::NewL(	MApiProvider& aApiProvider,	TRect& aRect )
       
    45 	{
       
    46     CFeedsTopicView* self = new (ELeave) CFeedsTopicView(aApiProvider);
       
    47     
       
    48     CleanupStack::PushL(self);
       
    49     self->ConstructL(aRect);
       
    50     CleanupStack::Pop();
       
    51 
       
    52     return self;
       
    53 	}
       
    54 
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CFeedsTopicView::CFeedsTopicView
       
    58 //
       
    59 // C++ default constructor.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CFeedsTopicView::CFeedsTopicView(MApiProvider& aApiProvider):
       
    63 	 CBrowserViewBase( aApiProvider ),iPenEnabled(EFalse)
       
    64 	{
       
    65     iPenEnabled = AknLayoutUtils::PenEnabled();
       
    66 	}
       
    67 
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CFeedsTopicView::ConstructL
       
    71 //
       
    72 // Symbian 2nd phase constructor can leave.
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 void CFeedsTopicView::ConstructL(TRect& aRect)
       
    76     {
       
    77     BaseConstructL(R_FEEDS_TOPIC_VIEW);
       
    78     
       
    79     iContainer = CFeedsTopicContainer::NewL( this, ApiProvider(), aRect );
       
    80     iContainer->MakeVisible(EFalse);
       
    81         
       
    82     if(iPenEnabled)
       
    83         {
       
    84         Toolbar()->SetToolbarObserver(this);;        
       
    85         }
       
    86     }
       
    87 
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CFeedsTopicView::~CFeedsTopicView
       
    91 //
       
    92 // Deconstructor.
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 CFeedsTopicView::~CFeedsTopicView()
       
    96     {
       
    97     DoDeactivate();
       
    98 
       
    99     delete iContainer;
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CFeedsTopicView::Id
       
   104 //
       
   105 // Returns the id of the view.
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 TUid CFeedsTopicView::Id() const
       
   109     {
       
   110     return KUidBrowserFeedsTopicViewId;
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CFeedsTopicView::HandleCommandL
       
   115 //
       
   116 // Processes commands.
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void CFeedsTopicView::HandleCommandL(TInt aCommand)
       
   120     {   
       
   121     TBool  handled = EFalse;
       
   122         
       
   123     // Handle softkeys and other Symbian commands first.
       
   124     switch (aCommand)
       
   125         {
       
   126 		case EAknSoftkeyBack:
       
   127 		    iApiProvider.FeedsClientUtilities().ShowFolderViewLocalL();
       
   128             handled = ETrue;
       
   129             break;
       
   130 
       
   131 #ifdef __SERIES60_HELP
       
   132         case EAknCmdHelp:
       
   133             {
       
   134             iApiProvider.SetLastActiveViewId(Id());
       
   135             HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), 
       
   136                     AppUi()->AppHelpContextL());
       
   137             handled = ETrue;
       
   138             break;
       
   139             }
       
   140 #endif //__SERIES60_HELP 
       
   141         }
       
   142         
       
   143     if (handled)
       
   144         {
       
   145         return;
       
   146         }
       
   147         
       
   148     // Handle menu commands.
       
   149     switch (aCommand)
       
   150         {
       
   151 		case EFeedsOpen:
       
   152     		if ((iApiProvider.FeedsClientUtilities().CurrentFeed()->GetChildren().Count()) > 0)
       
   153         		{
       
   154                 iContainer->HandleOpenL();     
       
   155         		}
       
   156             break;
       
   157 
       
   158 		case EFeedsUpdate:
       
   159 		    iContainer->HandleUpdateFeedL();
       
   160             break;
       
   161 
       
   162 		case EFeedsBackToPage:
       
   163             iApiProvider.FeedsClientUtilities().HandleCommandL(Id(), EWmlCmdBackToPage );
       
   164 			break;
       
   165 
       
   166         default:
       
   167             iApiProvider.FeedsClientUtilities().HandleCommandL(Id(),aCommand);
       
   168             break;
       
   169         }
       
   170     }
       
   171 
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // CFeedsTopicView::DoActivateL
       
   175 //
       
   176 // Called when the view is activated.
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 void CFeedsTopicView::DoActivateL(const TVwsViewId& /*aPrevViewId*/, 
       
   180         TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/)
       
   181     {
       
   182 
       
   183     // If need be, add the container to the control stack.
       
   184     if (!iContainerOnStack)
       
   185         {
       
   186         AppUi()->AddToViewStackL(*this, iContainer);
       
   187         iContainer->SetRect(ClientRect());
       
   188         iContainer->MakeVisible(ETrue);
       
   189         iContainerOnStack = ETrue;
       
   190         // resize screen after calling SetRect.  This way looks better
       
   191         iContainer->HandleResourceChange(KEikDynamicLayoutVariantSwitch);
       
   192         }
       
   193 
       
   194     // Set the current feed.
       
   195     iContainer->SetCurrentFeedL(*(iApiProvider.FeedsClientUtilities().CurrentFeed()), iInitialItem);
       
   196     iApiProvider.SetLastActiveViewId(Id());
       
   197     UpdateToolbarButtonsState();
       
   198     }
       
   199 
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CFeedsTopicView::DoDeactivate
       
   203 //
       
   204 // Called when the view is deactivated.
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 void CFeedsTopicView::DoDeactivate()
       
   208     {
       
   209     if (iContainerOnStack)
       
   210         {
       
   211         AppUi()->RemoveFromViewStack(*this, iContainer);
       
   212         iContainer->MakeVisible(EFalse);
       
   213         iContainer->ClearNavigationPane();
       
   214         iContainerOnStack = EFalse;
       
   215 
       
   216         iInitialItem = iContainer->CurrentIndex();
       
   217         }
       
   218 	}
       
   219 
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 // CFeedsTopicView::DynInitMenuPaneL
       
   223 //
       
   224 // Disables unrelated menu options.
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 void CFeedsTopicView::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
       
   228     {
       
   229 
       
   230 
       
   231     if (aResourceId == R_FEEDS_TOPIC_VIEW_MENU)
       
   232         {
       
   233         // Refresh (same as update?)
       
   234         iApiProvider.FeedsClientUtilities().AddItemL(*aMenuPane, EFeedsUpdate, R_FEEDS_UPDATE);
       
   235 
       
   236         // Back to Page (if page loaded)
       
   237         if ( iApiProvider.IsPageLoaded() )
       
   238             {
       
   239             iApiProvider.FeedsClientUtilities().AddItemL( *aMenuPane, EWmlCmdBackToPage, R_BROWSER_MENU_ITEM_BACK_TO_PAGE );
       
   240             }
       
   241         }      
       
   242         
       
   243     iApiProvider.FeedsClientUtilities().DynInitMenuPaneL(aResourceId, aMenuPane );
       
   244     }
       
   245 
       
   246 
       
   247 // -----------------------------------------------------------------------------
       
   248 // CFeedsTopicView::SetCurrentFeedL
       
   249 //
       
   250 // Sets the current feed
       
   251 // -----------------------------------------------------------------------------
       
   252 //
       
   253 void CFeedsTopicView::SetCurrentFeedL(const CFeedsEntity& aFeed, TInt aIndex)
       
   254     {
       
   255     iContainer->SetCurrentFeedL(aFeed, aIndex);
       
   256     }
       
   257     
       
   258     
       
   259 // -----------------------------------------------------------------------------
       
   260 // CFeedsTopicView::SetInitialItem
       
   261 //
       
   262 // Sets the initial item once the view is activated.
       
   263 // -----------------------------------------------------------------------------
       
   264 //
       
   265 void CFeedsTopicView::SetInitialItem(TInt aItemIndex)
       
   266     {
       
   267     iInitialItem = aItemIndex;
       
   268     }
       
   269 
       
   270 // -----------------------------------------------------------------------------
       
   271 // CFeedsTopicView::UpdateToolbarButtonsState
       
   272 //
       
   273 // Updates the state of the toolbar buttons depending on the situation
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 
       
   277 void CFeedsTopicView::UpdateToolbarButtonsState()
       
   278     {
       
   279     if (iApiProvider.IsPageLoaded())
       
   280         {
       
   281         Toolbar()->SetItemDimmed(EFeedsBackToPage, EFalse, ETrue);     
       
   282         }
       
   283     else
       
   284         {
       
   285         Toolbar()->SetItemDimmed(EFeedsBackToPage, ETrue, ETrue);            
       
   286         }
       
   287     if ((iApiProvider.FeedsClientUtilities().CurrentFeed()->GetChildren().Count()) > 0)
       
   288         {
       
   289         Toolbar()->SetItemDimmed(EFeedsOpen, EFalse, ETrue);     
       
   290         }
       
   291     else
       
   292         {
       
   293         Toolbar()->SetItemDimmed(EFeedsOpen, ETrue, ETrue);            
       
   294         }
       
   295     }
       
   296 
       
   297 // ---------------------------------------------------------------------------
       
   298 // CFeedsTopicView::CommandSetResourceIdL
       
   299 // ---------------------------------------------------------------------------
       
   300 TInt CFeedsTopicView::CommandSetResourceIdL()
       
   301     {
       
   302     // It is never called, but this function have to be implemented
       
   303     return KWmlEmptyResourceId;
       
   304     }
       
   305     
       
   306 // ---------------------------------------------------------
       
   307 // CFeedsTopicView::HandleClientRectChange
       
   308 // ---------------------------------------------------------
       
   309 //
       
   310 void CFeedsTopicView::HandleClientRectChange()
       
   311 	{
       
   312 	if( iContainer )
       
   313 	    {
       
   314         iContainer->SetRect( ClientRect() );
       
   315         }
       
   316 	}