mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 13:36:48 +08:00
committed by
Mathew Sutcliffe
parent
fe1a570c39
commit
4747b3b484
128
src/blackmisc/setnetwork.cpp
Normal file
128
src/blackmisc/setnetwork.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
#include "setnetwork.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include "blackmisc/statusmessages.h"
|
||||
#include "blackmisc/settingutilities.h"
|
||||
|
||||
using namespace BlackMisc::Network;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
CSettingsNetwork::CSettingsNetwork()
|
||||
{
|
||||
// settings
|
||||
}
|
||||
|
||||
bool CSettingsNetwork::setCurrentNetworkServer(const CServer ¤tServer)
|
||||
{
|
||||
if (this->m_trafficNetworkServerCurrent == currentServer) return false;
|
||||
m_trafficNetworkServerCurrent = currentServer;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert to string
|
||||
*/
|
||||
QString CSettingsNetwork::convertToQString(bool i18n) const
|
||||
{
|
||||
QString s("Traffic servers:");
|
||||
s.append(" ").append(this->m_trafficNetworkServers.toQString(i18n));
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
* Marshall to DBus
|
||||
*/
|
||||
void CSettingsNetwork::marshallToDbus(QDBusArgument &argument) const
|
||||
{
|
||||
argument << this->m_trafficNetworkServerCurrent;
|
||||
argument << this->m_trafficNetworkServers;
|
||||
}
|
||||
|
||||
/*
|
||||
* Unmarshall from DBus
|
||||
*/
|
||||
void CSettingsNetwork::unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
argument >> this->m_trafficNetworkServerCurrent;
|
||||
argument >> this->m_trafficNetworkServers;
|
||||
}
|
||||
|
||||
/*
|
||||
* Equal?
|
||||
*/
|
||||
bool CSettingsNetwork::operator ==(const CSettingsNetwork &other) const
|
||||
{
|
||||
if (this == &other) return true;
|
||||
return this->getValueHash() == other.getValueHash();
|
||||
}
|
||||
|
||||
/*
|
||||
* Unequal?
|
||||
*/
|
||||
bool CSettingsNetwork::operator !=(const CSettingsNetwork &other) const
|
||||
{
|
||||
return !((*this) == other);
|
||||
}
|
||||
|
||||
/*
|
||||
* Hash
|
||||
*/
|
||||
uint CSettingsNetwork::getValueHash() const
|
||||
{
|
||||
QList<uint> hashs;
|
||||
hashs << qHash(this->m_trafficNetworkServers);
|
||||
return BlackMisc::calculateHash(hashs, "CSettingsNetwork");
|
||||
}
|
||||
|
||||
/*
|
||||
* Register metadata
|
||||
*/
|
||||
void CSettingsNetwork::registerMetadata()
|
||||
{
|
||||
qRegisterMetaType<CSettingsNetwork>();
|
||||
qDBusRegisterMetaType<CSettingsNetwork>();
|
||||
}
|
||||
|
||||
/*
|
||||
* Value
|
||||
*/
|
||||
BlackMisc::CStatusMessages CSettingsNetwork::value(const QString &path, const QString &command, const QVariant &value, bool &changedFlag)
|
||||
{
|
||||
// TODO: This needs to be refactored to a smarter way to delegate commands
|
||||
changedFlag = false;
|
||||
CStatusMessages msgs;
|
||||
if (path == CSettingsNetwork::PathTrafficServer())
|
||||
{
|
||||
const CServer server = value.value<CServer>();
|
||||
if (command == CSettingsNetwork::CmdSetCurrentServer())
|
||||
{
|
||||
changedFlag = this->setCurrentNetworkServer(server);
|
||||
if (changedFlag)
|
||||
{
|
||||
// make sure the server is correct int the list too
|
||||
this->m_trafficNetworkServers.replaceOrAdd(&CServer::getName, server.getName(), server);
|
||||
}
|
||||
}
|
||||
else if (command == CSettingUtilities::CmdUpdate())
|
||||
{
|
||||
this->m_trafficNetworkServers.replaceOrAdd(&CServer::getName, server.getName(), server);
|
||||
changedFlag = true;
|
||||
}
|
||||
else if (command == CSettingUtilities::CmdRemove())
|
||||
{
|
||||
changedFlag = this->m_trafficNetworkServers.contains(&CServer::getName, server.getName());
|
||||
this->m_trafficNetworkServers.removeIf(&CServer::getName, server.getName());
|
||||
}
|
||||
msgs.append(CStatusMessage::getInfoMessage("set current server"));
|
||||
return msgs;
|
||||
}
|
||||
return CSettingUtilities::wrongPathMessages(path);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user