diff --git a/src/blackcore/context/contextapplication.cpp b/src/blackcore/context/contextapplication.cpp index 25789ec4c..17173c7d6 100644 --- a/src/blackcore/context/contextapplication.cpp +++ b/src/blackcore/context/contextapplication.cpp @@ -92,7 +92,7 @@ namespace BlackCore s = connect(this, &IContextApplication::hotkeyActionsRegistered, [this](const QStringList & actions, const CIdentifier & origin) { - if (origin.isFromSameProcess()) { return; } + if (origin.hasApplicationProcessId()) { return; } CInputManager::instance()->registerRemoteActions(actions); }); Q_ASSERT_X(s, Q_FUNC_INFO, "Connect hotkey actions failed"); diff --git a/src/blackcore/context/contextapplicationimpl.cpp b/src/blackcore/context/contextapplicationimpl.cpp index 158c9c64b..660206235 100644 --- a/src/blackcore/context/contextapplicationimpl.cpp +++ b/src/blackcore/context/contextapplicationimpl.cpp @@ -41,7 +41,7 @@ namespace BlackCore void CContextApplication::logMessage(const CStatusMessage &message, const CIdentifier &origin) { - if (!origin.isFromSameProcess()) + if (!origin.hasApplicationProcessId()) { CLogHandler::instance()->logRemoteMessage(message); } diff --git a/src/blackcore/context/contextapplicationproxy.cpp b/src/blackcore/context/contextapplicationproxy.cpp index 63af3c0f2..c347d9e85 100644 --- a/src/blackcore/context/contextapplicationproxy.cpp +++ b/src/blackcore/context/contextapplicationproxy.cpp @@ -32,7 +32,7 @@ namespace BlackCore connect(this, &IContextApplication::messageLogged, this, [](const CStatusMessage & message, const CIdentifier & origin) { - if (!origin.isFromSameProcess()) + if (!origin.hasApplicationProcessId()) { CLogHandler::instance()->logRemoteMessage(message); } diff --git a/src/blackgui/components/hotkeydialog.cpp b/src/blackgui/components/hotkeydialog.cpp index ecd6ad7c0..6281245bc 100644 --- a/src/blackgui/components/hotkeydialog.cpp +++ b/src/blackgui/components/hotkeydialog.cpp @@ -88,7 +88,7 @@ namespace BlackGui for (const auto &app : machineIdentifiersUnique) { ui->cb_Identifier->addItem(app.getMachineName(), QVariant::fromValue(app)); - if (m_actionHotkey.getApplicableMachine().isFromSameMachine(app)) { index = ui->cb_Identifier->count() - 1; } + if (m_actionHotkey.getApplicableMachine().hasSameMachineName(app)) { index = ui->cb_Identifier->count() - 1; } } if (index < 0 && ui->cb_Identifier->count() > 0) diff --git a/src/blackmisc/identifier.cpp b/src/blackmisc/identifier.cpp index 9d277cae9..c346d642c 100644 --- a/src/blackmisc/identifier.cpp +++ b/src/blackmisc/identifier.cpp @@ -100,22 +100,27 @@ namespace BlackMisc return QByteArray::fromBase64(m_machineIdBase64.toLocal8Bit()); } + bool CIdentifier::hasSameMachineName(const CIdentifier &other) const + { + return !other.getMachineName().isEmpty() && other.getMachineName() == this->getMachineName(); + } + + bool CIdentifier::hasSameMachineId(const CIdentifier &other) const + { + return !m_machineIdBase64.isEmpty() && m_machineIdBase64 == other.m_machineIdBase64; + } + bool CIdentifier::isFromLocalMachine() const { return QDBusConnection::localMachineId() == getMachineId(); } - bool CIdentifier::isFromSameMachine(const CIdentifier &other) const - { - return getMachineIdBase64() == other.getMachineIdBase64(); - } - - bool CIdentifier::isFromSameProcess() const + bool CIdentifier::hasApplicationProcessId() const { return QCoreApplication::applicationPid() == getProcessId() && isFromLocalMachine(); } - bool CIdentifier::isFromSameProcessName() const + bool CIdentifier::hasApplicationProcessName() const { return QCoreApplication::applicationName() == getProcessName(); } @@ -157,8 +162,8 @@ namespace BlackMisc case IndexProcessId: return CVariant::fromValue(m_processId); case IndexProcessName: return CVariant::fromValue(m_processName); case IndexIsFromLocalMachine: return CVariant::fromValue(isFromLocalMachine()); - case IndexIsFromSameProcess: return CVariant::fromValue(isFromSameProcess()); - case IndexIsFromSameProcessName: return CVariant::fromValue(isFromSameProcessName()); + case IndexIsFromSameProcess: return CVariant::fromValue(hasApplicationProcessId()); + case IndexIsFromSameProcessName: return CVariant::fromValue(hasApplicationProcessName()); default: return CValueObject::propertyByIndex(index); } } diff --git a/src/blackmisc/identifier.h b/src/blackmisc/identifier.h index ec15e9118..60becf49e 100644 --- a/src/blackmisc/identifier.h +++ b/src/blackmisc/identifier.h @@ -77,7 +77,7 @@ namespace BlackMisc QString toUuidString() const; //! Name - QString getName() const { return m_name; } + const QString &getName() const { return m_name; } //! Has name bool hasName() const { return !m_name.isEmpty(); } @@ -95,29 +95,32 @@ namespace BlackMisc //! Get machine id QByteArray getMachineId() const; - //! Machine 64 base64 encoded - QString getMachineIdBase64() const { return m_machineIdBase64; } + //! Machine base64 encoded + const QString &getMachineIdBase64() const { return m_machineIdBase64; } //! Machine name - QString getMachineName() const { return m_machineName; } + const QString &getMachineName() const { return m_machineName; } + + //! Check if the other identifier has the same machine name + bool hasSameMachineName(const CIdentifier &other) const; + + //! Check if other identifier is from the same machine id + bool hasSameMachineId(const CIdentifier &other) const; //! Get process id qint64 getProcessId() const {return m_processId;} //! Get process name - QString getProcessName() const {return m_processName;} + const QString &getProcessName() const {return m_processName;} //! Check if originating from the same local machine bool isFromLocalMachine() const; - //! Check if other identifier is from the same machine - bool isFromSameMachine(const CIdentifier &other) const; - //! Check if originating from the same process id - bool isFromSameProcess() const; + bool hasApplicationProcessId() const; //! Check if originating from the same process name - bool isFromSameProcessName() const; + bool hasApplicationProcessName() const; //! Check if it is anonymous identifier bool isAnonymous() const; diff --git a/src/blackmisc/identifierlist.cpp b/src/blackmisc/identifierlist.cpp index b587ab230..4467d269d 100644 --- a/src/blackmisc/identifierlist.cpp +++ b/src/blackmisc/identifierlist.cpp @@ -33,7 +33,7 @@ namespace BlackMisc { bool contained = il.containsBy([ = ] (const CIdentifier &ident) { - return identifier.isFromSameMachine(ident); + return identifier.hasSameMachineName(ident); }); if (!contained) { il.push_back(identifier); } } diff --git a/src/blackmisc/valuecache.cpp b/src/blackmisc/valuecache.cpp index 782933eda..abbd905a7 100644 --- a/src/blackmisc/valuecache.cpp +++ b/src/blackmisc/valuecache.cpp @@ -304,7 +304,7 @@ namespace BlackMisc while (out != end && out.key() < in.key()) { ++out; } auto &element = getElement(in.key(), out); - if (originator.isFromSameProcess()) // round trip + if (originator.hasApplicationProcessId()) // round trip { element.m_pendingChanges--; Q_ASSERT(element.m_pendingChanges >= 0);