1 /* |
|
2 * Copyright (c) 2010 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 "mainview.h" |
|
19 #include "enginewrapper.h" |
|
20 #include "notifications.h" |
|
21 #include "loadgen.hrh" |
|
22 #include <hblabel.h> |
|
23 #include <hbmenu.h> |
|
24 #include <hbaction.h> |
|
25 #include <hbmessagebox.h> |
|
26 #include <hbmainwindow.h> |
|
27 #include <hbapplication.h> |
|
28 //#include <hbcommonnote.h> |
|
29 //#include <hbconfirmationquery.h> |
|
30 #include <hbprogressdialog.h> |
|
31 #include <hbtextedit.h> |
|
32 #include <hblistview.h> |
|
33 #include <hbselectiondialog.h> |
|
34 |
|
35 #include <QGraphicsLinearLayout> |
|
36 #include <QStandardItemModel> |
|
37 #include <QStandardItem> |
|
38 #include <QSignalMapper> |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 |
|
42 MainView::MainView(HbMainWindow &mainWindow) : |
|
43 mMainWindow(mainWindow), |
|
44 mEngineWrapper(0), |
|
45 mIsLoadListEmpty(true), |
|
46 mStopAll(NULL), |
|
47 mSuspendAll(NULL), |
|
48 mResumeAll(NULL) |
|
49 |
|
50 { |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 |
|
55 MainView::~MainView() |
|
56 { |
|
57 if (mEngineWrapper != 0) { |
|
58 delete mEngineWrapper; |
|
59 } |
|
60 delete mListModel; |
|
61 delete mListView; |
|
62 delete mSm; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 |
|
67 void MainView::init(HbApplication &app) |
|
68 { |
|
69 this->setTitle("Load Gener."); |
|
70 mEngineWrapper = new EngineWrapper(mMainWindow, *this); |
|
71 int error = mEngineWrapper->init(); |
|
72 Q_ASSERT_X(error == 1, "LoadGen", "Engine initialization failed"); |
|
73 createMenu(app); |
|
74 loadListIinit(); |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 |
|
79 void MainView::createMenu(HbApplication &app) |
|
80 { |
|
81 HbMenu *menu = this->menu(); |
|
82 |
|
83 // signal mapper for identifying the different command actions |
|
84 // in executeCommand() handler function: |
|
85 mSm = new QSignalMapper(this); |
|
86 connect(mSm, SIGNAL(mapped(int)), this, SLOT(executeMenuCommand(int))); |
|
87 |
|
88 if (menu != NULL) { |
|
89 // Temp work-around for menu item bug in Orbit Wk38, |
|
90 // sub menu cannot contain more than 6 functional action items! |
|
91 // two sub menus created to fix this problem. |
|
92 mLoadSubMenu1 = menu->addMenu("New loads"); |
|
93 mLoadSubMenu2 = menu->addMenu("More new loads"); |
|
94 mCpuLoadAction = mLoadSubMenu1->addAction("CPU load"); |
|
95 connect(mCpuLoadAction, SIGNAL( triggered() ), mSm, SLOT(map())); |
|
96 mSm->setMapping(mCpuLoadAction, ELoadGenCmdNewLoadCPULoad); |
|
97 |
|
98 mMemoryEatLoadAction = mLoadSubMenu1->addAction("Eat memory"); |
|
99 connect(mMemoryEatLoadAction, SIGNAL( triggered() ), mSm, SLOT(map())); |
|
100 mSm->setMapping(mMemoryEatLoadAction, ELoadGenCmdNewLoadEatMemory); |
|
101 |
|
102 mPhoneCallLoadAction = mLoadSubMenu1->addAction("Phone calls"); |
|
103 connect(mPhoneCallLoadAction, SIGNAL( triggered() ), mSm, SLOT(map())); |
|
104 mSm->setMapping(mPhoneCallLoadAction, ELoadGenCmdNewLoadPhoneCall); |
|
105 |
|
106 mMessagesLoadAction = mLoadSubMenu1->addAction("Messages"); |
|
107 connect(mMessagesLoadAction, SIGNAL( triggered() ), mSm, SLOT(map())); |
|
108 mSm->setMapping(mMessagesLoadAction, ELoadGenCmdNewLoadMessages); |
|
109 //TODO to be fixed using replacement for downloadmanager |
|
110 /* |
|
111 mNetConnLoadAction = mLoadSubMenu1->addAction("Network conn."); |
|
112 connect(mNetConnLoadAction, SIGNAL( triggered() ), mSm, SLOT(map())); |
|
113 mSm->setMapping(mNetConnLoadAction, ELoadGenCmdNewLoadNetConn); |
|
114 */ |
|
115 mKeyPressLoadAction = mLoadSubMenu2->addAction("Key presses"); |
|
116 connect(mKeyPressLoadAction, SIGNAL( triggered() ), mSm, SLOT(map())); |
|
117 mSm->setMapping(mKeyPressLoadAction, ELoadGenCmdNewLoadKeyPress); |
|
118 |
|
119 mAppsLoadAction = mLoadSubMenu2->addAction("Applications"); |
|
120 connect(mAppsLoadAction, SIGNAL( triggered() ), mSm, SLOT(map())); |
|
121 mSm->setMapping(mAppsLoadAction, ELoadGenCmdNewLoadApplications); |
|
122 |
|
123 mPhotoCapturesLoadAction = mLoadSubMenu2->addAction("Photo captures"); |
|
124 connect(mPhotoCapturesLoadAction, SIGNAL( triggered() ), mSm, SLOT(map())); |
|
125 mSm->setMapping(mPhotoCapturesLoadAction, ELoadGenCmdNewLoadPhotoCaptures); |
|
126 |
|
127 mBtActionsLoadAction = mLoadSubMenu2->addAction("Bluetooth actions"); |
|
128 connect(mBtActionsLoadAction, SIGNAL( triggered() ), mSm, SLOT(map())); |
|
129 mSm->setMapping(mBtActionsLoadAction, ELoadGenCmdNewLoadBluetooth); |
|
130 |
|
131 mPointerEventsLoadAction = mLoadSubMenu2->addAction("Pointer events"); |
|
132 connect(mPointerEventsLoadAction, SIGNAL( triggered() ), mSm, SLOT(map())); |
|
133 mSm->setMapping(mPointerEventsLoadAction, ELoadGenCmdNewLoadPointerEvent); |
|
134 |
|
135 mActionPerfMon = menu->addAction("Launch PerfMon"); |
|
136 connect(mActionPerfMon, SIGNAL(triggered()), this, SLOT( launchPerfMon())); |
|
137 |
|
138 mActionAbout = menu->addAction("About"); |
|
139 connect(mActionAbout, SIGNAL(triggered()), this, SLOT( showAboutPopup())); |
|
140 |
|
141 mActionExit = menu->addAction("Exit"); |
|
142 connect(mActionExit, SIGNAL(triggered()), &app, SLOT(quit())); |
|
143 |
|
144 // menu dynamic update |
|
145 connect(menu, SIGNAL(aboutToShow()), this, SLOT(updateMenu())); |
|
146 } |
|
147 } |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 |
|
151 void MainView::loadListIinit() |
|
152 { |
|
153 // Create list view and model for it |
|
154 mListView = new HbListView(this); |
|
155 mListModel = new QStandardItemModel(this); |
|
156 mListView->setModel(mListModel); |
|
157 mListView->setSelectionMode(HbListView::NoSelection); |
|
158 mListView->setVisible( false ); //HighlightMode(HbItemHighlight::Hidden); |
|
159 |
|
160 QStandardItem *item = new QStandardItem(QString("No loads activated. (Select new load from menu to generate new load)")); |
|
161 mListModel->setItem(0, item); |
|
162 |
|
163 connect(mListView, |
|
164 SIGNAL(longPressed(HbAbstractViewItem*, QPointF)), |
|
165 this, |
|
166 SLOT(handleLoadListEvent(HbAbstractViewItem*, QPointF))); |
|
167 |
|
168 |
|
169 // Create layout and add list view there: |
|
170 QGraphicsLinearLayout *mainlayout = new QGraphicsLinearLayout(Qt::Vertical, this); |
|
171 mainlayout->addItem(mListView); |
|
172 mainlayout->setAlignment(mListView, Qt::AlignCenter); |
|
173 setLayout(mainlayout); |
|
174 } |
|
175 |
|
176 // --------------------------------------------------------------------------- |
|
177 |
|
178 void MainView::showAboutPopup() |
|
179 { |
|
180 Notifications::about(); |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 |
|
185 void MainView::executeMenuCommand(int cmd) |
|
186 { |
|
187 mEngineWrapper->startNewLoad(cmd); |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 |
|
192 void MainView::handleLoadListEvent(HbAbstractViewItem */*listViewItem*/, const QPointF &/*coords*/) |
|
193 { |
|
194 const QStringList items = (QStringList() << "Stop" << "Resume/Suspend" << "Edit"); |
|
195 HbSelectionDialog *dlg = new HbSelectionDialog(); |
|
196 dlg->setAttribute(Qt::WA_DeleteOnClose); |
|
197 dlg->setStringItems(items); |
|
198 dlg->setSelectionMode(HbAbstractItemView::SingleSelection); |
|
199 dlg->open(this, SLOT(ItemActionPopupClosed(HbAction*))); |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------------------------- |
|
203 |
|
204 void MainView::ItemActionPopupClosed(HbAction* action) |
|
205 { |
|
206 HbSelectionDialog *dlg = static_cast<HbSelectionDialog*>(sender()); |
|
207 if(!action && dlg->selectedItems().count()){ |
|
208 int userSelectionIndex = dlg->selectedItems().at(0).toInt(); |
|
209 // all operations for selected list item only. Query selected load list item index from model. |
|
210 if (userSelectionIndex == 0) { |
|
211 // stop selected load from the load list: |
|
212 stopLoad(false); |
|
213 } |
|
214 else if (userSelectionIndex == 1) { |
|
215 // Suspend or Resume |
|
216 mEngineWrapper->suspendOrResumeSelectedOrHighlightedItems(); |
|
217 } |
|
218 else { |
|
219 // current selected row number from the load list. |
|
220 int selectedRow = mListView->selectionModel()->currentIndex().row(); |
|
221 // edit load setttings: |
|
222 mEngineWrapper->loadEdit(selectedRow); |
|
223 } |
|
224 } |
|
225 } |
|
226 |
|
227 // -------------------------------------------------------------------------- |
|
228 |
|
229 void MainView::stopAllLoads() |
|
230 { |
|
231 stopLoad(true); |
|
232 } |
|
233 |
|
234 // --------------------------------------------------------------------------- |
|
235 |
|
236 bool MainView::stopLoad(bool stopAll) |
|
237 { |
|
238 int success = false; |
|
239 if (mListView != NULL) { |
|
240 if (stopAll == true) { |
|
241 success = mEngineWrapper->stopLoad(stopAll); |
|
242 mIsLoadListEmpty = true; |
|
243 } |
|
244 else { |
|
245 success = mEngineWrapper->stopLoad(stopAll); |
|
246 } |
|
247 } |
|
248 return success; |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------------------------- |
|
252 |
|
253 void MainView::updateMenu() |
|
254 { |
|
255 if (mIsLoadListEmpty != true) { |
|
256 if (mStopAll == NULL) { |
|
257 mStopAll = new HbAction("Stop all", menu()); |
|
258 connect(mStopAll, SIGNAL(triggered()), this, SLOT(stopAllLoads())); |
|
259 menu()->insertAction(mActionAbout, mStopAll); |
|
260 } |
|
261 else{ |
|
262 mStopAll->setVisible(true); |
|
263 } |
|
264 if (mSuspendAll == NULL) { |
|
265 mSuspendAll = new HbAction("Suspend all", menu()); |
|
266 connect(mSuspendAll, SIGNAL(triggered()), this, SLOT(suspendAllLoads())); |
|
267 menu()->insertAction(mActionAbout, mSuspendAll); |
|
268 } |
|
269 else{ |
|
270 mSuspendAll->setVisible(true); |
|
271 } |
|
272 if (mResumeAll == NULL) { |
|
273 mResumeAll = new HbAction("Resume all", menu()); |
|
274 connect(mResumeAll, SIGNAL(triggered()), this, SLOT(resumeAllLoads())); |
|
275 menu()->insertAction(mActionAbout, mResumeAll); |
|
276 } |
|
277 else{ |
|
278 mResumeAll->setVisible(true); |
|
279 } |
|
280 } |
|
281 else if (mIsLoadListEmpty == true) { |
|
282 if (mStopAll != NULL && mStopAll->text() == "Stop all") { |
|
283 mStopAll->setVisible(false); |
|
284 } |
|
285 if (mSuspendAll != NULL && mSuspendAll->text() == "Suspend all") { |
|
286 mSuspendAll->setVisible(false); |
|
287 } |
|
288 if (mResumeAll != NULL && mResumeAll->text() == "Resume all") { |
|
289 mSuspendAll->setVisible(false); |
|
290 } |
|
291 } |
|
292 } |
|
293 |
|
294 |
|
295 // --------------------------------------------------------------------------- |
|
296 |
|
297 int MainView::currentItemIndex() |
|
298 { |
|
299 return mListView->selectionModel()->currentIndex().row(); |
|
300 } |
|
301 |
|
302 // --------------------------------------------------------------------------- |
|
303 |
|
304 void MainView::setCurrentItemIndex(int index) |
|
305 { |
|
306 QModelIndex newIndex = mListView->model()->index(index, 0); |
|
307 mListView->selectionModel()->setCurrentIndex(newIndex, |
|
308 QItemSelectionModel::SelectCurrent); |
|
309 //mListView->setCurrentIndex( index ); //setCurrentRow(index); |
|
310 } |
|
311 |
|
312 // --------------------------------------------------------------------------- |
|
313 |
|
314 void MainView::launchPerfMon() |
|
315 { |
|
316 mEngineWrapper->launchPerfMonApp(); |
|
317 } |
|
318 |
|
319 // --------------------------------------------------------------------------- |
|
320 |
|
321 QList<int> MainView::listSelectionIndexes() |
|
322 { |
|
323 QList<int> indices; |
|
324 if (mListView != NULL) { |
|
325 QItemSelectionModel *selectionModel = mListView->selectionModel(); |
|
326 if (selectionModel->hasSelection()) { |
|
327 QModelIndexList modelIndexes = selectionModel->selectedIndexes(); |
|
328 QModelIndex index; |
|
329 foreach (index, modelIndexes) { |
|
330 indices.append(index.row()); |
|
331 } |
|
332 } |
|
333 } |
|
334 return indices; |
|
335 } |
|
336 |
|
337 // -------------------------------------------------------------------------------------------- |
|
338 |
|
339 void MainView::suspendAllLoads() |
|
340 { |
|
341 mEngineWrapper->suspendAllLoadItems(); |
|
342 } |
|
343 |
|
344 // --------------------------------------------------------------------------- |
|
345 |
|
346 void MainView::resumeAllLoads() |
|
347 { |
|
348 mEngineWrapper->resumeAllLoadItems(); |
|
349 } |
|
350 |
|
351 void MainView::clearListSelection() |
|
352 { |
|
353 if (mListView != NULL) { |
|
354 mListView->clearSelection(); |
|
355 } |
|
356 } |
|
357 |
|
358 // --------------------------------------------------------------------------- |
|
359 |
|
360 void MainView::setLoadListData(QStringList& items) |
|
361 { |
|
362 QString loadItem; |
|
363 QString iconName; |
|
364 |
|
365 if (mListView) { |
|
366 mListView->setSelectionMode(HbListView::MultiSelection); |
|
367 mListView->setVisible(true); //setHighlightMode(HbItemHighlight::AlwaysVisible); |
|
368 if(mListModel->rowCount()) |
|
369 { |
|
370 mListModel->removeRows(0,mListModel->rowCount()); |
|
371 } |
|
372 // mListModel->clear(); |
|
373 } |
|
374 if (items.count() > 0) { |
|
375 mIsLoadListEmpty = false; |
|
376 } |
|
377 else if (items.count() == 0) { |
|
378 mIsLoadListEmpty = true; |
|
379 } |
|
380 for (int i = 0; i < items.count(); i++) { |
|
381 QStandardItem *item = new QStandardItem(); |
|
382 loadItem = items.at(i); |
|
383 if (loadItem.startsWith("1")) { |
|
384 iconName = ":/paused.svg"; |
|
385 } |
|
386 else { |
|
387 iconName = ":/active.svg"; |
|
388 } |
|
389 // remove icon indicator info from string |
|
390 // to show in load in load list |
|
391 loadItem.remove(0,2); |
|
392 item->setText(loadItem); |
|
393 item->setIcon(QIcon(iconName)); |
|
394 // set new load to correct row in load list |
|
395 mListModel->insertRow(i, item); |
|
396 } |
|
397 } |
|
398 |
|
399 // --------------------------------------------------------------------------- |
|