refact 2
This commit is contained in:
parent
135b96a280
commit
84ca7e8879
11 changed files with 446 additions and 425 deletions
|
@ -38,9 +38,7 @@
|
|||
#include "vpnconnection.h"
|
||||
#include <functional>
|
||||
|
||||
#if defined Q_OS_MAC || defined Q_OS_LINUX
|
||||
#include "ui/macos_util.h"
|
||||
#endif
|
||||
#include "../uilogic.h"
|
||||
|
||||
using namespace amnezia;
|
||||
using namespace PageEnumNS;
|
||||
|
@ -48,7 +46,44 @@ using namespace PageEnumNS;
|
|||
|
||||
ServerListLogic::ServerListLogic(UiLogic *uiLogic, QObject *parent):
|
||||
QObject(parent),
|
||||
m_uiLogic(uiLogic)
|
||||
m_uiLogic(uiLogic),
|
||||
m_serverListModel{new ServersModel(this)}
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QObject* ServerListLogic::getServerListModel() const
|
||||
{
|
||||
return m_serverListModel;
|
||||
}
|
||||
|
||||
void ServerListLogic::onServerListPushbuttonDefaultClicked(int index)
|
||||
{
|
||||
m_settings.setDefaultServer(index);
|
||||
updateServersListPage();
|
||||
}
|
||||
|
||||
void ServerListLogic::onServerListPushbuttonSettingsClicked(int index)
|
||||
{
|
||||
m_uiLogic->selectedServerIndex = index;
|
||||
m_uiLogic->goToPage(Page::ServerSettings);
|
||||
}
|
||||
|
||||
void ServerListLogic::updateServersListPage()
|
||||
{
|
||||
const QJsonArray &servers = m_settings.serversArray();
|
||||
int defaultServer = m_settings.defaultServerIndex();
|
||||
std::vector<ServerModelContent> serverListContent;
|
||||
for(int i = 0; i < servers.size(); i++) {
|
||||
ServerModelContent c;
|
||||
auto server = servers.at(i).toObject();
|
||||
c.desc = server.value(config_key::description).toString();
|
||||
c.address = server.value(config_key::hostName).toString();
|
||||
if (c.desc.isEmpty()) {
|
||||
c.desc = c.address;
|
||||
}
|
||||
c.isDefault = (i == defaultServer);
|
||||
serverListContent.push_back(c);
|
||||
}
|
||||
m_serverListModel->setContent(serverListContent);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue