javauis/runtimeui_akn/src.s60/runtimeuiavkon.cpp
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 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 
       
    19 #include <string>
       
    20 #include <vector>
       
    21 #include "runtimeuiavkon.h"
       
    22 #include "globalmsgobserver.h"
       
    23 #include <AknGlobalMsgQuery.h>
       
    24 #include <AknGlobalListMsgQuery.h>
       
    25 #include <aknconsts.h>
       
    26 #include <avkon.mbg>
       
    27 
       
    28 using namespace java::runtimeui;
       
    29 
       
    30 OS_EXPORT void RuntimeUiAvkon::error(const TDesC& aAppName, const TDesC& aShortMsg, const TDesC& aDetailedMsg)
       
    31 {
       
    32     // create the answer observer/listener through which
       
    33     // AVKON delivers the user's answer
       
    34     TRAP_IGNORE(
       
    35         GlobalMsgObserver* msgObserver = GlobalMsgObserver::NewLC();
       
    36         CAknGlobalMsgQuery* errorMsgQuery = CAknGlobalMsgQuery::NewLC();
       
    37 
       
    38         // select the soft keys based on the existence of details:
       
    39         // OK only if there are no details available or
       
    40         // OK and DETAILS if details are available
       
    41         TInt softKeys = R_AVKON_SOFTKEYS_OK_EMPTY__OK;
       
    42         if (&aDetailedMsg && aDetailedMsg.Size() > 0)
       
    43 {
       
    44     softKeys = R_AVKON_SOFTKEYS_OK_DETAILS;
       
    45 }
       
    46 
       
    47 // show the short description of the error
       
    48 errorMsgQuery->ShowMsgQueryL(
       
    49     msgObserver->iStatus,
       
    50     aShortMsg,
       
    51     softKeys,
       
    52     aAppName,
       
    53     KNullDesC());
       
    54 if (msgObserver->getAnswer() == EAknSoftkeyDetails)
       
    55 {
       
    56     // show more details of the error
       
    57     errorMsgQuery->ShowMsgQueryL(// codescanner::leave
       
    58         msgObserver->iStatus,
       
    59         aDetailedMsg,
       
    60         R_AVKON_SOFTKEYS_OK_EMPTY__OK,
       
    61         aAppName,
       
    62         KNullDesC());
       
    63         msgObserver->getAnswer();
       
    64     }
       
    65     CleanupStack::PopAndDestroy(errorMsgQuery);
       
    66     CleanupStack::PopAndDestroy(msgObserver);
       
    67     );
       
    68 }
       
    69 
       
    70 OS_EXPORT bool RuntimeUiAvkon::confirm(const TDesC& aAppName, ConfirmData& aConfirmData, bool aIdentified)
       
    71 {
       
    72     TInt imageId = EMbmAvkonQgn_indi_midp_untrusted;
       
    73     TInt maskId = EMbmAvkonQgn_indi_midp_untrusted_mask;
       
    74     if (aIdentified)
       
    75     {
       
    76         imageId = EMbmAvkonQgn_indi_midp_trusted;
       
    77         maskId = EMbmAvkonQgn_indi_midp_trusted_mask;
       
    78     }
       
    79     bool answerAvailable = false;
       
    80     TRAP_IGNORE(
       
    81         GlobalMsgObserver* msgObserver = GlobalMsgObserver::NewLC();
       
    82         if (aConfirmData.iAnswerOptions.size() <= 2)
       
    83 {
       
    84     // use GlobalMsgQuery
       
    85     CAknGlobalMsgQuery* confirmMsgQuery = CAknGlobalMsgQuery::NewLC();
       
    86         switch (aConfirmData.iAnswerOptions.size())
       
    87         {
       
    88         case 0:
       
    89             confirmMsgQuery->ShowMsgQueryL(
       
    90                 msgObserver->iStatus,
       
    91                 aConfirmData.iQuestion,
       
    92                 R_AVKON_SOFTKEYS_OK_EMPTY__OK,
       
    93                 aAppName,
       
    94                 KAvkonBitmapFile,
       
    95                 imageId,
       
    96                 maskId);
       
    97             break;
       
    98         case 1:
       
    99             // SoftKeys should be something like R_AVKON_SOFTKEYS_iAnswerOptions[0]_EMPTY__OK
       
   100             confirmMsgQuery->ShowMsgQueryL(
       
   101                 msgObserver->iStatus,
       
   102                 aConfirmData.iQuestion,
       
   103                 R_AVKON_SOFTKEYS_OK_EMPTY__OK,
       
   104                 aAppName,
       
   105                 KAvkonBitmapFile,
       
   106                 imageId,
       
   107                 maskId);
       
   108             break;
       
   109         default:
       
   110             // SoftKeys should be something like R_AVKON_SOFTKEYS_iAnswerOptions[0]_iAnswerOptions[1]__OK
       
   111             confirmMsgQuery->ShowMsgQueryL(// codescanner::leave
       
   112                 msgObserver->iStatus,
       
   113                 aConfirmData.iQuestion,
       
   114                 R_AVKON_SOFTKEYS_YES_NO__YES,
       
   115                 aAppName,
       
   116                 KAvkonBitmapFile,
       
   117                 imageId,
       
   118                 maskId);
       
   119             break;
       
   120         }
       
   121     }
       
   122     else
       
   123     {
       
   124         // use GlobalListMsgQuery
       
   125         CDesCArray* answerOptions = new(ELeave) CDesCArrayFlat( // codescanner::leave
       
   126             aConfirmData.iAnswerOptions.size());
       
   127         CleanupStack::PushL(answerOptions);// codescanner::leave
       
   128         for (int i=0; i<aConfirmData.iAnswerOptions.size(); i++)
       
   129         {
       
   130             answerOptions->AppendL(*(aConfirmData.iAnswerOptions[i]));// codescanner::leave
       
   131         }
       
   132         CAknGlobalListMsgQuery* confirmMsgQuery =
       
   133             CAknGlobalListMsgQuery::NewLC();// codescanner::leave
       
   134         confirmMsgQuery->ShowListMsgQueryL(// codescanner::leave
       
   135             answerOptions,
       
   136             msgObserver->iStatus,
       
   137             aAppName,
       
   138             aConfirmData.iQuestion,
       
   139             aConfirmData.iAnswerSuggestion,
       
   140             R_AVKON_SOFTKEYS_OK_EMPTY__OK,
       
   141             EAknSoftkeyOk,
       
   142             0 /*EAknSoftkeyCancel*/,
       
   143             KAvkonBitmapFile,
       
   144             imageId,
       
   145             maskId);
       
   146     }
       
   147     int answer = msgObserver->getAnswer();
       
   148     CleanupStack::PopAndDestroy(); // confirmMsgQuery
       
   149     if (aConfirmData.iAnswerOptions.size() > 2)
       
   150 {
       
   151     CleanupStack::PopAndDestroy(); // answerOptions
       
   152     }
       
   153     CleanupStack::PopAndDestroy(msgObserver);
       
   154     if (answer == EAknSoftkeyCancel)
       
   155 {
       
   156     // no answer available
       
   157     answerAvailable = false;
       
   158 }
       
   159 else
       
   160 {
       
   161 
       
   162     switch (answer)
       
   163         {
       
   164         case EAknSoftkeyOk:
       
   165         case EAknSoftkeyYes:
       
   166             answer = 0;
       
   167             break;
       
   168         case EAknSoftkeyNo:
       
   169             answer = 1;
       
   170             break;
       
   171         }
       
   172         if (aConfirmData.iAnswerOptions.size() > 0)
       
   173         {
       
   174             aConfirmData.iAnswer = answer;
       
   175         }
       
   176         answerAvailable = true;
       
   177     }
       
   178     );
       
   179     return answerAvailable;
       
   180 }