phoneplugins/infowidgetplugin/infowidget/src/infowidgetsathandlerprivate.cpp
changeset 45 6b911d05207e
equal deleted inserted replaced
37:ba76fc04e6c2 45:6b911d05207e
       
     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 "infowidgetsathandlerprivate.h"
       
    20 #include "infowidgetsathandler.h"
       
    21 #include "infowidgetlogging.h"
       
    22 
       
    23 /*!
       
    24   \class InfoWidgetSatHandlerPrivate
       
    25   \brief Private implementation of InfoWidgetSatHandler  
       
    26 */
       
    27 
       
    28 /*!
       
    29    InfoWidgetSatHandlerPrivate::InfoWidgetSatHandlerPrivate   
       
    30  */
       
    31 InfoWidgetSatHandlerPrivate::InfoWidgetSatHandlerPrivate(
       
    32         InfoWidgetSatHandler *iwSatHandler, RSatService& satService)
       
    33     : CActive(CActive::EPriorityStandard), 
       
    34 	  q_ptr(iwSatHandler),
       
    35       m_satService(satService)
       
    36 {
       
    37     DPRINT << ": IN";
       
    38     CActiveScheduler::Add(this);
       
    39     DPRINT << ": OUT";
       
    40 }
       
    41 
       
    42 /*!
       
    43    InfoWidgetSatHandlerPrivate::~InfoWidgetSatHandlerPrivate           
       
    44 */
       
    45 InfoWidgetSatHandlerPrivate::~InfoWidgetSatHandlerPrivate()
       
    46 {
       
    47     DPRINT << ": IN";
       
    48     Cancel();
       
    49     DPRINT << ": OUT";
       
    50 }
       
    51 
       
    52 /*!
       
    53    InfoWidgetSatHandlerPrivate::connect
       
    54  */
       
    55 bool InfoWidgetSatHandlerPrivate::connect()
       
    56 {
       
    57     TInt err( KErrNone );
       
    58     bool connected(false); 
       
    59     
       
    60     TRAP(err, m_satSession.ConnectL());
       
    61     if (KErrNone != err) {
       
    62         DPRINT << ": Exception occured while connecting SatSession:" << err;
       
    63     }
       
    64     else{
       
    65         TRAP(err, m_satService.OpenL(m_satSession));
       
    66         if (KErrNone != err) {
       
    67             DCRITICAL << ": Exception occured while opening SatService:" << err;
       
    68             DCRITICAL << ": closing SAT session"; 
       
    69             m_satSession.Close(); 
       
    70         } else {
       
    71             connected = true; 
       
    72         }
       
    73     }
       
    74     
       
    75     return connected;
       
    76 }
       
    77 
       
    78 /*! 
       
    79    InfoWidgetSatHandlerPrivate::startObserving
       
    80     
       
    81    To get initial content if any and start listening    
       
    82  */
       
    83 void InfoWidgetSatHandlerPrivate::startObserving()
       
    84 {
       
    85     //not observing yet but
       
    86     getIdleModeData();
       
    87     // in case there were content, there is need to send response to SAT
       
    88     if(!m_idleTxt.isEmpty()){
       
    89         q_ptr->handleIdleModeTxtMessage( m_idleResult );
       
    90     }
       
    91     // Start observing for changes
       
    92     activate();
       
    93 }
       
    94 
       
    95 /*!
       
    96    InfoWidgetSatHandlerPrivate::disconnect   
       
    97  */
       
    98 int InfoWidgetSatHandlerPrivate::disconnect()
       
    99 {
       
   100     DPRINT << ": IN";
       
   101     m_idleTxt = "";
       
   102     Cancel();
       
   103     m_satService.NotifySetupIdleModeTextChangeCancel(); 
       
   104     m_satService.Close();
       
   105     m_satSession.Close();
       
   106     
       
   107     DPRINT << ": OUT";
       
   108     return 0;//TODO:Fixme
       
   109 }
       
   110 
       
   111 /*!
       
   112    InfoWidgetSatHandlerPrivate::getIdleModeData   
       
   113  */
       
   114 void InfoWidgetSatHandlerPrivate::getIdleModeData()
       
   115 {
       
   116     HBufC* string( NULL );
       
   117     TUint8 recordId( NULL );
       
   118     RSatService::TSatIconQualifier iconQualifier( 
       
   119         RSatService::ESatIconNoIcon );
       
   120     
       
   121     // Get setup idle mode text, icon qualifier and record id.
       
   122     TInt result( KErrNotFound  );
       
   123     TRAP(result, m_satService.GetSetupIdleModeTextL( string, iconQualifier, recordId )); 
       
   124     if (0 != result) {
       
   125         DPRINT << ": Exception occured while GetSetupIdleModeTextL :" << result;
       
   126         m_idleResult = RSatService::ESATIdleMeUnableToProcessCmd;
       
   127     }
       
   128     else{
       
   129         DPRINT << "string->Length() : " << string->Length();
       
   130         if(RSatService::ESatIconSelfExplanatory != iconQualifier){ 
       
   131             m_idleTxt = QString((QChar*)string->Des().Ptr(), string->Length());
       
   132         }else{
       
   133             m_idleTxt = "";
       
   134         }
       
   135         //determine result
       
   136         if(RSatService::ESatIconNoIcon != iconQualifier
       
   137                 && !m_idleTxt.isEmpty()){
       
   138             //icon requested but we don't have icon support
       
   139             m_idleResult = RSatService::ESATIdleSuccessRequestedIconNotDisplayed;
       
   140         }else if(RSatService::ESatIconNoIcon == iconQualifier
       
   141                 && !m_idleTxt.isEmpty()){
       
   142             m_idleResult = RSatService::ESATIdleSuccess;
       
   143         }else{ //got empty string, could be permanen problem as well?
       
   144             //m_idleResult = RSatService::ESATIdleCmdBeyondMeCapabilities
       
   145             m_idleResult = RSatService::ESATIdleMeUnableToProcessCmd;
       
   146         }
       
   147     }
       
   148     delete string;
       
   149     q_ptr->setSatDisplayText(m_idleTxt);//empty in case of selexplanatory icon
       
   150 }
       
   151 
       
   152 /*!
       
   153    InfoWidgetSatHandlerPrivate::RunL   
       
   154  */
       
   155 void InfoWidgetSatHandlerPrivate::RunL()
       
   156 { 
       
   157     DPRINT << ": IN";
       
   158     if ( KErrNone == iStatus.Int() )
       
   159         {   
       
   160         getIdleModeData();
       
   161         q_ptr->handleIdleModeTxtMessage( m_idleResult );
       
   162     } else {
       
   163         q_ptr->handleSatError(1,iStatus.Int());
       
   164     }
       
   165     if ( !IsActive() )
       
   166         {
       
   167         activate();
       
   168         }       
       
   169     DPRINT << ": OUT";
       
   170 }
       
   171 
       
   172 /*!
       
   173    InfoWidgetSatHandlerPrivate::DoCancel   
       
   174  */
       
   175 void InfoWidgetSatHandlerPrivate::DoCancel()
       
   176 {
       
   177     DPRINT << ": IN";
       
   178     m_satService.NotifySetupIdleModeTextChangeCancel(); 
       
   179     DPRINT << ": OUT";
       
   180 }
       
   181 
       
   182 /*!
       
   183    InfoWidgetSatHandlerPrivate::activate   
       
   184  */
       
   185 void InfoWidgetSatHandlerPrivate::activate()
       
   186 {
       
   187     DPRINT << ": IN";
       
   188     Cancel();   
       
   189     TInt error = m_satService.NotifySetupIdleModeTextChange( iStatus );
       
   190     
       
   191     if ( KErrNone == error )
       
   192         {
       
   193         SetActive();
       
   194         }
       
   195     DPRINT << ": OUT";
       
   196 }
       
   197 
       
   198 // End of File. 
       
   199     
       
   200