videofeeds/hgvodui/src/vcxhgvodutils.cpp
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     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:   HG VOD utility class*
       
    15 */
       
    16 
       
    17 
       
    18 #include <AknUtils.h>
       
    19 #include <avkon.rsg>
       
    20 #include <gulicon.h>
       
    21 #include <cemailaccounts.h>
       
    22 #include <CMessageData.h>
       
    23 #include <eikenv.h>
       
    24 #include <sendui.h>
       
    25 #include <SendUiConsts.h>
       
    26 #include <StringLoader.h>
       
    27 #include <txtrich.h>
       
    28 #include <tz.h>
       
    29 #include <utf.h>
       
    30 #include "vcxnscategory.h"
       
    31 #include <vcxhgvodui.rsg>
       
    32 
       
    33 #include "vcxhgvodutils.h"
       
    34 
       
    35 //CONSTANTS
       
    36 const TInt KVcxNsVideoSizeGB     = 0x40000000;
       
    37 const TInt KVcxNsVideoSizeHalfGB = 0x20000000;
       
    38 const TInt KVcxNsVideoSizeMB     = 0x100000;
       
    39 const TInt KVcxNsVideoSizeHalfMB = 0x80000;
       
    40 const TInt KVcxNsVideoSizeKB     = 0x400;
       
    41 const TInt KVcxNsVideoSizeHalfKB = 0x200; 
       
    42 
       
    43 const TInt KVcxNsHourInSeconds   = 3600;
       
    44 const TInt KVcxNsMinuteInSeconds = 60;
       
    45 
       
    46 const TInt KVcxNsLengthNumbersArraySize = 2;
       
    47 
       
    48 _LIT(KVcxNsComma, ", ");
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CVcxHgVodUtils::~CVcxHgVodUtils()
       
    52 // Destructor
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CVcxHgVodUtils::~CVcxHgVodUtils()
       
    56     {
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CVcxHgVodUtils::CVcxHgVodUtils()
       
    61 // Constructor
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CVcxHgVodUtils::CVcxHgVodUtils( )
       
    65     {
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 //       Landscape    Portrait
       
    70 // QVGA  320x240  or  240x320
       
    71 // QHD   640x360  or  360x640
       
    72 // VGA   640x480  or  480x640
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 CVcxHgVodUtils::TVcxScreenResolution CVcxHgVodUtils::GetScreenResolution( 
       
    76         CCoeEnv* aCoeEnv )
       
    77     {
       
    78     TVcxScreenResolution resolution( EVcxScreenResolutionUnknown );
       
    79     TSize screenSize = aCoeEnv->ScreenDevice()->SizeInPixels(); 
       
    80     TBool landscape = screenSize.iWidth > screenSize.iHeight;
       
    81 
       
    82     if ( ( landscape && screenSize.iHeight <= 240 ) ||
       
    83          ( ! landscape && screenSize.iWidth <= 240 ) )
       
    84         {
       
    85         resolution = EVcxScreenResolutionQVGA;
       
    86         }
       
    87     else if ( ( landscape && screenSize.iHeight <= 360 ) ||
       
    88               ( ! landscape && screenSize.iWidth <= 360 ) )
       
    89         {
       
    90         resolution = EVcxScreenResolutionQHD;
       
    91         }
       
    92     else if ( ( landscape && screenSize.iHeight <= 480 ) ||
       
    93               ( ! landscape && screenSize.iWidth <= 480 ) )
       
    94         {
       
    95         resolution = EVcxScreenResolutionVGA;
       
    96         }
       
    97 
       
    98     return resolution;
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CVcxHgVodUtils::LoadStringFromResourceLC
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 HBufC* CVcxHgVodUtils::LoadStringFromResourceLC( TInt aResourceId )
       
   106     {
       
   107     return StringLoader::LoadLC( aResourceId );
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CVcxHgVodUtils::LoadStringFromResourceLC
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 HBufC* CVcxHgVodUtils::LoadStringFromResourceLC( 
       
   115     TInt aResourceId, const TDesC& aDesc )
       
   116     {
       
   117     return StringLoader::LoadLC( aResourceId, aDesc );
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CVcxHgVodUtils::LoadStringFromResourceLC
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 HBufC* CVcxHgVodUtils::LoadStringFromResourceLC( TInt aResourceId, const TInt aNum )
       
   125     {
       
   126     return StringLoader::LoadLC( aResourceId, aNum );
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------
       
   130 // CVcxHgVodUtils::FormatDateAndTimeL()
       
   131 // ---------------------------------------------------------
       
   132 //
       
   133 void CVcxHgVodUtils::FormatDateAndTimeL( 
       
   134     TTime& aTime, 
       
   135     TDes& aFormattedString )
       
   136     {    
       
   137     TTime pubDate(aTime);
       
   138     aFormattedString.Zero();
       
   139     
       
   140     //Convert GMT time to local time
       
   141     RTz rtz;
       
   142     User::LeaveIfError( rtz.Connect() );
       
   143     CleanupClosePushL( rtz );
       
   144     User::LeaveIfError( rtz.ConvertToLocalTime( pubDate ) );
       
   145     CleanupStack::PopAndDestroy( &rtz );
       
   146     
       
   147     HBufC* dateFormatString = StringLoader::LoadLC( R_QTN_DATE_USUAL ); 
       
   148     HBufC* timeFormatString = StringLoader::LoadLC( R_QTN_TIME_USUAL ); 
       
   149     
       
   150     TBuf<KVcxNsMaxDateBufSize> dateString;
       
   151     // Format the date to user readable format. 
       
   152     // The format is locale dependent
       
   153     pubDate.FormatL( dateString, *dateFormatString );  
       
   154     aFormattedString.Append( dateString ); 
       
   155     
       
   156     aFormattedString.Append( KVcxNsSpaceString ); 
       
   157 
       
   158     TBuf<KVcxNsMaxTimeBufSize> timeString;
       
   159     // Format the time to user readable format.
       
   160     // The format is locale dependent
       
   161     pubDate.FormatL( timeString, *timeFormatString );  
       
   162     aFormattedString.Append( timeString ); 
       
   163 
       
   164     AknTextUtils::LanguageSpecificNumberConversion( aFormattedString );
       
   165 
       
   166     CleanupStack::PopAndDestroy( timeFormatString );
       
   167     CleanupStack::PopAndDestroy( dateFormatString );
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------
       
   171 // CVcxHgVodUtils::FormatLengthAndSizeL()
       
   172 // ---------------------------------------------------------
       
   173 //
       
   174 void CVcxHgVodUtils::FormatLengthAndSizeL( 
       
   175     TUint32 aLength, 
       
   176     TUint32 aSize, 
       
   177     TDes& aFormattedString )
       
   178     {
       
   179     aFormattedString.Zero();
       
   180 
       
   181     if ( aLength > 0 )
       
   182         {
       
   183         HBufC* videoLength;
       
   184         
       
   185         TInt hours  = aLength / KVcxNsHourInSeconds;
       
   186         TInt minutes = ( aLength - ( hours * KVcxNsHourInSeconds ) ) / KVcxNsMinuteInSeconds;
       
   187 
       
   188         if ( hours > 0 )
       
   189             {
       
   190             CArrayFix<TInt>* numbers = 
       
   191                 new (ELeave) CArrayFixFlat<TInt>(KVcxNsLengthNumbersArraySize); 
       
   192             CleanupStack::PushL( numbers );
       
   193             
       
   194             numbers->AppendL( hours );
       
   195             numbers->AppendL( minutes );
       
   196             
       
   197             videoLength = StringLoader::LoadLC( R_VCXHG_VIDEOLENGTH_FULL, *numbers ); 
       
   198             
       
   199             aFormattedString.Append( *videoLength );
       
   200                 
       
   201             CleanupStack::PopAndDestroy( videoLength );
       
   202             CleanupStack::PopAndDestroy( numbers ); 
       
   203             }
       
   204         else 
       
   205             {
       
   206             if ( hours == 0 && minutes == 0 )
       
   207                 {
       
   208                 minutes = 1;
       
   209                 }
       
   210             
       
   211             videoLength = StringLoader::LoadLC( R_VCXHG_VIDEOLENGTH_MIN, minutes ); 
       
   212             aFormattedString.Append( *videoLength );
       
   213             CleanupStack::PopAndDestroy( videoLength );
       
   214             }                        
       
   215         }    
       
   216 
       
   217     if ( aSize > 0 )
       
   218         {
       
   219         if ( aFormattedString.Length() > 0  )
       
   220             {
       
   221             aFormattedString.Append( KVcxNsComma ); //add comma separator 
       
   222             }
       
   223 
       
   224         HBufC* videosize;
       
   225         TUint dispSize;
       
   226     
       
   227         if ( aSize >= KVcxNsVideoSizeGB )                    // 1 GB 
       
   228             {
       
   229             dispSize  = aSize + KVcxNsVideoSizeHalfGB;       // ½ GB 
       
   230             dispSize /= KVcxNsVideoSizeGB;
       
   231             videosize   = StringLoader::LoadLC( R_VCXHG_VIDEOSIZE_GB, dispSize );
       
   232             }
       
   233         else if ( aSize >= KVcxNsVideoSizeMB )               // 1 MB 
       
   234             {
       
   235             dispSize  = aSize + KVcxNsVideoSizeHalfMB;       // ½ MB 
       
   236             dispSize /= KVcxNsVideoSizeMB;
       
   237             videosize   = StringLoader::LoadLC( R_VCXHG_VIDEOSIZE_MB, dispSize );
       
   238             }
       
   239         else
       
   240             {
       
   241             dispSize  = aSize + KVcxNsVideoSizeHalfKB;       // ½ kB 
       
   242             dispSize /= KVcxNsVideoSizeKB;                           
       
   243             if ( dispSize == 0 ) 
       
   244                 {
       
   245                 dispSize = 1;
       
   246                 }
       
   247             videosize = StringLoader::LoadLC( R_VCXHG_VIDEOSIZE_KB, dispSize );
       
   248             }
       
   249     
       
   250         aFormattedString.Append( *videosize );
       
   251         CleanupStack::PopAndDestroy( videosize );
       
   252         }
       
   253 
       
   254     }
       
   255 
       
   256 // ---------------------------------------------------------
       
   257 // CVcxHgVodUtils::FormatDownloadStateL()
       
   258 // ---------------------------------------------------------
       
   259 //
       
   260 void CVcxHgVodUtils::FormatDownloadStateL( 
       
   261     CVcxNsContent::TVcxContentDlStatus aStatus,
       
   262     TInt aProgress,
       
   263     TDes& aFormattedString )
       
   264     {
       
   265     aFormattedString.Zero();
       
   266    
       
   267     HBufC* desString = NULL;
       
   268     
       
   269     switch( aStatus )
       
   270         {
       
   271         case CVcxNsContent::EVcxContentDlStateDownloading:
       
   272             {
       
   273             desString = StringLoader::LoadLC( R_IPTV_VIDEO_DOWNLOADING, aProgress );
       
   274             }
       
   275             break;
       
   276         case CVcxNsContent::EVcxContentDlStateFailed:
       
   277             {
       
   278             desString = StringLoader::LoadLC( R_IPTV_DOWNLOAD_FAILED, aProgress );
       
   279             }
       
   280             break;
       
   281         case CVcxNsContent::EVcxContentDlStatePaused:
       
   282             {
       
   283             desString = StringLoader::LoadLC( R_IPTV_DOWNLOAD_PAUSED, aProgress );
       
   284             }
       
   285             break;
       
   286         case CVcxNsContent::EVcxContentDlStateDownloaded:
       
   287             {
       
   288             desString = StringLoader::LoadLC( R_IPTV_VIDEO_DOWNLOADED );
       
   289             }
       
   290             break; 
       
   291         default:
       
   292             {
       
   293             desString = KNullDesC().AllocLC();
       
   294             }
       
   295             break;
       
   296         }
       
   297 
       
   298     aFormattedString.Append( *desString );
       
   299     CleanupStack::PopAndDestroy( desString );
       
   300     }
       
   301 
       
   302 // ---------------------------------------------------------
       
   303 // 
       
   304 // ---------------------------------------------------------
       
   305 //
       
   306 TBool CVcxHgVodUtils::IsSearchCategory( CVcxNsCategory& aCategory )
       
   307     {
       
   308     return aCategory.GetCategoryId() == KVcxNsSearchCategoryId ? ETrue : EFalse;
       
   309     }
       
   310 
       
   311 // ---------------------------------------------------------
       
   312 // 
       
   313 // ---------------------------------------------------------
       
   314 //
       
   315 HBufC* CVcxHgVodUtils::ResolveCategoryNameLC( CVcxNsCategory& aCategory )
       
   316     {
       
   317     if ( IsSearchCategory( aCategory ) )
       
   318         {
       
   319         return LoadStringFromResourceLC( R_VCXHG_VIDEO_SEARCH );
       
   320         }
       
   321     else if ( aCategory.GetName().Length() == 0 )
       
   322         {
       
   323         return LoadStringFromResourceLC( R_VCXHG_CATEGORIES_VIDEO_LIST );
       
   324         }
       
   325     else
       
   326         {
       
   327         return aCategory.GetName().AllocLC();
       
   328         }
       
   329     }
       
   330 
       
   331 // ---------------------------------------------------------
       
   332 // 
       
   333 // ---------------------------------------------------------
       
   334 //
       
   335 HBufC* CVcxHgVodUtils::ResolveCategoryInfoLC( CVcxNsCategory& aCategory )
       
   336     {
       
   337     if( IsSearchCategory( aCategory ) )
       
   338         {
       
   339         if( aCategory.GetVideoCount() == 0 )
       
   340             {
       
   341             return HBufC::NewLC(0);
       
   342             }
       
   343         else if( aCategory.GetVideoCount() == 1 )
       
   344             {
       
   345             return LoadStringFromResourceLC( R_VCXHG_SEARCH_VIDEOS_FOUND_ONE );
       
   346             }
       
   347         else
       
   348             {
       
   349             return LoadStringFromResourceLC( R_VCXHG_SEARCH_VIDEOS_FOUND, 
       
   350                                              aCategory.GetVideoCount() );            
       
   351             }
       
   352         }
       
   353     else
       
   354         {
       
   355         if( aCategory.GetVideoCount() == 1 )
       
   356             {
       
   357             return LoadStringFromResourceLC( R_VCXHG_ONE_VIDEO_IN_CATEGORY );
       
   358             }
       
   359         else
       
   360             {
       
   361             return LoadStringFromResourceLC( R_VCXHG_VIDEOS_IN_CATEGORY,
       
   362                                              aCategory.GetVideoCount() );            
       
   363             }
       
   364         }
       
   365     }
       
   366 
       
   367 // -----------------------------------------------------------------------------
       
   368 // CVcxHgVodUtils::IsDefaultSmtpAccountDefinedL()
       
   369 // -----------------------------------------------------------------------------
       
   370 //
       
   371 TBool CVcxHgVodUtils::IsDefaultSmtpAccountDefinedL()
       
   372     {
       
   373     CEmailAccounts* mailAccounts = CEmailAccounts::NewLC();
       
   374 
       
   375     TSmtpAccount account;
       
   376     TInt error = mailAccounts->DefaultSmtpAccountL( account );
       
   377 
       
   378     CleanupStack::PopAndDestroy( mailAccounts );
       
   379     return ( KErrNone == error );
       
   380     }
       
   381 
       
   382 // -----------------------------------------------------------------------------
       
   383 // CVcxHgVodUtils::ShareLinkL()
       
   384 // -----------------------------------------------------------------------------
       
   385 //
       
   386 void CVcxHgVodUtils::ShareLinkL(
       
   387     const TDesC& aLink,
       
   388     const TUid aMessageTypeModule,
       
   389     CEikonEnv& aEikonEnv )
       
   390     {
       
   391     CSendUi* sendUi = CSendUi::NewLC();
       
   392     TInt linkLength = aLink.Length();
       
   393 
       
   394     // Must be able to send at least linkLength long body text,
       
   395     // make sure it's supported
       
   396     TSendingCapabilities sendingCapabilities(
       
   397         linkLength, linkLength, TSendingCapabilities::ESupportsBodyText );
       
   398 
       
   399     if ( sendUi->ValidateServiceL( aMessageTypeModule, sendingCapabilities ) )
       
   400         {
       
   401         CMessageData* message = CMessageData::NewLC();
       
   402         CRichText* richText = CRichText::NewL(
       
   403                 aEikonEnv.SystemParaFormatLayerL(),
       
   404                 aEikonEnv.SystemCharFormatLayerL() );
       
   405         CleanupStack::PushL( richText );
       
   406 
       
   407         richText->InsertL( 0, aLink );
       
   408         message->SetBodyTextL( richText );
       
   409 
       
   410         sendUi->CreateAndSendMessageL(
       
   411                 aMessageTypeModule,
       
   412                 message,
       
   413                 KNullUid,
       
   414                 EFalse ); // ETrue:  Open in embedded mode
       
   415                           // EFalse: Do not embed message editor
       
   416 
       
   417         CleanupStack::PopAndDestroy( richText );
       
   418         CleanupStack::PopAndDestroy( message );
       
   419         }
       
   420     else
       
   421         {
       
   422         // Sending link with aServiceUid is not supported
       
   423         User::Leave( KErrNotSupported );
       
   424         }
       
   425 
       
   426     CleanupStack::PopAndDestroy( sendUi );
       
   427     }
       
   428 
       
   429 // -----------------------------------------------------------------------------
       
   430 // CVcxHgVodUtils::DuplicateGulIconL()
       
   431 // -----------------------------------------------------------------------------
       
   432 //
       
   433 CGulIcon* CVcxHgVodUtils::DuplicateGulIconL( CGulIcon* aIcon )
       
   434     {
       
   435     CFbsBitmap* icon = new (ELeave) CFbsBitmap;
       
   436     CleanupStack::PushL( icon );
       
   437     
       
   438     CFbsBitmap* mask = NULL;
       
   439 
       
   440     icon->Duplicate( aIcon->Bitmap()->Handle() );
       
   441     
       
   442     if ( aIcon->Mask() )
       
   443         {
       
   444         mask = new (ELeave) CFbsBitmap();
       
   445         CleanupStack::PushL( mask );
       
   446         mask->Duplicate( aIcon->Mask()->Handle() );
       
   447         }
       
   448     
       
   449     CGulIcon* newIcon = CGulIcon::NewL( icon, mask );
       
   450     
       
   451     if ( mask )
       
   452         {
       
   453         CleanupStack::Pop( mask );
       
   454         }
       
   455     
       
   456     CleanupStack::Pop( icon );
       
   457     
       
   458     return newIcon;
       
   459     }