added output of notifications/errors after installation/import
This commit is contained in:
parent
0411792ca5
commit
1092abe776
39 changed files with 488 additions and 303 deletions
|
|
@ -83,6 +83,12 @@ QVariant ContainersModel::data(const QModelIndex &index, int role) const
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant ContainersModel::data(const int index, int role) const
|
||||
{
|
||||
QModelIndex modelIndex = this->index(index);
|
||||
return data(modelIndex, role);
|
||||
}
|
||||
|
||||
void ContainersModel::setCurrentlyProcessedServerIndex(const int index)
|
||||
{
|
||||
beginResetModel();
|
||||
|
|
@ -123,11 +129,12 @@ QJsonObject ContainersModel::getCurrentlyProcessedContainerConfig()
|
|||
return qvariant_cast<QJsonObject>(data(index(m_currentlyProcessedContainerIndex), ConfigRole));
|
||||
}
|
||||
|
||||
void ContainersModel::removeAllContainers()
|
||||
ErrorCode ContainersModel::removeAllContainers()
|
||||
{
|
||||
|
||||
ServerController serverController(m_settings);
|
||||
auto errorCode = serverController.removeAllContainers(m_settings->serverCredentials(m_currentlyProcessedServerIndex));
|
||||
ErrorCode errorCode =
|
||||
serverController.removeAllContainers(m_settings->serverCredentials(m_currentlyProcessedServerIndex));
|
||||
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
beginResetModel();
|
||||
|
|
@ -138,30 +145,32 @@ void ContainersModel::removeAllContainers()
|
|||
setData(index(DockerContainer::None, 0), true, IsDefaultRole);
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
// todo process errors
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
void ContainersModel::removeCurrentlyProcessedContainer()
|
||||
ErrorCode ContainersModel::removeCurrentlyProcessedContainer()
|
||||
{
|
||||
ServerController serverController(m_settings);
|
||||
auto credentials = m_settings->serverCredentials(m_currentlyProcessedServerIndex);
|
||||
auto dockerContainer = static_cast<DockerContainer>(m_currentlyProcessedContainerIndex);
|
||||
|
||||
ErrorCode e = serverController.removeContainer(credentials, dockerContainer);
|
||||
ErrorCode errorCode = serverController.removeContainer(credentials, dockerContainer);
|
||||
|
||||
beginResetModel(); // todo change to begin remove rows?
|
||||
m_settings->removeContainerConfig(m_currentlyProcessedServerIndex, dockerContainer);
|
||||
m_containers = m_settings->containers(m_currentlyProcessedServerIndex);
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
beginResetModel(); // todo change to begin remove rows?
|
||||
m_settings->removeContainerConfig(m_currentlyProcessedServerIndex, dockerContainer);
|
||||
m_containers = m_settings->containers(m_currentlyProcessedServerIndex);
|
||||
|
||||
if (m_defaultContainerIndex == m_currentlyProcessedContainerIndex) {
|
||||
if (m_containers.isEmpty()) {
|
||||
setData(index(DockerContainer::None, 0), true, IsDefaultRole);
|
||||
} else {
|
||||
setData(index(m_containers.begin().key(), 0), true, IsDefaultRole);
|
||||
if (m_defaultContainerIndex == m_currentlyProcessedContainerIndex) {
|
||||
if (m_containers.isEmpty()) {
|
||||
setData(index(DockerContainer::None, 0), true, IsDefaultRole);
|
||||
} else {
|
||||
setData(index(m_containers.begin().key(), 0), true, IsDefaultRole);
|
||||
}
|
||||
}
|
||||
endResetModel();
|
||||
}
|
||||
endResetModel();
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
void ContainersModel::clearCachedProfiles()
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ public:
|
|||
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
QVariant data(const int index, int role) const;
|
||||
|
||||
signals:
|
||||
void defaultContainerChanged();
|
||||
Q_PROPERTY(QString defaultContainerName READ getDefaultContainerName NOTIFY defaultContainerChanged)
|
||||
|
||||
public slots:
|
||||
DockerContainer getDefaultContainer();
|
||||
|
|
@ -52,8 +52,8 @@ public slots:
|
|||
QString getCurrentlyProcessedContainerName();
|
||||
QJsonObject getCurrentlyProcessedContainerConfig();
|
||||
|
||||
void removeAllContainers();
|
||||
void removeCurrentlyProcessedContainer();
|
||||
ErrorCode removeAllContainers();
|
||||
ErrorCode removeCurrentlyProcessedContainer();
|
||||
void clearCachedProfiles();
|
||||
|
||||
bool isAmneziaDnsContainerInstalled();
|
||||
|
|
@ -62,6 +62,9 @@ public slots:
|
|||
protected:
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
signals:
|
||||
void defaultContainerChanged();
|
||||
|
||||
private:
|
||||
QMap<DockerContainer, QJsonObject> m_containers;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ QHash<int, QByteArray> ProtocolsModel::roleNames() const
|
|||
|
||||
roles[ProtocolNameRole] = "protocolName";
|
||||
roles[ProtocolPageRole] = "protocolPage";
|
||||
roles[ProtocolIndexRole] = "protocolIndex";
|
||||
roles[RawConfigRole] = "rawConfig";
|
||||
|
||||
return roles;
|
||||
|
|
@ -35,6 +36,7 @@ QVariant ProtocolsModel::data(const QModelIndex &index, int role) const
|
|||
}
|
||||
case ProtocolPageRole:
|
||||
return static_cast<int>(protocolPage(ProtocolProps::protoFromString(m_content.keys().at(index.row()))));
|
||||
case ProtocolIndexRole: return ProtocolProps::protoFromString(m_content.keys().at(index.row()));
|
||||
case RawConfigRole: {
|
||||
auto protocolConfig = m_content.value(ContainerProps::containerTypeToString(m_container)).toObject();
|
||||
auto lastConfigJsonDoc =
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ public:
|
|||
enum Roles {
|
||||
ProtocolNameRole = Qt::UserRole + 1,
|
||||
ProtocolPageRole,
|
||||
ProtocolIndexRole,
|
||||
RawConfigRole
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -78,6 +78,15 @@ QVariant ServersModel::data(const int index, int role) const
|
|||
return data(modelIndex, role);
|
||||
}
|
||||
|
||||
void ServersModel::resetModel()
|
||||
{
|
||||
beginResetModel();
|
||||
m_servers = m_settings->serversArray();
|
||||
m_defaultServerIndex = m_settings->defaultServerIndex();
|
||||
m_currentlyProcessedServerIndex = m_defaultServerIndex;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void ServersModel::setDefaultServerIndex(const int index)
|
||||
{
|
||||
m_settings->setDefaultServer(index);
|
||||
|
|
@ -90,11 +99,31 @@ const int ServersModel::getDefaultServerIndex()
|
|||
return m_defaultServerIndex;
|
||||
}
|
||||
|
||||
const QString ServersModel::getDefaultServerName()
|
||||
{
|
||||
return qvariant_cast<QString>(data(m_defaultServerIndex, NameRole));
|
||||
}
|
||||
|
||||
const QString ServersModel::getDefaultServerHostName()
|
||||
{
|
||||
return qvariant_cast<QString>(data(m_defaultServerIndex, HostNameRole));
|
||||
}
|
||||
|
||||
const int ServersModel::getServersCount()
|
||||
{
|
||||
return m_servers.count();
|
||||
}
|
||||
|
||||
bool ServersModel::hasServerWithWriteAccess()
|
||||
{
|
||||
for (size_t i = 0; i < getServersCount(); i++) {
|
||||
if (qvariant_cast<bool>(data(i, HasWriteAccessRole))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ServersModel::setCurrentlyProcessedServerIndex(const int index)
|
||||
{
|
||||
m_currentlyProcessedServerIndex = index;
|
||||
|
|
@ -123,7 +152,7 @@ bool ServersModel::isCurrentlyProcessedServerHasWriteAccess()
|
|||
|
||||
bool ServersModel::isDefaultServerHasWriteAccess()
|
||||
{
|
||||
return qvariant_cast<bool>(data(m_currentlyProcessedServerIndex, HasWriteAccessRole));
|
||||
return qvariant_cast<bool>(data(m_defaultServerIndex, HasWriteAccessRole));
|
||||
}
|
||||
|
||||
void ServersModel::addServer(const QJsonObject &server)
|
||||
|
|
|
|||
|
|
@ -28,17 +28,24 @@ public:
|
|||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
QVariant data(const int index, int role = Qt::DisplayRole) const;
|
||||
|
||||
void resetModel();
|
||||
|
||||
Q_PROPERTY(int defaultIndex READ getDefaultServerIndex WRITE setDefaultServerIndex NOTIFY defaultServerIndexChanged)
|
||||
Q_PROPERTY(QString defaultServerName READ getDefaultServerName NOTIFY defaultServerIndexChanged)
|
||||
Q_PROPERTY(QString defaultServerHostName READ getDefaultServerHostName NOTIFY defaultServerIndexChanged)
|
||||
Q_PROPERTY(int currentlyProcessedIndex READ getCurrentlyProcessedServerIndex WRITE setCurrentlyProcessedServerIndex
|
||||
NOTIFY currentlyProcessedServerIndexChanged)
|
||||
|
||||
public slots:
|
||||
void setDefaultServerIndex(const int index);
|
||||
const int getDefaultServerIndex();
|
||||
const QString getDefaultServerName();
|
||||
const QString getDefaultServerHostName();
|
||||
bool isDefaultServerCurrentlyProcessed();
|
||||
|
||||
bool isCurrentlyProcessedServerHasWriteAccess();
|
||||
bool isDefaultServerHasWriteAccess();
|
||||
bool hasServerWithWriteAccess();
|
||||
|
||||
const int getServersCount();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue