refs #139 added keyboard key list to settings, so values can be changed

This commit is contained in:
Klaus Basan
2014-02-17 02:31:23 +01:00
parent bb5865936b
commit 87352df468
6 changed files with 90 additions and 40 deletions

View File

@@ -7,9 +7,10 @@
#include "coreruntime.h"
#include "blackmisc/settingutilities.h"
using namespace BlackMisc;
using namespace BlackMisc::Settings;
using namespace BlackMisc::Network;
using namespace BlackMisc;
using namespace BlackMisc::Hardware;
namespace BlackCore
{
@@ -17,7 +18,7 @@ namespace BlackCore
/*
* Init this context
*/
CContextSettings::CContextSettings(CCoreRuntime *runtime) : IContextSettings(runtime), m_settingsNetwork()
CContextSettings::CContextSettings(CCoreRuntime *runtime) : IContextSettings(runtime)
{
// create some dummy settings
// this would actually be reading the settings from disk ..
@@ -28,6 +29,17 @@ namespace BlackCore
this->m_settingsNetwork.addTrafficNetworkServer(CServer("Europe CC", "VATSIM Server", "5.9.155.43", 6809, CUser("vatsimid", "Black Client", "", "vatsimpw")));
this->m_settingsNetwork.addTrafficNetworkServer(CServer("UK", "VATSIM Server", "109.169.48.148", 6809, CUser("vatsimid", "Black Client", "", "vatsimpw")));
this->m_settingsNetwork.addTrafficNetworkServer(CServer("USA-W", "VATSIM Server", "64.151.108.52", 6809, CUser("vatsimid", "Black Client", "", "vatsimpw")));
// hotkeys
this->m_hotkeys.initAsHotkeyList();
}
/*
* Hotkeys
*/
Hardware::CKeyboardKeyList CContextSettings::getHotkeys() const
{
return this->m_hotkeys;
}
/*
@@ -45,15 +57,40 @@ namespace BlackCore
{
Q_ASSERT(path.length() > 3);
Q_ASSERT(path.indexOf('/') >= 0);
BlackMisc::CStatusMessageList msgs;
if (path.contains(IContextSettings::PathRoot()))
{
if (path.contains(IContextSettings::PathHotkeys()))
{
if (command == CSettingUtilities::CmdUpdate())
{
BlackMisc::Hardware::CKeyboardKeyList hotkeys = value.value<BlackMisc::Hardware::CKeyboardKeyList>();
this->m_hotkeys = hotkeys;
emit this->changedSettings();
msgs.push_back(CStatusMessage::getInfoMessage("set hotkeys"));
return msgs;
}
}
}
// next level
QString nextLevelPath = CSettingUtilities::removeLeadingPath(path);
BlackMisc::CStatusMessageList msgs = CSettingUtilities::wrongPathMessages(path);
bool changed = false;
if (path.startsWith(IContextSettings::PathNetworkSettings()))
{
msgs = this->m_settingsNetwork.value(nextLevelPath, command, value, changed);
if (changed) emit this->changedNetworkSettings();
if (changed)
{
emit this->changedNetworkSettings();
emit this->changedSettings();
}
}
else
{
// wrong path
msgs = CSettingUtilities::wrongPathMessages(path);
}
return msgs;
}
} // namespace

View File

@@ -9,8 +9,8 @@
#include "blackcore/coreruntime.h"
#include "blackcore/dbus_server.h"
#include "blackcore/context_settings_interface.h"
#include "blackmisc/statusmessage.h"
#include "blackmisc/statusmessagelist.h"
#include "blackmisc/hwkeyboardkeylist.h"
#include <QObject>
#define BLACKCORE_CONTEXTSETTINGS_INTERFACENAME "blackcore.contextsettings"
@@ -29,50 +29,37 @@ namespace BlackCore
public:
/*!
* Context
* \param runtime
*/
//! \brief Constructor
CContextSettings(CCoreRuntime *runtime);
/*!
* Destructor
*/
//! Destructor
virtual ~CContextSettings() {}
/*!
* \brief Register myself in DBus
* \param server
*/
//! \brief Register myself in DBus
void registerWithDBus(CDBusServer *server)
{
server->addObject(IContextSettings::ServicePath(), this);
}
/*!
* \brief Runtime
* \return
*/
//! \brief Runtime
const CCoreRuntime *getRuntime() const
{
return static_cast<CCoreRuntime *>(this->parent());
}
/*!
* \copydoc IContextSettings::value()
*/
//! \copydoc IContextSettings::value()
virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const QVariant &value);
public slots:
/*!
* \copydoc IContextSettings::getNetworkSettings()
*/
//! \copydoc IContextSettings::getNetworkSettings()
virtual BlackMisc::Settings::CSettingsNetwork getNetworkSettings() const;
//! \copydoc IContextSettings::getHotkeys()
virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const;
private:
BlackMisc::Settings::CSettingsNetwork m_settingsNetwork;
BlackMisc::Hardware::CKeyboardKeyList m_hotkeys;
};
}

View File

@@ -40,6 +40,14 @@ namespace BlackCore
return this->m_dBusInterface->callDBusRet<BlackMisc::Settings::CSettingsNetwork>(QLatin1Literal("getNetworkSettings"));
}
/*
* Relay tp DBus
*/
BlackMisc::Hardware::CKeyboardKeyList IContextSettings::getHotkeys() const
{
return this->m_dBusInterface->callDBusRet<BlackMisc::Hardware::CKeyboardKeyList>(QLatin1Literal("getHotkeys"));
}
/*
* Relay to DBus, but make this no slot
*/

View File

@@ -10,6 +10,7 @@
#include "blackmisc/genericdbusinterface.h"
#include "blackmisc/settingutilities.h"
#include "blackmisc/setnetwork.h"
#include "blackmisc/hwkeyboardkeylist.h"
#include <QObject>
#include <QVariant>
#include <QDBusAbstractInterface>
@@ -53,7 +54,7 @@ namespace BlackCore
/*!
* \brief Path for network settings
* \remark no to be confused with DBus paths
* \remarks no to be confused with DBus paths
*/
static const QString &PathNetworkSettings()
{
@@ -61,6 +62,26 @@ namespace BlackCore
return s;
}
/*!
* \brief Path for network settings
* \remarks no to be confused with DBus paths
*/
static const QString &PathRoot()
{
static QString s("root");
return s;
}
/*!
* \brief Path for hotkeys
* \remarks no to be confused with DBus paths
*/
static const QString &PathHotkeys()
{
static QString s("hotkeys");
return s;
}
/*!
* \brief DBus version constructor
*/
@@ -102,26 +123,25 @@ namespace BlackCore
IContextSettings(QObject *parent = nullptr) : QObject(parent), m_dBusInterface(nullptr) {}
signals:
//! \brief Settings have been changed
void changedSettings();
/*!
* \brief Settings have been changed
*/
//! \brief Network settings have been changed
void changedNetworkSettings();
public slots:
/*!
* \brief Network settings
*/
//! \brief Network settings
virtual BlackMisc::Settings::CSettingsNetwork getNetworkSettings() const;
//! \brief Hotkeys
virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const;
/*!
* \brief DBus version of value method.
* \remarks Basically an unwanted signature as this is different from the "local" signature and
* contains explicit DBus types (a: QDbusArgument, b: type for conversion).
* If this can be removed, fine.
*
*/
virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, QDBusVariant value, int unifiedBlackMetaType);
};