|
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: Implements CNcdDatabaseFileHandler class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <f32file.h> // RFs |
|
20 |
|
21 #include "ncddatabasefilehandler.h" |
|
22 #include "ncdproviderdefines.h" |
|
23 #include "catalogsdebug.h" |
|
24 #include "ncdstorageclient.h" |
|
25 #include "ncdstorage.h" |
|
26 #include "ncddatabasestorage.h" |
|
27 #include "ncdstoragefiledataitem.h" |
|
28 #include "ncdstoragebase.h" |
|
29 #include "catalogsutils.h" |
|
30 |
|
31 // ======== MEMBER FUNCTIONS ======== |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // NewL |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 CNcdDatabaseFileHandler* CNcdDatabaseFileHandler::NewL( |
|
38 MNcdStorageClient& aStorageClient, |
|
39 NcdNodeClassIds::TNcdNodeClassType aDataType ) |
|
40 { |
|
41 CNcdDatabaseFileHandler* self = new( ELeave ) |
|
42 CNcdDatabaseFileHandler( aStorageClient, aDataType ); |
|
43 CleanupStack::PushL( self ); |
|
44 self->ConstructL(); |
|
45 CleanupStack::Pop(); |
|
46 return self; |
|
47 } |
|
48 |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // Destructor |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 CNcdDatabaseFileHandler::~CNcdDatabaseFileHandler() |
|
55 { |
|
56 DLTRACE(("--><--")); |
|
57 } |
|
58 |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // MoveL |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 void CNcdDatabaseFileHandler::MoveFileL( const TDesC& aSourceFile, |
|
65 const TDesC& aNamespaceOrDir, const TDesC& aIdOrName, |
|
66 TBool /* aOverwrite */ ) |
|
67 { |
|
68 DLTRACEIN(("")); |
|
69 DLINFO(( _L("Src: %S, ns: %S, id: %S"), &aSourceFile, |
|
70 &aNamespaceOrDir, &aIdOrName )); |
|
71 |
|
72 // Get storage or create it if it doesn't exist |
|
73 MNcdStorage& storage = StorageL( aNamespaceOrDir ); |
|
74 |
|
75 MNcdDatabaseStorage& db = storage.DatabaseStorageL( |
|
76 NcdProviderDefines::KDefaultDatabaseUid ); |
|
77 |
|
78 // Stored data is of the given type |
|
79 MNcdStorageItem* item = db.StorageItemL( aIdOrName, |
|
80 iDataType ); |
|
81 |
|
82 |
|
83 CNcdStorageFileDataItem* dataItem = |
|
84 CNcdStorageFileDataItem::NewL( aSourceFile, |
|
85 storage.FileSession() ); |
|
86 CleanupStack::PushL( dataItem ); |
|
87 |
|
88 //DLINFO(("Internalizing the data")); |
|
89 item->SetDataItem( dataItem ); |
|
90 |
|
91 item->OpenL(); |
|
92 // Write the file to the storage |
|
93 //DLINFO(("Writing data")); |
|
94 item->WriteDataL(); |
|
95 |
|
96 DLINFO(("Saving data")); |
|
97 item->SaveL(); |
|
98 |
|
99 CleanupStack::PopAndDestroy( dataItem ); |
|
100 |
|
101 DLTRACE(( "Deleting source file" )); |
|
102 // Delete sourcefile after successful internalization |
|
103 User::LeaveIfError( storage.FileSession().Delete( aSourceFile ) ); |
|
104 DLTRACEOUT(( "" )); |
|
105 } |
|
106 |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // Constructor |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 CNcdDatabaseFileHandler::CNcdDatabaseFileHandler( |
|
113 MNcdStorageClient& aStorageClient, |
|
114 NcdNodeClassIds::TNcdNodeClassType aDataType ) : |
|
115 iStorageClient( aStorageClient ), iDataType( aDataType ) |
|
116 { |
|
117 } |
|
118 |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // ConstructL |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 void CNcdDatabaseFileHandler::ConstructL() |
|
125 { |
|
126 } |
|
127 |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // Ensures the storage exists |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 MNcdStorage& CNcdDatabaseFileHandler::StorageL( const TDesC& aNamespace ) |
|
134 { |
|
135 DLTRACEIN(("")); |
|
136 MNcdStorage* storage = NULL; |
|
137 // Search for the storage |
|
138 TRAPD( err, |
|
139 storage = &iStorageClient.StorageL( aNamespace ) ); |
|
140 |
|
141 if ( err == KErrNone ) |
|
142 { |
|
143 DLTRACEOUT(("")); |
|
144 return *storage; |
|
145 } |
|
146 else if ( err != KErrNotFound ) |
|
147 { |
|
148 DLTRACEOUT(("Leaving with: %d", err)); |
|
149 User::Leave( err ); |
|
150 } |
|
151 |
|
152 // Create the namespace |
|
153 return iStorageClient.CreateStorageL( aNamespace ); |
|
154 } |
|
155 |