|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <f32file.h> |
|
20 #include <s32file.h> |
|
21 |
|
22 #include "ncdnode.h" |
|
23 #include "catalogshttpoperation.h" |
|
24 #include "catalogshttpconfig.h" |
|
25 #include "catalogshttpsession.h" |
|
26 #include "ncdicondownloadhandler.h" |
|
27 #include "ncdnodemetadataimpl.h" |
|
28 #include "ncdnodeiconimpl.h" |
|
29 #include "ncdfilehandler.h" |
|
30 #include "ncdnodeidentifier.h" |
|
31 #include "ncdproviderutils.h" |
|
32 |
|
33 #include "catalogsdebug.h" |
|
34 |
|
35 |
|
36 // ======== MEMBER FUNCTIONS ======== |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // NewL |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 CNcdIconDownloadHandler* CNcdIconDownloadHandler::NewL( |
|
43 const CNcdNodeIdentifier& aNodeId, |
|
44 CNcdNodeManager& aNodeManager, |
|
45 MCatalogsHttpSession& aHttpSession ) |
|
46 { |
|
47 CNcdIconDownloadHandler* self = new( ELeave ) |
|
48 CNcdIconDownloadHandler( aNodeManager, aHttpSession ); |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL( aNodeId ); |
|
51 CleanupStack::Pop( self ); |
|
52 return self; |
|
53 } |
|
54 |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // Destructor |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 CNcdIconDownloadHandler::~CNcdIconDownloadHandler() |
|
61 { |
|
62 DLTRACE(("--><--")); |
|
63 } |
|
64 |
|
65 |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // DownloadL |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 MCatalogsHttpOperation* CNcdIconDownloadHandler::DownloadL() |
|
72 { |
|
73 DLTRACEIN(( "" )); |
|
74 |
|
75 CNcdNode& node( NodeL() ); |
|
76 |
|
77 DLTRACE(("Getting metadata")); |
|
78 // Get node metadata |
|
79 CNcdNodeMetaData& metadata = node.NodeMetaDataL(); |
|
80 |
|
81 DLTRACE(("Getting icon")); |
|
82 // Get icon |
|
83 const CNcdNodeIcon& icon = metadata.IconL(); |
|
84 |
|
85 DLINFO(( _L("Creating download for Uri: %S"), &icon.Uri() )); |
|
86 // Create download |
|
87 MCatalogsHttpOperation* dl = HttpSession().CreateDownloadL( |
|
88 icon.Uri(), EFalse ); |
|
89 CleanupStack::PushL( dl ); |
|
90 |
|
91 // ensure that transactions are not used to get HTTP headers |
|
92 dl->SetHeaderMode( ECatalogsHttpHeaderModeNoHead ); |
|
93 |
|
94 // Icon downloads are low priority |
|
95 dl->Config().SetPriority( ECatalogsPriorityLow ); |
|
96 |
|
97 // Prevent filename extension update because it's not needed |
|
98 dl->Config().SetOptions( |
|
99 dl->Config().Options() & ~ECatalogsHttpDisableHeadRequest ); |
|
100 |
|
101 HBufC* tempPath = CNcdProviderUtils::TempPathLC( |
|
102 NodeId().ClientUid().Name() ); |
|
103 |
|
104 // Use provider's temp path |
|
105 dl->Config().SetDirectoryL( |
|
106 *tempPath ); |
|
107 CleanupStack::PopAndDestroy( tempPath ); |
|
108 SetCurrentDownload( CurrentDownload() + 1 ); |
|
109 |
|
110 CleanupStack::Pop( dl ); |
|
111 DLTRACEOUT(( "" )); |
|
112 return dl; |
|
113 } |
|
114 |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // FinishDownloadL |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 void CNcdIconDownloadHandler::FinishDownloadL( |
|
121 MCatalogsHttpOperation& aDownload, |
|
122 MNcdFileHandler* aFileHandler) |
|
123 { |
|
124 DLTRACEIN(( "filehandler: %X", aFileHandler )); |
|
125 HBufC* filename = aDownload.Config().FullPathLC(); |
|
126 |
|
127 // Get node |
|
128 CNcdNode& node( NodeL() ); |
|
129 |
|
130 // Get node metadata |
|
131 CNcdNodeMetaData& metadata = node.NodeMetaDataL(); |
|
132 |
|
133 // Get icon |
|
134 const CNcdNodeIcon& icon = metadata.IconL(); |
|
135 |
|
136 DLINFO(( _L("Moving the file from %S"), filename )); |
|
137 |
|
138 // Moves the file to target location. |
|
139 // Using metadata's namespace |
|
140 aFileHandler-> |
|
141 MoveFileL( *filename, |
|
142 metadata.Identifier().NodeNameSpace(), |
|
143 icon.IconId() ); |
|
144 CleanupStack::PopAndDestroy( filename ); |
|
145 |
|
146 DLTRACEOUT(( "" )); |
|
147 } |
|
148 |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // Constructor |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 CNcdIconDownloadHandler::CNcdIconDownloadHandler( |
|
155 CNcdNodeManager& aNodeManager, |
|
156 MCatalogsHttpSession& aHttpSession ) : |
|
157 CNcdBaseDownloadHandler( aNodeManager, aHttpSession ) |
|
158 { |
|
159 } |
|
160 |