|
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 |
|
18 #include <QTranslator> |
|
19 #include <QLocale> |
|
20 #include <QtCore/qplugin.h> |
|
21 #include <QtCore/QString> |
|
22 #include <QtCore/QVariant> |
|
23 #include <QtCore/QMetaType> |
|
24 |
|
25 #include <HbLabel> |
|
26 #include <hbglobal.h> |
|
27 #include <hbapplication.h> |
|
28 #include <hbindicatorplugininterface.h> |
|
29 #include <hbindicatorinterface.h> |
|
30 #include "wlanindicatorplugin.h" |
|
31 #include "OstTraceDefinitions.h" |
|
32 #ifdef OST_TRACE_COMPILER_IN_USE |
|
33 #include "wlanindicatorpluginTraces.h" |
|
34 #endif |
|
35 |
|
36 Q_EXPORT_PLUGIN(WlanIndicatorPlugin) |
|
37 |
|
38 const static char IndicatorType[] = "com.nokia.hb.indicator.connectivity.wlanindicatorplugin/1.0"; |
|
39 |
|
40 |
|
41 /*! |
|
42 WlanIndicatorPlugin constructor. |
|
43 */ |
|
44 WlanIndicatorPlugin::WlanIndicatorPlugin() : |
|
45 HbIndicatorInterface(IndicatorType, GroupPriorityAverage, InteractionActivated), |
|
46 mError(0) |
|
47 { |
|
48 OstTraceFunctionEntry1(WLANINDICATORPLUGIN_WLANINDICATORPLUGIN_ENTRY, this); |
|
49 mIndicatorTypes << "com.nokia.hb.indicator.connectivity.wlanindicatorplugin/1.0"; |
|
50 OstTraceFunctionExit1(WLANINDICATORPLUGIN_WLANINDICATORPLUGIN_ENTRY_EXIT, this); |
|
51 } |
|
52 |
|
53 /*! |
|
54 WlanIndicatorPlugin destructor. |
|
55 */ |
|
56 WlanIndicatorPlugin::~WlanIndicatorPlugin() |
|
57 { |
|
58 OstTraceFunctionEntry1(DUP1_WLANINDICATORPLUGIN_WLANINDICATORPLUGIN_ENTRY, this); |
|
59 OstTraceFunctionExit1(DUP1_WLANINDICATORPLUGIN_WLANINDICATORPLUGIN_EXIT, this); |
|
60 } |
|
61 |
|
62 /*! |
|
63 The indicatorTypes returns type of indicator. In this case it is wlanindicatorplugin. |
|
64 */ |
|
65 QStringList WlanIndicatorPlugin::indicatorTypes() const |
|
66 { |
|
67 OstTraceFunctionEntry1(WLANINDICATORPLUGIN_INDICATORTYPES_ENTRY, this); |
|
68 OstTraceFunctionExit1(WLANINDICATORPLUGIN_INDICATORTYPES_EXIT, this); |
|
69 |
|
70 return mIndicatorTypes; |
|
71 } |
|
72 |
|
73 /*! |
|
74 The handleClientRequest handles client request to change indicators parameters. |
|
75 */ |
|
76 bool WlanIndicatorPlugin::accessAllowed(const QString &indicatorType, |
|
77 const HbSecurityInfo *securityInfo) const |
|
78 { |
|
79 OstTraceFunctionEntry1(WLANINDICATORPLUGIN_ACCESSALLOWED_ENTRY, this); |
|
80 |
|
81 Q_UNUSED(indicatorType) |
|
82 Q_UNUSED(securityInfo) |
|
83 |
|
84 OstTraceFunctionExit1(WLANINDICATORPLUGIN_ACCESSALLOWED_EXIT, this); |
|
85 |
|
86 return true; |
|
87 } |
|
88 |
|
89 /*! |
|
90 The createIndicator creates indicator plugin instance. |
|
91 */ |
|
92 HbIndicatorInterface* WlanIndicatorPlugin::createIndicator( |
|
93 const QString &indicatorType) |
|
94 { |
|
95 OstTraceFunctionEntry1(WLANINDICATORPLUGIN_CREATEINDICATOR_ENTRY, this); |
|
96 Q_UNUSED(indicatorType) |
|
97 |
|
98 // Install localization |
|
99 QTranslator *translator = new QTranslator(this); |
|
100 QString lang = QLocale::system().name(); |
|
101 QString path = "Z:/resource/qt/translations/"; |
|
102 translator->load("wlanindicatorplugin_" + lang, path); |
|
103 qApp->installTranslator(translator); |
|
104 |
|
105 OstTraceFunctionExit1(WLANINDICATORPLUGIN_CREATEINDICATOR_EXIT, this); |
|
106 return this; |
|
107 } |
|
108 |
|
109 /*! |
|
110 The error returns indicator error to HbIndicatorPluginInterface. |
|
111 */ |
|
112 int WlanIndicatorPlugin::error() const |
|
113 { |
|
114 OstTraceFunctionEntry1(WLANINDICATORPLUGIN_ERROR_ENTRY, this); |
|
115 OstTrace1( WLANINDICATORPLUGIN_ERR,ERROR,"WlanIndicatorPlugin error %u", mError); |
|
116 OstTraceFunctionExit1(WLANINDICATORPLUGIN_ERROR_EXIT, this); |
|
117 return mError; |
|
118 } |
|
119 |
|
120 /*! |
|
121 The handleInteraction is used launch WLAN list view. |
|
122 */ |
|
123 bool WlanIndicatorPlugin::handleInteraction(InteractionType type) |
|
124 { |
|
125 OstTraceFunctionEntry1(WLANINDICATORPLUGIN_HANDLEINTERACTION_ENTRY, this); |
|
126 |
|
127 bool handled = false; |
|
128 switch (type) { |
|
129 case InteractionActivated: |
|
130 //connect error() to slot processError() to get error, |
|
131 QObject::connect( &process, SIGNAL(error(QProcess::ProcessError)), |
|
132 this, SLOT(processError(QProcess::ProcessError))); |
|
133 |
|
134 // Show WLAN list view |
|
135 process.start("WlanSniffer"); |
|
136 handled = true; |
|
137 break; |
|
138 default: |
|
139 break; |
|
140 } |
|
141 |
|
142 OstTraceFunctionExit1(WLANINDICATORPLUGIN_HANDLEINTERACTION_EXIT, this); |
|
143 |
|
144 return handled; |
|
145 } |
|
146 |
|
147 /*! |
|
148 The handleClientRequest handles client request to change indicators paramters. |
|
149 */ |
|
150 bool WlanIndicatorPlugin::handleClientRequest(RequestType type, const QVariant ¶meter) |
|
151 { |
|
152 OstTraceFunctionEntry1(WLANINDICATORPLUGIN_CLIENTREQUEST_ENTRY, this); |
|
153 |
|
154 Q_UNUSED(parameter) |
|
155 bool handled(false); |
|
156 switch (type) { |
|
157 case RequestActivate: |
|
158 if (mParameter != parameter) { |
|
159 mParameter = parameter; |
|
160 emit dataChanged(); |
|
161 } |
|
162 handled = true; |
|
163 break; |
|
164 default: |
|
165 mParameter.clear(); |
|
166 } |
|
167 |
|
168 OstTraceFunctionExit1(WLANINDICATORPLUGIN_CLIENTREQUEST_EXIT, this); |
|
169 return handled; |
|
170 } |
|
171 |
|
172 /*! |
|
173 The indicatorData takes care of showing indicator's data. |
|
174 */ |
|
175 QVariant WlanIndicatorPlugin::indicatorData(int role) const |
|
176 { |
|
177 OstTraceFunctionEntry1(WLANINDICATORPLUGIN_INDICATORDATA_ENTRY, this); |
|
178 |
|
179 QVariant qvariant(""); |
|
180 QList<QVariant> indicatorText; |
|
181 bool validParameters = false; |
|
182 |
|
183 switch (role) { |
|
184 case PrimaryTextRole: |
|
185 qvariant = QString(hbTrId("txt_occ_dblist_indi_menu_wireless_lan")); |
|
186 break; |
|
187 case SecondaryTextRole: |
|
188 if (mParameter.isValid() && mParameter.type() == QVariant::List) { |
|
189 |
|
190 indicatorText = mParameter.toList(); |
|
191 validParameters = true; |
|
192 } |
|
193 if (validParameters && (indicatorText.size() > 0)) { |
|
194 |
|
195 if (indicatorText[0] == wlanNotConnected){ |
|
196 qvariant = QString(hbTrId("txt_occ_dblist_wireless_lan_val_not_connected")); |
|
197 } |
|
198 |
|
199 else if (indicatorText[0] == wlanConnected){ |
|
200 QString iapName = indicatorText[1].toString(); |
|
201 QString str = QString(hbTrId("txt_occ_dblist_wireless_lan_val_1_connected")); |
|
202 qvariant = str.arg(iapName); |
|
203 } |
|
204 } |
|
205 else |
|
206 { |
|
207 OstTrace0( WLANINDICATORPLUGIN_ERR,INVALID_PARAMS,"Invalid indicator parameters"); |
|
208 } |
|
209 break; |
|
210 case IconNameRole: |
|
211 if (mParameter.isValid()) { |
|
212 OstTraceFunctionExit1(DUP1_WLANINDICATORPLUGIN_INDICATORDATA_EXIT, this); |
|
213 qvariant = HbIcon("qtg_small_wlan"); |
|
214 break; |
|
215 } |
|
216 case DecorationNameRole: |
|
217 OstTraceFunctionExit1(DUP2_WLANINDICATORPLUGIN_INDICATORDATA_EXIT, this); |
|
218 qvariant = HbIcon("qtg_small_wlan"); |
|
219 break; |
|
220 default: |
|
221 OstTraceFunctionExit1(DUP3_WLANINDICATORPLUGIN_INDICATORDATA_EXIT, this); |
|
222 break; |
|
223 } |
|
224 return qvariant; |
|
225 } |
|
226 |
|
227 /*! |
|
228 The processError is a handler for error codes. |
|
229 */ |
|
230 void WlanIndicatorPlugin::processError(QProcess::ProcessError err) |
|
231 { |
|
232 OstTraceFunctionEntry1(WLANINDICATORPLUGIN_PROCESSERROR_ENTRY, this); |
|
233 |
|
234 switch (err) { |
|
235 case QProcess::FailedToStart: |
|
236 case QProcess::Crashed: |
|
237 case QProcess::Timedout: |
|
238 case QProcess::ReadError: |
|
239 case QProcess::WriteError: |
|
240 case QProcess::UnknownError: |
|
241 OstTrace1( WLANINDICATORPLUGIN_ERR,PROCESSERROR_KNOWN,"Process Error %u", err); |
|
242 break; |
|
243 default: |
|
244 OstTrace1( WLANINDICATORPLUGIN_ERR,PROCESSERROR_UNKNOWN,"Unknown Process Error %u", err); |
|
245 break; |
|
246 } |
|
247 OstTraceFunctionExit1(WLANINDICATORPLUGIN_PROCESSERROR_EXIT, this); |
|
248 } |