1 /* |
1 /* |
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
24 #include "logger.h" |
24 #include "logger.h" |
25 |
25 |
26 using namespace java::runtimeui; |
26 using namespace java::runtimeui; |
27 |
27 |
28 JNIEXPORT jboolean JNICALL Java_com_nokia_mj_impl_rt_ui_qt_RuntimeUiQt__1confirm |
28 JNIEXPORT jboolean JNICALL Java_com_nokia_mj_impl_rt_ui_qt_RuntimeUiQt__1confirm |
29 (JNIEnv * aEnv, jobject, jstring aAppName, jobject aConfirmData, jboolean /*aIdentified*/) |
29 (JNIEnv * aEnv, jobject, jstring aAppName, jobject aConfirmData, jboolean aIdentified) |
30 { |
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; |
31 CActiveScheduler* newScheduler = 0; |
35 |
32 |
36 if (CActiveScheduler::Current() == 0) |
33 if (CActiveScheduler::Current() == 0) |
37 { |
34 { |
38 // Create AS as not yet exists. |
35 // Create AS as not yet exists. |
47 = aEnv->GetMethodID(confirmDataClass,"getQuestion", "()Ljava/lang/String;"); |
44 = aEnv->GetMethodID(confirmDataClass,"getQuestion", "()Ljava/lang/String;"); |
48 jstring jQuestion = (jstring) aEnv->CallObjectMethod( |
45 jstring jQuestion = (jstring) aEnv->CallObjectMethod( |
49 aConfirmData, getQuestionMethod); |
46 aConfirmData, getQuestionMethod); |
50 JStringUtils question(*aEnv, jQuestion); |
47 JStringUtils question(*aEnv, jQuestion); |
51 |
48 |
52 int answer = -1; |
49 std::vector<HBufC*> answerOptions; |
|
50 jmethodID getAnswerOptionsMethod = aEnv->GetMethodID( |
|
51 confirmDataClass,"getAnswerOptions", "()[Ljava/lang/String;"); |
|
52 jobjectArray jAnswerOptions = (jobjectArray)aEnv->CallObjectMethod( |
|
53 aConfirmData, getAnswerOptionsMethod); |
|
54 if (jAnswerOptions != NULL) |
|
55 { |
|
56 int len = aEnv->GetArrayLength(jAnswerOptions); |
|
57 answerOptions.reserve(len); |
|
58 |
|
59 for (int i=0; i<len; i++) |
|
60 { |
|
61 jstring jAnswerOption = (jstring)aEnv->GetObjectArrayElement( |
|
62 jAnswerOptions, i); |
|
63 JStringUtils answerOption(*aEnv, jAnswerOption); |
|
64 answerOptions.push_back(answerOption.Alloc()); // If alloc fails NULL is added. |
|
65 } |
|
66 } |
|
67 |
|
68 // Answer suggestion is not supported because of touch UIs. |
|
69 ConfirmData confirmData(question, answerOptions, -1); |
|
70 |
|
71 int answer = ConfirmData::NO_ANSWER; |
53 bool result = false; |
72 bool result = false; |
54 |
73 |
55 TRAPD(err, answer = RuntimeUiQt::confirmL(appName, question)); |
74 TRAPD(err, answer = RuntimeUiQt::confirmL(appName, question, confirmData, aIdentified)); |
56 |
75 |
57 if (KErrNone != err) |
76 if (KErrNone != err) |
58 { |
77 { |
59 ELOG1(EJavaRuntime, "Error while showing confirmation dialog: %d", err); |
78 ELOG1(EJavaRuntime, "Error while showing confirmation dialog: %d", err); |
60 } |
79 } |
64 jmethodID setAnswerMethod = aEnv->GetMethodID(confirmDataClass,"setAnswer", "(I)V"); |
83 jmethodID setAnswerMethod = aEnv->GetMethodID(confirmDataClass,"setAnswer", "(I)V"); |
65 aEnv->CallVoidMethod(aConfirmData, setAnswerMethod, answer); |
84 aEnv->CallVoidMethod(aConfirmData, setAnswerMethod, answer); |
66 result = true; |
85 result = true; |
67 } |
86 } |
68 |
87 |
|
88 for (int i=0; i<answerOptions.size(); i++) |
|
89 { |
|
90 delete answerOptions.at(i); |
|
91 } |
|
92 |
|
93 // cleanup the vector |
|
94 answerOptions.clear(); |
69 delete newScheduler; |
95 delete newScheduler; |
|
96 |
70 return result; |
97 return result; |
71 } |
98 } |
72 |
99 |
73 JNIEXPORT void JNICALL Java_com_nokia_mj_impl_rt_ui_qt_RuntimeUiQt__1error |
100 JNIEXPORT void JNICALL Java_com_nokia_mj_impl_rt_ui_qt_RuntimeUiQt__1error |
74 (JNIEnv * aEnv, jobject, jstring aAppName, jstring aShortMsg, jstring aDetailedMsg) |
101 (JNIEnv * aEnv, jobject, jstring aAppName, jstring aShortMsg, jstring aDetailedMsg, jstring aDetailsButton, jstring aOkButton) |
75 { |
102 { |
76 CActiveScheduler* newScheduler = 0; |
103 CActiveScheduler* newScheduler = 0; |
77 |
104 |
78 if (CActiveScheduler::Current() == 0) |
105 if (CActiveScheduler::Current() == 0) |
79 { |
106 { |
84 |
111 |
85 // unmarshall the JNI parameters |
112 // unmarshall the JNI parameters |
86 JStringUtils appName(*aEnv, aAppName); |
113 JStringUtils appName(*aEnv, aAppName); |
87 JStringUtils shortMsg(*aEnv, aShortMsg); |
114 JStringUtils shortMsg(*aEnv, aShortMsg); |
88 JStringUtils detailedMsg(*aEnv, aDetailedMsg); |
115 JStringUtils detailedMsg(*aEnv, aDetailedMsg); |
|
116 JStringUtils detailsButton(*aEnv, aDetailsButton); |
|
117 JStringUtils okButton(*aEnv, aOkButton); |
89 |
118 |
90 // delegate the UI implementation to handle the error operation |
119 // delegate the UI implementation to handle the error operation |
91 TRAPD(err, RuntimeUiQt::errorL(appName, shortMsg, detailedMsg)); |
120 TRAPD(err, RuntimeUiQt::errorL(appName, shortMsg, detailedMsg, detailsButton, okButton)); |
92 |
121 |
93 if (KErrNone != err) |
122 if (KErrNone != err) |
94 { |
123 { |
95 ELOG1(EJavaRuntime, "Error while showing error dialog: %d", err); |
124 ELOG1(EJavaRuntime, "Error while showing error dialog: %d", err); |
96 } |
125 } |