aboutsummaryrefslogtreecommitdiffstats
path: root/PySide/QtCore/glue
diff options
context:
space:
mode:
authorrenato <renato.filho@openbossa.org>2009-12-30 11:45:09 -0300
committerHugo Lima <hugo.lima@openbossa.org>2010-01-04 18:59:39 -0200
commit359c973b425db0c27675add1a330734bbd7d8dbd (patch)
treef94fb1b9d80cc2596dc911be006ba0c2584769c9 /PySide/QtCore/glue
parent0d6a8f3978188f3e343c364806e0bb6e6ac1e643 (diff)
Implement disconnect function for Python callback.
Reviewed by Hugo Parente <hugo.lima@openbossa.org>
Diffstat (limited to 'PySide/QtCore/glue')
-rw-r--r--PySide/QtCore/glue/qobject_connect.cpp44
1 files changed, 43 insertions, 1 deletions
diff --git a/PySide/QtCore/glue/qobject_connect.cpp b/PySide/QtCore/glue/qobject_connect.cpp
index 846ab5012..96177322f 100644
--- a/PySide/QtCore/glue/qobject_connect.cpp
+++ b/PySide/QtCore/glue/qobject_connect.cpp
@@ -80,5 +80,47 @@ static bool qobjectConnectCallback(QObject* source, const char* signal, PyObject
}
slotIndex = metaObject->indexOfSlot(slot);
}
- return QMetaObject::connect(source, signalIndex, receiver, slotIndex, type);
+ if (QMetaObject::connect(source, signalIndex, receiver, slotIndex, type)) {
+ if (usingGlobalReceiver)
+ signalManager.globalReceiverConnectNotify(slotIndex);
+
+ return true;
+ }
+ return false;
+}
+
+
+static bool qobjectDisconnectCallback(QObject* source, const char* signal, PyObject* callback)
+{
+ if (!PySide::checkSignal(signal))
+ return false;
+
+ PySide::SignalManager& signalManager = PySide::SignalManager::instance();
+
+ // Extract receiver from callback
+ bool usingGlobalReceiver;
+ QObject* receiver = 0;
+ PyObject* self;
+ if (PyMethod_Check(callback)) {
+ self = PyMethod_GET_SELF(callback);
+ if (SbkQObject_Check(self))
+ receiver = SbkQObject_cptr(self);
+ }
+ usingGlobalReceiver = !receiver;
+ if (usingGlobalReceiver)
+ receiver = signalManager.globalReceiver();
+
+ const QMetaObject* metaObject = receiver->metaObject();
+ const QByteArray callbackSig = PySide::getCallbackSignature(signal, callback, usingGlobalReceiver).toAscii();
+ QByteArray qtSlotName(callbackSig);
+ qtSlotName = qtSlotName.prepend('1');
+
+ if (QObject::disconnect(source, signal, receiver, qtSlotName.constData())) {
+ if (usingGlobalReceiver) {
+ int slotIndex = metaObject->indexOfSlot(callbackSig.constData());
+ signalManager.globalReceiverDisconnectNotify(slotIndex);
+ }
+ return true;
+ }
+ return false;
}