idlefw/plugins/devicestatus/src/aidatepublisher.cpp
changeset 0 79c6a41cd166
child 8 d0529222e3f0
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:  Date publisher
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <StringLoader.h>
       
    20 #include <avkon.rsg>
       
    21 #include <AknUtils.h>
       
    22 #include <aidevstaplgres.rsg>
       
    23 #include <bacntf.h>
       
    24 #include "aidatepublisher.h"
       
    25 #include "aicontentobserver.h"
       
    26 
       
    27 const TInt KMaxDateStringLength = 100;
       
    28 
       
    29 // ======== MEMBER FUNCTIONS ========
       
    30 
       
    31 CAiDatePublisher::CAiDatePublisher()
       
    32     {
       
    33     }
       
    34 
       
    35 
       
    36 void CAiDatePublisher::ConstructL()
       
    37     {
       
    38   	// Create enviroment notifier
       
    39     iEnvNotifier = CEnvironmentChangeNotifier::NewL( 
       
    40 		CActive::EPriorityStandard, TCallBack( HandleCallBackL, this ) );
       
    41     iDateText = NULL;
       
    42 	// Start listening notifications
       
    43     iEnvNotifier->Start(); 
       
    44     }
       
    45 
       
    46 
       
    47 CAiDatePublisher* CAiDatePublisher::NewL()
       
    48     {
       
    49     CAiDatePublisher* self = new( ELeave ) CAiDatePublisher;
       
    50     CleanupStack::PushL( self );
       
    51     self->ConstructL();
       
    52     CleanupStack::Pop( self );
       
    53     return self;
       
    54     }
       
    55 
       
    56 
       
    57 CAiDatePublisher::~CAiDatePublisher()
       
    58     {
       
    59     delete iDateText;
       
    60     delete iEnvNotifier;
       
    61     }
       
    62 
       
    63 
       
    64 void CAiDatePublisher::ResumeL()
       
    65     {
       
    66     RefreshDateL();
       
    67     }
       
    68 
       
    69 
       
    70 void CAiDatePublisher::Subscribe( MAiContentObserver& aObserver, 
       
    71 								    MAiPropertyExtension& aExtension,
       
    72                                     MAiPublishPrioritizer& /*aPrioritizer*/,
       
    73                                     MAiPublisherBroadcaster& /*aBroadcaster*/ )
       
    74     {
       
    75     iContentObserver = &aObserver;
       
    76     iExtension = &aExtension;
       
    77     }
       
    78 
       
    79 
       
    80 void CAiDatePublisher::RefreshL( TBool /*aClean*/ )
       
    81     {
       
    82     RefreshDateL();
       
    83     }
       
    84 
       
    85 
       
    86 void CAiDatePublisher::RefreshDateL()
       
    87     {
       
    88     if( !iContentObserver )
       
    89         {
       
    90         return;
       
    91         }
       
    92 
       
    93     delete iDateText;
       
    94     iDateText = NULL;
       
    95     iDateText = ConstructDateStringL();
       
    96     if ( iDateText )
       
    97         {
       
    98         iContentObserver->Publish( *iExtension,
       
    99     						EAiDeviceStatusContentDate,
       
   100     						*iDateText,
       
   101     						0 );
       
   102         }
       
   103     }
       
   104 
       
   105 
       
   106 HBufC* CAiDatePublisher::GetDayNameStringLC( TDay aDay, CCoeEnv& aCoeEnv )
       
   107     {
       
   108 	//Create week day string
       
   109     TInt wkDayRes = KErrNotFound;
       
   110 
       
   111     switch( aDay )
       
   112         {
       
   113         case EMonday:
       
   114             wkDayRes = R_QTN_WEEK_TWO_CHARS_MO;
       
   115             break;
       
   116         case ETuesday:
       
   117             wkDayRes = R_QTN_WEEK_TWO_CHARS_TU;
       
   118             break;
       
   119         case EWednesday:
       
   120             wkDayRes = R_QTN_WEEK_TWO_CHARS_WE;
       
   121             break;
       
   122         case EThursday:
       
   123             wkDayRes = R_QTN_WEEK_TWO_CHARS_TH;
       
   124             break;
       
   125         case EFriday:
       
   126             wkDayRes = R_QTN_WEEK_TWO_CHARS_FR;
       
   127             break;
       
   128         case ESaturday:
       
   129             wkDayRes = R_QTN_WEEK_TWO_CHARS_SA;
       
   130             break;
       
   131         case ESunday:
       
   132             wkDayRes = R_QTN_WEEK_TWO_CHARS_SU;
       
   133             break;
       
   134         default:
       
   135             // invalid weekday fetched
       
   136 	        User::Leave( KErrNotFound );
       
   137         }
       
   138 
       
   139     return StringLoader::LoadLC( wkDayRes, &aCoeEnv );
       
   140     }
       
   141 
       
   142 
       
   143 HBufC* CAiDatePublisher::ConstructDateStringL()
       
   144     {
       
   145     // Construct date string using date format from resource file
       
   146     CCoeEnv* coeEnv = CCoeEnv::Static();
       
   147 
       
   148     if( !coeEnv )
       
   149         {
       
   150         User::Leave( KErrNotReady );
       
   151         }
       
   152 
       
   153     TTime time;
       
   154     time.HomeTime();
       
   155 
       
   156     HBufC* aiDateString = HBufC::NewLC( KMaxDateStringLength );
       
   157     HBufC* aiDateFormatString = StringLoader::LoadLC( R_ACTIVEIDLE_TIME_FORMAT,
       
   158     													coeEnv );
       
   159     HBufC* dateStringBuf = HBufC::NewLC( KMaxDateStringLength );
       
   160     HBufC* dateFormatString = StringLoader::LoadLC( R_QTN_DATE_SHORT_WITH_ZERO,
       
   161     												coeEnv );
       
   162     TPtr dateString( dateStringBuf->Des() );
       
   163     time.FormatL( dateString, *dateFormatString );
       
   164     CleanupStack::PopAndDestroy( dateFormatString );
       
   165 
       
   166     //now dateString contains string which is formatted using
       
   167     //R_QTN_DATE_USUAL_WITH_ZERO
       
   168 
       
   169     // To arabic
       
   170     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( dateString );
       
   171 
       
   172     TPtr aiDateStringPtr = aiDateString->Des();
       
   173     
       
   174     TDayNameAbb wkDayAbb = TDayNameAbb();
       
   175     wkDayAbb.Set(time.DayNoInWeek());
       
   176         
       
   177     //add date to string
       
   178     StringLoader::Format( aiDateStringPtr, *aiDateFormatString,	1,dateString );
       
   179 
       
   180     //reuse dateString
       
   181     dateString.Copy( aiDateStringPtr );
       
   182 
       
   183     //add weekday to string
       
   184     StringLoader::Format( aiDateStringPtr, dateString, 0, wkDayAbb );
       
   185 
       
   186     CleanupStack::PopAndDestroy( dateStringBuf );//dateStringBuf, aiDateFormatString
       
   187     CleanupStack::PopAndDestroy( aiDateFormatString );
       
   188 
       
   189     CleanupStack::Pop( aiDateString );
       
   190     return aiDateString;
       
   191     }
       
   192 
       
   193 
       
   194 TBool CAiDatePublisher::RefreshL( TInt aContentId, TBool /*aClean*/ )
       
   195 	{
       
   196 	if( aContentId == EAiDeviceStatusContentDate )
       
   197 	    {
       
   198 	    RefreshDateL();
       
   199 	    return ETrue;
       
   200 	    }
       
   201 	return EFalse;
       
   202 	}
       
   203 	
       
   204 	
       
   205 TInt CAiDatePublisher::HandleCallBackL( TAny *aPtr )
       
   206 	{
       
   207 	CAiDatePublisher* self = static_cast<CAiDatePublisher*>( aPtr );
       
   208 	
       
   209 	if( self )
       
   210 	    {
       
   211         TInt changes( self->iEnvNotifier->Change() );
       
   212         
       
   213         if ( changes & 
       
   214         	( EChangesLocale | EChangesMidnightCrossover | EChangesSystemTime ) )
       
   215         	{
       
   216         	self->RefreshDateL();
       
   217         	}	    
       
   218 	    }    
       
   219     	
       
   220 	return KErrNone;
       
   221 	}