Skip to content
Permalink
Browse files
[ssu] Add methods to return pretty strings about devices for use in UI
  • Loading branch information
bwachter committed Oct 24, 2013
1 parent 98f1a03 commit 1960cf53f13382b809dc944f06f6e0d6610b3d74
Showing with 78 additions and 1 deletion.
  1. +6 −0 dbus/org.nemo.ssu.xml
  2. +8 −0 libssu/ssu.h
  3. +42 −0 libssu/ssudeviceinfo.cpp
  4. +11 −0 libssu/ssudeviceinfo.h
  5. +3 −1 rndssucli/rndssucli.cpp
  6. +7 −0 ssud/ssud.cpp
  7. +1 −0 ssud/ssud.h
@@ -49,6 +49,12 @@
<method name="deviceVariant">
<arg direction="out" type="s" name="model"/>
</method>
<!-- return a model-specific string suitable for displaying -->
<!-- see documentation of Ssu::DisplayType for supported types -->
<method name="displayName">
<arg direction="out" type="s" name="label"/>
<arg direction="in" type="i" name="type" />
</method>

<!-- repository management -->
<method name="deviceMode">
@@ -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
@@ -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
@@ -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),
@@ -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;
@@ -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();
@@ -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);

0 comments on commit 1960cf5

Please sign in to comment.