6#include <QCoreApplication>
8#include <QStringBuilder>
30const QString &cachedEscapedApplicationName()
37const QString &cachedLocalHostName()
45 UuidStringLen =
sizeof(
"00000000-0000-0000-0000-000000000000")
51 return machineUniqueId;
56 CIdentifier::CIdentifier(
const QString &name)
57 : m_name(name.trimmed()), m_machineIdBase64(cachedMachineUniqueId().toBase64(
QByteArray::OmitTrailingEquals)),
58 m_machineName(cachedLocalHostName()), m_processName(cachedEscapedApplicationName()),
62 CIdentifier::CIdentifier(
const QString &name,
QObject *
object) : CIdentifier(name)
73 const QString &processName, qint64 processId)
74 : m_name(name), m_machineIdBase64(machineId), m_machineName(machineName), m_processName(processName),
75 m_processId(processId)
80 static const CIdentifier id(
"");
86 static const CIdentifier id(
"",
"",
"",
"", 0);
92 static const CIdentifier id(
94 "fake machine",
"fake process", 0);
103 baseData.
append(
reinterpret_cast<const char *
>(&m_processId),
sizeof(m_processId));
112 if (m_name.endsWith(name))
123 m_name = m_name.left(index);
125 m_name += QStringLiteral(
":") + name;
146 path +=
'/' % toDBusPathElement(m_machineName) %
"__" % toDBusPathElement(m_machineIdBase64);
147 path +=
'/' % toDBusPathElement(m_processName) %
"__" %
QString::number(m_processId);
149 const QString name = toDBusPath(m_name);
165 CIdentifier result(fromDBusPath(name));
166 result.m_machineIdBase64 = fromDBusPathElement(machine.
section(
"__", 1, 1));
167 result.m_machineName = fromDBusPathElement(machine.
section(
"__", 0, 0));
168 result.m_processId = process.
section(
"__", 1, 1).
toInt();
169 result.m_processName = fromDBusPathElement(process.
section(
"__", 0, 0));
180 return !m_machineIdBase64.isEmpty() && m_machineIdBase64 == other.m_machineIdBase64;
201 return cachedEscapedApplicationName() == toDBusPathElement(
getProcessName());
211 m_machineName = cachedLocalHostName();
223 const QString s = m_name % u
' ' % m_machineIdBase64 % u
' ' % m_machineName % u
' ' %
264 case IndexMachineIdBase64:
return m_machineIdBase64.compare(compareValue.m_machineIdBase64);
265 case IndexMachineName:
return m_machineName.compare(compareValue.m_machineName,
Qt::CaseInsensitive);
267 case IndexProcessId:
return Compare::compare(m_processId, compareValue.m_processId);
268 case IndexProcessName:
return m_processName.compare(compareValue.m_processName,
Qt::CaseInsensitive);
269 case IndexIsFromLocalMachine:
271 case IndexIsFromSameProcess:
273 case IndexIsFromSameProcessName:
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
bool hasApplicationProcessName() const
Check if originating from the same process name.
static const CIdentifier & anonymous()
Returns an anonymous identifier, which is a valid identifier without name.
bool hasSameMachineId(const CIdentifier &other) const
Check if other identifier is from the same machine id.
void appendName(const QString &name)
Set name or append name.
const QString & getProcessName() const
Get process name.
bool isNull() const
Null identifier (no name, ids etc).
const QString & getName() const
Name.
ColumnIndex
Properties by index.
bool isAnonymous() const
Check if it is anonymous identifier.
qint64 getProcessId() const
Get process id.
const QString & getMachineName() const
Machine name.
QUuid toUuid() const
Produces a UUID generated from the identifier.
QByteArray getMachineId() const
Get machine id.
bool hasApplicationProcessId() const
Check if originating from the same process id.
static CIdentifier fromDBusObjectPath(const QString &path, const QString &root={})
Reconstruct an identifier from a DBus object path.
static const CIdentifier & fake()
Returns a fake identifier.
bool hasSameMachineName(const CIdentifier &other) const
Check if the other identifier has the same machine name.
void updateToCurrentProcess()
Update to current process.
bool isFromLocalMachine() const
Check if originating from the same local machine.
void updateToCurrentMachine()
Update to current machine.
void linkWithQObjectName(QObject *object)
Reflect changes of QObject::
bool hasSameMachineNameOrId(const CIdentifier &other) const
Same machine or id?
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
static const CIdentifier & null()
Null (empty) identifier.
QString toUuidString() const
UUID string.
QString convertToQString(bool i18n=false) const
Cast as QString.
QString toDBusObjectPath(const QString &root={}) const
Produces a DBus object path from the identifier.
int comparePropertyByIndex(CPropertyIndexRef index, const CIdentifier &compareValue) const
Compare for index.
Non-owning reference to a CPropertyIndex with a subset of its features.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
int comparePropertyByIndex(CPropertyIndexRef index, const Derived &compareValue) const
Compare for index.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
int compare(T a, T b)
Compare arithmetic values.
Free functions in swift::misc.
SWIFT_MISC_EXPORT QByteArray utfToPercentEncoding(const QString &s, const QByteArray &allow={}, char percent='%')
Extended percent encoding supporting UTF-16.
SWIFT_MISC_EXPORT QString utfFromPercentEncoding(const QByteArray &ba, char percent='%')
Reverse utfFromPercentEncoding.
QByteArray & append(QByteArrayView data)
int compare(QByteArrayView bv, Qt::CaseSensitivity cs) const const
QByteArray::FromBase64Result fromBase64Encoding(QByteArray &&base64, QByteArray::Base64Options options)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void objectNameChanged(const QString &objectName)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
qsizetype lastIndexOf(QChar ch, Qt::CaseSensitivity cs) const const
qsizetype length() const const
QString mid(qsizetype position, qsizetype n) &&
QString number(double n, char format, int precision)
QString section(QChar sep, qsizetype start, qsizetype end, QString::SectionFlags flags) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
int toInt(bool *ok, int base) const const
QByteArray toLatin1() const const
QByteArray machineUniqueId()
QUuid createUuidV5(QUuid ns, QByteArrayView baseData)
QString toString(QUuid::StringFormat mode) const const
QVariant fromValue(T &&value)
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.