diff --git a/dbus/org.nemo.ssu.xml b/dbus/org.nemo.ssu.xml index 8bcd9b0..291f630 100644 --- a/dbus/org.nemo.ssu.xml +++ b/dbus/org.nemo.ssu.xml @@ -49,6 +49,12 @@ + + + + + + diff --git a/libssu/ssu.h b/libssu/ssu.h index e95067d..ec835bb 100644 --- a/libssu/ssu.h +++ b/libssu/ssu.h @@ -118,6 +118,14 @@ class Ssu: public QObject { ReleaseMode = 0x4, ///< Enable Release mode LenientMode = 0x8 ///< Disable strict mode (i.e., keep unmanaged repositories) }; + /** + * A list of types ssu provides shiny values suitable for displaying + */ + enum DisplayType { + DeviceManufacturer = 0, ///< Manufacturer, like ACME Corp. Board mappings key "deviceManufacturer" + DeviceModel, ///< Marketed device name, like Pogoblaster 3000. Board mappings key "prettyModel" + DeviceDesignation, ///< Type designation, like NCC-1701. Beard mappings key "deviceDesignation" + }; /** * Edit modes for variables containing bitmasks diff --git a/libssu/ssudeviceinfo.cpp b/libssu/ssudeviceinfo.cpp index bdc2a51..5203360 100644 --- a/libssu/ssudeviceinfo.cpp +++ b/libssu/ssudeviceinfo.cpp @@ -308,6 +308,48 @@ QStringList SsuDeviceInfo::disabledRepos(){ return result; } +QString SsuDeviceInfo::displayName(const int type){ + QString model = deviceModel(); + QString variant = deviceVariant(false); + QString value, key; + + + switch (type){ + case Ssu::DeviceManufacturer: + key = "/deviceManufacturer"; + break; + case Ssu::DeviceModel: + key = "/prettyModel"; + break; + case Ssu::DeviceDesignation: + key = "/deviceDesignation"; + break; + default: + return ""; + } + + /* + * Go through different levels of fallbacks: + * 1. model specific setting + * 2. variant specific setting + * 3. global setting + * 4. return model name, or "UNKNOWN" in case query was for manufacturer + */ + + if (boardMappings->contains(model + key)) + value = boardMappings->value(model + key).toString(); + else if (variant != "" && boardMappings->contains(variant + key)) + value = boardMappings->value(variant + key).toString(); + else if (boardMappings->contains(key)) + value = boardMappings->value(key).toString(); + else if (type != Ssu::DeviceManufacturer) + value = model; + else + value = "UNKNOWN"; + + return value; +} + // this half belongs into repo-manager, as it not only handles board-specific // repositories. Right now this one looks like the better place due to the // connection to board specific stuff, though diff --git a/libssu/ssudeviceinfo.h b/libssu/ssudeviceinfo.h index d09120d..ce90063 100644 --- a/libssu/ssudeviceinfo.h +++ b/libssu/ssudeviceinfo.h @@ -62,6 +62,17 @@ class SsuDeviceInfo: public QObject { * This does not include repositories only disabled in the user configuration. */ QStringList disabledRepos(); + /** + * Return a string suitable for display in dialogs, ... + * + * See Ssu::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); /** * Return the complete list of repositories configured for a device. * Depending on the filter options, all repostories (user and board), diff --git a/rndssucli/rndssucli.cpp b/rndssucli/rndssucli.cpp index ca8a226..bc7ebdf 100644 --- a/rndssucli/rndssucli.cpp +++ b/rndssucli/rndssucli.cpp @@ -489,7 +489,9 @@ void RndSsuCli::optStatus(){ qout << "Device registration status: " << (ssu.isRegistered() ? "registered" : "not registered") << endl; - qout << "Device model: " << deviceInfo.deviceModel() << endl; + qout << "Device model: " << deviceInfo.displayName(Ssu::DeviceModel) << " (" + << deviceInfo.deviceModel() << " / " + << deviceInfo.displayName(Ssu::DeviceDesignation) << ")" << endl; if (deviceInfo.deviceVariant() != "") qout << "Device variant: " << deviceInfo.deviceVariant() << endl; qout << "Device UID: " << deviceUid << endl; diff --git a/ssud/ssud.cpp b/ssud/ssud.cpp index 17cf051..2816db1 100644 --- a/ssud/ssud.cpp +++ b/ssud/ssud.cpp @@ -79,6 +79,13 @@ QString Ssud::deviceVariant(){ return deviceInfo.deviceVariant(); } +QString Ssud::displayName(int type){ + SsuDeviceInfo deviceInfo; + + autoclose.start(); + return deviceInfo.displayName(type); +} + bool Ssud::error(){ autoclose.start(); return ssu.error(); diff --git a/ssud/ssud.h b/ssud/ssud.h index b42bad5..5537835 100644 --- a/ssud/ssud.h +++ b/ssud/ssud.h @@ -27,6 +27,7 @@ class Ssud: public QObject { QString deviceFamily(); QString deviceUid(); QString deviceVariant(); + QString displayName(int type); /* credential management */ bool isRegistered(); void registerDevice(const QString &username, const QString &password);