idlefw/plugins/devicestatus/src/aiprofilepublisher.cpp
changeset 0 79c6a41cd166
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Profile publisher
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <MProfileEngine.h>
       
    20 #include <MProfile.h>
       
    21 #include <MProfileName.h>
       
    22 #include <Profile.hrh>
       
    23 #include <CProfileChangeNotifyHandler.h>
       
    24 #include <aidevstaplgres.rsg>
       
    25 #include <PUAcodes.hrh>
       
    26 #include "aiprofilepublisher.h"
       
    27 #include "aiprioritizer.h"
       
    28 #include "ainwidpriorities.h"
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 // PUA code for the timed profile, missing from PUAcodes.hrh
       
    33 #define KAiTimedProfilePUA 0xF815
       
    34 
       
    35 CAiProfilePublisher::CAiProfilePublisher() : 
       
    36     iLastPublishedProfileId(ENothingPublished),
       
    37     iLastPublishedProfileSilent( EFalse ),
       
    38     iLastPublishedProfileTimed( EFalse )
       
    39     {
       
    40     }
       
    41 
       
    42 
       
    43 void CAiProfilePublisher::ConstructL()
       
    44     {
       
    45     User::LeaveIfError( iSSSettings.Open() );
       
    46 
       
    47     iProfileEngine = CreateProfileEngineL();
       
    48     }
       
    49 
       
    50 
       
    51 CAiProfilePublisher* CAiProfilePublisher::NewL()
       
    52     {
       
    53     CAiProfilePublisher* self = new( ELeave ) CAiProfilePublisher;
       
    54     CleanupStack::PushL( self );
       
    55     self->ConstructL();
       
    56     CleanupStack::Pop( self );
       
    57     return self;
       
    58     }
       
    59 
       
    60 
       
    61 CAiProfilePublisher::~CAiProfilePublisher()
       
    62     {
       
    63     //TRAP_IGNORE: leaving function called in non-leaving function
       
    64     TRAP_IGNORE(CleanLastProfileL());
       
    65     iSSSettings.CancelAll( *this );
       
    66     iSSSettings.Close();
       
    67     delete iProfileNotifier;
       
    68 
       
    69     if( iProfileEngine )
       
    70         {
       
    71         iProfileEngine->Release();
       
    72         }     
       
    73     }
       
    74 
       
    75 
       
    76 void CAiProfilePublisher::ResumeL()
       
    77     {
       
    78   User::LeaveIfError( iSSSettings.Open() );
       
    79   //Register to listen ALS activation, if ALS status changes,
       
    80   //profile must be republished.
       
    81     TInt err = iSSSettings.Register( ESSSettingsAls, *this );
       
    82 
       
    83     if( err == KErrNotSupported ||
       
    84         err == KErrAlreadyExists )
       
    85         {
       
    86         //ALS not supported or already registered, that's fine
       
    87         err = KErrNone;
       
    88         }
       
    89 
       
    90     User::LeaveIfError( err );
       
    91 
       
    92   //Start to listen profile changes.
       
    93     delete iProfileNotifier;
       
    94     iProfileNotifier = NULL;
       
    95     iProfileNotifier = CProfileChangeNotifyHandler::NewL( this );
       
    96     }
       
    97 
       
    98 
       
    99 void CAiProfilePublisher::Subscribe( MAiContentObserver& aObserver, 
       
   100                       MAiPropertyExtension& aExtension,
       
   101                                         MAiPublishPrioritizer& aPrioritizer,
       
   102                                         MAiPublisherBroadcaster& aBroadcaster )
       
   103     {
       
   104     iContentObserver = &aObserver;
       
   105     iExtension = &aExtension;
       
   106     iPrioritizer = &aPrioritizer;
       
   107     iBroadcaster = &aBroadcaster;
       
   108     }
       
   109 
       
   110 
       
   111 void CAiProfilePublisher::RefreshL( TBool aClean )
       
   112     {
       
   113     TRAP_IGNORE( RefreshProfileL( aClean ) );
       
   114     }
       
   115 
       
   116 
       
   117 void CAiProfilePublisher::PhoneSettingChanged( TSSSettingsSetting aSetting,
       
   118                         TInt /*aNewValue*/ )
       
   119     {
       
   120     if( aSetting == ESSSettingsAls )
       
   121         {
       
   122         //refresh profile, can't do much if it doesn't work
       
   123         TRAP_IGNORE( RefreshProfileL( ETrue ) );
       
   124         }
       
   125     }
       
   126 
       
   127 
       
   128 void CAiProfilePublisher::HandleActiveProfileEventL(
       
   129               TProfileEvent aProfileEvent,
       
   130               TInt /*aProfileId*/ )
       
   131     {
       
   132   //Profile activated or modified.
       
   133     if( ( aProfileEvent == EProfileNewActiveProfile ) ||
       
   134       ( aProfileEvent == EProfileActiveProfileModified ) )
       
   135         {
       
   136         iActiveProfilePublish = ETrue; 
       
   137         RefreshProfileL( ETrue );
       
   138         }
       
   139     }
       
   140 
       
   141 
       
   142 void CAiProfilePublisher::CleanLastProfileL()
       
   143     {
       
   144     if ( iLastPublishedProfileSilent )
       
   145         {
       
   146         iContentObserver->Clean( *iExtension,
       
   147                                   EAiDeviceStatusContentSilentIndicator,
       
   148                                   0 );
       
   149         iLastPublishedProfileSilent = EFalse;
       
   150         }
       
   151     
       
   152     if ( iLastPublishedProfileTimed )
       
   153         {
       
   154         iContentObserver->Clean( *iExtension,
       
   155                                   EAiDeviceStatusContentTimedProfileIndicator,
       
   156                                   0 );
       
   157         iLastPublishedProfileTimed = EFalse;
       
   158         }
       
   159     
       
   160     if( iLastPublishedProfileId == EGeneralProfilePublished )
       
   161       {
       
   162         iContentObserver->Clean( *iExtension,
       
   163                                   EAiDeviceStatusContentGeneralProfileName,
       
   164                                   0 );
       
   165         }
       
   166     else if( iLastPublishedProfileId == EOfflineProfilePublished )
       
   167       {
       
   168       iPrioritizer->TryToCleanL( *iBroadcaster,
       
   169                                   EAiDeviceStatusContentNetworkIdentity,
       
   170                                   EAiOfflineProfile );
       
   171       }
       
   172     else
       
   173       {
       
   174       iContentObserver->Clean( *iExtension,
       
   175                                 EAiDeviceStatusContentProfileName,
       
   176                                 0 );  
       
   177       }
       
   178 
       
   179     iLastPublishedProfileId = ENothingPublished;
       
   180     iActiveProfilePublish = EFalse;
       
   181     }
       
   182 
       
   183 
       
   184 void CAiProfilePublisher::RefreshProfileL( TBool aClean )
       
   185     {
       
   186     // Profile is changed or Refresh is called for some other reason
       
   187     //  -> re-publish profile
       
   188     iSuccess = EFalse;
       
   189     if( !iContentObserver )
       
   190         {
       
   191         return;
       
   192         }
       
   193 
       
   194     MProfile* profile = iProfileEngine->ActiveProfileLC();
       
   195 
       
   196     const MProfileName& name = profile->ProfileName();
       
   197     
       
   198     TInt profileNameId = name.Id();
       
   199     
       
   200     if( ( aClean && iLastPublishedProfileId != profileNameId ) || iActiveProfilePublish ) 
       
   201         {
       
   202         CleanLastProfileL();
       
   203         }
       
   204 
       
   205     switch( profileNameId )
       
   206         {
       
   207         case EProfileGeneralId:
       
   208             {
       
   209             iContentObserver->Publish( *iExtension,
       
   210                                         EAiDeviceStatusContentGeneralProfileName,
       
   211                                         name.Name(),
       
   212                                         0 );
       
   213             break;
       
   214             }
       
   215             
       
   216         case EProfileOffLineId:
       
   217             {
       
   218             iContentObserver->Publish( *iExtension,
       
   219                                         EAiDeviceStatusContentGeneralProfileName,
       
   220                                         name.Name(),
       
   221                                         0 );
       
   222 
       
   223             iPrioritizer->TryToPublishL( *iBroadcaster,
       
   224                                           EAiDeviceStatusContentNetworkIdentity,
       
   225                                           name.Name(),
       
   226                                           EAiOfflineProfile );
       
   227             iSuccess = ETrue;
       
   228             break;
       
   229             }
       
   230           
       
   231         default:
       
   232             {
       
   233             iContentObserver->Publish( *iExtension,
       
   234                                         EAiDeviceStatusContentProfileName,
       
   235                                         name.Name(),
       
   236                                         0 );
       
   237             break;
       
   238             }
       
   239         }
       
   240 
       
   241     iLastPublishedProfileId = (TLastPublishedProfile)profileNameId;
       
   242         
       
   243     if ( iProfileEngine->IsActiveProfileTimedL() )
       
   244         {
       
   245         TBuf<1> timed; // one character
       
   246         timed.Append( KAiTimedProfilePUA );
       
   247         iContentObserver->Publish( *iExtension,
       
   248                                     EAiDeviceStatusContentTimedProfileIndicator,
       
   249                                     timed,
       
   250                                     0 );
       
   251         iLastPublishedProfileTimed = ETrue;
       
   252         }
       
   253 
       
   254   //If profile is silent, publish silent indicator.
       
   255     if( profile->IsSilent() )
       
   256         {
       
   257         TBuf<1> silent; // one character
       
   258         silent.Append( KPuaCodeSilentSymbol );
       
   259         iContentObserver->Publish( *iExtension,
       
   260                                     EAiDeviceStatusContentSilentIndicator,
       
   261                                     silent,
       
   262                                     0 );
       
   263         iLastPublishedProfileSilent = ETrue;
       
   264         }
       
   265 
       
   266     CleanupStack::PopAndDestroy();//profile
       
   267     }
       
   268 
       
   269 
       
   270 TBool CAiProfilePublisher::RefreshL( TInt aContentId, TBool aClean )
       
   271   {
       
   272     switch( aContentId )
       
   273         {
       
   274         case EAiDeviceStatusContentProfileName:
       
   275         case EAiDeviceStatusContentGeneralProfileName:
       
   276         case EAiDeviceStatusContentNetworkIdentity:
       
   277           {
       
   278           RefreshProfileL( aClean );
       
   279           return ETrue;
       
   280           }
       
   281       }
       
   282     return EFalse;
       
   283   }
       
   284 
       
   285 
       
   286 TBool CAiProfilePublisher::RefreshContentWithPriorityL( TInt aContentId, 
       
   287                                                         TInt aPriority )
       
   288   {
       
   289   if( aContentId == EAiDeviceStatusContentNetworkIdentity &&
       
   290       aPriority == EAiOfflineProfile )
       
   291         {
       
   292       RefreshProfileL( EFalse );
       
   293       if( iSuccess )
       
   294           {
       
   295           return ETrue;    
       
   296           }
       
   297         }
       
   298     return EFalse;
       
   299   }