|
1 /* |
|
2 * Copyright (c) 2006-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: General helper methods for message handling |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <stringloader.h> |
|
21 |
|
22 #include "chatdebugprint.h" |
|
23 #include "camessageutil.h" |
|
24 #include "mcamessage.h" |
|
25 #include "mcamessagecreator.h" |
|
26 #include "mcamessageswriteinterface.h" |
|
27 |
|
28 #include <caengineNG.rsg> // Resource |
|
29 #include <avkon.rsg> |
|
30 |
|
31 // CONSTANTS |
|
32 const TInt KMaxDateStringLength = 25; // max length of date message |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // CAMessageUtil::AppendDateStampL |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 void CAMessageUtil::AppendDateStampL( |
|
41 TTime aNewTime, |
|
42 MCAMessagesWriteInterface& aWriteInterface, |
|
43 MCAMessageCreator& aMessageCreator ) |
|
44 { |
|
45 // DateStamp is NOT appended if: |
|
46 // 1. There are no previous messages |
|
47 // 2. Previous message is from the same day as aNewTime |
|
48 |
|
49 CHAT_DP_FUNC_ENTER( "CAMessageUtil::AppendDateStampL" ) |
|
50 TTime lastTime = aWriteInterface.Time(); |
|
51 |
|
52 if ( lastTime == Time::NullTTime() ) |
|
53 { |
|
54 // no previous messages |
|
55 return; |
|
56 } |
|
57 |
|
58 // Compare timestamps |
|
59 TDateTime lastDate = lastTime.DateTime(); |
|
60 TDateTime newDate = aNewTime.DateTime(); |
|
61 |
|
62 if ( lastDate.Day() != newDate.Day() || |
|
63 lastDate.Month() != newDate.Month() || |
|
64 lastDate.Year() != newDate.Year() ) |
|
65 { |
|
66 // Day is not the same |
|
67 // Create a system message about new date |
|
68 |
|
69 // Format Date eg. "11.12.2006" |
|
70 HBufC* dateFormat = NULL; |
|
71 dateFormat = StringLoader::LoadLC( R_QTN_DATE_USUAL_WITH_ZERO ); |
|
72 HBufC* dateString = HBufC::NewLC( KMaxDateStringLength ); |
|
73 TPtr dateStringPtr( dateString->Des() ); |
|
74 aNewTime.FormatL( dateStringPtr, *dateFormat ); |
|
75 |
|
76 CHAT_DP( |
|
77 D_CHAT_LIT( "Adding datestamp to container: %U" ), dateStringPtr ); |
|
78 |
|
79 // Load date message |
|
80 HBufC* dateMessage = |
|
81 StringLoader::LoadLC( R_SYSTEM_MESSAGE_DATE_CHANGE, |
|
82 dateStringPtr ); |
|
83 |
|
84 // Cleanupstack not needed because ownership |
|
85 // is transferred to aWriteInterface |
|
86 MCAMessage* message = aMessageCreator.CreateSystemMessageL( // CSI: 35 # See comment above |
|
87 MCAMessage::ESystemMessageDateChange, *dateMessage ); |
|
88 |
|
89 // Append message to container |
|
90 // ownership is transferred |
|
91 aWriteInterface.AppendL( message ); |
|
92 |
|
93 // dateformat, datestring, dateMessage |
|
94 CleanupStack::PopAndDestroy( 3, dateFormat ); |
|
95 } |
|
96 |
|
97 CHAT_DP_FUNC_DONE( "CAMessageUtil::AppendDateStampL" ) |
|
98 } |
|
99 |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // CAMessageUtil::AppendMessageWithDateStampL |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 void CAMessageUtil::AppendMessageWithDateStampL( |
|
106 MCAMessage& aNewMessage, |
|
107 MCAMessagesWriteInterface& aWriteInterface, |
|
108 MCAMessageCreator& aMessageCreator, |
|
109 TBool aSharedOwnership ) |
|
110 { |
|
111 // Make sure this does not leave before the new message is |
|
112 // appended to interface, |
|
113 TRAP_IGNORE( AppendDateStampL( aNewMessage.TimeStamp(), |
|
114 aWriteInterface, |
|
115 aMessageCreator ) ); |
|
116 aWriteInterface.AppendL( &aNewMessage, aSharedOwnership ); |
|
117 } |
|
118 |
|
119 // End of file |