iaupdate/IAD/backgroundchecker/src/iaupdatebgsoftnotification.cpp
branchRCL_3
changeset 26 8b7f4e561641
parent 25 7333d7932ef7
equal deleted inserted replaced
25:7333d7932ef7 26:8b7f4e561641
     1 /*
     1 /*
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 
    19 
    20 // INCLUDE FILES
    20 // INCLUDE FILES
    21 #include <hbindicatorsymbian.h>
    21 #include <AknDynamicSoftNotifier.h>
    22 #include <hbsymbianvariant.h>
    22 #include <AknDynamicSoftNotificationParams.h>
    23 
    23 
    24 #include "iaupdatebgsoftnotification.h"
    24 #include "iaupdatebgsoftnotification.h"
    25 #include "iaupdatebginternalfilehandler.h"
    25 #include "iaupdatebginternalfilehandler.h"
    26 #include "iaupdatebgconst.h"
    26 #include "iaupdatebgconst.h"
    27 #include "iaupdatebglogger.h"
    27 #include "iaupdatebglogger.h"
    28 
    28 
    29 // Indicator type
       
    30 _LIT(KIndicatorTypeBgc, "com.nokia.iaupdate.indicatorplugin/1.0");
       
    31 
    29 
    32 // ============================ MEMBER FUNCTIONS ===============================
    30 // ============================ MEMBER FUNCTIONS ===============================
    33 void CIAUpdateBGSoftNotification::NotificationDialogActivated(
       
    34         const CHbDeviceNotificationDialogSymbian* /* aDialog */)
       
    35     {
       
    36     
       
    37     FLOG("[bgchecker] softnotification callback function ACCEPTED");
       
    38     
       
    39     // indicator shall not be shown 
       
    40     SetIndicatorEnabled( EFalse );
       
    41     
       
    42     // Remove (possibly) existing indicator
       
    43     RemoveIndicatorL();
       
    44     
       
    45     iCallback->SoftNotificationCallBack( ETrue );
       
    46     
       
    47     // remove dialog
       
    48     //delete iNotificationDialog;
       
    49     //iNotificationDialog = 0;
       
    50     
       
    51     return;
       
    52     }
       
    53 
       
    54 void CIAUpdateBGSoftNotification::NotificationDialogClosed
       
    55          ( const CHbDeviceNotificationDialogSymbian* /* aDialog */, 
       
    56            TInt /* aCompletionCode*/ )
       
    57     {
       
    58     
       
    59     
       
    60     FLOG("[bgchecker] softnotification callback function Closed");
       
    61 
       
    62     // Set indicator, if needed
       
    63     if (IsIndicatorEnabled())
       
    64         {
       
    65         ShowIndicatorL();
       
    66         }
       
    67     
       
    68     
       
    69     iCallback->SoftNotificationCallBack( EFalse );
       
    70     
       
    71     // remove dialog
       
    72     //delete iNotificationDialog;
       
    73     //iNotificationDialog = 0;
       
    74     
       
    75     return;
       
    76     }
       
    77 
       
    78 
       
    79 // -----------------------------------------------------------------------------
    31 // -----------------------------------------------------------------------------
    80 // CIAUpdateBGSoftNotification::NewLC
    32 // CIAUpdateBGSoftNotification::NewLC
    81 // Static constructor
    33 // Static constructor
    82 // -----------------------------------------------------------------------------
    34 // -----------------------------------------------------------------------------
    83 //
    35 //
    84 CIAUpdateBGSoftNotification* CIAUpdateBGSoftNotification::NewL( 
    36 CIAUpdateBGSoftNotification* CIAUpdateBGSoftNotification::NewL( MIAUpdateBGSoftNotificationCallBack* aCallback, 
    85         MIAUpdateBGSoftNotificationCallBack* aCallback ) 
    37                                                                 CIAUpdateBGInternalFileHandler* aInternalFile )
    86     {   
    38     {   
    87     CIAUpdateBGSoftNotification* self =
    39     CIAUpdateBGSoftNotification* self =
    88         new ( ELeave ) CIAUpdateBGSoftNotification( aCallback );
    40         new ( ELeave ) CIAUpdateBGSoftNotification( aCallback, aInternalFile );
    89     CleanupStack::PushL( self );
    41     CleanupStack::PushL( self );
    90     
    42     
    91     self->ConstructL();
    43     self->ConstructL();
    92     CleanupStack::Pop( self );
    44     CleanupStack::Pop( self );
    93     
    45     
    98 // Destructor
    50 // Destructor
    99 // -----------------------------------------------------------------------------
    51 // -----------------------------------------------------------------------------
   100 //
    52 //
   101 CIAUpdateBGSoftNotification::~CIAUpdateBGSoftNotification()
    53 CIAUpdateBGSoftNotification::~CIAUpdateBGSoftNotification()
   102     {
    54     {
   103 
    55     delete iSoftkey1;
   104     delete iTitle;
    56     delete iSoftkey2;
   105     delete iText;
    57 
   106     
    58     delete iLabel;
   107     delete iNotificationDialog;
    59     delete iGroupLabel;
   108 
    60 
   109     }
    61     delete iImageData;
   110    
    62 
   111 // -----------------------------------------------------------------------------
    63     delete iNotifier;
   112 // CIAUpdateBGSoftNotification::ShowNotificationL
    64     }
   113 // Displays notification
    65 
   114 // -----------------------------------------------------------------------------
    66 // -----------------------------------------------------------------------------
   115 //
    67 // CIAUpdateBGSoftNotification::NotificationAccepted
   116 void CIAUpdateBGSoftNotification::ShowNotificationL()
    68 // Dynamic soft notification was accepted by user.
   117     {
    69 // -----------------------------------------------------------------------------
   118     
    70 //
   119     FLOG("[bgchecker] ShowNotificationL");
    71 void CIAUpdateBGSoftNotification::NotificationAccepted( TInt /*aIdentifier*/ )
   120     
    72     {
   121     // crete dialog, id does not exist already
    73     FLOG("[bgchecker] softnotification callback function ACCEPTED");
   122     if (!iNotificationDialog)
    74     //remove the soft notifiation id
   123         {
    75     iInternalFile->SetSoftNotificationID( 0 );
   124         iNotificationDialog = CHbDeviceNotificationDialogSymbian::NewL( this );
    76     TRAP_IGNORE( iInternalFile->WriteControllerDataL() );
   125         }
    77     
   126     
    78     iCallback->SoftNotificationCallBack( ETrue );
   127     // enable indicator showing
    79     }
   128     SetIndicatorEnabled( ETrue );
    80 
   129 
    81 // -----------------------------------------------------------------------------
   130     // fill texts, icon & behaviour parameters
    82 // CIAUpdateBGSoftNotification::NotificationCanceled
   131     FillNotificationParams();
    83 // Dynamic soft notification was canceled by user.
   132     
    84 // -----------------------------------------------------------------------------
   133     iNotificationDialog->ShowL();
    85 //
   134     
    86 void CIAUpdateBGSoftNotification::NotificationCanceled( TInt /*aIdentifier*/ )
   135     return;
    87     {
   136     
    88     FLOG("[bgchecker] softnotification callback function Canceled");
   137     }
    89     //remove the soft notifiation id
   138 
    90     iInternalFile->SetSoftNotificationID( 0 );
   139 // -----------------------------------------------------------------------------
    91     TRAP_IGNORE( iInternalFile->WriteControllerDataL() );
   140 // CIAUpdateBGSoftNotification::ShowIndicatorL
    92           
   141 // Displays indicator
    93     iCallback->SoftNotificationCallBack( EFalse );
   142 // -----------------------------------------------------------------------------
    94     }
   143 //
    95     
   144 void CIAUpdateBGSoftNotification::ShowIndicatorL()
    96 // -----------------------------------------------------------------------------
   145     {
    97 // CIAUpdateBGSoftNotification::ShowSoftNotificationL
   146     
    98 // Displays a soft notification
   147     FLOG("[bgchecker] ShowIndicatorL");
    99 // -----------------------------------------------------------------------------
   148     
   100 //
   149     CHbIndicatorSymbian *ind = CHbIndicatorSymbian::NewL();
   101 void CIAUpdateBGSoftNotification::ShowSoftNotificationL()
   150     CleanupStack::PushL( ind );
   102     {
   151             
   103     TAknDynamicSoftNotificationParams param( KSoftNotificationPriority );
   152     TInt value = GetNrOfUpdates();
   104     FillNotificationParams( param );
   153             
   105     
   154     // Set indicator
   106     TInt oldId = iNotificationId;
   155     CHbSymbianVariant* varValue = CHbSymbianVariant::NewL( &value,
   107     iNotificationId =
   156         CHbSymbianVariant::EInt );
   108         iNotifier->SetDynamicNotificationCountL( param, iNotificationId, 1 );
   157     CleanupStack::PushL( varValue );
   109 
   158     // Temporary removal 
   110     if( oldId != iNotificationId )
   159     ind->Activate( KIndicatorTypeBgc, varValue );
   111         {           
   160     CleanupStack::PopAndDestroy( varValue );
   112         FLOG("[bgchecker] softnotification save notification Id");
   161     CleanupStack::PopAndDestroy( ind );
   113         iInternalFile->SetSoftNotificationID( iNotificationId );
   162     
   114         TRAP_IGNORE( iInternalFile->WriteControllerDataL() );
   163     return;
   115         
   164     
   116         iNotifier->StopObserving( oldId );
   165     }
   117         iNotifier->StartObservingL( iNotificationId, this );
   166 
   118         }
   167 // -----------------------------------------------------------------------------
   119     }
   168 // CIAUpdateBGSoftNotification::Remove indicator
   120 
   169 // Removes indicator
   121 // -----------------------------------------------------------------------------
   170 // -----------------------------------------------------------------------------
   122 // CIAUpdateBGSoftNotification::RemoveSoftNotificationL
   171 //
   123 // Cancels and removes the soft notification
   172 void CIAUpdateBGSoftNotification::RemoveIndicatorL()
   124 // -----------------------------------------------------------------------------
   173     {
   125 //
   174     
   126 void CIAUpdateBGSoftNotification::RemoveSoftNotificationL( TInt aNotifierId )
   175     FLOG("[bgchecker] RemoveIndicatorL");
   127     {
   176     
   128     if ( aNotifierId != 0 )
   177     CHbIndicatorSymbian *ind = CHbIndicatorSymbian::NewL();
   129         {
   178     CleanupStack::PushL( ind );
   130         iNotifier->CancelDynamicNotificationL( aNotifierId );
   179     // Temporary removal 
   131         }
   180     ind->Deactivate( KIndicatorTypeBgc ); 
       
   181     CleanupStack::PopAndDestroy(ind);
       
   182     
       
   183     return;
       
   184     
       
   185     }
   132     }
   186 
   133 
   187 // -----------------------------------------------------------------------------
   134 // -----------------------------------------------------------------------------
   188 // CIAUpdateBGSoftNotification::SetTextL
   135 // CIAUpdateBGSoftNotification::SetTextL
   189 // Sets a text for a soft notification
   136 // Sets a text for a soft notification
   190 // -----------------------------------------------------------------------------
   137 // -----------------------------------------------------------------------------
   191 //
   138 //
   192 void CIAUpdateBGSoftNotification::SetTextL( 
   139 void CIAUpdateBGSoftNotification::SetTextL( const TDesC& aText, const TDesC& aGroupText )
   193         const TDesC& aTitle, const TDesC& aText )
   140     {
   194     {
   141     HBufC* txt = aText.AllocL();
   195     HBufC* txt = aTitle.AllocL();
   142     delete iLabel;
   196     delete iTitle;
   143     iLabel = txt;
   197     iTitle = txt;
   144 
   198 
   145     txt = aGroupText.AllocL();
   199     txt = aText.AllocL();
   146     delete iGroupLabel;
   200     delete iText;
   147     iGroupLabel = txt;
   201     iText = txt;
   148     }
   202     }
   149 
   203 
   150 // -----------------------------------------------------------------------------
   204 // -----------------------------------------------------------------------------
   151 // CIAUpdateBGSoftNotification::SetSoftkeyLabelsL
   205 // CIAUpdateBGSoftNotification::SetNrOfUpdates
   152 // Sets new labels for softkeys
   206 // Sets an image path for a soft notification
   153 // -----------------------------------------------------------------------------
   207 // -----------------------------------------------------------------------------
   154 //
   208 //
   155 void CIAUpdateBGSoftNotification::SetSoftkeyLabelsL(
   209 void CIAUpdateBGSoftNotification::SetNrOfUpdates( const TInt& aNrOfUpdates)
   156     const TDesC& aSoftkey1Label,
   210     {
   157     const TDesC& aSoftkey2Label )
   211     // save number of updates
   158     {
   212     iNrOfUpdates = aNrOfUpdates;
   159     HBufC* txt = aSoftkey1Label.AllocL();
   213     return;
   160     delete iSoftkey1;
   214     }
   161     iSoftkey1 = txt;
       
   162 
       
   163     txt = aSoftkey2Label.AllocL();
       
   164     delete iSoftkey2;
       
   165     iSoftkey2 = txt;
       
   166     }
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // CIAUpdateBGSoftNotification::SetImageL
       
   170 // Sets an image for a soft notification
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 void CIAUpdateBGSoftNotification::SetImageL(
       
   174     const TDesC8& aImage )
       
   175     {
       
   176     HBufC8* image = aImage.AllocL();
       
   177     delete iImageData;
       
   178     iImageData = image;
       
   179     }
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CIAUpdateBGSoftNotification::Id
       
   183 // Notification Id
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 TInt CIAUpdateBGSoftNotification::Id()
       
   187     {
       
   188     return iNotificationId;
       
   189     }
       
   190 
   215 // -----------------------------------------------------------------------------
   191 // -----------------------------------------------------------------------------
   216 // CIAUpdateBGSoftNotification::ConstructL
   192 // CIAUpdateBGSoftNotification::ConstructL
   217 // Symbian 2nd phase constructor can leave.
   193 // Symbian 2nd phase constructor can leave.
   218 // -----------------------------------------------------------------------------
   194 // -----------------------------------------------------------------------------
   219 //
   195 //
   220 void CIAUpdateBGSoftNotification::ConstructL()
   196 void CIAUpdateBGSoftNotification::ConstructL()
   221     {
   197     {
   222     FLOG("[bgchecker] softnotification ConstructL");
   198     FLOG("[bgchecker] softnotification ConstructL");
       
   199     iNotifier = CAknDynamicSoftNotifier::NewL();
       
   200     
       
   201     iInternalFile->ReadControllerDataL();
       
   202     iNotificationId = iInternalFile->SoftNotificationID();
       
   203       
   223     }
   204     }
   224 
   205 
   225 // -----------------------------------------------------------------------------
   206 // -----------------------------------------------------------------------------
   226 // CIAUpdateBGSoftNotification::CIAUpdateBGSoftNotification
   207 // CIAUpdateBGSoftNotification::CIAUpdateBGSoftNotification
   227 // C++ default constructor can NOT contain any code, that
   208 // C++ default constructor can NOT contain any code, that
   228 // might leave.
   209 // might leave.
   229 // -----------------------------------------------------------------------------
   210 // -----------------------------------------------------------------------------
   230 //
   211 //
   231 CIAUpdateBGSoftNotification::CIAUpdateBGSoftNotification( 
   212 CIAUpdateBGSoftNotification::CIAUpdateBGSoftNotification( MIAUpdateBGSoftNotificationCallBack* aCallback, 
   232         MIAUpdateBGSoftNotificationCallBack* aCallback )
   213                                                           CIAUpdateBGInternalFileHandler* aInternalFile ) 
   233     : iCallback ( aCallback )
   214     : iCallback ( aCallback ), iInternalFile ( aInternalFile )
   234     {
   215     {
       
   216     }
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // CIAUpdateBGSoftNotification::StartObservingIfNeededL
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 void CIAUpdateBGSoftNotification::StartObservingIfNeededL()
       
   223     {
       
   224     if ( iNotificationId )
       
   225         {
       
   226         FLOG("[bgchecker] softnotification There is a buffered softnotification");
       
   227         //a buffering soft notification
       
   228         iNotifier->StartObservingL( iNotificationId, this );
       
   229         }
   235     }
   230     }
   236 
   231 
   237 // -----------------------------------------------------------------------------
   232 // -----------------------------------------------------------------------------
   238 // CIAUpdateBGSoftNotification::FillNotificationParams
   233 // CIAUpdateBGSoftNotification::FillNotificationParams
   239 // -----------------------------------------------------------------------------
   234 // -----------------------------------------------------------------------------
   240 //
   235 //
   241 
   236 void CIAUpdateBGSoftNotification::FillNotificationParams(
   242 void CIAUpdateBGSoftNotification::FillNotificationParams()
   237     TAknDynamicSoftNotificationParams& aParam )
   243     {
   238     {
   244     
   239     if( iSoftkey1 && iSoftkey2 )
   245     // set title, text and icon
   240         {
   246     if ( iTitle )
   241         aParam.SetSoftkeys( *iSoftkey1, *iSoftkey2 );
   247         {
   242         }
   248         iNotificationDialog->SetTitleL(iTitle->Des());
   243 
   249         }
   244     if( iLabel )
   250     
   245         {
   251     if ( iText )
   246         aParam.SetNoteLabels( *iLabel, *iLabel );
   252         {
   247         }
   253         iNotificationDialog->SetTextL(iText->Des());
   248 
   254         }
   249     if( iGroupLabel )
   255     
   250         {
   256     // set wrapping, timeout and touch 
   251         //aParam.SetGroupLabels( *iGroupLabel, *iGroupLabel );
   257     iNotificationDialog->SetTitleTextWrapping(
   252         }
   258             CHbDeviceNotificationDialogSymbian::TextWordWrap);
   253 
   259     iNotificationDialog->SetTimeout(4000); //default 3000
   254     if( iImageData )
   260     iNotificationDialog->EnableTouchActivation(ETrue); // default FALSE
   255         {
   261   
   256         aParam.SetImageData( *iImageData );
   262     }  
   257         }
   263 // ----------------------------------------------------------
   258     
   264 // CIAUpdateBGSoftNotification::EnableIndicator(TBool aEnabled)
   259     aParam.EnableObserver();
   265 // ----------------------------------------------------------
       
   266 void CIAUpdateBGSoftNotification::SetIndicatorEnabled( TBool aEnabled )
       
   267     {
       
   268     
       
   269     iActivateIndicator = aEnabled;
       
   270     
       
   271     }
       
   272 
       
   273 // ----------------------------------------------------------
       
   274 // CIAUpdateBGSoftNotification::IndicatorEnabled()
       
   275 // ----------------------------------------------------------
       
   276 TBool CIAUpdateBGSoftNotification::IsIndicatorEnabled()
       
   277     {
       
   278     
       
   279     return iActivateIndicator;
       
   280     
       
   281     }
       
   282 
       
   283 // ----------------------------------------------------------
       
   284 // CIAUpdateBGSoftNotification::GetNrOfUpdates()
       
   285 // ----------------------------------------------------------
       
   286 int CIAUpdateBGSoftNotification::GetNrOfUpdates()
       
   287     {
       
   288     
       
   289     return iNrOfUpdates;
       
   290     
       
   291     }
   260     }
   292 
   261 
   293 //  End of File
   262 //  End of File