cmmanager/cmmgr/Framework/Src/uncatdlg.cpp
changeset 20 9c97ad6591ae
parent 18 fcbbe021d614
child 21 b8e8e15e80f2
child 23 7ec726f93df1
child 28 860702281757
equal deleted inserted replaced
18:fcbbe021d614 20:9c97ad6591ae
     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 "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:  Implementation of CUncatDlg.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <avkon.hrh>
       
    19 #include <eikdef.h>
       
    20 #include <eikenv.h>
       
    21 #include <eikedwin.h>
       
    22 #include <cmmanager.rsg>
       
    23 #include <aknnavide.h>
       
    24 #include <akntitle.h>
       
    25 #include <eikmenup.h>
       
    26 #include <data_caging_path_literals.hrh>
       
    27 #include <StringLoader.h>
       
    28 #include <AknIconArray.h>
       
    29 
       
    30 #include "cmmanager.hrh"
       
    31 #include "uncatdlg.h"
       
    32 #include "cmlistitem.h"
       
    33 #include "cmlistitemlist.h"
       
    34 #include <cmpluginbaseeng.h>
       
    35 #include <cmpluginbase.h>
       
    36 #include "cmdestinationimpl.h"
       
    37 #include <cmcommonui.h>
       
    38 #include <cmcommonconstants.h>    
       
    39 #include <cmpbasesettingsdlg.h>
       
    40 #include "cmlistboxmodel.h"
       
    41 #include "selectdestinationdlg.h"
       
    42 #include "cmlogger.h"
       
    43 
       
    44 using namespace CMManager;
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // CUncatDlg::ConstructAndRunLD
       
    48 // Constructs the dialog and runs it.
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 TInt CUncatDlg::ConstructAndRunLD( TUint32 aHighlight,
       
    52                                    TUint32& aSelected )
       
    53     {
       
    54     CleanupStack::PushL( this );
       
    55     iHighlight = aHighlight;
       
    56     iSelected = &aSelected;
       
    57     ConstructL( R_CM_MENUBAR );
       
    58     PrepareLC(R_CM_DIALOG);
       
    59     CleanupStack::Pop( this );  // it will be PushL-d by ExecuteLD...
       
    60     iModel = new( ELeave ) CCmListboxModel();
       
    61     //destructed in base class destructor
       
    62     iInfoPopupNoteController = CAknInfoPopupNoteController::NewL();
       
    63 
       
    64     // Trace changes in CommsDat
       
    65     iCmManager->WatcherRegisterL( this );
       
    66     
       
    67     return RunLD();
       
    68     }
       
    69     
       
    70 // ---------------------------------------------------------------------------
       
    71 // CUncatDlg::NewL()
       
    72 // Two-phase dconstructor, second phase is ConstructAndRunLD
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 CUncatDlg* CUncatDlg::NewL(CCmManagerImpl* aCmManager )
       
    76     {
       
    77     CUncatDlg* self = new (ELeave) CUncatDlg( aCmManager );
       
    78     return self;
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CUncatDlg::CUncatDlg()
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CUncatDlg::CUncatDlg( CCmManagerImpl* aCmManager )
       
    86     : CCmDlg( aCmManager, NULL, NULL )
       
    87     , iCmUncatItems(KCmArraySmallGranularity)
       
    88     {
       
    89     CLOG_CREATE;
       
    90     CLOG_ATTACH( this, iCmManager );
       
    91     }
       
    92     
       
    93 // ---------------------------------------------------------------------------
       
    94 // CUncatDlg::~CUncatDlg
       
    95 // Destructor
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 CUncatDlg::~CUncatDlg()
       
    99     {
       
   100     CLOG_WRITE( "CUncatDlg::~CUncatDlg" );
       
   101     CleanupUncatArray();   
       
   102     CLOG_CLOSE;
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CUncatDlg::DynInitMenuPaneL
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 void CUncatDlg::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )
       
   110     {
       
   111     TBool hideAdd ( EFalse );
       
   112     TBool hideMove ( EFalse );
       
   113     TBool hideCopy( EFalse );
       
   114     TBool hidePrioritise( EFalse );
       
   115     
       
   116     CCmDlg::DynInitMenuPaneL( aResourceId, aMenuPane );
       
   117     if ( aResourceId == R_CM_MENU )
       
   118         {
       
   119         // There are no destinatons to move to OR
       
   120         // the highlighted connection method is in use
       
   121         if ( !iCmManager->DestinationCountL() )
       
   122             {
       
   123             hideMove = ETrue;
       
   124             }
       
   125 
       
   126         // No priorities in Uncategorized -> always disabled
       
   127         hidePrioritise = ETrue;
       
   128 
       
   129         aMenuPane->SetItemDimmed( ECmManagerUiCmdCmAdd, hideAdd );
       
   130         aMenuPane->SetItemDimmed( ECmManagerUiCmdCmPrioritise, hidePrioritise  );
       
   131         aMenuPane->SetItemDimmed( ECmManagerUiCmdCmCopyToOtherDestination, hideCopy );
       
   132         aMenuPane->SetItemDimmed( ECmManagerUiCmdCmCopyToOtherDestination, hideMove );
       
   133         }
       
   134     }
       
   135     
       
   136 // ---------------------------------------------------------------------------
       
   137 // CUncatDlg::InitTextsL
       
   138 // called before the dialog is shown
       
   139 // to initialize localized textual data
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 void CUncatDlg::InitTextsL()
       
   143     {
       
   144     // set pane text if neccessary...
       
   145     // pane text needed if not pop-up...
       
   146     HBufC* primary = 
       
   147               iEikonEnv->AllocReadResourceLC( R_CMMANAGERUI_EMPTY_METHOD_VIEW_PRIMARY );
       
   148     HBufC* secondary = 
       
   149               iEikonEnv->AllocReadResourceLC( R_CMMANAGERUI_EMPTY_METHOD_VIEW_SECONDARY );
       
   150     CDesCArrayFlat* items = new (ELeave) CDesCArrayFlat(2);
       
   151     CleanupStack::PushL(items);
       
   152     items->AppendL(primary->Des()); 
       
   153     items->AppendL(secondary->Des());      
       
   154     HBufC* emptyText = 
       
   155           StringLoader::LoadLC( R_TWO_STRING_FOR_EMPTY_VIEW , *items);              
       
   156     iListbox->View()->SetListEmptyTextL( *emptyText );    
       
   157     CleanupStack::PopAndDestroy( emptyText );
       
   158     CleanupStack::PopAndDestroy( items );
       
   159     CleanupStack::PopAndDestroy( secondary );
       
   160     CleanupStack::PopAndDestroy( primary );
       
   161 
       
   162     iStatusPane = iEikonEnv->AppUiFactory()->StatusPane();
       
   163     iTitlePane =
       
   164         ( CAknTitlePane* )iStatusPane->ControlL(
       
   165                             TUid::Uid( EEikStatusPaneUidTitle ) );
       
   166 
       
   167     iOldTitleText = iTitlePane->Text()->AllocL();
       
   168     HBufC* name = StringLoader::LoadLC( R_CMMANAGERUI_DEST_UNCATEGORIZED );
       
   169     iTitlePane->SetTextL( *name );
       
   170     CleanupStack::PopAndDestroy( name );
       
   171     iNaviPane = ( CAknNavigationControlContainer* ) 
       
   172                     iStatusPane->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) );
       
   173     iNaviDecorator = iNaviPane->CreateNavigationLabelL( KNullDesC );
       
   174     iNaviPane->PushL( *iNaviDecorator );
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // CUncatDlg::ProcessCommandL
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 void CUncatDlg::ProcessCommandL( TInt aCommandId )
       
   182     {
       
   183     if ( MenuShowing() )
       
   184         {
       
   185         HideMenu();
       
   186         }
       
   187 
       
   188     switch ( aCommandId )
       
   189         {
       
   190         case ECmManagerUiCmdCmMoveToOtherDestination:
       
   191             {
       
   192             if ( CurrentCML()->GetBoolAttributeL( ECmConnected ) )
       
   193                     {
       
   194                 TCmCommonUi::ShowNoteL( R_QTN_SET_NOTE_AP_IN_USE_EDIT,
       
   195                                     TCmCommonUi::ECmErrorNote );
       
   196                 }
       
   197             else
       
   198                 {
       
   199                 // The selected item will be at the same position
       
   200                 TInt selected = iListbox->CurrentItemIndex();
       
   201                 TInt noi = iListbox->Model()->NumberOfItems();
       
   202                 // If it is the last then the previous will be selected.
       
   203                 if( selected == noi-1 )
       
   204                     {
       
   205                     selected--;
       
   206                     }
       
   207                 
       
   208                 TRAPD( err, CCmDlg::ProcessCommandL(
       
   209                                 ECmManagerUiCmdCmCopyToOtherDestination ) );
       
   210                 if ( err == KErrCancel )
       
   211                     {
       
   212                     break;
       
   213                     }
       
   214                 else
       
   215                     {
       
   216                     User::LeaveIfError( err );
       
   217                     }
       
   218                     
       
   219                 if ( iListbox->Model()->NumberOfItems() )
       
   220                     {
       
   221                     //first item cannot be deleted
       
   222                     iListbox->ScrollToMakeItemVisible( selected);
       
   223                     iListbox->SetCurrentItemIndexAndDraw( selected );                            
       
   224                     }
       
   225                 else
       
   226                     {
       
   227                     TCmCommonUi::ShowNoteL( R_QTN_NETW_CONSET_INFO_UNCAT_EMPTY,
       
   228                                             TCmCommonUi::ECmInfoNote );
       
   229                     iCmManager->WatcherUnRegister();       
       
   230                     TryExitL( KDialogUserBack );                                
       
   231                     }
       
   232                 }
       
   233             }
       
   234             break;
       
   235             
       
   236         case EAknSoftkeyClear:
       
   237         case ECmManagerUiCmdCmDelete:            
       
   238             {
       
   239             CCmPluginBase* cm = CurrentCML();
       
   240             
       
   241             if ( cm->GetBoolAttributeL( ECmProtected ) )
       
   242                 {
       
   243                 TCmCommonUi::ShowNoteL( R_CMWIZARD_CANNOT_PERFORM_FOR_PROTECTED,
       
   244                                         TCmCommonUi::ECmErrorNote );
       
   245                                         
       
   246                 break;
       
   247                 }
       
   248            
       
   249             if ( cm->GetBoolAttributeL( ECmIsLinked ) )//same check as KErrLocked below
       
   250                 {
       
   251                 TCmCommonUi::ShowNoteL( R_QTN_NETW_CONSET_INFO_CANNOT_DELETE_VIRTUAL_REF,
       
   252                                         TCmCommonUi::ECmErrorNote );
       
   253                 
       
   254                 break;
       
   255                 }
       
   256            
       
   257             if ( cm->GetBoolAttributeL( ECmConnected ) )//same check as KErrInUse below
       
   258                 {
       
   259                 TCmCommonUi::ShowNoteL( R_CMMANAGERUI_INFO_CM_IN_USE_CANNOT_DELETE,
       
   260                                         TCmCommonUi::ECmErrorNote );
       
   261                 
       
   262                 break;
       
   263                 }
       
   264 
       
   265             HBufC* cmName = cm->GetStringAttributeL(ECmName);
       
   266             CleanupStack::PushL(cmName);
       
   267             
       
   268             if ( TCmCommonUi::ShowConfirmationQueryL( 
       
   269                                     R_CMMANAGERUI_QUEST_CM_DELETE, *cmName ) )
       
   270                 {
       
   271                 TRAPD( err, CurrentCML()->DeleteL( ETrue ) );
       
   272 
       
   273                 switch ( err )
       
   274                     {
       
   275                     case KErrInUse:
       
   276                         {
       
   277                         TCmCommonUi::ShowNoteL
       
   278                             ( R_CMMANAGERUI_INFO_CM_IN_USE_CANNOT_DELETE,
       
   279                               TCmCommonUi::ECmErrorNote );
       
   280                         }
       
   281                         break;
       
   282                         
       
   283                     case KErrLocked:
       
   284                         {
       
   285                         TCmCommonUi::ShowNoteL
       
   286                             ( R_QTN_NETW_CONSET_INFO_CANNOT_DELETE_VIRTUAL_REF,
       
   287                               TCmCommonUi::ECmErrorNote );
       
   288                         }
       
   289                         break;
       
   290                         
       
   291                     case KErrNone:
       
   292                         {
       
   293                         HandleListboxDataChangeL();
       
   294 
       
   295                         if ( !iListbox->Model()->NumberOfItems() )
       
   296                             {
       
   297                             TCmCommonUi::ShowNoteL( R_QTN_NETW_CONSET_INFO_UNCAT_EMPTY,
       
   298                                                     TCmCommonUi::ECmInfoNote );
       
   299                             iCmManager->WatcherUnRegister();       
       
   300                             TryExitL( KDialogUserBack );                                
       
   301                             }
       
   302                         }
       
   303                         break;
       
   304 
       
   305                     default:
       
   306                         {
       
   307                         }
       
   308                     }
       
   309 
       
   310                 }
       
   311             CleanupStack::PopAndDestroy( cmName );         
       
   312          
       
   313             }
       
   314             break;
       
   315             
       
   316         case ECmManagerUiCmdCmAdd:
       
   317         case ECmManagerUiCmdCmCopyToOtherDestination:
       
   318         case ECmManagerUiCmdCmPrioritise:
       
   319             {
       
   320             TCmCommonUi::ShowNoteL( R_CMWIZARD_CANNOT_PERFORM_FOR_PROTECTED,
       
   321                                     TCmCommonUi::ECmErrorNote );
       
   322             }
       
   323             break;
       
   324             
       
   325         default:
       
   326             {
       
   327             CCmDlg::ProcessCommandL(aCommandId);
       
   328             }        
       
   329         }        
       
   330     }
       
   331     
       
   332 // ---------------------------------------------------------------------------
       
   333 // CUncatDlg::CurrentCML
       
   334 // called before the dialog is shown to initialize listbox data
       
   335 // ---------------------------------------------------------------------------
       
   336 //
       
   337 CCmPluginBase* CUncatDlg::CurrentCML()
       
   338     {
       
   339     return CMByIndexL( iListbox->CurrentItemIndex() );
       
   340     }    
       
   341     
       
   342 // ---------------------------------------------------------------------------
       
   343 // CUncatDlg::CMByIndexL
       
   344 // a connection method in the list
       
   345 // ---------------------------------------------------------------------------
       
   346 //
       
   347 CCmPluginBase* CUncatDlg::CMByIndexL( TInt aIndex )
       
   348     {
       
   349     TInt anIndex = iItemIndex[aIndex];    
       
   350     if( !iCmUncatItems[anIndex].iPlugin )
       
   351         {
       
   352         iCmUncatItems[anIndex].iPlugin = 
       
   353                                 iCmManager->GetConnectionMethodL( 
       
   354                                                 iCmUncatItems[anIndex].iCmId );
       
   355         }
       
   356     return iCmUncatItems[anIndex].iPlugin;
       
   357     }
       
   358 
       
   359 // ---------------------------------------------------------------------------
       
   360 // CUncatDlg::CMCount
       
   361 // number of cms in the list
       
   362 // ---------------------------------------------------------------------------
       
   363 //
       
   364 TInt CUncatDlg::CMCount()
       
   365     {
       
   366     return iCmUncatItems.Count();
       
   367     }
       
   368 
       
   369 // --------------------------------------------------------------------------
       
   370 // CUncatDlg::ConstructCMArrayL
       
   371 // --------------------------------------------------------------------------
       
   372 //
       
   373 void CUncatDlg::ConstructCMArrayL( RArray<TUint32>& aCmIds )
       
   374     {
       
   375     // empty the array - reuse
       
   376     CleanupUncatArray( ETrue );
       
   377     iCmManager->ConnectionMethodL( aCmIds, EFalse );
       
   378     CleanupClosePushL( aCmIds );
       
   379     
       
   380     for( TInt i = 0; i < aCmIds.Count(); ++i )
       
   381         {
       
   382         TUncatItem item;
       
   383         
       
   384         item.iPlugin = NULL;
       
   385         item.iCmId = aCmIds[i];
       
   386         
       
   387         User::LeaveIfError( iCmUncatItems.Append( item ) );
       
   388         }
       
   389     
       
   390     CleanupStack::Pop( &aCmIds );
       
   391     }
       
   392 
       
   393 // --------------------------------------------------------------------------
       
   394 // CCmDlg::ClearHiddenCMsFromArrayL
       
   395 // --------------------------------------------------------------------------
       
   396 //
       
   397 void CUncatDlg::ClearHiddenCMsFromArrayL( RArray<TUint32>& aCmIds )
       
   398     {
       
   399     TBool hidden( EFalse );
       
   400     TInt err( KErrNone );
       
   401     for ( TInt index = 0; index < aCmIds.Count(); index++ )
       
   402         {
       
   403         TUint recId = aCmIds[index];
       
   404         TRAP( err, hidden = iCmManager->GetConnectionMethodInfoBoolL( recId, ECmHidden ) );
       
   405         if ( err || hidden )
       
   406             {
       
   407             aCmIds.Remove( index );
       
   408             index--;
       
   409             // Remove the same item from iCmUncatItems array
       
   410             for( TInt i = 0; i < iCmUncatItems.Count(); i++ )
       
   411                 {
       
   412                 if( iCmUncatItems[i].iCmId == recId )
       
   413                     {
       
   414                     iCmUncatItems.Remove( i );
       
   415                     break;
       
   416                     }
       
   417                 }
       
   418             }
       
   419         }
       
   420     }
       
   421 
       
   422 
       
   423 // --------------------------------------------------------------------------
       
   424 // CUncatDlg::CleanupUncatArray
       
   425 // --------------------------------------------------------------------------
       
   426 //
       
   427 void CUncatDlg::CleanupUncatArray( TBool aReuseArray )
       
   428     {
       
   429     CLOG_WRITE( "CUncatDlg::CleanupUncatArray" );
       
   430     for ( TInt i = 0; i < iCmUncatItems.Count(); ++i )
       
   431         {
       
   432         CCmPluginBase* cm = iCmUncatItems[i].iPlugin;
       
   433         delete cm;
       
   434         }
       
   435     
       
   436     if ( aReuseArray )
       
   437         {
       
   438         iCmUncatItems.Reset();
       
   439         }
       
   440     else
       
   441         {
       
   442         iCmUncatItems.Close();
       
   443         }
       
   444     }
       
   445 
       
   446 // --------------------------------------------------------------------------
       
   447 // CUncatDlg::CommsDatChangesL
       
   448 // --------------------------------------------------------------------------
       
   449 //
       
   450 void CUncatDlg::CommsDatChangesL()
       
   451     {
       
   452     // Update list box
       
   453     HandleListboxDataChangeL();
       
   454     }