Commit 631fa84e authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Simplify code that chooses camera

parent d4d62489
......@@ -78,7 +78,7 @@ DeviceManager::DeviceManager() : m_playingDevice(0)
g_list_free (devices);
if (!m_deviceList.isEmpty()) {
setPlayingObjectId(m_deviceList.constFirst()->objectId());
setPlayingDevice(m_deviceList.constFirst());
}
}
......@@ -112,40 +112,23 @@ int DeviceManager::rowCount(const QModelIndex& idx) const
return idx.isValid() ? 0 : m_deviceList.size();
}
void DeviceManager::setPlayingObjectId(const QString &objectId)
void DeviceManager::setPlayingDevice(Device* device)
{
Q_FOREACH(Device* d, m_deviceList) {
if(d->objectId() == objectId) {
if (m_playingDevice != d) {
m_playingDevice = d;
qDebug() << "Playing device changed" << d->description();
Q_EMIT playingDeviceChanged();
}
return;
}
}
if (device == m_playingDevice)
return;
qWarning() << "could not find device" << objectId;
m_playingDevice = nullptr;
m_playingDevice = device;
Q_EMIT playingDeviceChanged();
}
Device* DeviceManager::playingDevice()
Device* DeviceManager::playingDevice() const
{
return m_playingDevice;
}
QString DeviceManager::playingObjectId() const
{
if (!m_playingDevice) {
return {};
}
return m_playingDevice->objectId();
}
QString DeviceManager::objectIdAt(int i) const
Device* DeviceManager::deviceAt(int i) const
{
return m_deviceList[i]->objectId();
return m_deviceList[i];
}
QVariant DeviceManager::data(const QModelIndex& index, int role) const
......@@ -179,7 +162,7 @@ void DeviceManager::deviceAdded(GstDevice* device)
endInsertRows();
if (!m_playingDevice) {
setPlayingObjectId(m_deviceList.first()->objectId());
setPlayingDevice(m_deviceList.constFirst());
}
}
......@@ -191,8 +174,7 @@ void DeviceManager::deviceRemoved(GstDevice* device)
for(int i = 0, c = m_deviceList.size(); i<c; ++i) {
auto dev = m_deviceList.at(i);
if (m_playingDevice == dev) {
m_playingDevice = nullptr;
Q_EMIT playingDeviceChanged();
setPlayingDevice(nullptr);
}
if (dev->objectId() == objectId) {
......
......@@ -30,9 +30,8 @@ struct _GstDeviceMonitor;
class DeviceManager : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(QString playingObjectId READ playingObjectId WRITE setPlayingObjectId NOTIFY playingDeviceChanged)
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
Q_PROPERTY(Device* playingDevice READ playingDevice NOTIFY playingDeviceChanged)
Q_PROPERTY(Device* playingDevice READ playingDevice WRITE setPlayingDevice NOTIFY playingDeviceChanged)
public:
static DeviceManager* self();
enum {
......@@ -40,9 +39,8 @@ class DeviceManager : public QAbstractListModel
};
virtual QHash<int, QByteArray> roleNames() const override;
Device* playingDevice();
QString playingObjectId() const;
void setPlayingObjectId(const QString &objectId);
Device* playingDevice() const;
void setPlayingDevice(Device* device);
bool hasDevices() const;
virtual int rowCount(const QModelIndex& = QModelIndex()) const override;
......@@ -51,7 +49,7 @@ class DeviceManager : public QAbstractListModel
void deviceRemoved(_GstDevice *device);
void deviceAdded(_GstDevice *device);
Q_SCRIPTABLE QString objectIdAt(int i) const;
Q_SCRIPTABLE Device* deviceAt(int i) const;
public Q_SLOTS:
void save();
......
......@@ -301,7 +301,7 @@ StackView {
textRole: "display"
visible: count>1
onActivated: {
devicesModel.playingObjectId = devicesModel.objectIdAt(index)
devicesModel.playingDevice = devicesModel.deviceAt(index)
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment