phonebookui/Phonebook2/CommonUI/src/CPbk2CompressPolicyDiskSpace.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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 *     Phonebook 2 compress policy disk space utility.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbk2CompressPolicyDiskSpace.h"
       
    22 
       
    23 // Phonebook 2
       
    24 #include "MPbk2CompressPolicyManager.h"
       
    25 
       
    26 // Debugging headers
       
    27 #include <Pbk2Debug.h>
       
    28 
       
    29 // --------------------------------------------------------------------------
       
    30 // CPbk2CompressPolicyDiskSpace::CPbk2CompressPolicyDiskSpace
       
    31 // --------------------------------------------------------------------------
       
    32 //
       
    33 inline CPbk2CompressPolicyDiskSpace::CPbk2CompressPolicyDiskSpace
       
    34         ( MPbk2CompressPolicyManager& aManager,
       
    35         RFs& aFs, TInt64 aThreshold, TInt aDrive ) :
       
    36             CActive( CActive::EPriorityIdle ),
       
    37             iManager( aManager ), iFs( aFs ),
       
    38             iThreshold( aThreshold ), iDrive( aDrive )
       
    39     {
       
    40     CActiveScheduler::Add(this);
       
    41     }
       
    42 
       
    43 // --------------------------------------------------------------------------
       
    44 // CPbk2CompressPolicyDiskSpace::~CPbk2CompressPolicyDiskSpace
       
    45 // --------------------------------------------------------------------------
       
    46 //
       
    47 CPbk2CompressPolicyDiskSpace::~CPbk2CompressPolicyDiskSpace()
       
    48     {
       
    49     Cancel();
       
    50     }
       
    51 
       
    52 // --------------------------------------------------------------------------
       
    53 // CPbk2CompressPolicyDiskSpace::NewL
       
    54 // --------------------------------------------------------------------------
       
    55 //
       
    56 CPbk2CompressPolicyDiskSpace* CPbk2CompressPolicyDiskSpace::NewL
       
    57         (MPbk2CompressPolicyManager& aManager,
       
    58         RFs& aFs, TInt64 aThreshold, TInt aDrive)
       
    59     {
       
    60     CPbk2CompressPolicyDiskSpace* self =
       
    61         new ( ELeave ) CPbk2CompressPolicyDiskSpace
       
    62                 ( aManager, aFs, aThreshold, aDrive );
       
    63     return self;
       
    64     }
       
    65 
       
    66 // --------------------------------------------------------------------------
       
    67 // CPbk2CompressPolicyDiskSpace::Start
       
    68 // --------------------------------------------------------------------------
       
    69 //
       
    70 void CPbk2CompressPolicyDiskSpace::Start()
       
    71     {
       
    72     RequestNotification();
       
    73     }
       
    74 
       
    75 // --------------------------------------------------------------------------
       
    76 // CPbk2CompressPolicyDiskSpace::Stop
       
    77 // --------------------------------------------------------------------------
       
    78 //
       
    79 void CPbk2CompressPolicyDiskSpace::Stop()
       
    80     {
       
    81     Cancel();
       
    82     }
       
    83 
       
    84 // --------------------------------------------------------------------------
       
    85 // CPbk2CompressPolicyDiskSpace::DoCancel
       
    86 // --------------------------------------------------------------------------
       
    87 //
       
    88 void CPbk2CompressPolicyDiskSpace::DoCancel()
       
    89     {
       
    90     iFs.NotifyDiskSpaceCancel();
       
    91     }
       
    92 
       
    93 // --------------------------------------------------------------------------
       
    94 // CPbk2CompressPolicyDiskSpace::RunL
       
    95 // --------------------------------------------------------------------------
       
    96 //
       
    97 void CPbk2CompressPolicyDiskSpace::RunL()
       
    98     {
       
    99     PBK2_DEBUG_PRINT(   PBK2_DEBUG_STRING
       
   100         (   "CPbk2CompressPolicyDiskSpace::RunL() executed" ) );
       
   101 
       
   102     // Leave if NotifyDiskSpace signals error
       
   103     User::LeaveIfError(iStatus.Int());
       
   104 
       
   105     // Disk space is below CL -> initiate a compress
       
   106     iManager.CompressStores();
       
   107     // Renew notification request
       
   108     RequestNotification();
       
   109     }
       
   110 
       
   111 // --------------------------------------------------------------------------
       
   112 // CPbk2CompressPolicyDiskSpace::RunError
       
   113 // --------------------------------------------------------------------------
       
   114 //
       
   115 TInt CPbk2CompressPolicyDiskSpace::RunError( TInt /*aError*/ )
       
   116     {
       
   117     // Compression is a silent background operation -> ignore all errors
       
   118     return KErrNone;
       
   119     }
       
   120 
       
   121 // --------------------------------------------------------------------------
       
   122 // CPbk2CompressPolicyDiskSpace::RequestNotification
       
   123 // --------------------------------------------------------------------------
       
   124 //
       
   125 void CPbk2CompressPolicyDiskSpace::RequestNotification()
       
   126     {
       
   127     Cancel();
       
   128     iFs.NotifyDiskSpace( iThreshold, KDefaultDrive, iStatus );
       
   129     SetActive();
       
   130     }
       
   131 
       
   132 //  End of File