|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "agmcontent.h" |
|
17 #include <s32stor.h> |
|
18 |
|
19 |
|
20 EXPORT_C CAgnContent::CAgnContent() : iType(CCalContent::EDispositionUnknown) |
|
21 { |
|
22 } |
|
23 |
|
24 CAgnContent::CAgnContent(CCalContent::TDisposition aType) : iType(aType) |
|
25 { |
|
26 } |
|
27 |
|
28 EXPORT_C CAgnContent::~CAgnContent() |
|
29 { |
|
30 delete iContent; |
|
31 delete iMimeType; |
|
32 } |
|
33 |
|
34 /** Takes ownership of aSmallContent and aContentMimeType */ |
|
35 EXPORT_C void CAgnContent::SetContentL(TDesC8* aSmallContent, TDesC8* aContentMimeType, CCalContent::TDisposition aType) |
|
36 { |
|
37 delete iContent; |
|
38 iContent = aSmallContent; |
|
39 |
|
40 delete iMimeType; |
|
41 iMimeType = aContentMimeType; |
|
42 |
|
43 iType = aType; |
|
44 } |
|
45 |
|
46 |
|
47 EXPORT_C const TDesC8& CAgnContent::Content() const |
|
48 { |
|
49 if (iContent == NULL) |
|
50 { |
|
51 return KNullDesC8(); |
|
52 } |
|
53 |
|
54 return *iContent; |
|
55 } |
|
56 |
|
57 |
|
58 EXPORT_C const TDesC8& CAgnContent::MimeType() const |
|
59 { |
|
60 if (iMimeType == NULL) |
|
61 { |
|
62 return KNullDesC8(); |
|
63 } |
|
64 |
|
65 return *iMimeType; |
|
66 } |
|
67 |
|
68 |
|
69 EXPORT_C CCalContent::TDisposition CAgnContent::Type() const |
|
70 { |
|
71 return iType; |
|
72 } |
|
73 |
|
74 |
|
75 EXPORT_C CAgnContent* CAgnContent::CloneL() const |
|
76 { |
|
77 CAgnContent* clone = new (ELeave) CAgnContent(); |
|
78 CleanupStack::PushL(clone); |
|
79 |
|
80 HBufC8* content = NULL; |
|
81 if (iContent) |
|
82 { |
|
83 content = iContent->AllocL(); |
|
84 CleanupStack::PushL(content); |
|
85 } |
|
86 |
|
87 HBufC8* mimeType = NULL; |
|
88 if (iMimeType) |
|
89 { |
|
90 mimeType = iMimeType->AllocL(); |
|
91 CleanupStack::PushL(mimeType); |
|
92 } |
|
93 |
|
94 clone->SetContentL(content, mimeType, iType); // takes ownership of content & mimeType. |
|
95 |
|
96 if (mimeType != NULL) |
|
97 { |
|
98 CleanupStack::Pop(mimeType); |
|
99 } |
|
100 if (content != NULL) |
|
101 { |
|
102 CleanupStack::Pop(content); |
|
103 } |
|
104 |
|
105 CleanupStack::Pop(clone); |
|
106 return clone; |
|
107 } |
|
108 |
|
109 |
|
110 EXPORT_C void CAgnContent::InternalizeL(RReadStream& aStream) |
|
111 { |
|
112 delete iContent; |
|
113 iContent = NULL; |
|
114 iContent = HBufC8::NewL(aStream, KMaxTInt); |
|
115 |
|
116 delete iMimeType; |
|
117 iMimeType = NULL; |
|
118 iMimeType = HBufC8::NewL(aStream, KMaxTInt); |
|
119 |
|
120 TInt32 disposition; |
|
121 aStream >> disposition; |
|
122 iType = static_cast<CCalContent::TDisposition>(disposition); |
|
123 } |
|
124 |
|
125 |
|
126 EXPORT_C void CAgnContent::ExternalizeL(RWriteStream& aStream) const |
|
127 { |
|
128 aStream << Content(); // Use accessor so a KNullDesC8 is stored if content not set. |
|
129 aStream << MimeType(); // Use accessor so a KNullDesC8 is stored if mime type not set. |
|
130 aStream.WriteInt32L(iType); |
|
131 } |
|
132 |
|
133 void CAgnContent::SetContent(TDesC8* aContent) |
|
134 { |
|
135 delete iContent; |
|
136 iContent = aContent; |
|
137 } |
|
138 |
|
139 void CAgnContent::SetMimeType(TDesC8* aMimeType) |
|
140 { |
|
141 delete iMimeType; |
|
142 iMimeType = aMimeType; |
|
143 } |