|
1 /* |
|
2 * Copyright (c) 2002 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: The class converts from a stream to one or more agenda |
|
15 * entries. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 //debug |
|
21 #include "calendarengines_debug.h" |
|
22 |
|
23 // INCLUDE FILES |
|
24 #include "CalenImporter.h" |
|
25 |
|
26 |
|
27 #include "AgnExternalInterface.h" |
|
28 #include <agnimportobserver.h> |
|
29 |
|
30 #include <caldataexchange.h> |
|
31 #include <calentry.h> |
|
32 #include <caldataformat.h> |
|
33 #include <featmgr.h> |
|
34 |
|
35 #include <coemain.h> |
|
36 //#include <AgnVersit.h> // not used because of symbian's Sphinx release |
|
37 |
|
38 |
|
39 |
|
40 // LOCAL CONSTANTS AND MACROS |
|
41 _LIT8( KICalMimeType, "text/calendar" ); |
|
42 |
|
43 |
|
44 // ================= MEMBER FUNCTIONS ======================= |
|
45 |
|
46 // Two-phased constructor. |
|
47 EXPORT_C CCalenImporter* CCalenImporter::NewL( CCalSession& aSession ) |
|
48 { |
|
49 TRACE_ENTRY_POINT; |
|
50 |
|
51 CCalenImporter* self = new (ELeave) CCalenImporter( aSession ); |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(); |
|
54 CleanupStack::Pop(); // self |
|
55 |
|
56 TRACE_EXIT_POINT; |
|
57 return self; |
|
58 } |
|
59 |
|
60 // Destructor. |
|
61 EXPORT_C CCalenImporter::~CCalenImporter() |
|
62 { |
|
63 TRACE_ENTRY_POINT; |
|
64 |
|
65 delete iICalInterface; |
|
66 delete iVCalDataExchange; |
|
67 FeatureManager::UnInitializeLib(); |
|
68 |
|
69 TRACE_EXIT_POINT; |
|
70 } |
|
71 |
|
72 // C++ default constructor. |
|
73 CCalenImporter::CCalenImporter( CCalSession& aSession ) : |
|
74 iSession( aSession ) |
|
75 { |
|
76 TRACE_ENTRY_POINT; |
|
77 |
|
78 //Debug counter, used for incrementing the file number |
|
79 #ifdef TRACE_TO_FILE_IMPORT |
|
80 iFileNumber = 0; |
|
81 #endif |
|
82 |
|
83 iImportMode=ECalenImportModeNormal; |
|
84 |
|
85 TRACE_EXIT_POINT; |
|
86 } |
|
87 |
|
88 // By default Symbian OS constructor is private. |
|
89 void CCalenImporter::ConstructL() |
|
90 { |
|
91 TRACE_ENTRY_POINT; |
|
92 |
|
93 FeatureManager::InitializeLibL(); |
|
94 |
|
95 TRACE_EXIT_POINT; |
|
96 } |
|
97 |
|
98 // Possibility to set the import mode for importer to use e.g. japanese charset. |
|
99 EXPORT_C void CCalenImporter::SetImportMode(TCalenImportMode aImportMode) |
|
100 { |
|
101 TRACE_ENTRY_POINT; |
|
102 |
|
103 iImportMode=aImportMode; |
|
104 |
|
105 TRACE_EXIT_POINT; |
|
106 } |
|
107 |
|
108 |
|
109 // --------------------------------------------------------- |
|
110 // CCalenImporter::ImportVCalendarL |
|
111 // Import vCalendar entries from aReadStream to aArray. |
|
112 // (other items were commented in a header). |
|
113 // --------------------------------------------------------- |
|
114 // |
|
115 EXPORT_C void CCalenImporter::ImportVCalendarL( |
|
116 RReadStream& aReadStream, |
|
117 RPointerArray<CCalEntry>& aArray ) |
|
118 { |
|
119 TRACE_ENTRY_POINT; |
|
120 |
|
121 //Debug - Write the vCal to file |
|
122 #ifdef TRACE_TO_FILE_IMPORT |
|
123 DebugPrintFunction( aReadStream ); |
|
124 #endif |
|
125 |
|
126 if( ! iVCalDataExchange ) |
|
127 { |
|
128 iVCalDataExchange = CCalDataExchange::NewL( iSession ); |
|
129 } |
|
130 |
|
131 // check if extended flag is on and japanese variant is on. |
|
132 if ( (iImportMode==ECalenImportModeExtended) && (FeatureManager::FeatureSupported(KFeatureIdJapanese) )) |
|
133 { |
|
134 // if Japanese flag is set we will pass Japanese charset flag to ImportL |
|
135 iVCalDataExchange->ImportL( KUidVCalendar, aReadStream, aArray,KCalDataExchangeDefaultShiftJIS); |
|
136 |
|
137 } |
|
138 // we use normal method (ECalenImportModeNormal) |
|
139 else |
|
140 { |
|
141 iVCalDataExchange->ImportL( KUidVCalendar, aReadStream, aArray ); |
|
142 } |
|
143 |
|
144 TRACE_EXIT_POINT; |
|
145 } |
|
146 |
|
147 // --------------------------------------------------------- |
|
148 // CCalenImporter::ImportICalendarL |
|
149 // Import iCalendar entries from aReadStream to aArray. |
|
150 // (other items were commented in a header). |
|
151 // --------------------------------------------------------- |
|
152 // |
|
153 EXPORT_C void CCalenImporter::ImportICalendarL( |
|
154 RReadStream& aReadStream, |
|
155 RPointerArray<CCalEntry>& aArray ) |
|
156 { |
|
157 TRACE_ENTRY_POINT; |
|
158 |
|
159 //Debug - Write the iCal to file |
|
160 #ifdef TRACE_TO_FILE_IMPORT |
|
161 DebugPrintFunction( aReadStream ); |
|
162 #endif |
|
163 |
|
164 if( ! iICalInterface ) |
|
165 { |
|
166 iICalInterface = CAgnExternalInterface::NewL( KICalMimeType ); |
|
167 } |
|
168 iICalInterface->ImportL( aArray, aReadStream, 0, *this ); |
|
169 |
|
170 TRACE_EXIT_POINT; |
|
171 } |
|
172 |
|
173 MAgnImportObserver::TImpResponse CCalenImporter::AgnImportErrorL( |
|
174 TImpError /*aType*/, |
|
175 const TDesC8& /*aUid*/, |
|
176 const TDesC& /*aContext*/ ) |
|
177 { |
|
178 TRACE_ENTRY_POINT; |
|
179 TRACE_EXIT_POINT; |
|
180 return EImpResponseContinue; |
|
181 } |
|
182 |
|
183 |
|
184 #ifdef TRACE_TO_FILE_IMPORT |
|
185 //Wrapper function to write the readstream to file |
|
186 void CCalenImporter::DebugPrintFunction( RReadStream& aReadStream ) |
|
187 { |
|
188 TRAPD( error, WriteReadStreamToFileL( aReadStream ) ); |
|
189 |
|
190 //Even if WriteReadStreamToFileL leaves we want to reset the file |
|
191 //because we don't know which function left |
|
192 TRAP( error, ResetReadStreamL( aReadStream )); |
|
193 } |
|
194 |
|
195 //Writes the stream to a file |
|
196 void CCalenImporter::WriteReadStreamToFileL( RReadStream& aReadStream ) |
|
197 { |
|
198 TBuf<50> fileName; |
|
199 _LIT(KDefaultFileName, "C://calenImp_%d.txt"); |
|
200 fileName.Format( KDefaultFileName, iFileNumber ); |
|
201 |
|
202 RFs aFs; |
|
203 User::LeaveIfError(aFs.Connect()); |
|
204 CleanupClosePushL(aFs); |
|
205 aFs.MkDirAll(KDefaultFileName); |
|
206 |
|
207 RFileWriteStream rs; |
|
208 User::LeaveIfError(rs.Replace(aFs, fileName, EFileWrite)); |
|
209 CleanupClosePushL(rs); |
|
210 |
|
211 rs.WriteL( aReadStream ); |
|
212 rs.CommitL(); |
|
213 |
|
214 CleanupStack::PopAndDestroy(&rs); |
|
215 CleanupStack::PopAndDestroy(&aFs); |
|
216 |
|
217 //Increase the filenumber with one, a new file is created for each vCal/iCal |
|
218 ++iFileNumber; |
|
219 } |
|
220 |
|
221 //Resets the stream pointer to point to begining of stream |
|
222 void CCalenImporter::ResetReadStreamL( RReadStream& aReadStream ) |
|
223 { |
|
224 //Set the read pointer to point to the beginning of the stream |
|
225 TStreamPos pos( 0 ); |
|
226 MStreamBuf* streamBuf = aReadStream.Source(); |
|
227 streamBuf->SeekL( MStreamBuf::ERead, pos ); |
|
228 } |
|
229 #endif |
|
230 |
|
231 // ================= OTHER EXPORTED FUNCTIONS ============== |
|
232 // |
|
233 // --------------------------------------------------------- |
|
234 // E32Dll(TDllReason) |
|
235 // Entry point function for Symbian OS Apps |
|
236 // Returns: KErrNone: No error |
|
237 // --------------------------------------------------------- |
|
238 // |
|
239 #ifndef EKA2 |
|
240 GLDEF_C TInt E32Dll(TDllReason) |
|
241 { |
|
242 return KErrNone; |
|
243 } |
|
244 #endif |
|
245 |
|
246 // End of File |