javauis/runtimeui_qt/src.s60/jni.cpp
changeset 21 2a9601315dfc
child 78 71ad690e91f5
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     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 #include <vector>
       
    19 #include "javajniutils.h"
       
    20 #include "jstringutils.h"
       
    21 #include "runtimeuiqt.h"
       
    22 #include "com_nokia_mj_impl_rt_ui_qt_RuntimeUiQt.h"
       
    23 
       
    24 #include "logger.h"
       
    25 
       
    26 using namespace java::runtimeui;
       
    27 
       
    28 JNIEXPORT jboolean JNICALL Java_com_nokia_mj_impl_rt_ui_qt_RuntimeUiQt__1confirm
       
    29 (JNIEnv * aEnv, jobject, jstring aAppName, jobject aConfirmData, jboolean /*aIdentified*/)
       
    30 {
       
    31     // Identified parameter is not used. It was earlier used to add icon to query header
       
    32     // and that is currently not supported.
       
    33 
       
    34     CActiveScheduler* newScheduler = 0;
       
    35 
       
    36     if (CActiveScheduler::Current() == 0)
       
    37     {
       
    38         // Create AS as not yet exists.
       
    39         newScheduler = new CActiveScheduler;
       
    40         CActiveScheduler::Install(newScheduler);
       
    41     }
       
    42 
       
    43     // unmarshall the JNI parameters
       
    44     JStringUtils appName(*aEnv, aAppName);
       
    45     jclass confirmDataClass = aEnv->GetObjectClass(aConfirmData);
       
    46     jmethodID getQuestionMethod
       
    47     = aEnv->GetMethodID(confirmDataClass,"getQuestion", "()Ljava/lang/String;");
       
    48     jstring jQuestion = (jstring) aEnv->CallObjectMethod(
       
    49                             aConfirmData, getQuestionMethod);
       
    50     JStringUtils question(*aEnv, jQuestion);
       
    51 
       
    52     int answer = -1;
       
    53     bool result = false;
       
    54 
       
    55     TRAPD(err, answer = RuntimeUiQt::confirmL(appName, question));
       
    56 
       
    57     if (KErrNone != err)
       
    58     {
       
    59         ELOG1(EJavaRuntime, "Error while showing confirmation dialog: %d", err);
       
    60     }
       
    61     else
       
    62     {
       
    63         // marshall the answer back to Java
       
    64         jmethodID setAnswerMethod = aEnv->GetMethodID(confirmDataClass,"setAnswer", "(I)V");
       
    65         aEnv->CallVoidMethod(aConfirmData, setAnswerMethod, answer);
       
    66         result = true;
       
    67     }
       
    68 
       
    69     delete newScheduler;
       
    70     return result;
       
    71 }
       
    72 
       
    73 JNIEXPORT void JNICALL Java_com_nokia_mj_impl_rt_ui_qt_RuntimeUiQt__1error
       
    74 (JNIEnv * aEnv, jobject, jstring aAppName, jstring aShortMsg, jstring aDetailedMsg)
       
    75 {
       
    76     CActiveScheduler* newScheduler = 0;
       
    77 
       
    78     if (CActiveScheduler::Current() == 0)
       
    79     {
       
    80         // Create AS as not yet exists.
       
    81         newScheduler = new CActiveScheduler;
       
    82         CActiveScheduler::Install(newScheduler);
       
    83     }
       
    84 
       
    85     // unmarshall the JNI parameters
       
    86     JStringUtils appName(*aEnv, aAppName);
       
    87     JStringUtils shortMsg(*aEnv, aShortMsg);
       
    88     JStringUtils detailedMsg(*aEnv, aDetailedMsg);
       
    89 
       
    90     // delegate the UI implementation to handle the error operation
       
    91     TRAPD(err, RuntimeUiQt::errorL(appName, shortMsg, detailedMsg));
       
    92 
       
    93     if (KErrNone != err)
       
    94     {
       
    95         ELOG1(EJavaRuntime, "Error while showing error dialog: %d", err);
       
    96     }
       
    97     delete newScheduler;
       
    98 }