Simplify audio device description in combobox.

- Use of Map in Combobox.
- QML Combobox: Differentiate what we are displaying and the internal Object.
- Implement an equality operator for Objects (map).
This commit is contained in:
Julien Wadel 2024-11-15 19:48:57 +01:00
parent f40797af3b
commit 9fc3caa63c
10 changed files with 182 additions and 163 deletions

View file

@ -164,31 +164,34 @@ void SettingsCore::setSelf(QSharedPointer<SettingsCore> me) {
}); });
// Audio device(s) // Audio device(s)
mSettingsModelConnection->makeConnectToCore(&SettingsCore::lSetCaptureDevice, [this](const QString id) { mSettingsModelConnection->makeConnectToCore(&SettingsCore::lSetCaptureDevice, [this](QVariantMap device) {
mSettingsModelConnection->invokeToModel([this, id]() { SettingsModel::getInstance()->setCaptureDevice(id); }); mSettingsModelConnection->invokeToModel(
[this, device]() { SettingsModel::getInstance()->setCaptureDevice(device); });
}); });
mSettingsModelConnection->makeConnectToModel(&SettingsModel::captureDeviceChanged, [this](const QString device) { mSettingsModelConnection->makeConnectToModel(&SettingsModel::captureDeviceChanged, [this](QVariantMap device) {
mSettingsModelConnection->invokeToCore([this, device]() { mSettingsModelConnection->invokeToCore([this, device]() {
mCaptureDevice = device; mCaptureDevice = device;
emit captureDeviceChanged(device); emit captureDeviceChanged(device);
}); });
}); });
mSettingsModelConnection->makeConnectToCore(&SettingsCore::lSetPlaybackDevice, [this](const QString id) { mSettingsModelConnection->makeConnectToCore(&SettingsCore::lSetPlaybackDevice, [this](QVariantMap device) {
mSettingsModelConnection->invokeToModel([this, id]() { SettingsModel::getInstance()->setPlaybackDevice(id); }); mSettingsModelConnection->invokeToModel(
[this, device]() { SettingsModel::getInstance()->setPlaybackDevice(device); });
}); });
mSettingsModelConnection->makeConnectToModel(&SettingsModel::playbackDeviceChanged, [this](const QString device) { mSettingsModelConnection->makeConnectToModel(&SettingsModel::playbackDeviceChanged, [this](QVariantMap device) {
mSettingsModelConnection->invokeToCore([this, device]() { mSettingsModelConnection->invokeToCore([this, device]() {
mPlaybackDevice = device; mPlaybackDevice = device;
emit playbackDeviceChanged(device); emit playbackDeviceChanged(device);
}); });
}); });
mSettingsModelConnection->makeConnectToCore(&SettingsCore::lSetRingerDevice, [this](const QString id) { mSettingsModelConnection->makeConnectToCore(&SettingsCore::lSetRingerDevice, [this](QVariantMap device) {
mSettingsModelConnection->invokeToModel([this, id]() { SettingsModel::getInstance()->setRingerDevice(id); }); mSettingsModelConnection->invokeToModel(
[this, device]() { SettingsModel::getInstance()->setRingerDevice(device); });
}); });
mSettingsModelConnection->makeConnectToModel(&SettingsModel::ringerDeviceChanged, [this](const QString device) { mSettingsModelConnection->makeConnectToModel(&SettingsModel::ringerDeviceChanged, [this](QVariantMap device) {
mSettingsModelConnection->invokeToCore([this, device]() { mSettingsModelConnection->invokeToCore([this, device]() {
mRingerDevice = device; mRingerDevice = device;
emit ringerDeviceChanged(device); emit ringerDeviceChanged(device);
@ -223,28 +226,25 @@ void SettingsCore::setSelf(QSharedPointer<SettingsCore> me) {
mSettingsModelConnection->invokeToCore([this, value]() { emit micVolumeChanged(value); }); mSettingsModelConnection->invokeToCore([this, value]() { emit micVolumeChanged(value); });
}); });
mSettingsModelConnection->makeConnectToModel(&SettingsModel::captureDevicesChanged, mSettingsModelConnection->makeConnectToModel(&SettingsModel::captureDevicesChanged, [this](QVariantList devices) {
[this](const QStringList devices) { mSettingsModelConnection->invokeToCore([this, devices]() {
mSettingsModelConnection->invokeToCore([this, devices]() { mCaptureDevices = devices;
mCaptureDevices = devices; emit captureDevicesChanged(devices);
emit captureDevicesChanged(devices); });
}); });
});
mSettingsModelConnection->makeConnectToModel(&SettingsModel::playbackDevicesChanged, mSettingsModelConnection->makeConnectToModel(&SettingsModel::playbackDevicesChanged, [this](QVariantList devices) {
[this](const QStringList devices) { mSettingsModelConnection->invokeToCore([this, devices]() {
mSettingsModelConnection->invokeToCore([this, devices]() { mPlaybackDevices = devices;
mPlaybackDevices = devices; emit playbackDevicesChanged(devices);
emit playbackDevicesChanged(devices); });
}); });
}); mSettingsModelConnection->makeConnectToModel(&SettingsModel::ringerDevicesChanged, [this](QVariantList devices) {
mSettingsModelConnection->makeConnectToModel(&SettingsModel::ringerDevicesChanged, mSettingsModelConnection->invokeToCore([this, devices]() {
[this](const QStringList devices) { mRingerDevices = devices;
mSettingsModelConnection->invokeToCore([this, devices]() { emit ringerDevicesChanged(devices);
mRingerDevices = devices; });
emit ringerDevicesChanged(devices); });
});
});
// Video device(s) // Video device(s)
mSettingsModelConnection->makeConnectToCore(&SettingsCore::lSetVideoDevice, [this](const QString id) { mSettingsModelConnection->makeConnectToCore(&SettingsCore::lSetVideoDevice, [this](const QString id) {
@ -379,15 +379,15 @@ QString SettingsCore::getConfigPath(const QCommandLineParser &parser) {
return configPath; return configPath;
} }
QStringList SettingsCore::getCaptureDevices() const { QVariantList SettingsCore::getCaptureDevices() const {
return mCaptureDevices; return mCaptureDevices;
} }
QStringList SettingsCore::getPlaybackDevices() const { QVariantList SettingsCore::getPlaybackDevices() const {
return mPlaybackDevices; return mPlaybackDevices;
} }
QStringList SettingsCore::getRingerDevices() const { QVariantList SettingsCore::getRingerDevices() const {
return mRingerDevices; return mRingerDevices;
} }
@ -411,15 +411,15 @@ float SettingsCore::getPlaybackGain() const {
return mPlaybackGain; return mPlaybackGain;
} }
QString SettingsCore::getCaptureDevice() const { QVariantMap SettingsCore::getCaptureDevice() const {
return mCaptureDevice; return mCaptureDevice;
} }
QString SettingsCore::getPlaybackDevice() const { QVariantMap SettingsCore::getPlaybackDevice() const {
return mPlaybackDevice; return mPlaybackDevice;
} }
QString SettingsCore::getRingerDevice() const { QVariantMap SettingsCore::getRingerDevice() const {
return mRingerDevice; return mRingerDevice;
} }

View file

@ -46,16 +46,16 @@ class SettingsCore : public QObject, public AbstractObject {
Q_PROPERTY(bool captureGraphRunning READ getCaptureGraphRunning NOTIFY captureGraphRunningChanged) Q_PROPERTY(bool captureGraphRunning READ getCaptureGraphRunning NOTIFY captureGraphRunningChanged)
Q_PROPERTY(QStringList captureDevices READ getCaptureDevices NOTIFY captureDevicesChanged) Q_PROPERTY(QVariantList captureDevices READ getCaptureDevices NOTIFY captureDevicesChanged)
Q_PROPERTY(QStringList playbackDevices READ getPlaybackDevices NOTIFY playbackDevicesChanged) Q_PROPERTY(QVariantList playbackDevices READ getPlaybackDevices NOTIFY playbackDevicesChanged)
Q_PROPERTY(QStringList ringerDevices READ getRingerDevices NOTIFY ringerDevicesChanged) Q_PROPERTY(QVariantList ringerDevices READ getRingerDevices NOTIFY ringerDevicesChanged)
Q_PROPERTY(float playbackGain READ getPlaybackGain WRITE lSetPlaybackGain NOTIFY playbackGainChanged) Q_PROPERTY(float playbackGain READ getPlaybackGain WRITE lSetPlaybackGain NOTIFY playbackGainChanged)
Q_PROPERTY(float captureGain READ getCaptureGain WRITE lSetCaptureGain NOTIFY captureGainChanged) Q_PROPERTY(float captureGain READ getCaptureGain WRITE lSetCaptureGain NOTIFY captureGainChanged)
Q_PROPERTY(QString captureDevice READ getCaptureDevice WRITE lSetCaptureDevice NOTIFY captureDeviceChanged) Q_PROPERTY(QVariantMap captureDevice READ getCaptureDevice WRITE lSetCaptureDevice NOTIFY captureDeviceChanged)
Q_PROPERTY(QString playbackDevice READ getPlaybackDevice WRITE lSetPlaybackDevice NOTIFY playbackDeviceChanged) Q_PROPERTY(QVariantMap playbackDevice READ getPlaybackDevice WRITE lSetPlaybackDevice NOTIFY playbackDeviceChanged)
Q_PROPERTY(QString ringerDevice READ getRingerDevice WRITE lSetRingerDevice NOTIFY ringerDeviceChanged) Q_PROPERTY(QVariantMap ringerDevice READ getRingerDevice WRITE lSetRingerDevice NOTIFY ringerDeviceChanged)
Q_PROPERTY(QStringList videoDevices READ getVideoDevices NOTIFY videoDevicesChanged) Q_PROPERTY(QStringList videoDevices READ getVideoDevices NOTIFY videoDevicesChanged)
Q_PROPERTY(QString videoDevice READ getVideoDevice WRITE lSetVideoDevice NOTIFY videoDeviceChanged) Q_PROPERTY(QString videoDevice READ getVideoDevice WRITE lSetVideoDevice NOTIFY videoDeviceChanged)
@ -109,14 +109,13 @@ public:
float getCaptureGain() const; float getCaptureGain() const;
QStringList getCaptureDevices() const; QVariantList getCaptureDevices() const;
QStringList getPlaybackDevices() const; QVariantList getPlaybackDevices() const;
QStringList getRingerDevices() const; QVariantList getRingerDevices() const;
QString getCaptureDevice() const; QVariantMap getCaptureDevice() const;
QVariantMap getPlaybackDevice() const;
QString getPlaybackDevice() const; QVariantMap getRingerDevice() const;
QString getRingerDevice() const;
QString getVideoDevice() const { QString getVideoDevice() const {
return mVideoDevice; return mVideoDevice;
@ -191,18 +190,18 @@ signals:
void playbackGainChanged(float gain); void playbackGainChanged(float gain);
void captureGainChanged(float gain); void captureGainChanged(float gain);
void captureDevicesChanged(const QStringList &devices); void captureDevicesChanged(const QVariantList &devices);
void playbackDevicesChanged(const QStringList &devices); void playbackDevicesChanged(const QVariantList &devices);
void ringerDevicesChanged(const QStringList &devices); void ringerDevicesChanged(const QVariantList &devices);
void lSetCaptureDevice(const QString &device); void lSetCaptureDevice(const QVariantMap &device);
void captureDeviceChanged(const QString &device); void captureDeviceChanged(const QVariantMap &device);
void lSetPlaybackDevice(const QString &device); void lSetPlaybackDevice(const QVariantMap &device);
void playbackDeviceChanged(const QString &device); void playbackDeviceChanged(const QVariantMap &device);
void lSetRingerDevice(const QString &device); void lSetRingerDevice(const QVariantMap &device);
void ringerDeviceChanged(const QString &device); void ringerDeviceChanged(const QVariantMap &device);
void lSetVideoDevice(const QString &device); void lSetVideoDevice(const QString &device);
void videoDeviceChanged(); void videoDeviceChanged();
@ -247,12 +246,12 @@ private:
bool mAutomaticallyRecordCallsEnabled; bool mAutomaticallyRecordCallsEnabled;
// Audio // Audio
QStringList mCaptureDevices; QVariantList mCaptureDevices;
QStringList mPlaybackDevices; QVariantList mPlaybackDevices;
QStringList mRingerDevices; QVariantList mRingerDevices;
QString mCaptureDevice; QVariantMap mCaptureDevice;
QString mPlaybackDevice; QVariantMap mPlaybackDevice;
QString mRingerDevice; QVariantMap mRingerDevice;
// Video // Video
QStringList mVideoDevices; QStringList mVideoDevices;

View file

@ -88,27 +88,6 @@ std::string SettingsModel::getEntryFullName(const std::string &section, const st
return isReadOnly(section, name) ? name + "/readonly" : name; return isReadOnly(section, name) ? name + "/readonly" : name;
} }
QStringList SettingsModel::getVideoDevices() const {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
auto core = CoreModel::getInstance()->getCore();
QStringList result;
for (auto &device : core->getVideoDevicesList()) {
result.append(Utils::coreStringToAppString(device));
}
return result;
}
QString SettingsModel::getVideoDevice() const {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
return Utils::coreStringToAppString(CoreModel::getInstance()->getCore()->getVideoDevice());
}
void SettingsModel::setVideoDevice(const QString &device) {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
CoreModel::getInstance()->getCore()->setVideoDevice(Utils::appStringToCoreString(device));
emit videoDeviceChanged(device);
}
// ============================================================================= // =============================================================================
// Audio. // Audio.
// ============================================================================= // =============================================================================
@ -125,8 +104,9 @@ void SettingsModel::resetCaptureGraph() {
} }
void SettingsModel::createCaptureGraph() { void SettingsModel::createCaptureGraph() {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
mSimpleCaptureGraph = new MediastreamerUtils::SimpleCaptureGraph(Utils::appStringToCoreString(getCaptureDevice()), mSimpleCaptureGraph =
Utils::appStringToCoreString(getPlaybackDevice())); new MediastreamerUtils::SimpleCaptureGraph(Utils::appStringToCoreString(getCaptureDevice()["id"].toString()),
Utils::appStringToCoreString(getPlaybackDevice()["id"].toString()));
mSimpleCaptureGraph->start(); mSimpleCaptureGraph->start();
emit captureGraphRunningChanged(getCaptureGraphRunning()); emit captureGraphRunningChanged(getCaptureGraphRunning());
} }
@ -245,56 +225,68 @@ void SettingsModel::setCaptureGain(float gain) {
if ((int)(oldGain * 1000) != (int)(gain * 1000)) emit captureGainChanged(gain); if ((int)(oldGain * 1000) != (int)(gain * 1000)) emit captureGainChanged(gain);
} }
QStringList SettingsModel::getCaptureDevices() const { QVariantList SettingsModel::getCaptureDevices() const {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
shared_ptr<linphone::Core> core = CoreModel::getInstance()->getCore(); shared_ptr<linphone::Core> core = CoreModel::getInstance()->getCore();
QStringList list; QVariantList list;
for (const auto &device : core->getExtendedAudioDevices()) { for (const auto &device : core->getExtendedAudioDevices()) {
if (device->hasCapability(linphone::AudioDevice::Capabilities::CapabilityRecord)) if (device->hasCapability(linphone::AudioDevice::Capabilities::CapabilityRecord)) {
list << Utils::coreStringToAppString(device->getId()); list << ToolModel::createVariant(device);
}
} }
return list; return list;
} }
QStringList SettingsModel::getPlaybackDevices() const { QVariantList SettingsModel::getPlaybackDevices() const {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
shared_ptr<linphone::Core> core = CoreModel::getInstance()->getCore(); shared_ptr<linphone::Core> core = CoreModel::getInstance()->getCore();
QStringList list; QVariantList list;
for (const auto &device : core->getExtendedAudioDevices()) { for (const auto &device : core->getExtendedAudioDevices()) {
if (device->hasCapability(linphone::AudioDevice::Capabilities::CapabilityPlay)) if (device->hasCapability(linphone::AudioDevice::Capabilities::CapabilityPlay))
list << Utils::coreStringToAppString(device->getId()); list << ToolModel::createVariant(device);
} }
return list; return list;
} }
QStringList SettingsModel::getRingerDevices() const { QVariantList SettingsModel::getRingerDevices() const {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
shared_ptr<linphone::Core> core = CoreModel::getInstance()->getCore(); shared_ptr<linphone::Core> core = CoreModel::getInstance()->getCore();
QStringList list; QVariantList list;
for (const auto &device : core->getExtendedAudioDevices()) { for (const auto &device : core->getExtendedAudioDevices()) {
if (device->hasCapability(linphone::AudioDevice::Capabilities::CapabilityPlay)) if (device->hasCapability(linphone::AudioDevice::Capabilities::CapabilityPlay))
list << Utils::coreStringToAppString(device->getId()); list << ToolModel::createVariant(device);
} }
return list; return list;
} }
QStringList SettingsModel::getVideoDevices() const {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
auto core = CoreModel::getInstance()->getCore();
QStringList result;
for (auto &device : core->getVideoDevicesList()) {
result.append(Utils::coreStringToAppString(device));
}
return result;
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
QString SettingsModel::getCaptureDevice() const { QVariantMap SettingsModel::getCaptureDevice() const {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
auto audioDevice = CoreModel::getInstance()->getCore()->getInputAudioDevice(); auto audioDevice = CoreModel::getInstance()->getCore()->getInputAudioDevice();
if (!audioDevice) audioDevice = CoreModel::getInstance()->getCore()->getDefaultInputAudioDevice(); if (!audioDevice) audioDevice = CoreModel::getInstance()->getCore()->getDefaultInputAudioDevice();
return Utils::coreStringToAppString(audioDevice ? audioDevice->getId() : ""); return ToolModel::createVariant(audioDevice);
} }
void SettingsModel::setCaptureDevice(const QString &device) { void SettingsModel::setCaptureDevice(const QVariantMap &device) {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
auto audioDevice = ToolModel::findAudioDevice(device, linphone::AudioDevice::Capabilities::CapabilityRecord); auto audioDevice =
ToolModel::findAudioDevice(device["id"].toString(), linphone::AudioDevice::Capabilities::CapabilityRecord);
if (audioDevice) { if (audioDevice) {
CoreModel::getInstance()->getCore()->setDefaultInputAudioDevice(audioDevice); CoreModel::getInstance()->getCore()->setDefaultInputAudioDevice(audioDevice);
CoreModel::getInstance()->getCore()->setInputAudioDevice(audioDevice); CoreModel::getInstance()->getCore()->setInputAudioDevice(audioDevice);
@ -305,16 +297,17 @@ void SettingsModel::setCaptureDevice(const QString &device) {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
QString SettingsModel::getPlaybackDevice() const { QVariantMap SettingsModel::getPlaybackDevice() const {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
auto audioDevice = CoreModel::getInstance()->getCore()->getOutputAudioDevice(); auto audioDevice = CoreModel::getInstance()->getCore()->getOutputAudioDevice();
if (!audioDevice) audioDevice = CoreModel::getInstance()->getCore()->getDefaultOutputAudioDevice(); if (!audioDevice) audioDevice = CoreModel::getInstance()->getCore()->getDefaultOutputAudioDevice();
return Utils::coreStringToAppString(audioDevice ? audioDevice->getId() : ""); return ToolModel::createVariant(audioDevice);
} }
void SettingsModel::setPlaybackDevice(const QString &device) { void SettingsModel::setPlaybackDevice(const QVariantMap &device) {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
auto audioDevice = ToolModel::findAudioDevice(device, linphone::AudioDevice::Capabilities::CapabilityPlay); auto audioDevice =
ToolModel::findAudioDevice(device["id"].toString(), linphone::AudioDevice::Capabilities::CapabilityPlay);
if (audioDevice) { if (audioDevice) {
CoreModel::getInstance()->getCore()->setDefaultOutputAudioDevice(audioDevice); CoreModel::getInstance()->getCore()->setDefaultOutputAudioDevice(audioDevice);
CoreModel::getInstance()->getCore()->setOutputAudioDevice(audioDevice); CoreModel::getInstance()->getCore()->setOutputAudioDevice(audioDevice);
@ -325,22 +318,32 @@ void SettingsModel::setPlaybackDevice(const QString &device) {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
QString SettingsModel::getRingerDevice() const { QVariantMap SettingsModel::getRingerDevice() const {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
return Utils::coreStringToAppString(CoreModel::getInstance()->getCore()->getRingerDevice()); auto id = Utils::coreStringToAppString(CoreModel::getInstance()->getCore()->getRingerDevice());
auto audioDevice = ToolModel::findAudioDevice(id, linphone::AudioDevice::Capabilities::CapabilityPlay);
return ToolModel::createVariant(audioDevice);
} }
void SettingsModel::setRingerDevice(const QString &device) { void SettingsModel::setRingerDevice(const QVariantMap &device) {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
auto audioDevice = ToolModel::findAudioDevice(device, linphone::AudioDevice::Capabilities::CapabilityPlay); CoreModel::getInstance()->getCore()->setRingerDevice(Utils::appStringToCoreString(device["id"].toString()));
emit ringerDeviceChanged(device);
if (audioDevice) {
CoreModel::getInstance()->getCore()->setRingerDevice(audioDevice->getId());
emit ringerDeviceChanged(device);
} else qWarning() << "Cannot set Ringer device. The ID cannot be matched with an existant device : " << device;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
QString SettingsModel::getVideoDevice() const {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
return Utils::coreStringToAppString(CoreModel::getInstance()->getCore()->getVideoDevice());
}
void SettingsModel::setVideoDevice(const QString &device) {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
CoreModel::getInstance()->getCore()->setVideoDevice(Utils::appStringToCoreString(device));
emit videoDeviceChanged(device);
}
bool SettingsModel::getVideoEnabled() const { bool SettingsModel::getVideoEnabled() const {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
return CoreModel::getInstance()->getCore()->videoEnabled(); return CoreModel::getInstance()->getCore()->videoEnabled();

View file

@ -82,27 +82,26 @@ public:
float getCaptureGain() const; float getCaptureGain() const;
void setCaptureGain(float gain); void setCaptureGain(float gain);
QStringList getCaptureDevices() const; QVariantList getCaptureDevices() const;
QStringList getPlaybackDevices() const; QVariantList getPlaybackDevices() const;
QStringList getRingerDevices() const; QVariantList getRingerDevices() const;
QStringList getVideoDevices() const; // There is no VideoDevice API from SDK
QString getCaptureDevice() const; QVariantMap getCaptureDevice() const;
void setCaptureDevice(const QString &device); void setCaptureDevice(const QVariantMap &device);
QString getPlaybackDevice() const; QVariantMap getPlaybackDevice() const;
void setPlaybackDevice(const QString &device); void setPlaybackDevice(const QVariantMap &device);
QString getRingerDevice() const; QVariantMap getRingerDevice() const;
void setRingerDevice(const QString &device); void setRingerDevice(const QVariantMap &device);
void startEchoCancellerCalibration();
int getEchoCancellationCalibration() const;
QStringList getVideoDevices() const;
QString getVideoDevice() const; QString getVideoDevice() const;
void setVideoDevice(const QString &device); void setVideoDevice(const QString &device);
void startEchoCancellerCalibration();
int getEchoCancellationCalibration() const;
bool getLogsEnabled() const; bool getLogsEnabled() const;
void setLogsEnabled(bool status); void setLogsEnabled(bool status);
@ -172,19 +171,18 @@ signals:
void playbackGainChanged(float gain); void playbackGainChanged(float gain);
void captureGainChanged(float gain); void captureGainChanged(float gain);
void captureDevicesChanged(const QStringList &devices); void captureDevicesChanged(QVariantList devices);
void playbackDevicesChanged(const QStringList &devices); void playbackDevicesChanged(QVariantList devices);
void ringerDevicesChanged(const QStringList &devices); void ringerDevicesChanged(QVariantList devices);
void videoDevicesChanged(QStringList devices);
void captureDeviceChanged(const QString &device); void captureDeviceChanged(QVariantMap device);
void playbackDeviceChanged(const QString &device); void playbackDeviceChanged(QVariantMap device);
void ringerDeviceChanged(const QString &device); void ringerDeviceChanged(QVariantMap device);
void videoDeviceChanged(QString device);
void showAudioCodecsChanged(bool status); void showAudioCodecsChanged(bool status);
void videoDevicesChanged(const QStringList &devices);
void videoDeviceChanged(const QString &device);
void micVolumeChanged(float volume); void micVolumeChanged(float volume);
void logsEnabledChanged(bool status); void logsEnabledChanged(bool status);

View file

@ -350,3 +350,12 @@ void ToolModel::updateCodecs() {
} }
#endif // if defined(Q_OS_LINUX) || defined(Q_OS_WIN) #endif // if defined(Q_OS_LINUX) || defined(Q_OS_WIN)
} }
QVariantMap ToolModel::createVariant(const std::shared_ptr<const linphone::AudioDevice> &device) {
QVariantMap map;
map.insert("id", device ? Utils::coreStringToAppString(device->getId()) : "");
map.insert("display_name",
device ? Utils::coreStringToAppString(device->getDriverName() + ": " + device->getDeviceName())
: tr("Unknown device"));
return map;
}

View file

@ -68,6 +68,8 @@ public:
static void loadDownloadedCodecs(); static void loadDownloadedCodecs();
static void updateCodecs(); static void updateCodecs();
static QVariantMap createVariant(const std::shared_ptr<const linphone::AudioDevice> &device);
private: private:
DECLARE_ABSTRACT_OBJECT DECLARE_ABSTRACT_OBJECT
}; };

View file

@ -9,8 +9,6 @@ Control.ComboBox {
// Usage : each item of the model list must be {text: ..., img: ...} // Usage : each item of the model list must be {text: ..., img: ...}
// If string list, only text part of the delegate will be filled // If string list, only text part of the delegate will be filled
// readonly property string currentText: selectedItemText.text // readonly property string currentText: selectedItemText.text
// Layout.preferredWidth: mainItem.width
// Layout.preferredHeight: mainItem.height
property alias listView: listView property alias listView: listView
property string constantImageSource property string constantImageSource
property int pixelSize: 14 * DefaultStyle.dp property int pixelSize: 14 * DefaultStyle.dp
@ -24,7 +22,9 @@ Control.ComboBox {
var item = model[currentIndex] var item = model[currentIndex]
if (!item) item = model.getAt(currentIndex) if (!item) item = model.getAt(currentIndex)
if (!item) return if (!item) return
selectedItemText.text = item.text selectedItemText.text = mainItem.textRole
? item[mainItem.textRole]
: item.text
? item.text ? item.text
: item : item
? item ? item
@ -99,19 +99,6 @@ Control.ComboBox {
anchors.rightMargin: 20 * DefaultStyle.dp anchors.rightMargin: 20 * DefaultStyle.dp
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
Component.onCompleted: {
var index = mainItem.currentIndex < 0 ? 0 : mainItem.currentIndex
if (mainItem.model && mainItem.model[index]) {
if (mainItem.model[index] && mainItem.model[index].img) {
selectedItemImg.source = mainItem.model[index].img
}
else if (mainItem.model[index] && mainItem.model[index].text)
selectedItemText.text = mainItem.model[index].text
else
selectedItemText.text = mainItem.model[index]
}
}
} }
@ -183,11 +170,15 @@ Control.ComboBox {
Text { Text {
text: typeof(modelData) != "undefined" text: typeof(modelData) != "undefined"
? modelData.text ? mainItem.textRole
? modelData.text ? modelData[mainItem.textRole]
: modelData : modelData.text
? modelData.text
: modelData
: $modelData : $modelData
? $modelData ? mainItem.textRole
? $modelData[mainItem.textRole]
: $modelData
: "" : ""
elide: Text.ElideRight elide: Text.ElideRight
maximumLineCount: 1 maximumLineCount: 1

View file

@ -5,23 +5,24 @@ import Linphone
import 'qrc:/qt/qml/Linphone/view/Control/Tool/Helper/utils.js' as Utils import 'qrc:/qt/qml/Linphone/view/Control/Tool/Helper/utils.js' as Utils
ComboBox { ComboBox {
id: comboBox id: mainItem
Layout.preferredHeight: 49 * DefaultStyle.dp Layout.preferredHeight: 49 * DefaultStyle.dp
property string propertyName property string propertyName
property var propertyOwner property var propertyOwner
property alias entries: comboBox.model property alias entries: mainItem.model
oneLine: true oneLine: true
currentIndex: Utils.findIndex(model, function (entry) { currentIndex: Utils.findIndex(model, function (entry) {
return entry === propertyOwner[propertyName] return Utils.equalObject(entry,propertyOwner[propertyName])
}) })
onCurrentTextChanged: { onCurrentValueChanged: {
binding.when = currentText != propertyOwner[propertyName] binding.when = !Utils.equalObject(currentValue,propertyOwner[propertyName])
} }
Binding { Binding {
id: binding id: binding
target: propertyOwner target: propertyOwner
property: propertyName property: propertyName
value: comboBox.currentText value: mainItem.currentValue
when: false when: false
} }
} }

View file

@ -53,6 +53,7 @@ ColumnLayout {
entries: SettingsCpp.ringerDevices entries: SettingsCpp.ringerDevices
propertyName: "ringerDevice" propertyName: "ringerDevice"
propertyOwner: SettingsCpp propertyOwner: SettingsCpp
textRole: 'display_name'
} }
Item { Item {
Layout.fillHeight: true Layout.fillHeight: true
@ -84,6 +85,7 @@ ColumnLayout {
entries: SettingsCpp.playbackDevices entries: SettingsCpp.playbackDevices
propertyName: "playbackDevice" propertyName: "playbackDevice"
propertyOwner: SettingsCpp propertyOwner: SettingsCpp
textRole: 'display_name'
} }
Slider { Slider {
id: speakerVolume id: speakerVolume
@ -123,6 +125,7 @@ ColumnLayout {
entries: SettingsCpp.captureDevices entries: SettingsCpp.captureDevices
propertyName: "captureDevice" propertyName: "captureDevice"
propertyOwner: SettingsCpp propertyOwner: SettingsCpp
textRole: 'display_name'
} }
Slider { Slider {
id: microVolume id: microVolume

View file

@ -728,6 +728,19 @@ function printObject(o) {
return out; return out;
} }
function equalObject(a, b) {
var countA = 0, countB = 0;
if(a == b) return true // operator could be performed
for (var i in a) {// Check for all members
if(a[i] != b[i]) return false
else ++countA
}
for (var j in b) {// Check count
++countB
}
return countB == countA && countA > 0 // if count=0; then the first '==' should already worked
}
function infoDialog(window, message) { function infoDialog(window, message) {
window.attachVirtualWindow(buildCommonDialogUri('ConfirmDialog'), { window.attachVirtualWindow(buildCommonDialogUri('ConfirmDialog'), {
buttonTexts : ['',qsTr('okButton')], buttonTexts : ['',qsTr('okButton')],