wvuing/ImUtils/Src/IMUtils.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2006 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:  General utility class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "IMUtils.h"
       
    22 #include    "CAExternalInterface.h"
       
    23 #include    "chatdefinitions.h"
       
    24 #include    "ChatDebugPrint.h"
       
    25 #include    "CAUtils.h"
       
    26 #include    "IMPrivateCRKeys.h"
       
    27 
       
    28 #include    "CCAWaitNote.h"
       
    29 #include    "IMDialogUtils.h"
       
    30 #include    <ChatNG.rsg>
       
    31 #include    <hlplch.h>
       
    32 #include    <csxhelp/imng.hlp.hrh>
       
    33 #include    <eikmenup.h>
       
    34 
       
    35 #include    <PEngWVPresenceErrors2.h>   // wv error codes
       
    36 #include    <IMPSServiceSettingsUINGInternalCRKeys.h>
       
    37 #include    <CentralRepository.h>
       
    38 #include    <barsread.h>
       
    39 #include    <gulutil.h>
       
    40 #include    <gulicon.h>
       
    41 #include	<StringLoader.h>
       
    42 #include    <sysutil.h>
       
    43 #include    <caf/content.h>
       
    44 #include    <caf/manager.h>
       
    45 #include    <oma2agent.h>
       
    46 #include    <collate.h>
       
    47 #include	"PublicEngineDefinitions.h"
       
    48 
       
    49 ////401-1815 Ease of Instant Messaging branding
       
    50 //Code added for the above requirment
       
    51 #include 	"VariantKeys.h"
       
    52 #include 	<CAVariationNG.rsg>
       
    53 
       
    54 
       
    55 
       
    56 // LOCAL CONSTANTS AND MACROS
       
    57 _LIT( KPanicCategory, "IMUtilsNG" );
       
    58 
       
    59 
       
    60 #define 	KLibNotInitialized		KErrBadLibraryEntryPoint
       
    61 //End of code for CR 401-1815
       
    62 
       
    63 
       
    64 // ---------------------------------------------------------
       
    65 // IMUtils::PopulateFormattedOnlineListL
       
    66 // (other items were commented in a header).
       
    67 // ---------------------------------------------------------
       
    68 //
       
    69 EXPORT_C void IMUtils::PopulateFormattedOnlineListL( const MDesCArray& aRawOnlineList,
       
    70                                                      CDesCArray& aFormattedOnlineList )
       
    71     {
       
    72     // Add formatted data to second list
       
    73     const TInt onlineCount( aRawOnlineList.MdcaCount() );
       
    74     HBufC* formattedWVID = HBufC::NewLC( KWVUserIDMaxLength + KIconTabulator().Size() );
       
    75     TPtr formattedWVIDPtr( formattedWVID->Des() );
       
    76 
       
    77     for ( TInt i( 0 ); i < onlineCount; ++i )
       
    78         {
       
    79         formattedWVIDPtr.Append( KIconTabulator );
       
    80         formattedWVIDPtr.Append( aRawOnlineList.MdcaPoint( i ) );
       
    81         aFormattedOnlineList.AppendL( *formattedWVID );
       
    82         formattedWVIDPtr.Zero();
       
    83         }
       
    84 
       
    85     CleanupStack::PopAndDestroy( formattedWVID );
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------
       
    89 // IMUtils::LaunchHelpL()
       
    90 // (other items were commented in a header).
       
    91 // ---------------------------------------------------------
       
    92 //
       
    93 EXPORT_C void IMUtils::LaunchHelpL( const TDesC& aContext )
       
    94     {
       
    95     //make context array
       
    96     //granurality 1 is ok cos there is added just one item
       
    97     CArrayFix< TCoeHelpContext >* cntx = new( ELeave ) CArrayFixFlat< TCoeHelpContext >( 1 );
       
    98     CleanupStack::PushL( cntx );
       
    99 
       
   100     cntx->AppendL( TCoeHelpContext( KUidChatClient, aContext ) );
       
   101     CleanupStack::Pop( cntx );
       
   102 
       
   103     //and launch help - takes ownership of context array
       
   104     HlpLauncher::LaunchHelpApplicationL( CEikonEnv::Static()->WsSession(), cntx );
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------
       
   108 // IMUtils::WVSettingsChatLoginValue()
       
   109 // (other items were commented in a header).
       
   110 // Central Repository version
       
   111 // ---------------------------------------------------------
       
   112 //
       
   113 EXPORT_C TInt IMUtils::WVSettingsChatLoginValue( )
       
   114     {
       
   115     CHAT_DP( D_CHAT_LIT( "CCAUISessionManager::LoginType" ) );
       
   116 
       
   117     TInt readValue( KErrCouldNotConnect ); // initialize to an error value
       
   118 
       
   119     // get the login type from central repository
       
   120     CRepository* repository = NULL;
       
   121     TRAPD( err, repository = CRepository::NewL( KWVSettingsCenRepUid ) );
       
   122 
       
   123     if ( err )
       
   124         {
       
   125         // problems, return the error
       
   126         return err;
       
   127         }
       
   128 
       
   129     err = repository->Get( KIMPSCRChatLogin, readValue );
       
   130 
       
   131     delete repository;
       
   132 
       
   133     if ( err != KErrNone )
       
   134         {
       
   135         // there was an error
       
   136         return err;
       
   137         }
       
   138 
       
   139     return readValue;
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------
       
   143 // IMUtils::NeutralFind
       
   144 // (other items were commented in a header).
       
   145 // ---------------------------------------------------------
       
   146 //
       
   147 EXPORT_C TInt IMUtils::NeutralFind( const MDesCArray& aUserList, const TDesC& aUserId )
       
   148     {
       
   149     TInt count( aUserList.MdcaCount() );
       
   150     for ( TInt i( 0 ); i < count; ++i )
       
   151         {
       
   152         if ( CAUtils::NeutralCompare( aUserList.MdcaPoint( i ),
       
   153                                       aUserId ) == 0 )
       
   154             {
       
   155             return i;
       
   156             }
       
   157         }
       
   158     return KErrNotFound;
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------
       
   162 // IMUtils::IntResourceValueL
       
   163 // (other items were commented in a header).
       
   164 // ---------------------------------------------------------
       
   165 //
       
   166 EXPORT_C TInt IMUtils::IntResourceValueL( TInt aResourceId )
       
   167     {
       
   168 
       
   169     TInt val( 0 );
       
   170     TInt err ( KErrNone );
       
   171     ////401-1815 Ease of Instant Messaging branding
       
   172     //Code added for the above requirment
       
   173 
       
   174     //get the exact cenrep id for the aResourceId
       
   175     TInt key = aResourceId + KIMStartVariationID;
       
   176 
       
   177     err = TlsData()->RepositoryInstance().Get( key, val );
       
   178 
       
   179     if ( err != KErrNone )
       
   180         {
       
   181         val = IntResourceValueFromRssL( RSC_CRRSS_CHAT_VARIATION_START_ID + aResourceId );
       
   182         }
       
   183     // end of code for 401-1815 Ease of Instant Messaging Branding.
       
   184     return val;
       
   185     }
       
   186 
       
   187 
       
   188 
       
   189 ////401-1815 Ease of Instant Messaging branding
       
   190 //Code added for the above requirment
       
   191 // ---------------------------------------------------------
       
   192 // IMUtils::IntResourceValueFromRssL
       
   193 // (other items were commented in a header).
       
   194 // ---------------------------------------------------------
       
   195 //
       
   196 EXPORT_C TInt IMUtils::IntResourceValueFromRssL( TInt aResourceId )
       
   197     {
       
   198 
       
   199     TInt val( 0 );
       
   200 
       
   201     TResourceReader reader;
       
   202     CCoeEnv::Static()->CreateResourceReaderLC( reader, aResourceId );
       
   203 
       
   204     val = ResourceUtils::ReadTInt32L( reader );
       
   205     CleanupStack::PopAndDestroy(); // reader
       
   206 
       
   207     return val;
       
   208     }
       
   209 // end of code for 401-1815 Ease of Instant Messaging Branding.
       
   210 
       
   211 
       
   212 // ---------------------------------------------------------
       
   213 // IMUtils::MaxMsgLength
       
   214 // (other items were commented in a header).
       
   215 // ---------------------------------------------------------
       
   216 //
       
   217 EXPORT_C TInt IMUtils::MaxMsgLength()
       
   218     {
       
   219     TInt maxLength( 0 );
       
   220     TRAPD( err, maxLength = IntResourceValueL( RSC_CHAT_VARIATION_MESSAGE_MAX_LENGTH ) );
       
   221     if ( err != KErrNone )
       
   222         {
       
   223         CActiveScheduler::Current()->Error( err );
       
   224         }
       
   225     if ( maxLength <= 0 )
       
   226         {
       
   227         // if the resource value was invalid, assign default value
       
   228         maxLength = KDefaultMsgLength;
       
   229         }
       
   230 
       
   231     return maxLength;
       
   232     }
       
   233 
       
   234 
       
   235 // ---------------------------------------------------------
       
   236 // IMUtils::GetCRKeyL
       
   237 // (other items were commented in a header).
       
   238 // ---------------------------------------------------------
       
   239 //
       
   240 EXPORT_C TUint32 IMUtils::CRKeyL( TUid aUid, TUint32 aKey )
       
   241     {
       
   242     TInt val( 0 );
       
   243 
       
   244     TRAPD( err,
       
   245            CRepository* rep = CRepository::NewL( aUid );
       
   246            rep->Get( aKey, val );
       
   247            delete rep;
       
   248          );
       
   249 
       
   250     if ( err != KErrNotFound && err != KErrPathNotFound )
       
   251         {
       
   252         // "Not found" errors are ignored, because it's ok to
       
   253         // return zero if key is not found
       
   254         User::LeaveIfError( err );
       
   255         }
       
   256 
       
   257     return val;
       
   258     }
       
   259 
       
   260 
       
   261 // ---------------------------------------------------------
       
   262 // IMUtils::AddMenuItemL
       
   263 // (other items were commented in a header).
       
   264 // ---------------------------------------------------------
       
   265 //
       
   266 EXPORT_C void IMUtils::AddMenuItemL( TBool aAdd, CEikMenuPane& aMenuPane, TInt aTextResourceId,
       
   267                                      TInt aCommandId, TInt aCascadeId /*= 0*/ )
       
   268     {
       
   269     if ( aAdd )
       
   270         {
       
   271         HBufC* text = CCoeEnv::Static()->AllocReadResourceLC( aTextResourceId );
       
   272 
       
   273         CEikMenuPaneItem::SData data;
       
   274         data.iCommandId = aCommandId;
       
   275         data.iCascadeId = aCascadeId;
       
   276         data.iFlags = 0;
       
   277         data.iText.Copy( text->Des().Left( CEikMenuPaneItem::SData::ENominalTextLength ) );
       
   278         data.iExtraText.Zero();
       
   279         aMenuPane.AddMenuItemL( data );
       
   280 
       
   281         CleanupStack::PopAndDestroy( text );
       
   282         }
       
   283     }
       
   284 
       
   285 // ---------------------------------------------------------
       
   286 // IMUtils::SetIcon
       
   287 // ---------------------------------------------------------
       
   288 //
       
   289 EXPORT_C void IMUtils::SetIcon( CGulIcon& aTarget, CGulIcon& aSource )
       
   290     {
       
   291     aTarget.SetBitmap( aSource.Bitmap() );
       
   292     aTarget.SetMask( aSource.Mask() );
       
   293     aTarget.SetBitmapsOwnedExternally( aSource.BitmapsOwnedExternally() );
       
   294     if ( !aSource.BitmapsOwnedExternally() )
       
   295         {
       
   296         aSource.SetBitmapsOwnedExternally( ETrue );
       
   297         }
       
   298     }
       
   299 
       
   300 // ---------------------------------------------------------
       
   301 // IMUtils::UpdateIcon
       
   302 // ---------------------------------------------------------
       
   303 //
       
   304 EXPORT_C void IMUtils::UpdateIcon( CGulIcon*& aTarget, CGulIcon* aSource )
       
   305     {
       
   306     if ( aTarget )
       
   307         {
       
   308         IMUtils::SetIcon( *aTarget, *aSource );
       
   309         CleanupStack::PopAndDestroy();
       
   310         }
       
   311     else
       
   312         {
       
   313         aTarget = aSource;
       
   314         CleanupStack::Pop();
       
   315         }
       
   316 
       
   317     }
       
   318 // ---------------------------------------------------------
       
   319 // IMUtils::IgnoreOfflineStatusL()
       
   320 // ---------------------------------------------------------
       
   321 //
       
   322 EXPORT_C TInt IMUtils::IgnoreOfflineStatusL( const TDesC& aContactIdentification )
       
   323     {
       
   324     // These flags cannot be enabled simultaneously (UI spec.)
       
   325     TInt ignoreOffline = IntResourceValueL(
       
   326                              RSC_CHAT_VARIATION_SEND_MSG_IGNORE_OFFLINE );
       
   327     TInt ignoreOfflineNotify = IntResourceValueL(
       
   328                                    RSC_CHAT_VARIATION_SEND_MSG_IGNORE_OFFLINE_NOTIFY );
       
   329 
       
   330     // If RSC_CHAT_VARIATION_SEND_MSG_IGNORE_OFFLINE flag is set
       
   331     // offline state is ignored without any notifications
       
   332     TInt result = EAknSoftkeyOk;
       
   333 
       
   334     if ( !ignoreOffline )
       
   335         {
       
   336         if ( ignoreOfflineNotify )
       
   337             {
       
   338             // Show note about offline contact
       
   339             HBufC* msg = StringLoader::LoadLC(
       
   340                              R_QTN_CHAT_CONTACT_MAY_NOT_RECEIVE_MESSAGE,
       
   341                              aContactIdentification );
       
   342 
       
   343             result = IMDialogUtils::DisplayQueryDialogL(
       
   344                          R_CHAT_CONTACT_MAY_NOT_RECEIVE_MESSAGE_DIALOG,
       
   345                          msg->Des() );
       
   346             CleanupStack::PopAndDestroy( msg );
       
   347             }
       
   348         else
       
   349             {
       
   350             // Logged in and contact not online,
       
   351             // ignorance of offline state disabled
       
   352             IMDialogUtils::DisplayInformationNoteL(
       
   353                 R_QTN_CHAT_FRIEND_OFFLINE );
       
   354             result = EVariationDoesNotAllow;
       
   355             }
       
   356         }
       
   357 
       
   358     if ( result == EAknSoftkeyOk )
       
   359         {
       
   360         return EIgnoredByUser;
       
   361         }
       
   362     else if ( result == 0 ) // Dialog returns 0 if cancelled by user
       
   363         {
       
   364         return EUserCanceled;
       
   365         }
       
   366     else
       
   367         {
       
   368         return result;
       
   369         }
       
   370     }
       
   371 
       
   372 // ---------------------------------------------------------
       
   373 // IMUtils::FFSSpaceBelowCriticalLevelL()
       
   374 // ---------------------------------------------------------
       
   375 //
       
   376 EXPORT_C void IMUtils::FFSSpaceBelowCriticalLevelL( TInt aRequestedSpace /*= 0*/
       
   377                                                     , TBool
       
   378 #ifdef _DEBUG
       
   379                                                     aEmulateMemOut /*= EFalse*/
       
   380 #endif // _DEBUG
       
   381                                                   )
       
   382     {
       
   383 #ifdef _DEBUG
       
   384     if ( aEmulateMemOut )
       
   385         {
       
   386         User::Leave( KErrDiskFull );
       
   387         }
       
   388 #endif // _DEBUG
       
   389 
       
   390     // Check disk space
       
   391     if ( SysUtil::FFSSpaceBelowCriticalLevelL(
       
   392              &CEikonEnv::Static()->FsSession(), aRequestedSpace ) )
       
   393         {
       
   394         User::Leave( KErrDiskFull );
       
   395         }
       
   396     }
       
   397 
       
   398 // ---------------------------------------------------------
       
   399 // IMUtils::FileProtectedL()
       
   400 // ---------------------------------------------------------
       
   401 //
       
   402 EXPORT_C TBool IMUtils::FileProtectedL( const TFileName& aFileName )
       
   403     {
       
   404     TInt value( 0 );
       
   405     ContentAccess::CContent* content = ContentAccess::CContent::NewL( aFileName );
       
   406     TInt err( content->GetAttribute( ContentAccess::EIsProtected, value ) );
       
   407     delete content;
       
   408 
       
   409     return( err == KErrNone && value );
       
   410     }
       
   411 
       
   412 // ---------------------------------------------------------
       
   413 // IMUtils::ContentProtectedL()
       
   414 // ---------------------------------------------------------
       
   415 //
       
   416 EXPORT_C TBool IMUtils::ContentProtectedL( const TDesC8& aContent )
       
   417     {
       
   418     // Note that if this method is needed often, the list
       
   419     // of agents should be cached!
       
   420 
       
   421     RArray<ContentAccess::TAgent> agents;
       
   422     CleanupClosePushL( agents );
       
   423     ContentAccess::TAgent agentDRM;
       
   424 
       
   425     // get the list of agents
       
   426     ContentAccess::CManager* manager = ContentAccess::CManager::NewLC();
       
   427     manager->ListAgentsL( agents );
       
   428 
       
   429     // find the DRM agent
       
   430     TInt count( agents.Count() );
       
   431     for ( TInt i( 0 ); i < count; ++i )
       
   432         {
       
   433         if ( agents[i].Name().Compare( KOmaDrm2AgentName ) == 0 )
       
   434             {
       
   435             agentDRM = agents[i];
       
   436             break;
       
   437             }
       
   438         }
       
   439 
       
   440     HBufC8* empty = HBufC8::NewLC( 1 );
       
   441     TPtr8 output( empty->Des() );
       
   442 
       
   443     // execute agent specific command for OMA2 agent
       
   444     TInt ret( manager->AgentSpecificCommand( agentDRM, ContentAccess::EBufferContainsOma1Dcf,
       
   445                                              aContent, output ) );
       
   446 
       
   447     CleanupStack::PopAndDestroy( 3 ); // empty, manager, agents.Close()
       
   448     return ( ret != KErrNotFound );
       
   449     }
       
   450 
       
   451 // ---------------------------------------------------------
       
   452 // IMUtils::CombineStringFromResourceLC()
       
   453 // See header for details.
       
   454 // ---------------------------------------------------------
       
   455 //
       
   456 EXPORT_C HBufC* IMUtils::CombineStringFromResourceLC( TInt aResourceId1, TInt aResourceId2 )
       
   457     {
       
   458     // empty texts
       
   459     _LIT ( KPSUIEmptyStringHeader, "%S\n%S" );
       
   460     HBufC* emptyText = CCoeEnv::Static()->AllocReadResourceLC(
       
   461                            aResourceId1 );
       
   462 
       
   463     HBufC* emptyText2 = CCoeEnv::Static()->AllocReadResourceLC(
       
   464                             aResourceId2 );
       
   465 
       
   466     HBufC* emptyFinal = HBufC::NewLC(
       
   467                             emptyText->Length() + emptyText2->Length() + 2 );// 2 is length of "\n"
       
   468 
       
   469     CleanupStack::Pop( emptyFinal );
       
   470 
       
   471     emptyFinal->Des().Format( KPSUIEmptyStringHeader, emptyText, emptyText2 );
       
   472 
       
   473     CleanupStack::PopAndDestroy( 2 );// emptyText, emptyText2
       
   474 
       
   475     CleanupStack::PushL( emptyFinal );
       
   476 
       
   477     return emptyFinal;
       
   478 
       
   479     }
       
   480 
       
   481 
       
   482 
       
   483 ////401-1815 Ease of Instant Messaging branding
       
   484 //Code added for the above requirment
       
   485 // ---------------------------------------------------------
       
   486 // IMUtils::InitializeLibL()
       
   487 // See header for details.
       
   488 // ---------------------------------------------------------
       
   489 //
       
   490 EXPORT_C void IMUtils::InitializeLibL()
       
   491     {
       
   492     if ( !Dll::Tls() )
       
   493         {
       
   494         Dll::SetTls( CIMUtilsTlsData::NewL() );
       
   495         }
       
   496 
       
   497     }
       
   498 
       
   499 
       
   500 // ---------------------------------------------------------
       
   501 // IMUtils::UnInitializeLib()
       
   502 // See header for details.
       
   503 // ---------------------------------------------------------
       
   504 //
       
   505 EXPORT_C void IMUtils::UnInitializeLib()
       
   506     {
       
   507     if ( Dll::Tls() )
       
   508         {
       
   509         CIMUtilsTlsData* tlsData = TlsData();
       
   510 
       
   511         if ( TlsData() )
       
   512             {
       
   513             delete tlsData;
       
   514             Dll::SetTls( NULL );
       
   515             }
       
   516         }
       
   517     }
       
   518 
       
   519 
       
   520 
       
   521 // -----------------------------------------------------------------------------
       
   522 // IMUtils::TlsData()
       
   523 // -----------------------------------------------------------------------------
       
   524 //
       
   525 CIMUtilsTlsData* IMUtils::TlsData()
       
   526     {
       
   527     CIMUtilsTlsData* tlsData = STATIC_CAST( CIMUtilsTlsData*, Dll::Tls() );
       
   528 
       
   529     __ASSERT_ALWAYS( tlsData,
       
   530                      User::Panic( KPanicCategory, KLibNotInitialized ) );
       
   531 
       
   532     return tlsData;
       
   533     }
       
   534 
       
   535 
       
   536 
       
   537 
       
   538 
       
   539 // ============================ MEMBER FUNCTIONS ===============================
       
   540 
       
   541 // -----------------------------------------------------------------------------
       
   542 // CIMUtilsTlsData::CIMUtilsTlsData
       
   543 // C++ default constructor can NOT contain any code, that
       
   544 // might leave.
       
   545 // -----------------------------------------------------------------------------
       
   546 //
       
   547 CIMUtilsTlsData::CIMUtilsTlsData()
       
   548     {
       
   549     }
       
   550 
       
   551 // -----------------------------------------------------------------------------
       
   552 // CIMUtilsTlsData::ConstructL
       
   553 // Symbian 2nd phase constructor can leave.
       
   554 // -----------------------------------------------------------------------------
       
   555 //
       
   556 void CIMUtilsTlsData::ConstructL()
       
   557     {
       
   558     iRepository = CRepository::NewL( KCRUidIMNG );
       
   559     }
       
   560 
       
   561 // -----------------------------------------------------------------------------
       
   562 // CIMUtilsTlsData::NewL
       
   563 // Two-phased constructor.
       
   564 // -----------------------------------------------------------------------------
       
   565 //
       
   566 CIMUtilsTlsData* CIMUtilsTlsData::NewL()
       
   567     {
       
   568     CIMUtilsTlsData* self = new( ELeave ) CIMUtilsTlsData;
       
   569 
       
   570     CleanupStack::PushL( self );
       
   571     self->ConstructL();
       
   572     CleanupStack::Pop( self );
       
   573 
       
   574     return self;
       
   575     }
       
   576 
       
   577 
       
   578 // Destructor
       
   579 CIMUtilsTlsData::~CIMUtilsTlsData()
       
   580     {
       
   581     delete 	iRepository;
       
   582     }
       
   583 
       
   584 
       
   585 // -----------------------------------------------------------------------------
       
   586 // CIMUtilsTlsData::RepositoryInstance
       
   587 // Two-phased constructor.
       
   588 // -----------------------------------------------------------------------------
       
   589 //
       
   590 
       
   591 CRepository& CIMUtilsTlsData::RepositoryInstance()
       
   592     {
       
   593     return *iRepository;
       
   594     }
       
   595 
       
   596 //// End of code for 401-1815 Ease of Instant Messaging brand
       
   597 
       
   598 //  End of File