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 <HbToolBar> |
|
19 #include <HbAction> |
|
20 #include <HbDataForm> |
|
21 #include <HbDataFormModel> |
|
22 #include <HbProgressDialog> |
|
23 |
|
24 #include "memspyswmtview.h" |
|
25 #include "enginewrapper.h" |
|
26 |
|
27 const QStringList MODE_ITEMS = QStringList() << |
|
28 MemSpySwmtView::tr("Basic") << |
|
29 MemSpySwmtView::tr("Full") << |
|
30 MemSpySwmtView::tr("Custom"); |
|
31 |
|
32 const QStringList CATEGORIES_ITEMS = QStringList() << |
|
33 MemSpySwmtView::tr("FileServer Cache") << |
|
34 //MemSpySwmtView::tr("Bitmap Handles") << |
|
35 MemSpySwmtView::tr("User Heap") << |
|
36 //MemSpySwmtView::tr("Kernel Heap") << |
|
37 MemSpySwmtView::tr("Local Chunks") << |
|
38 MemSpySwmtView::tr("Global Chunks") << |
|
39 MemSpySwmtView::tr("RAM Drive") << |
|
40 //MemSpySwmtView::tr("User Stacks") << |
|
41 //MemSpySwmtView::tr("Global Data") << |
|
42 MemSpySwmtView::tr("RAM-loaded Code") << |
|
43 MemSpySwmtView::tr("Kernel Handles") << |
|
44 MemSpySwmtView::tr("Open Files") << |
|
45 MemSpySwmtView::tr("Disk Usage") << |
|
46 MemSpySwmtView::tr("System Memory") << |
|
47 MemSpySwmtView::tr("Windows Groups"); |
|
48 |
|
49 MemSpySwmtView::MemSpySwmtView(EngineWrapper &engine, ViewManager &viewManager) : |
|
50 MemSpyView(engine, viewManager), |
|
51 mToggleTimerAction(0), |
|
52 mCategoriesItem(0), |
|
53 mProgressDialog(0) |
|
54 { |
|
55 } |
|
56 |
|
57 MemSpySwmtView::~MemSpySwmtView() |
|
58 { |
|
59 } |
|
60 |
|
61 void MemSpySwmtView::initialize(const QVariantMap& params) |
|
62 { |
|
63 setTitle(tr("SWMT")); |
|
64 |
|
65 MemSpyView::initialize(params); |
|
66 } |
|
67 |
|
68 HbToolBar* MemSpySwmtView::createToolBar() |
|
69 { |
|
70 HbToolBar* toolBar = new HbToolBar(); |
|
71 mToggleTimerAction = toolBar->addAction("", this, SLOT(toggleTimer())); |
|
72 toolBar->addAction(tr("Dump Now"), this, SLOT(forceDump())); |
|
73 |
|
74 updateTimerAction(mEngine.isSwmtRunning()); |
|
75 |
|
76 return toolBar; |
|
77 } |
|
78 |
|
79 HbWidget* MemSpySwmtView::createCentralWidget() |
|
80 { |
|
81 mModel = new HbDataFormModel(this); |
|
82 |
|
83 mTimerItem = mModel->appendDataFormItem( |
|
84 HbDataFormModelItem::TextItem, tr("Timer (sec.)")); |
|
85 mTimerItem->setContentWidgetData("maxLength", 2); |
|
86 mTimerItem->setContentWidgetData("text", mEngine.settings().swmtTimerPeriod()); |
|
87 |
|
88 mModeItem = mModel->appendDataFormItem( |
|
89 HbDataFormModelItem::ComboBoxItem, tr("Tracking mode")); |
|
90 mModeItem->setContentWidgetData("items", MODE_ITEMS); |
|
91 mModeItem->setContentWidgetData("currentIndex", mEngine.settings().swmtMode()); |
|
92 |
|
93 modeChanged(mEngine.settings().swmtMode()); |
|
94 |
|
95 HbDataForm* form = new HbDataForm(this); |
|
96 form->setModel(mModel); |
|
97 |
|
98 form->addConnection(mModeItem, SIGNAL(currentIndexChanged(int)), this, SLOT(modeChanged(int))); |
|
99 |
|
100 return form; |
|
101 } |
|
102 |
|
103 void MemSpySwmtView::updateTimerAction(bool isRunning) |
|
104 { |
|
105 mToggleTimerAction->setText(isRunning ? tr("Stop Timer") : tr("Start Timer")); |
|
106 } |
|
107 |
|
108 void MemSpySwmtView::toggleTimer() |
|
109 { |
|
110 bool wasRunning = mEngine.isSwmtRunning(); |
|
111 if (wasRunning) |
|
112 mEngine.stopSwmt(); |
|
113 else |
|
114 { |
|
115 updateSettings(); |
|
116 mEngine.startSwmt(qBound(5, mTimerItem->contentWidgetData("text").toInt(), 60)); |
|
117 } |
|
118 |
|
119 updateTimerAction(!wasRunning); |
|
120 } |
|
121 |
|
122 void MemSpySwmtView::forceDump() |
|
123 { |
|
124 updateSettings(); |
|
125 mEngine.updateOutputSettings(); |
|
126 |
|
127 MemSpySwmtDumpTracker* tracker = mEngine.createSwmtDumpTracker(); |
|
128 connect(tracker, SIGNAL(finished(int)), this, SLOT(asyncOperationFinished(int))); |
|
129 |
|
130 mProgressDialog = new HbProgressDialog(HbProgressDialog::WaitDialog); |
|
131 mProgressDialog->setText(tr("Please wait...")); |
|
132 mProgressDialog->show(); |
|
133 |
|
134 tracker->start(); |
|
135 } |
|
136 |
|
137 void MemSpySwmtView::updateSettings() |
|
138 { |
|
139 mEngine.settings().setSwmtTimerPeriod(mTimerItem->contentWidgetData("text").toInt()); |
|
140 mEngine.settings().setSwmtMode(static_cast<SwmtMode>( |
|
141 mModeItem->contentWidgetData("currentIndex").toInt())); |
|
142 if (mCategoriesItem) |
|
143 mEngine.settings().setSwmtCategories(mCategoriesItem->contentWidgetData("selectedItems").toList()); |
|
144 |
|
145 mEngine.setSwmtSettings(static_cast<SwmtMode>(mEngine.settings().swmtMode()), |
|
146 mEngine.settings().swmtCategories()); |
|
147 } |
|
148 |
|
149 void MemSpySwmtView::modeChanged(int mode) |
|
150 { |
|
151 if (mode != SwmtModeCustom && mCategoriesItem) |
|
152 removeCategoriesItem(); |
|
153 else if (mode == SwmtModeCustom && !mCategoriesItem) |
|
154 createCategoriesItem(); |
|
155 } |
|
156 |
|
157 void MemSpySwmtView::asyncOperationFinished(int errorCode) |
|
158 { |
|
159 Q_UNUSED(errorCode); |
|
160 |
|
161 mProgressDialog->hide(); |
|
162 delete mProgressDialog; |
|
163 mProgressDialog = 0; |
|
164 |
|
165 delete sender(); |
|
166 } |
|
167 |
|
168 void MemSpySwmtView::createCategoriesItem() |
|
169 { |
|
170 mCategoriesItem = mModel->appendDataFormItem( |
|
171 HbDataFormModelItem::MultiselectionItem, tr("Categories")); |
|
172 mCategoriesItem->setContentWidgetData("items", CATEGORIES_ITEMS); |
|
173 mCategoriesItem->setContentWidgetData("selectedItems", mEngine.settings().swmtCategories()); |
|
174 } |
|
175 |
|
176 void MemSpySwmtView::removeCategoriesItem() |
|
177 { |
|
178 mModel->removeItem(mCategoriesItem); |
|
179 mCategoriesItem = 0; |
|
180 } |
|