|
|
|
@ -15,7 +15,7 @@ |
|
|
|
|
#include <QFile> |
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
|
QJsonObject createJsonObject(const QString& name, const QString& address, const QString& password, bool isSsl) |
|
|
|
|
QJsonObject createJsonObject(const QString& name, const QString& address, const QString& password, const QString& sasl, bool isSsl) |
|
|
|
|
{ |
|
|
|
|
namespace Key = ServerJsonKey; |
|
|
|
|
|
|
|
|
@ -36,6 +36,9 @@ QJsonObject createJsonObject(const QString& name, const QString& address, const |
|
|
|
|
obj[Key::SSL] = isSsl; |
|
|
|
|
obj[Key::Password] = password; |
|
|
|
|
|
|
|
|
|
if (!sasl.isEmpty()) |
|
|
|
|
obj[Key::SASL] = sasl; |
|
|
|
|
|
|
|
|
|
return obj; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -55,16 +58,16 @@ bool ServerModel::saveToFile() |
|
|
|
|
if (item.isNetwork()) { |
|
|
|
|
QJsonArray networkServers; |
|
|
|
|
for (auto& child : item.children()) { |
|
|
|
|
QJsonObject server{ createJsonObject(child.name(), child.address(), child.password(), child.ssl()) }; |
|
|
|
|
QJsonObject server{ createJsonObject(child.name(), child.address(), child.password(), "", child.ssl()) }; |
|
|
|
|
networkServers << server; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QJsonObject network{ createJsonObject(item.name(), item.address(), item.password(), item.ssl()) }; |
|
|
|
|
QJsonObject network{ createJsonObject(item.name(), item.address(), item.password(), item.sasl(), item.ssl()) }; |
|
|
|
|
network[Key::Servers] = networkServers; |
|
|
|
|
networks << network; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
QJsonObject server{ createJsonObject(item.name(), item.address(), item.password(), item.ssl()) }; |
|
|
|
|
QJsonObject server{ createJsonObject(item.name(), item.address(), item.password(), item.sasl(), item.ssl()) }; |
|
|
|
|
servers << server; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -151,6 +154,7 @@ QVariant ServerModel::headerData(int section, Qt::Orientation orientation, int r |
|
|
|
|
tr("Name"), |
|
|
|
|
tr("Address"), |
|
|
|
|
"", |
|
|
|
|
"", |
|
|
|
|
"" |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -230,7 +234,7 @@ QModelIndex ServerModel::parent(const QModelIndex& index) const |
|
|
|
|
return createIndex(parentItem->row(), 0, parentItem); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ServerModel::addServer(const QString& name, const QString& address, const QString& password, bool isSsl, int networkIdx) |
|
|
|
|
void ServerModel::addServer(const QString& name, const QString& address, const QString& password, const QString& sasl, bool isSsl, int networkIdx) |
|
|
|
|
{ |
|
|
|
|
QList<ServerItem>* items{}; |
|
|
|
|
ServerItem* parentNetworkItem{}; |
|
|
|
@ -258,14 +262,15 @@ void ServerModel::addServer(const QString& name, const QString& address, const Q |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const auto obj{ createJsonObject(name, address, password, isSsl) }; |
|
|
|
|
const auto obj{ createJsonObject(name, address, password, sasl, isSsl) }; |
|
|
|
|
beginInsertRows(modelIdx, pos, pos); |
|
|
|
|
items->insert(pos, ServerItem(obj, pos, parentNetworkItem, false)); |
|
|
|
|
endInsertRows(); |
|
|
|
|
|
|
|
|
|
emit newEntry( |
|
|
|
|
createIndex(pos, 2, &((*items)[pos])), // SSL
|
|
|
|
|
createIndex(pos, 3, &((*items)[pos])) // Password
|
|
|
|
|
createIndex(pos, 3, &((*items)[pos])), // Password
|
|
|
|
|
createIndex(pos, 4, &((*items)[pos])) // SASL
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -288,9 +293,9 @@ void ServerModel::addServer(const QString& name, const QString& address, const Q |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ServerModel::addNetwork(const QString& name, const QString& address, const QString& password, bool isSsl) |
|
|
|
|
void ServerModel::addNetwork(const QString& name, const QString& address, const QString& password, const QString& sasl, bool isSsl) |
|
|
|
|
{ |
|
|
|
|
const auto obj{ createJsonObject(name, address, password, isSsl) }; |
|
|
|
|
const auto obj{ createJsonObject(name, address, password, sasl, isSsl) }; |
|
|
|
|
|
|
|
|
|
const auto idx{ m_items.count() }; |
|
|
|
|
beginInsertRows(QModelIndex{}, idx, idx); |
|
|
|
@ -299,7 +304,8 @@ void ServerModel::addNetwork(const QString& name, const QString& address, const |
|
|
|
|
|
|
|
|
|
emit newEntry( |
|
|
|
|
createIndex(idx, 2, &(m_items.back())), // SSL
|
|
|
|
|
createIndex(idx, 3, &(m_items.back())) // Password
|
|
|
|
|
createIndex(idx, 3, &(m_items.back())), // Password
|
|
|
|
|
createIndex(idx, 4, &(m_items.back())) // SASL
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -342,6 +348,7 @@ QList<QModelIndex> ServerModel::getEditorColumns() |
|
|
|
|
for (auto& topItem : m_items) { |
|
|
|
|
indexList << createIndex(topItem.row(), 2, &topItem); |
|
|
|
|
indexList << createIndex(topItem.row(), 3, &topItem); |
|
|
|
|
indexList << createIndex(topItem.row(), 4, &topItem); |
|
|
|
|
|
|
|
|
|
if (topItem.isNetwork()) { |
|
|
|
|
auto& items = topItem.children(); |
|
|
|
|