Skip to content

Commit

Permalink
Merge branch 'jb33055' into 'master'
Browse files Browse the repository at this point in the history
[ssu] Provide read-only SsuDeviceInfo access to QML. Contributes to JB#33055



See merge request !2
  • Loading branch information
jpetrell committed Mar 4, 2016
2 parents d8bded1 + 3d2c2a6 commit ecc323b
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 2 deletions.
6 changes: 4 additions & 2 deletions declarative/declarative.pro
Expand Up @@ -15,9 +15,11 @@ CONFIG += plugin

target.path = $$TARGETPATH

HEADERS = declarativessufeaturemodel.h
HEADERS = declarativessufeaturemodel.h \
declarativessudeviceinfo.h
SOURCES += plugin.cpp \
declarativessufeaturemodel.cpp
declarativessufeaturemodel.cpp \
declarativessudeviceinfo.cpp

qmldir.files = qmldir *.qml *.js
qmldir.path = $$target.path
Expand Down
33 changes: 33 additions & 0 deletions declarative/declarativessudeviceinfo.cpp
@@ -0,0 +1,33 @@
/**
* @file declarativessufeaturemodel.cpp
* @copyright 2016 Jolla Ltd.
* @author Martin Jones <martin.jones@jolla.com>
* @date 2016
*/

#include "declarativessudeviceinfo.h"

DeclarativeSsuDeviceInfo::DeclarativeSsuDeviceInfo()
{
}

QString DeclarativeSsuDeviceInfo::deviceFamily()
{
return info.deviceFamily();
}

QString DeclarativeSsuDeviceInfo::deviceVariant(bool fallback)
{
return info.deviceVariant(fallback);
}

QString DeclarativeSsuDeviceInfo::deviceModel()
{
return info.deviceModel();
}

QString DeclarativeSsuDeviceInfo::displayName(const int type)
{
return info.displayName(type);
}

63 changes: 63 additions & 0 deletions declarative/declarativessudeviceinfo.h
@@ -0,0 +1,63 @@
/**
* @file declarativessufeaturemodel.h
* @copyright 2016 Jolla Ltd.
* @author Martin Jones <martin.jones@jolla.com>
* @date 2016
*/

#ifndef _DECLARATIVESSUDEVICEINFO_H
#define _DECLARATIVESSUDEVICEINFO_H

#include "../libssu/ssudeviceinfo.h"

class DeclarativeSsuDeviceInfo : public QObject
{
Q_OBJECT
Q_ENUMS(DisplayType)
public:
/**
* A list of types ssu provides shiny values suitable for displaying
*/
enum DisplayType {
DeviceManufacturer = Ssu::DeviceManufacturer, ///< Manufacturer, like ACME Corp. Board mappings key "deviceManufacturer"
DeviceModel = Ssu::DeviceModel, ///< Marketed device name, like Pogoblaster 3000. Board mappings key "prettyModel"
DeviceDesignation = Ssu::DeviceDesignation, ///< Type designation, like NCC-1701. Beard mappings key "deviceDesignation"
};

DeclarativeSsuDeviceInfo();

/**
* Try to find the device family for the system this is running on. This function
* temporarily changes the detected model, and therefore should not be used in a
* multithreaded environment, unless you like funny results.
*/
Q_INVOKABLE QString deviceFamily();
/**
* Try to find the device variant for the system this is running on.
* If the device is not a variant it will return an empty string. If
* fallback is set to true it return the device model in this case.
*/
Q_INVOKABLE QString deviceVariant(bool fallback=false);
/**
* Try to find out ond what kind of system this is running
*/
Q_INVOKABLE QString deviceModel();
/**
* Return a string suitable for display in dialogs, ...
*
* See DeviceTypes for supported types.
*
* If not configured the model name used by ssu will be returned instead
* for product and type.
* If no manufacturer is found UNKNOWN is returned.
* For an invalid type an empty string is returned.
*/
Q_INVOKABLE QString displayName(const int type);

private:
SsuDeviceInfo info;
};

#endif


7 changes: 7 additions & 0 deletions declarative/plugin.cpp
Expand Up @@ -10,6 +10,12 @@

#include <qqml.h>
#include "declarativessufeaturemodel.h"
#include "declarativessudeviceinfo.h"

static QObject *device_info_factory(QQmlEngine *, QJSEngine *)
{
return new DeclarativeSsuDeviceInfo;
}

class NemoSsuPlugin : public QQmlExtensionPlugin
{
Expand All @@ -20,6 +26,7 @@ class NemoSsuPlugin : public QQmlExtensionPlugin
virtual void registerTypes(const char *)
{
qmlRegisterType<DeclarativeSsuFeatureModel>("Nemo.Ssu", 1, 0, "FeatureModel");
qmlRegisterSingletonType<DeclarativeSsuDeviceInfo>("Nemo.Ssu", 1, 1, "DeviceInfo", device_info_factory);
}
};

Expand Down

0 comments on commit ecc323b

Please sign in to comment.