21 #include <AknInfoPopupNoteController.h> |
21 #include <AknInfoPopupNoteController.h> |
22 #include <StringLoader.h> |
22 #include <StringLoader.h> |
23 #include <eikenv.h> |
23 #include <eikenv.h> |
24 #include <esmrgui.rsg> |
24 #include <esmrgui.rsg> |
25 #include <avkon.rsg> |
25 #include <avkon.rsg> |
|
26 #include <ct/rcpointerarray.h> |
|
27 #include <AknUtils.h> |
|
28 #include <aknlayoutscalable_avkon.cdl.h> |
|
29 #include <layoutmetadata.cdl.h> |
26 |
30 |
27 #include "emailtrace.h" |
31 #include "emailtrace.h" |
28 |
32 |
29 // Unnamed namespace for local definitions |
33 // Unnamed namespace for local definitions |
30 namespace{ |
34 namespace{ |
31 |
35 |
32 const TInt KTimeDelayBeforeShow(0); // 0 Seconds |
36 const TInt KTimeDelayBeforeShow(0); // 0 Seconds |
33 const TInt KTimeForView(5000); // 5 Seconds |
37 const TInt KTimeForView(5000); // 5 Seconds |
34 const TInt KZero(0); |
|
35 const TInt KTimeStringLength(20); |
38 const TInt KTimeStringLength(20); |
36 const TInt KMaxSummaryLength(25); |
39 const TInt KArrayGranularity( 4 ); |
37 |
40 |
38 _LIT( KNewLine, "\n"); |
41 const TInt KPortraitWindowVariety( 4 ); |
39 _LIT( KMessageStart, "("); |
42 const TInt KLandscapeWindowVariety( 7 ); |
40 _LIT( KMessageEnd, ")"); |
43 const TInt KTextLineVariety( 5 ); |
41 _LIT( KStringCont, "...\n"); |
44 |
42 _LIT (KSpace , " " ); |
45 const TInt KNumTitleLines( 1 ); |
43 const TInt KFullTimeStringSize(256); |
46 const TInt KNumLocationLines( 2 ); |
44 |
47 |
45 void CalEntryPointerArrayCleanup( TAny* aArray ) |
48 /** |
46 { |
49 * Clips given text and allocates new buffer if needed. |
47 RPointerArray<CCalEntry>* entryArray = |
50 * @param aSource text to clip |
48 static_cast<RPointerArray<CCalEntry>*>( aArray ); |
51 * @param aNumLines number of popup note lines available for visual text. |
49 |
52 * @return new buffer or NULL if aSource must not be clipped |
50 entryArray->ResetAndDestroy(); |
53 */ |
51 entryArray->Close(); |
54 |
52 } |
55 HBufC* ClipTextL( const TDesC& aSource, TInt aNumLines ) |
|
56 { |
|
57 TRect mainPane; |
|
58 AknLayoutUtils::LayoutMetricsRect( |
|
59 AknLayoutUtils::EMainPane, |
|
60 mainPane ); |
|
61 |
|
62 // Get the correct popup window text line layout |
|
63 TInt windowVariety( KPortraitWindowVariety ); |
|
64 if ( Layout_Meta_Data::IsLandscapeOrientation() ) |
|
65 { |
|
66 windowVariety = KLandscapeWindowVariety; |
|
67 } |
|
68 |
|
69 TAknWindowComponentLayout popupNoteWindow = |
|
70 AknLayoutScalable_Avkon::popup_preview_text_window( windowVariety ); |
|
71 TAknLayoutRect popupNoteRect; |
|
72 popupNoteRect.LayoutRect( mainPane, popupNoteWindow ); |
|
73 |
|
74 TAknTextComponentLayout popupNoteTextLine = |
|
75 AknLayoutScalable_Avkon::popup_preview_text_window_t3( KTextLineVariety ); |
|
76 TAknLayoutText textLayout; |
|
77 textLayout.LayoutText( popupNoteRect.Rect(), popupNoteTextLine ); |
|
78 |
|
79 TInt lineWidth( textLayout.TextRect().Width() ); |
|
80 const CFont* font = textLayout.Font(); |
|
81 |
|
82 HBufC* text = NULL; |
|
83 |
|
84 if ( font->TextWidthInPixels( aSource ) > lineWidth ) |
|
85 { |
|
86 // Text must be clipped to fit |
|
87 // Allocate result buffer and reserve space for line feeds |
|
88 text = HBufC::NewLC( |
|
89 aSource.Length() + aNumLines ); |
|
90 |
|
91 CArrayFix<TInt>* lineWidthArray = |
|
92 new( ELeave ) CArrayFixFlat<TInt>( aNumLines ); |
|
93 CleanupStack::PushL( lineWidthArray ); |
|
94 for ( TInt i = 0; i < aNumLines; ++i ) |
|
95 { |
|
96 lineWidthArray->AppendL( lineWidth ); |
|
97 } |
|
98 |
|
99 CPtrC16Array* strings = new( ELeave ) CPtrC16Array( aNumLines ); |
|
100 CleanupStack::PushL( strings ); |
|
101 TPtr des( text->Des() ); |
|
102 |
|
103 // Wrap string |
|
104 AknTextUtils::WrapToStringAndClipL( |
|
105 aSource, |
|
106 *lineWidthArray, |
|
107 *font, |
|
108 des ); |
|
109 |
|
110 // Trim trailing line feeds |
|
111 des.TrimRight(); |
|
112 |
|
113 CleanupStack::PopAndDestroy( 2, lineWidthArray ); |
|
114 CleanupStack::Pop( text ); |
|
115 } |
|
116 |
|
117 return text; |
|
118 } |
|
119 |
53 |
120 |
54 }//namespace |
121 }//namespace |
55 |
122 |
56 // ======== MEMBER FUNCTIONS ======== |
123 // ======== MEMBER FUNCTIONS ======== |
57 |
124 |
116 // --------------------------------------------------------------------------- |
183 // --------------------------------------------------------------------------- |
117 // |
184 // |
118 void CESMRConflictPopup::PrepareDisplayStringL() |
185 void CESMRConflictPopup::PrepareDisplayStringL() |
119 { |
186 { |
120 FUNC_LOG; |
187 FUNC_LOG; |
121 RPointerArray<CCalEntry> entryArray; |
188 RCPointerArray<CCalEntry> entryArray; |
122 CleanupStack::PushL( |
189 CleanupClosePushL( entryArray ); |
123 TCleanupItem( |
190 |
124 CalEntryPointerArrayCleanup, |
|
125 &entryArray ) ); |
|
126 |
|
127 TInt ret = iEntry->FetchConflictingEntriesL( entryArray ); |
191 TInt ret = iEntry->FetchConflictingEntriesL( entryArray ); |
128 if( ret == KErrNotFound ) |
192 if( ret == KErrNotFound ) |
129 { |
193 { |
130 User::Leave( KErrNotFound ); |
194 User::Leave( KErrNotFound ); |
131 } |
195 } |
132 |
196 |
133 TInt numEnteries = entryArray.Count(); |
197 // Pointer descriptor for R_QTN_MEET_REQ_CONFLICT_UNNAMED |
134 TInt dispStrLength(KZero); |
198 TPtrC unnamedTitle( KNullDesC ); |
135 TBuf <KFullTimeStringSize> meetingTitle ; |
199 |
136 TBuf <KFullTimeStringSize> meetingLocation ; |
200 // Actual title to shown in popup |
137 TTime startTime ; |
201 TPtrC meetingTitle( KNullDesC ); |
138 TTime endTime ; |
202 |
139 |
203 // Location to show in popup |
140 if (numEnteries != KZero) |
204 TPtrC meetingLocation( KNullDesC ); |
|
205 |
|
206 TTime startTime; |
|
207 TTime endTime; |
|
208 |
|
209 CCoeEnv* env = CCoeEnv::Static(); |
|
210 |
|
211 if ( entryArray.Count() > 0 ) |
141 {// there is atleast one entry |
212 {// there is atleast one entry |
142 // get the first conflicting entry and set the string for display |
213 // get the first conflicting entry and set the string for display |
143 meetingTitle = entryArray[KZero]->SummaryL(); |
214 meetingTitle.Set( entryArray[ 0 ]->SummaryL() ); |
144 meetingLocation = entryArray[KZero]->LocationL(); |
215 meetingLocation.Set( entryArray[ 0 ]->LocationL() ); |
145 |
216 |
146 |
217 if ( ( meetingLocation.Length() == 0 ) && ( meetingTitle.Length() == 0 ) ) |
147 if ( ( meetingLocation.Length()== 0 ) && ( meetingTitle.Length() == 0 ) ) |
|
148 { |
218 { |
149 // if no title, set unnamed text: |
219 // if no title, set unnamed text: |
150 HBufC* title = StringLoader::LoadLC ( R_QTN_MEET_REQ_CONFLICT_UNNAMED ); |
220 HBufC* title = StringLoader::LoadLC( |
151 meetingTitle.Copy( *title ); |
221 R_QTN_MEET_REQ_CONFLICT_UNNAMED, |
152 CleanupStack::PopAndDestroy( title ); |
222 env ); |
153 } |
223 unnamedTitle.Set( *title ); |
154 |
224 meetingTitle.Set( unnamedTitle ); |
155 dispStrLength = meetingTitle.Length() + meetingLocation.Length(); |
225 } |
156 startTime = entryArray[KZero]->StartTimeL().TimeLocalL(); |
226 |
157 endTime = entryArray[KZero]->EndTimeL().TimeLocalL(); |
227 startTime = entryArray[ 0 ]->StartTimeL().TimeLocalL(); |
158 } |
228 endTime = entryArray[ 0 ]->EndTimeL().TimeLocalL(); |
159 |
229 } |
160 HBufC* stringHolder = |
230 |
161 StringLoader::LoadLC(R_QTN_MEET_REQ_CONFLICTS_WITH_LABEL); |
231 HBufC* conflictLabel = StringLoader::LoadLC( |
162 dispStrLength = stringHolder->Length() + meetingTitle.Length() |
232 R_QTN_MEET_REQ_CONFLICTS_WITH_LABEL, |
163 + meetingLocation.Length() + KFullTimeStringSize; |
233 env ); |
164 |
234 |
165 HBufC* timeFormatString = CCoeEnv::Static()->AllocReadResourceLC(R_QTN_TIME_USUAL_WITH_ZERO); |
235 HBufC* timeFormatString = StringLoader::LoadLC( |
|
236 R_QTN_TIME_USUAL_WITH_ZERO, |
|
237 env ); |
166 |
238 |
167 TBuf<KTimeStringLength> startBuf; |
239 TBuf<KTimeStringLength> startBuf; |
168 TBuf<KTimeStringLength> endBuf; |
240 TBuf<KTimeStringLength> endBuf; |
169 |
241 |
170 startTime.FormatL( startBuf, *timeFormatString ); |
242 startTime.FormatL( startBuf, *timeFormatString ); |
171 endTime.FormatL( endBuf, *timeFormatString ); |
243 endTime.FormatL( endBuf, *timeFormatString ); |
172 |
244 |
173 CDesCArrayFlat* strings = new(ELeave) CDesCArrayFlat( 2 ); |
245 CPtrC16Array* strings = new( ELeave ) CPtrC16Array( KArrayGranularity ); |
174 CleanupStack::PushL( strings ); |
246 CleanupStack::PushL( strings ); |
175 strings->AppendL( startBuf ); //First string |
247 strings->AppendL( startBuf ); //start time string |
176 strings->AppendL( endBuf ); //Second string |
248 strings->AppendL( endBuf ); //end time string |
177 |
249 |
178 HBufC* finalTimeBuf = |
250 HBufC* finalTimeBuf = |
179 StringLoader::LoadL( |
251 StringLoader::LoadLC( |
180 R_QTN_MEET_REQ_TIME_SEPARATOR, |
252 R_QTN_MEET_REQ_TIME_SEPARATOR, |
181 *strings, |
253 *strings, |
182 CEikonEnv::Static() ); // codescanner::eikonenvstatic |
254 env ); |
|
255 |
|
256 if ( meetingLocation.Length() > 0 ) |
|
257 { |
|
258 // format Meeting location |
|
259 HBufC* formatText = StringLoader::LoadLC( |
|
260 R_MEET_REQ_CONFLICT_LOCATION_FORMAT, |
|
261 meetingLocation, |
|
262 env ); |
|
263 meetingLocation.Set( *formatText ); |
|
264 } |
|
265 |
|
266 // Format final display string |
|
267 strings->Reset(); |
|
268 strings->AppendL( *conflictLabel ); |
|
269 strings->AppendL( *finalTimeBuf ); |
|
270 |
|
271 HBufC* titleBuf = NULL; |
|
272 HBufC* locationBuf = NULL; |
|
273 |
|
274 if ( meetingTitle.Length() > 0 ) |
|
275 { |
|
276 // Prepare title |
|
277 titleBuf = ClipTextL( meetingTitle, KNumTitleLines ); |
|
278 if ( titleBuf ) |
|
279 { |
|
280 CleanupStack::PushL( titleBuf ); |
|
281 meetingTitle.Set( *titleBuf ); |
|
282 } |
|
283 strings->AppendL( meetingTitle ); |
|
284 |
|
285 // Prepare location |
|
286 locationBuf = ClipTextL( meetingLocation, KNumLocationLines ); |
|
287 if ( locationBuf ) |
|
288 { |
|
289 CleanupStack::PushL( locationBuf ); |
|
290 meetingLocation.Set( *locationBuf ); |
|
291 } |
|
292 strings->AppendL( meetingLocation ); |
|
293 } |
|
294 else |
|
295 { |
|
296 // Prepare location |
|
297 locationBuf = ClipTextL( |
|
298 meetingLocation, |
|
299 KNumTitleLines + KNumLocationLines ); |
|
300 if ( locationBuf ) |
|
301 { |
|
302 CleanupStack::PushL( locationBuf ); |
|
303 meetingLocation.Set( *locationBuf ); |
|
304 } |
|
305 strings->AppendL( meetingLocation ); |
|
306 strings->AppendL( KNullDesC() ); |
|
307 } |
|
308 |
|
309 HBufC* displayString = StringLoader::LoadLC( |
|
310 R_MEET_REQ_CONFLICT_TEXT_FORMAT, |
|
311 *strings, |
|
312 env ); |
|
313 |
|
314 // Trim trailing white space |
|
315 displayString->Des().TrimRight(); |
|
316 |
|
317 // Set display string to popup note |
|
318 iNote->SetTextL( *displayString ); |
|
319 |
|
320 // Clean allocated buffers |
|
321 CleanupStack::PopAndDestroy( displayString ); |
|
322 if ( locationBuf ) |
|
323 { |
|
324 CleanupStack::PopAndDestroy( locationBuf ); |
|
325 } |
|
326 if ( titleBuf ) |
|
327 { |
|
328 CleanupStack::PopAndDestroy( titleBuf ); |
|
329 } |
|
330 if ( meetingLocation.Length() > 0 ) |
|
331 { |
|
332 CleanupStack::PopAndDestroy(); // R_MEET_REQ_CONFLICT_LOCATION_FORMAT |
|
333 } |
|
334 CleanupStack::PopAndDestroy( finalTimeBuf ); |
183 CleanupStack::PopAndDestroy( strings ); |
335 CleanupStack::PopAndDestroy( strings ); |
184 CleanupStack::PushL( finalTimeBuf ); |
|
185 |
|
186 HBufC* displayString = HBufC::NewLC(dispStrLength); |
|
187 displayString->Des().Append(stringHolder->Des()); |
|
188 displayString->Des().Append(KNewLine); |
|
189 displayString->Des().Append(finalTimeBuf->Des()); |
|
190 |
|
191 |
|
192 displayString->Des().Append(KMessageStart); |
|
193 // Check the length of meetingTitle |
|
194 // If its greater than some KMaxSummaryLength value then |
|
195 // truncate to some reasonable value & append KStringCont |
|
196 if ( meetingTitle.Length() > KMaxSummaryLength ) |
|
197 { |
|
198 displayString->Des().Append(meetingTitle.Ptr(),KMaxSummaryLength); |
|
199 displayString->Des().Append(KStringCont); |
|
200 } |
|
201 else |
|
202 { |
|
203 displayString->Des().Append(meetingTitle); |
|
204 displayString->Des().Append(KSpace); |
|
205 } |
|
206 |
|
207 displayString->Des().Append(meetingLocation); |
|
208 displayString->Des().Append(KMessageEnd); |
|
209 |
|
210 iNote->SetTextL(displayString->Des() ); |
|
211 |
|
212 CleanupStack::PopAndDestroy( displayString ); |
|
213 CleanupStack::PopAndDestroy( finalTimeBuf ); |
|
214 CleanupStack::PopAndDestroy( timeFormatString ); |
336 CleanupStack::PopAndDestroy( timeFormatString ); |
215 CleanupStack::PopAndDestroy( stringHolder ); |
337 CleanupStack::PopAndDestroy( conflictLabel ); |
|
338 if ( unnamedTitle.Length() > 0 ) |
|
339 { |
|
340 CleanupStack::PopAndDestroy(); // R_QTN_MEET_REQ_CONFLICT_UNNAMED |
|
341 } |
216 CleanupStack::PopAndDestroy( &entryArray ); |
342 CleanupStack::PopAndDestroy( &entryArray ); |
217 } |
343 } |
218 |
344 |
219 |
345 |
220 // --------------------------------------------------------------------------- |
346 // --------------------------------------------------------------------------- |