|
1 /* |
|
2 * Copyright (c) 2008 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: Converts PIM Event items and native calendar anniversaries |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // CLASS HEADER |
|
20 #include "cpimagnannivadapter.h" |
|
21 |
|
22 // INTERNAL INCLUDES |
|
23 #include "agneventsupport.h" |
|
24 #include "mpimrepeatruledata.h" |
|
25 #include "mpimeventitem.h" |
|
26 #include "mpimitemdata.h" |
|
27 #include "pimpanics.h" |
|
28 #include "logger.h" |
|
29 |
|
30 // EXTERNAL INCLUDES |
|
31 #include <calentry.h> |
|
32 #include <calrrule.h> |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CPIMAgnAnnivAdapter::NewL |
|
38 // Two-phased constructor. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CPIMAgnAnnivAdapter* CPIMAgnAnnivAdapter::NewL( |
|
42 java::util::FunctionServer* aFuncServer) |
|
43 { |
|
44 JELOG2(EPim); |
|
45 CPIMAgnAnnivAdapter* self = new(ELeave) CPIMAgnAnnivAdapter(aFuncServer); |
|
46 CleanupStack::PushL(self); |
|
47 CallMethodL(self, &CPIMAgnAnnivAdapter::ConstructL, self->iFuncServer); |
|
48 CleanupStack::Pop(self); |
|
49 return self; |
|
50 } |
|
51 |
|
52 // destructor |
|
53 CPIMAgnAnnivAdapter::~CPIMAgnAnnivAdapter() |
|
54 { |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CPIMAgnAnnivAdapter::CreateItemToAgnL |
|
59 // Creates a new Agenda Model Anniv item from a PIM item data. |
|
60 // Returns: A Anniv item based on PIM item data. |
|
61 // The ownership of the Anniv item is transferred to the caller. |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 CCalEntry* CPIMAgnAnnivAdapter::CreateItemToAgnL(const MPIMEventItem& aItem) |
|
65 { |
|
66 JELOG2(EPim); |
|
67 // Create new calendar entry. Native type is anniversary |
|
68 CCalEntry* entry = CreateCalendarEntryLC(CCalEntry::EAnniv); |
|
69 // Add default values to the item. The default values are used |
|
70 // by the native calendar application and therefore needed to be added |
|
71 AddDefaultValuesToEntryL(aItem, *entry); |
|
72 // Convert fields from Java side to the native side |
|
73 ConvertFieldsToAgnL(aItem, *entry); |
|
74 // Convert repeat rule to the item if the item supports recurrence orders |
|
75 if (aItem.IsRepeating()) |
|
76 { |
|
77 ConvertRepeatToAgnL(aItem, *entry); |
|
78 } |
|
79 |
|
80 CleanupStack::Pop(entry); |
|
81 return entry; |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CPIMAgnAnnivAdapter::ReadAgnToItemL |
|
86 // Reads an Agenda Model Anniv item and converts it to a framework PIM item. |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 void CPIMAgnAnnivAdapter::ReadAgnToItemL(MPIMEventItem& aItem, |
|
90 CCalEntry& aEntry) |
|
91 { |
|
92 JELOG2(EPim); |
|
93 ReadFieldsFromAgnL(aItem, aEntry, KPIMSupportedAnnivFields, |
|
94 KPIMSupportedAnnivFieldsCount); |
|
95 |
|
96 TCalRRule tempRule; |
|
97 if (aEntry.GetRRuleL(tempRule)) |
|
98 { |
|
99 ReadRepeatFromAgnL(aItem, aEntry); |
|
100 aItem.GetRepeat()->BackupRepeatL(); |
|
101 } |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // CPIMAgnAnnivAdapter::UpdateItemToAgnL |
|
106 // Reads an Agenda Model Anniv item and updates it based on the PIM item data. |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 void CPIMAgnAnnivAdapter::UpdateItemToAgnL(const MPIMEventItem& aItem, |
|
110 CCalEntry& aEntry) |
|
111 { |
|
112 JELOG2(EPim); |
|
113 // Before updating values, empty the fields or set default values for the |
|
114 // fields that PIM api supports |
|
115 ClearPIMFieldsL(aEntry, KPIMSupportedAnnivFields, |
|
116 KPIMSupportedAnnivFieldsCount); |
|
117 |
|
118 // Convert fields from Java side to the native side |
|
119 ConvertFieldsToAgnL(aItem, aEntry); |
|
120 |
|
121 // Convert repeat rule to the native entry if the item is repeating |
|
122 // and the repeating rules have been changed in the Java item |
|
123 if (aItem.IsRepeating()) |
|
124 { |
|
125 if (aItem.GetRepeat()->IsModified()) |
|
126 { |
|
127 ConvertRepeatToAgnL(aItem, aEntry); |
|
128 } |
|
129 } |
|
130 else |
|
131 { |
|
132 aEntry.ClearRepeatingPropertiesL(); |
|
133 } |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CPIMAgnAnnivAdapter::CPIMAgnAnnivAdapter |
|
138 // C++ constructor can NOT contain any code, that |
|
139 // might leave. |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 CPIMAgnAnnivAdapter::CPIMAgnAnnivAdapter( |
|
143 java::util::FunctionServer* aFuncServer) : |
|
144 CPIMAgnEventAdapter(aFuncServer) |
|
145 { |
|
146 JELOG2(EPim); |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CPIMAgnAnnivAdapter::ReadStartFromAgnL |
|
151 // Reads Agenda entry's start field and converts it into PIM Item field. |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 void CPIMAgnAnnivAdapter::ReadStartFromAgnL(MPIMEventItem& aItem, |
|
155 CCalEntry& aEntry) |
|
156 { |
|
157 JELOG2(EPim); |
|
158 // Get time as local time since it needs to be modified |
|
159 TTime startTime = aEntry.StartTimeL().TimeLocalL(); |
|
160 if (startTime != Time::NullTTime()) |
|
161 { |
|
162 // Convert start field to start of the date |
|
163 TTime startOfDay(StartOfDay(startTime)); |
|
164 // Convert date to UTC time because PIM API handles internal times in UTC |
|
165 ConvertTimeL(startOfDay, EPIMDateUTC); |
|
166 TPIMFieldData fieldData(EPIMEventStart, KPIMAttrNone, startOfDay); |
|
167 aItem.ItemData().AddValueL(fieldData); |
|
168 } |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // CPIMAgnAnnivAdapter::ConvertDateFieldToAgnL |
|
173 // Converts Date fields from PIM event item to native calendar anniversary entry |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 void CPIMAgnAnnivAdapter::ConvertDateFieldToAgnL(const MPIMEventItem& aItem, |
|
177 CCalEntry& aEntry, const TPIMEventField aField) |
|
178 { |
|
179 JELOG2(EPim); |
|
180 __ASSERT_DEBUG(aField == EPIMEventStart, User::Panic(KPIMPanicCategory, |
|
181 EPIMPanicUnsupportedDateField)); |
|
182 // Get value from the item. There should be only one start date |
|
183 // since multiple start dates are not supported by native entries |
|
184 const MPIMItemData& itemData = aItem.ItemData(); |
|
185 const TPIMFieldData fieldData = itemData.ValueL(aField, 0); |
|
186 const TPIMDate& date = fieldData.DateValue(); |
|
187 |
|
188 // Check that the date is inside the valid range |
|
189 __ASSERT_ALWAYS(IsDateInValidAgendaRange(date), User::Leave(KErrAbort)); |
|
190 |
|
191 // By default, times are in UTC time format in PIM API and therefore the |
|
192 // time must be converted to local time when changing time to the start of day |
|
193 TTime timeLocal(date); |
|
194 ConvertTimeL(timeLocal, EPIMDateLocal); |
|
195 // Set converted time to the native entry |
|
196 TCalTime calTime; |
|
197 calTime.SetTimeLocalL(StartOfDay(timeLocal)); |
|
198 aEntry.SetStartAndEndTimeL(calTime, calTime); |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CPIMAgnAnnivAdapter::ReadEndFromAgnL |
|
203 // Reads Agenda entry's end field and converts it into PIM Item field. |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 void CPIMAgnAnnivAdapter::ReadEndFromAgnL(MPIMEventItem&, CCalEntry&) |
|
207 { |
|
208 JELOG2(EPim); |
|
209 // Empty implementation, as no END field is supported for Anniversary. |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CPIMAgnAnnivAdapter::AddDefaultValuesToEntryL |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 void CPIMAgnAnnivAdapter::AddDefaultValuesToEntryL(const MPIMEventItem& aItem, |
|
217 CCalEntry& aEntry) const |
|
218 { |
|
219 JELOG2(EPim); |
|
220 // Add common event default values to the native entry |
|
221 CPIMAgnEventAdapter::AddDefaultValuesToEntryL(aItem, aEntry); |
|
222 const MPIMItemData& data = aItem.ItemData(); |
|
223 |
|
224 if (data.CountValues(EPIMEventStart) == 0) |
|
225 { |
|
226 TTime local; |
|
227 local.HomeTime(); |
|
228 // Convert start field to start of the date. Time component is ignored |
|
229 // Set time as local time since acquired above as local time |
|
230 TCalTime calTime; |
|
231 calTime.SetTimeLocalL(StartOfDay(local)); |
|
232 aEntry.SetStartAndEndTimeL(calTime, calTime); |
|
233 } |
|
234 } |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // CPIMAgnAnnivAdapter::ConstructL |
|
238 // Symbian 2nd phase constructor can leave. |
|
239 // ----------------------------------------------------------------------------- |
|
240 // |
|
241 void CPIMAgnAnnivAdapter::ConstructL() |
|
242 { |
|
243 JELOG2(EPim); |
|
244 CPIMAgnEventAdapter::ConstructL(); |
|
245 } |
|
246 |
|
247 // End of File |