play continues...
This commit is contained in:
parent
c18ee6f1d8
commit
a54dd853ff
3 changed files with 54 additions and 102 deletions
|
@ -15,9 +15,6 @@ Q_DECLARE_METATYPE(QDBusPendingReply<bool>)
|
||||||
Q_DECLARE_METATYPE(QDBusPendingReply<int>)
|
Q_DECLARE_METATYPE(QDBusPendingReply<int>)
|
||||||
Q_DECLARE_METATYPE(QDBusPendingReply<QString>)
|
Q_DECLARE_METATYPE(QDBusPendingReply<QString>)
|
||||||
|
|
||||||
//Q_DECLARE_METATYPE(DBusResponseWaiter::onComplete)
|
|
||||||
//Q_DECLARE_METATYPE(DBusResponseWaiter::onError)
|
|
||||||
|
|
||||||
DBusResponseWaiter::DBusResponseWaiter()
|
DBusResponseWaiter::DBusResponseWaiter()
|
||||||
: QObject()
|
: QObject()
|
||||||
{
|
{
|
||||||
|
@ -28,9 +25,6 @@ DBusResponseWaiter::DBusResponseWaiter()
|
||||||
<< qRegisterMetaType<QDBusPendingReply<int> >("QDBusPendingReply<int>")
|
<< qRegisterMetaType<QDBusPendingReply<int> >("QDBusPendingReply<int>")
|
||||||
<< qRegisterMetaType<QDBusPendingReply<QString> >("QDBusPendingReply<QString>")
|
<< qRegisterMetaType<QDBusPendingReply<QString> >("QDBusPendingReply<QString>")
|
||||||
;
|
;
|
||||||
|
|
||||||
//qRegisterMetaType<DBusResponseWaiter::onComplete>("DBusResponseWaiter::onComplete");
|
|
||||||
//qRegisterMetaType<DBusResponseWaiter::onError>("DBusResponseWaiter::onError");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant DBusResponseWaiter::waitForReply(QVariant variant) const
|
QVariant DBusResponseWaiter::waitForReply(QVariant variant) const
|
||||||
|
@ -50,17 +44,13 @@ QVariant DBusResponseWaiter::waitForReply(QVariant variant) const
|
||||||
|
|
||||||
void DBusResponse::setPendingCall(QVariant variant)
|
void DBusResponse::setPendingCall(QVariant variant)
|
||||||
{
|
{
|
||||||
qDebug() << "spc1";
|
if (QDBusPendingCall* call = const_cast<QDBusPendingCall*>(DBusResponseWaiter().extractPendingCall(variant)))
|
||||||
m_pendingCall = variant;
|
|
||||||
qDebug() << "spc2";
|
|
||||||
if (QDBusPendingCall* call = const_cast<QDBusPendingCall*>(DBusResponseWaiter().extractPendingCall(m_pendingCall)))
|
|
||||||
{
|
{
|
||||||
qDebug() << "spc3";
|
|
||||||
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(*call);
|
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(*call);
|
||||||
|
watcher->setProperty("pengingCall", variant);
|
||||||
connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(onCallFinished(QDBusPendingCallWatcher*)));
|
connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(onCallFinished(QDBusPendingCallWatcher*)));
|
||||||
connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), watcher, SLOT(deleteLater()));
|
connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), watcher, SLOT(deleteLater()));
|
||||||
};
|
};
|
||||||
qDebug() << "spc4";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,39 +58,23 @@ void DBusResponse::onCallFinished(QDBusPendingCallWatcher* watcher)
|
||||||
{
|
{
|
||||||
QVariant variant = watcher->property("pengingCall");
|
QVariant variant = watcher->property("pengingCall");
|
||||||
|
|
||||||
qDebug() << "ocf 1";
|
if (QDBusPendingCall* call = const_cast<QDBusPendingCall*>(DBusResponseWaiter().extractPendingCall(variant)))
|
||||||
if (QDBusPendingCall* call = const_cast<QDBusPendingCall*>(DBusResponseWaiter().extractPendingCall(m_pendingCall)))
|
|
||||||
{
|
{
|
||||||
qDebug() << "ocf 2";
|
|
||||||
if (call->isError())
|
if (call->isError())
|
||||||
{
|
{
|
||||||
|
Q_EMIT error(call->error().message());
|
||||||
}
|
}
|
||||||
else
|
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();
|
QDBusMessage reply = call->reply();
|
||||||
|
|
||||||
if (reply.arguments().count() > 0)
|
if (reply.arguments().count() > 0)
|
||||||
{
|
{
|
||||||
// success(reply.arguments().first());
|
Q_EMIT success(reply.arguments().first());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// success(QVariant());
|
Q_EMIT success(QVariant());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,38 +15,20 @@ class DBusResponse : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(QVariant pendingCall READ pendingCall WRITE setPendingCall NOTIFY pendingCallChanged)
|
Q_PROPERTY(QVariant pendingCall WRITE setPendingCall)
|
||||||
Q_PROPERTY(QVariant onError READ onError WRITE setOnError NOTIFY onErrorChanged)
|
|
||||||
Q_PROPERTY(QVariant onSuccess READ onSuccess WRITE setOnSuccess NOTIFY onSuccessChanged)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DBusResponse(QDeclarativeEngine* e = 0) : QObject(e) , e_(e) {qDebug() << "C";};
|
DBusResponse(QObject* parent = 0) : QObject(parent) {}
|
||||||
virtual ~DBusResponse() {};
|
virtual ~DBusResponse() {};
|
||||||
|
|
||||||
void setPendingCall(QVariant e);
|
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:
|
Q_SIGNALS:
|
||||||
void onSuccessChanged();
|
void success(QVariant result);
|
||||||
void onErrorChanged();
|
void error(QString message);
|
||||||
void pendingCallChanged();
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void onCallFinished(QDBusPendingCallWatcher* watcher);
|
void onCallFinished(QDBusPendingCallWatcher* watcher);
|
||||||
|
|
||||||
private:
|
|
||||||
QVariant m_pendingCall;
|
|
||||||
QVariant m_onError;
|
|
||||||
QVariant m_onSuccess;
|
|
||||||
|
|
||||||
QDeclarativeEngine* e_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class DBusResponseWaiter : public QObject
|
class DBusResponseWaiter : public QObject
|
||||||
|
|
|
@ -27,57 +27,25 @@ PlasmaComponents.ListItem
|
||||||
{
|
{
|
||||||
id: root
|
id: root
|
||||||
property string deviceId: model.deviceId
|
property string deviceId: model.deviceId
|
||||||
property variant sftp: null
|
property variant sftp: SftpDbusInterfaceFactory.create(deviceId)
|
||||||
|
|
||||||
|
|
||||||
DBusResponse
|
DBusResponse
|
||||||
{
|
{
|
||||||
id: resp
|
id: resp
|
||||||
|
onSuccess: {
|
||||||
function wow() {
|
console.log(1)
|
||||||
console.log("wow")
|
if (result)
|
||||||
}
|
{
|
||||||
}
|
browse.state = "MOUNTED"
|
||||||
|
}
|
||||||
Component.onCompleted: {
|
}
|
||||||
sftp = SftpDbusInterfaceFactory.create(deviceId)
|
onError: function(message) {
|
||||||
|
console.debug("error:" + message)
|
||||||
// resp.wow()
|
}
|
||||||
// resp.wow()
|
pendingCall: sftp.isMounted()
|
||||||
// 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()))
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
|
|
||||||
|
@ -93,10 +61,34 @@ PlasmaComponents.ListItem
|
||||||
id: browse
|
id: browse
|
||||||
text: "Browse"
|
text: "Browse"
|
||||||
state: "UNMOUNTED"
|
state: "UNMOUNTED"
|
||||||
|
|
||||||
|
function mounted() {
|
||||||
|
console.debug("SUCCESS")
|
||||||
|
}
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (state == "UNMOUNTED") {
|
if (state == "UNMOUNTED") {
|
||||||
sftp.startBrowsing()
|
state = "MOUNTING"
|
||||||
state = "MOUNTED"
|
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 {
|
else {
|
||||||
sftp.umount()
|
sftp.umount()
|
||||||
|
@ -109,6 +101,10 @@ PlasmaComponents.ListItem
|
||||||
name: "UNMOUNTED"
|
name: "UNMOUNTED"
|
||||||
PropertyChanges { target: browse; text: "Browse"}
|
PropertyChanges { target: browse; text: "Browse"}
|
||||||
},
|
},
|
||||||
|
State {
|
||||||
|
name: "MOUNTING"
|
||||||
|
PropertyChanges { target: browse; text: "Mounting..."}
|
||||||
|
},
|
||||||
State {
|
State {
|
||||||
name: "MOUNTED"
|
name: "MOUNTED"
|
||||||
PropertyChanges { target: browse; text: "Unmount"}
|
PropertyChanges { target: browse; text: "Unmount"}
|
||||||
|
|
Loading…
Reference in a new issue