|
1 /* |
|
2 * Copyright (c) 2002-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: Navigable file list model |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <bautils.h> |
|
22 #include "CGflmNavigatorModel.h" |
|
23 #include "CGflmItemGroupImpl.h" |
|
24 #include "CGflmItemLocalizer.h" |
|
25 #include "CGflmDriveResolver.h" |
|
26 #include "GFLM.hrh" |
|
27 #include "GflmUtils.h" |
|
28 #include "GFLMConsts.h" |
|
29 |
|
30 |
|
31 // CONSTANTS |
|
32 |
|
33 // Granularity of iBackstepStack array |
|
34 const TInt KBackstepStackGranularity = 3; |
|
35 |
|
36 |
|
37 // ============================ MEMBER FUNCTIONS =============================== |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CGflmNavigatorModel::CGflmNavigatorModel |
|
41 // C++ default constructor can NOT contain any code, that |
|
42 // might leave. |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CGflmNavigatorModel::CGflmNavigatorModel( RFs& aFs ) : |
|
46 CGflmFileListModel( aFs ) |
|
47 { |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CGflmNavigatorModel::ConstructL() |
|
52 // Symbian 2nd phase constructor can leave. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 void CGflmNavigatorModel::ConstructL() |
|
56 { |
|
57 CGflmFileListModel::ConstructL(); |
|
58 iBackstepStack = new( ELeave ) CDesCArraySeg( KBackstepStackGranularity ); |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CGflmNavigatorModel::NewL() |
|
63 // Two-phased constructor. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 EXPORT_C CGflmNavigatorModel* CGflmNavigatorModel::NewL( RFs& aFs ) |
|
67 { |
|
68 CGflmNavigatorModel* self = new( ELeave ) CGflmNavigatorModel( aFs ); |
|
69 |
|
70 CleanupStack::PushL( self ); |
|
71 self->ConstructL(); |
|
72 CleanupStack::Pop( self ); |
|
73 |
|
74 return self; |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CGflmNavigatorModel::~CGflmNavigatorModel() |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 CGflmNavigatorModel::~CGflmNavigatorModel() |
|
82 { |
|
83 delete iBackstepStack; |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CGflmNavigatorModel::GoToDirectoryL() |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 EXPORT_C void CGflmNavigatorModel::GoToDirectoryL( |
|
91 const TDesC& aPath, TBool aBackstepping ) |
|
92 { |
|
93 if ( !aPath.CompareF( CurrentDirectory() ) ) |
|
94 { |
|
95 return; // Already in the directory |
|
96 } |
|
97 SetBaseDirectoryL( aPath ); |
|
98 |
|
99 // Update the backstepping stack after calling SetBaseDirectoryL() |
|
100 // because it might leave |
|
101 if ( !aBackstepping ) |
|
102 { |
|
103 iBackstepStack->Reset(); |
|
104 } |
|
105 iBackstepStack->AppendL( aPath ); |
|
106 |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CGflmNavigatorModel::BackstepL() |
|
111 // (other items were commented in a header). |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 EXPORT_C void CGflmNavigatorModel::BackstepL() |
|
115 { |
|
116 if ( iBackstepStack->MdcaCount() ) |
|
117 { |
|
118 iBackstepStack->Delete( iBackstepStack->MdcaCount() - 1 ); |
|
119 if ( iBackstepStack->MdcaCount() ) |
|
120 { |
|
121 TPtrC dir( iBackstepStack->MdcaPoint( |
|
122 iBackstepStack->MdcaCount() - 1 ) ); |
|
123 SetSourceL( dir ); |
|
124 if ( !IsValidSource( dir ) ) |
|
125 { |
|
126 User::Leave( KErrPathNotFound ); |
|
127 } |
|
128 } |
|
129 else |
|
130 { |
|
131 SetSourceL( KNullDesC ); |
|
132 } |
|
133 } |
|
134 else |
|
135 { |
|
136 User::Leave( KErrUnderflow ); |
|
137 } |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CGflmNavigatorModel::GoToDirectoryL() |
|
142 // (other items were commented in a header). |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 EXPORT_C void CGflmNavigatorModel::GoToDirectoryL( const TDesC& aBasePath, |
|
146 const TDesC& aTopPath ) |
|
147 { |
|
148 // Use copies because descriptors may come from backstep stack itself |
|
149 HBufC* basePathBuffer = aBasePath.AllocLC(); |
|
150 TPtrC basePath( basePathBuffer->Des() ); |
|
151 HBufC* topPathBuffer = aTopPath.AllocLC(); |
|
152 TPtrC topPath( topPathBuffer->Des() ); |
|
153 const TInt KNthMatch = 2; |
|
154 |
|
155 // Clear the backstepping stack |
|
156 iBackstepStack->Reset(); |
|
157 |
|
158 // Construct the backstepping stack |
|
159 |
|
160 while ( basePath.CompareF( topPath ) ) |
|
161 { |
|
162 iBackstepStack->InsertL( 0, topPath ); |
|
163 |
|
164 // Find the second backslash starting from the end |
|
165 TInt cutPoint( GflmUtils::LocateReverseNth( |
|
166 topPath, KGFLMBackslash()[ 0 ], KNthMatch ) ); |
|
167 User::LeaveIfError( cutPoint ); |
|
168 topPath.Set( topPath.Left( cutPoint + 1 ) ); |
|
169 } |
|
170 |
|
171 // Add basepath too |
|
172 iBackstepStack->InsertL( 0, topPath ); |
|
173 |
|
174 SetBaseDirectoryL( *topPathBuffer ); |
|
175 |
|
176 CleanupStack::PopAndDestroy( topPathBuffer ); |
|
177 CleanupStack::PopAndDestroy( basePathBuffer ); |
|
178 } |
|
179 |
|
180 // ----------------------------------------------------------------------------- |
|
181 // CGflmNavigatorModel::CurrentDirectory() |
|
182 // (other items were commented in a header). |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 EXPORT_C TPtrC CGflmNavigatorModel::CurrentDirectory() const |
|
186 { |
|
187 TInt stackSize( iBackstepStack->MdcaCount() ); |
|
188 if ( stackSize <= 0 ) |
|
189 { |
|
190 return KNullDesC(); |
|
191 } |
|
192 return iBackstepStack->MdcaPoint( stackSize - 1 ); |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // CGflmNavigatorModel::LocalizedNameOfCurrentDirectory() |
|
197 // (other items were commented in a header). |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 EXPORT_C TPtrC CGflmNavigatorModel::LocalizedNameOfCurrentDirectory() const |
|
201 { |
|
202 TInt stackSize( iBackstepStack->MdcaCount() ); |
|
203 if ( stackSize <= 0 ) |
|
204 { |
|
205 return TPtrC( KNullDesC ); |
|
206 } |
|
207 TPtrC directory( iBackstepStack->MdcaPoint( stackSize - 1 ) ); |
|
208 TPtrC localizedName( iItemLocalizer->Localize( directory ) ); |
|
209 if ( localizedName.Length() ) |
|
210 { |
|
211 // Return the localized name |
|
212 return localizedName; |
|
213 } |
|
214 // Directory has no localized name => return the name of the directory |
|
215 TPtrC ptr( GflmUtils::StripFinalBackslash( directory ) ); |
|
216 TInt lastBs( ptr.LocateReverse( KGFLMBackslash()[ 0 ] ) ); |
|
217 if ( lastBs != KErrNotFound ) |
|
218 { |
|
219 return ptr.Mid( lastBs + 1 ); |
|
220 } |
|
221 return TPtrC( KNullDesC ); |
|
222 } |
|
223 |
|
224 // ----------------------------------------------------------------------------- |
|
225 // CGflmNavigatorModel::SetBaseDirectoryL() |
|
226 // (other items were commented in a header). |
|
227 // ----------------------------------------------------------------------------- |
|
228 // |
|
229 void CGflmNavigatorModel::SetBaseDirectoryL( const TDesC& aDirectory ) |
|
230 { |
|
231 if ( IsValidSource( aDirectory ) ) |
|
232 { |
|
233 SetSourceL( aDirectory ); |
|
234 } |
|
235 else |
|
236 { |
|
237 User::Leave( KErrPathNotFound ); |
|
238 } |
|
239 } |
|
240 |
|
241 // ----------------------------------------------------------------------------- |
|
242 // CGflmNavigatorModel::NavigationLevel() |
|
243 // (other items were commented in a header). |
|
244 // ----------------------------------------------------------------------------- |
|
245 // |
|
246 EXPORT_C TInt CGflmNavigatorModel::NavigationLevel() const |
|
247 { |
|
248 return iBackstepStack->Count() - 1; |
|
249 } |
|
250 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // CGflmNavigatorModel::CurrentDrive() |
|
253 // (other items were commented in a header). |
|
254 // ----------------------------------------------------------------------------- |
|
255 // |
|
256 EXPORT_C CGflmDriveItem* CGflmNavigatorModel::CurrentDrive() const |
|
257 { |
|
258 return DriveFromPath( CurrentDirectory() ); |
|
259 } |
|
260 |
|
261 // ----------------------------------------------------------------------------- |
|
262 // CGflmNavigatorModel::SetSourceL() |
|
263 // (other items were commented in a header). |
|
264 // ----------------------------------------------------------------------------- |
|
265 // |
|
266 void CGflmNavigatorModel::SetSourceL( const TDesC& aSource ) |
|
267 { |
|
268 TBool empty( !aSource.Length() ); |
|
269 TInt groupCount( iGroups->Count() ); |
|
270 for ( TInt i( 0 ); i < groupCount; i++ ) |
|
271 { |
|
272 MGflmItemGroup* group = iGroups->At( i ); |
|
273 group->ResetSources(); |
|
274 if ( !empty ) |
|
275 { |
|
276 group->AddSourceL( aSource ); |
|
277 } |
|
278 } |
|
279 } |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // CGflmNavigatorModel::IsValidSource() |
|
283 // (other items were commented in a header). |
|
284 // ----------------------------------------------------------------------------- |
|
285 // |
|
286 TBool CGflmNavigatorModel::IsValidSource( const TDesC& aSource ) const |
|
287 { |
|
288 if ( aSource.Length() && |
|
289 !iDriveResolver->IsRemoteDrive( aSource ) && |
|
290 !BaflUtils::PathExists( iFs, aSource ) && |
|
291 !iDriveResolver->IsRootPath( aSource ) ) |
|
292 { |
|
293 return EFalse; |
|
294 } |
|
295 return ETrue; |
|
296 } |
|
297 |
|
298 // End of File |