browserui/browser/FeedsSrc/FeedsClientUtilities.cpp
changeset 0 84ad3b177aa3
child 1 57d5b8e231c4
equal deleted inserted replaced
-1:000000000000 0:84ad3b177aa3
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Manages the feed related views and implements the FeedsViewBridge.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <AknView.h>
       
    20 #include <AknViewAppUi.h>
       
    21 #include <BaUtils.h>
       
    22 #include <BaDesca.h>
       
    23 #include <BrCtlInterface.h>
       
    24 #include <GulIcon.h>
       
    25 #include <data_caging_path_literals.hrh>
       
    26 #include <eikmenup.h>
       
    27 #include <StringLoader.h>
       
    28 
       
    29 
       
    30 #include <BrowserNG.rsg>
       
    31 #include <BrCtlDialogsProvider.h>
       
    32 #include <BrowserDialogsProvider.h>
       
    33 #include <BrCtlDefs.h>
       
    34 #include <InternetConnectionManager.h>
       
    35 #include <FeatMgr.h>
       
    36 #include <Uri16.h>
       
    37 
       
    38 #include "Browser.hrh"
       
    39 #include "BrowserAppUi.h"
       
    40 #include "CommonConstants.h"
       
    41 #include "BrowserWindow.h"
       
    42 #include "BrowserWindowManager.h"
       
    43 #include "BrowserUIVariant.hrh"
       
    44 #include "Preferences.h"
       
    45 #include "BrowserGotoPane.h"
       
    46 #include "BrowserAdaptiveListPopup.h"
       
    47 #include "FeedsFeedView.h"
       
    48 #include "FeedsFolderView.h"
       
    49 #include "BrowserDialogs.h"
       
    50 #include "FeedsTopicView.h"
       
    51 #include "BrowserUtil.h"
       
    52 #include "BrowserSpecialLoadObserver.h"
       
    53 
       
    54 #include "FeedsClientUtilities.h"
       
    55 
       
    56 #include "BrowserBmOTABinSender.h"
       
    57 
       
    58 // CONSTANTS
       
    59 _LIT(KSupportedMimeTypes, "application/rss+xml;application/atom+xml;text/xml;application/xml");
       
    60 const TInt KLastUpdateGranularity = 10;
       
    61 
       
    62 const TInt KWmlSettingsAutomaticUpdatingNotSet = 32767;
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CFeedsClientUtilities::NewL
       
    66 //
       
    67 // Two-phased constructor.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CFeedsClientUtilities* CFeedsClientUtilities::NewL(CAknViewAppUi& aAppUI, MApiProvider& aApiProvider)
       
    71     {
       
    72     CFeedsClientUtilities* self = new (ELeave) CFeedsClientUtilities(aAppUI, aApiProvider);
       
    73     
       
    74     CleanupStack::PushL(self);
       
    75     self->ConstructL();
       
    76     CleanupStack::Pop();
       
    77 
       
    78     return self;
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CFeedsClientUtilities::CFeedsClientUtilities
       
    83 //
       
    84 // C++ default constructor.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 CFeedsClientUtilities::CFeedsClientUtilities(CAknViewAppUi& aAppUI, MApiProvider& aApiProvider):
       
    88 		iAppUI(aAppUI), iApiProvider(aApiProvider), iIsUpdatingFeed(EFalse), iWaitDialog(0),
       
    89 		iEnteredURL(0), iFolderView(0), iTopicView(0), iFeedView(0), 
       
    90         iIsConnected(EFalse), iItemIds(20), iItemStatus(20), iMimeTypes(0),
       
    91         iFeedUpdateTimeIds(KLastUpdateGranularity), iFeedUpdateTimeTimestamps(KLastUpdateGranularity),
       
    92         iPendingFolderItemTitle(NULL), iPendingFolderItemUrl(NULL), iExportFileName(NULL),
       
    93 	    iSearchAgent(NULL),
       
    94     	iSearchOptList(NULL),
       
    95     	iFeedImportRequested(EFalse),
       
    96     	iRequestCanceled(EFalse),
       
    97         iIsWaitDialogDisplayed(EFalse), 
       
    98         iFeedsInterface(*this,0),
       
    99         iCanceledRequest(CTransaction::ENone)
       
   100 	{
       
   101 	}
       
   102 
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CFeedsClientUtilities::ConstructL
       
   106 //
       
   107 // Symbian 2nd phase constructor can leave.
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 void CFeedsClientUtilities::ConstructL()
       
   111     {
       
   112 	iApiProvider.Preferences().AddObserverL( this );
       
   113 	
       
   114 	// Set up MimeTypes
       
   115 	iMimeTypes = HBufC::NewL( KSupportedMimeTypes().Length() + 1 );
       
   116     TPtr ptr( iMimeTypes->Des() );
       
   117     ptr.Append( KSupportedMimeTypes() );
       
   118     ptr.ZeroTerminate();
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CFolderItem::Search
       
   123 //
       
   124 // Searches for a FolderItem with the given name.  If "this"
       
   125 // isn't a folder it only checks whether or not it matches
       
   126 // the given name.  If "this" is a folder it also checks 
       
   127 // all embedded items.
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 const CFeedsEntity* CFeedsClientUtilities::Search(const TDesC& aName,const CFeedsEntity& aFolder) const
       
   131     {
       
   132     TPtrC title;
       
   133     if (aFolder.GetType() == EFolder)
       
   134         {
       
   135         aFolder.GetStringValue(EFolderAttributeTitle,title);	
       
   136         }
       
   137     else
       
   138         {
       
   139         aFolder.GetStringValue(EFeedAttributeTitle,title);	
       
   140         }
       
   141     if (aName.CompareF(title) == 0)
       
   142         {
       
   143     	return &aFolder;
       
   144         }
       
   145     if (aFolder.GetType() == EFolder)
       
   146         {
       
   147     	for(TInt i=0;i<aFolder.GetChildren().Count();i++)
       
   148     	    {
       
   149     		const CFeedsEntity *item;
       
   150     		CFeedsEntity *child = aFolder.GetChildren()[i];
       
   151     		if((item = Search(aName,*child)) != NULL)
       
   152     		    {
       
   153     			return item;
       
   154     		    }
       
   155     	    }
       
   156         }
       
   157 
       
   158     // Otherwise no match was found.
       
   159     return NULL;
       
   160     }
       
   161 
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CFolderItem::Search
       
   165 //
       
   166 // Searches for a FolderItem with the given id.  If "this"
       
   167 // isn't a folder it only checks whether or not it matches
       
   168 // the given id.  If "this" is a folder it also checks 
       
   169 // all embedded items.
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 const CFeedsEntity* CFeedsClientUtilities::Search(TInt aFolderItemId,const CFeedsEntity& aFolder) const
       
   173     {
       
   174     if (aFolderItemId == aFolder.GetId())
       
   175         {
       
   176     	return &aFolder;
       
   177         }
       
   178     if (aFolder.GetType() == EFolder)
       
   179         {
       
   180     	for(TInt i=0;i<aFolder.GetChildren().Count();i++)
       
   181     	    {
       
   182     		const CFeedsEntity *item;
       
   183     		CFeedsEntity *child = aFolder.GetChildren()[i];
       
   184     		if ((item = Search(aFolderItemId,*child)) != NULL)
       
   185     		    {
       
   186     			return item;
       
   187     		    }
       
   188     	    }
       
   189         }
       
   190 
       
   191     // Otherwise no match was found.
       
   192     return NULL;
       
   193     }
       
   194 
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CFeedsClientUtilities::~CFeedsClientUtilities
       
   198 //
       
   199 // Deconstructor.
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 CFeedsClientUtilities::~CFeedsClientUtilities()
       
   203     {
       
   204     DisconnectFromServer();
       
   205     
       
   206     iApiProvider.Preferences().RemoveObserver( this );
       
   207     
       
   208     delete iWaitDialog;   
       
   209     delete iMimeTypes;
       
   210     
       
   211     iFeedUpdateTimeIds.Close();
       
   212     iFeedUpdateTimeTimestamps.Close(); 
       
   213     
       
   214     delete iPendingFolderItemTitle;
       
   215     delete iPendingFolderItemUrl;
       
   216     delete iExportFileName;
       
   217     delete iEnteredURL;
       
   218     delete iSearchAgent;
       
   219     
       
   220     iItemIds.Close();
       
   221     iItemStatus.Close();
       
   222     iItemStatusOrig.Close();    
       
   223 
       
   224     }
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // CFeedsClientUtilities::RequestCompleted()
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 void CFeedsClientUtilities::RequestCompleted(CTransaction* aTrans,TInt /*aEvent*/)
       
   231 {
       
   232 TInt status = aTrans->GetStatusCode();
       
   233 
       
   234 switch (aTrans->Type())
       
   235     {
       
   236     	case CTransaction::EFetchRootFolderItem:
       
   237    	        FolderItemRequestCompleted(status, CTransaction::EFetchRootFolderItem);
       
   238 
       
   239     	    break;
       
   240     	
       
   241     	case CTransaction::EWatchForChanges:
       
   242     	    break;
       
   243         
       
   244     	case CTransaction::EExportOPML:
       
   245     	case CTransaction::EImportOPML:
       
   246     	    FolderItemRequestCompleted(status, aTrans->Type());
       
   247     	    break;
       
   248     	    
       
   249         case CTransaction::EAddFolderItem:
       
   250         case CTransaction::EDeleteFolderItem:
       
   251         case CTransaction::EChangeFolderItem:
       
   252         case CTransaction::EMoveFolderItem:
       
   253         case CTransaction::EMoveFolderItemTo:
       
   254         case CTransaction::EUpdateFolderItem:
       
   255     	    FolderItemRequestCompleted(status, aTrans->Type());
       
   256     	    break;
       
   257 
       
   258         case CTransaction::EChangeSettings:
       
   259             break;
       
   260 
       
   261     	case CTransaction::EFetchFeed:
       
   262    	        FeedRequestCompleted(status);
       
   263     	    break;
       
   264     	case CTransaction::EUpdateItemStatus:
       
   265             break;
       
   266         
       
   267         default:
       
   268             FolderItemRequestCompleted(status, aTrans->Type());
       
   269             break;
       
   270     }
       
   271 }
       
   272     
       
   273 // -----------------------------------------------------------------------------
       
   274 // CFeedsClientUtilities::NetworkConnectionNeededL()
       
   275 // -----------------------------------------------------------------------------
       
   276 //
       
   277 void CFeedsClientUtilities::NetworkConnectionNeededL(
       
   278         TInt* aConnectionPtr, TInt& aSockSvrHandle,
       
   279         TBool& aNewConn, TApBearerType& aBearerType )
       
   280     {
       
   281     iApiProvider.SpecialLoadObserver().NetworkConnectionNeededL(
       
   282         aConnectionPtr, &aSockSvrHandle, &aNewConn, &aBearerType );
       
   283      //Wait dialog is shown only in the case of a new connection.
       
   284      if ( aNewConn )
       
   285          {
       
   286          iWaitDialog->ShowWaitDialogL(R_FEEDS_UPDATING_FEED);
       
   287          iIsWaitDialogDisplayed = ETrue;
       
   288          }
       
   289     }
       
   290 
       
   291 // -----------------------------------------------------------------------------
       
   292 // CFeedsClientUtilities::HandlePreferencesChangeL()
       
   293 // -----------------------------------------------------------------------------
       
   294 //
       
   295 void CFeedsClientUtilities::HandlePreferencesChangeL(
       
   296         const TPreferencesEvent aEvent,
       
   297         TPreferencesValues& aValues,
       
   298         TBrCtlDefs::TBrCtlSettings aSettingType )
       
   299     {
       
   300     // no specific TBrCtlDefs::TBrCtlSettings are defined for FeedsSettings
       
   301     // so we trigger for an Unknown setting
       
   302     if(   (EPreferencesItemChange == aEvent || EPreferencesDeactivate == aEvent)  &&
       
   303           (TBrCtlDefs::ESettingsUnknown == aSettingType ) )
       
   304         {
       
   305         SetPreferencesToFeedL( aValues );
       
   306         }
       
   307     }
       
   308 
       
   309 // -----------------------------------------------------------------------------
       
   310 // CFeedsClientUtilities::SetPreferencesToFeedL()
       
   311 // -----------------------------------------------------------------------------
       
   312 //
       
   313 void CFeedsClientUtilities::SetPreferencesToFeedL( const TPreferencesValues& aValues )
       
   314     {
       
   315     if ( iIsWaitDialogDisplayed )
       
   316         {
       
   317     	return;
       
   318         }    
       
   319     TFeedsServerSetting setting;
       
   320 
       
   321     // always set to 32767 in the case of feed level auto updating.
       
   322     //setting.iAutoUpdate = KWmlSettingsAutomaticUpdatingNotSet;
       
   323     setting.iAutoUpdate = EFalse;
       
   324     setting.iAutoUpdateFreq = KWmlSettingsAutomaticUpdatingNotSet;
       
   325   setting.iAutoUpdateWhileRoaming = aValues.iAutomaticUpdatingWhileRoaming;
       
   326     
       
   327     TUint32 autoUpdatingAP( 0 );
       
   328 #ifndef __WINSCW__
       
   329     if (aValues.iAutomaticUpdatingAP != KWmlNoDefaultAccessPoint)
       
   330         {
       
   331         autoUpdatingAP = Util::IapIdFromWapIdL( iApiProvider, aValues.iAutomaticUpdatingAP );
       
   332         }
       
   333 #endif //__WINSCW__
       
   334 	setting.iAutoUpdateAP = autoUpdatingAP;
       
   335 
       
   336     SetFeedsServerSettingsL( setting );
       
   337     }
       
   338 
       
   339 // -----------------------------------------------------------------------------
       
   340 // CFeedsClientUtilities::DisconnectManualUpdateConnectionL()
       
   341 //
       
   342 // Disconnect connection provided by client for manual update.
       
   343 // -----------------------------------------------------------------------------
       
   344 //
       
   345 void CFeedsClientUtilities::DisconnectManualUpdateConnectionL()
       
   346     {
       
   347     if ( iIsConnected )
       
   348         {
       
   349         // Ensure that the connection is available.
       
   350         ConnectToServerL(EFalse);
       
   351 
       
   352         // Pass the updated settings to the server.
       
   353         iFeedsInterface.DisconnectManualUpdateConnectionL();
       
   354         }
       
   355     }
       
   356 
       
   357 // -----------------------------------------------------------------------------
       
   358 // CFeedsClientUtilities::DisconnectFeedsViewL()
       
   359 //
       
   360 // Disconnect connection used by FeedsView.
       
   361 // -----------------------------------------------------------------------------
       
   362 //
       
   363 void CFeedsClientUtilities::DisconnectFeedsViewL()
       
   364     {
       
   365     if( iFeedView )
       
   366         {
       
   367         iFeedView->DisconnectL();
       
   368         }
       
   369     }
       
   370 
       
   371 // -----------------------------------------------------------------------------
       
   372 // CFeedsClientUtilities::LoadUrlL()
       
   373 // -----------------------------------------------------------------------------
       
   374 //
       
   375 void CFeedsClientUtilities::LoadUrlL( const TDesC& aUrl )
       
   376     {
       
   377         
       
   378     if( iApiProvider.IsPageLoaded() &&
       
   379 		iApiProvider.Preferences().UiLocalFeatureSupported( KBrowserMultipleWindows ) &&
       
   380     	!iApiProvider.Preferences().UiLocalFeatureSupported( KBrowserMinimalMultipleWindows ))
       
   381 	    {	    
       
   382 	    // there is already a window, so create a new one if not over the max number of windows allowed
       
   383 	    if(iApiProvider.WindowMgr().WindowCount() == iApiProvider.WindowMgr().MaxWindowCount())
       
   384 	    	{
       
   385 	    	// Show warning to user
       
   386             TBrowserDialogs::ErrorNoteL( R_BROWSER_NOTE_MAX_WINDOWS );
       
   387 		  	return;
       
   388 	    	}
       
   389 
       
   390 	    if(iApiProvider.WindowMgr().WindowCount() < iApiProvider.WindowMgr().MaxWindowCount())
       
   391 	    	{
       
   392 		    CBrowserWindow *win = iApiProvider.WindowMgr().CreateWindowL( 0, &KNullDesC );
       
   393 		    if (win != NULL)
       
   394     		    {
       
   395     		    CleanupStack::PushL( win );
       
   396     		    iApiProvider.WindowMgr().SwitchWindowL( win->WindowId() );
       
   397     		    CleanupStack::Pop();  // win		        
       
   398     		    }
       
   399 	    	}
       
   400 	    }
       
   401 	
       
   402 	iApiProvider.WindowMgr().CurrentWindow()->SetHasFeedsContent(ETrue);
       
   403 	iApiProvider.FetchL( aUrl );
       
   404     }
       
   405 
       
   406 // -----------------------------------------------------------------------------
       
   407 // CFeedsClientUtilities::ShowFolderViewL
       
   408 //
       
   409 // Shows the folder view, loading the folder list from the FeedsServer if need be.
       
   410 // -----------------------------------------------------------------------------
       
   411 //
       
   412 void CFeedsClientUtilities::ShowFolderViewL(TUid aCalledFromView /*= KUidBrowserBookmarksViewId*/)
       
   413     {
       
   414     
       
   415     if ( iIsWaitDialogDisplayed )
       
   416         {
       
   417     	return;
       
   418         }
       
   419    	// Record the view from which feeds was launched.
       
   420    	// If this function is not called with an argument,
       
   421    	// its default value "KUidBrowserBookmarksViewId" is used.
       
   422    	// This is specified in the header FeedsClientUtilities.h 
       
   423    	SetCalledFromView(aCalledFromView);    	 
       
   424 
       
   425     // Ensure that "this" is ready for uses.
       
   426     LazyInitL(EFalse);
       
   427 
       
   428     // Show wait dialog.
       
   429     iWaitDialog->ShowWaitDialogL(R_FEEDS_OPENING_FEED);
       
   430     iIsWaitDialogDisplayed = ETrue;
       
   431     
       
   432     // Set the view to show once the folder is ready.
       
   433     iNextViewId = KUidBrowserFeedsFolderViewId;
       
   434     iIsUpdatingFeed = EFalse;   
       
   435 
       
   436     // Get the root folder.
       
   437     FetchRootFolderL();
       
   438     iCurrentRequest = CTransaction::EFetchRootFolderItem;
       
   439     }
       
   440 
       
   441 
       
   442 // -----------------------------------------------------------------------------
       
   443 // CFeedsClientUtilities::ShowTopicViewL
       
   444 //
       
   445 // Shows the topic view, loading the given feed associated with the given folder item.
       
   446 // -----------------------------------------------------------------------------
       
   447 //
       
   448 void CFeedsClientUtilities::ShowTopicViewL(const CFeedsEntity& aFolderItem)
       
   449     {
       
   450     TTime timestamp;
       
   451     
       
   452     if ( iIsWaitDialogDisplayed )
       
   453         {
       
   454     	return;
       
   455         }    
       
   456         
       
   457     // Ensure that "this" is ready for uses.
       
   458     LazyInitL(EFalse);
       
   459 
       
   460     // Show wait dialog.
       
   461     timestamp = aFolderItem.GetTimeValue(EFeedAttributeTimestamp,timestamp);
       
   462     if ( timestamp.Int64() == 0 )
       
   463         {
       
   464     	if ( iApiProvider.Connection().Connected() )
       
   465         	{
       
   466     		iWaitDialog->ShowWaitDialogL(R_FEEDS_UPDATING_FEED);
       
   467         	}
       
   468         }
       
   469     else
       
   470         {
       
   471     	iWaitDialog->ShowWaitDialogL(R_FEEDS_OPENING_FEED);
       
   472         }
       
   473     iIsWaitDialogDisplayed = ETrue;   
       
   474     
       
   475     // Set the view to show once the feed is ready.
       
   476     iNextViewId = KUidBrowserFeedsTopicViewId;
       
   477     iIsUpdatingFeed = EFalse;
       
   478     
       
   479     // Fetch the feed.
       
   480     FetchFeedL(aFolderItem);
       
   481     iCurrentRequest = CTransaction::EFetchFeed;
       
   482     }
       
   483 
       
   484 // -----------------------------------------------------------------------------
       
   485 // CFeedsClientUtilities::SupportedMimeTypesL
       
   486 //
       
   487 // Returns the feed related mime-types supported by the bridge.  This makes 
       
   488 // for a clean way to pass downloaded feeds content from the client to the FeedsServer 
       
   489 // (via CFeedsClientUtilities::HandleFeedL).
       
   490 // -----------------------------------------------------------------------------
       
   491 //
       
   492 TPtrC CFeedsClientUtilities::SupportedMimeTypesL()
       
   493     {
       
   494     return iMimeTypes->Des();
       
   495     }
       
   496 
       
   497 
       
   498 // -----------------------------------------------------------------------------
       
   499 // CFeedsClientUtilities::SubscribeToL
       
   500 //
       
   501 // Shows the folder view and subscribes to the given feed.
       
   502 // -----------------------------------------------------------------------------
       
   503 //
       
   504 void CFeedsClientUtilities::SubscribeToL(const TDesC& aTitle, const TDesC& aUrl)
       
   505     {  
       
   506    	SetCalledFromView(KUidBrowserContentViewId); 
       
   507 
       
   508     // If the root folder is available then Add the feed.
       
   509     if (iFeedsInterface.RootFolder() != NULL)
       
   510         {        
       
   511         // Ensure that "this" is ready for uses.  
       
   512         LazyInitL( EFalse );
       
   513 		CFeedsMap* temp = CFeedsMap::NewL();
       
   514 		temp->SetStringAttribute(EFeedAttributeTitle,aTitle);
       
   515         temp->SetStringAttribute(EFeedAttributeLink,aUrl);
       
   516         temp->SetIntegerAttribute(EFeedAttributeAutoUpdateFreq,0);
       
   517         
       
   518         // Set the next view to show after the new add folder item is added.
       
   519         iNextViewId = KUidBrowserFeedsFolderViewId; 
       
   520         
       
   521         iFeedsInterface.AddL(EFeed,*temp, *(iFeedsInterface.RootFolder()));
       
   522 
       
   523 		delete temp;
       
   524         // Ensure the Folder View shows the root-folder when AddFolderItemL completes.
       
   525         iFolderView->SetCurrentFolder(*(iFeedsInterface.RootFolder()), ETrue);
       
   526         }
       
   527         
       
   528     // Otherwise queue the folder item until the root folder is fetched (see above).
       
   529     else
       
   530         {
       
   531         // Ensure that "this" is ready for uses.  ETrue is passed to ensure that
       
   532         // the root folder will be fetched if it isn't already available.
       
   533         LazyInitL( ETrue );
       
   534 
       
   535         delete iPendingFolderItemTitle;
       
   536         iPendingFolderItemTitle = NULL;
       
   537         delete iPendingFolderItemUrl;
       
   538         iPendingFolderItemUrl = NULL;
       
   539         
       
   540         iPendingFolderItemTitle = aTitle.AllocL();
       
   541         TRAPD(err, iPendingFolderItemUrl = aUrl.AllocL());
       
   542         if (err != KErrNone)
       
   543             {
       
   544             delete iPendingFolderItemTitle;
       
   545             iPendingFolderItemTitle = NULL;
       
   546             
       
   547             User::Leave(err);
       
   548             }
       
   549         }
       
   550     }
       
   551 
       
   552 
       
   553 
       
   554 
       
   555 // -----------------------------------------------------------------------------
       
   556 // CFeedsClientUtilities::FeedsServerSettings
       
   557 //
       
   558 // Returns Feeds Server related settings.
       
   559 // -----------------------------------------------------------------------------
       
   560 //
       
   561 TInt CFeedsClientUtilities::FeedsServerSettingsL(TFeedsServerSetting& aSetting)
       
   562     {
       
   563     // Ensure that the connection is available.
       
   564     ConnectToServerL(EFalse);
       
   565 
       
   566     return iFeedsInterface.GetSettingsL(aSetting);
       
   567     }
       
   568     
       
   569 
       
   570 // -----------------------------------------------------------------------------
       
   571 // CFeedsClientUtilities::SetFeedsServerSettings
       
   572 //
       
   573 // Sets Feeds Server related settings.
       
   574 // -----------------------------------------------------------------------------
       
   575 //
       
   576 void CFeedsClientUtilities::SetFeedsServerSettingsL(const TFeedsServerSetting& aNewSetting)
       
   577     {
       
   578     // Ensure that the connection is available.
       
   579     ConnectToServerL(EFalse);
       
   580 
       
   581     // Pass the updated settings to the server.
       
   582     iFeedsInterface.SetSettingsL(aNewSetting);
       
   583     }
       
   584     
       
   585 
       
   586 // -----------------------------------------------------------------------------
       
   587 // CFeedsClientUtilities::SetBrowserControlSettingL
       
   588 //
       
   589 // Sets a Browser Control related settings.  These settings are directly passed to all 
       
   590 // Browser Control instances used by the CFeedsViewBridge.  As such see the Browser
       
   591 // Control documentation for infomation about the settings.
       
   592 // -----------------------------------------------------------------------------
       
   593 //
       
   594 void CFeedsClientUtilities::SetBrowserControlSettingL(TUint aSetting, TUint aValue)
       
   595     {
       
   596     // Pass the setting to the Feed View's Browser Control.
       
   597     iApiProvider.BrCtlInterface().SetBrowserSettingL(aSetting, aValue);
       
   598     }
       
   599 
       
   600 // -----------------------------------------------------------------------------
       
   601 // CFeedsClientUtilities::FolderItemRequestCompleted
       
   602 //
       
   603 // Called by RequestHandlerCompleted when the root FolderItem is either ready 
       
   604 // or an error occured.
       
   605 // -----------------------------------------------------------------------------
       
   606 //
       
   607 void CFeedsClientUtilities::FolderItemRequestCompleted(TInt aStatus, CTransaction::TTransactionType aTransType/*=ENone*/)
       
   608     {
       
   609 	TRAP_IGNORE( FolderItemRequestCompletedL(aStatus, aTransType) );
       
   610     }
       
   611 
       
   612 // -----------------------------------------------------------------------------
       
   613 // CFeedsClientUtilities::FolderItemRequestCompletedL
       
   614 //
       
   615 // Called by FolderItemRequestCompleted.
       
   616 // -----------------------------------------------------------------------------
       
   617 //
       
   618 void CFeedsClientUtilities::FolderItemRequestCompletedL(TInt aStatus, CTransaction::TTransactionType aTransType/*=ENone*/)
       
   619     {
       
   620     if (aTransType == iCanceledRequest)
       
   621         {
       
   622         iCanceledRequest = CTransaction::ENone;
       
   623         return;
       
   624         }
       
   625     // Close the wait dialog.
       
   626     if (iWaitDialog)
       
   627         {
       
   628         iWaitDialog->Close();
       
   629         }
       
   630     iIsWaitDialogDisplayed = EFalse;
       
   631     	
       
   632     // Show the view if everything went ok.
       
   633     if (aStatus == KErrNone)
       
   634         {
       
   635         switch(aTransType)
       
   636         	{
       
   637         	case CTransaction::EExportOPML:
       
   638 	        	//launch send ui
       
   639 	        	SendOPMLFileL();
       
   640 				break;
       
   641 
       
   642        		case CTransaction::EImportOPML:
       
   643 				// Delete temp file here if it exists
       
   644 				if(iTempOPMLImportFilePath.Length() > 0)
       
   645 					{
       
   646 					RFs tempRFs;
       
   647 					if (tempRFs.Connect() != KErrNone)
       
   648 						{
       
   649 						break;
       
   650 						}
       
   651 					CleanupClosePushL(tempRFs);
       
   652 					tempRFs.Delete( iTempOPMLImportFilePath );
       
   653 					tempRFs.Close();
       
   654 					CleanupStack::PopAndDestroy(); // cleanup tempRFs and reset temp file import path
       
   655 					iTempOPMLImportFilePath = _L("");
       
   656 					}
       
   657 									
       
   658 		        // Again show folder view to trigger a redraw
       
   659 				ShowFolderViewL();	
       
   660 				break;
       
   661 
       
   662         	default:
       
   663         		// if an import OPML was requested, do that now
       
   664         	    if(iFeedImportRequested)
       
   665         			{
       
   666         			// clear flag
       
   667         			iFeedImportRequested = EFalse;
       
   668 
       
   669         			// show wait dialog
       
   670 					iWaitDialog->ShowWaitDialogL(R_FEEDS_WAIT_IMPORTING_FEEDS);
       
   671 				    iIsWaitDialogDisplayed = ETrue;
       
   672 					
       
   673         	
       
   674 					if(iTempOPMLImportFilePath.Length())
       
   675 						{
       
   676 						iFeedsInterface.ImportOPMLL( iTempOPMLImportFilePath );
       
   677 						}
       
   678             iCurrentRequest = CTransaction::EImportOPML;
       
   679         			}       	
       
   680         	
       
   681 		        // Set the updated folder
       
   682 		        iFolderView->RootFolderChangedL(*(iFeedsInterface.RootFolder()));
       
   683 		        
       
   684 		        // Show it.
       
   685 		        if (iNextViewId == KUidBrowserFeedsFolderViewId)
       
   686 		            {            
       
   687 		            ShowFolderViewLocalL();
       
   688 		            }
       
   689 		        
       
   690 		        // If the user tried to subscribe to a feed before it was connected
       
   691 		        // to the server then add the item now.
       
   692 		        if (iPendingFolderItemTitle != NULL)
       
   693 		            {
       
   694 		            TRAPD(err, SubscribeToL(*iPendingFolderItemTitle, *iPendingFolderItemUrl));
       
   695 		            if (err == KErrNone)
       
   696 		                {
       
   697 		                delete iPendingFolderItemTitle;
       
   698 		                iPendingFolderItemTitle = NULL;
       
   699 		                delete iPendingFolderItemUrl;
       
   700 		                iPendingFolderItemUrl = NULL;                
       
   701 		                }
       
   702 		            // Don't reset next-view; iNextViewId is EFolderViewId after above SubscribeToL() call
       
   703 		                
       
   704 		            // Otherwise try to add the folder item next time.
       
   705 		            }
       
   706 		        else if(iNextViewId == KUidBrowserFeedsFolderViewId)
       
   707 		            {
       
   708 		            // Reset next-view.
       
   709 		            iNextViewId = KUidBrowserNullViewId;
       
   710 		            }
       
   711 
       
   712 		        // Reset the "last updated" cache now that a new folder list is available.
       
   713 		        ResetFeedUpdateTime();        
       
   714         	}
       
   715         }
       
   716     // Otherwise show an error.
       
   717     else
       
   718         {
       
   719         // If the server terminated, reconnect to it.
       
   720         if (aStatus == KErrServerTerminated)
       
   721             {
       
   722             DisconnectFromServer();
       
   723             ConnectToServerL();
       
   724            
       
   725             }
       
   726         
       
   727         ShowServerError(aStatus, aTransType);
       
   728         
       
   729         // This happens when user subscribe to a feed from content view
       
   730         // If it failed, we want to show the content view.
       
   731         if (aStatus == KErrAlreadyExists)
       
   732             {
       
   733             // Set content view as the last view id.
       
   734             iApiProvider.SetLastActiveViewId( KUidBrowserContentViewId );
       
   735     
       
   736             // Show the view.
       
   737             // We already started switching to the feeds folder view and shut off full screen
       
   738             // This will force the DoActivate on the ContentView and set back to full screen
       
   739             iApiProvider.SetViewToBeActivatedIfNeededL( KUidBrowserFeedsFolderViewId );
       
   740             iApiProvider.SetViewToBeActivatedIfNeededL( KUidBrowserContentViewId );
       
   741             }
       
   742 
       
   743         // Reset next-view.
       
   744         iNextViewId = KUidBrowserNullViewId;
       
   745         }        
       
   746     }
       
   747 
       
   748 // -----------------------------------------------------------------------------
       
   749 // CFeedsClientUtilities::FeedRequestCompleted
       
   750 //
       
   751 // Called when the asynchronous request is complete.
       
   752 // -----------------------------------------------------------------------------
       
   753 //
       
   754 void CFeedsClientUtilities::FeedRequestCompleted(TInt aEvent)
       
   755     {
       
   756     TRAP_IGNORE( FeedRequestCompletedL(aEvent) );
       
   757     }
       
   758     
       
   759 // -----------------------------------------------------------------------------
       
   760 // CFeedsClientUtilities::FeedRequestCompletedL
       
   761 //
       
   762 // Called when the asynchronous request is complete.
       
   763 // -----------------------------------------------------------------------------
       
   764 //
       
   765 void CFeedsClientUtilities::FeedRequestCompletedL(TInt aStatus)
       
   766     {
       
   767     if (CTransaction::EFetchFeed == iCanceledRequest)
       
   768         {
       
   769         iCanceledRequest = CTransaction::ENone;
       
   770         return;
       
   771         }    
       
   772     // Close the wait dialog.
       
   773     iWaitDialog->Close();
       
   774     iIsWaitDialogDisplayed = EFalse;
       
   775 
       
   776     // Show the view if everything went ok.
       
   777     if (aStatus == KErrNone)
       
   778         {
       
   779         // Extract out the intial item status -- later on, iItemStatusOrig is 
       
   780         // used to determine which item status' change.
       
   781         RArray<TInt>  ignore(20);
       
   782         
       
   783         iItemIds.Reset();
       
   784         iItemStatus.Reset();
       
   785         iItemStatusOrig.Reset();
       
   786         
       
   787         CleanupClosePushL(ignore);
       
   788         ItemStatusL(iItemIds, iItemStatus, *(iFeedsInterface.Feed()));
       
   789         ItemStatusL(ignore, iItemStatusOrig, *(iFeedsInterface.Feed()));
       
   790         CleanupStack::PopAndDestroy(/*ignore*/);
       
   791         
       
   792         // update folder view for unread count
       
   793         TInt unreadCount = 0;
       
   794         for (TInt i = 0; i < iItemStatus.Count(); i++)
       
   795             {
       
   796             if ( iItemStatus[i] == EItemStatusUnread || iItemStatus[i] == EItemStatusNew )
       
   797                 {
       
   798                 unreadCount++;
       
   799                 }
       
   800             }
       
   801         iFolderView->SetUnreadCountL( unreadCount );               
       
   802 
       
   803         // The method was called because of a updated feed.  In general, update
       
   804         // the current view to reflect the updated feed.
       
   805         if (iIsUpdatingFeed)
       
   806             {
       
   807             if (iApiProvider.LastActiveViewId() == KUidBrowserFeedsTopicViewId)
       
   808             	{
       
   809 				iTopicView->SetCurrentFeedL(*(CurrentFeed()), 0);            	
       
   810                 }
       
   811             }
       
   812         
       
   813         // Otherwise, this is a newly requested feed, so show the next
       
   814         // view now that it is available.
       
   815         else
       
   816             {            
       
   817             if (iNextViewId == KUidBrowserFeedsFeedViewId)
       
   818                 {
       
   819                 ShowFeedViewLocalL(0);
       
   820                 }
       
   821             else if (iNextViewId == KUidBrowserFeedsTopicViewId)
       
   822             	{
       
   823             	ShowTopicViewLocalL(0);
       
   824                 }
       
   825             }
       
   826             
       
   827         // Update the feed's "last updated" value in the cache.
       
   828         UpdateFeedUpdatedTimeL(*(iFeedsInterface.Feed()));
       
   829         }
       
   830     
       
   831     // Otherwise show an error.
       
   832     else
       
   833         {
       
   834         // If the server terminated, reconnect to it.
       
   835         if (aStatus == KErrServerTerminated)
       
   836             {
       
   837             DisconnectFromServer();
       
   838             ConnectToServerL();
       
   839             
       
   840             }
       
   841             
       
   842         ShowServerError(aStatus);
       
   843         }
       
   844 
       
   845     // Reset updating feed.
       
   846     iIsUpdatingFeed = EFalse;
       
   847 
       
   848     // Reset next-view.
       
   849     iNextViewId = KUidBrowserNullViewId;
       
   850     }
       
   851 
       
   852 
       
   853 // -----------------------------------------------------------------------------
       
   854 // CFeedsClientUtilities::DialogDismissedL
       
   855 //
       
   856 // Called when the user presses the cancel button.
       
   857 // -----------------------------------------------------------------------------
       
   858 //
       
   859 void CFeedsClientUtilities::DialogDismissedL()
       
   860     {
       
   861     // Cancel all activities that can be cancelled.
       
   862     iIsWaitDialogDisplayed = EFalse;
       
   863 
       
   864     
       
   865     // If there is an ongoing search by the search agent, make sure
       
   866     // it's cancelled and search agent destroyed  
       
   867     if(iSearchAgent != NULL)
       
   868         {
       
   869         iSearchAgent->CancelSearch();
       
   870         delete(iSearchAgent);
       
   871         iSearchAgent = NULL;
       
   872         }
       
   873     else
       
   874         {
       
   875         iCanceledRequest = iCurrentRequest;
       
   876         iFeedsInterface.CancelAllL();
       
   877         }    
       
   878     }
       
   879 
       
   880 
       
   881 // -----------------------------------------------------------------------------
       
   882 // CFeedsClientUtilities::FetchRootFolderL
       
   883 //
       
   884 // Get the root folder from the Feeds server.
       
   885 // -----------------------------------------------------------------------------
       
   886 //
       
   887 void CFeedsClientUtilities::FetchRootFolderL()
       
   888     {
       
   889     iFeedsInterface.GetRootFolderL();
       
   890     }
       
   891 
       
   892 // -----------------------------------------------------------------------------
       
   893 // CFeedsClientUtilities::AddFolderItemL
       
   894 //
       
   895 // Add a new folder item.
       
   896 // -----------------------------------------------------------------------------
       
   897 //
       
   898 void CFeedsClientUtilities::AddFolderItemL(const TDesC& aTitle, const TDesC& aUrl,
       
   899         TBool aIsFolder, const CFeedsEntity& aParent, TInt aFreq)
       
   900     {
       
   901     
       
   902 		CFeedsMap* temp = CFeedsMap::NewL();
       
   903 		
       
   904 		temp->SetStringAttribute(EFeedAttributeTitle,aTitle);
       
   905 		temp->SetStringAttribute(EFeedAttributeLink,aUrl);	
       
   906         temp->SetIntegerAttribute(EFeedAttributeAutoUpdateFreq,aFreq);
       
   907 
       
   908         // Set the next view to show after the new add folder item is added.
       
   909         iNextViewId = KUidBrowserFeedsFolderViewId;
       
   910     	
       
   911         iFeedsInterface.AddL(aIsFolder?EFolder:EFeed,*temp, aParent);
       
   912 
       
   913 		delete temp;
       
   914     }
       
   915 
       
   916 
       
   917 // -----------------------------------------------------------------------------
       
   918 // CFeedsClientUtilities::ChangeFolderItemL
       
   919 //
       
   920 // Change the folder item.  If this is a folder then KNullDesC should be passed 
       
   921 // to the aUrl argument.
       
   922 // -----------------------------------------------------------------------------
       
   923 //
       
   924 void CFeedsClientUtilities::ChangeFolderItemL(CFeedsEntity& aFolderItem, 
       
   925                 const TDesC& aTitle, const TDesC& aUrl,TInt aFreq)
       
   926     {
       
   927 	CFeedsMap* temp = CFeedsMap::NewL();
       
   928 	temp->SetStringAttribute(EFeedAttributeTitle,aTitle);
       
   929     temp->SetStringAttribute(EFeedAttributeLink,aUrl);
       
   930     temp->SetIntegerAttribute(EFeedAttributeAutoUpdateFreq,aFreq);
       
   931     // Set the next view to show after the new add folder item is added.
       
   932     iNextViewId = KUidBrowserFeedsFolderViewId;
       
   933     	
       
   934     aFolderItem.ChangeValueL(*temp);
       
   935     delete temp;
       
   936     }
       
   937 
       
   938 
       
   939 // -----------------------------------------------------------------------------
       
   940 // CFeedsClientUtilities::DeleteFolderItemsL
       
   941 //
       
   942 // Delete the folder items. 
       
   943 // -----------------------------------------------------------------------------
       
   944 //
       
   945 void CFeedsClientUtilities::DeleteFolderItemsL(RPointerArray<const CFeedsEntity>& aFolderItems)
       
   946     {
       
   947     iFeedsInterface.DeleteL(aFolderItems);
       
   948     }
       
   949 
       
   950 
       
   951 // -----------------------------------------------------------------------------
       
   952 // CFeedsClientUtilities::MoveFolderItemsToL
       
   953 //
       
   954 // Move the folder items to a different parent. 
       
   955 // -----------------------------------------------------------------------------
       
   956 //
       
   957 void CFeedsClientUtilities::MoveFolderItemsToL(RPointerArray<const CFeedsEntity>& aFolderItems,
       
   958         const CFeedsEntity& aParent)
       
   959     {
       
   960     iFeedsInterface.MoveToFolderL(aFolderItems, aParent);
       
   961     }
       
   962 
       
   963 
       
   964 // -----------------------------------------------------------------------------
       
   965 // CFeedsClientUtilities::MoveFolderItemsL
       
   966 //
       
   967 // Move the folder item to a different index. 
       
   968 // -----------------------------------------------------------------------------
       
   969 //
       
   970 void CFeedsClientUtilities::MoveFolderItemsL(RPointerArray<const CFeedsEntity>& aFolderItems,
       
   971         TInt aIndex)
       
   972     {
       
   973     iFeedsInterface.MoveL(aFolderItems, aIndex);
       
   974     }
       
   975 
       
   976 
       
   977 // -----------------------------------------------------------------------------
       
   978 // CFeedsClientUtilities::FetchFeedL
       
   979 //
       
   980 // Get the given feed from the Feeds server.
       
   981 // -----------------------------------------------------------------------------
       
   982 //
       
   983 void CFeedsClientUtilities::FetchFeedL(const CFeedsEntity& aFeedEntity, TBool aForceUpdate, 
       
   984         TBool aNoCache)
       
   985     {
       
   986     // Fetch the new feed.
       
   987     iFeedsInterface.FetchL(aFeedEntity, aForceUpdate, aNoCache);
       
   988     }
       
   989 
       
   990 
       
   991 // -----------------------------------------------------------------------------
       
   992 // CFeedsClientUtilities::UpdateFeedL
       
   993 //
       
   994 // Updates the feed with the given id.
       
   995 // -----------------------------------------------------------------------------
       
   996 //
       
   997 void CFeedsClientUtilities::UpdateFeedL(const CFeedsEntity& aFeedEntity)
       
   998     {
       
   999     if(iIsWaitDialogDisplayed)
       
  1000     {
       
  1001     	return;
       
  1002     }
       
  1003     // Show wait dialog iff connection is already established.
       
  1004     if(iApiProvider.Connection().Connected())
       
  1005     {
       
  1006         iWaitDialog->ShowWaitDialogL(R_FEEDS_UPDATING_FEED);
       
  1007         iIsWaitDialogDisplayed = ETrue;
       
  1008     }    
       
  1009     
       
  1010     iIsUpdatingFeed = ETrue;
       
  1011 
       
  1012     // Fetch the feed.
       
  1013     FetchFeedL(aFeedEntity, ETrue);
       
  1014     iCurrentRequest = CTransaction::EFetchFeed;
       
  1015     }
       
  1016 
       
  1017 
       
  1018 // -----------------------------------------------------------------------------
       
  1019 // CFeedsClientUtilities::UpdateFolderItemsL
       
  1020 //
       
  1021 // Updates the given feeds in the background.
       
  1022 // -----------------------------------------------------------------------------
       
  1023 //
       
  1024 void CFeedsClientUtilities::UpdateFolderItemsL(const RPointerArray<const CFeedsEntity>& 
       
  1025         aFolderItems)
       
  1026     {
       
  1027     if (iIsWaitDialogDisplayed)
       
  1028         {
       
  1029     	return;
       
  1030         }    
       
  1031     // Show wait dialog iff connection is already established.
       
  1032     if (iApiProvider.Connection().Connected())
       
  1033         {
       
  1034         iWaitDialog->ShowWaitDialogL(R_FEEDS_UPDATING_FEED);
       
  1035         iIsWaitDialogDisplayed = ETrue;
       
  1036         }    
       
  1037 
       
  1038     // Fetch the feeds.
       
  1039     iFeedsInterface.UpdateL(aFolderItems);
       
  1040     iCurrentRequest = CTransaction::EUpdateFolderItem;
       
  1041     }
       
  1042 
       
  1043 
       
  1044 // -----------------------------------------------------------------------------
       
  1045 // CFeedsClientUtilities::UpdateFolderItemsL
       
  1046 //
       
  1047 // Updates all of feeds in the background.
       
  1048 // -----------------------------------------------------------------------------
       
  1049 //
       
  1050 void CFeedsClientUtilities::UpdateFolderItemsL()
       
  1051     {
       
  1052     if (iIsWaitDialogDisplayed)
       
  1053         {
       
  1054     	return;
       
  1055         } 
       
  1056        
       
  1057     // Show wait dialog iff connection is already established.
       
  1058     if (iApiProvider.Connection().Connected())
       
  1059         {
       
  1060         iWaitDialog->ShowWaitDialogL(R_FEEDS_UPDATING_ALL_WAIT_DIALOG);
       
  1061         iIsWaitDialogDisplayed = ETrue;
       
  1062         }    
       
  1063 
       
  1064     // Fetch the feeds.
       
  1065     RPointerArray<const CFeedsEntity> aFolderItem;
       
  1066     aFolderItem.Append((iFeedsInterface.RootFolder()));
       
  1067     
       
  1068     iFeedsInterface.UpdateL(aFolderItem);
       
  1069     iCurrentRequest = CTransaction::EUpdateFolderItem;
       
  1070     }
       
  1071 
       
  1072 // -----------------------------------------------------------------------------
       
  1073 // CFeedsClientUtilities::ImportFeeds
       
  1074 //
       
  1075 // Import feeds from OPML file
       
  1076 // -----------------------------------------------------------------------------
       
  1077 //
       
  1078 
       
  1079 void CFeedsClientUtilities::ImportFeedsL()
       
  1080 	{
       
  1081     if (iIsWaitDialogDisplayed)
       
  1082         {
       
  1083     	return;
       
  1084         }    
       
  1085 	
       
  1086 	// construct search agent
       
  1087 	if(NULL != iSearchAgent)
       
  1088 		{
       
  1089 		delete(iSearchAgent);
       
  1090 		iSearchAgent = NULL;
       
  1091 		}
       
  1092 	iSearchAgent = CFeedsFileSearchAgent::NewL(*this);
       
  1093 
       
  1094     iWaitDialog->ShowWaitDialogL(R_FEEDS_WAIT_SEARCHING_FOR_FEEDS);
       
  1095     iIsWaitDialogDisplayed = ETrue;
       
  1096 
       
  1097 	// Start search
       
  1098 	if(NULL != iSearchAgent)
       
  1099 		{
       
  1100 		iSearchAgent->StartSearchingL();
       
  1101 		}
       
  1102 	}
       
  1103 
       
  1104 // -----------------------------------------------------------------------------
       
  1105 // CFeedsClientUtilities::FeedsFileSearchCompleteL
       
  1106 //
       
  1107 // Implemented from the MFeedsFileSearchAgentCallback mixin, this
       
  1108 // callback is called when the search for files in the filesystem has completed
       
  1109 // -----------------------------------------------------------------------------
       
  1110 //
       
  1111 
       
  1112 void CFeedsClientUtilities::FeedsFileSearchCompleteL(TInt aCount)
       
  1113 	{
       
  1114 	TFileEntry * fileEntry;
       
  1115 	TInt i;
       
  1116 
       
  1117 	iWaitDialog->Close();
       
  1118 	iIsWaitDialogDisplayed = EFalse;
       
  1119 	
       
  1120 	// If nothing is found, indicate that, cleanup and quit
       
  1121 	if(aCount == 0)
       
  1122 		{
       
  1123 	    HBufC* note = StringLoader::LoadLC(R_FEEDS_NO_FEEDS_FOUND_ON_DEVICE);
       
  1124         iApiProvider.DialogsProvider().DialogAlertL(_L(""),*note);       
       
  1125         CleanupStack::PopAndDestroy( note );
       
  1126 		}
       
  1127 	else
       
  1128 		{
       
  1129 		//
       
  1130 		// construct results dialog box to show search results
       
  1131 		//
       
  1132 		if(NULL != iSearchOptList)
       
  1133 			{
       
  1134 			delete(iSearchOptList);
       
  1135 			iSearchOptList = NULL;
       
  1136 			}
       
  1137 		
       
  1138 		iSearchOptList = new( ELeave ) CArrayFixFlat<TBrCtlSelectOptionData>(aCount);
       
  1139                 
       
  1140 	    HBufC* title = StringLoader::LoadLC(R_FEEDS_POPUP_TITLE_FEEDS_FILES_FOUND);	    
       
  1141 
       
  1142 		// loop through the search results
       
  1143         for(i = 0; i < aCount; i++)
       
  1144 	        {
       
  1145 	        if(iSearchAgent)
       
  1146 	        	{
       
  1147 					// grab file found from the search agent results and add it 
       
  1148 					// as an option
       
  1149 	        		fileEntry = iSearchAgent->GetFileEntry(i);
       
  1150 	        		if(NULL != fileEntry)
       
  1151 	        			{ 
       
  1152 			            TBrCtlSelectOptionData t(fileEntry->iEntry.iName, EFalse, EFalse, EFalse);
       
  1153         		    	iSearchOptList->AppendL(t);
       
  1154     	       			}
       
  1155 	        	}
       
  1156 	        }
       
  1157 	    
       
  1158         TBool ret(iApiProvider.DialogsProvider().DialogSelectOptionL( *title,
       
  1159         	ESelectTypeNone, *iSearchOptList));
       
  1160         	
       
  1161 		CleanupStack::PopAndDestroy(title);
       
  1162 		
       
  1163 		//
       
  1164 		// If the user selects an option, import it
       
  1165 		//		
       
  1166     	if ( ret )
       
  1167         	{
       
  1168        		for( i = 0; i < aCount; i++)
       
  1169             	{
       
  1170             	if( (*iSearchOptList)[i].IsSelected() )
       
  1171                 	{
       
  1172 	                if(iSearchAgent)
       
  1173 			        	{
       
  1174 	        			fileEntry = iSearchAgent->GetFileEntry(i);
       
  1175 	        			if(NULL != fileEntry)
       
  1176 	        				{
       
  1177 	        				BeginImportOPMLFeedsFileL(fileEntry->iPath);
       
  1178 	        				}
       
  1179 			        	}
       
  1180 			        	break;
       
  1181                 	}
       
  1182             	}
       
  1183         	}
       
  1184 	
       
  1185 		}
       
  1186 
       
  1187 		// destroy the search agent
       
  1188 		delete(iSearchAgent);
       
  1189 		iSearchAgent = NULL;
       
  1190 	}
       
  1191 
       
  1192 // -----------------------------------------------------------------------------
       
  1193 // CFeedsClientUtilities::BeginImportOPMLFeedsFileL
       
  1194 //
       
  1195 // Given a path, save it in the class, show the root folder view and set
       
  1196 // a flag to indicate we're importing. When the root folder is done opening,
       
  1197 // then begin the actual import
       
  1198 // -----------------------------------------------------------------------------
       
  1199 //
       
  1200 
       
  1201 void CFeedsClientUtilities::BeginImportOPMLFeedsFileL( TFileName& aFilepath )
       
  1202 	{
       
  1203 		// save path
       
  1204 		iTempOPMLImportFilePath = aFilepath;
       
  1205 
       
  1206 		// Switch to feeds view, setting the flag will import 
       
  1207 		// from the tempOPMLImportFilePath when the view is ready
       
  1208 		iFeedImportRequested = ETrue;		
       
  1209 		ShowFolderViewL();	
       
  1210 	
       
  1211 	}
       
  1212 
       
  1213 // -----------------------------------------------------------------------------
       
  1214 // CFeedsClientUtilities::ExportFeeds
       
  1215 //
       
  1216 // Export feeds to OPML file
       
  1217 // -----------------------------------------------------------------------------
       
  1218 //
       
  1219 
       
  1220 void CFeedsClientUtilities::ExportFeedsL(RPointerArray<const CFeedsEntity>& aFolderItems, const TDesC &aExportFileName)
       
  1221 	{
       
  1222     if (iIsWaitDialogDisplayed)
       
  1223         {
       
  1224     	return;
       
  1225         }    
       
  1226 
       
  1227 	iWaitDialog->ShowWaitDialogL(R_FEEDS_WAIT_PROCESSING);
       
  1228 	iIsWaitDialogDisplayed = ETrue;
       
  1229 	
       
  1230 	if (iExportFileName)
       
  1231 		{
       
  1232     	delete iExportFileName;
       
  1233     	iExportFileName = NULL;
       
  1234 		}
       
  1235 	
       
  1236 	iExportFileName = aExportFileName.AllocL();
       
  1237     iFeedsInterface.ExportFoldersL(aFolderItems, aExportFileName);
       
  1238     iCurrentRequest = CTransaction::EExportOPML;
       
  1239 	}
       
  1240 
       
  1241 // -----------------------------------------------------------------------------
       
  1242 // CFeedsClientUtilities::ShowFolderViewLocalL
       
  1243 //
       
  1244 // Shows the folder view.
       
  1245 // -----------------------------------------------------------------------------
       
  1246 //
       
  1247 void CFeedsClientUtilities::ShowFolderViewLocalL()
       
  1248     {
       
  1249     // Set this as the last view id -- this is used in ShowLastViewL.
       
  1250     iApiProvider.SetLastActiveViewId(KUidBrowserFeedsFolderViewId);
       
  1251     
       
  1252     // Show the view.
       
  1253     iApiProvider.SetViewToBeActivatedIfNeededL(KUidBrowserFeedsFolderViewId);    
       
  1254     }
       
  1255 
       
  1256 
       
  1257 // -----------------------------------------------------------------------------
       
  1258 // CFeedsClientUtilities::ShowTopicViewLocalL
       
  1259 //
       
  1260 // Shows the topic view.
       
  1261 // -----------------------------------------------------------------------------
       
  1262 //
       
  1263 void CFeedsClientUtilities::ShowTopicViewLocalL(TInt aInitialItem)
       
  1264     {
       
  1265     // Set this as the last view id -- this is used in ShowLastViewL.
       
  1266     iApiProvider.SetLastActiveViewId(KUidBrowserFeedsTopicViewId);
       
  1267     
       
  1268     // Set the inital item.
       
  1269     if (iTopicView == NULL)
       
  1270 		{
       
  1271 		TRect rect(iAppUI.ClientRect());
       
  1272 		iTopicView = CFeedsTopicView::NewL( iApiProvider, rect );
       
  1273 		iAppUI.AddViewL( iTopicView ); // transfer ownership to CAknViewAppUi
       
  1274 		}
       
  1275 
       
  1276     iTopicView->SetInitialItem(aInitialItem);
       
  1277 
       
  1278     // Show the view.
       
  1279     iApiProvider.SetViewToBeActivatedIfNeededL(KUidBrowserFeedsTopicViewId);    
       
  1280     }
       
  1281 
       
  1282 
       
  1283 // -----------------------------------------------------------------------------
       
  1284 // CFeedsClientUtilities::ShowFeedViewLocalL
       
  1285 //
       
  1286 // Shows the feed view.
       
  1287 // -----------------------------------------------------------------------------
       
  1288 //
       
  1289 void CFeedsClientUtilities::ShowFeedViewLocalL(TInt aInitialItem)
       
  1290     {
       
  1291     // Set this as the last view id -- this is used in ShowLastViewL.
       
  1292     iApiProvider.SetLastActiveViewId(KUidBrowserFeedsFeedViewId);
       
  1293     
       
  1294     // Set the inital item.
       
  1295     if (iFeedView == NULL)
       
  1296 		{
       
  1297 		TRect rect(iAppUI.ClientRect());
       
  1298 		iFeedView = CFeedsFeedView::NewL( iApiProvider, rect );
       
  1299 		iAppUI.AddViewL( iFeedView ); // transfer ownership to CAknViewAppUi
       
  1300 		}
       
  1301 
       
  1302     iFeedView->SetInitialItem(aInitialItem);
       
  1303 
       
  1304     // Show the view.
       
  1305     iApiProvider.SetViewToBeActivatedIfNeededL(KUidBrowserFeedsFeedViewId);    
       
  1306     }
       
  1307 
       
  1308 
       
  1309 // -----------------------------------------------------------------------------
       
  1310 // CFeedsClientUtilities::CurrentRootFolder
       
  1311 //
       
  1312 // Returns the current root folder.
       
  1313 // -----------------------------------------------------------------------------
       
  1314 //
       
  1315 const CFeedsEntity* CFeedsClientUtilities::CurrentRootFolder() 
       
  1316     {
       
  1317     return iFeedsInterface.RootFolder();
       
  1318     }
       
  1319 
       
  1320 
       
  1321 // -----------------------------------------------------------------------------
       
  1322 // CFeedsClientUtilities::CurrentFeed
       
  1323 //
       
  1324 // Returns the current feed.
       
  1325 // -----------------------------------------------------------------------------
       
  1326 //
       
  1327 CFeedsEntity* CFeedsClientUtilities::CurrentFeed() 
       
  1328     {
       
  1329     return iFeedsInterface.Feed();
       
  1330     }
       
  1331 
       
  1332 // -----------------------------------------------------------------------------
       
  1333 // CFeedsClientUtilities::AddItemL
       
  1334 //
       
  1335 // Add a menu item to the given menu.
       
  1336 // -----------------------------------------------------------------------------
       
  1337 //
       
  1338 void CFeedsClientUtilities::AddItemL(CEikMenuPane& aMenuPane, TInt aCommand, 
       
  1339         TInt aTitleId)
       
  1340     {
       
  1341     CEikMenuPaneItem::SData  item;
       
  1342     HBufC*                   buf = NULL;
       
  1343     
       
  1344     buf = StringLoader::LoadLC(aTitleId);    
       
  1345     item.iText.Copy(*buf);
       
  1346     CleanupStack::PopAndDestroy(buf);
       
  1347     buf = NULL;
       
  1348     
       
  1349     item.iCommandId = aCommand;
       
  1350     item.iFlags = 0;
       
  1351     item.iCascadeId = 0;
       
  1352     aMenuPane.AddMenuItemL(item);
       
  1353     }
       
  1354 
       
  1355 
       
  1356 // -----------------------------------------------------------------------------
       
  1357 // CFeedsClientUtilities::AddCascadeL
       
  1358 //
       
  1359 // Add a sub-menu to the given menu.
       
  1360 // -----------------------------------------------------------------------------
       
  1361 //
       
  1362 void CFeedsClientUtilities::AddCascadeL(CEikMenuPane& aMenuPane, TInt aCommand, 
       
  1363         TInt aTitleId, TInt aCascade)
       
  1364     {
       
  1365     CEikMenuPaneItem::SData  item;
       
  1366     HBufC*                   buf = NULL;
       
  1367     
       
  1368     buf = StringLoader::LoadLC(aTitleId);    
       
  1369     item.iText.Copy(*buf);
       
  1370     CleanupStack::PopAndDestroy(buf);
       
  1371     buf = NULL;
       
  1372     
       
  1373     item.iCommandId = aCommand;
       
  1374     item.iFlags = 0;
       
  1375     item.iCascadeId = aCascade;
       
  1376     aMenuPane.AddMenuItemL(item);
       
  1377     }
       
  1378 
       
  1379 
       
  1380 // -----------------------------------------------------------------------------
       
  1381 // CFeedsClientUtilities::SetItemStatus
       
  1382 //
       
  1383 // Sets the item's status (read/unread/new).
       
  1384 // -----------------------------------------------------------------------------
       
  1385 //
       
  1386 void CFeedsClientUtilities::SetItemStatusL(CFeedsEntity* aItem, TFeedItemStatus aStatus)
       
  1387     {
       
  1388     TInt	ret;
       
  1389 	CFeedsMap* temp = CFeedsMap::NewL();
       
  1390 	temp->SetIntegerAttribute(EItemAttributeStatus,aStatus);
       
  1391     ret = aItem->ChangeValueL(*temp);
       
  1392 	delete temp;
       
  1393 
       
  1394     if (ret != KErrNone)
       
  1395         {
       
  1396         ShowServerError(ret);
       
  1397         }
       
  1398     }
       
  1399 
       
  1400 
       
  1401 // -----------------------------------------------------------------------------
       
  1402 // CFeedsClientUtilities::ItemStatus
       
  1403 //
       
  1404 // Returns the item's status (read/unread/new).
       
  1405 // -----------------------------------------------------------------------------
       
  1406 //
       
  1407 TFeedItemStatus CFeedsClientUtilities::ItemStatus(TInt aItemId)
       
  1408     {
       
  1409     TInt         pos;
       
  1410     TFeedItemStatus  status = EItemStatusUndefined;
       
  1411     
       
  1412     if ((pos = iItemIds.Find(aItemId)) != KErrNotFound)
       
  1413         {        
       
  1414         status = iItemStatus[pos];
       
  1415         }
       
  1416     else
       
  1417         {
       
  1418         // TODO: panic
       
  1419         }
       
  1420         
       
  1421     return status;
       
  1422     }
       
  1423 
       
  1424 
       
  1425 // -----------------------------------------------------------------------------
       
  1426 // CFeedsClientUtilities::ItemStatusWriteToServerL
       
  1427 //
       
  1428 // Writes the item status out to the server.
       
  1429 // -----------------------------------------------------------------------------
       
  1430 //
       
  1431 void CFeedsClientUtilities::ItemStatusWriteToServerL()
       
  1432     {
       
  1433     RArray<TInt>         ids(20);
       
  1434     RArray<TFeedItemStatus>  status(20);
       
  1435     TInt     unreadCountDelta = 0;
       
  1436     TInt     unreadCount = 0;
       
  1437     
       
  1438     if (iItemStatus.Count() == 0)
       
  1439         {
       
  1440         return;
       
  1441         }
       
  1442         
       
  1443     CleanupClosePushL(ids);
       
  1444     CleanupClosePushL(status);
       
  1445     
       
  1446     // Build new status arrays that only contains items that changed.
       
  1447     for (TInt i = 0; i < iItemStatus.Count(); i++)
       
  1448         {
       
  1449         if (iItemStatus[i] != iItemStatusOrig[i])
       
  1450             {
       
  1451             // update orig, since the old orig doesn't hold true any more
       
  1452             // important to do so: 
       
  1453             // because this method will be called whenever deactivateView of FeedsView is called
       
  1454             iItemStatusOrig[i] = iItemStatus[i];
       
  1455 
       
  1456             ids.AppendL(iItemIds[i]);
       
  1457             status.AppendL(iItemStatus[i]);
       
  1458 
       
  1459             // In current UI, status can only change from New -> Read, or Unread -> Read
       
  1460             if ( iItemStatus[i] == EItemStatusRead )
       
  1461                 {
       
  1462                 unreadCountDelta--;
       
  1463                 }
       
  1464             }
       
  1465         }    
       
  1466 
       
  1467     // update folder view
       
  1468     unreadCount = iFolderView->UnreadCountChangedL( unreadCountDelta );
       
  1469 
       
  1470     // Write the item status out to the server.
       
  1471     iFeedsInterface.UpdateFeedItemStatusL(ids, status, unreadCount);
       
  1472     CleanupStack::PopAndDestroy(/*status*/);
       
  1473     CleanupStack::PopAndDestroy(/*ids*/);
       
  1474     }
       
  1475 
       
  1476 
       
  1477 // -----------------------------------------------------------------------------
       
  1478 // CFeedsClientUtilities::FaviconL
       
  1479 //
       
  1480 // Returns the Favicon to the given url or NULL if one isn't found.
       
  1481 // -----------------------------------------------------------------------------
       
  1482 //
       
  1483 CGulIcon* CFeedsClientUtilities::FaviconL(const TDesC& aUrl)
       
  1484     {
       
  1485     CGulIcon*    icon = NULL;
       
  1486     
       
  1487     // TODO: Do this if access to the database is too slow.
       
  1488         // First search the local cache.
       
  1489         
       
  1490         // If not found extract it from the Feeds View's Browser Control and add
       
  1491         // it to the local cache.
       
  1492 
       
  1493     // Get the favicon from the Browser Control.
       
  1494 	icon = iApiProvider.WindowMgr().CurrentWindow()->BrCtlInterface().GetBitmapData(aUrl, TBrCtlDefs::EBitmapFavicon);    
       
  1495     if (icon != NULL)
       
  1496         {
       
  1497         icon->SetMask(NULL);
       
  1498         }
       
  1499     
       
  1500     return icon;
       
  1501     }
       
  1502     
       
  1503 
       
  1504 // -----------------------------------------------------------------------------
       
  1505 // CFeedsClientUtilities::LazyInitL
       
  1506 //
       
  1507 // Ensures that the views and the connection to the FeedsServer are ready.
       
  1508 // -----------------------------------------------------------------------------
       
  1509 //
       
  1510 void CFeedsClientUtilities::LazyInitL(TBool aGetRootFolder)
       
  1511     {   
       
  1512     // Create Views
       
  1513 	if(iFolderView == NULL)
       
  1514 		{
       
  1515 	    TRect rect(iAppUI.ClientRect());
       
  1516 	    iFolderView = CFeedsFolderView::NewL( iApiProvider, rect );
       
  1517 	    iAppUI.AddViewL( iFolderView ); // transfer ownership to CAknViewAppUi
       
  1518 		}
       
  1519 		
       
  1520     // Create the WaitDialog
       
  1521     if (iWaitDialog == NULL)
       
  1522         {        
       
  1523         iWaitDialog = CFeedsWaitDialog::NewL(*this);
       
  1524         }
       
  1525     
       
  1526     // Connect to the server.
       
  1527     ConnectToServerL(aGetRootFolder);
       
  1528     }
       
  1529     
       
  1530     
       
  1531 // -----------------------------------------------------------------------------
       
  1532 // CFeedsClientUtilities::ShowServerError
       
  1533 //
       
  1534 // Show a server error.
       
  1535 // -----------------------------------------------------------------------------
       
  1536 //
       
  1537 void CFeedsClientUtilities::ShowServerError(TInt aStatus, CTransaction::TTransactionType aRequestType/*=ENone*/)
       
  1538     {
       
  1539     TInt labelId;
       
  1540 
       
  1541     // Determine which label to use.
       
  1542     switch(aStatus)
       
  1543         {
       
  1544         case KErrNoMemory:
       
  1545             labelId = R_FEEDS_OUT_OF_MEMORY;
       
  1546             break;
       
  1547 		// Few errors wont be shown as pop up dialog as they will appear in list box main pane
       
  1548         case KErrCorrupt:
       
  1549             // A pop up error note should be displayed if import is requested,
       
  1550             // else error will be displayed in main pane itself
       
  1551             if (aRequestType == CTransaction::EImportOPML) 
       
  1552                 {
       
  1553                 labelId = R_FEEDS_MALFORMED_FEED_ERROR;
       
  1554                 break;	
       
  1555                 }
       
  1556 		case KErrNotSupported:
       
  1557 		case KErrTimedOut:
       
  1558 	   	case  KErrBadName:
       
  1559         	return;
       
  1560 			
       
  1561         case -KErrNotSupported:
       
  1562             // Show the special http not supported on WINSCW error
       
  1563             TRAP_IGNORE(TBrowserDialogs::InfoNoteL(R_BROWSER_INFO_NOTE, R_FEEDS_HTTP_UNSUPPORTED_WINSCW));
       
  1564             return;
       
  1565 
       
  1566 		case KErrAlreadyExists:
       
  1567             labelId = R_FEEDS_NAME_ALREADY_IN_USE;
       
  1568 			break;			
       
  1569 
       
  1570         	
       
  1571         case KErrArgument:
       
  1572             // A pop up error note should be displayed if import is requested,
       
  1573             // else error will be displayed in main pane itself
       
  1574             if (aRequestType == CTransaction::EImportOPML)
       
  1575                 {
       
  1576                	labelId = R_FEEDS_MALFORMED_FEED_ERROR;
       
  1577                 break;
       
  1578                 }
       
  1579         default:
       
  1580 			if (aStatus > 0) // All network errors
       
  1581                 {
       
  1582                 // Error will shown in listbox main pane
       
  1583                 return;
       
  1584                 }
       
  1585 
       
  1586             // Otherwise.
       
  1587             else
       
  1588                 {
       
  1589                 labelId = R_FEEDS_GENERAL_ERROR;
       
  1590                 }
       
  1591             break;
       
  1592         }
       
  1593 
       
  1594     // Show the error dialog.
       
  1595 	if (aStatus != KErrCancel)
       
  1596 		{
       
  1597 		TRAP_IGNORE(TBrowserDialogs::InfoNoteL(R_BROWSER_INFO_NOTE, labelId));
       
  1598 		}
       
  1599     }
       
  1600 
       
  1601 
       
  1602 // -----------------------------------------------------------------------------
       
  1603 // CFeedsClientUtilities::ConnectToServerL
       
  1604 //
       
  1605 // Connect to the server.
       
  1606 // -----------------------------------------------------------------------------
       
  1607 //
       
  1608 void CFeedsClientUtilities::ConnectToServerL(TBool aGetRootFolder)
       
  1609     {
       
  1610     if (!iIsConnected)
       
  1611         {
       
  1612         User::LeaveIfError(iFeedsInterface.Connect());
       
  1613         iIsConnected = ETrue;
       
  1614         }        
       
  1615     
       
  1616     if (aGetRootFolder)
       
  1617         {
       
  1618         // Set this to no-view so the folder view isn't shown after it's fetched.
       
  1619         iNextViewId = KUidBrowserNullViewId;
       
  1620         
       
  1621         FetchRootFolderL();
       
  1622         }
       
  1623     }
       
  1624 
       
  1625 
       
  1626 // -----------------------------------------------------------------------------
       
  1627 // CFeedsClientUtilities::DisconnectFromServer
       
  1628 //
       
  1629 // Disconnect from the server.
       
  1630 // -----------------------------------------------------------------------------
       
  1631 //
       
  1632 void CFeedsClientUtilities::DisconnectFromServer()
       
  1633     {
       
  1634     if( !iIsConnected )
       
  1635         {
       
  1636         //Nothing connected, return, this is causing crash.
       
  1637         return; 
       
  1638         }
       
  1639     iFeedsInterface.Close();
       
  1640 
       
  1641     iIsConnected = EFalse;
       
  1642     }
       
  1643 
       
  1644 
       
  1645 // -----------------------------------------------------------------------------
       
  1646 // CFeedsClientUtilities::FeedUpdatedTime
       
  1647 //
       
  1648 // Since the folder list isn't updated after it is fetched the FeedsClientUtilities 
       
  1649 // tracks the last update times for feeds the user visits in the current session.
       
  1650 // This method returns the "last updated" timestamp of the given item.
       
  1651 // -----------------------------------------------------------------------------
       
  1652 //
       
  1653 TTime CFeedsClientUtilities::FeedUpdatedTime(const CFeedsEntity& aItem)
       
  1654     {
       
  1655     TTime  timestamp;
       
  1656     TInt   pos;
       
  1657     
       
  1658     
       
  1659     // Search the cache for the feed's url.
       
  1660     if ((pos = iFeedUpdateTimeIds.Find(aItem.GetId())) != KErrNotFound)
       
  1661         {
       
  1662         timestamp = iFeedUpdateTimeTimestamps[pos];
       
  1663         }
       
  1664         
       
  1665     // Otherwise return the item's timestamp.
       
  1666     else
       
  1667         {
       
  1668         aItem.GetTimeValue(EFeedAttributeTimestamp,timestamp);
       
  1669         }
       
  1670         
       
  1671     // Return the cached value.
       
  1672     return timestamp;
       
  1673     }
       
  1674     
       
  1675     
       
  1676 // -----------------------------------------------------------------------------
       
  1677 // CFeedsClientUtilities::ResetFeedUpdateTime
       
  1678 //
       
  1679 // Resets the "last updated" cache.
       
  1680 // -----------------------------------------------------------------------------
       
  1681 //
       
  1682 void CFeedsClientUtilities::ResetFeedUpdateTime()
       
  1683     {
       
  1684     // Reset the arrays.
       
  1685     iFeedUpdateTimeIds.Reset();
       
  1686     iFeedUpdateTimeTimestamps.Reset();
       
  1687     }
       
  1688 
       
  1689 
       
  1690 // -----------------------------------------------------------------------------
       
  1691 // CFeedsClientUtilities::UpdateFeedUpdatedTimeL
       
  1692 //
       
  1693 // Update the feed's "last updated" value in the cache.
       
  1694 // -----------------------------------------------------------------------------
       
  1695 //
       
  1696 void CFeedsClientUtilities::UpdateFeedUpdatedTimeL(const CFeedsEntity& aFeed)
       
  1697     {    
       
  1698     TInt  pos;
       
  1699     TInt  err;
       
  1700     
       
  1701     // TODO: Use the feed's id instead of the url.  This would require the
       
  1702     //       packed folder to store the feed id as well.
       
  1703     
       
  1704     // Search the cache for the feed's url and if found then update the timestamp.
       
  1705     if ((pos = iFeedUpdateTimeIds.Find(aFeed.GetId())) != KErrNotFound)
       
  1706         {
       
  1707         	TTime time;
       
  1708         	aFeed.GetTimeValue(EFeedAttributeTimestamp,time);
       
  1709         	iFeedUpdateTimeTimestamps[pos] = time;
       
  1710         }
       
  1711 
       
  1712     // Otherwise add a new slot.  
       
  1713     else
       
  1714         {
       
  1715         User::LeaveIfError(iFeedUpdateTimeIds.Append(aFeed.GetId()));
       
  1716        	TTime time;
       
  1717        	aFeed.GetTimeValue(EFeedAttributeTimestamp,time);
       
  1718 
       
  1719         err = iFeedUpdateTimeTimestamps.Append(time);
       
  1720         
       
  1721         // Ensure the arrays don't get out of sync if the second append fails.
       
  1722         if (err != KErrNone)
       
  1723             {
       
  1724             iFeedUpdateTimeIds.Remove(iFeedUpdateTimeIds.Count() - 1);
       
  1725             User::LeaveIfError(err);
       
  1726             }
       
  1727         }
       
  1728     }
       
  1729 
       
  1730 
       
  1731 // -----------------------------------------------------------------------------
       
  1732 // CFeedsClientUtilities::InitMenuItemL()
       
  1733 // -----------------------------------------------------------------------------
       
  1734 //
       
  1735 void CFeedsClientUtilities::InitMenuItemL( CEikMenuPane* aMenuPane,
       
  1736                                              TInt aCommandId,
       
  1737                                              TInt aResourceId, 
       
  1738                                              TInt aCascadeId,
       
  1739                                              TInt aFlags )
       
  1740     {
       
  1741     CEikMenuPaneItem::SData item;
       
  1742     item.iCommandId = aCommandId;
       
  1743     item.iFlags = aFlags;
       
  1744     item.iCascadeId = aCascadeId;
       
  1745     HBufC* buf = StringLoader::LoadLC( aResourceId );
       
  1746     item.iText.Copy( *buf );
       
  1747     CleanupStack::PopAndDestroy( buf );	// buf
       
  1748     buf = NULL;
       
  1749 
       
  1750     aMenuPane->AddMenuItemL( item );    
       
  1751     }
       
  1752     
       
  1753 // -----------------------------------------------------------------------------
       
  1754 // CFeedsClientUtilities::SendOPMLFileL()
       
  1755 // -----------------------------------------------------------------------------
       
  1756 //    
       
  1757 void CFeedsClientUtilities::SendOPMLFileL( )
       
  1758     {
       
  1759     RFs                 rfs;
       
  1760     
       
  1761     _LIT(KPath, "C:\\system\\temp\\");
       
  1762     TBuf<KMaxFileName>  path(KPath);
       
  1763     
       
  1764 	User::LeaveIfError(rfs.Connect());
       
  1765 	CleanupClosePushL(rfs);
       
  1766 
       
  1767 	path.Append(*iExportFileName);
       
  1768 	
       
  1769 	MBmOTABinSender& sender = iApiProvider.BmOTABinSenderL();
       
  1770 
       
  1771 	sender.ResetAndDestroy();
       
  1772     sender.SendOPMLFileL(path);
       
  1773     
       
  1774     CleanupStack::PopAndDestroy(/*rfs*/);
       
  1775     }
       
  1776     
       
  1777 // -----------------------------------------------------------------------------
       
  1778 // CFeedsClientUtilities::HandleCommandL()
       
  1779 // -----------------------------------------------------------------------------
       
  1780 //
       
  1781 void CFeedsClientUtilities::HandleCommandL( TUid aViewId, TInt aCommand )
       
  1782     {
       
  1783      switch (aCommand)
       
  1784         {           
       
  1785         case EWmlCmdBackToPage:
       
  1786             {
       
  1787             iApiProvider.SetViewToReturnOnClose( aViewId );
       
  1788             iApiProvider.SetViewToBeActivatedIfNeededL( KUidBrowserContentViewId );
       
  1789             break;
       
  1790             }
       
  1791 
       
  1792         case EFeedsImport:
       
  1793         	ImportFeedsL();
       
  1794         	break;
       
  1795         
       
  1796         default:
       
  1797 		    // pass common commands to app ui
       
  1798 		    iAppUI.HandleCommandL( aCommand );
       
  1799         }
       
  1800     }
       
  1801 
       
  1802 // -----------------------------------------------------------------------------
       
  1803 // CFeedsClientUtilities::DynInitMenuPaneL()
       
  1804 // -----------------------------------------------------------------------------
       
  1805 //
       
  1806 void CFeedsClientUtilities::DynInitMenuPaneL(
       
  1807         TInt aResourceId,
       
  1808         CEikMenuPane* aMenuPane )
       
  1809     {
       
  1810     
       
  1811     // Option menu items common to all three feeds views
       
  1812     if ((aResourceId == R_FEEDS_FOLDER_VIEW_MENU) ||
       
  1813         (aResourceId == R_FEEDS_FEED_VIEW_MENU) ||
       
  1814         (aResourceId == R_FEEDS_TOPIC_VIEW_MENU))
       
  1815         {      
       
  1816         // browser prefs
       
  1817         InitMenuItemL( aMenuPane, EWmlCmdPreferences, R_WMLBROWSER_SETTINGS_TITLE );
       
  1818         
       
  1819         // Help
       
  1820 	InitMenuItemL( aMenuPane, EAknCmdHelp, R_BROWSER_MENU_ITEM_HELP, R_FEEDS_HELP_SUBMENU );
       
  1821 
       
  1822         // exit
       
  1823         InitMenuItemL( aMenuPane, EWmlCmdUserExit, R_BROWSER_MENU_ITEM_EXIT );
       
  1824         }
       
  1825    }
       
  1826 
       
  1827 // -----------------------------------------------------------------------------
       
  1828 // CFeedsClientUtilities::SetCalledFromView()
       
  1829 // -----------------------------------------------------------------------------
       
  1830 //
       
  1831 void CFeedsClientUtilities::SetCalledFromView(TUid aViewId)
       
  1832     {
       
  1833     iCalledFromView = aViewId;
       
  1834     }
       
  1835 
       
  1836 // -----------------------------------------------------------------------------
       
  1837 // CFeedsClientUtilities::CalledFromView()
       
  1838 // -----------------------------------------------------------------------------
       
  1839 //
       
  1840 TUid CFeedsClientUtilities::CalledFromView()
       
  1841     {
       
  1842     return iCalledFromView;
       
  1843     }
       
  1844 
       
  1845 // -----------------------------------------------------------------------------
       
  1846 // CFeedsClientUtilities::ItemStatusL
       
  1847 //
       
  1848 // Returns the INITIAL status of each of the items in the feed.
       
  1849 // The caller can then modify the values and call UpdateFeedItemStatusL
       
  1850 // to request the feeds server to update the feed's item status. 
       
  1851 // -----------------------------------------------------------------------------
       
  1852 //
       
  1853 void CFeedsClientUtilities::ItemStatusL(RArray<TInt>& aItemIds, 
       
  1854                 RArray<TFeedItemStatus>& aItemStatus, const CFeedsEntity& aFeed) const
       
  1855     {
       
  1856     TInt status;
       
  1857 
       
  1858     aItemIds.Reset();
       
  1859     aItemStatus.Reset();
       
  1860 
       
  1861     for(TInt index=0 ; index< aFeed.GetChildren().Count() ; index++)
       
  1862         {
       
  1863         CFeedsEntity *feedEntity = aFeed.GetChildren()[index];
       
  1864 
       
  1865         feedEntity->GetIntegerValue(EItemAttributeStatus,status);
       
  1866 
       
  1867         User::LeaveIfError(aItemIds.Append(feedEntity->GetId()));
       
  1868         User::LeaveIfError(aItemStatus.Append((TFeedItemStatus)status));
       
  1869         }
       
  1870     }