uifw/AknGlobalUI/AknCapServer/src/AknMemoryCardDialogImpl.cpp
changeset 0 2f259fa3e83a
child 10 9f56a4e1b8ab
child 45 667edd0b8678
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:  
       
    15 *
       
    16 */
       
    17 
       
    18 #include <AknQueryDialog.h>
       
    19 #include <aknmemorycardui.rsg>
       
    20 #include <StringLoader.h>
       
    21 #include <aknsoundsystem.h>
       
    22 #include <SecondaryDisplay/AknSecondaryDisplayDefs.h>
       
    23 #include "AknCapServerEntry.h"
       
    24 #include "AknCapServerDefs.h"
       
    25 #include "AknMemoryCardDialogImpl.h"
       
    26 
       
    27 class CAknCodeQuery: public CAknTextQueryDialog
       
    28     {
       
    29 public:
       
    30     CAknCodeQuery(
       
    31         TDes& aDataText, 
       
    32         const CAknTextQueryDialog::TTone& aTone = CAknTextQueryDialog::ENoTone);
       
    33         
       
    34     TBool OkToExitL(TInt aButtonId);
       
    35     void TryExit(TInt aButtonId); 
       
    36     void SetObserver(CAknCodeQuery** aSelf, CAknMMCPasswordRequester* aObserver );
       
    37     ~CAknCodeQuery(){};
       
    38     
       
    39 private:
       
    40     CAknMMCPasswordRequester* iObserver;
       
    41     CAknCodeQuery** iSelf;
       
    42     };
       
    43 
       
    44 CAknMMCPasswordRequester::CAknMMCPasswordRequester()
       
    45     {
       
    46     }
       
    47 
       
    48 CAknMMCPasswordRequester* CAknMMCPasswordRequester::NewL()
       
    49     {
       
    50     CAknMMCPasswordRequester* self = new (ELeave) CAknMMCPasswordRequester();
       
    51     CleanupStack::PushL(self);
       
    52     self->ConstructL();
       
    53     CleanupStack::Pop(); //self
       
    54     return self;
       
    55     }
       
    56 
       
    57 void CAknMMCPasswordRequester::ConstructL()
       
    58     {
       
    59     iResFileLdr.AddResourceFileL();
       
    60     }
       
    61 
       
    62 CAknMMCPasswordRequester::~CAknMMCPasswordRequester()
       
    63     {
       
    64     if (iQuery)
       
    65         {
       
    66         delete iQuery;
       
    67         CompleteAllMessages(KErrDied);
       
    68         }
       
    69 
       
    70     iResFileLdr.DeleteResourceFile();
       
    71 
       
    72     delete iPrompt;
       
    73     iPrompt = NULL;
       
    74     
       
    75     iMessages.Close();
       
    76     }
       
    77 
       
    78 void CAknMMCPasswordRequester::ClientExit( TInt aClientID, TBool aCompleteWithCancel )
       
    79     {
       
    80     for(TInt i = iMessages.Count()-1; i >= 0; i--)
       
    81         {
       
    82         if (iMessages[i].iClientId == aClientID)
       
    83             {
       
    84             if (aCompleteWithCancel)
       
    85                 {
       
    86                 iMessages[i].iMessage.Complete(KErrCancel);
       
    87                 }
       
    88             iMessages.Remove(i);
       
    89             break;
       
    90             }
       
    91         }
       
    92     }
       
    93     
       
    94 void CAknMMCPasswordRequester::CompleteAllMessages(TInt aReason)
       
    95    {
       
    96    for(TInt i = iMessages.Count()-1; i >= 0; i--)
       
    97         {
       
    98         iMessages[i].iMessage.Complete(aReason);
       
    99         iMessages.Remove(i);
       
   100         }
       
   101     }
       
   102 
       
   103 void CAknMMCPasswordRequester::AppendQueueItemL(const RMessagePtr2& aMessage, TInt aClientID)
       
   104     {
       
   105     if (!aClientID)
       
   106         {
       
   107         // recursive call for start (there must be active message before this can occur)
       
   108         __ASSERT_ALWAYS(iMessages.Count(), User::Invariant());
       
   109         return; 
       
   110         }
       
   111     for(TInt i = iMessages.Count()-1; i >= 0; i--)
       
   112         {
       
   113         if (iMessages[i].iClientId == aClientID)
       
   114             {
       
   115             User::Leave(KErrAlreadyExists);
       
   116             }
       
   117         }
       
   118     User::LeaveIfError(iMessages.Append(TMessageWithClientId(aMessage, aClientID)));
       
   119     }   
       
   120 
       
   121 void CAknMMCPasswordRequester::StartL(TInt aDrive, TBool aStore, const RMessagePtr2& aMessage, 
       
   122     TInt aClientID)
       
   123     {
       
   124     // Will leave if same client tries to activate new request while old pending, basically should
       
   125     // panic the client.
       
   126     AppendQueueItemL(aMessage, aClientID); 
       
   127     
       
   128     if (iQuery)
       
   129         {
       
   130         return;
       
   131         }
       
   132 
       
   133     iStore = aStore;
       
   134     iDriveNumber = aDrive;
       
   135     
       
   136     SetPromptL();
       
   137 
       
   138     iPassWd.FillZ(); // this is safe as we are derived from 
       
   139                      // CBase and this is done for every unlock operation
       
   140     iPassWd.Zero();
       
   141     
       
   142     iQuery = new (ELeave) CAknCodeQuery(iPassWd);
       
   143     iQuery->PrepareLC(R_MMC_PASSWORD_QUERY);
       
   144     iQuery->SetObserver(&iQuery,this);
       
   145 
       
   146     if (iPrompt)
       
   147         {
       
   148         iQuery->SetPromptL(*iPrompt);
       
   149         }
       
   150     
       
   151     CAknKeySoundSystem* sounds = iAvkonAppUi->KeySounds();
       
   152     // we are assuming that there is no need to bring sounds forwards more than once per operation
       
   153     if (iNumberOfAttempts == 0 && sounds ) 
       
   154         {
       
   155         sounds->BringToForeground();
       
   156         }
       
   157 
       
   158     iQuery->PublishDialogL(EAknMemoryCardQuery);
       
   159     iQuery->RunLD();
       
   160     // block apps key after it is sure that OkToExitL will be called for query
       
   161     ((CAknCapAppServerAppUi*)iAvkonAppUi)->SuppressAppSwitchingL(EAknAppsKeyBlockAddCount, 0);
       
   162     }
       
   163 
       
   164 void CAknMMCPasswordRequester::Cancel(TInt aClientID)
       
   165     {
       
   166     if ( iQuery )
       
   167         {
       
   168         if (iMessages.Count() == 1)
       
   169             {
       
   170             iQuery->TryExit( EEikBidCancel ); // completes the message        
       
   171             }
       
   172         else
       
   173             {
       
   174             ClientExit(aClientID, ETrue );
       
   175             }
       
   176         }
       
   177     }
       
   178 
       
   179 void CAknMMCPasswordRequester::SetPromptL()
       
   180     {
       
   181     delete iPrompt;
       
   182     iPrompt = NULL;
       
   183 
       
   184     if ( iNumberOfAttempts > 0 ) 
       
   185         {
       
   186         iPrompt = StringLoader::LoadL(R_QTN_MEM_CARD_UNLOCK_ERROR); 
       
   187         }
       
   188     else 
       
   189         {
       
   190         iPrompt = StringLoader::LoadL(R_QTN_MEM_CARD_UNLOCK_PROMPT);
       
   191         }
       
   192     }
       
   193 
       
   194 void CAknMMCPasswordRequester::UnlockCard(TBool aAccept)
       
   195     {
       
   196     if ( aAccept ) 
       
   197         {
       
   198         TMediaPassword p;
       
   199         p.FillZ(KMaxMediaPassword); // not sure if fileserver uses buffer length correctly
       
   200         p.Zero();
       
   201 
       
   202         const TUint8 *pt8Src = reinterpret_cast<const TUint8 *>(iPassWd.Ptr());
       
   203         // We use this to check whether there is something else than zeros in ttext8 array left
       
   204         const TUint16 *pt16Src = iPassWd.Ptr();
       
   205 
       
   206         for (TInt j = 0; j < KMaxMediaPassword / 2 && pt16Src[j]; ++j)
       
   207             {
       
   208             p.Append(pt8Src[j << 1]);
       
   209             p.Append(pt8Src[(j << 1) + 1]);
       
   210             }
       
   211 
       
   212         iNumberOfAttempts++;
       
   213         TInt err = CCoeEnv::Static()->FsSession().UnlockDrive(iDriveNumber,p,ETrue);
       
   214 #ifdef _DEBUG
       
   215         RDebug::Print(_L("CAknMMCPasswordRequester::Ulock ret: %D"),err);
       
   216 #endif
       
   217         if (err == KErrNone || err == KErrAlreadyExists)
       
   218             {
       
   219             CompleteAllMessages(KErrNone);
       
   220             iNumberOfAttempts = 0;
       
   221             }
       
   222         else 
       
   223             {
       
   224             // borrow top most message, it is not used anyway                
       
   225             TRAPD (err, StartL(iDriveNumber,iStore,iMessages[0].iMessage)); 
       
   226             if (err)
       
   227                 {
       
   228                 CompleteAllMessages(err); // To ensure that old instance of query will be deleted. 
       
   229                 }
       
   230             iNumberOfAttempts = 0;
       
   231             return;
       
   232             }
       
   233         }
       
   234     else // user or system cancel 
       
   235         {
       
   236         CompleteAllMessages(KErrCancel);
       
   237         iNumberOfAttempts = 0;
       
   238         }
       
   239     }
       
   240 
       
   241 CAknCodeQuery::CAknCodeQuery(TDes& aDataText, const CAknTextQueryDialog::TTone& aTone)
       
   242     :CAknTextQueryDialog(aDataText, aTone)
       
   243     {
       
   244     }
       
   245 
       
   246 TBool CAknCodeQuery::OkToExitL(TInt aButtonId)
       
   247     {
       
   248     TBool result = (aButtonId == EAknSoftkeyOk||aButtonId == EEikBidOk);
       
   249 
       
   250     if ( result )
       
   251         {
       
   252         CAknQueryControl* control = QueryControl();
       
   253         if (control)
       
   254             {
       
   255             control->GetText(iDataText);
       
   256             }
       
   257         }
       
   258     (*iSelf) = 0;
       
   259 
       
   260     iObserver->UnlockCard( result ); // synch, ie. query will be deleted after this returns !
       
   261     ((CAknCapAppServerAppUi*)iAvkonAppUi)->SuppressAppSwitchingL(EAknAppsKeyBlockDecreaseCount, 0);
       
   262     return ETrue;
       
   263     }
       
   264         
       
   265 void CAknCodeQuery::SetObserver(CAknCodeQuery** aSelf, CAknMMCPasswordRequester* aObserver )
       
   266     {
       
   267     iObserver = aObserver;
       
   268     iSelf = aSelf;
       
   269     }
       
   270 
       
   271 void CAknCodeQuery::TryExit(TInt aButtonId)
       
   272     { 
       
   273     TRAP_IGNORE( TryExitL(aButtonId));
       
   274     }
       
   275 
       
   276 // End of file