uifw/AvKon/memorycardui/src/aknMemoryCardDialog.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002-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:  The dialog used to unlock memory card
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <stringresourcereader.h>
       
    21 #include <AknGlobalNote.h>
       
    22 #include <avkon.rsg>
       
    23 #include <pathinfo.h>
       
    24 #include <f32file.h>
       
    25 
       
    26 #include "aknmemorycarddialog.h"
       
    27 
       
    28 _LIT(KResFileName,         "z:\\resource\\avkon.rsc");
       
    29 
       
    30 // ======== LOCAL FUNCTIONS ========
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // NotifierArray
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 EXPORT_C   CArrayPtr<MEikSrvNotifierBase2>* NotifierArray()
       
    37     {
       
    38     return 0;
       
    39     }
       
    40 
       
    41 // ======== MEMBER FUNCTIONS ========
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // CAknMemoryCardDialog::NewLC
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 EXPORT_C CAknMemoryCardDialog* CAknMemoryCardDialog::NewLC(
       
    48     MAknMemoryCardDialogObserver* aObserver)
       
    49     {
       
    50     CAknMemoryCardDialog* self =
       
    51         new (ELeave) CAknMemoryCardDialog( aObserver );
       
    52     CleanupStack::PushL(self);
       
    53 
       
    54     // Locked (i.e. password protected) memory card support disabled / enabled.
       
    55     // Variation made with __MMC_LOCK feature flag.
       
    56     TInt lockedMMCsupported = EFalse;
       
    57 #ifdef __MMC_LOCK
       
    58     lockedMMCsupported = ETrue;
       
    59 #endif
       
    60     self->ConstructL( lockedMMCsupported );
       
    61     return self;
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CAknMemoryCardDialog::UnlockCardLD
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 EXPORT_C void CAknMemoryCardDialog::UnlockCardLD(TBool aStore)
       
    69     {
       
    70 #ifdef _DEBUG
       
    71     RDebug::Print(_L("CAknMemoryCardDialog::UnlockCardLD"));
       
    72 #endif
       
    73 
       
    74     CleanupStack::Pop(); //this
       
    75     iStore = aStore;
       
    76 
       
    77     TPath mmcRootPath = PathInfo::MemoryCardRootPath();
       
    78     TDriveUnit unit( mmcRootPath );
       
    79     TDriveNumber defaultMMCDrive = TDriveNumber( TInt( unit ) );
       
    80     StartL( defaultMMCDrive );
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // CAknMemoryCardDialog::SetSelfPointer
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 EXPORT_C void CAknMemoryCardDialog::SetSelfPointer(
       
    88     CAknMemoryCardDialog** aSelf)
       
    89     {
       
    90     iSelf = aSelf;
       
    91     }
       
    92 
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // C++ constructor
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 CAknMemoryCardDialog::CAknMemoryCardDialog(
       
    99     MAknMemoryCardDialogObserver* aObserver)
       
   100     : CActive(CActive::EPriorityLow),
       
   101       iObserver(aObserver)
       
   102     {
       
   103     CActiveScheduler::Add( this );
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // Symbian C++ constructor
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 void CAknMemoryCardDialog::ConstructL( TBool aUnlock )
       
   111     {
       
   112     iStubInUse = !aUnlock;
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // C++ destructor
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 CAknMemoryCardDialog::~CAknMemoryCardDialog()
       
   120     {
       
   121     iBoolDeletingAlready = ETrue;
       
   122 
       
   123     Cancel();
       
   124 
       
   125     if ( iSelf )
       
   126         {
       
   127         ( *iSelf ) = 0;
       
   128         }
       
   129 
       
   130     iAknCapServerClient.Close();
       
   131     if ( !iObserverNotified && iObserver )
       
   132         {
       
   133         iObserver->UnlockComplete( KErrCancel );
       
   134         }
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // From CActive
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 void CAknMemoryCardDialog::DoCancel()
       
   142     {
       
   143     iAknCapServerClient.CancelUnlockMedia();
       
   144     if ( !iBoolDeletingAlready )
       
   145         {
       
   146         delete this;
       
   147         }
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // From CActive
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 void CAknMemoryCardDialog::RunL()
       
   155     {
       
   156     NotifyObserverAndExit( iStatus.Int() );
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // CAknMemoryCardDialog::StartL
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 void CAknMemoryCardDialog::StartL( TDriveNumber& aDrive )
       
   164     {
       
   165     if ( IsActive() )
       
   166         return;
       
   167 
       
   168     if ( !iStubInUse )
       
   169         {
       
   170         iAknCapServerClient.UnlockMedia( aDrive, iStore, iStatus );
       
   171         SetActive();
       
   172         }
       
   173     else
       
   174         {
       
   175         CAknGlobalNote*note = CAknGlobalNote::NewLC();
       
   176         // load Note text
       
   177         TFileName resourceFile = KResFileName();
       
   178         CStringResourceReader* reader =
       
   179             CStringResourceReader::NewLC(resourceFile);
       
   180         HBufC* noteText =
       
   181             reader->ReadResourceString(R_AKN_LOCKED_MEMORY_CARD_NOT_SUPPORTED)
       
   182             .AllocLC();
       
   183             
       
   184         // ignore return value            
       
   185         note->ShowNoteL( EAknGlobalInformationNote, *noteText );
       
   186         
       
   187         CleanupStack::PopAndDestroy(3); // note, reader and text
       
   188 
       
   189         SetActive();
       
   190         TRequestStatus* ptr = &iStatus;
       
   191         User::RequestComplete( ptr, KErrCancel );
       
   192         }
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // CAknMemoryCardDialog::NotifyObserverAndExit
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 void CAknMemoryCardDialog::NotifyObserverAndExit( TInt aResult ) const
       
   200     {
       
   201     // ugly const cast..
       
   202     ((CAknMemoryCardDialog*)this)->iObserverNotified = ETrue; 
       
   203     
       
   204     if ( iObserver )
       
   205         {
       
   206 #ifdef _DEBUG
       
   207         RDebug::Print(_L("CAknMemoryCardDialog::UnlockComplete: %D"), aResult);
       
   208 #endif
       
   209         iObserver->UnlockComplete(aResult);
       
   210         }
       
   211         
       
   212     if ( !iBoolDeletingAlready )
       
   213         {
       
   214         delete this;
       
   215         }
       
   216     }
       
   217 
       
   218 // ---------------------------------------------------------------------------
       
   219 // CAknMemoryCardDialog::UnlockCardLD
       
   220 // ---------------------------------------------------------------------------
       
   221 //
       
   222 EXPORT_C void CAknMemoryCardDialog::UnlockCardLD(
       
   223     TDriveNumber& aDrive, TBool aStore)
       
   224     {
       
   225 #ifdef _DEBUG
       
   226     RDebug::Print(_L("CAknMemoryCardDialog::UnlockCardLD"));
       
   227 #endif
       
   228 
       
   229     CleanupStack::Pop(); //this
       
   230     iStore = aStore;
       
   231 
       
   232     StartL( aDrive );
       
   233     }