|
1 /******************************************************************************* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. This program and the accompanying materials |
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
|
5 * which accompanies this distribution, and is available at |
|
6 * http://www.eclipse.org/legal/epl-v10.html |
|
7 * |
|
8 * Contributors: |
|
9 * Nokia Corporation - initial implementation |
|
10 *******************************************************************************/ |
|
11 |
|
12 #include <QPoint> |
|
13 #include <QString> |
|
14 #include <QUrl> |
|
15 #include <QModelIndex> |
|
16 #ifdef __SYMBIAN32__ |
|
17 #include <cntservicescontact.h> |
|
18 #endif |
|
19 |
|
20 #include "QItemSelection" |
|
21 #include "QListWidgetItem" |
|
22 |
|
23 #include "slotcallback.h" |
|
24 #include "jniutils.h" |
|
25 #include "swtapplication.h" |
|
26 #include "swtlog.h" |
|
27 |
|
28 using namespace Java::eSWT; |
|
29 |
|
30 SlotCallback::SlotCallback(JNIEnv* aJniEnv, jobject aPeer, QObject* aParent, const int& aSignalId) |
|
31 : QObject(aParent), |
|
32 mJniEnv(aJniEnv), |
|
33 mPeer(NULL), |
|
34 mJmethod(NULL), |
|
35 mSignalId(aSignalId) |
|
36 { |
|
37 SWT_LOG_FUNC_CALL(); |
|
38 |
|
39 // If Java peer is not Display then jobject ref and methodID are needed. |
|
40 // Otherwise they are managed by JniUtils. |
|
41 if (aPeer != NULL) |
|
42 { |
|
43 mPeer = aJniEnv->NewGlobalRef(aPeer); |
|
44 if(!mPeer) |
|
45 { |
|
46 throw std::bad_alloc(); |
|
47 } |
|
48 mJmethod = swtApp->jniUtils().FindJavaMethodID(aJniEnv, mPeer, "eventProcess", |
|
49 "(IIIIIIIILjava/lang/String;)Z"); |
|
50 if(!mJmethod) |
|
51 { |
|
52 throw std::bad_alloc(); |
|
53 } |
|
54 } |
|
55 } |
|
56 |
|
57 SlotCallback::~SlotCallback() |
|
58 { |
|
59 SWT_LOG_FUNC_CALL(); |
|
60 if (mPeer) |
|
61 { |
|
62 mJniEnv->DeleteGlobalRef(mPeer); |
|
63 } |
|
64 } |
|
65 |
|
66 void SlotCallback::callJava(const int& a1, const int& a2, const int& a3, |
|
67 const int& a4, const int& a5, const jstring aString) |
|
68 { |
|
69 JniUtils& jniUtils = swtApp->jniUtils(); |
|
70 if (mPeer) |
|
71 { |
|
72 // Call non-Display peer using our own jobject ref and jmethodID |
|
73 jniUtils.eventProcess(mPeer, mJmethod, parent(), mSignalId, a1, a2, a3, a4, a5, aString); |
|
74 } |
|
75 else |
|
76 { |
|
77 // Call Display peer, JniUtils manages the jobject ref and jmethodID |
|
78 jniUtils.eventProcess(parent(), mSignalId, a1, a2, a3, a4, a5, aString); |
|
79 } |
|
80 } |
|
81 |
|
82 void SlotCallback::widgetSignal() |
|
83 { |
|
84 SWT_LOG_FUNC_CALL(); |
|
85 callJava(); |
|
86 } |
|
87 |
|
88 void SlotCallback::widgetSignal(int aInt) |
|
89 { |
|
90 SWT_LOG_FUNC_CALL(); |
|
91 callJava(aInt); |
|
92 } |
|
93 #ifndef QT_NO_SYSTEMTRAYICON |
|
94 void SlotCallback::widgetSignal(QSystemTrayIcon::ActivationReason aReason) |
|
95 { |
|
96 SWT_LOG_FUNC_CALL(); |
|
97 callJava(aReason); |
|
98 } |
|
99 #endif |
|
100 void SlotCallback::widgetSignal(int aInt1, int aInt2) |
|
101 { |
|
102 SWT_LOG_FUNC_CALL(); |
|
103 callJava(aInt1, aInt2); |
|
104 } |
|
105 |
|
106 void SlotCallback::widgetSignal(int aInt1, int aInt2, int aInt3) |
|
107 { |
|
108 SWT_LOG_FUNC_CALL(); |
|
109 callJava(aInt1, aInt2, aInt3); |
|
110 } |
|
111 |
|
112 void SlotCallback::widgetSignal(int aInt1, int aInt2, int aInt3, int aInt4) |
|
113 { |
|
114 SWT_LOG_FUNC_CALL(); |
|
115 callJava(aInt1, aInt2, aInt3, aInt4); |
|
116 } |
|
117 |
|
118 void SlotCallback::widgetSignal(int aInt1, int aInt2, int aInt3, int aInt4, |
|
119 int aInt5) |
|
120 { |
|
121 SWT_LOG_FUNC_CALL(); |
|
122 callJava(aInt1, aInt2, aInt3, aInt4, aInt5); |
|
123 } |
|
124 |
|
125 void SlotCallback::widgetSignal(bool aBoolean) |
|
126 { |
|
127 SWT_LOG_FUNC_CALL(); |
|
128 callJava(aBoolean ? 1 : 0); |
|
129 } |
|
130 |
|
131 void SlotCallback::widgetSignal(const QPoint& aPoint) |
|
132 { |
|
133 SWT_LOG_FUNC_CALL(); |
|
134 callJava(aPoint.x(), aPoint.y()); |
|
135 } |
|
136 |
|
137 void SlotCallback::widgetSignal(const QString& aString) |
|
138 { |
|
139 SWT_LOG_FUNC_CALL(); |
|
140 callJava(0, 0, 0, 0, 0, swtApp->jniUtils().QStringToJavaString(mJniEnv, aString)); |
|
141 } |
|
142 |
|
143 void SlotCallback::widgetSignal(const QUrl& aUrl) |
|
144 { |
|
145 widgetSignal(aUrl.toString()); |
|
146 } |
|
147 |
|
148 void SlotCallback::widgetSignal(const QDateTime& /*aDateTime*/) |
|
149 { |
|
150 // QDateTime parameter is not needed, just ignore it |
|
151 widgetSignal(); |
|
152 } |
|
153 |
|
154 void SlotCallback::widgetSignal(const QItemSelection& aSelected, |
|
155 const QItemSelection& aDeSelected) |
|
156 { |
|
157 SWT_LOG_FUNC_CALL(); |
|
158 const jint selectionHandle = reinterpret_cast<jint> (&aSelected); |
|
159 const jint deSelectionHandle = reinterpret_cast<jint> (&aDeSelected); |
|
160 callJava(selectionHandle, deSelectionHandle); |
|
161 } |
|
162 |
|
163 void SlotCallback::widgetSignal(QListWidgetItem* aSelected) |
|
164 { |
|
165 SWT_LOG_FUNC_CALL(); |
|
166 jint selectionHandle = reinterpret_cast<jint> (aSelected); |
|
167 callJava(selectionHandle); |
|
168 } |
|
169 |
|
170 void SlotCallback::widgetSignal(QTreeWidgetItem* aSelected, int aColumn) |
|
171 { |
|
172 SWT_LOG_FUNC_CALL(); |
|
173 jint selectionHandle = reinterpret_cast<jint> (aSelected); |
|
174 callJava(selectionHandle, aColumn); |
|
175 } |
|
176 |
|
177 void SlotCallback::widgetSignal(QTreeWidgetItem* aSelected) |
|
178 { |
|
179 SWT_LOG_FUNC_CALL(); |
|
180 jint selectionHandle = reinterpret_cast<jint> (aSelected); |
|
181 callJava(selectionHandle); |
|
182 } |
|
183 |
|
184 void SlotCallback::widgetSignal( const QModelIndex& index ) |
|
185 { |
|
186 SWT_LOG_FUNC_CALL(); |
|
187 callJava(index.row(), index.column()); |
|
188 } |
|
189 |
|
190 void SlotCallback::widgetSignal( QWidget* aWidget1, QWidget* aWidget2 ) |
|
191 { |
|
192 SWT_LOG_FUNC_CALL(); |
|
193 callJava(reinterpret_cast<jint>(aWidget1), reinterpret_cast<jint>(aWidget2)); |
|
194 } |
|
195 |
|
196 void SlotCallback::widgetSignal(const QVariant& value) |
|
197 { |
|
198 SWT_LOG_FUNC_CALL(); |
|
199 callJava(reinterpret_cast<jint>(&value)); |
|
200 } |
|
201 |
|
202 #ifdef __SYMBIAN32__ |
|
203 Q_IMPLEMENT_USER_METATYPE(CntServicesContact) |
|
204 Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(CntServicesContactList) |
|
205 #endif |
|
206 |