|
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 entries |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // CLASS HEADER |
|
20 #include "cpimagnapptadapter.h" |
|
21 |
|
22 // INTERNAL INCLUDES |
|
23 #include "pimpanics.h" |
|
24 #include "agneventsupport.h" |
|
25 #include "mpimrepeatruledata.h" |
|
26 #include "mpimitemdata.h" |
|
27 #include "mpimeventitem.h" |
|
28 #include "logger.h" |
|
29 |
|
30 // EXTERNAL INCLUDES |
|
31 #include <calentry.h> |
|
32 #include <calrrule.h> |
|
33 #include <calalarm.h> |
|
34 |
|
35 // ============================ MEMBER FUNCTIONS =============================== |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CPIMAgnApptAdapter::NewL |
|
39 // Two-phased constructor. |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CPIMAgnApptAdapter* CPIMAgnApptAdapter::NewL( |
|
43 java::util::FunctionServer* aFuncServer) |
|
44 { |
|
45 JELOG2(EPim); |
|
46 CPIMAgnApptAdapter* self = new(ELeave) CPIMAgnApptAdapter(aFuncServer); |
|
47 CleanupStack::PushL(self); |
|
48 CallMethodL(self, &CPIMAgnApptAdapter::ConstructL, self->iFuncServer); |
|
49 CleanupStack::Pop(self); |
|
50 return self; |
|
51 } |
|
52 |
|
53 // destructor |
|
54 CPIMAgnApptAdapter::~CPIMAgnApptAdapter() |
|
55 { |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CPIMAgnApptAdapter::CreateItemToAgnL |
|
60 // Creates a new Agenda Model Appt item from a PIM item data. |
|
61 // Returns: A Appt item based on PIM item data. |
|
62 // The ownership of the Appt item is transferred to the caller. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CCalEntry* CPIMAgnApptAdapter::CreateItemToAgnL(const MPIMEventItem& aItem) |
|
66 { |
|
67 JELOG2(EPim); |
|
68 // Create new calendar entry |
|
69 CCalEntry* entry = CreateCalendarEntryLC(CCalEntry::EAppt); |
|
70 // Add default values to the item. The default values are used |
|
71 // by the native calendar application and therefore needed to be added |
|
72 AddDefaultValuesToEntryL(aItem, *entry); |
|
73 // Convert fields from Java side to the native side |
|
74 ConvertFieldsToAgnL(aItem, *entry); |
|
75 // Convert repeat rule since appointments can have recurrence rules |
|
76 if (aItem.IsRepeating()) |
|
77 { |
|
78 ConvertRepeatToAgnL(aItem, *entry); |
|
79 } |
|
80 |
|
81 CleanupStack::Pop(entry); |
|
82 return entry; |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CPIMAgnApptAdapter::ReadAgnToItemL |
|
87 // Reads an Agenda Model Appointment item and converts it to framework PIM item. |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 void CPIMAgnApptAdapter::ReadAgnToItemL(MPIMEventItem& aItem, CCalEntry& aEntry) |
|
91 { |
|
92 JELOG2(EPim); |
|
93 ReadFieldsFromAgnL(aItem, aEntry, KPIMSupportedApptFields, |
|
94 KPIMSupportedApptFieldsCount); |
|
95 |
|
96 TCalRRule tempRepeat; |
|
97 if (aEntry.GetRRuleL(tempRepeat)) |
|
98 { |
|
99 ReadRepeatFromAgnL(aItem, aEntry); |
|
100 aItem.GetRepeat()->BackupRepeatL(); |
|
101 } |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // CPIMAgnApptAdapter::UpdateItemToAgnL |
|
106 // Reads an Agenda Model Appt item and updates it based on the PIM item data. |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 void CPIMAgnApptAdapter::UpdateItemToAgnL(const MPIMEventItem& aItem, // PIM Item Data |
|
110 CCalEntry& aEntry) // Agenda Model entry |
|
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, KPIMSupportedApptFields, |
|
116 KPIMSupportedApptFieldsCount); |
|
117 |
|
118 // Convert fields from Java side to the native side |
|
119 ConvertFieldsToAgnL(aItem, aEntry); |
|
120 // If there is a defined repeat rule, convert it also |
|
121 if (aItem.IsRepeating()) |
|
122 { |
|
123 if (aItem.GetRepeat()->IsModified()) |
|
124 { |
|
125 ConvertRepeatToAgnL(aItem, aEntry); |
|
126 } |
|
127 } |
|
128 else |
|
129 { |
|
130 // Clear the repeat, as it might have been removed. |
|
131 aEntry.ClearRepeatingPropertiesL(); |
|
132 } |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // CPIMAgnApptAdapter::CPIMAgnApptAdapter |
|
137 // C++ constructor can NOT contain any code, that |
|
138 // might leave. |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 CPIMAgnApptAdapter::CPIMAgnApptAdapter(java::util::FunctionServer* aFuncServer) : |
|
142 CPIMAgnEventAdapter(aFuncServer) |
|
143 { |
|
144 JELOG2(EPim); |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CPIMAgnApptAdapter::ReadStartFromAgnL |
|
149 // Reads Agenda entry's start field and converts it into PIM Item field. |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 void CPIMAgnApptAdapter::ReadStartFromAgnL(MPIMEventItem& aItem, |
|
153 CCalEntry& aEntry) |
|
154 { |
|
155 JELOG2(EPim); |
|
156 TTime agnStartTime = aEntry.StartTimeL().TimeUtcL(); |
|
157 if (agnStartTime != Time::NullTTime()) |
|
158 { |
|
159 TPIMFieldData fieldData(EPIMEventStart, KPIMAttrNone, agnStartTime); |
|
160 aItem.ItemData().AddValueL(fieldData); |
|
161 } |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CPIMAgnApptAdapter::ReadEndFromAgnL |
|
166 // Reads Agenda entry's end field and converts it into PIM Item field. |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 void CPIMAgnApptAdapter::ReadEndFromAgnL(MPIMEventItem& aItem, |
|
170 CCalEntry& aEntry) |
|
171 { |
|
172 JELOG2(EPim); |
|
173 TTime agnEndTime = aEntry.EndTimeL().TimeUtcL(); |
|
174 if (agnEndTime != Time::NullTTime()) |
|
175 { |
|
176 TPIMFieldData fieldData(EPIMEventEnd, KPIMAttrNone, agnEndTime); |
|
177 aItem.ItemData().AddValueL(fieldData); |
|
178 } |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CPIMAgnApptAdapter::AddDefaultValuesToEntryL |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 void CPIMAgnApptAdapter::AddDefaultValuesToEntryL(const MPIMEventItem& aItem, |
|
186 CCalEntry& aEntry) const |
|
187 { |
|
188 JELOG2(EPim); |
|
189 // Add common event default values to the native entry |
|
190 CPIMAgnEventAdapter::AddDefaultValuesToEntryL(aItem, aEntry); |
|
191 const MPIMItemData& data = aItem.ItemData(); |
|
192 |
|
193 // Set default start and end time if these are not present in the Java item |
|
194 if (data.CountValues(EPIMEventStart) == 0 && data.CountValues(EPIMEventEnd) |
|
195 == 0) |
|
196 { |
|
197 TCalTime defaultTime; |
|
198 TTime currentTime; |
|
199 // Get current time in universal time |
|
200 currentTime.UniversalTime(); |
|
201 defaultTime.SetTimeUtcL(currentTime); |
|
202 aEntry.SetStartAndEndTimeL(defaultTime, defaultTime); |
|
203 } |
|
204 } |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // CPIMAgnApptAdapter::ConstructL |
|
208 // Symbian 2nd phase constructor can leave. |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 void CPIMAgnApptAdapter::ConstructL() |
|
212 { |
|
213 JELOG2(EPim); |
|
214 CPIMAgnEventAdapter::ConstructL(); |
|
215 } |
|
216 |
|
217 // End of file |