play continues...

This commit is contained in:
Samoilenko Yuri 2014-01-30 20:25:22 +04:00
parent c18ee6f1d8
commit a54dd853ff
3 changed files with 54 additions and 102 deletions

View file

@ -15,9 +15,6 @@ Q_DECLARE_METATYPE(QDBusPendingReply<bool>)
Q_DECLARE_METATYPE(QDBusPendingReply<int>)
Q_DECLARE_METATYPE(QDBusPendingReply<QString>)
//Q_DECLARE_METATYPE(DBusResponseWaiter::onComplete)
//Q_DECLARE_METATYPE(DBusResponseWaiter::onError)
DBusResponseWaiter::DBusResponseWaiter()
: QObject()
{
@ -28,9 +25,6 @@ DBusResponseWaiter::DBusResponseWaiter()
<< qRegisterMetaType<QDBusPendingReply<int> >("QDBusPendingReply<int>")
<< qRegisterMetaType<QDBusPendingReply<QString> >("QDBusPendingReply<QString>")
;
//qRegisterMetaType<DBusResponseWaiter::onComplete>("DBusResponseWaiter::onComplete");
//qRegisterMetaType<DBusResponseWaiter::onError>("DBusResponseWaiter::onError");
}
QVariant DBusResponseWaiter::waitForReply(QVariant variant) const
@ -50,17 +44,13 @@ QVariant DBusResponseWaiter::waitForReply(QVariant variant) const
void DBusResponse::setPendingCall(QVariant variant)
{
qDebug() << "spc1";
m_pendingCall = variant;
qDebug() << "spc2";
if (QDBusPendingCall* call = const_cast<QDBusPendingCall*>(DBusResponseWaiter().extractPendingCall(m_pendingCall)))
if (QDBusPendingCall* call = const_cast<QDBusPendingCall*>(DBusResponseWaiter().extractPendingCall(variant)))
{
qDebug() << "spc3";
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(*call);
watcher->setProperty("pengingCall", variant);
connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(onCallFinished(QDBusPendingCallWatcher*)));
connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), watcher, SLOT(deleteLater()));
};
qDebug() << "spc4";
}
@ -68,39 +58,23 @@ void DBusResponse::onCallFinished(QDBusPendingCallWatcher* watcher)
{
QVariant variant = watcher->property("pengingCall");
qDebug() << "ocf 1";
if (QDBusPendingCall* call = const_cast<QDBusPendingCall*>(DBusResponseWaiter().extractPendingCall(m_pendingCall)))
if (QDBusPendingCall* call = const_cast<QDBusPendingCall*>(DBusResponseWaiter().extractPendingCall(variant)))
{
qDebug() << "ocf 2";
if (call->isError())
{
Q_EMIT error(call->error().message());
}
else
{
qDebug() << "ocf 4444:" << this;
// onComplete success = watcher->property("onComplete").value<onComplete>();
// e_->rootContext()->setContextProperty("test_func", m_onSuccess);
QDeclarativeExpression *expr = new QDeclarativeExpression(e_->rootContext(), this, "wow");
qDebug() << "ocf 555";
expr->evaluate(); // result = 400
// qDebug() << "ocf 666" << expr->error();
//
QDBusMessage reply = call->reply();
if (reply.arguments().count() > 0)
{
// success(reply.arguments().first());
Q_EMIT success(reply.arguments().first());
}
else
{
// success(QVariant());
Q_EMIT success(QVariant());
}
}
}

View file

@ -15,38 +15,20 @@ class DBusResponse : public QObject
{
Q_OBJECT
Q_PROPERTY(QVariant pendingCall READ pendingCall WRITE setPendingCall NOTIFY pendingCallChanged)
Q_PROPERTY(QVariant onError READ onError WRITE setOnError NOTIFY onErrorChanged)
Q_PROPERTY(QVariant onSuccess READ onSuccess WRITE setOnSuccess NOTIFY onSuccessChanged)
Q_PROPERTY(QVariant pendingCall WRITE setPendingCall)
public:
DBusResponse(QDeclarativeEngine* e = 0) : QObject(e) , e_(e) {qDebug() << "C";};
DBusResponse(QObject* parent = 0) : QObject(parent) {}
virtual ~DBusResponse() {};
void setPendingCall(QVariant e);
QVariant pendingCall() {return m_pendingCall;}
void setOnError(QVariant e) {m_onError = e;}
QVariant onError() {return m_onError;}
void setOnSuccess(QVariant e) {m_onSuccess = e;}
QVariant onSuccess() {return m_onSuccess;}
Q_SIGNALS:
void onSuccessChanged();
void onErrorChanged();
void pendingCallChanged();
void success(QVariant result);
void error(QString message);
private Q_SLOTS:
void onCallFinished(QDBusPendingCallWatcher* watcher);
private:
QVariant m_pendingCall;
QVariant m_onError;
QVariant m_onSuccess;
QDeclarativeEngine* e_;
};
class DBusResponseWaiter : public QObject

View file

@ -27,55 +27,23 @@ PlasmaComponents.ListItem
{
id: root
property string deviceId: model.deviceId
property variant sftp: null
property variant sftp: SftpDbusInterfaceFactory.create(deviceId)
DBusResponse
{
id: resp
function wow() {
console.log("wow")
}
}
Component.onCompleted: {
sftp = SftpDbusInterfaceFactory.create(deviceId)
// resp.wow()
// resp.wow()
// resp.wow()
// resp.func = bb
resp.pendingCall = sftp.isMounted()
var response = DBusResponseFactory.create()
response.pendingCall = sftp.isMounted()
/*
response.onSuccess = bb;
// function (v) {
// console.debug("SUCCESSS");
// console.debug(v);
// }
console.log("o3")
response.onError = function(v) {console.log("eeeeee")}
console.log("o4")
response.pendingCall = sftp.isMounted()
console.log("o5")*/
// rr.pendingCall = 1;
// onCompleted: {
// console.debug("GGGGGGGGGGGGGGGGG")
// }
// }
//
// console.debug(ResponseWaiter.waitForReply(sftp.mountPoint()))
id: resp
onSuccess: {
console.log(1)
if (result)
{
browse.state = "MOUNTED"
}
}
onError: function(message) {
console.debug("error:" + message)
}
pendingCall: sftp.isMounted()
}
Column {
@ -93,10 +61,34 @@ PlasmaComponents.ListItem
id: browse
text: "Browse"
state: "UNMOUNTED"
function mounted() {
console.debug("SUCCESS")
}
onClicked: {
if (state == "UNMOUNTED") {
sftp.startBrowsing()
state = "MOUNTED"
state = "MOUNTING"
resp.success.connect(function(result){
if (result) {
state = "MOUNTED"
}
else {
state = "UNMOUNTED"
}
})
resp.error.connect(function(){
console.debug("ERROR")
})
resp.pendingCall = sftp.startBrowsing()
// if (ResponseWaiter.waitForReply(sftp.startBrowsing()))
// {
// state = "MOUNTED"
// }
// else
// {
// state = "UNMOUNTED"
// }
}
else {
sftp.umount()
@ -109,6 +101,10 @@ PlasmaComponents.ListItem
name: "UNMOUNTED"
PropertyChanges { target: browse; text: "Browse"}
},
State {
name: "MOUNTING"
PropertyChanges { target: browse; text: "Mounting..."}
},
State {
name: "MOUNTED"
PropertyChanges { target: browse; text: "Unmount"}