videocollection/hgmyvideos/src/vcxhgmyvideosmemorystatus.cpp
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2008 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:      Common model class for component*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <aknmessagequerydialog.h>
       
    22 #include <StringLoader.h>
       
    23 #include "CIptvDriveMonitor.h"
       
    24 #include <vcxhgmyvideos.rsg>
       
    25 #include "vcxhgmyvideosmodel.h"
       
    26 #include "vcxhgmyvideosmemorystatus.h"
       
    27 
       
    28 // CONSTANTS
       
    29 _LIT( KEnterString, "\n" );
       
    30 const TInt KVcxHgExtraSpace ( 20 );
       
    31 const TInt KVcxHgVideoSizeGB ( 0x40000000 );
       
    32 const TInt KVcxHgVideoSizeHalfGB ( 0x20000000 );
       
    33 const TInt KVcxHgVideoSizeMB ( 0x100000 );
       
    34 const TInt KVcxHgVideoSizeHalfMB ( 0x80000 );
       
    35 const TInt KVcxHgVideoSizeKB ( 0x400 );
       
    36 const TInt KVcxHgVideoSizeHalfKB ( 0x200 );
       
    37 const TUint64 KVcxHgFullPercentage ( 100 );
       
    38 
       
    39 // ========================== MEMBER FUNCTIONS ===============================
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // TVcxHgMyVideosMemoryStatusDialog::TVcxHgMyVideosMemoryStatusDialog()
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 TVcxHgMyVideosMemoryStatusDialog::TVcxHgMyVideosMemoryStatusDialog()
       
    46     {
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // TVcxHgMyVideosMemoryStatusDialog::ShowMemoryStatusDialogL()
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 void TVcxHgMyVideosMemoryStatusDialog::ShowMemoryStatusDialogL( CVcxHgMyVideosModel& aModel )
       
    54     {
       
    55     HBufC* strFreeMemory = NULL;
       
    56     HBufC* strUsedMemory = NULL;
       
    57     TUint64 dispSize = 0;
       
    58     TUint64 driveTotalSize = 0;
       
    59     TUint64 driveFreeSize = 0;
       
    60     TUint64 driveUsedSize = 0;
       
    61     TInt freePercentage = 0;
       
    62     TInt usedPercentage = 0;
       
    63     TVolumeInfo volumeInfo;
       
    64 
       
    65     for ( TInt i = 0; i < aModel.DriveMonitorL().iAvailableDrives.Count(); i++ )
       
    66             {
       
    67             if ( aModel.FileServerSessionL().Volume( 
       
    68                      volumeInfo, aModel.DriveMonitorL().iAvailableDrives[i].iDrive )
       
    69                  == KErrNone )
       
    70                 {
       
    71                 driveFreeSize += volumeInfo.iFree;
       
    72                 driveTotalSize += volumeInfo.iSize;
       
    73                 }
       
    74             }
       
    75 
       
    76     if ( !driveTotalSize )
       
    77         {
       
    78         freePercentage = 0;
       
    79         }
       
    80     else
       
    81         {
       
    82         freePercentage = driveFreeSize * KVcxHgFullPercentage / driveTotalSize;
       
    83         }
       
    84     
       
    85     usedPercentage = KVcxHgFullPercentage - freePercentage;
       
    86     driveUsedSize = driveTotalSize - driveFreeSize;
       
    87 
       
    88     HBufC* strFreePercentage = StringLoader::LoadLC( R_VCXHGMYVIDEOS_MEMORY_PERCENTAGE,
       
    89                                    ( freePercentage ) );
       
    90     HBufC* strUsedPercentage = StringLoader::LoadLC( R_VCXHGMYVIDEOS_MEMORY_PERCENTAGE, 
       
    91                                    ( usedPercentage ) );
       
    92 
       
    93     HBufC* FreeMemoryTitle = StringLoader::LoadLC( R_VCXHGMYVIDEOS_FREE_MEMORY );    
       
    94     
       
    95     if ( driveFreeSize >= KVcxHgVideoSizeGB )
       
    96         {
       
    97         dispSize = driveFreeSize + KVcxHgVideoSizeHalfGB;
       
    98         dispSize /= KVcxHgVideoSizeGB;
       
    99         strFreeMemory = StringLoader::LoadLC( R_VCXHGMYVIDEOS_SIZE_GB_SHORT,
       
   100                                                     static_cast<TUint32>( dispSize ) );        
       
   101         }
       
   102     
       
   103     else if ( driveFreeSize >= KVcxHgVideoSizeMB )
       
   104         {
       
   105         dispSize = driveFreeSize + KVcxHgVideoSizeHalfMB;
       
   106         dispSize /= KVcxHgVideoSizeMB;
       
   107         strFreeMemory = StringLoader::LoadLC( R_VCXHGMYVIDEOS_SIZE_MB_SHORT,
       
   108                                                     static_cast<TUint32>( dispSize ) );        
       
   109         }
       
   110     
       
   111     else
       
   112         {
       
   113         dispSize = driveFreeSize + KVcxHgVideoSizeHalfKB;
       
   114         dispSize /= KVcxHgVideoSizeKB;
       
   115         strFreeMemory = StringLoader::LoadLC( R_VCXHGMYVIDEOS_SIZE_KB_SHORT,
       
   116                                                     static_cast<TUint32>( dispSize ) );        
       
   117         }
       
   118     
       
   119     HBufC* UsedMemoryTitle = StringLoader::LoadLC( R_VCXHGMYVIDEOS_USED_MEMORY );
       
   120 
       
   121     if ( driveUsedSize >= KVcxHgVideoSizeGB )
       
   122         {
       
   123         dispSize = driveUsedSize + KVcxHgVideoSizeHalfGB;
       
   124         dispSize /= KVcxHgVideoSizeGB;
       
   125         strUsedMemory = StringLoader::LoadLC( R_VCXHGMYVIDEOS_SIZE_GB_SHORT,
       
   126                                                     static_cast<TUint32>( dispSize ) );        
       
   127         }
       
   128     
       
   129     else if ( driveUsedSize >= KVcxHgVideoSizeMB )
       
   130         {
       
   131         dispSize = driveUsedSize + KVcxHgVideoSizeHalfMB;
       
   132         dispSize /= KVcxHgVideoSizeMB;
       
   133         strUsedMemory = StringLoader::LoadLC( R_VCXHGMYVIDEOS_SIZE_MB_SHORT,
       
   134                                                     static_cast<TUint32>( dispSize ) );        
       
   135         }
       
   136     
       
   137     else
       
   138         {
       
   139         dispSize = driveUsedSize + KVcxHgVideoSizeHalfKB;
       
   140         dispSize /= KVcxHgVideoSizeKB;
       
   141         strUsedMemory = StringLoader::LoadLC( R_VCXHGMYVIDEOS_SIZE_KB_SHORT,
       
   142                                                     static_cast<TUint32>( dispSize ) );        
       
   143         }    
       
   144     
       
   145     HBufC* context = HBufC::NewLC(FreeMemoryTitle->Length() +
       
   146                                   strFreePercentage->Length() +
       
   147                                   strFreeMemory->Length() +
       
   148                                   UsedMemoryTitle->Length() +
       
   149                                   strUsedPercentage->Length() +
       
   150                                   strUsedMemory->Length() +
       
   151                                   KVcxHgExtraSpace );
       
   152     
       
   153     context->Des().Append( *FreeMemoryTitle );
       
   154     context->Des().Append( KEnterString );
       
   155     context->Des().Append( *strFreePercentage);
       
   156     context->Des().Append( KEnterString );
       
   157     context->Des().Append( *strFreeMemory );
       
   158     context->Des().Append( KEnterString );
       
   159     context->Des().Append( *UsedMemoryTitle );
       
   160     context->Des().Append( KEnterString );
       
   161     context->Des().Append( *strUsedPercentage );
       
   162     context->Des().Append( KEnterString );
       
   163     context->Des().Append( *strUsedMemory );
       
   164                                
       
   165     CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL( *context );
       
   166     dlg->ExecuteLD(R_VCXHGMYVIDEOS_MEMORY_STATUS_MESSAGE_QUERY);
       
   167 
       
   168     CleanupStack::PopAndDestroy( context );
       
   169     CleanupStack::PopAndDestroy( strUsedMemory );
       
   170     CleanupStack::PopAndDestroy( UsedMemoryTitle );
       
   171     CleanupStack::PopAndDestroy( strFreeMemory );
       
   172     CleanupStack::PopAndDestroy( FreeMemoryTitle );
       
   173     CleanupStack::PopAndDestroy( strUsedPercentage );
       
   174     CleanupStack::PopAndDestroy( strFreePercentage );
       
   175     }