|
1 /* |
|
2 * ============================================================================ |
|
3 * Name : hbindicatorautolockplugin.cpp |
|
4 * Part of : hb / hbcore |
|
5 * Description : indicator autolock plugin implementation |
|
6 * Version : %version: 1 % |
|
7 * |
|
8 * Copyright (c) 2009 Nokia. All rights reserved. |
|
9 * This material, including documentation and any related computer |
|
10 * programs, is protected by copyright controlled by Nokia. All |
|
11 * rights are reserved. Copying, including reproducing, storing, |
|
12 * adapting or translating, any or all of this material requires the |
|
13 * prior written consent of Nokia. This material also contains |
|
14 * confidential information which may not be disclosed to others |
|
15 * without the prior written consent of Nokia. |
|
16 * ============================================================================ |
|
17 */ |
|
18 |
|
19 #include <QtPlugin> |
|
20 #include <QVariant> |
|
21 #include <HbInstance> |
|
22 #include <HbMainWindow> |
|
23 #include <QDebug> |
|
24 |
|
25 #include "hbindicatorautolockplugin.h" |
|
26 |
|
27 Q_EXPORT_PLUGIN(HbIndicatorAutolockPlugin) |
|
28 |
|
29 // Constructor |
|
30 HbIndicatorAutolockPlugin::HbIndicatorAutolockPlugin() : mError(0) |
|
31 { |
|
32 for (int i = 0; i < IndicatorCount; ++i) { |
|
33 mIndicatorTypes.append(indicatorName(i)); |
|
34 } |
|
35 } |
|
36 |
|
37 // Destructor |
|
38 HbIndicatorAutolockPlugin::~HbIndicatorAutolockPlugin() |
|
39 { |
|
40 } |
|
41 |
|
42 // Return notification types this plugin implements |
|
43 QStringList HbIndicatorAutolockPlugin::indicatorTypes() const |
|
44 { |
|
45 return mIndicatorTypes; |
|
46 } |
|
47 |
|
48 // Check if client is allowed to use notification widget |
|
49 bool HbIndicatorAutolockPlugin::accessAllowed(const QString &indicatorType, |
|
50 const QVariantMap &securityInfo) const |
|
51 { |
|
52 Q_UNUSED(indicatorType) |
|
53 Q_UNUSED(securityInfo) |
|
54 |
|
55 // This plugin doesn't perform operations that may compromise security. |
|
56 // All clients are allowed to use. |
|
57 return true; |
|
58 } |
|
59 |
|
60 HbIndicatorInterface* HbIndicatorAutolockPlugin::createIndicator( |
|
61 const QString &indicatorType) |
|
62 { |
|
63 HbIndicatorInterface *indicator = 0; |
|
64 int index(typeIndex(indicatorType)); |
|
65 if (index >= 0) { |
|
66 indicator = new HbAutolockIndicator( |
|
67 indicatorType, index, IndicatorInfos[index].interaction); |
|
68 } |
|
69 return indicator; |
|
70 } |
|
71 |
|
72 int HbIndicatorAutolockPlugin::error() const |
|
73 { |
|
74 return mError; |
|
75 } |
|
76 |
|
77 int HbIndicatorAutolockPlugin::typeIndex(const QString &indicatorType) const |
|
78 { |
|
79 for (int i = 0; i < mIndicatorTypes.count(); ++i) { |
|
80 if (mIndicatorTypes.at(i) == indicatorType) { |
|
81 return i; |
|
82 } |
|
83 } |
|
84 return -1; |
|
85 } |
|
86 |
|
87 HbAutolockIndicator::HbAutolockIndicator(const QString &indicatorType, |
|
88 int typeIndex, |
|
89 Interaction interaction) : |
|
90 HbIndicatorInterface(indicatorType, IndicatorInfos[typeIndex].category, |
|
91 (interaction == InteractionNone) ? NoInteraction : InteractionActivated), |
|
92 mPrimaryText(IndicatorInfos[typeIndex].primaryText), |
|
93 mSecondaryText(IndicatorInfos[typeIndex].secondaryText), |
|
94 mIcon(IndicatorInfos[typeIndex].icon), |
|
95 mIconMono(IndicatorInfos[typeIndex].iconMono), |
|
96 mTypeIndex(typeIndex), mInteraction(interaction) |
|
97 { |
|
98 } |
|
99 |
|
100 HbAutolockIndicator::~HbAutolockIndicator() |
|
101 { |
|
102 } |
|
103 |
|
104 bool HbAutolockIndicator::handleInteraction(InteractionType type) |
|
105 { |
|
106 if (type == InteractionActivated) { |
|
107 switch(mInteraction) { |
|
108 case ChangeContent: |
|
109 mPrimaryText = "Clicked"; |
|
110 mSecondaryText = "content changed!"; |
|
111 mIcon = "qtg_mono_ok.svg"; |
|
112 break; |
|
113 case Deactivate: |
|
114 emit deactivate(); |
|
115 break; |
|
116 case ChangeOrientation: |
|
117 qDebug() << "============= HbAutolockIndicator::handleInteraction doesn't react to ChangeOrientation"; |
|
118 /* |
|
119 if (hbInstance->orientation() == Qt::Horizontal) { |
|
120 hbInstance->setOrientation(Qt::Vertical); |
|
121 } else { |
|
122 hbInstance->setOrientation(Qt::Horizontal); |
|
123 } |
|
124 */ |
|
125 if (hbInstance->allMainWindows().at(0)->orientation() == Qt::Horizontal) { |
|
126 hbInstance->allMainWindows().at(0)->setOrientation(Qt::Vertical); |
|
127 } else { |
|
128 hbInstance->allMainWindows().at(0)->setOrientation(Qt::Horizontal); |
|
129 } |
|
130 break; |
|
131 default: |
|
132 return false; |
|
133 } |
|
134 emit dataChanged(); |
|
135 } |
|
136 return false; |
|
137 } |
|
138 |
|
139 QVariant HbAutolockIndicator::indicatorData(int role) const |
|
140 { |
|
141 if (role == PrimaryTextRole) { |
|
142 if (mParameter.isValid()) { |
|
143 qDebug() << "============= HbAutolockIndicator::indicatorData 11="; |
|
144 qDebug() << QString("data:").append(mParameter.toString()) |
|
145 .append(" ") |
|
146 .append(mPrimaryText); |
|
147 return QString("data:").append(mParameter.toString()) |
|
148 .append(" ") |
|
149 .append(mPrimaryText); |
|
150 } else { |
|
151 qDebug() << "============= HbAutolockIndicator::indicatorData 12="; |
|
152 qDebug() << mPrimaryText ; |
|
153 return mPrimaryText; |
|
154 } |
|
155 } else if (role == SecondaryTextRole && mTypeIndex != 7) { |
|
156 if (mParameter.isValid()) { |
|
157 qDebug() << "============= HbAutolockIndicator::indicatorData 21="; |
|
158 qDebug() << QString("data:").append(mParameter.toString()) |
|
159 .append(" ") |
|
160 .append(mPrimaryText); |
|
161 return QString("data:").append(mParameter.toString()) |
|
162 .append(" ") |
|
163 .append(mSecondaryText); |
|
164 } else { |
|
165 qDebug() << "============= HbAutolockIndicator::indicatorData 22="; |
|
166 qDebug() << mSecondaryText ; |
|
167 return mSecondaryText; |
|
168 } |
|
169 } else if (role == MonoDecorationNameRole) { |
|
170 if (mParameter.isValid()) { |
|
171 qDebug() << "============= HbAutolockIndicator::indicatorData 31="; |
|
172 qDebug() << "qtg_mono_ok.svg" ; |
|
173 return "qtg_mono_ok.svg"; |
|
174 } else { |
|
175 qDebug() << "============= HbAutolockIndicator::indicatorData 32="; |
|
176 qDebug() << mIcon ; |
|
177 return mIcon; |
|
178 } |
|
179 } else if (role == DecorationNameRole) { |
|
180 if (mParameter.isValid()) { |
|
181 qDebug() << "============= HbAutolockIndicator::indicatorData 41="; |
|
182 qDebug() << "qtg_mono_ok.svg" ; |
|
183 return "qtg_mono_ok.svg"; |
|
184 } else { |
|
185 qDebug() << "============= HbAutolockIndicator::indicatorData 42="; |
|
186 qDebug() << mIcon ; |
|
187 return mIcon; |
|
188 } |
|
189 } else if (role == MonoDecorationNameRole) { |
|
190 if (mParameter.isValid()) { |
|
191 qDebug() << "============= HbAutolockIndicator::indicatorData 51="; |
|
192 qDebug() << "qtg_mono_ok.svg" ; |
|
193 return "qtg_mono_ok.svg"; |
|
194 } else { |
|
195 qDebug() << "============= HbAutolockIndicator::indicatorData 52="; |
|
196 qDebug() << mIconMono ; |
|
197 return mIconMono; |
|
198 } |
|
199 } |
|
200 return QVariant(); |
|
201 } |
|
202 |
|
203 bool HbAutolockIndicator::handleClientRequest(RequestType type, const QVariant ¶meter) |
|
204 { |
|
205 bool handled(false); |
|
206 switch (type) { |
|
207 case RequestActivate: |
|
208 if (mParameter != parameter) { |
|
209 mParameter = parameter; |
|
210 emit dataChanged(); |
|
211 } |
|
212 handled = true; |
|
213 break; |
|
214 default: |
|
215 mParameter.clear(); |
|
216 } |
|
217 |
|
218 return handled; |
|
219 } |
|
220 |