42
|
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 "btcpuidevicedetail.h"
|
|
19 |
#include "btcpuideviceview.h"
|
|
20 |
#include "btcpuidevicedetailsview.h"
|
|
21 |
|
|
22 |
#include <btdevsettingpluginloader.h>
|
|
23 |
#include <bluetoothuitrace.h>
|
|
24 |
#include <HbInstance>
|
|
25 |
|
47
|
26 |
|
42
|
27 |
BtCpUiDeviceDetail::BtCpUiDeviceDetail(QObject *parent) :
|
|
28 |
QObject(parent), mDeviceDetailView(0)
|
|
29 |
{
|
|
30 |
mMainWindow = hbInstance->allMainWindows().first();
|
|
31 |
}
|
|
32 |
|
|
33 |
BtCpUiDeviceDetail::~BtCpUiDeviceDetail()
|
|
34 |
{
|
|
35 |
clearDeviceDetailList();
|
|
36 |
delete mDeviceDetailView;
|
|
37 |
}
|
|
38 |
|
|
39 |
void BtCpUiDeviceDetail::loadDeviceDetailPlugins(QString deviceAddress, QString deviceName)
|
|
40 |
{
|
|
41 |
QList<BtDevSettingInterface*> interfaces;
|
|
42 |
BtAbstractDevSetting *devSetting;
|
|
43 |
|
|
44 |
clearDeviceDetailList();
|
|
45 |
interfaces = BtDevSettingPluginLoader::loadDevSettingInterfaces();
|
|
46 |
QList<BtDevSettingInterface*>::const_iterator i;
|
|
47 |
|
|
48 |
for (i = interfaces.constBegin(); i != interfaces.constEnd(); ++i) {
|
|
49 |
devSetting = 0;
|
|
50 |
devSetting = (*i)->createDevSetting( deviceAddress );
|
|
51 |
if(devSetting) {
|
|
52 |
appendDeviceToList(devSetting);
|
|
53 |
}
|
|
54 |
}
|
|
55 |
|
|
56 |
for (int i = interfaces.count() - 1; i >= 0; --i ) {
|
|
57 |
delete interfaces.at(i);
|
|
58 |
}
|
|
59 |
|
47
|
60 |
createDeviceDetailsView(deviceName);
|
42
|
61 |
notifyDeviceDetailStatus();
|
47
|
62 |
|
42
|
63 |
}
|
|
64 |
|
|
65 |
void BtCpUiDeviceDetail::appendDeviceToList(BtAbstractDevSetting *devSetting)
|
|
66 |
{
|
|
67 |
bool ret = false;
|
|
68 |
BtDeviceDetails devicedetails;
|
|
69 |
devicedetails.mSetting = 0;
|
|
70 |
devicedetails.mSettingForm = 0;
|
|
71 |
devicedetails.mSettingAvailable = false;
|
|
72 |
|
|
73 |
devicedetails.mSetting = devSetting;
|
|
74 |
devicedetails.mSettingAvailable = devSetting->isSettingAvailable();
|
|
75 |
devicedetails.mSettingForm = devSetting->getSettingWidget();
|
|
76 |
|
|
77 |
mDeviceDetailList.append(devicedetails);
|
|
78 |
|
|
79 |
ret = connect(devicedetails.mSetting, SIGNAL(settingAvailabilityChanged(BtAbstractDevSetting *, bool)),
|
|
80 |
this, SLOT(handleSettingChange(BtAbstractDevSetting *, bool)));
|
|
81 |
BTUI_ASSERT_X( ret, "BtCpUiDeviceDetail::appendDeviceToList", "connect settingAvailabilityChanged() failed");
|
|
82 |
|
|
83 |
}
|
|
84 |
|
|
85 |
void BtCpUiDeviceDetail::handleSettingChange(BtAbstractDevSetting *setting, bool available)
|
|
86 |
{
|
|
87 |
QList<BtDeviceDetails>::iterator i;
|
47
|
88 |
|
42
|
89 |
for (i = mDeviceDetailList.begin(); i != mDeviceDetailList.end(); ++i) {
|
|
90 |
if((setting == (*i).mSetting) && mDeviceDetailView) {
|
|
91 |
(*i).mSettingAvailable = available;
|
|
92 |
if(available) {
|
|
93 |
if(((*i).mSettingForm)) {
|
|
94 |
//If item already exists, remove it first.
|
|
95 |
mDeviceDetailView->removeItem((*i).mSettingForm);
|
|
96 |
}
|
|
97 |
(*i).mSettingForm = setting->getSettingWidget();
|
|
98 |
//add widget
|
|
99 |
mDeviceDetailView->addItem((*i).mSettingForm);
|
|
100 |
}
|
|
101 |
else {
|
|
102 |
if((*i).mSettingForm) {
|
|
103 |
//remove widget
|
|
104 |
mDeviceDetailView->removeItem((*i).mSettingForm);
|
47
|
105 |
(*i).mSettingForm = 0;
|
|
106 |
checkDeviceDetailSettings();
|
42
|
107 |
}
|
|
108 |
}
|
|
109 |
notifyDeviceDetailStatus();
|
|
110 |
}
|
|
111 |
}
|
|
112 |
}
|
|
113 |
|
|
114 |
|
47
|
115 |
void BtCpUiDeviceDetail::checkDeviceDetailSettings()
|
|
116 |
{
|
|
117 |
QList<BtDeviceDetails>::const_iterator i;
|
|
118 |
bool devicedetail = false;
|
|
119 |
|
|
120 |
for (i = mDeviceDetailList.constBegin(); i != mDeviceDetailList.constEnd(); ++i) {
|
|
121 |
if((*i).mSettingForm) {
|
|
122 |
devicedetail = true;
|
|
123 |
break;
|
|
124 |
}
|
|
125 |
}
|
|
126 |
//If no setting is available and current view is device detail
|
|
127 |
//view move to previous view.
|
|
128 |
if((!devicedetail) && (mMainWindow->currentView() == mDeviceDetailView)) {
|
|
129 |
mMainWindow->removeView(mDeviceDetailView);
|
|
130 |
mMainWindow->setCurrentView( mPreviousView );
|
|
131 |
}
|
|
132 |
}
|
|
133 |
|
42
|
134 |
void BtCpUiDeviceDetail::notifyDeviceDetailStatus()
|
|
135 |
{
|
|
136 |
QList<BtDeviceDetails>::const_iterator i;
|
|
137 |
bool devicedetail = false;
|
|
138 |
|
|
139 |
for (i = mDeviceDetailList.constBegin(); i != mDeviceDetailList.constEnd(); ++i) {
|
|
140 |
if(((*i).mSettingAvailable == true) && ((*i).mSettingForm) ) {
|
|
141 |
devicedetail = true;
|
|
142 |
break;
|
|
143 |
}
|
|
144 |
}
|
|
145 |
emit deviceSettingsChanged(devicedetail);
|
|
146 |
}
|
|
147 |
|
|
148 |
void BtCpUiDeviceDetail::clearDeviceDetailList()
|
|
149 |
{
|
|
150 |
QList<BtDeviceDetails>::const_iterator i;
|
|
151 |
|
|
152 |
for (i = mDeviceDetailList.constBegin(); i != mDeviceDetailList.constEnd(); ++i) {
|
|
153 |
if((*i).mSetting ) {
|
|
154 |
disconnect((*i).mSetting);
|
|
155 |
delete (*i).mSetting;
|
|
156 |
}
|
|
157 |
}
|
|
158 |
mDeviceDetailList.clear();
|
|
159 |
}
|
|
160 |
|
|
161 |
void BtCpUiDeviceDetail::createDeviceDetailsView(QString deviceName)
|
|
162 |
{
|
|
163 |
bool ret = false;
|
|
164 |
//Launch Device Detail View.
|
|
165 |
mDeviceDetailView = new BtCpUiDeviceDetailsView();
|
|
166 |
mDeviceDetailView->setDeviceName(deviceName);
|
|
167 |
|
|
168 |
ret = connect(mDeviceDetailView, SIGNAL(aboutToClose()), this,
|
|
169 |
SLOT(handleDeviceDetailViewClose()));
|
|
170 |
BTUI_ASSERT_X( ret, "BtCpUiDeviceDetail::loadDeviceDetailsView", "connect deviceDetailViewClosed() failed");
|
|
171 |
|
|
172 |
QList<BtDeviceDetails>::const_iterator i;
|
|
173 |
|
|
174 |
for (i = mDeviceDetailList.constBegin(); i != mDeviceDetailList.constEnd(); ++i) {
|
|
175 |
if((*i).mSettingForm) {
|
|
176 |
mDeviceDetailView->addItem((*i).mSettingForm);
|
|
177 |
}
|
|
178 |
}
|
|
179 |
}
|
|
180 |
|
|
181 |
void BtCpUiDeviceDetail::loadDeviceDetailsView()
|
|
182 |
{
|
|
183 |
|
|
184 |
mPreviousView = mMainWindow->currentView();
|
|
185 |
mMainWindow->addView(mDeviceDetailView);
|
|
186 |
|
|
187 |
notifyViewStatusToPlugins(AboutToShow);
|
|
188 |
|
|
189 |
mMainWindow->setCurrentView( mDeviceDetailView );
|
|
190 |
}
|
|
191 |
|
|
192 |
void BtCpUiDeviceDetail::handleDeviceDetailViewClose()
|
|
193 |
{
|
|
194 |
notifyViewStatusToPlugins(AboutToHide);
|
|
195 |
|
|
196 |
mMainWindow->removeView(mDeviceDetailView);
|
|
197 |
|
|
198 |
mMainWindow->setCurrentView( mPreviousView );
|
|
199 |
|
|
200 |
}
|
|
201 |
|
|
202 |
void BtCpUiDeviceDetail::notifyViewStatusToPlugins(BtCpUiDeviceDetail::NotifyType type)
|
|
203 |
{
|
|
204 |
QList<BtDeviceDetails>::const_iterator i;
|
|
205 |
BtAbstractDevSetting *deviceSetting = 0;
|
|
206 |
for (i = mDeviceDetailList.constBegin(); i != mDeviceDetailList.constEnd(); ++i) {
|
|
207 |
deviceSetting = (*i).mSetting;
|
|
208 |
if(deviceSetting) {
|
|
209 |
switch(type) {
|
|
210 |
case AboutToShow:
|
|
211 |
deviceSetting->aboutToForeground();
|
|
212 |
break;
|
|
213 |
case AboutToHide:
|
|
214 |
deviceSetting->aboutToBackground();
|
|
215 |
break;
|
|
216 |
case AboutToClose:
|
|
217 |
deviceSetting->aboutToClose();
|
|
218 |
break;
|
|
219 |
}
|
|
220 |
}
|
|
221 |
}
|
|
222 |
|
|
223 |
}
|
|
224 |
|
47
|
225 |
void BtCpUiDeviceDetail::sendCloseEvent()
|
|
226 |
{
|
|
227 |
notifyViewStatusToPlugins(AboutToClose);
|
|
228 |
}
|
42
|
229 |
|
47
|
230 |
|