More work on the device browser
This commit is contained in:
parent
57f68bcdc0
commit
a385188d37
@ -58,6 +58,8 @@
|
||||
#include "loggingcategories.h"
|
||||
#include "logging/logvaluetool.h"
|
||||
|
||||
#include "types/mediabrowseritem.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QJsonDocument>
|
||||
#include <QDebug>
|
||||
@ -90,6 +92,8 @@ QVariantList JsonTypes::s_networkDeviceState;
|
||||
QVariantList JsonTypes::s_userError;
|
||||
QVariantList JsonTypes::s_tagError;
|
||||
QVariantList JsonTypes::s_cloudConnectionState;
|
||||
QVariantList JsonTypes::s_browserIcon;
|
||||
QVariantList JsonTypes::s_mediaBrowserIcon;
|
||||
|
||||
QVariantMap JsonTypes::s_paramType;
|
||||
QVariantMap JsonTypes::s_param;
|
||||
@ -154,6 +158,8 @@ void JsonTypes::init()
|
||||
s_userError = enumToStrings(UserManager::staticMetaObject, "UserError");
|
||||
s_tagError = enumToStrings(TagsStorage::staticMetaObject, "TagError");
|
||||
s_cloudConnectionState = enumToStrings(CloudManager::staticMetaObject, "CloudConnectionState");
|
||||
s_browserIcon = enumToStrings(BrowserItem::staticMetaObject, "BrowserIcon");
|
||||
s_mediaBrowserIcon = enumToStrings(MediaBrowserItem::staticMetaObject, "MediaBrowserIcon");
|
||||
|
||||
// ParamType
|
||||
s_paramType.insert("id", basicTypeToString(Uuid));
|
||||
@ -425,9 +431,11 @@ void JsonTypes::init()
|
||||
s_browserItem.insert("id", basicTypeToString(QVariant::String));
|
||||
s_browserItem.insert("displayName", basicTypeToString(QVariant::String));
|
||||
s_browserItem.insert("description", basicTypeToString(QVariant::String));
|
||||
s_browserItem.insert("icon", browserIconRef());
|
||||
s_browserItem.insert("thumbnail", basicTypeToString(QVariant::String));
|
||||
s_browserItem.insert("executable", basicTypeToString(QVariant::Bool));
|
||||
s_browserItem.insert("browsable", basicTypeToString(QVariant::Bool));
|
||||
s_browserItem.insert("o:mediaIcon", mediaBrowserIconRef());
|
||||
|
||||
s_initialized = true;
|
||||
}
|
||||
@ -477,6 +485,8 @@ QVariantMap JsonTypes::allTypes()
|
||||
allTypes.insert("UserError", userError());
|
||||
allTypes.insert("TagError", tagError());
|
||||
allTypes.insert("CloudConnectionState", cloudConnectionState());
|
||||
allTypes.insert("BrowserIcon", browserIconRef());
|
||||
allTypes.insert("MediaBrowserIcon", mediaBrowserIconRef());
|
||||
|
||||
allTypes.insert("StateType", stateTypeDescription());
|
||||
allTypes.insert("StateDescriptor", stateDescriptorDescription());
|
||||
@ -513,6 +523,7 @@ QVariantMap JsonTypes::allTypes()
|
||||
allTypes.insert("MqttPolicy", mqttPolicyDescription());
|
||||
allTypes.insert("Package", packageDescription());
|
||||
allTypes.insert("Repository", repositoryDescription());
|
||||
allTypes.insert("BrowserItem", browserItemDescription());
|
||||
|
||||
return allTypes;
|
||||
}
|
||||
@ -724,6 +735,10 @@ QVariantMap JsonTypes::packBrowserItem(const BrowserItem &item)
|
||||
ret.insert("id", item.id());
|
||||
ret.insert("displayName", item.displayName());
|
||||
ret.insert("description", item.description());
|
||||
ret.insert("icon", browserIconToString(item.icon()));
|
||||
if (item.extendedPropertiesFlags().testFlag(BrowserItem::ExtendedPropertiesMedia)) {
|
||||
ret.insert("mediaIcon", mediaBrowserIconToString(static_cast<MediaBrowserItem::MediaBrowserIcon>(item.extendedProperty("mediaIcon").toInt())));
|
||||
}
|
||||
ret.insert("thumbnail", item.thumbnail());
|
||||
ret.insert("executable", item.executable());
|
||||
ret.insert("browsable", item.browsable());
|
||||
@ -2252,6 +2267,18 @@ QPair<bool, QString> JsonTypes::validateVariant(const QVariant &templateVariant,
|
||||
qCWarning(dcJsonRpc()) << QString("Value %1 not allowed in %2").arg(variant.toString()).arg(cloudConnectionStateRef());
|
||||
return result;
|
||||
}
|
||||
} else if (refName == browserIconRef()) {
|
||||
QPair<bool, QString> result = validateEnum(s_browserIcon, variant);
|
||||
if (!result.first) {
|
||||
qCWarning(dcJsonRpc()) << QString("Value %1 not allowed in %2").arg(variant.toString()).arg(browserIconRef());
|
||||
return result;
|
||||
}
|
||||
} else if (refName == mediaBrowserIconRef()) {
|
||||
QPair<bool, QString> result = validateEnum(s_mediaBrowserIcon, variant);
|
||||
if (!result.first) {
|
||||
qCWarning(dcJsonRpc()) << QString("Value %1 not allowed in %2").arg(variant.toString()).arg(mediaBrowserIconRef());
|
||||
return result;
|
||||
}
|
||||
} else {
|
||||
Q_ASSERT_X(false, "JsonTypes", QString("Unhandled ref: %1").arg(refName).toLatin1().data());
|
||||
return report(false, QString("Unhandled ref %1. Server implementation incomplete.").arg(refName));
|
||||
|
||||
@ -37,6 +37,7 @@
|
||||
#include "types/paramtype.h"
|
||||
#include "types/paramdescriptor.h"
|
||||
#include "types/ruleactionparam.h"
|
||||
#include "types/mediabrowseritem.h"
|
||||
|
||||
#include "logging/logging.h"
|
||||
#include "logging/logentry.h"
|
||||
@ -90,10 +91,8 @@ namespace nymeaserver {
|
||||
return s_##typeName; \
|
||||
} \
|
||||
static QString typeName##ToString(className::enumName value) { \
|
||||
const QMetaObject &metaObject = className::staticMetaObject; \
|
||||
int enumIndex = metaObject.indexOfEnumerator(enumString); \
|
||||
QMetaEnum metaEnum = metaObject.enumerator(enumIndex); \
|
||||
return metaEnum.valueToKey(metaEnum.value(value)); \
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<className::enumName>(); \
|
||||
return metaEnum.valueToKey(value); \
|
||||
} \
|
||||
private: \
|
||||
static QVariantList s_##typeName; \
|
||||
@ -102,7 +101,6 @@ namespace nymeaserver {
|
||||
class JsonTypes
|
||||
{
|
||||
Q_GADGET
|
||||
Q_ENUMS(BasicType)
|
||||
|
||||
public:
|
||||
enum BasicType {
|
||||
@ -118,6 +116,7 @@ public:
|
||||
Time,
|
||||
Object
|
||||
};
|
||||
Q_ENUM(BasicType)
|
||||
|
||||
static QVariantMap allTypes();
|
||||
|
||||
@ -143,6 +142,8 @@ public:
|
||||
DECLARE_TYPE(userError, "UserError", UserManager, UserError)
|
||||
DECLARE_TYPE(tagError, "TagError", TagsStorage, TagError)
|
||||
DECLARE_TYPE(cloudConnectionState, "CloudConnectionState", CloudManager, CloudConnectionState)
|
||||
DECLARE_TYPE(browserIcon, "BrowserIcon", BrowserItem, BrowserIcon)
|
||||
DECLARE_TYPE(mediaBrowserIcon, "MediaBrowserIcon", MediaBrowserItem, MediaBrowserIcon)
|
||||
|
||||
DECLARE_OBJECT(paramType, "ParamType")
|
||||
DECLARE_OBJECT(param, "Param")
|
||||
|
||||
@ -28,11 +28,6 @@ namespace nymeaserver {
|
||||
class Logging
|
||||
{
|
||||
Q_GADGET
|
||||
Q_ENUMS(LoggingError)
|
||||
Q_ENUMS(LoggingSource)
|
||||
Q_FLAGS(LoggingSources)
|
||||
Q_ENUMS(LoggingLevel)
|
||||
Q_ENUMS(LoggingEventType)
|
||||
|
||||
public:
|
||||
enum LoggingError {
|
||||
@ -40,6 +35,7 @@ public:
|
||||
LoggingErrorLogEntryNotFound,
|
||||
LoggingErrorInvalidFilterParameter
|
||||
};
|
||||
Q_ENUM(LoggingError)
|
||||
|
||||
enum LoggingSource {
|
||||
LoggingSourceSystem,
|
||||
@ -48,12 +44,15 @@ public:
|
||||
LoggingSourceStates,
|
||||
LoggingSourceRules
|
||||
};
|
||||
Q_ENUM(LoggingSource)
|
||||
Q_FLAGS(LoggingSources)
|
||||
Q_DECLARE_FLAGS(LoggingSources, LoggingSource)
|
||||
|
||||
enum LoggingLevel {
|
||||
LoggingLevelInfo,
|
||||
LoggingLevelAlert
|
||||
};
|
||||
Q_ENUM(LoggingLevel)
|
||||
|
||||
enum LoggingEventType {
|
||||
LoggingEventTypeTrigger,
|
||||
@ -62,8 +61,9 @@ public:
|
||||
LoggingEventTypeActionsExecuted,
|
||||
LoggingEventTypeExitActionsExecuted
|
||||
};
|
||||
Q_ENUM(LoggingEventType)
|
||||
|
||||
Logging(QObject *parent = 0);
|
||||
Logging(QObject *parent = nullptr);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -35,9 +35,6 @@ namespace nymeaserver {
|
||||
class NetworkDevice : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(NetworkDeviceType)
|
||||
Q_ENUMS(NetworkDeviceState)
|
||||
Q_ENUMS(NetworkDeviceStateReason)
|
||||
|
||||
public:
|
||||
enum NetworkDeviceState {
|
||||
@ -55,6 +52,7 @@ public:
|
||||
NetworkDeviceStateDeactivating = 110,
|
||||
NetworkDeviceStateFailed = 120
|
||||
};
|
||||
Q_ENUM(NetworkDeviceState)
|
||||
|
||||
enum NetworkDeviceStateReason {
|
||||
NetworkDeviceStateReasonNone = 0,
|
||||
@ -121,6 +119,7 @@ public:
|
||||
NetworkDeviceStateReasonParentChanged = 61,
|
||||
NetworkDeviceStateReasonParentManagedChanged = 62
|
||||
};
|
||||
Q_ENUM(NetworkDeviceStateReason)
|
||||
|
||||
enum NetworkDeviceType {
|
||||
NetworkDeviceTypeUnknown = 0,
|
||||
@ -143,8 +142,9 @@ public:
|
||||
NetworkDeviceTypeVXLan = 19,
|
||||
NetworkDeviceTypeVEth = 20,
|
||||
};
|
||||
Q_ENUM(NetworkDeviceType)
|
||||
|
||||
explicit NetworkDevice(const QDBusObjectPath &objectPath, QObject *parent = 0);
|
||||
explicit NetworkDevice(const QDBusObjectPath &objectPath, QObject *parent = nullptr);
|
||||
|
||||
QDBusObjectPath objectPath() const;
|
||||
|
||||
|
||||
@ -40,9 +40,6 @@ namespace nymeaserver {
|
||||
class NetworkManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(NetworkManagerState)
|
||||
Q_ENUMS(NetworkManagerConnectivityState)
|
||||
Q_ENUMS(NetworkManagerError)
|
||||
|
||||
public:
|
||||
enum NetworkManagerState {
|
||||
@ -55,6 +52,7 @@ public:
|
||||
NetworkManagerStateConnectedSite = 60,
|
||||
NetworkManagerStateConnectedGlobal = 70
|
||||
};
|
||||
Q_ENUM(NetworkManagerState)
|
||||
|
||||
enum NetworkManagerConnectivityState {
|
||||
NetworkManagerConnectivityStateUnknown = 0,
|
||||
@ -63,6 +61,7 @@ public:
|
||||
NetworkManagerConnectivityStateLimited = 3,
|
||||
NetworkManagerConnectivityStateFull = 4
|
||||
};
|
||||
Q_ENUM(NetworkManagerConnectivityState)
|
||||
|
||||
enum NetworkManagerError {
|
||||
NetworkManagerErrorNoError,
|
||||
@ -76,8 +75,9 @@ public:
|
||||
NetworkManagerErrorNetworkingDisabled,
|
||||
NetworkManagerErrorNetworkManagerNotAvailable
|
||||
};
|
||||
Q_ENUM(NetworkManagerError)
|
||||
|
||||
explicit NetworkManager(QObject *parent = 0);
|
||||
explicit NetworkManager(QObject *parent = nullptr);
|
||||
|
||||
bool available();
|
||||
bool wifiAvailable();
|
||||
|
||||
@ -69,7 +69,6 @@ typedef QList<MqttPolicy> MqttPolicies;
|
||||
class NymeaConfiguration : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(ConfigurationError)
|
||||
|
||||
public:
|
||||
enum ConfigurationError {
|
||||
@ -82,6 +81,7 @@ public:
|
||||
ConfigurationErrorBluetoothHardwareNotAvailable,
|
||||
ConfigurationErrorInvalidCertificate
|
||||
};
|
||||
Q_ENUM(ConfigurationError)
|
||||
|
||||
explicit NymeaConfiguration(QObject *parent = nullptr);
|
||||
|
||||
|
||||
@ -36,8 +36,6 @@ namespace nymeaserver {
|
||||
class RuleEngine : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(RuleError)
|
||||
Q_ENUMS(RemovePolicy)
|
||||
public:
|
||||
enum RuleError {
|
||||
RuleErrorNoError,
|
||||
@ -62,11 +60,13 @@ public:
|
||||
RuleErrorNoExitActions,
|
||||
RuleErrorInterfaceNotFound
|
||||
};
|
||||
Q_ENUM(RuleError)
|
||||
|
||||
enum RemovePolicy {
|
||||
RemovePolicyCascade,
|
||||
RemovePolicyUpdate
|
||||
};
|
||||
Q_ENUM(RemovePolicy)
|
||||
|
||||
explicit RuleEngine(QObject *parent = nullptr);
|
||||
~RuleEngine();
|
||||
|
||||
@ -117,9 +117,10 @@ void TcpServer::sendData(const QUuid &clientId, const QByteArray &data)
|
||||
QTcpSocket *client = nullptr;
|
||||
client = m_clientList.value(clientId);
|
||||
if (client) {
|
||||
qCDebug(dcTcpServer()) << "Sending to client" << clientId.toString() << data;
|
||||
client->write(data + '\n');
|
||||
} else {
|
||||
qWarning(dcTcpServer()) << "Client" << clientId << "unknown to this transport";
|
||||
qCWarning(dcTcpServer()) << "Client" << clientId << "unknown to this transport";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -31,7 +31,6 @@ namespace nymeaserver {
|
||||
class RepeatingOption
|
||||
{
|
||||
Q_GADGET
|
||||
Q_ENUMS(RepeatingMode)
|
||||
|
||||
public:
|
||||
enum RepeatingMode {
|
||||
@ -42,6 +41,7 @@ public:
|
||||
RepeatingModeMonthly,
|
||||
RepeatingModeYearly
|
||||
};
|
||||
Q_ENUM(RepeatingMode)
|
||||
|
||||
RepeatingOption();
|
||||
RepeatingOption(const RepeatingMode &mode, const QList<int> &weekDays = QList<int>(), const QList<int> &monthDays = QList<int>());
|
||||
|
||||
@ -33,7 +33,6 @@ class PushButtonDBusService;
|
||||
class UserManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(UserError)
|
||||
public:
|
||||
enum UserError {
|
||||
UserErrorNoError,
|
||||
@ -44,6 +43,7 @@ public:
|
||||
UserErrorTokenNotFound,
|
||||
UserErrorPermissionDenied
|
||||
};
|
||||
Q_ENUM(UserError)
|
||||
|
||||
explicit UserManager(const QString &dbName, QObject *parent = nullptr);
|
||||
|
||||
|
||||
@ -30,7 +30,6 @@
|
||||
class LIBNYMEA_EXPORT CoapOption
|
||||
{
|
||||
Q_GADGET
|
||||
Q_ENUMS(Option)
|
||||
|
||||
public:
|
||||
// Options format: https://tools.ietf.org/html/rfc7252#section-3.1
|
||||
@ -54,6 +53,7 @@ public:
|
||||
ProxyScheme = 39,
|
||||
Size1 = 60
|
||||
};
|
||||
Q_ENUM(Option)
|
||||
|
||||
CoapOption();
|
||||
|
||||
|
||||
@ -15,7 +15,8 @@ HEADERS += \
|
||||
libnymea.h \
|
||||
platform/package.h \
|
||||
platform/repository.h \
|
||||
types/browseritem.h \
|
||||
types/browseritem.h \
|
||||
types/mediabrowseritem.h \
|
||||
typeutils.h \
|
||||
loggingcategories.h \
|
||||
nymeasettings.h \
|
||||
@ -111,7 +112,8 @@ SOURCES += \
|
||||
coap/corelinkparser.cpp \
|
||||
coap/corelink.cpp \
|
||||
coap/coapobserveresource.cpp \
|
||||
types/browseritem.cpp \
|
||||
types/browseritem.cpp \
|
||||
types/mediabrowseritem.cpp \
|
||||
types/deviceclass.cpp \
|
||||
types/action.cpp \
|
||||
types/actiontype.cpp \
|
||||
|
||||
@ -19,6 +19,11 @@ QString BrowserItem::displayName() const
|
||||
return m_displayName;
|
||||
}
|
||||
|
||||
void BrowserItem::setDisplayName(const QString &displayName)
|
||||
{
|
||||
m_displayName = displayName;
|
||||
}
|
||||
|
||||
QString BrowserItem::description() const
|
||||
{
|
||||
return m_description;
|
||||
@ -49,6 +54,16 @@ void BrowserItem::setBrowsable(bool browsable)
|
||||
m_browsable = browsable;
|
||||
}
|
||||
|
||||
BrowserItem::BrowserIcon BrowserItem::icon() const
|
||||
{
|
||||
return m_icon;
|
||||
}
|
||||
|
||||
void BrowserItem::setIcon(BrowserIcon icon)
|
||||
{
|
||||
m_icon = icon;
|
||||
}
|
||||
|
||||
QString BrowserItem::thumbnail() const
|
||||
{
|
||||
return m_thumbnail;
|
||||
@ -59,6 +74,16 @@ void BrowserItem::setThumbnail(const QString &thumbnail)
|
||||
m_thumbnail = thumbnail;
|
||||
}
|
||||
|
||||
BrowserItem::ExtendedPropertiesFlags BrowserItem::extendedPropertiesFlags() const
|
||||
{
|
||||
return m_extendedPropertiesFlags;
|
||||
}
|
||||
|
||||
QVariant BrowserItem::extendedProperty(const QString &propertyName) const
|
||||
{
|
||||
return m_extendedProperties[propertyName];
|
||||
}
|
||||
|
||||
BrowserItems::BrowserItems()
|
||||
{
|
||||
|
||||
|
||||
@ -8,7 +8,30 @@
|
||||
|
||||
class LIBNYMEA_EXPORT BrowserItem
|
||||
{
|
||||
Q_GADGET
|
||||
public:
|
||||
enum BrowserIcon {
|
||||
BrowserIconNone,
|
||||
BrowserIconFolder,
|
||||
BrowserIconFile,
|
||||
BrowserIconMusic,
|
||||
BrowserIconVideo,
|
||||
BrowserIconPictures,
|
||||
BrowserIconApplication,
|
||||
BrowserIconDocument,
|
||||
BrowserIconPackage,
|
||||
BrowserIconFavorites,
|
||||
};
|
||||
Q_ENUM(BrowserIcon)
|
||||
|
||||
enum ExtendedProperties {
|
||||
ExtendedPropertiesNone = 0x00,
|
||||
ExtendedPropertiesMedia = 0x01
|
||||
};
|
||||
Q_ENUM(ExtendedProperties)
|
||||
Q_DECLARE_FLAGS(ExtendedPropertiesFlags, ExtendedProperties)
|
||||
|
||||
|
||||
BrowserItem(const QString &id = QString(), const QString &displayName = QString(), bool browsable = false);
|
||||
|
||||
QString id() const;
|
||||
@ -26,18 +49,31 @@ public:
|
||||
bool browsable() const;
|
||||
void setBrowsable(bool browsable);
|
||||
|
||||
BrowserIcon icon() const;
|
||||
void setIcon(BrowserIcon icon);
|
||||
|
||||
QString thumbnail() const;
|
||||
void setThumbnail(const QString &thumbnail);
|
||||
|
||||
ExtendedPropertiesFlags extendedPropertiesFlags() const;
|
||||
QVariant extendedProperty(const QString &propertyName) const;
|
||||
|
||||
private:
|
||||
QString m_id;
|
||||
QString m_displayName;
|
||||
QString m_description;
|
||||
bool m_executable = false;
|
||||
bool m_browsable = false;
|
||||
BrowserIcon m_icon = BrowserIconNone;
|
||||
QString m_thumbnail;
|
||||
|
||||
protected:
|
||||
ExtendedPropertiesFlags m_extendedPropertiesFlags = ExtendedPropertiesNone;
|
||||
QHash<QString, QVariant> m_extendedProperties;
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(BrowserItem::ExtendedPropertiesFlags)
|
||||
|
||||
|
||||
class LIBNYMEA_EXPORT BrowserItems: public QList<BrowserItem>
|
||||
{
|
||||
|
||||
@ -38,10 +38,6 @@
|
||||
class LIBNYMEA_EXPORT DeviceClass
|
||||
{
|
||||
Q_GADGET
|
||||
Q_ENUMS(CreateMethod)
|
||||
Q_ENUMS(SetupMethod)
|
||||
Q_ENUMS(BasicTag)
|
||||
Q_ENUMS(CreateMethods)
|
||||
|
||||
public:
|
||||
enum CreateMethod {
|
||||
@ -49,6 +45,7 @@ public:
|
||||
CreateMethodAuto = 0x02,
|
||||
CreateMethodDiscovery = 0x04
|
||||
};
|
||||
Q_ENUM(CreateMethod)
|
||||
Q_DECLARE_FLAGS(CreateMethods, CreateMethod)
|
||||
|
||||
enum SetupMethod {
|
||||
@ -57,6 +54,7 @@ public:
|
||||
SetupMethodEnterPin,
|
||||
SetupMethodPushButton
|
||||
};
|
||||
Q_ENUM(SetupMethod)
|
||||
|
||||
DeviceClass(const PluginId &pluginId = PluginId(), const VendorId &vendorId = VendorId(), const DeviceClassId &id = DeviceClassId());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user