Skip to content

Commit

Permalink
fix: add bluetooth mode setting (#1901)
Browse files Browse the repository at this point in the history
add bluetooth mode setting

Log: add bluetooth mode setting
pms: BUG-291887
pms: BUG-291843

Co-authored-by: swq <[email protected]>
  • Loading branch information
swq11 and swq authored Dec 11, 2024
1 parent 1645fa4 commit f047220
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 10 deletions.
15 changes: 15 additions & 0 deletions src/plugin-sound/operation/soundmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ SoundModel::SoundModel(QObject *parent)
, m_soundOutputDeviceModel(new SoundDeviceModel(this))
, m_soundInputDeviceModel(new SoundDeviceModel(this))
, m_audioServerModel(new AudioServerModel(this))
, m_showBluetoothMode(false)
{
m_soundEffectMapBattery = {
{ tr("Boot up"), DDesktopServices::SSE_BootUp },
Expand Down Expand Up @@ -202,6 +203,7 @@ void SoundModel::setActiveOutPutPort(Port *newActiveOutPutPort)
{
m_activeOutPutPort = newActiveOutPutPort;
setOutPutPortComboIndex(m_outPutPortCombo.indexOf(m_activeOutPutPort->name() + "(" + m_activeOutPutPort->cardName() + ")"));
setShowBluetoothMode(m_activeOutPutPort->isBluetoothPort());
}

int SoundModel::outPutPortComboIndex() const
Expand Down Expand Up @@ -648,6 +650,19 @@ void SoundModel::setAudioMono(bool newAudioMono)
emit audioMonoChanged();
}

bool SoundModel::showBluetoothMode() const
{
return m_showBluetoothMode;
}

void SoundModel::setShowBluetoothMode(bool newShowBluetoothMode)
{
if (m_showBluetoothMode == newShowBluetoothMode)
return;
m_showBluetoothMode = newShowBluetoothMode;
emit showBluetoothModeChanged();
}

void SoundModel::setInPutPortCount(int newInPutPortCount)
{
if (m_inPutPortCount == newInPutPortCount)
Expand Down
9 changes: 9 additions & 0 deletions src/plugin-sound/operation/soundmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class SoundModel : public QObject
Q_PROPERTY(int outPutCount READ outPutCount NOTIFY outPutCountChanged FINAL)
Q_PROPERTY(bool audioServerStatus READ audioServerChangedState NOTIFY onSetAudioServerFinish FINAL)
Q_PROPERTY(bool audioMono READ audioMono NOTIFY audioMonoChanged FINAL)
Q_PROPERTY(QStringList bluetoothModeOpts READ bluetoothAudioModeOpts NOTIFY bluetoothModeOptsChanged FINAL)
Q_PROPERTY(QString currentBluetoothAudioMode READ currentBluetoothAudioMode NOTIFY bluetoothModeChanged FINAL)
Q_PROPERTY(bool showBluetoothMode READ showBluetoothMode NOTIFY showBluetoothModeChanged FINAL)

QML_NAMED_ELEMENT(SoundModel)
QML_SINGLETON
Expand Down Expand Up @@ -196,6 +199,9 @@ class SoundModel : public QObject
bool audioMono() const;
void setAudioMono(bool newAudioMono);

bool showBluetoothMode() const;
void setShowBluetoothMode(bool newShowBluetoothMode);

private:


Expand Down Expand Up @@ -253,6 +259,8 @@ class SoundModel : public QObject

void audioMonoChanged();

void showBluetoothModeChanged();

private:
QString m_audioServer; // 当前使用音频框架
bool m_audioServerStatus{true}; // 设置音频时的状态
Expand Down Expand Up @@ -309,6 +317,7 @@ class SoundModel : public QObject
int m_outPutCount;

bool m_audioMono;
bool m_showBluetoothMode;
};

#endif // DCC_SOUND_SOUNDMODEL_H
29 changes: 23 additions & 6 deletions src/plugin-sound/qml/MicrophonePage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import org.deepin.dcc 1.0
DccObject {
id: root

// readonly property int itemDelegateMaxWidth: parent.width
// readonly property int itemDelegateMaxheight: 40

function toPercent(value: string) {
return Number(value * 100).toFixed(0) + "%"
}
Expand All @@ -35,18 +32,39 @@ DccObject {
}

DccObject {
name: "inputGroup"
name: "noIntput"
parentName: "sound/inPut"
weight: 20
pageType: DccObject.Item
backgroundType: DccObject.Normal
visible: dccData.model().inPutPortCombo.length === 0
page: Column {
width: parent.width
Label {
height: 100
width: parent.width
Layout.leftMargin: 10
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
font: DTK.fontManager.t4
text: qsTr("No input device for sound found")
}
}
}

DccObject {
name: "inputGroup"
parentName: "sound/inPut"
weight: 30
pageType: DccObject.Item
page: DccGroupView {}
visible: dccData.model().inPutPortCombo.length !== 0
DccObject{
name: "inputVolume"
parentName: "sound/inPut/inputGroup"
displayName: qsTr("Input Volume")
weight: 10
pageType: DccObject.Editor
visible: dccData.model().inPutPortCombo.length !== 0
page: RowLayout {
Layout.alignment: Qt.AlignRight

Expand Down Expand Up @@ -102,7 +120,6 @@ DccObject {
displayName: qsTr("Input Level")
weight: 20
pageType: DccObject.Editor
visible: dccData.model().inPutPortCombo.length !== 0
page: RowLayout {
Layout.alignment: Qt.AlignRight
Layout.rightMargin: 10
Expand Down
58 changes: 54 additions & 4 deletions src/plugin-sound/qml/SpeakerPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,34 @@ DccObject {
}
}
}

DccObject {
name: "outputGroup"
name: "noOutput"
parentName: "sound/outPut"
weight: 20
pageType: DccObject.Item
backgroundType: DccObject.Normal
visible: dccData.model().outPutPortCombo.length === 0
page: Column {
width: parent.width
Label {
height: 100
width: parent.width
Layout.leftMargin: 10
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
font: DTK.fontManager.t4
text: qsTr("No output device for sound found")
}
}
}

DccObject {
name: "outputGroup"
parentName: "sound/outPut"
weight: 30
visible: dccData.model().outPutPortCombo.length !== 0
pageType: DccObject.Item
page: DccGroupView {
height: implicitHeight + 10
spacing: 0
Expand All @@ -42,7 +65,6 @@ DccObject {
displayName: qsTr("Output Volume")
weight: 10
pageType: DccObject.Editor
visible: dccData.model().outPutPortCombo.length !== 0
page: RowLayout {
Label {
font: DTK.fontManager.t7
Expand Down Expand Up @@ -91,7 +113,6 @@ DccObject {
displayName: qsTr("Volume Boost")
description: qsTr("If the volume is louder than 100%, it may distort audio and be harmful to output devices")
weight: 20
visible: dccData.model().outPutPortCombo.length !== 0
pageType: DccObject.Editor
page: Switch {
Layout.alignment: Qt.AlignRight
Expand All @@ -107,7 +128,6 @@ DccObject {
parentName: "sound/outPut/outputGroup"
displayName: qsTr("Left Right Balance")
weight: 30
visible: dccData.model().outPutPortCombo.length !== 0
pageType: DccObject.Editor
page: RowLayout {
Label {
Expand Down Expand Up @@ -195,5 +215,35 @@ DccObject {
}
}
}

DccObject {
name: "bluetoothMode"
parentName: "sound/outPut/outputGroup"
displayName: qsTr("Mode")
weight: 60
pageType: DccObject.Editor
visible: dccData.model().showBluetoothMode
page: ComboBox {
id: bluetoothModeCombo
Layout.alignment: Qt.AlignRight
Layout.rightMargin: 10
flat: true
model: dccData.model().bluetoothModeOpts
currentIndex: indexOfValue(dccData.model().currentBluetoothAudioMode)
property bool isInitialized: false
// 等待组件加载完成后,设置 isInitialized 为 true
Component.onCompleted: {
console.log("outputDevice onCompleted:", isInitialized)
incrementCurrentIndex()
isInitialized = true
}
onCurrentIndexChanged: {
console.log("Selected index:", currentIndex, isInitialized)
if (isInitialized) {
dccData.worker().setBluetoothMode(valueAt(currentIndex))
}
}
}
}
}
}
1 change: 1 addition & 0 deletions src/plugin-sound/qml/soundMain.qml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ DccObject {
displayName: qsTr("DevicesManger")
description: qsTr("Enable/disable audio devices")
icon: "equipment_management"
visible: dccData.model().inPutPortCount !== 0 || dccData.model().outPutCount !== 0
weight: 40
SoundDevicemanagesPage {}
}
Expand Down

0 comments on commit f047220

Please sign in to comment.