From f970e7cfaa27e30194027682df636ad4ffe7c2fa Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Wed, 20 Aug 2014 01:28:38 +0200 Subject: [PATCH] refs #318 Value class CEventHotkeyFunction Event which will be transferred to another process and trigger a hotkey function remotely. --- src/blackmisc/blackmiscfreefunctions.cpp | 11 +++ src/blackmisc/blackmiscfreefunctions.h | 6 ++ src/blackmisc/eventallclasses.h | 16 ++++ src/blackmisc/eveventhotkeyfunction.cpp | 93 ++++++++++++++++++++++++ src/blackmisc/eveventhotkeyfunction.h | 89 +++++++++++++++++++++++ 5 files changed, 215 insertions(+) create mode 100644 src/blackmisc/eventallclasses.h create mode 100644 src/blackmisc/eveventhotkeyfunction.cpp create mode 100644 src/blackmisc/eveventhotkeyfunction.h diff --git a/src/blackmisc/blackmiscfreefunctions.cpp b/src/blackmisc/blackmiscfreefunctions.cpp index c0bbe1476..c762ddc74 100644 --- a/src/blackmisc/blackmiscfreefunctions.cpp +++ b/src/blackmisc/blackmiscfreefunctions.cpp @@ -22,6 +22,7 @@ #include "variant.h" #include "statusmessagelist.h" #include "iconlist.h" +#include "eventallclasses.h" #include #include #include @@ -147,6 +148,15 @@ void BlackMisc::Hardware::registerMetadata() CJoystickButton::registerMetadata(); } +/* + * Metadata for Event + */ +void BlackMisc::Event::registerMetadata() +{ + COriginator::registerMetadata(); + CEventHotkeyFunction::registerMetadata(); +} + /* * Metadata for Blackmisc */ @@ -173,6 +183,7 @@ void BlackMisc::registerMetadata() Settings::registerMetadata(); Audio::registerMetadata(); Hardware::registerMetadata(); + Event::registerMetadata(); // needed by XBus proxy class qRegisterMetaType>(); diff --git a/src/blackmisc/blackmiscfreefunctions.h b/src/blackmisc/blackmiscfreefunctions.h index 48b2978d2..b2b7e9b26 100644 --- a/src/blackmisc/blackmiscfreefunctions.h +++ b/src/blackmisc/blackmiscfreefunctions.h @@ -87,6 +87,12 @@ namespace BlackMisc void registerMetadata(); } + namespace Event + { + //! Register metadata for Event + void registerMetadata(); + } + //! Register all relevant metadata in BlackMisc void registerMetadata(); diff --git a/src/blackmisc/eventallclasses.h b/src/blackmisc/eventallclasses.h new file mode 100644 index 000000000..6e0b8a79d --- /dev/null +++ b/src/blackmisc/eventallclasses.h @@ -0,0 +1,16 @@ +/* Copyright (C) 2014 + * 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 and at http://www.swift-project.org/license.html. 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. + */ + +#ifndef BLACKMISC_EVENT_ALLCLASSES_H +#define BLACKMISC_EVENT_ALLCLASSES_H + +#include "blackmisc/evoriginator.h" +#include "blackmisc/eveventhotkeyfunction.h" + +#endif // guard diff --git a/src/blackmisc/eveventhotkeyfunction.cpp b/src/blackmisc/eveventhotkeyfunction.cpp new file mode 100644 index 000000000..092ee9228 --- /dev/null +++ b/src/blackmisc/eveventhotkeyfunction.cpp @@ -0,0 +1,93 @@ +/* Copyright (C) 2014 + * 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 and at http://www.swift-project.org/license.html. 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 "eveventhotkeyfunction.h" + +namespace BlackMisc +{ + namespace Event + { + CEventHotkeyFunction::CEventHotkeyFunction() + { + + } + + CEventHotkeyFunction::CEventHotkeyFunction(CHotkeyFunction func, bool argument) + : m_hotkeyFunc(func), m_hotkeyFuncArgument(argument) + { + } + + // Hash + uint CEventHotkeyFunction::getValueHash() const + { + return qHash(TupleConverter::toMetaTuple(*this)); + } + + // Register metadata + void CEventHotkeyFunction::registerMetadata() + { + qRegisterMetaType(); + qDBusRegisterMetaType(); + } + + /* + * Convert to string + */ + QString CEventHotkeyFunction::convertToQString(bool i18n) const + { + QString s; + s.append(m_eventOriginator.toQString(i18n)); + s.append(" ").append(m_hotkeyFunc.toQString(i18n)); + return s; + } + + /* + * metaTypeId + */ + int CEventHotkeyFunction::getMetaTypeId() const + { + return qMetaTypeId(); + } + + /* + * is a + */ + bool CEventHotkeyFunction::isA(int metaTypeId) const + { + if (metaTypeId == qMetaTypeId()) { return true; } + + return this->CValueObject::isA(metaTypeId); + } + + /* + * Compare + */ + int CEventHotkeyFunction::compareImpl(const CValueObject &otherBase) const + { + const auto &other = static_cast(otherBase); + return compare(TupleConverter::toMetaTuple(*this), TupleConverter::toMetaTuple(other)); + } + + /* + * Marshall to DBus + */ + void CEventHotkeyFunction::marshallToDbus(QDBusArgument &argument) const + { + argument << TupleConverter::toMetaTuple(*this); + } + + /* + * Unmarshall from DBus + */ + void CEventHotkeyFunction::unmarshallFromDbus(const QDBusArgument &argument) + { + argument >> TupleConverter::toMetaTuple(*this); + } + } +} diff --git a/src/blackmisc/eveventhotkeyfunction.h b/src/blackmisc/eveventhotkeyfunction.h new file mode 100644 index 000000000..44325b090 --- /dev/null +++ b/src/blackmisc/eveventhotkeyfunction.h @@ -0,0 +1,89 @@ +/* Copyright (C) 2014 + * 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 and at http://www.swift-project.org/license.html. 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. + */ + +#ifndef BLACKMISC_EVENT_HOTKEYFUNCTION_H +#define BLACKMISC_EVENT_HOTKEYFUNCTION_H + +//! \file + +#include "valueobject.h" +#include "evoriginator.h" +#include "hotkeyfunction.h" +#include "blackmiscfreefunctions.h" + +namespace BlackMisc +{ + namespace Event + { + //! Value object encapsulating a hotkey function for distribution + class CEventHotkeyFunction : public BlackMisc::CValueObject + { + public: + + //! Default constructor. + CEventHotkeyFunction(); + + //! Constructor. + CEventHotkeyFunction(CHotkeyFunction func, bool argument); + + //! \copydoc CValueObject::toQVariant + virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); } + + //! \copydoc CValueObject::convertFromQVariant + virtual void convertFromQVariant(const QVariant &variant) override { BlackMisc::setFromQVariant(this, variant); } + + //! \copydoc CValueObject::getValueHash + virtual uint getValueHash() const override; + + //! Register metadata + static void registerMetadata(); + + //! Get the event originator + const COriginator &getEventOriginator() const {return m_eventOriginator;} + + //! Get the event key + const BlackMisc::CHotkeyFunction &getFunction() const {return m_hotkeyFunc;} + + //! Get boolean hotkey function argument + bool getFunctionArgument() const { return m_hotkeyFuncArgument; } + + protected: + //! \copydoc CValueObject::convertToQString + virtual QString convertToQString(bool i18n = false) const override; + + //! \copydoc CValueObject::getMetaTypeId + virtual int getMetaTypeId() const override; + + //! \copydoc CValueObject::isA + virtual bool isA(int metaTypeId) const override; + + //! \copydoc CValueObject::compareImpl + virtual int compareImpl(const CValueObject &other) const override; + + //! \copydoc CValueObject::marshallToDbus + virtual void marshallToDbus(QDBusArgument &argument) const override; + + //! \copydoc CValueObject::unmarshallFromDbus + virtual void unmarshallFromDbus(const QDBusArgument &argument) override; + + private: + BLACK_ENABLE_TUPLE_CONVERSION(CEventHotkeyFunction) + COriginator m_eventOriginator; + CHotkeyFunction m_hotkeyFunc; + + // This is the required argument to call a registered function per CHotkeyFunction + bool m_hotkeyFuncArgument = false; + }; + } +} + +BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Event::CEventHotkeyFunction, (o.m_eventOriginator, o.m_hotkeyFunc)) +Q_DECLARE_METATYPE(BlackMisc::Event::CEventHotkeyFunction) + +#endif // BLACKMISC_EVENTHOTKEY_H