|
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 "psmindicator.h" |
|
18 |
|
19 #include <QWidget> |
|
20 #include <QtPlugin> |
|
21 #include <QProcess> |
|
22 #include <cppluginlauncher.h> |
|
23 #include <hbview.h> |
|
24 #include <hbapplication.h> |
|
25 #include <hbmainwindow.h> |
|
26 #include <hbaction.h> |
|
27 #include <cpbasesettingview.h> |
|
28 #include <e32debug.h> |
|
29 |
|
30 |
|
31 Q_EXPORT_PLUGIN(PsmIndicatorPlugin) |
|
32 const static char IndicatorType[] = "com.nokia.hb.powersavemodeplugin/1.0"; |
|
33 QString KPsm = "PSM"; |
|
34 QString KCharging = "Charging"; |
|
35 |
|
36 PsmIndicatorPlugin::PsmIndicatorPlugin():HbIndicatorInterface(IndicatorType,HbIndicatorInterface::NotificationCategory,InteractionActivated) |
|
37 { |
|
38 RDebug::Print( _L("PsmIndicatorPlugin constructor begin ") ); |
|
39 iIndicatorTypes << "com.nokia.hb.powersavemodeplugin/1.0"; |
|
40 RDebug::Print( _L("PsmIndicatorPlugin constructor end ") ); |
|
41 } |
|
42 |
|
43 PsmIndicatorPlugin::~PsmIndicatorPlugin() |
|
44 { |
|
45 RDebug::Print( _L("PsmIndicatorPlugin destructor begin ") ); |
|
46 } |
|
47 |
|
48 // ---------------------------------------------------------------------------- |
|
49 // psmIndicatorPlugin::indicatorTypes |
|
50 // returns the indicator types handled by this plugin |
|
51 // ---------------------------------------------------------------------------- |
|
52 |
|
53 QStringList PsmIndicatorPlugin::indicatorTypes() const |
|
54 { |
|
55 RDebug::Print( _L("PsmIndicatorPlugin indicatortypes ")); |
|
56 return iIndicatorTypes; |
|
57 } |
|
58 |
|
59 // ---------------------------------------------------------------------------- |
|
60 // psmIndicatorPlugin::createIndicator |
|
61 // creates an indicator. |
|
62 // ---------------------------------------------------------------------------- |
|
63 |
|
64 HbIndicatorInterface* PsmIndicatorPlugin::createIndicator( |
|
65 const QString &indicatorType) |
|
66 { |
|
67 Q_UNUSED(indicatorType) |
|
68 RDebug::Print( _L("PsmIndicatorPlugin createindicator ") ); |
|
69 return this; |
|
70 } |
|
71 |
|
72 // ---------------------------------------------------------------------------- |
|
73 // psmIndicatorPlugin::error |
|
74 // returns the error code. |
|
75 // ---------------------------------------------------------------------------- |
|
76 |
|
77 int PsmIndicatorPlugin::error() const |
|
78 { |
|
79 RDebug::Print( _L("PsmIndicatorPlugin error ") ); |
|
80 return mError; |
|
81 } |
|
82 |
|
83 // ---------------------------------------------------------------------------- |
|
84 // psmIndicatorPlugin::accessAllowed |
|
85 // check for the access rights of the client. As there are no restrictions for |
|
86 // this plugin it always returns true. |
|
87 // ---------------------------------------------------------------------------- |
|
88 |
|
89 bool PsmIndicatorPlugin::accessAllowed(const QString &indicatorType, |
|
90 const QVariantMap & securityInfo) const |
|
91 { |
|
92 Q_UNUSED(indicatorType) |
|
93 Q_UNUSED(securityInfo) |
|
94 |
|
95 RDebug::Print( _L("PsmIndicatorPlugin accessallowed ") ); |
|
96 return true; |
|
97 } |
|
98 |
|
99 // ---------------------------------------------------------------------------- |
|
100 // psmIndicator::handleInteraction |
|
101 // called when the user interacts with the indicator.Enable the interaction |
|
102 // for psm enabled and charger connected |
|
103 // ---------------------------------------------------------------------------- |
|
104 bool PsmIndicatorPlugin::handleInteraction(InteractionType type) |
|
105 { |
|
106 bool handled = false; |
|
107 RDebug::Print( _L("PsmIndicatorPlugin handleinteraction begin ")); |
|
108 if (type == InteractionActivated) |
|
109 { |
|
110 RDebug::Print( _L("PsmIndicatorPlugin handleinteraction inside interactionactivated ") ); |
|
111 QObject::connect( &iProcess, SIGNAL(error(QProcess::ProcessError)), |
|
112 this, SLOT(processError(QProcess::ProcessError))); |
|
113 |
|
114 // Launch the process to show the view. |
|
115 iProcess.start("CpPsmPluginLauncher"); |
|
116 handled = true; |
|
117 |
|
118 } |
|
119 RDebug::Print( _L("PsmIndicatorPlugin handleinteraction end ") ); |
|
120 return handled; |
|
121 } |
|
122 |
|
123 // ---------------------------------------------------------------------------- |
|
124 // psmIndicator::indicatorData |
|
125 // returns the name and icon to be displayed in the universal indicator menu. |
|
126 // ---------------------------------------------------------------------------- |
|
127 QVariant PsmIndicatorPlugin::indicatorData(int role) const |
|
128 { |
|
129 RDebug::Print( _L("PsmIndicatorPlugin indicatordata begin ") ); |
|
130 switch(role) |
|
131 { |
|
132 //for displaying the string in indicator. |
|
133 case PrimaryTextRole: |
|
134 { |
|
135 return iDisplayName; |
|
136 } |
|
137 //for displaying the icon in indicator. |
|
138 case DecorationNameRole: |
|
139 { |
|
140 return iIcon; |
|
141 } |
|
142 default: |
|
143 return QVariant(); |
|
144 } |
|
145 } |
|
146 |
|
147 // ---------------------------------------------------------------------------- |
|
148 // psmIndicatorPlugin::handleClientRequest |
|
149 // this function gets called when client activates plugin |
|
150 // ---------------------------------------------------------------------------- |
|
151 bool PsmIndicatorPlugin::handleClientRequest( RequestType type, |
|
152 const QVariant ¶meter) |
|
153 { |
|
154 RDebug::Print( _L("PsmIndicatorPlugin handleclientrequest begin ") ); |
|
155 bool handled(false); |
|
156 switch (type) |
|
157 { |
|
158 case RequestActivate: |
|
159 { |
|
160 RDebug::Print( _L("PsmIndicatorPlugin handleclientrequest requestactivate ") ); |
|
161 // Get the param from the hbindicator.activate() which is called from sysap. |
|
162 HbTranslator trans("powermanagement"); |
|
163 iDisplayName.clear(); |
|
164 //if it's a PSM indicator then prepare the string and icon accordingly |
|
165 if((parameter.operator ==(QString("PSM")))) |
|
166 { |
|
167 RDebug::Print( _L("PsmIndicatorPlugin handleclientrequest requestactivate PSM ")); |
|
168 iDisplayName.append(hbTrId("txt_power_management_dpopinfo_psm_activated_automa")); |
|
169 iIcon.append(QString("qtg_large_psm")); |
|
170 } |
|
171 //else it's a charging indicator then prepare the string and icon accordingly |
|
172 else |
|
173 { |
|
174 RDebug::Print( _L("PsmIndicatorPlugin handleclientrequest requestactivate charging ") ); |
|
175 iDisplayName.append(hbTrId("txt_power_management_dblist_charging")); |
|
176 iIcon.append(QString("qtg_mono_flash_charging")); |
|
177 } |
|
178 |
|
179 |
|
180 emit dataChanged(); |
|
181 handled = true; |
|
182 } |
|
183 break; |
|
184 case RequestDeactivate: |
|
185 { |
|
186 RDebug::Print( _L("PsmIndicatorPlugin handleclientrequest requestdeactivate ") ); |
|
187 // reset data |
|
188 iDisplayName = QString(); |
|
189 iIcon=QString(); |
|
190 |
|
191 emit deactivate(); |
|
192 } |
|
193 break; |
|
194 default: |
|
195 break; |
|
196 } |
|
197 RDebug::Print( _L("PsmIndicatorPlugin handleclientrequest end ") ); |
|
198 return handled; |
|
199 } |
|
200 |
|
201 |
|
202 // ---------------------------------------------------------------------------- |
|
203 // psmIndicator::processError |
|
204 // handle the error conditions returned by the QProcess. |
|
205 // ---------------------------------------------------------------------------- |
|
206 |
|
207 void PsmIndicatorPlugin::processError(QProcess::ProcessError err) |
|
208 { |
|
209 RDebug::Print( _L("PsmIndicatorPlugin processerror begin ")); |
|
210 switch (err) |
|
211 { |
|
212 case QProcess::FailedToStart: |
|
213 case QProcess::Crashed: |
|
214 case QProcess::Timedout: |
|
215 case QProcess::ReadError: |
|
216 case QProcess::WriteError: |
|
217 case QProcess::UnknownError: |
|
218 break; |
|
219 default: |
|
220 break; |
|
221 } |
|
222 } |
|
223 |
|
224 |