|
1 /* |
|
2 * Copyright (c) 2008-2009 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: CGlxImageViewerManager implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "glximageviewermanager.h" |
|
20 #include <glxsingletonstore.h> |
|
21 #include <glxtracer.h> |
|
22 #include <glxlog.h> |
|
23 |
|
24 #include <f32file.h> |
|
25 #include <caf/manager.h> |
|
26 #include <caf/content.h> |
|
27 #include <driveinfo.h> |
|
28 #include <coeutils.h> |
|
29 #include <coemain.h> |
|
30 |
|
31 _LIT( KPrivateFolder, "\\Private\\" ); |
|
32 _LIT( KGifFileMime, "image/gif" ); |
|
33 _LIT( KMbmFileExt, "image/x-epoc-mbm"); |
|
34 _LIT( KTempFilePath, "?:\\data\\images\\" ); |
|
35 |
|
36 EXPORT_C CGlxImageViewerManager* CGlxImageViewerManager::InstanceL() |
|
37 { |
|
38 TRACER("CGlxImageViewerManager::InstanceL()"); |
|
39 return CGlxSingletonStore::InstanceL(&NewL); |
|
40 } |
|
41 |
|
42 EXPORT_C void CGlxImageViewerManager::DeleteInstance() |
|
43 { |
|
44 TRACER("CGlxImageViewerManager::DeleteInstance()"); |
|
45 CGlxSingletonStore::Close(this); |
|
46 } |
|
47 |
|
48 EXPORT_C HBufC* CGlxImageViewerManager::ImageUri() |
|
49 { |
|
50 TRACER("CGlxImageViewerManager::ImageUri()"); |
|
51 return iImageUri; |
|
52 } |
|
53 |
|
54 EXPORT_C RFile64& CGlxImageViewerManager::ImageFileHandle() |
|
55 { |
|
56 TRACER("CGlxImageViewerManager::ImageFileHandle()"); |
|
57 return *iFile; |
|
58 } |
|
59 |
|
60 EXPORT_C TBool CGlxImageViewerManager::IsPrivate() |
|
61 { |
|
62 TRACER("CGlxImageViewerManager::IsPrivate()"); |
|
63 return iIsPrivate; |
|
64 } |
|
65 |
|
66 EXPORT_C TBool CGlxImageViewerManager::IsPrivateGif() |
|
67 { |
|
68 TRACER("CGlxImageViewerManager::IsPrivateGif()"); |
|
69 return iIsPrivateGif; |
|
70 } |
|
71 |
|
72 CGlxImageViewerManager::CGlxImageViewerManager() |
|
73 : iImageUri(NULL), iFile(NULL), iIsPrivate(EFalse) |
|
74 { |
|
75 TRACER("CGlxImageViewerManager::CGlxImageViewerManager()"); |
|
76 // No implementation required |
|
77 } |
|
78 |
|
79 CGlxImageViewerManager::~CGlxImageViewerManager() |
|
80 { |
|
81 TRACER("CGlxImageViewerManager::~CGlxImageViewerManager()"); |
|
82 Reset(); |
|
83 } |
|
84 |
|
85 CGlxImageViewerManager* CGlxImageViewerManager::NewLC() |
|
86 { |
|
87 TRACER("CGlxImageViewerManager::NewLC()"); |
|
88 CGlxImageViewerManager* self = new (ELeave) CGlxImageViewerManager(); |
|
89 CleanupStack::PushL(self); |
|
90 self->ConstructL(); |
|
91 return self; |
|
92 } |
|
93 |
|
94 CGlxImageViewerManager* CGlxImageViewerManager::NewL() |
|
95 { |
|
96 TRACER("CGlxImageViewerManager::NewL()"); |
|
97 CGlxImageViewerManager* self = CGlxImageViewerManager::NewLC(); |
|
98 CleanupStack::Pop(self); |
|
99 return self; |
|
100 } |
|
101 |
|
102 void CGlxImageViewerManager::ConstructL() |
|
103 { |
|
104 TRACER("CGlxImageViewerManager::ConstructL()"); |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // SetImageUri |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 EXPORT_C void CGlxImageViewerManager::SetImageUriL(const TDesC& aFileName) |
|
112 { |
|
113 TRACER("void CGlxImageViewerManager::SetImageUriL()"); |
|
114 GLX_LOG_URI("CGlxImageViewerManager::SetImageUriL(%S)", &aFileName); |
|
115 if ( iImageUri ) |
|
116 { |
|
117 delete iImageUri; |
|
118 iImageUri = NULL; |
|
119 } |
|
120 if (aFileName.Length() == 0) |
|
121 { |
|
122 User::Leave(KErrNotSupported); |
|
123 } |
|
124 iImageUri = aFileName.AllocL(); |
|
125 CreateImageDecoderL(); |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // Reset |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 EXPORT_C void CGlxImageViewerManager::Reset() |
|
133 { |
|
134 TRACER("void CGlxImageViewerManager::Reset()"); |
|
135 if( iFile ) |
|
136 { |
|
137 iFile->Close(); |
|
138 } |
|
139 delete iFile; |
|
140 iFile = NULL; |
|
141 |
|
142 CloseImageDecoder(); |
|
143 |
|
144 if (iIsPrivateGif) |
|
145 { |
|
146 iManager->DeleteFile(iImageUri->Des()); |
|
147 iIsPrivateGif = EFalse; |
|
148 } |
|
149 |
|
150 if ( iManager ) |
|
151 { |
|
152 delete iManager; |
|
153 iManager = NULL; |
|
154 } |
|
155 |
|
156 if ( iImageUri ) |
|
157 { |
|
158 delete iImageUri; |
|
159 iImageUri = NULL; |
|
160 } |
|
161 iIsPrivate = EFalse; |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // SetImageFileHandleL |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 EXPORT_C void CGlxImageViewerManager::SetImageFileHandleL(const RFile& aFileHandle) |
|
169 { |
|
170 TRACER("void CGlxImageViewerManager::SetImageFileHandleL()"); |
|
171 TFileName filePath; |
|
172 User::LeaveIfError(aFileHandle.FullName(filePath)); |
|
173 TParsePtrC parse(filePath); |
|
174 if (parse.PathPresent() && parse.Path().Length() |
|
175 > KPrivateFolder().Length() && parse.Path().Left( |
|
176 KPrivateFolder().Length()).CompareF(KPrivateFolder) == 0) |
|
177 { |
|
178 // File is in private folder; duplicate file handle |
|
179 iFile = new (ELeave) RFile64; |
|
180 User::LeaveIfError(iFile->Duplicate(aFileHandle)); |
|
181 iIsPrivate = ETrue; |
|
182 |
|
183 // Better to use contentaccess as we need to deal with DRM files |
|
184 TBuf<KMaxName> mimeBuf; |
|
185 ContentAccess::CContent* content = ContentAccess::CContent::NewLC( |
|
186 *iFile); |
|
187 TInt err(content->GetStringAttribute(ContentAccess::EMimeType, |
|
188 mimeBuf)); |
|
189 CleanupStack::PopAndDestroy(content); |
|
190 |
|
191 // Gif / MBM file from private path, hence make a local copy. |
|
192 if (mimeBuf.Compare(KGifFileMime) == 0 |
|
193 || mimeBuf.Compare(KMbmFileExt) == 0) |
|
194 { |
|
195 TFileName ramFilePath; |
|
196 ramFilePath.Copy(KTempFilePath); |
|
197 ramFilePath.Append(parse.NameAndExt()); |
|
198 |
|
199 TChar drive; |
|
200 User::LeaveIfError(DriveInfo::GetDefaultDrive( |
|
201 DriveInfo::EDefaultRam, drive)); |
|
202 ramFilePath[0] = drive; |
|
203 ConeUtils::EnsurePathExistsL(ramFilePath); |
|
204 if (!iManager) |
|
205 { |
|
206 iManager = ContentAccess::CManager::NewL(); |
|
207 } |
|
208 iManager->CopyFile(*iFile, ramFilePath); |
|
209 filePath.Copy(ramFilePath); |
|
210 iIsPrivateGif = ETrue; |
|
211 } |
|
212 } |
|
213 SetImageUriL( filePath ); |
|
214 } |
|
215 |
|
216 // --------------------------------------------------------------------------- |
|
217 // CloseImageDecoder |
|
218 // --------------------------------------------------------------------------- |
|
219 // |
|
220 EXPORT_C void CGlxImageViewerManager::CloseImageDecoder() |
|
221 { |
|
222 TRACER("void CGlxImageViewerManager::CloseImageDecoder()"); |
|
223 if (iImageDecoder) |
|
224 { |
|
225 delete iImageDecoder; |
|
226 iImageDecoder = NULL; |
|
227 } |
|
228 } |
|
229 |
|
230 // --------------------------------------------------------------------------- |
|
231 // CreateImageDecoderL |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 EXPORT_C void CGlxImageViewerManager::CreateImageDecoderL() |
|
235 { |
|
236 TRACER("void CGlxImageViewerManager::CreateImageDecoderL()"); |
|
237 |
|
238 CloseImageDecoder(); |
|
239 |
|
240 TInt err = KErrNone; |
|
241 if (IsPrivate()) |
|
242 { |
|
243 if (&ImageFileHandle()) |
|
244 { |
|
245 GLX_DEBUG1("CGlxImageViewerManager::CreateImageDecoderL() FH"); |
|
246 TRAP(err, iImageDecoder = CImageDecoder::FileNewL( |
|
247 ImageFileHandle(), ContentAccess::EPeek)); |
|
248 } |
|
249 } |
|
250 else |
|
251 { |
|
252 if (ImageUri()) |
|
253 { |
|
254 GLX_DEBUG1("CGlxImageViewerManager::CreateImageDecoderL() FN"); |
|
255 TRAP(err, iImageDecoder = CImageDecoder::FileNewL( |
|
256 CCoeEnv::Static()->FsSession(), ImageUri()->Des())); |
|
257 } |
|
258 } |
|
259 |
|
260 GLX_DEBUG2("CGlxImageViewerManager::CreateImageDecoderL() err(%d)", err); |
|
261 User::LeaveIfError(err); |
|
262 } |