|
1 /******************************************************************************* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. This program and the accompanying materials |
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
|
5 * which accompanies this distribution, and is available at |
|
6 * http://www.eclipse.org/legal/epl-v10.html |
|
7 * |
|
8 * Contributors: |
|
9 * Nokia Corporation - S60 implementation |
|
10 *******************************************************************************/ |
|
11 |
|
12 |
|
13 #include "mifconverter.h" |
|
14 |
|
15 |
|
16 CMifConverter* CMifConverter::NewL(RFs& aFs, const TDesC& aMifFile) |
|
17 { |
|
18 CMifConverter* self = new(ELeave) CMifConverter(aFs); |
|
19 CleanupStack::PushL(self); |
|
20 self->ConstructL(aMifFile); |
|
21 CleanupStack::Pop(self); |
|
22 return self; |
|
23 } |
|
24 |
|
25 CMifConverter::~CMifConverter() |
|
26 { |
|
27 iMifWriteStream.Close(); |
|
28 } |
|
29 |
|
30 |
|
31 void CMifConverter::WriteMifFileHeaderL(const TMifFileHeader& aMifFileHeader) |
|
32 { |
|
33 // write file header |
|
34 iMifWriteStream.WriteInt32L(aMifFileHeader.iUid); |
|
35 iMifWriteStream.WriteInt32L(aMifFileHeader.iVersion); |
|
36 iMifWriteStream.WriteInt32L(aMifFileHeader.iOffset); |
|
37 iMifWriteStream.WriteInt32L(aMifFileHeader.iLength); |
|
38 iMifWriteStream.CommitL(); |
|
39 } |
|
40 |
|
41 |
|
42 void CMifConverter::WriteMifIconOffsetL(const TMifIconOffset& aMifIconOffset) |
|
43 { |
|
44 // write icon offset |
|
45 iMifWriteStream.WriteInt32L(aMifIconOffset.iIconOffset); |
|
46 iMifWriteStream.WriteInt32L(aMifIconOffset.iIconLength); |
|
47 iMifWriteStream.CommitL(); |
|
48 } |
|
49 |
|
50 |
|
51 void CMifConverter::WriteMifIconHeaderL(const TMifIconHeader& aMifIconHeader) |
|
52 { |
|
53 // write icon header |
|
54 iMifWriteStream.WriteInt32L(aMifIconHeader.iUid); |
|
55 iMifWriteStream.WriteInt32L(aMifIconHeader.iVersion); |
|
56 iMifWriteStream.WriteInt32L(aMifIconHeader.iOffset); |
|
57 iMifWriteStream.WriteInt32L(aMifIconHeader.iLength); |
|
58 iMifWriteStream.WriteInt32L(aMifIconHeader.iType); |
|
59 iMifWriteStream.WriteInt32L(aMifIconHeader.iDepth); |
|
60 iMifWriteStream.WriteInt32L(aMifIconHeader.iAnimated); |
|
61 iMifWriteStream.WriteInt32L(aMifIconHeader.iMaskDepth); |
|
62 iMifWriteStream.CommitL(); |
|
63 } |
|
64 |
|
65 |
|
66 void CMifConverter::WriteMifBodyL(const TDesC8& apIconBuf) |
|
67 { |
|
68 iMifWriteStream.WriteL(apIconBuf); |
|
69 iMifWriteStream.CommitL(); |
|
70 } |
|
71 |
|
72 CMifConverter::CMifConverter(RFs& aFs): iFs(aFs) |
|
73 { |
|
74 } |
|
75 |
|
76 void CMifConverter::ConstructL(const TDesC& aMifFile) |
|
77 { |
|
78 TInt err = iMifWriteStream.Create(iFs, aMifFile, EFileWrite); |
|
79 if (KErrAlreadyExists == err) |
|
80 { |
|
81 // Temp file has not been removed as it should, |
|
82 // must destroy it before we can reuse it. |
|
83 err = iFs.Delete(aMifFile); |
|
84 User::LeaveIfError(err); |
|
85 // Destroying the file succeeded, try again to create write stream |
|
86 err = iMifWriteStream.Create(iFs, aMifFile, EFileWrite); |
|
87 } |
|
88 User::LeaveIfError(err); |
|
89 } |