mediasettings/feedsettingsviews/src/feedsettingsviewserviceselection.cpp
changeset 0 96612d01cf9f
child 1 6711b85517b7
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2006 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:    Class for "service selection list" in Settings UI.*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <aknlists.h>
       
    21 #include <StringLoader.h>
       
    22 #include <akntitle.h>
       
    23 #include <eikclbd.h>
       
    24 #include <barsread.h>
       
    25 #include <aknViewAppUi.h>
       
    26 #include <BrowserLauncher.h>
       
    27 #include <BrowserOverriddenSettings.h>
       
    28 #include <uriutils.h>
       
    29 #include "IptvDebug.h"
       
    30 #include <AknQueryDialog.h>
       
    31 #include <ipvideo/vcxconnectionutility.h>
       
    32 #include <vcxnssettingsview.rsg>
       
    33 #include "vcxnsservicesettings.h"
       
    34 
       
    35 #include "CIptvService.h"
       
    36 #include "feedsettingsviewremoveservicequerydialog.h"
       
    37 #include "feedsettingsview.h"
       
    38 #include "feedsettingsviewserviceselection.h"
       
    39 #include "iptvlocalisationliterals.h"
       
    40 
       
    41 // CONSTANTS
       
    42 /* Parameter for embedded browser launch */
       
    43 _LIT(KUrlLaunchParameter, "4 ");
       
    44 _LIT(KServicesListItemFormat, "1\t%S");
       
    45 _LIT( KLinkTagOpen, "<AknMessageQuery Link>" );
       
    46 _LIT( KLinkTagClose, "</AknMessageQuery Link>" );
       
    47 _LIT( KNextLine, "\n" );
       
    48 
       
    49 const TInt KServicesListItemMaxLength = KIptvSmServicesDbNameMaxLength + 5;
       
    50 const TInt KIptvMskPosition = 3;
       
    51 
       
    52 // ================= MEMBER FUNCTIONS =======================
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CVcSettingsViewServiceSelection::CVcSettingsViewServiceSelection()
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CVcxNsSettingsViewServiceSelection::CVcxNsSettingsViewServiceSelection(
       
    59         CVcxNsSettingsViewContainer* aParent,
       
    60         CVcxNsServiceSettings& aServiceSettings )
       
    61  :  iParent(aParent),
       
    62     iServiceSettings(aServiceSettings),
       
    63     iOwnButtons(EFalse),    
       
    64     iServiceType((CIptvService::TServiceType)0)
       
    65     {
       
    66     __ASSERT_DEBUG(iParent, User::Panic(KNullDesC, KErrBadHandle));
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CVcSettingsViewServiceSelection::NewL()
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 CVcxNsSettingsViewServiceSelection* CVcxNsSettingsViewServiceSelection::NewL(
       
    74         CVcxNsSettingsViewContainer* aParent,
       
    75         CVcxNsServiceSettings& aServiceSettings )
       
    76     {
       
    77     CVcxNsSettingsViewServiceSelection* self = 
       
    78         new (ELeave) CVcxNsSettingsViewServiceSelection(aParent, aServiceSettings);
       
    79 
       
    80     CleanupStack::PushL(self);
       
    81     self->ConstructL();
       
    82     CleanupStack::Pop(self);
       
    83     return self;
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CVcSettingsViewServiceSelection::ConstructL()
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CVcxNsSettingsViewServiceSelection::ConstructL()
       
    91     {
       
    92     TResourceReader reader;
       
    93     iListbox = new (ELeave) CAknSingleGraphicStyleListBox();
       
    94     iParent->ControlEnv()->CreateResourceReaderLC( reader, 
       
    95                                  R_VCSETTINGSVIEW_SERVICESELECTION_LIST );
       
    96     iListbox->SetContainerWindowL(*iParent);
       
    97     iListbox->SetListBoxObserver(iParent);
       
    98     iListbox->ConstructFromResourceL(reader);
       
    99     CleanupStack::PopAndDestroy(); // reader
       
   100     const TInt KGranularity( 4 );
       
   101     CAknIconArray* icons = new (ELeave) CAknIconArray( KGranularity );
       
   102     CleanupStack::PushL(icons);
       
   103     icons->ConstructFromResourceL(R_IPTV_CHECKBOX_ICONS);
       
   104     CleanupStack::Pop(icons);
       
   105     iListbox->ItemDrawer()->ColumnData()->SetIconArray(icons);
       
   106     CTextListBoxModel* model = iListbox->Model();
       
   107     model->SetOwnershipType(ELbmOwnsItemArray);
       
   108     
       
   109     iListbox->CreateScrollBarFrameL(ETrue);
       
   110     iListbox->SetMopParent(iParent);    
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CVcSettingsViewServiceSelection::~CVcSettingsViewServiceSelection()
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 CVcxNsSettingsViewServiceSelection::~CVcxNsSettingsViewServiceSelection()
       
   118     {
       
   119     if ( iOwnButtons && iParent )
       
   120         {
       
   121         CEikButtonGroupContainer* cba = iParent->SettingsView()->GetButtonGroupContainer();
       
   122         if ( cba )
       
   123             {
       
   124             RemoveCommandsFromCba( *cba );
       
   125             }
       
   126         }
       
   127 
       
   128     delete iListbox;
       
   129     delete iServicesArray;
       
   130     delete iServicesArrayVodCast;
       
   131     delete iLauncher;
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CVcSettingsViewServiceSelection::ActivateL()
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 void CVcxNsSettingsViewServiceSelection::ActivateL()
       
   139     {
       
   140     // Force MSK refresh after every activation
       
   141     iCurrentMskResource = KErrNotFound;
       
   142 
       
   143     if (iServicesArray)
       
   144         {
       
   145         if (iServicesArray->Count() > 0)
       
   146             {
       
   147             iListbox->SetCurrentItemIndex(0);
       
   148             }
       
   149         }
       
   150 
       
   151     iParent->SetTitleL( R_MPSETT_FEEDS_VIEW_TITLE );
       
   152     
       
   153     iListbox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, 
       
   154                                                          CEikScrollBarFrame::EAuto );
       
   155     iListbox->MakeVisible(ETrue);
       
   156     iListbox->DrawNow();
       
   157 
       
   158     iListbox->UpdateScrollBarsL();
       
   159     }
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CVcSettingsViewServiceSelection::Deactivate()
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 void CVcxNsSettingsViewServiceSelection::Deactivate()
       
   166     {
       
   167     if (iOwnButtons)
       
   168         {
       
   169         CEikButtonGroupContainer* cba = iParent->SettingsView()->GetButtonGroupContainer();
       
   170         if ( cba )
       
   171             {
       
   172             RemoveCommandsFromCba( *cba );
       
   173             cba->DrawNow();
       
   174             }
       
   175         iOwnButtons = EFalse;
       
   176         }
       
   177 
       
   178     TRAP_IGNORE(iListbox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   179                 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOff));
       
   180 
       
   181     // Clear msk value so that when we return 
       
   182     // to original menu we can set the correct msk.
       
   183     iParent->ClearMsk();    
       
   184 
       
   185     iListbox->MakeVisible(EFalse);
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CVcSettingsViewServiceSelection::SetServiceType()
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 void CVcxNsSettingsViewServiceSelection::SetServiceType(
       
   193                                          CIptvService::TServiceType aServiceType )
       
   194     {
       
   195     iServiceType = aServiceType;
       
   196     }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // CVcSettingsViewServiceSelection::GetServiceType()
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 CIptvService::TServiceType CVcxNsSettingsViewServiceSelection::GetServiceType()
       
   203     {
       
   204     return iServiceType;
       
   205     }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // CVcSettingsViewServiceSelection::GetCurrentServiceL()
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 CIptvService* CVcxNsSettingsViewServiceSelection::GetCurrentServiceL()
       
   212     {
       
   213     TInt index = iListbox->CurrentItemIndex();
       
   214 
       
   215     if (index != KErrNotFound)
       
   216         {
       
   217         CIptvService* iptvService = CIptvService::NewL();
       
   218         CleanupStack::PushL(iptvService);
       
   219         iptvService->SetL(iServicesArray->MdcaPoint(index));
       
   220         CleanupStack::Pop(iptvService);
       
   221         return iptvService;
       
   222         }
       
   223     else
       
   224         {
       
   225         return NULL;    
       
   226         }
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // CVcSettingsViewServiceSelection::IsCurrentServiceReadOnlyL()
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 TBool CVcxNsSettingsViewServiceSelection::IsCurrentServiceReadOnlyL()
       
   234     {
       
   235     CIptvService* service  = GetCurrentServiceL();
       
   236     TBool toReturn ( EFalse );
       
   237     
       
   238     if (service)
       
   239         {
       
   240         CleanupStack::PushL(service);
       
   241         
       
   242         TUint32 flags = service->GetFlags();
       
   243         
       
   244         if (flags & CIptvService::EReadOnly)
       
   245             {
       
   246             toReturn = ETrue;
       
   247             }
       
   248 
       
   249         CleanupStack::PopAndDestroy(service);        
       
   250         }
       
   251 
       
   252     return toReturn;
       
   253     }
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // CVcSettingsViewServiceSelection::ShowAccountMgmtDialogL
       
   257 //
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 TInt CVcxNsSettingsViewServiceSelection::ShowAccountMgmtDialogL()
       
   261     {
       
   262     TInt result(0);
       
   263     
       
   264     //Get texts for the message query
       
   265     HBufC* removeServiceText = 
       
   266         StringLoader::LoadLC( R_VCSETTINGSVIEW_REMOVE_SERVICE_WITH_ACCOUNT );
       
   267     HBufC* link = StringLoader::LoadLC( R_VCSETTINGSVIEW_LINK_ACCOUNT );
       
   268     HBufC* accMgmtLink = link->ReAllocL( link->Length() +
       
   269                                          KLinkTagOpen().Length() + 
       
   270                                          KLinkTagClose().Length() );
       
   271     
       
   272     CleanupStack::Pop( link );
       
   273     link = accMgmtLink;
       
   274     CleanupStack::PushL( link );
       
   275     
       
   276     link->Des().Insert(0, KLinkTagOpen);
       
   277     link->Des().Append( KLinkTagClose );   
       
   278 
       
   279     HBufC* msgText = HBufC::NewLC( removeServiceText->Length() + 
       
   280                                    link->Length() + 
       
   281                                    KNextLine().Length() );
       
   282                              
       
   283                                         
       
   284     TPtr ptr( msgText->Des() );   
       
   285     ptr += *removeServiceText;        
       
   286     ptr += KNextLine;
       
   287     ptr += *link;
       
   288 
       
   289     TCallBack accMgmtCallback( ShowLinkL, this );
       
   290         
       
   291     // Create and show the message query dialog
       
   292     CVcxNsSettingsViewRemoveServiceQueryDialog* dlg =
       
   293       CVcxNsSettingsViewRemoveServiceQueryDialog::NewL( *msgText );
       
   294     
       
   295     // PrepareLC pushes *this to cleanup stack.
       
   296     dlg->PrepareLC( R_VCSETTINGSVIEW_REMOVE_SERVICE_QUERY );
       
   297     dlg->ButtonGroupContainer().SetCommandSetL( 
       
   298                                      R_VCSETTINGSVIEW_SOFTKEYS_REMOVE_CANCEL );
       
   299     dlg->SetLink( accMgmtCallback );
       
   300     
       
   301     result = dlg->RunLD();
       
   302     
       
   303     CleanupStack::PopAndDestroy( msgText ); // message, this
       
   304     CleanupStack::PopAndDestroy( link );
       
   305     CleanupStack::PopAndDestroy( removeServiceText );
       
   306     
       
   307     return result;    
       
   308     }
       
   309 
       
   310 // -----------------------------------------------------------------------------
       
   311 // CVcSettingsViewServiceSelection::ShowLinkL
       
   312 // Used as a callback function in message query.
       
   313 // -----------------------------------------------------------------------------
       
   314 //
       
   315 TInt CVcxNsSettingsViewServiceSelection::ShowLinkL( TAny* ptr )
       
   316     {
       
   317     TInt error(KErrNone);
       
   318     
       
   319     CVcxNsSettingsViewServiceSelection* serviceSelection = 
       
   320         static_cast<CVcxNsSettingsViewServiceSelection*>(ptr);
       
   321     TInt index = serviceSelection->ListBox()->CurrentItemIndex();
       
   322     TBuf<KIptvSmServicesDbAccountManagementUrlMaxLength> accMgmtUri;
       
   323     if ( index >= 0 )
       
   324         {
       
   325         // Get some basic data about the service.
       
   326         CIptvService* iptvService = CIptvService::NewL();
       
   327         CleanupStack::PushL(iptvService);
       
   328         iptvService->SetL(serviceSelection->iServicesArray->MdcaPoint(index));
       
   329         accMgmtUri  = iptvService->GetAccountManagementUrl();
       
   330         CleanupStack::PopAndDestroy(iptvService);
       
   331         
       
   332         if ( accMgmtUri.Length() > 0 )
       
   333             {
       
   334             serviceSelection->OpenEmbeddedBrowserL( accMgmtUri );
       
   335             }
       
   336         }
       
   337     return error;
       
   338     }
       
   339 
       
   340 // -----------------------------------------------------------------------------
       
   341 // CVcSettingsViewServiceSelection::DeleteCurrentServiceL()
       
   342 // -----------------------------------------------------------------------------
       
   343 //
       
   344 void CVcxNsSettingsViewServiceSelection::DeleteCurrentServiceL()
       
   345     {
       
   346     TInt index = iListbox->CurrentItemIndex();
       
   347 
       
   348     if (index >= 0)
       
   349         {
       
   350         TBuf<KIptvSmServicesDbNameMaxLength> name;
       
   351         TBuf<KIptvSmServicesDbAccountManagementUrlMaxLength> accMgmtUri;
       
   352         CAknQueryDialog*                   dlg    = NULL;
       
   353         HBufC*                             text   = NULL;
       
   354         TUint32                            itemId = 0;
       
   355         TInt                               result = 0;
       
   356 
       
   357         // Get some basic data about the service.
       
   358         CIptvService* iptvService = CIptvService::NewL();
       
   359         CleanupStack::PushL(iptvService);
       
   360         iptvService->SetL(iServicesArray->MdcaPoint(index));
       
   361         itemId      = iptvService->GetId();
       
   362         name        = iptvService->GetName();
       
   363         accMgmtUri  = iptvService->GetAccountManagementUrl();
       
   364         CleanupStack::PopAndDestroy(iptvService);
       
   365 
       
   366         // Display confirmation query.
       
   367         switch ( iServiceType )
       
   368             {
       
   369             case CIptvService::EVod:
       
   370             case CIptvService::EServiceGroup:
       
   371             case CIptvService::ELiveTv:
       
   372                 {
       
   373                 if ( accMgmtUri.Length() > 0 )
       
   374                     {
       
   375                     result= ShowAccountMgmtDialogL();    
       
   376                     break;
       
   377                     }
       
   378                 else
       
   379                     {
       
   380                     text = StringLoader::LoadLC( R_IPTV_REMOVE_SERVICE_CONFIRMATION,
       
   381                                                  name );
       
   382                     break;
       
   383                     }
       
   384                 }
       
   385             case CIptvService::EVodCast:
       
   386                 {
       
   387                 // "Remove feed %U?"
       
   388                 text = StringLoader::LoadLC(R_IPTV_REMOVE_FEED_CONFIRMATION,
       
   389                                             name );
       
   390                 break;
       
   391                 }
       
   392 
       
   393             case CIptvService::EBrowser:
       
   394                 {
       
   395                 text = StringLoader::LoadLC(R_IPTV_REMOVE_WEB_LINK_CONFIRMATION,
       
   396                                             name );
       
   397                 break;
       
   398                 }
       
   399             default:
       
   400                 break;    
       
   401             }
       
   402         if (text)
       
   403             {
       
   404             dlg    = CAknQueryDialog::NewL();
       
   405             result = dlg->ExecuteLD(R_VCSETTINGSVIEW_DELETE_CONFIRMATION_QUERY, *text);
       
   406             CleanupStack::PopAndDestroy(text);
       
   407             }
       
   408 
       
   409         if (result == EAknSoftkeyYes || result == EAknSoftkeyOk)
       
   410             {
       
   411                 
       
   412             // Create copy of currently selected items.
       
   413             const CListBoxView::CSelectionIndexArray* indices = 
       
   414                                                 iListbox->SelectionIndexes();
       
   415             RArray<TInt> copyIndices;
       
   416             CleanupClosePushL(copyIndices);
       
   417             TInt err( KErrNone );
       
   418             for (TInt i = 0; i < indices->Count(); i++)
       
   419                 {
       
   420                 err = copyIndices.InsertInOrder((*indices)[i]);
       
   421                 if ( err != KErrNone )
       
   422                     {
       
   423                     IPTVLOGSTRING2_LOW_LEVEL( 
       
   424                         "CVcSettingsViewServiceSelection::DeleteCurrentServiceL:\
       
   425                         InsertInOrder failed: %d", err );
       
   426                     
       
   427                     if ( err != KErrAlreadyExists )
       
   428                         {
       
   429                         User::Leave( err );
       
   430                         }
       
   431                     }
       
   432                 }
       
   433 
       
   434             // Remove the item from listbox.
       
   435             CTextListBoxModel* model = iListbox->Model();
       
   436             CDesCArray* array = STATIC_CAST(CDesCArray*, model->ItemTextArray());
       
   437             array->Delete(index);
       
   438 
       
   439             // Remove the item from DB.
       
   440             iServiceSettings.DeleteServiceL(itemId);
       
   441 
       
   442             // Remove the item from iServicesArray-list.
       
   443             iServicesArray->Delete(index);
       
   444 
       
   445             AknListBoxUtils::HandleItemRemovalAndPositionHighlightL( iListbox, 
       
   446                                                                      index, 
       
   447                                                                      ETrue );
       
   448 
       
   449             // Mark the items that were marked before deletion.
       
   450             for (TInt j = 0; j < copyIndices.Count(); j++)
       
   451                 {
       
   452                 if (copyIndices[j] < index)
       
   453                     {
       
   454                     iListbox->View()->SelectItemL(copyIndices[j]);
       
   455                     }
       
   456                 else if (copyIndices[j] > index)
       
   457                     {
       
   458                     iListbox->View()->SelectItemL(copyIndices[j] - 1);
       
   459                     }
       
   460                 }
       
   461             CleanupStack::PopAndDestroy( &copyIndices );
       
   462             iListbox->DrawNow();
       
   463             iParent->DrawNow();            
       
   464             }
       
   465         }
       
   466     }
       
   467 
       
   468 // -----------------------------------------------------------------------------
       
   469 // CVcSettingsViewServiceSelection::LoadL()
       
   470 // -----------------------------------------------------------------------------
       
   471 //
       
   472 void CVcxNsSettingsViewServiceSelection::LoadL()
       
   473     {
       
   474     IPTVLOGSTRING_LOW_LEVEL(
       
   475         "Settings view ## CVcSettingsViewServiceSelection::LoadL() - Enter");
       
   476 
       
   477     TBuf<KServicesListItemMaxLength> item;
       
   478 
       
   479     delete iServicesArray;
       
   480     iServicesArray = NULL;
       
   481     iServicesArray = iServiceSettings.GetServicesByTypeL(iServiceType);
       
   482     
       
   483     CTextListBoxModel* model = iListbox->Model();
       
   484     CDesCArray* array = STATIC_CAST(CDesCArray*, model->ItemTextArray());
       
   485     array->Reset();    
       
   486     
       
   487     if (iServicesArray)
       
   488         {
       
   489         CIptvService*  iptvService = CIptvService::NewL();
       
   490         CleanupStack::PushL(iptvService);
       
   491 
       
   492         // remove services that are inside a servicegroup from the list.
       
   493         TInt i = 0;
       
   494         while ( i < iServicesArray->MdcaCount() )
       
   495             {
       
   496             iptvService->SetL(iServicesArray->MdcaPoint(i));
       
   497 
       
   498             TUint32 flags = iptvService->GetFlags();
       
   499             if ( flags & CIptvService::EGroupedService )
       
   500                 {
       
   501                 iServicesArray->Delete( i );
       
   502                 }
       
   503             else
       
   504                 {
       
   505                 i++;
       
   506                 }
       
   507             }
       
   508         
       
   509         // Note: Item order of our iServicesArray-list matches order of 
       
   510         // iServiceSelectionList-listbox.
       
   511 
       
   512         for (TInt i = 0; i < iServicesArray->MdcaCount(); i++)
       
   513             {
       
   514             iptvService->SetL(iServicesArray->MdcaPoint(i));
       
   515             
       
   516             if ( iptvService->GetName().Match( KQtnIptvNewServiceMain ) == 0 )
       
   517                 {
       
   518                 // "qtn_iptv_new_service_main" is replaced to localised text.
       
   519                 HBufC* addServicesLocalised = 
       
   520                                 StringLoader::LoadLC( R_IPTV_NEW_SERVICE_MAIN );
       
   521                 item.Format( KServicesListItemFormat, addServicesLocalised );
       
   522                 CleanupStack::PopAndDestroy( addServicesLocalised );
       
   523                 }
       
   524             else if ( iptvService->GetName().Match( KQtnIptvVideoDirectoryList ) == 0 )
       
   525                 {
       
   526                 // "qtn_iptv_video_directory_list" is replaced to localised text.
       
   527                 HBufC* videoDirectoryLocalised = 
       
   528                             StringLoader::LoadLC( R_IPTV_VIDEO_DIRECTORY_LIST );
       
   529                 item.Format( KServicesListItemFormat, videoDirectoryLocalised );
       
   530                 CleanupStack::PopAndDestroy( videoDirectoryLocalised );
       
   531                 }
       
   532             else 
       
   533                 {
       
   534                 TPtrC16 name( iptvService->GetName() );
       
   535                 item.Format( KServicesListItemFormat, &name );
       
   536                 }
       
   537         
       
   538             array->AppendL( item );
       
   539 
       
   540             TUint32 flags = iptvService->GetFlags();
       
   541             if (flags & CIptvService::ESelected)
       
   542                 {
       
   543                 iListbox->View()->SelectItemL(i);
       
   544                 }
       
   545             else
       
   546                 {
       
   547                 iListbox->View()->DeselectItem(i);
       
   548                 }
       
   549             }
       
   550            
       
   551         CleanupStack::PopAndDestroy(iptvService);
       
   552         }
       
   553 
       
   554     // Update empty text.
       
   555     HBufC* emptyText = NULL;
       
   556     switch (iServiceType)
       
   557         {
       
   558         case CIptvService::EVod:
       
   559         case CIptvService::EServiceGroup:
       
   560         case CIptvService::ELiveTv:
       
   561             {
       
   562             // "No services."
       
   563             emptyText = StringLoader::LoadLC(R_IPTV_NO_VIDEO_SERVICES);
       
   564             break;
       
   565             }
       
   566         case CIptvService::EVodCast:
       
   567             {
       
   568             // "No feeds."
       
   569             emptyText = StringLoader::LoadLC(R_IPTV_NO_FEEDS_SELECTED);
       
   570             break;
       
   571             }
       
   572         case CIptvService::EBrowser:
       
   573             {
       
   574             // "No links."
       
   575             emptyText = StringLoader::LoadLC(R_IPTV_NO_WEB_LINKS);
       
   576             break;
       
   577             }
       
   578         default:
       
   579             break;    
       
   580         }
       
   581     if (emptyText)
       
   582         {
       
   583         iListbox->View()->SetListEmptyTextL(*emptyText);
       
   584         CleanupStack::PopAndDestroy(emptyText);    
       
   585         }
       
   586 
       
   587     iListbox->HandleItemAdditionL();
       
   588     iListbox->DrawNow();
       
   589     iParent->DrawNow();
       
   590 
       
   591     IPTVLOGSTRING_LOW_LEVEL(
       
   592         "Settings view ## CVcSettingsViewServiceSelection::LoadL() - Exit");
       
   593     }
       
   594 
       
   595 // -----------------------------------------------------------------------------
       
   596 // CVcSettingsViewServiceSelection::SaveL()
       
   597 // -----------------------------------------------------------------------------
       
   598 //
       
   599 void CVcxNsSettingsViewServiceSelection::SaveL()
       
   600     {
       
   601     const CListBoxView::CSelectionIndexArray* indices = iListbox->SelectionIndexes();
       
   602     CTextListBoxModel*                        model   = iListbox->Model();
       
   603 
       
   604     // We go through each item in list. Those that are in indices
       
   605     // list are updated as selected, and those that are not are
       
   606     // updated as not selected.
       
   607     for (TInt i = 0; i < model->NumberOfItems(); i++)
       
   608         {
       
   609         TBool bSelected ( EFalse );
       
   610         
       
   611         for (TInt j = 0; j < indices->Count(); j++)
       
   612             {
       
   613             // Check if currently processed item is selected.
       
   614             if (i == ((*indices)[j]))
       
   615                 {
       
   616                 bSelected = ETrue;
       
   617                 break;
       
   618                 }
       
   619             }
       
   620 
       
   621         // Update the information for currently processed item.
       
   622         CIptvService* iptvService = CIptvService::NewL();
       
   623         CleanupStack::PushL(iptvService);
       
   624         iptvService->SetL(iServicesArray->MdcaPoint(i));
       
   625         
       
   626         TUint32 flags    = iptvService->GetFlags();
       
   627         TUint32 oldFlags = flags;
       
   628         
       
   629         if (bSelected)
       
   630             {
       
   631             flags |= CIptvService::ESelected;                
       
   632             }
       
   633         else
       
   634             {
       
   635             flags &= ~CIptvService::ESelected;
       
   636             }
       
   637 
       
   638         if (flags != oldFlags)
       
   639             {
       
   640             iptvService->SetFlags(flags);
       
   641             iServiceSettings.UpdateServiceL(*iptvService);
       
   642             }
       
   643 
       
   644         CleanupStack::PopAndDestroy(iptvService);
       
   645         }
       
   646     }
       
   647     
       
   648 // -----------------------------------------------------------------------------
       
   649 // CVcSettingsViewServiceSelection::ListBox()
       
   650 // -----------------------------------------------------------------------------
       
   651 //
       
   652 CAknSingleGraphicStyleListBox* CVcxNsSettingsViewServiceSelection::ListBox()
       
   653     {
       
   654     __ASSERT_DEBUG(iListbox, User::Panic(KNullDesC, KErrBadHandle));
       
   655 
       
   656     return iListbox;
       
   657     }    
       
   658 
       
   659 // -----------------------------------------------------------------------------
       
   660 // CVcSettingsViewServiceSelection::GetServiceIdL
       
   661 // -----------------------------------------------------------------------------
       
   662 //
       
   663 void CVcxNsSettingsViewServiceSelection::GetServiceIdL( 
       
   664     TUint32& aServiceId )
       
   665     {
       
   666     TInt currentItem = iListbox->CurrentItemIndex();
       
   667 
       
   668     // Make sure that view is not empty.
       
   669     if ( currentItem >= 0 && currentItem < iServicesArray->Count() )
       
   670         {
       
   671         CIptvService* iptvService = CIptvService::NewL();
       
   672         CleanupStack::PushL( iptvService );
       
   673         
       
   674         iptvService->SetL( iServicesArray->MdcaPoint( currentItem ) );
       
   675         aServiceId = iptvService->GetId();
       
   676         
       
   677         CleanupStack::PopAndDestroy( iptvService );
       
   678         }
       
   679     }
       
   680     
       
   681 // -----------------------------------------------------------------------------
       
   682 // CVcSettingsViewServiceSelection::CheckMsk()
       
   683 // -----------------------------------------------------------------------------
       
   684 //
       
   685 void CVcxNsSettingsViewServiceSelection::CheckMsk( )
       
   686     {
       
   687     TInt resourceId( 0 );
       
   688     
       
   689     if ( ! iParent ||
       
   690          ! iParent->SettingsView() ||
       
   691          ! iParent->SettingsView()->GetButtonGroupContainer() )
       
   692         {
       
   693         return;
       
   694         }
       
   695     
       
   696     if ( !iListbox || !iListbox->Model() ||
       
   697          iListbox->Model()->NumberOfItems() < 1 )
       
   698         {
       
   699         resourceId = R_VCSETTINGSVIEW_MSK_EMPTY;
       
   700         }
       
   701     else if ( IsCurrentListItemMarked() )
       
   702         {
       
   703         resourceId = R_VCSETTINGSVIEW_SERVICE_SELECTION_MSK_BUTTON_UNMARK;
       
   704         }
       
   705     else
       
   706         {
       
   707         resourceId = R_VCSETTINGSVIEW_SERVICE_SELECTION_MSK_BUTTON_MARK;
       
   708         }
       
   709 
       
   710     if ( resourceId )
       
   711         {
       
   712         iCurrentMskResource = resourceId;
       
   713 
       
   714         CEikButtonGroupContainer* cba =
       
   715                         iParent->SettingsView()->GetButtonGroupContainer();
       
   716 
       
   717         TRAPD( err, cba->SetCommandL( KIptvMskPosition, iCurrentMskResource ) );
       
   718         if ( err == KErrNone )
       
   719             {                            
       
   720             cba->DrawDeferred();            
       
   721             }
       
   722         }
       
   723     }
       
   724     
       
   725 // ---------------------------------------------------------
       
   726 // CVcSettingsViewServiceSelection::IsCurrentListItemMarked()
       
   727 // ---------------------------------------------------------
       
   728 //
       
   729 TBool CVcxNsSettingsViewServiceSelection::IsCurrentListItemMarked()
       
   730     {	
       
   731 	TInt currentIndex = iListbox->View()->CurrentItemIndex();
       
   732 	if ( currentIndex >= 0 )
       
   733 	    {
       
   734 	    return iListbox->View()->ItemIsSelected( currentIndex );
       
   735 	    }
       
   736 	else
       
   737 	    {
       
   738 	    return EFalse;
       
   739 	    }
       
   740     }
       
   741 
       
   742 // -----------------------------------------------------------------------------
       
   743 // Open browser in embedded mode with specified uri
       
   744 // -----------------------------------------------------------------------------
       
   745 //
       
   746 void CVcxNsSettingsViewServiceSelection::OpenEmbeddedBrowserL( const TDesC& aUri )
       
   747     {
       
   748     if ( aUri.Length() > 0 )
       
   749         {
       
   750         CUri8* inetUri = NULL;
       
   751         inetUri = UriUtils::CreateUriL( aUri );
       
   752         CleanupStack::PushL( inetUri );
       
   753 
       
   754         HBufC8* parameter = HBufC8::NewLC( inetUri->Uri().UriDes().Length() ); 
       
   755         parameter->Des().Format( _L8( "%S" ), &inetUri->Uri().UriDes() );
       
   756 
       
   757         HBufC* parsed = HBufC::NewLC( parameter->Length() );                 
       
   758         parsed->Des().Copy(*parameter);
       
   759                          
       
   760         if ( !iLauncher )
       
   761             {
       
   762             iLauncher = CBrowserLauncher::NewL();
       
   763             } 
       
   764 
       
   765         HBufC* urlToLaunch = HBufC::NewLC( 
       
   766             parsed->Length() + KUrlLaunchParameter.iTypeLength );
       
   767         urlToLaunch->Des().Append( KUrlLaunchParameter );
       
   768         urlToLaunch->Des().Append( *parsed );
       
   769         
       
   770 #if defined(__WINSCW__)
       
   771         //custom ap overriden settings cannot be used in emulator environment
       
   772         iLauncher->LaunchBrowserEmbeddedL( *urlToLaunch, NULL, this );
       
   773 #else
       
   774         iConnUtil = CVcxConnectionUtility::InstanceL();
       
   775         TUint32 iap( 0 );
       
   776         User::LeaveIfError( iConnUtil->GetIap( iap, ETrue ) );
       
   777 
       
   778         TBrowserOverriddenSettings overriddenSettings;
       
   779         overriddenSettings.SetBrowserSetting( EBrowserOverSettingsCustomAp, iap );
       
   780                 
       
   781         iLauncher->LaunchBrowserEmbeddedL( *urlToLaunch, NULL, this, &overriddenSettings );
       
   782 #endif
       
   783 
       
   784         CleanupStack::PopAndDestroy( urlToLaunch );
       
   785         CleanupStack::PopAndDestroy( parsed );
       
   786         CleanupStack::PopAndDestroy( parameter );
       
   787         CleanupStack::PopAndDestroy( inetUri );
       
   788         }
       
   789     }
       
   790 
       
   791 // -----------------------------------------------------------------------------
       
   792 // 
       
   793 // -----------------------------------------------------------------------------
       
   794 //
       
   795 void CVcxNsSettingsViewServiceSelection::RemoveCommandsFromCba( CEikButtonGroupContainer& aCba )
       
   796     {
       
   797     TInt nPos1 = aCba.PositionById( EAknSoftkeyOptions );
       
   798     if ( nPos1 != KErrNotFound )
       
   799         {
       
   800         aCba.RemoveCommandObserver( nPos1 ); 
       
   801         aCba.RemoveCommandFromStack( nPos1, EAknSoftkeyOptions );
       
   802         }
       
   803     TInt nPos2 = aCba.PositionById( EVcSettingsViewSoftkeyDone );
       
   804     if ( nPos2 != KErrNotFound )
       
   805         {
       
   806         aCba.RemoveCommandObserver( nPos2 );
       
   807         aCba.RemoveCommandFromStack( nPos2, EVcSettingsViewSoftkeyDone );
       
   808         }
       
   809     }