1 /* |
|
2 * Copyright (c) 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 "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 #include "MemSpyViewOpenFiles.h" |
|
19 |
|
20 // System includes |
|
21 #include <AknIconArray.h> |
|
22 #include <eikdef.h> |
|
23 #include <eikclbd.h> |
|
24 #include <aknconsts.h> |
|
25 #include <gulicon.h> |
|
26 #include <avkon.mbg> |
|
27 |
|
28 // Engine includes |
|
29 #include <memspy/engine/memspyengine.h> |
|
30 #include <memspy/engine/memspyengineobjectprocess.h> |
|
31 #include <memspy/engine/memspyengineobjectthread.h> |
|
32 #include <memspy/engine/memspyengineobjectcontainer.h> |
|
33 #include <memspy/engine/memspyengineobjectthreadinfoobjects.h> |
|
34 #include <memspy/engine/memspyengineobjectthreadinfocontainer.h> |
|
35 #include <memspy/engine/memspyenginehelperprocess.h> |
|
36 |
|
37 // User includes |
|
38 #include "MemSpyUiUtils.h" |
|
39 #include "MemSpyViewThreads.h" |
|
40 #include "MemSpyViewMainMenu.h" |
|
41 #include "MemSpyContainerObserver.h" |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 CMemSpyViewOpenFiles::CMemSpyViewOpenFiles( CMemSpyEngine& aEngine, MMemSpyViewObserver& aObserver ) |
|
47 : CMemSpyViewBase( aEngine, aObserver ) |
|
48 { |
|
49 } |
|
50 |
|
51 |
|
52 CMemSpyViewOpenFiles::~CMemSpyViewOpenFiles() |
|
53 { |
|
54 iThreadIds.Close(); |
|
55 iFileNames.Close(); |
|
56 } |
|
57 |
|
58 |
|
59 void CMemSpyViewOpenFiles::ConstructL( const TRect& aRect, CCoeControl& aContainer, TAny* aSelectionRune ) |
|
60 { |
|
61 _LIT( KTitle, "Open Files" ); |
|
62 SetTitleL( KTitle ); |
|
63 // |
|
64 CMemSpyViewBase::ConstructL( aRect, aContainer, aSelectionRune ); |
|
65 } |
|
66 |
|
67 |
|
68 CEikListBox* CMemSpyViewOpenFiles::ConstructListBoxL() |
|
69 { |
|
70 delete iListBox; |
|
71 iListBox = NULL; |
|
72 CAknDoubleGraphicStyleListBox* listbox = new (ELeave) CAknDoubleGraphicStyleListBox(); |
|
73 iListBox = listbox; |
|
74 // |
|
75 listbox->ConstructL( this, EAknListBoxSelectionList | EAknListBoxLoopScrolling ); |
|
76 listbox->SetContainerWindowL( *this ); |
|
77 listbox->CreateScrollBarFrameL( ETrue ); |
|
78 SetListBoxModelL(); |
|
79 listbox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); |
|
80 listbox->SetListBoxObserver( this ); |
|
81 listbox->SetObserver( this ); |
|
82 |
|
83 // Create icon array |
|
84 CAknIconArray* iconArray = new (ELeave) CAknIconArray(1); |
|
85 CleanupStack::PushL( iconArray ); |
|
86 |
|
87 // Create bitmap |
|
88 CFbsBitmap* bitmap = new(ELeave) CFbsBitmap(); |
|
89 CleanupStack::PushL( bitmap ); |
|
90 const TInt error1 = bitmap->Create( TSize(10,10), EColor16M ); |
|
91 User::LeaveIfError( error1 ); |
|
92 |
|
93 // Create mask |
|
94 CFbsBitmap* mask = new(ELeave) CFbsBitmap(); |
|
95 CleanupStack::PushL( mask ); |
|
96 const TInt error2 = mask->Create( TSize(10,10), EColor16M ); |
|
97 User::LeaveIfError( error2 ); |
|
98 |
|
99 // Create icon & transfer bitmap |
|
100 CGulIcon* icon = CGulIcon::NewL( bitmap, mask ); |
|
101 CleanupStack::Pop( 2, bitmap ); |
|
102 CleanupStack::PushL( icon ); |
|
103 |
|
104 // Transfer icon to array |
|
105 iconArray->AppendL( icon ); |
|
106 CleanupStack::Pop( icon ); |
|
107 |
|
108 // Give icon array to listbox |
|
109 static_cast<CEikFormattedCellListBox*>(iListBox)->ItemDrawer()->FormattedCellData()->SetIconArrayL(iconArray); |
|
110 CleanupStack::Pop( iconArray ); |
|
111 // |
|
112 return listbox; |
|
113 } |
|
114 |
|
115 |
|
116 void CMemSpyViewOpenFiles::RefreshL() |
|
117 { |
|
118 SetListBoxModelL(); |
|
119 CMemSpyViewBase::RefreshL(); |
|
120 } |
|
121 |
|
122 |
|
123 TMemSpyViewType CMemSpyViewOpenFiles::ViewType() const |
|
124 { |
|
125 return EMemSpyViewTypeOpenFiles; |
|
126 } |
|
127 |
|
128 |
|
129 TBool CMemSpyViewOpenFiles::HandleCommandL( TInt aCommand ) |
|
130 { |
|
131 TBool handled = ETrue; |
|
132 // |
|
133 switch ( aCommand ) |
|
134 { |
|
135 case EMemSpyCmdToolsListOpenFiles: |
|
136 OnCmdListOpenFilesL(); |
|
137 break; |
|
138 |
|
139 default: |
|
140 handled = CMemSpyViewBase::HandleCommandL( aCommand ); |
|
141 break; |
|
142 } |
|
143 // |
|
144 return handled; |
|
145 } |
|
146 |
|
147 |
|
148 void CMemSpyViewOpenFiles::OnCmdListOpenFilesL() |
|
149 { |
|
150 iEngine.ListOpenFilesL(); |
|
151 } |
|
152 |
|
153 |
|
154 CMemSpyViewBase* CMemSpyViewOpenFiles::PrepareParentViewL() |
|
155 { |
|
156 CMemSpyViewMainMenu* parent = new(ELeave) CMemSpyViewMainMenu( iEngine, iObserver ); |
|
157 CleanupStack::PushL( parent ); |
|
158 parent->ConstructL( Rect(), *Parent(), (TAny*) ViewType() ); |
|
159 CleanupStack::Pop( parent ); |
|
160 return parent; |
|
161 } |
|
162 |
|
163 |
|
164 CMemSpyViewBase* CMemSpyViewOpenFiles::PrepareChildViewL() |
|
165 { |
|
166 CMemSpyViewBase* child = NULL; |
|
167 |
|
168 // First, try to find the selected thread |
|
169 if ( iActionedThreadId ) |
|
170 { |
|
171 // Try to create a view of the thread in question |
|
172 CMemSpyProcess* process = NULL; |
|
173 CMemSpyThread* thread = NULL; |
|
174 const TInt error = iEngine.Container().ProcessAndThreadByThreadId( *iActionedThreadId, process, thread ); |
|
175 if ( error == KErrNone && thread != NULL ) |
|
176 { |
|
177 child = new(ELeave) CMemSpyViewThreads( iEngine, iObserver, thread->Process() ); |
|
178 CleanupStack::PushL( child ); |
|
179 child->ConstructL( Rect(), *Parent(), thread ); |
|
180 CleanupStack::Pop( child ); |
|
181 } |
|
182 } |
|
183 // |
|
184 return child; |
|
185 } |
|
186 |
|
187 |
|
188 void CMemSpyViewOpenFiles::SetListBoxModelL() |
|
189 { |
|
190 _LIT(KLineFormatSpec, "%d\t%S\t%S %S"); |
|
191 |
|
192 CDesCArrayFlat* model = new(ELeave) CDesCArrayFlat(5); |
|
193 CleanupStack::PushL( model ); |
|
194 |
|
195 TBuf<KMaxFullName + 50> item; |
|
196 TMemSpySizeText valueBuf; |
|
197 TBuf<64> timeBuf; |
|
198 |
|
199 iFileNames.Reset(); |
|
200 iThreadIds.Reset(); |
|
201 iActionedThreadId = NULL; |
|
202 |
|
203 RFs& fsSession = iCoeEnv->FsSession(); |
|
204 TOpenFileScan scanner( fsSession ); |
|
205 |
|
206 CFileList* list = NULL; |
|
207 scanner.NextL( list ); |
|
208 |
|
209 TIdentityRelation<TEntry> comparer( CompareTEntryObjects ); |
|
210 |
|
211 while( list != NULL ) |
|
212 { |
|
213 CleanupStack::PushL( list ); |
|
214 |
|
215 const TInt entryCount = list->Count(); |
|
216 for(TInt i=0; i<entryCount; i++) |
|
217 { |
|
218 const TEntry& entry = (*list)[ i ]; |
|
219 |
|
220 // Check for duplicates |
|
221 const TInt foundIndex = iFileNames.Find( entry, comparer ); |
|
222 if ( foundIndex == KErrNotFound ) |
|
223 { |
|
224 // Get time and size format strings |
|
225 valueBuf = MemSpyUiUtils::FormatSizeText( entry.iSize ); |
|
226 MemSpyUiUtils::FormatTimeL( timeBuf, entry.iModified ); |
|
227 |
|
228 // Get just file name |
|
229 TParsePtrC parser( entry.iName ); |
|
230 const TPtrC pJustName( parser.NameAndExt() ); |
|
231 |
|
232 // Create item |
|
233 item.Format( KLineFormatSpec, 0, &pJustName, &valueBuf, &timeBuf ); |
|
234 model->AppendL( item ); |
|
235 iThreadIds.AppendL( scanner.ThreadId() ); |
|
236 iFileNames.AppendL( entry ); |
|
237 } |
|
238 } |
|
239 |
|
240 CleanupStack::PopAndDestroy( list ); |
|
241 list = NULL; |
|
242 scanner.NextL( list ); |
|
243 } |
|
244 |
|
245 // Set up list box |
|
246 CAknSettingStyleListBox* listbox = static_cast< CAknSettingStyleListBox* >( iListBox ); |
|
247 listbox->Model()->SetItemTextArray( model ); |
|
248 listbox->Model()->SetOwnershipType( ELbmOwnsItemArray ); |
|
249 CleanupStack::Pop( model ); |
|
250 } |
|
251 |
|
252 |
|
253 void CMemSpyViewOpenFiles::HandleListBoxItemActionedL( TInt aCurrentIndex ) |
|
254 { |
|
255 if ( aCurrentIndex >= 0 && aCurrentIndex < iThreadIds.Count() ) |
|
256 { |
|
257 iActionedThreadId = &iThreadIds[ aCurrentIndex ]; |
|
258 } |
|
259 else |
|
260 { |
|
261 iActionedThreadId = NULL; |
|
262 } |
|
263 |
|
264 // Notify observer about an item being 'fired' |
|
265 ReportEventL( MMemSpyViewObserver::EEventItemActioned ); |
|
266 } |
|
267 |
|
268 |
|
269 TBool CMemSpyViewOpenFiles::CompareTEntryObjects( const TEntry& aLeft, const TEntry& aRight ) |
|
270 { |
|
271 return ( aLeft.iName.CompareF( aRight.iName ) == 0 ); |
|
272 } |
|
273 |
|
274 |
|