refs #318 Value class CEventHotkeyFunction

Event which will be transferred to another process and trigger a
hotkey function remotely.
This commit is contained in:
Roland Winklmeier
2014-08-20 01:28:38 +02:00
parent 2304b8e4db
commit f970e7cfaa
5 changed files with 215 additions and 0 deletions

View File

@@ -22,6 +22,7 @@
#include "variant.h"
#include "statusmessagelist.h"
#include "iconlist.h"
#include "eventallclasses.h"
#include <QtNetwork/QHostInfo>
#include <QProcessEnvironment>
#include <QSysInfo>
@@ -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<CSequence<double>>();

View File

@@ -87,6 +87,12 @@ namespace BlackMisc
void registerMetadata();
}
namespace Event
{
//! Register metadata for Event
void registerMetadata();
}
//! Register all relevant metadata in BlackMisc
void registerMetadata();

View File

@@ -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

View File

@@ -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<CEventHotkeyFunction>::toMetaTuple(*this));
}
// Register metadata
void CEventHotkeyFunction::registerMetadata()
{
qRegisterMetaType<CEventHotkeyFunction>();
qDBusRegisterMetaType<CEventHotkeyFunction>();
}
/*
* 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<CEventHotkeyFunction>();
}
/*
* is a
*/
bool CEventHotkeyFunction::isA(int metaTypeId) const
{
if (metaTypeId == qMetaTypeId<CEventHotkeyFunction>()) { return true; }
return this->CValueObject::isA(metaTypeId);
}
/*
* Compare
*/
int CEventHotkeyFunction::compareImpl(const CValueObject &otherBase) const
{
const auto &other = static_cast<const CEventHotkeyFunction &>(otherBase);
return compare(TupleConverter<CEventHotkeyFunction>::toMetaTuple(*this), TupleConverter<CEventHotkeyFunction>::toMetaTuple(other));
}
/*
* Marshall to DBus
*/
void CEventHotkeyFunction::marshallToDbus(QDBusArgument &argument) const
{
argument << TupleConverter<CEventHotkeyFunction>::toMetaTuple(*this);
}
/*
* Unmarshall from DBus
*/
void CEventHotkeyFunction::unmarshallFromDbus(const QDBusArgument &argument)
{
argument >> TupleConverter<CEventHotkeyFunction>::toMetaTuple(*this);
}
}
}

View File

@@ -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