|
1 /* |
|
2 * Copyright (c) 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: smiely engine class |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <smiley.rsg> |
|
19 #include <eikenv.h> |
|
20 #include <barsread.h> |
|
21 #include <eikon.hrh> |
|
22 #include <f32file.h> |
|
23 #include <centralrepository.h> |
|
24 #include <AvkonInternalCRKeys.h> |
|
25 #include <coeutils.h> |
|
26 #include "smileymanager.h" |
|
27 #include "smileymodel.h" |
|
28 #include "smileyinforeader.h" |
|
29 |
|
30 const TText KSmileyZDrive = 'Z'; |
|
31 _LIT( KSmileyResourceDir, "C:\\resource\\" ); |
|
32 _LIT( KSmileyIconDir, "C:\\resource\\apps\\" ); |
|
33 _LIT( KDefaultFileName, "smiley" ); |
|
34 _LIT( KRscFileExtName, ".rsc" ); |
|
35 _LIT( KMifFileExtName, ".mif" ); |
|
36 const TInt KSmileyPathLength = 60; |
|
37 |
|
38 // ======== MEMBER FUNCTIONS ======== |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // CSmileyInfoReader::CSmileyInfoReader |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 CSmileyInfoReader::CSmileyInfoReader( CSmileyModel& aModel ) : |
|
45 iModel( &aModel ) |
|
46 { |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // CSmileyInfoReader::~CSmileyInfoReader |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 CSmileyInfoReader::~CSmileyInfoReader() |
|
54 { |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // CSmileyInfoReader::ReadCenRepInfoL |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 void CSmileyInfoReader::ReadCenRepInfoL( TInt& aResourceId, |
|
62 TDes& aResourceFile, TDes& aIconFile ) |
|
63 { |
|
64 aResourceId = R_SMILEY_ICONS_INFO; |
|
65 const TInt fileNameLength( 30 ); |
|
66 HBufC* fileName( HBufC::NewL( fileNameLength ) ); |
|
67 CleanupStack::PushL( fileName ); |
|
68 TPtr ptr( fileName->Des() ); |
|
69 CRepository* repository( CRepository::NewL( KCRUidAvkon ) ); |
|
70 TInt err( repository->Get( KAknEmotionResourceFileName, |
|
71 ptr ) ); |
|
72 if ( err != KErrNone ) |
|
73 { |
|
74 ptr.Copy( KDefaultFileName ); |
|
75 } |
|
76 delete repository; |
|
77 |
|
78 aResourceFile.Append( KSmileyResourceDir ); |
|
79 aResourceFile.Append( ptr ); |
|
80 aResourceFile.Append( KRscFileExtName ); |
|
81 aIconFile.Append( KSmileyIconDir ); |
|
82 aIconFile.Append( ptr ); |
|
83 aIconFile.Append( KMifFileExtName ); |
|
84 CleanupStack::PopAndDestroy( fileName ); |
|
85 |
|
86 if ( ConeUtils::FileExists( aResourceFile ) && |
|
87 ConeUtils::FileExists( aIconFile ) ) |
|
88 { |
|
89 return; |
|
90 } |
|
91 aResourceFile[0] = KSmileyZDrive; |
|
92 aIconFile[0] = KSmileyZDrive; |
|
93 if ( !ConeUtils::FileExists( aResourceFile ) || |
|
94 !ConeUtils::FileExists( aIconFile ) ) |
|
95 { |
|
96 User::Leave( KErrNotFound ); |
|
97 } |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // CSmileyInfoReader::LoadSmileysFromResource |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 void CSmileyInfoReader::ReadSmileyL( CSmileyInfo& aInfo, |
|
105 TResourceReader& aReader ) |
|
106 { |
|
107 aInfo.iImageInfo.iIsAnimation = ( aReader.ReadInt16() == 1 ); |
|
108 aInfo.iImageInfo.iCode = aReader.ReadInt16(); |
|
109 aInfo.iImageInfo.iBmpId = aReader.ReadInt32(); |
|
110 aInfo.iImageInfo.iMaskId = aReader.ReadInt32(); |
|
111 aInfo.iImageInfo.iStaticBmpId = aReader.ReadInt32(); |
|
112 aInfo.iImageInfo.iStaticMaskId = aReader.ReadInt32(); |
|
113 TPtrC ptrc( aReader.ReadTPtrC() ); |
|
114 aInfo.SetSmileyText( ptrc ); |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // CSmileyInfoReader::LoadSmileysFromResource |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 void CSmileyInfoReader::LoadSmileysFromResourceL() |
|
122 { |
|
123 TInt resourceId( 0 ); |
|
124 TBuf<KSmileyPathLength> resourceFile; |
|
125 TBuf<KSmileyPathLength> iconFile; |
|
126 ReadCenRepInfoL( resourceId, resourceFile, iconFile ); |
|
127 iModel->SetSmileyIconFileL( iconFile ); |
|
128 |
|
129 CEikonEnv* env( CEikonEnv::Static() ); |
|
130 TInt offset( env->AddResourceFileL( resourceFile ) ); |
|
131 TResourceReader reader; |
|
132 env->CreateResourceReaderLC( reader, resourceId ); |
|
133 TInt count( reader.ReadInt16() ); |
|
134 if ( count > 0 ) |
|
135 { |
|
136 CSmileyInfo* info( new( ELeave ) CSmileyInfo ); |
|
137 CleanupStack::PushL( info ); |
|
138 for ( TInt i( 0 ); i < count; i++ ) |
|
139 { |
|
140 info->Reset(); |
|
141 ReadSmileyL( *info, reader ); |
|
142 iModel->AddSimleyL( *info ); |
|
143 } |
|
144 CleanupStack::PopAndDestroy( info ); |
|
145 } |
|
146 CleanupStack::PopAndDestroy(); // reader |
|
147 env->DeleteResourceFile( offset ); |
|
148 } |
|
149 |