|
1 /* |
|
2 * Copyright (c) 2005-2007 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: CUpnpSelectionWriter class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 // INCLUDE FILES |
|
24 |
|
25 #include <upnpstring.h> |
|
26 #include <centralrepository.h> |
|
27 #include <s32file.h> |
|
28 |
|
29 #include "upnpselectionwriter.h" |
|
30 #include "upnpcontentservercrkeys.h" |
|
31 #include "upnpcontentserverdefs.h" |
|
32 |
|
33 _LIT( KComponentLogfile, "contentserver.txt"); |
|
34 #include "upnplog.h" |
|
35 |
|
36 using namespace UpnpContentServer; |
|
37 |
|
38 // ================= MEMBER FUNCTIONS ======================= |
|
39 |
|
40 // -------------------------------------------------------------------------- |
|
41 // CUpnpSelectionWriter::NewL |
|
42 // Two-phased constructor. |
|
43 // -------------------------------------------------------------------------- |
|
44 // |
|
45 CUpnpSelectionWriter* CUpnpSelectionWriter::NewL( |
|
46 TUpnpMediaType aMediaType ) |
|
47 { |
|
48 __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ ); |
|
49 |
|
50 CUpnpSelectionWriter* self = |
|
51 new(ELeave) CUpnpSelectionWriter(); |
|
52 |
|
53 CleanupStack::PushL(self); |
|
54 self->ConstructL( aMediaType ); |
|
55 CleanupStack::Pop(self); |
|
56 __LOG8_1( "%s end.", __PRETTY_FUNCTION__ ); |
|
57 return self; |
|
58 } |
|
59 |
|
60 |
|
61 // -------------------------------------------------------------------------- |
|
62 // CUpnpSelectionWriter::ConstructL |
|
63 // Symbian 2nd phase constructor can leave. |
|
64 // -------------------------------------------------------------------------- |
|
65 // |
|
66 void CUpnpSelectionWriter::ConstructL( |
|
67 TUpnpMediaType aMediaType ) |
|
68 { |
|
69 __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ ); |
|
70 iMediaType = aMediaType; |
|
71 |
|
72 iFileArray = new (ELeave) CDesCArrayFlat(4); |
|
73 iOkItems.Reset(); |
|
74 |
|
75 __LOG8_1( "%s end.", __PRETTY_FUNCTION__ ); |
|
76 } |
|
77 |
|
78 |
|
79 // -------------------------------------------------------------------------- |
|
80 // CUpnpSelectionWriter::CUpnpSelectionWriter |
|
81 // C++ default constructor can NOT contain any code, that |
|
82 // might leave. |
|
83 // -------------------------------------------------------------------------- |
|
84 // |
|
85 CUpnpSelectionWriter::CUpnpSelectionWriter() |
|
86 { |
|
87 __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ ); |
|
88 __LOG8_1( "%s end.", __PRETTY_FUNCTION__ ); |
|
89 } |
|
90 |
|
91 // -------------------------------------------------------------------------- |
|
92 // CUpnpSelectionWriter::CUpnpSelectionWriter |
|
93 // C++ default destructor. |
|
94 // -------------------------------------------------------------------------- |
|
95 // |
|
96 CUpnpSelectionWriter::~CUpnpSelectionWriter() |
|
97 { |
|
98 __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ ); |
|
99 |
|
100 delete iFileArray; |
|
101 iOkItems.Reset(); |
|
102 delete iRepository; |
|
103 |
|
104 __LOG8_1( "%s end.", __PRETTY_FUNCTION__ ); |
|
105 } |
|
106 |
|
107 // -------------------------------------------------------------------------- |
|
108 // CUpnpSelectionWriter::AppendItemL |
|
109 // ( other items were commented in header ) |
|
110 // -------------------------------------------------------------------------- |
|
111 // |
|
112 void CUpnpSelectionWriter::AppendItemL( const TPtrC aNewObject) |
|
113 { |
|
114 __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ ); |
|
115 iFileArray->AppendL( aNewObject ); |
|
116 __LOG8_1( "%s end.", __PRETTY_FUNCTION__ ); |
|
117 } |
|
118 |
|
119 // -------------------------------------------------------------------------- |
|
120 // CUpnpSelectionWriter::AppendStatusL |
|
121 // ( other items were commented in header ) |
|
122 // -------------------------------------------------------------------------- |
|
123 // |
|
124 void CUpnpSelectionWriter::AppendStatusL( TInt aIndex ) |
|
125 { |
|
126 __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ ); |
|
127 iOkItems.AppendL( aIndex ); |
|
128 __LOG8_1( "%s end.", __PRETTY_FUNCTION__ ); |
|
129 } |
|
130 |
|
131 // -------------------------------------------------------------------------- |
|
132 // CUpnpSelectionWriter::SaveSharingState |
|
133 // Saves sharing state to central repository |
|
134 // -------------------------------------------------------------------------- |
|
135 // |
|
136 TInt CUpnpSelectionWriter::SaveSharingStateL( TInt aShareAllSelection ) |
|
137 { |
|
138 __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ ); |
|
139 |
|
140 TInt status = KErrNone; |
|
141 iRepository = CRepository::NewL( KCrUidUpnpContentserver ); |
|
142 switch ( iMediaType ) |
|
143 { |
|
144 case EImageAndVideo: |
|
145 { |
|
146 if (aShareAllSelection == EShareAll || |
|
147 aShareAllSelection == EShareNone || |
|
148 aShareAllSelection == EShareMany ) |
|
149 { |
|
150 status = iRepository->Set( KUPnPAppShareAllVisualFiles, |
|
151 aShareAllSelection); |
|
152 } |
|
153 break; |
|
154 } |
|
155 case EPlaylist: |
|
156 { |
|
157 if (aShareAllSelection == EShareAll || |
|
158 aShareAllSelection == EShareNone || |
|
159 aShareAllSelection == EShareMany ) |
|
160 { |
|
161 status = iRepository->Set( KUPnPAppShareAllMusicFiles, |
|
162 aShareAllSelection); |
|
163 } |
|
164 break; |
|
165 } |
|
166 default: |
|
167 { |
|
168 __LOG( "SaveSharingStateL - default"); |
|
169 break; |
|
170 } |
|
171 } |
|
172 |
|
173 delete iRepository; |
|
174 iRepository = NULL; |
|
175 |
|
176 // Store the item array |
|
177 if ( aShareAllSelection == EShareMany ) |
|
178 { |
|
179 StoreSharedContainerIDsL(); |
|
180 } |
|
181 |
|
182 __LOG8_1( "%s end.", __PRETTY_FUNCTION__ ); |
|
183 return status; |
|
184 } |
|
185 |
|
186 // -------------------------------------------------------------------------- |
|
187 // CUPnPFileSharingEngine::StoreSharedContainerIDsL |
|
188 // Creates main containers and starts sharing them |
|
189 // -------------------------------------------------------------------------- |
|
190 // |
|
191 TInt CUpnpSelectionWriter::StoreSharedContainerIDsL() const |
|
192 { |
|
193 __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ ); |
|
194 |
|
195 // Leave if aIdArray = NULL |
|
196 if ( !iFileArray ) |
|
197 { |
|
198 User::Leave(KErrArgument); |
|
199 } |
|
200 |
|
201 RFs fs; |
|
202 RFile file; |
|
203 User::LeaveIfError( fs.Connect() ); |
|
204 CleanupClosePushL(fs); |
|
205 |
|
206 TFileName directory; |
|
207 |
|
208 // Get private directory path |
|
209 fs.SessionPath(directory); |
|
210 |
|
211 // Try to create directory |
|
212 TInt error = fs.MkDir(directory); |
|
213 // it's ok if directory already exists |
|
214 if (!(error != KErrNone && error != KErrAlreadyExists)) |
|
215 { |
|
216 |
|
217 // Add file name |
|
218 if ( iMediaType == EImageAndVideo ) |
|
219 { |
|
220 directory.Append( KVisualFile ); |
|
221 } |
|
222 else if ( iMediaType == EPlaylist ) |
|
223 { |
|
224 directory.Append( KMusicFile ); |
|
225 } |
|
226 |
|
227 error = file.Replace(fs, directory, EFileWrite ); |
|
228 if ( !error ) |
|
229 { |
|
230 CleanupClosePushL( file ); |
|
231 RFileWriteStream writeStream(file); |
|
232 CleanupClosePushL( writeStream ); |
|
233 |
|
234 for (TInt index = 0; index < iFileArray->Count(); index++) |
|
235 { |
|
236 // check that sharing of the container was succesful |
|
237 if ( iOkItems.Find( index ) != KErrNotFound ) |
|
238 { |
|
239 // Write identifiers to the file |
|
240 writeStream << iFileArray->MdcaPoint(index); |
|
241 } |
|
242 } |
|
243 |
|
244 // Clean up |
|
245 CleanupStack::PopAndDestroy(&writeStream); // Close writeStream |
|
246 CleanupStack::PopAndDestroy(&file); // Close file |
|
247 } |
|
248 } |
|
249 CleanupStack::PopAndDestroy(&fs); |
|
250 __LOG8_1( "%s end.", __PRETTY_FUNCTION__ ); |
|
251 return error; |
|
252 } |
|
253 |
|
254 // End of file |