|
1 /* |
|
2 * Copyright (c) 2003-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: Data classs and structures. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <string.h> |
|
20 #include <sys/stat.h> |
|
21 |
|
22 #include "SDCGlobals.h" |
|
23 #include "SDCData.h" |
|
24 #include "SDCException.h" |
|
25 #include "SDCInput.h" |
|
26 |
|
27 // Make std namespace available for compatibility |
|
28 namespace std {} |
|
29 using namespace std; |
|
30 |
|
31 ////////////////////////////////////////////////////////////////////// |
|
32 // Construction/Destruction |
|
33 ////////////////////////////////////////////////////////////////////// |
|
34 |
|
35 CSDCData::CSDCData() |
|
36 { |
|
37 iNextOwnMinor = 0x1000; |
|
38 iAHOverridePid.iPID1 = 0; |
|
39 iAHOverridePid.iPID2 = 0; |
|
40 iParentPid.iPID1 = 0; |
|
41 iParentPid.iPID2 = 0; |
|
42 iPalettePid.iPID1 = 0; |
|
43 iPalettePid.iPID2 = 0; |
|
44 iProtection = 0; |
|
45 iAuthor[0] = 0; |
|
46 iCopyright[0] = 0; |
|
47 iTool[0] = 0; |
|
48 iBmpPath[0] = 0; |
|
49 iCurrentRestriction = 0; |
|
50 |
|
51 iNextIconIndex = 16384; |
|
52 } |
|
53 |
|
54 CSDCData::~CSDCData() |
|
55 { |
|
56 while( iNameVector.size()>0 ) |
|
57 { |
|
58 delete iNameVector.back(); |
|
59 iNameVector.pop_back(); |
|
60 } |
|
61 while( iMbmVector.size()>0 ) |
|
62 { |
|
63 delete iMbmVector.back(); |
|
64 iMbmVector.pop_back(); |
|
65 } |
|
66 while( iBitmapDefVector.size()>0 ) |
|
67 { |
|
68 delete iBitmapDefVector.back(); |
|
69 iBitmapDefVector.pop_back(); |
|
70 } |
|
71 while( iColorTableDefVector.size()>0 ) |
|
72 { |
|
73 delete iColorTableDefVector.back(); |
|
74 iColorTableDefVector.pop_back(); |
|
75 } |
|
76 while( iFrameDefVector.size()>0 ) |
|
77 { |
|
78 delete iFrameDefVector.back(); |
|
79 iFrameDefVector.pop_back(); |
|
80 } |
|
81 while( iAppIconDefVector.size()>0 ) |
|
82 { |
|
83 delete iAppIconDefVector.back(); |
|
84 iAppIconDefVector.pop_back(); |
|
85 } |
|
86 while( iBmpAnimDefVector.size()>0 ) |
|
87 { |
|
88 delete iBmpAnimDefVector.back(); |
|
89 iBmpAnimDefVector.pop_back(); |
|
90 } |
|
91 while( iTargetDeviceVector.size()>0 ) |
|
92 { |
|
93 delete iTargetDeviceVector.back(); |
|
94 iTargetDeviceVector.pop_back(); |
|
95 } |
|
96 while( iStringDefVector.size()>0 ) |
|
97 { |
|
98 delete iStringDefVector.back(); |
|
99 iStringDefVector.pop_back(); |
|
100 } |
|
101 while( iScalableItemDefVector.size()>0 ) |
|
102 { |
|
103 delete iScalableItemDefVector.back(); |
|
104 iScalableItemDefVector.pop_back(); |
|
105 } |
|
106 while( iAnimationDefVector.size()>0 ) |
|
107 { |
|
108 delete iAnimationDefVector.back(); |
|
109 iAnimationDefVector.pop_back(); |
|
110 } |
|
111 while( iLanguageVector.size()>0 ) |
|
112 { |
|
113 iLanguageVector.pop_back(); |
|
114 } |
|
115 } |
|
116 |
|
117 ////////////////////////////////////////////////////////////////////// |
|
118 // Other methods |
|
119 ////////////////////////////////////////////////////////////////////// |
|
120 |
|
121 bool CSDCData::IsScalable() |
|
122 { |
|
123 if( iSkinType == 0x80 ) return true; |
|
124 return false; |
|
125 } |
|
126 |
|
127 bool CSDCData::IsDefined( const TSDCIID aIID ) |
|
128 { |
|
129 int i; |
|
130 for( i=0; i<iBitmapDefVector.size(); i++ ) |
|
131 { |
|
132 TSDCBitmapDef* entry = iBitmapDefVector[i]; |
|
133 if( (entry->iIID.iMajor==aIID.iMajor) && (entry->iIID.iMinor==aIID.iMinor) ) return true; |
|
134 } |
|
135 for( i=0; i<iColorTableDefVector.size(); i++ ) |
|
136 { |
|
137 TSDCColorTableDef* entry = iColorTableDefVector[i]; |
|
138 if( (entry->iIID.iMajor==aIID.iMajor) && (entry->iIID.iMinor==aIID.iMinor) ) return true; |
|
139 } |
|
140 for( i=0; i<iFrameDefVector.size(); i++ ) |
|
141 { |
|
142 TSDCFrameDef* entry = iFrameDefVector[i]; |
|
143 if( (entry->iIID.iMajor==aIID.iMajor) && (entry->iIID.iMinor==aIID.iMinor) ) return true; |
|
144 } |
|
145 for( i=0; i<iAppIconDefVector.size(); i++ ) |
|
146 { |
|
147 TSDCAppIconDef* entry = iAppIconDefVector[i]; |
|
148 if( (entry->iIID.iMajor==aIID.iMajor) && (entry->iIID.iMinor==aIID.iMinor) ) return true; |
|
149 } |
|
150 for( i=0; i<iBmpAnimDefVector.size(); i++ ) |
|
151 { |
|
152 TSDCBmpAnimDef* entry = iBmpAnimDefVector[i]; |
|
153 if( (entry->iIID.iMajor==aIID.iMajor) && (entry->iIID.iMinor==aIID.iMinor) ) return true; |
|
154 } |
|
155 for( i=0; i<iStringDefVector.size(); i++ ) |
|
156 { |
|
157 TSDCStringDef* entry = iStringDefVector[i]; |
|
158 if( (entry->iIID.iMajor==aIID.iMajor) && (entry->iIID.iMinor==aIID.iMinor) ) return true; |
|
159 } |
|
160 for( i=0; i<iScalableItemDefVector.size(); i++ ) |
|
161 { |
|
162 TSDCScalableItemDef* entry = iScalableItemDefVector[i]; |
|
163 if( (entry->iIID.iMajor==aIID.iMajor) && (entry->iIID.iMinor==aIID.iMinor) ) return true; |
|
164 } |
|
165 for( i=0; i<iAnimationDefVector.size(); i++ ) |
|
166 { |
|
167 TSDCAnimationDef* entry = iAnimationDefVector[i]; |
|
168 if( (entry->iIID.iMajor==aIID.iMajor) && (entry->iIID.iMinor==aIID.iMinor) ) return true; |
|
169 } |
|
170 return false; |
|
171 } |
|
172 |
|
173 bool CSDCData::IsDefined( const TSDCIID aIID, const int aRestriction ) |
|
174 { |
|
175 int i; |
|
176 for( i=0; i<iBitmapDefVector.size(); i++ ) |
|
177 { |
|
178 TSDCBitmapDef* entry = iBitmapDefVector[i]; |
|
179 if( (entry->iIID.iMajor==aIID.iMajor) && (entry->iIID.iMinor==aIID.iMinor) && (entry->iRestriction==aRestriction) ) return true; |
|
180 } |
|
181 for( i=0; i<iColorTableDefVector.size(); i++ ) |
|
182 { |
|
183 TSDCColorTableDef* entry = iColorTableDefVector[i]; |
|
184 if( (entry->iIID.iMajor==aIID.iMajor) && (entry->iIID.iMinor==aIID.iMinor) && (entry->iRestriction==aRestriction) ) return true; |
|
185 } |
|
186 for( i=0; i<iFrameDefVector.size(); i++ ) |
|
187 { |
|
188 TSDCFrameDef* entry = iFrameDefVector[i]; |
|
189 if( (entry->iIID.iMajor==aIID.iMajor) && (entry->iIID.iMinor==aIID.iMinor) && (entry->iRestriction==aRestriction) ) return true; |
|
190 } |
|
191 for( i=0; i<iAppIconDefVector.size(); i++ ) |
|
192 { |
|
193 TSDCAppIconDef* entry = iAppIconDefVector[i]; |
|
194 if( (entry->iIID.iMajor==aIID.iMajor) && (entry->iIID.iMinor==aIID.iMinor) && (entry->iRestriction==aRestriction) ) return true; |
|
195 } |
|
196 for( i=0; i<iBmpAnimDefVector.size(); i++ ) |
|
197 { |
|
198 TSDCBmpAnimDef* entry = iBmpAnimDefVector[i]; |
|
199 if( (entry->iIID.iMajor==aIID.iMajor) && (entry->iIID.iMinor==aIID.iMinor) && (entry->iRestriction==aRestriction) ) return true; |
|
200 } |
|
201 for( i=0; i<iStringDefVector.size(); i++ ) |
|
202 { |
|
203 TSDCStringDef* entry = iStringDefVector[i]; |
|
204 if( (entry->iIID.iMajor==aIID.iMajor) && (entry->iIID.iMinor==aIID.iMinor) && (entry->iRestriction==aRestriction) ) return true; |
|
205 } |
|
206 for( i=0; i<iScalableItemDefVector.size(); i++ ) |
|
207 { |
|
208 TSDCScalableItemDef* entry = iScalableItemDefVector[i]; |
|
209 if( (entry->iIID.iMajor==aIID.iMajor) && (entry->iIID.iMinor==aIID.iMinor) && (entry->iRestriction==aRestriction) ) return true; |
|
210 } |
|
211 for( i=0; i<iAnimationDefVector.size(); i++ ) |
|
212 { |
|
213 TSDCAnimationDef* entry = iAnimationDefVector[i]; |
|
214 if( (entry->iIID.iMajor==aIID.iMajor) && (entry->iIID.iMinor==aIID.iMinor) && (entry->iRestriction==aRestriction) ) return true; |
|
215 } |
|
216 return false; |
|
217 } |
|
218 |
|
219 void CSDCData::AppendNameEntry( const int aLanguageID, const wchar_t* aName ) |
|
220 { |
|
221 for( int i=0; i<iNameVector.size(); i++ ) |
|
222 { |
|
223 TSDCNameEntry* entry = iNameVector[i]; |
|
224 if( entry->iLanguageID == aLanguageID ) throw CSDCException( ESDCContentError, "Name for the language ID has already been specified" ); |
|
225 } |
|
226 |
|
227 TSDCNameEntry* entry = new TSDCNameEntry(); |
|
228 entry->iLanguageID = aLanguageID; |
|
229 wcscpy( entry->iName, aName ); |
|
230 iNameVector.push_back( entry ); |
|
231 } |
|
232 |
|
233 void CSDCData::AppendTargetDeviceEntry( const wchar_t* aDeviceName ) |
|
234 { |
|
235 TSDCTargetDeviceEntry* entry = new TSDCTargetDeviceEntry(); |
|
236 wcscpy( entry->iDeviceName, aDeviceName ); |
|
237 iTargetDeviceVector.push_back( entry ); |
|
238 } |
|
239 |
|
240 bool CSDCData::HasMbmEntry( const TSDCColorDepth aColorDepth, const wchar_t* aFilename ) |
|
241 { |
|
242 return FindMbmEntry(aColorDepth,aFilename)?true:false; |
|
243 } |
|
244 |
|
245 TSDCMBMEntry* CSDCData::FindMbmEntry( const TSDCColorDepth aColorDepth, const wchar_t* aFilename ) |
|
246 { |
|
247 for( int i=0; i<iMbmVector.size(); i++ ) |
|
248 { |
|
249 TSDCMBMEntry* entry = iMbmVector[i]; |
|
250 if( (_wcsicmp(entry->iSourcePath,iBmpPath)==0) && |
|
251 (entry->iColorDepth==aColorDepth) && |
|
252 (_wcsicmp(entry->iSourceFilename,aFilename)==0) ) return entry; |
|
253 } |
|
254 return NULL; |
|
255 } |
|
256 |
|
257 TSDCMBMEntry* CSDCData::AppendMbmEntry( const bool aSvg, |
|
258 const TSDCColorDepth aColorDepth, const wchar_t* aFilename, |
|
259 const bool aSvgAnim ) |
|
260 { |
|
261 TSDCMBMEntry* entry = FindMbmEntry( aColorDepth, aFilename ); |
|
262 if( entry ) return entry; |
|
263 |
|
264 entry = new TSDCMBMEntry(); |
|
265 |
|
266 //check file |
|
267 if( !CheckFile( iBmpPath , aFilename ) ) |
|
268 { |
|
269 char filename[512]; |
|
270 CSDCInput::ConvertToAscii( filename, aFilename ); |
|
271 printf("NOTE: item %s not add beacuse file not exist!!\n",filename); |
|
272 return entry; |
|
273 } |
|
274 |
|
275 entry->iIndex = iNextIconIndex; |
|
276 iNextIconIndex += 2; |
|
277 |
|
278 wcscpy( entry->iSourceFilename, aFilename ); |
|
279 |
|
280 entry->iColorDepth = aColorDepth; |
|
281 wcscpy( entry->iSourcePath, iBmpPath ); |
|
282 |
|
283 entry->iMaskColorDepth = ESDCColorDepthNone; |
|
284 wcscpy( entry->iMaskSourceFilename, L"" ); |
|
285 |
|
286 entry->iSvgAnim = aSvgAnim; |
|
287 |
|
288 iMbmVector.push_back( entry ); |
|
289 return entry; |
|
290 } |
|
291 |
|
292 void CSDCData::SetBmpPath( const wchar_t* aPath ) |
|
293 { |
|
294 if( !aPath ) |
|
295 { |
|
296 wcscpy( iBmpPath, L"" ); |
|
297 } |
|
298 else |
|
299 { |
|
300 wcscpy( iBmpPath, aPath ); |
|
301 if( wcslen( iBmpPath ) && |
|
302 wcscmp( iBmpPath+wcslen(iBmpPath)-1, L"\\" ) ) |
|
303 { |
|
304 wcscat( iBmpPath, L"\\" ); |
|
305 printf("NOTE: Trailing backslash appended to bitmap path\n"); |
|
306 } |
|
307 } |
|
308 } |
|
309 |
|
310 void CSDCData::CreateBitmapDef( const TSDCIID aIID, const int aIndex, const int aMaskIndex, const TSDCImageAttributes aAttributes, const bool aAppIcon, const int aRestriction ) |
|
311 { |
|
312 if( IsDefined( aIID, aRestriction ) ) throw CSDCException( ESDCContentError, "Item already defined" ); |
|
313 |
|
314 TSDCBitmapDef* entry = new TSDCBitmapDef(); |
|
315 entry->iIID = aIID; |
|
316 entry->iMBMIndex = aIndex; |
|
317 entry->iMaskMBMIndex = aMaskIndex; |
|
318 entry->iAttributes = aAttributes; |
|
319 entry->iAppIconBitmap = aAppIcon; |
|
320 entry->iRestriction = aRestriction; |
|
321 iBitmapDefVector.push_back( entry ); |
|
322 } |
|
323 |
|
324 TSDCBitmapDef* CSDCData::GetBitmapDef( const TSDCIID aIID ) |
|
325 { |
|
326 for( int i=0; i<iBitmapDefVector.size(); i++ ) |
|
327 { |
|
328 TSDCBitmapDef* entry = iBitmapDefVector[i]; |
|
329 if( (entry->iIID.iMajor==aIID.iMajor) && (entry->iIID.iMinor==aIID.iMinor) ) return entry; |
|
330 } |
|
331 return NULL; |
|
332 } |
|
333 |
|
334 void CSDCData::CreateColorTableDef( const TSDCIID aIID, const vector<TSDCColorTableEntry> aColors, const int aRestriction ) |
|
335 { |
|
336 if( IsDefined( aIID, aRestriction ) ) throw CSDCException( ESDCContentError, "Item already defined" ); |
|
337 |
|
338 TSDCColorTableDef* entry = new TSDCColorTableDef(); |
|
339 entry->iIID = aIID; |
|
340 entry->iColors = aColors; |
|
341 entry->iRestriction = aRestriction; |
|
342 iColorTableDefVector.push_back( entry ); |
|
343 } |
|
344 |
|
345 void CSDCData::CreateFrameDef( const TSDCIID aIID, const vector<TSDCIID> aElements, const int aRestriction ) |
|
346 { |
|
347 if( IsDefined( aIID, aRestriction ) ) throw CSDCException( ESDCContentError, "Item already defined" ); |
|
348 if( aElements.size() != 9 ) throw CSDCException( ESDCContentError, "Frame must have 9 elements" ); |
|
349 |
|
350 TSDCFrameDef* entry = new TSDCFrameDef(); |
|
351 entry->iIID = aIID; |
|
352 entry->iElements = aElements; |
|
353 entry->iRestriction = aRestriction; |
|
354 iFrameDefVector.push_back( entry ); |
|
355 } |
|
356 |
|
357 void CSDCData::CreateAppIconDef( const TSDCIID aIID, const vector<TSDCIID> aIcons, const int aRestriction ) |
|
358 { |
|
359 if( IsDefined( aIID, aRestriction ) ) throw CSDCException( ESDCContentError, "Item already defined" ); |
|
360 |
|
361 TSDCAppIconDef* entry = new TSDCAppIconDef(); |
|
362 entry->iIID = aIID; |
|
363 entry->iIcons = aIcons; |
|
364 entry->iRestriction = aRestriction; |
|
365 iAppIconDefVector.push_back( entry ); |
|
366 } |
|
367 |
|
368 void CSDCData::CreateBmpAnimDef( const TSDCIID aIID, const int aInterval, const int aPlayMode, const int aFlash, const vector<TSDCBmpAnimFrame> aFrames, const int aRestriction ) |
|
369 { |
|
370 if( IsDefined( aIID, aRestriction ) ) throw CSDCException( ESDCContentError, "Item already defined" ); |
|
371 |
|
372 TSDCBmpAnimDef* entry = new TSDCBmpAnimDef(); |
|
373 entry->iIID = aIID; |
|
374 entry->iInterval = aInterval; |
|
375 entry->iPlayMode = aPlayMode; |
|
376 entry->iFlash = aFlash; |
|
377 entry->iFrames = aFrames; |
|
378 entry->iRestriction = aRestriction; |
|
379 iBmpAnimDefVector.push_back( entry ); |
|
380 } |
|
381 |
|
382 void CSDCData::CreateStringDef( const TSDCIID aIID, const wchar_t* aString, const int aRestriction ) |
|
383 { |
|
384 if( IsDefined( aIID, aRestriction ) ) throw CSDCException( ESDCContentError, "Item already defined" ); |
|
385 |
|
386 TSDCStringDef* entry = new TSDCStringDef(); |
|
387 entry->iIID = aIID; |
|
388 entry->iRestriction = aRestriction; |
|
389 wcscpy( entry->iString, aString ); |
|
390 iStringDefVector.push_back( entry ); |
|
391 } |
|
392 |
|
393 void CSDCData::CreateScalableItemDef( const TSDCIID aIID, const int aInput, const int aOutput, const vector<TSDCEffectCommand> aCommands, const int aRestriction ) |
|
394 { |
|
395 if( IsDefined( aIID, aRestriction ) ) throw CSDCException( ESDCContentError, "Item already defined" ); |
|
396 |
|
397 TSDCScalableItemDef* entry = new TSDCScalableItemDef(); |
|
398 entry->iIID = aIID; |
|
399 entry->iRefIID.iMajor = 0; |
|
400 entry->iRefIID.iMinor = 0; |
|
401 entry->iInput = aInput; |
|
402 entry->iOutput = aOutput; |
|
403 entry->iCommands = aCommands; |
|
404 entry->iRestriction = aRestriction; |
|
405 iScalableItemDefVector.push_back( entry ); |
|
406 } |
|
407 |
|
408 void CSDCData::CreateScalableItemRefDef( const TSDCIID aIID, const TSDCIID aRefIID, const int aRestriction ) |
|
409 { |
|
410 if( IsDefined( aIID, aRestriction ) ) throw CSDCException( ESDCContentError, "Item already defined" ); |
|
411 |
|
412 TSDCScalableItemDef* entry = new TSDCScalableItemDef(); |
|
413 entry->iIID = aIID; |
|
414 entry->iRefIID = aRefIID; |
|
415 entry->iInput = 0; |
|
416 entry->iOutput = 0; |
|
417 entry->iRestriction = aRestriction; |
|
418 iScalableItemDefVector.push_back( entry ); |
|
419 } |
|
420 |
|
421 void CSDCData::CreateAnimationDef( const TSDCIID aIID, const int aInput, const int aOutput, const int aMinInterval, |
|
422 const vector<TSDCEffectCommand> aPreprocessCommands, const vector<TSDCEffectCommand> aAnimCommands, |
|
423 const vector<TSDCAnimParamGroup> aValues, const vector<TSDCAnimParamGroup> aTimingModels, |
|
424 const vector<TSDCAnimParamGroup> aSizeBoundParams, const bool aMorphing, const int aRestriction ) |
|
425 { |
|
426 if( IsDefined( aIID, aRestriction ) ) throw CSDCException( ESDCContentError, "Item already defined" ); |
|
427 |
|
428 TSDCAnimationDef* entry = new TSDCAnimationDef(); |
|
429 entry->iIID = aIID; |
|
430 entry->iInput = aInput; |
|
431 entry->iOutput = aOutput; |
|
432 entry->iMinInterval = aMinInterval; |
|
433 entry->iMorphing = aMorphing; |
|
434 entry->iPreprocessCommands = aPreprocessCommands; |
|
435 entry->iAnimCommands = aAnimCommands; |
|
436 entry->iValues = aValues; |
|
437 entry->iTimingModels = aTimingModels; |
|
438 entry->iSizeBoundParams = aSizeBoundParams; |
|
439 entry->iRestriction = aRestriction; |
|
440 iAnimationDefVector.push_back( entry ); |
|
441 } |
|
442 |
|
443 |
|
444 bool CSDCData::CheckFile( const wchar_t* aPath , const wchar_t* aFileName ) |
|
445 { |
|
446 char asciiPatch[512]; |
|
447 CSDCInput::ConvertToAscii( asciiPatch, aPath ); |
|
448 char asciiFileName[512]; |
|
449 CSDCInput::ConvertToAscii( asciiFileName, aFileName ); |
|
450 |
|
451 strcat(asciiPatch,asciiFileName); |
|
452 |
|
453 struct _stat buf; |
|
454 int result = _stat( asciiPatch, &buf ); |
|
455 if(result == -1) |
|
456 { |
|
457 return false; |
|
458 } |
|
459 return true; |
|
460 |
|
461 } |
|
462 |
|
463 // End of file |