screensaver/screensaverplugins/snsrbigclockscreensaverplugin/snsrindicatorwidget/src/snsrindicatormodel.cpp
changeset 77 4b195f3bea29
parent 61 2b1b11a301d2
child 81 7dd137878ff8
equal deleted inserted replaced
61:2b1b11a301d2 77:4b195f3bea29
    27     \class SnsrIndicatorModel
    27     \class SnsrIndicatorModel
    28     \ingroup group_snsrbigclockscreensaverplugin
    28     \ingroup group_snsrbigclockscreensaverplugin
    29     \brief Model for handling indicator data.
    29     \brief Model for handling indicator data.
    30  */
    30  */
    31 
    31 
    32 // TODO: what is the type string of silent indicator? couldn't
    32 // TODO: what is the final type string of silent indicator? couldn't
    33 // find it in wk22 -> workaround solution: assume that it contains
    33 // find it in wk22 -> workaround solution: assume that it contains
    34 // substring "silent"
    34 // substring "silence" like in their demo app.
    35 const char *gSilentIndicatorTypeString = "silent";
    35 const char *gSilentIndicatorTypeString = "silence";
    36 const char *gOfflineIndicatorTypeString = "offline";
    36 const char *gOfflineIndicatorTypeString = "offline";
    37 
    37 
    38 
    38 
    39 /*!
    39 /*!
    40     Constructs a new SnsrIndicatorModel
    40     Constructs a new SnsrIndicatorModel
    78         HbIndicatorInterface* activatedIndicator = activeIndicators.at(i);
    78         HbIndicatorInterface* activatedIndicator = activeIndicators.at(i);
    79         SnsrIndicatorInfo indicatorInfo;
    79         SnsrIndicatorInfo indicatorInfo;
    80         if (activatedIndicator 
    80         if (activatedIndicator 
    81             && showIndicatorInScreensaver(*activatedIndicator,indicatorInfo)) {
    81             && showIndicatorInScreensaver(*activatedIndicator,indicatorInfo)) {
    82             addIndicator(indicatorInfo);
    82             addIndicator(indicatorInfo);
       
    83             connectToIndicatorsUpdateSignal(*activatedIndicator);
    83             addedAny = true;
    84             addedAny = true;
    84         }
    85         }
    85     }
    86     }
    86     
    87     
    87     // Send signal only once if there were any such indicators that
    88     // Send signal only once if there were any such indicators that
    88     // screensaver is supposed to show (=added to the model).
    89     // screensaver is supposed to show (=added to the model).
    89     if (addedAny) {
    90     if (addedAny) {
    90         emitChangeSignal();
    91         emitChangeSignal();
    91     }
    92     }
    92     
       
    93     // TODO: no we need to listen to update signals?
       
    94     // used for changing icon?
       
    95     /* //connect indicator's update signal
       
    96      QObject::connect(activatedIndicator, SIGNAL(dataChanged()),
       
    97                       this, SLOT(indicatorUpdated()));*/
       
    98 }
    93 }
    99 
    94 
   100 /*!
    95 /*!
   101     Called when some universal indicator gets activated.
    96     Called when some universal indicator gets activated.
   102     \param activatedIndicator Activated universal indicator
    97     \param activatedIndicator Activated universal indicator
   105     HbIndicatorInterface *activatedIndicator)
   100     HbIndicatorInterface *activatedIndicator)
   106 {
   101 {
   107     SnsrIndicatorInfo indicatorInfo;
   102     SnsrIndicatorInfo indicatorInfo;
   108     if (activatedIndicator
   103     if (activatedIndicator
   109         && showIndicatorInScreensaver(*activatedIndicator,indicatorInfo)) {
   104         && showIndicatorInScreensaver(*activatedIndicator,indicatorInfo)) {
   110         addIndicator(indicatorInfo);
   105         if (addIndicator(indicatorInfo)) {
   111         emitChangeSignal();
   106             connectToIndicatorsUpdateSignal(*activatedIndicator);
       
   107             emitChangeSignal();
       
   108         }
   112     }
   109     }
   113 }
   110 }
   114 
   111 
   115 /*!
   112 /*!
   116     Called when some universal indicator gets deactivated.
   113     Called when some universal indicator gets deactivated.
   127         
   124         
   128         if (findAndRemoveIndicator(indicatorInfo)) {
   125         if (findAndRemoveIndicator(indicatorInfo)) {
   129             emitChangeSignal();
   126             emitChangeSignal();
   130         }
   127         }
   131     }
   128     }
       
   129 }
       
   130 
       
   131 /*!
       
   132     Called when some universal indicator updates its data by
       
   133     emitting dataChanged signal. 
       
   134     We listen to this signal because at least the silent indicator plugin demo 
       
   135     uses this method to inform the clients when it gets deactivated/activated 
       
   136     once it has been activated once by setting its icon path to empty/valid string.
       
   137     Don't know if this is going to be the final solution as it's unconventional (?) 
       
   138     but let's be prepared also to this kind of approach. 
       
   139  */
       
   140 void SnsrIndicatorModel::handleUpdatedIndicator()
       
   141 {
       
   142     HbIndicatorInterface* indicator =
       
   143         qobject_cast<HbIndicatorInterface*>(sender());
       
   144     if (!indicator) {
       
   145         return;
       
   146     }
       
   147     
       
   148     // If indicator's icon path was set to empty string, then treat it
       
   149     // like it were deactivated. And if not empty, then it's active again.
       
   150     if (indicator->indicatorData(
       
   151             HbIndicatorInterface::MonoDecorationNameRole).toString().isEmpty()) {
       
   152         handleDeactivatedIndicator(indicator);
       
   153     }
       
   154     else {
       
   155         handleActivatedIndicator(indicator);
       
   156     }
       
   157     
   132 }
   158 }
   133 
   159 
   134 /*!
   160 /*!
   135     Sends a signal with a list of all currently active indicators.
   161     Sends a signal with a list of all currently active indicators.
   136     No signal is sent if there are no active indicators currently.
   162     No signal is sent if there are no active indicators currently.
   173 
   199 
   174 /*!
   200 /*!
   175     Add the indicator into this model. Handle here the order in which
   201     Add the indicator into this model. Handle here the order in which
   176     indicators are shown in screensaver: notification indicators should be
   202     indicators are shown in screensaver: notification indicators should be
   177     shown in the same order as shown in statusbar, that is in reversed
   203     shown in the same order as shown in statusbar, that is in reversed
   178     chronological order. Silent indicator should always be the right-most.
   204     chronological order. Silent indicator should always be the right-most one.
   179  */
   205     /retval true if indicator was added (not found already in the listings)
   180 void SnsrIndicatorModel::addIndicator(const SnsrIndicatorInfo &indicatorInfo)
   206  */
   181 {
   207 bool SnsrIndicatorModel::addIndicator(const SnsrIndicatorInfo &indicatorInfo)
   182     // info from pattern library - todo: remove
   208 {
   183     //Indicators are displayed inside of each group in reversed chronological order 
   209     // To be on the safe side, check that the indicator doesn't already
   184     // according to the arrival time; the indicator that appeared most recently is placed on top of the group.
   210     // exists in the active indicator listings.
   185 
   211     bool added(false);
   186     //Status bar indicators follow the same order; the most recent notification indicator (4) is on the left 
   212     
   187     // and similarly the most recent settings indicator (5) is on the right.
   213     // Use prepend to keep the list in reversed chronological order
   188 
   214     if (indicatorInfo.category == HbIndicatorInterface::NotificationCategory
   189     // use prepend to keep the list in reversed chronological order
   215         && !isIndicatorAlreadyAdded(indicatorInfo)) {
   190     if (indicatorInfo.category == HbIndicatorInterface::NotificationCategory) {
       
   191         mNotificationIndicators.prepend(indicatorInfo);
   216         mNotificationIndicators.prepend(indicatorInfo);
   192     }
   217         added = true;
   193     else {
   218     }
       
   219     else if (indicatorInfo.category == HbIndicatorInterface::SettingCategory
       
   220              && !isIndicatorAlreadyAdded(indicatorInfo)) {
   194         mSettingIndicators.append(indicatorInfo);
   221         mSettingIndicators.append(indicatorInfo);
   195     }
   222         added = true;
       
   223     }
       
   224     
       
   225     return added;
       
   226 }
       
   227 
       
   228 /*!
       
   229     Check whether the indicator is already added in the active 
       
   230     indicator listing.
       
   231     /retval true if indicator is already added; false if not.
       
   232  */
       
   233 bool SnsrIndicatorModel::isIndicatorAlreadyAdded(const SnsrIndicatorInfo &indicatorInfo) const
       
   234 {
       
   235     bool alreadyExits(false);
       
   236     
       
   237     const QList<SnsrIndicatorInfo> &indicatorList = 
       
   238         indicatorInfo.category == HbIndicatorInterface::NotificationCategory 
       
   239         ? mNotificationIndicators : mSettingIndicators;
       
   240     
       
   241     for (int i = 0; i < indicatorList.size(); ++i) {
       
   242         if (indicatorList.at(i).type == indicatorInfo.type) {
       
   243             alreadyExits = true;
       
   244             break;
       
   245         }
       
   246     }
       
   247     return alreadyExits;
   196 }
   248 }
   197 
   249 
   198 /*!
   250 /*!
   199    Remove indicator if it can be found.
   251    Remove indicator if it can be found.
   200    /retval true if the indicator was removed
   252    /retval true if the indicator was removed
   252     }
   304     }
   253     else if (category == HbIndicatorInterface::SettingCategory
   305     else if (category == HbIndicatorInterface::SettingCategory
   254              && !iconPath.isEmpty()
   306              && !iconPath.isEmpty()
   255              // TODO: what is the type string of silent indicator? couldn't
   307              // TODO: what is the type string of silent indicator? couldn't
   256              // find it in wk22 -> workaround solution: assume that it contains
   308              // find it in wk22 -> workaround solution: assume that it contains
   257              // substring "silent"
   309              // substring "silence" like in their demo app.
   258              // && type == gSilentIndicatorTypeString ) { 
   310              // && type == gSilentIndicatorTypeString ) { 
   259              && typeString.contains(gSilentIndicatorTypeString, Qt::CaseInsensitive)) {  
   311              && typeString.contains(gSilentIndicatorTypeString, Qt::CaseInsensitive)) {  
   260         show = true;
   312         show = true;
   261     }
   313     }
   262     else { // e.g. no Progress category indicators are shown
   314     else { // e.g. no Progress category indicators are shown
   267     indicatorInfo.type = typeString;
   319     indicatorInfo.type = typeString;
   268     indicatorInfo.iconPath = iconPath;
   320     indicatorInfo.iconPath = iconPath;
   269     indicatorInfo.category = category;
   321     indicatorInfo.category = category;
   270         
   322         
   271     return show;
   323     return show;
       
   324 }
       
   325 
       
   326 /*!
       
   327    Start listening to indicator's dataChanged signals.
       
   328    /parameter indicator whose dataChanged signal we want to listen
       
   329  */
       
   330 void SnsrIndicatorModel::connectToIndicatorsUpdateSignal(const HbIndicatorInterface &indicatorInterface)
       
   331 {
       
   332     // Connect to silent indicator's dataChanged signal as it seems to 
       
   333     // use unconventional method (demo at least) to inform when
       
   334     // it's get deactivated/activated: dataChanged signal is emitted and
       
   335     // icon path is set to empty string/valid string.
       
   336     // It's assumed that we don't need to listen to other indicators
       
   337     // as we are not interested e.g. when primary/secondary texts change etc.
       
   338     
       
   339     // NOTE: do NOT disconnect the indicator signal anywhere explicitly here
       
   340     // or we won't get activation/deactivation messages.
       
   341     if (indicatorInterface.indicatorType().contains(gSilentIndicatorTypeString, Qt::CaseInsensitive)) {
       
   342         QObject::connect( &indicatorInterface, SIGNAL(dataChanged()),
       
   343                           this, SLOT(handleUpdatedIndicator()));
       
   344     }
   272 }
   345 }
   273 
   346 
   274 /*!
   347 /*!
   275    Check whether there is any active indicator currently.
   348    Check whether there is any active indicator currently.
   276    /retval true if there is at least one indicator to show
   349    /retval true if there is at least one indicator to show