mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 11:05:33 +08:00
Replace INetwork::CConnectionStatus with proper value object
This commit is contained in:
32
src/blackmisc/network/connectionstatus.cpp
Normal file
32
src/blackmisc/network/connectionstatus.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
/* Copyright (C) 2019
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
||||
* or distributed except according to the terms contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackmisc/network/connectionstatus.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Network
|
||||
{
|
||||
QString CConnectionStatus::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
|
||||
switch (m_connectionStatus)
|
||||
{
|
||||
case Connected: return QStringLiteral("Connected");
|
||||
case Connecting: return QStringLiteral("Connecting");
|
||||
case Disconnecting: return QStringLiteral("Disconnecting");
|
||||
case Disconnected: return QStringLiteral("Disconnected");
|
||||
}
|
||||
|
||||
Q_UNREACHABLE();
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
70
src/blackmisc/network/connectionstatus.h
Normal file
70
src/blackmisc/network/connectionstatus.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/* Copyright (C) 2019
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
||||
* or distributed except according to the terms contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_NETWORK_CONNECTIONSTATUS_H
|
||||
#define BLACKMISC_NETWORK_CONNECTIONSTATUS_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Network
|
||||
{
|
||||
//! Value object encapsulating information about a connection status
|
||||
class BLACKMISC_EXPORT CConnectionStatus : public CValueObject<CConnectionStatus>
|
||||
{
|
||||
public:
|
||||
//! Connection Status
|
||||
enum ConnectionStatus
|
||||
{
|
||||
Connected,
|
||||
Connecting,
|
||||
Disconnecting,
|
||||
Disconnected
|
||||
};
|
||||
|
||||
//! Default constructor.
|
||||
CConnectionStatus() = default;
|
||||
|
||||
//! Constructor
|
||||
CConnectionStatus(ConnectionStatus status) : m_connectionStatus(status) {}
|
||||
|
||||
bool isConnected() const { return m_connectionStatus == Connected; }
|
||||
|
||||
bool isConnecting() const { return m_connectionStatus == Connecting; }
|
||||
|
||||
bool isDisconnecting() const { return m_connectionStatus == Disconnecting; }
|
||||
|
||||
bool isDisconnected() const { return m_connectionStatus == Disconnected; }
|
||||
|
||||
//! Get status
|
||||
ConnectionStatus getConnectionStatus() const { return m_connectionStatus; }
|
||||
|
||||
//! Set status
|
||||
void setConnectionStatus(ConnectionStatus status) { m_connectionStatus = status; }
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
private:
|
||||
ConnectionStatus m_connectionStatus = Disconnected;
|
||||
|
||||
BLACK_METACLASS(
|
||||
CConnectionStatus,
|
||||
BLACK_METAMEMBER(connectionStatus)
|
||||
);
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Network::CConnectionStatus)
|
||||
|
||||
#endif // guard
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "blackmisc/network/authenticateduser.h"
|
||||
#include "blackmisc/network/client.h"
|
||||
#include "blackmisc/network/clientlist.h"
|
||||
#include "blackmisc/network/connectionstatus.h"
|
||||
#include "blackmisc/network/ecosystem.h"
|
||||
#include "blackmisc/network/ecosystemlist.h"
|
||||
#include "blackmisc/network/entityflags.h"
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace BlackMisc
|
||||
void registerMetadata()
|
||||
{
|
||||
CAuthenticatedUser::registerMetadata();
|
||||
CConnectionStatus::registerMetadata();
|
||||
CClient::registerMetadata();
|
||||
qDBusRegisterMetaType<CClient::Capability>();
|
||||
qRegisterMetaTypeStreamOperators<CClient::Capability>();
|
||||
|
||||
Reference in New Issue
Block a user