Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[ssu] Add methods to return pretty strings about devices for use in UI
  • Loading branch information
Bernd Wachter committed Oct 24, 2013
1 parent 98f1a03 commit 1960cf5
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 1 deletion.
6 changes: 6 additions & 0 deletions dbus/org.nemo.ssu.xml
Expand Up @@ -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">
Expand Down
8 changes: 8 additions & 0 deletions libssu/ssu.h
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions libssu/ssudeviceinfo.cpp
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions libssu/ssudeviceinfo.h
Expand Up @@ -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),
Expand Down
4 changes: 3 additions & 1 deletion rndssucli/rndssucli.cpp
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions ssud/ssud.cpp
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions ssud/ssud.h
Expand Up @@ -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);
Expand Down

0 comments on commit 1960cf5

Please sign in to comment.