diff --git a/shvspy/src/appversion.h b/shvspy/src/appversion.h index 06d9efe..04e7e3b 100644 --- a/shvspy/src/appversion.h +++ b/shvspy/src/appversion.h @@ -1,4 +1,4 @@ #pragma once -#define APP_VERSION "1.9.12" +#define APP_VERSION "1.10.0" diff --git a/shvspy/src/dlgbrokerproperties.cpp b/shvspy/src/dlgbrokerproperties.cpp index 7fccd22..8b66540 100644 --- a/shvspy/src/dlgbrokerproperties.cpp +++ b/shvspy/src/dlgbrokerproperties.cpp @@ -50,7 +50,7 @@ DlgBrokerProperties::DlgBrokerProperties(QWidget *parent) : ui->cbxConnectionType->setCurrentIndex(0); ui->rpc_protocolType->addItem(Rpc::protocolTypeToString(Rpc::ProtocolType::ChainPack), static_cast(Rpc::ProtocolType::ChainPack)); - //ui->rpc_protocolType->addItem(Rpc::protocolTypeToString(Rpc::ProtocolType::Cpon), static_cast(Rpc::ProtocolType::Cpon)); + ui->rpc_protocolType->addItem(Rpc::protocolTypeToString(Rpc::ProtocolType::Cpon), static_cast(Rpc::ProtocolType::Cpon)); //ui->rpc_protocolType->addItem(Rpc::protocolTypeToString(Rpc::ProtocolType::JsonRpc), static_cast(Rpc::ProtocolType::JsonRpc)); ui->rpc_protocolType->setCurrentIndex(0); diff --git a/shvspy/src/dlgmountseditor.cpp b/shvspy/src/dlgmountseditor.cpp index 5c1fa30..230c924 100644 --- a/shvspy/src/dlgmountseditor.cpp +++ b/shvspy/src/dlgmountseditor.cpp @@ -2,6 +2,7 @@ #include "ui_dlgmountseditor.h" #include "dlgaddeditmount.h" +#include "theapp.h" #include #include @@ -14,7 +15,7 @@ static const std::string METHOD_VALUE = "value"; static const std::string METHOD_SET_VALUE = "setValue"; -DlgMountsEditor::DlgMountsEditor(QWidget *parent, shv::iotqt::rpc::ClientConnection *rpc_connection) : +DlgMountsEditor::DlgMountsEditor(QWidget *parent, shv::iotqt::rpc::ClientConnection *rpc_connection, const std::string &broker_path) : QDialog(parent), ui(new Ui::DlgMountsEditor) { @@ -24,6 +25,8 @@ DlgMountsEditor::DlgMountsEditor(QWidget *parent, shv::iotqt::rpc::ClientConnect m_rpcConnection = rpc_connection; + m_aclNodePath = TheApp::aclAccessPath(broker_path, m_rpcConnection->shvApiVersion()); + static constexpr double ROW_HEIGHT_RATIO = 1.3; static QStringList INFO_HEADER_NAMES { tr("Device ID"), tr("Mount point"), tr("Description") }; @@ -49,6 +52,8 @@ DlgMountsEditor::DlgMountsEditor(QWidget *parent, shv::iotqt::rpc::ClientConnect connect(ui->leFilter, &QLineEdit::textChanged, m_modelProxy, &QSortFilterProxyModel::setFilterFixedString); setStatusText(QString()); + + listMounts(); } DlgMountsEditor::~DlgMountsEditor() @@ -56,15 +61,9 @@ DlgMountsEditor::~DlgMountsEditor() delete ui; } -void DlgMountsEditor::init(const std::string &acl_node_path) -{ - m_aclEtcNodePath = acl_node_path; - listMounts(); -} - std::string DlgMountsEditor::aclEtcMountsNodePath() { - return m_aclEtcNodePath + "/mounts"; + return m_aclNodePath + "/mounts"; } QString DlgMountsEditor::selectedMount() @@ -79,7 +78,7 @@ QString DlgMountsEditor::selectedMount() void DlgMountsEditor::onAddMountClicked() { - auto dlg = new DlgAddEditMount(this, m_rpcConnection, m_aclEtcNodePath, DlgAddEditMount::DialogType::Add); + auto dlg = new DlgAddEditMount(this, m_rpcConnection, m_aclNodePath, DlgAddEditMount::DialogType::Add); connect(dlg, &QDialog::finished, dlg, [this, dlg] (int result) { if (result == QDialog::Accepted){ listMounts(); @@ -135,7 +134,7 @@ void DlgMountsEditor::onEditMountClicked() setStatusText(QString()); - auto dlg = new DlgAddEditMount(this, m_rpcConnection, m_aclEtcNodePath, DlgAddEditMount::DialogType::Edit); + auto dlg = new DlgAddEditMount(this, m_rpcConnection, m_aclNodePath, DlgAddEditMount::DialogType::Edit); dlg->init(mount); connect(dlg, &QDialog::finished, dlg, [this, dlg] (int result) { if (result == QDialog::Accepted){ diff --git a/shvspy/src/dlgmountseditor.h b/shvspy/src/dlgmountseditor.h index 6a51349..378b919 100644 --- a/shvspy/src/dlgmountseditor.h +++ b/shvspy/src/dlgmountseditor.h @@ -17,10 +17,8 @@ class DlgMountsEditor : public QDialog Q_OBJECT public: - explicit DlgMountsEditor(QWidget *parent, shv::iotqt::rpc::ClientConnection *rpc_connection); + explicit DlgMountsEditor(QWidget *parent, shv::iotqt::rpc::ClientConnection *rpc_connection, const std::string &broker_path); ~DlgMountsEditor() override; - void init(const std::string &acl_node_path); - private: std::string aclEtcMountsNodePath(); @@ -45,7 +43,7 @@ class DlgMountsEditor : public QDialog RpcCallStatus status = Unfinished; }; Ui::DlgMountsEditor *ui; - std::string m_aclEtcNodePath; + std::string m_aclNodePath; shv::iotqt::rpc::ClientConnection *m_rpcConnection = nullptr; QMap m_mountPoints; QString m_lastCurrentId; diff --git a/shvspy/src/dlgroleseditor.cpp b/shvspy/src/dlgroleseditor.cpp index 71ea29c..81ae60e 100644 --- a/shvspy/src/dlgroleseditor.cpp +++ b/shvspy/src/dlgroleseditor.cpp @@ -2,6 +2,7 @@ #include "ui_dlgroleseditor.h" #include "dlgaddeditrole.h" +#include "theapp.h" #include #include @@ -13,9 +14,10 @@ static const std::string SET_VALUE_METHOD = "setValue"; -DlgRolesEditor::DlgRolesEditor(QWidget *parent, shv::iotqt::rpc::ClientConnection *rpc_connection) : - QDialog(parent), - ui(new Ui::DlgRolesEditor) +DlgRolesEditor::DlgRolesEditor(QWidget *parent, shv::iotqt::rpc::ClientConnection *rpc_connection, const std::string &broker_path) + : QDialog(parent) + , ui(new Ui::DlgRolesEditor) + , m_brokerPath(broker_path) { ui->setupUi(this); @@ -45,6 +47,8 @@ DlgRolesEditor::DlgRolesEditor(QWidget *parent, shv::iotqt::rpc::ClientConnectio connect(ui->leFilter, &QLineEdit::textChanged, m_modelProxy, &QSortFilterProxyModel::setFilterFixedString); setStatusText(QString()); + + listRoles(); } DlgRolesEditor::~DlgRolesEditor() @@ -52,20 +56,14 @@ DlgRolesEditor::~DlgRolesEditor() delete ui; } -void DlgRolesEditor::init(const std::string &acl_node_path) -{ - m_aclEtcNodePath = acl_node_path; - listRoles(); -} - std::string DlgRolesEditor::aclEtcRolesNodePath() { - return m_aclEtcNodePath + "/roles"; + return aclAccessPath() + "/roles"; } std::string DlgRolesEditor::aclEtcAccessNodePath() { - return m_aclEtcNodePath + "/access"; + return aclAccessPath() + "/access"; } QString DlgRolesEditor::selectedRole() @@ -75,7 +73,7 @@ QString DlgRolesEditor::selectedRole() void DlgRolesEditor::onAddRoleClicked() { - auto dlg = new DlgAddEditRole(this, m_rpcConnection, m_aclEtcNodePath, DlgAddEditRole::DialogType::Add); + auto dlg = new DlgAddEditRole(this, m_rpcConnection, aclAccessPath(), DlgAddEditRole::DialogType::Add); connect(dlg, &QDialog::finished, dlg, [this, dlg] (int result) { if (result == QDialog::Accepted){ listRoles(); @@ -97,7 +95,7 @@ void DlgRolesEditor::onEditRoleClicked() setStatusText(QString()); - auto dlg = new DlgAddEditRole(this, m_rpcConnection, m_aclEtcNodePath, DlgAddEditRole::DialogType::Edit); + auto dlg = new DlgAddEditRole(this, m_rpcConnection, aclAccessPath(), DlgAddEditRole::DialogType::Edit); dlg->init(role); connect(dlg, &QDialog::finished, dlg, [this, dlg] (int result) { if (result == QDialog::Accepted){ @@ -190,3 +188,8 @@ void DlgRolesEditor::setStatusText(const QString &txt) ui->lblStatus->setText(txt); } } + +std::string DlgRolesEditor::aclAccessPath() +{ + return TheApp::aclAccessPath(m_brokerPath, m_rpcConnection->shvApiVersion()); +} diff --git a/shvspy/src/dlgroleseditor.h b/shvspy/src/dlgroleseditor.h index 8e69171..7d7a781 100644 --- a/shvspy/src/dlgroleseditor.h +++ b/shvspy/src/dlgroleseditor.h @@ -16,9 +16,8 @@ class DlgRolesEditor : public QDialog Q_OBJECT public: - explicit DlgRolesEditor(QWidget *parent, shv::iotqt::rpc::ClientConnection *rpc_connection); + explicit DlgRolesEditor(QWidget *parent, shv::iotqt::rpc::ClientConnection *rpc_connection, const std::string &broker_path); ~DlgRolesEditor() override; - void init(const std::string &acl_node_path); private: std::string aclEtcRolesNodePath(); @@ -33,10 +32,10 @@ class DlgRolesEditor : public QDialog void onTableRoleDoubleClicked(QModelIndex ix); void setStatusText(const QString &txt); - + std::string aclAccessPath(); private: Ui::DlgRolesEditor *ui; - std::string m_aclEtcNodePath; + std::string m_brokerPath; shv::iotqt::rpc::ClientConnection *m_rpcConnection = nullptr; QStandardItemModel *m_dataModel; QSortFilterProxyModel *m_modelProxy; diff --git a/shvspy/src/dlgselectroles.cpp b/shvspy/src/dlgselectroles.cpp index a634eef..6729d18 100644 --- a/shvspy/src/dlgselectroles.cpp +++ b/shvspy/src/dlgselectroles.cpp @@ -14,39 +14,39 @@ DlgSelectRoles::DlgSelectRoles(QWidget *parent): void DlgSelectRoles::init(shv::iotqt::rpc::ClientConnection *rpc_connection, const std::string &acl_etc_node_path, const std::vector &roles) { - m_rpcConnection = rpc_connection; - m_aclEtcNodePath = acl_etc_node_path; + m_rpcConnection = rpc_connection; + m_aclEtcNodePath = acl_etc_node_path; m_rolesTreeModel = new RolesTreeModel(this); m_rolesTreeModel->load(rpc_connection, aclEtcRolesNodePath()); ui->tvRoles->setModel(m_rolesTreeModel); - ui->tvRoles->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu); + ui->tvRoles->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu); m_userRoles = roles; - connect(ui->tvRoles, &QTreeView::customContextMenuRequested, this, &DlgSelectRoles::contextMenu); - connect(ui->tvRoles->selectionModel(), &QItemSelectionModel::currentChanged, this, [this]() { - ui->editRoleButton->setEnabled(ui->tvRoles->currentIndex().isValid()); - }); - connect(ui->editRoleButton, &QPushButton::clicked, this, &DlgSelectRoles::editRole); + connect(ui->tvRoles, &QTreeView::customContextMenuRequested, this, &DlgSelectRoles::contextMenu); + connect(ui->tvRoles->selectionModel(), &QItemSelectionModel::currentChanged, this, [this]() { + ui->editRoleButton->setEnabled(ui->tvRoles->currentIndex().isValid()); + }); + connect(ui->editRoleButton, &QPushButton::clicked, this, &DlgSelectRoles::editRole); - ui->lblStatus->setText(tr("Loading...")); - ui->tvRoles->setEnabled(false); - ui->editRoleButton->setEnabled(false); + ui->lblStatus->setText(tr("Loading...")); + ui->tvRoles->setEnabled(false); + ui->editRoleButton->setEnabled(false); connect(m_rolesTreeModel, &RolesTreeModel::loadFinished, this, [this](){ - ui->lblStatus->clear(); - ui->tvRoles->setEnabled(true); + ui->lblStatus->clear(); + ui->tvRoles->setEnabled(true); m_rolesTreeModel->setSelectedRoles(m_userRoles); - if (!m_currentItemPath.isEmpty()) { - QStandardItem *item = findChildItem(m_rolesTreeModel->invisibleRootItem(), m_currentItemPath); - if (item) { - QModelIndex ix = m_rolesTreeModel->indexFromItem(item); - ui->tvRoles->setCurrentIndex(ix); - ui->tvRoles->scrollTo(ix); - } - } - }); + if (!m_currentItemPath.isEmpty()) { + QStandardItem *item = findChildItem(m_rolesTreeModel->invisibleRootItem(), m_currentItemPath); + if (item) { + QModelIndex ix = m_rolesTreeModel->indexFromItem(item); + ui->tvRoles->setCurrentIndex(ix); + ui->tvRoles->scrollTo(ix); + } + } + }); connect(m_rolesTreeModel, &RolesTreeModel::loadError, this, [this](QString error){ ui->lblStatus->setText(error); @@ -60,73 +60,73 @@ std::vector DlgSelectRoles::selectedRoles() void DlgSelectRoles::setUserRoles(const std::vector &roles) { - m_rolesTreeModel->setSelectedRoles(roles); + m_rolesTreeModel->setSelectedRoles(roles); } void DlgSelectRoles::contextMenu(const QPoint &glob_pos) { - QMenu menu(this); - auto *edit_role = new QAction(tr("&Edit role"), &menu); - connect(edit_role, &QAction::triggered, this, &DlgSelectRoles::editRole); - edit_role->setEnabled(ui->tvRoles->currentIndex().isValid()); - menu.addAction(edit_role); - menu.exec(mapToGlobal(glob_pos)); + QMenu menu(this); + auto *edit_role = new QAction(tr("&Edit role"), &menu); + connect(edit_role, &QAction::triggered, this, &DlgSelectRoles::editRole); + edit_role->setEnabled(ui->tvRoles->currentIndex().isValid()); + menu.addAction(edit_role); + menu.exec(mapToGlobal(glob_pos)); } void DlgSelectRoles::editRole() { - QStandardItem *item = m_rolesTreeModel->itemFromIndex(ui->tvRoles->currentIndex()); - QString role_name = item->data(RolesTreeModel::NameRole).toString(); + QStandardItem *item = m_rolesTreeModel->itemFromIndex(ui->tvRoles->currentIndex()); + QString role_name = item->data(RolesTreeModel::NameRole).toString(); - auto dlg = new DlgAddEditRole (this, m_rpcConnection, m_aclEtcNodePath, DlgAddEditRole::DialogType::Edit); + auto dlg = new DlgAddEditRole (this, m_rpcConnection, m_aclEtcNodePath, DlgAddEditRole::DialogType::Edit); dlg->init(role_name); connect(dlg, &QDialog::finished, dlg, [this, dlg, item] (int result) mutable { - if (result == QDialog::Accepted) { - m_currentItemPath << item->text(); - while (item->parent()) { - item = item->parent(); - m_currentItemPath.prepend(item->text()); - } - m_userRoles = selectedRoles(); - - m_rolesTreeModel->clear(); - ui->tvRoles->setEnabled(false); - ui->lblStatus->setText(tr("Reloading roles...")); - ui->editRoleButton->setEnabled(false); - m_rolesTreeModel->load(m_rpcConnection, aclEtcRolesNodePath()); - } + if (result == QDialog::Accepted) { + m_currentItemPath << item->text(); + while (item->parent()) { + item = item->parent(); + m_currentItemPath.prepend(item->text()); + } + m_userRoles = selectedRoles(); + + m_rolesTreeModel->clear(); + ui->tvRoles->setEnabled(false); + ui->lblStatus->setText(tr("Reloading roles...")); + ui->editRoleButton->setEnabled(false); + m_rolesTreeModel->load(m_rpcConnection, aclEtcRolesNodePath()); + } dlg->deleteLater(); }); - dlg->open(); + dlg->open(); } QStandardItem *DlgSelectRoles::findChildItem(QStandardItem *item, const QStringList &path, int ix) { - QStandardItem *child = findChildItem(item, path[ix]); - if (!child) { - return nullptr; - } - if (++ix == path.count()) { - return child; - } - return findChildItem(child, path, ix); + QStandardItem *child = findChildItem(item, path[ix]); + if (!child) { + return nullptr; + } + if (++ix == path.count()) { + return child; + } + return findChildItem(child, path, ix); } QStandardItem *DlgSelectRoles::findChildItem(QStandardItem *item, const QString &text) { - for (int i = 0; i < item->rowCount(); ++i) { - QStandardItem *child = item->child(i, 0); - if (child->text() == text) { - return child; - } - } - return nullptr; + for (int i = 0; i < item->rowCount(); ++i) { + QStandardItem *child = item->child(i, 0); + if (child->text() == text) { + return child; + } + } + return nullptr; } std::string DlgSelectRoles::aclEtcRolesNodePath() { - return m_aclEtcNodePath + "/roles"; + return m_aclEtcNodePath + "/roles"; } DlgSelectRoles::~DlgSelectRoles() diff --git a/shvspy/src/dlgselectroles.h b/shvspy/src/dlgselectroles.h index 28b843b..58dc562 100644 --- a/shvspy/src/dlgselectroles.h +++ b/shvspy/src/dlgselectroles.h @@ -26,17 +26,17 @@ class DlgSelectRoles : public QDialog private: - void contextMenu(const QPoint &glob_pos); - void editRole(); - QStandardItem *findChildItem(QStandardItem *item, const QStringList &path, int ix = 0); - QStandardItem *findChildItem(QStandardItem *item, const QString &text); + void contextMenu(const QPoint &glob_pos); + void editRole(); + QStandardItem *findChildItem(QStandardItem *item, const QStringList &path, int ix = 0); + QStandardItem *findChildItem(QStandardItem *item, const QString &text); std::string aclEtcRolesNodePath(); std::vector m_userRoles; - QStringList m_currentItemPath; + QStringList m_currentItemPath; RolesTreeModel *m_rolesTreeModel = nullptr; - shv::iotqt::rpc::ClientConnection *m_rpcConnection = nullptr; - std::string m_aclEtcNodePath; + shv::iotqt::rpc::ClientConnection *m_rpcConnection = nullptr; + std::string m_aclEtcNodePath; Ui::DlgSelectRoles *ui; }; diff --git a/shvspy/src/dlguserseditor.cpp b/shvspy/src/dlguserseditor.cpp index 9039762..63941ff 100644 --- a/shvspy/src/dlguserseditor.cpp +++ b/shvspy/src/dlguserseditor.cpp @@ -2,6 +2,7 @@ #include "ui_dlguserseditor.h" #include "dlgaddedituser.h" +#include "theapp.h" #include #include @@ -178,11 +179,7 @@ void DlgUsersEditor::onTableUsersDoubleClicked(QModelIndex ix) std::string DlgUsersEditor::aclAccessPath() { - switch (m_rpcConnection->shvApiVersion()) { - case shv::chainpack::IRpcConnection::ShvApiVersion::V2: return m_brokerPath + "/etc/acl"; - case shv::chainpack::IRpcConnection::ShvApiVersion::V3: return m_brokerPath + "/access"; - } - return ""; + return TheApp::aclAccessPath(m_brokerPath, m_rpcConnection->shvApiVersion()); } std::string DlgUsersEditor::aclAccessUsersPath() diff --git a/shvspy/src/mainwindow.cpp b/shvspy/src/mainwindow.cpp index b3bcd62..2f5e125 100644 --- a/shvspy/src/mainwindow.cpp +++ b/shvspy/src/mainwindow.cpp @@ -367,8 +367,7 @@ void MainWindow::onTreeServers_customContextMenuRequested(const QPoint &pos) if(nd) { shv::iotqt::rpc::ClientConnection *cc = nd->serverNode()->clientConnection(); - auto dlg = new DlgRolesEditor (this, cc); - dlg->init(nd->shvPath() + "/etc/acl"); + auto dlg = new DlgRolesEditor (this, cc, nd->shvPath()); dlg->open(); connect(dlg, &QDialog::finished, dlg, &QObject::deleteLater); } @@ -378,8 +377,7 @@ void MainWindow::onTreeServers_customContextMenuRequested(const QPoint &pos) if(nd) { shv::iotqt::rpc::ClientConnection *cc = nd->serverNode()->clientConnection(); - auto dlg = new DlgMountsEditor(this, cc); - dlg->init(nd->shvPath() + "/etc/acl"); + auto dlg = new DlgMountsEditor(this, cc, nd->shvPath()); dlg->open(); connect(dlg, &QDialog::finished, dlg, &QObject::deleteLater); } diff --git a/shvspy/src/servertreemodel/shvbrokernodeitem.cpp b/shvspy/src/servertreemodel/shvbrokernodeitem.cpp index 17d86d2..d05d417 100644 --- a/shvspy/src/servertreemodel/shvbrokernodeitem.cpp +++ b/shvspy/src/servertreemodel/shvbrokernodeitem.cpp @@ -278,6 +278,10 @@ void ShvBrokerNodeItem::open() cli->setPassword(pwd); //cli->setSkipLoginPhase(m_brokerPropeties.value("skipLoginPhase").toBool()); + auto protocol_type = static_cast(m_brokerPropeties.value(brokerProperty::RPC_PROTOCOLTYPE, static_cast(shv::chainpack::Rpc::ProtocolType::ChainPack)).toInt()); + cli->setProtocolType(protocol_type); + + #if QT_VERSION_MAJOR >= 6 && defined(WITH_AZURE_SUPPORT) bool azure_login = m_brokerPropeties.value(brokerProperty::AZURELOGIN, false).toBool(); diff --git a/shvspy/src/theapp.cpp b/shvspy/src/theapp.cpp index 7e23f7e..7920d8e 100644 --- a/shvspy/src/theapp.cpp +++ b/shvspy/src/theapp.cpp @@ -42,3 +42,12 @@ void TheApp::saveSettings(QSettings &settings) { m_serverTreeModel->saveSettings(settings); } + +std::string TheApp::aclAccessPath(const std::string &broker_path, shv::iotqt::rpc::ClientConnection::ShvApiVersion api_version) +{ + switch (api_version) { + case shv::chainpack::IRpcConnection::ShvApiVersion::V2: return broker_path + "/etc/acl"; + case shv::chainpack::IRpcConnection::ShvApiVersion::V3: return broker_path + "/access"; + } + return ""; +} diff --git a/shvspy/src/theapp.h b/shvspy/src/theapp.h index f39f7a3..2f64b51 100644 --- a/shvspy/src/theapp.h +++ b/shvspy/src/theapp.h @@ -2,6 +2,7 @@ #define THEAPP_H #include +#include #include #include @@ -35,6 +36,7 @@ class TheApp : public QApplication void loadSettings(QSettings &settings); void saveSettings(QSettings &settings); + static std::string aclAccessPath(const std::string &broker_path, shv::iotqt::rpc::ClientConnection::ShvApiVersion api_version); private: ServerTreeModel *m_serverTreeModel = nullptr; AttributesModel *m_attributesModel = nullptr;