#include "devicemanager.h"
#include <cassert>
-#include <cstring>
+#include <sstream>
#include <stdexcept>
#include <string>
return driver_devices;
}
+string DeviceManager::format_device_title(const sr_dev_inst *const sdi)
+{
+ ostringstream s;
+
+ assert(sdi);
+
+ if (sdi->vendor && sdi->vendor[0]) {
+ s << sdi->vendor;
+ if ((sdi->model && sdi->model[0]) ||
+ (sdi->version && sdi->version[0]))
+ s << ' ';
+ }
+
+ if (sdi->model && sdi->model[0]) {
+ s << sdi->model;
+ if (sdi->version && sdi->version[0])
+ s << ' ';
+ }
+
+ if (sdi->version && sdi->version[0])
+ s << sdi->version;
+
+ return s.str();
+}
+
void DeviceManager::init_drivers()
{
// Initialise all libsigrok drivers
bool DeviceManager::compare_devices(const sr_dev_inst *const a,
const sr_dev_inst *const b)
{
- assert(a);
- assert(b);
-
- const int vendor_cmp = strcasecmp(a->vendor, b->vendor);
- if(vendor_cmp < 0)
- return true;
- else if(vendor_cmp > 0)
- return false;
-
- const int model_cmp = strcasecmp(a->model, b->model);
- if(model_cmp < 0)
- return true;
- else if(model_cmp > 0)
- return false;
-
- return strcasecmp(a->version, b->version) < 0;
+ return format_device_title(a).compare(format_device_title(b)) < 0;
}
} // namespace pv
#include <glib.h>
#include <list>
+#include <string>
struct sr_context;
struct sr_dev_driver;
struct sr_dev_driver *const driver,
GSList *const drvopts = NULL);
+ static std::string format_device_title(const sr_dev_inst *const sdi);
+
private:
void init_drivers();
g_slist_free_full(drvopts, (GDestroyNotify)free_drvopts);
- BOOST_FOREACH(sr_dev_inst *const sdi, devices) {
-
- QString text;
- if (sdi->vendor && sdi->vendor[0])
- text += QString("%1 ").arg(sdi->vendor);
- if (sdi->model && sdi->model[0])
- text += QString("%1 ").arg(sdi->model);
- if (sdi->version && sdi->version[0])
- text += QString("%1 ").arg(sdi->version);
+ BOOST_FOREACH(sr_dev_inst *const sdi, devices)
+ {
+ const string title = DeviceManager::format_device_title(sdi);
+ QString text(title.c_str());
if (sdi->probes) {
- text += QString("with %1 probes").arg(
+ text += QString(" with %1 probes").arg(
g_slist_length(sdi->probes));
}
#include "samplingbar.h"
+#include <pv/devicemanager.h>
#include <pv/dialogs/deviceoptions.h>
+using namespace std;
+
namespace pv {
namespace toolbars {
_device_selector.clear();
BOOST_FOREACH (sr_dev_inst *sdi, devices) {
- QString title;
- if (sdi->vendor && sdi->vendor[0])
- title += sdi->vendor + QString(" ");
- if (sdi->model && sdi->model[0])
- title += sdi->model + QString(" ");
- if (sdi->version && sdi->version[0])
- title += sdi->version + QString(" ");
-
- _device_selector.addItem(title, qVariantFromValue(
- (void*)sdi));
+ const string title = DeviceManager::format_device_title(sdi);
+ _device_selector.addItem(title.c_str(),
+ qVariantFromValue((void*)sdi));
}
update_sample_rate_selector();