uifw/AknGlobalUI/AknDynamicSoftNote/src/AknDynamicSoftNoteObserver.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Dynamic soft notification observer.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "AknDynamicSoftNoteObserver.h"
       
    19 #include "AknDynamicSoftNotifier.h" 
       
    20 #include "aknsoftnoteconsts.h"
       
    21 
       
    22 //-----------------------------------------------------------------------------
       
    23 // CAknDynamicSoftNoteObserver::CAknDynamicSoftNoteObserver
       
    24 //-----------------------------------------------------------------------------
       
    25 // 
       
    26 CAknDynamicSoftNoteObserver::CAknDynamicSoftNoteObserver(
       
    27     CAknDynamicSoftNotifier& aDynamicSoftNotifier,
       
    28     MAknDynamicSoftNoteObserver* aClientApp, 
       
    29     TInt aNoteId ) :
       
    30     // members
       
    31     CActive(EPriorityStandard), 
       
    32     iClientApp(aClientApp), 
       
    33     iDynamicSoftNotifier(aDynamicSoftNotifier), 
       
    34     iNoteId(aNoteId)
       
    35     {
       
    36     CActiveScheduler::Add(this);
       
    37     }
       
    38 
       
    39 //-----------------------------------------------------------------------------
       
    40 // CAknDynamicSoftNoteObserver::ConstructL
       
    41 //-----------------------------------------------------------------------------
       
    42 //     
       
    43 void CAknDynamicSoftNoteObserver::ConstructL()
       
    44     {
       
    45     User::LeaveIfError(iSession.Connect());        
       
    46     User::LeaveIfError(iSession.PreAllocateDynamicSoftNoteEvent(iNoteId));
       
    47     IssueRequest();
       
    48     }   
       
    49      
       
    50 //-----------------------------------------------------------------------------
       
    51 // CAknDynamicSoftNoteObserver::~CAknDynamicSoftNoteObserver
       
    52 //-----------------------------------------------------------------------------
       
    53 //    
       
    54 CAknDynamicSoftNoteObserver::~CAknDynamicSoftNoteObserver()
       
    55     {
       
    56     Cancel();
       
    57     iSession.Close();
       
    58     }
       
    59     
       
    60 //-----------------------------------------------------------------------------
       
    61 // CAknDynamicSoftNoteObserver::NewL
       
    62 //-----------------------------------------------------------------------------
       
    63 //     
       
    64 EXPORT_C CAknDynamicSoftNoteObserver* CAknDynamicSoftNoteObserver::NewL(
       
    65     CAknDynamicSoftNotifier& aDynamicSoftNotifier, 
       
    66     MAknDynamicSoftNoteObserver* aClientApp, 
       
    67     TInt aNoteId)
       
    68     {
       
    69     CAknDynamicSoftNoteObserver* self = 
       
    70         CAknDynamicSoftNoteObserver::NewLC(aDynamicSoftNotifier, aClientApp, aNoteId);
       
    71         
       
    72     CleanupStack::Pop(self);
       
    73     return self;
       
    74     }
       
    75    
       
    76 //-----------------------------------------------------------------------------
       
    77 // CAknDynamicSoftNoteObserver::NewLC
       
    78 //-----------------------------------------------------------------------------
       
    79 //         
       
    80 EXPORT_C CAknDynamicSoftNoteObserver* CAknDynamicSoftNoteObserver::NewLC(
       
    81     CAknDynamicSoftNotifier& aDynamicSoftNotifier,
       
    82     MAknDynamicSoftNoteObserver* aClientApp, 
       
    83     TInt aNoteId)
       
    84     {
       
    85     CAknDynamicSoftNoteObserver* self = 
       
    86         new (ELeave) CAknDynamicSoftNoteObserver(aDynamicSoftNotifier, aClientApp, aNoteId);
       
    87         
       
    88     CleanupStack::PushL(self);
       
    89     self->ConstructL();
       
    90     return self;
       
    91     }     
       
    92    
       
    93 //-----------------------------------------------------------------------------
       
    94 // CAknDynamicSoftNoteObserver::NoteId
       
    95 //-----------------------------------------------------------------------------
       
    96 //     
       
    97 TInt CAknDynamicSoftNoteObserver::NoteId() const
       
    98     {
       
    99     return iNoteId;            
       
   100     }
       
   101     
       
   102 //-----------------------------------------------------------------------------
       
   103 // CAknDynamicSoftNoteObserver::RunL
       
   104 //-----------------------------------------------------------------------------
       
   105 //     
       
   106 void CAknDynamicSoftNoteObserver::RunL()
       
   107     {
       
   108     TInt err = iStatus.Int();
       
   109         
       
   110     if (err == KErrNone)
       
   111         {
       
   112         // Handle response.
       
   113         TInt actionId = iEventBuffer();
       
   114         
       
   115         // IssueRequest();
       
   116         switch (actionId)
       
   117             {
       
   118             case EAknDynamicSNoteEventAccepted:
       
   119                 {
       
   120                 iClientApp->NotificationAccepted(iNoteId);
       
   121                 break;
       
   122                 }
       
   123             case EAknDynamicSNoteEventCanceled:
       
   124                 {
       
   125                 iClientApp->NotificationCanceled(iNoteId);
       
   126                 break;
       
   127                 }
       
   128             default:
       
   129                 {
       
   130                 User::Panic(_L("DynamicSoftNote"), KErrArgument);
       
   131                 break;
       
   132                 }
       
   133             }
       
   134         }
       
   135 #ifdef _DEBUG
       
   136     else
       
   137         {
       
   138         _LIT(KDmsg1, "AknDynamicSoftNoteObserver, RunL(): iStatus not equal to KErrNone, err:%d");
       
   139         RDebug::Print(KDmsg1, err);
       
   140         }        
       
   141 #endif        
       
   142     
       
   143     iDynamicSoftNotifier.DeleteObserver(this);
       
   144     // This instance is deleted
       
   145     }
       
   146 
       
   147 //-----------------------------------------------------------------------------
       
   148 // CAknDynamicSoftNoteObserver::IssueRequest
       
   149 //-----------------------------------------------------------------------------
       
   150 //     
       
   151 void CAknDynamicSoftNoteObserver::IssueRequest()
       
   152     {
       
   153     iSession.NotifyDynamicSoftNoteEvent(iStatus, iEventBuffer);
       
   154     SetActive();    
       
   155     }
       
   156     
       
   157 //-----------------------------------------------------------------------------
       
   158 // CAknDynamicSoftNoteObserver::DoCancel
       
   159 //-----------------------------------------------------------------------------
       
   160 //    
       
   161 void CAknDynamicSoftNoteObserver::DoCancel()
       
   162     {
       
   163     iSession.CancelDynamicSoftNoteEventNotification();
       
   164     }    
       
   165    
       
   166 // End of File