|
1 /* |
|
2 * Copyright (c) 2003-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 the License "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 <caf/caf.h> |
|
20 #include <caf/cafpanic.h> |
|
21 #include <caf/dirstreamable.h> |
|
22 #include "f32agentmanager.h" |
|
23 #include "f32defaultattributes.h" |
|
24 #include "f32agentui.h" |
|
25 |
|
26 using namespace ContentAccess; |
|
27 |
|
28 CF32AgentManager* CF32AgentManager::NewL() |
|
29 { |
|
30 CF32AgentManager* self=new(ELeave) CF32AgentManager(); |
|
31 CleanupStack::PushL(self); |
|
32 self->ConstructL(); |
|
33 CleanupStack::Pop(self); |
|
34 return self; |
|
35 } |
|
36 |
|
37 CF32AgentManager::CF32AgentManager() |
|
38 { |
|
39 } |
|
40 |
|
41 CF32AgentManager::~CF32AgentManager() |
|
42 { |
|
43 delete iFileMan; |
|
44 iFs.Close(); |
|
45 } |
|
46 |
|
47 void CF32AgentManager::ConstructL() |
|
48 { |
|
49 User::LeaveIfError(iFs.Connect()); |
|
50 iFileMan = CFileMan::NewL(iFs); |
|
51 } |
|
52 |
|
53 TBool CF32AgentManager::IsRecognizedL(const TDesC&, TContentShareMode) const |
|
54 { |
|
55 // F32 should be the default agent and should never be called here |
|
56 return EFalse; |
|
57 } |
|
58 |
|
59 TBool CF32AgentManager::IsRecognizedL(RFile& ) const |
|
60 { |
|
61 return EFalse; |
|
62 } |
|
63 |
|
64 TBool CF32AgentManager::RecognizeFileL(const TDesC&, const TDesC8&, TDes8&, TDes8&) const |
|
65 { |
|
66 // F32 should be the default agent and should never be called here |
|
67 return EFalse; |
|
68 } |
|
69 |
|
70 TInt CF32AgentManager::DeleteFile(const TDesC &aFileName) |
|
71 { |
|
72 TInt err = KErrNone; |
|
73 CF32AgentUi* ui = NULL; |
|
74 TBool enableDelete = ETrue; |
|
75 |
|
76 // get a pointer to the UI |
|
77 TRAP(err, ui = &AgentUiL()); |
|
78 if(err == KErrNone) |
|
79 { |
|
80 // UI confirmation supported, see if user wants to delete |
|
81 TRAP(err, enableDelete = ui->ConfirmDeleteL(aFileName)); |
|
82 if(err == KErrNone && enableDelete) |
|
83 { |
|
84 // User agrees to delete |
|
85 err = iFs.Delete(aFileName); |
|
86 } |
|
87 } |
|
88 else if(err == KErrCANotSupported) |
|
89 { |
|
90 // UI is not supported, just delete it |
|
91 err = iFs.Delete(aFileName); |
|
92 } |
|
93 return err; |
|
94 } |
|
95 |
|
96 TInt CF32AgentManager::CopyFile(const TDesC& aSource, const TDesC& aDestination) |
|
97 { |
|
98 return iFileMan->Copy(aSource, aDestination); |
|
99 } |
|
100 |
|
101 TInt CF32AgentManager::CopyFile(RFile& aSource, const TDesC& aDestination) |
|
102 { |
|
103 return iFileMan->Copy(aSource, aDestination); |
|
104 } |
|
105 |
|
106 TInt CF32AgentManager::RenameFile(const TDesC& aSource, const TDesC& aDestination) |
|
107 { |
|
108 TInt result = iFileMan->Rename(aSource, aDestination); |
|
109 // If the files are on a different drive, Rename will fail |
|
110 // Therefore we simulate the Move by doing a Copy, followed by Delete |
|
111 if (result != KErrNone) |
|
112 { |
|
113 result = iFileMan->Copy(aSource,aDestination); |
|
114 if (result == KErrNone) |
|
115 { |
|
116 // If the copy was successful try and delete the original |
|
117 result = iFileMan->Delete(aSource); |
|
118 if (result != KErrNone) |
|
119 { |
|
120 // Delete failed so try to cleanup the destination file as we're going to exit with an error |
|
121 // We can safely ignore any error from this as the previous error is more important to propagate, since this is just cleanup |
|
122 iFileMan->Delete(aDestination); |
|
123 } |
|
124 } |
|
125 } |
|
126 return result; |
|
127 } |
|
128 |
|
129 TInt CF32AgentManager::MkDir(const TDesC& aPath) |
|
130 { |
|
131 return iFs.MkDir(aPath); |
|
132 } |
|
133 |
|
134 TInt CF32AgentManager::MkDirAll(const TDesC& aPath) |
|
135 { |
|
136 return iFs.MkDirAll(aPath); |
|
137 } |
|
138 |
|
139 TInt CF32AgentManager::RmDir(const TDesC& aPath) |
|
140 { |
|
141 return iFs.RmDir(aPath); |
|
142 } |
|
143 |
|
144 TInt CF32AgentManager::RenameDir(const TDesC& aOldName, const TDesC& aNewName) |
|
145 { |
|
146 return iFs.Rename(aOldName, aNewName); |
|
147 } |
|
148 |
|
149 TInt CF32AgentManager::GetDir(const TDesC& aName,TUint aEntryAttMask,TUint aEntrySortKey, CDir*& aEntryList) const |
|
150 { |
|
151 return iFs.GetDir(aName, aEntryAttMask, aEntrySortKey, aEntryList); |
|
152 } |
|
153 |
|
154 TInt CF32AgentManager::GetDir(const TDesC& aName,TUint aEntryAttMask,TUint aEntrySortKey, CDir*& aEntryList,CDir*& aDirList) const |
|
155 { |
|
156 return iFs.GetDir(aName, aEntryAttMask, aEntrySortKey, aEntryList, aDirList); |
|
157 } |
|
158 |
|
159 TInt CF32AgentManager::GetDir(const TDesC& aName,const TUidType& aEntryUid,TUint aEntrySortKey, CDir*& aFileList) const |
|
160 { |
|
161 return iFs.GetDir( aName, aEntryUid, aEntrySortKey, aFileList); |
|
162 } |
|
163 |
|
164 TInt CF32AgentManager::GetAttribute(TInt aAttribute, TInt& aValue, const TVirtualPathPtr& aVirtualPath) |
|
165 { |
|
166 // check that the virtual path exists |
|
167 if(TF32DefaultAttributes::CheckVirtualPath(aVirtualPath) != KErrNone) |
|
168 { |
|
169 return KErrNotFound; |
|
170 } |
|
171 |
|
172 return TF32DefaultAttributes::GetAttribute(aAttribute, aValue, aVirtualPath.URI()); |
|
173 } |
|
174 |
|
175 TInt CF32AgentManager::GetAttributeSet(RAttributeSet& aAttributeSet, const TVirtualPathPtr& aVirtualPath) |
|
176 { |
|
177 // check that the virtual path exists |
|
178 if(TF32DefaultAttributes::CheckVirtualPath(aVirtualPath) != KErrNone) |
|
179 { |
|
180 return KErrNotFound; |
|
181 } |
|
182 |
|
183 return TF32DefaultAttributes::GetAttributeSet(aAttributeSet, aVirtualPath.URI()); |
|
184 } |
|
185 |
|
186 TInt CF32AgentManager::GetStringAttribute(TInt aAttribute, TDes& aValue, const TVirtualPathPtr& aVirtualPath) |
|
187 { |
|
188 // check that the virtual path exists |
|
189 if(TF32DefaultAttributes::CheckVirtualPath(aVirtualPath) != KErrNone) |
|
190 { |
|
191 return KErrNotFound; |
|
192 } |
|
193 |
|
194 return TF32DefaultAttributes::GetStringAttribute(aAttribute, aValue, aVirtualPath.URI()); |
|
195 } |
|
196 |
|
197 TInt CF32AgentManager::GetStringAttributeSet(RStringAttributeSet& aAttributeSet, const TVirtualPathPtr& aVirtualPath) |
|
198 { |
|
199 // check that the virtual path exists |
|
200 if(TF32DefaultAttributes::CheckVirtualPath(aVirtualPath) != KErrNone) |
|
201 { |
|
202 return KErrNotFound; |
|
203 } |
|
204 |
|
205 return TF32DefaultAttributes::GetStringAttributeSet(aAttributeSet, aVirtualPath.URI()); |
|
206 } |
|
207 |
|
208 void CF32AgentManager::NotifyStatusChange(const TDesC& , TEventMask , TRequestStatus& aStatus) |
|
209 { |
|
210 TRequestStatus* ptr = &aStatus; |
|
211 User::RequestComplete(ptr, KErrCANotSupported); |
|
212 } |
|
213 |
|
214 TInt CF32AgentManager::CancelNotifyStatusChange(const TDesC& , TRequestStatus& ) |
|
215 { |
|
216 return KErrCANotSupported; |
|
217 } |
|
218 |
|
219 TInt CF32AgentManager::SetProperty(TAgentProperty aProperty, TInt aValue) |
|
220 { |
|
221 if(aProperty==EAgentPropertyAgentUI) |
|
222 // should only pass type EAgentPropertyAgentUI |
|
223 { |
|
224 |
|
225 CF32AgentUi* ui = NULL; |
|
226 // get a pointer to the UI |
|
227 TRAPD(err, ui = &AgentUiL()); |
|
228 if(err) |
|
229 { |
|
230 return err; |
|
231 } |
|
232 return ui->SetProperty(aProperty, aValue); |
|
233 } |
|
234 else |
|
235 { |
|
236 return KErrCANotSupported; |
|
237 } |
|
238 } |
|
239 |
|
240 void CF32AgentManager::DisplayInfoL(TDisplayInfo aInfo, const TVirtualPathPtr& aVirtualPath) |
|
241 { |
|
242 RFile file; |
|
243 |
|
244 // Check that the client hasn't specified some incorrect UniqueId |
|
245 User::LeaveIfError(TF32DefaultAttributes::CheckUniqueId(aVirtualPath.UniqueId())); |
|
246 |
|
247 // Open the file as read only |
|
248 User::LeaveIfError(file.Open(iFs, aVirtualPath.URI(), EFileShareReadersOnly | EFileStream | EFileRead)); |
|
249 CleanupClosePushL(file); |
|
250 AgentUiL().DisplayInfoL(aInfo, file); |
|
251 CleanupStack::PopAndDestroy(&file); |
|
252 } |
|
253 |
|
254 TInt CF32AgentManager::AgentSpecificCommand(TInt , const TDesC8& , TDes8& ) |
|
255 { |
|
256 return KErrCANotSupported; |
|
257 } |
|
258 |
|
259 void CF32AgentManager::AgentSpecificCommand(TInt , const TDesC8& , TDes8& , TRequestStatus& aStatus) |
|
260 { |
|
261 TRequestStatus* ptr = &aStatus; |
|
262 User::RequestComplete(ptr, KErrCANotSupported); |
|
263 } |
|
264 |
|
265 void CF32AgentManager::DisplayManagementInfoL() |
|
266 { |
|
267 User::Panic(KCafPanicString, ECafPanicF32AgentManagementInfoNotSupported); |
|
268 } |
|
269 |
|
270 CF32AgentUi& CF32AgentManager::AgentUiL() |
|
271 { |
|
272 if(!iAgentUi) |
|
273 { |
|
274 iAgentUi = TF32AgentUiFactory::CreateF32AgentUiL(); |
|
275 } |
|
276 return *iAgentUi; |
|
277 } |
|
278 |
|
279 void CF32AgentManager::PrepareHTTPRequestHeaders(RStringPool& /*aStringPool*/, RHTTPHeaders& /*aRequestHeaders*/) const |
|
280 { |
|
281 User::Panic(KCafPanicString, ECafPanicF32AgentPrepareHTTPHeadersNotSupported); |
|
282 } |