wvuing/wvuiprocess/Src/CCAInvitationPC.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:  Singleton base class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CCAInvitationPC.h"
       
    22 #include    "MCAInvitationObserverPC.h"
       
    23 
       
    24 #include 	"MCAMessage.h"
       
    25 #include 	"CCAStorageManagerFactory.h"
       
    26 #include    "MCAStoredContact.h"
       
    27 #include    "MCAStoredContacts.h"
       
    28 #include 	"MCAInvite.h"
       
    29 
       
    30 #include 	"MCAMainViewArrayPC.h"
       
    31 #include 	"MCAInvitation.h"
       
    32 
       
    33 #include 	"ChatDebugAssert.h"
       
    34 #include 	"ChatDebugPrint.h"
       
    35 
       
    36 
       
    37 #include    "MCAChatInterface.h"
       
    38 #include 	"MCAProcessManager.h"
       
    39 #include 	"CCAProcessManagerFactory.h"
       
    40 #include    "CAUtils.h"
       
    41 #include 	"CCAEngine.h"
       
    42 #include    "CCALoginPC.h"
       
    43 #include    <e32std.h>
       
    44 
       
    45 
       
    46 // ============================ MEMBER FUNCTIONS ===============================
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CCAInvitationPC::CCAInvitationPC
       
    50 // C++ default constructor can NOT contain any code, that
       
    51 // might leave.
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CCAInvitationPC::CCAInvitationPC( CCAEngine& aEngine, MCAChatInterface& aChatInterface )
       
    55         : iEngine( aEngine ),
       
    56         iChatInterface( aChatInterface ),
       
    57         iInviteInterface( *iEngine.GetInvitationInterface() )
       
    58     {
       
    59     }
       
    60 
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CCAInvitationPC::CCAInvitationPC
       
    64 // C++ default constructor can NOT contain any code, that
       
    65 // might leave.
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CCAInvitationPC* CCAInvitationPC::NewL( CCAEngine& aEngine, MCAChatInterface& aChatInterface )
       
    69     {
       
    70     CCAInvitationPC* self = new ( ELeave ) CCAInvitationPC( aEngine, aChatInterface );
       
    71     CleanupStack::PushL( self );
       
    72     self->ConstructL();
       
    73     CleanupStack::Pop( self );
       
    74     return self;
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CCAInvitationPC::~CCAInvitationPC
       
    79 // Destructor
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 CCAInvitationPC::~CCAInvitationPC()
       
    83     {
       
    84 
       
    85     iInvitationArray.Reset();
       
    86     iInvitationArray.Close();
       
    87     iEngine.GetInvitationInterface()->RemoveInviteObserver( this );
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CCAInvitationPC::ConstructL
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 void CCAInvitationPC::ConstructL( )
       
    95     {
       
    96     // codescanner warning can be ignored
       
    97     iInviteInterface.PopulateInviteList( iInvitationArray );
       
    98     iCurrentActiveInvitation = 0;
       
    99     iEngine.GetInvitationInterface()->AddInviteObserver( this );
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CCAInvitationPC::RegisterObserver
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 void CCAInvitationPC::RegisterObserver( MCAInvitationObserverPC* aObserver )
       
   107     {
       
   108     ASSERT( aObserver );
       
   109 
       
   110     iObserver = aObserver;
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CCAInvitationPC::UnRegisterObserver
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 void CCAInvitationPC::UnRegisterObserver()
       
   118     {
       
   119 
       
   120     iObserver = NULL;
       
   121     }
       
   122 
       
   123 
       
   124 
       
   125 // ---------------------------------------------------------
       
   126 // CCAInvitationPC::InvitationUserIDL
       
   127 // ---------------------------------------------------------
       
   128 //
       
   129 const TDesC& CCAInvitationPC::InvitationUserIDL( TInt aIndex )
       
   130     {
       
   131     if ( aIndex < 0 || aIndex >= iInvitationArray.Count() )
       
   132         {
       
   133         CHAT_DP( D_CHAT_LIT( "!!! check your logic, trying to delete at %d !!!" ),
       
   134                  aIndex );
       
   135         return KNullDesC();
       
   136         }
       
   137 
       
   138     MCAInvitation* inv = iInvitationArray[ aIndex ];
       
   139     return inv->UserID();
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------
       
   143 // CCAInvitationPC::InvUserIdentificationL
       
   144 // ---------------------------------------------------------
       
   145 //
       
   146 TPtrC CCAInvitationPC::InvUserIdentificationL( TInt aIndex )
       
   147     {
       
   148 
       
   149     if ( aIndex < 0 || aIndex >= iInvitationArray.Count() )
       
   150         {
       
   151         CHAT_DP( D_CHAT_LIT( "!!! check your logic, trying to delete at %d !!!" ),
       
   152                  aIndex );
       
   153         return KNullDesC();
       
   154         }
       
   155     MCAInvitation* inv = iInvitationArray[ aIndex ];
       
   156     MCAStoredContacts* contacts = CCAStorageManagerFactory::ContactListInterfaceL();
       
   157     return contacts->Identification( inv->UserID() );
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------
       
   161 // CCAInvitationPC::ReceivedAt
       
   162 // ---------------------------------------------------------
       
   163 //
       
   164 TTime CCAInvitationPC::ReceivedAt( TInt aIndex )
       
   165     {
       
   166     TTime receviedat( 0 );
       
   167     if ( aIndex < 0 || aIndex >= iInvitationArray.Count() )
       
   168         {
       
   169         CHAT_DP( D_CHAT_LIT( "!!! check your logic, trying to delete at %d !!!" ),
       
   170                  aIndex );
       
   171         return receviedat;
       
   172         }
       
   173     MCAInvitation* inv = iInvitationArray[ aIndex ];
       
   174     receviedat = inv->ReceivedAt();
       
   175     return receviedat;
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------
       
   179 // CCAInvitationPC::Message
       
   180 // ---------------------------------------------------------
       
   181 //
       
   182 const TDesC& CCAInvitationPC::Message( TInt aIndex )
       
   183     {
       
   184 
       
   185     if ( aIndex < 0 || aIndex >= iInvitationArray.Count() )
       
   186         {
       
   187         CHAT_DP( D_CHAT_LIT( "!!! check your logic, trying to delete at %d !!!" ),
       
   188                  aIndex );
       
   189         return KNullDesC;
       
   190         }
       
   191     MCAInvitation* inv = iInvitationArray[ aIndex ];
       
   192     return inv->Message();
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------
       
   196 // CCAInvitationPC::ReceivedAt
       
   197 // ---------------------------------------------------------
       
   198 //
       
   199 const TDesC& CCAInvitationPC::GroupName( TInt aIndex )
       
   200     {
       
   201     if ( aIndex < 0 || aIndex >= iInvitationArray.Count() )
       
   202         {
       
   203         CHAT_DP( D_CHAT_LIT( "!!! check your logic, trying to delete at %d !!!" ),
       
   204                  aIndex );
       
   205         return KNullDesC;
       
   206         }
       
   207     MCAInvitation* inv = iInvitationArray[ aIndex ];
       
   208     return inv->GroupId();
       
   209     }
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // CCAInvitationPC: SetActiveInvitation
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 void CCAInvitationPC::SetActiveInvitation( const TInt aIndex )
       
   216     {
       
   217     iCurrentActiveInvitation = aIndex;
       
   218 
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------
       
   222 // CCAPrivateChatListContainer::HandleInvitation()
       
   223 // (other items were commented in a header).
       
   224 // ---------------------------------------------------------
       
   225 //
       
   226 void CCAInvitationPC::HandleInvitationEventL(
       
   227     TInviteEventType aEvent, const MCAInvitation* aInvitation  )
       
   228     {
       
   229     TInt count = iInvitationArray.Count();
       
   230     switch ( aEvent )
       
   231         {
       
   232         case ENewInvite:
       
   233             {
       
   234             iInvitationArray.Append( aInvitation );
       
   235 
       
   236             if ( iObserver )
       
   237                 {
       
   238                 iObserver->HandleInvitationEventL( TEnumsPC::ENewInvite, count );
       
   239                 }
       
   240             break;
       
   241             }
       
   242         case EInviteCancel: // Flowthrough
       
   243         case EInviteExpired:
       
   244             {
       
   245             TInt inviteIndex = FindIndexForInvitation( aInvitation );
       
   246             if ( inviteIndex != KErrNotFound )
       
   247                 {
       
   248                 Delete( inviteIndex );
       
   249                 }
       
   250             break;
       
   251             }
       
   252 
       
   253         default:
       
   254             {
       
   255             break;
       
   256             }
       
   257         }
       
   258     }
       
   259 
       
   260 // ---------------------------------------------------------
       
   261 // CCAInvitationPC::HandleInvitationResponse()
       
   262 // (other items were commented in a header).
       
   263 // ---------------------------------------------------------
       
   264 //
       
   265 void CCAInvitationPC::HandleInvitationResponse(
       
   266     TBool /*aAcceptance*/,
       
   267     const TDesC& /*aUserId*/,
       
   268     const TDesC& /*aGroupName*/,
       
   269     const TDesC& /*aResponse*/ )
       
   270     {
       
   271     // nothing to do here since CCAppUi shows the dialog
       
   272     }
       
   273 
       
   274 
       
   275 // ---------------------------------------------------------
       
   276 // CCAInvitationPC::GetActiveInvitationIndex()
       
   277 // (other items were commented in a header).
       
   278 // ---------------------------------------------------------
       
   279 //
       
   280 TInt CCAInvitationPC::GetActiveInvitationIndex()
       
   281     {
       
   282     return iCurrentActiveInvitation;
       
   283     }
       
   284 
       
   285 // ---------------------------------------------------------
       
   286 // CCAInvitationPC::IsInvitationUnread()
       
   287 // (other items were commented in a header).
       
   288 // ---------------------------------------------------------
       
   289 //
       
   290 TBool CCAInvitationPC::IsInvitationUnread( TInt aIndex )
       
   291     {
       
   292     if ( aIndex < 0 || aIndex >= iInvitationArray.Count() )
       
   293         {
       
   294         CHAT_DP( D_CHAT_LIT( "!!! check your logic, trying to delete at %d !!!" ),
       
   295                  aIndex );
       
   296         return KErrGeneral;
       
   297         }
       
   298     MCAInvitation* inv = iInvitationArray[ aIndex ];
       
   299     return inv->IsRead();
       
   300     }
       
   301 
       
   302 // ---------------------------------------------------------
       
   303 // CCAInvitationPC::SetInvitationAsReadL()
       
   304 // (other items were commented in a header).
       
   305 // ---------------------------------------------------------
       
   306 //
       
   307 void CCAInvitationPC::SetInvitationAsReadL( TInt aIndex )
       
   308     {
       
   309     if ( aIndex < 0 || aIndex >= iInvitationArray.Count() )
       
   310         {
       
   311         CHAT_DP( D_CHAT_LIT( "!!! check your logic, trying to delete at %d !!!" ),
       
   312                  aIndex );
       
   313         return;
       
   314         }
       
   315     MCAInvitation* inv = iInvitationArray[ aIndex ];
       
   316     inv->SetInvitationAsReadL();
       
   317     }
       
   318 
       
   319 // ---------------------------------------------------------
       
   320 // CCAInvitationPC::GetInvitationIndex()
       
   321 // Resolves the tabindex to invitationarrayindex.
       
   322 // (other items were commented in a header).
       
   323 // ---------------------------------------------------------
       
   324 //
       
   325 TInt CCAInvitationPC::GetInvitationIndex( TInt aTabIndex )
       
   326     {
       
   327     TInt count = InvitationCount();
       
   328     TInt invitationIndex = ( count - 1 ) - aTabIndex;
       
   329     return invitationIndex;
       
   330     }
       
   331 
       
   332 // -----------------------------------------------------------------------------
       
   333 // CCAInvitationPC: InvitationCount
       
   334 // -----------------------------------------------------------------------------
       
   335 //
       
   336 TInt CCAInvitationPC::InvitationCount( )
       
   337     {
       
   338     return iInvitationArray.Count();
       
   339     }
       
   340 
       
   341 // -----------------------------------------------------------------------------
       
   342 // CCAInvitationPC: InvitationCount
       
   343 // -----------------------------------------------------------------------------
       
   344 //
       
   345 void CCAInvitationPC::DeleteInvitationL( TInt aInvitationIndex )
       
   346     {
       
   347     if ( aInvitationIndex < 0 )   // negative indices shouldn't exist
       
   348         {
       
   349         CHAT_DP( D_CHAT_LIT( "!!! check your logic, trying to delete at %d !!!" ),
       
   350                  aInvitationIndex );
       
   351         return;
       
   352         }
       
   353 
       
   354     MCAInvitation* inv = iInvitationArray[  aInvitationIndex ];
       
   355     MCAMainViewArrayPC* mainViewArrayPC = CCAProcessManagerFactory::InstanceL()->
       
   356                                           GetProcessManager()->GetArrayInterface();
       
   357 
       
   358     mainViewArrayPC->FindInvitationAndDelete( inv->InviteID() );
       
   359 
       
   360     iInviteInterface.RemoveInvitationL( inv );
       
   361     iInvitationArray.Remove( aInvitationIndex );
       
   362 
       
   363     }
       
   364 
       
   365 // -----------------------------------------------------------------------------
       
   366 // CCAInvitationPC: RejectInvitationL()
       
   367 // -----------------------------------------------------------------------------
       
   368 //
       
   369 void CCAInvitationPC::ReplyInvitationL( const TInt aInvitationIndex,
       
   370                                         const TBool aInviteAccepted,
       
   371                                         const TDesC& aResponse,
       
   372                                         const TDesC& aScreenName )
       
   373     {
       
   374     if ( aInvitationIndex < 0 || aInvitationIndex >= iInvitationArray.Count() )
       
   375         {
       
   376         CHAT_DP( D_CHAT_LIT( "!!! check your logic, trying to delete at %d !!!" ),
       
   377                  aInvitationIndex );
       
   378         return;
       
   379         }
       
   380     MCAInvitation* inv = iInvitationArray[  aInvitationIndex ];
       
   381     MCAMainViewArrayPC* mainViewArrayPC = CCAProcessManagerFactory::InstanceL()->
       
   382                                           GetProcessManager()->GetArrayInterface();
       
   383     mainViewArrayPC->FindInvitationAndDelete( inv->InviteID() );
       
   384 
       
   385     iInviteInterface.ReplyInvitationL( inv, aInviteAccepted, aResponse, aScreenName );
       
   386     iInvitationArray.Remove( aInvitationIndex );
       
   387 
       
   388     }
       
   389 
       
   390 // -----------------------------------------------------------------------------
       
   391 // CCAInvitationPC: RejectReason()
       
   392 // -----------------------------------------------------------------------------
       
   393 //
       
   394 HBufC* CCAInvitationPC::RejectReason()
       
   395     {
       
   396     return iInviteInterface.RejectReasonPtr();
       
   397     }
       
   398 
       
   399 // -----------------------------------------------------------------------------
       
   400 // CCAInvitationPC::FindIndexForInvitation
       
   401 // (other items were commented in a header).
       
   402 // -----------------------------------------------------------------------------
       
   403 //
       
   404 TInt CCAInvitationPC::FindIndexForInvitation(
       
   405     const MCAInvitation* aInvitation ) const
       
   406     {
       
   407     return iInvitationArray.Find( aInvitation );
       
   408     }
       
   409 
       
   410 // ---------------------------------------------------------
       
   411 // CCAInvitationPC::Delete
       
   412 // (other items were commented in a header).
       
   413 // ---------------------------------------------------------
       
   414 //
       
   415 void CCAInvitationPC::Delete( TInt aIndex )
       
   416     {
       
   417     if ( aIndex < 0 )   // negative indices shouldn't exist
       
   418         {
       
   419         CHAT_DP( D_CHAT_LIT( "!!! check your logic, trying to delete at %d !!!" ),
       
   420                  aIndex );
       
   421         return;
       
   422         }
       
   423     else if ( aIndex < iInvitationArray.Count() )
       
   424         {
       
   425         iInvitationArray.Remove( aIndex );
       
   426         }
       
   427     }
       
   428 
       
   429 // ---------------------------------------------------------
       
   430 // CCAInvitationPC::DeleteSingleListViewInvitationL
       
   431 // (other items were commented in a header).
       
   432 // ---------------------------------------------------------
       
   433 //
       
   434 void CCAInvitationPC::DeleteSingleListViewInvitationL( const TDesC& aInviteID /*TInt aIndex*/ )
       
   435     {
       
   436     for ( TInt index = 0; index < iInvitationArray.Count();index++ )
       
   437         {
       
   438         MCAInvitation* inviteItem =
       
   439             dynamic_cast<MCAInvitation*>( iInvitationArray[ index ] );
       
   440 
       
   441         if ( CAUtils::NeutralCompare( aInviteID, inviteItem->InviteID() ) == 0 )
       
   442             {
       
   443             iInviteInterface.RemoveInvitationL( inviteItem );
       
   444             iInvitationArray.Remove( index );
       
   445             break;
       
   446             }
       
   447         }
       
   448     }
       
   449 
       
   450 // ---------------------------------------------------------
       
   451 // CCAInvitationPC::FindInvitationIndex
       
   452 // (other items were commented in a header).
       
   453 // ---------------------------------------------------------
       
   454 //
       
   455 TInt CCAInvitationPC::FindInvitationIndex( const TDesC& aWvId, TTime aInviteTime )
       
   456     {
       
   457     for ( TInt index = 0; index < iInvitationArray.Count(); index++ )
       
   458         {
       
   459         MCAInvitation* inv = iInvitationArray[ index ];
       
   460 
       
   461         if ( ( CAUtils::NeutralCompare( aWvId, inv->UserID() ) == 0 ) &&
       
   462              ( inv->ReceivedAt() == aInviteTime ) )
       
   463             {
       
   464             return 	index;
       
   465             }
       
   466         }
       
   467 
       
   468     return -1;
       
   469 
       
   470     }
       
   471 
       
   472 
       
   473 // ---------------------------------------------------------
       
   474 // CCAInvitationPC::FindInvitationIndex
       
   475 // Based on invite id. The ablove method based on user id and
       
   476 // time will be removed.
       
   477 // ---------------------------------------------------------
       
   478 //
       
   479 TInt CCAInvitationPC::FindInvitationIndex( const TDesC& aInviteId )
       
   480     {
       
   481     for ( TInt index = 0; index < iInvitationArray.Count(); index++ )
       
   482         {
       
   483         MCAInvitation* inv = iInvitationArray[ index ];
       
   484 
       
   485         if (  CAUtils::NeutralCompare( aInviteId, inv->InviteID() ) == 0  )
       
   486             {
       
   487             return 	index;
       
   488             }
       
   489         }
       
   490 
       
   491     return -1;
       
   492 
       
   493     }
       
   494 // ---------------------------------------------------------
       
   495 // CCAInvitationPC::UnreadInvitesCount
       
   496 // (other items were commented in a header).
       
   497 // ---------------------------------------------------------
       
   498 //
       
   499 TInt CCAInvitationPC::UnreadInvitesCount() const
       
   500     {
       
   501     return iEngine.GetInvitationInterface()->UnreadInvitesCount();
       
   502     }
       
   503 
       
   504 // ---------------------------------------------------------
       
   505 // CCAInvitationPC::UnreadInvitesCount
       
   506 // (other items were commented in a header).
       
   507 // ---------------------------------------------------------
       
   508 
       
   509 const TDesC& CCAInvitationPC::UnresdInvitationInfo()
       
   510     {
       
   511     for ( TInt index = 0; index < iInvitationArray.Count(); index++ )
       
   512         {
       
   513         MCAInvitation* inv = iInvitationArray[ index ];
       
   514         if ( ! inv->IsRead() )
       
   515             {
       
   516             return inv->InviteID();
       
   517             }
       
   518         }
       
   519 
       
   520     return KNullDesC();
       
   521     }
       
   522 
       
   523 // ---------------------------------------------------------
       
   524 // CCAInvitationPC::UnreadInvitesCount
       
   525 // (other items were commented in a header).
       
   526 // ---------------------------------------------------------
       
   527 //
       
   528 const TDesC& CCAInvitationPC::GetInviteID( TInt aInvitationIndex )
       
   529     {
       
   530     for ( TInt index = 0; index < iInvitationArray.Count(); index++ )
       
   531         {
       
   532         if ( index == aInvitationIndex )
       
   533             {
       
   534             MCAInvitation* inv = iInvitationArray[ index ];
       
   535             return inv->InviteID();
       
   536             }
       
   537         }
       
   538 
       
   539     return KNullDesC();
       
   540     }
       
   541 
       
   542 
       
   543 
       
   544 //End Of File