|
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 <QTimer> |
|
19 #include <hbaction.h> |
|
20 #include <hbmainwindow.h> |
|
21 #include <hbview.h> |
|
22 #include <hblistwidget.h> |
|
23 #include <hblistwidgetitem.h> |
|
24 #include <hblabel.h> |
|
25 #include <hbmenu.h> |
|
26 |
|
27 #include "satappuiprovider.h" |
|
28 #include "satappeventprovider.h" |
|
29 #include "satappview.h" |
|
30 #include "tflogger.h" |
|
31 #include "satappcommonconstant.h" |
|
32 |
|
33 const char *SATAPP_MENUITEM = "s:ListWidget"; |
|
34 const char *SATAPP_SUBTITLE = "t:label"; |
|
35 const char *SATAPP_SELECTITEM = "t:ListWidget"; |
|
36 |
|
37 |
|
38 // ======== MEMBER FUNCTIONS ================================================== |
|
39 |
|
40 // ---------------------------------------------------------------------------- |
|
41 // SatAppView::SatAppView |
|
42 // (Constructor). |
|
43 // ---------------------------------------------------------------------------- |
|
44 // |
|
45 SatAppView::SatAppView(QGraphicsItem *parent) : |
|
46 HbView(parent), |
|
47 mTimeout(false), |
|
48 mSelectItem(false), |
|
49 mClickBackSoftkey(false), |
|
50 mItemIndex(0), |
|
51 mLoop(0), |
|
52 mTimer(0), |
|
53 mWindow(0), |
|
54 mSoftKeyQuitAction(0), |
|
55 mSoftKeyBackAction(0), |
|
56 mEvent(0), |
|
57 mUi(0), |
|
58 mListWidget(0), |
|
59 mSelectListWidget(0), |
|
60 mSubTitle(0) |
|
61 { |
|
62 TFLOGSTRING("SATAPP: SatAppView::SatAppView call-exit") |
|
63 } |
|
64 |
|
65 // ---------------------------------------------------------------------------- |
|
66 // SatAppView::~SatAppView |
|
67 // (Disconstructor). |
|
68 // ---------------------------------------------------------------------------- |
|
69 // |
|
70 SatAppView::~SatAppView() |
|
71 { |
|
72 TFLOGSTRING("SATAPP: SatAppView::~SatAppView") |
|
73 // The objects are outside the object tree, Delete them manually |
|
74 if (mTimer) { |
|
75 delete mTimer; |
|
76 mTimer = 0; |
|
77 TFLOGSTRING("SATAPP: SatAppView::~SatAppView delete subtitle") |
|
78 } |
|
79 |
|
80 if (mLoop) { |
|
81 if (mLoop->isRunning()) { |
|
82 mLoop->quit(); |
|
83 } |
|
84 delete mLoop; |
|
85 mLoop = 0; |
|
86 TFLOGSTRING("SATAPP: SatAppView::~SatAppView delete subtitle") |
|
87 } |
|
88 TFLOGSTRING("SATAPP: SatAppView::~SatAppView Exit") |
|
89 } |
|
90 |
|
91 // ---------------------------------------------------------------------------- |
|
92 // SatAppView::initSetupMenu |
|
93 // (Init the setup menu view). |
|
94 // ---------------------------------------------------------------------------- |
|
95 // |
|
96 void SatAppView::initSetupMenu( |
|
97 SatAppEventProvider &event, |
|
98 SatAppUiProvider &ui) |
|
99 { |
|
100 TFLOGSTRING( "SATAPP: SatAppView::initSetupMenu call" ) |
|
101 mEvent = &event; |
|
102 mUi = &ui; |
|
103 |
|
104 // Listwidget |
|
105 mListWidget = qobject_cast<HbListWidget *> |
|
106 ( mUi->docmlLoader()->findWidget(SATAPP_MENUITEM )); |
|
107 //mMenu = new HbMenu(); |
|
108 if (mListWidget && mWindow) { |
|
109 mSoftKeyQuitAction = new HbAction(Hb::QuitAction,this); |
|
110 HbMenu *addMenu = menu(); |
|
111 HbAction *menuAction = addMenu->addAction("Exit"); |
|
112 bool ret = connect(menuAction, SIGNAL(triggered()), |
|
113 mSoftKeyQuitAction, SIGNAL(triggered())); |
|
114 TFLOGSTRING2("SATAPP: SatAppView::initSetupMenu: \ |
|
115 menu connected %d", ret) |
|
116 ret = connect(mSoftKeyQuitAction, SIGNAL(triggered()), |
|
117 mWindow, SLOT(close())); |
|
118 TFLOGSTRING2("SATAPP: SatAppView::initSetupMenu: \ |
|
119 quit connected %d", ret) |
|
120 |
|
121 } |
|
122 TFLOGSTRING("SATAPP: SatAppView::initSetupMenu exit") |
|
123 } |
|
124 |
|
125 |
|
126 // ---------------------------------------------------------------------------- |
|
127 // SatAppView::initSelectItem |
|
128 // (Init the select item view). |
|
129 // ---------------------------------------------------------------------------- |
|
130 // |
|
131 void SatAppView::initSelectItem( |
|
132 SatAppEventProvider &event, |
|
133 SatAppUiProvider &ui) |
|
134 { |
|
135 TFLOGSTRING( "SATAPP: SatAppView::initSelectItem call") |
|
136 mEvent = &event; |
|
137 mUi = &ui; |
|
138 // Subtitle |
|
139 mSubTitle = qobject_cast<HbLabel *> |
|
140 ( mUi->docmlLoader()->findWidget(SATAPP_SUBTITLE) ); |
|
141 |
|
142 mSelectListWidget = qobject_cast<HbListWidget *> |
|
143 ( mUi->docmlLoader()->findWidget(SATAPP_SELECTITEM )); |
|
144 |
|
145 if (mSelectListWidget && mWindow) { |
|
146 mSoftKeyBackAction = new HbAction(Hb::BackAction,this); |
|
147 HbMenu *addMenu = menu(); |
|
148 HbAction *menuBack = addMenu->addAction("Back"); |
|
149 bool ret = connect(menuBack, SIGNAL(triggered()), |
|
150 mSoftKeyBackAction, SIGNAL(triggered())); |
|
151 TFLOGSTRING2("SATAPP: SatAppView::initSelectItem: \ |
|
152 menu connected %d", ret) |
|
153 HbAction *menuQuit = addMenu->addAction("Exit"); |
|
154 ret = connect(menuQuit, SIGNAL(triggered()), |
|
155 mWindow, SLOT(close())); |
|
156 TFLOGSTRING2("SATAPP: SatAppView::initSelectItem: \ |
|
157 close connected %d", ret) |
|
158 ret = connect(mSoftKeyBackAction, SIGNAL(triggered()), |
|
159 this, SLOT(backButtonClicked())); |
|
160 TFLOGSTRING2("SATAPP: SatAppView::initSelectItem: \ |
|
161 back connected %d", ret) |
|
162 } |
|
163 TFLOGSTRING("SATAPP: SatAppView::initSelectItem exit") |
|
164 } |
|
165 |
|
166 // ---------------------------------------------------------------------------- |
|
167 // SatAppView::SatAppView |
|
168 // (Set up menu). |
|
169 // ---------------------------------------------------------------------------- |
|
170 // |
|
171 void SatAppView::showSetUpMenuContent( |
|
172 TSatUiResponse& aRes, |
|
173 const QString& aText, |
|
174 const QStringList& aMenuItems, |
|
175 //const CArrayFixFlat<TSatAction>* aMenuItemNextActions, |
|
176 //const HbIcon& aIcon, |
|
177 //const CAknIconArray* aItemIconsArray, |
|
178 const bool /*aSelfExplanatoryItems*/, |
|
179 const bool /*aHelpIsAvailable*/) |
|
180 { |
|
181 TFLOGSTRING("SATAPP: SatAppView::SetUpMenu") |
|
182 // Disconnect select item |
|
183 disconnectItem(); |
|
184 aRes = ESatSuccess; |
|
185 mSelectItem = false; |
|
186 |
|
187 // The text is the application name |
|
188 // should be shown on the menu area always |
|
189 if (!aText.isEmpty()) { |
|
190 TFLOGSTRING( "SATAPP: SatAppView::SetUpMenu: title" ) |
|
191 setTitle(aText); |
|
192 } |
|
193 if (mListWidget) { |
|
194 TFLOGSTRING("SATAPP: SatAppView::SetUpMenu mListWidget") |
|
195 mListWidget->clear(); |
|
196 for(int i = 0; i < aMenuItems.count(); i++ ) { |
|
197 mListWidget->addItem(aMenuItems.at( i )); |
|
198 } |
|
199 // connect setup menu item |
|
200 connectItem(); |
|
201 |
|
202 if (mWindow) { |
|
203 //Set the secondary softkey as quit when receiving the |
|
204 //SetUpMenu command |
|
205 TFLOGSTRING("SATAPP: SatAppView::SetUpMenu, \ |
|
206 initialize secondary softkey as quit key") |
|
207 mWindow->addSoftKeyAction(Hb::SecondarySoftKey, mSoftKeyQuitAction); |
|
208 } |
|
209 } |
|
210 TFLOGSTRING("SATAPP: SatAppView::SetUpMenu exit") |
|
211 } |
|
212 |
|
213 |
|
214 // ---------------------------------------------------------------------------- |
|
215 // SatAppView::SelectItem |
|
216 // (Selected item). |
|
217 // ---------------------------------------------------------------------------- |
|
218 // |
|
219 void SatAppView::showSelectItemContent( |
|
220 TSatUiResponse& aRes, |
|
221 const QString& aText, |
|
222 const QStringList& aMenuItems, |
|
223 //const CArrayFixFlat<TSatAction>* aMenuItemNextActions, |
|
224 const int aDefaultItem, |
|
225 unsigned char& aSelection, |
|
226 //const HbIcon& aIcon, |
|
227 //const CAknIconArray* aItemsIconArray, |
|
228 const bool /*aSelfExplanatoryItems*/, |
|
229 const bool /*aHelpIsAvailable*/) |
|
230 { |
|
231 TFLOGSTRING("SATAPP: SatAppView::selectItem") |
|
232 // Disconnect setup menu item |
|
233 disconnectItem(); |
|
234 aRes = ESatSuccess; |
|
235 mSelectItem = true; |
|
236 mClickBackSoftkey = false; |
|
237 if (mWindow){ |
|
238 mWindow->setCurrentViewIndex(aDefaultItem); |
|
239 } |
|
240 |
|
241 // Set sub title |
|
242 if (!aText.isEmpty()) { |
|
243 TFLOGSTRING2("SATAPP: aText=%s", aText.utf16()) |
|
244 mSubTitle->setPlainText(aText); |
|
245 } else { |
|
246 TFLOGSTRING("SATAPP: txt_sat_selectitem_title") |
|
247 mSubTitle->setPlainText(hbTrId("txt_sat_selectitem_title")); |
|
248 } |
|
249 // Set List widget |
|
250 if (mSelectListWidget) { |
|
251 TFLOGSTRING("SATAPP: SatAppView::selectItem mSelectListWidget") |
|
252 mSelectListWidget->clear(); |
|
253 for(int i = 0; i < aMenuItems.count(); i++ ) { |
|
254 mSelectListWidget->addItem(aMenuItems.at( i )); |
|
255 } |
|
256 } |
|
257 // Set Back key |
|
258 setSoftkeyBack(); |
|
259 // connect selectitem |
|
260 connectItem(); |
|
261 |
|
262 mTimer = new QTimer(); |
|
263 if (mTimer) { |
|
264 bool ret = connect(mTimer, SIGNAL(timeout()), |
|
265 this, SLOT(selectItemTimeOut())); |
|
266 TFLOGSTRING2("SATAPP: SatAppView::selectItem timer %d", ret) |
|
267 mTimer->start( KDefaultSelectionTimeoutMseconds ); |
|
268 mLoop = new QEventLoop(); |
|
269 TFLOGSTRING("SATAPP: SatAppView::selectItem loop exec before") |
|
270 mLoop->exec(QEventLoop::AllEvents); |
|
271 TFLOGSTRING("SATAPP: SatAppView::selectItem loop exec after") |
|
272 delete mTimer; |
|
273 mTimer = 0; |
|
274 delete mLoop; |
|
275 mLoop = 0; |
|
276 } |
|
277 |
|
278 if (mTimeout) { |
|
279 aRes = ESatNoResponseFromUser; |
|
280 TFLOGSTRING("SATAPP: SatAppView::selectItem time out") |
|
281 } else if (mClickBackSoftkey) { |
|
282 TFLOGSTRING("SATAPP: SatAppView::selectItem, \ |
|
283 user click the back softkey") |
|
284 aRes = ESatBackwardModeRequestedByUser; |
|
285 } else { |
|
286 TFLOGSTRING2("SATAPP: SatAppView::selectItem selected %d", |
|
287 mItemIndex) |
|
288 //TODO: fix this below. |
|
289 //For Demo. We will not return user select item to SIM. |
|
290 aSelection = mItemIndex; |
|
291 } |
|
292 // disconnet select item |
|
293 disconnectItem(); |
|
294 TFLOGSTRING2("SATAPP: SatAppView::selectItem aRes:%d", aRes) |
|
295 mTimeout=false; |
|
296 TFLOGSTRING("SATAPP: SatAppView::selectItem exit") |
|
297 } |
|
298 |
|
299 // ---------------------------------------------------------------------------- |
|
300 // SatAppView::selectItemTimeOut |
|
301 // (Time Out of select item). |
|
302 // ---------------------------------------------------------------------------- |
|
303 // |
|
304 void SatAppView::selectItemTimeOut() |
|
305 { |
|
306 TFLOGSTRING("SATAPP: SatAppView::selectItemTimeOut") |
|
307 if (mSelectItem && mLoop && mLoop->isRunning()) { |
|
308 TFLOGSTRING("SATAPP: SatAppView::selectItemTimeOut time out") |
|
309 mTimeout = true; |
|
310 mLoop->exit(); |
|
311 } |
|
312 TFLOGSTRING("SATAPP: SatAppView::selectItemTimeOut exit") |
|
313 } |
|
314 |
|
315 // ---------------------------------------------------------------------------- |
|
316 // SatAppView::keyPressEvent |
|
317 // (keyPressEvent). |
|
318 // ---------------------------------------------------------------------------- |
|
319 // |
|
320 void SatAppView::keyPressEvent(QKeyEvent *event) |
|
321 { |
|
322 TFLOGSTRING("SATAPP: SatAppView::keyPressEvent") |
|
323 // Need updating, End key support is still missing |
|
324 switch (event->key()) |
|
325 { |
|
326 case Qt::Key_Hangup: |
|
327 { |
|
328 TFLOGSTRING("SATAPP: SatAppView::keyPressEvent end key") |
|
329 } |
|
330 break; |
|
331 default: |
|
332 { |
|
333 TFLOGSTRING2("SATAPP: SatAppView::keyPressEvent key %d", |
|
334 event->key()) |
|
335 HbView::keyPressEvent(event); |
|
336 } |
|
337 } |
|
338 TFLOGSTRING("SATAPP: SatAppView::keyPressEvent exit") |
|
339 } |
|
340 |
|
341 // ---------------------------------------------------------------------------- |
|
342 // SatAppView::setSoftkeyBack |
|
343 // (Set back action). |
|
344 // ---------------------------------------------------------------------------- |
|
345 // |
|
346 void SatAppView::setSoftkeyBack() |
|
347 { |
|
348 TFLOGSTRING("SATAPP: SatAppView::setSoftkeyBack") |
|
349 if (mWindow && mSoftKeyBackAction) { |
|
350 mWindow->addSoftKeyAction(Hb::SecondarySoftKey, mSoftKeyBackAction); |
|
351 } |
|
352 TFLOGSTRING("SATAPP: SatAppView::setSoftkeyBack Exit") |
|
353 } |
|
354 |
|
355 // ---------------------------------------------------------------------------- |
|
356 // SatAppView::backButtonClicked |
|
357 // (Back action). |
|
358 // ---------------------------------------------------------------------------- |
|
359 // |
|
360 void SatAppView::backButtonClicked() |
|
361 { |
|
362 TFLOGSTRING("SATAPP: SatAppView::backButtonClicked") |
|
363 if (mSelectItem && mLoop->isRunning() ) { |
|
364 mClickBackSoftkey = true; |
|
365 TFLOGSTRING("SATAPP: SatAppView::backButtonClicked back selected") |
|
366 mLoop->exit(); |
|
367 } |
|
368 TFLOGSTRING("SATAPP: SatAppView::backButtonClicked exit") |
|
369 } |
|
370 |
|
371 // ---------------------------------------------------------------------------- |
|
372 // SatAppView::setMainWindow |
|
373 // (Set window for view). |
|
374 // ---------------------------------------------------------------------------- |
|
375 // |
|
376 void SatAppView::setMainWindow(HbMainWindow &mainWindow) |
|
377 { |
|
378 TFLOGSTRING("SATAPP: SatAppView::setMainWindow") |
|
379 TFLOGSTRING2("SATAPP: SatAppView::setMainWindow \ |
|
380 &mainWindow=0x%x", &mainWindow) |
|
381 mWindow = &mainWindow; |
|
382 TFLOGSTRING("SATAPP: SatAppView::setMainWindow exit") |
|
383 } |
|
384 |
|
385 // ---------------------------------------------------------------------------- |
|
386 // SatAppView::menuItemSelected |
|
387 // (Menu item selected). |
|
388 // ---------------------------------------------------------------------------- |
|
389 // |
|
390 void SatAppView::menuItemSelected(HbListWidgetItem *item) |
|
391 { |
|
392 TFLOGSTRING("SATAPP: SatAppView::menuItemSelected") |
|
393 if(mSelectItem && mSelectListWidget) { |
|
394 mItemIndex = mSelectListWidget->row(item); |
|
395 if (mLoop && mLoop->isRunning()) { |
|
396 TFLOGSTRING( "SATAPP: SatAppView::menuItemSelected sel item") |
|
397 mLoop->quit(); |
|
398 TFLOGSTRING( "SATAPP: SatAppView::menuItemSelected exit loop") |
|
399 } |
|
400 } |
|
401 if (!mSelectItem && mListWidget) { |
|
402 mItemIndex = mListWidget->row(item); |
|
403 TFLOGSTRING( "SATAPP: SatAppView::menuItemSelected setup menu") |
|
404 if (mEvent) { |
|
405 mEvent->menuSelection( mItemIndex, false ); |
|
406 TFLOGSTRING( "SATAPP: SatAppView::menuItemSelected setup menu") |
|
407 } |
|
408 // disconnet the list widget, when server returns response, |
|
409 // the connect again |
|
410 disconnectItem(); |
|
411 } |
|
412 TFLOGSTRING("SATAPP: SatAppView::menuItemSelected exit") |
|
413 } |
|
414 |
|
415 // ---------------------------------------------------------------------------- |
|
416 // SatAppView::connectItem |
|
417 // (Connect listwidget item). |
|
418 // ---------------------------------------------------------------------------- |
|
419 // |
|
420 void SatAppView::connectItem() |
|
421 { |
|
422 TFLOGSTRING("SATAPP: SatAppView::connectItem") |
|
423 if (!mSelectItem && mListWidget) { |
|
424 const bool result = connect( |
|
425 mListWidget, SIGNAL(activated(HbListWidgetItem *)), |
|
426 this, SLOT(menuItemSelected(HbListWidgetItem *))); |
|
427 TFLOGSTRING2( |
|
428 "SATAPP: SatAppView::connectItem exit: setup menu item result=%d", |
|
429 result) |
|
430 } |
|
431 |
|
432 if (mSelectItem && mSelectListWidget) { |
|
433 const bool result = connect( |
|
434 mSelectListWidget, SIGNAL(activated(HbListWidgetItem *)), |
|
435 this, SLOT(menuItemSelected(HbListWidgetItem *))); |
|
436 TFLOGSTRING2( |
|
437 "SATAPP: SatAppView::connectItem exit: select item result=%d", |
|
438 result) |
|
439 } |
|
440 TFLOGSTRING("SATAPP: SatAppView::connectItem exit") |
|
441 } |
|
442 |
|
443 // ---------------------------------------------------------------------------- |
|
444 // SatAppView::disconnectItem |
|
445 // (Disconnect listwidget item). |
|
446 // ---------------------------------------------------------------------------- |
|
447 // |
|
448 void SatAppView::disconnectItem() |
|
449 { |
|
450 TFLOGSTRING("SATAPP: SatAppView::disconnectItem") |
|
451 // setup menu view |
|
452 if (!mSelectItem && mListWidget) { |
|
453 disconnect(mListWidget, SIGNAL( activated(HbListWidgetItem *)), |
|
454 this, SLOT( menuItemSelected( HbListWidgetItem *))); |
|
455 TFLOGSTRING("SATAPP: SatAppView::disconnectItem: setup menu item ") |
|
456 } |
|
457 // select item view |
|
458 if (mSelectItem && mSelectListWidget) { |
|
459 disconnect(mSelectListWidget, SIGNAL( activated(HbListWidgetItem *)), |
|
460 this, SLOT( menuItemSelected( HbListWidgetItem *))); |
|
461 TFLOGSTRING("SATAPP: SatAppView::disconnectItem: select item ") |
|
462 } |
|
463 TFLOGSTRING("SATAPP: SatAppView::disconnectItem exit") |
|
464 } |
|
465 |
|
466 // End of file |