messagingapp/msgnotifications/msgnotifier/src/msgnotifier_p.cpp
changeset 27 e4592d119491
parent 25 84d9eb65b26f
child 47 5b14749788d7
equal deleted inserted replaced
25:84d9eb65b26f 27:e4592d119491
    21 #include <ccsclientconversation.h>
    21 #include <ccsclientconversation.h>
    22 #include <ccsrequesthandler.h>
    22 #include <ccsrequesthandler.h>
    23 #include <ccsconversationentry.h>
    23 #include <ccsconversationentry.h>
    24 #include <xqservicerequest.h>
    24 #include <xqservicerequest.h>
    25 #include <QString>
    25 #include <QString>
       
    26 #include <w32std.h>
       
    27 #include <APGTASK.H> 
       
    28 #include <XQSettingsManager>
       
    29 #include <xqpublishandsubscribeutils.h>
    26 
    30 
    27 //USER INCLUDES
    31 //USER INCLUDES
    28 #include "msgnotifier.h"
    32 #include "msgnotifier.h"
    29 #include "msgnotifier_p.h"
    33 #include "msgnotifier_p.h"
    30 #include "s60qconversions.h"
    34 #include "s60qconversions.h"
    31 #include "msgstorehandler.h"
    35 #include "msgstorehandler.h"
    32 #include "msginfodefs.h"
    36 #include "msginfodefs.h"
    33 #include <QtDebug>
    37 #include "conversationidpsconsts.h"
    34 
    38 #include "debugtraces.h"
    35 #define QDEBUG_WRITE(str) {qDebug() << str;}
    39 
    36 #define QDEBUG_WRITE_FORMAT(str, val) {qDebug() << str << val;}
       
    37 #define QCRITICAL_WRITE(str) {qCritical() << str;}
       
    38 #define QCRITICAL_WRITE_FORMAT(str, val) {qCritical() << str << val;}
       
    39 
    40 
    40 // ----------------------------------------------------------------------------
    41 // ----------------------------------------------------------------------------
    41 // MsgNotifierPrivate::MsgNotifierPrivate
    42 // MsgNotifierPrivate::MsgNotifierPrivate
    42 // @see MsgNotifierPrivate.h
    43 // @see MsgNotifierPrivate.h
    43 // ----------------------------------------------------------------------------
    44 // ----------------------------------------------------------------------------
    44 MsgNotifierPrivate::MsgNotifierPrivate(MsgNotifier* MsgNotifier) :
    45 MsgNotifierPrivate::MsgNotifierPrivate(MsgNotifier* MsgNotifier) :
    45     q_ptr(MsgNotifier), mCvServer(NULL), iMsgStoreHandler(NULL)
    46     q_ptr(MsgNotifier), mCvServer(NULL), iMsgStoreHandler(NULL),
       
    47     mSettingsManager(NULL),mPSUtils(NULL)
    46 {
    48 {
    47     QDEBUG_WRITE("MsgNotifierPrivate::MsgNotifierPrivate : Enter")
    49     QDEBUG_WRITE("MsgNotifierPrivate::MsgNotifierPrivate : Enter")
    48 
    50 
    49     TRAP_IGNORE(initL());
    51     TRAP_IGNORE(initL());
    50     QDEBUG_WRITE("MsgNotifierPrivate::MsgNotifierPrivate : Exit")
    52     QDEBUG_WRITE("MsgNotifierPrivate::MsgNotifierPrivate : Exit")
    65 
    67 
    66     if (iMsgStoreHandler) {
    68     if (iMsgStoreHandler) {
    67         delete iMsgStoreHandler;
    69         delete iMsgStoreHandler;
    68         iMsgStoreHandler = NULL;
    70         iMsgStoreHandler = NULL;
    69     }
    71     }
       
    72     
       
    73     if(mPSUtils)
       
    74         {
       
    75         delete mPSUtils;
       
    76         }
       
    77     
       
    78     if(mSettingsManager)
       
    79         {
       
    80         delete mSettingsManager;
       
    81         }
       
    82     
    70     QDEBUG_WRITE("MsgNotifierPrivate::~MsgNotifierPrivate : Exit")
    83     QDEBUG_WRITE("MsgNotifierPrivate::~MsgNotifierPrivate : Exit")
    71 }
    84 }
    72 
    85 
    73 // ----------------------------------------------------------------------------
    86 // ----------------------------------------------------------------------------
    74 // MsgNotifierPrivate::initL
    87 // MsgNotifierPrivate::initL
    82     mCvServer->RequestConversationListChangeEventL(this);
    95     mCvServer->RequestConversationListChangeEventL(this);
    83     iMsgStoreHandler = new MsgStoreHandler(this, mCvServer);
    96     iMsgStoreHandler = new MsgStoreHandler(this, mCvServer);
    84     updateUnreadIndications(true); 
    97     updateUnreadIndications(true); 
    85     updateOutboxIndications();
    98     updateOutboxIndications();
    86 
    99 
       
   100     mSettingsManager = new XQSettingsManager();
       
   101     
       
   102     // define property
       
   103     mPSUtils = new XQPublishAndSubscribeUtils(*mSettingsManager);
       
   104     XQPublishAndSubscribeSettingsKey convIdKey(
       
   105             KMsgCVIdProperty, KMsgCVIdKey);
       
   106     bool success = mPSUtils->defineProperty(convIdKey, 
       
   107                             XQSettingsManager::TypeInt);
       
   108     
       
   109     QDEBUG_WRITE_FORMAT("MsgNotifierPrivate::initL "
       
   110                         "property creation ret value",success)
       
   111     
       
   112     // write -1 initially 
       
   113     success = mSettingsManager->writeItemValue(convIdKey,-1);
       
   114     
       
   115     QDEBUG_WRITE_FORMAT("MsgNotifierPrivate::initL "
       
   116                            "writing ret value",success)
       
   117     
    87     QDEBUG_WRITE("MsgNotifierPrivate::initL : Exit")
   118     QDEBUG_WRITE("MsgNotifierPrivate::initL : Exit")
    88 }
   119 }
    89 
   120 
    90 // ----------------------------------------------------------------------------
   121 // ----------------------------------------------------------------------------
    91 // MsgNotifierPrivate::AddConversationList
   122 // MsgNotifierPrivate::AddConversationList
   183         if(descrp)
   214         if(descrp)
   184             {
   215             {
   185             notifData.mDescription = S60QConversions::s60DescToQString(*descrp);
   216             notifData.mDescription = S60QConversions::s60DescToQString(*descrp);
   186             }
   217             }
   187         
   218         
   188         q_ptr->displayNewMessageNotification(notifData);
   219         // check whether opened cv id and received 
   189         
   220         // cv id are same and show notification
   190         QDEBUG_WRITE("processListEntry : Notification display called")
   221         if( showNotification(notifData.mConversationId ))
       
   222             {
       
   223              q_ptr->displayNewMessageNotification(notifData);
       
   224              QDEBUG_WRITE("processListEntry : Notification display called")
       
   225             }
       
   226        
   191         }
   227         }
   192     
   228     
   193     QDEBUG_WRITE("MsgNotifierPrivate::processListEntry : Exit")
   229     QDEBUG_WRITE("MsgNotifierPrivate::processListEntry : Exit")
   194     }
   230     }
   195 
   231 
   285     snd.send();
   321     snd.send();
   286     QDEBUG_WRITE("[MsgNotifierPrivate::handleFailedState] : left")
   322     QDEBUG_WRITE("[MsgNotifierPrivate::handleFailedState] : left")
   287 
   323 
   288 }
   324 }
   289 
   325 
       
   326 // ----------------------------------------------------------------------------
       
   327 // MsgNotifierPrivate::showNotification
       
   328 // @see MsgNotifierPrivate.h
       
   329 // ----------------------------------------------------------------------------
       
   330 bool MsgNotifierPrivate::showNotification(int receivedMsgConvId)
       
   331 {
       
   332     bool showNotification = true;
       
   333     
       
   334     RWsSession wsSession ;
       
   335     wsSession.Connect();
       
   336 
       
   337     TApaTaskList taskList( wsSession );
       
   338     TApaTask task = taskList.FindApp(KMsgAppUid); // find msgapp is running
       
   339 
       
   340     if(task.Exists())
       
   341         {
       
   342         TApaTask foregndtask =   taskList.FindByPos(0) ;  // foreground app
       
   343         // compare  window group id  
       
   344         // if application is in foregorund, then check the currently
       
   345         // opened conversation is same as received one.
       
   346         if(task.WgId() == foregndtask.WgId() )
       
   347             {
       
   348             // get the current conversation ID
       
   349             XQPublishAndSubscribeSettingsKey convIdKey( KMsgCVIdProperty, 
       
   350                     KMsgCVIdKey);
       
   351             QVariant value = mSettingsManager->readItemValue(convIdKey, 
       
   352                     XQSettingsManager::TypeInt);
       
   353 
       
   354             int openedConvId  = value.toInt();
       
   355             if( openedConvId == receivedMsgConvId)
       
   356                 {
       
   357                 showNotification = false;
       
   358                 QDEBUG_WRITE("processListEntry : Notification not shown")
       
   359                 }
       
   360             }
       
   361         }
       
   362 
       
   363     wsSession.Close();
       
   364     return showNotification;
       
   365 }
   290 //EOF
   366 //EOF