moved handling of connection states from qml in connectionController
- added a check for already installed containers before installing the server/container - added a button to scan the server for installed containers - added separation for read/write and readonly servers for pageHome
This commit is contained in:
parent
3a264e6baf
commit
249be451f7
21 changed files with 466 additions and 245 deletions
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
#include "core/servercontroller.h"
|
||||
|
||||
ContainersModel::ContainersModel(std::shared_ptr<Settings> settings, QObject *parent) : m_settings(settings), QAbstractListModel(parent)
|
||||
ContainersModel::ContainersModel(std::shared_ptr<Settings> settings, QObject *parent)
|
||||
: m_settings(settings), QAbstractListModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -21,25 +22,25 @@ bool ContainersModel::setData(const QModelIndex &index, const QVariant &value, i
|
|||
DockerContainer container = ContainerProps::allContainers().at(index.row());
|
||||
|
||||
switch (role) {
|
||||
case NameRole:
|
||||
// return ContainerProps::containerHumanNames().value(container);
|
||||
case DescRole:
|
||||
// return ContainerProps::containerDescriptions().value(container);
|
||||
case ConfigRole: //todo save to model also
|
||||
m_settings->setContainerConfig(m_currentlyProcessedServerIndex,
|
||||
container,
|
||||
value.toJsonObject());
|
||||
case ServiceTypeRole:
|
||||
// return ContainerProps::containerService(container);
|
||||
case DockerContainerRole:
|
||||
// return container;
|
||||
case IsInstalledRole:
|
||||
// return m_settings->containers(m_currentlyProcessedServerIndex).contains(container);
|
||||
case IsDefaultRole: {
|
||||
m_settings->setDefaultContainer(m_currentlyProcessedServerIndex, container);
|
||||
m_defaultContainerIndex = container;
|
||||
emit defaultContainerChanged();
|
||||
}
|
||||
case NameRole:
|
||||
// return ContainerProps::containerHumanNames().value(container);
|
||||
case DescRole:
|
||||
// return ContainerProps::containerDescriptions().value(container);
|
||||
case ConfigRole: {
|
||||
m_settings->setContainerConfig(m_currentlyProcessedServerIndex, container, value.toJsonObject());
|
||||
m_containers = m_settings->containers(m_currentlyProcessedServerIndex);
|
||||
}
|
||||
case ServiceTypeRole:
|
||||
// return ContainerProps::containerService(container);
|
||||
case DockerContainerRole:
|
||||
// return container;
|
||||
case IsInstalledRole:
|
||||
// return m_settings->containers(m_currentlyProcessedServerIndex).contains(container);
|
||||
case IsDefaultRole: {
|
||||
m_settings->setDefaultContainer(m_currentlyProcessedServerIndex, container);
|
||||
m_defaultContainerIndex = container;
|
||||
emit defaultContainerChanged();
|
||||
}
|
||||
}
|
||||
|
||||
emit dataChanged(index, index);
|
||||
|
|
@ -48,40 +49,30 @@ bool ContainersModel::setData(const QModelIndex &index, const QVariant &value, i
|
|||
|
||||
QVariant ContainersModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0
|
||||
|| index.row() >= ContainerProps::allContainers().size()) {
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= ContainerProps::allContainers().size()) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
DockerContainer container = ContainerProps::allContainers().at(index.row());
|
||||
|
||||
switch (role) {
|
||||
case NameRole:
|
||||
return ContainerProps::containerHumanNames().value(container);
|
||||
case DescRole:
|
||||
return ContainerProps::containerDescriptions().value(container);
|
||||
case ConfigRole: {
|
||||
if (container == DockerContainer::None) return QJsonObject();
|
||||
return m_containers.value(container);
|
||||
case NameRole: return ContainerProps::containerHumanNames().value(container);
|
||||
case DescRole: return ContainerProps::containerDescriptions().value(container);
|
||||
case ConfigRole: {
|
||||
if (container == DockerContainer::None) {
|
||||
return QJsonObject();
|
||||
}
|
||||
case ServiceTypeRole:
|
||||
return ContainerProps::containerService(container);
|
||||
case DockerContainerRole:
|
||||
return container;
|
||||
case IsEasySetupContainerRole:
|
||||
return ContainerProps::isEasySetupContainer(container);
|
||||
case EasySetupHeaderRole:
|
||||
return ContainerProps::easySetupHeader(container);
|
||||
case EasySetupDescriptionRole:
|
||||
return ContainerProps::easySetupDescription(container);
|
||||
case IsInstalledRole:
|
||||
return m_containers.contains(container);
|
||||
case IsCurrentlyProcessedRole:
|
||||
return container == static_cast<DockerContainer>(m_currentlyProcessedContainerIndex);
|
||||
case IsDefaultRole:
|
||||
return container == m_defaultContainerIndex;
|
||||
case IsSupportedRole:
|
||||
return ContainerProps::isSupportedByCurrentPlatform(container);
|
||||
return m_containers.value(container);
|
||||
}
|
||||
case ServiceTypeRole: return ContainerProps::containerService(container);
|
||||
case DockerContainerRole: return container;
|
||||
case IsEasySetupContainerRole: return ContainerProps::isEasySetupContainer(container);
|
||||
case EasySetupHeaderRole: return ContainerProps::easySetupHeader(container);
|
||||
case EasySetupDescriptionRole: return ContainerProps::easySetupDescription(container);
|
||||
case IsInstalledRole: return m_containers.contains(container);
|
||||
case IsCurrentlyProcessedRole: return container == static_cast<DockerContainer>(m_currentlyProcessedContainerIndex);
|
||||
case IsDefaultRole: return container == m_defaultContainerIndex;
|
||||
case IsSupportedRole: return ContainerProps::isSupportedByCurrentPlatform(container);
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
|
|
@ -130,7 +121,7 @@ void ContainersModel::removeAllContainers()
|
|||
endResetModel();
|
||||
}
|
||||
|
||||
//todo process errors
|
||||
// todo process errors
|
||||
}
|
||||
|
||||
void ContainersModel::clearCachedProfiles()
|
||||
|
|
@ -141,7 +132,8 @@ void ContainersModel::clearCachedProfiles()
|
|||
}
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> ContainersModel::roleNames() const {
|
||||
QHash<int, QByteArray> ContainersModel::roleNames() const
|
||||
{
|
||||
QHash<int, QByteArray> roles;
|
||||
roles[NameRole] = "name";
|
||||
roles[DescRole] = "description";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "servers_model.h"
|
||||
|
||||
ServersModel::ServersModel(std::shared_ptr<Settings> settings, QObject *parent) : m_settings(settings), QAbstractListModel(parent)
|
||||
ServersModel::ServersModel(std::shared_ptr<Settings> settings, QObject *parent)
|
||||
: m_settings(settings), QAbstractListModel(parent)
|
||||
{
|
||||
m_servers = m_settings->serversArray();
|
||||
m_defaultServerIndex = m_settings->defaultServerIndex();
|
||||
|
|
@ -14,8 +15,7 @@ int ServersModel::rowCount(const QModelIndex &parent) const
|
|||
|
||||
bool ServersModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (!index.isValid() || index.row() < 0
|
||||
|| index.row() >= static_cast<int>(m_servers.size())) {
|
||||
if (!index.isValid() || index.row() < 0 || index.row() >= static_cast<int>(m_servers.size())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -29,8 +29,7 @@ bool ServersModel::setData(const QModelIndex &index, const QVariant &value, int
|
|||
break;
|
||||
}
|
||||
case IsDefaultRole: {
|
||||
m_settings->setDefaultServer(index.row());
|
||||
m_defaultServerIndex = m_settings->defaultServerIndex();
|
||||
setDefaultServerIndex(index.row());
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
|
@ -58,16 +57,11 @@ QVariant ServersModel::data(const QModelIndex &index, int role) const
|
|||
}
|
||||
return description;
|
||||
}
|
||||
case HostNameRole:
|
||||
return server.value(config_key::hostName).toString();
|
||||
case CredentialsRole:
|
||||
return QVariant::fromValue(m_settings->serverCredentials(index.row()));
|
||||
case CredentialsLoginRole:
|
||||
return m_settings->serverCredentials(index.row()).userName;
|
||||
case IsDefaultRole:
|
||||
return index.row() == m_defaultServerIndex;
|
||||
case IsCurrentlyProcessedRole:
|
||||
return index.row() == m_currenlyProcessedServerIndex;
|
||||
case HostNameRole: return server.value(config_key::hostName).toString();
|
||||
case CredentialsRole: return QVariant::fromValue(m_settings->serverCredentials(index.row()));
|
||||
case CredentialsLoginRole: return m_settings->serverCredentials(index.row()).userName;
|
||||
case IsDefaultRole: return index.row() == m_defaultServerIndex;
|
||||
case IsCurrentlyProcessedRole: return index.row() == m_currenlyProcessedServerIndex;
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
|
|
@ -92,6 +86,7 @@ const int ServersModel::getServersCount()
|
|||
void ServersModel::setCurrentlyProcessedServerIndex(int index)
|
||||
{
|
||||
m_currenlyProcessedServerIndex = index;
|
||||
emit currentlyProcessedServerIndexChanged();
|
||||
}
|
||||
|
||||
int ServersModel::getCurrentlyProcessedServerIndex()
|
||||
|
|
@ -104,6 +99,12 @@ bool ServersModel::isDefaultServerCurrentlyProcessed()
|
|||
return m_defaultServerIndex == m_currenlyProcessedServerIndex;
|
||||
}
|
||||
|
||||
bool ServersModel::isCurrentlyProcessedServerHasWriteAccess()
|
||||
{
|
||||
auto credentials = m_settings->serverCredentials(m_currenlyProcessedServerIndex);
|
||||
return (!credentials.userName.isEmpty() && !credentials.secretData.isEmpty());
|
||||
}
|
||||
|
||||
void ServersModel::addServer(const QJsonObject &server)
|
||||
{
|
||||
beginResetModel();
|
||||
|
|
@ -119,18 +120,19 @@ void ServersModel::removeServer()
|
|||
m_servers = m_settings->serversArray();
|
||||
|
||||
if (m_settings->defaultServerIndex() == m_currenlyProcessedServerIndex) {
|
||||
m_settings->setDefaultServer(0);
|
||||
setDefaultServerIndex(0);
|
||||
} else if (m_settings->defaultServerIndex() > m_currenlyProcessedServerIndex) {
|
||||
m_settings->setDefaultServer(m_settings->defaultServerIndex() - 1);
|
||||
setDefaultServerIndex(m_settings->defaultServerIndex() - 1);
|
||||
}
|
||||
|
||||
if (m_settings->serversCount() == 0) {
|
||||
m_settings->setDefaultServer(-1);
|
||||
setDefaultServerIndex(-1);
|
||||
}
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> ServersModel::roleNames() const {
|
||||
QHash<int, QByteArray> ServersModel::roleNames() const
|
||||
{
|
||||
QHash<int, QByteArray> roles;
|
||||
roles[NameRole] = "name";
|
||||
roles[HostNameRole] = "hostName";
|
||||
|
|
@ -140,3 +142,9 @@ QHash<int, QByteArray> ServersModel::roleNames() const {
|
|||
roles[IsCurrentlyProcessedRole] = "isCurrentlyProcessed";
|
||||
return roles;
|
||||
}
|
||||
|
||||
void ServersModel::setDefaultServerIndex(const int index)
|
||||
{
|
||||
m_settings->setDefaultServer(index);
|
||||
m_defaultServerIndex = m_settings->defaultServerIndex();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@
|
|||
|
||||
#include "settings.h"
|
||||
|
||||
struct ServerModelContent {
|
||||
struct ServerModelContent
|
||||
{
|
||||
QString desc;
|
||||
QString address;
|
||||
bool isDefault;
|
||||
|
|
@ -15,7 +16,7 @@ class ServersModel : public QAbstractListModel
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum ServersModelRoles {
|
||||
enum Roles {
|
||||
NameRole = Qt::UserRole + 1,
|
||||
HostNameRole,
|
||||
CredentialsRole,
|
||||
|
|
@ -35,6 +36,7 @@ public:
|
|||
public slots:
|
||||
const int getDefaultServerIndex();
|
||||
bool isDefaultServerCurrentlyProcessed();
|
||||
bool isCurrentlyProcessedServerHasWriteAccess();
|
||||
|
||||
const int getServersCount();
|
||||
|
||||
|
|
@ -47,7 +49,12 @@ public slots:
|
|||
protected:
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
signals:
|
||||
void currentlyProcessedServerIndexChanged();
|
||||
|
||||
private:
|
||||
void setDefaultServerIndex(const int index);
|
||||
|
||||
QJsonArray m_servers;
|
||||
|
||||
std::shared_ptr<Settings> m_settings;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue