button works
This commit is contained in:
parent
881450146f
commit
776543409d
4 changed files with 60 additions and 51 deletions
|
@ -43,7 +43,7 @@ QObject* createSftpInterface(QVariant deviceId)
|
||||||
|
|
||||||
QObject* createDBusResponse()
|
QObject* createDBusResponse()
|
||||||
{
|
{
|
||||||
return new DBusResponse();
|
return new DBusAsyncResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KdeConnectDeclarativePlugin::registerTypes(const char* uri)
|
void KdeConnectDeclarativePlugin::registerTypes(const char* uri)
|
||||||
|
@ -54,7 +54,7 @@ void KdeConnectDeclarativePlugin::registerTypes(const char* uri)
|
||||||
qmlRegisterType<NotificationsModel>("org.kde.kdeconnect", 1, 0, "NotificationsModel");
|
qmlRegisterType<NotificationsModel>("org.kde.kdeconnect", 1, 0, "NotificationsModel");
|
||||||
qmlRegisterType<BatteryInterface>("org.kde.kdeconnect", 1, 0, "BatteryInterface");
|
qmlRegisterType<BatteryInterface>("org.kde.kdeconnect", 1, 0, "BatteryInterface");
|
||||||
|
|
||||||
qmlRegisterType<DBusResponse>("org.kde.kdeconnect", 1, 0, "DBusResponse");
|
qmlRegisterType<DBusAsyncResponse>("org.kde.kdeconnect", 1, 0, "DBusResponse");
|
||||||
}
|
}
|
||||||
|
|
||||||
void KdeConnectDeclarativePlugin::initializeEngine(QDeclarativeEngine* engine, const char* uri)
|
void KdeConnectDeclarativePlugin::initializeEngine(QDeclarativeEngine* engine, const char* uri)
|
||||||
|
@ -68,6 +68,6 @@ void KdeConnectDeclarativePlugin::initializeEngine(QDeclarativeEngine* engine, c
|
||||||
engine->rootContext()->setContextProperty("DBusResponseFactory"
|
engine->rootContext()->setContextProperty("DBusResponseFactory"
|
||||||
, new ObjectFactory(engine, createDBusResponse));
|
, new ObjectFactory(engine, createDBusResponse));
|
||||||
|
|
||||||
engine->rootContext()->setContextProperty("ResponseWaiter"
|
engine->rootContext()->setContextProperty("DBusResponseWaiter"
|
||||||
, new DBusResponseWaiter());
|
, DBusResponseWaiter::instance());
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,17 @@ 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>)
|
||||||
|
|
||||||
|
DBusResponseWaiter* DBusResponseWaiter::m_instance = 0;
|
||||||
|
|
||||||
|
DBusResponseWaiter* DBusResponseWaiter::instance()
|
||||||
|
{
|
||||||
|
if (!m_instance)
|
||||||
|
{
|
||||||
|
m_instance = new DBusResponseWaiter();
|
||||||
|
}
|
||||||
|
return m_instance;
|
||||||
|
}
|
||||||
|
|
||||||
DBusResponseWaiter::DBusResponseWaiter()
|
DBusResponseWaiter::DBusResponseWaiter()
|
||||||
: QObject()
|
: QObject()
|
||||||
{
|
{
|
||||||
|
@ -42,9 +53,9 @@ QVariant DBusResponseWaiter::waitForReply(QVariant variant) const
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBusResponse::setPendingCall(QVariant variant)
|
void DBusAsyncResponse::setPendingCall(QVariant variant)
|
||||||
{
|
{
|
||||||
if (QDBusPendingCall* call = const_cast<QDBusPendingCall*>(DBusResponseWaiter().extractPendingCall(variant)))
|
if (QDBusPendingCall* call = const_cast<QDBusPendingCall*>(DBusResponseWaiter::instance()->extractPendingCall(variant)))
|
||||||
{
|
{
|
||||||
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(*call);
|
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(*call);
|
||||||
watcher->setProperty("pengingCall", variant);
|
watcher->setProperty("pengingCall", variant);
|
||||||
|
@ -54,11 +65,11 @@ void DBusResponse::setPendingCall(QVariant variant)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DBusResponse::onCallFinished(QDBusPendingCallWatcher* watcher)
|
void DBusAsyncResponse::onCallFinished(QDBusPendingCallWatcher* watcher)
|
||||||
{
|
{
|
||||||
QVariant variant = watcher->property("pengingCall");
|
QVariant variant = watcher->property("pengingCall");
|
||||||
|
|
||||||
if (QDBusPendingCall* call = const_cast<QDBusPendingCall*>(DBusResponseWaiter().extractPendingCall(variant)))
|
if (QDBusPendingCall* call = const_cast<QDBusPendingCall*>(DBusResponseWaiter::instance()->extractPendingCall(variant)))
|
||||||
{
|
{
|
||||||
if (call->isError())
|
if (call->isError())
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,15 +11,36 @@
|
||||||
class QDBusPendingCall;
|
class QDBusPendingCall;
|
||||||
class QDBusPendingCallWatcher;
|
class QDBusPendingCallWatcher;
|
||||||
|
|
||||||
class DBusResponse : public QObject
|
class DBusResponseWaiter : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
static DBusResponseWaiter* instance();
|
||||||
|
|
||||||
|
///extract QDbusPendingCall from \p variant and blocks untill completed
|
||||||
|
Q_INVOKABLE QVariant waitForReply(QVariant variant) const;
|
||||||
|
|
||||||
|
const QDBusPendingCall* extractPendingCall(QVariant& variant) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
DBusResponseWaiter();
|
||||||
|
|
||||||
|
static DBusResponseWaiter* m_instance;
|
||||||
|
QList<int> m_registered;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class DBusAsyncResponse : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(QVariant pendingCall WRITE setPendingCall)
|
Q_PROPERTY(QVariant pendingCall WRITE setPendingCall)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DBusResponse(QObject* parent = 0) : QObject(parent) {}
|
DBusAsyncResponse(QObject* parent = 0) : QObject(parent) {}
|
||||||
virtual ~DBusResponse() {};
|
virtual ~DBusAsyncResponse() {};
|
||||||
|
|
||||||
void setPendingCall(QVariant e);
|
void setPendingCall(QVariant e);
|
||||||
|
|
||||||
|
@ -31,22 +52,5 @@ private Q_SLOTS:
|
||||||
void onCallFinished(QDBusPendingCallWatcher* watcher);
|
void onCallFinished(QDBusPendingCallWatcher* watcher);
|
||||||
};
|
};
|
||||||
|
|
||||||
class DBusResponseWaiter : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
DBusResponseWaiter();
|
|
||||||
|
|
||||||
virtual ~DBusResponseWaiter(){};
|
|
||||||
|
|
||||||
///extract QDbusPendingCall from \p variant and blocks untill completed
|
|
||||||
Q_INVOKABLE QVariant waitForReply(QVariant variant) const;
|
|
||||||
|
|
||||||
const QDBusPendingCall* extractPendingCall(QVariant& variant) const;
|
|
||||||
|
|
||||||
QList<int> m_registered;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -31,13 +31,23 @@ PlasmaComponents.ListItem
|
||||||
|
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
|
|
||||||
|
sftp.mounted.connect( function() {
|
||||||
|
browse.state = "MOUNTED"
|
||||||
|
})
|
||||||
|
|
||||||
|
sftp.unmounted.connect( function() {
|
||||||
|
console.log(222)
|
||||||
|
browse.state = "UNMOUNTED"
|
||||||
|
})
|
||||||
|
|
||||||
var response = DBusResponseFactory.create()
|
var response = DBusResponseFactory.create()
|
||||||
response.success.connect( function(result) {
|
response.success.connect( function(result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
state = "MOUNTED"
|
browse.state = "MOUNTED"
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
state = "UNMOUNTED"
|
browse.state = "UNMOUNTED"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -62,47 +72,31 @@ PlasmaComponents.ListItem
|
||||||
|
|
||||||
PlasmaComponents.Button {
|
PlasmaComponents.Button {
|
||||||
id: browse
|
id: browse
|
||||||
text: "Browse"
|
checkable: true
|
||||||
state: "UNMOUNTED"
|
state: "UNMOUNTED"
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (state == "UNMOUNTED") {
|
if (state == "UNMOUNTED") {
|
||||||
state = "MOUNTING"
|
state = "MOUNTING"
|
||||||
var response = DBusResponseFactory.create()
|
sftp.startBrowsing()
|
||||||
response.success.connect( function(result){
|
|
||||||
if (result) {
|
|
||||||
state = "MOUNTED"
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
state = "UNMOUNTED"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
response.error.connect( function(message) {
|
|
||||||
console.error("Error:" + message)
|
|
||||||
state = "UNMOUNTED"
|
|
||||||
})
|
|
||||||
|
|
||||||
response.pendingCall = sftp.startBrowsing()
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sftp.umount()
|
sftp.umount()
|
||||||
state = "UNMOUNTED"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
states: [
|
states: [
|
||||||
State {
|
State {
|
||||||
name: "UNMOUNTED"
|
name: "UNMOUNTED"
|
||||||
PropertyChanges { target: browse; text: "Browse"}
|
PropertyChanges { target: browse; checked: false; text: "Browse"}
|
||||||
},
|
},
|
||||||
State {
|
State {
|
||||||
name: "MOUNTING"
|
name: "MOUNTING"
|
||||||
PropertyChanges { target: browse; text: "Mounting..."}
|
PropertyChanges { target: browse; checked: true; text: "Mounting..."}
|
||||||
},
|
},
|
||||||
State {
|
State {
|
||||||
name: "MOUNTED"
|
name: "MOUNTED"
|
||||||
PropertyChanges { target: browse; text: "Unmount"}
|
PropertyChanges { target: browse; checked: false; text: "Unmount"}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue