Reputation: 71
I am preparing pure qml plasmoid for my new panel appereance in KDE Plasma 4 and I have to use at most Qt 4.7 library and Qt.Quick 1.1 for that. Is it possible to pick up current user's fullname? Is there any plasma API related to that like PlasmaCore or KSM etc. or any PlasmaCore datasource engine like the following:
#import org.kde.PlasmaCore 0.1 PlasmaCore
{
Item{
PlasmaCore.DataSource{
engine : "SystemInformation"
connection : "get_user_fullname"
}
}
}
Or should I build a service like this? What are your suggestions, and thoughts?
Upvotes: 0
Views: 1056
Reputation: 71
I figured out ! I did create custom Data Engine that provides user's info over qdbus bridge you can learn basics of it from here : https://techbase.kde.org/Development/Tutorials/Plasma4/DataEngines @douyw basically misunderstood the question and i do not know who minused the question. Anyway , its an important issue for new generation of qml developing , making Data Engines is simply making API.
Upvotes: 1
Reputation: 4074
Anything can be exported into qml context via a cpp wrapper. The following sample code snippets are copied from official doc(Qt4.8).
1) Write a wrapper class:
In this example, it exports current datetime. You can export your stuff in a similar way.
class ApplicationData : public QObject
{
Q_OBJECT
public:
Q_INVOKABLE QDateTime getCurrentDateTime() const {
return QDateTime::currentDateTime();
}
};
2) Export the wrapper class via qml context:
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QDeclarativeView view;
ApplicationData data;
view.rootContext()->setContextProperty("applicationData", &data);
view.setSource(QUrl::fromLocalFile("MyItem.qml"));
view.show();
return app.exec();
}
3) Use it in qml file(MyItem.qml):
import QtQuick 1.0
Text { text: applicationData.getCurrentDateTime() }
That's it!
Upvotes: 0