homescreenplugins/videochplugin/src/videonotificationlauncher.cpp
branchRCL_3
changeset 10 112a725ff2c2
parent 9 5294c000a26d
child 11 8970fbd719ec
equal deleted inserted replaced
9:5294c000a26d 10:112a725ff2c2
     1 /*
       
     2 * Copyright (c) 2008-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 the License "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 // Version : %version: 12 %
       
    19 
       
    20 
       
    21 #include <e32std.h>
       
    22 #include <e32base.h>
       
    23 #include <eikenv.h>
       
    24 #include <f32file.h>
       
    25 
       
    26 #include <avkon.hrh>
       
    27 #include <bautils.h>
       
    28 #include <akndiscreetpopup.h>
       
    29 #include <tultextresourceutils.h>
       
    30 #include <data_caging_path_literals.hrh>
       
    31 
       
    32 #include <vcxmyvideosdefs.h>
       
    33 #include <mpxmedia.h>
       
    34 #include <mpxmediageneraldefs.h>
       
    35 #include <vcxmyvideosuids.h>
       
    36 #include <videoplayeractivationmessage.h>
       
    37 #include <videocontentharvester.rsg>
       
    38 
       
    39 #include "videochmcategorylistener.h"
       
    40 #include "videocontentharvesterplugin.h"
       
    41 #include "videonotificationlauncher.h"
       
    42 #include "videochpublishabledata.h"
       
    43 #include "videochpublisher.h"
       
    44 #include "iptvlastwatchedapi.h"
       
    45 #include "iptvlastwatcheddata.h"
       
    46 #include "IptvDebug.h"
       
    47 
       
    48 // CONSTANTS
       
    49 const TInt KMediaExtSize( 8 );
       
    50 
       
    51 _LIT( KResourceFile, "videocontentharvester.rsc");
       
    52 
       
    53 
       
    54 
       
    55 // ============================ MEMBER FUNCTIONS ==============================
       
    56 
       
    57 
       
    58 // ----------------------------------------------------------------------------
       
    59 // CVcxNsNotificationLauncher::CVcxNsNotificationLauncher
       
    60 // C++ default constructor
       
    61 // ----------------------------------------------------------------------------
       
    62 //
       
    63 CVcxNsNotificationLauncher::CVcxNsNotificationLauncher( CVcxNsChPublishableData* aPublishableData,
       
    64                                                          CVcxNsChPublisher* aPublisher ) :
       
    65     iPublishableData( aPublishableData ),
       
    66     iPublisher( aPublisher )
       
    67     {          
       
    68     }
       
    69 
       
    70 // ----------------------------------------------------------------------------
       
    71 // CVcxNsNotificationLauncher::ConstructL
       
    72 // ----------------------------------------------------------------------------
       
    73 //
       
    74 void CVcxNsNotificationLauncher::ConstructL()
       
    75     {
       
    76     iDownloadCompletedBuffer = LoadResourceStringL( R_IPTV_DOWNLOAD_COMPLETE );
       
    77     
       
    78     iDownloadsContinueBuffer = LoadResourceStringL( R_IPTV_UNFINISHED_DNLOADS_CONTINUE );
       
    79     
       
    80     TUid domain   = TUid::Uid( KVcxNsMpxMediatorDomain );
       
    81     TUid category = TUid::Uid( KVcxNsMpxMediatorCategory );
       
    82     TVersion version = TVersion( KVcxNsMpxEventVersion, 0, 0 );
       
    83     iCatListener = CVcxNsChMCategoryListener::NewL( this, 
       
    84                                                     domain,
       
    85                                                     category,
       
    86                                                     version );
       
    87     
       
    88     iCatListener->RegisterAndSubscribeL( KVcxNsMpxEventDownloadCompleted );
       
    89     }
       
    90 
       
    91 // ----------------------------------------------------------------------------
       
    92 // CVcxNsNotificationLauncher::NewL
       
    93 // ----------------------------------------------------------------------------
       
    94 //
       
    95 CVcxNsNotificationLauncher* CVcxNsNotificationLauncher::NewL( 
       
    96                                      CVcxNsChPublishableData* aPublishableData,
       
    97                                      CVcxNsChPublisher* aPublisher )
       
    98     {
       
    99     CVcxNsNotificationLauncher* self = 
       
   100         new( ELeave ) CVcxNsNotificationLauncher( aPublishableData, aPublisher );
       
   101     
       
   102     CleanupStack::PushL( self );
       
   103     self->ConstructL();
       
   104     CleanupStack::Pop( self );
       
   105     
       
   106     return self;
       
   107     }
       
   108 
       
   109 // ----------------------------------------------------------------------------
       
   110 // CVcxNsNotificationLauncher::~CVcxNsNotificationLauncher
       
   111 // ----------------------------------------------------------------------------
       
   112 //
       
   113 CVcxNsNotificationLauncher::~CVcxNsNotificationLauncher()
       
   114      {   
       
   115      delete iCatListener;
       
   116      delete iDownloadCompletedBuffer;
       
   117      delete iDownloadsContinueBuffer;
       
   118      }
       
   119 
       
   120 // ----------------------------------------------------------------------------
       
   121 // CVcxNsNotificationLauncher::MediatorEventL
       
   122 // ----------------------------------------------------------------------------
       
   123 //
       
   124 void CVcxNsNotificationLauncher::MediatorEventL( TUid aDomain,
       
   125                                                  TUid aCategory,
       
   126                                                  TInt aEventId,
       
   127                                                  const TDesC8& aData )
       
   128     {
       
   129     IPTVLOGSTRING_LOW_LEVEL("Cvcxnsnotificationlauncher::MediatorEventL IN");
       
   130         
       
   131     TBool validData( aData.Length() == KMediaExtSize );
       
   132     TBool validDomain( aDomain == TUid::Uid( KVcxNsMpxMediatorDomain ) ); 
       
   133     TBool validCategory( aCategory == TUid::Uid( KVcxNsMpxMediatorCategory ) );
       
   134     TBool validEvent( aEventId == KVcxNsMpxEventDownloadCompleted  );
       
   135     
       
   136     if ( validDomain && validCategory && validEvent && validData )
       
   137         {                
       
   138         HBufC8* buffer = HBufC8::NewL( KMediaExtSize );
       
   139         CleanupStack::PushL( buffer );
       
   140 
       
   141         TPtr8 des = buffer->Des();
       
   142         des.Copy( aData );
       
   143         
       
   144         RDesReadStream stream;
       
   145         CleanupClosePushL( stream );
       
   146         stream.Open( aData );
       
   147 
       
   148         CMPXMedia* media = CMPXMedia::NewL();
       
   149         CleanupStack::PushL( media );
       
   150 
       
   151         media->InternalizeL( stream );
       
   152 
       
   153         if ( media->IsSupported( KMPXMediaGeneralTitle ) )
       
   154             {
       
   155             DlCompletedNotificationL( *media );
       
   156             }
       
   157 
       
   158         CleanupStack::PopAndDestroy( media );
       
   159         CleanupStack::PopAndDestroy( &stream );
       
   160         CleanupStack::PopAndDestroy( buffer );
       
   161         }
       
   162     
       
   163     IPTVLOGSTRING_LOW_LEVEL("Cvcxnsnotificationlauncher::MediatorEventL OUT");
       
   164     }
       
   165 
       
   166 // ----------------------------------------------------------------------------
       
   167 // CVcxNsNotificationLauncher::LaunchExitingNotificationL
       
   168 // ----------------------------------------------------------------------------
       
   169 //
       
   170 void CVcxNsNotificationLauncher::LaunchExitingNotificationL()
       
   171     {
       
   172     CAknDiscreetPopup::ShowGlobalPopupL( *iDownloadsContinueBuffer );
       
   173     }
       
   174 
       
   175 // ----------------------------------------------------------------------------
       
   176 // CVcxNsNotificationLauncher::DlCompletedNotificationL 
       
   177 // ----------------------------------------------------------------------------
       
   178 //
       
   179 void CVcxNsNotificationLauncher::DlCompletedNotificationL( const CMPXMedia& aMedia )
       
   180     {
       
   181     IPTVLOGSTRING_LOW_LEVEL("CVcxNsNotificationLauncher::DlCompletedNotificationL");            
       
   182 
       
   183     TPtrC name = aMedia.ValueText( KMPXMediaGeneralTitle );
       
   184 
       
   185     TUint popupFlags( KAknDiscreetPopupDurationLong );
       
   186     
       
   187     const TInt KMaxDlCompleteTextLength = 300;
       
   188     
       
   189     TBuf<KMaxDlCompleteTextLength> text;
       
   190     
       
   191     TulTextResourceUtils::Format( text, *iDownloadCompletedBuffer, -1, name );
       
   192 
       
   193     CAknDiscreetPopup::ShowGlobalPopupL(
       
   194            text,
       
   195            KNullDesC,
       
   196            KAknsIIDNone,
       
   197            KNullDesC,
       
   198            -1,
       
   199            -1,
       
   200            popupFlags );
       
   201     }
       
   202 //
       
   203 // ----------------------------------------------------------
       
   204 //  LoadResourceString.
       
   205 // ----------------------------------------------------------
       
   206 //
       
   207 HBufC* CVcxNsNotificationLauncher::LoadResourceStringL( TInt aResourceId )
       
   208     {
       
   209     RFs fs;
       
   210     User::LeaveIfError(fs.Connect());
       
   211     CleanupClosePushL(fs);  
       
   212 
       
   213     TFileName dllName;
       
   214     Dll::FileName( dllName );
       
   215     TParsePtrC parse( dllName );
       
   216     
       
   217     TFileName fileName;
       
   218     fileName = parse.Drive();
       
   219     fileName.Append( KDC_APP_RESOURCE_DIR );
       
   220     fileName.Append( KResourceFile() );
       
   221     
       
   222     BaflUtils::NearestLanguageFile( fs, fileName );
       
   223     
       
   224     if( !BaflUtils::FileExists( fs, fileName ) )
       
   225         {
       
   226         User::Leave(KErrNotFound);
       
   227         }
       
   228     
       
   229     RResourceFile resourceFile;
       
   230     resourceFile.OpenL( fs,fileName );
       
   231     CleanupClosePushL( resourceFile );
       
   232     resourceFile.ConfirmSignatureL( 0 );
       
   233 
       
   234     HBufC8* dataBuffer = resourceFile.AllocReadLC( aResourceId );
       
   235     TResourceReader theReader;
       
   236     theReader.SetBuffer( dataBuffer );
       
   237     HBufC* locstring = theReader.ReadHBufCL();
       
   238     
       
   239     CleanupStack::PopAndDestroy( dataBuffer );
       
   240     CleanupStack::PopAndDestroy( &resourceFile );
       
   241     CleanupStack::PopAndDestroy( &fs );
       
   242 
       
   243     return locstring;
       
   244     }