work in progress
This commit is contained in:
parent
838bc4c757
commit
d9e2c4d3bf
@ -13,18 +13,24 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_INSTALL_PREFIX
|
||||
"/home/SMB.BASEALT.RU/kozyrevid/work/new_alterator/install")
|
||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick QuickWidgets DBus #[[QmlTypes]])
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick QuickWidgets DBus Xml)
|
||||
|
||||
option(ALTERATOR_LIBDIR "Destination directory for alteratorlib"
|
||||
"/lib64")
|
||||
|
||||
set(SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/alterator_loader.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/dbus_connector.cpp)
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/dbus_connector.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/dbus_interface.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/dbus_action.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/dbus_property_map.cpp)
|
||||
|
||||
set(HEADERS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/alterator_loader.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/dbus_connector.h)
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/dbus_connector.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/dbus_interface.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/dbus_action.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/dbus_property_map.h)
|
||||
|
||||
set(ALTERATORLIB_VERSION 0.0.1)
|
||||
set(ALTERATORLIB_SOVERSION 1)
|
||||
@ -47,7 +53,8 @@ find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick QuickWidgets D
|
||||
Qt${QT_VERSION_MAJOR}::Core
|
||||
Qt${QT_VERSION_MAJOR}::Quick
|
||||
Qt${QT_VERSION_MAJOR}::QuickWidgets
|
||||
Qt${QT_VERSION_MAJOR}::DBus)
|
||||
Qt${QT_VERSION_MAJOR}::DBus
|
||||
Qt${QT_VERSION_MAJOR}::Xml)
|
||||
|
||||
set_target_properties(alteratorlib PROPERTIES
|
||||
VERSION ${ALTERATORLIB_VERSION}
|
||||
|
@ -2,4 +2,6 @@
|
||||
#define ALTERATOLIB_H
|
||||
#include "alterator/include/alterator_loader.h"
|
||||
#include "alterator/include/dbus_connector.h"
|
||||
#include "alterator/include/dbus_interface.h"
|
||||
#include "alterator/include/dbus_action.h"
|
||||
#endif
|
||||
|
@ -8,7 +8,10 @@
|
||||
#include <QVector>
|
||||
#include <QProcess>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include "dbus_connector.h"
|
||||
#include "dbus_interface.h"
|
||||
#include "alterator_loader_config.h"
|
||||
#include "dbus_action.h"
|
||||
|
||||
namespace Alterator{
|
||||
class Loader: public QObject
|
||||
@ -19,7 +22,8 @@ public:
|
||||
|
||||
signals:
|
||||
void move(QString windowId, QString targetUrl);
|
||||
void windowHistory(QString windiwId, QHash<QString, QVector<QString>> data);
|
||||
void ifaceReq( QString senderId, QString service, QString path
|
||||
, QString interface, QDBusConnection connection );
|
||||
|
||||
public slots:
|
||||
void openReq(QString targetUrl);
|
||||
@ -27,17 +31,21 @@ public slots:
|
||||
void closed(QString senderId);
|
||||
void back(QString senderId);
|
||||
void forvard(QString senderId);
|
||||
void getIface(QList<DBusInterface> ifaces);
|
||||
|
||||
private:
|
||||
const QString windowUrl = windowURLM;
|
||||
|
||||
void open(QString targetUrl);
|
||||
void justMove(QString senderId, QString targetUrl);
|
||||
void collectIfaces(QString targetId);
|
||||
void pushInIface(QString targetId, DBusInterface *iface);
|
||||
|
||||
QHash<QString, QVector<QString>> past;
|
||||
QHash<QString, QVector<QString>> future;
|
||||
QHash<QString, QObject*> widgets;
|
||||
QQmlApplicationEngine *engine;
|
||||
DBusConnector *dbus;
|
||||
};
|
||||
}
|
||||
|
||||
|
24
alterator/include/dbus_action.h
Normal file
24
alterator/include/dbus_action.h
Normal file
@ -0,0 +1,24 @@
|
||||
#include <QObject>
|
||||
#include <QDBusInterface>
|
||||
|
||||
namespace Alterator {
|
||||
class DBusAction : public QObject{
|
||||
public:
|
||||
DBusAction(QDBusInterface *iface, QObject *parent = nullptr);
|
||||
virtual void execute(QList<QString> args) = 0;
|
||||
protected:
|
||||
QDBusInterface *interface;
|
||||
};
|
||||
|
||||
class DBusSetProperty : public DBusAction{
|
||||
public:
|
||||
DBusSetProperty(QDBusInterface *iface, QObject *parent = nullptr);
|
||||
void execute(QList<QVariant> args);
|
||||
};
|
||||
|
||||
class DBusCall : public DBusAction{
|
||||
public:
|
||||
DBusCall(QDBusInterface *iface, QObject *parent = nullptr);
|
||||
void execute(QList<QVariant> args);
|
||||
};
|
||||
}
|
@ -4,24 +4,28 @@
|
||||
#include <QtDBus/QtDBus>
|
||||
#include <QProcess>
|
||||
#include <QHash>
|
||||
#include "dbus_interface.h"
|
||||
#include <QQmlPropertyMap>
|
||||
|
||||
namespace Alterator{
|
||||
class DBusConnector: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DBusConnector(QObject *parent = nullptr);
|
||||
|
||||
Q_INVOKABLE void addInterface( QString service, QString path
|
||||
, QString interface, bool systemBus, QString shortName);
|
||||
Q_INVOKABLE QVariant getProperty(QString InterfaceName, QString propertyName);
|
||||
Q_INVOKABLE bool setProperty(QString interfaceName, QString propertyName, QVariant value);
|
||||
Q_INVOKABLE QDBusInterface &getInterface(QString shortName);
|
||||
Q_INVOKABLE QDBusMessage call(const QString &interfaceName, QDBus::CallMode mode, const QString &method, const QList<QVariant> &args);
|
||||
signals:
|
||||
void pushInLogs(QString targetId, QList<QString> logs);
|
||||
void giveInterface(QString targetId, DBusInterface *iface);
|
||||
|
||||
public slots:
|
||||
void ifaceReq(QString senderId, QString service, QString path
|
||||
, QString interface, QDBusConnection connection);
|
||||
private:
|
||||
QHash<QString, QDBusInterface *> interfaces;
|
||||
// QDBusConnection systemBus;
|
||||
// QDBusConnection sessionBus;
|
||||
// QHash<QString, QDBusInterface *> realIfaces;
|
||||
// QHash<QString, QQmlPropertyMap *> introspections;
|
||||
|
||||
QQmlPropertyMap *introspect(QString service, QString path
|
||||
, QString interface, QDBusConnection connection);
|
||||
};
|
||||
}
|
||||
|
||||
|
21
alterator/include/dbus_interface.h
Normal file
21
alterator/include/dbus_interface.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef DBUS_INTERFACE_H
|
||||
#define DBUS_INTERFACE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDBusInterface>
|
||||
#include <QQmlPropertyMap>
|
||||
|
||||
namespace Alterator{
|
||||
class DBusInterface : public QObject{
|
||||
Q_OBJECT
|
||||
Q_ENUM(QDBus::CallMode)
|
||||
public:
|
||||
DBusInterface( QQmlPropertyMap *introspection, QDBusInterface *ri
|
||||
, QObject *parent = 0 );
|
||||
private:
|
||||
QDBusInterface *realIface;
|
||||
QQmlPropertyMap *properties;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // DBUS_INTERFACE_H
|
4
alterator/include/dbus_property_map.h
Normal file
4
alterator/include/dbus_property_map.h
Normal file
@ -0,0 +1,4 @@
|
||||
#ifndef DBUS_PROPERTY_MAP_H
|
||||
#define DBUS_PROPERTY_MAP_H
|
||||
|
||||
#endif // DBUS_PROPERTY_MAP_H
|
@ -11,6 +11,7 @@
|
||||
namespace Alterator {
|
||||
Loader::Loader(QObject *p):QObject(p)
|
||||
{
|
||||
dbus = new DBusConnector(this);
|
||||
engine = new QQmlApplicationEngine(this);
|
||||
engine->addImportPath("../../new_alterator/");
|
||||
qmlRegisterType<Alterator::DistInfo>("Alterator.DistInfo", 1, 0, "DistInfo");
|
||||
|
20
alterator/src/dbus_action.cpp
Normal file
20
alterator/src/dbus_action.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include "dbus_action.h"
|
||||
|
||||
namespace Alterator {
|
||||
DBusAction::DBusAction(QDBusInterface *iface, QObject *parent) : QObject(parent){
|
||||
interface = iface;
|
||||
}
|
||||
DBusSetProperty::DBusSetProperty(QDBusInterface *iface, QObject *parent) : DBusAction(iface, parent){}
|
||||
DBusCall::DBusCall(QDBusInterface *iface, QObject *parent) : DBusAction(iface, parent){}
|
||||
|
||||
void DBusSetProperty::execute(QList<QVariant> args){
|
||||
auto t = args[0].toString().toStdString();
|
||||
const char *name = t.c_str();
|
||||
interface->setProperty(name, args[1].toString());
|
||||
}
|
||||
void DBusCall::execute(QList<QVariant> args){
|
||||
QString name = args[0].toString();
|
||||
args.removeFirst();
|
||||
interface->callWithArgumentList(QDBus::Block, name, args);
|
||||
}
|
||||
}
|
@ -1,88 +1,34 @@
|
||||
#include "../include/dbus_connector.h"
|
||||
#include "dbus_connector.h"
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusConnection>
|
||||
#include <QXmlStreamReader>
|
||||
|
||||
namespace Alterator{
|
||||
DBusConnector::DBusConnector(QObject *parent): QObject(parent)
|
||||
{
|
||||
// systemBus = ;
|
||||
// sessionBus = QDBusConnection::sessionBus;
|
||||
interfaces = QHash<QString, QDBusInterface *>();
|
||||
addInterface("org.freedesktop.hostname1", "/org/freedesktop/hostname1",
|
||||
"org.freedesktop.hostname1", false, "hostname");
|
||||
// realIfaces = QHash<QString, QDBusInterface *>();
|
||||
// introspections = QHash<QString, QQmlPropertyMap *>();
|
||||
}
|
||||
|
||||
void DBusConnector::addInterface(QString service, QString path, QString interface
|
||||
, bool isSessionBus, QString shortName){
|
||||
QDBusInterface *iface =
|
||||
new QDBusInterface(service, path, interface, isSessionBus
|
||||
? QDBusConnection::sessionBus()
|
||||
: QDBusConnection::systemBus(), this);
|
||||
interfaces.insert(shortName, iface);
|
||||
QQmlPropertyMap *DBusConnector::introspect(QString service, QString path //FIXME
|
||||
, QString interface
|
||||
, QDBusConnection connection)
|
||||
{
|
||||
QDBusInterface introspectable =
|
||||
QDBusInterface(service, path
|
||||
, "org.freedesktop.DBus.Introspectable", connection);
|
||||
QQmlPropertyMap *introspection = new QQmlPropertyMap(this);
|
||||
QXmlStreamReader reader = QXmlStreamReader(
|
||||
introspectable.call("Introspect").arguments()[0].toString());
|
||||
return introspection;
|
||||
}
|
||||
|
||||
QVariant DBusConnector::getProperty(QString interfaceName, QString propertyName){
|
||||
try{
|
||||
if (interfaces.contains(interfaceName)){
|
||||
return interfaces[interfaceName]->property(propertyName.toLocal8Bit().constData());
|
||||
}
|
||||
else {
|
||||
throw "There is no such interface in the connector";
|
||||
}
|
||||
}
|
||||
catch(QString msg){
|
||||
qDebug() << msg;
|
||||
return QVariant::fromValue(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
bool DBusConnector::setProperty(QString interfaceName, QString propertyName
|
||||
, QVariant value){
|
||||
try{
|
||||
if (interfaces.contains(interfaceName)){
|
||||
return interfaces[interfaceName]->setProperty(propertyName.toLocal8Bit().constData(), value);
|
||||
}
|
||||
else {
|
||||
throw "There is no such interface in the connector";
|
||||
}
|
||||
}
|
||||
catch(QString msg){
|
||||
qDebug() << msg;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QDBusInterface &DBusConnector::getInterface(QString shortName){
|
||||
try{
|
||||
if (interfaces.contains(shortName)){
|
||||
return *interfaces[shortName];
|
||||
}
|
||||
else {
|
||||
throw "There is no such interface in the connector";
|
||||
return *interfaces.begin().value();
|
||||
}
|
||||
}
|
||||
catch(QString msg){
|
||||
qDebug() << msg;
|
||||
return *interfaces.begin().value();
|
||||
}
|
||||
}
|
||||
|
||||
QDBusMessage DBusConnector::call( const QString &interfaceName
|
||||
, QDBus::CallMode mode
|
||||
, const QString &method
|
||||
, const QList<QVariant> &args){
|
||||
try{
|
||||
if (interfaces.contains(interfaceName)){
|
||||
return interfaces[interfaceName]->callWithArgumentList(mode, method, args);
|
||||
}
|
||||
else {
|
||||
throw "There is no such interface in the connector";
|
||||
}
|
||||
}
|
||||
catch(QString msg){
|
||||
qDebug() << msg;
|
||||
return QDBusMessage();
|
||||
}
|
||||
void DBusConnector::ifaceReq(QString senderId, QString service, QString path
|
||||
, QString interface, QDBusConnection connection){
|
||||
QDBusInterface *realIface = new QDBusInterface( service, path, interface
|
||||
, connection, this);
|
||||
DBusInterface *iface = new DBusInterface(
|
||||
introspect(service, path, interface, connection), realIface, this);
|
||||
emit(giveInterface(senderId, iface));
|
||||
}
|
||||
}
|
||||
|
9
alterator/src/dbus_interface.cpp
Normal file
9
alterator/src/dbus_interface.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include "dbus_interface.h"
|
||||
|
||||
namespace Alterator {
|
||||
DBusInterface::DBusInterface( QQmlPropertyMap *introspection, QDBusInterface *ri
|
||||
, QObject *parent): QObject(parent){
|
||||
realIface = ri;
|
||||
properties = introspection;
|
||||
}
|
||||
}
|
0
alterator/src/dbus_property_map.cpp
Normal file
0
alterator/src/dbus_property_map.cpp
Normal file
@ -10,6 +10,13 @@ import shared 1.0
|
||||
ScrollView {
|
||||
id: view
|
||||
|
||||
property var RequiredInterfaces:
|
||||
[ {shortname : "hostname"
|
||||
, service : "org.freedesktop.hostname1"
|
||||
, path : "/org/freedesktop/hostname1"
|
||||
, interface : "org.freedesktop.hostname1"
|
||||
, isSessionBus : false}]
|
||||
|
||||
anchors.fill: parent
|
||||
ColumnLayout{
|
||||
id: content
|
||||
|
@ -29,11 +29,11 @@ Window{
|
||||
|
||||
anchors.fill: parent
|
||||
|
||||
// AlteratorToolBar{
|
||||
// id: toolBar
|
||||
AlteratorToolBar{
|
||||
id: toolBar
|
||||
|
||||
// z: 1
|
||||
// }
|
||||
z: 1
|
||||
}
|
||||
|
||||
RowLayout{
|
||||
id: layout2
|
||||
|
Loading…
x
Reference in New Issue
Block a user