|
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 "tsdevicedialogcontainer.h" |
|
19 |
|
20 #include <QAbstractListModel> |
|
21 |
|
22 #include <HbDialog> |
|
23 #include <HbMainWindow> |
|
24 #include <HbLabel> |
|
25 |
|
26 #include <tspropertydefs.h> |
|
27 |
|
28 #include "tstasksgrid.h" |
|
29 #include "tstasksgriditem.h" |
|
30 |
|
31 namespace { |
|
32 const char KDocmlPath[] = ":/resource/layout.docml"; |
|
33 } |
|
34 |
|
35 TsDeviceDialogContainer::TsDeviceDialogContainer(QAbstractListModel *model, |
|
36 QObject *parent) |
|
37 : |
|
38 QObject(parent), |
|
39 mVisibilityPublisher(TsProperty::KTsPath), |
|
40 mDismissRequestSubscriber(QString("%1/%2").arg(TsProperty::KTsPath).arg(TsProperty::KDismissRequestPath)) |
|
41 { |
|
42 bool ok(true); |
|
43 mLoader.load(KDocmlPath, &ok); |
|
44 Q_ASSERT(ok); |
|
45 |
|
46 HbDialog *dialog = |
|
47 qobject_cast<HbDialog*>(mLoader.findWidget("tsdevicedialog")); |
|
48 TsTasksGrid *grid = |
|
49 qobject_cast<TsTasksGrid *>(mLoader.findWidget("taskgrid")); |
|
50 Q_ASSERT(dialog); |
|
51 Q_ASSERT(grid); |
|
52 |
|
53 grid->setModel(model); |
|
54 |
|
55 changeOrientation(dialog->mainWindow()->orientation()); |
|
56 switchViewOnModelChange(); |
|
57 |
|
58 // needed because of Qt::QueuedConnection used below |
|
59 // @todo: check if we actually need queued connections |
|
60 qRegisterMetaType<QModelIndex>("QModelIndex"); |
|
61 |
|
62 // connect the grid and model |
|
63 connect(grid, |
|
64 SIGNAL(activated(QModelIndex)), |
|
65 model, |
|
66 SLOT(openApplication(QModelIndex))); |
|
67 connect(grid, |
|
68 SIGNAL(activated(QModelIndex)), |
|
69 dialog, |
|
70 SLOT(close())); |
|
71 connect(grid, |
|
72 SIGNAL(deleteButtonClicked(QModelIndex)), |
|
73 model, SLOT(closeApplication(QModelIndex)), |
|
74 Qt::QueuedConnection); |
|
75 |
|
76 connect(dialog->mainWindow(), |
|
77 SIGNAL(orientationChanged(Qt::Orientation)), |
|
78 this, |
|
79 SLOT(changeOrientation(Qt::Orientation))); |
|
80 connect(dialog, |
|
81 SIGNAL(aboutToClose()), |
|
82 this, |
|
83 SIGNAL(deviceDialogClosed())); |
|
84 |
|
85 // note: connect to more signals when partial model updates are implemented |
|
86 connect(model, |
|
87 SIGNAL(modelReset()), |
|
88 this, |
|
89 SLOT(switchViewOnModelChange())); |
|
90 |
|
91 connect(this, |
|
92 SIGNAL(deviceDialogClosed()), |
|
93 this, |
|
94 SLOT(notifyDialogClosed())); |
|
95 mVisibilityPublisher.setValue(TsProperty::KVisibilityPath, |
|
96 static_cast<int>(true)); |
|
97 mVisibilityPublisher.sync(); |
|
98 |
|
99 connect(&mDismissRequestSubscriber, |
|
100 SIGNAL(contentsChanged()), |
|
101 this, |
|
102 SLOT(handleDismissRequest())); |
|
103 } |
|
104 |
|
105 TsDeviceDialogContainer::~TsDeviceDialogContainer() |
|
106 { |
|
107 delete deviceDialogWidget(); |
|
108 } |
|
109 |
|
110 bool TsDeviceDialogContainer::setDeviceDialogParameters( |
|
111 const QVariantMap ¶meters) |
|
112 { |
|
113 Q_UNUSED(parameters); |
|
114 return false; |
|
115 } |
|
116 |
|
117 int TsDeviceDialogContainer::deviceDialogError() const |
|
118 { |
|
119 return 0; |
|
120 } |
|
121 |
|
122 void TsDeviceDialogContainer::closeDeviceDialog(bool byClient) |
|
123 { |
|
124 Q_UNUSED(byClient) |
|
125 // @todo: should there be hide calls? deviceDialogWidget->hide(); |
|
126 emit deviceDialogClosed(); |
|
127 } |
|
128 |
|
129 HbPopup *TsDeviceDialogContainer::deviceDialogWidget() const |
|
130 { |
|
131 HbDialog *widget = |
|
132 qobject_cast<HbDialog*>(mLoader.findWidget("tsdevicedialog")); |
|
133 Q_ASSERT(widget); |
|
134 return widget; |
|
135 } |
|
136 |
|
137 QObject *TsDeviceDialogContainer::signalSender() const |
|
138 { |
|
139 return const_cast<TsDeviceDialogContainer*>(this); |
|
140 } |
|
141 |
|
142 void TsDeviceDialogContainer::changeOrientation(Qt::Orientation orientation) |
|
143 { |
|
144 bool ok(true); |
|
145 if (orientation == Qt::Horizontal) { |
|
146 mLoader.load(KDocmlPath, "landscape", &ok); |
|
147 } else { |
|
148 mLoader.load(KDocmlPath, "portrait", &ok); |
|
149 } |
|
150 Q_ASSERT(ok); |
|
151 } |
|
152 |
|
153 void TsDeviceDialogContainer::notifyDialogClosed() |
|
154 { |
|
155 mVisibilityPublisher.setValue(TsProperty::KVisibilityPath, |
|
156 static_cast<int>(false)); |
|
157 mVisibilityPublisher.sync(); |
|
158 } |
|
159 |
|
160 void TsDeviceDialogContainer::switchViewOnModelChange() |
|
161 { |
|
162 TsTasksGrid *grid = |
|
163 qobject_cast<TsTasksGrid *>(mLoader.findWidget("taskgrid")); |
|
164 HbWidget *noItemsWidget = |
|
165 qobject_cast<HbWidget *>(mLoader.findWidget("noitemswidget")); |
|
166 Q_ASSERT(grid); |
|
167 Q_ASSERT(noItemsWidget); |
|
168 |
|
169 if (grid->model()->rowCount()) { |
|
170 noItemsWidget->hide(); |
|
171 grid->show(); |
|
172 } else { |
|
173 noItemsWidget->show(); |
|
174 grid->hide(); |
|
175 } |
|
176 } |
|
177 |
|
178 void TsDeviceDialogContainer::handleDismissRequest() |
|
179 { |
|
180 if (mDismissRequestSubscriber.value().toBool()) { |
|
181 emit deviceDialogClosed(); |
|
182 } |
|
183 } |