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 #include "tspresentation.h" |
|
18 |
|
19 #include <hbinstance.h> |
|
20 #include <hbview.h> |
|
21 #include <hbdialog.h> |
|
22 |
|
23 #include "tstasksgrid.h" |
|
24 #include "tstasksgriditem.h" |
|
25 #include "tstaskpopuphandler.h" |
|
26 |
|
27 // FIXME: workaround for Orbit bug: not moving to foreground after QWidget::activateWindow(); |
|
28 #ifdef Q_OS_SYMBIAN |
|
29 #include <apgtask.h> |
|
30 #include <eikenv.h> |
|
31 #endif |
|
32 |
|
33 /*! |
|
34 \class TsPresentation |
|
35 \ingroup group_tsserviceplugin |
|
36 \brief Class providing UI for presenting TS data. |
|
37 */ |
|
38 TsPresentation::TsPresentation(QObject *parent) : TsPresentationInterface(parent), mDialog(NULL), mGrid(NULL) |
|
39 { |
|
40 HbMainWindow *mainWindow = HbInstance::instance()->allMainWindows().first(); |
|
41 |
|
42 // load layout from XML |
|
43 bool ok(true); |
|
44 mLoader.load(":/xml/resource/layout.docml", &ok); |
|
45 Q_ASSERT(ok); |
|
46 loadOrientationSpecificLayoutData(mainWindow->orientation()); |
|
47 |
|
48 // get all items |
|
49 HbView *view = qobject_cast<HbView*>(mLoader.findWidget("view")); |
|
50 mGrid = qobject_cast<TsTasksGrid*>(mLoader.findWidget("taskgrid")); |
|
51 mDialog = qobject_cast<HbDialog*>(mLoader.findWidget("dialog")); |
|
52 Q_ASSERT(view); |
|
53 Q_ASSERT(mGrid); |
|
54 Q_ASSERT(mDialog); |
|
55 |
|
56 mGrid->setItemPrototype(new TsTasksGridItem()); |
|
57 |
|
58 // forward grid signals |
|
59 connect(mGrid, SIGNAL(activated(QModelIndex)), this, SIGNAL(openApplication(QModelIndex))); |
|
60 connect(mGrid, SIGNAL(activated(QModelIndex)), this, SIGNAL(hideTaskSwitcher())); |
|
61 qRegisterMetaType<QModelIndex>("QModelIndex"); |
|
62 connect(mGrid, SIGNAL(deleteButtonClicked(QModelIndex)), this, SIGNAL(closeApplication(QModelIndex)), Qt::QueuedConnection); |
|
63 |
|
64 // task popup |
|
65 TsTaskPopupHandler *popupHandler = new TsTaskPopupHandler(this); |
|
66 connect(mGrid, SIGNAL(longPressed(HbAbstractViewItem*, QPointF)), popupHandler, SLOT(showTaskPopup(HbAbstractViewItem*, QPointF))); |
|
67 connect(popupHandler, SIGNAL(closeTask(QModelIndex)), this, SIGNAL(closeApplication(QModelIndex)),Qt::QueuedConnection); |
|
68 connect(popupHandler, SIGNAL(closeAllTasks()), this, SIGNAL(closeAllApplications())); |
|
69 |
|
70 // dismiss |
|
71 connect(mDialog, SIGNAL(aboutToHide()), this, SIGNAL(hideTaskSwitcher())); |
|
72 |
|
73 // orientation change handling |
|
74 connect(mainWindow, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(loadOrientationSpecificLayoutData(Qt::Orientation))); |
|
75 |
|
76 mainWindow->addView(view); |
|
77 } |
|
78 |
|
79 void TsPresentation::setModel(QAbstractItemModel *model) |
|
80 { |
|
81 mGrid->setModel(model); |
|
82 } |
|
83 |
|
84 void TsPresentation::hide() |
|
85 { |
|
86 mDialog->hide(); |
|
87 HbInstance::instance()->allMainWindows().first()->hide(); |
|
88 } |
|
89 |
|
90 void TsPresentation::show() |
|
91 { |
|
92 HbMainWindow *window = HbInstance::instance()->allMainWindows().first(); |
|
93 window->show(); |
|
94 window->activateWindow(); |
|
95 |
|
96 #ifdef Q_OS_SYMBIAN |
|
97 // FIXME: workaround for Orbit bug: not moving to foreground after QWidget::activateWindow(); |
|
98 TApaTaskList taskList(CEikonEnv::Static()->WsSession()); |
|
99 TApaTask task = taskList.FindApp(RProcess().Type()[2]); |
|
100 Q_ASSERT_X(task.Exists(), "Bringing task switcher to foreground", "Application couldn't find task with its own UID"); |
|
101 task.BringToForeground(); |
|
102 #endif |
|
103 |
|
104 mDialog->show(); |
|
105 } |
|
106 |
|
107 void TsPresentation::loadOrientationSpecificLayoutData(Qt::Orientation orientation) |
|
108 { |
|
109 bool ok(true); |
|
110 if (orientation == Qt::Horizontal) { |
|
111 mLoader.load(":/xml/resource/layout.docml", "landscape", &ok); |
|
112 } else { |
|
113 mLoader.load(":/xml/resource/layout.docml", "portrait", &ok); |
|
114 } |
|
115 Q_ASSERT(ok); |
|
116 } |
|