added pages for sftp and tor website settings

This commit is contained in:
vladimir.kuznetsov 2023-07-18 11:15:04 +09:00
parent 75489c00c2
commit 5d677a9115
22 changed files with 713 additions and 6 deletions

View file

@ -118,6 +118,11 @@ QString ContainersModel::getCurrentlyProcessedContainerName()
return ContainerProps::containerHumanNames().value(static_cast<DockerContainer>(m_currentlyProcessedContainerIndex));
}
QJsonObject ContainersModel::getCurrentlyProcessedContainerConfig()
{
return qvariant_cast<QJsonObject>(data(index(m_currentlyProcessedContainerIndex), ConfigRole));
}
void ContainersModel::removeAllContainers()
{

View file

@ -50,6 +50,7 @@ public slots:
int getCurrentlyProcessedContainerIndex();
QString getCurrentlyProcessedContainerName();
QJsonObject getCurrentlyProcessedContainerConfig();
void removeAllContainers();
void removeCurrentlyProcessedContainer();

View file

@ -106,6 +106,11 @@ int ServersModel::getCurrentlyProcessedServerIndex()
return m_currentlyProcessedServerIndex;
}
QString ServersModel::getCurrentlyProcessedServerHostName()
{
return qvariant_cast<QString>(data(m_currentlyProcessedServerIndex, HostNameRole));
}
bool ServersModel::isDefaultServerCurrentlyProcessed()
{
return m_defaultServerIndex == m_currentlyProcessedServerIndex;

View file

@ -45,6 +45,8 @@ public slots:
void setCurrentlyProcessedServerIndex(const int index);
int getCurrentlyProcessedServerIndex();
QString getCurrentlyProcessedServerHostName();
void addServer(const QJsonObject &server);
void removeServer();

View file

@ -0,0 +1,64 @@
#include "sftpConfigModel.h"
#include "protocols/protocols_defs.h"
SftpConfigModel::SftpConfigModel(QObject *parent) : QAbstractListModel(parent)
{
}
int SftpConfigModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 1;
}
QVariant SftpConfigModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() < 0 || index.row() >= rowCount()) {
return false;
}
switch (role) {
case Roles::PortRole: return m_protocolConfig.value(config_key::port).toString();
case Roles::UserNameRole:
return m_protocolConfig.value(config_key::userName).toString(protocols::sftp::defaultUserName);
case Roles::PasswordRole: return m_protocolConfig.value(config_key::password).toString();
}
return QVariant();
}
void SftpConfigModel::updateModel(const QJsonObject &config)
{
beginResetModel();
m_container = ContainerProps::containerFromString(config.value(config_key::container).toString());
m_fullConfig = config;
QJsonObject protocolConfig = config.value(config_key::sftp).toObject();
m_protocolConfig.insert(config_key::userName,
protocolConfig.value(config_key::userName).toString(protocols::sftp::defaultUserName));
m_protocolConfig.insert(config_key::password, protocolConfig.value(config_key::password).toString());
m_protocolConfig.insert(config_key::port, protocolConfig.value(config_key::port).toString());
endResetModel();
}
QJsonObject SftpConfigModel::getConfig()
{
m_fullConfig.insert(config_key::sftp, m_protocolConfig);
return m_fullConfig;
}
QHash<int, QByteArray> SftpConfigModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[PortRole] = "port";
roles[UserNameRole] = "username";
roles[PasswordRole] = "password";
return roles;
}

View file

@ -0,0 +1,39 @@
#ifndef SFTPCONFIGMODEL_H
#define SFTPCONFIGMODEL_H
#include <QAbstractListModel>
#include <QJsonObject>
#include "containers/containers_defs.h"
class SftpConfigModel : public QAbstractListModel
{
Q_OBJECT
public:
enum Roles {
PortRole = Qt::UserRole + 1,
UserNameRole,
PasswordRole
};
explicit SftpConfigModel(QObject *parent = nullptr);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
public slots:
void updateModel(const QJsonObject &config);
QJsonObject getConfig();
protected:
QHash<int, QByteArray> roleNames() const override;
private:
DockerContainer m_container;
QJsonObject m_protocolConfig;
QJsonObject m_fullConfig;
};
#endif // SFTPCONFIGMODEL_H