1 /* |
|
2 * Copyright (c) 2006 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: Implementation of the CVFolderInfo class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <vcommandapi.h> |
|
20 #include <AknsSkinInstance.h> |
|
21 #include <AknsUtils.h> |
|
22 #include <AknsConstants.h> |
|
23 #include <gulicon.h> |
|
24 #include <mifconvdefs.h> |
|
25 #include "rubydebug.h" |
|
26 |
|
27 /** |
|
28 * File name to read icons from if icon file name is not specified |
|
29 */ |
|
30 _LIT( KDefaultIconFile, "Z:\\resource\\apps\\vcommand.mif" ); |
|
31 const TInt KDefaultIconIndex = KMifIdFirst; // first image in the file |
|
32 |
|
33 /** |
|
34 * The version of the streamed data protocol |
|
35 * It is rather likely, that the format of the data streamed changes in the future. |
|
36 * Using the protocol version, the code can check if it knows how to parse the |
|
37 * input stream |
|
38 */ |
|
39 const TInt32 KVCFolderInfoProtocolVersion = 2; |
|
40 |
|
41 static const TAknsItemID* const KIconId[] = |
|
42 { |
|
43 &KAknsIIDQgnPropFolderVcGeneral, |
|
44 &KAknsIIDQgnPropFolderVcTools, |
|
45 &KAknsIIDQgnPropFolderVcOrganiser, |
|
46 &KAknsIIDQgnPropFolderVcMessage, |
|
47 &KAknsIIDQgnPropFolderVcMedia, |
|
48 &KAknsIIDQgnPropFolderVcProfiles |
|
49 }; |
|
50 |
|
51 /** |
|
52 * This object does not take an ownership of the passed descriptors, |
|
53 * but makes own copies. |
|
54 * |
|
55 * @param aTitle Folder title. It is shown at the top of the screen, |
|
56 * when the folder is opened in the VCommand application |
|
57 * @param aListedName Version of a title shown when the folder is |
|
58 * is displayed in the list of VCommands in the VCommand app |
|
59 * @param aHelpTopicId Topic to open when help is requested for the |
|
60 * given folder |
|
61 * @param aIconIndex Index of the folder icon in the folder icons mbm file |
|
62 * each index correspods to two images - the actual icon and its mask |
|
63 * @param aIconFile Mbm file where the icons are obtained from. If KNullDesC, |
|
64 * the default icon file is used |
|
65 */ |
|
66 EXPORT_C CVCFolderInfo* CVCFolderInfo::NewL( const TDesC& aTitle, |
|
67 const TDesC& aListedName, TUint32 aHelpTopicId, TUint aIconIndex, |
|
68 const TDesC& aIconFile ) |
|
69 { |
|
70 CVCFolderInfo* self = new (ELeave) CVCFolderInfo( aHelpTopicId, aIconIndex ); |
|
71 CleanupStack::PushL( self ); |
|
72 self->ConstructL( aTitle, aListedName, aIconFile ); |
|
73 CleanupStack::Pop( self ); |
|
74 return self; |
|
75 } |
|
76 |
|
77 /** |
|
78 * Copy the existing CVCFolderInfo |
|
79 */ |
|
80 EXPORT_C CVCFolderInfo* CVCFolderInfo::NewL( const CVCFolderInfo& aOriginal ) |
|
81 { |
|
82 CVCFolderInfo* self = new (ELeave) CVCFolderInfo( aOriginal.HelpTopicId(), |
|
83 aOriginal.IconIndex() ); |
|
84 CleanupStack::PushL( self ); |
|
85 self->ConstructL( aOriginal.Title(), aOriginal.ListedName(), aOriginal.IconFile() ); |
|
86 CleanupStack::Pop( self ); |
|
87 return self; |
|
88 } |
|
89 |
|
90 /** |
|
91 * Constructs the folder information from stream |
|
92 * @leave KErrNotSupported if the stream data format is unsupported |
|
93 */ |
|
94 EXPORT_C CVCFolderInfo* CVCFolderInfo::NewL( RReadStream &aStream ) |
|
95 { |
|
96 CVCFolderInfo* self = new (ELeave) CVCFolderInfo; |
|
97 CleanupStack::PushL( self ); |
|
98 self->ConstructL( aStream ); |
|
99 CleanupStack::Pop( self ); |
|
100 return self; |
|
101 } |
|
102 |
|
103 CVCFolderInfo::CVCFolderInfo( TUint32 aHelpTopicId, TUint aIconIndex ) : |
|
104 iHelpTopicId( aHelpTopicId ), iIconIndex (aIconIndex ) |
|
105 { |
|
106 // empty |
|
107 } |
|
108 |
|
109 void CVCFolderInfo::ConstructL( RReadStream &aStream ) |
|
110 { |
|
111 /** |
|
112 * @todo extract the repeated descriptor internalization code into |
|
113 * a separate method |
|
114 */ |
|
115 TInt32 ver; |
|
116 aStream >> ver; |
|
117 __ASSERT_ALWAYS( ver == KVCFolderInfoProtocolVersion, User::Leave( KErrNotSupported ) ); |
|
118 iTitle = HBufC::NewL( aStream.ReadInt32L() ); |
|
119 TPtr pTitle = iTitle->Des(); |
|
120 aStream >> pTitle; |
|
121 iListedName = HBufC::NewL( aStream.ReadInt32L() ); |
|
122 TPtr pListedName = iListedName->Des(); |
|
123 aStream >> pListedName; |
|
124 iHelpTopicId = aStream.ReadUint32L(); |
|
125 iIconFile = HBufC::NewL( aStream.ReadInt32L() ); |
|
126 TPtr pIconFile = iIconFile->Des(); |
|
127 aStream >> pIconFile; |
|
128 iIconIndex = aStream.ReadUint32L(); |
|
129 } |
|
130 |
|
131 |
|
132 /** |
|
133 * Second-phase constructor |
|
134 */ |
|
135 void CVCFolderInfo::ConstructL( const TDesC& aTitle, const TDesC& aListedName, |
|
136 const TDesC& aIconFile ) |
|
137 { |
|
138 RUBY_DEBUG_BLOCKL( "" ); |
|
139 iTitle = HBufC::NewL( aTitle.Length() ); |
|
140 *iTitle = aTitle; |
|
141 iListedName = HBufC::NewL( aListedName.Length() ); |
|
142 *iListedName = aListedName; |
|
143 iIconFile = HBufC::NewL( aIconFile.Length() ); |
|
144 *iIconFile = aIconFile; |
|
145 } |
|
146 |
|
147 EXPORT_C CVCFolderInfo::~CVCFolderInfo() |
|
148 { |
|
149 delete iListedName; |
|
150 delete iTitle; |
|
151 delete iIconFile; |
|
152 } |
|
153 |
|
154 /** |
|
155 * Saves the command to stream. |
|
156 * Descriptor components are saved as <length><descriptor> pairs, where |
|
157 * <length> is TInt32 and <descriptor> is the default descriptor represetation |
|
158 * TBools are saved as TInt32 either |
|
159 */ |
|
160 EXPORT_C void CVCFolderInfo::ExternalizeL( RWriteStream &aStream ) const |
|
161 { |
|
162 aStream << KVCFolderInfoProtocolVersion; |
|
163 aStream << static_cast<TInt32>( iTitle->Length() ); |
|
164 aStream << *iTitle; |
|
165 aStream << static_cast<TInt32>( iListedName->Length() ); |
|
166 aStream << *iListedName; |
|
167 aStream << iHelpTopicId; |
|
168 aStream << static_cast<TInt32> ( iIconFile->Length() ); |
|
169 aStream << *iIconFile; |
|
170 // Mandate saving index as Uint32 to preserve the string format |
|
171 aStream << static_cast<TUint32> ( iIconIndex ); |
|
172 } |
|
173 |
|
174 |
|
175 EXPORT_C const TDesC& CVCFolderInfo::Title() const |
|
176 { |
|
177 return *iTitle; |
|
178 } |
|
179 |
|
180 EXPORT_C const TDesC& CVCFolderInfo::ListedName() const |
|
181 { |
|
182 return *iListedName; |
|
183 } |
|
184 |
|
185 EXPORT_C TUint32 CVCFolderInfo::HelpTopicId() const |
|
186 { |
|
187 return iHelpTopicId; |
|
188 } |
|
189 |
|
190 EXPORT_C TBool CVCFolderInfo::operator==( const CVCFolderInfo& aFolderInfo ) const |
|
191 { |
|
192 return ( |
|
193 ( iHelpTopicId == aFolderInfo.HelpTopicId() ) && |
|
194 ( *iTitle == aFolderInfo.Title() ) && |
|
195 ( *iListedName == aFolderInfo.ListedName() ) && |
|
196 ( *iIconFile == aFolderInfo.IconFile() ) && |
|
197 ( iIconIndex == aFolderInfo.IconIndex() ) |
|
198 ); |
|
199 } |
|
200 |
|
201 EXPORT_C TDesC& CVCFolderInfo::IconFile() const |
|
202 { |
|
203 return *iIconFile; |
|
204 } |
|
205 |
|
206 EXPORT_C TUint CVCFolderInfo::IconIndex() const |
|
207 { |
|
208 return iIconIndex; |
|
209 } |
|
210 |
|
211 /** |
|
212 * Creates an icon to represent this folder. Works only if CEikonEnv is available |
|
213 * @return Icon for the folder |
|
214 */ |
|
215 EXPORT_C CGulIcon* CVCFolderInfo::IconLC() const |
|
216 { |
|
217 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
218 CFbsBitmap* bitmap = NULL; |
|
219 CFbsBitmap* mask = NULL; |
|
220 const TInt KBitmapsPerIcon = 2; |
|
221 |
|
222 // Every "index" corrsponds to two bitmaps - actual icon and its mask |
|
223 TInt iconIndex = KMifIdFirst + IconIndex()*KBitmapsPerIcon; |
|
224 TInt maskIndex = iconIndex + 1; |
|
225 TDesC& iconFile = IconFile(); |
|
226 if ( iconFile == KNullDesC ) |
|
227 { |
|
228 iconFile = KDefaultIconFile; |
|
229 } |
|
230 |
|
231 TRAPD( err, |
|
232 AknsUtils::CreateIconLC( skin, *KIconId[ IconIndex() ], |
|
233 bitmap, mask, iconFile, iconIndex, |
|
234 maskIndex ); |
|
235 CleanupStack::Pop( 2 ); // mask, bitmap |
|
236 ) |
|
237 if( err != KErrNone ) |
|
238 { |
|
239 RUBY_DEBUG1( "CreateIconLC failed with %d. Loading default icon", err ); |
|
240 AknsUtils::CreateIconLC( skin, *KIconId[ IconIndex() ], |
|
241 bitmap, mask, KDefaultIconFile, KDefaultIconIndex, |
|
242 KDefaultIconIndex + 1 ); |
|
243 CleanupStack::Pop( 2 ); // mask, bitmap |
|
244 } |
|
245 |
|
246 CleanupStack::PushL( mask ); |
|
247 CleanupStack::PushL( bitmap ); |
|
248 CGulIcon* icon = CGulIcon::NewL( bitmap, mask ); |
|
249 icon->SetBitmapsOwnedExternally( EFalse ); |
|
250 |
|
251 // icon now owns the bitmaps, no need to keep on cleanup stack. |
|
252 CleanupStack::Pop( bitmap ); |
|
253 CleanupStack::Pop( mask ); |
|
254 |
|
255 CleanupStack::PushL( icon ); |
|
256 return icon; |
|
257 } |
|
258 |
|
259 //End of file |
|