Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Weixuan Xiao
kdeconnect-kde
Commits
1d8ea764
Commit
1d8ea764
authored
Jan 28, 2014
by
Samoilenko Yuri
Browse files
dealing with DBus from QML
parent
a9ed55b6
Changes
6
Hide whitespace changes
Inline
Side-by-side
kded/daemon.cpp
View file @
1d8ea764
...
...
@@ -94,7 +94,7 @@ Daemon::Daemon(QObject *parent) : QObject(parent)
//Load backends (hardcoded by now, should be plugins in a future)
mLinkProviders
.
insert
(
new
LanLinkProvider
());
//
mLinkProviders.insert(new LoopbackLinkProvider());
//
mLinkProviders.insert(new LoopbackLinkProvider());
//Read remebered paired devices
const
KConfigGroup
&
known
=
config
->
group
(
"trusted_devices"
);
...
...
kded/plugins/sftp/sftpplugin.cpp
View file @
1d8ea764
...
...
@@ -113,16 +113,21 @@ void SftpPlugin::mount()
connect
(
m_d
->
mounter
,
SIGNAL
(
failed
(
QString
)),
this
,
SLOT
(
onFailed
(
QString
)));
}
void
SftpPlugin
::
umount
()
{
kDebug
(
kdeconnect_kded
())
<<
"Device:"
<<
device
()
->
name
();
delete
m_d
->
mounter
.
data
();
}
bool
SftpPlugin
::
mountAndWait
()
{
mount
();
return
m_d
->
mounter
->
wait
();
}
void
SftpPlugin
::
um
ount
()
bool
SftpPlugin
::
isM
ount
ed
()
{
kDebug
(
kdeconnect_kded
())
<<
"Device:"
<<
device
()
->
name
();
delete
m_d
->
mounter
.
data
();
return
m_d
->
mounter
;
}
void
SftpPlugin
::
startBrowsing
()
...
...
kded/plugins/sftp/sftpplugin.h
View file @
1d8ea764
...
...
@@ -54,9 +54,9 @@ public Q_SLOTS:
Q_SCRIPTABLE
void
mount
();
Q_SCRIPTABLE
void
umount
();
Q_SCRIPTABLE
bool
mountAndWait
();
Q_SCRIPTABLE
bool
isMounted
();
Q_SCRIPTABLE
void
startBrowsing
();
Q_SCRIPTABLE
QString
mountPoint
();
private
Q_SLOTS
:
...
...
plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp
View file @
1d8ea764
...
...
@@ -21,15 +21,36 @@
#include "kdeconnectdeclarativeplugin.h"
#include <QtDeclarative/QDeclarativeItem>
#include <QtDeclarative/QDeclarativeEngine>
#include <QtDeclarative/QDeclarativeContext>
#include "libkdeconnect/devicesmodel.h"
#include "libkdeconnect/notificationsmodel.h"
#include "batteryinterface.h"
Q_EXPORT_PLUGIN2
(
kdeconnectdeclarativeplugin
,
KdeConnectDeclarativePlugin
);
QObject
*
createSftpInterface
(
QVariant
deviceId
)
{
return
new
SyncSftpDbusInterface
(
deviceId
.
toString
());
}
void
KdeConnectDeclarativePlugin
::
registerTypes
(
const
char
*
uri
)
{
Q_UNUSED
(
uri
);
qmlRegisterType
<
DevicesModel
>
(
"org.kde.kdeconnect"
,
1
,
0
,
"DevicesModel"
);
qmlRegisterType
<
NotificationsModel
>
(
"org.kde.kdeconnect"
,
1
,
0
,
"NotificationsModel"
);
qmlRegisterType
<
BatteryInterface
>
(
"org.kde.kdeconnect"
,
1
,
0
,
"BatteryInterface"
);
//qmlRegisterUncreatableType<TestT>("org.kde.kdeconnect", 1, 0, "SftpDbusInterface", "no create");
}
void
KdeConnectDeclarativePlugin
::
initializeEngine
(
QDeclarativeEngine
*
engine
,
const
char
*
uri
)
{
QDeclarativeExtensionPlugin
::
initializeEngine
(
engine
,
uri
);
engine
->
rootContext
()
->
setContextProperty
(
"SftpDbusInterfaceFactory"
,
new
ObjectFactory
(
engine
,
createSftpInterface
));
}
plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.h
View file @
1d8ea764
...
...
@@ -21,13 +21,68 @@
#ifndef ANALITZADECLARATIVEPLUGIN_H
#define ANALITZADECLARATIVEPLUGIN_H
#include <QVariant>
#include <QDeclarativeExtensionPlugin>
//FIXME HACK Force some slot to be synchronous
#include <libkdeconnect/dbusinterfaces.h>
class
SyncSftpDbusInterface
:
public
SftpDbusInterface
{
Q_OBJECT
public:
SyncSftpDbusInterface
(
const
QString
&
id
)
:
SftpDbusInterface
(
id
)
{}
~
SyncSftpDbusInterface
(){}
Q_INVOKABLE
bool
isMounted
()
{
return
SftpDbusInterface
::
isMounted
();
}
};
class
ObjectFactory
:
public
QObject
{
Q_OBJECT
typedef
QObject
*
(
*
Func0
)();
typedef
QObject
*
(
*
Func1
)(
QVariant
);
typedef
QObject
*
(
*
Func2
)(
QVariant
,
QVariant
);
public:
ObjectFactory
(
QObject
*
parent
,
Func0
f0
)
:
QObject
(
parent
),
m_f0
(
f0
),
m_f1
(
0
),
m_f2
(
0
)
{}
ObjectFactory
(
QObject
*
parent
,
Func1
f1
)
:
QObject
(
parent
),
m_f0
(
0
),
m_f1
(
f1
),
m_f2
(
0
)
{}
ObjectFactory
(
QObject
*
parent
,
Func2
f2
)
:
QObject
(
parent
),
m_f0
(
0
),
m_f1
(
0
),
m_f2
(
f2
)
{}
virtual
~
ObjectFactory
()
{};
Q_INVOKABLE
QObject
*
create
()
{
if
(
m_f0
)
return
m_f0
();
return
0
;
}
Q_INVOKABLE
QObject
*
create
(
QVariant
arg1
)
{
if
(
m_f1
)
return
m_f1
(
arg1
);
return
0
;
}
Q_INVOKABLE
QObject
*
create
(
QVariant
arg1
,
QVariant
arg2
)
{
if
(
m_f2
)
return
m_f2
(
arg1
,
arg2
);
return
0
;
}
private:
Func0
m_f0
;
Func1
m_f1
;
Func2
m_f2
;
};
class
KdeConnectDeclarativePlugin
:
public
QDeclarativeExtensionPlugin
{
virtual
void
registerTypes
(
const
char
*
uri
);
virtual
void
initializeEngine
(
QDeclarativeEngine
*
engine
,
const
char
*
uri
);
};
Q_EXPORT_PLUGIN2
(
kdeconnectdeclarativeplugin
,
KdeConnectDeclarativePlugin
);
#endif // ANALITZADECLARATIVEPLUGIN_H
plasmoid/package/contents/ui/DeviceDelegate.qml
View file @
1d8ea764
...
...
@@ -27,6 +27,16 @@ PlasmaComponents.ListItem
{
id
:
root
property
string
deviceId
:
model
.
deviceId
property
variant
sftp
:
null
Component.onCompleted
:
{
sftp
=
SftpDbusInterfaceFactory
.
create
(
deviceId
)
console
.
debug
(
"
hello
"
)
//console.debug(sftp.isMounted())
if
(
sftp
.
isMounted
())
{
browse
.
state
=
"
MOUNTED
"
}
}
Column
{
width
:
parent
.
width
...
...
@@ -42,9 +52,30 @@ PlasmaComponents.ListItem
PlasmaComponents.Button
{
id
:
browse
text
:
"
Browse
"
state
:
"
UNMOUNTED
"
onClicked
:
{
text
=
"
Hello
"
if
(
state
==
"
UNMOUNTED
"
)
{
sftp
.
startBrowsing
()
state
=
"
MOUNTED
"
console
.
debug
(
sftp
.
mountPoint
())
}
else
{
sftp
.
umount
()
state
=
"
UNMOUNTED
"
}
}
states
:
[
State
{
name
:
"
UNMOUNTED
"
PropertyChanges
{
target
:
browse
;
text
:
"
Browse
"
}
},
State
{
name
:
"
MOUNTED
"
PropertyChanges
{
target
:
browse
;
text
:
"
Unmount
"
}
}
]
}
height
:
browse
.
height
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment