|
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 #include "accindicator.h" |
|
18 |
|
19 #include <QtPlugin> |
|
20 #include <QProcess> |
|
21 #include <accpolgenericiddefinitions.h> |
|
22 |
|
23 Q_EXPORT_PLUGIN(AccIndicatorPlugin) |
|
24 const static char IndicatorType[] = "com.nokia.accessory.indicatorplugin/1.0"; |
|
25 QString KAccMode = "AccMode"; |
|
26 QString KAccType = "AccType"; |
|
27 |
|
28 AccIndicatorPlugin::AccIndicatorPlugin() : |
|
29 HbIndicatorInterface(IndicatorType, |
|
30 HbIndicatorInterface::GroupPriorityLow, |
|
31 InteractionActivated) |
|
32 { |
|
33 mIndicatorTypes << "com.nokia.accessory.indicatorplugin/1.0"; |
|
34 } |
|
35 |
|
36 AccIndicatorPlugin::~AccIndicatorPlugin() |
|
37 { |
|
38 } |
|
39 |
|
40 // ---------------------------------------------------------------------------- |
|
41 // AccIndicatorPlugin::indicatorTypes |
|
42 // returns the indicator types handled by this plugin |
|
43 // ---------------------------------------------------------------------------- |
|
44 |
|
45 QStringList AccIndicatorPlugin::indicatorTypes() const |
|
46 { |
|
47 return mIndicatorTypes; |
|
48 } |
|
49 |
|
50 // ---------------------------------------------------------------------------- |
|
51 // AccIndicatorPlugin::createIndicator |
|
52 // creates an indicator. |
|
53 // ---------------------------------------------------------------------------- |
|
54 |
|
55 HbIndicatorInterface* AccIndicatorPlugin::createIndicator( |
|
56 const QString &indicatorType) |
|
57 { |
|
58 Q_UNUSED(indicatorType) |
|
59 return this; |
|
60 } |
|
61 |
|
62 // ---------------------------------------------------------------------------- |
|
63 // AccIndicatorPlugin::error |
|
64 // returns the error code. |
|
65 // ---------------------------------------------------------------------------- |
|
66 |
|
67 int AccIndicatorPlugin::error() const |
|
68 { |
|
69 return mError; |
|
70 } |
|
71 |
|
72 // ---------------------------------------------------------------------------- |
|
73 // AccIndicatorPlugin::accessAllowed |
|
74 // check for the access rights of the client. As there are no restrictions for |
|
75 // this plugin it always returns true. |
|
76 // ---------------------------------------------------------------------------- |
|
77 |
|
78 bool AccIndicatorPlugin::accessAllowed(const QString &indicatorType, |
|
79 const HbSecurityInfo *securityInfo) const |
|
80 { |
|
81 Q_UNUSED(indicatorType) |
|
82 Q_UNUSED(securityInfo) |
|
83 |
|
84 return true; |
|
85 } |
|
86 |
|
87 // ---------------------------------------------------------------------------- |
|
88 // AccIndicator::handleInteraction |
|
89 // called when the user interacts with the indicator.Enable the interaction only |
|
90 // for headset,tty and tv-out for user to change the settings. |
|
91 // ---------------------------------------------------------------------------- |
|
92 bool AccIndicatorPlugin::handleInteraction(InteractionType type) |
|
93 { |
|
94 bool handled = false; |
|
95 if (type == InteractionActivated) |
|
96 { |
|
97 // If it is 3-pole ( i.e., HeadSet or TTY ) and TV-Out enable the handleInteraction() to change the settings. |
|
98 if(mAccMode == EAccModeWiredHeadset || mAccMode == EAccModeWirelessHeadset || mAccMode == EAccModeTextDevice || mAccMode == EAccModeTVOut ) |
|
99 { |
|
100 QObject::connect( &mProcess, SIGNAL(error(QProcess::ProcessError)), |
|
101 this, SLOT(processError(QProcess::ProcessError))); |
|
102 |
|
103 QVariant mode,type; |
|
104 mode.setValue((int)mAccMode); |
|
105 type.setValue((int)mAccType); |
|
106 mArgs.append(mode.toString()); |
|
107 mArgs.append(type.toString()); |
|
108 |
|
109 // Launch the process to show the view. |
|
110 mProcess.start("accindicatorsettings" , mArgs); |
|
111 handled = true; |
|
112 } |
|
113 } |
|
114 return handled; |
|
115 } |
|
116 |
|
117 // ---------------------------------------------------------------------------- |
|
118 // AccIndicator::indicatorData |
|
119 // returns the name and icon to be displayed in the universal indicator menu. |
|
120 // ---------------------------------------------------------------------------- |
|
121 QVariant AccIndicatorPlugin::indicatorData(int role) const |
|
122 { |
|
123 switch(role) |
|
124 { |
|
125 //for displaying the string in indicator. |
|
126 case PrimaryTextRole: |
|
127 { |
|
128 QString type(mDisplayName); |
|
129 return type; |
|
130 } |
|
131 //for displaying the icon in indicator. |
|
132 case DecorationNameRole: |
|
133 { |
|
134 QString iconName; |
|
135 if(mAccType == KPCWired || mAccType == KPCUSB) |
|
136 { |
|
137 iconName = QString("z:/resource/accindicator/wired_accessory.svg"); |
|
138 } |
|
139 else if (mAccType == KPCBluetooth || mAccType == KPCInfraRed) |
|
140 { |
|
141 iconName = QString("z:/resource/accindicator/wireless_accessory.svg"); |
|
142 } |
|
143 return iconName; |
|
144 } |
|
145 default: |
|
146 return QVariant(); |
|
147 } |
|
148 } |
|
149 |
|
150 // ---------------------------------------------------------------------------- |
|
151 // AccIndicatorPlugin::handleClientRequest |
|
152 // this function gets called when client activates plugin |
|
153 // ---------------------------------------------------------------------------- |
|
154 bool AccIndicatorPlugin::handleClientRequest( RequestType type, |
|
155 const QVariant ¶meter) |
|
156 { |
|
157 bool handled(false); |
|
158 switch (type) { |
|
159 case RequestActivate: |
|
160 { |
|
161 // Get the params(acctype and mode) from the hbindicator.activate() which is called from sysap. |
|
162 |
|
163 QVariantMap mapValues = parameter.toMap(); |
|
164 if(mapValues.contains(KAccMode)) |
|
165 { |
|
166 mAccMode = static_cast<TAccMode>(mapValues.value(KAccMode).toInt()); |
|
167 } |
|
168 if(mapValues.contains(KAccType)) |
|
169 { |
|
170 mAccType = mapValues.value(KAccType).toInt(); |
|
171 } |
|
172 |
|
173 // prepare the name to be displayed in the universal indicator menu. |
|
174 prepareDisplayName(); |
|
175 emit dataChanged(); |
|
176 handled = true; |
|
177 } |
|
178 break; |
|
179 case RequestDeactivate: |
|
180 { |
|
181 // reset data |
|
182 mDisplayName = QString(); |
|
183 emit deactivate(); |
|
184 } |
|
185 break; |
|
186 default: |
|
187 break; |
|
188 } |
|
189 return handled; |
|
190 } |
|
191 |
|
192 // ---------------------------------------------------------------------------- |
|
193 // AccIndicator::prepareDisplayName |
|
194 // prepare the name to be displayed in the indicator menu. |
|
195 // ---------------------------------------------------------------------------- |
|
196 void AccIndicatorPlugin::prepareDisplayName() |
|
197 { |
|
198 mDisplayName.clear(); |
|
199 switch(mAccMode) |
|
200 { |
|
201 case EAccModeWiredHeadset: |
|
202 mDisplayName.append(QString("Wired Headset")); |
|
203 break; |
|
204 case EAccModeWirelessHeadset: |
|
205 mDisplayName.append(QString("Wireless Headset")); |
|
206 break; |
|
207 case EAccModeWiredCarKit: |
|
208 mDisplayName.append(QString("Wired CarKit")); |
|
209 break; |
|
210 case EAccModeWirelessCarKit: |
|
211 mDisplayName.append(QString("Wireless Carkit")); |
|
212 break; |
|
213 case EAccModeTextDevice: |
|
214 mDisplayName.append(QString("TTY")); |
|
215 break; |
|
216 case EAccModeLoopset: |
|
217 mDisplayName.append(QString("LoopSet")); |
|
218 break; |
|
219 case EAccModeMusicStand: |
|
220 mDisplayName.append(QString("Music Stand")); |
|
221 break; |
|
222 case EAccModeTVOut: |
|
223 mDisplayName.append(QString("TV Out")); |
|
224 break; |
|
225 case EAccModeHeadphones: |
|
226 mDisplayName.append(QString("Head Phones")); |
|
227 break; |
|
228 default : |
|
229 mDisplayName.append(QString("Unknown")); |
|
230 } |
|
231 } |
|
232 |
|
233 // ---------------------------------------------------------------------------- |
|
234 // AccIndicator::processError |
|
235 // handle the error conditions reurned by the QProcess. |
|
236 // ---------------------------------------------------------------------------- |
|
237 |
|
238 void AccIndicatorPlugin::processError(QProcess::ProcessError err) |
|
239 { |
|
240 switch (err) { |
|
241 case QProcess::FailedToStart: |
|
242 case QProcess::Crashed: |
|
243 case QProcess::Timedout: |
|
244 case QProcess::ReadError: |
|
245 case QProcess::WriteError: |
|
246 case QProcess::UnknownError: |
|
247 break; |
|
248 default: |
|
249 break; |
|
250 } |
|
251 } |