|
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 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "profiler_gui_appui.h" |
|
22 #include "profiler_gui_mainview.h" |
|
23 #include "profiler_gui.hrh" |
|
24 #include "profiler_gui_model.h" |
|
25 #include "profiler_gui_document.h" |
|
26 #include <piprofilerui.rsg> |
|
27 #include <piprofiler/ProfilerTraces.h> |
|
28 #include <piprofiler/ProfilerSession.h> |
|
29 #include <piprofiler/ProfilerConfig.h> |
|
30 |
|
31 #include <AknWaitDialog.h> |
|
32 #include <AknGlobalNote.h> |
|
33 #include <avkon.hrh> |
|
34 #include <AknQueryDialog.h> |
|
35 #include <aknmessagequerydialog.h> |
|
36 #include <pathinfo.h> |
|
37 |
|
38 |
|
39 // ================= MEMBER FUNCTIONS ======================= |
|
40 |
|
41 void CProfilerGuiAppUi::ConstructL() |
|
42 { |
|
43 // set as system application to prevent getting shut down events |
|
44 iEikonEnv->SetSystem(ETrue); |
|
45 |
|
46 BaseConstructL(EAknEnableSkin); |
|
47 |
|
48 // get model |
|
49 iModel = static_cast<CProfilerGuiDocument*>(reinterpret_cast<CEikAppUi*>(iEikonEnv->AppUi())->Document())->Model(); |
|
50 |
|
51 LOGTEXT(_L("ProfilerGuiAppUi::ConstructL - setting main view settings")); |
|
52 |
|
53 CProfilerGuiMainView* mainView = new(ELeave) CProfilerGuiMainView; |
|
54 CleanupStack::PushL(mainView); |
|
55 mainView->ConstructL(); |
|
56 AddViewL(mainView); // transfer ownership to CAknViewAppUi |
|
57 CleanupStack::Pop(); // mainView |
|
58 |
|
59 LOGTEXT(_L("ProfilerGuiAppUi::ConstructL - setting default view")); |
|
60 |
|
61 SetDefaultViewL(*mainView); |
|
62 |
|
63 LOGTEXT(_L("ProfilerGuiAppUi::ConstructL - activating model")); |
|
64 |
|
65 // notify the model that everything has been constructed |
|
66 iModel->ActivateModelL(); |
|
67 } |
|
68 |
|
69 // -------------------------------------------------------------------------------------------- |
|
70 |
|
71 CProfilerGuiAppUi::~CProfilerGuiAppUi() |
|
72 { |
|
73 // notify the model that the application is closing |
|
74 if (iModel) |
|
75 TRAP_IGNORE(iModel->DeActivateModelL()); |
|
76 |
|
77 } |
|
78 |
|
79 // -------------------------------------------------------------------------------------------- |
|
80 |
|
81 void CProfilerGuiAppUi::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane) |
|
82 { |
|
83 if( aResourceId == R_PROFILER_START_SUBMENU ) |
|
84 { |
|
85 CEikMenuPaneItem::SData itemData; |
|
86 _LIT(KMenuText, "Profiling for %d sec."); |
|
87 itemData.iText.Format(KMenuText, iModel->GeneralSettings().iTimedSamplingPeriod);// = _L("Profiling for %d sec."); // Label text for the menu item |
|
88 itemData.iCommandId = EProfilerGuiCmdStartTimed; // Command ID for the menu item |
|
89 itemData.iFlags = 0; |
|
90 itemData.iCascadeId = 0; |
|
91 aMenuPane->AddMenuItemL( itemData ); |
|
92 } |
|
93 if (aResourceId == R_PROFILER_GUI_APP_MENU) |
|
94 { |
|
95 if(iModel->iState == MProfilerStatusObserver::ERunning) |
|
96 { |
|
97 aMenuPane->SetItemDimmed(EProfilerGuiCmdStartAll, ETrue); |
|
98 aMenuPane->SetItemDimmed(EProfilerGuiCmdStopAll, EFalse); |
|
99 aMenuPane->SetItemDimmed(EProfilerGuiCmdSamplerControl, ETrue); |
|
100 aMenuPane->SetItemDimmed(EProfilerGuiCmdSettings, ETrue); |
|
101 } |
|
102 else if(iModel->iState == MProfilerStatusObserver::EIdle) |
|
103 { |
|
104 aMenuPane->SetItemDimmed(EProfilerGuiCmdStartAll, EFalse); |
|
105 aMenuPane->SetItemDimmed(EProfilerGuiCmdStopAll, ETrue); |
|
106 aMenuPane->SetItemDimmed(EProfilerGuiCmdSamplerControl, EFalse); |
|
107 aMenuPane->SetItemDimmed(EProfilerGuiCmdSettings, EFalse); |
|
108 } |
|
109 else |
|
110 { |
|
111 // if initializing or stopping no start/stop actions allowed |
|
112 aMenuPane->SetItemDimmed(EProfilerGuiCmdStartAll, ETrue); |
|
113 aMenuPane->SetItemDimmed(EProfilerGuiCmdStopAll, ETrue); |
|
114 aMenuPane->SetItemDimmed(EProfilerGuiCmdSamplerControl, ETrue); |
|
115 aMenuPane->SetItemDimmed(EProfilerGuiCmdSettings, ETrue); |
|
116 } |
|
117 } |
|
118 |
|
119 if(aResourceId == R_PROFILER_SAMPLER_CONTROL_MENU) |
|
120 { |
|
121 // check if item hidden, i.e. sampler cannot be started/stopped |
|
122 if(!iModel->GetSelectedItemHidden()) |
|
123 { |
|
124 // item enabled => dimm the "enable" item, and other way round |
|
125 if(iModel->GetSelectedItemEnabled()) |
|
126 { |
|
127 aMenuPane->SetItemDimmed(EProfilerGuiCmdSamplerEnable, ETrue); |
|
128 aMenuPane->SetItemDimmed(EProfilerGuiCmdSamplerDisable, EFalse); |
|
129 } |
|
130 // item enabled => dimm the "enable" item, and other way round |
|
131 else |
|
132 { |
|
133 aMenuPane->SetItemDimmed(EProfilerGuiCmdSamplerEnable, EFalse); |
|
134 aMenuPane->SetItemDimmed(EProfilerGuiCmdSamplerDisable, ETrue); |
|
135 } |
|
136 |
|
137 } |
|
138 // item hidden => dimm both enable and disable items |
|
139 else |
|
140 { |
|
141 aMenuPane->SetItemDimmed(EProfilerGuiCmdSamplerEnable, ETrue); |
|
142 aMenuPane->SetItemDimmed(EProfilerGuiCmdSamplerDisable, ETrue); |
|
143 } |
|
144 |
|
145 // if sampler item has specific settings to control |
|
146 if(iModel->GetSelectedItemHasSettings()) |
|
147 { |
|
148 aMenuPane->SetItemDimmed(EProfilerGuiCmdSamplerSettings, EFalse); |
|
149 } |
|
150 else |
|
151 { |
|
152 aMenuPane->SetItemDimmed(EProfilerGuiCmdSamplerSettings, ETrue); |
|
153 } |
|
154 } |
|
155 } |
|
156 |
|
157 // -------------------------------------------------------------------------------------------- |
|
158 |
|
159 TKeyResponse CProfilerGuiAppUi::HandleKeyEventL(const TKeyEvent& /*aKeyEvent*/, TEventCode /*aType*/) |
|
160 { |
|
161 return EKeyWasNotConsumed; |
|
162 } |
|
163 |
|
164 void CProfilerGuiAppUi::HandleSystemEventL(const TWsEvent& aEvent) |
|
165 { |
|
166 switch (*(TApaSystemEvent*)(aEvent.EventData())) |
|
167 { |
|
168 case EApaSystemEventShutdown: |
|
169 // check if still profiling |
|
170 if( iModel->iState != MProfilerStatusObserver::EIdle ) |
|
171 { |
|
172 // stop profiling process |
|
173 iModel->StopAllSamplerItemsL(); |
|
174 } |
|
175 |
|
176 // terminate profiler engine |
|
177 iModel->TerminateProfilerL(); |
|
178 break; |
|
179 default: |
|
180 break; |
|
181 } |
|
182 // call base class implementation |
|
183 CAknAppUi::HandleSystemEventL(aEvent); |
|
184 } |
|
185 |
|
186 // -------------------------------------------------------------------------------------------- |
|
187 |
|
188 void CProfilerGuiAppUi::HandleCommandL(TInt aCommand) |
|
189 { |
|
190 switch ( aCommand ) |
|
191 { |
|
192 case EProfilerGuiCmdSettings: |
|
193 { |
|
194 // check if exit command received |
|
195 if (iModel->LaunchSettingsDialogL() == EAknCmdExit) |
|
196 { |
|
197 // terminate profiler engine... |
|
198 iModel->TerminateProfilerL(); |
|
199 |
|
200 // ... and exit |
|
201 Exit(); |
|
202 } |
|
203 break; |
|
204 } |
|
205 case EProfilerGuiCmdAbout: |
|
206 { |
|
207 CAknMessageQueryDialog* dialog = new(ELeave) CAknMessageQueryDialog; |
|
208 dialog->ExecuteLD(R_PROFILER_GUI_ABOUT_DIALOG); |
|
209 } |
|
210 break; |
|
211 |
|
212 // a normal way to close an application |
|
213 case EAknCmdExit: |
|
214 case EEikCmdExit: |
|
215 case EAknSoftkeyExit: |
|
216 { |
|
217 // decrease the client reference count in the server: |
|
218 iModel->RemoveClient(); |
|
219 // check if still profiling |
|
220 if( iModel->iState != MProfilerStatusObserver::EIdle && |
|
221 iModel->iState != MProfilerStatusObserver::EStopping ) |
|
222 { |
|
223 // ask user if he wants to leave profiling running in background process |
|
224 if( this->RunConfQueryL( NULL ) == 0 ) |
|
225 { |
|
226 // stop profiling process |
|
227 iModel->StopAllSamplerItemsL(); |
|
228 |
|
229 // terminate profiler engine |
|
230 iModel->TerminateProfilerL(); |
|
231 } |
|
232 } |
|
233 else |
|
234 { |
|
235 // terminate profiler engine |
|
236 iModel->TerminateProfilerL(); |
|
237 } |
|
238 |
|
239 Exit(); |
|
240 } |
|
241 break; |
|
242 |
|
243 default: |
|
244 break; |
|
245 } |
|
246 } |
|
247 |
|
248 TInt CProfilerGuiAppUi::RunConfQueryL( const TDesC* aOverrideText ) |
|
249 { |
|
250 CAknQueryDialog* queryDialog = CAknQueryDialog::NewL(); |
|
251 |
|
252 if(aOverrideText) |
|
253 { |
|
254 queryDialog->SetPromptL(*aOverrideText); |
|
255 } |
|
256 return queryDialog->ExecuteLD(R_PROFILER_GUI_CONF_QUERY); |
|
257 } |
|
258 |
|
259 |
|
260 // End of File |