diff -r 2b1b11a301d2 -r 4b195f3bea29 screensaver/screensaverplugins/snsrbigclockscreensaverplugin/snsrindicatorwidget/src/snsrindicatormodel.cpp --- a/screensaver/screensaverplugins/snsrbigclockscreensaverplugin/snsrindicatorwidget/src/snsrindicatormodel.cpp Tue Jul 06 14:06:53 2010 +0300 +++ b/screensaver/screensaverplugins/snsrbigclockscreensaverplugin/snsrindicatorwidget/src/snsrindicatormodel.cpp Wed Aug 18 09:40:07 2010 +0300 @@ -29,10 +29,10 @@ \brief Model for handling indicator data. */ -// TODO: what is the type string of silent indicator? couldn't +// TODO: what is the final type string of silent indicator? couldn't // find it in wk22 -> workaround solution: assume that it contains -// substring "silent" -const char *gSilentIndicatorTypeString = "silent"; +// substring "silence" like in their demo app. +const char *gSilentIndicatorTypeString = "silence"; const char *gOfflineIndicatorTypeString = "offline"; @@ -80,6 +80,7 @@ if (activatedIndicator && showIndicatorInScreensaver(*activatedIndicator,indicatorInfo)) { addIndicator(indicatorInfo); + connectToIndicatorsUpdateSignal(*activatedIndicator); addedAny = true; } } @@ -89,12 +90,6 @@ if (addedAny) { emitChangeSignal(); } - - // TODO: no we need to listen to update signals? - // used for changing icon? - /* //connect indicator's update signal - QObject::connect(activatedIndicator, SIGNAL(dataChanged()), - this, SLOT(indicatorUpdated()));*/ } /*! @@ -107,8 +102,10 @@ SnsrIndicatorInfo indicatorInfo; if (activatedIndicator && showIndicatorInScreensaver(*activatedIndicator,indicatorInfo)) { - addIndicator(indicatorInfo); - emitChangeSignal(); + if (addIndicator(indicatorInfo)) { + connectToIndicatorsUpdateSignal(*activatedIndicator); + emitChangeSignal(); + } } } @@ -132,6 +129,35 @@ } /*! + Called when some universal indicator updates its data by + emitting dataChanged signal. + We listen to this signal because at least the silent indicator plugin demo + uses this method to inform the clients when it gets deactivated/activated + once it has been activated once by setting its icon path to empty/valid string. + Don't know if this is going to be the final solution as it's unconventional (?) + but let's be prepared also to this kind of approach. + */ +void SnsrIndicatorModel::handleUpdatedIndicator() +{ + HbIndicatorInterface* indicator = + qobject_cast(sender()); + if (!indicator) { + return; + } + + // If indicator's icon path was set to empty string, then treat it + // like it were deactivated. And if not empty, then it's active again. + if (indicator->indicatorData( + HbIndicatorInterface::MonoDecorationNameRole).toString().isEmpty()) { + handleDeactivatedIndicator(indicator); + } + else { + handleActivatedIndicator(indicator); + } + +} + +/*! Sends a signal with a list of all currently active indicators. No signal is sent if there are no active indicators currently. */ @@ -175,24 +201,50 @@ Add the indicator into this model. Handle here the order in which indicators are shown in screensaver: notification indicators should be shown in the same order as shown in statusbar, that is in reversed - chronological order. Silent indicator should always be the right-most. + chronological order. Silent indicator should always be the right-most one. + /retval true if indicator was added (not found already in the listings) */ -void SnsrIndicatorModel::addIndicator(const SnsrIndicatorInfo &indicatorInfo) +bool SnsrIndicatorModel::addIndicator(const SnsrIndicatorInfo &indicatorInfo) { - // info from pattern library - todo: remove - //Indicators are displayed inside of each group in reversed chronological order - // according to the arrival time; the indicator that appeared most recently is placed on top of the group. + // To be on the safe side, check that the indicator doesn't already + // exists in the active indicator listings. + bool added(false); + + // Use prepend to keep the list in reversed chronological order + if (indicatorInfo.category == HbIndicatorInterface::NotificationCategory + && !isIndicatorAlreadyAdded(indicatorInfo)) { + mNotificationIndicators.prepend(indicatorInfo); + added = true; + } + else if (indicatorInfo.category == HbIndicatorInterface::SettingCategory + && !isIndicatorAlreadyAdded(indicatorInfo)) { + mSettingIndicators.append(indicatorInfo); + added = true; + } + + return added; +} - //Status bar indicators follow the same order; the most recent notification indicator (4) is on the left - // and similarly the most recent settings indicator (5) is on the right. - - // use prepend to keep the list in reversed chronological order - if (indicatorInfo.category == HbIndicatorInterface::NotificationCategory) { - mNotificationIndicators.prepend(indicatorInfo); +/*! + Check whether the indicator is already added in the active + indicator listing. + /retval true if indicator is already added; false if not. + */ +bool SnsrIndicatorModel::isIndicatorAlreadyAdded(const SnsrIndicatorInfo &indicatorInfo) const +{ + bool alreadyExits(false); + + const QList &indicatorList = + indicatorInfo.category == HbIndicatorInterface::NotificationCategory + ? mNotificationIndicators : mSettingIndicators; + + for (int i = 0; i < indicatorList.size(); ++i) { + if (indicatorList.at(i).type == indicatorInfo.type) { + alreadyExits = true; + break; + } } - else { - mSettingIndicators.append(indicatorInfo); - } + return alreadyExits; } /*! @@ -254,7 +306,7 @@ && !iconPath.isEmpty() // TODO: what is the type string of silent indicator? couldn't // find it in wk22 -> workaround solution: assume that it contains - // substring "silent" + // substring "silence" like in their demo app. // && type == gSilentIndicatorTypeString ) { && typeString.contains(gSilentIndicatorTypeString, Qt::CaseInsensitive)) { show = true; @@ -272,6 +324,27 @@ } /*! + Start listening to indicator's dataChanged signals. + /parameter indicator whose dataChanged signal we want to listen + */ +void SnsrIndicatorModel::connectToIndicatorsUpdateSignal(const HbIndicatorInterface &indicatorInterface) +{ + // Connect to silent indicator's dataChanged signal as it seems to + // use unconventional method (demo at least) to inform when + // it's get deactivated/activated: dataChanged signal is emitted and + // icon path is set to empty string/valid string. + // It's assumed that we don't need to listen to other indicators + // as we are not interested e.g. when primary/secondary texts change etc. + + // NOTE: do NOT disconnect the indicator signal anywhere explicitly here + // or we won't get activation/deactivation messages. + if (indicatorInterface.indicatorType().contains(gSilentIndicatorTypeString, Qt::CaseInsensitive)) { + QObject::connect( &indicatorInterface, SIGNAL(dataChanged()), + this, SLOT(handleUpdatedIndicator())); + } +} + +/*! Check whether there is any active indicator currently. /retval true if there is at least one indicator to show */