|
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 "tsdevicedialogcontainer.h" |
|
18 |
|
19 #include <QAbstractListModel> |
|
20 |
|
21 #include <HbDialog> |
|
22 #include <HbMainWindow> |
|
23 |
|
24 #include <tspropertydefs.h> |
|
25 |
|
26 #include "tstasksgrid.h" |
|
27 #include "tstasksgriditem.h" |
|
28 |
|
29 namespace { |
|
30 const char KDocmlPath[] = ":/resource/layout.docml"; |
|
31 } |
|
32 |
|
33 TsDeviceDialogContainer::TsDeviceDialogContainer(QAbstractListModel *model, QObject *parent) : QObject(parent), mVisibilityPublisher(TsProperty::KTsPath) |
|
34 { |
|
35 bool ok(true); |
|
36 mLoader.load(KDocmlPath, &ok); |
|
37 Q_ASSERT(ok); |
|
38 |
|
39 HbDialog *dialog = qobject_cast<HbDialog*>(mLoader.findWidget("tsdevicedialog")); |
|
40 TsTasksGrid *grid = qobject_cast<TsTasksGrid *>(mLoader.findWidget("taskgrid")); |
|
41 Q_ASSERT(dialog); |
|
42 Q_ASSERT(grid); |
|
43 |
|
44 changeOrientation(dialog->mainWindow()->orientation()); |
|
45 |
|
46 grid->setModel(model); |
|
47 |
|
48 // needed because of Qt::QueuedConnection used below |
|
49 // @todo: check if we actually need queued connections |
|
50 qRegisterMetaType<QModelIndex>("QModelIndex"); |
|
51 |
|
52 // connect the grid and model |
|
53 disconnect(grid, SIGNAL(activated(QModelIndex)), model, SLOT(openApplication(QModelIndex))); |
|
54 disconnect(grid, SIGNAL(activated(QModelIndex)), dialog, SLOT(close())); |
|
55 disconnect(grid, SIGNAL(deleteButtonClicked(QModelIndex)), model, SLOT(closeApplication(QModelIndex))); |
|
56 |
|
57 connect(grid, SIGNAL(activated(QModelIndex)), model, SLOT(openApplication(QModelIndex))); |
|
58 connect(grid, SIGNAL(activated(QModelIndex)), dialog, SLOT(close())); |
|
59 connect(grid, SIGNAL(deleteButtonClicked(QModelIndex)), model, SLOT(closeApplication(QModelIndex)), Qt::QueuedConnection); |
|
60 |
|
61 connect(dialog->mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(changeOrientation(Qt::Orientation))); |
|
62 connect(dialog, SIGNAL(aboutToClose()), this, SIGNAL(deviceDialogClosed())); |
|
63 |
|
64 connect(this, SIGNAL(deviceDialogClosed()), this, SLOT(notifyDialogClosed())); |
|
65 mVisibilityPublisher.setValue(TsProperty::KVisibilityPath, true); |
|
66 mVisibilityPublisher.sync(); |
|
67 } |
|
68 |
|
69 TsDeviceDialogContainer::~TsDeviceDialogContainer() |
|
70 { |
|
71 delete deviceDialogWidget(); |
|
72 } |
|
73 |
|
74 bool TsDeviceDialogContainer::setDeviceDialogParameters(const QVariantMap ¶meters) |
|
75 { |
|
76 Q_UNUSED(parameters); |
|
77 return false; |
|
78 } |
|
79 |
|
80 int TsDeviceDialogContainer::deviceDialogError() const |
|
81 { |
|
82 return 0; |
|
83 } |
|
84 |
|
85 void TsDeviceDialogContainer::closeDeviceDialog(bool byClient) |
|
86 { |
|
87 Q_UNUSED(byClient) |
|
88 // @todo: should there be hide calls? deviceDialogWidget->hide(); |
|
89 emit deviceDialogClosed(); |
|
90 } |
|
91 |
|
92 HbPopup *TsDeviceDialogContainer::deviceDialogWidget() const |
|
93 { |
|
94 HbDialog *widget = qobject_cast<HbDialog*>(mLoader.findWidget("tsdevicedialog")); |
|
95 Q_ASSERT(widget); |
|
96 return widget; |
|
97 } |
|
98 |
|
99 QObject *TsDeviceDialogContainer::signalSender() const |
|
100 { |
|
101 return const_cast<TsDeviceDialogContainer*>(this); |
|
102 } |
|
103 |
|
104 void TsDeviceDialogContainer::changeOrientation(Qt::Orientation orientation) |
|
105 { |
|
106 bool ok(true); |
|
107 if (orientation == Qt::Horizontal) { |
|
108 mLoader.load(KDocmlPath, "landscape", &ok); |
|
109 } else { |
|
110 mLoader.load(KDocmlPath, "portrait", &ok); |
|
111 } |
|
112 Q_ASSERT(ok); |
|
113 } |
|
114 |
|
115 void TsDeviceDialogContainer::notifyDialogClosed() |
|
116 { |
|
117 mVisibilityPublisher.setValue(TsProperty::KVisibilityPath, false); |
|
118 mVisibilityPublisher.sync(); |
|
119 } |