35 #include "hbstatusbar_p_p.h" |
35 #include "hbstatusbar_p_p.h" |
36 #include "hbstyleoptionstatusbar_p.h" |
36 #include "hbstyleoptionstatusbar_p.h" |
37 #include "hbsignalindicator_p.h" |
37 #include "hbsignalindicator_p.h" |
38 #include "hbbatteryindicator_p.h" |
38 #include "hbbatteryindicator_p.h" |
39 #include "hbindicatorgroup_p.h" |
39 #include "hbindicatorgroup_p.h" |
|
40 #include "hbdevicedialogserverstatus_p.h" |
40 |
41 |
41 #if defined(Q_OS_SYMBIAN) |
42 #if defined(Q_OS_SYMBIAN) |
42 #include "hbindicatorsym_p.h" |
43 #include "hbindicatorsym_p.h" |
43 #include <bacntf.h> // CEnvironmentChangeNotifier |
44 #include <bacntf.h> // CEnvironmentChangeNotifier |
44 #include <coemain.h> // EActivePriorityLogonA |
45 #include <coemain.h> // EActivePriorityLogonA |
45 #else |
46 #else |
46 #include "hbindicatorwin32_p.h" |
47 #include "hbindicatorwin32_p.h" |
47 #endif // defined(Q_OS_SYMBIAN) |
48 #endif // defined(Q_OS_SYMBIAN) |
48 |
49 |
49 const int clockUpdateDelay = 10000; // 10 s |
|
50 |
|
51 /* |
50 /* |
52 \class HbStatusBar |
51 \class HbStatusBar |
53 \brief HbStatusBar is the class implementing statusbar decorator. |
52 \brief HbStatusBar is the class implementing statusbar decorator. |
54 Statusbar is a container for two indicator groups (left and right), |
53 Statusbar is a container for two indicator groups (left and right), |
55 a clock which is located in the middle of indicator groups and for |
54 a clock which is located in the middle of indicator groups and for |
56 a battery and signal status indicators. |
55 a battery and signal status indicators. |
57 */ |
56 */ |
58 |
57 |
59 HbStatusBarPrivate::HbStatusBarPrivate() : |
58 HbStatusBarPrivate::HbStatusBarPrivate() : |
|
59 mClockTimerId(0), |
60 mTimeTextItem(0), |
60 mTimeTextItem(0), |
61 mSignalIndicator(0), |
61 mSignalIndicator(0), |
62 mBatteryIndicator(0), |
62 mBatteryIndicator(0), |
63 mNotificationIndicatorGroup(0), |
63 mNotificationIndicatorGroup(0), |
64 mSettingsIndicatorGroup(0), |
64 mSettingsIndicatorGroup(0), |
65 mMainWindow(0), |
65 mMainWindow(0), |
66 mPreviousProperties(0), |
66 mPreviousProperties(0), |
67 mIndicatorPrivate(0) |
67 mIndicatorPrivate(0), |
|
68 mServerStatus(0) |
68 { |
69 { |
69 #if defined(Q_OS_SYMBIAN) |
70 #if defined(Q_OS_SYMBIAN) |
70 // Register for system environment changes |
71 // Register for system environment changes |
71 TCallBack envCallback(EnvChangeCallback, this); |
72 TCallBack envCallback(EnvChangeCallback, this); |
72 |
73 |
73 mEnvChangeNotifier = |
74 mEnvChangeNotifier = |
74 CEnvironmentChangeNotifier::NewL(EActivePriorityLogonA, envCallback); |
75 CEnvironmentChangeNotifier::NewL(EActivePriorityLogonA, envCallback); |
75 |
76 |
76 mEnvChangeNotifier->Start(); |
77 mEnvChangeNotifier->Start(); |
77 #endif |
78 #endif |
|
79 mServerStatus = new HbDeviceDialogServerStatus(false); |
78 } |
80 } |
79 |
81 |
80 HbStatusBarPrivate::~HbStatusBarPrivate() |
82 HbStatusBarPrivate::~HbStatusBarPrivate() |
81 { |
83 { |
82 mIndicatorPrivate->stopListen(); |
84 mIndicatorPrivate->stopListen(); |
123 q, SIGNAL(activated(const QList<IndicatorClientInfo> &))); |
126 q, SIGNAL(activated(const QList<IndicatorClientInfo> &))); |
124 q->connect(mIndicatorPrivate, SIGNAL(allActivated(const QList<IndicatorClientInfo> &)), |
127 q->connect(mIndicatorPrivate, SIGNAL(allActivated(const QList<IndicatorClientInfo> &)), |
125 q, SIGNAL(allActivated(const QList<IndicatorClientInfo> &))); |
128 q, SIGNAL(allActivated(const QList<IndicatorClientInfo> &))); |
126 q->connect(mIndicatorPrivate, SIGNAL(deactivated(const QList<IndicatorClientInfo> &)), |
129 q->connect(mIndicatorPrivate, SIGNAL(deactivated(const QList<IndicatorClientInfo> &)), |
127 q, SIGNAL(deactivated(const QList<IndicatorClientInfo> &))); |
130 q, SIGNAL(deactivated(const QList<IndicatorClientInfo> &))); |
|
131 q->connect(mIndicatorPrivate, SIGNAL(updated(const QList<IndicatorClientInfo> &)), |
|
132 q, SIGNAL(updated(const QList<IndicatorClientInfo> &))); |
128 |
133 |
129 q->connect(mIndicatorPrivate, SIGNAL(activated(const QList<IndicatorClientInfo> &)), |
134 q->connect(mIndicatorPrivate, SIGNAL(activated(const QList<IndicatorClientInfo> &)), |
130 q, SLOT(_q_indicatorsChanged())); |
135 q, SLOT(_q_indicatorsChanged())); |
131 q->connect(mIndicatorPrivate, SIGNAL(allActivated(const QList<IndicatorClientInfo> &)), |
136 q->connect(mIndicatorPrivate, SIGNAL(allActivated(const QList<IndicatorClientInfo> &)), |
132 q, SLOT(_q_indicatorsChanged())); |
137 q, SLOT(_q_indicatorsChanged())); |
133 q->connect(mIndicatorPrivate, SIGNAL(updated(const QList<IndicatorClientInfo> &)), |
138 q->connect(mIndicatorPrivate, SIGNAL(updated(const QList<IndicatorClientInfo> &)), |
134 q, SLOT(_q_indicatorsChanged())); |
139 q, SLOT(_q_indicatorsChanged())); |
135 q->connect(mIndicatorPrivate, SIGNAL(deactivated(const QList<IndicatorClientInfo> &)), |
140 q->connect(mIndicatorPrivate, SIGNAL(deactivated(const QList<IndicatorClientInfo> &)), |
136 q, SLOT(_q_indicatorsChanged())); |
141 q, SLOT(_q_indicatorsChanged())); |
137 |
142 |
138 mClockTimerId = q->startTimer(clockUpdateDelay); |
143 q->connect(mMainWindow, SIGNAL(currentViewChanged(HbView*)), q, SLOT(currentViewChanged(HbView*))); |
|
144 |
|
145 q->connect(mMainWindow, SIGNAL(revealed()), q, SLOT(startClockTimer())); |
|
146 |
139 mIndicatorPrivate->startListen(); |
147 mIndicatorPrivate->startListen(); |
140 |
148 |
141 q->grabGesture(Qt::TapGesture); |
149 q->grabGesture(Qt::TapGesture); |
142 q->grabGesture(Qt::TapAndHoldGesture); |
150 q->grabGesture(Qt::TapAndHoldGesture); |
143 q->grabGesture(Qt::PanGesture); |
151 q->grabGesture(Qt::PanGesture); |
150 Q_Q(HbStatusBar); |
158 Q_Q(HbStatusBar); |
151 |
159 |
152 HbStyle::setItemName(q, "statusbar"); |
160 HbStyle::setItemName(q, "statusbar"); |
153 |
161 |
154 mSignalIndicator = new HbSignalIndicator(q); |
162 mSignalIndicator = new HbSignalIndicator(q); |
155 q->style()->setItemName(mSignalIndicator, "signal"); |
163 HbStyle::setItemName(mSignalIndicator, "signal"); |
156 mBatteryIndicator = new HbBatteryIndicator(q); |
164 mBatteryIndicator = new HbBatteryIndicator(q); |
157 q->style()->setItemName(mBatteryIndicator, "battery"); |
165 HbStyle::setItemName(mBatteryIndicator, "battery"); |
158 |
166 |
159 mNotificationIndicatorGroup = new HbIndicatorGroup(HbIndicatorGroup::NotificationType, q); |
167 mNotificationIndicatorGroup = new HbIndicatorGroup(HbIndicatorGroup::NotificationType, q); |
160 q->style()->setItemName(mNotificationIndicatorGroup, "notificationindicators"); |
168 HbStyle::setItemName(mNotificationIndicatorGroup, "notificationindicators"); |
161 |
169 |
162 mSettingsIndicatorGroup = new HbIndicatorGroup(HbIndicatorGroup::SettingsType, q); |
170 mSettingsIndicatorGroup = new HbIndicatorGroup(HbIndicatorGroup::SettingsType, q); |
163 q->style()->setItemName(mSettingsIndicatorGroup, "settingsindicators"); |
171 HbStyle::setItemName(mSettingsIndicatorGroup, "settingsindicators"); |
164 |
172 |
165 mIndicatorPrivate = new HbIndicatorPrivate; |
173 mIndicatorPrivate = new HbIndicatorPrivate; |
166 mIndicatorPrivate->init(); |
174 mIndicatorPrivate->init(); |
167 |
175 |
168 QObject::connect(mSignalIndicator, SIGNAL(levelChanged()), q, SLOT(_q_signalLevelChanged())); |
176 QObject::connect(mSignalIndicator, SIGNAL(levelChanged()), q, SLOT(_q_signalLevelChanged())); |
189 { |
197 { |
190 Q_Q(HbStatusBar); |
198 Q_Q(HbStatusBar); |
191 emit q->contentChanged(HbStatusBar::IndicatorsChanged); |
199 emit q->contentChanged(HbStatusBar::IndicatorsChanged); |
192 } |
200 } |
193 |
201 |
|
202 QString HbStatusBarPrivate::timeFormat() |
|
203 { |
|
204 QString timeFormat; |
|
205 HbExtendedLocale extendedLocale = HbExtendedLocale(); |
|
206 |
|
207 // time separator |
|
208 timeFormat.append("hh"); |
|
209 // Index0 HH Index1 MM Index2 SS Index3 |
|
210 int indexOfHourMinuteSeparator(1); |
|
211 timeFormat.append(extendedLocale.timeSeparator(indexOfHourMinuteSeparator)); |
|
212 timeFormat.append("mm"); |
|
213 |
|
214 if (extendedLocale.timeStyle() == HbExtendedLocale::Time24){ |
|
215 // 24-hour format |
|
216 return timeFormat; |
|
217 } |
|
218 |
|
219 // 12-hour time format |
|
220 QString amPm = "ap"; |
|
221 QString space = " "; |
|
222 if (extendedLocale.amPmSpace()){ |
|
223 // case: space between time & amPm text |
|
224 if (extendedLocale.amPmSymbolPosition() == HbExtendedLocale::After){ |
|
225 amPm.prepend(space); |
|
226 timeFormat.append(amPm); |
|
227 }else if (extendedLocale.amPmSymbolPosition() == HbExtendedLocale::Before){ |
|
228 amPm.append(space); |
|
229 timeFormat.prepend(amPm); |
|
230 } |
|
231 } else { |
|
232 // case: no space between time & amPm text |
|
233 if (extendedLocale.amPmSymbolPosition() == HbExtendedLocale::After){ |
|
234 timeFormat.append(amPm); |
|
235 }else if (extendedLocale.amPmSymbolPosition() == HbExtendedLocale::Before){ |
|
236 timeFormat.prepend(amPm); |
|
237 } |
|
238 } |
|
239 return timeFormat; |
|
240 } |
|
241 |
|
242 |
194 void HbStatusBarPrivate::updateTime() |
243 void HbStatusBarPrivate::updateTime() |
195 { |
244 { |
196 Q_Q(HbStatusBar); |
245 Q_Q(HbStatusBar); |
197 |
|
198 QString timeFormat; |
|
199 // set the time format accordingly |
|
200 if (HbExtendedLocale().timeStyle() == HbExtendedLocale::Time12) { |
|
201 timeFormat.clear(); |
|
202 timeFormat.insert(0, "hh:mm ap"); |
|
203 } else { |
|
204 timeFormat.clear(); |
|
205 timeFormat.insert(0, "hh:mm"); |
|
206 } |
|
207 |
246 |
208 QTime current = QTime::currentTime(); |
247 QTime current = QTime::currentTime(); |
209 |
248 |
210 // set time, using a proper formatting |
249 // set time, using a proper formatting |
211 QString oldTimeText = mTimeText; |
250 QString oldTimeText = mTimeText; |
212 mTimeText = current.toString(timeFormat); |
251 mTimeText = current.toString(timeFormat()); |
213 |
|
214 q->updatePrimitives(); |
|
215 |
252 |
216 if (mTimeText != oldTimeText) { |
253 if (mTimeText != oldTimeText) { |
|
254 q->updatePrimitives(); |
217 emit q->contentChanged(HbStatusBar::TimeChanged); |
255 emit q->contentChanged(HbStatusBar::TimeChanged); |
|
256 } |
|
257 } |
|
258 |
|
259 void HbStatusBarPrivate::startClockTimer() |
|
260 { |
|
261 Q_Q(HbStatusBar); |
|
262 updateTime(); |
|
263 if (mClockTimerId == 0) { |
|
264 int delay = (60 - QTime::currentTime().second()) * 1000; |
|
265 mClockTimerId = q->startTimer(delay); |
|
266 } |
|
267 } |
|
268 |
|
269 void HbStatusBarPrivate::killClockTimer() |
|
270 { |
|
271 Q_Q(HbStatusBar); |
|
272 if (mClockTimerId != 0) { |
|
273 q->killTimer(mClockTimerId); |
|
274 mClockTimerId = 0; |
218 } |
275 } |
219 } |
276 } |
220 |
277 |
221 #if defined(Q_OS_SYMBIAN) |
278 #if defined(Q_OS_SYMBIAN) |
222 TInt HbStatusBarPrivate::EnvChangeCallback(TAny *aObject) |
279 TInt HbStatusBarPrivate::EnvChangeCallback(TAny *aObject) |
275 |
333 |
276 void HbStatusBar::propertiesChanged() |
334 void HbStatusBar::propertiesChanged() |
277 { |
335 { |
278 Q_D(HbStatusBar); |
336 Q_D(HbStatusBar); |
279 if (d->mMainWindow && d->mMainWindow->currentView()) { |
337 if (d->mMainWindow && d->mMainWindow->currentView()) { |
280 currentViewChanged(d->mMainWindow->currentView()); |
338 // only do repolish if properties have changed |
|
339 HbView *view = d->mMainWindow->currentView(); |
|
340 if (d->mPreviousProperties != view->viewFlags()) { |
|
341 d->mPreviousProperties = view->viewFlags(); |
|
342 repolish(); |
|
343 updatePrimitives(); |
|
344 } |
281 } |
345 } |
282 } |
346 } |
283 |
347 |
284 void HbStatusBar::createPrimitives() |
348 void HbStatusBar::createPrimitives() |
285 { |
349 { |
286 Q_D(HbStatusBar); |
350 Q_D(HbStatusBar); |
287 |
351 |
288 d->mTimeTextItem = style()->createPrimitive(HbStyle::P_StatusBar_timetext, this); |
352 d->mTimeTextItem = HbStylePrivate::createPrimitive(HbStylePrivate::P_StatusBar_timetext, this); |
289 d->setBackgroundItem(HbStyle::P_StatusBar_background); |
353 d->setBackgroundItem(HbStylePrivate::P_StatusBar_background); |
290 |
354 |
291 d->updateTime(); |
355 d->updateTime(); |
292 } |
356 } |
293 |
357 |
294 void HbStatusBar::updatePrimitives() |
358 void HbStatusBar::updatePrimitives() |
295 { |
359 { |
296 Q_D(HbStatusBar); |
360 Q_D(HbStatusBar); |
297 HbStyleOptionStatusBar option; |
361 HbStyleOptionStatusBar option; |
298 |
362 |
299 initStyleOption(&option); |
363 initStyleOption(&option); |
300 style()->updatePrimitive(backgroundItem(), HbStyle::P_StatusBar_background, &option); |
364 HbStylePrivate::updatePrimitive(backgroundItem(), HbStylePrivate::P_StatusBar_background, &option); |
301 style()->updatePrimitive(d->mTimeTextItem, HbStyle::P_StatusBar_timetext, &option); |
365 HbStylePrivate::updatePrimitive(d->mTimeTextItem, HbStylePrivate::P_StatusBar_timetext, &option); |
302 } |
366 } |
303 |
367 |
304 /* |
368 /* |
305 This slot is called when active HbView changes. |
369 This slot is called when active HbView changes. |
306 */ |
370 */ |
313 } |
377 } |
314 |
378 |
315 d->mNotificationIndicatorGroup->currentViewChanged(view); |
379 d->mNotificationIndicatorGroup->currentViewChanged(view); |
316 d->mSettingsIndicatorGroup->currentViewChanged(view); |
380 d->mSettingsIndicatorGroup->currentViewChanged(view); |
317 |
381 |
318 // only do repolish if properties have changed |
382 propertiesChanged(); |
319 if (d->mPreviousProperties != view->viewFlags()) { |
|
320 d->mPreviousProperties = view->viewFlags(); |
|
321 repolish(); |
|
322 updatePrimitives(); |
|
323 } |
|
324 } |
383 } |
325 |
384 |
326 void HbStatusBar::initStyleOption(HbStyleOptionStatusBar *option) const |
385 void HbStatusBar::initStyleOption(HbStyleOptionStatusBar *option) const |
327 { |
386 { |
328 const Q_D(HbStatusBar); |
387 const Q_D(HbStatusBar); |
329 HbWidget::initStyleOption(option); |
388 HbWidget::initStyleOption(option); |
330 |
389 |
331 option->timeText = d->mTimeText; |
390 option->timeText = d->mTimeText; |
332 |
391 |
333 if (mainWindow() && mainWindow()->currentView()) { |
392 if (mainWindow() && mainWindow()->currentView()) { |
334 if (mainWindow()->currentView()->viewFlags() & HbView::ViewStatusBarTransparent) { |
393 if (mainWindow()->currentView()->viewFlags() & HbView::ViewStatusBarTransparent) { |
340 void HbStatusBar::timerEvent(QTimerEvent *event) |
399 void HbStatusBar::timerEvent(QTimerEvent *event) |
341 { |
400 { |
342 Q_D(HbStatusBar); |
401 Q_D(HbStatusBar); |
343 if (event->timerId() == d->mClockTimerId) { |
402 if (event->timerId() == d->mClockTimerId) { |
344 d->updateTime(); // get current time |
403 d->updateTime(); // get current time |
|
404 d->killClockTimer(); |
|
405 d->startClockTimer(); |
345 } |
406 } |
346 } |
407 } |
347 |
408 |
348 /*! |
409 /*! |
349 \reimp |
410 \reimp |
350 */ |
411 */ |
351 QGraphicsItem *HbStatusBar::primitive(const QString &itemName) const |
412 QGraphicsItem *HbStatusBar::primitive(const QString &itemName) const |
352 { |
413 { |
353 const Q_D(HbStatusBar); |
414 const Q_D(HbStatusBar); |
354 if (itemName == "") { |
415 if (itemName.isEmpty()) { |
355 return 0; |
416 return 0; |
356 } else { |
417 } else { |
357 if (itemName == "background") { |
418 if (itemName == "background") { |
358 return this->backgroundItem(); |
419 return this->backgroundItem(); |
359 } |
420 } |
390 \reimp |
451 \reimp |
391 */ |
452 */ |
392 bool HbStatusBar::event(QEvent *e) |
453 bool HbStatusBar::event(QEvent *e) |
393 { |
454 { |
394 Q_D(HbStatusBar); |
455 Q_D(HbStatusBar); |
395 if (e->type() == HbEvent::SleepModeEnter) { |
456 if (e->type() == HbEvent::SleepModeEnter || e->type() == QEvent::Hide) { |
396 if (d->mClockTimerId != 0) { |
457 d->killClockTimer(); |
397 killTimer(d->mClockTimerId); |
458 } else if (e->type() == HbEvent::SleepModeExit || e->type() == QEvent::Show) { |
398 d->mClockTimerId = 0; |
459 d->startClockTimer(); |
399 } |
|
400 } else if (e->type() == HbEvent::SleepModeExit) { |
|
401 d->updateTime(); |
|
402 d->mClockTimerId = startTimer(clockUpdateDelay); |
|
403 } |
460 } |
404 return HbWidget::event(e); |
461 return HbWidget::event(e); |
405 } |
462 } |
406 |
463 |
|
464 bool HbStatusBar::eventFilter(QObject *obj, QEvent *event) |
|
465 { |
|
466 Q_D(HbStatusBar); |
|
467 if (event->type() == QEvent::ApplicationActivate) { |
|
468 d->startClockTimer(); |
|
469 d->mBatteryIndicator->chargingEvent(true); |
|
470 } else if (event->type() == QEvent::ApplicationDeactivate) { |
|
471 HbDeviceDialogServerStatus::StatusFlags flags = d->mServerStatus->status(); |
|
472 if ((flags & HbDeviceDialogServerStatus::ShowingDialog) == HbDeviceDialogServerStatus::NoFlags || |
|
473 flags & HbDeviceDialogServerStatus::ShowingScreenSaver) { |
|
474 d->killClockTimer(); |
|
475 d->mBatteryIndicator->chargingEvent(false); |
|
476 } |
|
477 } |
|
478 return HbWidget::eventFilter(obj, event); |
|
479 } |
|
480 |
|
481 void HbStatusBar::startClockTimer() |
|
482 { |
|
483 Q_D(HbStatusBar); |
|
484 d->startClockTimer(); |
|
485 } |
|
486 |
407 #include "moc_hbstatusbar_p.cpp" |
487 #include "moc_hbstatusbar_p.cpp" |