phoneplugins/infowidgetplugin/infowidget/src/infowidgetsathandler_p.cpp
branchRCL_3
changeset 24 41a7f70b3818
equal deleted inserted replaced
23:40a3f856b14d 24:41a7f70b3818
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:
       
    15  *
       
    16  */
       
    17 
       
    18 #include <fbs.h>
       
    19 #include "infowidgetsathandler_p.h"
       
    20 #include "infowidgetsathandler.h"
       
    21 #include "infowidgetlogging.h"
       
    22 
       
    23 /*!
       
    24   \class InfoWidgetSatHandlerPrivate
       
    25   \brief Private implementation of InfoWidgetSatHandler  
       
    26 */
       
    27 
       
    28 /*!
       
    29    Constructor. 
       
    30  */
       
    31 InfoWidgetSatHandlerPrivate::InfoWidgetSatHandlerPrivate(
       
    32         InfoWidgetSatHandler *satHandler, RSatService& satService)
       
    33     : CActive(CActive::EPriorityStandard), 
       
    34       m_satHandler(satHandler),
       
    35       m_satService(satService)
       
    36 {
       
    37     DPRINT;
       
    38     CActiveScheduler::Add(this);
       
    39 }
       
    40 
       
    41 /*!
       
    42    Desctuctor.            
       
    43 */
       
    44 InfoWidgetSatHandlerPrivate::~InfoWidgetSatHandlerPrivate()
       
    45 {
       
    46     DPRINT;
       
    47     Cancel();
       
    48 }
       
    49 
       
    50 /*!
       
    51    Connect RSatSession and open RSatService. 
       
    52  */
       
    53 bool InfoWidgetSatHandlerPrivate::connect()
       
    54 {
       
    55     TInt err( KErrNone );
       
    56     bool connected(false); 
       
    57     
       
    58     TRAP(err, m_satSession.ConnectL());
       
    59     if (KErrNone != err) {
       
    60         DCRITICAL << ": Exception occured while connecting SatSession:" << err;
       
    61     }
       
    62     else{
       
    63         TRAP(err, m_satService.OpenL(m_satSession));
       
    64         if (KErrNone != err) {
       
    65             DCRITICAL << ": Exception occured while opening SatService:" << err;
       
    66             m_satSession.Close(); 
       
    67         } else {
       
    68             connected = true; 
       
    69         }
       
    70     }
       
    71     
       
    72     return connected;
       
    73 }
       
    74 
       
    75 /*! 
       
    76    Gets initial content if any and starts 
       
    77    listening for changes.     
       
    78  */
       
    79 void InfoWidgetSatHandlerPrivate::startObserving()
       
    80 {
       
    81     // Not observing yet but
       
    82     getIdleModeData();
       
    83     // in case there were content, there is need to send response to SAT
       
    84     if (!m_idleTxt.isEmpty()) {
       
    85         m_satHandler->handleIdleModeTxtMessage(m_idleResult);
       
    86     }
       
    87     // Start observing for changes
       
    88     activate();
       
    89 }
       
    90 
       
    91 /*!
       
    92    Disconnect session(s) and reset idle text data.    
       
    93  */
       
    94 void InfoWidgetSatHandlerPrivate::disconnect()
       
    95 {
       
    96     DPRINT;
       
    97     m_idleTxt.clear();
       
    98     Cancel();
       
    99     m_satService.NotifySetupIdleModeTextChangeCancel(); 
       
   100     m_satService.Close();
       
   101     m_satSession.Close();
       
   102 }
       
   103 
       
   104 /*!
       
   105    Get idle mode text.   
       
   106  */
       
   107 void InfoWidgetSatHandlerPrivate::getIdleModeData()
       
   108 {
       
   109     DPRINT << ": IN"; 
       
   110     HBufC* string(NULL);
       
   111     TUint8 recordId(NULL);
       
   112     RSatService::TSatIconQualifier iconQualifier( 
       
   113         RSatService::ESatIconNoIcon );
       
   114     
       
   115     // Get setup idle mode text, icon qualifier and record id.
       
   116     TInt result(KErrNotFound);
       
   117     TRAP(result, m_satService.GetSetupIdleModeTextL(
       
   118             string, iconQualifier, recordId)); 
       
   119     
       
   120     if (0 != result) {
       
   121         DWARNING << ": Exception occured while GetSetupIdleModeTextL :" << result;
       
   122         m_idleResult = RSatService::ESATIdleMeUnableToProcessCmd;
       
   123     } else{
       
   124         if (RSatService::ESatIconSelfExplanatory != iconQualifier) { 
       
   125             m_idleTxt = QString((QChar*)string->Des().Ptr(), string->Length());
       
   126         }else {
       
   127             m_idleTxt.clear();
       
   128         }
       
   129         //Determine result
       
   130         if(RSatService::ESatIconNoIcon != iconQualifier
       
   131                 && !m_idleTxt.isEmpty()){
       
   132             // Icon requested but we don't have icon support
       
   133             m_idleResult = RSatService::ESATIdleSuccessRequestedIconNotDisplayed;
       
   134         }else if(RSatService::ESatIconNoIcon == iconQualifier
       
   135                 && !m_idleTxt.isEmpty()){
       
   136             m_idleResult = RSatService::ESATIdleSuccess;
       
   137         }else{ 
       
   138             // Got empty string, could be permanent problem as well?
       
   139             m_idleResult = RSatService::ESATIdleMeUnableToProcessCmd;
       
   140         }
       
   141     }
       
   142     delete string;
       
   143     
       
   144     // Text (m_idleTxt) is empty in case of selfexplanatory icon
       
   145     m_satHandler->setSatDisplayText(m_idleTxt); 
       
   146     DPRINT << ": OUT"; 
       
   147 }
       
   148 
       
   149 /*!
       
   150    InfoWidgetSatHandlerPrivate::RunL   
       
   151  */
       
   152 void InfoWidgetSatHandlerPrivate::RunL()
       
   153 { 
       
   154     DPRINT;
       
   155     if (KErrNone == iStatus.Int()) {   
       
   156         getIdleModeData();
       
   157         m_satHandler->handleIdleModeTxtMessage(m_idleResult);
       
   158     } else {
       
   159         m_satHandler->handleSatError(1, iStatus.Int());
       
   160     }
       
   161 
       
   162     if (!IsActive()) {
       
   163         activate();
       
   164     }       
       
   165 }
       
   166 
       
   167 /*!
       
   168    Cancel SetupIdleModeTextChange notify.     
       
   169  */
       
   170 void InfoWidgetSatHandlerPrivate::DoCancel()
       
   171 {
       
   172     DPRINT;
       
   173     m_satService.NotifySetupIdleModeTextChangeCancel(); 
       
   174 }
       
   175 
       
   176 /*!
       
   177    Start listening SetupIdleModeTextChange notify.    
       
   178  */
       
   179 void InfoWidgetSatHandlerPrivate::activate()
       
   180 {
       
   181     DPRINT;
       
   182     Cancel();   
       
   183     TInt error = m_satService.NotifySetupIdleModeTextChange(iStatus);
       
   184     
       
   185     if (KErrNone == error) {
       
   186         SetActive();
       
   187         }
       
   188 }
       
   189 
       
   190 // End of File. 
       
   191     
       
   192