Files
amnezia-client/client/ui/pages_logic/ServerListLogic.cpp
T

50 lines
1.4 KiB
C++
Raw Normal View History

2021-09-03 20:17:13 +03:00
#include "ServerListLogic.h"
2021-09-06 12:39:46 +03:00
#include "vpnconnection.h"
2021-09-09 20:15:44 +03:00
#include "../models/servers_model.h"
2021-09-03 22:15:05 +03:00
#include "../uilogic.h"
2021-09-03 20:17:13 +03:00
2021-09-07 21:01:56 +03:00
ServerListLogic::ServerListLogic(UiLogic *logic, QObject *parent):
PageLogicBase(logic, parent),
2021-09-03 22:15:05 +03:00
m_serverListModel{new ServersModel(this)}
2021-09-03 20:17:13 +03:00
{
}
2021-09-03 22:15:05 +03:00
void ServerListLogic::onServerListPushbuttonDefaultClicked(int index)
{
2022-08-25 12:47:02 +03:00
m_settings->setDefaultServer(index);
2021-11-17 15:01:48 +03:00
uiLogic()->onUpdateAllPages();
2022-12-12 13:28:03 +01:00
emit currServerIdxChanged();
2021-09-03 22:15:05 +03:00
}
void ServerListLogic::onServerListPushbuttonSettingsClicked(int index)
{
2023-02-20 09:46:50 +03:00
uiLogic()->m_selectedServerIndex = index;
2021-09-07 21:01:56 +03:00
uiLogic()->goToPage(Page::ServerSettings);
2021-09-03 22:15:05 +03:00
}
2022-12-12 13:28:03 +01:00
int ServerListLogic::currServerIdx() const
{
return m_settings->defaultServerIndex();
}
void ServerListLogic::onUpdatePage()
2021-09-03 22:15:05 +03:00
{
2022-08-25 12:47:02 +03:00
const QJsonArray &servers = m_settings->serversArray();
int defaultServer = m_settings->defaultServerIndex();
2021-09-03 22:15:05 +03:00
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);
}
2021-09-08 13:52:36 +03:00
qobject_cast<ServersModel*>(m_serverListModel)->setContent(serverListContent);
2021-09-03 22:15:05 +03:00
}