|
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 |
|
26 BtCpUiDeviceDetail::BtCpUiDeviceDetail(QObject *parent) : |
|
27 QObject(parent), mDeviceDetailView(0) |
|
28 { |
|
29 mMainWindow = hbInstance->allMainWindows().first(); |
|
30 } |
|
31 |
|
32 BtCpUiDeviceDetail::~BtCpUiDeviceDetail() |
|
33 { |
|
34 notifyViewStatusToPlugins(AboutToClose); |
|
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 |
|
60 notifyDeviceDetailStatus(); |
|
61 createDeviceDetailsView(deviceName); |
|
62 } |
|
63 |
|
64 void BtCpUiDeviceDetail::appendDeviceToList(BtAbstractDevSetting *devSetting) |
|
65 { |
|
66 bool ret = false; |
|
67 BtDeviceDetails devicedetails; |
|
68 devicedetails.mSetting = 0; |
|
69 devicedetails.mSettingForm = 0; |
|
70 devicedetails.mSettingAvailable = false; |
|
71 |
|
72 devicedetails.mSetting = devSetting; |
|
73 devicedetails.mSettingAvailable = devSetting->isSettingAvailable(); |
|
74 devicedetails.mSettingForm = devSetting->getSettingWidget(); |
|
75 |
|
76 mDeviceDetailList.append(devicedetails); |
|
77 |
|
78 ret = connect(devicedetails.mSetting, SIGNAL(settingAvailabilityChanged(BtAbstractDevSetting *, bool)), |
|
79 this, SLOT(handleSettingChange(BtAbstractDevSetting *, bool))); |
|
80 BTUI_ASSERT_X( ret, "BtCpUiDeviceDetail::appendDeviceToList", "connect settingAvailabilityChanged() failed"); |
|
81 |
|
82 } |
|
83 |
|
84 void BtCpUiDeviceDetail::handleSettingChange(BtAbstractDevSetting *setting, bool available) |
|
85 { |
|
86 QList<BtDeviceDetails>::iterator i; |
|
87 for (i = mDeviceDetailList.begin(); i != mDeviceDetailList.end(); ++i) { |
|
88 if((setting == (*i).mSetting) && mDeviceDetailView) { |
|
89 (*i).mSettingAvailable = available; |
|
90 if(available) { |
|
91 if(((*i).mSettingForm)) { |
|
92 //If item already exists, remove it first. |
|
93 mDeviceDetailView->removeItem((*i).mSettingForm); |
|
94 } |
|
95 (*i).mSettingForm = setting->getSettingWidget(); |
|
96 //add widget |
|
97 mDeviceDetailView->addItem((*i).mSettingForm); |
|
98 } |
|
99 else { |
|
100 if((*i).mSettingForm) { |
|
101 //remove widget |
|
102 //todo: In case if no items are there close this view |
|
103 //and disable device settings button. |
|
104 mDeviceDetailView->removeItem((*i).mSettingForm); |
|
105 (*i).mSettingForm = 0; |
|
106 } |
|
107 } |
|
108 notifyDeviceDetailStatus(); |
|
109 } |
|
110 } |
|
111 } |
|
112 |
|
113 |
|
114 void BtCpUiDeviceDetail::notifyDeviceDetailStatus() |
|
115 { |
|
116 QList<BtDeviceDetails>::const_iterator i; |
|
117 bool devicedetail = false; |
|
118 |
|
119 for (i = mDeviceDetailList.constBegin(); i != mDeviceDetailList.constEnd(); ++i) { |
|
120 if(((*i).mSettingAvailable == true) && ((*i).mSettingForm) ) { |
|
121 devicedetail = true; |
|
122 break; |
|
123 } |
|
124 } |
|
125 emit deviceSettingsChanged(devicedetail); |
|
126 } |
|
127 |
|
128 void BtCpUiDeviceDetail::clearDeviceDetailList() |
|
129 { |
|
130 QList<BtDeviceDetails>::const_iterator i; |
|
131 |
|
132 for (i = mDeviceDetailList.constBegin(); i != mDeviceDetailList.constEnd(); ++i) { |
|
133 if((*i).mSetting ) { |
|
134 disconnect((*i).mSetting); |
|
135 delete (*i).mSetting; |
|
136 } |
|
137 } |
|
138 mDeviceDetailList.clear(); |
|
139 } |
|
140 |
|
141 void BtCpUiDeviceDetail::createDeviceDetailsView(QString deviceName) |
|
142 { |
|
143 bool ret = false; |
|
144 //Launch Device Detail View. |
|
145 mDeviceDetailView = new BtCpUiDeviceDetailsView(); |
|
146 mDeviceDetailView->setDeviceName(deviceName); |
|
147 |
|
148 ret = connect(mDeviceDetailView, SIGNAL(aboutToClose()), this, |
|
149 SLOT(handleDeviceDetailViewClose())); |
|
150 BTUI_ASSERT_X( ret, "BtCpUiDeviceDetail::loadDeviceDetailsView", "connect deviceDetailViewClosed() failed"); |
|
151 |
|
152 QList<BtDeviceDetails>::const_iterator i; |
|
153 |
|
154 for (i = mDeviceDetailList.constBegin(); i != mDeviceDetailList.constEnd(); ++i) { |
|
155 if((*i).mSettingForm) { |
|
156 mDeviceDetailView->addItem((*i).mSettingForm); |
|
157 } |
|
158 } |
|
159 |
|
160 } |
|
161 |
|
162 void BtCpUiDeviceDetail::loadDeviceDetailsView() |
|
163 { |
|
164 |
|
165 mPreviousView = mMainWindow->currentView(); |
|
166 mMainWindow->addView(mDeviceDetailView); |
|
167 |
|
168 notifyViewStatusToPlugins(AboutToShow); |
|
169 |
|
170 mMainWindow->setCurrentView( mDeviceDetailView ); |
|
171 } |
|
172 |
|
173 void BtCpUiDeviceDetail::handleDeviceDetailViewClose() |
|
174 { |
|
175 notifyViewStatusToPlugins(AboutToHide); |
|
176 |
|
177 mMainWindow->removeView(mDeviceDetailView); |
|
178 |
|
179 mMainWindow->setCurrentView( mPreviousView ); |
|
180 |
|
181 } |
|
182 |
|
183 void BtCpUiDeviceDetail::notifyViewStatusToPlugins(BtCpUiDeviceDetail::NotifyType type) |
|
184 { |
|
185 QList<BtDeviceDetails>::const_iterator i; |
|
186 BtAbstractDevSetting *deviceSetting = 0; |
|
187 for (i = mDeviceDetailList.constBegin(); i != mDeviceDetailList.constEnd(); ++i) { |
|
188 deviceSetting = (*i).mSetting; |
|
189 if(deviceSetting) { |
|
190 switch(type) { |
|
191 case AboutToShow: |
|
192 deviceSetting->aboutToForeground(); |
|
193 break; |
|
194 case AboutToHide: |
|
195 deviceSetting->aboutToBackground(); |
|
196 break; |
|
197 case AboutToClose: |
|
198 deviceSetting->aboutToClose(); |
|
199 break; |
|
200 } |
|
201 } |
|
202 } |
|
203 |
|
204 } |
|
205 |
|
206 |