instantmessagesalert/src/cimalertnotifierimpl.cpp
changeset 0 5e5d6b214f4f
equal deleted inserted replaced
-1:000000000000 0:5e5d6b214f4f
       
     1 /*
       
     2 * Copyright (c) 2009 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:  Publish and subscribe implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include    "cimalertnotifierimpl.h"
       
    20 #include    "mimalertnotifierkeyobserver.h"
       
    21 #include    "cimalertpropertyobserver.h"
       
    22 #include    <e32property.h>
       
    23 
       
    24 // ============================ MEMBER FUNCTIONS ===============================
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CIMAlertNotifierImpl::CIMAlertNotifierImpl
       
    28 // C++ default constructor can NOT contain any code, that
       
    29 // might leave.
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 CIMAlertNotifierImpl::CIMAlertNotifierImpl( MIMAlertNotifierKeyObserver* aObserver )
       
    33 :iObserver( aObserver )
       
    34     {
       
    35     }
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CIMAlertNotifierImpl::NewL
       
    39 // Two-phased constructor.
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CIMAlertNotifierImpl* CIMAlertNotifierImpl::NewL( MIMAlertNotifierKeyObserver* aObserver )
       
    43     {
       
    44     CIMAlertNotifierImpl* self = new( ELeave ) CIMAlertNotifierImpl( aObserver );
       
    45     return self;
       
    46     }
       
    47 
       
    48     
       
    49 // Destructor
       
    50 CIMAlertNotifierImpl::~CIMAlertNotifierImpl()
       
    51     {
       
    52     delete iPropWatcher;
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CIMAlertNotifierImpl::SetInt
       
    57 // (other items were commented in a header).
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 TInt CIMAlertNotifierImpl::SetInt( TNotifyKey aKey, TInt aValue )
       
    61 	{
       
    62 	TInt err = KErrNone;
       
    63 	switch ( aKey ) 
       
    64 		{
       
    65 		case EMSGToneQuitKey:	
       
    66 		    err = RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsMessageToneQuit, aValue );
       
    67 			break;
       
    68 		default:
       
    69 			{
       
    70 			return KErrNotFound;
       
    71 			}
       
    72 		}	
       
    73 	return err;
       
    74 	}    
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CIMAlertNotifierImpl::GetInt
       
    78 // (other items were commented in a header).
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 TInt CIMAlertNotifierImpl::GetInt( TNotifyKey aKey, TInt& aValue )
       
    82 	{
       
    83 	TInt err = KErrNone;
       
    84 	switch ( aKey ) 
       
    85 		{
       
    86 		case EMSGToneQuitKey:
       
    87 			{
       
    88 			err = RProperty::Get( KPSUidCoreApplicationUIs, KCoreAppUIsMessageToneQuit, aValue );		
       
    89 			break;
       
    90 			}
       
    91 		default:
       
    92 			{
       
    93 			err = KErrNotFound;	
       
    94 			break;
       
    95 			}
       
    96 		}
       
    97 	return err;
       
    98 	}
       
    99 	
       
   100 // -----------------------------------------------------------------------------
       
   101 // CIMAlertNotifierImpl::ListenKeyChanges
       
   102 // (other items were commented in a header).
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 TInt CIMAlertNotifierImpl::ListenKeyChanges( TNotifyKey aKey )
       
   106 	{
       
   107 	TInt err = KErrNone;
       
   108 	delete iPropWatcher;
       
   109 	iPropWatcher = NULL;
       
   110 	switch ( aKey ) 
       
   111 		{
       
   112 		case EMSGToneQuitKey:
       
   113 			{
       
   114 			TRAP( err, iPropWatcher = CIMAlertPropertyObserver::NewL( *this ) );
       
   115 			if( !err )
       
   116 			    {
       
   117 			    TRAP( err, iPropWatcher->ObservePropertyChangeL( 
       
   118 			                KPSUidCoreApplicationUIs, KCoreAppUIsMessageToneQuit ) );
       
   119 			    }
       
   120 			break;
       
   121 			}
       
   122 		default:
       
   123 			{
       
   124 			err = KErrNotFound;
       
   125 			break;
       
   126 			}
       
   127 		}
       
   128 	return err;
       
   129 	}
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CIMAlertNotifierImpl::HandlePropertyNotificationEventL
       
   133 // (other items were commented in a header).
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 void CIMAlertNotifierImpl::HandlePropertyNotificationEventL( TUid /* aCategory */, TUint aKey )
       
   137     {
       
   138     TInt value( 0 );
       
   139     User::LeaveIfError( 
       
   140           RProperty::Get( KPSUidCoreApplicationUIs, aKey, value ) );
       
   141     TUpdatedKey key;
       
   142     key.iUid = KPSUidCoreApplicationUIs;
       
   143     key.iKey = aKey;
       
   144     key.iValue = value;
       
   145     iObserver->HandleKeyChange( key );
       
   146     }
       
   147 
       
   148 //  End of File