logsui/LogsIndicatorPlugin/CLogsIndicatorPlugin.cpp
changeset 0 e686773b3f54
child 68 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002 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 *     Ecom plugin to implement touch support for universal missed calls indicator. 
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "CLogsIndicatorPlugin.h"
       
    23 
       
    24 #include <apacmdln.h>  // -> For CApaCommandLine 
       
    25 #include <apgcli.h>
       
    26 #include <apgtask.h>
       
    27 
       
    28 #include <LogsUiCmdStarter.h>
       
    29 
       
    30 #include <StringLoader.h> 
       
    31 #include <Logs.rsg>
       
    32 #include <AknUtils.h>
       
    33 #include <LogsDomainCRKeys.h>
       
    34 
       
    35 #include <AknPreviewPopUpController.h>
       
    36 #include <centralrepository.h>   
       
    37 #include <bautils.h>
       
    38 #include <pathinfo.h>
       
    39 
       
    40 #include "LogsDebug.h"
       
    41 
       
    42 
       
    43 #include <data_caging_path_literals.hrh> // KDC_APP_RESOURCE_DIR
       
    44 
       
    45 
       
    46 // CONSTANTS
       
    47 
       
    48 // LogsIndicator.RSS is included in Logs.RSS and compiled to Logs.RSC.
       
    49 // Needed for the resource strings.
       
    50 _LIT( KIndicatorResourceFile, "Logs.RSC" );  
       
    51 
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // CLogsIndicatorPlugin::NewL
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CLogsIndicatorPlugin* CLogsIndicatorPlugin::NewL()
       
    58     {
       
    59     CLogsIndicatorPlugin* self = new( ELeave ) CLogsIndicatorPlugin;
       
    60     CleanupStack::PushL( self );
       
    61     self->ConstructL();
       
    62     CleanupStack::Pop( self );
       
    63     return self;
       
    64     }
       
    65     
       
    66     
       
    67 // ---------------------------------------------------------------------------
       
    68 // CLogsIndicatorPlugin::ConstructL
       
    69 // Symbian 2nd phase constructor can leave.
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 void CLogsIndicatorPlugin::ConstructL()
       
    73     {
       
    74     // Access to Central repository is needed to later retrieve
       
    75     // the number of missed calls     
       
    76     iRepositoryLogs    = CRepository::NewL( KCRUidLogs );
       
    77     
       
    78     iNotifyHandlerLogs = CCenRepNotifyHandler::NewL
       
    79         (*this, *iRepositoryLogs, CCenRepNotifyHandler::EIntKey, KLogsNewMissedCalls);
       
    80         
       
    81     iNotifyHandlerLogs->StartListeningL();
       
    82  
       
    83     // Read resource strings    
       
    84     CCoeEnv* env = CCoeEnv::Static();
       
    85     
       
    86     if( !iResourceFileOffset )
       
    87         {
       
    88         TFileName* resFile = new( ELeave )TFileName( 
       
    89             TParsePtrC( PathInfo::RomRootPath() ).Drive() );
       
    90         CleanupStack::PushL( resFile );
       
    91         resFile->Append( KDC_APP_RESOURCE_DIR );
       
    92         resFile->Append( KIndicatorResourceFile );
       
    93 
       
    94         BaflUtils::NearestLanguageFile( env->FsSession(), *resFile );
       
    95         iResourceFileOffset = env->AddResourceFileL( *resFile );
       
    96 
       
    97         CleanupStack::PopAndDestroy( resFile );
       
    98         }
       
    99    
       
   100     iPopupHeading =         env->AllocReadResourceL( R_QTN_LOGS_STYLUS_POPUP_LOGS );
       
   101 	iPopupTextOne =         env->AllocReadResourceL( R_QTN_LOGS_STYLUS_POPUP_MISSED1 );
       
   102 	iPopupTextMultiple =    env->AllocReadResourceL( R_QTN_LOGS_STYLUS_POPUP_MISSED );   
       
   103 
       
   104 	iUid = 0;
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // CLogsIndicatorPlugin::CLogsIndicatorPlugin
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 CLogsIndicatorPlugin::CLogsIndicatorPlugin()
       
   112     {
       
   113     }
       
   114     
       
   115 // ---------------------------------------------------------------------------
       
   116 // CLogsIndicatorPlugin::~CLogsIndicatorPlugin
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 CLogsIndicatorPlugin::~CLogsIndicatorPlugin()
       
   120     {
       
   121     delete iPopupHeading;   
       
   122     delete iPopupTextOne;
       
   123     delete iPopupTextMultiple;  
       
   124     
       
   125     // notify cenrep that this observer is no longer here. 
       
   126     if (iNotifyHandlerLogs)
       
   127         {
       
   128         iNotifyHandlerLogs->StopListening();  
       
   129         delete iNotifyHandlerLogs; 
       
   130         }
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // CLogsIndicatorPlugin::HandleIndicatorTapL
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 void CLogsIndicatorPlugin::HandleIndicatorTapL(const TInt /*aUid*/)
       
   138     {
       
   139     // Start Logs application Missed calls view
       
   140     LogsUiCmdStarter::CmdStartL( LogsUiCmdStarterConsts::KMissedView() );     
       
   141     }
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // CLogsIndicatorPlugin::TextL
       
   145 //
       
   146 // Called by framework first during construction and later after UpdateL
       
   147 // is called - see CLogsIndicatorPlugin::HandleNotifyInt
       
   148 // ---------------------------------------------------------------------------
       
   149 //    
       
   150 HBufC* CLogsIndicatorPlugin::TextL( const TInt aUid, TInt& aTextType )
       
   151     {
       
   152     // store the internal uid of this plugin
       
   153     iUid = aUid;
       
   154     aTextType = EAknIndicatorPluginLinkText;
       
   155     
       
   156     return CreatePopupContentMessageL();
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // CLogsIndicatorPlugin::CreatePopupContentMessageL
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 HBufC* CLogsIndicatorPlugin::CreatePopupContentMessageL()
       
   164     {
       
   165     TInt missedCount;
       
   166     
       
   167     // Get new missed calls count
       
   168     iRepositoryLogs->Get( KLogsNewMissedCalls, missedCount );   
       
   169       
       
   170     // Construct proper popup message (singular or plural)
       
   171     HBufC* dynStringBuf = NULL;
       
   172     if( missedCount > 1 )
       
   173         {
       
   174         TInt reqDynLen = iPopupTextMultiple->Length() + KMaxEventNumberLength;
       
   175         dynStringBuf = HBufC::NewL( reqDynLen );
       
   176         TPtr dynString = dynStringBuf->Des();
       
   177         StringLoader::Format( dynString,
       
   178                               iPopupTextMultiple->Des(),
       
   179                               -1,             //No index code in source string
       
   180                               missedCount );
       
   181         }
       
   182     else // eventCount <= 1
       
   183         {
       
   184         dynStringBuf = iPopupTextOne->AllocL();
       
   185         }
       
   186     return dynStringBuf;
       
   187     }
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // CLogsIndicatorPlugin::HandleNotifyInt
       
   191 // ---------------------------------------------------------------------------
       
   192 //
       
   193 void CLogsIndicatorPlugin::HandleNotifyInt( TUint32 aId, TInt aNewValue )
       
   194     {
       
   195     // Sanity check the parameters
       
   196     if (aId == KLogsNewMissedCalls && aNewValue >= 0)
       
   197         {   
       
   198         // Call UpdateL which will eventually lead to a callback to the TextL here and
       
   199         // the update of the popup message (missed calls count)        
       
   200         TRAPD(err, UpdateL(iUid));
       
   201         if (err != KErrNone)
       
   202             {
       
   203             // nothing to do, the plugin text just won't be updated
       
   204             LOGS_DEBUG_PRINT(LOGS_DEBUG_STRING
       
   205                 ( "CLogsIndicatorPlugin::HandleNotifyInt - UpdateL failed")); 
       
   206             }
       
   207         }
       
   208     }
       
   209 
       
   210 
       
   211 
       
   212 // end of file