added connector
This commit is contained in:
parent
29d5515997
commit
59cc6c0e6f
@ -22,11 +22,13 @@ project(new_alterator
|
||||
set(SOURCES
|
||||
${CMAKE_SOURCE_DIR}/src/alterator_loader.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/dist_info.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/main.cpp)
|
||||
${CMAKE_SOURCE_DIR}/src/main.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/dbus_connector.cpp)
|
||||
|
||||
set(HEADERS
|
||||
${CMAKE_SOURCE_DIR}/include/alterator_loader.h
|
||||
${CMAKE_SOURCE_DIR}/include/dist_info.h)
|
||||
${CMAKE_SOURCE_DIR}/include/dist_info.h
|
||||
${CMAKE_SOURCE_DIR}/include/dbus_connector.h)
|
||||
|
||||
set(RESOURCES
|
||||
${CMAKE_SOURCE_DIR}/resources/wiki_logo.svg
|
||||
|
@ -8,42 +8,35 @@
|
||||
#include <QProcess>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
class AlteratorLoader: public QObject
|
||||
namespace Alterator{
|
||||
class Loader: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
AlteratorLoader(QObject *p);
|
||||
Loader(QObject *p);
|
||||
|
||||
signals:
|
||||
void move(QString windowId, QString targetUrl);
|
||||
|
||||
void windowHistory(QString windiwId, QHash<QString, QVector<QString>> data);
|
||||
|
||||
public slots:
|
||||
void openReq(QString targetUrl);
|
||||
|
||||
void moveReq(QString senderId, QString targetUrl);
|
||||
|
||||
void closed(QString senderId);
|
||||
|
||||
void back(QString senderId);
|
||||
|
||||
void forvard(QString senderId);
|
||||
|
||||
private:
|
||||
const QString windowUrl = "../shared/AlteratorWindow.qml";
|
||||
|
||||
void open(QString targetUrl);
|
||||
|
||||
void justMove(QString senderId, QString targetUrl);
|
||||
|
||||
QHash<QString, QVector<QString>> past;
|
||||
|
||||
QHash<QString, QVector<QString>> future;
|
||||
|
||||
QHash<QString, QObject*> widgets;
|
||||
|
||||
QQmlApplicationEngine *engine;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // ALTERATORLOADER_H
|
||||
|
26
include/dbus_connector.h
Normal file
26
include/dbus_connector.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef DBUS_CONNECTOR_H
|
||||
#define DBUS_CONNECTOR_H
|
||||
|
||||
#include <QtDBus/QtDBus>
|
||||
#include <QProcess>
|
||||
#include <QHash>
|
||||
|
||||
namespace Alterator{
|
||||
class DBusConnector: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DBusConnector(QObject *parent);
|
||||
DBusConnector();
|
||||
~DBusConnector();
|
||||
|
||||
int addInterface( QString service, QString path
|
||||
, QString interface, bool systemBus, QString shortName);
|
||||
QVariant getProperty(QString InterfaceName, QString propertyName);
|
||||
QDBusInterface getInterface(QString shortName);
|
||||
private:
|
||||
QHash<QString, QDBusInterface> interfaces;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // DBUS_CONNECTOR_H
|
@ -4,47 +4,34 @@
|
||||
#include <QtDBus/QtDBus>
|
||||
#include <QProcess>
|
||||
|
||||
class AlteratorDistInfo: public QObject
|
||||
namespace Alterator {
|
||||
class DistInfo: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
AlteratorDistInfo(QObject *parent);
|
||||
|
||||
AlteratorDistInfo();
|
||||
|
||||
~AlteratorDistInfo();
|
||||
DistInfo(QObject *parent);
|
||||
DistInfo();
|
||||
~DistInfo();
|
||||
|
||||
Q_INVOKABLE QString getOS();
|
||||
|
||||
Q_INVOKABLE QString getInstalledOS();
|
||||
|
||||
Q_INVOKABLE QString getKernel();
|
||||
|
||||
Q_INVOKABLE QString getProcessor();
|
||||
|
||||
Q_INVOKABLE QString getRAM();
|
||||
|
||||
Q_INVOKABLE QString getChassis();
|
||||
|
||||
Q_INVOKABLE QString getVendor();
|
||||
|
||||
Q_INVOKABLE QString getDevice();
|
||||
|
||||
Q_INVOKABLE QString getRealm();
|
||||
|
||||
Q_INVOKABLE QString getHostname();
|
||||
|
||||
Q_INVOKABLE QString getRole();
|
||||
|
||||
Q_INVOKABLE QString getWorkgroup();
|
||||
|
||||
Q_INVOKABLE QString getHomeURL();
|
||||
|
||||
Q_INVOKABLE QString getBugURL();
|
||||
|
||||
private:
|
||||
QDBusInterface *DBusInterface;
|
||||
|
||||
QProcess *commandLineP;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // ALTERATORDISTINFO_H
|
||||
|
@ -2,7 +2,7 @@ import QtQuick 2.15
|
||||
import QtQuick.Window 2.15
|
||||
import QtQuick.Layouts 1.15
|
||||
import QtQuick.Controls 2.15
|
||||
import ru.basealt.DistInfoBack 1.0
|
||||
import Alterator.DistInfo 1.0
|
||||
import shared 1.0
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ ScrollView {
|
||||
|
||||
height: view.height
|
||||
|
||||
DistInfoBack{id: back}
|
||||
DistInfo{id: back}
|
||||
|
||||
TextWithHeader{
|
||||
id: editionArea
|
||||
@ -23,7 +23,7 @@ ScrollView {
|
||||
Layout.minimumWidth: 500
|
||||
Layout.preferredWidth: currentPage.width
|
||||
headerS: "ALT edition"
|
||||
keys: ["Kernel version", "OS version", ifDiffK()]
|
||||
keys: ["Kernel", "OS version", ifDiffK()]
|
||||
vals: [back.getKernel(), back.getInstalledOS(), ifDiffV()]
|
||||
n: 3
|
||||
comp: Component{
|
||||
@ -50,16 +50,19 @@ ScrollView {
|
||||
Layout.preferredWidth: currentPage.width
|
||||
headerS: "System"
|
||||
keys: ["Chassis", "Vendor", "Device name", "Processor", "RAM", "GPU"]
|
||||
vals: [back.getChassis(), back.getVendor(), back.getDevice(), back.getProcessor(), back.getRAM(), getSysType()]
|
||||
vals: [ back.getChassis(), back.getVendor(), back.getDevice()
|
||||
, back.getProcessor(), back.getRAM(), getSysType() ]
|
||||
n: 6
|
||||
comp: Component{
|
||||
Button{
|
||||
text: "More information"
|
||||
text: '<font color="blue"><u>More information</u></font>'
|
||||
background: Rectangle{
|
||||
color: "white"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getRAM(){return "cba"}
|
||||
function getSysType(){return "qwerty"}
|
||||
function getSysType() { return "qwerty" }
|
||||
}
|
||||
|
||||
TextWithHeader{
|
||||
@ -73,13 +76,12 @@ ScrollView {
|
||||
n: 4
|
||||
comp: Component{
|
||||
Button{
|
||||
text: "Domain settings"
|
||||
text: '<font color="blue"><u>Domain settings</u></font>'
|
||||
background: Rectangle{
|
||||
color: "white"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getProcessor(){return "abc"}
|
||||
function getRAM(){return "cba"}
|
||||
function getSysType(){return "qwerty"}
|
||||
}
|
||||
|
||||
Item {Layout.fillHeight: true}
|
||||
|
@ -29,11 +29,11 @@ Window{
|
||||
|
||||
anchors.fill: parent
|
||||
|
||||
AlteratorToolBar{
|
||||
id: toolBar
|
||||
// AlteratorToolBar{
|
||||
// id: toolBar
|
||||
|
||||
z: 1
|
||||
}
|
||||
// z: 1
|
||||
// }
|
||||
|
||||
RowLayout{
|
||||
id: layout2
|
||||
|
@ -7,11 +7,12 @@
|
||||
#include <QQmlContext>
|
||||
#include <QtQml>
|
||||
|
||||
AlteratorLoader::AlteratorLoader(QObject *p):QObject(p)
|
||||
namespace Alterator {
|
||||
Loader::Loader(QObject *p):QObject(p)
|
||||
{
|
||||
engine = new QQmlApplicationEngine(this);
|
||||
engine->addImportPath("../../new_alterator/");
|
||||
qmlRegisterType<AlteratorDistInfo>("ru.basealt.DistInfoBack", 1, 0, "DistInfoBack");
|
||||
qmlRegisterType<Alterator::DistInfo>("Alterator.DistInfo", 1, 0, "DistInfo");
|
||||
QString startingPage = "../resources/DistInfo.qml";
|
||||
past = QHash<QString, QVector<QString>>();
|
||||
future = QHash<QString, QVector<QString>>();
|
||||
@ -19,7 +20,7 @@ AlteratorLoader::AlteratorLoader(QObject *p):QObject(p)
|
||||
open(startingPage);
|
||||
}
|
||||
|
||||
void AlteratorLoader::open(QString targetUrl){
|
||||
void Loader::open(QString targetUrl){
|
||||
QString windowId = QUuid::createUuid().toString();
|
||||
engine->load(windowUrl);
|
||||
QObject *window = engine->rootObjects().last();
|
||||
@ -35,11 +36,11 @@ void AlteratorLoader::open(QString targetUrl){
|
||||
connect(window, SIGNAL(forvardS(QString)), this, SLOT(forvard(QString)));
|
||||
}
|
||||
|
||||
void AlteratorLoader::openReq(QString targetUrl){
|
||||
void Loader::openReq(QString targetUrl){
|
||||
open(targetUrl);
|
||||
}
|
||||
|
||||
void AlteratorLoader::justMove(QString senderId, QString targetUrl){
|
||||
void Loader::justMove(QString senderId, QString targetUrl){
|
||||
QObject *window = widgets[senderId];
|
||||
QObject *loader = window->findChild<QObject *>("currentPageN");
|
||||
loader->setProperty("active", "false");
|
||||
@ -48,13 +49,13 @@ void AlteratorLoader::justMove(QString senderId, QString targetUrl){
|
||||
engine->clearComponentCache();
|
||||
}
|
||||
|
||||
void AlteratorLoader::moveReq(QString senderId, QString targetUrl){
|
||||
void Loader::moveReq(QString senderId, QString targetUrl){
|
||||
justMove(senderId, targetUrl);
|
||||
past[senderId].append(targetUrl);
|
||||
future[senderId] = QVector<QString>();
|
||||
}
|
||||
|
||||
void AlteratorLoader::closed(QString senderId){
|
||||
void Loader::closed(QString senderId){
|
||||
past.remove(senderId);
|
||||
future.remove(senderId);
|
||||
widgets[senderId]->deleteLater();
|
||||
@ -64,7 +65,7 @@ void AlteratorLoader::closed(QString senderId){
|
||||
}
|
||||
}
|
||||
|
||||
void AlteratorLoader::back(QString senderId){
|
||||
void Loader::back(QString senderId){
|
||||
if (past[senderId].size() > 1){
|
||||
future[senderId].append(past[senderId].last());
|
||||
past[senderId].removeLast();
|
||||
@ -73,7 +74,7 @@ void AlteratorLoader::back(QString senderId){
|
||||
}
|
||||
}
|
||||
|
||||
void AlteratorLoader::forvard(QString senderId){
|
||||
void Loader::forvard(QString senderId){
|
||||
if (future[senderId].size() > 0){
|
||||
past[senderId].append(future[senderId].last());
|
||||
future[senderId].removeLast();
|
||||
@ -81,3 +82,4 @@ void AlteratorLoader::forvard(QString senderId){
|
||||
justMove(senderId, targetUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "../include/dist_info.h"
|
||||
#include <QJsonDocument>
|
||||
|
||||
AlteratorDistInfo::AlteratorDistInfo(QObject *parent): QObject(parent)
|
||||
namespace Alterator{
|
||||
DistInfo::DistInfo(QObject *parent): QObject(parent)
|
||||
{
|
||||
QDBusConnection bus = QDBusConnection::systemBus();
|
||||
DBusInterface = new QDBusInterface("org.freedesktop.hostname1", "/org/freedesktop/hostname1",
|
||||
@ -9,43 +9,54 @@ AlteratorDistInfo::AlteratorDistInfo(QObject *parent): QObject(parent)
|
||||
commandLineP = new QProcess(this);
|
||||
}
|
||||
|
||||
AlteratorDistInfo::AlteratorDistInfo(): QObject( )
|
||||
DistInfo::DistInfo(): QObject( )
|
||||
{
|
||||
QDBusConnection bus = QDBusConnection::systemBus();
|
||||
DBusInterface = new QDBusInterface("org.freedesktop.hostname1", "/org/freedesktop/hostname1",
|
||||
"org.freedesktop.hostname1", bus);
|
||||
}
|
||||
|
||||
AlteratorDistInfo::~AlteratorDistInfo(){
|
||||
DistInfo::~DistInfo(){
|
||||
delete DBusInterface;
|
||||
}
|
||||
|
||||
QString AlteratorDistInfo::getChassis(){
|
||||
QString DistInfo::getChassis(){
|
||||
return DBusInterface->property("Chassis").toString();
|
||||
}
|
||||
|
||||
QString AlteratorDistInfo::getVendor(){
|
||||
QString DistInfo::getVendor(){
|
||||
return DBusInterface->property("HardwareVendor").toString();
|
||||
}
|
||||
|
||||
QString AlteratorDistInfo::getDevice(){
|
||||
QString DistInfo::getDevice(){
|
||||
return DBusInterface->property("HardwareModel").toString();
|
||||
}
|
||||
|
||||
QString AlteratorDistInfo::getOS(){
|
||||
QString DistInfo::getOS(){
|
||||
return DBusInterface->property("OperatingSystemPrettyName").toString();
|
||||
}
|
||||
|
||||
QString AlteratorDistInfo::getInstalledOS(){
|
||||
return "hmmm";
|
||||
QString DistInfo::getInstalledOS(){
|
||||
QProcess clp;
|
||||
clp.start("cat", QStringList() << "/etc/os-release");
|
||||
if (!clp.waitForStarted())
|
||||
return "";
|
||||
if (!clp.waitForFinished())
|
||||
return "";
|
||||
QString result = clp.readAll();
|
||||
QStringRef res = &result;
|
||||
res = res.right(res.size() - res.indexOf("BUILD_ID"));
|
||||
res = res.right(res.size() - res.indexOf("\"") - 1);
|
||||
res = res.left(res.indexOf("\""));
|
||||
return res.toString();
|
||||
}
|
||||
|
||||
QString AlteratorDistInfo::getKernel(){
|
||||
QString DistInfo::getKernel(){
|
||||
return DBusInterface->property("KernelName").toString() + " " +
|
||||
DBusInterface->property("KernelRelease").toString();
|
||||
DBusInterface->property("KernelRelease").toString();
|
||||
}
|
||||
|
||||
QString AlteratorDistInfo::getProcessor(){
|
||||
QString DistInfo::getProcessor(){
|
||||
QProcess clp;
|
||||
clp.start("cat", QStringList() << "/proc/cpuinfo");
|
||||
if (!clp.waitForStarted())
|
||||
@ -64,7 +75,7 @@ QString AlteratorDistInfo::getProcessor(){
|
||||
return res.toString() + " " + QChar(0x00D7) + " " + QString::number(cores.toInt());
|
||||
}
|
||||
|
||||
QString AlteratorDistInfo::getRAM(){
|
||||
QString DistInfo::getRAM(){
|
||||
QProcess clp;
|
||||
clp.start("cat", QStringList() << "/proc/meminfo");
|
||||
if (!clp.waitForStarted())
|
||||
@ -77,14 +88,14 @@ QString AlteratorDistInfo::getRAM(){
|
||||
res = res.left(res.indexOf("\n"));
|
||||
res = res.left(res.lastIndexOf(" "));
|
||||
res = res.right(res.size() - res.lastIndexOf(" "));
|
||||
return QString::number(res.toDouble() / 1024 / 1024, 'f', 3) + " Gb";
|
||||
return QString::number(res.toDouble() / 1024 / 1024, 'f', 1) + " Gb";
|
||||
}
|
||||
|
||||
QString AlteratorDistInfo::getHostname(){
|
||||
QString DistInfo::getHostname(){
|
||||
return DBusInterface->property("Hostname").toString();
|
||||
}
|
||||
|
||||
QString AlteratorDistInfo::getRealm(){
|
||||
QString DistInfo::getRealm(){
|
||||
QProcess clp;
|
||||
clp.start("testparm", QStringList() << "-s");
|
||||
if (!clp.waitForStarted())
|
||||
@ -99,7 +110,7 @@ QString AlteratorDistInfo::getRealm(){
|
||||
return res.toString();
|
||||
}
|
||||
|
||||
QString AlteratorDistInfo::getWorkgroup(){
|
||||
QString DistInfo::getWorkgroup(){
|
||||
QProcess clp;
|
||||
clp.start("testparm", QStringList() << "-s");
|
||||
if (!clp.waitForStarted())
|
||||
@ -114,24 +125,24 @@ QString AlteratorDistInfo::getWorkgroup(){
|
||||
return res.toString();
|
||||
}
|
||||
|
||||
QString AlteratorDistInfo::getRole(){
|
||||
// QProcess clp;
|
||||
// clp.start("testparm", QStringList());
|
||||
// if (!clp.waitForStarted())
|
||||
// return "";
|
||||
// if (!clp.waitForFinished())
|
||||
// return "";
|
||||
// QString result = clp.readAll();
|
||||
// QStringRef res = &result;
|
||||
// res = res.right(res.size() - res.indexOf("Server role: "));
|
||||
// res = res.left(res.indexOf("\n"));
|
||||
// res = res.right(res.size() - res.indexOf(": ") - 2);
|
||||
// qDebug() << result;
|
||||
// return res.toString();
|
||||
QString DistInfo::getRole(){
|
||||
// QProcess clp;
|
||||
// clp.start("testparm", QStringList());
|
||||
// if (!clp.waitForStarted())
|
||||
// return "";
|
||||
// if (!clp.waitForFinished())
|
||||
// return "";
|
||||
// QString result = clp.readAll();
|
||||
// QStringRef res = &result;
|
||||
// res = res.right(res.size() - res.indexOf("Server role: "));
|
||||
// res = res.left(res.indexOf("\n"));
|
||||
// res = res.right(res.size() - res.indexOf(": ") - 2);
|
||||
// qDebug() << result;
|
||||
// return res.toString();
|
||||
return "...";
|
||||
}
|
||||
|
||||
QString AlteratorDistInfo::getHomeURL(){
|
||||
QString DistInfo::getHomeURL(){
|
||||
QProcess clp;
|
||||
clp.start("cat", QStringList() << "/etc/os-release");
|
||||
if (!clp.waitForStarted())
|
||||
@ -147,7 +158,7 @@ QString AlteratorDistInfo::getHomeURL(){
|
||||
return res.toString();
|
||||
}
|
||||
|
||||
QString AlteratorDistInfo::getBugURL(){
|
||||
QString DistInfo::getBugURL(){
|
||||
QProcess clp;
|
||||
clp.start("cat", QStringList() << "/etc/os-release");
|
||||
if (!clp.waitForStarted())
|
||||
@ -161,3 +172,4 @@ QString AlteratorDistInfo::getBugURL(){
|
||||
res = res.left(res.indexOf("\"") - 1);
|
||||
return res.toString();
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
AlteratorLoader l = AlteratorLoader(&a);
|
||||
Alterator::Loader l = Alterator::Loader(&a);
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user