wvuing/wvuiave/AppSrc/CCAUINGUtils.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     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:  General utility class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CCAUINGUtils.h"
       
    22 #include	"CCAAppUi.h"
       
    23 #include 	"MCAProcessManager.h"
       
    24 #include 	"MCAMainViewArrayPC.h"
       
    25 #include    "CCAWaitNote.h"
       
    26 #include    "IMDialogUtils.h"
       
    27 #include    "IMNoteMapper.h"
       
    28 #include    "PublicEngineDefinitions.h"
       
    29 #include    "CCAPCUtils.h"
       
    30 #include    "aknnotewrappers.h"
       
    31 #include	"CCAAppUi.h"
       
    32 #include    "CCAStatusPaneHandler.h"
       
    33 
       
    34 #include    <ChatNG.rsg>
       
    35 #include    <hlplch.h>
       
    36 #include    <csxhelp/imng.hlp.hrh>
       
    37 #include    <eikmenup.h>
       
    38 
       
    39 #include	<StringLoader.h>
       
    40 #include    "ImpsCSPAllErrors.h"
       
    41 #include    <PEngWVPresenceErrors2.h>   // wv error codes
       
    42 // The Settings have been moved to Cenrep (also retained in the Resource file),
       
    43 // so the enums for keys and central repository header is added here
       
    44 #include 	"VariantKeys.h"
       
    45 
       
    46 #include    "IMUtils.h"
       
    47 #include    "CAUtils.h"
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CCAUINGUtils::NewContactlistL
       
    51 // Creates a new contact list and shows the appropriate dialogs
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 TInt CCAUINGUtils::NewContactListL( TInt& aIndex )
       
    55     {
       
    56     CCAAppUi* appUi = static_cast<CCAAppUi*>( CCoeEnv::Static()->AppUi() );
       
    57     MCAMainViewArrayPC* mainViewArrayPC = appUi->GetProcessManager().GetArrayInterface();
       
    58     TInt capitalizeListname( IMUtils::IntResourceValueL( RSC_CHAT_VARIATION_CONTACT_LISTS_CAPITALIZED ) );
       
    59     // ask name for new list
       
    60     HBufC* name = HBufC::NewLC( KMaxWVIDLength );
       
    61     TPtr namePtr( name->Des() );
       
    62     TInt err( KErrCancel );
       
    63 
       
    64     // We loop until we get a valid name or user cancels
       
    65     do
       
    66         {
       
    67 
       
    68         TInt result( IMDialogUtils::DisplayTextQueryDialogL( namePtr,
       
    69                                                              R_QTN_CHAT_CONTACT_LIST_NAME_QUERY,
       
    70                                                              R_CHATCLIENT_CONVLIST_RECIP_QUERY,
       
    71                                                              ETrue // T9
       
    72                                                            ) );
       
    73 
       
    74         if ( result == EAknSoftkeyOk || result == EAknSoftkeyDone )
       
    75             {
       
    76             // show wait note and create list
       
    77 
       
    78             TInt contactListsExists = mainViewArrayPC->ContactListsExistL();
       
    79             if ( contactListsExists == KErrGeneral )
       
    80                 {
       
    81                 //can not proceed
       
    82                 HBufC* text = StringLoader::LoadLC( R_QTN_CHAT_CONTACT_LIST_FAILED );
       
    83                 IMDialogUtils::DisplayErrorConfirmationNoteL( *text );
       
    84                 CleanupStack::PopAndDestroy( text );
       
    85                 return KErrGeneral;
       
    86                 }
       
    87 
       
    88             err = mainViewArrayPC->ListAlreadyExistsL( namePtr );
       
    89 
       
    90 
       
    91             if ( err == KErrNone )
       
    92                 {
       
    93                 CCAWaitNote* waitNote =
       
    94                     CCAWaitNote::ShowWaitNoteLC( R_QTN_GEN_NOTE_SAVING );
       
    95 
       
    96                 // UI CR  ID: 101-39727 : capitalizing contact listname
       
    97 
       
    98                 if ( capitalizeListname )
       
    99                     {
       
   100                     HBufC* capitalizedList = CAUtils::CapitalizeListNameL( *name );
       
   101                     CleanupStack::PushL( capitalizedList );
       
   102                     err = err  = mainViewArrayPC->CreateContactListL( *capitalizedList , aIndex );
       
   103                     CleanupStack::PopAndDestroy();
       
   104                     }
       
   105                 else
       
   106                     {
       
   107                     err  = mainViewArrayPC->CreateContactListL( *name , aIndex );
       
   108                     }
       
   109                 CleanupStack::PopAndDestroy(); // waitnote
       
   110                 }
       
   111 
       
   112             if ( err != KErrNone )
       
   113                 {
       
   114                 HBufC* text = NULL;
       
   115 
       
   116                 // Max number of contact lists exeeded
       
   117                 if ( err == KPEngNwErrMaxNumberOfContactListsReached )
       
   118                     {
       
   119                     text = StringLoader::LoadLC( R_QTN_CHAT_CONTACT_LISTS_FULL );
       
   120                     IMDialogUtils::DisplayErrorConfirmationNoteL( *text );
       
   121                     CleanupStack::PopAndDestroy( text );
       
   122                     }
       
   123 
       
   124                 // contact list already exists
       
   125                 else if ( err == KErrAlreadyExists ||
       
   126                           err == KPEngNwErrContactListAlreadyExists )
       
   127                     {
       
   128                     text = StringLoader::LoadLC(
       
   129                                R_QTN_FLDR_NAME_ALREADY_USED, namePtr );
       
   130                     IMDialogUtils::DisplayInformationNoteL( *text );
       
   131                     CleanupStack::PopAndDestroy( text );
       
   132                     }
       
   133 
       
   134                 // default error message
       
   135                 else
       
   136                     {
       
   137                     text = StringLoader::LoadLC( R_QTN_CHAT_CONTACT_LIST_FAILED );
       
   138                     IMDialogUtils::DisplayErrorConfirmationNoteL( *text );
       
   139                     CleanupStack::PopAndDestroy( text );
       
   140                     }
       
   141                 }
       
   142             }
       
   143         else
       
   144             {
       
   145             // User canceled the dialog
       
   146             err = KErrCancel;
       
   147             }
       
   148 
       
   149 
       
   150         } while ( err != KErrNone && err != KErrCancel
       
   151               && err != KPEngNwErrMaxNumberOfContactListsReached );
       
   152 
       
   153     CleanupStack::PopAndDestroy( name );
       
   154     return err;
       
   155     }
       
   156 
       
   157 
       
   158 // ---------------------------------------------------------
       
   159 // CCAUINGUtils::VerifyContactlistL()
       
   160 // Verifies the we have at least one contact list
       
   161 // else tries to create one.
       
   162 // ---------------------------------------------------------
       
   163 //
       
   164 CCAUINGUtils::TChatContactListCreationType CCAUINGUtils::VerifyContactlistL()
       
   165     {
       
   166     // Check that we have even one contact list where to add the contact
       
   167     CCAAppUi* appUi = static_cast<CCAAppUi*>( CCoeEnv::Static()->AppUi() );
       
   168     MCAMainViewArrayPC* mainViewArrayPC = appUi->GetProcessManager().GetArrayInterface();
       
   169 
       
   170     if ( mainViewArrayPC->ListCountL() == 0 )
       
   171         {
       
   172         IMDialogUtils::DisplayQueryDialogL( R_CHAT_NO_CONTACT_LISTS_QUERY );
       
   173         TInt initValue = KErrNotFound;
       
   174         if ( NewContactListL( initValue ) != KErrNone )
       
   175             {
       
   176             // contact list was not created
       
   177             return EChatNoContactList;
       
   178             }
       
   179         else
       
   180             {
       
   181             // new contact list was created
       
   182             return EChatContactListWasCreated;
       
   183             }
       
   184         }
       
   185 
       
   186     return EChatContactListExists;
       
   187     }
       
   188 
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // CCAUINGUtils::HandleErrorL
       
   192 // (other items were commented in a header).
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 void CCAUINGUtils::HandleErrorL( TInt aError )
       
   196     {
       
   197     if ( aError == ECSPPartiallySuccessful )
       
   198         {
       
   199         HandlePartialSuccessL();
       
   200         }
       
   201     else if ( aError != KErrNone )
       
   202         {
       
   203         User::Leave( aError );
       
   204         }
       
   205     }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // CCAUINGUtils::HandlePartialSuccessL
       
   209 // (other items were commented in a header).
       
   210 // -----------------------------------------------------------------------------
       
   211 //
       
   212 void CCAUINGUtils::HandlePartialSuccessL()
       
   213     {
       
   214     TInt errorCode( 0 );
       
   215     for ( TInt i( 0 ); i < CCAPCUtils::PartialSucessCountL(); i++ )
       
   216         {
       
   217         errorCode = CCAPCUtils::GetErrorCodeL( i );
       
   218         if ( errorCode == ECSPInvalidParameter || errorCode == ECSPUnknownUserId )
       
   219             {
       
   220             errorCode = ECSPUnknownUserId;
       
   221             IMNoteMapper::ShowNoteL( errorCode );
       
   222             }
       
   223         }
       
   224     if ( CCAPCUtils::PartialSucessCountL() == 0 )
       
   225         {
       
   226         IMNoteMapper::ShowNoteL( EGeneralServerError );
       
   227         }
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // CCAUINGUtils::SetTitleL
       
   232 // (other items were commented in a header).
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 void CCAUINGUtils::SetTitleL( TInt aResourceId, const TUid aViewId )
       
   236     {
       
   237     HBufC* chatListViewTitle =
       
   238         CCoeEnv::Static()->AllocReadResourceLC( aResourceId );
       
   239     CCAAppUi* appUi = static_cast<CCAAppUi*>( CCoeEnv::Static()->AppUi() );
       
   240     CCAStatusPaneHandler* statusPane = appUi->CAStatusPane();
       
   241 
       
   242     statusPane->SetTitleL( *chatListViewTitle );
       
   243     CleanupStack::PopAndDestroy( chatListViewTitle );
       
   244     statusPane->ShowTabGroupL( aViewId );
       
   245     }
       
   246 
       
   247 // -----------------------------------------------------------------------------
       
   248 // CCAUINGUtils::DisplayErrorNoteL
       
   249 // (other items were commented in a header).
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 void CCAUINGUtils::DisplayErrorNoteL( TInt aResourceId )
       
   253     {
       
   254     HBufC* noteBuf = CCoeEnv::Static()->AllocReadResourceLC( aResourceId );
       
   255     CAknErrorNote* errorNote = new( ELeave ) CAknErrorNote();
       
   256     errorNote->ExecuteLD( *noteBuf );
       
   257     CleanupStack::PopAndDestroy( noteBuf );
       
   258     }