emailservices/nmailagent/src/nmmailagent.cpp
changeset 54 997a02608b3a
parent 53 bf7eb7911fc5
child 59 16ed8d08d0b1
equal deleted inserted replaced
53:bf7eb7911fc5 54:997a02608b3a
    24 #include <xqaiwrequest.h>
    24 #include <xqaiwrequest.h>
    25 
    25 
    26 #include <xqsettingsmanager.h>
    26 #include <xqsettingsmanager.h>
    27 #include <xqcentralrepositoryutils.h>
    27 #include <xqcentralrepositoryutils.h>
    28 #include <xqsystemtoneservice.h>
    28 #include <xqsystemtoneservice.h>
       
    29 #include <xqsettingskey.h>
       
    30 #include <ProfileEngineInternalCRKeys.h>
    29 
    31 
    30 // CONSTS
    32 // CONSTS
    31 const int NmAgentIndicatorNotSet = -1;
    33 const int NmAgentIndicatorNotSet = -1;
    32 const int NmAgentAlertToneTimer = 60000; // 60s
    34 const int NmAgentAlertToneTimer = 60000; // 60s
    33 const int NmAgentDefaultVibraDuration = 1000; // 1 second
    35 const int NmAgentDefaultVibraDuration = 1000; // 1 second
    34 static const quint32 NmRepositoryId = 0x2002C326; 
    36 static const quint32 NmRepositoryId = 0x2002C326;
    35 static const QString NmMailboxIndicatorType = "com.nokia.nmail.indicatorplugin_%1/1.0";
    37 static const QString NmMailboxIndicatorType = "com.nokia.nmail.indicatorplugin_%1/1.0";
    36 static const QString NmSendIndicatorName = "com.nokia.nmail.indicatorplugin.send/1.0";
    38 static const QString NmSendIndicatorName = "com.nokia.nmail.indicatorplugin.send/1.0";
    37 static const QString NmUnreadIndicatorName = "com.nokia.nmail.indicatorplugin.unread/1.0";
    39 static const QString NmUnreadIndicatorName = "com.nokia.nmail.indicatorplugin.unread/1.0";
       
    40 const XQCentralRepositorySettingsKey NmSilenceModeKey(KCRUidProfileEngine.iUid, KProEngSilenceMode);
       
    41 const int NmSilenceModeOn = 1;
       
    42 
       
    43 /*!
       
    44     Helper method for finding out if XQSettingsKey and XQCentralRepositorySettingsKey points to
       
    45     same key.
       
    46 
       
    47     @param settingKey XQSettingsKey
       
    48     @param cenrepSettingKey XQCentralRepositorySettingsKey
       
    49     @return <code>true</code> if target, uid and key matches otherwise returns <code>false</code>
       
    50 */
       
    51 bool keysEqual(const XQSettingsKey& settingKey, const XQCentralRepositorySettingsKey& cenrepSettingKey)
       
    52 {
       
    53     return ((settingKey.target() == cenrepSettingKey.target()) &&
       
    54             (settingKey.uid() == cenrepSettingKey.uid()) &&
       
    55             (settingKey.key() == cenrepSettingKey.key()));
       
    56 }
    38 
    57 
    39 
    58 
    40 /*!
    59 /*!
    41     \class NmMailAgent
    60     \class NmMailAgent
    42 
    61 
    66  mSystemTone(NULL),
    85  mSystemTone(NULL),
    67  mPluginFactory(NULL),
    86  mPluginFactory(NULL),
    68  mVibra(NULL),
    87  mVibra(NULL),
    69  mAlertToneAllowed(true),
    88  mAlertToneAllowed(true),
    70  mLastOutboxCount(0),
    89  mLastOutboxCount(0),
    71  mUnreadIndicatorActive(false)
    90  mUnreadIndicatorActive(false),
       
    91  mSettingManager(NULL),
       
    92  mSilenceMode(NmSilenceModeOn)  // by default silent mode is on
    72 {
    93 {
    73     NM_FUNCTION;
    94     NM_FUNCTION;
    74 }
    95 }
    75 
    96 
    76 /*!
    97 /*!
    97     if (!mPluginFactory) {
   118     if (!mPluginFactory) {
    98         NM_ERROR(1,"NmMailAgent::init(): PluginFactory not created");
   119         NM_ERROR(1,"NmMailAgent::init(): PluginFactory not created");
    99         return false;
   120         return false;
   100     }
   121     }
   101 
   122 
   102     //mSystemTone = new XQSystemToneService();
   123     // Check status of silent mode.
   103     
   124     delete mSettingManager;
       
   125     mSettingManager = NULL;
       
   126     mSettingManager = new XQSettingsManager();
       
   127     QVariant silenceMode = mSettingManager->readItemValue(NmSilenceModeKey,
       
   128         XQSettingsManager::TypeInt);
       
   129     mSilenceMode = silenceMode.toInt();
       
   130 
       
   131     // Start monitoring silence mode key.
       
   132     bool monitoring(mSettingManager->startMonitoring(NmSilenceModeKey, XQSettingsManager::TypeInt));
       
   133     monitoring &= connect(mSettingManager,
       
   134                           SIGNAL(valueChanged(const XQSettingsKey&, const QVariant&)),
       
   135                           this,
       
   136                           SLOT(valueChanged(const XQSettingsKey&, const QVariant&)),
       
   137                           Qt::UniqueConnection);
       
   138 
       
   139     // If silence mode monitoring can't be started, then change silence mode on to be sure
       
   140     // that no tone is played if silence mode is turned on at somepoint.
       
   141     if (!monitoring) {
       
   142         mSilenceMode = NmSilenceModeOn;
       
   143     }
       
   144 
       
   145     delete mSystemTone;
       
   146     mSystemTone = NULL;
       
   147     mSystemTone = new XQSystemToneService();
       
   148 
       
   149     delete mIndicator;
       
   150     mIndicator = NULL;
   104     mIndicator = new HbIndicator();
   151     mIndicator = new HbIndicator();
   105     connect(mIndicator,SIGNAL(userActivated(const QString &, const QVariantMap&)),
   152     connect(mIndicator,SIGNAL(userActivated(const QString &, const QVariantMap&)),
   106         this, SLOT(indicatorActivated(const QString&, const QVariantMap&)));
   153         this, SLOT(indicatorActivated(const QString&, const QVariantMap&)));
   107 
   154 
   108     QList<QObject*> *plugins = mPluginFactory->pluginInstances();
   155     QList<QObject*> *plugins = mPluginFactory->pluginInstances();
   129 				Qt::UniqueConnection);
   176 				Qt::UniqueConnection);
   130     	}
   177     	}
   131     }
   178     }
   132 
   179 
   133     // Construct the vibra interface instance.
   180     // Construct the vibra interface instance.
       
   181     delete mVibra;
       
   182     mVibra = NULL;
   134     TRAP_IGNORE(mVibra = CHWRMVibra::NewL());
   183     TRAP_IGNORE(mVibra = CHWRMVibra::NewL());
   135 
   184 
   136     // load all current mailboxes
   185     // load all current mailboxes
   137     initMailboxStatus();
   186     initMailboxStatus();
   138 
   187 
   142 NmMailAgent::~NmMailAgent()
   191 NmMailAgent::~NmMailAgent()
   143 {
   192 {
   144     NM_FUNCTION;
   193     NM_FUNCTION;
   145 
   194 
   146     delete mVibra;
   195     delete mVibra;
   147     //delete mSystemTone;
   196     delete mSystemTone;
   148 
   197     if (mSettingManager) {
       
   198         mSettingManager->stopMonitoring(NmSilenceModeKey);
       
   199         delete mSettingManager;
       
   200     }
   149     qDeleteAll(mMailboxes);
   201     qDeleteAll(mMailboxes);
   150 
   202 
   151     //delete mSystemTone;
       
   152     NmDataPluginFactory::releaseInstance(mPluginFactory);
   203     NmDataPluginFactory::releaseInstance(mPluginFactory);
   153 }
   204 }
   154 
   205 
   155 /*!
   206 /*!
   156     Initialize the mailbox list with the current state
   207     Initialize the mailbox list with the current state
   295     Get list of unread counts in active mailboxes
   346     Get list of unread counts in active mailboxes
   296 	\returns total number of unread mails
   347 	\returns total number of unread mails
   297 */
   348 */
   298 int NmMailAgent::getTotalUnreadCount() const
   349 int NmMailAgent::getTotalUnreadCount() const
   299 {
   350 {
       
   351     NM_FUNCTION;
       
   352 
   300     int unreads = 0;
   353     int unreads = 0;
   301     foreach (const NmMailboxInfo *mailbox, mMailboxes) {
   354     foreach (const NmMailboxInfo *mailbox, mMailboxes) {
   302         if (mailbox->mActive && mailbox->mInboxActive) {
   355         if (mailbox->mActive && mailbox->mInboxActive) {
   303             unreads += mailbox->mUnreadMailIdList.count();
   356             unreads += mailbox->mUnreadMailIdList.count();
   304         }
   357         }
   310     Update the "@" indicator state according to unread state
   363     Update the "@" indicator state according to unread state
   311     \return true if the indicator was activated
   364     \return true if the indicator was activated
   312 */
   365 */
   313 bool NmMailAgent::updateUnreadIndicator()
   366 bool NmMailAgent::updateUnreadIndicator()
   314 {
   367 {
       
   368     NM_FUNCTION;
       
   369 
   315     int unreads = getTotalUnreadCount();
   370     int unreads = getTotalUnreadCount();
   316     return updateUnreadIndicator(unreads>0);
   371     return updateUnreadIndicator(unreads>0);
   317 }
   372 }
   318 
   373 
   319 /*!
   374 /*!
   330 
   385 
   331     NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
   386     NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
   332     bool changed = false;
   387     bool changed = false;
   333     if (mailboxInfo->mActive != active ||
   388     if (mailboxInfo->mActive != active ||
   334         refreshAlways) {
   389         refreshAlways) {
   335         
   390 
   336 		// store the new state to permanent storage
   391 		// store the new state to permanent storage
   337         storeMailboxActive(mailboxId, active);
   392         storeMailboxActive(mailboxId, active);
   338         
   393 
   339         mailboxInfo->mActive = active;
   394         mailboxInfo->mActive = active;
   340         changed = true;
   395         changed = true;
   341         if (active) {
   396         if (active) {
   342             // Mailbox is not yet assigned to any indicator
   397             // Mailbox is not yet assigned to any indicator
   343             if (mailboxInfo->mIndicatorIndex < 0) {
   398             if (mailboxInfo->mIndicatorIndex < 0) {
   402     \return true if the indicator was activated
   457     \return true if the indicator was activated
   403 */
   458 */
   404 bool NmMailAgent::updateUnreadIndicator(bool active)
   459 bool NmMailAgent::updateUnreadIndicator(bool active)
   405 {
   460 {
   406     NM_FUNCTION;
   461     NM_FUNCTION;
       
   462 
   407     bool activated = false;
   463     bool activated = false;
   408 
       
   409     if (active != mUnreadIndicatorActive) {
   464     if (active != mUnreadIndicatorActive) {
   410         if (active) {
   465         if (active) {
   411             mIndicator->activate(NmUnreadIndicatorName);
   466             mIndicator->activate(NmUnreadIndicatorName);
   412             activated = true;
   467             activated = true;
   413         }
   468         }
   426 */
   481 */
   427 bool NmMailAgent::launchMailbox(quint64 mailboxId)
   482 bool NmMailAgent::launchMailbox(quint64 mailboxId)
   428 {
   483 {
   429     NM_FUNCTION;
   484     NM_FUNCTION;
   430 
   485 
       
   486     bool ok(false);
   431     XQApplicationManager appManager;
   487     XQApplicationManager appManager;
   432     XQAiwRequest *request = appManager.create(
   488     XQAiwRequest *request = appManager.create(
   433         XQI_EMAIL_INBOX_VIEW, XQOP_EMAIL_INBOX_VIEW, false);
   489         XQI_EMAIL_INBOX_VIEW, XQOP_EMAIL_INBOX_VIEW, false);
   434     
   490     // Instance might be NULL if the service is not available.
   435     QList<QVariant> list;
   491     if (request) {
   436     list.append(QVariant(mailboxId));
   492         QList<QVariant> list;
   437     request->setArguments(list);
   493         list.append(QVariant(mailboxId));
   438     
   494         request->setArguments(list);
   439     bool ok = request->send();
   495 
   440     NM_COMMENT(QString("Launch ok=%1 error=%2").arg(ok).arg(request->lastError()));
   496         ok = request->send();
   441     delete request;
   497         NM_COMMENT(QString("Launch ok=%1 error=%2").arg(ok).arg(request->lastError()));
       
   498         delete request;
       
   499     }
   442     return ok;
   500     return ok;
   443 }
   501 }
   444 
   502 
   445 /*!
   503 /*!
   446     Get next free indicator index, starting from 0
   504     Get next free indicator index, starting from 0
   477 
   535 
   478     switch(event) {
   536     switch(event) {
   479         case NmMailboxCreated:
   537         case NmMailboxCreated:
   480             foreach (NmId mailboxId, mailboxIds) {
   538             foreach (NmId mailboxId, mailboxIds) {
   481                 getMailboxInfo(mailboxId); // create a new mailbox if needed
   539                 getMailboxInfo(mailboxId); // create a new mailbox if needed
   482                 
   540 
   483                 // make sure the mailbox activity data is reseted
   541                 // make sure the mailbox activity data is reseted
   484                 deleteStoredMailboxActivity(mailboxId);
   542                 deleteStoredMailboxActivity(mailboxId);
   485             }
   543             }
   486             break;
   544             break;
   487         case NmMailboxChanged:
   545         case NmMailboxChanged:
   509             break;
   567             break;
   510         case NmMailboxDeleted:
   568         case NmMailboxDeleted:
   511             foreach (NmId mailboxId, mailboxIds) {
   569             foreach (NmId mailboxId, mailboxIds) {
   512                 // Will hide also the indicator
   570                 // Will hide also the indicator
   513                 removeMailboxInfo(mailboxId);
   571                 removeMailboxInfo(mailboxId);
   514                 
   572 
   515                 // make sure the mailbox activity data is deleted
   573                 // make sure the mailbox activity data is deleted
   516                 deleteStoredMailboxActivity(mailboxId);
   574                 deleteStoredMailboxActivity(mailboxId);
   517             }
   575             }
   518             updateUnreadIndicator();
   576             updateUnreadIndicator();
   519             break;
   577             break;
   526    Map the type name to mailbox info
   584    Map the type name to mailbox info
   527     \return NULL if no mailbox match the type
   585     \return NULL if no mailbox match the type
   528 */
   586 */
   529 NmMailboxInfo *NmMailAgent::getMailboxByType(const QString &type)
   587 NmMailboxInfo *NmMailAgent::getMailboxByType(const QString &type)
   530 {
   588 {
       
   589     NM_FUNCTION;
       
   590 
   531     foreach (NmMailboxInfo *mailbox, mMailboxes) {
   591     foreach (NmMailboxInfo *mailbox, mMailboxes) {
   532         // mailbox is shown in indicators
   592         // mailbox is shown in indicators
   533         if (mailbox->mIndicatorIndex >= 0 && mailbox->mActive) {
   593         if (mailbox->mIndicatorIndex >= 0 && mailbox->mActive) {
   534             QString typeName = QString(NmMailboxIndicatorType).arg(mailbox->mIndicatorIndex);
   594             QString typeName = QString(NmMailboxIndicatorType).arg(mailbox->mIndicatorIndex);
   535 
   595 
   549 */
   609 */
   550 void NmMailAgent::indicatorActivated(const QString &type, const QVariantMap &data)
   610 void NmMailAgent::indicatorActivated(const QString &type, const QVariantMap &data)
   551 {
   611 {
   552     NM_FUNCTION;
   612     NM_FUNCTION;
   553     Q_UNUSED(data);
   613     Q_UNUSED(data);
   554     
   614 
   555     // map the indicator type to mailbox
   615     // map the indicator type to mailbox
   556     NmMailboxInfo *info = getMailboxByType(type);
   616     NmMailboxInfo *info = getMailboxByType(type);
   557     if (info) {
   617     if (info) {
   558         info->mActive = false; // indicator is no longer active
   618         info->mActive = false; // indicator is no longer active
   559         info->mInboxActive = false; // also inbox does not activate the indicator
   619         info->mInboxActive = false; // also inbox does not activate the indicator
   563         launchMailbox(info->mId.id());
   623         launchMailbox(info->mId.id());
   564     }
   624     }
   565 }
   625 }
   566 
   626 
   567 /*!
   627 /*!
       
   628     Called when cenrep key value has been changed.
       
   629     - only silence mode key handled
       
   630 
       
   631     @param key changed key
       
   632     @param value value for a key.
       
   633 */
       
   634 void NmMailAgent::valueChanged(const XQSettingsKey& key, const QVariant& value)
       
   635 {
       
   636     NM_FUNCTION;
       
   637 
       
   638     if(keysEqual(key, NmSilenceModeKey)) {
       
   639         mSilenceMode = value.toInt();
       
   640     }
       
   641 }
       
   642 
       
   643 /*!
   568     Received from NmFrameworkAdapter messageEvent signal
   644     Received from NmFrameworkAdapter messageEvent signal
   569     \sa NmFrameworkAdapter
   645     \sa NmFrameworkAdapter
   570 */
   646 */
   571 void NmMailAgent::handleMessageEvent(
   647 void NmMailAgent::handleMessageEvent(
   572             NmMessageEvent event,
   648             NmMessageEvent event,
   573             const NmId &folderId,
   649             const NmId &folderId,
   574             const QList<NmId> &messageIds,
   650             const QList<NmId> &messageIds,
   575             const NmId& mailboxId)
   651             const NmId& mailboxId)
   576 {
   652 {
   577     NM_FUNCTION;
   653     NM_FUNCTION;
       
   654 
   578     NM_COMMENT(QString("NmMailAgent::handleMessageEvent(): event=%1, id=%2").
   655     NM_COMMENT(QString("NmMailAgent::handleMessageEvent(): event=%1, id=%2").
   579         arg(event).arg(mailboxId.id()));
   656         arg(event).arg(mailboxId.id()));
   580 
   657 
   581     bool updateNeeded = false;
   658     bool updateNeeded = false;
   582     bool activate = false;
   659     bool activate = false;
   583 
   660 
   584     switch (event) {
   661     switch (event) {
   585         case NmMessageCreated: {
   662         case NmMessageCreated: {
       
   663             // Check the new messages to make the indicator appear earlier
   586             NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
   664             NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
   587 
   665             
   588             // Check the new messages to make the indicator appear earlier
   666             // Inbox folder ID may be still unknown
   589             if (mailboxInfo->mSyncState == Synchronizing) {
   667             if (mailboxInfo->mInboxFolderId.id() == 0) {
   590                 
   668                 NmDataPluginInterface *plugin =
   591                 // Inbox folder ID may be still unknown
   669                     mPluginFactory->interfaceInstance(mailboxId);
   592                 if (mailboxInfo->mInboxFolderId.id()==0) {
   670 
   593                     NmDataPluginInterface *plugin = mPluginFactory->interfaceInstance(mailboxId);
   671                 if (plugin) {
   594                     if (plugin) {
   672                     mailboxInfo->mInboxFolderId =
   595                         mailboxInfo->mInboxFolderId =
   673                         plugin->getStandardFolderId(mailboxId, NmFolderInbox);
   596                             plugin->getStandardFolderId(mailboxId, NmFolderInbox);
       
   597                     }
       
   598                 }
   674                 }
   599                 
   675             }
   600                 if (folderId == mailboxInfo->mInboxFolderId) {
   676 
   601                     foreach (NmId messageId, messageIds) {
   677             if (folderId == mailboxInfo->mInboxFolderId) {
   602                         bool messageUnread = false;
   678                 foreach (NmId messageId, messageIds) {
   603 
   679                     bool messageUnread = false;
   604                         // Check the message if we can either play a tone or if the "@" is 
   680 
   605                         // not visible at the moment
   681                     // Check the message if we can either play a tone or if the "@" is
   606                         if (mAlertToneAllowed || !mUnreadIndicatorActive) {
   682                     // not visible at the moment
   607                             if (getMessageUnreadInfo(folderId, messageId, mailboxId, messageUnread)) {
   683                     if (mAlertToneAllowed || !mUnreadIndicatorActive) {
   608                                 if (messageUnread) {
   684                         if (getMessageUnreadInfo(folderId, messageId, mailboxId, messageUnread)) {
   609                                     mailboxInfo->mUnreadMailIdList.append(messageId);
   685                             if (messageUnread) {
   610                                     mailboxInfo->mInboxActive = true;
   686                                 mailboxInfo->mUnreadMailIdList.append(messageId);
   611                                     updateMailboxState(mailboxId, true, false);
   687                                 mailboxInfo->mInboxActive = true;
   612 
   688                                 updateMailboxState(mailboxId, true, false);
   613                                     // make the "@" appear immediatelly
   689 
   614                                     updateUnreadIndicator(true);
   690                                 // make the "@" appear immediatelly
   615 
   691                                 updateUnreadIndicator(true);
   616                                     // Play the tone as well
   692 
   617                                     playAlertTone();
   693                                 // Play the tone as well
   618                                 }
   694                                 playAlertTone();
   619                             }
   695                             }
   620                         }
   696                         }
   621                     }
   697                     }
   622                 }
   698                 }
   623             }
   699             }
   624             
   700 
   625             if (folderId==mailboxInfo->mInboxFolderId) {
   701             if (folderId==mailboxInfo->mInboxFolderId) {
   626                 mailboxInfo->mInboxCreatedMessages += messageIds.count();
   702                 mailboxInfo->mInboxCreatedMessages += messageIds.count();
   627             }
   703             }
   628 
   704 
   629             // When created a new mail in the outbox, we are in sending state
   705             // When created a new mail in the outbox, we are in sending state
   633 					NM_COMMENT("NmMailAgent: first mail in outbox");
   709 					NM_COMMENT("NmMailAgent: first mail in outbox");
   634                 }
   710                 }
   635                 // Always activate the indicator
   711                 // Always activate the indicator
   636                 activate = true;
   712                 activate = true;
   637                 updateNeeded = true;
   713                 updateNeeded = true;
   638                 
   714 
   639                 mailboxInfo->mOutboxMails += messageIds.count();
   715                 mailboxInfo->mOutboxMails += messageIds.count();
   640 				updateSendIndicator();
   716 				updateSendIndicator();
   641             }
   717             }
   642             break;
   718             break;
   643         }
   719         }
   679                 }
   755                 }
   680 
   756 
   681                 // The last mail was now deleted
   757                 // The last mail was now deleted
   682                 if (mailboxInfo->mOutboxMails == 0) {
   758                 if (mailboxInfo->mOutboxMails == 0) {
   683 					NM_COMMENT("NmMailAgent: last mail deleted from outbox");
   759 					NM_COMMENT("NmMailAgent: last mail deleted from outbox");
   684                     // Keep it active if there is unread mails and inbox is still active
   760 					updateNeeded = true;
   685 					if (mailboxInfo->mInboxActive &&
   761 
       
   762 	                // Keep it active if there is unread mails and inbox is still active
       
   763  				    if (mailboxInfo->mInboxActive &&
   686 					    mailboxInfo->mUnreadMailIdList.count() > 0) {
   764 					    mailboxInfo->mUnreadMailIdList.count() > 0) {
   687 					    activate = true;
   765 					    activate = true;
   688                     }
   766 	                }
   689                     updateNeeded = true;
   767 				}
   690                 }
   768 				else {
       
   769 	                // Also update the indicator status if it is already shown
       
   770     	            if (mailboxInfo->mActive) {
       
   771 						activate = true;
       
   772             	        updateNeeded = true;
       
   773 					}
       
   774 				}
   691 				updateSendIndicator();
   775 				updateSendIndicator();
   692             }
   776             }
   693             break;
   777             break;
   694         }
   778         }
   695         default:
   779         default:
   908 	\returns true if the tone was played
   992 	\returns true if the tone was played
   909 */
   993 */
   910 bool NmMailAgent::playAlertTone()
   994 bool NmMailAgent::playAlertTone()
   911 {
   995 {
   912     NM_FUNCTION;
   996     NM_FUNCTION;
   913 	bool played = false;
   997 	bool played(false);
   914 
   998 
   915     if (mAlertToneAllowed) {
   999     if (mAlertToneAllowed) {
   916         //mSystemTone->playTone(XQSystemToneService::EmailAlertTone);
  1000         // Play tone only if system tone service is available and
   917         
  1001         // phone is not in silence mode.
       
  1002         if (mSystemTone && !mSilenceMode) {
       
  1003             mSystemTone->playTone(XQSystemToneService::EmailAlertTone);
       
  1004         }
       
  1005 
   918         // Execute the vibra effect.
  1006         // Execute the vibra effect.
   919         if (mVibra) {
  1007         if (mVibra) {
   920             TRAP_IGNORE(mVibra->StartVibraL(NmAgentDefaultVibraDuration));
  1008             TRAP_IGNORE(mVibra->StartVibraL(NmAgentDefaultVibraDuration));
   921         }
  1009         }
   922         
  1010 
   923         // play alert only once per minute
  1011         // play alert only once per minute
   924         mAlertToneAllowed = false;
  1012         mAlertToneAllowed = false;
   925         QTimer::singleShot(NmAgentAlertToneTimer, this, SLOT(enableAlertTone()));
  1013         QTimer::singleShot(NmAgentAlertToneTimer, this, SLOT(enableAlertTone()));
   926 		played = true;
  1014 		played = true;
   927     }
  1015     }
   942 /*!
  1030 /*!
   943     update send indicator according to outbox state
  1031     update send indicator according to outbox state
   944 */
  1032 */
   945 void NmMailAgent::updateSendIndicator()
  1033 void NmMailAgent::updateSendIndicator()
   946 {
  1034 {
       
  1035     NM_FUNCTION;
       
  1036 
   947     // Get number of mails in outboxes
  1037     // Get number of mails in outboxes
   948     int outboxMails = 0;
  1038     int outboxMails = 0;
   949     foreach (NmMailboxInfo *mailboxInfo, mMailboxes) {
  1039     foreach (NmMailboxInfo *mailboxInfo, mMailboxes) {
   950         outboxMails += mailboxInfo->mOutboxMails;
  1040         outboxMails += mailboxInfo->mOutboxMails;
   951     }
  1041     }
   968     \param mailboxId id of the mailbox
  1058     \param mailboxId id of the mailbox
   969     \param active true if the mailbox is active
  1059     \param active true if the mailbox is active
   970 */
  1060 */
   971 void NmMailAgent::storeMailboxActive(const NmId &mailboxId, bool active)
  1061 void NmMailAgent::storeMailboxActive(const NmId &mailboxId, bool active)
   972 {
  1062 {
   973     XQCentralRepositorySettingsKey key(NmRepositoryId, mailboxId.id());
  1063     NM_FUNCTION;
   974     XQSettingsManager mgr;
  1064 
   975     XQCentralRepositoryUtils utils(mgr);
  1065     if (mSettingManager) {
   976     
  1066         XQCentralRepositorySettingsKey key(NmRepositoryId, mailboxId.id());
   977     if (active) {
  1067         XQCentralRepositoryUtils utils(*mSettingManager);
   978         // when mailbox is active, key can be deleted
  1068 
   979         utils.deleteKey(key);
  1069         if (active) {
   980     }
  1070             // when mailbox is active, key can be deleted
   981     else {
  1071             utils.deleteKey(key);
   982         utils.createKey(key,(int)active);
  1072         }
   983     }
  1073         else {
   984 }
  1074             utils.createKey(key,(int)active);
   985 
  1075         }
   986 /*!
  1076     }
   987     Get the mailbox activity state. 
  1077 }
       
  1078 
       
  1079 /*!
       
  1080     Get the mailbox activity state.
   988     \param mailboxId id of the mailbox
  1081     \param mailboxId id of the mailbox
   989     \return true if the mailbox is active or no information was stored earlier
  1082     \return true if the mailbox is active or no information was stored earlier
   990 */
  1083 */
   991 bool NmMailAgent::isMailboxActive(const NmId &mailboxId)
  1084 bool NmMailAgent::isMailboxActive(const NmId &mailboxId)
   992 {
  1085 {
   993     XQCentralRepositorySettingsKey key(NmRepositoryId, mailboxId.id());
  1086     NM_FUNCTION;
   994     XQSettingsManager mgr;
  1087 
   995     QVariant value = mgr.readItemValue(key,XQSettingsManager::TypeInt);
  1088     bool mailboxActive(true);
   996     if (!value.isValid()) {
  1089     if (mSettingManager) {
   997         // no valid value found, key missing?
  1090         XQCentralRepositorySettingsKey key(NmRepositoryId, mailboxId.id());
   998         NM_COMMENT("NmMailAgent::isMailboxActive - value not valid");
  1091         QVariant value = mSettingManager->readItemValue(key, XQSettingsManager::TypeInt);
   999         return true;
  1092         if (value.isValid()) {
  1000     }
  1093             NM_COMMENT(QString("NmMailAgent::isMailboxActive - value=%1").arg(value.toInt()));
  1001     NM_COMMENT(QString("NmMailAgent::isMailboxActive - value=%1").arg(value.toInt()));
  1094             mailboxActive = value.toInt();
  1002     return value.toInt();
  1095         }
       
  1096     }
       
  1097     return mailboxActive;
  1003 }
  1098 }
  1004 
  1099 
  1005 /*!
  1100 /*!
  1006     Delete all stored activity information for the mailbox id
  1101     Delete all stored activity information for the mailbox id
  1007     \param mailboxId id of the mailbox
  1102     \param mailboxId id of the mailbox
  1008 */
  1103 */
  1009 void NmMailAgent::deleteStoredMailboxActivity(const NmId &mailboxId)
  1104 void NmMailAgent::deleteStoredMailboxActivity(const NmId &mailboxId)
  1010 {
  1105 {
       
  1106     NM_FUNCTION;
       
  1107 
  1011     // deactivation delete the key too
  1108     // deactivation delete the key too
  1012     storeMailboxActive(mailboxId,false);
  1109     storeMailboxActive(mailboxId,false);
  1013 }
  1110 }
  1014 
  1111 
  1015 // End of file
  1112 // End of file
  1016