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