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